zcov: / lib/AST/StmtViz.cpp


Files: 1 Branches Taken: 0.0% 0 / 8
Generated: 2010-02-10 01:31 Branches Executed: 0.0% 0 / 8
Line Coverage: 0.0% 0 / 17


Programs: 1 Runs 2897


       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.
      12                 : //
      13                 : //===----------------------------------------------------------------------===//
      14                 : 
      15                 : #include "clang/AST/StmtGraphTraits.h"
      16                 : #include "clang/AST/Decl.h"
      17                 : #include "llvm/Support/GraphWriter.h"
      18                 : 
      19                 : using namespace clang;
      20                 : 
      21                0: void Stmt::viewAST() const {
      22                 : #ifndef NDEBUG
      23                0:   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
      28                0: }
      29                 : 
      30                 : namespace llvm {
      31                 : template<>
      32                 : struct DOTGraphTraits<const Stmt*> : public DefaultDOTGraphTraits {
      33                0:   DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
      34                 : 
      35                0:   static std::string getNodeLabel(const Stmt* Node, const Stmt* Graph) {
      36                 : 
      37                 : #ifndef NDEBUG
      38                0:     std::string OutSStr;
      39                0:     llvm::raw_string_ostream Out(OutSStr);
      40                 : 
                        0: branch 0 not taken
                        0: branch 1 not taken
      41                0:     if (Node)
      42                0:       Out << Node->getStmtClassName();
      43                 :     else
      44                0:       Out << "<NULL>";
      45                 : 
      46                0:     std::string OutStr = Out.str();
                        0: branch 1 not taken
                        0: branch 2 not taken
      47                0:     if (OutStr[0] == '\n') OutStr.erase(OutStr.begin());
      48                 : 
      49                 :     // Process string output to make it nicer...
                        0: branch 1 not taken
                        0: branch 2 not taken
      50                0:     for (unsigned i = 0; i != OutStr.length(); ++i)
                        0: branch 1 not taken
                        0: branch 2 not taken
      51                0:       if (OutStr[i] == '\n') {                            // Left justify
      52                0:         OutStr[i] = '\\';
      53                0:         OutStr.insert(OutStr.begin()+i+1, 'l');
      54                 :       }
      55                 : 
      56                0:     return OutStr;
      57                 : #else
      58                 :     return "";
      59                 : #endif
      60                 :   }
      61                 : };
      62                 : } // end namespace llvm

Generated: 2010-02-10 01:31 by zcov