Index: clang/include/clang/AST/DeclBase.h =================================================================== --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -1129,6 +1129,8 @@ raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation = 0); + void printJson(raw_ostream &Out, bool AddQuotes) const; + // Debuggers don't usually respect default arguments. void dump() const; Index: clang/lib/AST/DeclPrinter.cpp =================================================================== --- clang/lib/AST/DeclPrinter.cpp +++ clang/lib/AST/DeclPrinter.cpp @@ -20,6 +20,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/PrettyPrinter.h" +#include "clang/Basic/JsonSupport.h" #include "clang/Basic/Module.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -118,7 +119,8 @@ void Decl::print(raw_ostream &Out, unsigned Indentation, bool PrintInstantiation) const { - print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation); + print(Out, getASTContext().getPrintingPolicy(), Indentation, + PrintInstantiation); } void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy, @@ -128,6 +130,15 @@ Printer.Visit(const_cast(this)); } +void Decl::printJson(raw_ostream &Out, bool AddQuotes) const { + std::string Buf; + llvm::raw_string_ostream TempOut(Buf); + + print(TempOut, getASTContext().getPrintingPolicy()); + + Out << JsonFormat(TempOut.str(), AddQuotes); +} + void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW) const { print(Out, Context, Context.getPrintingPolicy(), OmitTemplateKW); Index: clang/lib/Analysis/ProgramPoint.cpp =================================================================== --- clang/lib/Analysis/ProgramPoint.cpp +++ clang/lib/Analysis/ProgramPoint.cpp @@ -116,18 +116,18 @@ case ProgramPoint::PreImplicitCallKind: { ImplicitCallPoint PC = castAs(); - Out << "PreCall\", \"stmt\": \""; - PC.getDecl()->print(Out, Context.getLangOpts()); - Out << "\", "; + Out << "PreCall\", \"decl\": "; + PC.getDecl()->printJson(Out, /*AddQuotes=*/true); + Out << ", "; printLocJson(Out, PC.getLocation(), SM); break; } case ProgramPoint::PostImplicitCallKind: { ImplicitCallPoint PC = castAs(); - Out << "PostCall\", \"stmt\": \""; - PC.getDecl()->print(Out, Context.getLangOpts()); - Out << "\", "; + Out << "PostCall\", \"decl\": "; + PC.getDecl()->printJson(Out, /*AddQuotes=*/true); + Out << ", "; printLocJson(Out, PC.getLocation(), SM); break; }