]> granicus.if.org Git - clang/commitdiff
Added -ast-list option to dump filterable AST decl node names.
authorAlexander Kornienko <alexfh@google.com>
Tue, 31 Jul 2012 09:37:40 +0000 (09:37 +0000)
committerAlexander Kornienko <alexfh@google.com>
Tue, 31 Jul 2012 09:37:40 +0000 (09:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161040 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1Options.td
include/clang/Frontend/ASTConsumers.h
include/clang/Frontend/FrontendActions.h
include/clang/Frontend/FrontendOptions.h
lib/Frontend/ASTConsumers.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/FrontendActions.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp

index 48d143d2e1d6c6e36e2ada6bbeed26aacfd4e593..1b5afbb4d7008d766662ea095051b6e9379193a9 100644 (file)
@@ -289,7 +289,8 @@ def version : Flag<"-version">,
 def ast_dump_filter : Separate<"-ast-dump-filter">,
   MetaVarName<"<dump_filter>">,
   HelpText<"Use with -ast-dump or -ast-print to dump/print only AST declaration"
-           " nodes having a certain substring in a qualified name.">;
+           " nodes having a certain substring in a qualified name. Use"
+           " -ast-list to list all filterable declaration node names.">;
 
 let Group = Action_Group in {
 
@@ -314,6 +315,8 @@ def emit_html : Flag<"-emit-html">,
   HelpText<"Output input source as HTML">;
 def ast_print : Flag<"-ast-print">,
   HelpText<"Build ASTs and then pretty-print them">;
+def ast_list : Flag<"-ast-list">,
+  HelpText<"Build ASTs and print the list of declaration node qualified names">;
 def ast_dump : Flag<"-ast-dump">,
   HelpText<"Build ASTs and then debug dump them">;
 def ast_dump_xml : Flag<"-ast-dump-xml">,
index eebdfb8dc20c37ac2ff6004cb1e748aeac620e86..3731478403ef7e9b00e214289cc3bdcbbd7716ad 100644 (file)
@@ -39,6 +39,10 @@ ASTConsumer *CreateASTPrinter(raw_ostream *OS, StringRef FilterString);
 // intended for debugging.
 ASTConsumer *CreateASTDumper(StringRef FilterString);
 
+// AST Decl node lister: prints qualified names of all filterable AST Decl
+// nodes.
+ASTConsumer *CreateASTDeclNodeLister();
+
 // AST XML-dumper: dumps out the AST to stderr in a very detailed XML
 // format; this is intended for particularly intense debugging.
 ASTConsumer *CreateASTDumperXML(raw_ostream &OS);
index 8f7fe87ee67de2d5f7086f6a6b8581df79a08541..477ac45a9570bbf3e2519d0a1fd2fd527d14c7de 100644 (file)
@@ -50,6 +50,12 @@ protected:
                                          StringRef InFile);
 };
 
+class ASTDeclListAction : public ASTFrontendAction {
+protected:
+  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
+                                         StringRef InFile);
+};
+
 class ASTDumpXMLAction : public ASTFrontendAction {
 protected:
   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
index 5d674caca589114ec5a63bae1657a349be7ab7a8..ce1cd9b2d3bcbaa8b0bace32da10d6b5a861a7af 100644 (file)
@@ -20,6 +20,7 @@ namespace clang {
 
 namespace frontend {
   enum ActionKind {
+    ASTDeclList,            ///< Parse ASTs and list Decl nodes.
     ASTDump,                ///< Parse ASTs and dump them.
     ASTDumpXML,             ///< Parse ASTs and dump them in XML.
     ASTPrint,               ///< Parse ASTs and print them.
index 80f94397aa88b126a23fe0b8bb7c952b832bc51a..bb1a4e6644687f4050107ce064cb377ff58cb098 100644 (file)
@@ -86,6 +86,29 @@ namespace {
     bool Dump;
     std::string FilterString;
   };
+
+  class ASTDeclNodeLister : public ASTConsumer,
+                     public RecursiveASTVisitor<ASTDeclNodeLister> {
+    typedef RecursiveASTVisitor<ASTPrinter> base;
+
+  public:
+    ASTDeclNodeLister(raw_ostream *Out = NULL)
+        : Out(Out ? *Out : llvm::outs()) {}
+
+    virtual void HandleTranslationUnit(ASTContext &Context) {
+      TraverseDecl(Context.getTranslationUnitDecl());
+    }
+
+    bool shouldWalkTypesOfTypeLocs() const { return false; }
+
+    virtual bool VisitNamedDecl(NamedDecl *D) {
+      Out << D->getQualifiedNameAsString() << "\n";
+      return true;
+    }
+
+  private:
+    raw_ostream &Out;
+  };
 } // end anonymous namespace
 
 ASTConsumer *clang::CreateASTPrinter(raw_ostream *Out,
@@ -97,6 +120,10 @@ ASTConsumer *clang::CreateASTDumper(StringRef FilterString) {
   return new ASTPrinter(0, /*Dump=*/ true, FilterString);
 }
 
+ASTConsumer *clang::CreateASTDeclNodeLister() {
+  return new ASTDeclNodeLister(0);
+}
+
 //===----------------------------------------------------------------------===//
 /// ASTViewer - AST Visualization
 
index ea735ed122c7d873678c66b7722f13f7ef2a3564..94a89f47f751af53efebbe418b469f60e80679e9 100644 (file)
@@ -434,6 +434,7 @@ static const char *getActionName(frontend::ActionKind Kind) {
   case frontend::PluginAction:
     llvm_unreachable("Invalid kind!");
 
+  case frontend::ASTDeclList:            return "-ast-list";
   case frontend::ASTDump:                return "-ast-dump";
   case frontend::ASTDumpXML:             return "-ast-dump-xml";
   case frontend::ASTPrint:               return "-ast-print";
@@ -1438,6 +1439,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
     switch (A->getOption().getID()) {
     default:
       llvm_unreachable("Invalid option in group!");
+    case OPT_ast_list:
+      Opts.ProgramAction = frontend::ASTDeclList; break;
     case OPT_ast_dump:
       Opts.ProgramAction = frontend::ASTDump; break;
     case OPT_ast_dump_xml:
index ffd3d907295faedb85c2cfc657b1980758481a84..24960cf6a0c96dba142d98ca33a390a0d8b1f56d 100644 (file)
@@ -56,6 +56,11 @@ ASTConsumer *ASTDumpAction::CreateASTConsumer(CompilerInstance &CI,
   return CreateASTDumper(CI.getFrontendOpts().ASTDumpFilter);
 }
 
+ASTConsumer *ASTDeclListAction::CreateASTConsumer(CompilerInstance &CI,
+                                                  StringRef InFile) {
+  return CreateASTDeclNodeLister();
+}
+
 ASTConsumer *ASTDumpXMLAction::CreateASTConsumer(CompilerInstance &CI,
                                                  StringRef InFile) {
   raw_ostream *OS;
index 2662844b2edc59ae83662f679d636f94d8c3afcc..bd50083bf1c999d6c35caa768ecf62df0c275202 100644 (file)
@@ -32,6 +32,7 @@ static FrontendAction *CreateFrontendBaseAction(CompilerInstance &CI) {
   using namespace clang::frontend;
 
   switch (CI.getFrontendOpts().ProgramAction) {
+  case ASTDeclList:            return new ASTDeclListAction();
   case ASTDump:                return new ASTDumpAction();
   case ASTDumpXML:             return new ASTDumpXMLAction();
   case ASTPrint:               return new ASTPrintAction();