Index: include/clang/AST/TextNodeDumper.h =================================================================== --- include/clang/AST/TextNodeDumper.h +++ include/clang/AST/TextNodeDumper.h @@ -25,6 +25,7 @@ class TextNodeDumper : public comments::ConstCommentVisitor { + TextTreeStructure &TreeStructure; raw_ostream &OS; const bool ShowColors; @@ -43,7 +44,8 @@ const char *getCommandName(unsigned CommandID); public: - TextNodeDumper(raw_ostream &OS, bool ShowColors, const SourceManager *SM, + TextNodeDumper(TextTreeStructure &TreeStructure, raw_ostream &OS, + bool ShowColors, const SourceManager *SM, const PrintingPolicy &PrintPolicy, const comments::CommandTraits *Traits); @@ -59,6 +61,8 @@ void dumpAccessSpecifier(AccessSpecifier AS); void dumpCXXTemporary(const CXXTemporary *Temporary); + void dumpDeclRef(const Decl *D, const char *Label = nullptr); + void visitTextComment(const comments::TextComment *C, const comments::FullComment *); void visitInlineCommandComment(const comments::InlineCommandComment *C, Index: lib/AST/ASTDumper.cpp =================================================================== --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -76,8 +76,8 @@ const SourceManager *SM, bool ShowColors, const PrintingPolicy &PrintPolicy) : TreeStructure(OS, ShowColors), - NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS), - PrintPolicy(PrintPolicy), ShowColors(ShowColors) {} + NodeDumper(TreeStructure, OS, ShowColors, SM, PrintPolicy, Traits), + OS(OS), PrintPolicy(PrintPolicy), ShowColors(ShowColors) {} void setDeserialize(bool D) { Deserialize = D; } @@ -89,7 +89,6 @@ void dumpType(QualType T) { NodeDumper.dumpType(T); } void dumpTypeAsChild(QualType T); void dumpTypeAsChild(const Type *T); - void dumpDeclRef(const Decl *Node, const char *Label = nullptr); void dumpBareDeclRef(const Decl *Node) { NodeDumper.dumpBareDeclRef(Node); } bool hasNodes(const DeclContext *DC); void dumpDeclContext(const DeclContext *DC); @@ -208,10 +207,10 @@ dumpChild([=] { OS << "..."; }); } void VisitUnresolvedUsingType(const UnresolvedUsingType *T) { - dumpDeclRef(T->getDecl()); + NodeDumper.dumpDeclRef(T->getDecl()); } void VisitTypedefType(const TypedefType *T) { - dumpDeclRef(T->getDecl()); + NodeDumper.dumpDeclRef(T->getDecl()); } void VisitTypeOfExprType(const TypeOfExprType *T) { dumpStmt(T->getUnderlyingExpr()); @@ -228,7 +227,7 @@ dumpTypeAsChild(T->getBaseType()); } void VisitTagType(const TagType *T) { - dumpDeclRef(T->getDecl()); + NodeDumper.dumpDeclRef(T->getDecl()); } void VisitAttributedType(const AttributedType *T) { // FIXME: AttrKind @@ -237,7 +236,7 @@ void VisitTemplateTypeParmType(const TemplateTypeParmType *T) { OS << " depth " << T->getDepth() << " index " << T->getIndex(); if (T->isParameterPack()) OS << " pack"; - dumpDeclRef(T->getDecl()); + NodeDumper.dumpDeclRef(T->getDecl()); } void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { dumpTypeAsChild(T->getReplacedParameter()); @@ -261,10 +260,10 @@ dumpTypeAsChild(T->getAliasedType()); } void VisitInjectedClassNameType(const InjectedClassNameType *T) { - dumpDeclRef(T->getDecl()); + NodeDumper.dumpDeclRef(T->getDecl()); } void VisitObjCInterfaceType(const ObjCInterfaceType *T) { - dumpDeclRef(T->getDecl()); + NodeDumper.dumpDeclRef(T->getDecl()); } void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { dumpTypeAsChild(T->getPointeeType()); @@ -508,17 +507,6 @@ }); } -void ASTDumper::dumpDeclRef(const Decl *D, const char *Label) { - if (!D) - return; - - dumpChild([=]{ - if (Label) - OS << Label << ' '; - dumpBareDeclRef(D); - }); -} - bool ASTDumper::hasNodes(const DeclContext *DC) { if (!DC) return false; @@ -713,7 +701,7 @@ break; case TemplateArgument::Declaration: OS << " decl"; - dumpDeclRef(A.getAsDecl()); + NodeDumper.dumpDeclRef(A.getAsDecl()); break; case TemplateArgument::NullPtr: OS << " nullptr"; @@ -864,7 +852,7 @@ NodeDumper.dumpType(D->getType()); for (auto *Child : D->chain()) - dumpDeclRef(Child); + NodeDumper.dumpDeclRef(Child); } void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { @@ -1102,7 +1090,7 @@ if (D->isInline()) OS << " inline"; if (!D->isOriginalNamespace()) - dumpDeclRef(D->getOriginalNamespace(), "original"); + NodeDumper.dumpDeclRef(D->getOriginalNamespace(), "original"); } void ASTDumper::VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) { @@ -1112,7 +1100,7 @@ void ASTDumper::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) { NodeDumper.dumpName(D); - dumpDeclRef(D->getAliasedNamespace()); + NodeDumper.dumpDeclRef(D->getAliasedNamespace()); } void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { @@ -1298,7 +1286,7 @@ case TSK_Undeclared: case TSK_ImplicitInstantiation: if (DumpRefOnly) - dumpDeclRef(Redecl); + NodeDumper.dumpDeclRef(Redecl); else dumpDecl(Redecl); DumpedAny = true; @@ -1310,7 +1298,7 @@ // Ensure we dump at least one decl for each specialization. if (!DumpedAny) - dumpDeclRef(D); + NodeDumper.dumpDeclRef(D); } template @@ -1389,8 +1377,8 @@ if (D->hasDefaultArgument()) dumpTemplateArgument(D->getDefaultArgument()); if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + NodeDumper.dumpDeclRef( + From, D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { @@ -1402,8 +1390,8 @@ if (D->hasDefaultArgument()) dumpTemplateArgument(D->getDefaultArgument()); if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + NodeDumper.dumpDeclRef( + From, D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitTemplateTemplateParmDecl( @@ -1416,8 +1404,8 @@ if (D->hasDefaultArgument()) dumpTemplateArgumentLoc(D->getDefaultArgument()); if (auto *From = D->getDefaultArgStorage().getInheritedFrom()) - dumpDeclRef(From, D->defaultArgumentWasInherited() ? "inherited from" - : "previous"); + NodeDumper.dumpDeclRef( + From, D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } void ASTDumper::VisitUsingDecl(const UsingDecl *D) { @@ -1567,42 +1555,42 @@ void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { NodeDumper.dumpName(D); - dumpDeclRef(D->getClassInterface()); + NodeDumper.dumpDeclRef(D->getClassInterface()); dumpObjCTypeParamList(D->getTypeParamList()); - dumpDeclRef(D->getImplementation()); + NodeDumper.dumpDeclRef(D->getImplementation()); for (ObjCCategoryDecl::protocol_iterator I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I) - dumpDeclRef(*I); + NodeDumper.dumpDeclRef(*I); } void ASTDumper::VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) { NodeDumper.dumpName(D); - dumpDeclRef(D->getClassInterface()); - dumpDeclRef(D->getCategoryDecl()); + NodeDumper.dumpDeclRef(D->getClassInterface()); + NodeDumper.dumpDeclRef(D->getCategoryDecl()); } void ASTDumper::VisitObjCProtocolDecl(const ObjCProtocolDecl *D) { NodeDumper.dumpName(D); for (auto *Child : D->protocols()) - dumpDeclRef(Child); + NodeDumper.dumpDeclRef(Child); } void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { NodeDumper.dumpName(D); dumpObjCTypeParamList(D->getTypeParamListAsWritten()); - dumpDeclRef(D->getSuperClass(), "super"); + NodeDumper.dumpDeclRef(D->getSuperClass(), "super"); - dumpDeclRef(D->getImplementation()); + NodeDumper.dumpDeclRef(D->getImplementation()); for (auto *Child : D->protocols()) - dumpDeclRef(Child); + NodeDumper.dumpDeclRef(Child); } void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { NodeDumper.dumpName(D); - dumpDeclRef(D->getSuperClass(), "super"); - dumpDeclRef(D->getClassInterface()); + NodeDumper.dumpDeclRef(D->getSuperClass(), "super"); + NodeDumper.dumpDeclRef(D->getClassInterface()); for (ObjCImplementationDecl::init_const_iterator I = D->init_begin(), E = D->init_end(); I != E; ++I) @@ -1611,7 +1599,7 @@ void ASTDumper::VisitObjCCompatibleAliasDecl(const ObjCCompatibleAliasDecl *D) { NodeDumper.dumpName(D); - dumpDeclRef(D->getClassInterface()); + NodeDumper.dumpDeclRef(D->getClassInterface()); } void ASTDumper::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) { @@ -1648,9 +1636,9 @@ if (Attrs & ObjCPropertyDecl::OBJC_PR_class) OS << " class"; if (Attrs & ObjCPropertyDecl::OBJC_PR_getter) - dumpDeclRef(D->getGetterMethodDecl(), "getter"); + NodeDumper.dumpDeclRef(D->getGetterMethodDecl(), "getter"); if (Attrs & ObjCPropertyDecl::OBJC_PR_setter) - dumpDeclRef(D->getSetterMethodDecl(), "setter"); + NodeDumper.dumpDeclRef(D->getSetterMethodDecl(), "setter"); } } @@ -1660,8 +1648,8 @@ OS << " synthesize"; else OS << " dynamic"; - dumpDeclRef(D->getPropertyDecl()); - dumpDeclRef(D->getPropertyIvarDecl()); + NodeDumper.dumpDeclRef(D->getPropertyDecl()); + NodeDumper.dumpDeclRef(D->getPropertyIvarDecl()); } void ASTDumper::VisitBlockDecl(const BlockDecl *D) { @@ -2199,7 +2187,7 @@ void ASTDumper::VisitExprWithCleanups(const ExprWithCleanups *Node) { VisitExpr(Node); for (unsigned i = 0, e = Node->getNumObjects(); i != e; ++i) - dumpDeclRef(Node->getObject(i), "cleanup"); + NodeDumper.dumpDeclRef(Node->getObject(i), "cleanup"); } void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { Index: lib/AST/TextNodeDumper.cpp =================================================================== --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -15,12 +15,13 @@ using namespace clang; -TextNodeDumper::TextNodeDumper(raw_ostream &OS, bool ShowColors, +TextNodeDumper::TextNodeDumper(TextTreeStructure &TreeStructure, + raw_ostream &OS, bool ShowColors, const SourceManager *SM, const PrintingPolicy &PrintPolicy, const comments::CommandTraits *Traits) - : OS(OS), ShowColors(ShowColors), SM(SM), PrintPolicy(PrintPolicy), - Traits(Traits) {} + : TreeStructure(TreeStructure), OS(OS), ShowColors(ShowColors), SM(SM), + PrintPolicy(PrintPolicy), Traits(Traits) {} void TextNodeDumper::visit(const comments::Comment *C, const comments::FullComment *FC) { @@ -161,6 +162,17 @@ OS << ")"; } +void TextNodeDumper::dumpDeclRef(const Decl *D, const char *Label) { + if (!D) + return; + + TreeStructure.addChild([=] { + if (Label) + OS << Label << ' '; + dumpBareDeclRef(D); + }); +} + const char *TextNodeDumper::getCommandName(unsigned CommandID) { if (Traits) return Traits->getCommandInfo(CommandID)->Name;