From 5e97d4b5ec7ce97e311d7aa4e8bd2b4fd9dbfa2e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 19 Sep 2007 18:18:40 +0000 Subject: [PATCH] Added GraphTraits template specialization for Stmt* to treat ASTs like graphs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42146 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Stmt.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index e7de0b264f..c86da49291 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -17,6 +17,7 @@ #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/iterator" +#include "llvm/ADT/GraphTraits.h" #include namespace clang { @@ -634,4 +635,41 @@ public: } // end namespace clang +//===----------------------------------------------------------------------===// +// GraphTraits specialization to treat ASTs (Stmt*) as graphs +//===----------------------------------------------------------------------===// + +namespace llvm { + +template <> struct GraphTraits { + 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 { + 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 -- 2.40.0