From ae6814efb6c41bd0c0f6413d25097105284d5be7 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 13 Aug 2008 21:24:49 +0000 Subject: [PATCH] Renamed GRState::CheckerStatePrinter to GRState::Printer. Updated checker state printer interface to allow transfer functions to return an arbitrary number of GRState::Printers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54762 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/Analysis/PathSensitive/GRState.h | 17 ++++++------- .../Analysis/PathSensitive/GRTransferFuncs.h | 6 ++--- lib/Analysis/CFRefCount.cpp | 24 ++++++++++-------- lib/Analysis/GRExprEngine.cpp | 25 ++++++++++++++----- lib/Analysis/GRState.cpp | 21 ++++++++-------- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/include/clang/Analysis/PathSensitive/GRState.h b/include/clang/Analysis/PathSensitive/GRState.h index 7605cb6f2c..d8609a8ddf 100644 --- a/include/clang/Analysis/PathSensitive/GRState.h +++ b/include/clang/Analysis/PathSensitive/GRState.h @@ -171,19 +171,18 @@ public: ce_iterator ce_begin() const { return ConstEq.begin(); } ce_iterator ce_end() const { return ConstEq.end(); } - class CheckerStatePrinter { + class Printer { public: - virtual ~CheckerStatePrinter() {} - virtual void PrintCheckerState(std::ostream& Out, void* State, - const char* nl, const char* sep) = 0; + virtual ~Printer() {} + virtual void Print(std::ostream& Out, const GRState* state, + const char* nl, const char* sep) = 0; }; - void print(std::ostream& Out, CheckerStatePrinter* P = NULL, - const char* nl = "\n", const char* sep = "") const; + void print(std::ostream& Out, Printer **Beg = 0, Printer **End = 0, + const char* nl = "\n", const char *sep = "") const; - void printStdErr(CheckerStatePrinter* P = NULL) const; - - void printDOT(std::ostream& Out, CheckerStatePrinter*P = NULL) const; + void printStdErr(Printer **Beg = 0, Printer **End = 0) const; + void printDOT(std::ostream& Out, Printer **Beg = 0, Printer **End = 0) const; }; template<> struct GRTrait { diff --git a/include/clang/Analysis/PathSensitive/GRTransferFuncs.h b/include/clang/Analysis/PathSensitive/GRTransferFuncs.h index dedb521a3f..86b52cb949 100644 --- a/include/clang/Analysis/PathSensitive/GRTransferFuncs.h +++ b/include/clang/Analysis/PathSensitive/GRTransferFuncs.h @@ -18,6 +18,7 @@ #include "clang/Analysis/PathSensitive/RValues.h" #include "clang/Analysis/PathSensitive/GRCoreEngine.h" #include "clang/Analysis/PathSensitive/GRState.h" +#include namespace clang { @@ -42,10 +43,7 @@ public: GRTransferFuncs() {} virtual ~GRTransferFuncs() {} - virtual GRState::CheckerStatePrinter* getCheckerStatePrinter() { - return NULL; - } - + virtual void getStatePrinters(std::vector& Printers) {} virtual void RegisterChecks(GRExprEngine& Eng); // Casts. diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 2d69d9bb3d..256072ab3a 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -1211,10 +1211,10 @@ public: typedef llvm::DenseMap*> LeaksTy; - class BindingsPrinter : public GRState::CheckerStatePrinter { + class BindingsPrinter : public GRState::Printer { public: - virtual void PrintCheckerState(std::ostream& Out, void* State, - const char* nl, const char* sep); + virtual void Print(std::ostream& Out, const GRState* state, + const char* nl, const char* sep); }; private: @@ -1231,6 +1231,10 @@ public: static RefBindings GetRefBindings(const GRState& StImpl) { return RefBindings((const RefBindings::TreeTy*) StImpl.CheckerState); } + + static RefBindings GetRefBindings(const GRState* state) { + return RefBindings((const RefBindings::TreeTy*) state->CheckerState); + } private: @@ -1272,8 +1276,8 @@ public: virtual void RegisterChecks(GRExprEngine& Eng); - virtual GRState::CheckerStatePrinter* getCheckerStatePrinter() { - return &Printer; + virtual void getStatePrinters(std::vector& Printers) { + Printers.push_back(&Printer); } bool isGCEnabled() const { return Summaries.isGCEnabled(); } @@ -1363,12 +1367,12 @@ public: -void CFRefCount::BindingsPrinter::PrintCheckerState(std::ostream& Out, - void* State, const char* nl, - const char* sep) { - RefBindings B((RefBindings::TreeTy*) State); +void CFRefCount::BindingsPrinter::Print(std::ostream& Out, const GRState* state, + const char* nl, const char* sep) { + + RefBindings B = GetRefBindings(state); - if (State) + if (!B.isEmpty()) Out << sep << nl; for (RefBindings::iterator I=B.begin(), E=B.end(); I!=E; ++I) { diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 43f5ef2185..cb423e18af 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -2257,7 +2257,7 @@ void GRExprEngine::EvalBinOp(GRStateSet& OStates, const GRState* St, #ifndef NDEBUG static GRExprEngine* GraphPrintCheckerState; static SourceManager* GraphPrintSourceManager; -static GRState::CheckerStatePrinter* GraphCheckerStatePrinter; +static GRState::Printer **GraphStatePrinterBeg, **GraphStatePrinterEnd; namespace llvm { template<> @@ -2500,7 +2500,7 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : Out << "\\|StateID: " << (void*) N->getState() << "\\|"; - N->getState()->printDOT(Out, GraphCheckerStatePrinter); + N->getState()->printDOT(Out, GraphStatePrinterBeg, GraphStatePrinterEnd); Out << "\\l"; return Out.str(); @@ -2565,13 +2565,20 @@ void GRExprEngine::ViewGraph(bool trim) { else { GraphPrintCheckerState = this; GraphPrintSourceManager = &getContext().getSourceManager(); - GraphCheckerStatePrinter = getTF().getCheckerStatePrinter(); + + // Get the state printers. + std::vector Printers; + getTF().getStatePrinters(Printers); + GraphStatePrinterBeg = Printers.empty() ? 0 : &Printers[0]; + GraphStatePrinterEnd = Printers.empty() ? 0 : &Printers[0]+Printers.size(); + llvm::ViewGraph(*G.roots_begin(), "GRExprEngine"); GraphPrintCheckerState = NULL; GraphPrintSourceManager = NULL; - GraphCheckerStatePrinter = NULL; + GraphStatePrinterBeg = NULL; + GraphStatePrinterEnd = NULL; } #endif } @@ -2580,7 +2587,12 @@ void GRExprEngine::ViewGraph(NodeTy** Beg, NodeTy** End) { #ifndef NDEBUG GraphPrintCheckerState = this; GraphPrintSourceManager = &getContext().getSourceManager(); - GraphCheckerStatePrinter = getTF().getCheckerStatePrinter(); + + // Get the state printers. + std::vector Printers; + getTF().getStatePrinters(Printers); + GraphStatePrinterBeg = Printers.empty() ? 0 : &Printers[0]; + GraphStatePrinterEnd = Printers.empty() ? 0 : &Printers[0]+Printers.size(); GRExprEngine::GraphTy* TrimmedG = G.Trim(Beg, End); @@ -2593,6 +2605,7 @@ void GRExprEngine::ViewGraph(NodeTy** Beg, NodeTy** End) { GraphPrintCheckerState = NULL; GraphPrintSourceManager = NULL; - GraphCheckerStatePrinter = NULL; + GraphStatePrinterBeg = NULL; + GraphStatePrinterEnd = NULL; #endif } diff --git a/lib/Analysis/GRState.cpp b/lib/Analysis/GRState.cpp index 2704bf2f37..1c7df79c02 100644 --- a/lib/Analysis/GRState.cpp +++ b/lib/Analysis/GRState.cpp @@ -202,16 +202,17 @@ const GRState* GRStateManager::getPersistentState(GRState& State) { return I; } -void GRState::printDOT(std::ostream& Out, CheckerStatePrinter* P) const { - print(Out, P, "\\l", "\\|"); +void GRState::printDOT(std::ostream& Out, + Printer** Beg, Printer** End) const { + print(Out, Beg, End, "\\l", "\\|"); } -void GRState::printStdErr(CheckerStatePrinter* P) const { - print(*llvm::cerr, P); +void GRState::printStdErr(Printer** Beg, Printer** End) const { + print(*llvm::cerr, Beg, End); } -void GRState::print(std::ostream& Out, CheckerStatePrinter* P, - const char* nl, const char* sep) const { +void GRState::print(std::ostream& Out, Printer** Beg, Printer** End, + const char* nl, const char* sep) const { // Print Variable Bindings Out << "Variables:" << nl; @@ -264,6 +265,7 @@ void GRState::print(std::ostream& Out, CheckerStatePrinter* P, } // Print equality constraints. + // FIXME: Make just another printer do this. if (!ConstEq.isEmpty()) { @@ -278,6 +280,7 @@ void GRState::print(std::ostream& Out, CheckerStatePrinter* P, } // Print != constraints. + // FIXME: Make just another printer do this. if (!ConstNotEq.isEmpty()) { @@ -300,10 +303,8 @@ void GRState::print(std::ostream& Out, CheckerStatePrinter* P, } } - // Print checker-specific data. - - if (P && CheckerState) - P->PrintCheckerState(Out, CheckerState, nl, sep); + // Print checker-specific data. + for ( ; Beg != End ; ++Beg) (*Beg)->Print(Out, this, nl, sep); } -- 2.40.0