Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- DeclVisitor.h - Visitor for Decl subclasses --------------*- 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 the DeclVisitor interface.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_DECLVISITOR_H
0014 #define LLVM_CLANG_AST_DECLVISITOR_H
0015 
0016 #include "clang/AST/Decl.h"
0017 #include "clang/AST/DeclBase.h"
0018 #include "clang/AST/DeclCXX.h"
0019 #include "clang/AST/DeclFriend.h"
0020 #include "clang/AST/DeclObjC.h"
0021 #include "clang/AST/DeclOpenMP.h"
0022 #include "clang/AST/DeclTemplate.h"
0023 #include "llvm/ADT/STLExtras.h"
0024 #include "llvm/Support/ErrorHandling.h"
0025 
0026 namespace clang {
0027 
0028 namespace declvisitor {
0029 /// A simple visitor class that helps create declaration visitors.
0030 template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
0031 class Base {
0032 public:
0033 #define PTR(CLASS) typename Ptr<CLASS>::type
0034 #define DISPATCH(NAME, CLASS) \
0035   return static_cast<ImplClass*>(this)->Visit##NAME(static_cast<PTR(CLASS)>(D))
0036 
0037   RetTy Visit(PTR(Decl) D) {
0038     switch (D->getKind()) {
0039 #define DECL(DERIVED, BASE) \
0040       case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl);
0041 #define ABSTRACT_DECL(DECL)
0042 #include "clang/AST/DeclNodes.inc"
0043     }
0044     llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
0045   }
0046 
0047   // If the implementation chooses not to implement a certain visit
0048   // method, fall back to the parent.
0049 #define DECL(DERIVED, BASE) \
0050   RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); }
0051 #include "clang/AST/DeclNodes.inc"
0052 
0053   RetTy VisitDecl(PTR(Decl) D) { return RetTy(); }
0054 
0055 #undef PTR
0056 #undef DISPATCH
0057 };
0058 
0059 } // namespace declvisitor
0060 
0061 /// A simple visitor class that helps create declaration visitors.
0062 ///
0063 /// This class does not preserve constness of Decl pointers (see also
0064 /// ConstDeclVisitor).
0065 template <typename ImplClass, typename RetTy = void>
0066 class DeclVisitor
0067     : public declvisitor::Base<std::add_pointer, ImplClass, RetTy> {};
0068 
0069 /// A simple visitor class that helps create declaration visitors.
0070 ///
0071 /// This class preserves constness of Decl pointers (see also DeclVisitor).
0072 template <typename ImplClass, typename RetTy = void>
0073 class ConstDeclVisitor
0074     : public declvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy> {};
0075 
0076 } // namespace clang
0077 
0078 #endif // LLVM_CLANG_AST_DECLVISITOR_H