r362003 - [analyzer] print() JSONify: CFG implementation

Csaba Dabis via cfe-commits cfe-commits at lists.llvm.org
Wed May 29 11:29:31 PDT 2019


Author: charusso
Date: Wed May 29 11:29:31 2019
New Revision: 362003

URL: http://llvm.org/viewvc/llvm-project?rev=362003&view=rev
Log:
[analyzer] print() JSONify: CFG implementation

Summary: -

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

Reviewed By: NoQ

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

Tags: #clang

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

Modified:
    cfe/trunk/include/clang/Analysis/CFG.h
    cfe/trunk/lib/Analysis/CFG.cpp
    cfe/trunk/lib/Analysis/ProgramPoint.cpp

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=362003&r1=362002&r2=362003&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Wed May 29 11:29:31 2019
@@ -882,7 +882,11 @@ public:
   void dump(const CFG *cfg, const LangOptions &LO, bool ShowColors = false) const;
   void print(raw_ostream &OS, const CFG* cfg, const LangOptions &LO,
              bool ShowColors) const;
+
   void printTerminator(raw_ostream &OS, const LangOptions &LO) const;
+  void printTerminatorJson(raw_ostream &Out, const LangOptions &LO,
+                           bool AddQuotes) const;
+  
   void printAsOperand(raw_ostream &OS, bool /*PrintType*/) {
     OS << "BB#" << getBlockID();
   }

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=362003&r1=362002&r2=362003&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Wed May 29 11:29:31 2019
@@ -27,10 +27,11 @@
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/Type.h"
-#include "clang/Analysis/Support/BumpVector.h"
 #include "clang/Analysis/ConstructionContext.h"
+#include "clang/Analysis/Support/BumpVector.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/ExceptionSpecificationType.h"
+#include "clang/Basic/JsonSupport.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceLocation.h"
@@ -5561,6 +5562,17 @@ void CFGBlock::printTerminator(raw_ostre
   TPrinter.print(getTerminator());
 }
 
+/// printTerminatorJson - Pretty-prints the terminator in JSON format.
+void CFGBlock::printTerminatorJson(raw_ostream &Out, const LangOptions &LO,
+                                   bool AddQuotes) const {
+  std::string Buf;
+  llvm::raw_string_ostream TempOut(Buf);
+
+  printTerminator(TempOut, LO);
+
+  Out << JsonFormat(TempOut.str(), AddQuotes);
+}
+
 Stmt *CFGBlock::getTerminatorCondition(bool StripParens) {
   Stmt *Terminator = getTerminatorStmt();
   if (!Terminator)

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=362003&r1=362002&r2=362003&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Wed May 29 11:29:31 2019
@@ -149,13 +149,16 @@ void ProgramPoint::printJson(llvm::raw_o
     const BlockEdge &E = castAs<BlockEdge>();
     const Stmt *T = E.getSrc()->getTerminatorStmt();
     Out << "Edge\", \"src_id\": " << E.getSrc()->getBlockID()
-        << ", \"dst_id\": " << E.getDst()->getBlockID()
-        << ", \"terminator\": " << (!T ? "null, \"term_kind\": null" : "\"");
-    if (!T)
+        << ", \"dst_id\": " << E.getDst()->getBlockID() << ", \"terminator\": ";
+
+    if (!T) {
+      Out << "null, \"term_kind\": null";
       break;
+    }
 
-    E.getSrc()->printTerminator(Out, Context.getLangOpts());
-    Out << "\", ";
+    E.getSrc()->printTerminatorJson(Out, Context.getLangOpts(),
+                                    /*AddQuotes=*/true);
+    Out << ", ";
     printLocJson(Out, T->getBeginLoc(), SM);
 
     Out << ", \"term_kind\": \"";




More information about the cfe-commits mailing list