[cfe-commits] r42146 - /cfe/trunk/include/clang/AST/Stmt.h

Ted Kremenek kremenek at apple.com
Wed Sep 19 11:18:40 PDT 2007


Author: kremenek
Date: Wed Sep 19 13:18:40 2007
New Revision: 42146

URL: http://llvm.org/viewvc/llvm-project?rev=42146&view=rev
Log:
Added GraphTraits template specialization for Stmt* to treat ASTs like graphs.

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=42146&r1=42145&r2=42146&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Sep 19 13:18:40 2007
@@ -17,6 +17,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator"
+#include "llvm/ADT/GraphTraits.h"
 #include <iosfwd>
 
 namespace clang {
@@ -634,4 +635,41 @@
 
 }  // 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





More information about the cfe-commits mailing list