r329391 - Allow the creation of human-friendly ASTDumper to arbitrary output stream
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 6 06:01:13 PDT 2018
Author: alexfh
Date: Fri Apr 6 06:01:12 2018
New Revision: 329391
URL: http://llvm.org/viewvc/llvm-project?rev=329391&view=rev
Log:
Allow the creation of human-friendly ASTDumper to arbitrary output stream
Summary:
`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 output, 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, [[ http://github.com/Ericsson/CodeCompass | 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.
Reviewers: alexfh, klimek, rsmith
Reviewed By: alexfh
Subscribers: rnkovacs, dkrupp, gsd, xazax.hun, cfe-commits, #clang
Tags: #clang
Patch by Whisperity!
Differential Revision: https://reviews.llvm.org/D45096
Modified:
cfe/trunk/docs/HowToSetupToolingForLLVM.rst
cfe/trunk/include/clang/Frontend/ASTConsumers.h
cfe/trunk/lib/Frontend/ASTConsumers.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/tools/clang-check/ClangCheck.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp
Modified: cfe/trunk/docs/HowToSetupToolingForLLVM.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/HowToSetupToolingForLLVM.rst?rev=329391&r1=329390&r2=329391&view=diff
==============================================================================
--- cfe/trunk/docs/HowToSetupToolingForLLVM.rst (original)
+++ cfe/trunk/docs/HowToSetupToolingForLLVM.rst Fri Apr 6 06:01:12 2018
@@ -133,7 +133,8 @@ Examples:
if (this->ASTList.operator _Bool())
return clang::CreateASTDeclNodeLister();
if (this->ASTDump.operator _Bool())
- return clang::CreateASTDumper(this->ASTDumpFilter);
+ return clang::CreateASTDumper(nullptr /*Dump to stdout.*/,
+ this->ASTDumpFilter);
if (this->ASTPrint.operator _Bool())
return clang::CreateASTPrinter(&llvm::outs(), this->ASTDumpFilter);
return new clang::ASTConsumer();
Modified: cfe/trunk/include/clang/Frontend/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTConsumers.h?rev=329391&r1=329390&r2=329391&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTConsumers.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTConsumers.h Fri Apr 6 06:01:12 2018
@@ -34,9 +34,10 @@ class TargetOptions;
std::unique_ptr<ASTConsumer> CreateASTPrinter(std::unique_ptr<raw_ostream> OS,
StringRef FilterString);
-// AST dumper: dumps the raw AST in human-readable form to stderr; this is
-// intended for debugging.
-std::unique_ptr<ASTConsumer> CreateASTDumper(StringRef FilterString,
+// AST dumper: dumps the raw AST in human-readable form to the given output
+// stream, or stdout if OS is nullptr.
+std::unique_ptr<ASTConsumer> CreateASTDumper(std::unique_ptr<raw_ostream> OS,
+ StringRef FilterString,
bool DumpDecls, bool Deserialize,
bool DumpLookups);
Modified: cfe/trunk/lib/Frontend/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTConsumers.cpp?rev=329391&r1=329390&r2=329391&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTConsumers.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTConsumers.cpp Fri Apr 6 06:01:12 2018
@@ -138,12 +138,14 @@ clang::CreateASTPrinter(std::unique_ptr<
FilterString);
}
-std::unique_ptr<ASTConsumer> clang::CreateASTDumper(StringRef FilterString,
- bool DumpDecls,
- bool Deserialize,
- bool 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,
Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=329391&r1=329390&r2=329391&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Fri Apr 6 06:01:12 2018
@@ -74,7 +74,8 @@ ASTPrintAction::CreateASTConsumer(Compil
std::unique_ptr<ASTConsumer>
ASTDumpAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
- return CreateASTDumper(CI.getFrontendOpts().ASTDumpFilter,
+ return CreateASTDumper(nullptr /*Dump to stdout.*/,
+ CI.getFrontendOpts().ASTDumpFilter,
CI.getFrontendOpts().ASTDumpDecls,
CI.getFrontendOpts().ASTDumpAll,
CI.getFrontendOpts().ASTDumpLookups);
Modified: cfe/trunk/tools/clang-check/ClangCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-check/ClangCheck.cpp?rev=329391&r1=329390&r2=329391&view=diff
==============================================================================
--- cfe/trunk/tools/clang-check/ClangCheck.cpp (original)
+++ cfe/trunk/tools/clang-check/ClangCheck.cpp Fri Apr 6 06:01:12 2018
@@ -138,7 +138,9 @@ public:
if (ASTList)
return clang::CreateASTDeclNodeLister();
if (ASTDump)
- return clang::CreateASTDumper(ASTDumpFilter, /*DumpDecls=*/true,
+ return clang::CreateASTDumper(nullptr /*Dump to stdout.*/,
+ ASTDumpFilter,
+ /*DumpDecls=*/true,
/*Deserialize=*/false,
/*DumpLookups=*/false);
if (ASTPrint)
Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=329391&r1=329390&r2=329391&view=diff
==============================================================================
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Fri Apr 6 06:01:12 2018
@@ -313,7 +313,8 @@ llvm::Expected<CIAndOrigins> Parse(const
auto &CG = *static_cast<CodeGenerator *>(ASTConsumers.back().get());
if (ShouldDumpAST)
- ASTConsumers.push_back(CreateASTDumper("", true, false, false));
+ ASTConsumers.push_back(CreateASTDumper(nullptr /*Dump to stdout.*/,
+ "", true, false, false));
CI.getDiagnosticClient().BeginSourceFile(
CI.getCompilerInstance().getLangOpts(),
More information about the cfe-commits
mailing list