clang: include/clang/AST/JSONNodeDumper.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_AST_JSONNODEDUMPER_H

15#define LLVM_CLANG_AST_JSONNODEDUMPER_H

16

27#include "llvm/Support/JSON.h"

28

30

32

34 bool FirstChild = true;

35 bool TopLevel = true;

36 llvm::SmallVector<std::function<void(bool IsLastChild)>, 32> Pending;

37

38protected:

39 llvm::json::OStream JOS;

40

41public:

42

43 template void AddChild(Fn DoAddChild) {

44 return AddChild("", DoAddChild);

45 }

46

47

48

49 template void AddChild(StringRef Label, Fn DoAddChild) {

50

51

52 if (TopLevel) {

53 TopLevel = false;

54 JOS.objectBegin();

55

56 DoAddChild();

57

58 while (!Pending.empty()) {

59 Pending.back()(true);

60 Pending.pop_back();

61 }

62

63 JOS.objectEnd();

64 TopLevel = true;

65 return;

66 }

67

68

69

70 std::string LabelStr(Label.empty() ? Label : "inner");

71 bool WasFirstChild = FirstChild;

72 auto DumpWithIndent = [=](bool IsLastChild) {

73 if (WasFirstChild) {

74 JOS.attributeBegin(LabelStr);

75 JOS.arrayBegin();

76 }

77

78 FirstChild = true;

79 unsigned Depth = Pending.size();

80 JOS.objectBegin();

81

82 DoAddChild();

83

84

85

86 while (Depth < Pending.size()) {

87 Pending.back()(true);

88 this->Pending.pop_back();

89 }

90

91 JOS.objectEnd();

92

93 if (IsLastChild) {

94 JOS.arrayEnd();

95 JOS.attributeEnd();

96 }

97 };

98

99 if (FirstChild) {

100 Pending.push_back(std::move(DumpWithIndent));

101 } else {

102 Pending.back()(false);

103 Pending.back() = std::move(DumpWithIndent);

104 }

105 FirstChild = false;

106 }

107

109};

110

111

112

113

114

115

119 const comments::FullComment *>,

126

132 StringRef LastLocFilename, LastLocPresumedFilename;

133 unsigned LastLocLine, LastLocPresumedLine;

134

143

144 void attributeOnlyIfTrue(StringRef Key, bool Value) {

147 }

148

149 void writeIncludeStack(PresumedLoc Loc, bool JustFirst = false);

150

151

152 void writeBareSourceLocation(SourceLocation Loc, bool IsSpelling);

153

154

155

156

157

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);

166 llvm::json::Object createCXXBaseSpecifier(const CXXBaseSpecifier &BS);

168 llvm::json::Array createCastPath(const CastExpr *C);

169

170 void writePreviousDeclImpl(...) {}

171

172 template void writePreviousDeclImpl(const Mergeable *D) {

173 const T *First = D->getFirstDecl();

175 JOS.attribute("firstRedecl", createPointerRepresentation(First));

176 }

177

178 template void writePreviousDeclImpl(const Redeclarable *D) {

179 const T *Prev = D->getPreviousDecl();

180 if (Prev)

181 JOS.attribute("previousDecl", createPointerRepresentation(Prev));

182 }

183 void addPreviousDeclaration(const Decl *D);

184

185 StringRef getCommentCommandName(unsigned CommandID) const;

186

187public:

191 : NodeStreamer(OS), SM(SrcMgr), Ctx(Ctx), ASTNameGen(Ctx),

192 PrintPolicy(PrintPolicy), Traits(Traits), LastLocLine(0),

193 LastLocPresumedLine(0) {}

194

201

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 *);

213

221

236 void

246

270

283

316

326

333

342

352

354 const comments::FullComment *);

356 const comments::FullComment *);

358 const comments::FullComment *);

360 const comments::FullComment *);

362 const comments::FullComment *);

364 const comments::FullComment *FC);

366 const comments::FullComment *FC);

368 const comments::FullComment *);

369 void

371 const comments::FullComment *);

373 const comments::FullComment *);

374};

375

378

379 template

380 void writeTemplateDeclSpecialization(const SpecializationDecl *SD,

381 bool DumpExplicitInst,

382 bool DumpRefOnly) {

383 bool DumpedAny = false;

384 for (const auto *RedeclWithBadType : SD->redecls()) {

385

386

387

388 const auto *Redecl = dyn_cast(RedeclWithBadType);

389 if (!Redecl) {

390

391

392

393 assert(isa(RedeclWithBadType) &&

394 "expected an injected-class-name");

395 continue;

396 }

397

398 switch (Redecl->getTemplateSpecializationKind()) {

401 if (!DumpExplicitInst)

402 break;

403 [[fallthrough]];

406 if (DumpRefOnly)

407 NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(Redecl); });

408 else

410 DumpedAny = true;

411 break;

413 break;

414 }

415 }

416

417

418 if (!DumpedAny)

419 NodeDumper.AddChild([=] { NodeDumper.writeBareDeclRef(SD); });

420 }

421

422 template

423 void writeTemplateDecl(const TemplateDecl *TD, bool DumpExplicitInst) {

424

425

426

427

428

429

431

433

434 for (const auto *Child : TD->specializations())

435 writeTemplateDeclSpecialization(Child, DumpExplicitInst,

437 }

438

439public:

443 : NodeDumper(OS, SrcMgr, Ctx, PrintPolicy, Traits) {}

444

446

448 writeTemplateDecl(FTD, true);

449 }

451 writeTemplateDecl(CTD, false);

452 }

454 writeTemplateDecl(VTD, false);

455 }

456};

457

458}

459

460#endif

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 VisitOpenACCAsteriskSizeExpr(const OpenACCAsteriskSizeExpr *E)

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.