whisperity created this revision. whisperity added reviewers: alexfh, klimek, rsmith. whisperity added a project: clang. Herald added subscribers: dkrupp, rnkovacs.
`ASTPrinter` allows setting the ouput to any O-Stream, but that printer creates source-code-like syntax (and is also marked with a `FIXME`). The nice, colourful, mostly human-readable `ASTDumper` only works on the standard error, which is not feasible in case a user wants to see the AST of a file through a code navigation/comprehension tool. This small addition of an overload solves generating a nice colourful AST block for the users of a tool I'm working on, CodeCompass <http://github.com/Ericsson/CodeCompass>, as opposed to having to duplicate the behaviour of definitions that only exist in the anonymous namespace of implementation TUs related to this module. Repository: rC Clang https://reviews.llvm.org/D45096 Files: include/clang/Frontend/ASTConsumers.h lib/Frontend/ASTConsumers.cpp Index: lib/Frontend/ASTConsumers.cpp =================================================================== --- lib/Frontend/ASTConsumers.cpp +++ lib/Frontend/ASTConsumers.cpp @@ -142,8 +142,18 @@ bool DumpDecls, bool Deserialize, bool DumpLookups) { + return CreateASTDumper(nullptr, FilterString, + DumpDecls, Deserialize, DumpLookups); +} + +std::unique_ptr<ASTConsumer> +clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, + StringRef FilterString, + bool DumpDecls, + bool Deserialize, + bool DumpLookups) { assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump"); - return llvm::make_unique<ASTPrinter>(nullptr, + return llvm::make_unique<ASTPrinter>(std::move(Out), Deserialize ? ASTPrinter::DumpFull : DumpDecls ? ASTPrinter::Dump : ASTPrinter::None, Index: include/clang/Frontend/ASTConsumers.h =================================================================== --- include/clang/Frontend/ASTConsumers.h +++ include/clang/Frontend/ASTConsumers.h @@ -40,6 +40,13 @@ bool DumpDecls, bool Deserialize, bool DumpLookups); +// AST dumper: dumps the raw AST in human-readable form to the given output +// stream. +std::unique_ptr<ASTConsumer> CreateASTDumper(std::unique_ptr<raw_ostream> OS, + StringRef FilterString, + bool DumpDecls, bool Deserialize, + bool DumpLookups); + // AST Decl node lister: prints qualified names of all filterable AST Decl // nodes. std::unique_ptr<ASTConsumer> CreateASTDeclNodeLister();
Index: lib/Frontend/ASTConsumers.cpp =================================================================== --- lib/Frontend/ASTConsumers.cpp +++ lib/Frontend/ASTConsumers.cpp @@ -142,8 +142,18 @@ bool DumpDecls, bool Deserialize, bool DumpLookups) { + return CreateASTDumper(nullptr, FilterString, + DumpDecls, Deserialize, DumpLookups); +} + +std::unique_ptr<ASTConsumer> +clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, + StringRef FilterString, + bool DumpDecls, + bool Deserialize, + bool DumpLookups) { assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump"); - return llvm::make_unique<ASTPrinter>(nullptr, + return llvm::make_unique<ASTPrinter>(std::move(Out), Deserialize ? ASTPrinter::DumpFull : DumpDecls ? ASTPrinter::Dump : ASTPrinter::None, Index: include/clang/Frontend/ASTConsumers.h =================================================================== --- include/clang/Frontend/ASTConsumers.h +++ include/clang/Frontend/ASTConsumers.h @@ -40,6 +40,13 @@ bool DumpDecls, bool Deserialize, bool DumpLookups); +// AST dumper: dumps the raw AST in human-readable form to the given output +// stream. +std::unique_ptr<ASTConsumer> CreateASTDumper(std::unique_ptr<raw_ostream> OS, + StringRef FilterString, + bool DumpDecls, bool Deserialize, + bool DumpLookups); + // AST Decl node lister: prints qualified names of all filterable AST Decl // nodes. std::unique_ptr<ASTConsumer> CreateASTDeclNodeLister();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits