| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "clang/AST/StmtGraphTraits.h" |
| 15 | #include "clang/AST/Decl.h" |
| 16 | #include "llvm/Support/GraphWriter.h" |
| 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | void Stmt::viewAST() const { |
| 21 | #ifndef NDEBUG |
| 22 | llvm::ViewGraph(this,"AST"); |
| 23 | #else |
| 24 | llvm::errs() << "Stmt::viewAST is only available in debug builds on " |
| 25 | << "systems with Graphviz or gv!\n"; |
| 26 | #endif |
| 27 | } |
| 28 | |
| 29 | namespace llvm { |
| 30 | template<> |
| 31 | struct DOTGraphTraits<const Stmt*> : public DefaultDOTGraphTraits { |
| 32 | DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} |
| 33 | |
| 34 | static std::string getNodeLabel(const Stmt* Node, const Stmt* Graph) { |
| 35 | |
| 36 | #ifndef NDEBUG |
| 37 | std::string OutSStr; |
| 38 | llvm::raw_string_ostream Out(OutSStr); |
| 39 | |
| 40 | if (Node) |
| 41 | Out << Node->getStmtClassName(); |
| 42 | else |
| 43 | Out << "<NULL>"; |
| 44 | |
| 45 | std::string OutStr = Out.str(); |
| 46 | if (OutStr[0] == '\n') OutStr.erase(OutStr.begin()); |
| 47 | |
| 48 | |
| 49 | for (unsigned i = 0; i != OutStr.length(); ++i) |
| 50 | if (OutStr[i] == '\n') { |
| 51 | OutStr[i] = '\\'; |
| 52 | OutStr.insert(OutStr.begin()+i+1, 'l'); |
| 53 | } |
| 54 | |
| 55 | return OutStr; |
| 56 | #else |
| 57 | return ""; |
| 58 | #endif |
| 59 | } |
| 60 | }; |
| 61 | } |
| 62 | |