14#ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H
15#define LLVM_CLANG_AST_JSONNODEDUMPER_H
27#include "llvm/Support/JSON.h"
34 bool FirstChild =
true;
39 llvm::json::OStream
JOS;
43 template <
typename Fn>
void AddChild(Fn DoAddChild) {
58 while (!Pending.empty()) {
70 std::string LabelStr(!
Label.empty() ?
Label :
"inner");
71 bool WasFirstChild = FirstChild;
72 auto DumpWithIndent = [=](
bool IsLastChild) {
74 JOS.attributeBegin(LabelStr);
79 unsigned Depth = Pending.size();
86 while (Depth < Pending.size()) {
88 this->Pending.pop_back();
100 Pending.push_back(std::move(DumpWithIndent));
102 Pending.back()(
false);
103 Pending.back() = std::move(DumpWithIndent);
119 const comments::FullComment *>,
132 StringRef LastLocFilename, LastLocPresumedFilename;
133 unsigned LastLocLine, LastLocPresumedLine;
144 void attributeOnlyIfTrue(StringRef Key,
bool Value) {
160 std::string createPointerRepresentation(
const void *Ptr);
161 llvm::json::Object createQualType(
QualType QT,
bool Desugar =
true);
162 llvm::json::Object createBareDeclRef(
const Decl *
D);
164 void writeBareDeclRef(
const Decl *
D);
165 llvm::json::Object createCXXRecordDefinitionData(
const CXXRecordDecl *RD);
168 llvm::json::Array createCastPath(
const CastExpr *
C);
170 void writePreviousDeclImpl(...) {}
172 template <
typename T>
void writePreviousDeclImpl(
const Mergeable<T> *
D) {
173 const T *
First =
D->getFirstDecl();
175 JOS.attribute(
"firstRedecl", createPointerRepresentation(
First));
178 template <
typename T>
void writePreviousDeclImpl(
const Redeclarable<T> *
D) {
179 const T *Prev =
D->getPreviousDecl();
181 JOS.attribute(
"previousDecl", createPointerRepresentation(Prev));
183 void addPreviousDeclaration(
const Decl *
D);
185 StringRef getCommentCommandName(
unsigned CommandID)
const;
192 PrintPolicy(PrintPolicy), Traits(Traits), LastLocLine(0),
193 LastLocPresumedLine(0) {}
204 const Decl *From =
nullptr, StringRef
Label = {});
205 void Visit(
const CXXCtorInitializer *
Init);
206 void Visit(
const OpenACCClause *
C);
207 void Visit(
const OMPClause *
C);
208 void Visit(
const BlockDecl::Capture &
C);
210 void Visit(
const concepts::Requirement *R);
211 void Visit(
const APValue &
Value, QualType Ty);
212 void Visit(
const ConceptReference *);
353 const comments::FullComment *);
355 const comments::FullComment *);
357 const comments::FullComment *);
359 const comments::FullComment *);
361 const comments::FullComment *);
363 const comments::FullComment *FC);
365 const comments::FullComment *FC);
367 const comments::FullComment *);
370 const comments::FullComment *);
372 const comments::FullComment *);
378 template <
typename SpecializationDecl>
379 void writeTemplateDeclSpecialization(
const SpecializationDecl *SD,
380 bool DumpExplicitInst,
382 bool DumpedAny =
false;
383 for (
const auto *RedeclWithBadType : SD->redecls()) {
387 const auto *Redecl = dyn_cast<SpecializationDecl>(RedeclWithBadType);
392 assert(isa<CXXRecordDecl>(RedeclWithBadType) &&
393 "expected an injected-class-name");
397 switch (Redecl->getTemplateSpecializationKind()) {
400 if (!DumpExplicitInst)
406 NodeDumper.
AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });
418 NodeDumper.
AddChild([=] { NodeDumper.writeBareDeclRef(SD); });
421 template <
typename TemplateDecl>
422 void writeTemplateDecl(
const TemplateDecl *TD,
bool DumpExplicitInst) {
433 for (
const auto *Child : TD->specializations())
434 writeTemplateDeclSpecialization(Child, DumpExplicitInst,
442 : NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {}
447 writeTemplateDecl(FTD,
true);
450 writeTemplateDecl(CTD,
false);
453 writeTemplateDecl(VTD,
false);
Defines the clang::ASTContext interface.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ASTNodeTraverser traverses the Clang AST for dumping purposes.
void Visit(const Decl *D, bool VisitLocs=false)
void dumpTemplateParameters(const TemplateParameterList *TPL)
Attr - This represents one attribute.
Represents a base class of a C++ class.
Represents a C++ struct/union/class.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Declaration of a class template.
A simple visitor class that helps create attribute visitors.
A simple visitor class that helps create declaration visitors.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
A simple visitor class that helps create template argument visitors.
Decl - This represents one declaration (or definition), e.g.
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Represents difference between two FPOptions values.
Declaration of a template function.
AssociationTy< true > ConstAssociation
void VisitClassTemplateDecl(const ClassTemplateDecl *CTD)
void VisitVarTemplateDecl(const VarTemplateDecl *VTD)
JSONNodeDumper & doGetNodeDelegate()
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *FTD)
JSONDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx, const PrintingPolicy &PrintPolicy, const comments::CommandTraits *Traits)
void VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *OSRE)
void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D)
void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE)
void VisitCleanupAttr(const CleanupAttr *CA)
void VisitCaseStmt(const CaseStmt *CS)
void VisitImplicitCastExpr(const ImplicitCastExpr *ICE)
void VisitNamespaceAliasDecl(const NamespaceAliasDecl *NAD)
void VisitFunctionProtoType(const FunctionProtoType *T)
void VisitObjCImplementationDecl(const ObjCImplementationDecl *D)
void VisitVectorType(const VectorType *VT)
void VisitFunctionDecl(const FunctionDecl *FD)
void VisitObjCProtocolExpr(const ObjCProtocolExpr *OPE)
void VisitUsingDecl(const UsingDecl *UD)
void VisitEnumConstantDecl(const EnumConstantDecl *ECD)
void VisitConstantExpr(const ConstantExpr *CE)
void VisitRequiresExpr(const RequiresExpr *RE)
void VisitExprWithCleanups(const ExprWithCleanups *EWC)
void VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *BLE)
void VisitTagType(const TagType *TT)
void Visit(const Attr *A)
void VisitLabelStmt(const LabelStmt *LS)
void VisitRValueReferenceType(const ReferenceType *RT)
void VisitObjCInterfaceType(const ObjCInterfaceType *OIT)
void VisitCXXConstructExpr(const CXXConstructExpr *CE)
void VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE)
void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *ME)
void VisitStringLiteral(const StringLiteral *SL)
void VisitBlockDecl(const BlockDecl *D)
void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *Node)
void VisitSizeOfPackExpr(const SizeOfPackExpr *SOPE)
void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *UCE)
void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE)
void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D)
void VisitAccessSpecDecl(const AccessSpecDecl *ASD)
void VisitDeprecatedAttr(const DeprecatedAttr *DA)
void VisitMemberPointerType(const MemberPointerType *MPT)
void VisitMemberExpr(const MemberExpr *ME)
void visitBlockCommandComment(const comments::BlockCommandComment *C, const comments::FullComment *)
void VisitCXXRecordDecl(const CXXRecordDecl *RD)
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D)
void VisitSwitchStmt(const SwitchStmt *SS)
void visitHTMLEndTagComment(const comments::HTMLEndTagComment *C, const comments::FullComment *)
void VisitBinaryOperator(const BinaryOperator *BO)
void visitVerbatimBlockLineComment(const comments::VerbatimBlockLineComment *C, const comments::FullComment *)
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D)
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D)
void VisitLinkageSpecDecl(const LinkageSpecDecl *LSD)
void VisitTypedefDecl(const TypedefDecl *TD)
void VisitTypedefType(const TypedefType *TT)
void VisitUnresolvedUsingType(const UnresolvedUsingType *UUT)
void VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T)
void VisitElaboratedType(const ElaboratedType *ET)
void VisitUnaryTransformType(const UnaryTransformType *UTT)
void VisitCallExpr(const CallExpr *CE)
void VisitVisibilityAttr(const VisibilityAttr *VA)
void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO)
void visitParamCommandComment(const comments::ParamCommandComment *C, const comments::FullComment *FC)
void visitVerbatimBlockComment(const comments::VerbatimBlockComment *C, const comments::FullComment *)
void VisitAtomicExpr(const AtomicExpr *AE)
void VisitUsingShadowDecl(const UsingShadowDecl *USD)
void VisitFloatingLiteral(const FloatingLiteral *FL)
void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT)
void VisitUsingDirectiveDecl(const UsingDirectiveDecl *UDD)
void VisitTemplateSpecializationType(const TemplateSpecializationType *TST)
void VisitWhileStmt(const WhileStmt *WS)
void VisitDeclarationTemplateArgument(const TemplateArgument &TA)
void VisitVarDecl(const VarDecl *VD)
void VisitEnumDecl(const EnumDecl *ED)
void VisitPackTemplateArgument(const TemplateArgument &TA)
void VisitTemplateExpansionTemplateArgument(const TemplateArgument &TA)
void visitTextComment(const comments::TextComment *C, const comments::FullComment *)
void VisitFieldDecl(const FieldDecl *FD)
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE)
void VisitIntegralTemplateArgument(const TemplateArgument &TA)
void VisitObjCSelectorExpr(const ObjCSelectorExpr *OSE)
void VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E)
void VisitDeclRefExpr(const DeclRefExpr *DRE)
void VisitNullPtrTemplateArgument(const TemplateArgument &TA)
void VisitNamespaceDecl(const NamespaceDecl *ND)
void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *OIRE)
void visitVerbatimLineComment(const comments::VerbatimLineComment *C, const comments::FullComment *)
void VisitAutoType(const AutoType *AT)
void VisitObjCIvarDecl(const ObjCIvarDecl *D)
void VisitUnavailableAttr(const UnavailableAttr *UA)
void VisitMacroQualifiedType(const MacroQualifiedType *MQT)
void VisitObjCPropertyDecl(const ObjCPropertyDecl *D)
void VisitObjCMethodDecl(const ObjCMethodDecl *D)
void visitTParamCommandComment(const comments::TParamCommandComment *C, const comments::FullComment *FC)
void VisitAddrLabelExpr(const AddrLabelExpr *ALE)
void VisitPredefinedExpr(const PredefinedExpr *PE)
void VisitAliasAttr(const AliasAttr *AA)
void VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D)
void VisitPackExpansionType(const PackExpansionType *PET)
void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *VT)
void visitHTMLStartTagComment(const comments::HTMLStartTagComment *C, const comments::FullComment *)
void VisitSectionAttr(const SectionAttr *SA)
void VisitUsingType(const UsingType *TT)
void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *STTPT)
void VisitArrayType(const ArrayType *AT)
void VisitTypeTemplateArgument(const TemplateArgument &TA)
void VisitObjCBoxedExpr(const ObjCBoxedExpr *OBE)
void VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D)
void VisitGenericSelectionExpr(const GenericSelectionExpr *GSE)
void VisitTemplateTemplateArgument(const TemplateArgument &TA)
void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *Node)
void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *OBLE)
void VisitFixedPointLiteral(const FixedPointLiteral *FPL)
void VisitGotoStmt(const GotoStmt *GS)
void VisitCharacterLiteral(const CharacterLiteral *CL)
void VisitInitListExpr(const InitListExpr *ILE)
void VisitObjCProtocolDecl(const ObjCProtocolDecl *D)
void VisitTLSModelAttr(const TLSModelAttr *TA)
void VisitCompoundStmt(const CompoundStmt *IS)
void VisitHLSLBufferDecl(const HLSLBufferDecl *D)
void VisitCXXThisExpr(const CXXThisExpr *TE)
void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE)
void VisitConstantArrayType(const ConstantArrayType *CAT)
void VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D)
void VisitCXXNewExpr(const CXXNewExpr *NE)
void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *OACS)
void VisitNullTemplateArgument(const TemplateArgument &TA)
void VisitCastExpr(const CastExpr *CE)
void VisitInjectedClassNameType(const InjectedClassNameType *ICNT)
JSONNodeDumper(raw_ostream &OS, const SourceManager &SrcMgr, ASTContext &Ctx, const PrintingPolicy &PrintPolicy, const comments::CommandTraits *Traits)
void VisitIfStmt(const IfStmt *IS)
void VisitUnaryOperator(const UnaryOperator *UO)
void visitInlineCommandComment(const comments::InlineCommandComment *C, const comments::FullComment *)
void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *TTE)
void VisitIntegerLiteral(const IntegerLiteral *IL)
void VisitUsingEnumDecl(const UsingEnumDecl *UED)
void VisitObjCMessageExpr(const ObjCMessageExpr *OME)
void VisitFunctionType(const FunctionType *T)
void VisitRecordDecl(const RecordDecl *RD)
void VisitTypeAliasDecl(const TypeAliasDecl *TAD)
void VisitExpressionTemplateArgument(const TemplateArgument &TA)
void VisitNamedDecl(const NamedDecl *ND)
void VisitObjCCategoryDecl(const ObjCCategoryDecl *D)
void VisitFriendDecl(const FriendDecl *FD)
void VisitCXXDeleteExpr(const CXXDeleteExpr *DE)
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *MTE)
void AddChild(Fn DoAddChild)
Add a child of the current node. Calls DoAddChild without arguments.
NodeStreamer(raw_ostream &OS)
void AddChild(StringRef Label, Fn DoAddChild)
Add a child of the current node with an optional label.
Represents an unpacked "presumed" location which can be presented to the user.
A (possibly-)qualified type.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Represents a template argument.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Base wrapper for a particular "section" of type source info.
The base class of the type hierarchy.
Declaration of a variable template.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Describes how types, statements, expressions, and declarations should be printed.