]> granicus.if.org Git - clang/commitdiff
Add a new -ast-dump-full option that traverses the translation unit
authorDouglas Gregor <dgregor@apple.com>
Sun, 26 Apr 2009 02:02:08 +0000 (02:02 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 26 Apr 2009 02:02:08 +0000 (02:02 +0000)
declaration rather than printing through the HandleTopLevelDecl
action. Using this, one can deserialize an entire PCH file and dump
it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70108 91177308-0d34-0410-b5e6-96231b3b80d8

tools/clang-cc/ASTConsumers.cpp
tools/clang-cc/ASTConsumers.h
tools/clang-cc/clang-cc.cpp

index 9e2d9e3471f9a14bd495bbe550d971306a3a7659..d68b61cc3d54f41d9b4b316d5382e00231568cf1 100644 (file)
@@ -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
index 13fd4f4ed82f6fb4101a48cdd3fca7721eb838cd..4a1de114767348ba8414329e3bf576ff7bc99683 100644 (file)
@@ -34,7 +34,7 @@ class LangOptions;
 
 ASTConsumer *CreateASTPrinter(llvm::raw_ostream* OS = NULL);
 
-ASTConsumer *CreateASTDumper();
+ASTConsumer *CreateASTDumper(bool FullDump);
 
 ASTConsumer *CreateASTViewer();
 
index af8b5b62437b910d891946d4337157dbd7a84bdd..ab72d6b29c1e99615d1fc3457b02f804566de808 100644 (file)
@@ -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();