clang 10.0.0git

StmtGraphTraits.h
Go to the documentation of this file.
1 //===- StmtGraphTraits.h - Graph Traits for the class Stmt ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a template specialization of llvm::GraphTraits to
10 // treat ASTs (Stmt*) as graphs
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_STMTGRAPHTRAITS_H
15 #define LLVM_CLANG_AST_STMTGRAPHTRAITS_H
16
17 #include "clang/AST/Stmt.h"
18 #include "llvm/ADT/DepthFirstIterator.h"
19 #include "llvm/ADT/GraphTraits.h"
20
21 namespace llvm {
22
23 template <> struct GraphTraits<clang::Stmt *> {
24 using NodeRef = clang::Stmt *;
25 using ChildIteratorType = clang::Stmt::child_iterator;
26 using nodes_iterator = llvm::df_iterator<clang::Stmt *>;
27
28 static NodeRef getEntryNode(clang::Stmt *S) { return S; }
29
30 static ChildIteratorType child_begin(NodeRef N) {
31 if (N) return N->child_begin();
32 else return ChildIteratorType();
33 }
34
35 static ChildIteratorType child_end(NodeRef N) {
36 if (N) return N->child_end();
37 else return ChildIteratorType();
38 }
39
40 static nodes_iterator nodes_begin(clang::Stmt* S) {
41 return df_begin(S);
42 }
43
44 static nodes_iterator nodes_end(clang::Stmt* S) {
45 return df_end(S);
46 }
47 };
48
49 template <> struct GraphTraits<const clang::Stmt *> {
50 using NodeRef = const clang::Stmt *;
51 using ChildIteratorType = clang::Stmt::const_child_iterator;
52 using nodes_iterator = llvm::df_iterator<const clang::Stmt *>;
53
54 static NodeRef getEntryNode(const clang::Stmt *S) { return S; }
55
56 static ChildIteratorType child_begin(NodeRef N) {
57 if (N) return N->child_begin();
58 else return ChildIteratorType();
59 }
60
61 static ChildIteratorType child_end(NodeRef N) {
62 if (N) return N->child_end();
63 else return ChildIteratorType();
64 }
65
66 static nodes_iterator nodes_begin(const clang::Stmt* S) {
67 return df_begin(S);
68 }
69
70 static nodes_iterator nodes_end(const clang::Stmt* S) {
71 return df_end(S);
72 }
73 };
74
75 } // namespace llvm
76
77 #endif // LLVM_CLANG_AST_STMTGRAPHTRAITS_H
clang::Stmt::child_begin
child_iterator child_begin()
Definition: Stmt.h:1190
llvm::GraphTraits< const clang::Stmt * >::child_end
static ChildIteratorType child_end(NodeRef N)
Definition: StmtGraphTraits.h:61
llvm
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Definition: Dominators.h:30
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
llvm::GraphTraits< clang::Stmt * >::child_end
static ChildIteratorType child_end(NodeRef N)
Definition: StmtGraphTraits.h:35
llvm::GraphTraits< const clang::Stmt * >::getEntryNode
static NodeRef getEntryNode(const clang::Stmt *S)
Definition: StmtGraphTraits.h:54
llvm::GraphTraits< clang::Stmt * >::child_begin
static ChildIteratorType child_begin(NodeRef N)
Definition: StmtGraphTraits.h:30
llvm::GraphTraits< clang::Stmt * >::nodes_end
static nodes_iterator nodes_end(clang::Stmt *S)
Definition: StmtGraphTraits.h:44
llvm::GraphTraits< const clang::Stmt * >::nodes_iterator
llvm::df_iterator< const clang::Stmt * > nodes_iterator
Definition: StmtGraphTraits.h:52
llvm::GraphTraits< const clang::Stmt * >::child_begin
static ChildIteratorType child_begin(NodeRef N)
Definition: StmtGraphTraits.h:56
clang::Stmt::const_child_iterator
ConstStmtIterator const_child_iterator
Definition: Stmt.h:1178
llvm::GraphTraits< const clang::Stmt * >::nodes_begin
static nodes_iterator nodes_begin(const clang::Stmt *S)
Definition: StmtGraphTraits.h:66
llvm::GraphTraits< clang::Stmt * >::nodes_iterator
llvm::df_iterator< clang::Stmt * > nodes_iterator
Definition: StmtGraphTraits.h:26
llvm::GraphTraits< const clang::Stmt * >::nodes_end
static nodes_iterator nodes_end(const clang::Stmt *S)
Definition: StmtGraphTraits.h:70
Stmt.h
clang::Stmt::child_iterator
StmtIterator child_iterator
Child Iterators: All subclasses must implement &#39;children&#39; to permit easy iteration over the substatem...
Definition: Stmt.h:1177
clang::StmtIterator
Definition: StmtIterator.h:124
GraphTraits
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::ConstStmtIterator
Definition: StmtIterator.h:140
llvm::GraphTraits< clang::Stmt * >::nodes_begin
static nodes_iterator nodes_begin(clang::Stmt *S)
Definition: StmtGraphTraits.h:40
llvm::GraphTraits< clang::Stmt * >::getEntryNode
static NodeRef getEntryNode(clang::Stmt *S)
Definition: StmtGraphTraits.h:28
clang::Stmt::child_end
child_iterator child_end()
Definition: Stmt.h:1191