[cfe-commits] r42150 - in /cfe/trunk/include/clang/AST: Stmt.h StmtGraphTraits.h

Ted Kremenek kremenek at apple.com
Wed Sep 19 14:21:39 PDT 2007


Author: kremenek
Date: Wed Sep 19 16:21:39 2007
New Revision: 42150

URL: http://llvm.org/viewvc/llvm-project?rev=42150&view=rev
Log:
Moved GraphTraits<Stmt*> to StmtGraphTraits.h.  This allows consumers of Stmt.h not to have to pay the cost
of parsing the GraphTraits templates if they don't need that functionality.

Defined nodes_iterator for GraphTraits<Stmt*> to be based on llvm::df_iterator.

Added:
    cfe/trunk/include/clang/AST/StmtGraphTraits.h
Modified:
    cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=42150&r1=42149&r2=42150&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Sep 19 16:21:39 2007
@@ -17,7 +17,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator"
-#include "llvm/ADT/GraphTraits.h"
 #include <iosfwd>
 
 namespace clang {
@@ -79,6 +78,10 @@
   void dumpPretty() const;
   void printPretty(std::ostream &OS, PrinterHelper* = NULL) const;
   
+  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
+  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
+  void viewAST() const;
+  
   // Implement isa<T> support.
   static bool classof(const Stmt *) { return true; }  
   
@@ -635,41 +638,4 @@
 
 }  // end namespace clang
 
-//===----------------------------------------------------------------------===//
-// GraphTraits specialization to treat ASTs (Stmt*) as graphs
-//===----------------------------------------------------------------------===//
-
-namespace llvm {
-
-template <> struct GraphTraits<clang::Stmt*> {
-  typedef clang::Stmt                  NodeType;
-  typedef clang::Stmt::child_iterator  ChildIteratorType;
-  
-  static NodeType* getEntryNode(clang::Stmt* S) { return S; }
-
-  static inline ChildIteratorType child_begin(NodeType* N) {
-    return N->child_begin();
-  }
-  
-  static inline ChildIteratorType child_end(NodeType* N) {
-    return N->child_end();
-  }
-};
-
-template <> struct GraphTraits<const clang::Stmt*> {
-  typedef const clang::Stmt                  NodeType;
-  typedef clang::Stmt::const_child_iterator  ChildIteratorType;
-  
-  static NodeType* getEntryNode(const clang::Stmt* S) { return S; }
-  
-  static inline ChildIteratorType child_begin(NodeType* N) {
-    return N->child_begin();
-  }
-  
-  static inline ChildIteratorType child_end(NodeType* N) {
-    return N->child_end();
-  }
-};
-
-} // end namespace llvm
 #endif

Added: cfe/trunk/include/clang/AST/StmtGraphTraits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtGraphTraits.h?rev=42150&view=auto

==============================================================================
--- cfe/trunk/include/clang/AST/StmtGraphTraits.h (added)
+++ cfe/trunk/include/clang/AST/StmtGraphTraits.h Wed Sep 19 16:21:39 2007
@@ -0,0 +1,83 @@
+//===--- StmtGraphTraits.h - Graph Traits for the class Stmt ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Ted Kremenek and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines a template specialization of llvm::GraphTraits to 
+//  treat ASTs (Stmt*) as graphs
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_STMT_GRAPHTRAITS_H
+#define LLVM_CLANG_AST_STMT_GRAPHTRAITS_H
+
+#include "clang/AST/Stmt.h"
+#include "llvm/ADT/GraphTraits.h"
+#include "llvm/ADT/DepthFirstIterator.h"
+
+namespace llvm {
+  
+//template <typename T> struct GraphTraits;
+
+
+template <> struct GraphTraits<clang::Stmt*> {
+  typedef clang::Stmt                       NodeType;
+  typedef clang::Stmt::child_iterator       ChildIteratorType;
+  typedef llvm::df_iterator<clang::Stmt*>   nodes_iterator;
+    
+  static NodeType* getEntryNode(clang::Stmt* S) { return S; }
+  
+  static inline ChildIteratorType child_begin(NodeType* N) {
+    if (N) return N->child_begin();
+    else return NULL;
+  }
+  
+  static inline ChildIteratorType child_end(NodeType* N) {
+    if (N) return N->child_end();
+    else return NULL;
+  }
+  
+  static nodes_iterator nodes_begin(clang::Stmt* S) {
+    return df_begin(S);
+  }
+  
+  static nodes_iterator nodes_end(clang::Stmt* S) {
+    return df_end(S);
+  }
+};
+
+
+template <> struct GraphTraits<const clang::Stmt*> {
+  typedef const clang::Stmt                       NodeType;
+  typedef clang::Stmt::const_child_iterator       ChildIteratorType;
+  typedef llvm::df_iterator<const clang::Stmt*>   nodes_iterator;
+  
+  static NodeType* getEntryNode(const clang::Stmt* S) { return S; }
+  
+  static inline ChildIteratorType child_begin(NodeType* N) {
+    if (N) return N->child_begin();
+    else return NULL;    
+  }
+  
+  static inline ChildIteratorType child_end(NodeType* N) {
+    if (N) return N->child_end();
+    else return NULL;
+  }
+  
+  static nodes_iterator nodes_begin(const clang::Stmt* S) {
+    return df_begin(S);
+  }
+  
+  static nodes_iterator nodes_end(const clang::Stmt* S) {
+    return df_end(S);
+  }
+};
+
+  
+} // end namespace llvm
+
+#endif





More information about the cfe-commits mailing list