diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-26 02:02:08 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-26 02:02:08 +0000 |
commit | 32887f0274cbb332f344a19b91d12b58eeaca637 (patch) | |
tree | 56ec5d601d587e72fad107ed8b5e848a0b6c07f9 /clang/tools | |
parent | 44b03a67f8a8d9dd4611b1a87918ca4371929304 (diff) | |
download | bcm5719-llvm-32887f0274cbb332f344a19b91d12b58eeaca637.tar.gz bcm5719-llvm-32887f0274cbb332f344a19b91d12b58eeaca637.zip |
Add a new -ast-dump-full option that traverses the translation unit
declaration rather than printing through the HandleTopLevelDecl
action. Using this, one can deserialize an entire PCH file and dump
it.
llvm-svn: 70108
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/clang-cc/ASTConsumers.cpp | 22 | ||||
-rw-r--r-- | clang/tools/clang-cc/ASTConsumers.h | 2 | ||||
-rw-r--r-- | clang/tools/clang-cc/clang-cc.cpp | 9 |
3 files changed, 29 insertions, 4 deletions
diff --git a/clang/tools/clang-cc/ASTConsumers.cpp b/clang/tools/clang-cc/ASTConsumers.cpp index 9e2d9e3471f..d68b61cc3d5 100644 --- a/clang/tools/clang-cc/ASTConsumers.cpp +++ b/clang/tools/clang-cc/ASTConsumers.cpp @@ -591,18 +591,34 @@ ASTConsumer *clang::CreateASTPrinter(llvm::raw_ostream* out) { namespace { class ASTDumper : public ASTConsumer, public DeclPrinter { ASTContext *Ctx; + bool FullDump; + public: - ASTDumper() : DeclPrinter() {} + explicit ASTDumper(bool FullDump) : DeclPrinter(), FullDump(FullDump) {} void Initialize(ASTContext &Context) { Ctx = &Context; } virtual void HandleTopLevelDecl(DeclGroupRef D) { + if (FullDump) + return; for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) HandleTopLevelSingleDecl(*I); } void HandleTopLevelSingleDecl(Decl *D); + + virtual void HandleTranslationUnit(ASTContext &Ctx) { + if (!FullDump) + return; + + for (DeclContext::decl_iterator + D = Ctx.getTranslationUnitDecl()->decls_begin(Ctx), + DEnd = Ctx.getTranslationUnitDecl()->decls_end(Ctx); + D != DEnd; + ++D) + HandleTopLevelSingleDecl(*D); + } }; } // end anonymous namespace @@ -652,7 +668,9 @@ void ASTDumper::HandleTopLevelSingleDecl(Decl *D) { } } -ASTConsumer *clang::CreateASTDumper() { return new ASTDumper(); } +ASTConsumer *clang::CreateASTDumper(bool FullDump) { + return new ASTDumper(FullDump); +} //===----------------------------------------------------------------------===// /// ASTViewer - AST Visualization diff --git a/clang/tools/clang-cc/ASTConsumers.h b/clang/tools/clang-cc/ASTConsumers.h index 13fd4f4ed82..4a1de114767 100644 --- a/clang/tools/clang-cc/ASTConsumers.h +++ b/clang/tools/clang-cc/ASTConsumers.h @@ -34,7 +34,7 @@ class LangOptions; ASTConsumer *CreateASTPrinter(llvm::raw_ostream* OS = NULL); -ASTConsumer *CreateASTDumper(); +ASTConsumer *CreateASTDumper(bool FullDump); ASTConsumer *CreateASTViewer(); diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index af8b5b62437..ab72d6b29c1 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -183,6 +183,8 @@ enum ProgActions { EmitHTML, // Translate input source into HTML. ASTPrint, // Parse ASTs and print them. ASTDump, // Parse ASTs and dump them. + ASTDumpFull, // Parse ASTs and dump them, including the + // contents of a PCH file. ASTView, // Parse ASTs and view them in Graphviz. PrintDeclContext, // Print DeclContext and their Decls. ParsePrintCallbacks, // Parse and print each callback. @@ -224,6 +226,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Build ASTs and then pretty-print them"), clEnumValN(ASTDump, "ast-dump", "Build ASTs and then debug dump them"), + clEnumValN(ASTDumpFull, "ast-dump-full", + "Build ASTs and then debug dump them, including PCH"), clEnumValN(ASTView, "ast-view", "Build ASTs and view them with GraphViz"), clEnumValN(PrintDeclContext, "print-decl-contexts", @@ -1539,7 +1543,10 @@ static ASTConsumer *CreateASTConsumer(const std::string& InFile, return CreateASTPrinter(); case ASTDump: - return CreateASTDumper(); + return CreateASTDumper(false); + + case ASTDumpFull: + return CreateASTDumper(true); case ASTView: return CreateASTViewer(); |