clang  6.0.0svn
StmtGraphTraits.h
Go to the documentation of this file.
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 * NodeRef;
30  typedef llvm::df_iterator<clang::Stmt*> nodes_iterator;
31 
32  static NodeRef getEntryNode(clang::Stmt *S) { return S; }
33 
34  static ChildIteratorType child_begin(NodeRef N) {
35  if (N) return N->child_begin();
36  else return ChildIteratorType();
37  }
38 
39  static ChildIteratorType child_end(NodeRef N) {
40  if (N) return N->child_end();
41  else return ChildIteratorType();
42  }
43 
44  static nodes_iterator nodes_begin(clang::Stmt* S) {
45  return df_begin(S);
46  }
47 
48  static nodes_iterator nodes_end(clang::Stmt* S) {
49  return df_end(S);
50  }
51 };
52 
53 
54 template <> struct GraphTraits<const clang::Stmt*> {
55  typedef const clang::Stmt * NodeRef;
57  typedef llvm::df_iterator<const clang::Stmt*> nodes_iterator;
58 
59  static NodeRef getEntryNode(const clang::Stmt *S) { return S; }
60 
61  static ChildIteratorType child_begin(NodeRef N) {
62  if (N) return N->child_begin();
63  else return ChildIteratorType();
64  }
65 
66  static ChildIteratorType child_end(NodeRef N) {
67  if (N) return N->child_end();
68  else return ChildIteratorType();
69  }
70 
71  static nodes_iterator nodes_begin(const clang::Stmt* S) {
72  return df_begin(S);
73  }
74 
75  static nodes_iterator nodes_end(const clang::Stmt* S) {
76  return df_end(S);
77  }
78 };
79 
80 
81 } // end namespace llvm
82 
83 #endif
child_iterator child_begin()
Definition: Stmt.h:431
static ChildIteratorType child_end(NodeRef N)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
Stmt - This represents one statement.
Definition: Stmt.h:60
static ChildIteratorType child_end(NodeRef N)
static NodeRef getEntryNode(const clang::Stmt *S)
static ChildIteratorType child_begin(NodeRef N)
llvm::df_iterator< const clang::Stmt * > nodes_iterator
static nodes_iterator nodes_end(clang::Stmt *S)
static ChildIteratorType child_begin(NodeRef N)
static nodes_iterator nodes_begin(const clang::Stmt *S)
static nodes_iterator nodes_end(const clang::Stmt *S)
clang::Stmt::const_child_iterator ChildIteratorType
llvm::df_iterator< clang::Stmt * > nodes_iterator
clang::Stmt::child_iterator ChildIteratorType
Dataflow Directional Tag Classes.
static nodes_iterator nodes_begin(clang::Stmt *S)
static NodeRef getEntryNode(clang::Stmt *S)
child_iterator child_end()
Definition: Stmt.h:432