]> granicus.if.org Git - clang/commitdiff
[analyzer] print() JSONify: SVal implementation
authorCsaba Dabis <dabis.csaba98@gmail.com>
Wed, 29 May 2019 18:38:52 +0000 (18:38 +0000)
committerCsaba Dabis <dabis.csaba98@gmail.com>
Wed, 29 May 2019 18:38:52 +0000 (18:38 +0000)
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
             Szelethus, donat.nagy, dkrupp

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62497

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362008 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
lib/StaticAnalyzer/Core/Environment.cpp
lib/StaticAnalyzer/Core/SVals.cpp

index 8861f1504814dbbf713206d92fcd1e4dd109e350..1abe2978208867be4f2f9aad4bb447fa37ec063d 100644 (file)
@@ -190,6 +190,9 @@ public:
 
   const MemRegion *getAsRegion() const;
 
+  /// printJson - Pretty-prints in JSON format.
+  void printJson(raw_ostream &Out, bool AddQuotes) const;
+
   void dumpToStream(raw_ostream &OS) const;
   void dump() const;
 
index 3ebb66c6af10ce947d37150fabb1a978d757a54f..94cc4d6dbb2fdf08629ece1af610c886d0c0946f 100644 (file)
@@ -263,10 +263,12 @@ void Environment::printJson(raw_ostream &Out, const ASTContext &Ctx,
       Indent(Out, InnerSpace, IsDot)
           << "{ \"lctx_id\": " << LC->getID()
           << ", \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
-
       S->printJson(Out, nullptr, PP, /*AddQuotes=*/true);
 
-      Out << ", \"value\": \"" << I->second << "\" }";
+      Out << ", \"value\": ";
+      I->second.printJson(Out, /*AddQuotes=*/true);
+
+      Out << " }";
 
       if (I != LastI)
         Out << ',';
index b3c83e7792da3c299d1683fdc40b0ae01d5b3bc3..9b5de6c3eb92bfffd459e86091842823f3f22a30 100644 (file)
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Type.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
@@ -283,6 +284,15 @@ SVal loc::ConcreteInt::evalBinOp(BasicValueFactory& BasicVals,
 
 LLVM_DUMP_METHOD void SVal::dump() const { dumpToStream(llvm::errs()); }
 
+void SVal::printJson(raw_ostream &Out, bool AddQuotes) const {
+  std::string Buf;
+  llvm::raw_string_ostream TempOut(Buf);
+
+  dumpToStream(TempOut);
+
+  Out << JsonFormat(TempOut.str(), AddQuotes);
+}
+
 void SVal::dumpToStream(raw_ostream &os) const {
   switch (getBaseKind()) {
     case UnknownValKind: