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 <> struct GraphTraits<clang::Stmt *> {
25 using NodeRef = clang::Stmt *;
26 using ChildIteratorType = clang::Stmt::child_iterator;
27 using nodes_iterator = llvm::df_iterator<clang::Stmt *>;
29 static NodeRef getEntryNode(clang::Stmt *S) { return S; }
31 static ChildIteratorType child_begin(NodeRef N) {
32 if (N) return N->child_begin();
33 else return ChildIteratorType();
36 static ChildIteratorType child_end(NodeRef N) {
37 if (N) return N->child_end();
38 else return ChildIteratorType();
41 static nodes_iterator nodes_begin(clang::Stmt* S) {
45 static nodes_iterator nodes_end(clang::Stmt* S) {
50 template <> struct GraphTraits<const clang::Stmt *> {
51 using NodeRef = const clang::Stmt *;
52 using ChildIteratorType = clang::Stmt::const_child_iterator;
53 using nodes_iterator = llvm::df_iterator<const clang::Stmt *>;
55 static NodeRef getEntryNode(const clang::Stmt *S) { return S; }
57 static ChildIteratorType child_begin(NodeRef N) {
58 if (N) return N->child_begin();
59 else return ChildIteratorType();
62 static ChildIteratorType child_end(NodeRef N) {
63 if (N) return N->child_end();
64 else return ChildIteratorType();
67 static nodes_iterator nodes_begin(const clang::Stmt* S) {
71 static nodes_iterator nodes_end(const clang::Stmt* S) {
78 #endif // LLVM_CLANG_AST_STMTGRAPHTRAITS_H