Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
// similar to RecursiveASTVisitor.
//
//===----------------------------------------------------------------------===//
//
// Modifications to this file by SEI staff are copyright Carnegie Mellon
// University and contributed under the Apache License v2.0 with LLVM
// Exceptions.
Comment on lines +15 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @llvm-beanz regarding licensing concerns. Pretty sure this is not something we can accept per: https://llvm.org/docs/DeveloperPolicy.html#embedded-copyright-or-contributed-by-statements

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed. We do not accept embedded copyright notices.

//
// SEI Contributions are made with funding sand support from the Department of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SEI Contributions are made with funding sand support from the Department of
// SEI Contributions are made with funding and support from the Department of

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, but we probably can't allow this copyright notice anyway, per project policy.

// Defense under Contract No. FA8702-15-D-0002 with Carnegie Mellon University
// for the operation of the Software Engineering Institute, a federally funded
// research and development center.
//
// The view, opinions, and/or findings contained in this material are those of
// the author(s) and should not be construed as an official Government position,
// policy, or decision, unless designated by other documentation.
// DM24-0194
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_ASTNODETRAVERSER_H
#define LLVM_CLANG_AST_ASTNODETRAVERSER_H
Expand Down Expand Up @@ -177,14 +193,34 @@ class ASTNodeTraverser
if (!SQT.Quals.hasQualifiers())
return Visit(SQT.Ty);

getNodeDelegate().AddChild([=] {
// SEI: changed from default label to "qualTypeDetail"
getNodeDelegate().AddChild("qualTypeDetail", [this, T] {
getNodeDelegate().Visit(T);
Visit(T.split().Ty);
});

// SEI function pointer support. this gets called whenever the three
// conditions are met:
// 1. the function pointer is not typedef'd
// 2. after Visit(VarDecl *) gets called
// 3. if VarDecl determines this is a function pointer
if (T->isFunctionPointerType()) {
// create as a child node to this type
getNodeDelegate().AddChild(
[=] { getNodeDelegate().Visit(T->getPointeeType()); });
}

// SEI: traverse PointerType information
if (T->isPointerType())
Visit(T->getPointeeType());
}

// SEI: traverse ReturnType information
void VisitReturnType(QualType T) { getNodeDelegate().VisitReturnType(T); }

void Visit(const Type *T) {
getNodeDelegate().AddChild([=] {
// SEI: renamed this from default label
getNodeDelegate().AddChild("typeDetails", [this, T] {
getNodeDelegate().Visit(T);
if (!T)
return;
Expand All @@ -209,7 +245,8 @@ class ASTNodeTraverser
}

void Visit(const Attr *A) {
getNodeDelegate().AddChild([=] {
// SEI: renamed from default label
getNodeDelegate().AddChild("attrDetails", [this, A] {
getNodeDelegate().Visit(A);
ConstAttrVisitor<Derived>::Visit(A);
});
Expand Down Expand Up @@ -416,8 +453,20 @@ class ASTNodeTraverser
Visit(T->getSizeExpr());
}
void VisitVectorType(const VectorType *T) { Visit(T->getElementType()); }
void VisitFunctionType(const FunctionType *T) { Visit(T->getReturnType()); }
void VisitFunctionType(const FunctionType *T) {

Visit(T->getReturnType());

// SEI: add functionDetails, incl. return type
getNodeDelegate().AddChild("functionDetails", [this, T] {
getNodeDelegate().VisitFunctionType(T);
getNodeDelegate().VisitReturnType(T->getReturnType());
});
}

void VisitFunctionProtoType(const FunctionProtoType *T) {

// SEI: visit the function type. this will force the return type info too.
VisitFunctionType(T);
for (const QualType &PT : T->getParamTypes())
Visit(PT);
Expand Down Expand Up @@ -585,6 +634,12 @@ class ASTNodeTraverser
Visit(TSI->getTypeLoc());
if (D->hasInit())
Visit(D->getInit());

// SEI: if this is a function pointer, then we need to get the
// FunctionProtoType and then make add'l visits. if the FP is typedef'd,
// then this behavior occurs for us outside of Visit(VarDecl *)
//getNodeDelegate().Visit(D->getType(), true);
Visit(D->getType());
}

void VisitDecompositionDecl(const DecompositionDecl *D) {
Expand Down
49 changes: 47 additions & 2 deletions clang/include/clang/AST/JSONNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
// a JSON.
//
//===----------------------------------------------------------------------===//
//
// Modifications to this file by SEI staff are copyright Carnegie Mellon
// University and contributed under the Apache License v2.0 with LLVM
// Exceptions.
//
// SEI Contributions are made with funding sand support from the Department of
// Defense under Contract No. FA8702-15-D-0002 with Carnegie Mellon University
// for the operation of the Software Engineering Institute, a federally funded
// research and development center.
//
// The view, opinions, and/or findings contained in this material are those of
// the author(s) and should not be construed as an official Government position,
// policy, or decision, unless designated by other documentation.
// DM24-0194
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H
#define LLVM_CLANG_AST_JSONNODEDUMPER_H
Expand All @@ -26,6 +42,9 @@
#include "clang/AST/Type.h"
#include "llvm/Support/JSON.h"

// SEI: added for caching addresses of certain visited nodes
#include <unordered_set>

namespace clang {

class APValue;
Expand Down Expand Up @@ -111,8 +130,8 @@ class NodeStreamer {
// Dumps AST nodes in JSON format. There is no implied stability for the
// content or format of the dump between major releases of Clang, other than it
// being valid JSON output. Further, there is no requirement that the
// information dumped is a complete representation of the AST, only that the
// information presented is correct.
// information dumped be a complete representation of the AST, only that the
// information presented be correct.
class JSONNodeDumper
: public ConstAttrVisitor<JSONNodeDumper>,
public comments::ConstCommentVisitor<JSONNodeDumper, void,
Expand All @@ -132,6 +151,9 @@ class JSONNodeDumper
StringRef LastLocFilename, LastLocPresumedFilename;
unsigned LastLocLine, LastLocPresumedLine;

// SEI: caches addresses for QualType nodes that are duplicates
std::unordered_set<void *> AddressCache;

using InnerAttrVisitor = ConstAttrVisitor<JSONNodeDumper>;
using InnerCommentVisitor =
comments::ConstCommentVisitor<JSONNodeDumper, void,
Expand Down Expand Up @@ -184,6 +206,18 @@ class JSONNodeDumper

StringRef getCommentCommandName(unsigned CommandID) const;

/// SEI: simple cacher for addresses of nodes to reduce
/// bloat caused by SEI changes
/// Return True if it's already cached, otherwise false
bool cacheAddress(void *p) {
if (AddressCache.find(p) == AddressCache.end()) {
AddressCache.insert(p);
return false;
}

return true;
}

public:
JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx,
const PrintingPolicy &PrintPolicy,
Expand All @@ -196,6 +230,17 @@ class JSONNodeDumper
void Visit(const Stmt *Node);
void Visit(const Type *T);
void Visit(QualType T);

// SEI: forwarding function to Visit(QualType T); so that it's applied here
// from a VarDecl call
void Visit(QualType T, bool isFromDecl);

// SEI: get specific details from the qual type
void VisitQualTypeDetails(QualType T);

// SEI: traverse ReturnType information
void VisitReturnType(QualType T);

void Visit(const Decl *D);
void Visit(TypeLoc TL);

Expand Down
25 changes: 25 additions & 0 deletions clang/include/clang/AST/TextNodeDumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
// This file implements AST dumping of components of individual AST nodes.
//
//===----------------------------------------------------------------------===//
//
// Modifications to this file by SEI staff are copyright Carnegie Mellon
// University and contributed under the Apache License v2.0 with LLVM
// Exceptions.
//
// SEI Contributions are made with funding sand support from the Department of
// Defense under Contract No. FA8702-15-D-0002 with Carnegie Mellon University
// for the operation of the Software Engineering Institute, a federally funded
// research and development center.
//
// The view, opinions, and/or findings contained in this material are those of
// the author(s) and should not be construed as an official Government position,
// policy, or decision, unless designated by other documentation.
// DM24-0194
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_AST_TEXTNODEDUMPER_H
#define LLVM_CLANG_AST_TEXTNODEDUMPER_H
Expand Down Expand Up @@ -181,8 +197,17 @@ class TextNodeDumper

void Visit(QualType T);

// SEI: added to prevent this from being added whenever it comes from VarDecl
void Visit(QualType T, bool isFromDecl);

void Visit(TypeLoc);

// SEI: added support for getting ReturnType information
void VisitReturnType(QualType T);

// SEI: added support for more QT details. it's a passthrough for this class
void VisitQualTypeDetails(QualType T) {}

void Visit(const Decl *D);

void Visit(const CXXCtorInitializer *Init);
Expand Down
Loading