From: Ted Kremenek Date: Mon, 13 Jul 2009 23:53:06 +0000 (+0000) Subject: Tidy pretty-printing for SVals, using 'dump()' instead of 'printStdErr()', and implem... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f9b3a4d7143362d3c2ac1f843d76971799f5b97;p=clang Tidy pretty-printing for SVals, using 'dump()' instead of 'printStdErr()', and implementing operator<< support for llvm::raw_ostream. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75560 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/SVals.h b/include/clang/Analysis/PathSensitive/SVals.h index dd7c93639f..0a42548200 100644 --- a/include/clang/Analysis/PathSensitive/SVals.h +++ b/include/clang/Analysis/PathSensitive/SVals.h @@ -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 @@ public: 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 @@ protected: 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 support. static inline bool classof(const SVal* V) { @@ -185,7 +189,7 @@ protected: : SVal(const_cast(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 @@ public: } // 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 diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index ba1ccf1f90..f1f051f244 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -611,8 +611,7 @@ void BasicStoreManager::print(Store store, llvm::raw_ostream& Out, else Out << nl; - Out << ' ' << I.getKey() << " : "; - I.getData().print(Out); + Out << ' ' << I.getKey() << " : " << I.getData(); } } diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp index 54c0afbff3..b849bea0b5 100644 --- a/lib/Analysis/GRState.cpp +++ b/lib/Analysis/GRState.cpp @@ -168,8 +168,7 @@ void GRState::print(llvm::raw_ostream& Out, const char* nl, 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 @@ void GRState::print(llvm::raw_ostream& Out, const char* nl, 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); diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index 8a40e4ae52..6a531b9917 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -178,7 +178,7 @@ void CompoundLiteralRegion::dumpToStream(llvm::raw_ostream& os) const { } 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 { diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 2999225a43..c59d935c3d 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -1438,8 +1438,6 @@ void RegionStoreManager::print(Store store, llvm::raw_ostream& OS, 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; } diff --git a/lib/Analysis/SVals.cpp b/lib/Analysis/SVals.cpp index d711ce0a22..e5657ff6b6 100644 --- a/lib/Analysis/SVals.cpp +++ b/lib/Analysis/SVals.cpp @@ -239,98 +239,83 @@ SVal loc::ConcreteInt::EvalBinOp(BasicValueFactory& BasicVals, // 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(this)->print(Out); break; - + cast(this)->dumpToStream(os); + break; case LocKind: - cast(this)->print(Out); break; - + cast(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(this)->getValue().getZExtValue(); - + os << cast(this)->getValue().getZExtValue(); if (cast(this)->getValue().isUnsigned()) - Out << 'U'; - - break; - + os << 'U'; + break; case nonloc::SymbolValKind: - Out << '$' << cast(this)->getSymbol(); - break; - + os << '$' << cast(this)->getSymbol(); + break; case nonloc::SymExprValKind: { const nonloc::SymExprVal& C = *cast(this); const SymExpr *SE = C.getSymbolicExpression(); - Out << SE; + os << SE; break; - } - + } case nonloc::LocAsIntegerKind: { const nonloc::LocAsInteger& C = *cast(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(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(this)->getValue().getZExtValue() - << " (Loc)"; - break; - + os << cast(this)->getValue().getZExtValue() << " (Loc)"; + break; case loc::GotoLabelKind: - Out << "&&" - << cast(this)->getLabel()->getID()->getName(); + os << "&&" << cast(this)->getLabel()->getID()->getName(); break; - case loc::MemRegionKind: - Out << '&' << cast(this)->getRegion()->getString(); - break; - + os << '&' << cast(this)->getRegion()->getString(); + break; default: - assert (false && "Pretty-printing not implemented for this Loc."); + assert(false && "Pretty-printing not implemented for this Loc."); break; } }