From 930191c0110668d91aeebd5a7ac50f0569954a58 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 23 Jan 2008 22:30:44 +0000 Subject: [PATCH] some prettying of the GraphViz visualization of GRConstants analysis results. llvm-svn: 46284 --- clang/Analysis/GRConstants.cpp | 67 +++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/clang/Analysis/GRConstants.cpp b/clang/Analysis/GRConstants.cpp index 8bd58facf2f8..4cfad27adb16 100644 --- a/clang/Analysis/GRConstants.cpp +++ b/clang/Analysis/GRConstants.cpp @@ -341,13 +341,16 @@ void ExprValue::print(std::ostream& Out) const { Out << "Invalid"; break; case RValueMayEqualSetKind: { - Out << "MayEqual{"; APSIntSetTy S = cast(this)->GetValues(); + bool first = true; - for (APSIntSetTy::iterator I=S.begin(), E=S.end(); I!=E; ++I) - Out << ' ' << (*I).toString(); - - Out << " }"; + for (APSIntSetTy::iterator I=S.begin(), E=S.end(); I!=E; ++I) { + if (first) first = false; + else Out << " | "; + + Out << (*I).toString(); + } + break; } @@ -720,10 +723,24 @@ template<> struct VISIBILITY_HIDDEN DOTGraphTraits : public DefaultDOTGraphTraits { + + static std::string getNodeAttributes(void*, void*) { + return "fontname=\"monaco,fixed\", fontsize=\"11\""; + } + + static void PrintKind(std::ostringstream& Out, ValueKey::Kind kind) { + switch (kind) { + case ValueKey::IsSubExp: Out << "Sub-Expressions:\\l"; break; + case ValueKey::IsDecl: Out << "Variables:\\l"; break; + case ValueKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break; + default: assert (false && "Unknown ValueKey type."); + } + } + static std::string getNodeLabel(const GRConstants::NodeTy* N, void*) { std::ostringstream Out; - - Out << "Vertex: " << (void*) N << '\n'; + + // Program Location. ProgramPoint Loc = N->getLocation(); switch (Loc.getKind()) { @@ -738,7 +755,7 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : case ProgramPoint::PostStmtKind: { const PostStmt& L = cast(Loc); - Out << "Stmt: " << (void*) L.getStmt() << '\n'; + Out << "(" << (void*) L.getStmt() << ") "; L.getStmt()->printPretty(Out); break; } @@ -750,31 +767,47 @@ struct VISIBILITY_HIDDEN DOTGraphTraits : } } - Out << "\n{"; + Out << "\\|"; GRConstants::StateTy M = N->getState(); bool isFirst = true; + ValueKey::Kind kind; for (GRConstants::StateTy::iterator I=M.begin(), E=M.end(); I!=E; ++I) { - if (!isFirst) - Out << '\n'; - else + if (!isFirst) { + ValueKey::Kind newKind = I.getKey().getKind(); + + if (newKind != kind) { + Out << "\\l\\l"; + PrintKind(Out, newKind); + } + else + Out << "\\l"; + + kind = newKind; + } + else { + kind = I.getKey().getKind(); + PrintKind(Out, kind); isFirst = false; + } + + Out << ' '; if (ValueDecl* V = dyn_cast(I.getKey())) { - Out << "Decl: " << (void*) V << ", " << V->getName(); + Out << V->getName(); } else { Stmt* E = cast(I.getKey()); - Out << "Stmt: " << (void*) E; + Out << " (" << (void*) E << ") "; + E->printPretty(Out); } - Out << " => "; + Out << " : "; I.getData().print(Out); } - Out << " }"; - + Out << "\\l"; return Out.str(); } };