[cfe-commits] r75560 - in /cfe/trunk: include/clang/Analysis/PathSensitive/SVals.h lib/Analysis/BasicStore.cpp lib/Analysis/GRState.cpp lib/Analysis/MemRegion.cpp lib/Analysis/RegionStore.cpp lib/Analysis/SVals.cpp

Ted Kremenek kremenek at apple.com
Mon Jul 13 16:53:08 PDT 2009


Author: kremenek
Date: Mon Jul 13 18:53:06 2009
New Revision: 75560

URL: http://llvm.org/viewvc/llvm-project?rev=75560&view=rev
Log:
Tidy pretty-printing for SVals, using 'dump()' instead of 'printStdErr()', and implementing operator<< support for llvm::raw_ostream.

Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
    cfe/trunk/lib/Analysis/BasicStore.cpp
    cfe/trunk/lib/Analysis/GRState.cpp
    cfe/trunk/lib/Analysis/MemRegion.cpp
    cfe/trunk/lib/Analysis/RegionStore.cpp
    cfe/trunk/lib/Analysis/SVals.cpp

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h?rev=75560&r1=75559&r2=75560&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/SVals.h Mon Jul 13 18:53:06 2009
@@ -18,7 +18,11 @@
 #include "clang/Analysis/PathSensitive/SymbolManager.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/ADT/ImmutableList.h"
-  
+
+namespace llvm {
+  class raw_ostream;
+}
+
 //==------------------------------------------------------------------------==//
 //  Base SVal types.
 //==------------------------------------------------------------------------==//
@@ -113,8 +117,8 @@
 
   const MemRegion *getAsRegion() const;
   
-  void print(llvm::raw_ostream& OS) const;
-  void printStdErr() const;
+  void dumpToStream(llvm::raw_ostream& OS) const;
+  void dump() const;
 
   // Iterators.
   class symbol_iterator {
@@ -171,7 +175,7 @@
   NonLoc(unsigned SubKind, const void* d) : SVal(d, false, SubKind) {}
   
 public:
-  void print(llvm::raw_ostream& Out) const;
+  void dumpToStream(llvm::raw_ostream& Out) const;
   
   // Implement isa<T> support.
   static inline bool classof(const SVal* V) {
@@ -185,7 +189,7 @@
   : SVal(const_cast<void*>(D), true, SubKind) {}
 
 public:
-  void print(llvm::raw_ostream& Out) const;
+  void dumpToStream(llvm::raw_ostream& Out) const;
 
   Loc(const Loc& X) : SVal(X.Data, true, X.getSubKind()) {}
   Loc& operator=(const Loc& X) { memcpy(this, &X, sizeof(Loc)); return *this; }
@@ -418,4 +422,11 @@
 } // end clang::loc namespace
 } // end clang namespace  
 
+namespace llvm {
+static inline llvm::raw_ostream& operator<<(llvm::raw_ostream& os,
+                                            clang::SVal V) {
+  V.dumpToStream(os);
+  return os;
+}
+} // end llvm namespace
 #endif

Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=75560&r1=75559&r2=75560&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Mon Jul 13 18:53:06 2009
@@ -611,8 +611,7 @@
     else
       Out << nl;
     
-    Out << ' ' << I.getKey() << " : ";
-    I.getData().print(Out);
+    Out << ' ' << I.getKey() << " : " << I.getData();
   }
 }
 

Modified: cfe/trunk/lib/Analysis/GRState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRState.cpp?rev=75560&r1=75559&r2=75560&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRState.cpp (original)
+++ cfe/trunk/lib/Analysis/GRState.cpp Mon Jul 13 18:53:06 2009
@@ -168,8 +168,7 @@
     Out << " (" << (void*) I.getKey() << ") ";
     LangOptions LO; // FIXME.
     I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
-    Out << " : ";
-    I.getData().print(Out);
+    Out << " : " << I.getData();
   }
   
   // Print block-expression bindings.
@@ -186,8 +185,7 @@
     Out << " (" << (void*) I.getKey() << ") ";
     LangOptions LO; // FIXME.
     I.getKey()->printPretty(Out, 0, PrintingPolicy(LO));
-    Out << " : ";
-    I.getData().print(Out);
+    Out << " : " << I.getData();
   }
   
   Mgr->getConstraintManager().print(this, Out, nl, sep);

Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=75560&r1=75559&r2=75560&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Mon Jul 13 18:53:06 2009
@@ -178,7 +178,7 @@
 }
 
 void ElementRegion::dumpToStream(llvm::raw_ostream& os) const {
-  os << superRegion << '['; Index.print(os); os << ']';
+  os << superRegion << '[' << Index << ']';
 }
 
 void FieldRegion::dumpToStream(llvm::raw_ostream& os) const {

Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=75560&r1=75559&r2=75560&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Mon Jul 13 18:53:06 2009
@@ -1438,8 +1438,6 @@
   RegionBindingsTy B = GetRegionBindings(store);
   OS << "Store:" << nl;
   
-  for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) {
-    OS << ' ' << I.getKey() << " : ";
-    I.getData().print(OS); OS << nl;
-  }
+  for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I)
+    OS << ' ' << I.getKey() << " : " << I.getData() << nl;
 }

Modified: cfe/trunk/lib/Analysis/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/SVals.cpp?rev=75560&r1=75559&r2=75560&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/SVals.cpp (original)
+++ cfe/trunk/lib/Analysis/SVals.cpp Mon Jul 13 18:53:06 2009
@@ -239,98 +239,83 @@
 // Pretty-Printing.
 //===----------------------------------------------------------------------===//
 
-void SVal::printStdErr() const { print(llvm::errs()); }
+void SVal::dump() const { dumpToStream(llvm::errs()); }
 
-void SVal::print(llvm::raw_ostream& Out) const {
-
-  switch (getBaseKind()) {
-      
+void SVal::dumpToStream(llvm::raw_ostream& os) const {
+  switch (getBaseKind()) {      
     case UnknownKind:
-      Out << "Invalid"; break;
-      
+      os << "Invalid";
+      break;      
     case NonLocKind:
-      cast<NonLoc>(this)->print(Out); break;
-      
+      cast<NonLoc>(this)->dumpToStream(os);
+      break;      
     case LocKind:
-      cast<Loc>(this)->print(Out); break;
-      
+      cast<Loc>(this)->dumpToStream(os);
+      break;      
     case UndefinedKind:
-      Out << "Undefined"; break;
-      
+      os << "Undefined";
+      break;      
     default:
       assert (false && "Invalid SVal.");
   }
 }
 
-void NonLoc::print(llvm::raw_ostream& Out) const {
-
+void NonLoc::dumpToStream(llvm::raw_ostream& os) const {
   switch (getSubKind()) {  
-
     case nonloc::ConcreteIntKind:
-      Out << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
-
+      os << cast<nonloc::ConcreteInt>(this)->getValue().getZExtValue();
       if (cast<nonloc::ConcreteInt>(this)->getValue().isUnsigned())
-        Out << 'U';
-      
-      break;
-      
+        os << 'U';      
+      break;      
     case nonloc::SymbolValKind:
-      Out << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
-      break;
-     
+      os << '$' << cast<nonloc::SymbolVal>(this)->getSymbol();
+      break;     
     case nonloc::SymExprValKind: {
       const nonloc::SymExprVal& C = *cast<nonloc::SymExprVal>(this);
       const SymExpr *SE = C.getSymbolicExpression();
-      Out << SE;
+      os << SE;
       break;
-    }
-    
+    }    
     case nonloc::LocAsIntegerKind: {
       const nonloc::LocAsInteger& C = *cast<nonloc::LocAsInteger>(this);
-      C.getLoc().print(Out);
-      Out << " [as " << C.getNumBits() << " bit integer]";
+      os << C.getLoc() << " [as " << C.getNumBits() << " bit integer]";
       break;
     }
-      
     case nonloc::CompoundValKind: {
       const nonloc::CompoundVal& C = *cast<nonloc::CompoundVal>(this);
-      Out << " {";
+      os << " {";
       bool first = true;
       for (nonloc::CompoundVal::iterator I=C.begin(), E=C.end(); I!=E; ++I) {
-        if (first) { Out << ' '; first = false; }
-        else Out << ", ";
-        (*I).print(Out);
+        if (first) { 
+          os << ' '; first = false;
+        }
+        else
+          os << ", ";
+
+        (*I).dumpToStream(os);
       }
-      Out << " }";
+      os << " }";
       break;
-    }
-      
+    }      
     default:
       assert (false && "Pretty-printed not implemented for this NonLoc.");
       break;
   }
 }
 
-void Loc::print(llvm::raw_ostream& Out) const {
-  
+void Loc::dumpToStream(llvm::raw_ostream& os) const {  
   switch (getSubKind()) {        
-
     case loc::ConcreteIntKind:
-      Out << cast<loc::ConcreteInt>(this)->getValue().getZExtValue()
-          << " (Loc)";
-      break;
-      
+      os << cast<loc::ConcreteInt>(this)->getValue().getZExtValue() << " (Loc)";
+      break;      
     case loc::GotoLabelKind:
-      Out << "&&"
-          << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
+      os << "&&" << cast<loc::GotoLabel>(this)->getLabel()->getID()->getName();
       break;
-
     case loc::MemRegionKind:
-      Out << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
-      break;
-      
+      os << '&' << cast<loc::MemRegionVal>(this)->getRegion()->getString();
+      break;      
     default:
-      assert (false && "Pretty-printing not implemented for this Loc.");
+      assert(false && "Pretty-printing not implemented for this Loc.");
       break;
   }
 }





More information about the cfe-commits mailing list