/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/StmtViz.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- StmtViz.cpp - Graphviz visualization for Stmt ASTs -----*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements Stmt::viewAST, which generates a Graphviz DOT file |
10 | | // that depicts the AST and then calls Graphviz/dot+gv on it. |
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 | 0 | void Stmt::viewAST() const { |
21 | 0 | #ifndef NDEBUG |
22 | 0 | 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 | 0 | } |
28 | | |
29 | | namespace llvm { |
30 | | template<> |
31 | | struct DOTGraphTraits<const Stmt*> : public DefaultDOTGraphTraits { |
32 | 0 | DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} |
33 | | |
34 | 0 | static std::string getNodeLabel(const Stmt* Node, const Stmt* Graph) { |
35 | |
|
36 | 0 | #ifndef NDEBUG |
37 | 0 | std::string OutSStr; |
38 | 0 | llvm::raw_string_ostream Out(OutSStr); |
39 | |
|
40 | 0 | if (Node) |
41 | 0 | Out << Node->getStmtClassName(); |
42 | 0 | else |
43 | 0 | Out << "<NULL>"; |
44 | |
|
45 | 0 | std::string OutStr = Out.str(); |
46 | 0 | if (OutStr[0] == '\n') OutStr.erase(OutStr.begin()); |
47 | | |
48 | | // Process string output to make it nicer... |
49 | 0 | for (unsigned i = 0; i != OutStr.length(); ++i) |
50 | 0 | if (OutStr[i] == '\n') { // Left justify |
51 | 0 | OutStr[i] = '\\'; |
52 | 0 | OutStr.insert(OutStr.begin()+i+1, 'l'); |
53 | 0 | } |
54 | |
|
55 | 0 | return OutStr; |
56 | | #else |
57 | | return ""; |
58 | | #endif |
59 | 0 | } |
60 | | }; |
61 | | } // end namespace llvm |