clang 8.0.0

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