etc/services - sync with NetBSD-8
[minix.git] / external / bsd / llvm / dist / clang / lib / AST / StmtViz.cpp
blob8be287e7cb2178b8827c7f1ca17a14b4dfa02194
1 //===--- StmtViz.cpp - Graphviz visualization for Stmt ASTs -----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements Stmt::viewAST, which generates a Graphviz DOT file
11 // that depicts the AST and then calls Graphviz/dot+gv on it.
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/StmtGraphTraits.h"
16 #include "clang/AST/Decl.h"
17 #include "llvm/Support/GraphWriter.h"
19 using namespace clang;
21 void Stmt::viewAST() const {
22 #ifndef NDEBUG
23 llvm::ViewGraph(this,"AST");
24 #else
25 llvm::errs() << "Stmt::viewAST is only available in debug builds on "
26 << "systems with Graphviz or gv!\n";
27 #endif
30 namespace llvm {
31 template<>
32 struct DOTGraphTraits<const Stmt*> : public DefaultDOTGraphTraits {
33 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
35 static std::string getNodeLabel(const Stmt* Node, const Stmt* Graph) {
37 #ifndef NDEBUG
38 std::string OutSStr;
39 llvm::raw_string_ostream Out(OutSStr);
41 if (Node)
42 Out << Node->getStmtClassName();
43 else
44 Out << "<NULL>";
46 std::string OutStr = Out.str();
47 if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
49 // Process string output to make it nicer...
50 for (unsigned i = 0; i != OutStr.length(); ++i)
51 if (OutStr[i] == '\n') { // Left justify
52 OutStr[i] = '\\';
53 OutStr.insert(OutStr.begin()+i+1, 'l');
56 return OutStr;
57 #else
58 return "";
59 #endif
62 } // end namespace llvm