This revision was automatically updated to reflect the committed changes.
Closed by commit rC361983: [analyzer] print() JSONify: Program state 
implementation (authored by Charusso, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62087?vs=201907&id=201960#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62087/new/

https://reviews.llvm.org/D62087

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  lib/StaticAnalyzer/Core/ProgramState.cpp
  test/Analysis/dump_egraph.cpp
  test/Analysis/expr-inspection.c

Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -10,13 +10,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Basic/JsonSupport.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
-#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicTypeMap.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -441,15 +442,18 @@
 //===----------------------------------------------------------------------===//
 
 void ProgramState::printJson(raw_ostream &Out, const LocationContext *LCtx,
-                             const char *NL, const char *Sep,
-                             unsigned int Space, bool IsDot) const {
-  // Print the store.
+                             const char *NL, unsigned int Space,
+                             bool IsDot) const {
+  Indent(Out, Space, IsDot) << "\"program_state\": {" << NL;
+  ++Space;
+
   ProgramStateManager &Mgr = getStateManager();
-  const ASTContext &Context = getStateManager().getContext();
+
+  // Print the store.
   Mgr.getStoreManager().printJson(Out, getStore(), NL, Space, IsDot);
 
   // Print out the environment.
-  Env.printJson(Out, Context, LCtx, NL, Space, IsDot);
+  Env.printJson(Out, Mgr.getContext(), LCtx, NL, Space, IsDot);
 
   // Print out the constraints.
   Mgr.getConstraintManager().printJson(Out, this, NL, Space, IsDot);
@@ -459,11 +463,14 @@
 
   // Print checker-specific data.
   Mgr.getOwningEngine().printJson(Out, this, LCtx, NL, Space, IsDot);
+
+  --Space;
+  Indent(Out, Space, IsDot) << '}';
 }
 
 void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LCtx,
                             unsigned int Space) const {
-  printJson(Out, LCtx, "\\l", "\\|", Space, /*IsDot=*/true);
+  printJson(Out, LCtx, /*NL=*/"\\l", Space, /*IsDot=*/true);
 }
 
 LLVM_DUMP_METHOD void ProgramState::dump() const {
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -425,8 +425,8 @@
 
   // Pretty-printing.
   void printJson(raw_ostream &Out, const LocationContext *LCtx = nullptr,
-                 const char *NL = "\n", const char *Sep = "",
-                 unsigned int Space = 0, bool IsDot = false) const;
+                 const char *NL = "\n", unsigned int Space = 0,
+                 bool IsDot = false) const;
 
   void printDOT(raw_ostream &Out, const LocationContext *LCtx = nullptr,
                 unsigned int Space = 0) const;
Index: test/Analysis/dump_egraph.cpp
===================================================================
--- test/Analysis/dump_egraph.cpp
+++ test/Analysis/dump_egraph.cpp
@@ -16,9 +16,9 @@
   T t;
 }
 
-// CHECK: \"constructing_objects\": [\l&nbsp;&nbsp;\{ \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;\{ \"lctx_id\": 1, \"stmt_id\": 1155, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\"
+// CHECK: \"constructing_objects\": [\l&nbsp;&nbsp;&nbsp;&nbsp;\{ \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"lctx_id\": 1, \"stmt_id\": 1155, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\"
 
-// CHECK: \"constructing_objects\": [\l&nbsp;&nbsp;\{ \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;\{ \"lctx_id\": 2, \"init_id\": 1092, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\"
+// CHECK: \"constructing_objects\": [\l&nbsp;&nbsp;&nbsp;&nbsp;\{ \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"lctx_id\": 2, \"init_id\": 1092, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"&t-\>s\"
 
-// CHECK: \"store\": [\l&nbsp;&nbsp;\{ \"cluster\": \"t\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
+// CHECK: \"store\": [\l&nbsp;&nbsp;&nbsp;&nbsp;\{ \"cluster\": \"t\", \"items\": [\l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
 
Index: test/Analysis/expr-inspection.c
===================================================================
--- test/Analysis/expr-inspection.c
+++ test/Analysis/expr-inspection.c
@@ -23,20 +23,22 @@
   }
 }
 
-// CHECK:      "store": [
-// CHECK-NEXT:   { "cluster": "y", "items": [
-// CHECK-NEXT:     { "kind": "Direct", "offset": 0, "value": "2 S32b" }
-// CHECK-NEXT:   ]}
-// CHECK-NEXT: ],
-// CHECK-NEXT: "environment": [
-// CHECK-NEXT:   { "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
-// CHECK-NEXT:     { "lctx_id": 1, "stmt_id": 847, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
-// CHECK-NEXT:   ]}
-// CHECK-NEXT: ],
-// CHECK-NEXT: "constraints": [
-// CHECK-NEXT:   { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
-// CHECK-NEXT: ],
-// CHECK-NEXT: "dynamic_types": null,
-// CHECK-NEXT: "constructing_objects": null,
-// CHECK-NEXT: "checker_messages": null
+// CHECK:      "program_state": {
+// CHECK-NEXT:   "store": [
+// CHECK-NEXT:     { "cluster": "y", "items": [
+// CHECK-NEXT:       { "kind": "Direct", "offset": 0, "value": "2 S32b" }
+// CHECK-NEXT:     ]}
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "environment": [
+// CHECK-NEXT:     { "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
+// CHECK-NEXT:       { "lctx_id": 1, "stmt_id": 847, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
+// CHECK-NEXT:     ]}
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "constraints": [
+// CHECK-NEXT:     { "symbol": "reg_$0<int x>", "range": "{ [-2147483648, 13] }" }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "dynamic_types": null,
+// CHECK-NEXT:   "constructing_objects": null,
+// CHECK-NEXT:   "checker_messages": null
+// CHECK-NEXT: }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to