Deleted Added
full compact
DeclVisitor.h (234353) DeclVisitor.h (249423)
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#ifndef LLVM_CLANG_AST_DECLVISITOR_H
14#define LLVM_CLANG_AST_DECLVISITOR_H
15
16#include "clang/AST/Decl.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#ifndef LLVM_CLANG_AST_DECLVISITOR_H
14#define LLVM_CLANG_AST_DECLVISITOR_H
15
16#include "clang/AST/Decl.h"
17#include "clang/AST/DeclObjC.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclFriend.h"
17#include "clang/AST/DeclCXX.h"
18#include "clang/AST/DeclFriend.h"
19#include "clang/AST/DeclObjC.h"
20#include "clang/AST/DeclOpenMP.h"
20#include "clang/AST/DeclTemplate.h"
21
22namespace clang {
21#include "clang/AST/DeclTemplate.h"
22
23namespace clang {
24namespace declvisitor {
23
25
24#define DISPATCH(NAME, CLASS) \
25 return static_cast<ImplClass*>(this)-> Visit##NAME(static_cast<CLASS*>(D))
26template <typename T> struct make_ptr { typedef T *type; };
27template <typename T> struct make_const_ptr { typedef const T *type; };
26
27/// \brief A simple visitor class that helps create declaration visitors.
28
29/// \brief A simple visitor class that helps create declaration visitors.
28template
29class DeclVisitor {
30template<template <typename> class Ptr, typename ImplClass, typename RetTy=void>
31class Base {
30public:
32public:
31 RetTy Visit(Decl *D) {
33
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) {
32 switch (D->getKind()) {
33#define DECL(DERIVED, BASE) \
34 case Decl::DERIVED: DISPATCH(DERIVED##Decl, DERIVED##Decl);
35#define ABSTRACT_DECL(DECL)
36#include "clang/AST/DeclNodes.inc"
37 }
38 llvm_unreachable("Decl that isn't part of DeclNodes.inc!");
39 }
40
41 // If the implementation chooses not to implement a certain visit
42 // method, fall back to the parent.
43#define DECL(DERIVED, BASE) \
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) \
44 RetTy Visit##DERIVED##Decl(DERIVED##Decl *D) { DISPATCH(BASE, BASE); }
51 RetTy Visit##DERIVED##Decl(PTR(DERIVED##Decl) D) { DISPATCH(BASE, BASE); }
45#include "clang/AST/DeclNodes.inc"
46
52#include "clang/AST/DeclNodes.inc"
53
47 RetTy VisitDecl(Decl *D) { return RetTy(); }
48};
54 RetTy VisitDecl(PTR(Decl) D) { return RetTy(); }
49
55
56#undef PTR
50#undef DISPATCH
57#undef DISPATCH
58};
51
59
60} // end namespace declvisitor
61
62/// \brief A simple visitor class that helps create declaration visitors.
63///
64/// This class does not preserve constness of Decl pointers (see also
65/// ConstDeclVisitor).
66template<typename ImplClass, typename RetTy=void>
67class DeclVisitor
68 : public declvisitor::Base<declvisitor::make_ptr, ImplClass, RetTy> {};
69
70/// \brief A simple visitor class that helps create declaration visitors.
71///
72/// This class preserves constness of Decl pointers (see also DeclVisitor).
73template<typename ImplClass, typename RetTy=void>
74class ConstDeclVisitor
75 : public declvisitor::Base<declvisitor::make_const_ptr, ImplClass, RetTy> {};
76
52} // end namespace clang
53
54#endif // LLVM_CLANG_AST_DECLVISITOR_H
77} // end namespace clang
78
79#endif // LLVM_CLANG_AST_DECLVISITOR_H