From 625ed58bba995fb530a6a2506042766ab8ba136d Mon Sep 17 00:00:00 2001 From: Frederich Munch Date: Wed, 25 Jan 2017 14:21:23 -0500 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98asttree=E2=80=99=20predicate=20t?= =?UTF-8?q?o=20stats=20command,=20courtesy=20of=20vkhristenko.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Interpreter/Interpreter.cpp | 8 +++++++- lib/MetaProcessor/MetaSema.cpp | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index 29c57e33..ea0d4890 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -38,6 +38,7 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Basic/SourceManager.h" #include "clang/CodeGen/ModuleBuilder.h" +#include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/Utils.h" #include "clang/Lex/Preprocessor.h" @@ -469,7 +470,12 @@ namespace cling { // FIXME: Add stream argument and move DumpIncludePath path here. void Interpreter::dump(llvm::StringRef what, llvm::StringRef filter) { llvm::raw_ostream &where = cling::log(); - if (what.equals("ast")) + if (what.equals("asttree")) { + std::unique_ptr printer = + clang::CreateASTDumper(filter, true /*DumpDecls*/, + false /*DumpLookups*/ ); + printer->HandleTranslationUnit(getSema().getASTContext()); + } else if (what.equals("ast")) getSema().getASTContext().PrintStats(); else if (what.equals("decl")) ClangInternalState::printLookupTables(where, getSema().getASTContext()); diff --git a/lib/MetaProcessor/MetaSema.cpp b/lib/MetaProcessor/MetaSema.cpp index fbcab15b..3d4d2aa9 100644 --- a/lib/MetaProcessor/MetaSema.cpp +++ b/lib/MetaProcessor/MetaSema.cpp @@ -360,6 +360,7 @@ namespace cling { "\n" " " << metaString << "stats [name]\t\t- Show stats for internal data structures\n" "\t\t\t\t 'ast' abstract syntax tree stats\n" + "\t\t\t\t 'asttree [filter]' abstract syntax tree layout\n" "\t\t\t\t 'decl' dump ast declarations\n" "\t\t\t\t 'undo' show undo stack\n" "\n"