| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #ifndef LLVM_CLANG_AST_ATTRVISITOR_H |
| 14 | #define LLVM_CLANG_AST_ATTRVISITOR_H |
| 15 | |
| 16 | #include "clang/AST/Attr.h" |
| 17 | |
| 18 | namespace clang { |
| 19 | |
| 20 | namespace attrvisitor { |
| 21 | |
| 22 | |
| 23 | template <template <typename> class Ptr, typename ImplClass, |
| 24 | typename RetTy = void, class... ParamTys> |
| 25 | class Base { |
| 26 | public: |
| 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)) |
| 30 | |
| 31 | RetTy Visit(PTR(Attr) A) { |
| 32 | switch (A->getKind()) { |
| 33 | |
| 34 | #define ATTR(NAME) \ |
| 35 | case attr::NAME: \ |
| 36 | DISPATCH(NAME##Attr); |
| 37 | #include "clang/Basic/AttrList.inc" |
| 38 | } |
| 39 | llvm_unreachable("Attr that isn't part of AttrList.inc!"); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | |
| 44 | #define ATTR(NAME) \ |
| 45 | RetTy Visit##NAME##Attr(PTR(NAME##Attr) A) { DISPATCH(Attr); } |
| 46 | #include "clang/Basic/AttrList.inc" |
| 47 | |
| 48 | RetTy VisitAttr(PTR(Attr)) { return RetTy(); } |
| 49 | |
| 50 | #undef PTR |
| 51 | #undef DISPATCH |
| 52 | }; |
| 53 | |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | template <typename ImplClass, typename RetTy = void, typename... ParamTys> |
| 61 | class AttrVisitor : public attrvisitor::Base<std::add_pointer, ImplClass, RetTy, |
| 62 | ParamTys...> {}; |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | template <typename ImplClass, typename RetTy = void, typename... ParamTys> |
| 69 | class ConstAttrVisitor |
| 70 | : public attrvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy, |
| 71 | ParamTys...> {}; |
| 72 | |
| 73 | } |
| 74 | |
| 75 | #endif |
| 76 | |