summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Driver/CC1Options.td5
-rw-r--r--include/clang/Frontend/ASTConsumers.h4
-rw-r--r--include/clang/Frontend/FrontendActions.h6
-rw-r--r--include/clang/Frontend/FrontendOptions.h1
-rw-r--r--lib/Frontend/ASTConsumers.cpp27
-rw-r--r--lib/Frontend/CompilerInvocation.cpp3
-rw-r--r--lib/Frontend/FrontendActions.cpp5
-rw-r--r--lib/FrontendTool/ExecuteCompilerInvocation.cpp1
8 files changed, 51 insertions, 1 deletions
diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td
index 48d143d2e1..1b5afbb4d7 100644
--- a/include/clang/Driver/CC1Options.td
+++ b/include/clang/Driver/CC1Options.td
@@ -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">,
diff --git a/include/clang/Frontend/ASTConsumers.h b/include/clang/Frontend/ASTConsumers.h
index eebdfb8dc2..3731478403 100644
--- a/include/clang/Frontend/ASTConsumers.h
+++ b/include/clang/Frontend/ASTConsumers.h
@@ -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);
diff --git a/include/clang/Frontend/FrontendActions.h b/include/clang/Frontend/FrontendActions.h
index 8f7fe87ee6..477ac45a95 100644
--- a/include/clang/Frontend/FrontendActions.h
+++ b/include/clang/Frontend/FrontendActions.h
@@ -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,
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index 5d674caca5..ce1cd9b2d3 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -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.
diff --git a/lib/Frontend/ASTConsumers.cpp b/lib/Frontend/ASTConsumers.cpp
index 80f94397aa..bb1a4e6644 100644
--- a/lib/Frontend/ASTConsumers.cpp
+++ b/lib/Frontend/ASTConsumers.cpp
@@ -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
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index ea735ed122..94a89f47f7 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -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:
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index ffd3d90729..24960cf6a0 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -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;
diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 2662844b2e..bd50083bf1 100644
--- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -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();