1 //===- AttrVisitor.h - Visitor for Attr subclasses --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the AttrVisitor interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_ATTRVISITOR_H
15 #define LLVM_CLANG_AST_ATTRVISITOR_H
17 #include "clang/AST/Attr.h"
21 namespace attrvisitor {
23 /// A simple visitor class that helps create attribute visitors.
24 template <template <typename> class Ptr, typename ImplClass,
25 typename RetTy = void, class... ParamTys>
28 #define PTR(CLASS) typename Ptr<CLASS>::type
29 #define DISPATCH(NAME) \
30 return static_cast<ImplClass *>(this)->Visit##NAME(static_cast<PTR(NAME)>(A))
32 RetTy Visit(PTR(Attr) A) {
33 switch (A->getKind()) {
38 #include "clang/Basic/AttrList.inc"
40 llvm_unreachable("Attr that isn't part of AttrList.inc!");
43 // If the implementation chooses not to implement a certain visit
44 // method, fall back to the parent.
46 RetTy Visit##NAME##Attr(PTR(NAME##Attr) A) { DISPATCH(Attr); }
47 #include "clang/Basic/AttrList.inc"
49 RetTy VisitAttr(PTR(Attr)) { return RetTy(); }
55 } // namespace attrvisitor
57 /// A simple visitor class that helps create attribute visitors.
59 /// This class does not preserve constness of Attr pointers (see
60 /// also ConstAttrVisitor).
61 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
62 class AttrVisitor : public attrvisitor::Base<std::add_pointer, ImplClass, RetTy,
65 /// A simple visitor class that helps create attribute visitors.
67 /// This class preserves constness of Attr pointers (see also
69 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
70 class ConstAttrVisitor
71 : public attrvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy,
76 #endif // LLVM_CLANG_AST_ATTRVISITOR_H