]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/StmtGraphTraits.h
Merge ^/head r304236 through r304536.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / StmtGraphTraits.h
1 //===--- StmtGraphTraits.h - Graph Traits for the class Stmt ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines a template specialization of llvm::GraphTraits to
11 //  treat ASTs (Stmt*) as graphs
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_AST_STMTGRAPHTRAITS_H
16 #define LLVM_CLANG_AST_STMTGRAPHTRAITS_H
17
18 #include "clang/AST/Stmt.h"
19 #include "llvm/ADT/DepthFirstIterator.h"
20 #include "llvm/ADT/GraphTraits.h"
21
22 namespace llvm {
23
24 //template <typename T> struct GraphTraits;
25
26
27 template <> struct GraphTraits<clang::Stmt*> {
28   typedef clang::Stmt                       NodeType;
29   typedef clang::Stmt *                     NodeRef;
30   typedef clang::Stmt::child_iterator       ChildIteratorType;
31   typedef llvm::df_iterator<clang::Stmt*>   nodes_iterator;
32
33   static NodeType* getEntryNode(clang::Stmt* S) { return S; }
34
35   static inline ChildIteratorType child_begin(NodeType* N) {
36     if (N) return N->child_begin();
37     else return ChildIteratorType();
38   }
39
40   static inline ChildIteratorType child_end(NodeType* N) {
41     if (N) return N->child_end();
42     else return ChildIteratorType();
43   }
44
45   static nodes_iterator nodes_begin(clang::Stmt* S) {
46     return df_begin(S);
47   }
48
49   static nodes_iterator nodes_end(clang::Stmt* S) {
50     return df_end(S);
51   }
52 };
53
54
55 template <> struct GraphTraits<const clang::Stmt*> {
56   typedef const clang::Stmt                       NodeType;
57   typedef const clang::Stmt *                     NodeRef;
58   typedef clang::Stmt::const_child_iterator       ChildIteratorType;
59   typedef llvm::df_iterator<const clang::Stmt*>   nodes_iterator;
60
61   static NodeType* getEntryNode(const clang::Stmt* S) { return S; }
62
63   static inline ChildIteratorType child_begin(NodeType* N) {
64     if (N) return N->child_begin();
65     else return ChildIteratorType();
66   }
67
68   static inline ChildIteratorType child_end(NodeType* N) {
69     if (N) return N->child_end();
70     else return ChildIteratorType();
71   }
72
73   static nodes_iterator nodes_begin(const clang::Stmt* S) {
74     return df_begin(S);
75   }
76
77   static nodes_iterator nodes_end(const clang::Stmt* S) {
78     return df_end(S);
79   }
80 };
81
82
83 } // end namespace llvm
84
85 #endif