@@ -80,6 +80,13 @@ using FunctionDeclTy =
80
80
// /
81
81
class Function final {
82
82
public:
83
+ enum class FunctionKind {
84
+ Normal,
85
+ Ctor,
86
+ Dtor,
87
+ LambdaStaticInvoker,
88
+ LambdaCallOperator,
89
+ };
83
90
using ParamDescriptor = std::pair<PrimType, Descriptor *>;
84
91
85
92
// / Returns the size of the function's local stack.
@@ -141,43 +148,31 @@ class Function final {
141
148
bool isConstexpr () const { return IsValid || isLambdaStaticInvoker (); }
142
149
143
150
// / Checks if the function is virtual.
144
- bool isVirtual () const ;
151
+ bool isVirtual () const { return Virtual; } ;
145
152
146
153
// / Checks if the function is a constructor.
147
- bool isConstructor () const {
148
- return isa_and_nonnull<CXXConstructorDecl>(
149
- dyn_cast<const FunctionDecl *>(Source));
150
- }
154
+ bool isConstructor () const { return Kind == FunctionKind::Ctor; }
151
155
// / Checks if the function is a destructor.
152
- bool isDestructor () const {
153
- return isa_and_nonnull<CXXDestructorDecl>(
154
- dyn_cast<const FunctionDecl *>(Source));
155
- }
156
-
157
- // / Returns the parent record decl, if any.
158
- const CXXRecordDecl *getParentDecl () const {
159
- if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
160
- dyn_cast<const FunctionDecl *>(Source)))
161
- return MD->getParent ();
162
- return nullptr ;
163
- }
156
+ bool isDestructor () const { return Kind == FunctionKind::Dtor; }
164
157
165
158
// / Returns whether this function is a lambda static invoker,
166
159
// / which we generate custom byte code for.
167
160
bool isLambdaStaticInvoker () const {
168
- if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
169
- dyn_cast<const FunctionDecl *>(Source)))
170
- return MD->isLambdaStaticInvoker ();
171
- return false ;
161
+ return Kind == FunctionKind::LambdaStaticInvoker;
172
162
}
173
163
174
164
// / Returns whether this function is the call operator
175
165
// / of a lambda record decl.
176
166
bool isLambdaCallOperator () const {
167
+ return Kind == FunctionKind::LambdaCallOperator;
168
+ }
169
+
170
+ // / Returns the parent record decl, if any.
171
+ const CXXRecordDecl *getParentDecl () const {
177
172
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
178
173
dyn_cast<const FunctionDecl *>(Source)))
179
- return clang::isLambdaCallOperator (MD );
180
- return false ;
174
+ return MD-> getParent ( );
175
+ return nullptr ;
181
176
}
182
177
183
178
// / Checks if the function is fully done compiling.
@@ -213,7 +208,7 @@ class Function final {
213
208
214
209
bool isThisPointerExplicit () const {
215
210
if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
216
- Source. dyn_cast <const FunctionDecl *>()))
211
+ dyn_cast<const FunctionDecl *>(Source )))
217
212
return MD->isExplicitObjectMemberFunction ();
218
213
return false ;
219
214
}
@@ -232,7 +227,7 @@ class Function final {
232
227
llvm::SmallVectorImpl<PrimType> &&ParamTypes,
233
228
llvm::DenseMap<unsigned , ParamDescriptor> &&Params,
234
229
llvm::SmallVectorImpl<unsigned > &&ParamOffsets, bool HasThisPointer,
235
- bool HasRVO, unsigned BuiltinID );
230
+ bool HasRVO);
236
231
237
232
// / Sets the code of a function.
238
233
void setCode (unsigned NewFrameSize, std::vector<std::byte> &&NewCode,
@@ -255,6 +250,8 @@ class Function final {
255
250
256
251
// / Program reference.
257
252
Program &P;
253
+ // / Function Kind.
254
+ FunctionKind Kind;
258
255
// / Declaration this function was compiled from.
259
256
FunctionDeclTy Source;
260
257
// / Local area size: storage + metadata.
@@ -289,6 +286,7 @@ class Function final {
289
286
bool HasBody = false ;
290
287
bool Defined = false ;
291
288
bool Variadic = false ;
289
+ bool Virtual = false ;
292
290
unsigned BuiltinID = 0 ;
293
291
294
292
public:
0 commit comments