1 //===- AttrVisitor.h - Visitor for Attr subclasses --------------*- 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 the AttrVisitor interface.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_AST_ATTRVISITOR_H
14 #define LLVM_CLANG_AST_ATTRVISITOR_H
16 #include "clang/AST/Attr.h"
20 namespace attrvisitor {
22 /// A simple visitor class that helps create attribute visitors.
23 template <template <typename> class Ptr, typename ImplClass,
24 typename RetTy = void, class... ParamTys>
27 #define PTR(CLASS) typename Ptr<CLASS>::type
28 #define DISPATCH(NAME) \
29 return static_cast<ImplClass *>(this)->Visit##NAME(static_cast<PTR(NAME)>(A))
31 RetTy Visit(PTR(Attr) A) {
32 switch (A->getKind()) {
37 #include "clang/Basic/AttrList.inc"
39 llvm_unreachable("Attr that isn't part of AttrList.inc!");
42 // If the implementation chooses not to implement a certain visit
43 // method, fall back to the parent.
45 RetTy Visit##NAME##Attr(PTR(NAME##Attr) A) { DISPATCH(Attr); }
46 #include "clang/Basic/AttrList.inc"
48 RetTy VisitAttr(PTR(Attr)) { return RetTy(); }
54 } // namespace attrvisitor
56 /// A simple visitor class that helps create attribute visitors.
58 /// This class does not preserve constness of Attr pointers (see
59 /// also ConstAttrVisitor).
60 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
61 class AttrVisitor : public attrvisitor::Base<std::add_pointer, ImplClass, RetTy,
64 /// A simple visitor class that helps create attribute visitors.
66 /// This class preserves constness of Attr pointers (see also
68 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
69 class ConstAttrVisitor
70 : public attrvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy,
75 #endif // LLVM_CLANG_AST_ATTRVISITOR_H