[cfe-commits] r145828 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h lib/StaticAnalyzer/Core/ProgramState.cpp

Anna Zaks ganna at apple.com
Mon Dec 5 10:58:08 PST 2011


Author: zaks
Date: Mon Dec  5 12:58:08 2011
New Revision: 145828

URL: http://llvm.org/viewvc/llvm-project?rev=145828&view=rev
Log:
[analyzer] Add ability to do a simple ProgramState dump() without
requiring CFG.

Adding more ugly code; the evnvironment printing should be moved to
envirnment at some point.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
    cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=145828&r1=145827&r2=145828&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h Mon Dec  5 12:58:08 2011
@@ -356,13 +356,15 @@
   }
 
   // Pretty-printing.
-  void print(raw_ostream &Out, CFG &C, const char *nl = "\n",
+  void print(raw_ostream &Out, CFG *C, const char *nl = "\n",
              const char *sep = "") const;
 
-  void printStdErr(CFG &C) const;
+  void dump(CFG &C) const;
 
   void printDOT(raw_ostream &Out, CFG &C) const;
 
+  void dump() const;
+
 private:
   /// Increments the number of times this state is referenced by ExplodeNodes.
   void incrementReferenceCount() { ++refCount; }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=145828&r1=145827&r2=145828&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Mon Dec  5 12:58:08 2011
@@ -385,53 +385,71 @@
   return (bool) (((uintptr_t) S) & 0x1);
 }
 
-void ProgramState::print(raw_ostream &Out, CFG &C,
+void ProgramState::print(raw_ostream &Out, CFG *C,
                          const char *NL, const char *Sep) const {
   // Print the store.
   ProgramStateManager &Mgr = getStateManager();
   Mgr.getStoreManager().print(getStore(), Out, NL, Sep);
-
-  // Print Subexpression bindings.
   bool isFirst = true;
 
   // FIXME: All environment printing should be moved inside Environment.
-  for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
-    if (C.isBlkExpr(I.getKey()) || IsEnvLoc(I.getKey()))
-      continue;
-
-    if (isFirst) {
-      Out << NL << NL << "Sub-Expressions:" << NL;
-      isFirst = false;
-    } else {
-      Out << NL;
+  if (C) {
+    // Print Subexpression bindings.
+    for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
+      if (C->isBlkExpr(I.getKey()) || IsEnvLoc(I.getKey()))
+        continue;
+
+      if (isFirst) {
+        Out << NL << NL << "Sub-Expressions:" << NL;
+        isFirst = false;
+      } else {
+        Out << NL;
+      }
+
+      Out << " (" << (void*) I.getKey() << ") ";
+      LangOptions LO; // FIXME.
+      I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
+      Out << " : " << I.getData();
     }
 
-    Out << " (" << (void*) I.getKey() << ") ";
-    LangOptions LO; // FIXME.
-    I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
-    Out << " : " << I.getData();
-  }
-
-  // Print block-expression bindings.
-  isFirst = true;
-
-  for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
-    if (!C.isBlkExpr(I.getKey()))
-      continue;
-
-    if (isFirst) {
-      Out << NL << NL << "Block-level Expressions:" << NL;
-      isFirst = false;
-    } else {
-      Out << NL;
+    // Print block-expression bindings.
+    isFirst = true;
+    for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
+      if (!C->isBlkExpr(I.getKey()))
+        continue;
+
+      if (isFirst) {
+        Out << NL << NL << "Block-level Expressions:" << NL;
+        isFirst = false;
+      } else {
+        Out << NL;
+      }
+
+      Out << " (" << (void*) I.getKey() << ") ";
+      LangOptions LO; // FIXME.
+      I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
+      Out << " : " << I.getData();
+    }
+  } else {
+    // Print All bindings - no info to differentiate block from subexpressions.
+    for (Environment::iterator I = Env.begin(), E = Env.end(); I != E; ++I) {
+      if (IsEnvLoc(I.getKey()))
+        continue;
+
+      if (isFirst) {
+        Out << NL << NL << "Expressions:" << NL;
+        isFirst = false;
+      } else {
+        Out << NL;
+      }
+
+      Out << " (" << (void*) I.getKey() << ") ";
+      LangOptions LO; // FIXME.
+      I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
+      Out << " : " << I.getData();
     }
-
-    Out << " (" << (void*) I.getKey() << ") ";
-    LangOptions LO; // FIXME.
-    I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
-    Out << " : " << I.getData();
   }
-  
+
   // Print locations.
   isFirst = true;
   
@@ -461,11 +479,15 @@
 }
 
 void ProgramState::printDOT(raw_ostream &Out, CFG &C) const {
-  print(Out, C, "\\l", "\\|");
+  print(Out, &C, "\\l", "\\|");
+}
+
+void ProgramState::dump(CFG &C) const {
+  print(llvm::errs(), &C);
 }
 
-void ProgramState::printStdErr(CFG &C) const {
-  print(llvm::errs(), C);
+void ProgramState::dump() const {
+  print(llvm::errs(), 0);
 }
 
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list