diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2019-05-13 21:39:55 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2019-05-13 21:39:55 +0000 |
commit | 2ce598a44a353f159157d780721c6a08b4d35c60 (patch) | |
tree | 58eca5642aefaa29c6a56ab90818e3b08d30dddd /clang/lib/Frontend/ASTConsumers.cpp | |
parent | aeeeb37e373700350472d40cf0a0969b070be0a0 (diff) | |
download | bcm5719-llvm-2ce598a44a353f159157d780721c6a08b4d35c60.tar.gz bcm5719-llvm-2ce598a44a353f159157d780721c6a08b4d35c60.zip |
Introduce the ability to dump the AST to JSON.
This adds the -ast-dump=json cc1 flag (in addition to -ast-dump=default, which is the default if no dump format is specified), as well as some initial AST dumping functionality and tests.
llvm-svn: 360622
Diffstat (limited to 'clang/lib/Frontend/ASTConsumers.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTConsumers.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/clang/lib/Frontend/ASTConsumers.cpp b/clang/lib/Frontend/ASTConsumers.cpp index 662cfd6a21d..26154ee2e85 100644 --- a/clang/lib/Frontend/ASTConsumers.cpp +++ b/clang/lib/Frontend/ASTConsumers.cpp @@ -34,10 +34,12 @@ namespace { public: enum Kind { DumpFull, Dump, Print, None }; - ASTPrinter(std::unique_ptr<raw_ostream> Out, Kind K, StringRef FilterString, + ASTPrinter(std::unique_ptr<raw_ostream> Out, Kind K, + ASTDumpOutputFormat Format, StringRef FilterString, bool DumpLookups = false) : Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)), - OutputKind(K), FilterString(FilterString), DumpLookups(DumpLookups) {} + OutputKind(K), OutputFormat(Format), FilterString(FilterString), + DumpLookups(DumpLookups) {} void HandleTranslationUnit(ASTContext &Context) override { TranslationUnitDecl *D = Context.getTranslationUnitDecl(); @@ -90,7 +92,7 @@ namespace { PrintingPolicy Policy(D->getASTContext().getLangOpts()); D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true); } else if (OutputKind != None) - D->dump(Out, OutputKind == DumpFull); + D->dump(Out, OutputKind == DumpFull, OutputFormat); } raw_ostream &Out; @@ -99,6 +101,9 @@ namespace { /// How to output individual declarations. Kind OutputKind; + /// What format should the output take? + ASTDumpOutputFormat OutputFormat; + /// Which declarations or DeclContexts to display. std::string FilterString; @@ -135,20 +140,18 @@ std::unique_ptr<ASTConsumer> clang::CreateASTPrinter(std::unique_ptr<raw_ostream> Out, StringRef FilterString) { return llvm::make_unique<ASTPrinter>(std::move(Out), ASTPrinter::Print, - FilterString); + ADOF_Default, FilterString); } std::unique_ptr<ASTConsumer> -clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, - StringRef FilterString, - bool DumpDecls, - bool Deserialize, - bool DumpLookups) { +clang::CreateASTDumper(std::unique_ptr<raw_ostream> Out, StringRef FilterString, + bool DumpDecls, bool Deserialize, bool DumpLookups, + ASTDumpOutputFormat Format) { assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump"); return llvm::make_unique<ASTPrinter>(std::move(Out), Deserialize ? ASTPrinter::DumpFull : DumpDecls ? ASTPrinter::Dump : - ASTPrinter::None, + ASTPrinter::None, Format, FilterString, DumpLookups); } |