clang 20.0.0git
DeclVisitor.h
Go to the documentation of this file.
1//===- DeclVisitor.h - Visitor for Decl 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 DeclVisitor interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_DECLVISITOR_H
14#define LLVM_CLANG_AST_DECLVISITOR_H
15
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclBase.h"
18#include "clang/AST/DeclCXX.h"
20#include "clang/AST/DeclObjC.h"
23#include "llvm/ADT/STLExtras.h"
24#include "llvm/Support/ErrorHandling.h"
25
26namespace clang {
27
28namespace declvisitor {
29/// A simple visitor class that helps create declaration visitors.
30template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
31class Base {
32public:
33#define PTR(CLASS) typename Ptr<CLASS>::type
34#define DISPATCH(NAME, CLASS) \
35 return static_cast<ImplClass*>(this)->Visit##NAME(static_cast<PTR(CLASS)>(D))
36
37 RetTy Visit(PTR(Decl) D) {
38 switch (D->getKind()) {
39#define DECL(DERIVED, BASE) \
40 case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl);
41#define ABSTRACT_DECL(DECL)
42#include "clang/AST/DeclNodes.inc"
43 }
44 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
45 }
46
47 // If the implementation chooses not to implement a certain visit
48 // method, fall back to the parent.
49#define DECL(DERIVED, BASE) \
50 RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); }
51#include "clang/AST/DeclNodes.inc"
52
53 RetTy VisitDecl(PTR(Decl) D) { return RetTy(); }
54
55#undef PTR
56#undef DISPATCH
57};
58
59} // namespace declvisitor
60
61/// A simple visitor class that helps create declaration visitors.
62///
63/// This class does not preserve constness of Decl pointers (see also
64/// ConstDeclVisitor).
65template <typename ImplClass, typename RetTy = void>
67 : public declvisitor::Base<std::add_pointer, ImplClass, RetTy> {};
68
69/// A simple visitor class that helps create declaration visitors.
70///
71/// This class preserves constness of Decl pointers (see also DeclVisitor).
72template <typename ImplClass, typename RetTy = void>
74 : public declvisitor::Base<llvm::make_const_ptr, ImplClass, RetTy> {};
75
76} // namespace clang
77
78#endif // LLVM_CLANG_AST_DECLVISITOR_H
#define PTR(CLASS)
Definition: AttrVisitor.h:27
const Decl * D
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:74
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:31
RetTy Visit(PTR(Decl) D)
Definition: DeclVisitor.h:37
RetTy VisitDecl(PTR(Decl) D)
Definition: DeclVisitor.h:53
The JSON file list parser is used to communicate input to InstallAPI.