diff options
-rw-r--r-- | include/clang/Analysis/PathSensitive/MemRegion.h | 28 | ||||
-rw-r--r-- | include/clang/Analysis/PathSensitive/SymbolManager.h | 23 | ||||
-rw-r--r-- | lib/Analysis/MemRegion.cpp | 37 | ||||
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 2 | ||||
-rw-r--r-- | lib/Analysis/SymbolManager.cpp | 43 |
5 files changed, 66 insertions, 67 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h index 310d194eff..cc7c44c06a 100644 --- a/include/clang/Analysis/PathSensitive/MemRegion.h +++ b/include/clang/Analysis/PathSensitive/MemRegion.h @@ -82,9 +82,9 @@ public: bool hasHeapOrStackStorage() const; - virtual void print(llvm::raw_ostream& os) const; + virtual void dumpToStream(llvm::raw_ostream& os) const; - void printStdErr() const; + void dump() const; Kind getKind() const { return kind; } @@ -163,7 +163,7 @@ public: static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex, unsigned Cnt, const MemRegion *superRegion); - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; static bool classof(const MemRegion* R) { return R->getKind() == AllocaRegionKind; @@ -259,7 +259,7 @@ public: bool isBoundable() const { return false; } - virtual void print(llvm::raw_ostream& os) const; + virtual void dumpToStream(llvm::raw_ostream& os) const; void Profile(llvm::FoldingSetNodeID& ID) const; @@ -296,7 +296,7 @@ public: SymbolRef sym, const MemRegion* superRegion); - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; static bool classof(const MemRegion* R) { return R->getKind() == SymbolicRegionKind; @@ -330,7 +330,7 @@ public: ProfileRegion(ID, Str, superRegion); } - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; static bool classof(const MemRegion* R) { return R->getKind() == StringRegionKind; @@ -349,7 +349,7 @@ class TypedViewRegion : public TypedRegion { public: - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; QualType getLocationType(ASTContext&) const { return LValueType; @@ -400,7 +400,7 @@ public: void Profile(llvm::FoldingSetNodeID& ID) const; - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; const CompoundLiteralExpr* getLiteralExpr() const { return CL; } @@ -448,7 +448,7 @@ public: return C.getCanonicalType(getDecl()->getType()); } - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; static bool classof(const MemRegion* R) { return R->getKind() == VarRegionKind; @@ -463,7 +463,7 @@ class FieldRegion : public DeclRegion { public: - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; const FieldDecl* getDecl() const { return cast<FieldDecl>(D); } @@ -559,7 +559,7 @@ public: return ElementType; } - void print(llvm::raw_ostream& os) const; + void dumpToStream(llvm::raw_ostream& os) const; void Profile(llvm::FoldingSetNodeID& ID) const; @@ -840,10 +840,10 @@ template<> struct MemRegionManagerTrait<CodeTextRegion> { //===----------------------------------------------------------------------===// namespace llvm { -static inline raw_ostream& operator<<(raw_ostream& O, +static inline raw_ostream& operator<<(raw_ostream& os, const clang::MemRegion* R) { - R->print(O); - return O; + R->dumpToStream(os); + return os; } } // end llvm namespace diff --git a/include/clang/Analysis/PathSensitive/SymbolManager.h b/include/clang/Analysis/PathSensitive/SymbolManager.h index f32a7e3481..5aff90bc1b 100644 --- a/include/clang/Analysis/PathSensitive/SymbolManager.h +++ b/include/clang/Analysis/PathSensitive/SymbolManager.h @@ -50,6 +50,10 @@ public: virtual ~SymExpr() {} Kind getKind() const { return K; } + + void dump() const; + + virtual void dumpToStream(llvm::raw_ostream &os) const = 0; virtual QualType getType(ASTContext&) const = 0; virtual void Profile(llvm::FoldingSetNodeID& profile) = 0; @@ -71,7 +75,7 @@ public: virtual ~SymbolData() {} SymbolID getSymbolID() const { return Sym; } - + // Implement isa<T> support. static inline bool classof(const SymExpr* SE) { Kind k = SE->getKind(); @@ -104,6 +108,8 @@ public: Profile(profile, R, T); } + void dumpToStream(llvm::raw_ostream &os) const; + QualType getType(ASTContext&) const; // Implement isa<T> support. @@ -130,6 +136,8 @@ public: QualType getType(ASTContext&) const; + void dumpToStream(llvm::raw_ostream &os) const; + static void Profile(llvm::FoldingSetNodeID& profile, const Stmt* S, QualType T, unsigned Count, const void* SymbolTag) { profile.AddInteger((unsigned) ConjuredKind); @@ -166,6 +174,8 @@ public: QualType getType(ASTContext& C) const { return T; } BinaryOperator::Opcode getOpcode() const { return Op; } + + void dumpToStream(llvm::raw_ostream &os) const; const SymExpr *getLHS() const { return LHS; } const llvm::APSInt &getRHS() const { return RHS; } @@ -208,7 +218,9 @@ public: // FIXME: We probably need to make this out-of-line to avoid redundant // generation of virtual functions. QualType getType(ASTContext& C) const { return T; } - + + void dumpToStream(llvm::raw_ostream &os) const; + static void Profile(llvm::FoldingSetNodeID& ID, const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t) { ID.AddInteger((unsigned) SymSymKind); @@ -325,7 +337,10 @@ public: } // end clang namespace namespace llvm { - llvm::raw_ostream& operator<<(llvm::raw_ostream& Out, - const clang::SymExpr *SE); +static inline llvm::raw_ostream& operator<<(llvm::raw_ostream& os, + const clang::SymExpr *SE) { + SE->dumpToStream(os); + return os; } +} // end llvm namespace #endif diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index 0dac76be11..ec0608bc98 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -143,26 +143,26 @@ void CodeTextRegion::Profile(llvm::FoldingSetNodeID& ID) const { // Region pretty-printing. //===----------------------------------------------------------------------===// -void MemRegion::printStdErr() const { - print(llvm::errs()); +void MemRegion::dump() const { + dumpToStream(llvm::errs()); } std::string MemRegion::getString() const { std::string s; llvm::raw_string_ostream os(s); - print(os); + dumpToStream(os); return os.str(); } -void MemRegion::print(llvm::raw_ostream& os) const { +void MemRegion::dumpToStream(llvm::raw_ostream& os) const { os << "<Unknown Region>"; } -void AllocaRegion::print(llvm::raw_ostream& os) const { +void AllocaRegion::dumpToStream(llvm::raw_ostream& os) const { os << "alloca{" << (void*) Ex << ',' << Cnt << '}'; } -void CodeTextRegion::print(llvm::raw_ostream& os) const { +void CodeTextRegion::dumpToStream(llvm::raw_ostream& os) const { os << "code{"; if (isDeclared()) os << getDecl()->getDeclName().getAsString(); @@ -172,37 +172,34 @@ void CodeTextRegion::print(llvm::raw_ostream& os) const { os << '}'; } -void CompoundLiteralRegion::print(llvm::raw_ostream& os) const { +void CompoundLiteralRegion::dumpToStream(llvm::raw_ostream& os) const { // FIXME: More elaborate pretty-printing. os << "{ " << (void*) CL << " }"; } -void ElementRegion::print(llvm::raw_ostream& os) const { - superRegion->print(os); - os << '['; Index.print(os); os << ']'; +void ElementRegion::dumpToStream(llvm::raw_ostream& os) const { + os << superRegion << '['; Index.print(os); os << ']'; } -void FieldRegion::print(llvm::raw_ostream& os) const { - superRegion->print(os); - os << "->" << getDecl()->getNameAsString(); +void FieldRegion::dumpToStream(llvm::raw_ostream& os) const { + os << superRegion << "->" << getDecl()->getNameAsString(); } -void StringRegion::print(llvm::raw_ostream& os) const { +void StringRegion::dumpToStream(llvm::raw_ostream& os) const { LangOptions LO; // FIXME. Str->printPretty(os, 0, PrintingPolicy(LO)); } -void SymbolicRegion::print(llvm::raw_ostream& os) const { +void SymbolicRegion::dumpToStream(llvm::raw_ostream& os) const { os << "SymRegion-" << sym; } -void TypedViewRegion::print(llvm::raw_ostream& os) const { - os << "typed_view{" << LValueType.getAsString() << ','; - getSuperRegion()->print(os); - os << '}'; +void TypedViewRegion::dumpToStream(llvm::raw_ostream& os) const { + os << "typed_view{" << LValueType.getAsString() << ',' + << getSuperRegion() << '}'; } -void VarRegion::print(llvm::raw_ostream& os) const { +void VarRegion::dumpToStream(llvm::raw_ostream& os) const { os << cast<VarDecl>(D)->getNameAsString(); } diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 00a086d374..2999225a43 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -1439,7 +1439,7 @@ void RegionStoreManager::print(Store store, llvm::raw_ostream& OS, OS << "Store:" << nl; for (RegionBindingsTy::iterator I = B.begin(), E = B.end(); I != E; ++I) { - OS << ' '; I.getKey()->print(OS); OS << " : "; + OS << ' ' << I.getKey() << " : "; I.getData().print(OS); OS << nl; } } diff --git a/lib/Analysis/SymbolManager.cpp b/lib/Analysis/SymbolManager.cpp index 275f30a296..e59d0bd437 100644 --- a/lib/Analysis/SymbolManager.cpp +++ b/lib/Analysis/SymbolManager.cpp @@ -18,7 +18,9 @@ using namespace clang; -static void print(llvm::raw_ostream& os, const SymExpr *SE); +void SymExpr::dump() const { + dumpToStream(llvm::errs()); +} static void print(llvm::raw_ostream& os, BinaryOperator::Opcode Op) { switch (Op) { @@ -44,45 +46,30 @@ static void print(llvm::raw_ostream& os, BinaryOperator::Opcode Op) { } } -static void print(llvm::raw_ostream& os, const SymIntExpr *SE) { +void SymIntExpr::dumpToStream(llvm::raw_ostream& os) const { os << '('; - print(os, SE->getLHS()); + getLHS()->dumpToStream(os); os << ") "; - print(os, SE->getOpcode()); - os << ' ' << SE->getRHS().getZExtValue(); - if (SE->getRHS().isUnsigned()) os << 'U'; + print(os, getOpcode()); + os << ' ' << getRHS().getZExtValue(); + if (getRHS().isUnsigned()) os << 'U'; } -static void print(llvm::raw_ostream& os, const SymSymExpr *SE) { +void SymSymExpr::dumpToStream(llvm::raw_ostream& os) const { os << '('; - print(os, SE->getLHS()); + getLHS()->dumpToStream(os); os << ") "; os << '('; - print(os, SE->getRHS()); + getRHS()->dumpToStream(os); os << ')'; } -static void print(llvm::raw_ostream& os, const SymExpr *SE) { - switch (SE->getKind()) { - case SymExpr::BEGIN_SYMBOLS: - case SymExpr::RegionValueKind: - case SymExpr::ConjuredKind: - case SymExpr::END_SYMBOLS: - os << '$' << cast<SymbolData>(SE)->getSymbolID(); - return; - case SymExpr::SymIntKind: - print(os, cast<SymIntExpr>(SE)); - return; - case SymExpr::SymSymKind: - print(os, cast<SymSymExpr>(SE)); - return; - } +void SymbolConjured::dumpToStream(llvm::raw_ostream& os) const { + os << "conj_$" << getSymbolID(); } - -llvm::raw_ostream& llvm::operator<<(llvm::raw_ostream& os, const SymExpr *SE) { - print(os, SE); - return os; +void SymbolRegionValue::dumpToStream(llvm::raw_ostream& os) const { + os << "reg_$" << getSymbolID() << "<" << R << ">"; } const SymbolRegionValue* |