11553Srgrimes//===- AttrVisitor.h - Visitor for Attr subclasses --------------*- C++ -*-===// 21553Srgrimes// 31553Srgrimes// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 41553Srgrimes// See https://llvm.org/LICENSE.txt for license information. 51553Srgrimes// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61553Srgrimes// 71553Srgrimes//===----------------------------------------------------------------------===// 81553Srgrimes// 91553Srgrimes// This file defines the AttrVisitor interface. 101553Srgrimes// 111553Srgrimes//===----------------------------------------------------------------------===// 121553Srgrimes 131553Srgrimes#ifndef LLVM_CLANG_AST_ATTRVISITOR_H 141553Srgrimes#define LLVM_CLANG_AST_ATTRVISITOR_H 151553Srgrimes 161553Srgrimes#include "clang/AST/Attr.h" 171553Srgrimes 181553Srgrimesnamespace clang { 191553Srgrimes 201553Srgrimesnamespace attrvisitor { 211553Srgrimes 221553Srgrimes/// A simple visitor class that helps create attribute visitors. 231553Srgrimestemplate <template <typename> class Ptr, typename ImplClass, 241553Srgrimes typename RetTy = void, class... ParamTys> 251553Srgrimesclass Base { 261553Srgrimespublic: 271553Srgrimes#define PTR(CLASS) typename Ptr<CLASS>::type 281553Srgrimes#define DISPATCH(NAME) \ 291553Srgrimes return static_cast<ImplClass *>(this)->Visit##NAME(static_cast<PTR(NAME)>(A)) 301553Srgrimes 311553Srgrimes RetTy Visit(PTR(Attr) A) { 321553Srgrimes switch (A->getKind()) { 331553Srgrimes 341553Srgrimes#define ATTR(NAME) \ 3530602Scharnier case attr::NAME: \ 361553Srgrimes DISPATCH(NAME##Attr); 371553Srgrimes#include "clang/Basic/AttrList.inc" 381553Srgrimes } 391553Srgrimes llvm_unreachable("Attr that isn't part of AttrList.inc!"); 401553Srgrimes } 4130602Scharnier 4230602Scharnier // If the implementation chooses not to implement a certain visit 4330602Scharnier // method, fall back to the parent. 446284Swollman#define ATTR(NAME) \ 4550476Speter RetTy Visit##NAME##Attr(PTR(NAME##Attr) A) { DISPATCH(Attr); } 461553Srgrimes#include "clang/Basic/AttrList.inc" 471553Srgrimes 4812946Sphk RetTy VisitAttr(PTR(Attr)) { return RetTy(); } 491553Srgrimes 501553Srgrimes#undef PTR 5112946Sphk#undef DISPATCH 5288696Sphk}; 531553Srgrimes 5430602Scharnier} // namespace attrvisitor 5530602Scharnier 561553Srgrimes/// A simple visitor class that helps create attribute visitors. 571553Srgrimes/// 581553Srgrimes/// This class does not preserve constness of Attr pointers (see 591553Srgrimes/// also ConstAttrVisitor). 6030602Scharniertemplate <typename ImplClass, typename RetTy = void, typename... ParamTys> 611553Srgrimesclass AttrVisitor : public attrvisitor::Base<std::add_pointer, ImplClass, RetTy, 6288006Sluigi ParamTys...> {}; 631553Srgrimes 6412946Sphk/// A simple visitor class that helps create attribute visitors. 6512946Sphk/// 6612946Sphk/// This class preserves constness of Attr pointers (see also 6712946Sphk/// AttrVisitor). 6812946Sphktemplate <typename ImplClass, typename RetTy = void, typename... ParamTys> 691553Srgrimesclass ConstAttrVisitor 7088696Sphk : public attrvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy, 7188696Sphk ParamTys...> {}; 7212946Sphk 7312946Sphk} // namespace clang 7412946Sphk 751553Srgrimes#endif // LLVM_CLANG_AST_ATTRVISITOR_H 7677330Sdes