clang  14.0.0git
NonTrivialTypeVisitor.h
Go to the documentation of this file.
1 //===-- NonTrivialTypeVisitor.h - Visitor for non-trivial Types -*- 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 visitor classes that are used to traverse non-trivial
10 // structs.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_NON_TRIVIAL_TYPE_VISITOR_H
15 #define LLVM_CLANG_NON_TRIVIAL_TYPE_VISITOR_H
16 
17 #include "clang/AST/Type.h"
18 
19 namespace clang {
20 
21 template <class Derived, class RetTy = void> struct DestructedTypeVisitor {
22  template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
23  return asDerived().visitWithKind(FT.isDestructedType(), FT,
24  std::forward<Ts>(Args)...);
25  }
26 
27  template <class... Ts>
29  Ts &&... Args) {
30  switch (DK) {
32  return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
34  return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
35  case QualType::DK_none:
36  return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
38  return asDerived().visitCXXDestructor(FT, std::forward<Ts>(Args)...);
40  return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
41  }
42 
43  llvm_unreachable("unknown destruction kind");
44  }
45 
46  Derived &asDerived() { return static_cast<Derived &>(*this); }
47 };
48 
49 template <class Derived, class RetTy = void>
51  template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
52  return asDerived().visitWithKind(
54  std::forward<Ts>(Args)...);
55  }
56 
57  template <class... Ts>
59  QualType FT, Ts &&... Args) {
60  switch (PDIK) {
62  return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
64  return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
66  return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
68  return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
69  }
70 
71  llvm_unreachable("unknown default-initialize kind");
72  }
73 
74  Derived &asDerived() { return static_cast<Derived &>(*this); }
75 };
76 
77 template <class Derived, bool IsMove, class RetTy = void>
79  template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
83  return asDerived().visitWithKind(PCK, FT, std::forward<Ts>(Args)...);
84  }
85 
86  template <class... Ts>
88  Ts &&... Args) {
89  asDerived().preVisit(PCK, FT, std::forward<Ts>(Args)...);
90 
91  switch (PCK) {
93  return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
95  return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
97  return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
99  return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
101  return asDerived().visitVolatileTrivial(FT, std::forward<Ts>(Args)...);
102  }
103 
104  llvm_unreachable("unknown primitive copy kind");
105  }
106 
107  Derived &asDerived() { return static_cast<Derived &>(*this); }
108 };
109 
110 } // end namespace clang
111 
112 #endif
clang::QualType::PCK_Struct
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1186
clang::QualType::DK_nontrivial_c_struct
@ DK_nontrivial_c_struct
Definition: Type.h:1207
clang::QualType::PCK_ARCWeak
@ PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1178
clang::DefaultInitializedTypeVisitor::visit
RetTy visit(QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:51
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:2544
clang::DefaultInitializedTypeVisitor::visitWithKind
RetTy visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:58
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::QualType::PCK_ARCStrong
@ PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1174
clang::QualType::PCK_VolatileTrivial
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1170
clang::DestructedTypeVisitor::visitWithKind
RetTy visitWithKind(QualType::DestructionKind DK, QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:28
clang::QualType::DK_cxx_destructor
@ DK_cxx_destructor
Definition: Type.h:1204
clang::QualType::PDIK_Struct
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
Definition: Type.h:1150
clang::CopiedTypeVisitor
Definition: NonTrivialTypeVisitor.h:78
clang::CopiedTypeVisitor::visit
RetTy visit(QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:79
clang::QualType::DK_none
@ DK_none
Definition: Type.h:1203
clang::QualType::PDIK_Trivial
@ PDIK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1139
Type.h
clang::CopiedTypeVisitor::asDerived
Derived & asDerived()
Definition: NonTrivialTypeVisitor.h:107
clang::DestructedTypeVisitor::asDerived
Derived & asDerived()
Definition: NonTrivialTypeVisitor.h:46
clang::QualType::PCK_Trivial
@ PCK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1165
clang::QualType::PDIK_ARCStrong
@ PDIK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1143
clang::QualType::DK_objc_strong_lifetime
@ DK_objc_strong_lifetime
Definition: Type.h:1205
clang::QualType::DestructionKind
DestructionKind
Definition: Type.h:1202
clang::QualType::DK_objc_weak_lifetime
@ DK_objc_weak_lifetime
Definition: Type.h:1206
clang::CopiedTypeVisitor::visitWithKind
RetTy visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:87
clang
Definition: CalledOnceCheck.h:17
clang::DestructedTypeVisitor::visit
RetTy visit(QualType FT, Ts &&... Args)
Definition: NonTrivialTypeVisitor.h:22
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:2526
clang::QualType::isNonTrivialToPrimitiveDefaultInitialize
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2510
clang::DefaultInitializedTypeVisitor
Definition: NonTrivialTypeVisitor.h:50
clang::QualType::PrimitiveDefaultInitializeKind
PrimitiveDefaultInitializeKind
Definition: Type.h:1135
clang::QualType::PDIK_ARCWeak
@ PDIK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1147
clang::DestructedTypeVisitor
Definition: NonTrivialTypeVisitor.h:21
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:1214
clang::QualType::PrimitiveCopyKind
PrimitiveCopyKind
Definition: Type.h:1161
clang::DefaultInitializedTypeVisitor::asDerived
Derived & asDerived()
Definition: NonTrivialTypeVisitor.h:74