1 //===- StmtGraphTraits.h - Graph Traits for the class Stmt ------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines a template specialization of llvm::GraphTraits to
10 // treat ASTs (Stmt*) as graphs
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_STMTGRAPHTRAITS_H
15 #define LLVM_CLANG_AST_STMTGRAPHTRAITS_H
17 #include "clang/AST/Stmt.h"
18 #include "llvm/ADT/DepthFirstIterator.h"
19 #include "llvm/ADT/GraphTraits.h"
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 *>;
28 static NodeRef getEntryNode(clang::Stmt *S) { return S; }
30 static ChildIteratorType child_begin(NodeRef N) {
31 if (N) return N->child_begin();
32 else return ChildIteratorType();
35 static ChildIteratorType child_end(NodeRef N) {
36 if (N) return N->child_end();
37 else return ChildIteratorType();
40 static nodes_iterator nodes_begin(clang::Stmt* S) {
44 static nodes_iterator nodes_end(clang::Stmt* S) {
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 *>;
54 static NodeRef getEntryNode(const clang::Stmt *S) { return S; }
56 static ChildIteratorType child_begin(NodeRef N) {
57 if (N) return N->child_begin();
58 else return ChildIteratorType();
61 static ChildIteratorType child_end(NodeRef N) {
62 if (N) return N->child_end();
63 else return ChildIteratorType();
66 static nodes_iterator nodes_begin(const clang::Stmt* S) {
70 static nodes_iterator nodes_end(const clang::Stmt* S) {
77 #endif // LLVM_CLANG_AST_STMTGRAPHTRAITS_H