clang 8.0.0

NonTrivialTypeVisitor.h
Go to the documentation of this file.
1 //===-- NonTrivialTypeVisitor.h - Visitor for non-trivial Types *- 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 visitor classes that are used to traverse non-trivial
11 // structs.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_NON_TRIVIAL_TYPE_VISITOR_H
16 #define LLVM_CLANG_NON_TRIVIAL_TYPE_VISITOR_H
17
18 #include "clang/AST/Type.h"
19
20 namespace clang {
21
22 template <class Derived, class RetTy = void> struct DestructedTypeVisitor {
23 template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
24 return asDerived().visitWithKind(FT.isDestructedType(), FT,
25 std::forward<Ts>(Args)...);
26 }
27
28 template <class... Ts>
29 RetTy visitWithKind(QualType::DestructionKind DK, QualType FT,
30 Ts &&... Args) {
31 switch (DK) {
32 case QualType::DK_objc_strong_lifetime:
33 return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
34 case QualType::DK_nontrivial_c_struct:
35 return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
36 case QualType::DK_none:
37 return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
38 case QualType::DK_cxx_destructor:
39 return asDerived().visitCXXDestructor(FT, std::forward<Ts>(Args)...);
40 case QualType::DK_objc_weak_lifetime:
41 return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
42 }
43
44 llvm_unreachable("unknown destruction kind");
45 }
46
47 Derived &asDerived() { return static_cast<Derived &>(*this); }
48 };
49
50 template <class Derived, class RetTy = void>
51 struct DefaultInitializedTypeVisitor {
52 template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
53 return asDerived().visitWithKind(
54 FT.isNonTrivialToPrimitiveDefaultInitialize(), FT,
55 std::forward<Ts>(Args)...);
56 }
57
58 template <class... Ts>
59 RetTy visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK,
60 QualType FT, Ts &&... Args) {
61 switch (PDIK) {
62 case QualType::PDIK_ARCStrong:
63 return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
64 case QualType::PDIK_ARCWeak:
65 return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
66 case QualType::PDIK_Struct:
67 return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
68 case QualType::PDIK_Trivial:
69 return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
70 }
71
72 llvm_unreachable("unknown default-initialize kind");
73 }
74
75 Derived &asDerived() { return static_cast<Derived &>(*this); }
76 };
77
78 template <class Derived, bool IsMove, class RetTy = void>
79 struct CopiedTypeVisitor {
80 template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
81 QualType::PrimitiveCopyKind PCK =
82 IsMove ? FT.isNonTrivialToPrimitiveDestructiveMove()
83 : FT.isNonTrivialToPrimitiveCopy();
84 return asDerived().visitWithKind(PCK, FT, std::forward<Ts>(Args)...);
85 }
86
87 template <class... Ts>
88 RetTy visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT,
89 Ts &&... Args) {
90 asDerived().preVisit(PCK, FT, std::forward<Ts>(Args)...);
91
92 switch (PCK) {
93 case QualType::PCK_ARCStrong:
94 return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
95 case QualType::PCK_ARCWeak:
96 return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
97 case QualType::PCK_Struct:
98 return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
99 case QualType::PCK_Trivial:
100 return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
101 case QualType::PCK_VolatileTrivial:
102 return asDerived().visitVolatileTrivial(FT, std::forward<Ts>(Args)...);
103 }
104
105 llvm_unreachable("unknown primitive copy kind");
106 }
107
108 Derived &asDerived() { return static_cast<Derived &>(*this); }
109 };
110
111 } // end namespace clang
112
113 #endif
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:638
clang::DestructedTypeVisitor::visit
RetTy visit(QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:23
clang::QualType::isNonTrivialToPrimitiveDefaultInitialize
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2249
clang::DestructedTypeVisitor
Definition: NonTrivialTypeVisitor.h:22
clang::QualType::DK_nontrivial_c_struct
Definition: Type.h:1145
Type.h
C Language Family Type Representation.
clang::QualType::PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
Definition: Type.h:1088
clang::QualType::PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1108
clang::DestructedTypeVisitor::asDerived
Derived & asDerived()
Definition: NonTrivialTypeVisitor.h:47
clang::CopiedTypeVisitor
Definition: NonTrivialTypeVisitor.h:79
clang::QualType::PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier...
Definition: Type.h:1112
clang::QualType::PDIK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier...
Definition: Type.h:1081
clang::QualType::PrimitiveDefaultInitializeKind
PrimitiveDefaultInitializeKind
Definition: Type.h:1073
clang::QualType::PCK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1103
clang::QualType::PDIK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1077
clang::CopiedTypeVisitor::visit
RetTy visit(QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:80
clang::QualType::isNonTrivialToPrimitiveDestructiveMove
PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2283
clang::QualType::PDIK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier...
Definition: Type.h:1085
clang::DefaultInitializedTypeVisitor::asDerived
Derived & asDerived()
Definition: NonTrivialTypeVisitor.h:75
clang::QualType::PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1124
clang::CopiedTypeVisitor::asDerived
Derived & asDerived()
Definition: NonTrivialTypeVisitor.h:108
clang::QualType::isDestructedType
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
Definition: Type.h:1152
clang::QualType::DK_objc_strong_lifetime
Definition: Type.h:1143
clang::QualType::isNonTrivialToPrimitiveCopy
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2265
clang::QualType::DestructionKind
DestructionKind
Definition: Type.h:1140
clang::QualType::PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier...
Definition: Type.h:1116
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::QualType::DK_objc_weak_lifetime
Definition: Type.h:1144
clang::DefaultInitializedTypeVisitor
Definition: NonTrivialTypeVisitor.h:51
clang::QualType::DK_none
Definition: Type.h:1141
clang::CopiedTypeVisitor::visitWithKind
RetTy visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:88
clang::DestructedTypeVisitor::visitWithKind
RetTy visitWithKind(QualType::DestructionKind DK, QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:29
clang::QualType::DK_cxx_destructor
Definition: Type.h:1142
clang::DefaultInitializedTypeVisitor::visit
RetTy visit(QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:52
clang::DefaultInitializedTypeVisitor::visitWithKind
RetTy visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:59
clang::QualType::PrimitiveCopyKind
PrimitiveCopyKind
Definition: Type.h:1099