diff options
author | Csaba Dabis <dabis.csaba98@gmail.com> | 2019-05-29 18:05:53 +0000 |
---|---|---|
committer | Csaba Dabis <dabis.csaba98@gmail.com> | 2019-05-29 18:05:53 +0000 |
commit | 13e491cca51ed187f52ee2e86e2b09ae19017bab (patch) | |
tree | 49a26fbad5e275d06b90d70d0075e1a159bdb577 /clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | |
parent | f6faa382f3e0eae41e8e82848e4eafe08ea1ccb5 (diff) | |
download | bcm5719-llvm-13e491cca51ed187f52ee2e86e2b09ae19017bab.tar.gz bcm5719-llvm-13e491cca51ed187f52ee2e86e2b09ae19017bab.zip |
[analyzer] print() JSONify: getNodeLabel implementation
Summary: This patch also rewrites the ProgramPoint printing.
Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus
Reviewed By: NoQ
Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
donat.nagy, dkrupp
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62346
llvm-svn: 361997
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ExprEngine.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 6fa7cf2e232..e87b6535c1e 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -162,12 +162,12 @@ public: << "\", \"argument_index\": "; if (getItem().getKind() == ConstructionContextItem::ArgumentKind) - Out << getItem().getIndex() << '\"'; + Out << getItem().getIndex(); else Out << "null"; // Pretty-print - Out << ", \"pretty\": \""; + Out << ", \"pretty\": "; if (S) { llvm::SmallString<256> TempBuf; @@ -176,13 +176,13 @@ public: // See whether the current statement is pretty-printable. S->printPretty(TempOut, Helper, PP); if (!TempBuf.empty()) { - Out << TempBuf.str().trim() << '\"'; + Out << '\"' << TempBuf.str().trim() << '\"'; TempBuf.clear(); } else { Out << "null"; } } else { - Out << I->getAnyMember()->getNameAsString() << '\"'; + Out << '\"' << I->getAnyMember()->getNameAsString() << '\"'; } } @@ -3079,37 +3079,55 @@ struct DOTGraphTraits<ExplodedGraph*> : public DefaultDOTGraphTraits { } static std::string getNodeLabel(const ExplodedNode *N, ExplodedGraph *G){ - std::string sbuf; - llvm::raw_string_ostream Out(sbuf); + std::string Buf; + llvm::raw_string_ostream Out(Buf); + const bool IsDot = true; + const unsigned int Space = 1; ProgramStateRef State = N->getState(); + Out << "{ \"node_id\": \"" << (const void *)N + << "\", \"state_id\": " << State->getID() + << ", \"has_report\": " << (nodeHasBugReport(N) ? "true" : "false") + << ",\\l"; + + Indent(Out, Space, IsDot) << "\"program_points\": [\\l"; + // Dump program point for all the previously skipped nodes. traverseHiddenNodes( N, [&](const ExplodedNode *OtherNode) { - OtherNode->getLocation().print(/*CR=*/"\\l", Out); + Indent(Out, Space + 1, IsDot) << "{ "; + OtherNode->getLocation().printJson(Out, /*NL=*/"\\l"); + Out << ", \"tag\": "; if (const ProgramPointTag *Tag = OtherNode->getLocation().getTag()) - Out << "\\lTag:" << Tag->getTagDescription(); - if (N->isSink()) - Out << "\\lNode is sink\\l"; - if (nodeHasBugReport(N)) - Out << "\\lBug report attached\\l"; + Out << '\"' << Tag->getTagDescription() << "\" }"; + else + Out << "null }"; }, - [&](const ExplodedNode *) { Out << "\\l--------\\l"; }, + // Adds a comma and a new-line between each program point. + [&](const ExplodedNode *) { Out << ",\\l"; }, [&](const ExplodedNode *) { return false; }); - Out << "\\l\\|"; - - Out << "StateID: ST" << State->getID() << ", NodeID: N" << N->getID(G) - << " <" << (const void *)N << ">\\|"; + Out << "\\l"; // Adds a new-line to the last program point. + Indent(Out, Space, IsDot) << "],\\l"; bool SameAsAllPredecessors = std::all_of(N->pred_begin(), N->pred_end(), [&](const ExplodedNode *P) { return P->getState() == State; }); - if (!SameAsAllPredecessors) - State->printDOT(Out, N->getLocationContext()); + + if (!SameAsAllPredecessors) { + State->printDOT(Out, N->getLocationContext(), Space); + } else { + Indent(Out, Space, IsDot) << "\"program_state\": null"; + } + + Out << "\\l}"; + if (!N->succ_empty()) + Out << ','; + Out << "\\l"; + return Out.str(); } }; |