forked from OSchip/llvm-project
Added -ast-list option to dump filterable AST decl node names.
llvm-svn: 161040
This commit is contained in:
parent
61b06cbcb4
commit
4de035947b
|
@ -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">,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue