15 #ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H 16 #define LLVM_CLANG_AST_JSONNODEDUMPER_H 25 #include "llvm/Support/JSON.h" 30 bool FirstChild =
true;
35 llvm::json::OStream
JOS;
39 template <
typename Fn>
void AddChild(Fn DoAddChild) {
54 while (!Pending.empty()) {
66 std::string LabelStr = !Label.empty() ?
Label :
"inner";
67 bool WasFirstChild = FirstChild;
68 auto DumpWithIndent = [=](
bool IsLastChild) {
70 JOS.attributeBegin(LabelStr);
75 unsigned Depth = Pending.size();
82 while (Depth < Pending.size()) {
84 this->Pending.pop_back();
96 Pending.push_back(std::move(DumpWithIndent));
98 Pending.back()(
false);
99 Pending.back() = std::move(DumpWithIndent);
115 const comments::FullComment *>,
127 StringRef LastLocFilename;
128 unsigned LastLocLine, LastLocPresumedLine;
139 void attributeOnlyIfTrue(StringRef Key,
bool Value) {
141 JOS.attribute(Key, Value);
145 void writeBareSourceLocation(
SourceLocation Loc,
bool IsSpelling);
153 std::string createPointerRepresentation(
const void *Ptr);
155 llvm::json::Object createBareDeclRef(
const Decl *D);
156 void writeBareDeclRef(
const Decl *D);
157 llvm::json::Object createCXXRecordDefinitionData(
const CXXRecordDecl *RD);
160 llvm::json::Array createCastPath(
const CastExpr *
C);
162 void writePreviousDeclImpl(...) {}
164 template <
typename T>
void writePreviousDeclImpl(
const Mergeable<T> *D) {
167 JOS.attribute(
"firstRedecl", createPointerRepresentation(First));
170 template <
typename T>
void writePreviousDeclImpl(
const Redeclarable<T> *D) {
173 JOS.attribute(
"previousDecl", createPointerRepresentation(Prev));
175 void addPreviousDeclaration(
const Decl *D);
177 StringRef getCommentCommandName(
unsigned CommandID)
const;
183 :
NodeStreamer(OS), SM(SrcMgr), Ctx(Ctx), PrintPolicy(PrintPolicy),
184 Traits(Traits), LastLocLine(0), LastLocPresumedLine(0) {}
186 void Visit(
const Attr *A);
188 void Visit(
const Type *T);
190 void Visit(
const Decl *D);
194 const Decl *From =
nullptr, StringRef
Label = {});
204 void VisitArrayType(
const ArrayType *AT);
210 void VisitTagType(
const TagType *TT);
212 void VisitAutoType(
const AutoType *AT);
221 void VisitNamedDecl(
const NamedDecl *ND);
227 void VisitUsingDecl(
const UsingDecl *UD);
229 void VisitVarDecl(
const VarDecl *VD);
230 void VisitFieldDecl(
const FieldDecl *FD);
232 void VisitEnumDecl(
const EnumDecl *ED);
265 void VisitCastExpr(
const CastExpr *CE);
267 void VisitCallExpr(
const CallExpr *CE);
300 void VisitIfStmt(
const IfStmt *IS);
302 void VisitCaseStmt(
const CaseStmt *CS);
303 void VisitLabelStmt(
const LabelStmt *LS);
304 void VisitGotoStmt(
const GotoStmt *GS);
305 void VisitWhileStmt(
const WhileStmt *WS);
319 const comments::FullComment *);
321 const comments::FullComment *);
323 const comments::FullComment *);
325 const comments::FullComment *);
327 const comments::FullComment *);
329 const comments::FullComment *FC);
331 const comments::FullComment *FC);
333 const comments::FullComment *);
336 const comments::FullComment *);
338 const comments::FullComment *);
342 JSONNodeDumper NodeDumper;
344 template <
typename SpecializationDecl>
345 void writeTemplateDeclSpecialization(
const SpecializationDecl *SD,
346 bool DumpExplicitInst,
348 bool DumpedAny =
false;
349 for (
const auto *RedeclWithBadType : SD->redecls()) {
353 const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
358 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
359 "expected an injected-class-name");
363 switch (Redecl->getTemplateSpecializationKind()) {
366 if (!DumpExplicitInst)
372 NodeDumper.
AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });
384 NodeDumper.
AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
387 template <
typename TemplateDecl>
388 void writeTemplateDecl(
const TemplateDecl *TD,
bool DumpExplicitInst) {
399 for (
const auto *Child : TD->specializations())
400 writeTemplateDeclSpecialization(Child, DumpExplicitInst,
408 : NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {}
413 writeTemplateDecl(FTD,
true);
416 writeTemplateDecl(CTD,
false);
419 writeTemplateDecl(VTD,
false);
425 #endif // LLVM_CLANG_AST_JSONNODEDUMPER_H ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *FTD)
Defines the clang::ASTContext interface.
Represents a type that was referred to using an elaborated type keyword, e.g., struct S...
Represents a function declaration or definition.
A class which contains all the information about a particular captured value.
Represents the dependent type named by a dependently-scoped typename using declaration, e.g.
A (possibly-)qualified type.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
FunctionType - C99 6.7.5.3 - Function Declarators.
IfStmt - This represents an if/then/else.
An instance of this object exists for each enum constant that is defined.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Decl - This represents one declaration (or definition), e.g.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Represents a C++11 auto or C++14 decltype(auto) type.
The base class of the type hierarchy.
Declaration of a variable template.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represent a C++ namespace.
Represents a call to a C++ constructor.
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Represents a variable declaration or definition.
ObjCMethodDecl - Represents an instance or class method declaration.
Describes how types, statements, expressions, and declarations should be printed. ...
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Defines the clang::Expr interface and subclasses for C++ expressions.
LabelStmt - Represents a label, which has a substatement.
Represents a struct/union/class.
Provides common interface for the Decls that can be redeclared.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a member of a struct/union/class.
A simple visitor class that helps create attribute visitors.
void AddChild(StringRef Label, Fn DoAddChild)
Add a child of the current node with an optional label.
Represents an access specifier followed by colon ':'.
JSONNodeDumper & doGetNodeDelegate()
Represents Objective-C's @catch statement.
Describes an C or C++ initializer list.
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Represents a C++ using-declaration.
AssociationTy< true > ConstAssociation
A simple visitor class that helps create template argument visitors.
void VisitClassTemplateDecl(const ClassTemplateDecl *CTD)
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation...
A builtin binary operation expression such as "x + y" or "x <= y".
CaseStmt - Represent a case statement.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents an Objective-C protocol declaration.
Represents binding an expression to a temporary.
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Represents an ObjC class declaration.
Represents a linkage specification.
Represents an extended vector type where either the type or size is dependent.
Represents the this expression in C++.
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Represents a prototype with parameter type info, e.g.
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand...
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Declaration of a template type parameter.
ObjCSelectorExpr used for @selector in Objective-C.
Represents an expression that computes the length of a parameter pack.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
An expression that sends a message to the given Objective-C object or class.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Represents a GCC generic vector type.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx, const PrintingPolicy &PrintPolicy, const comments::CommandTraits *Traits)
static QualType Desugar(ASTContext &Context, QualType QT, bool &ShouldAKA)
This template specialization was implicitly instantiated from a template.
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Encodes a location in the source.
Interfaces are the core concept in Objective-C for object oriented design.
JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx, const PrintingPolicy &PrintPolicy, const comments::CommandTraits *Traits)
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)"...
ObjCCategoryDecl - Represents a category declaration.
This is a basic class for representing single OpenMP clause.
ObjCProtocolExpr used for protocol expression in Objective-C.
ASTNodeTraverser traverses the Clang AST for dumping purposes.
Represents one property declaration in an Objective-C interface.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
This template specialization was instantiated from a template due to an explicit instantiation defini...
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
ObjCBoxedExpr - used for generalized expression boxing.
NodeStreamer(raw_ostream &OS)
The injected class name of a C++ class template or class template partial specialization.
Represents a pack expansion of types.
CompoundAssignOperator - For compound assignments (e.g.
Represents a C11 generic selection.
AddrLabelExpr - The GNU address of label extension, representing &&label.
ast_type_traits::DynTypedNode Node
Represents a template argument.
Dataflow Directional Tag Classes.
[C99 6.4.2.2] - A predefined identifier such as func.
Represents a delete expression for memory deallocation and destructor calls, e.g. ...
The base class of all kinds of template declarations (e.g., class, function, etc.).
This template specialization was instantiated from a template due to an explicit instantiation declar...
Represents the declaration of an Objective-C type parameter.
A pointer to member type per C++ 8.3.3 - Pointers to members.
SwitchStmt - This represents a 'switch' stmt.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
Represents a C++ base or member initializer.
This template specialization was declared or defined by an explicit specialization (C++ [temp...
ObjCEncodeExpr, used for @encode in Objective-C.
Base for LValueReferenceType and RValueReferenceType.
Represents a base class of a C++ class.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
void VisitVarTemplateDecl(const VarTemplateDecl *VTD)
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
GotoStmt - This represents a direct goto.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Represents a C++ struct/union/class.
ObjCIvarDecl - Represents an ObjC instance variable.
WhileStmt - This represents a 'while' stmt.
Declaration of a class template.
StringLiteral - This represents a string literal expression, e.g.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
A reference to a declared variable, function, enum, etc.
Represents a type template specialization; the template must be a class template, a type alias templa...
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
A boolean literal, per ([C++ lex.bool] Boolean literals).
Represents a C++ namespace alias.
void AddChild(Fn DoAddChild)
Add a child of the current node. Calls DoAddChild without arguments.
Represents C++ using-directive.
A simple visitor class that helps create declaration visitors.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Represents the canonical version of C arrays with a specified constant size.
This class handles loading and caching of source files into memory.
Declaration of a template function.
Attr - This represents one attribute.
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
ObjCCompatibleAliasDecl - Represents alias of a class.