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>
30  Ts &&... Args) {
31  switch (DK) {
33  return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
35  return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
36  case QualType::DK_none:
37  return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
39  return asDerived().visitCXXDestructor(FT, std::forward<Ts>(Args)...);
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>
52  template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
53  return asDerived().visitWithKind(
55  std::forward<Ts>(Args)...);
56  }
57 
58  template <class... Ts>
60  QualType FT, Ts &&... Args) {
61  switch (PDIK) {
63  return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
65  return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
67  return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
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>
80  template <class... Ts> RetTy visit(QualType FT, Ts &&... Args) {
84  return asDerived().visitWithKind(PCK, FT, std::forward<Ts>(Args)...);
85  }
86 
87  template <class... Ts>
89  Ts &&... Args) {
90  asDerived().preVisit(PCK, FT, std::forward<Ts>(Args)...);
91 
92  switch (PCK) {
94  return asDerived().visitARCStrong(FT, std::forward<Ts>(Args)...);
96  return asDerived().visitARCWeak(FT, std::forward<Ts>(Args)...);
98  return asDerived().visitStruct(FT, std::forward<Ts>(Args)...);
100  return asDerived().visitTrivial(FT, std::forward<Ts>(Args)...);
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
A (possibly-)qualified type.
Definition: Type.h:638
RetTy visit(QualType FT, Ts &&... Args)
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2249
C Language Family Type Representation.
The type is a struct containing a field whose type is not PCK_Trivial.
Definition: Type.h:1088
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1108
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier...
Definition: Type.h:1112
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier...
Definition: Type.h:1081
PrimitiveDefaultInitializeKind
Definition: Type.h:1073
The type does not fall into any of the following categories.
Definition: Type.h:1103
The type does not fall into any of the following categories.
Definition: Type.h:1077
RetTy visit(QualType FT, Ts &&... Args)
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
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier...
Definition: Type.h:1085
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1124
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after...
Definition: Type.h:1152
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
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier...
Definition: Type.h:1116
Dataflow Directional Tag Classes.
RetTy visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT, Ts &&... Args)
RetTy visitWithKind(QualType::DestructionKind DK, QualType FT, Ts &&... Args)
RetTy visit(QualType FT, Ts &&... Args)
RetTy visitWithKind(QualType::PrimitiveDefaultInitializeKind PDIK, QualType FT, Ts &&... Args)