1 //===--- StmtGraphTraits.h - Graph Traits for the class Stmt ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a template specialization of llvm::GraphTraits to
11 // treat ASTs (Stmt*) as graphs
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_AST_STMTGRAPHTRAITS_H
16 #define LLVM_CLANG_AST_STMTGRAPHTRAITS_H
18 #include "clang/AST/Stmt.h"
19 #include "llvm/ADT/DepthFirstIterator.h"
20 #include "llvm/ADT/GraphTraits.h"
24 //template <typename T> struct GraphTraits;
27 template <> struct GraphTraits<clang::Stmt*> {
28 typedef clang::Stmt NodeType;
29 typedef clang::Stmt::child_iterator ChildIteratorType;
30 typedef llvm::df_iterator<clang::Stmt*> nodes_iterator;
32 static NodeType* getEntryNode(clang::Stmt* S) { return S; }
34 static inline ChildIteratorType child_begin(NodeType* N) {
35 if (N) return N->child_begin();
36 else return ChildIteratorType();
39 static inline ChildIteratorType child_end(NodeType* N) {
40 if (N) return N->child_end();
41 else return ChildIteratorType();
44 static nodes_iterator nodes_begin(clang::Stmt* S) {
48 static nodes_iterator nodes_end(clang::Stmt* S) {
54 template <> struct GraphTraits<const clang::Stmt*> {
55 typedef const clang::Stmt NodeType;
56 typedef clang::Stmt::const_child_iterator ChildIteratorType;
57 typedef llvm::df_iterator<const clang::Stmt*> nodes_iterator;
59 static NodeType* getEntryNode(const clang::Stmt* S) { return S; }
61 static inline ChildIteratorType child_begin(NodeType* N) {
62 if (N) return N->child_begin();
63 else return ChildIteratorType();
66 static inline ChildIteratorType child_end(NodeType* N) {
67 if (N) return N->child_end();
68 else return ChildIteratorType();
71 static nodes_iterator nodes_begin(const clang::Stmt* S) {
75 static nodes_iterator nodes_end(const clang::Stmt* S) {
81 } // end namespace llvm