Back to home page

EIC code displayed by LXR

 
 

    


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

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