Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:42

0001 //===- StmtGraphTraits.h - Graph Traits for the class Stmt ------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines a template specialization of llvm::GraphTraits to
0010 //  treat ASTs (Stmt*) as graphs
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_AST_STMTGRAPHTRAITS_H
0015 #define LLVM_CLANG_AST_STMTGRAPHTRAITS_H
0016 
0017 #include "clang/AST/Stmt.h"
0018 #include "llvm/ADT/DepthFirstIterator.h"
0019 #include "llvm/ADT/GraphTraits.h"
0020 
0021 namespace llvm {
0022 
0023 template <> struct GraphTraits<clang::Stmt *> {
0024   using NodeRef = clang::Stmt *;
0025   using ChildIteratorType = clang::Stmt::child_iterator;
0026   using nodes_iterator = llvm::df_iterator<clang::Stmt *>;
0027 
0028   static NodeRef getEntryNode(clang::Stmt *S) { return S; }
0029 
0030   static ChildIteratorType child_begin(NodeRef N) {
0031     if (N) return N->child_begin();
0032     else return ChildIteratorType();
0033   }
0034 
0035   static ChildIteratorType child_end(NodeRef N) {
0036     if (N) return N->child_end();
0037     else return ChildIteratorType();
0038   }
0039 
0040   static nodes_iterator nodes_begin(clang::Stmt* S) {
0041     return df_begin(S);
0042   }
0043 
0044   static nodes_iterator nodes_end(clang::Stmt* S) {
0045     return df_end(S);
0046   }
0047 };
0048 
0049 template <> struct GraphTraits<const clang::Stmt *> {
0050   using NodeRef = const clang::Stmt *;
0051   using ChildIteratorType = clang::Stmt::const_child_iterator;
0052   using nodes_iterator = llvm::df_iterator<const clang::Stmt *>;
0053 
0054   static NodeRef getEntryNode(const clang::Stmt *S) { return S; }
0055 
0056   static ChildIteratorType child_begin(NodeRef N) {
0057     if (N) return N->child_begin();
0058     else return ChildIteratorType();
0059   }
0060 
0061   static ChildIteratorType child_end(NodeRef N) {
0062     if (N) return N->child_end();
0063     else return ChildIteratorType();
0064   }
0065 
0066   static nodes_iterator nodes_begin(const clang::Stmt* S) {
0067     return df_begin(S);
0068   }
0069 
0070   static nodes_iterator nodes_end(const clang::Stmt* S) {
0071     return df_end(S);
0072   }
0073 };
0074 
0075 } // namespace llvm
0076 
0077 #endif // LLVM_CLANG_AST_STMTGRAPHTRAITS_H