]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/DeclVisitor.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / DeclVisitor.h
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/Support/ErrorHandling.h"
25
26 namespace clang {
27
28 namespace declvisitor {
29
30 template <typename T> struct make_ptr { using type = T *; };
31 template <typename T> struct make_const_ptr { using type = const T *; };
32
33 /// A simple visitor class that helps create declaration visitors.
34 template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
35 class Base {
36 public:
37 #define PTR(CLASS) typename Ptr<CLASS>::type
38 #define DISPATCH(NAME, CLASS) \
39   return static_cast<ImplClass*>(this)->Visit##NAME(static_cast<PTR(CLASS)>(D))
40
41   RetTy Visit(PTR(Decl) D) {
42     switch (D->getKind()) {
43 #define DECL(DERIVED, BASE) \
44       case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl);
45 #define ABSTRACT_DECL(DECL)
46 #include "clang/AST/DeclNodes.inc"
47     }
48     llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
49   }
50
51   // If the implementation chooses not to implement a certain visit
52   // method, fall back to the parent.
53 #define DECL(DERIVED, BASE) \
54   RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); }
55 #include "clang/AST/DeclNodes.inc"
56
57   RetTy VisitDecl(PTR(Decl) D) { return RetTy(); }
58
59 #undef PTR
60 #undef DISPATCH
61 };
62
63 } // namespace declvisitor
64
65 /// A simple visitor class that helps create declaration visitors.
66 ///
67 /// This class does not preserve constness of Decl pointers (see also
68 /// ConstDeclVisitor).
69 template<typename ImplClass, typename RetTy = void>
70 class DeclVisitor
71  : public declvisitor::Base<declvisitor::make_ptr, ImplClass, RetTy> {};
72
73 /// A simple visitor class that helps create declaration visitors.
74 ///
75 /// This class preserves constness of Decl pointers (see also DeclVisitor).
76 template<typename ImplClass, typename RetTy = void>
77 class ConstDeclVisitor
78  : public declvisitor::Base<declvisitor::make_const_ptr, ImplClass, RetTy> {};
79
80 } // namespace clang
81
82 #endif // LLVM_CLANG_AST_DECLVISITOR_H