Index: include/clang/AST/ASTTextNodeDumper.h =================================================================== --- /dev/null +++ include/clang/AST/ASTTextNodeDumper.h @@ -0,0 +1,169 @@ +//===--- ASTTextNodeDumper.h - Printing of AST nodes ----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements AST dumping of components of individual AST nodes. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTTEXTNODEDUMPER_H +#define LLVM_CLANG_AST_ASTTEXTNODEDUMPER_H + +#include "clang/AST/ASTContext.h" +#include "clang/AST/ASTDumperUtils.h" +#include "clang/AST/ExprCXX.h" + +namespace clang { + +namespace ast_dumper { + +class TextNodeDumper { + raw_ostream &OS; + const bool ShowColors; + + /// Keep track of the last location we print out so that we can + /// print out deltas from then on out. + const char *LastLocFilename = ""; + unsigned LastLocLine = ~0U; + + const SourceManager *SM; + + /// The policy to use for printing; can be defaulted. + PrintingPolicy PrintPolicy; + +public: + TextNodeDumper(raw_ostream &OS, bool ShowColors, const SourceManager *SM, + const PrintingPolicy &PrintPolicy) + : OS(OS), ShowColors(ShowColors), SM(SM), PrintPolicy(PrintPolicy) {} + + void dumpPointer(const void *Ptr) { + ColorScope Color(OS, ShowColors, AddressColor); + OS << ' ' << Ptr; + } + + void dumpLocation(SourceLocation Loc) { + if (!SM) + return; + + ColorScope Color(OS, ShowColors, LocationColor); + SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); + + // The general format we print out is filename:line:col, but we drop pieces + // that haven't changed since the last loc printed. + PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc); + + if (PLoc.isInvalid()) { + OS << ""; + return; + } + + if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) { + OS << PLoc.getFilename() << ':' << PLoc.getLine() << ':' + << PLoc.getColumn(); + LastLocFilename = PLoc.getFilename(); + LastLocLine = PLoc.getLine(); + } else if (PLoc.getLine() != LastLocLine) { + OS << "line" << ':' << PLoc.getLine() << ':' << PLoc.getColumn(); + LastLocLine = PLoc.getLine(); + } else { + OS << "col" << ':' << PLoc.getColumn(); + } + } + + void dumpSourceRange(SourceRange R) { + // Can't translate locations if a SourceManager isn't available. + if (!SM) + return; + + OS << " <"; + dumpLocation(R.getBegin()); + if (R.getBegin() != R.getEnd()) { + OS << ", "; + dumpLocation(R.getEnd()); + } + OS << ">"; + + // + } + + void dumpBareType(QualType T, bool Desugar = true) { + ColorScope Color(OS, ShowColors, TypeColor); + + SplitQualType T_split = T.split(); + OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'"; + + if (Desugar && !T.isNull()) { + // If the type is sugared, also dump a (shallow) desugared type. + SplitQualType D_split = T.getSplitDesugaredType(); + if (T_split != D_split) + OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'"; + } + } + + void dumpType(QualType T) { + OS << ' '; + dumpBareType(T); + } + + void dumpBareDeclRef(const Decl *D) { + if (!D) { + ColorScope Color(OS, ShowColors, NullColor); + OS << "<<>>"; + return; + } + + { + ColorScope Color(OS, ShowColors, DeclKindNameColor); + OS << D->getDeclKindName(); + } + dumpPointer(D); + + if (const NamedDecl *ND = dyn_cast(D)) { + ColorScope Color(OS, ShowColors, DeclNameColor); + OS << " '" << ND->getDeclName() << '\''; + } + + if (const ValueDecl *VD = dyn_cast(D)) + dumpType(VD->getType()); + } + + void dumpName(const NamedDecl *ND) { + if (ND->getDeclName()) { + ColorScope Color(OS, ShowColors, DeclNameColor); + OS << ' ' << ND->getNameAsString(); + } + } + + void dumpAccessSpecifier(AccessSpecifier AS) { + switch (AS) { + case AS_none: + break; + case AS_public: + OS << "public"; + break; + case AS_protected: + OS << "protected"; + break; + case AS_private: + OS << "private"; + break; + } + } + + void dumpCXXTemporary(const CXXTemporary *Temporary) { + OS << "(CXXTemporary"; + dumpPointer(Temporary); + OS << ")"; + } +}; + +} // namespace ast_dumper + +} // namespace clang + +#endif // LLVM_CLANG_AST_ASTTEXTNODEDUMPER_H Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -14,6 +14,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ASTDumperUtils.h" +#include "clang/AST/ASTTextNodeDumper.h" #include "clang/AST/Attr.h" #include "clang/AST/CommentVisitor.h" #include "clang/AST/DeclCXX.h" @@ -45,6 +46,7 @@ public TypeVisitor { TextChildDumper ChildDumper; + TextNodeDumper NodeDumper; raw_ostream &OS; const CommandTraits *Traits; @@ -57,11 +59,6 @@ /// not already been loaded. bool Deserialize = false; - /// Keep track of the last location we print out so that we can - /// print out deltas from then on out. - const char *LastLocFilename = ""; - unsigned LastLocLine = ~0U; - const bool ShowColors; /// Dump a child of the current node. @@ -81,8 +78,9 @@ ASTDumper(raw_ostream &OS, const CommandTraits *Traits, const SourceManager *SM, bool ShowColors, const PrintingPolicy &PrintPolicy) - : ChildDumper(OS, ShowColors), OS(OS), Traits(Traits), SM(SM), - PrintPolicy(PrintPolicy), ShowColors(ShowColors) {} + : ChildDumper(OS, ShowColors), + NodeDumper(OS, ShowColors, SM, PrintPolicy), OS(OS), Traits(Traits), + SM(SM), PrintPolicy(PrintPolicy), ShowColors(ShowColors) {} void setDeserialize(bool D) { Deserialize = D; } @@ -91,23 +89,17 @@ void dumpFullComment(const FullComment *C); // Utilities - void dumpPointer(const void *Ptr); - void dumpSourceRange(SourceRange R); - void dumpLocation(SourceLocation Loc); - void dumpBareType(QualType T, bool Desugar = true); - void dumpType(QualType T); + void dumpType(QualType T) { NodeDumper.dumpType(T); } void dumpTypeAsChild(QualType T); void dumpTypeAsChild(const Type *T); - void dumpBareDeclRef(const Decl *Node); void dumpDeclRef(const Decl *Node, const char *Label = nullptr); - void dumpName(const NamedDecl *D); + void dumpBareDeclRef(const Decl *Node) { NodeDumper.dumpBareDeclRef(Node); } bool hasNodes(const DeclContext *DC); void dumpDeclContext(const DeclContext *DC); void dumpLookups(const DeclContext *DC, bool DumpDecls); void dumpAttr(const Attr *A); // C++ Utilities - void dumpAccessSpecifier(AccessSpecifier AS); void dumpCXXCtorInitializer(const CXXCtorInitializer *Init); void dumpTemplateParameters(const TemplateParameterList *TPL); void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); @@ -156,20 +148,20 @@ } void VisitVariableArrayType(const VariableArrayType *T) { OS << " "; - dumpSourceRange(T->getBracketsRange()); + NodeDumper.dumpSourceRange(T->getBracketsRange()); VisitArrayType(T); dumpStmt(T->getSizeExpr()); } void VisitDependentSizedArrayType(const DependentSizedArrayType *T) { VisitArrayType(T); OS << " "; - dumpSourceRange(T->getBracketsRange()); + NodeDumper.dumpSourceRange(T->getBracketsRange()); dumpStmt(T->getSizeExpr()); } void VisitDependentSizedExtVectorType( const DependentSizedExtVectorType *T) { OS << " "; - dumpLocation(T->getAttributeLoc()); + NodeDumper.dumpLocation(T->getAttributeLoc()); dumpTypeAsChild(T->getElementType()); dumpStmt(T->getSizeExpr()); } @@ -421,7 +413,6 @@ void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node); void VisitExprWithCleanups(const ExprWithCleanups *Node); void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node); - void dumpCXXTemporary(const CXXTemporary *Temporary); void VisitLambdaExpr(const LambdaExpr *Node) { VisitExpr(Node); dumpDecl(Node->getLambdaClass()); @@ -475,77 +466,6 @@ // Utilities //===----------------------------------------------------------------------===// -void ASTDumper::dumpPointer(const void *Ptr) { - ColorScope Color(OS, ShowColors, AddressColor); - OS << ' ' << Ptr; -} - -void ASTDumper::dumpLocation(SourceLocation Loc) { - if (!SM) - return; - - ColorScope Color(OS, ShowColors, LocationColor); - SourceLocation SpellingLoc = SM->getSpellingLoc(Loc); - - // The general format we print out is filename:line:col, but we drop pieces - // that haven't changed since the last loc printed. - PresumedLoc PLoc = SM->getPresumedLoc(SpellingLoc); - - if (PLoc.isInvalid()) { - OS << ""; - return; - } - - if (strcmp(PLoc.getFilename(), LastLocFilename) != 0) { - OS << PLoc.getFilename() << ':' << PLoc.getLine() - << ':' << PLoc.getColumn(); - LastLocFilename = PLoc.getFilename(); - LastLocLine = PLoc.getLine(); - } else if (PLoc.getLine() != LastLocLine) { - OS << "line" << ':' << PLoc.getLine() - << ':' << PLoc.getColumn(); - LastLocLine = PLoc.getLine(); - } else { - OS << "col" << ':' << PLoc.getColumn(); - } -} - -void ASTDumper::dumpSourceRange(SourceRange R) { - // Can't translate locations if a SourceManager isn't available. - if (!SM) - return; - - OS << " <"; - dumpLocation(R.getBegin()); - if (R.getBegin() != R.getEnd()) { - OS << ", "; - dumpLocation(R.getEnd()); - } - OS << ">"; - - // - -} - -void ASTDumper::dumpBareType(QualType T, bool Desugar) { - ColorScope Color(OS, ShowColors, TypeColor); - - SplitQualType T_split = T.split(); - OS << "'" << QualType::getAsString(T_split, PrintPolicy) << "'"; - - if (Desugar && !T.isNull()) { - // If the type is sugared, also dump a (shallow) desugared type. - SplitQualType D_split = T.getSplitDesugaredType(); - if (T_split != D_split) - OS << ":'" << QualType::getAsString(D_split, PrintPolicy) << "'"; - } -} - -void ASTDumper::dumpType(QualType T) { - OS << ' '; - dumpBareType(T); -} - void ASTDumper::dumpTypeAsChild(QualType T) { SplitQualType SQT = T.split(); if (!SQT.Quals.hasQualifiers()) @@ -553,9 +473,9 @@ dumpChild([=] { OS << "QualType"; - dumpPointer(T.getAsOpaquePtr()); + NodeDumper.dumpPointer(T.getAsOpaquePtr()); OS << " "; - dumpBareType(T, false); + NodeDumper.dumpBareType(T, false); OS << " " << T.split().Quals.getAsString(); dumpTypeAsChild(T.split().Ty); }); @@ -573,7 +493,7 @@ ColorScope Color(OS, ShowColors, TypeColor); OS << "LocInfo Type"; } - dumpPointer(T); + NodeDumper.dumpPointer(T); dumpTypeAsChild(LIT->getTypeSourceInfo()->getType()); return; } @@ -582,9 +502,9 @@ ColorScope Color(OS, ShowColors, TypeColor); OS << T->getTypeClassName() << "Type"; } - dumpPointer(T); + NodeDumper.dumpPointer(T); OS << " "; - dumpBareType(QualType(T, 0), false); + NodeDumper.dumpBareType(QualType(T, 0), false); QualType SingleStepDesugar = T->getLocallyUnqualifiedSingleStepDesugaredType(); @@ -608,28 +528,6 @@ }); } -void ASTDumper::dumpBareDeclRef(const Decl *D) { - if (!D) { - ColorScope Color(OS, ShowColors, NullColor); - OS << "<<>>"; - return; - } - - { - ColorScope Color(OS, ShowColors, DeclKindNameColor); - OS << D->getDeclKindName(); - } - dumpPointer(D); - - if (const NamedDecl *ND = dyn_cast(D)) { - ColorScope Color(OS, ShowColors, DeclNameColor); - OS << " '" << ND->getDeclName() << '\''; - } - - if (const ValueDecl *VD = dyn_cast(D)) - dumpType(VD->getType()); -} - void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) { if (!D) return; @@ -641,13 +539,6 @@ }); } -void ASTDumper::dumpName(const NamedDecl *ND) { - if (ND->getDeclName()) { - ColorScope Color(OS, ShowColors, DeclNameColor); - OS << ' ' << ND->getNameAsString(); - } -} - bool ASTDumper::hasNodes(const DeclContext *DC) { if (!DC) return false; @@ -675,12 +566,12 @@ void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { dumpChild([=] { OS << "StoredDeclsMap "; - dumpBareDeclRef(cast(DC)); + NodeDumper.dumpBareDeclRef(cast(DC)); const DeclContext *Primary = DC->getPrimaryContext(); if (Primary != DC) { OS << " primary"; - dumpPointer(cast(Primary)); + NodeDumper.dumpPointer(cast(Primary)); } bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage(); @@ -702,7 +593,7 @@ for (DeclContextLookupResult::iterator RI = R.begin(), RE = R.end(); RI != RE; ++RI) { dumpChild([=] { - dumpBareDeclRef(*RI); + NodeDumper.dumpBareDeclRef(*RI); if ((*RI)->isHidden()) OS << " hidden"; @@ -742,8 +633,8 @@ } OS << "Attr"; } - dumpPointer(A); - dumpSourceRange(A->getRange()); + NodeDumper.dumpPointer(A); + NodeDumper.dumpSourceRange(A->getRange()); if (A->isInherited()) OS << " Inherited"; if (A->isImplicit()) @@ -785,32 +676,16 @@ // C++ Utilities //===----------------------------------------------------------------------===// -void ASTDumper::dumpAccessSpecifier(AccessSpecifier AS) { - switch (AS) { - case AS_none: - break; - case AS_public: - OS << "public"; - break; - case AS_protected: - OS << "protected"; - break; - case AS_private: - OS << "private"; - break; - } -} - void ASTDumper::dumpCXXCtorInitializer(const CXXCtorInitializer *Init) { dumpChild([=] { OS << "CXXCtorInitializer"; if (Init->isAnyMemberInitializer()) { OS << ' '; - dumpBareDeclRef(Init->getAnyMember()); + NodeDumper.dumpBareDeclRef(Init->getAnyMember()); } else if (Init->isBaseInitializer()) { - dumpType(QualType(Init->getBaseClass(), 0)); + NodeDumper.dumpType(QualType(Init->getBaseClass(), 0)); } else if (Init->isDelegatingInitializer()) { - dumpType(Init->getTypeSourceInfo()->getType()); + NodeDumper.dumpType(Init->getTypeSourceInfo()->getType()); } else { llvm_unreachable("Unknown initializer type"); } @@ -846,7 +721,7 @@ dumpChild([=] { OS << "TemplateArgument"; if (R.isValid()) - dumpSourceRange(R); + NodeDumper.dumpSourceRange(R); switch (A.getKind()) { case TemplateArgument::Null: @@ -854,7 +729,7 @@ break; case TemplateArgument::Type: OS << " type"; - dumpType(A.getAsType()); + NodeDumper.dumpType(A.getAsType()); break; case TemplateArgument::Declaration: OS << " decl"; @@ -916,13 +791,13 @@ ColorScope Color(OS, ShowColors, DeclKindNameColor); OS << D->getDeclKindName() << "Decl"; } - dumpPointer(D); + NodeDumper.dumpPointer(D); if (D->getLexicalDeclContext() != D->getDeclContext()) OS << " parent " << cast(D->getDeclContext()); dumpPreviousDecl(OS, D); - dumpSourceRange(D->getSourceRange()); + NodeDumper.dumpSourceRange(D->getSourceRange()); OS << ' '; - dumpLocation(D->getLocation()); + NodeDumper.dumpLocation(D->getLocation()); if (D->isFromASTFile()) OS << " imported"; if (Module *M = D->getOwningModule()) @@ -964,13 +839,11 @@ }); } -void ASTDumper::VisitLabelDecl(const LabelDecl *D) { - dumpName(D); -} +void ASTDumper::VisitLabelDecl(const LabelDecl *D) { NodeDumper.dumpName(D); } void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) { - dumpName(D); - dumpType(D->getUnderlyingType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getUnderlyingType()); if (D->isModulePrivate()) OS << " __module_private__"; dumpTypeAsChild(D->getUnderlyingType()); @@ -983,16 +856,16 @@ else OS << " struct"; } - dumpName(D); + NodeDumper.dumpName(D); if (D->isModulePrivate()) OS << " __module_private__"; if (D->isFixed()) - dumpType(D->getIntegerType()); + NodeDumper.dumpType(D->getIntegerType()); } void ASTDumper::VisitRecordDecl(const RecordDecl *D) { OS << ' ' << D->getKindName(); - dumpName(D); + NodeDumper.dumpName(D); if (D->isModulePrivate()) OS << " __module_private__"; if (D->isCompleteDefinition()) @@ -1000,23 +873,23 @@ } void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); if (const Expr *Init = D->getInitExpr()) dumpStmt(Init); } void ASTDumper::VisitIndirectFieldDecl(const IndirectFieldDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); for (auto *Child : D->chain()) dumpDeclRef(Child); } void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); StorageClass SC = D->getStorageClass(); if (SC != SC_None) @@ -1097,8 +970,8 @@ } void ASTDumper::VisitFieldDecl(const FieldDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); if (D->isMutable()) OS << " mutable"; if (D->isModulePrivate()) @@ -1111,8 +984,8 @@ } void ASTDumper::VisitVarDecl(const VarDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); StorageClass SC = D->getStorageClass(); if (SC != SC_None) OS << ' ' << VarDecl::getStorageClassSpecifierString(SC); @@ -1146,8 +1019,8 @@ } void ASTDumper::VisitBindingDecl(const BindingDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); if (auto *E = D->getBinding()) dumpStmt(E); } @@ -1194,8 +1067,8 @@ } void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); OS << " combiner"; dumpStmt(D->getCombiner()); if (auto *Initializer = D->getInitializer()) { @@ -1228,15 +1101,15 @@ OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() << ClauseName.drop_front() << "Clause"; } - dumpPointer(C); - dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc())); + NodeDumper.dumpPointer(C); + NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc())); }); } } void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); dumpStmt(D->getInit()); } @@ -1245,7 +1118,7 @@ //===----------------------------------------------------------------------===// void ASTDumper::VisitNamespaceDecl(const NamespaceDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); if (D->isInline()) OS << " inline"; if (!D->isOriginalNamespace()) @@ -1254,22 +1127,22 @@ void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { OS << ' '; - dumpBareDeclRef(D->getNominatedNamespace()); + NodeDumper.dumpBareDeclRef(D->getNominatedNamespace()); } void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpDeclRef(D->getAliasedNamespace()); } void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { - dumpName(D); - dumpType(D->getUnderlyingType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getUnderlyingType()); dumpTypeAsChild(D->getUnderlyingType()); } void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); dumpDecl(D->getTemplatedDecl()); } @@ -1405,8 +1278,8 @@ dumpChild([=] { if (I.isVirtual()) OS << "virtual "; - dumpAccessSpecifier(I.getAccessSpecifier()); - dumpType(I.getType()); + NodeDumper.dumpAccessSpecifier(I.getAccessSpecifier()); + NodeDumper.dumpType(I.getType()); if (I.isPackExpansion()) OS << "..."; }); @@ -1463,7 +1336,7 @@ template void ASTDumper::VisitTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst) { - dumpName(D); + NodeDumper.dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); dumpDecl(D->getTemplatedDecl()); @@ -1508,7 +1381,7 @@ } void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); } @@ -1532,25 +1405,25 @@ OS << " depth " << D->getDepth() << " index " << D->getIndex(); if (D->isParameterPack()) OS << " ..."; - dumpName(D); + NodeDumper.dumpName(D); if (D->hasDefaultArgument()) dumpTemplateArgument(D->getDefaultArgument()); if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + dumpDeclRef( + From, D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { - dumpType(D->getType()); + NodeDumper.dumpType(D->getType()); OS << " depth " << D->getDepth() << " index " << D->getIndex(); if (D->isParameterPack()) OS << " ..."; - dumpName(D); + NodeDumper.dumpName(D); if (D->hasDefaultArgument()) dumpTemplateArgument(D->getDefaultArgument()); if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + dumpDeclRef( + From, D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitTemplateTemplateParmDecl( @@ -1558,13 +1431,13 @@ OS << " depth " << D->getDepth() << " index " << D->getIndex(); if (D->isParameterPack()) OS << " ..."; - dumpName(D); + NodeDumper.dumpName(D); dumpTemplateParameters(D->getTemplateParameters()); if (D->hasDefaultArgument()) dumpTemplateArgumentLoc(D->getDefaultArgument()); if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + dumpDeclRef( + From, D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitUsingDecl(const UsingDecl *D) { @@ -1587,12 +1460,12 @@ if (D->getQualifier()) D->getQualifier()->print(OS, D->getASTContext().getPrintingPolicy()); OS << D->getNameAsString(); - dumpType(D->getType()); + NodeDumper.dumpType(D->getType()); } void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) { OS << ' '; - dumpBareDeclRef(D->getTargetDecl()); + NodeDumper.dumpBareDeclRef(D->getTargetDecl()); if (auto *TD = dyn_cast(D->getUnderlyingDecl())) dumpTypeAsChild(TD->getTypeForDecl()); } @@ -1604,21 +1477,21 @@ dumpChild([=] { OS << "target "; - dumpBareDeclRef(D->getTargetDecl()); + NodeDumper.dumpBareDeclRef(D->getTargetDecl()); }); dumpChild([=] { OS << "nominated "; - dumpBareDeclRef(D->getNominatedBaseClass()); + NodeDumper.dumpBareDeclRef(D->getNominatedBaseClass()); OS << ' '; - dumpBareDeclRef(D->getNominatedBaseClassShadowDecl()); + NodeDumper.dumpBareDeclRef(D->getNominatedBaseClassShadowDecl()); }); dumpChild([=] { OS << "constructed "; - dumpBareDeclRef(D->getConstructedBaseClass()); + NodeDumper.dumpBareDeclRef(D->getConstructedBaseClass()); OS << ' '; - dumpBareDeclRef(D->getConstructedBaseClassShadowDecl()); + NodeDumper.dumpBareDeclRef(D->getConstructedBaseClassShadowDecl()); }); } @@ -1631,12 +1504,12 @@ void ASTDumper::VisitAccessSpecDecl(const AccessSpecDecl *D) { OS << ' '; - dumpAccessSpecifier(D->getAccess()); + NodeDumper.dumpAccessSpecifier(D->getAccess()); } void ASTDumper::VisitFriendDecl(const FriendDecl *D) { if (TypeSourceInfo *T = D->getFriendType()) - dumpType(T->getType()); + NodeDumper.dumpType(T->getType()); else dumpDecl(D->getFriendDecl()); } @@ -1646,8 +1519,8 @@ //===----------------------------------------------------------------------===// void ASTDumper::VisitObjCIvarDecl(const ObjCIvarDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); if (D->getSynthesize()) OS << " synthesize"; @@ -1675,8 +1548,8 @@ OS << " -"; else OS << " +"; - dumpName(D); - dumpType(D->getReturnType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getReturnType()); if (D->isThisDeclarationADefinition()) { dumpDeclContext(D); @@ -1693,7 +1566,7 @@ } void ASTDumper::VisitObjCTypeParamDecl(const ObjCTypeParamDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); switch (D->getVariance()) { case ObjCTypeParamVariance::Invariant: break; @@ -1709,11 +1582,11 @@ if (D->hasExplicitBound()) OS << " bounded"; - dumpType(D->getUnderlyingType()); + NodeDumper.dumpType(D->getUnderlyingType()); } void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpDeclRef(D->getClassInterface()); dumpObjCTypeParamList(D->getTypeParamList()); dumpDeclRef(D->getImplementation()); @@ -1724,20 +1597,20 @@ } void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpDeclRef(D->getClassInterface()); dumpDeclRef(D->getCategoryDecl()); } void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); for (auto *Child : D->protocols()) dumpDeclRef(Child); } void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpObjCTypeParamList(D->getTypeParamListAsWritten()); dumpDeclRef(D->getSuperClass(), "super"); @@ -1747,7 +1620,7 @@ } void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpDeclRef(D->getSuperClass(), "super"); dumpDeclRef(D->getClassInterface()); for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(), @@ -1757,13 +1630,13 @@ } void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) { - dumpName(D); + NodeDumper.dumpName(D); dumpDeclRef(D->getClassInterface()); } void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { - dumpName(D); - dumpType(D->getType()); + NodeDumper.dumpName(D); + NodeDumper.dumpType(D->getType()); if (D->getPropertyImplementation() == ObjCPropertyDecl::Required) OS << " required"; @@ -1802,7 +1675,7 @@ } void ASTDumper::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { - dumpName(D->getPropertyDecl()); + NodeDumper.dumpName(D->getPropertyDecl()); if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) OS << " synthesize"; else @@ -1830,7 +1703,7 @@ OS << " nested"; if (I.getVariable()) { OS << ' '; - dumpBareDeclRef(I.getVariable()); + NodeDumper.dumpBareDeclRef(I.getVariable()); } if (I.hasCopyExpr()) dumpStmt(I.getCopyExpr()); @@ -1868,8 +1741,8 @@ ColorScope Color(OS, ShowColors, StmtColor); OS << Node->getStmtClassName(); } - dumpPointer(Node); - dumpSourceRange(Node->getSourceRange()); + NodeDumper.dumpPointer(Node); + NodeDumper.dumpSourceRange(Node->getSourceRange()); } void ASTDumper::VisitDeclStmt(const DeclStmt *Node) { @@ -1920,7 +1793,7 @@ void ASTDumper::VisitGotoStmt(const GotoStmt *Node) { VisitStmt(Node); OS << " '" << Node->getLabel()->getName() << "'"; - dumpPointer(Node->getLabel()); + NodeDumper.dumpPointer(Node->getLabel()); } void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) { @@ -1959,8 +1832,8 @@ OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() << ClauseName.drop_front() << "Clause"; } - dumpPointer(C); - dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc())); + NodeDumper.dumpPointer(C); + NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc())); if (C->isImplicit()) OS << " "; for (auto *S : C->children()) @@ -1975,7 +1848,7 @@ void ASTDumper::VisitExpr(const Expr *Node) { VisitStmt(Node); - dumpType(Node->getType()); + NodeDumper.dumpType(Node->getType()); { ColorScope Color(OS, ShowColors, ValueKindColor); @@ -2058,10 +1931,10 @@ VisitExpr(Node); OS << " "; - dumpBareDeclRef(Node->getDecl()); + NodeDumper.dumpBareDeclRef(Node->getDecl()); if (Node->getDecl() != Node->getFoundDecl()) { OS << " ("; - dumpBareDeclRef(Node->getFoundDecl()); + NodeDumper.dumpBareDeclRef(Node->getFoundDecl()); OS << ")"; } } @@ -2078,7 +1951,7 @@ if (I == E) OS << " empty"; for (; I != E; ++I) - dumpPointer(*I); + NodeDumper.dumpPointer(*I); } void ASTDumper::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node) { @@ -2089,7 +1962,7 @@ OS << " " << Node->getDecl()->getDeclKindName() << "Decl"; } OS << "='" << *Node->getDecl() << "'"; - dumpPointer(Node->getDecl()); + NodeDumper.dumpPointer(Node->getDecl()); if (Node->isFreeIvar()) OS << " isFreeIvar"; } @@ -2143,7 +2016,7 @@ } if (auto *Field = ILE->getInitializedFieldInUnion()) { OS << " field "; - dumpBareDeclRef(Field); + NodeDumper.dumpBareDeclRef(Field); } } @@ -2176,13 +2049,13 @@ break; } if (Node->isArgumentType()) - dumpType(Node->getArgumentType()); + NodeDumper.dumpType(Node->getArgumentType()); } void ASTDumper::VisitMemberExpr(const MemberExpr *Node) { VisitExpr(Node); OS << " " << (Node->isArrow() ? "->" : ".") << *Node->getMemberDecl(); - dumpPointer(Node->getMemberDecl()); + NodeDumper.dumpPointer(Node->getMemberDecl()); } void ASTDumper::VisitExtVectorElementExpr(const ExtVectorElementExpr *Node) { @@ -2200,9 +2073,9 @@ VisitExpr(Node); OS << " '" << BinaryOperator::getOpcodeStr(Node->getOpcode()) << "' ComputeLHSTy="; - dumpBareType(Node->getComputationLHSType()); + NodeDumper.dumpBareType(Node->getComputationLHSType()); OS << " ComputeResultTy="; - dumpBareType(Node->getComputationResultType()); + NodeDumper.dumpBareType(Node->getComputationResultType()); } void ASTDumper::VisitBlockExpr(const BlockExpr *Node) { @@ -2228,7 +2101,7 @@ dumpChild([=] { if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) { OS << "case "; - dumpType(TSI->getType()); + NodeDumper.dumpType(TSI->getType()); } else { OS << "default"; } @@ -2248,7 +2121,7 @@ void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) { VisitExpr(Node); OS << " " << Node->getLabel()->getName(); - dumpPointer(Node->getLabel()); + NodeDumper.dumpPointer(Node->getLabel()); } //===----------------------------------------------------------------------===// @@ -2283,7 +2156,7 @@ void ASTDumper::VisitCXXUnresolvedConstructExpr( const CXXUnresolvedConstructExpr *Node) { VisitExpr(Node); - dumpType(Node->getTypeAsWritten()); + NodeDumper.dumpType(Node->getTypeAsWritten()); if (Node->isListInitialization()) OS << " list"; } @@ -2291,7 +2164,7 @@ void ASTDumper::VisitCXXConstructExpr(const CXXConstructExpr *Node) { VisitExpr(Node); CXXConstructorDecl *Ctor = Node->getConstructor(); - dumpType(Ctor->getType()); + NodeDumper.dumpType(Ctor->getType()); if (Node->isElidable()) OS << " elidable"; if (Node->isListInitialization()) @@ -2305,7 +2178,7 @@ void ASTDumper::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node) { VisitExpr(Node); OS << " "; - dumpCXXTemporary(Node->getTemporary()); + NodeDumper.dumpCXXTemporary(Node->getTemporary()); } void ASTDumper::VisitCXXNewExpr(const CXXNewExpr *Node) { @@ -2316,7 +2189,7 @@ OS << " array"; if (Node->getOperatorNew()) { OS << ' '; - dumpBareDeclRef(Node->getOperatorNew()); + NodeDumper.dumpBareDeclRef(Node->getOperatorNew()); } // We could dump the deallocation function used in case of error, but it's // usually not that interesting. @@ -2330,7 +2203,7 @@ OS << " array"; if (Node->getOperatorDelete()) { OS << ' '; - dumpBareDeclRef(Node->getOperatorDelete()); + NodeDumper.dumpBareDeclRef(Node->getOperatorDelete()); } } @@ -2339,7 +2212,7 @@ VisitExpr(Node); if (const ValueDecl *VD = Node->getExtendingDecl()) { OS << " extended by "; - dumpBareDeclRef(VD); + NodeDumper.dumpBareDeclRef(VD); } } @@ -2349,16 +2222,10 @@ dumpDeclRef(Node->getObject(i), "cleanup"); } -void ASTDumper::dumpCXXTemporary(const CXXTemporary *Temporary) { - OS << "(CXXTemporary"; - dumpPointer(Temporary); - OS << ")"; -} - void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { VisitExpr(Node); - dumpPointer(Node->getPack()); - dumpName(Node->getPack()); + NodeDumper.dumpPointer(Node->getPack()); + NodeDumper.dumpName(Node->getPack()); if (Node->isPartiallySubstituted()) for (const auto &A : Node->getPartialArguments()) dumpTemplateArgument(A); @@ -2384,7 +2251,7 @@ case ObjCMessageExpr::Class: OS << " class="; - dumpBareType(Node->getClassReceiver()); + NodeDumper.dumpBareType(Node->getClassReceiver()); break; case ObjCMessageExpr::SuperInstance: @@ -2415,7 +2282,7 @@ void ASTDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *Node) { VisitExpr(Node); - dumpType(Node->getEncodedType()); + NodeDumper.dumpType(Node->getEncodedType()); } void ASTDumper::VisitObjCSelectorExpr(const ObjCSelectorExpr *Node) { @@ -2519,8 +2386,8 @@ ColorScope Color(OS, ShowColors, CommentColor); OS << C->getCommentKindName(); } - dumpPointer(C); - dumpSourceRange(C->getSourceRange()); + NodeDumper.dumpPointer(C); + NodeDumper.dumpSourceRange(C->getSourceRange()); ConstCommentVisitor::visit(C, FC); for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); I != E; ++I)