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/AST/ASTDumper.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/AST/ASTDumper.cpp')
-rw-r--r-- | clang/lib/AST/ASTDumper.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index f8938512afe..a1f9e3f5391 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -14,6 +14,7 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/ASTNodeTraverser.h" #include "clang/AST/DeclLookups.h" +#include "clang/AST/JSONNodeDumper.h" #include "clang/AST/TextNodeDumper.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/Module.h" @@ -222,13 +223,21 @@ LLVM_DUMP_METHOD void Type::dump(llvm::raw_ostream &OS) const { LLVM_DUMP_METHOD void Decl::dump() const { dump(llvm::errs()); } -LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize) const { +LLVM_DUMP_METHOD void Decl::dump(raw_ostream &OS, bool Deserialize, + ASTDumpOutputFormat Format) const { const ASTContext &Ctx = getASTContext(); const SourceManager &SM = Ctx.getSourceManager(); - ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM, - SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy()); - P.setDeserialize(Deserialize); - P.Visit(this); + + if (ADOF_JSON == Format) { + JSONDumper P(OS, SM, Ctx.getPrintingPolicy()); + (void)Deserialize; // FIXME? + P.Visit(this); + } else { + ASTDumper P(OS, &Ctx.getCommentCommandTraits(), &SM, + SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy()); + P.setDeserialize(Deserialize); + P.Visit(this); + } } LLVM_DUMP_METHOD void Decl::dumpColor() const { |