[PATCH] D45096: Allow the creation of human-friendly ASTDumper to arbitrary output stream
Whisperity via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 30 08:57:13 PDT 2018
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45096.140437.patch
Type: text/x-patch
Size: 2065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180330/dfca31ac/attachment.bin>
More information about the cfe-commits
mailing list