clang API Documentation
00001 //===--- StmtGraphTraits.h - Graph Traits for the class Stmt ----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a template specialization of llvm::GraphTraits to 00011 // treat ASTs (Stmt*) as graphs 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_CLANG_AST_STMTGRAPHTRAITS_H 00016 #define LLVM_CLANG_AST_STMTGRAPHTRAITS_H 00017 00018 #include "clang/AST/Stmt.h" 00019 #include "llvm/ADT/DepthFirstIterator.h" 00020 #include "llvm/ADT/GraphTraits.h" 00021 00022 namespace llvm { 00023 00024 //template <typename T> struct GraphTraits; 00025 00026 00027 template <> struct GraphTraits<clang::Stmt*> { 00028 typedef clang::Stmt NodeType; 00029 typedef clang::Stmt::child_iterator ChildIteratorType; 00030 typedef llvm::df_iterator<clang::Stmt*> nodes_iterator; 00031 00032 static NodeType* getEntryNode(clang::Stmt* S) { return S; } 00033 00034 static inline ChildIteratorType child_begin(NodeType* N) { 00035 if (N) return N->child_begin(); 00036 else return ChildIteratorType(); 00037 } 00038 00039 static inline ChildIteratorType child_end(NodeType* N) { 00040 if (N) return N->child_end(); 00041 else return ChildIteratorType(); 00042 } 00043 00044 static nodes_iterator nodes_begin(clang::Stmt* S) { 00045 return df_begin(S); 00046 } 00047 00048 static nodes_iterator nodes_end(clang::Stmt* S) { 00049 return df_end(S); 00050 } 00051 }; 00052 00053 00054 template <> struct GraphTraits<const clang::Stmt*> { 00055 typedef const clang::Stmt NodeType; 00056 typedef clang::Stmt::const_child_iterator ChildIteratorType; 00057 typedef llvm::df_iterator<const clang::Stmt*> nodes_iterator; 00058 00059 static NodeType* getEntryNode(const clang::Stmt* S) { return S; } 00060 00061 static inline ChildIteratorType child_begin(NodeType* N) { 00062 if (N) return N->child_begin(); 00063 else return ChildIteratorType(); 00064 } 00065 00066 static inline ChildIteratorType child_end(NodeType* N) { 00067 if (N) return N->child_end(); 00068 else return ChildIteratorType(); 00069 } 00070 00071 static nodes_iterator nodes_begin(const clang::Stmt* S) { 00072 return df_begin(S); 00073 } 00074 00075 static nodes_iterator nodes_end(const clang::Stmt* S) { 00076 return df_end(S); 00077 } 00078 }; 00079 00080 00081 } // end namespace llvm 00082 00083 #endif