clang 20.0.0git
AttrVisitor.h
Go to the documentation of this file.
1//===- AttrVisitor.h - Visitor for Attr subclasses --------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the AttrVisitor interface.
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
18namespace clang {
19
20namespace attrvisitor {
21
22/// A simple visitor class that helps create attribute visitors.
23template <template <typename> class Ptr, typename ImplClass,
24 typename RetTy = void, class... ParamTys>
25class Base {
26public:
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 // If the implementation chooses not to implement a certain visit
43 // method, fall back to the parent.
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} // namespace attrvisitor
55
56/// A simple visitor class that helps create attribute visitors.
57///
58/// This class does not preserve constness of Attr pointers (see
59/// also ConstAttrVisitor).
60template <typename ImplClass, typename RetTy = void, typename... ParamTys>
61class AttrVisitor : public attrvisitor::Base<std::add_pointer, ImplClass, RetTy,
62 ParamTys...> {};
63
64/// A simple visitor class that helps create attribute visitors.
65///
66/// This class preserves constness of Attr pointers (see also
67/// AttrVisitor).
68template <typename ImplClass, typename RetTy = void, typename... ParamTys>
70 : public attrvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy,
71 ParamTys...> {};
72
73} // namespace clang
74
75#endif // LLVM_CLANG_AST_ATTRVISITOR_H
#define PTR(CLASS)
Definition: AttrVisitor.h:27
A simple visitor class that helps create attribute visitors.
Definition: AttrVisitor.h:62
Attr - This represents one attribute.
Definition: Attr.h:42
attr::Kind getKind() const
Definition: Attr.h:88
A simple visitor class that helps create attribute visitors.
Definition: AttrVisitor.h:71
A simple visitor class that helps create attribute visitors.
Definition: AttrVisitor.h:25
RetTy Visit(PTR(Attr) A)
Definition: AttrVisitor.h:31
RetTy VisitAttr(PTR(Attr))
Definition: AttrVisitor.h:48
The JSON file list parser is used to communicate input to InstallAPI.