clang 8.0.0

AttrVisitor.h
Go to the documentation of this file.
1 //===- AttrVisitor.h - Visitor for Attr subclasses --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the AttrVisitor interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_AST_ATTRVISITOR_H
15 #define LLVM_CLANG_AST_ATTRVISITOR_H
16
17 #include "clang/AST/Attr.h"
18
19 namespace clang {
20
21 namespace attrvisitor {
22
23 /// A simple visitor class that helps create attribute visitors.
24 template <template <typename> class Ptr, typename ImplClass,
25 typename RetTy = void, class... ParamTys>
26 class Base {
27 public:
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))
31
32 RetTy Visit(PTR(Attr) A) {
33 switch (A->getKind()) {
34
35 #define ATTR(NAME) \
36 case attr::NAME: \
37 DISPATCH(NAME##Attr);
38 #include "clang/Basic/AttrList.inc"
39 }
40 llvm_unreachable("Attr that isn't part of AttrList.inc!");
41 }
42
43 // If the implementation chooses not to implement a certain visit
44 // method, fall back to the parent.
45 #define ATTR(NAME) \
46 RetTy Visit##NAME##Attr(PTR(NAME##Attr) A) { DISPATCH(Attr); }
47 #include "clang/Basic/AttrList.inc"
48
49 RetTy VisitAttr(PTR(Attr)) { return RetTy(); }
50
51 #undef PTR
52 #undef DISPATCH
53 };
54
55 } // namespace attrvisitor
56
57 /// A simple visitor class that helps create attribute visitors.
58 ///
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,
63 ParamTys...> {};
64
65 /// A simple visitor class that helps create attribute visitors.
66 ///
67 /// This class preserves constness of Attr pointers (see also
68 /// AttrVisitor).
69 template <typename ImplClass, typename RetTy = void, typename... ParamTys>
70 class ConstAttrVisitor
71 : public attrvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy,
72 ParamTys...> {};
73
74 } // namespace clang
75
76 #endif // LLVM_CLANG_AST_ATTRVISITOR_H
clang::ConstAttrVisitor
A simple visitor class that helps create attribute visitors.
Definition: AttrVisitor.h:70
clang::attrvisitor::Base::Visit
RetTy Visit(PTR(Attr) A)
Definition: AttrVisitor.h:32
Attr.h
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::attrvisitor::Base::VisitAttr
RetTy VisitAttr(PTR(Attr))
Definition: AttrVisitor.h:49
PTR
#define PTR(CLASS)
Definition: AttrVisitor.h:28
clang::attrvisitor::Base
A simple visitor class that helps create attribute visitors.
Definition: AttrVisitor.h:26
clang::Attr::getKind
attr::Kind getKind() const
Definition: Attr.h:87
clang::AttrVisitor
A simple visitor class that helps create attribute visitors.
Definition: AttrVisitor.h:62
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:44