diff options
Diffstat (limited to 'lib/AST/ASTDumper.cpp')
-rw-r--r-- | lib/AST/ASTDumper.cpp | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 62261ccc905b6..ef491ab06f8c3 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -102,22 +102,26 @@ namespace { /// Pending[i] is an action to dump an entity at level i. llvm::SmallVector<std::function<void(bool isLastChild)>, 32> Pending; + /// Indicates whether we should trigger deserialization of nodes that had + /// not already been loaded. + bool Deserialize = false; + /// Indicates whether we're at the top level. - bool TopLevel; + bool TopLevel = true; /// Indicates if we're handling the first child after entering a new depth. - bool FirstChild; + bool FirstChild = true; /// Prefix for currently-being-dumped entity. std::string Prefix; /// 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; + const char *LastLocFilename = ""; + unsigned LastLocLine = ~0U; /// The \c FullComment parent of the comment being dumped. - const FullComment *FC; + const FullComment *FC = nullptr; bool ShowColors; @@ -203,15 +207,14 @@ namespace { public: ASTDumper(raw_ostream &OS, const CommandTraits *Traits, const SourceManager *SM) - : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true), - LastLocFilename(""), LastLocLine(~0U), FC(nullptr), + : OS(OS), Traits(Traits), SM(SM), ShowColors(SM && SM->getDiagnostics().getShowColors()) { } ASTDumper(raw_ostream &OS, const CommandTraits *Traits, const SourceManager *SM, bool ShowColors) - : OS(OS), Traits(Traits), SM(SM), TopLevel(true), FirstChild(true), - LastLocFilename(""), LastLocLine(~0U), - ShowColors(ShowColors) { } + : OS(OS), Traits(Traits), SM(SM), ShowColors(ShowColors) {} + + void setDeserialize(bool D) { Deserialize = D; } void dumpDecl(const Decl *D); void dumpStmt(const Stmt *S); @@ -764,14 +767,15 @@ bool ASTDumper::hasNodes(const DeclContext *DC) { return false; return DC->hasExternalLexicalStorage() || - DC->noload_decls_begin() != DC->noload_decls_end(); + (Deserialize ? DC->decls_begin() != DC->decls_end() + : DC->noload_decls_begin() != DC->noload_decls_end()); } void ASTDumper::dumpDeclContext(const DeclContext *DC) { if (!DC) return; - for (auto *D : DC->noload_decls()) + for (auto *D : (Deserialize ? DC->decls() : DC->noload_decls())) dumpDecl(D); if (DC->hasExternalLexicalStorage()) { @@ -795,11 +799,13 @@ void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { bool HasUndeserializedLookups = Primary->hasExternalVisibleStorage(); - DeclContext::all_lookups_iterator I = Primary->noload_lookups_begin(), - E = Primary->noload_lookups_end(); - while (I != E) { + for (auto I = Deserialize ? Primary->lookups_begin() + : Primary->noload_lookups_begin(), + E = Deserialize ? Primary->lookups_end() + : Primary->noload_lookups_end(); + I != E; ++I) { DeclarationName Name = I.getLookupName(); - DeclContextLookupResult R = *I++; + DeclContextLookupResult R = *I; dumpChild([=] { OS << "DeclarationName "; @@ -1463,6 +1469,7 @@ void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { OS << " typename"; else OS << " class"; + OS << " depth " << D->getDepth() << " index " << D->getIndex(); if (D->isParameterPack()) OS << " ..."; dumpName(D); @@ -1472,6 +1479,7 @@ void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { dumpType(D->getType()); + OS << " depth " << D->getDepth() << " index " << D->getIndex(); if (D->isParameterPack()) OS << " ..."; dumpName(D); @@ -1481,6 +1489,7 @@ void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { void ASTDumper::VisitTemplateTemplateParmDecl( const TemplateTemplateParmDecl *D) { + OS << " depth " << D->getDepth() << " index " << D->getIndex(); if (D->isParameterPack()) OS << " ..."; dumpName(D); @@ -2504,9 +2513,10 @@ LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const { LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); } -LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS) const { +LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const { ASTDumper P(OS, &getASTContext().getCommentCommandTraits(), &getASTContext().getSourceManager()); + P.setDeserialize(Deserialize); P.dumpDecl(this); } @@ -2521,12 +2531,14 @@ LLVM_DUMP_METHOD void DeclContext::dumpLookups() const { } LLVM_DUMP_METHOD void DeclContext::dumpLookups(raw_ostream &OS, - bool DumpDecls) const { + bool DumpDecls, + bool Deserialize) const { const DeclContext *DC = this; while (!DC->isTranslationUnit()) DC = DC->getParent(); ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext(); ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &Ctx.getSourceManager()); + P.setDeserialize(Deserialize); P.dumpLookups(this, DumpDecls); } |