clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name DeclCXX.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include/clang/AST -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangAST/../include -I /usr/src/gnu/usr.bin/clang/libclangAST/obj -I /usr/src/gnu/usr.bin/clang/libclangAST/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangAST/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangAST/../../../llvm/clang/lib/AST/DeclCXX.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "clang/AST/DeclCXX.h" |
14 | #include "clang/AST/ASTContext.h" |
15 | #include "clang/AST/ASTLambda.h" |
16 | #include "clang/AST/ASTMutationListener.h" |
17 | #include "clang/AST/ASTUnresolvedSet.h" |
18 | #include "clang/AST/Attr.h" |
19 | #include "clang/AST/CXXInheritance.h" |
20 | #include "clang/AST/DeclBase.h" |
21 | #include "clang/AST/DeclTemplate.h" |
22 | #include "clang/AST/DeclarationName.h" |
23 | #include "clang/AST/Expr.h" |
24 | #include "clang/AST/ExprCXX.h" |
25 | #include "clang/AST/LambdaCapture.h" |
26 | #include "clang/AST/NestedNameSpecifier.h" |
27 | #include "clang/AST/ODRHash.h" |
28 | #include "clang/AST/Type.h" |
29 | #include "clang/AST/TypeLoc.h" |
30 | #include "clang/AST/UnresolvedSet.h" |
31 | #include "clang/Basic/Diagnostic.h" |
32 | #include "clang/Basic/IdentifierTable.h" |
33 | #include "clang/Basic/LLVM.h" |
34 | #include "clang/Basic/LangOptions.h" |
35 | #include "clang/Basic/OperatorKinds.h" |
36 | #include "clang/Basic/PartialDiagnostic.h" |
37 | #include "clang/Basic/SourceLocation.h" |
38 | #include "clang/Basic/Specifiers.h" |
39 | #include "llvm/ADT/None.h" |
40 | #include "llvm/ADT/SmallPtrSet.h" |
41 | #include "llvm/ADT/SmallVector.h" |
42 | #include "llvm/ADT/iterator_range.h" |
43 | #include "llvm/Support/Casting.h" |
44 | #include "llvm/Support/ErrorHandling.h" |
45 | #include "llvm/Support/Format.h" |
46 | #include "llvm/Support/raw_ostream.h" |
47 | #include <algorithm> |
48 | #include <cassert> |
49 | #include <cstddef> |
50 | #include <cstdint> |
51 | |
52 | using namespace clang; |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | void AccessSpecDecl::anchor() {} |
59 | |
60 | AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
61 | return new (C, ID) AccessSpecDecl(EmptyShell()); |
62 | } |
63 | |
64 | void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const { |
65 | ExternalASTSource *Source = C.getExternalSource(); |
66 | assert(Impl.Decls.isLazy() && "getFromExternalSource for non-lazy set"); |
67 | assert(Source && "getFromExternalSource with no external source"); |
68 | |
69 | for (ASTUnresolvedSet::iterator I = Impl.begin(); I != Impl.end(); ++I) |
70 | I.setDecl(cast<NamedDecl>(Source->GetExternalDecl( |
71 | reinterpret_cast<uintptr_t>(I.getDecl()) >> 2))); |
72 | Impl.Decls.setLazy(false); |
73 | } |
74 | |
75 | CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) |
76 | : UserDeclaredConstructor(false), UserDeclaredSpecialMembers(0), |
77 | Aggregate(true), PlainOldData(true), Empty(true), Polymorphic(false), |
78 | Abstract(false), IsStandardLayout(true), IsCXX11StandardLayout(true), |
79 | HasBasesWithFields(false), HasBasesWithNonStaticDataMembers(false), |
80 | HasPrivateFields(false), HasProtectedFields(false), |
81 | HasPublicFields(false), HasMutableFields(false), HasVariantMembers(false), |
82 | HasOnlyCMembers(true), HasInClassInitializer(false), |
83 | HasUninitializedReferenceMember(false), HasUninitializedFields(false), |
84 | HasInheritedConstructor(false), |
85 | HasInheritedDefaultConstructor(false), |
86 | HasInheritedAssignment(false), |
87 | NeedOverloadResolutionForCopyConstructor(false), |
88 | NeedOverloadResolutionForMoveConstructor(false), |
89 | NeedOverloadResolutionForCopyAssignment(false), |
90 | NeedOverloadResolutionForMoveAssignment(false), |
91 | NeedOverloadResolutionForDestructor(false), |
92 | DefaultedCopyConstructorIsDeleted(false), |
93 | DefaultedMoveConstructorIsDeleted(false), |
94 | DefaultedCopyAssignmentIsDeleted(false), |
95 | DefaultedMoveAssignmentIsDeleted(false), |
96 | DefaultedDestructorIsDeleted(false), HasTrivialSpecialMembers(SMF_All), |
97 | HasTrivialSpecialMembersForCall(SMF_All), |
98 | DeclaredNonTrivialSpecialMembers(0), |
99 | DeclaredNonTrivialSpecialMembersForCall(0), HasIrrelevantDestructor(true), |
100 | HasConstexprNonCopyMoveConstructor(false), |
101 | HasDefaultedDefaultConstructor(false), |
102 | DefaultedDefaultConstructorIsConstexpr(true), |
103 | HasConstexprDefaultConstructor(false), |
104 | DefaultedDestructorIsConstexpr(true), |
105 | HasNonLiteralTypeFieldsOrBases(false), StructuralIfLiteral(true), |
106 | UserProvidedDefaultConstructor(false), DeclaredSpecialMembers(0), |
107 | ImplicitCopyConstructorCanHaveConstParamForVBase(true), |
108 | ImplicitCopyConstructorCanHaveConstParamForNonVBase(true), |
109 | ImplicitCopyAssignmentHasConstParam(true), |
110 | HasDeclaredCopyConstructorWithConstParam(false), |
111 | HasDeclaredCopyAssignmentWithConstParam(false), |
112 | IsAnyDestructorNoReturn(false), IsLambda(false), |
113 | IsParsingBaseSpecifiers(false), ComputedVisibleConversions(false), |
114 | HasODRHash(false), Definition(D) {} |
115 | |
116 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getBasesSlowCase() const { |
117 | return Bases.get(Definition->getASTContext().getExternalSource()); |
118 | } |
119 | |
120 | CXXBaseSpecifier *CXXRecordDecl::DefinitionData::getVBasesSlowCase() const { |
121 | return VBases.get(Definition->getASTContext().getExternalSource()); |
122 | } |
123 | |
124 | CXXRecordDecl::CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, |
125 | DeclContext *DC, SourceLocation StartLoc, |
126 | SourceLocation IdLoc, IdentifierInfo *Id, |
127 | CXXRecordDecl *PrevDecl) |
128 | : RecordDecl(K, TK, C, DC, StartLoc, IdLoc, Id, PrevDecl), |
129 | DefinitionData(PrevDecl ? PrevDecl->DefinitionData |
130 | : nullptr) {} |
131 | |
132 | CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK, |
133 | DeclContext *DC, SourceLocation StartLoc, |
134 | SourceLocation IdLoc, IdentifierInfo *Id, |
135 | CXXRecordDecl *PrevDecl, |
136 | bool DelayTypeCreation) { |
137 | auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, C, DC, StartLoc, IdLoc, Id, |
138 | PrevDecl); |
139 | R->setMayHaveOutOfDateDef(C.getLangOpts().Modules); |
140 | |
141 | |
142 | if (!DelayTypeCreation) |
143 | C.getTypeDeclType(R, PrevDecl); |
144 | return R; |
145 | } |
146 | |
147 | CXXRecordDecl * |
148 | CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC, |
149 | TypeSourceInfo *Info, SourceLocation Loc, |
150 | bool Dependent, bool IsGeneric, |
151 | LambdaCaptureDefault CaptureDefault) { |
152 | auto *R = new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, C, DC, Loc, Loc, |
153 | nullptr, nullptr); |
154 | R->setBeingDefined(true); |
155 | R->DefinitionData = |
156 | new (C) struct LambdaDefinitionData(R, Info, Dependent, IsGeneric, |
157 | CaptureDefault); |
158 | R->setMayHaveOutOfDateDef(false); |
159 | R->setImplicit(true); |
160 | C.getTypeDeclType(R, nullptr); |
161 | return R; |
162 | } |
163 | |
164 | CXXRecordDecl * |
165 | CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) { |
166 | auto *R = new (C, ID) CXXRecordDecl( |
167 | CXXRecord, TTK_Struct, C, nullptr, SourceLocation(), SourceLocation(), |
168 | nullptr, nullptr); |
169 | R->setMayHaveOutOfDateDef(false); |
170 | return R; |
171 | } |
172 | |
173 | |
174 | |
175 | |
176 | static bool hasRepeatedBaseClass(const CXXRecordDecl *StartRD) { |
177 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> SeenBaseTypes; |
178 | SmallVector<const CXXRecordDecl*, 8> WorkList = {StartRD}; |
179 | while (!WorkList.empty()) { |
180 | const CXXRecordDecl *RD = WorkList.pop_back_val(); |
181 | for (const CXXBaseSpecifier &BaseSpec : RD->bases()) { |
182 | if (const CXXRecordDecl *B = BaseSpec.getType()->getAsCXXRecordDecl()) { |
183 | if (!SeenBaseTypes.insert(B).second) |
184 | return true; |
185 | WorkList.push_back(B); |
186 | } |
187 | } |
188 | } |
189 | return false; |
190 | } |
191 | |
192 | void |
193 | CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases, |
194 | unsigned NumBases) { |
195 | ASTContext &C = getASTContext(); |
196 | |
197 | if (!data().Bases.isOffset() && data().NumBases > 0) |
198 | C.Deallocate(data().getBases()); |
199 | |
200 | if (NumBases) { |
201 | if (!C.getLangOpts().CPlusPlus17) { |
202 | |
203 | |
204 | data().Aggregate = false; |
205 | } |
206 | |
207 | |
208 | |
209 | data().PlainOldData = false; |
210 | } |
211 | |
212 | |
213 | llvm::SmallPtrSet<CanQualType, 8> SeenVBaseTypes; |
214 | |
215 | |
216 | SmallVector<const CXXBaseSpecifier *, 8> VBases; |
217 | |
218 | data().Bases = new(C) CXXBaseSpecifier [NumBases]; |
219 | data().NumBases = NumBases; |
220 | for (unsigned i = 0; i < NumBases; ++i) { |
221 | data().getBases()[i] = *Bases[i]; |
222 | |
223 | const CXXBaseSpecifier *Base = Bases[i]; |
224 | QualType BaseType = Base->getType(); |
225 | |
226 | if (BaseType->isDependentType()) |
227 | continue; |
228 | auto *BaseClassDecl = |
229 | cast<CXXRecordDecl>(BaseType->castAs<RecordType>()->getDecl()); |
230 | |
231 | |
232 | |
233 | |
234 | |
235 | |
236 | if (BaseClassDecl->data().HasBasesWithFields || |
237 | !BaseClassDecl->field_empty()) { |
238 | if (data().HasBasesWithFields) |
239 | |
240 | data().IsStandardLayout = false; |
241 | data().HasBasesWithFields = true; |
242 | } |
243 | |
244 | |
245 | |
246 | |
247 | |
248 | if (BaseClassDecl->data().HasBasesWithNonStaticDataMembers || |
249 | BaseClassDecl->hasDirectFields()) { |
250 | if (data().HasBasesWithNonStaticDataMembers) |
251 | data().IsCXX11StandardLayout = false; |
252 | data().HasBasesWithNonStaticDataMembers = true; |
253 | } |
254 | |
255 | if (!BaseClassDecl->isEmpty()) { |
256 | |
257 | |
258 | |
259 | data().Empty = false; |
260 | } |
261 | |
262 | |
263 | |
264 | if (Base->getAccessSpecifier() != AS_public) { |
265 | data().Aggregate = false; |
266 | |
267 | |
268 | |
269 | |
270 | data().StructuralIfLiteral = false; |
271 | } |
272 | |
273 | |
274 | |
275 | |
276 | if (BaseClassDecl->isPolymorphic()) { |
277 | data().Polymorphic = true; |
278 | |
279 | |
280 | data().Aggregate = false; |
281 | } |
282 | |
283 | |
284 | |
285 | |
286 | if (!BaseClassDecl->isStandardLayout()) |
287 | data().IsStandardLayout = false; |
288 | if (!BaseClassDecl->isCXX11StandardLayout()) |
289 | data().IsCXX11StandardLayout = false; |
290 | |
291 | |
292 | if (!hasNonLiteralTypeFieldsOrBases() && !BaseType->isLiteralType(C)) |
293 | data().HasNonLiteralTypeFieldsOrBases = true; |
294 | |
295 | |
296 | for (const auto &VBase : BaseClassDecl->vbases()) { |
297 | |
298 | if (SeenVBaseTypes.insert(C.getCanonicalType(VBase.getType())).second) { |
299 | VBases.push_back(&VBase); |
300 | |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | if (CXXRecordDecl *VBaseDecl = VBase.getType()->getAsCXXRecordDecl()) |
307 | if (!VBaseDecl->hasCopyConstructorWithConstParam()) |
308 | data().ImplicitCopyConstructorCanHaveConstParamForVBase = false; |
309 | |
310 | |
311 | |
312 | data().Aggregate = false; |
313 | } |
314 | } |
315 | |
316 | if (Base->isVirtual()) { |
317 | |
318 | if (SeenVBaseTypes.insert(C.getCanonicalType(BaseType)).second) |
319 | VBases.push_back(Base); |
320 | |
321 | |
322 | |
323 | |
324 | data().Empty = false; |
325 | |
326 | |
327 | |
328 | data().Aggregate = false; |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | data().HasTrivialSpecialMembers &= SMF_Destructor; |
335 | data().HasTrivialSpecialMembersForCall &= SMF_Destructor; |
336 | |
337 | |
338 | |
339 | |
340 | data().IsStandardLayout = false; |
341 | data().IsCXX11StandardLayout = false; |
342 | |
343 | |
344 | |
345 | |
346 | |
347 | data().DefaultedDefaultConstructorIsConstexpr = false; |
348 | data().DefaultedDestructorIsConstexpr = false; |
349 | |
350 | |
351 | |
352 | |
353 | |
354 | |
355 | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) |
356 | data().ImplicitCopyConstructorCanHaveConstParamForVBase = false; |
357 | } else { |
358 | |
359 | |
360 | |
361 | |
362 | if (!BaseClassDecl->hasTrivialDefaultConstructor()) |
363 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | |
370 | if (!BaseClassDecl->hasTrivialCopyConstructor()) |
371 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
372 | |
373 | if (!BaseClassDecl->hasTrivialCopyConstructorForCall()) |
374 | data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor; |
375 | |
376 | |
377 | |
378 | |
379 | |
380 | if (!BaseClassDecl->hasTrivialMoveConstructor()) |
381 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
382 | |
383 | if (!BaseClassDecl->hasTrivialMoveConstructorForCall()) |
384 | data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor; |
385 | |
386 | |
387 | |
388 | |
389 | |
390 | |
391 | if (!BaseClassDecl->hasTrivialCopyAssignment()) |
392 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
393 | |
394 | |
395 | |
396 | |
397 | if (!BaseClassDecl->hasTrivialMoveAssignment()) |
398 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
399 | |
400 | |
401 | |
402 | |
403 | |
404 | if (!BaseClassDecl->hasConstexprDefaultConstructor()) |
405 | data().DefaultedDefaultConstructorIsConstexpr = false; |
406 | |
407 | |
408 | |
409 | |
410 | |
411 | |
412 | if (!BaseClassDecl->hasCopyConstructorWithConstParam()) |
413 | data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false; |
414 | } |
415 | |
416 | |
417 | |
418 | |
419 | if (!BaseClassDecl->hasTrivialDestructor()) |
420 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
421 | |
422 | if (!BaseClassDecl->hasTrivialDestructorForCall()) |
423 | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; |
424 | |
425 | if (!BaseClassDecl->hasIrrelevantDestructor()) |
426 | data().HasIrrelevantDestructor = false; |
427 | |
428 | if (BaseClassDecl->isAnyDestructorNoReturn()) |
429 | data().IsAnyDestructorNoReturn = true; |
430 | |
431 | |
432 | |
433 | |
434 | |
435 | |
436 | if (!BaseClassDecl->hasCopyAssignmentWithConstParam()) |
437 | data().ImplicitCopyAssignmentHasConstParam = false; |
438 | |
439 | |
440 | |
441 | if (BaseClassDecl->hasObjectMember()) |
442 | setHasObjectMember(true); |
443 | |
444 | if (BaseClassDecl->hasVolatileMember()) |
445 | setHasVolatileMember(true); |
446 | |
447 | if (BaseClassDecl->getArgPassingRestrictions() == |
448 | RecordDecl::APK_CanNeverPassInRegs) |
449 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); |
450 | |
451 | |
452 | if (BaseClassDecl->hasMutableFields()) |
453 | data().HasMutableFields = true; |
454 | |
455 | if (BaseClassDecl->hasUninitializedReferenceMember()) |
456 | data().HasUninitializedReferenceMember = true; |
457 | |
458 | if (!BaseClassDecl->allowConstDefaultInit()) |
459 | data().HasUninitializedFields = true; |
460 | |
461 | addedClassSubobject(BaseClassDecl); |
462 | } |
463 | |
464 | |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | if (data().IsStandardLayout && NumBases > 1 && hasRepeatedBaseClass(this)) |
472 | data().IsStandardLayout = false; |
473 | |
474 | if (VBases.empty()) { |
475 | data().IsParsingBaseSpecifiers = false; |
476 | return; |
477 | } |
478 | |
479 | |
480 | data().VBases = new (C) CXXBaseSpecifier[VBases.size()]; |
481 | data().NumVBases = VBases.size(); |
482 | for (int I = 0, E = VBases.size(); I != E; ++I) { |
483 | QualType Type = VBases[I]->getType(); |
484 | if (!Type->isDependentType()) |
485 | addedClassSubobject(Type->getAsCXXRecordDecl()); |
486 | data().getVBases()[I] = *VBases[I]; |
487 | } |
488 | |
489 | data().IsParsingBaseSpecifiers = false; |
490 | } |
491 | |
492 | unsigned CXXRecordDecl::getODRHash() const { |
493 | assert(hasDefinition() && "ODRHash only for records with definitions"); |
494 | |
495 | |
496 | if (DefinitionData->HasODRHash) |
497 | return DefinitionData->ODRHash; |
498 | |
499 | |
500 | ODRHash Hash; |
501 | Hash.AddCXXRecordDecl(getDefinition()); |
502 | DefinitionData->HasODRHash = true; |
503 | DefinitionData->ODRHash = Hash.CalculateHash(); |
504 | |
505 | return DefinitionData->ODRHash; |
506 | } |
507 | |
508 | void CXXRecordDecl::addedClassSubobject(CXXRecordDecl *Subobj) { |
509 | |
510 | |
511 | |
512 | |
513 | |
514 | |
515 | if (!Subobj->hasSimpleCopyConstructor()) |
516 | data().NeedOverloadResolutionForCopyConstructor = true; |
517 | if (!Subobj->hasSimpleMoveConstructor()) |
518 | data().NeedOverloadResolutionForMoveConstructor = true; |
519 | |
520 | |
521 | |
522 | |
523 | |
524 | |
525 | |
526 | if (!Subobj->hasSimpleCopyAssignment()) |
527 | data().NeedOverloadResolutionForCopyAssignment = true; |
528 | if (!Subobj->hasSimpleMoveAssignment()) |
529 | data().NeedOverloadResolutionForMoveAssignment = true; |
530 | |
531 | |
532 | |
533 | |
534 | |
535 | |
536 | |
537 | |
538 | if (!Subobj->hasSimpleDestructor()) { |
539 | data().NeedOverloadResolutionForCopyConstructor = true; |
540 | data().NeedOverloadResolutionForMoveConstructor = true; |
541 | data().NeedOverloadResolutionForDestructor = true; |
542 | } |
543 | |
544 | |
545 | |
546 | |
547 | |
548 | |
549 | if (!Subobj->hasConstexprDestructor()) |
550 | data().DefaultedDestructorIsConstexpr = false; |
551 | |
552 | |
553 | |
554 | |
555 | |
556 | if (!Subobj->data().StructuralIfLiteral) |
557 | data().StructuralIfLiteral = false; |
558 | } |
559 | |
560 | bool CXXRecordDecl::hasConstexprDestructor() const { |
561 | auto *Dtor = getDestructor(); |
562 | return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr(); |
563 | } |
564 | |
565 | bool CXXRecordDecl::hasAnyDependentBases() const { |
566 | if (!isDependentContext()) |
567 | return false; |
568 | |
569 | return !forallBases([](const CXXRecordDecl *) { return true; }); |
570 | } |
571 | |
572 | bool CXXRecordDecl::isTriviallyCopyable() const { |
573 | |
574 | |
575 | |
576 | if (hasNonTrivialCopyConstructor()) return false; |
577 | |
578 | if (hasNonTrivialMoveConstructor()) return false; |
579 | |
580 | if (hasNonTrivialCopyAssignment()) return false; |
581 | |
582 | if (hasNonTrivialMoveAssignment()) return false; |
583 | |
584 | if (!hasTrivialDestructor()) return false; |
585 | |
586 | return true; |
587 | } |
588 | |
589 | void CXXRecordDecl::markedVirtualFunctionPure() { |
590 | |
591 | |
592 | data().Abstract = true; |
593 | } |
594 | |
595 | bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType( |
596 | ASTContext &Ctx, const CXXRecordDecl *XFirst) { |
597 | if (!getNumBases()) |
598 | return false; |
599 | |
600 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> Bases; |
601 | llvm::SmallPtrSet<const CXXRecordDecl*, 8> M; |
602 | SmallVector<const CXXRecordDecl*, 8> WorkList; |
603 | |
604 | |
605 | auto Visit = [&](const CXXRecordDecl *RD) -> bool { |
606 | RD = RD->getCanonicalDecl(); |
607 | |
608 | |
609 | |
610 | |
611 | |
612 | |
613 | |
614 | if (!RD->data().HasBasesWithFields) { |
615 | |
616 | |
617 | if (Bases.empty()) { |
618 | bool RDIsBase = !forallBases([&](const CXXRecordDecl *Base) -> bool { |
619 | Base = Base->getCanonicalDecl(); |
620 | if (RD == Base) |
621 | return false; |
622 | Bases.insert(Base); |
623 | return true; |
624 | }); |
625 | if (RDIsBase) |
626 | return true; |
627 | } else { |
628 | if (Bases.count(RD)) |
629 | return true; |
630 | } |
631 | } |
632 | |
633 | if (M.insert(RD).second) |
634 | WorkList.push_back(RD); |
635 | return false; |
636 | }; |
637 | |
638 | if (Visit(XFirst)) |
639 | return true; |
640 | |
641 | while (!WorkList.empty()) { |
642 | const CXXRecordDecl *X = WorkList.pop_back_val(); |
643 | |
644 | |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | bool IsFirstField = true; |
652 | for (auto *FD : X->fields()) { |
653 | |
654 | |
655 | if (FD->isUnnamedBitfield()) |
656 | continue; |
657 | |
658 | if (!IsFirstField && !FD->isZeroSize(Ctx)) |
659 | continue; |
660 | |
661 | |
662 | QualType T = Ctx.getBaseElementType(FD->getType()); |
663 | if (auto *RD = T->getAsCXXRecordDecl()) |
664 | if (Visit(RD)) |
665 | return true; |
666 | |
667 | if (!X->isUnion()) |
668 | IsFirstField = false; |
669 | } |
670 | } |
671 | |
672 | return false; |
673 | } |
674 | |
675 | bool CXXRecordDecl::lambdaIsDefaultConstructibleAndAssignable() const { |
676 | assert(isLambda() && "not a lambda"); |
677 | |
678 | |
679 | |
680 | |
681 | |
682 | |
683 | |
684 | |
685 | |
686 | |
687 | |
688 | if (getLambdaCaptureDefault() != LCD_None || capture_size() != 0) |
689 | return false; |
690 | return getASTContext().getLangOpts().CPlusPlus20; |
691 | } |
692 | |
693 | void CXXRecordDecl::addedMember(Decl *D) { |
694 | if (!D->isImplicit() && |
695 | !isa<FieldDecl>(D) && |
696 | !isa<IndirectFieldDecl>(D) && |
697 | (!isa<TagDecl>(D) || cast<TagDecl>(D)->getTagKind() == TTK_Class || |
698 | cast<TagDecl>(D)->getTagKind() == TTK_Interface)) |
699 | data().HasOnlyCMembers = false; |
700 | |
701 | |
702 | if (D->getFriendObjectKind() || D->isInvalidDecl()) |
703 | return; |
704 | |
705 | auto *FunTmpl = dyn_cast<FunctionTemplateDecl>(D); |
706 | if (FunTmpl) |
707 | D = FunTmpl->getTemplatedDecl(); |
708 | |
709 | |
710 | Decl *DUnderlying = D; |
711 | if (auto *ND = dyn_cast<NamedDecl>(DUnderlying)) { |
712 | DUnderlying = ND->getUnderlyingDecl(); |
713 | if (auto *UnderlyingFunTmpl = dyn_cast<FunctionTemplateDecl>(DUnderlying)) |
714 | DUnderlying = UnderlyingFunTmpl->getTemplatedDecl(); |
715 | } |
716 | |
717 | if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
718 | if (Method->isVirtual()) { |
719 | |
720 | |
721 | data().Aggregate = false; |
722 | |
723 | |
724 | |
725 | data().PlainOldData = false; |
726 | |
727 | |
728 | |
729 | data().Empty = false; |
730 | |
731 | |
732 | |
733 | |
734 | data().Polymorphic = true; |
735 | |
736 | |
737 | |
738 | |
739 | |
740 | data().HasTrivialSpecialMembers &= SMF_Destructor; |
741 | data().HasTrivialSpecialMembersForCall &= SMF_Destructor; |
742 | |
743 | |
744 | |
745 | |
746 | data().IsStandardLayout = false; |
747 | data().IsCXX11StandardLayout = false; |
748 | } |
749 | } |
750 | |
751 | |
752 | |
753 | if (!isBeingDefined() && D->isImplicit()) |
754 | if (ASTMutationListener *L = getASTMutationListener()) |
755 | L->AddedCXXImplicitMember(data().Definition, D); |
756 | |
757 | |
758 | unsigned SMKind = 0; |
759 | |
760 | |
761 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
762 | if (Constructor->isInheritingConstructor()) { |
763 | |
764 | |
765 | } else { |
766 | if (!Constructor->isImplicit()) { |
767 | |
768 | data().UserDeclaredConstructor = true; |
769 | |
770 | |
771 | |
772 | |
773 | |
774 | |
775 | data().PlainOldData = false; |
776 | } |
777 | |
778 | if (Constructor->isDefaultConstructor()) { |
779 | SMKind |= SMF_DefaultConstructor; |
780 | |
781 | if (Constructor->isUserProvided()) |
782 | data().UserProvidedDefaultConstructor = true; |
783 | if (Constructor->isConstexpr()) |
784 | data().HasConstexprDefaultConstructor = true; |
785 | if (Constructor->isDefaulted()) |
786 | data().HasDefaultedDefaultConstructor = true; |
787 | } |
788 | |
789 | if (!FunTmpl) { |
790 | unsigned Quals; |
791 | if (Constructor->isCopyConstructor(Quals)) { |
792 | SMKind |= SMF_CopyConstructor; |
793 | |
794 | if (Quals & Qualifiers::Const) |
795 | data().HasDeclaredCopyConstructorWithConstParam = true; |
796 | } else if (Constructor->isMoveConstructor()) |
797 | SMKind |= SMF_MoveConstructor; |
798 | } |
799 | |
800 | |
801 | |
802 | |
803 | |
804 | |
805 | |
806 | if (getASTContext().getLangOpts().CPlusPlus20 |
807 | ? !Constructor->isImplicit() |
808 | : (Constructor->isUserProvided() || Constructor->isExplicit())) |
809 | data().Aggregate = false; |
810 | } |
811 | } |
812 | |
813 | |
814 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(DUnderlying)) { |
815 | |
816 | |
817 | |
818 | |
819 | |
820 | |
821 | if (Constructor->isConstexpr() && !Constructor->isCopyOrMoveConstructor()) |
822 | data().HasConstexprNonCopyMoveConstructor = true; |
823 | if (!isa<CXXConstructorDecl>(D) && Constructor->isDefaultConstructor()) |
824 | data().HasInheritedDefaultConstructor = true; |
825 | } |
826 | |
827 | |
828 | if (const auto *DD = dyn_cast<CXXDestructorDecl>(D)) { |
829 | SMKind |= SMF_Destructor; |
830 | |
831 | if (DD->isUserProvided()) |
832 | data().HasIrrelevantDestructor = false; |
833 | |
834 | |
835 | |
836 | |
837 | |
838 | |
839 | if (DD->isVirtual()) { |
840 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
841 | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; |
842 | } |
843 | |
844 | if (DD->isNoReturn()) |
845 | data().IsAnyDestructorNoReturn = true; |
846 | } |
847 | |
848 | |
849 | if (const auto *Method = dyn_cast<CXXMethodDecl>(D)) { |
850 | if (Method->isCopyAssignmentOperator()) { |
851 | SMKind |= SMF_CopyAssignment; |
852 | |
853 | const auto *ParamTy = |
854 | Method->getParamDecl(0)->getType()->getAs<ReferenceType>(); |
855 | if (!ParamTy || ParamTy->getPointeeType().isConstQualified()) |
856 | data().HasDeclaredCopyAssignmentWithConstParam = true; |
857 | } |
858 | |
859 | if (Method->isMoveAssignmentOperator()) |
860 | SMKind |= SMF_MoveAssignment; |
861 | |
862 | |
863 | if (auto *Conversion = dyn_cast<CXXConversionDecl>(D)) { |
864 | |
865 | |
866 | |
867 | |
868 | |
869 | |
870 | AccessSpecifier AS = Conversion->getAccessUnsafe(); |
871 | |
872 | if (Conversion->getPrimaryTemplate()) { |
873 | |
874 | } else { |
875 | ASTContext &Ctx = getASTContext(); |
876 | ASTUnresolvedSet &Conversions = data().Conversions.get(Ctx); |
877 | NamedDecl *Primary = |
878 | FunTmpl ? cast<NamedDecl>(FunTmpl) : cast<NamedDecl>(Conversion); |
879 | if (Primary->getPreviousDecl()) |
880 | Conversions.replace(cast<NamedDecl>(Primary->getPreviousDecl()), |
881 | Primary, AS); |
882 | else |
883 | Conversions.addDecl(Ctx, Primary, AS); |
884 | } |
885 | } |
886 | |
887 | if (SMKind) { |
888 | |
889 | |
890 | data().HasTrivialSpecialMembers &= |
891 | data().DeclaredSpecialMembers | ~SMKind; |
892 | data().HasTrivialSpecialMembersForCall &= |
893 | data().DeclaredSpecialMembers | ~SMKind; |
894 | |
895 | if (!Method->isImplicit() && !Method->isUserProvided()) { |
896 | |
897 | |
898 | |
899 | } else if (Method->isTrivial()) { |
900 | data().HasTrivialSpecialMembers |= SMKind; |
901 | data().HasTrivialSpecialMembersForCall |= SMKind; |
902 | } else if (Method->isTrivialForCall()) { |
903 | data().HasTrivialSpecialMembersForCall |= SMKind; |
904 | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
905 | } else { |
906 | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
907 | |
908 | |
909 | |
910 | |
911 | |
912 | if (!Method->isUserProvided()) |
913 | data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; |
914 | } |
915 | |
916 | |
917 | |
918 | data().DeclaredSpecialMembers |= SMKind; |
919 | |
920 | if (!Method->isImplicit()) { |
921 | data().UserDeclaredSpecialMembers |= SMKind; |
922 | |
923 | |
924 | |
925 | |
926 | |
927 | |
928 | |
929 | |
930 | |
931 | |
932 | |
933 | |
934 | data().PlainOldData = false; |
935 | } |
936 | } |
937 | |
938 | return; |
939 | } |
940 | |
941 | |
942 | if (const auto *Field = dyn_cast<FieldDecl>(D)) { |
943 | ASTContext &Context = getASTContext(); |
944 | |
945 | |
946 | |
947 | |
948 | |
949 | |
950 | if (data().HasBasesWithFields) |
951 | data().IsStandardLayout = false; |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | if (Field->isUnnamedBitfield()) { |
958 | |
959 | |
960 | |
961 | if (data().Empty && !Field->isZeroLengthBitField(Context) && |
962 | Context.getLangOpts().getClangABICompat() > |
963 | LangOptions::ClangABI::Ver6) |
964 | data().Empty = false; |
965 | return; |
966 | } |
967 | |
968 | |
969 | |
970 | |
971 | |
972 | if (data().HasBasesWithNonStaticDataMembers) |
973 | data().IsCXX11StandardLayout = false; |
974 | |
975 | |
976 | |
977 | |
978 | |
979 | |
980 | if (D->getAccess() == AS_private || D->getAccess() == AS_protected) { |
981 | data().Aggregate = false; |
982 | data().PlainOldData = false; |
983 | |
984 | |
985 | |
986 | |
987 | data().StructuralIfLiteral = false; |
988 | } |
989 | |
990 | |
991 | |
992 | bool IsFirstField = !data().HasPrivateFields && |
993 | !data().HasProtectedFields && !data().HasPublicFields; |
994 | |
995 | |
996 | |
997 | |
998 | |
999 | switch (D->getAccess()) { |
1000 | case AS_private: data().HasPrivateFields = true; break; |
1001 | case AS_protected: data().HasProtectedFields = true; break; |
1002 | case AS_public: data().HasPublicFields = true; break; |
1003 | case AS_none: llvm_unreachable("Invalid access specifier"); |
1004 | }; |
1005 | if ((data().HasPrivateFields + data().HasProtectedFields + |
1006 | data().HasPublicFields) > 1) { |
1007 | data().IsStandardLayout = false; |
1008 | data().IsCXX11StandardLayout = false; |
1009 | } |
1010 | |
1011 | |
1012 | if (Field->isMutable()) { |
1013 | data().HasMutableFields = true; |
1014 | |
1015 | |
1016 | |
1017 | |
1018 | data().StructuralIfLiteral = false; |
1019 | } |
1020 | |
1021 | |
1022 | |
1023 | |
1024 | if (isUnion() && !Field->isAnonymousStructOrUnion()) |
1025 | data().HasVariantMembers = true; |
1026 | |
1027 | |
1028 | |
1029 | |
1030 | |
1031 | |
1032 | |
1033 | |
1034 | QualType T = Context.getBaseElementType(Field->getType()); |
1035 | if (T->isObjCRetainableType() || T.isObjCGCStrong()) { |
1036 | if (T.hasNonTrivialObjCLifetime()) { |
1037 | |
1038 | |
1039 | |
1040 | |
1041 | |
1042 | |
1043 | setHasObjectMember(true); |
1044 | struct DefinitionData &Data = data(); |
1045 | Data.PlainOldData = false; |
1046 | Data.HasTrivialSpecialMembers = 0; |
1047 | |
1048 | |
1049 | |
1050 | Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime(); |
1051 | if (LT != Qualifiers::OCL_Strong && LT != Qualifiers::OCL_Weak) |
1052 | data().HasTrivialSpecialMembersForCall = 0; |
1053 | |
1054 | |
1055 | if (LT == Qualifiers::OCL_Weak) |
1056 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); |
1057 | |
1058 | Data.HasIrrelevantDestructor = false; |
1059 | |
1060 | if (isUnion()) { |
1061 | data().DefaultedCopyConstructorIsDeleted = true; |
1062 | data().DefaultedMoveConstructorIsDeleted = true; |
1063 | data().DefaultedCopyAssignmentIsDeleted = true; |
1064 | data().DefaultedMoveAssignmentIsDeleted = true; |
1065 | data().DefaultedDestructorIsDeleted = true; |
1066 | data().NeedOverloadResolutionForCopyConstructor = true; |
1067 | data().NeedOverloadResolutionForMoveConstructor = true; |
1068 | data().NeedOverloadResolutionForCopyAssignment = true; |
1069 | data().NeedOverloadResolutionForMoveAssignment = true; |
1070 | data().NeedOverloadResolutionForDestructor = true; |
1071 | } |
1072 | } else if (!Context.getLangOpts().ObjCAutoRefCount) { |
1073 | setHasObjectMember(true); |
1074 | } |
1075 | } else if (!T.isCXX98PODType(Context)) |
1076 | data().PlainOldData = false; |
1077 | |
1078 | if (T->isReferenceType()) { |
1079 | if (!Field->hasInClassInitializer()) |
1080 | data().HasUninitializedReferenceMember = true; |
1081 | |
1082 | |
1083 | |
1084 | |
1085 | data().IsStandardLayout = false; |
1086 | data().IsCXX11StandardLayout = false; |
1087 | |
1088 | |
1089 | |
1090 | |
1091 | if (T->isRValueReferenceType()) |
1092 | data().DefaultedCopyConstructorIsDeleted = true; |
1093 | } |
1094 | |
1095 | if (!Field->hasInClassInitializer() && !Field->isMutable()) { |
1096 | if (CXXRecordDecl *FieldType = T->getAsCXXRecordDecl()) { |
1097 | if (FieldType->hasDefinition() && !FieldType->allowConstDefaultInit()) |
1098 | data().HasUninitializedFields = true; |
1099 | } else { |
1100 | data().HasUninitializedFields = true; |
1101 | } |
1102 | } |
1103 | |
1104 | |
1105 | if (!T->isLiteralType(Context) || T.isVolatileQualified()) |
1106 | data().HasNonLiteralTypeFieldsOrBases = true; |
1107 | |
1108 | if (Field->hasInClassInitializer() || |
1109 | (Field->isAnonymousStructOrUnion() && |
1110 | Field->getType()->getAsCXXRecordDecl()->hasInClassInitializer())) { |
1111 | data().HasInClassInitializer = true; |
1112 | |
1113 | |
1114 | |
1115 | |
1116 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
1117 | |
1118 | |
1119 | |
1120 | |
1121 | |
1122 | |
1123 | if (!getASTContext().getLangOpts().CPlusPlus14) |
1124 | data().Aggregate = false; |
1125 | |
1126 | |
1127 | |
1128 | data().PlainOldData = false; |
1129 | } |
1130 | |
1131 | |
1132 | |
1133 | |
1134 | |
1135 | if (T->isReferenceType()) { |
1136 | data().DefaultedCopyAssignmentIsDeleted = true; |
1137 | data().DefaultedMoveAssignmentIsDeleted = true; |
1138 | } |
1139 | |
1140 | |
1141 | |
1142 | bool IsZeroSize = Field->isZeroSize(Context); |
1143 | |
1144 | if (const auto *RecordTy = T->getAs<RecordType>()) { |
1145 | auto *FieldRec = cast<CXXRecordDecl>(RecordTy->getDecl()); |
1146 | if (FieldRec->getDefinition()) { |
1147 | addedClassSubobject(FieldRec); |
1148 | |
1149 | |
1150 | |
1151 | if (T.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile)) { |
1152 | |
1153 | |
1154 | |
1155 | data().NeedOverloadResolutionForCopyConstructor = true; |
1156 | data().NeedOverloadResolutionForMoveConstructor = true; |
1157 | data().NeedOverloadResolutionForCopyAssignment = true; |
1158 | data().NeedOverloadResolutionForMoveAssignment = true; |
1159 | } |
1160 | |
1161 | |
1162 | |
1163 | |
1164 | |
1165 | |
1166 | if (isUnion()) { |
1167 | if (FieldRec->hasNonTrivialCopyConstructor()) |
1168 | data().DefaultedCopyConstructorIsDeleted = true; |
1169 | if (FieldRec->hasNonTrivialMoveConstructor()) |
1170 | data().DefaultedMoveConstructorIsDeleted = true; |
1171 | if (FieldRec->hasNonTrivialCopyAssignment()) |
1172 | data().DefaultedCopyAssignmentIsDeleted = true; |
1173 | if (FieldRec->hasNonTrivialMoveAssignment()) |
1174 | data().DefaultedMoveAssignmentIsDeleted = true; |
1175 | if (FieldRec->hasNonTrivialDestructor()) |
1176 | data().DefaultedDestructorIsDeleted = true; |
1177 | } |
1178 | |
1179 | |
1180 | |
1181 | if (Field->isAnonymousStructOrUnion()) { |
1182 | data().NeedOverloadResolutionForCopyConstructor |= |
1183 | FieldRec->data().NeedOverloadResolutionForCopyConstructor; |
1184 | data().NeedOverloadResolutionForMoveConstructor |= |
1185 | FieldRec->data().NeedOverloadResolutionForMoveConstructor; |
1186 | data().NeedOverloadResolutionForCopyAssignment |= |
1187 | FieldRec->data().NeedOverloadResolutionForCopyAssignment; |
1188 | data().NeedOverloadResolutionForMoveAssignment |= |
1189 | FieldRec->data().NeedOverloadResolutionForMoveAssignment; |
1190 | data().NeedOverloadResolutionForDestructor |= |
1191 | FieldRec->data().NeedOverloadResolutionForDestructor; |
1192 | } |
1193 | |
1194 | |
1195 | |
1196 | |
1197 | |
1198 | |
1199 | if (!FieldRec->hasTrivialDefaultConstructor()) |
1200 | data().HasTrivialSpecialMembers &= ~SMF_DefaultConstructor; |
1201 | |
1202 | |
1203 | |
1204 | |
1205 | |
1206 | |
1207 | |
1208 | if (!FieldRec->hasTrivialCopyConstructor()) |
1209 | data().HasTrivialSpecialMembers &= ~SMF_CopyConstructor; |
1210 | |
1211 | if (!FieldRec->hasTrivialCopyConstructorForCall()) |
1212 | data().HasTrivialSpecialMembersForCall &= ~SMF_CopyConstructor; |
1213 | |
1214 | |
1215 | |
1216 | |
1217 | if (!FieldRec->hasTrivialMoveConstructor()) |
1218 | data().HasTrivialSpecialMembers &= ~SMF_MoveConstructor; |
1219 | |
1220 | if (!FieldRec->hasTrivialMoveConstructorForCall()) |
1221 | data().HasTrivialSpecialMembersForCall &= ~SMF_MoveConstructor; |
1222 | |
1223 | |
1224 | |
1225 | |
1226 | |
1227 | |
1228 | |
1229 | if (!FieldRec->hasTrivialCopyAssignment()) |
1230 | data().HasTrivialSpecialMembers &= ~SMF_CopyAssignment; |
1231 | |
1232 | |
1233 | |
1234 | if (!FieldRec->hasTrivialMoveAssignment()) |
1235 | data().HasTrivialSpecialMembers &= ~SMF_MoveAssignment; |
1236 | |
1237 | if (!FieldRec->hasTrivialDestructor()) |
1238 | data().HasTrivialSpecialMembers &= ~SMF_Destructor; |
1239 | if (!FieldRec->hasTrivialDestructorForCall()) |
1240 | data().HasTrivialSpecialMembersForCall &= ~SMF_Destructor; |
1241 | if (!FieldRec->hasIrrelevantDestructor()) |
1242 | data().HasIrrelevantDestructor = false; |
1243 | if (FieldRec->isAnyDestructorNoReturn()) |
1244 | data().IsAnyDestructorNoReturn = true; |
1245 | if (FieldRec->hasObjectMember()) |
1246 | setHasObjectMember(true); |
1247 | if (FieldRec->hasVolatileMember()) |
1248 | setHasVolatileMember(true); |
1249 | if (FieldRec->getArgPassingRestrictions() == |
1250 | RecordDecl::APK_CanNeverPassInRegs) |
1251 | setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs); |
1252 | |
1253 | |
1254 | |
1255 | |
1256 | |
1257 | if (!FieldRec->isStandardLayout()) |
1258 | data().IsStandardLayout = false; |
1259 | if (!FieldRec->isCXX11StandardLayout()) |
1260 | data().IsCXX11StandardLayout = false; |
1261 | |
1262 | |
1263 | |
1264 | |
1265 | |
1266 | if (data().IsStandardLayout && |
1267 | (isUnion() || IsFirstField || IsZeroSize) && |
1268 | hasSubobjectAtOffsetZeroOfEmptyBaseType(Context, FieldRec)) |
1269 | data().IsStandardLayout = false; |
1270 | |
1271 | |
1272 | |
1273 | |
1274 | |
1275 | if (data().IsCXX11StandardLayout && IsFirstField) { |
1276 | |
1277 | |
1278 | for (const auto &BI : bases()) { |
1279 | if (Context.hasSameUnqualifiedType(BI.getType(), T)) { |
1280 | data().IsCXX11StandardLayout = false; |
1281 | break; |
1282 | } |
1283 | } |
1284 | } |
1285 | |
1286 | |
1287 | if (FieldRec->hasMutableFields()) |
1288 | data().HasMutableFields = true; |
1289 | |
1290 | if (Field->isMutable()) { |
1291 | |
1292 | |
1293 | |
1294 | data().NeedOverloadResolutionForCopyConstructor = true; |
1295 | data().NeedOverloadResolutionForCopyAssignment = true; |
1296 | } |
1297 | |
1298 | |
1299 | |
1300 | |
1301 | |
1302 | |
1303 | |
1304 | |
1305 | if (!Field->hasInClassInitializer() && |
1306 | !FieldRec->hasConstexprDefaultConstructor() && !isUnion()) |
1307 | |
1308 | |
1309 | data().DefaultedDefaultConstructorIsConstexpr = false; |
1310 | |
1311 | |
1312 | |
1313 | |
1314 | |
1315 | |
1316 | if (!FieldRec->hasCopyConstructorWithConstParam()) |
1317 | data().ImplicitCopyConstructorCanHaveConstParamForNonVBase = false; |
1318 | |
1319 | |
1320 | |
1321 | |
1322 | |
1323 | |
1324 | |
1325 | if (!FieldRec->hasCopyAssignmentWithConstParam()) |
1326 | data().ImplicitCopyAssignmentHasConstParam = false; |
1327 | |
1328 | if (FieldRec->hasUninitializedReferenceMember() && |
1329 | !Field->hasInClassInitializer()) |
1330 | data().HasUninitializedReferenceMember = true; |
1331 | |
1332 | |
1333 | |
1334 | |
1335 | if (FieldRec->hasVariantMembers() && |
1336 | Field->isAnonymousStructOrUnion()) |
1337 | data().HasVariantMembers = true; |
1338 | } |
1339 | } else { |
1340 | |
1341 | if (!T->isLiteralType(Context) || |
1342 | (!Field->hasInClassInitializer() && !isUnion() && |
1343 | !Context.getLangOpts().CPlusPlus20)) |
1344 | data().DefaultedDefaultConstructorIsConstexpr = false; |
1345 | |
1346 | |
1347 | |
1348 | |
1349 | |
1350 | |
1351 | if (T.isConstQualified()) { |
1352 | data().DefaultedCopyAssignmentIsDeleted = true; |
1353 | data().DefaultedMoveAssignmentIsDeleted = true; |
1354 | } |
1355 | |
1356 | |
1357 | |
1358 | |
1359 | |
1360 | |
1361 | if (!T->isStructuralType()) |
1362 | data().StructuralIfLiteral = false; |
1363 | } |
1364 | |
1365 | |
1366 | |
1367 | |
1368 | if (data().Empty && !IsZeroSize) |
1369 | data().Empty = false; |
1370 | } |
1371 | |
1372 | |
1373 | if (auto *Shadow = dyn_cast<UsingShadowDecl>(D)) { |
1374 | if (Shadow->getDeclName().getNameKind() |
1375 | == DeclarationName::CXXConversionFunctionName) { |
1376 | ASTContext &Ctx = getASTContext(); |
1377 | data().Conversions.get(Ctx).addDecl(Ctx, Shadow, Shadow->getAccess()); |
1378 | } |
1379 | } |
1380 | |
1381 | if (const auto *Using = dyn_cast<UsingDecl>(D)) { |
1382 | if (Using->getDeclName().getNameKind() == |
1383 | DeclarationName::CXXConstructorName) { |
1384 | data().HasInheritedConstructor = true; |
1385 | |
1386 | |
1387 | data().Aggregate = false; |
1388 | } |
1389 | |
1390 | if (Using->getDeclName().getCXXOverloadedOperator() == OO_Equal) |
1391 | data().HasInheritedAssignment = true; |
1392 | } |
1393 | } |
1394 | |
1395 | void CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) { |
1396 | assert(!D->isImplicit() && !D->isUserProvided()); |
1397 | |
1398 | |
1399 | unsigned SMKind = 0; |
1400 | |
1401 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
1402 | if (Constructor->isDefaultConstructor()) { |
1403 | SMKind |= SMF_DefaultConstructor; |
1404 | if (Constructor->isConstexpr()) |
1405 | data().HasConstexprDefaultConstructor = true; |
1406 | } |
1407 | if (Constructor->isCopyConstructor()) |
1408 | SMKind |= SMF_CopyConstructor; |
1409 | else if (Constructor->isMoveConstructor()) |
1410 | SMKind |= SMF_MoveConstructor; |
1411 | else if (Constructor->isConstexpr()) |
1412 | |
1413 | data().HasConstexprNonCopyMoveConstructor = true; |
1414 | } else if (isa<CXXDestructorDecl>(D)) { |
1415 | SMKind |= SMF_Destructor; |
1416 | if (!D->isTrivial() || D->getAccess() != AS_public || D->isDeleted()) |
1417 | data().HasIrrelevantDestructor = false; |
1418 | } else if (D->isCopyAssignmentOperator()) |
1419 | SMKind |= SMF_CopyAssignment; |
1420 | else if (D->isMoveAssignmentOperator()) |
1421 | SMKind |= SMF_MoveAssignment; |
1422 | |
1423 | |
1424 | |
1425 | if (D->isTrivial()) |
1426 | data().HasTrivialSpecialMembers |= SMKind; |
1427 | else |
1428 | data().DeclaredNonTrivialSpecialMembers |= SMKind; |
1429 | } |
1430 | |
1431 | void CXXRecordDecl::setCaptures(ASTContext &Context, |
1432 | ArrayRef<LambdaCapture> Captures) { |
1433 | CXXRecordDecl::LambdaDefinitionData &Data = getLambdaData(); |
1434 | |
1435 | |
1436 | Data.NumCaptures = Captures.size(); |
1437 | Data.NumExplicitCaptures = 0; |
1438 | Data.Captures = (LambdaCapture *)Context.Allocate(sizeof(LambdaCapture) * |
1439 | Captures.size()); |
1440 | LambdaCapture *ToCapture = Data.Captures; |
1441 | for (unsigned I = 0, N = Captures.size(); I != N; ++I) { |
1442 | if (Captures[I].isExplicit()) |
1443 | ++Data.NumExplicitCaptures; |
1444 | |
1445 | *ToCapture++ = Captures[I]; |
1446 | } |
1447 | |
1448 | if (!lambdaIsDefaultConstructibleAndAssignable()) |
1449 | Data.DefaultedCopyAssignmentIsDeleted = true; |
1450 | } |
1451 | |
1452 | void CXXRecordDecl::setTrivialForCallFlags(CXXMethodDecl *D) { |
1453 | unsigned SMKind = 0; |
1454 | |
1455 | if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(D)) { |
1456 | if (Constructor->isCopyConstructor()) |
1457 | SMKind = SMF_CopyConstructor; |
1458 | else if (Constructor->isMoveConstructor()) |
1459 | SMKind = SMF_MoveConstructor; |
1460 | } else if (isa<CXXDestructorDecl>(D)) |
1461 | SMKind = SMF_Destructor; |
1462 | |
1463 | if (D->isTrivialForCall()) |
1464 | data().HasTrivialSpecialMembersForCall |= SMKind; |
1465 | else |
1466 | data().DeclaredNonTrivialSpecialMembersForCall |= SMKind; |
1467 | } |
1468 | |
1469 | bool CXXRecordDecl::isCLike() const { |
1470 | if (getTagKind() == TTK_Class || getTagKind() == TTK_Interface || |
1471 | !TemplateOrInstantiation.isNull()) |
1472 | return false; |
1473 | if (!hasDefinition()) |
1474 | return true; |
1475 | |
1476 | return isPOD() && data().HasOnlyCMembers; |
1477 | } |
1478 | |
1479 | bool CXXRecordDecl::isGenericLambda() const { |
1480 | if (!isLambda()) return false; |
1481 | return getLambdaData().IsGenericLambda; |
1482 | } |
1483 | |
1484 | #ifndef NDEBUG |
1485 | static bool allLookupResultsAreTheSame(const DeclContext::lookup_result &R) { |
1486 | for (auto *D : R) |
1487 | if (!declaresSameEntity(D, R.front())) |
1488 | return false; |
1489 | return true; |
1490 | } |
1491 | #endif |
1492 | |
1493 | static NamedDecl* getLambdaCallOperatorHelper(const CXXRecordDecl &RD) { |
1494 | if (!RD.isLambda()) return nullptr; |
1495 | DeclarationName Name = |
1496 | RD.getASTContext().DeclarationNames.getCXXOperatorName(OO_Call); |
1497 | DeclContext::lookup_result Calls = RD.lookup(Name); |
1498 | |
1499 | assert(!Calls.empty() && "Missing lambda call operator!"); |
1500 | assert(allLookupResultsAreTheSame(Calls) && |
1501 | "More than one lambda call operator!"); |
1502 | return Calls.front(); |
1503 | } |
1504 | |
1505 | FunctionTemplateDecl* CXXRecordDecl::getDependentLambdaCallOperator() const { |
1506 | NamedDecl *CallOp = getLambdaCallOperatorHelper(*this); |
1507 | return dyn_cast_or_null<FunctionTemplateDecl>(CallOp); |
1508 | } |
1509 | |
1510 | CXXMethodDecl *CXXRecordDecl::getLambdaCallOperator() const { |
1511 | NamedDecl *CallOp = getLambdaCallOperatorHelper(*this); |
1512 | |
1513 | if (CallOp == nullptr) |
1514 | return nullptr; |
1515 | |
1516 | if (const auto *CallOpTmpl = dyn_cast<FunctionTemplateDecl>(CallOp)) |
1517 | return cast<CXXMethodDecl>(CallOpTmpl->getTemplatedDecl()); |
1518 | |
1519 | return cast<CXXMethodDecl>(CallOp); |
1520 | } |
1521 | |
1522 | CXXMethodDecl* CXXRecordDecl::getLambdaStaticInvoker() const { |
1523 | CXXMethodDecl *CallOp = getLambdaCallOperator(); |
1524 | CallingConv CC = CallOp->getType()->castAs<FunctionType>()->getCallConv(); |
1525 | return getLambdaStaticInvoker(CC); |
1526 | } |
1527 | |
1528 | static DeclContext::lookup_result |
1529 | getLambdaStaticInvokers(const CXXRecordDecl &RD) { |
1530 | assert(RD.isLambda() && "Must be a lambda"); |
1531 | DeclarationName Name = |
1532 | &RD.getASTContext().Idents.get(getLambdaStaticInvokerName()); |
1533 | return RD.lookup(Name); |
1534 | } |
1535 | |
1536 | static CXXMethodDecl *getInvokerAsMethod(NamedDecl *ND) { |
1537 | if (const auto *InvokerTemplate = dyn_cast<FunctionTemplateDecl>(ND)) |
1538 | return cast<CXXMethodDecl>(InvokerTemplate->getTemplatedDecl()); |
1539 | return cast<CXXMethodDecl>(ND); |
1540 | } |
1541 | |
1542 | CXXMethodDecl *CXXRecordDecl::getLambdaStaticInvoker(CallingConv CC) const { |
1543 | if (!isLambda()) |
1544 | return nullptr; |
1545 | DeclContext::lookup_result Invoker = getLambdaStaticInvokers(*this); |
1546 | |
1547 | for (NamedDecl *ND : Invoker) { |
1548 | const auto *FTy = |
1549 | cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>(); |
1550 | if (FTy->getCallConv() == CC) |
1551 | return getInvokerAsMethod(ND); |
1552 | } |
1553 | |
1554 | return nullptr; |
1555 | } |
1556 | |
1557 | void CXXRecordDecl::getCaptureFields( |
1558 | llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1559 | FieldDecl *&ThisCapture) const { |
1560 | Captures.clear(); |
1561 | ThisCapture = nullptr; |
1562 | |
1563 | LambdaDefinitionData &Lambda = getLambdaData(); |
1564 | RecordDecl::field_iterator Field = field_begin(); |
1565 | for (const LambdaCapture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; |
1566 | C != CEnd; ++C, ++Field) { |
1567 | if (C->capturesThis()) |
1568 | ThisCapture = *Field; |
1569 | else if (C->capturesVariable()) |
1570 | Captures[C->getCapturedVar()] = *Field; |
1571 | } |
1572 | assert(Field == field_end()); |
1573 | } |
1574 | |
1575 | TemplateParameterList * |
1576 | CXXRecordDecl::getGenericLambdaTemplateParameterList() const { |
1577 | if (!isGenericLambda()) return nullptr; |
1578 | CXXMethodDecl *CallOp = getLambdaCallOperator(); |
1579 | if (FunctionTemplateDecl *Tmpl = CallOp->getDescribedFunctionTemplate()) |
1580 | return Tmpl->getTemplateParameters(); |
1581 | return nullptr; |
1582 | } |
1583 | |
1584 | ArrayRef<NamedDecl *> |
1585 | CXXRecordDecl::getLambdaExplicitTemplateParameters() const { |
1586 | TemplateParameterList *List = getGenericLambdaTemplateParameterList(); |
1587 | if (!List) |
1588 | return {}; |
1589 | |
1590 | assert(std::is_partitioned(List->begin(), List->end(), |
1591 | [](const NamedDecl *D) { return !D->isImplicit(); }) |
1592 | && "Explicit template params should be ordered before implicit ones"); |
1593 | |
1594 | const auto ExplicitEnd = llvm::partition_point( |
1595 | *List, [](const NamedDecl *D) { return !D->isImplicit(); }); |
1596 | return llvm::makeArrayRef(List->begin(), ExplicitEnd); |
1597 | } |
1598 | |
1599 | Decl *CXXRecordDecl::getLambdaContextDecl() const { |
1600 | assert(isLambda() && "Not a lambda closure type!"); |
1601 | ExternalASTSource *Source = getParentASTContext().getExternalSource(); |
1602 | return getLambdaData().ContextDecl.get(Source); |
1603 | } |
1604 | |
1605 | void CXXRecordDecl::setDeviceLambdaManglingNumber(unsigned Num) const { |
1606 | assert(isLambda() && "Not a lambda closure type!"); |
1607 | if (Num) |
1608 | getASTContext().DeviceLambdaManglingNumbers[this] = Num; |
1609 | } |
1610 | |
1611 | unsigned CXXRecordDecl::getDeviceLambdaManglingNumber() const { |
1612 | assert(isLambda() && "Not a lambda closure type!"); |
1613 | auto I = getASTContext().DeviceLambdaManglingNumbers.find(this); |
1614 | if (I != getASTContext().DeviceLambdaManglingNumbers.end()) |
1615 | return I->second; |
1616 | return 0; |
1617 | } |
1618 | |
1619 | static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) { |
1620 | QualType T = |
1621 | cast<CXXConversionDecl>(Conv->getUnderlyingDecl()->getAsFunction()) |
1622 | ->getConversionType(); |
1623 | return Context.getCanonicalType(T); |
1624 | } |
1625 | |
1626 | |
1627 | |
1628 | |
1629 | |
1630 | |
1631 | |
1632 | |
1633 | |
1634 | |
1635 | |
1636 | |
1637 | |
1638 | static void CollectVisibleConversions( |
1639 | ASTContext &Context, const CXXRecordDecl *Record, bool InVirtual, |
1640 | AccessSpecifier Access, |
1641 | const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes, |
1642 | ASTUnresolvedSet &Output, UnresolvedSetImpl &VOutput, |
1643 | llvm::SmallPtrSet<NamedDecl *, 8> &HiddenVBaseCs) { |
1644 | |
1645 | |
1646 | |
1647 | const llvm::SmallPtrSet<CanQualType, 8> *HiddenTypes = &ParentHiddenTypes; |
1648 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypesBuffer; |
1649 | |
1650 | |
1651 | |
1652 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
1653 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
1654 | if (ConvI != ConvE) { |
1655 | HiddenTypesBuffer = ParentHiddenTypes; |
1656 | HiddenTypes = &HiddenTypesBuffer; |
1657 | |
1658 | for (CXXRecordDecl::conversion_iterator I = ConvI; I != ConvE; ++I) { |
1659 | CanQualType ConvType(GetConversionType(Context, I.getDecl())); |
1660 | bool Hidden = ParentHiddenTypes.count(ConvType); |
1661 | if (!Hidden) |
1662 | HiddenTypesBuffer.insert(ConvType); |
1663 | |
1664 | |
1665 | |
1666 | if (Hidden && InVirtual) |
1667 | HiddenVBaseCs.insert(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())); |
1668 | |
1669 | |
1670 | else if (!Hidden) { |
1671 | AccessSpecifier IAccess |
1672 | = CXXRecordDecl::MergeAccess(Access, I.getAccess()); |
1673 | |
1674 | if (InVirtual) |
1675 | VOutput.addDecl(I.getDecl(), IAccess); |
1676 | else |
1677 | Output.addDecl(Context, I.getDecl(), IAccess); |
1678 | } |
1679 | } |
1680 | } |
1681 | |
1682 | |
1683 | for (const auto &I : Record->bases()) { |
1684 | const auto *RT = I.getType()->getAs<RecordType>(); |
1685 | if (!RT) continue; |
1686 | |
1687 | AccessSpecifier BaseAccess |
1688 | = CXXRecordDecl::MergeAccess(Access, I.getAccessSpecifier()); |
1689 | bool BaseInVirtual = InVirtual || I.isVirtual(); |
1690 | |
1691 | auto *Base = cast<CXXRecordDecl>(RT->getDecl()); |
1692 | CollectVisibleConversions(Context, Base, BaseInVirtual, BaseAccess, |
1693 | *HiddenTypes, Output, VOutput, HiddenVBaseCs); |
1694 | } |
1695 | } |
1696 | |
1697 | |
1698 | |
1699 | |
1700 | |
1701 | static void CollectVisibleConversions(ASTContext &Context, |
1702 | const CXXRecordDecl *Record, |
1703 | ASTUnresolvedSet &Output) { |
1704 | |
1705 | |
1706 | |
1707 | UnresolvedSet<8> VBaseCs; |
1708 | |
1709 | |
1710 | |
1711 | llvm::SmallPtrSet<NamedDecl*, 8> HiddenVBaseCs; |
1712 | |
1713 | |
1714 | llvm::SmallPtrSet<CanQualType, 8> HiddenTypes; |
1715 | |
1716 | |
1717 | |
1718 | CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin(); |
1719 | CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end(); |
1720 | Output.append(Context, ConvI, ConvE); |
1721 | for (; ConvI != ConvE; ++ConvI) |
1722 | HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl())); |
1723 | |
1724 | |
1725 | for (const auto &I : Record->bases()) { |
1726 | const auto *RT = I.getType()->getAs<RecordType>(); |
1727 | if (!RT) continue; |
1728 | |
1729 | CollectVisibleConversions(Context, cast<CXXRecordDecl>(RT->getDecl()), |
1730 | I.isVirtual(), I.getAccessSpecifier(), |
1731 | HiddenTypes, Output, VBaseCs, HiddenVBaseCs); |
1732 | } |
1733 | |
1734 | |
1735 | for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end(); |
1736 | I != E; ++I) { |
1737 | if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl()))) |
1738 | Output.addDecl(Context, I.getDecl(), I.getAccess()); |
1739 | } |
1740 | } |
1741 | |
1742 | |
1743 | |
1744 | llvm::iterator_range<CXXRecordDecl::conversion_iterator> |
1745 | CXXRecordDecl::getVisibleConversionFunctions() const { |
1746 | ASTContext &Ctx = getASTContext(); |
1747 | |
1748 | ASTUnresolvedSet *Set; |
1749 | if (bases_begin() == bases_end()) { |
| 1 | Calling 'CXXRecordDecl::bases_end' | |
|
1750 | |
1751 | Set = &data().Conversions.get(Ctx); |
1752 | } else { |
1753 | Set = &data().VisibleConversions.get(Ctx); |
1754 | |
1755 | if (!data().ComputedVisibleConversions) { |
1756 | CollectVisibleConversions(Ctx, this, *Set); |
1757 | data().ComputedVisibleConversions = true; |
1758 | } |
1759 | } |
1760 | return llvm::make_range(Set->begin(), Set->end()); |
1761 | } |
1762 | |
1763 | void CXXRecordDecl::removeConversion(const NamedDecl *ConvDecl) { |
1764 | |
1765 | |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | |
1775 | ASTUnresolvedSet &Convs = data().Conversions.get(getASTContext()); |
1776 | for (unsigned I = 0, E = Convs.size(); I != E; ++I) { |
1777 | if (Convs[I].getDecl() == ConvDecl) { |
1778 | Convs.erase(I); |
1779 | assert(llvm::find(Convs, ConvDecl) == Convs.end() && |
1780 | "conversion was found multiple times in unresolved set"); |
1781 | return; |
1782 | } |
1783 | } |
1784 | |
1785 | llvm_unreachable("conversion not found in set!"); |
1786 | } |
1787 | |
1788 | CXXRecordDecl *CXXRecordDecl::getInstantiatedFromMemberClass() const { |
1789 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
1790 | return cast<CXXRecordDecl>(MSInfo->getInstantiatedFrom()); |
1791 | |
1792 | return nullptr; |
1793 | } |
1794 | |
1795 | MemberSpecializationInfo *CXXRecordDecl::getMemberSpecializationInfo() const { |
1796 | return TemplateOrInstantiation.dyn_cast<MemberSpecializationInfo *>(); |
1797 | } |
1798 | |
1799 | void |
1800 | CXXRecordDecl::setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1801 | TemplateSpecializationKind TSK) { |
1802 | assert(TemplateOrInstantiation.isNull() && |
1803 | "Previous template or instantiation?"); |
1804 | assert(!isa<ClassTemplatePartialSpecializationDecl>(this)); |
1805 | TemplateOrInstantiation |
1806 | = new (getASTContext()) MemberSpecializationInfo(RD, TSK); |
1807 | } |
1808 | |
1809 | ClassTemplateDecl *CXXRecordDecl::getDescribedClassTemplate() const { |
1810 | return TemplateOrInstantiation.dyn_cast<ClassTemplateDecl *>(); |
1811 | } |
1812 | |
1813 | void CXXRecordDecl::setDescribedClassTemplate(ClassTemplateDecl *Template) { |
1814 | TemplateOrInstantiation = Template; |
1815 | } |
1816 | |
1817 | TemplateSpecializationKind CXXRecordDecl::getTemplateSpecializationKind() const{ |
1818 | if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) |
1819 | return Spec->getSpecializationKind(); |
1820 | |
1821 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) |
1822 | return MSInfo->getTemplateSpecializationKind(); |
1823 | |
1824 | return TSK_Undeclared; |
1825 | } |
1826 | |
1827 | void |
1828 | CXXRecordDecl::setTemplateSpecializationKind(TemplateSpecializationKind TSK) { |
1829 | if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
1830 | Spec->setSpecializationKind(TSK); |
1831 | return; |
1832 | } |
1833 | |
1834 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
1835 | MSInfo->setTemplateSpecializationKind(TSK); |
1836 | return; |
1837 | } |
1838 | |
1839 | llvm_unreachable("Not a class template or member class specialization"); |
1840 | } |
1841 | |
1842 | const CXXRecordDecl *CXXRecordDecl::getTemplateInstantiationPattern() const { |
1843 | auto GetDefinitionOrSelf = |
1844 | [](const CXXRecordDecl *D) -> const CXXRecordDecl * { |
1845 | if (auto *Def = D->getDefinition()) |
1846 | return Def; |
1847 | return D; |
1848 | }; |
1849 | |
1850 | |
1851 | |
1852 | if (auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(this)) { |
1853 | auto From = TD->getInstantiatedFrom(); |
1854 | if (auto *CTD = From.dyn_cast<ClassTemplateDecl *>()) { |
1855 | while (auto *NewCTD = CTD->getInstantiatedFromMemberTemplate()) { |
1856 | if (NewCTD->isMemberSpecialization()) |
1857 | break; |
1858 | CTD = NewCTD; |
1859 | } |
1860 | return GetDefinitionOrSelf(CTD->getTemplatedDecl()); |
1861 | } |
1862 | if (auto *CTPSD = |
1863 | From.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) { |
1864 | while (auto *NewCTPSD = CTPSD->getInstantiatedFromMember()) { |
1865 | if (NewCTPSD->isMemberSpecialization()) |
1866 | break; |
1867 | CTPSD = NewCTPSD; |
1868 | } |
1869 | return GetDefinitionOrSelf(CTPSD); |
1870 | } |
1871 | } |
1872 | |
1873 | if (MemberSpecializationInfo *MSInfo = getMemberSpecializationInfo()) { |
1874 | if (isTemplateInstantiation(MSInfo->getTemplateSpecializationKind())) { |
1875 | const CXXRecordDecl *RD = this; |
1876 | while (auto *NewRD = RD->getInstantiatedFromMemberClass()) |
1877 | RD = NewRD; |
1878 | return GetDefinitionOrSelf(RD); |
1879 | } |
1880 | } |
1881 | |
1882 | assert(!isTemplateInstantiation(this->getTemplateSpecializationKind()) && |
1883 | "couldn't find pattern for class template instantiation"); |
1884 | return nullptr; |
1885 | } |
1886 | |
1887 | CXXDestructorDecl *CXXRecordDecl::getDestructor() const { |
1888 | ASTContext &Context = getASTContext(); |
1889 | QualType ClassType = Context.getTypeDeclType(this); |
1890 | |
1891 | DeclarationName Name |
1892 | = Context.DeclarationNames.getCXXDestructorName( |
1893 | Context.getCanonicalType(ClassType)); |
1894 | |
1895 | DeclContext::lookup_result R = lookup(Name); |
1896 | |
1897 | return R.empty() ? nullptr : dyn_cast<CXXDestructorDecl>(R.front()); |
1898 | } |
1899 | |
1900 | static bool isDeclContextInNamespace(const DeclContext *DC) { |
1901 | while (!DC->isTranslationUnit()) { |
1902 | if (DC->isNamespace()) |
1903 | return true; |
1904 | DC = DC->getParent(); |
1905 | } |
1906 | return false; |
1907 | } |
1908 | |
1909 | bool CXXRecordDecl::isInterfaceLike() const { |
1910 | assert(hasDefinition() && "checking for interface-like without a definition"); |
1911 | |
1912 | if (isInterface()) |
1913 | return true; |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | if (isLambda() || hasUserDeclaredConstructor() || |
1919 | hasUserDeclaredDestructor() || !field_empty() || hasFriends() || |
1920 | getNumVBases() > 0 || conversion_end() - conversion_begin() > 0) |
1921 | return false; |
1922 | |
1923 | |
1924 | for (const auto *const Method : methods()) |
1925 | if (Method->isDefined() && !Method->isImplicit()) |
1926 | return false; |
1927 | |
1928 | |
1929 | const auto *Uuid = getAttr<UuidAttr>(); |
1930 | |
1931 | |
1932 | |
1933 | if (Uuid && isStruct() && !getDeclContext()->isExternCContext() && |
1934 | !isDeclContextInNamespace(getDeclContext()) && |
1935 | ((getName() == "IUnknown" && |
1936 | Uuid->getGuid() == "00000000-0000-0000-C000-000000000046") || |
1937 | (getName() == "IDispatch" && |
1938 | Uuid->getGuid() == "00020400-0000-0000-C000-000000000046"))) { |
1939 | if (getNumBases() > 0) |
1940 | return false; |
1941 | return true; |
1942 | } |
1943 | |
1944 | |
1945 | |
1946 | |
1947 | |
1948 | if (getNumBases() != 1) |
1949 | return false; |
1950 | |
1951 | const auto BaseSpec = *bases_begin(); |
1952 | if (BaseSpec.isVirtual() || BaseSpec.getAccessSpecifier() != AS_public) |
1953 | return false; |
1954 | const auto *Base = BaseSpec.getType()->getAsCXXRecordDecl(); |
1955 | if (Base->isInterface() || !Base->isInterfaceLike()) |
1956 | return false; |
1957 | return true; |
1958 | } |
1959 | |
1960 | void CXXRecordDecl::completeDefinition() { |
1961 | completeDefinition(nullptr); |
1962 | } |
1963 | |
1964 | void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) { |
1965 | RecordDecl::completeDefinition(); |
1966 | |
1967 | |
1968 | |
1969 | if (mayBeAbstract()) { |
1970 | CXXFinalOverriderMap MyFinalOverriders; |
1971 | if (!FinalOverriders) { |
1972 | getFinalOverriders(MyFinalOverriders); |
1973 | FinalOverriders = &MyFinalOverriders; |
1974 | } |
1975 | |
1976 | bool Done = false; |
1977 | for (CXXFinalOverriderMap::iterator M = FinalOverriders->begin(), |
1978 | MEnd = FinalOverriders->end(); |
1979 | M != MEnd && !Done; ++M) { |
1980 | for (OverridingMethods::iterator SO = M->second.begin(), |
1981 | SOEnd = M->second.end(); |
1982 | SO != SOEnd && !Done; ++SO) { |
1983 | assert(SO->second.size() > 0 && |
1984 | "All virtual functions have overriding virtual functions"); |
1985 | |
1986 | |
1987 | |
1988 | |
1989 | |
1990 | if (SO->second.front().Method->isPure()) { |
1991 | data().Abstract = true; |
1992 | Done = true; |
1993 | break; |
1994 | } |
1995 | } |
1996 | } |
1997 | } |
1998 | |
1999 | |
2000 | for (conversion_iterator I = conversion_begin(), E = conversion_end(); |
2001 | I != E; ++I) |
2002 | I.setAccess((*I)->getAccess()); |
2003 | } |
2004 | |
2005 | bool CXXRecordDecl::mayBeAbstract() const { |
2006 | if (data().Abstract || isInvalidDecl() || !data().Polymorphic || |
2007 | isDependentContext()) |
2008 | return false; |
2009 | |
2010 | for (const auto &B : bases()) { |
2011 | const auto *BaseDecl = |
2012 | cast<CXXRecordDecl>(B.getType()->castAs<RecordType>()->getDecl()); |
2013 | if (BaseDecl->isAbstract()) |
2014 | return true; |
2015 | } |
2016 | |
2017 | return false; |
2018 | } |
2019 | |
2020 | bool CXXRecordDecl::isEffectivelyFinal() const { |
2021 | auto *Def = getDefinition(); |
2022 | if (!Def) |
2023 | return false; |
2024 | if (Def->hasAttr<FinalAttr>()) |
2025 | return true; |
2026 | if (const auto *Dtor = Def->getDestructor()) |
2027 | if (Dtor->hasAttr<FinalAttr>()) |
2028 | return true; |
2029 | return false; |
2030 | } |
2031 | |
2032 | void CXXDeductionGuideDecl::anchor() {} |
2033 | |
2034 | bool ExplicitSpecifier::isEquivalent(const ExplicitSpecifier Other) const { |
2035 | if ((getKind() != Other.getKind() || |
2036 | getKind() == ExplicitSpecKind::Unresolved)) { |
2037 | if (getKind() == ExplicitSpecKind::Unresolved && |
2038 | Other.getKind() == ExplicitSpecKind::Unresolved) { |
2039 | ODRHash SelfHash, OtherHash; |
2040 | SelfHash.AddStmt(getExpr()); |
2041 | OtherHash.AddStmt(Other.getExpr()); |
2042 | return SelfHash.CalculateHash() == OtherHash.CalculateHash(); |
2043 | } else |
2044 | return false; |
2045 | } |
2046 | return true; |
2047 | } |
2048 | |
2049 | ExplicitSpecifier ExplicitSpecifier::getFromDecl(FunctionDecl *Function) { |
2050 | switch (Function->getDeclKind()) { |
2051 | case Decl::Kind::CXXConstructor: |
2052 | return cast<CXXConstructorDecl>(Function)->getExplicitSpecifier(); |
2053 | case Decl::Kind::CXXConversion: |
2054 | return cast<CXXConversionDecl>(Function)->getExplicitSpecifier(); |
2055 | case Decl::Kind::CXXDeductionGuide: |
2056 | return cast<CXXDeductionGuideDecl>(Function)->getExplicitSpecifier(); |
2057 | default: |
2058 | return {}; |
2059 | } |
2060 | } |
2061 | |
2062 | CXXDeductionGuideDecl * |
2063 | CXXDeductionGuideDecl::Create(ASTContext &C, DeclContext *DC, |
2064 | SourceLocation StartLoc, ExplicitSpecifier ES, |
2065 | const DeclarationNameInfo &NameInfo, QualType T, |
2066 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
2067 | CXXConstructorDecl *Ctor) { |
2068 | return new (C, DC) CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T, |
2069 | TInfo, EndLocation, Ctor); |
2070 | } |
2071 | |
2072 | CXXDeductionGuideDecl *CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C, |
2073 | unsigned ID) { |
2074 | return new (C, ID) CXXDeductionGuideDecl( |
2075 | C, nullptr, SourceLocation(), ExplicitSpecifier(), DeclarationNameInfo(), |
2076 | QualType(), nullptr, SourceLocation(), nullptr); |
2077 | } |
2078 | |
2079 | RequiresExprBodyDecl *RequiresExprBodyDecl::Create( |
2080 | ASTContext &C, DeclContext *DC, SourceLocation StartLoc) { |
2081 | return new (C, DC) RequiresExprBodyDecl(C, DC, StartLoc); |
2082 | } |
2083 | |
2084 | RequiresExprBodyDecl *RequiresExprBodyDecl::CreateDeserialized(ASTContext &C, |
2085 | unsigned ID) { |
2086 | return new (C, ID) RequiresExprBodyDecl(C, nullptr, SourceLocation()); |
2087 | } |
2088 | |
2089 | void CXXMethodDecl::anchor() {} |
2090 | |
2091 | bool CXXMethodDecl::isStatic() const { |
2092 | const CXXMethodDecl *MD = getCanonicalDecl(); |
2093 | |
2094 | if (MD->getStorageClass() == SC_Static) |
2095 | return true; |
2096 | |
2097 | OverloadedOperatorKind OOK = getDeclName().getCXXOverloadedOperator(); |
2098 | return isStaticOverloadedOperator(OOK); |
2099 | } |
2100 | |
2101 | static bool recursivelyOverrides(const CXXMethodDecl *DerivedMD, |
2102 | const CXXMethodDecl *BaseMD) { |
2103 | for (const CXXMethodDecl *MD : DerivedMD->overridden_methods()) { |
2104 | if (MD->getCanonicalDecl() == BaseMD->getCanonicalDecl()) |
2105 | return true; |
2106 | if (recursivelyOverrides(MD, BaseMD)) |
2107 | return true; |
2108 | } |
2109 | return false; |
2110 | } |
2111 | |
2112 | CXXMethodDecl * |
2113 | CXXMethodDecl::getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2114 | bool MayBeBase) { |
2115 | if (this->getParent()->getCanonicalDecl() == RD->getCanonicalDecl()) |
2116 | return this; |
2117 | |
2118 | |
2119 | if (isa<CXXDestructorDecl>(this)) { |
2120 | CXXMethodDecl *MD = RD->getDestructor(); |
2121 | if (MD) { |
2122 | if (recursivelyOverrides(MD, this)) |
2123 | return MD; |
2124 | if (MayBeBase && recursivelyOverrides(this, MD)) |
2125 | return MD; |
2126 | } |
2127 | return nullptr; |
2128 | } |
2129 | |
2130 | for (auto *ND : RD->lookup(getDeclName())) { |
2131 | auto *MD = dyn_cast<CXXMethodDecl>(ND); |
2132 | if (!MD) |
2133 | continue; |
2134 | if (recursivelyOverrides(MD, this)) |
2135 | return MD; |
2136 | if (MayBeBase && recursivelyOverrides(this, MD)) |
2137 | return MD; |
2138 | } |
2139 | |
2140 | return nullptr; |
2141 | } |
2142 | |
2143 | CXXMethodDecl * |
2144 | CXXMethodDecl::getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2145 | bool MayBeBase) { |
2146 | if (auto *MD = getCorrespondingMethodDeclaredInClass(RD, MayBeBase)) |
2147 | return MD; |
2148 | |
2149 | llvm::SmallVector<CXXMethodDecl*, 4> FinalOverriders; |
2150 | auto AddFinalOverrider = [&](CXXMethodDecl *D) { |
2151 | |
2152 | |
2153 | for (CXXMethodDecl *OtherD : FinalOverriders) { |
2154 | if (declaresSameEntity(D, OtherD) || recursivelyOverrides(OtherD, D)) |
2155 | return; |
2156 | } |
2157 | |
2158 | |
2159 | FinalOverriders.erase( |
2160 | std::remove_if(FinalOverriders.begin(), FinalOverriders.end(), |
2161 | [&](CXXMethodDecl *OtherD) { |
2162 | return recursivelyOverrides(D, OtherD); |
2163 | }), |
2164 | FinalOverriders.end()); |
2165 | |
2166 | FinalOverriders.push_back(D); |
2167 | }; |
2168 | |
2169 | for (const auto &I : RD->bases()) { |
2170 | const RecordType *RT = I.getType()->getAs<RecordType>(); |
2171 | if (!RT) |
2172 | continue; |
2173 | const auto *Base = cast<CXXRecordDecl>(RT->getDecl()); |
2174 | if (CXXMethodDecl *D = this->getCorrespondingMethodInClass(Base)) |
2175 | AddFinalOverrider(D); |
2176 | } |
2177 | |
2178 | return FinalOverriders.size() == 1 ? FinalOverriders.front() : nullptr; |
2179 | } |
2180 | |
2181 | CXXMethodDecl *CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD, |
2182 | SourceLocation StartLoc, |
2183 | const DeclarationNameInfo &NameInfo, |
2184 | QualType T, TypeSourceInfo *TInfo, |
2185 | StorageClass SC, bool isInline, |
2186 | ConstexprSpecKind ConstexprKind, |
2187 | SourceLocation EndLocation, |
2188 | Expr *TrailingRequiresClause) { |
2189 | return new (C, RD) |
2190 | CXXMethodDecl(CXXMethod, C, RD, StartLoc, NameInfo, T, TInfo, SC, |
2191 | isInline, ConstexprKind, EndLocation, |
2192 | TrailingRequiresClause); |
2193 | } |
2194 | |
2195 | CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2196 | return new (C, ID) |
2197 | CXXMethodDecl(CXXMethod, C, nullptr, SourceLocation(), |
2198 | DeclarationNameInfo(), QualType(), nullptr, SC_None, false, |
2199 | ConstexprSpecKind::Unspecified, SourceLocation(), nullptr); |
2200 | } |
2201 | |
2202 | CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base, |
2203 | bool IsAppleKext) { |
2204 | assert(isVirtual() && "this method is expected to be virtual"); |
2205 | |
2206 | |
2207 | |
2208 | if (IsAppleKext) |
2209 | return nullptr; |
2210 | |
2211 | |
2212 | |
2213 | if (hasAttr<FinalAttr>()) |
2214 | return isPure() ? nullptr : this; |
2215 | |
2216 | |
2217 | if (!Base) |
2218 | return nullptr; |
2219 | |
2220 | |
2221 | |
2222 | Base = Base->getBestDynamicClassTypeExpr(); |
2223 | if (Base->isPRValue() && Base->getType()->isRecordType()) |
2224 | return this; |
2225 | |
2226 | |
2227 | const CXXRecordDecl *BestDynamicDecl = Base->getBestDynamicClassType(); |
2228 | if (!BestDynamicDecl) |
2229 | return nullptr; |
2230 | |
2231 | |
2232 | CXXMethodDecl *DevirtualizedMethod = |
2233 | getCorrespondingMethodInClass(BestDynamicDecl); |
2234 | |
2235 | |
2236 | |
2237 | if (!DevirtualizedMethod) |
2238 | return nullptr; |
2239 | |
2240 | |
2241 | |
2242 | |
2243 | if (DevirtualizedMethod->isPure()) |
2244 | return nullptr; |
2245 | |
2246 | |
2247 | if (DevirtualizedMethod->hasAttr<FinalAttr>()) |
2248 | return DevirtualizedMethod; |
2249 | |
2250 | |
2251 | |
2252 | |
2253 | if (BestDynamicDecl->isEffectivelyFinal()) |
2254 | return DevirtualizedMethod; |
2255 | |
2256 | if (const auto *DRE = dyn_cast<DeclRefExpr>(Base)) { |
2257 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
2258 | if (VD->getType()->isRecordType()) |
2259 | |
2260 | return DevirtualizedMethod; |
2261 | |
2262 | return nullptr; |
2263 | } |
2264 | |
2265 | |
2266 | |
2267 | |
2268 | if (const auto *ME = dyn_cast<MemberExpr>(Base)) { |
2269 | const ValueDecl *VD = ME->getMemberDecl(); |
2270 | return VD->getType()->isRecordType() ? DevirtualizedMethod : nullptr; |
2271 | } |
2272 | |
2273 | |
2274 | |
2275 | if (auto *BO = dyn_cast<BinaryOperator>(Base)) { |
2276 | if (BO->isPtrMemOp()) { |
2277 | auto *MPT = BO->getRHS()->getType()->castAs<MemberPointerType>(); |
2278 | if (MPT->getPointeeType()->isRecordType()) |
2279 | return DevirtualizedMethod; |
2280 | } |
2281 | } |
2282 | |
2283 | |
2284 | return nullptr; |
2285 | } |
2286 | |
2287 | bool CXXMethodDecl::isUsualDeallocationFunction( |
2288 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const { |
2289 | assert(PreventedBy.empty() && "PreventedBy is expected to be empty"); |
2290 | if (getOverloadedOperator() != OO_Delete && |
2291 | getOverloadedOperator() != OO_Array_Delete) |
2292 | return false; |
2293 | |
2294 | |
2295 | |
2296 | |
2297 | if (getPrimaryTemplate()) |
2298 | return false; |
2299 | |
2300 | |
2301 | |
2302 | |
2303 | |
2304 | if (getNumParams() == 1) |
2305 | return true; |
2306 | unsigned UsualParams = 1; |
2307 | |
2308 | |
2309 | |
2310 | |
2311 | |
2312 | |
2313 | if (isDestroyingOperatorDelete()) |
2314 | ++UsualParams; |
2315 | |
2316 | |
2317 | |
2318 | |
2319 | |
2320 | |
2321 | |
2322 | |
2323 | |
2324 | |
2325 | |
2326 | ASTContext &Context = getASTContext(); |
2327 | if (UsualParams < getNumParams() && |
2328 | Context.hasSameUnqualifiedType(getParamDecl(UsualParams)->getType(), |
2329 | Context.getSizeType())) |
2330 | ++UsualParams; |
2331 | |
2332 | if (UsualParams < getNumParams() && |
2333 | getParamDecl(UsualParams)->getType()->isAlignValT()) |
2334 | ++UsualParams; |
2335 | |
2336 | if (UsualParams != getNumParams()) |
2337 | return false; |
2338 | |
2339 | |
2340 | |
2341 | |
2342 | |
2343 | |
2344 | if (Context.getLangOpts().CPlusPlus17 || |
2345 | Context.getLangOpts().AlignedAllocation || |
2346 | isDestroyingOperatorDelete()) |
2347 | return true; |
2348 | |
2349 | |
2350 | |
2351 | DeclContext::lookup_result R = getDeclContext()->lookup(getDeclName()); |
2352 | bool Result = true; |
2353 | for (const auto *D : R) { |
2354 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { |
2355 | if (FD->getNumParams() == 1) { |
2356 | PreventedBy.push_back(FD); |
2357 | Result = false; |
2358 | } |
2359 | } |
2360 | } |
2361 | return Result; |
2362 | } |
2363 | |
2364 | bool CXXMethodDecl::isCopyAssignmentOperator() const { |
2365 | |
2366 | |
2367 | |
2368 | |
2369 | if (getOverloadedOperator() != OO_Equal || |
2370 | isStatic() || |
2371 | getPrimaryTemplate() || getDescribedFunctionTemplate() || |
2372 | getNumParams() != 1) |
2373 | return false; |
2374 | |
2375 | QualType ParamType = getParamDecl(0)->getType(); |
2376 | if (const auto *Ref = ParamType->getAs<LValueReferenceType>()) |
2377 | ParamType = Ref->getPointeeType(); |
2378 | |
2379 | ASTContext &Context = getASTContext(); |
2380 | QualType ClassType |
2381 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
2382 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
2383 | } |
2384 | |
2385 | bool CXXMethodDecl::isMoveAssignmentOperator() const { |
2386 | |
2387 | |
2388 | |
2389 | |
2390 | if (getOverloadedOperator() != OO_Equal || isStatic() || |
2391 | getPrimaryTemplate() || getDescribedFunctionTemplate() || |
2392 | getNumParams() != 1) |
2393 | return false; |
2394 | |
2395 | QualType ParamType = getParamDecl(0)->getType(); |
2396 | if (!isa<RValueReferenceType>(ParamType)) |
2397 | return false; |
2398 | ParamType = ParamType->getPointeeType(); |
2399 | |
2400 | ASTContext &Context = getASTContext(); |
2401 | QualType ClassType |
2402 | = Context.getCanonicalType(Context.getTypeDeclType(getParent())); |
2403 | return Context.hasSameUnqualifiedType(ClassType, ParamType); |
2404 | } |
2405 | |
2406 | void CXXMethodDecl::addOverriddenMethod(const CXXMethodDecl *MD) { |
2407 | assert(MD->isCanonicalDecl() && "Method is not canonical!"); |
2408 | assert(!MD->getParent()->isDependentContext() && |
2409 | "Can't add an overridden method to a class template!"); |
2410 | assert(MD->isVirtual() && "Method is not virtual!"); |
2411 | |
2412 | getASTContext().addOverriddenMethod(this, MD); |
2413 | } |
2414 | |
2415 | CXXMethodDecl::method_iterator CXXMethodDecl::begin_overridden_methods() const { |
2416 | if (isa<CXXConstructorDecl>(this)) return nullptr; |
2417 | return getASTContext().overridden_methods_begin(this); |
2418 | } |
2419 | |
2420 | CXXMethodDecl::method_iterator CXXMethodDecl::end_overridden_methods() const { |
2421 | if (isa<CXXConstructorDecl>(this)) return nullptr; |
2422 | return getASTContext().overridden_methods_end(this); |
2423 | } |
2424 | |
2425 | unsigned CXXMethodDecl::size_overridden_methods() const { |
2426 | if (isa<CXXConstructorDecl>(this)) return 0; |
2427 | return getASTContext().overridden_methods_size(this); |
2428 | } |
2429 | |
2430 | CXXMethodDecl::overridden_method_range |
2431 | CXXMethodDecl::overridden_methods() const { |
2432 | if (isa<CXXConstructorDecl>(this)) |
2433 | return overridden_method_range(nullptr, nullptr); |
2434 | return getASTContext().overridden_methods(this); |
2435 | } |
2436 | |
2437 | static QualType getThisObjectType(ASTContext &C, const FunctionProtoType *FPT, |
2438 | const CXXRecordDecl *Decl) { |
2439 | QualType ClassTy = C.getTypeDeclType(Decl); |
2440 | return C.getQualifiedType(ClassTy, FPT->getMethodQuals()); |
2441 | } |
2442 | |
2443 | QualType CXXMethodDecl::getThisType(const FunctionProtoType *FPT, |
2444 | const CXXRecordDecl *Decl) { |
2445 | ASTContext &C = Decl->getASTContext(); |
2446 | QualType ObjectTy = ::getThisObjectType(C, FPT, Decl); |
2447 | return C.getPointerType(ObjectTy); |
2448 | } |
2449 | |
2450 | QualType CXXMethodDecl::getThisObjectType(const FunctionProtoType *FPT, |
2451 | const CXXRecordDecl *Decl) { |
2452 | ASTContext &C = Decl->getASTContext(); |
2453 | return ::getThisObjectType(C, FPT, Decl); |
2454 | } |
2455 | |
2456 | QualType CXXMethodDecl::getThisType() const { |
2457 | |
2458 | |
2459 | |
2460 | |
2461 | |
2462 | assert(isInstance() && "No 'this' for static methods!"); |
2463 | return CXXMethodDecl::getThisType(getType()->castAs<FunctionProtoType>(), |
2464 | getParent()); |
2465 | } |
2466 | |
2467 | QualType CXXMethodDecl::getThisObjectType() const { |
2468 | |
2469 | assert(isInstance() && "No 'this' for static methods!"); |
2470 | return CXXMethodDecl::getThisObjectType( |
2471 | getType()->castAs<FunctionProtoType>(), getParent()); |
2472 | } |
2473 | |
2474 | bool CXXMethodDecl::hasInlineBody() const { |
2475 | |
2476 | |
2477 | const FunctionDecl *CheckFn = getTemplateInstantiationPattern(); |
2478 | if (!CheckFn) |
2479 | CheckFn = this; |
2480 | |
2481 | const FunctionDecl *fn; |
2482 | return CheckFn->isDefined(fn) && !fn->isOutOfLine() && |
2483 | (fn->doesThisDeclarationHaveABody() || fn->willHaveBody()); |
2484 | } |
2485 | |
2486 | bool CXXMethodDecl::isLambdaStaticInvoker() const { |
2487 | const CXXRecordDecl *P = getParent(); |
2488 | return P->isLambda() && getDeclName().isIdentifier() && |
2489 | getName() == getLambdaStaticInvokerName(); |
2490 | } |
2491 | |
2492 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
2493 | TypeSourceInfo *TInfo, bool IsVirtual, |
2494 | SourceLocation L, Expr *Init, |
2495 | SourceLocation R, |
2496 | SourceLocation EllipsisLoc) |
2497 | : Initializee(TInfo), Init(Init), MemberOrEllipsisLocation(EllipsisLoc), |
2498 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(IsVirtual), |
2499 | IsWritten(false), SourceOrder(0) {} |
2500 | |
2501 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2502 | SourceLocation MemberLoc, |
2503 | SourceLocation L, Expr *Init, |
2504 | SourceLocation R) |
2505 | : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc), |
2506 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
2507 | IsWritten(false), SourceOrder(0) {} |
2508 | |
2509 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
2510 | IndirectFieldDecl *Member, |
2511 | SourceLocation MemberLoc, |
2512 | SourceLocation L, Expr *Init, |
2513 | SourceLocation R) |
2514 | : Initializee(Member), Init(Init), MemberOrEllipsisLocation(MemberLoc), |
2515 | LParenLoc(L), RParenLoc(R), IsDelegating(false), IsVirtual(false), |
2516 | IsWritten(false), SourceOrder(0) {} |
2517 | |
2518 | CXXCtorInitializer::CXXCtorInitializer(ASTContext &Context, |
2519 | TypeSourceInfo *TInfo, |
2520 | SourceLocation L, Expr *Init, |
2521 | SourceLocation R) |
2522 | : Initializee(TInfo), Init(Init), LParenLoc(L), RParenLoc(R), |
2523 | IsDelegating(true), IsVirtual(false), IsWritten(false), SourceOrder(0) {} |
2524 | |
2525 | int64_t CXXCtorInitializer::getID(const ASTContext &Context) const { |
2526 | return Context.getAllocator() |
2527 | .identifyKnownAlignedObject<CXXCtorInitializer>(this); |
2528 | } |
2529 | |
2530 | TypeLoc CXXCtorInitializer::getBaseClassLoc() const { |
2531 | if (isBaseInitializer()) |
2532 | return Initializee.get<TypeSourceInfo*>()->getTypeLoc(); |
2533 | else |
2534 | return {}; |
2535 | } |
2536 | |
2537 | const Type *CXXCtorInitializer::getBaseClass() const { |
2538 | if (isBaseInitializer()) |
2539 | return Initializee.get<TypeSourceInfo*>()->getType().getTypePtr(); |
2540 | else |
2541 | return nullptr; |
2542 | } |
2543 | |
2544 | SourceLocation CXXCtorInitializer::getSourceLocation() const { |
2545 | if (isInClassMemberInitializer()) |
2546 | return getAnyMember()->getLocation(); |
2547 | |
2548 | if (isAnyMemberInitializer()) |
2549 | return getMemberLocation(); |
2550 | |
2551 | if (const auto *TSInfo = Initializee.get<TypeSourceInfo *>()) |
2552 | return TSInfo->getTypeLoc().getLocalSourceRange().getBegin(); |
2553 | |
2554 | return {}; |
2555 | } |
2556 | |
2557 | SourceRange CXXCtorInitializer::getSourceRange() const { |
2558 | if (isInClassMemberInitializer()) { |
2559 | FieldDecl *D = getAnyMember(); |
2560 | if (Expr *I = D->getInClassInitializer()) |
2561 | return I->getSourceRange(); |
2562 | return {}; |
2563 | } |
2564 | |
2565 | return SourceRange(getSourceLocation(), getRParenLoc()); |
2566 | } |
2567 | |
2568 | CXXConstructorDecl::CXXConstructorDecl( |
2569 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2570 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2571 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2572 | ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited, |
2573 | Expr *TrailingRequiresClause) |
2574 | : CXXMethodDecl(CXXConstructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2575 | SC_None, isInline, ConstexprKind, SourceLocation(), |
2576 | TrailingRequiresClause) { |
2577 | setNumCtorInitializers(0); |
2578 | setInheritingConstructor(static_cast<bool>(Inherited)); |
2579 | setImplicit(isImplicitlyDeclared); |
2580 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier = ES.getExpr() ? 1 : 0; |
2581 | if (Inherited) |
2582 | *getTrailingObjects<InheritedConstructor>() = Inherited; |
2583 | setExplicitSpecifier(ES); |
2584 | } |
2585 | |
2586 | void CXXConstructorDecl::anchor() {} |
2587 | |
2588 | CXXConstructorDecl *CXXConstructorDecl::CreateDeserialized(ASTContext &C, |
2589 | unsigned ID, |
2590 | uint64_t AllocKind) { |
2591 | bool hasTrailingExplicit = static_cast<bool>(AllocKind & TAKHasTailExplicit); |
2592 | bool isInheritingConstructor = |
2593 | static_cast<bool>(AllocKind & TAKInheritsConstructor); |
2594 | unsigned Extra = |
2595 | additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>( |
2596 | isInheritingConstructor, hasTrailingExplicit); |
2597 | auto *Result = new (C, ID, Extra) CXXConstructorDecl( |
2598 | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, |
2599 | ExplicitSpecifier(), false, false, ConstexprSpecKind::Unspecified, |
2600 | InheritedConstructor(), nullptr); |
2601 | Result->setInheritingConstructor(isInheritingConstructor); |
2602 | Result->CXXConstructorDeclBits.HasTrailingExplicitSpecifier = |
2603 | hasTrailingExplicit; |
2604 | Result->setExplicitSpecifier(ExplicitSpecifier()); |
2605 | return Result; |
2606 | } |
2607 | |
2608 | CXXConstructorDecl *CXXConstructorDecl::Create( |
2609 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2610 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2611 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2612 | ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited, |
2613 | Expr *TrailingRequiresClause) { |
2614 | assert(NameInfo.getName().getNameKind() |
2615 | == DeclarationName::CXXConstructorName && |
2616 | "Name must refer to a constructor"); |
2617 | unsigned Extra = |
2618 | additionalSizeToAlloc<InheritedConstructor, ExplicitSpecifier>( |
2619 | Inherited ? 1 : 0, ES.getExpr() ? 1 : 0); |
2620 | return new (C, RD, Extra) |
2621 | CXXConstructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, ES, isInline, |
2622 | isImplicitlyDeclared, ConstexprKind, Inherited, |
2623 | TrailingRequiresClause); |
2624 | } |
2625 | |
2626 | CXXConstructorDecl::init_const_iterator CXXConstructorDecl::init_begin() const { |
2627 | return CtorInitializers.get(getASTContext().getExternalSource()); |
2628 | } |
2629 | |
2630 | CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const { |
2631 | assert(isDelegatingConstructor() && "Not a delegating constructor!"); |
2632 | Expr *E = (*init_begin())->getInit()->IgnoreImplicit(); |
2633 | if (const auto *Construct = dyn_cast<CXXConstructExpr>(E)) |
2634 | return Construct->getConstructor(); |
2635 | |
2636 | return nullptr; |
2637 | } |
2638 | |
2639 | bool CXXConstructorDecl::isDefaultConstructor() const { |
2640 | |
2641 | |
2642 | |
2643 | |
2644 | return getMinRequiredArguments() == 0; |
2645 | } |
2646 | |
2647 | bool |
2648 | CXXConstructorDecl::isCopyConstructor(unsigned &TypeQuals) const { |
2649 | return isCopyOrMoveConstructor(TypeQuals) && |
2650 | getParamDecl(0)->getType()->isLValueReferenceType(); |
2651 | } |
2652 | |
2653 | bool CXXConstructorDecl::isMoveConstructor(unsigned &TypeQuals) const { |
2654 | return isCopyOrMoveConstructor(TypeQuals) && |
2655 | getParamDecl(0)->getType()->isRValueReferenceType(); |
2656 | } |
2657 | |
2658 | |
2659 | bool CXXConstructorDecl::isCopyOrMoveConstructor(unsigned &TypeQuals) const { |
2660 | |
2661 | |
2662 | |
2663 | |
2664 | |
2665 | |
2666 | |
2667 | |
2668 | |
2669 | |
2670 | if (!hasOneParamOrDefaultArgs() || getPrimaryTemplate() != nullptr || |
2671 | getDescribedFunctionTemplate() != nullptr) |
2672 | return false; |
2673 | |
2674 | const ParmVarDecl *Param = getParamDecl(0); |
2675 | |
2676 | |
2677 | const auto *ParamRefType = Param->getType()->getAs<ReferenceType>(); |
2678 | if (!ParamRefType) |
2679 | return false; |
2680 | |
2681 | |
2682 | ASTContext &Context = getASTContext(); |
2683 | |
2684 | CanQualType PointeeType |
2685 | = Context.getCanonicalType(ParamRefType->getPointeeType()); |
2686 | CanQualType ClassTy |
2687 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
2688 | if (PointeeType.getUnqualifiedType() != ClassTy) |
2689 | return false; |
2690 | |
2691 | |
2692 | |
2693 | |
2694 | TypeQuals = PointeeType.getCVRQualifiers(); |
2695 | return true; |
2696 | } |
2697 | |
2698 | bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const { |
2699 | |
2700 | |
2701 | |
2702 | |
2703 | |
2704 | |
2705 | if (isExplicit() && !AllowExplicit) |
2706 | return false; |
2707 | |
2708 | |
2709 | |
2710 | |
2711 | return getNumParams() == 0 |
2712 | ? getType()->castAs<FunctionProtoType>()->isVariadic() |
2713 | : getMinRequiredArguments() <= 1; |
2714 | } |
2715 | |
2716 | bool CXXConstructorDecl::isSpecializationCopyingObject() const { |
2717 | if (!hasOneParamOrDefaultArgs() || getDescribedFunctionTemplate() != nullptr) |
2718 | return false; |
2719 | |
2720 | const ParmVarDecl *Param = getParamDecl(0); |
2721 | |
2722 | ASTContext &Context = getASTContext(); |
2723 | CanQualType ParamType = Context.getCanonicalType(Param->getType()); |
2724 | |
2725 | |
2726 | CanQualType ClassTy |
2727 | = Context.getCanonicalType(Context.getTagDeclType(getParent())); |
2728 | if (ParamType.getUnqualifiedType() != ClassTy) |
2729 | return false; |
2730 | |
2731 | return true; |
2732 | } |
2733 | |
2734 | void CXXDestructorDecl::anchor() {} |
2735 | |
2736 | CXXDestructorDecl * |
2737 | CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2738 | return new (C, ID) CXXDestructorDecl( |
2739 | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, |
2740 | false, false, ConstexprSpecKind::Unspecified, nullptr); |
2741 | } |
2742 | |
2743 | CXXDestructorDecl *CXXDestructorDecl::Create( |
2744 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2745 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2746 | bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2747 | Expr *TrailingRequiresClause) { |
2748 | assert(NameInfo.getName().getNameKind() |
2749 | == DeclarationName::CXXDestructorName && |
2750 | "Name must refer to a destructor"); |
2751 | return new (C, RD) |
2752 | CXXDestructorDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, |
2753 | isImplicitlyDeclared, ConstexprKind, |
2754 | TrailingRequiresClause); |
2755 | } |
2756 | |
2757 | void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) { |
2758 | auto *First = cast<CXXDestructorDecl>(getFirstDecl()); |
2759 | if (OD && !First->OperatorDelete) { |
2760 | First->OperatorDelete = OD; |
2761 | First->OperatorDeleteThisArg = ThisArg; |
2762 | if (auto *L = getASTMutationListener()) |
2763 | L->ResolvedOperatorDelete(First, OD, ThisArg); |
2764 | } |
2765 | } |
2766 | |
2767 | void CXXConversionDecl::anchor() {} |
2768 | |
2769 | CXXConversionDecl * |
2770 | CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2771 | return new (C, ID) CXXConversionDecl( |
2772 | C, nullptr, SourceLocation(), DeclarationNameInfo(), QualType(), nullptr, |
2773 | false, ExplicitSpecifier(), ConstexprSpecKind::Unspecified, |
2774 | SourceLocation(), nullptr); |
2775 | } |
2776 | |
2777 | CXXConversionDecl *CXXConversionDecl::Create( |
2778 | ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2779 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2780 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2781 | SourceLocation EndLocation, Expr *TrailingRequiresClause) { |
2782 | assert(NameInfo.getName().getNameKind() |
2783 | == DeclarationName::CXXConversionFunctionName && |
2784 | "Name must refer to a conversion function"); |
2785 | return new (C, RD) |
2786 | CXXConversionDecl(C, RD, StartLoc, NameInfo, T, TInfo, isInline, ES, |
2787 | ConstexprKind, EndLocation, TrailingRequiresClause); |
2788 | } |
2789 | |
2790 | bool CXXConversionDecl::isLambdaToBlockPointerConversion() const { |
2791 | return isImplicit() && getParent()->isLambda() && |
2792 | getConversionType()->isBlockPointerType(); |
2793 | } |
2794 | |
2795 | LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2796 | SourceLocation LangLoc, LanguageIDs lang, |
2797 | bool HasBraces) |
2798 | : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec), |
2799 | ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) { |
2800 | setLanguage(lang); |
2801 | LinkageSpecDeclBits.HasBraces = HasBraces; |
2802 | } |
2803 | |
2804 | void LinkageSpecDecl::anchor() {} |
2805 | |
2806 | LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C, |
2807 | DeclContext *DC, |
2808 | SourceLocation ExternLoc, |
2809 | SourceLocation LangLoc, |
2810 | LanguageIDs Lang, |
2811 | bool HasBraces) { |
2812 | return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces); |
2813 | } |
2814 | |
2815 | LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, |
2816 | unsigned ID) { |
2817 | return new (C, ID) LinkageSpecDecl(nullptr, SourceLocation(), |
2818 | SourceLocation(), lang_c, false); |
2819 | } |
2820 | |
2821 | void UsingDirectiveDecl::anchor() {} |
2822 | |
2823 | UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC, |
2824 | SourceLocation L, |
2825 | SourceLocation NamespaceLoc, |
2826 | NestedNameSpecifierLoc QualifierLoc, |
2827 | SourceLocation IdentLoc, |
2828 | NamedDecl *Used, |
2829 | DeclContext *CommonAncestor) { |
2830 | if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Used)) |
2831 | Used = NS->getOriginalNamespace(); |
2832 | return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc, |
2833 | IdentLoc, Used, CommonAncestor); |
2834 | } |
2835 | |
2836 | UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C, |
2837 | unsigned ID) { |
2838 | return new (C, ID) UsingDirectiveDecl(nullptr, SourceLocation(), |
2839 | SourceLocation(), |
2840 | NestedNameSpecifierLoc(), |
2841 | SourceLocation(), nullptr, nullptr); |
2842 | } |
2843 | |
2844 | NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() { |
2845 | if (auto *NA = dyn_cast_or_null<NamespaceAliasDecl>(NominatedNamespace)) |
2846 | return NA->getNamespace(); |
2847 | return cast_or_null<NamespaceDecl>(NominatedNamespace); |
2848 | } |
2849 | |
2850 | NamespaceDecl::NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline, |
2851 | SourceLocation StartLoc, SourceLocation IdLoc, |
2852 | IdentifierInfo *Id, NamespaceDecl *PrevDecl) |
2853 | : NamedDecl(Namespace, DC, IdLoc, Id), DeclContext(Namespace), |
2854 | redeclarable_base(C), LocStart(StartLoc), |
2855 | AnonOrFirstNamespaceAndInline(nullptr, Inline) { |
2856 | setPreviousDecl(PrevDecl); |
2857 | |
2858 | if (PrevDecl) |
2859 | AnonOrFirstNamespaceAndInline.setPointer(PrevDecl->getOriginalNamespace()); |
2860 | } |
2861 | |
2862 | NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, |
2863 | bool Inline, SourceLocation StartLoc, |
2864 | SourceLocation IdLoc, IdentifierInfo *Id, |
2865 | NamespaceDecl *PrevDecl) { |
2866 | return new (C, DC) NamespaceDecl(C, DC, Inline, StartLoc, IdLoc, Id, |
2867 | PrevDecl); |
2868 | } |
2869 | |
2870 | NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2871 | return new (C, ID) NamespaceDecl(C, nullptr, false, SourceLocation(), |
2872 | SourceLocation(), nullptr, nullptr); |
2873 | } |
2874 | |
2875 | NamespaceDecl *NamespaceDecl::getOriginalNamespace() { |
2876 | if (isFirstDecl()) |
2877 | return this; |
2878 | |
2879 | return AnonOrFirstNamespaceAndInline.getPointer(); |
2880 | } |
2881 | |
2882 | const NamespaceDecl *NamespaceDecl::getOriginalNamespace() const { |
2883 | if (isFirstDecl()) |
2884 | return this; |
2885 | |
2886 | return AnonOrFirstNamespaceAndInline.getPointer(); |
2887 | } |
2888 | |
2889 | bool NamespaceDecl::isOriginalNamespace() const { return isFirstDecl(); } |
2890 | |
2891 | NamespaceDecl *NamespaceDecl::getNextRedeclarationImpl() { |
2892 | return getNextRedeclaration(); |
2893 | } |
2894 | |
2895 | NamespaceDecl *NamespaceDecl::getPreviousDeclImpl() { |
2896 | return getPreviousDecl(); |
2897 | } |
2898 | |
2899 | NamespaceDecl *NamespaceDecl::getMostRecentDeclImpl() { |
2900 | return getMostRecentDecl(); |
2901 | } |
2902 | |
2903 | void NamespaceAliasDecl::anchor() {} |
2904 | |
2905 | NamespaceAliasDecl *NamespaceAliasDecl::getNextRedeclarationImpl() { |
2906 | return getNextRedeclaration(); |
2907 | } |
2908 | |
2909 | NamespaceAliasDecl *NamespaceAliasDecl::getPreviousDeclImpl() { |
2910 | return getPreviousDecl(); |
2911 | } |
2912 | |
2913 | NamespaceAliasDecl *NamespaceAliasDecl::getMostRecentDeclImpl() { |
2914 | return getMostRecentDecl(); |
2915 | } |
2916 | |
2917 | NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC, |
2918 | SourceLocation UsingLoc, |
2919 | SourceLocation AliasLoc, |
2920 | IdentifierInfo *Alias, |
2921 | NestedNameSpecifierLoc QualifierLoc, |
2922 | SourceLocation IdentLoc, |
2923 | NamedDecl *Namespace) { |
2924 | |
2925 | if (auto *NS = dyn_cast_or_null<NamespaceDecl>(Namespace)) |
2926 | Namespace = NS->getOriginalNamespace(); |
2927 | return new (C, DC) NamespaceAliasDecl(C, DC, UsingLoc, AliasLoc, Alias, |
2928 | QualifierLoc, IdentLoc, Namespace); |
2929 | } |
2930 | |
2931 | NamespaceAliasDecl * |
2932 | NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2933 | return new (C, ID) NamespaceAliasDecl(C, nullptr, SourceLocation(), |
2934 | SourceLocation(), nullptr, |
2935 | NestedNameSpecifierLoc(), |
2936 | SourceLocation(), nullptr); |
2937 | } |
2938 | |
2939 | void LifetimeExtendedTemporaryDecl::anchor() {} |
2940 | |
2941 | |
2942 | StorageDuration LifetimeExtendedTemporaryDecl::getStorageDuration() const { |
2943 | const ValueDecl *ExtendingDecl = getExtendingDecl(); |
2944 | if (!ExtendingDecl) |
2945 | return SD_FullExpression; |
2946 | |
2947 | |
2948 | if (isa<FieldDecl>(ExtendingDecl)) |
2949 | return SD_Automatic; |
2950 | |
2951 | |
2952 | if (isa<BindingDecl>(ExtendingDecl)) |
2953 | return ExtendingDecl->getDeclContext()->isFunctionOrMethod() ? SD_Automatic |
2954 | : SD_Static; |
2955 | return cast<VarDecl>(ExtendingDecl)->getStorageDuration(); |
2956 | } |
2957 | |
2958 | APValue *LifetimeExtendedTemporaryDecl::getOrCreateValue(bool MayCreate) const { |
2959 | assert(getStorageDuration() == SD_Static && |
2960 | "don't need to cache the computed value for this temporary"); |
2961 | if (MayCreate && !Value) { |
2962 | Value = (new (getASTContext()) APValue); |
2963 | getASTContext().addDestruction(Value); |
2964 | } |
2965 | assert(Value && "may not be null"); |
2966 | return Value; |
2967 | } |
2968 | |
2969 | void UsingShadowDecl::anchor() {} |
2970 | |
2971 | UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, |
2972 | SourceLocation Loc, DeclarationName Name, |
2973 | BaseUsingDecl *Introducer, NamedDecl *Target) |
2974 | : NamedDecl(K, DC, Loc, Name), redeclarable_base(C), |
2975 | UsingOrNextShadow(Introducer) { |
2976 | if (Target) |
2977 | setTargetDecl(Target); |
2978 | setImplicit(); |
2979 | } |
2980 | |
2981 | UsingShadowDecl::UsingShadowDecl(Kind K, ASTContext &C, EmptyShell Empty) |
2982 | : NamedDecl(K, nullptr, SourceLocation(), DeclarationName()), |
2983 | redeclarable_base(C) {} |
2984 | |
2985 | UsingShadowDecl * |
2986 | UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
2987 | return new (C, ID) UsingShadowDecl(UsingShadow, C, EmptyShell()); |
2988 | } |
2989 | |
2990 | BaseUsingDecl *UsingShadowDecl::getIntroducer() const { |
2991 | const UsingShadowDecl *Shadow = this; |
2992 | while (const auto *NextShadow = |
2993 | dyn_cast<UsingShadowDecl>(Shadow->UsingOrNextShadow)) |
2994 | Shadow = NextShadow; |
2995 | return cast<BaseUsingDecl>(Shadow->UsingOrNextShadow); |
2996 | } |
2997 | |
2998 | void ConstructorUsingShadowDecl::anchor() {} |
2999 | |
3000 | ConstructorUsingShadowDecl * |
3001 | ConstructorUsingShadowDecl::Create(ASTContext &C, DeclContext *DC, |
3002 | SourceLocation Loc, UsingDecl *Using, |
3003 | NamedDecl *Target, bool IsVirtual) { |
3004 | return new (C, DC) ConstructorUsingShadowDecl(C, DC, Loc, Using, Target, |
3005 | IsVirtual); |
3006 | } |
3007 | |
3008 | ConstructorUsingShadowDecl * |
3009 | ConstructorUsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3010 | return new (C, ID) ConstructorUsingShadowDecl(C, EmptyShell()); |
3011 | } |
3012 | |
3013 | CXXRecordDecl *ConstructorUsingShadowDecl::getNominatedBaseClass() const { |
3014 | return getIntroducer()->getQualifier()->getAsRecordDecl(); |
3015 | } |
3016 | |
3017 | void BaseUsingDecl::anchor() {} |
3018 | |
3019 | void BaseUsingDecl::addShadowDecl(UsingShadowDecl *S) { |
3020 | assert(std::find(shadow_begin(), shadow_end(), S) == shadow_end() && |
3021 | "declaration already in set"); |
3022 | assert(S->getIntroducer() == this); |
3023 | |
3024 | if (FirstUsingShadow.getPointer()) |
3025 | S->UsingOrNextShadow = FirstUsingShadow.getPointer(); |
3026 | FirstUsingShadow.setPointer(S); |
3027 | } |
3028 | |
3029 | void BaseUsingDecl::removeShadowDecl(UsingShadowDecl *S) { |
3030 | assert(std::find(shadow_begin(), shadow_end(), S) != shadow_end() && |
3031 | "declaration not in set"); |
3032 | assert(S->getIntroducer() == this); |
3033 | |
3034 | |
3035 | |
3036 | if (FirstUsingShadow.getPointer() == S) { |
3037 | FirstUsingShadow.setPointer( |
3038 | dyn_cast<UsingShadowDecl>(S->UsingOrNextShadow)); |
3039 | S->UsingOrNextShadow = this; |
3040 | return; |
3041 | } |
3042 | |
3043 | UsingShadowDecl *Prev = FirstUsingShadow.getPointer(); |
3044 | while (Prev->UsingOrNextShadow != S) |
3045 | Prev = cast<UsingShadowDecl>(Prev->UsingOrNextShadow); |
3046 | Prev->UsingOrNextShadow = S->UsingOrNextShadow; |
3047 | S->UsingOrNextShadow = this; |
3048 | } |
3049 | |
3050 | void UsingDecl::anchor() {} |
3051 | |
3052 | UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL, |
3053 | NestedNameSpecifierLoc QualifierLoc, |
3054 | const DeclarationNameInfo &NameInfo, |
3055 | bool HasTypename) { |
3056 | return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename); |
3057 | } |
3058 | |
3059 | UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3060 | return new (C, ID) UsingDecl(nullptr, SourceLocation(), |
3061 | NestedNameSpecifierLoc(), DeclarationNameInfo(), |
3062 | false); |
3063 | } |
3064 | |
3065 | SourceRange UsingDecl::getSourceRange() const { |
3066 | SourceLocation Begin = isAccessDeclaration() |
3067 | ? getQualifierLoc().getBeginLoc() : UsingLocation; |
3068 | return SourceRange(Begin, getNameInfo().getEndLoc()); |
3069 | } |
3070 | |
3071 | void UsingEnumDecl::anchor() {} |
3072 | |
3073 | UsingEnumDecl *UsingEnumDecl::Create(ASTContext &C, DeclContext *DC, |
3074 | SourceLocation UL, SourceLocation EL, |
3075 | SourceLocation NL, EnumDecl *Enum) { |
3076 | return new (C, DC) UsingEnumDecl(DC, Enum->getDeclName(), UL, EL, NL, Enum); |
3077 | } |
3078 | |
3079 | UsingEnumDecl *UsingEnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3080 | return new (C, ID) UsingEnumDecl(nullptr, DeclarationName(), SourceLocation(), |
3081 | SourceLocation(), SourceLocation(), nullptr); |
3082 | } |
3083 | |
3084 | SourceRange UsingEnumDecl::getSourceRange() const { |
3085 | return SourceRange(EnumLocation, getLocation()); |
3086 | } |
3087 | |
3088 | void UsingPackDecl::anchor() {} |
3089 | |
3090 | UsingPackDecl *UsingPackDecl::Create(ASTContext &C, DeclContext *DC, |
3091 | NamedDecl *InstantiatedFrom, |
3092 | ArrayRef<NamedDecl *> UsingDecls) { |
3093 | size_t Extra = additionalSizeToAlloc<NamedDecl *>(UsingDecls.size()); |
3094 | return new (C, DC, Extra) UsingPackDecl(DC, InstantiatedFrom, UsingDecls); |
3095 | } |
3096 | |
3097 | UsingPackDecl *UsingPackDecl::CreateDeserialized(ASTContext &C, unsigned ID, |
3098 | unsigned NumExpansions) { |
3099 | size_t Extra = additionalSizeToAlloc<NamedDecl *>(NumExpansions); |
3100 | auto *Result = new (C, ID, Extra) UsingPackDecl(nullptr, nullptr, None); |
3101 | Result->NumExpansions = NumExpansions; |
3102 | auto *Trail = Result->getTrailingObjects<NamedDecl *>(); |
3103 | for (unsigned I = 0; I != NumExpansions; ++I) |
3104 | new (Trail + I) NamedDecl*(nullptr); |
3105 | return Result; |
3106 | } |
3107 | |
3108 | void UnresolvedUsingValueDecl::anchor() {} |
3109 | |
3110 | UnresolvedUsingValueDecl * |
3111 | UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC, |
3112 | SourceLocation UsingLoc, |
3113 | NestedNameSpecifierLoc QualifierLoc, |
3114 | const DeclarationNameInfo &NameInfo, |
3115 | SourceLocation EllipsisLoc) { |
3116 | return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc, |
3117 | QualifierLoc, NameInfo, |
3118 | EllipsisLoc); |
3119 | } |
3120 | |
3121 | UnresolvedUsingValueDecl * |
3122 | UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3123 | return new (C, ID) UnresolvedUsingValueDecl(nullptr, QualType(), |
3124 | SourceLocation(), |
3125 | NestedNameSpecifierLoc(), |
3126 | DeclarationNameInfo(), |
3127 | SourceLocation()); |
3128 | } |
3129 | |
3130 | SourceRange UnresolvedUsingValueDecl::getSourceRange() const { |
3131 | SourceLocation Begin = isAccessDeclaration() |
3132 | ? getQualifierLoc().getBeginLoc() : UsingLocation; |
3133 | return SourceRange(Begin, getNameInfo().getEndLoc()); |
3134 | } |
3135 | |
3136 | void UnresolvedUsingTypenameDecl::anchor() {} |
3137 | |
3138 | UnresolvedUsingTypenameDecl * |
3139 | UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC, |
3140 | SourceLocation UsingLoc, |
3141 | SourceLocation TypenameLoc, |
3142 | NestedNameSpecifierLoc QualifierLoc, |
3143 | SourceLocation TargetNameLoc, |
3144 | DeclarationName TargetName, |
3145 | SourceLocation EllipsisLoc) { |
3146 | return new (C, DC) UnresolvedUsingTypenameDecl( |
3147 | DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc, |
3148 | TargetName.getAsIdentifierInfo(), EllipsisLoc); |
3149 | } |
3150 | |
3151 | UnresolvedUsingTypenameDecl * |
3152 | UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3153 | return new (C, ID) UnresolvedUsingTypenameDecl( |
3154 | nullptr, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(), |
3155 | SourceLocation(), nullptr, SourceLocation()); |
3156 | } |
3157 | |
3158 | UnresolvedUsingIfExistsDecl * |
3159 | UnresolvedUsingIfExistsDecl::Create(ASTContext &Ctx, DeclContext *DC, |
3160 | SourceLocation Loc, DeclarationName Name) { |
3161 | return new (Ctx, DC) UnresolvedUsingIfExistsDecl(DC, Loc, Name); |
3162 | } |
3163 | |
3164 | UnresolvedUsingIfExistsDecl * |
3165 | UnresolvedUsingIfExistsDecl::CreateDeserialized(ASTContext &Ctx, unsigned ID) { |
3166 | return new (Ctx, ID) |
3167 | UnresolvedUsingIfExistsDecl(nullptr, SourceLocation(), DeclarationName()); |
3168 | } |
3169 | |
3170 | UnresolvedUsingIfExistsDecl::UnresolvedUsingIfExistsDecl(DeclContext *DC, |
3171 | SourceLocation Loc, |
3172 | DeclarationName Name) |
3173 | : NamedDecl(Decl::UnresolvedUsingIfExists, DC, Loc, Name) {} |
3174 | |
3175 | void UnresolvedUsingIfExistsDecl::anchor() {} |
3176 | |
3177 | void StaticAssertDecl::anchor() {} |
3178 | |
3179 | StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC, |
3180 | SourceLocation StaticAssertLoc, |
3181 | Expr *AssertExpr, |
3182 | StringLiteral *Message, |
3183 | SourceLocation RParenLoc, |
3184 | bool Failed) { |
3185 | return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message, |
3186 | RParenLoc, Failed); |
3187 | } |
3188 | |
3189 | StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, |
3190 | unsigned ID) { |
3191 | return new (C, ID) StaticAssertDecl(nullptr, SourceLocation(), nullptr, |
3192 | nullptr, SourceLocation(), false); |
3193 | } |
3194 | |
3195 | void BindingDecl::anchor() {} |
3196 | |
3197 | BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC, |
3198 | SourceLocation IdLoc, IdentifierInfo *Id) { |
3199 | return new (C, DC) BindingDecl(DC, IdLoc, Id); |
3200 | } |
3201 | |
3202 | BindingDecl *BindingDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3203 | return new (C, ID) BindingDecl(nullptr, SourceLocation(), nullptr); |
3204 | } |
3205 | |
3206 | VarDecl *BindingDecl::getHoldingVar() const { |
3207 | Expr *B = getBinding(); |
3208 | if (!B) |
3209 | return nullptr; |
3210 | auto *DRE = dyn_cast<DeclRefExpr>(B->IgnoreImplicit()); |
3211 | if (!DRE) |
3212 | return nullptr; |
3213 | |
3214 | auto *VD = cast<VarDecl>(DRE->getDecl()); |
3215 | assert(VD->isImplicit() && "holding var for binding decl not implicit"); |
3216 | return VD; |
3217 | } |
3218 | |
3219 | void DecompositionDecl::anchor() {} |
3220 | |
3221 | DecompositionDecl *DecompositionDecl::Create(ASTContext &C, DeclContext *DC, |
3222 | SourceLocation StartLoc, |
3223 | SourceLocation LSquareLoc, |
3224 | QualType T, TypeSourceInfo *TInfo, |
3225 | StorageClass SC, |
3226 | ArrayRef<BindingDecl *> Bindings) { |
3227 | size_t Extra = additionalSizeToAlloc<BindingDecl *>(Bindings.size()); |
3228 | return new (C, DC, Extra) |
3229 | DecompositionDecl(C, DC, StartLoc, LSquareLoc, T, TInfo, SC, Bindings); |
3230 | } |
3231 | |
3232 | DecompositionDecl *DecompositionDecl::CreateDeserialized(ASTContext &C, |
3233 | unsigned ID, |
3234 | unsigned NumBindings) { |
3235 | size_t Extra = additionalSizeToAlloc<BindingDecl *>(NumBindings); |
3236 | auto *Result = new (C, ID, Extra) |
3237 | DecompositionDecl(C, nullptr, SourceLocation(), SourceLocation(), |
3238 | QualType(), nullptr, StorageClass(), None); |
3239 | |
3240 | Result->NumBindings = NumBindings; |
3241 | auto *Trail = Result->getTrailingObjects<BindingDecl *>(); |
3242 | for (unsigned I = 0; I != NumBindings; ++I) |
3243 | new (Trail + I) BindingDecl*(nullptr); |
3244 | return Result; |
3245 | } |
3246 | |
3247 | void DecompositionDecl::printName(llvm::raw_ostream &os) const { |
3248 | os << '['; |
3249 | bool Comma = false; |
3250 | for (const auto *B : bindings()) { |
3251 | if (Comma) |
3252 | os << ", "; |
3253 | B->printName(os); |
3254 | Comma = true; |
3255 | } |
3256 | os << ']'; |
3257 | } |
3258 | |
3259 | void MSPropertyDecl::anchor() {} |
3260 | |
3261 | MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC, |
3262 | SourceLocation L, DeclarationName N, |
3263 | QualType T, TypeSourceInfo *TInfo, |
3264 | SourceLocation StartL, |
3265 | IdentifierInfo *Getter, |
3266 | IdentifierInfo *Setter) { |
3267 | return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter); |
3268 | } |
3269 | |
3270 | MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C, |
3271 | unsigned ID) { |
3272 | return new (C, ID) MSPropertyDecl(nullptr, SourceLocation(), |
3273 | DeclarationName(), QualType(), nullptr, |
3274 | SourceLocation(), nullptr, nullptr); |
3275 | } |
3276 | |
3277 | void MSGuidDecl::anchor() {} |
3278 | |
3279 | MSGuidDecl::MSGuidDecl(DeclContext *DC, QualType T, Parts P) |
3280 | : ValueDecl(Decl::MSGuid, DC, SourceLocation(), DeclarationName(), T), |
3281 | PartVal(P), APVal() {} |
3282 | |
3283 | MSGuidDecl *MSGuidDecl::Create(const ASTContext &C, QualType T, Parts P) { |
3284 | DeclContext *DC = C.getTranslationUnitDecl(); |
3285 | return new (C, DC) MSGuidDecl(DC, T, P); |
3286 | } |
3287 | |
3288 | MSGuidDecl *MSGuidDecl::CreateDeserialized(ASTContext &C, unsigned ID) { |
3289 | return new (C, ID) MSGuidDecl(nullptr, QualType(), Parts()); |
3290 | } |
3291 | |
3292 | void MSGuidDecl::printName(llvm::raw_ostream &OS) const { |
3293 | OS << llvm::format("GUID{%08" PRIx32 "-%04" PRIx16 "-%04" PRIx16 "-", |
3294 | PartVal.Part1, PartVal.Part2, PartVal.Part3); |
3295 | unsigned I = 0; |
3296 | for (uint8_t Byte : PartVal.Part4And5) { |
3297 | OS << llvm::format("%02" PRIx8, Byte); |
3298 | if (++I == 2) |
3299 | OS << '-'; |
3300 | } |
3301 | OS << '}'; |
3302 | } |
3303 | |
3304 | |
3305 | static bool isValidStructGUID(ASTContext &Ctx, QualType T) { |
3306 | |
3307 | |
3308 | using MatcherRef = llvm::function_ref<bool(QualType)>; |
3309 | |
3310 | auto IsInt = [&Ctx](unsigned N) { |
3311 | return [&Ctx, N](QualType T) { |
3312 | return T->isUnsignedIntegerOrEnumerationType() && |
3313 | Ctx.getIntWidth(T) == N; |
3314 | }; |
3315 | }; |
3316 | |
3317 | auto IsArray = [&Ctx](MatcherRef Elem, unsigned N) { |
3318 | return [&Ctx, Elem, N](QualType T) { |
3319 | const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(T); |
3320 | return CAT && CAT->getSize() == N && Elem(CAT->getElementType()); |
3321 | }; |
3322 | }; |
3323 | |
3324 | auto IsStruct = [](std::initializer_list<MatcherRef> Fields) { |
3325 | return [Fields](QualType T) { |
3326 | const RecordDecl *RD = T->getAsRecordDecl(); |
3327 | if (!RD || RD->isUnion()) |
3328 | return false; |
3329 | RD = RD->getDefinition(); |
3330 | if (!RD) |
3331 | return false; |
3332 | if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) |
3333 | if (CXXRD->getNumBases()) |
3334 | return false; |
3335 | auto MatcherIt = Fields.begin(); |
3336 | for (const FieldDecl *FD : RD->fields()) { |
3337 | if (FD->isUnnamedBitfield()) continue; |
3338 | if (FD->isBitField() || MatcherIt == Fields.end() || |
3339 | !(*MatcherIt)(FD->getType())) |
3340 | return false; |
3341 | ++MatcherIt; |
3342 | } |
3343 | return MatcherIt == Fields.end(); |
3344 | }; |
3345 | }; |
3346 | |
3347 | |
3348 | return IsStruct({IsInt(32), IsInt(16), IsInt(16), IsArray(IsInt(8), 8)})(T); |
3349 | } |
3350 | |
3351 | APValue &MSGuidDecl::getAsAPValue() const { |
3352 | if (APVal.isAbsent() && isValidStructGUID(getASTContext(), getType())) { |
3353 | using llvm::APInt; |
3354 | using llvm::APSInt; |
3355 | APVal = APValue(APValue::UninitStruct(), 0, 4); |
3356 | APVal.getStructField(0) = APValue(APSInt(APInt(32, PartVal.Part1), true)); |
3357 | APVal.getStructField(1) = APValue(APSInt(APInt(16, PartVal.Part2), true)); |
3358 | APVal.getStructField(2) = APValue(APSInt(APInt(16, PartVal.Part3), true)); |
3359 | APValue &Arr = APVal.getStructField(3) = |
3360 | APValue(APValue::UninitArray(), 8, 8); |
3361 | for (unsigned I = 0; I != 8; ++I) { |
3362 | Arr.getArrayInitializedElt(I) = |
3363 | APValue(APSInt(APInt(8, PartVal.Part4And5[I]), true)); |
3364 | } |
3365 | |
3366 | |
3367 | getASTContext().addDestruction(&APVal); |
3368 | } |
3369 | |
3370 | return APVal; |
3371 | } |
3372 | |
3373 | static const char *getAccessName(AccessSpecifier AS) { |
3374 | switch (AS) { |
3375 | case AS_none: |
3376 | llvm_unreachable("Invalid access specifier!"); |
3377 | case AS_public: |
3378 | return "public"; |
3379 | case AS_private: |
3380 | return "private"; |
3381 | case AS_protected: |
3382 | return "protected"; |
3383 | } |
3384 | llvm_unreachable("Invalid access specifier!"); |
3385 | } |
3386 | |
3387 | const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB, |
3388 | AccessSpecifier AS) { |
3389 | return DB << getAccessName(AS); |
3390 | } |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | #ifndef LLVM_CLANG_AST_DECLCXX_H |
16 | #define LLVM_CLANG_AST_DECLCXX_H |
17 | |
18 | #include "clang/AST/ASTUnresolvedSet.h" |
19 | #include "clang/AST/Decl.h" |
20 | #include "clang/AST/DeclBase.h" |
21 | #include "clang/AST/DeclarationName.h" |
22 | #include "clang/AST/Expr.h" |
23 | #include "clang/AST/ExternalASTSource.h" |
24 | #include "clang/AST/LambdaCapture.h" |
25 | #include "clang/AST/NestedNameSpecifier.h" |
26 | #include "clang/AST/Redeclarable.h" |
27 | #include "clang/AST/Stmt.h" |
28 | #include "clang/AST/Type.h" |
29 | #include "clang/AST/TypeLoc.h" |
30 | #include "clang/AST/UnresolvedSet.h" |
31 | #include "clang/Basic/LLVM.h" |
32 | #include "clang/Basic/Lambda.h" |
33 | #include "clang/Basic/LangOptions.h" |
34 | #include "clang/Basic/OperatorKinds.h" |
35 | #include "clang/Basic/SourceLocation.h" |
36 | #include "clang/Basic/Specifiers.h" |
37 | #include "llvm/ADT/ArrayRef.h" |
38 | #include "llvm/ADT/DenseMap.h" |
39 | #include "llvm/ADT/PointerIntPair.h" |
40 | #include "llvm/ADT/PointerUnion.h" |
41 | #include "llvm/ADT/STLExtras.h" |
42 | #include "llvm/ADT/TinyPtrVector.h" |
43 | #include "llvm/ADT/iterator_range.h" |
44 | #include "llvm/Support/Casting.h" |
45 | #include "llvm/Support/Compiler.h" |
46 | #include "llvm/Support/PointerLikeTypeTraits.h" |
47 | #include "llvm/Support/TrailingObjects.h" |
48 | #include <cassert> |
49 | #include <cstddef> |
50 | #include <iterator> |
51 | #include <memory> |
52 | #include <vector> |
53 | |
54 | namespace clang { |
55 | |
56 | class ASTContext; |
57 | class ClassTemplateDecl; |
58 | class ConstructorUsingShadowDecl; |
59 | class CXXBasePath; |
60 | class CXXBasePaths; |
61 | class CXXConstructorDecl; |
62 | class CXXDestructorDecl; |
63 | class CXXFinalOverriderMap; |
64 | class CXXIndirectPrimaryBaseSet; |
65 | class CXXMethodDecl; |
66 | class DecompositionDecl; |
67 | class DiagnosticBuilder; |
68 | class FriendDecl; |
69 | class FunctionTemplateDecl; |
70 | class IdentifierInfo; |
71 | class MemberSpecializationInfo; |
72 | class BaseUsingDecl; |
73 | class TemplateDecl; |
74 | class TemplateParameterList; |
75 | class UsingDecl; |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | class AccessSpecDecl : public Decl { |
88 | |
89 | SourceLocation ColonLoc; |
90 | |
91 | AccessSpecDecl(AccessSpecifier AS, DeclContext *DC, |
92 | SourceLocation ASLoc, SourceLocation ColonLoc) |
93 | : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) { |
94 | setAccess(AS); |
95 | } |
96 | |
97 | AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {} |
98 | |
99 | virtual void anchor(); |
100 | |
101 | public: |
102 | |
103 | SourceLocation getAccessSpecifierLoc() const { return getLocation(); } |
104 | |
105 | |
106 | void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); } |
107 | |
108 | |
109 | SourceLocation getColonLoc() const { return ColonLoc; } |
110 | |
111 | |
112 | void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; } |
113 | |
114 | SourceRange getSourceRange() const override LLVM_READONLY { |
115 | return SourceRange(getAccessSpecifierLoc(), getColonLoc()); |
116 | } |
117 | |
118 | static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS, |
119 | DeclContext *DC, SourceLocation ASLoc, |
120 | SourceLocation ColonLoc) { |
121 | return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc); |
122 | } |
123 | |
124 | static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
125 | |
126 | |
127 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
128 | static bool classofKind(Kind K) { return K == AccessSpec; } |
129 | }; |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | class CXXBaseSpecifier { |
148 | |
149 | |
150 | |
151 | SourceRange Range; |
152 | |
153 | |
154 | |
155 | SourceLocation EllipsisLoc; |
156 | |
157 | |
158 | unsigned Virtual : 1; |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | unsigned BaseOfClass : 1; |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | unsigned Access : 2; |
171 | |
172 | |
173 | |
174 | unsigned InheritConstructors : 1; |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | TypeSourceInfo *BaseTypeInfo; |
181 | |
182 | public: |
183 | CXXBaseSpecifier() = default; |
184 | CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A, |
185 | TypeSourceInfo *TInfo, SourceLocation EllipsisLoc) |
186 | : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC), |
187 | Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {} |
188 | |
189 | |
190 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
191 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
192 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
193 | |
194 | |
195 | SourceLocation getBaseTypeLoc() const LLVM_READONLY { |
196 | return BaseTypeInfo->getTypeLoc().getBeginLoc(); |
197 | } |
198 | |
199 | |
200 | bool isVirtual() const { return Virtual; } |
201 | |
202 | |
203 | |
204 | bool isBaseOfClass() const { return BaseOfClass; } |
205 | |
206 | |
207 | bool isPackExpansion() const { return EllipsisLoc.isValid(); } |
208 | |
209 | |
210 | bool getInheritConstructors() const { return InheritConstructors; } |
211 | |
212 | |
213 | void setInheritConstructors(bool Inherit = true) { |
214 | InheritConstructors = Inherit; |
215 | } |
216 | |
217 | |
218 | SourceLocation getEllipsisLoc() const { |
219 | return EllipsisLoc; |
220 | } |
221 | |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | AccessSpecifier getAccessSpecifier() const { |
228 | if ((AccessSpecifier)Access == AS_none) |
229 | return BaseOfClass? AS_private : AS_public; |
230 | else |
231 | return (AccessSpecifier)Access; |
232 | } |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 | AccessSpecifier getAccessSpecifierAsWritten() const { |
240 | return (AccessSpecifier)Access; |
241 | } |
242 | |
243 | |
244 | |
245 | |
246 | QualType getType() const { |
247 | return BaseTypeInfo->getType().getUnqualifiedType(); |
248 | } |
249 | |
250 | |
251 | TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; } |
252 | }; |
253 | |
254 | |
255 | class CXXRecordDecl : public RecordDecl { |
256 | friend class ASTDeclReader; |
257 | friend class ASTDeclWriter; |
258 | friend class ASTNodeImporter; |
259 | friend class ASTReader; |
260 | friend class ASTRecordWriter; |
261 | friend class ASTWriter; |
262 | friend class DeclContext; |
263 | friend class LambdaExpr; |
264 | |
265 | friend void FunctionDecl::setPure(bool); |
266 | friend void TagDecl::startDefinition(); |
267 | |
268 | |
269 | enum SpecialMemberFlags { |
270 | SMF_DefaultConstructor = 0x1, |
271 | SMF_CopyConstructor = 0x2, |
272 | SMF_MoveConstructor = 0x4, |
273 | SMF_CopyAssignment = 0x8, |
274 | SMF_MoveAssignment = 0x10, |
275 | SMF_Destructor = 0x20, |
276 | SMF_All = 0x3f |
277 | }; |
278 | |
279 | struct DefinitionData { |
280 | #define FIELD(Name, Width, Merge) \ |
281 | unsigned Name : Width; |
282 | #include "CXXRecordDeclDefinitionBits.def" |
283 | |
284 | |
285 | unsigned IsLambda : 1; |
286 | |
287 | |
288 | unsigned IsParsingBaseSpecifiers : 1; |
289 | |
290 | |
291 | |
292 | unsigned ComputedVisibleConversions : 1; |
293 | |
294 | unsigned HasODRHash : 1; |
295 | |
296 | |
297 | unsigned ODRHash = 0; |
298 | |
299 | |
300 | unsigned NumBases = 0; |
301 | |
302 | |
303 | unsigned NumVBases = 0; |
304 | |
305 | |
306 | |
307 | |
308 | LazyCXXBaseSpecifiersPtr Bases; |
309 | |
310 | |
311 | LazyCXXBaseSpecifiersPtr VBases; |
312 | |
313 | |
314 | |
315 | |
316 | |
317 | LazyASTUnresolvedSet Conversions; |
318 | |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | LazyASTUnresolvedSet VisibleConversions; |
325 | |
326 | |
327 | CXXRecordDecl *Definition; |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | LazyDeclPtr FirstFriend; |
334 | |
335 | DefinitionData(CXXRecordDecl *D); |
336 | |
337 | |
338 | CXXBaseSpecifier *getBases() const { |
339 | if (!Bases.isOffset()) |
| 4 | | Assuming the condition is true | |
|
| |
340 | return Bases.get(nullptr); |
| 6 | | Passing null pointer value via 1st parameter 'Source' | |
|
| 7 | | Calling 'LazyOffsetPtr::get' | |
|
341 | return getBasesSlowCase(); |
342 | } |
343 | |
344 | |
345 | CXXBaseSpecifier *getVBases() const { |
346 | if (!VBases.isOffset()) |
347 | return VBases.get(nullptr); |
348 | return getVBasesSlowCase(); |
349 | } |
350 | |
351 | ArrayRef<CXXBaseSpecifier> bases() const { |
352 | return llvm::makeArrayRef(getBases(), NumBases); |
353 | } |
354 | |
355 | ArrayRef<CXXBaseSpecifier> vbases() const { |
356 | return llvm::makeArrayRef(getVBases(), NumVBases); |
357 | } |
358 | |
359 | private: |
360 | CXXBaseSpecifier *getBasesSlowCase() const; |
361 | CXXBaseSpecifier *getVBasesSlowCase() const; |
362 | }; |
363 | |
364 | struct DefinitionData *DefinitionData; |
365 | |
366 | |
367 | struct LambdaDefinitionData : public DefinitionData { |
368 | using Capture = LambdaCapture; |
369 | |
370 | |
371 | |
372 | |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | unsigned Dependent : 1; |
379 | |
380 | |
381 | unsigned IsGenericLambda : 1; |
382 | |
383 | |
384 | unsigned CaptureDefault : 2; |
385 | |
386 | |
387 | unsigned NumCaptures : 15; |
388 | |
389 | |
390 | unsigned NumExplicitCaptures : 13; |
391 | |
392 | |
393 | unsigned HasKnownInternalLinkage : 1; |
394 | |
395 | |
396 | |
397 | unsigned ManglingNumber : 31; |
398 | |
399 | |
400 | |
401 | |
402 | |
403 | LazyDeclPtr ContextDecl; |
404 | |
405 | |
406 | |
407 | Capture *Captures = nullptr; |
408 | |
409 | |
410 | TypeSourceInfo *MethodTyInfo; |
411 | |
412 | LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool Dependent, |
413 | bool IsGeneric, LambdaCaptureDefault CaptureDefault) |
414 | : DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric), |
415 | CaptureDefault(CaptureDefault), NumCaptures(0), |
416 | NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0), |
417 | MethodTyInfo(Info) { |
418 | IsLambda = true; |
419 | |
420 | |
421 | |
422 | Aggregate = false; |
423 | PlainOldData = false; |
424 | } |
425 | }; |
426 | |
427 | struct DefinitionData *dataPtr() const { |
428 | |
429 | getMostRecentDecl(); |
430 | return DefinitionData; |
431 | } |
432 | |
433 | struct DefinitionData &data() const { |
434 | auto *DD = dataPtr(); |
435 | assert(DD && "queried property of class with no definition"); |
436 | return *DD; |
437 | } |
438 | |
439 | struct LambdaDefinitionData &getLambdaData() const { |
440 | |
441 | |
442 | auto *DD = DefinitionData; |
443 | assert(DD && DD->IsLambda && "queried lambda property of non-lambda class"); |
444 | return static_cast<LambdaDefinitionData&>(*DD); |
445 | } |
446 | |
447 | |
448 | |
449 | |
450 | |
451 | |
452 | |
453 | |
454 | |
455 | |
456 | llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *> |
457 | TemplateOrInstantiation; |
458 | |
459 | |
460 | |
461 | void addedClassSubobject(CXXRecordDecl *Base); |
462 | |
463 | |
464 | |
465 | |
466 | |
467 | |
468 | void addedMember(Decl *D); |
469 | |
470 | void markedVirtualFunctionPure(); |
471 | |
472 | |
473 | |
474 | FriendDecl *getFirstFriend() const; |
475 | |
476 | |
477 | |
478 | |
479 | bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx, |
480 | const CXXRecordDecl *X); |
481 | |
482 | protected: |
483 | CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC, |
484 | SourceLocation StartLoc, SourceLocation IdLoc, |
485 | IdentifierInfo *Id, CXXRecordDecl *PrevDecl); |
486 | |
487 | public: |
488 | |
489 | using base_class_iterator = CXXBaseSpecifier *; |
490 | |
491 | |
492 | using base_class_const_iterator = const CXXBaseSpecifier *; |
493 | |
494 | CXXRecordDecl *getCanonicalDecl() override { |
495 | return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl()); |
496 | } |
497 | |
498 | const CXXRecordDecl *getCanonicalDecl() const { |
499 | return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl(); |
500 | } |
501 | |
502 | CXXRecordDecl *getPreviousDecl() { |
503 | return cast_or_null<CXXRecordDecl>( |
504 | static_cast<RecordDecl *>(this)->getPreviousDecl()); |
505 | } |
506 | |
507 | const CXXRecordDecl *getPreviousDecl() const { |
508 | return const_cast<CXXRecordDecl*>(this)->getPreviousDecl(); |
509 | } |
510 | |
511 | CXXRecordDecl *getMostRecentDecl() { |
512 | return cast<CXXRecordDecl>( |
513 | static_cast<RecordDecl *>(this)->getMostRecentDecl()); |
514 | } |
515 | |
516 | const CXXRecordDecl *getMostRecentDecl() const { |
517 | return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl(); |
518 | } |
519 | |
520 | CXXRecordDecl *getMostRecentNonInjectedDecl() { |
521 | CXXRecordDecl *Recent = |
522 | static_cast<CXXRecordDecl *>(this)->getMostRecentDecl(); |
523 | while (Recent->isInjectedClassName()) { |
524 | |
525 | assert(Recent->getPreviousDecl()); |
526 | Recent = Recent->getPreviousDecl(); |
527 | } |
528 | return Recent; |
529 | } |
530 | |
531 | const CXXRecordDecl *getMostRecentNonInjectedDecl() const { |
532 | return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl(); |
533 | } |
534 | |
535 | CXXRecordDecl *getDefinition() const { |
536 | |
537 | |
538 | auto *DD = DefinitionData ? DefinitionData : dataPtr(); |
539 | return DD ? DD->Definition : nullptr; |
540 | } |
541 | |
542 | bool hasDefinition() const { return DefinitionData || dataPtr(); } |
543 | |
544 | static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC, |
545 | SourceLocation StartLoc, SourceLocation IdLoc, |
546 | IdentifierInfo *Id, |
547 | CXXRecordDecl *PrevDecl = nullptr, |
548 | bool DelayTypeCreation = false); |
549 | static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC, |
550 | TypeSourceInfo *Info, SourceLocation Loc, |
551 | bool DependentLambda, bool IsGeneric, |
552 | LambdaCaptureDefault CaptureDefault); |
553 | static CXXRecordDecl *CreateDeserialized(const ASTContext &C, unsigned ID); |
554 | |
555 | bool isDynamicClass() const { |
556 | return data().Polymorphic || data().NumVBases != 0; |
557 | } |
558 | |
559 | |
560 | |
561 | bool mayBeDynamicClass() const { |
562 | return !hasDefinition() || isDynamicClass() || hasAnyDependentBases(); |
563 | } |
564 | |
565 | |
566 | |
567 | bool mayBeNonDynamicClass() const { |
568 | return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases(); |
569 | } |
570 | |
571 | void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; } |
572 | |
573 | bool isParsingBaseSpecifiers() const { |
574 | return data().IsParsingBaseSpecifiers; |
575 | } |
576 | |
577 | unsigned getODRHash() const; |
578 | |
579 | |
580 | void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases); |
581 | |
582 | |
583 | unsigned getNumBases() const { return data().NumBases; } |
584 | |
585 | using base_class_range = llvm::iterator_range<base_class_iterator>; |
586 | using base_class_const_range = |
587 | llvm::iterator_range<base_class_const_iterator>; |
588 | |
589 | base_class_range bases() { |
590 | return base_class_range(bases_begin(), bases_end()); |
591 | } |
592 | base_class_const_range bases() const { |
593 | return base_class_const_range(bases_begin(), bases_end()); |
594 | } |
595 | |
596 | base_class_iterator bases_begin() { return data().getBases(); } |
597 | base_class_const_iterator bases_begin() const { return data().getBases(); } |
| 3 | | Calling 'DefinitionData::getBases' | |
|
598 | base_class_iterator bases_end() { return bases_begin() + data().NumBases; } |
599 | base_class_const_iterator bases_end() const { |
600 | return bases_begin() + data().NumBases; |
| 2 | | Calling 'CXXRecordDecl::bases_begin' | |
|
601 | } |
602 | |
603 | |
604 | unsigned getNumVBases() const { return data().NumVBases; } |
605 | |
606 | base_class_range vbases() { |
607 | return base_class_range(vbases_begin(), vbases_end()); |
608 | } |
609 | base_class_const_range vbases() const { |
610 | return base_class_const_range(vbases_begin(), vbases_end()); |
611 | } |
612 | |
613 | base_class_iterator vbases_begin() { return data().getVBases(); } |
614 | base_class_const_iterator vbases_begin() const { return data().getVBases(); } |
615 | base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; } |
616 | base_class_const_iterator vbases_end() const { |
617 | return vbases_begin() + data().NumVBases; |
618 | } |
619 | |
620 | |
621 | |
622 | bool hasAnyDependentBases() const; |
623 | |
624 | |
625 | |
626 | |
627 | using method_iterator = specific_decl_iterator<CXXMethodDecl>; |
628 | using method_range = |
629 | llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>; |
630 | |
631 | method_range methods() const { |
632 | return method_range(method_begin(), method_end()); |
633 | } |
634 | |
635 | |
636 | |
637 | method_iterator method_begin() const { |
638 | return method_iterator(decls_begin()); |
639 | } |
640 | |
641 | |
642 | method_iterator method_end() const { |
643 | return method_iterator(decls_end()); |
644 | } |
645 | |
646 | |
647 | using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>; |
648 | using ctor_range = |
649 | llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>; |
650 | |
651 | ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); } |
652 | |
653 | ctor_iterator ctor_begin() const { |
654 | return ctor_iterator(decls_begin()); |
655 | } |
656 | |
657 | ctor_iterator ctor_end() const { |
658 | return ctor_iterator(decls_end()); |
659 | } |
660 | |
661 | |
662 | |
663 | class friend_iterator; |
664 | using friend_range = llvm::iterator_range<friend_iterator>; |
665 | |
666 | friend_range friends() const; |
667 | friend_iterator friend_begin() const; |
668 | friend_iterator friend_end() const; |
669 | void pushFriendDecl(FriendDecl *FD); |
670 | |
671 | |
672 | bool hasFriends() const { |
673 | return data().FirstFriend.isValid(); |
674 | } |
675 | |
676 | |
677 | |
678 | bool defaultedCopyConstructorIsDeleted() const { |
679 | assert((!needsOverloadResolutionForCopyConstructor() || |
680 | (data().DeclaredSpecialMembers & SMF_CopyConstructor)) && |
681 | "this property has not yet been computed by Sema"); |
682 | return data().DefaultedCopyConstructorIsDeleted; |
683 | } |
684 | |
685 | |
686 | |
687 | bool defaultedMoveConstructorIsDeleted() const { |
688 | assert((!needsOverloadResolutionForMoveConstructor() || |
689 | (data().DeclaredSpecialMembers & SMF_MoveConstructor)) && |
690 | "this property has not yet been computed by Sema"); |
691 | return data().DefaultedMoveConstructorIsDeleted; |
692 | } |
693 | |
694 | |
695 | bool defaultedDestructorIsDeleted() const { |
696 | assert((!needsOverloadResolutionForDestructor() || |
697 | (data().DeclaredSpecialMembers & SMF_Destructor)) && |
698 | "this property has not yet been computed by Sema"); |
699 | return data().DefaultedDestructorIsDeleted; |
700 | } |
701 | |
702 | |
703 | |
704 | bool hasSimpleCopyConstructor() const { |
705 | return !hasUserDeclaredCopyConstructor() && |
706 | !data().DefaultedCopyConstructorIsDeleted; |
707 | } |
708 | |
709 | |
710 | |
711 | bool hasSimpleMoveConstructor() const { |
712 | return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() && |
713 | !data().DefaultedMoveConstructorIsDeleted; |
714 | } |
715 | |
716 | |
717 | |
718 | bool hasSimpleCopyAssignment() const { |
719 | return !hasUserDeclaredCopyAssignment() && |
720 | !data().DefaultedCopyAssignmentIsDeleted; |
721 | } |
722 | |
723 | |
724 | |
725 | bool hasSimpleMoveAssignment() const { |
726 | return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() && |
727 | !data().DefaultedMoveAssignmentIsDeleted; |
728 | } |
729 | |
730 | |
731 | |
732 | bool hasSimpleDestructor() const { |
733 | return !hasUserDeclaredDestructor() && |
734 | !data().DefaultedDestructorIsDeleted; |
735 | } |
736 | |
737 | |
738 | bool hasDefaultConstructor() const { |
739 | return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) || |
740 | needsImplicitDefaultConstructor(); |
741 | } |
742 | |
743 | |
744 | |
745 | |
746 | |
747 | bool needsImplicitDefaultConstructor() const { |
748 | return (!data().UserDeclaredConstructor && |
749 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) && |
750 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) || |
751 | |
752 | |
753 | |
754 | (data().HasInheritedDefaultConstructor && |
755 | !(data().DeclaredSpecialMembers & SMF_DefaultConstructor)); |
756 | } |
757 | |
758 | |
759 | |
760 | |
761 | bool hasUserDeclaredConstructor() const { |
762 | return data().UserDeclaredConstructor; |
763 | } |
764 | |
765 | |
766 | |
767 | bool hasUserProvidedDefaultConstructor() const { |
768 | return data().UserProvidedDefaultConstructor; |
769 | } |
770 | |
771 | |
772 | |
773 | |
774 | bool hasUserDeclaredCopyConstructor() const { |
775 | return data().UserDeclaredSpecialMembers & SMF_CopyConstructor; |
776 | } |
777 | |
778 | |
779 | |
780 | bool needsImplicitCopyConstructor() const { |
781 | return !(data().DeclaredSpecialMembers & SMF_CopyConstructor); |
782 | } |
783 | |
784 | |
785 | |
786 | bool needsOverloadResolutionForCopyConstructor() const { |
787 | |
788 | |
789 | |
790 | |
791 | |
792 | |
793 | if (data().UserDeclaredSpecialMembers & |
794 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
795 | return true; |
796 | return data().NeedOverloadResolutionForCopyConstructor; |
797 | } |
798 | |
799 | |
800 | |
801 | bool implicitCopyConstructorHasConstParam() const { |
802 | return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase && |
803 | (isAbstract() || |
804 | data().ImplicitCopyConstructorCanHaveConstParamForVBase); |
805 | } |
806 | |
807 | |
808 | |
809 | bool hasCopyConstructorWithConstParam() const { |
810 | return data().HasDeclaredCopyConstructorWithConstParam || |
811 | (needsImplicitCopyConstructor() && |
812 | implicitCopyConstructorHasConstParam()); |
813 | } |
814 | |
815 | |
816 | |
817 | |
818 | |
819 | |
820 | bool hasUserDeclaredMoveOperation() const { |
821 | return data().UserDeclaredSpecialMembers & |
822 | (SMF_MoveConstructor | SMF_MoveAssignment); |
823 | } |
824 | |
825 | |
826 | |
827 | bool hasUserDeclaredMoveConstructor() const { |
828 | return data().UserDeclaredSpecialMembers & SMF_MoveConstructor; |
829 | } |
830 | |
831 | |
832 | bool hasMoveConstructor() const { |
833 | return (data().DeclaredSpecialMembers & SMF_MoveConstructor) || |
834 | needsImplicitMoveConstructor(); |
835 | } |
836 | |
837 | |
838 | |
839 | void setImplicitCopyConstructorIsDeleted() { |
840 | assert((data().DefaultedCopyConstructorIsDeleted || |
841 | needsOverloadResolutionForCopyConstructor()) && |
842 | "Copy constructor should not be deleted"); |
843 | data().DefaultedCopyConstructorIsDeleted = true; |
844 | } |
845 | |
846 | |
847 | |
848 | void setImplicitMoveConstructorIsDeleted() { |
849 | assert((data().DefaultedMoveConstructorIsDeleted || |
850 | needsOverloadResolutionForMoveConstructor()) && |
851 | "move constructor should not be deleted"); |
852 | data().DefaultedMoveConstructorIsDeleted = true; |
853 | } |
854 | |
855 | |
856 | |
857 | void setImplicitDestructorIsDeleted() { |
858 | assert((data().DefaultedDestructorIsDeleted || |
859 | needsOverloadResolutionForDestructor()) && |
860 | "destructor should not be deleted"); |
861 | data().DefaultedDestructorIsDeleted = true; |
862 | } |
863 | |
864 | |
865 | |
866 | bool needsImplicitMoveConstructor() const { |
867 | return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) && |
868 | !hasUserDeclaredCopyConstructor() && |
869 | !hasUserDeclaredCopyAssignment() && |
870 | !hasUserDeclaredMoveAssignment() && |
871 | !hasUserDeclaredDestructor(); |
872 | } |
873 | |
874 | |
875 | |
876 | bool needsOverloadResolutionForMoveConstructor() const { |
877 | return data().NeedOverloadResolutionForMoveConstructor; |
878 | } |
879 | |
880 | |
881 | |
882 | |
883 | |
884 | bool hasUserDeclaredCopyAssignment() const { |
885 | return data().UserDeclaredSpecialMembers & SMF_CopyAssignment; |
886 | } |
887 | |
888 | |
889 | |
890 | void setImplicitCopyAssignmentIsDeleted() { |
891 | assert((data().DefaultedCopyAssignmentIsDeleted || |
892 | needsOverloadResolutionForCopyAssignment()) && |
893 | "copy assignment should not be deleted"); |
894 | data().DefaultedCopyAssignmentIsDeleted = true; |
895 | } |
896 | |
897 | |
898 | |
899 | bool needsImplicitCopyAssignment() const { |
900 | return !(data().DeclaredSpecialMembers & SMF_CopyAssignment); |
901 | } |
902 | |
903 | |
904 | |
905 | bool needsOverloadResolutionForCopyAssignment() const { |
906 | |
907 | |
908 | |
909 | |
910 | |
911 | |
912 | if (data().UserDeclaredSpecialMembers & |
913 | (SMF_MoveConstructor | SMF_MoveAssignment)) |
914 | return true; |
915 | return data().NeedOverloadResolutionForCopyAssignment; |
916 | } |
917 | |
918 | |
919 | |
920 | bool implicitCopyAssignmentHasConstParam() const { |
921 | return data().ImplicitCopyAssignmentHasConstParam; |
922 | } |
923 | |
924 | |
925 | |
926 | |
927 | bool hasCopyAssignmentWithConstParam() const { |
928 | return data().HasDeclaredCopyAssignmentWithConstParam || |
929 | (needsImplicitCopyAssignment() && |
930 | implicitCopyAssignmentHasConstParam()); |
931 | } |
932 | |
933 | |
934 | |
935 | bool hasUserDeclaredMoveAssignment() const { |
936 | return data().UserDeclaredSpecialMembers & SMF_MoveAssignment; |
937 | } |
938 | |
939 | |
940 | bool hasMoveAssignment() const { |
941 | return (data().DeclaredSpecialMembers & SMF_MoveAssignment) || |
942 | needsImplicitMoveAssignment(); |
943 | } |
944 | |
945 | |
946 | |
947 | void setImplicitMoveAssignmentIsDeleted() { |
948 | assert((data().DefaultedMoveAssignmentIsDeleted || |
949 | needsOverloadResolutionForMoveAssignment()) && |
950 | "move assignment should not be deleted"); |
951 | data().DefaultedMoveAssignmentIsDeleted = true; |
952 | } |
953 | |
954 | |
955 | |
956 | |
957 | bool needsImplicitMoveAssignment() const { |
958 | return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) && |
959 | !hasUserDeclaredCopyConstructor() && |
960 | !hasUserDeclaredCopyAssignment() && |
961 | !hasUserDeclaredMoveConstructor() && |
962 | !hasUserDeclaredDestructor() && |
963 | (!isLambda() || lambdaIsDefaultConstructibleAndAssignable()); |
964 | } |
965 | |
966 | |
967 | |
968 | bool needsOverloadResolutionForMoveAssignment() const { |
969 | return data().NeedOverloadResolutionForMoveAssignment; |
970 | } |
971 | |
972 | |
973 | |
974 | |
975 | bool hasUserDeclaredDestructor() const { |
976 | return data().UserDeclaredSpecialMembers & SMF_Destructor; |
977 | } |
978 | |
979 | |
980 | |
981 | bool needsImplicitDestructor() const { |
982 | return !(data().DeclaredSpecialMembers & SMF_Destructor); |
983 | } |
984 | |
985 | |
986 | |
987 | bool needsOverloadResolutionForDestructor() const { |
988 | return data().NeedOverloadResolutionForDestructor; |
989 | } |
990 | |
991 | |
992 | bool isLambda() const { |
993 | |
994 | auto *DD = DefinitionData; |
995 | return DD && DD->IsLambda; |
996 | } |
997 | |
998 | |
999 | |
1000 | |
1001 | bool isGenericLambda() const; |
1002 | |
1003 | |
1004 | |
1005 | bool lambdaIsDefaultConstructibleAndAssignable() const; |
1006 | |
1007 | |
1008 | |
1009 | CXXMethodDecl *getLambdaCallOperator() const; |
1010 | |
1011 | |
1012 | |
1013 | FunctionTemplateDecl *getDependentLambdaCallOperator() const; |
1014 | |
1015 | |
1016 | |
1017 | |
1018 | |
1019 | |
1020 | |
1021 | |
1022 | CXXMethodDecl *getLambdaStaticInvoker() const; |
1023 | CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const; |
1024 | |
1025 | |
1026 | |
1027 | |
1028 | TemplateParameterList *getGenericLambdaTemplateParameterList() const; |
1029 | |
1030 | |
1031 | ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const; |
1032 | |
1033 | LambdaCaptureDefault getLambdaCaptureDefault() const { |
1034 | assert(isLambda()); |
1035 | return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault); |
1036 | } |
1037 | |
1038 | |
1039 | void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures); |
1040 | |
1041 | |
1042 | |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | |
1053 | void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures, |
1054 | FieldDecl *&ThisCapture) const; |
1055 | |
1056 | using capture_const_iterator = const LambdaCapture *; |
1057 | using capture_const_range = llvm::iterator_range<capture_const_iterator>; |
1058 | |
1059 | capture_const_range captures() const { |
1060 | return capture_const_range(captures_begin(), captures_end()); |
1061 | } |
1062 | |
1063 | capture_const_iterator captures_begin() const { |
1064 | return isLambda() ? getLambdaData().Captures : nullptr; |
1065 | } |
1066 | |
1067 | capture_const_iterator captures_end() const { |
1068 | return isLambda() ? captures_begin() + getLambdaData().NumCaptures |
1069 | : nullptr; |
1070 | } |
1071 | |
1072 | unsigned capture_size() const { return getLambdaData().NumCaptures; } |
1073 | |
1074 | using conversion_iterator = UnresolvedSetIterator; |
1075 | |
1076 | conversion_iterator conversion_begin() const { |
1077 | return data().Conversions.get(getASTContext()).begin(); |
1078 | } |
1079 | |
1080 | conversion_iterator conversion_end() const { |
1081 | return data().Conversions.get(getASTContext()).end(); |
1082 | } |
1083 | |
1084 | |
1085 | |
1086 | |
1087 | void removeConversion(const NamedDecl *Old); |
1088 | |
1089 | |
1090 | |
1091 | llvm::iterator_range<conversion_iterator> |
1092 | getVisibleConversionFunctions() const; |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | |
1098 | bool isAggregate() const { return data().Aggregate; } |
1099 | |
1100 | |
1101 | |
1102 | |
1103 | bool hasInClassInitializer() const { return data().HasInClassInitializer; } |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 | |
1113 | bool hasUninitializedReferenceMember() const { |
1114 | return !isUnion() && !hasUserDeclaredConstructor() && |
1115 | data().HasUninitializedReferenceMember; |
1116 | } |
1117 | |
1118 | |
1119 | |
1120 | |
1121 | |
1122 | |
1123 | |
1124 | |
1125 | |
1126 | bool isPOD() const { return data().PlainOldData; } |
1127 | |
1128 | |
1129 | |
1130 | bool isCLike() const; |
1131 | |
1132 | |
1133 | |
1134 | |
1135 | |
1136 | |
1137 | |
1138 | |
1139 | |
1140 | |
1141 | bool isEmpty() const { return data().Empty; } |
1142 | |
1143 | bool hasPrivateFields() const { |
1144 | return data().HasPrivateFields; |
1145 | } |
1146 | |
1147 | bool hasProtectedFields() const { |
1148 | return data().HasProtectedFields; |
1149 | } |
1150 | |
1151 | |
1152 | bool hasDirectFields() const { |
1153 | auto &D = data(); |
1154 | return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields; |
1155 | } |
1156 | |
1157 | |
1158 | |
1159 | bool isPolymorphic() const { return data().Polymorphic; } |
1160 | |
1161 | |
1162 | |
1163 | |
1164 | |
1165 | |
1166 | bool isAbstract() const { return data().Abstract; } |
1167 | |
1168 | |
1169 | |
1170 | bool isStandardLayout() const { return data().IsStandardLayout; } |
1171 | |
1172 | |
1173 | |
1174 | bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; } |
1175 | |
1176 | |
1177 | |
1178 | bool hasMutableFields() const { return data().HasMutableFields; } |
1179 | |
1180 | |
1181 | bool hasVariantMembers() const { return data().HasVariantMembers; } |
1182 | |
1183 | |
1184 | |
1185 | bool hasTrivialDefaultConstructor() const { |
1186 | return hasDefaultConstructor() && |
1187 | (data().HasTrivialSpecialMembers & SMF_DefaultConstructor); |
1188 | } |
1189 | |
1190 | |
1191 | |
1192 | bool hasNonTrivialDefaultConstructor() const { |
1193 | return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) || |
1194 | (needsImplicitDefaultConstructor() && |
1195 | !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor)); |
1196 | } |
1197 | |
1198 | |
1199 | |
1200 | bool hasConstexprNonCopyMoveConstructor() const { |
1201 | return data().HasConstexprNonCopyMoveConstructor || |
1202 | (needsImplicitDefaultConstructor() && |
1203 | defaultedDefaultConstructorIsConstexpr()); |
1204 | } |
1205 | |
1206 | |
1207 | |
1208 | bool defaultedDefaultConstructorIsConstexpr() const { |
1209 | return data().DefaultedDefaultConstructorIsConstexpr && |
1210 | (!isUnion() || hasInClassInitializer() || !hasVariantMembers() || |
1211 | getLangOpts().CPlusPlus20); |
1212 | } |
1213 | |
1214 | |
1215 | bool hasConstexprDefaultConstructor() const { |
1216 | return data().HasConstexprDefaultConstructor || |
1217 | (needsImplicitDefaultConstructor() && |
1218 | defaultedDefaultConstructorIsConstexpr()); |
1219 | } |
1220 | |
1221 | |
1222 | |
1223 | bool hasTrivialCopyConstructor() const { |
1224 | return data().HasTrivialSpecialMembers & SMF_CopyConstructor; |
1225 | } |
1226 | |
1227 | bool hasTrivialCopyConstructorForCall() const { |
1228 | return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor; |
1229 | } |
1230 | |
1231 | |
1232 | |
1233 | bool hasNonTrivialCopyConstructor() const { |
1234 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor || |
1235 | !hasTrivialCopyConstructor(); |
1236 | } |
1237 | |
1238 | bool hasNonTrivialCopyConstructorForCall() const { |
1239 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1240 | SMF_CopyConstructor) || |
1241 | !hasTrivialCopyConstructorForCall(); |
1242 | } |
1243 | |
1244 | |
1245 | |
1246 | bool hasTrivialMoveConstructor() const { |
1247 | return hasMoveConstructor() && |
1248 | (data().HasTrivialSpecialMembers & SMF_MoveConstructor); |
1249 | } |
1250 | |
1251 | bool hasTrivialMoveConstructorForCall() const { |
1252 | return hasMoveConstructor() && |
1253 | (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor); |
1254 | } |
1255 | |
1256 | |
1257 | |
1258 | bool hasNonTrivialMoveConstructor() const { |
1259 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) || |
1260 | (needsImplicitMoveConstructor() && |
1261 | !(data().HasTrivialSpecialMembers & SMF_MoveConstructor)); |
1262 | } |
1263 | |
1264 | bool hasNonTrivialMoveConstructorForCall() const { |
1265 | return (data().DeclaredNonTrivialSpecialMembersForCall & |
1266 | SMF_MoveConstructor) || |
1267 | (needsImplicitMoveConstructor() && |
1268 | !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor)); |
1269 | } |
1270 | |
1271 | |
1272 | |
1273 | bool hasTrivialCopyAssignment() const { |
1274 | return data().HasTrivialSpecialMembers & SMF_CopyAssignment; |
1275 | } |
1276 | |
1277 | |
1278 | |
1279 | bool hasNonTrivialCopyAssignment() const { |
1280 | return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment || |
1281 | !hasTrivialCopyAssignment(); |
1282 | } |
1283 | |
1284 | |
1285 | |
1286 | bool hasTrivialMoveAssignment() const { |
1287 | return hasMoveAssignment() && |
1288 | (data().HasTrivialSpecialMembers & SMF_MoveAssignment); |
1289 | } |
1290 | |
1291 | |
1292 | |
1293 | bool hasNonTrivialMoveAssignment() const { |
1294 | return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) || |
1295 | (needsImplicitMoveAssignment() && |
1296 | !(data().HasTrivialSpecialMembers & SMF_MoveAssignment)); |
1297 | } |
1298 | |
1299 | |
1300 | |
1301 | bool defaultedDestructorIsConstexpr() const { |
1302 | return data().DefaultedDestructorIsConstexpr && |
1303 | getLangOpts().CPlusPlus20; |
1304 | } |
1305 | |
1306 | |
1307 | bool hasConstexprDestructor() const; |
1308 | |
1309 | |
1310 | |
1311 | bool hasTrivialDestructor() const { |
1312 | return data().HasTrivialSpecialMembers & SMF_Destructor; |
1313 | } |
1314 | |
1315 | bool hasTrivialDestructorForCall() const { |
1316 | return data().HasTrivialSpecialMembersForCall & SMF_Destructor; |
1317 | } |
1318 | |
1319 | |
1320 | |
1321 | bool hasNonTrivialDestructor() const { |
1322 | return !(data().HasTrivialSpecialMembers & SMF_Destructor); |
1323 | } |
1324 | |
1325 | bool hasNonTrivialDestructorForCall() const { |
1326 | return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor); |
1327 | } |
1328 | |
1329 | void setHasTrivialSpecialMemberForCall() { |
1330 | data().HasTrivialSpecialMembersForCall = |
1331 | (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor); |
1332 | } |
1333 | |
1334 | |
1335 | |
1336 | bool allowConstDefaultInit() const { |
1337 | return !data().HasUninitializedFields || |
1338 | !(data().HasDefaultedDefaultConstructor || |
1339 | needsImplicitDefaultConstructor()); |
1340 | } |
1341 | |
1342 | |
1343 | |
1344 | |
1345 | |
1346 | |
1347 | bool hasIrrelevantDestructor() const { |
1348 | return data().HasIrrelevantDestructor; |
1349 | } |
1350 | |
1351 | |
1352 | |
1353 | bool hasNonLiteralTypeFieldsOrBases() const { |
1354 | return data().HasNonLiteralTypeFieldsOrBases; |
1355 | } |
1356 | |
1357 | |
1358 | |
1359 | bool hasInheritedConstructor() const { |
1360 | return data().HasInheritedConstructor; |
1361 | } |
1362 | |
1363 | |
1364 | |
1365 | bool hasInheritedAssignment() const { |
1366 | return data().HasInheritedAssignment; |
1367 | } |
1368 | |
1369 | |
1370 | |
1371 | bool isTriviallyCopyable() const; |
1372 | |
1373 | |
1374 | |
1375 | |
1376 | |
1377 | |
1378 | bool isTrivial() const { |
1379 | return isTriviallyCopyable() && hasTrivialDefaultConstructor(); |
1380 | } |
1381 | |
1382 | |
1383 | |
1384 | |
1385 | |
1386 | |
1387 | |
1388 | |
1389 | |
1390 | |
1391 | |
1392 | |
1393 | |
1394 | |
1395 | |
1396 | |
1397 | |
1398 | |
1399 | bool isLiteral() const { |
1400 | const LangOptions &LangOpts = getLangOpts(); |
1401 | return (LangOpts.CPlusPlus20 ? hasConstexprDestructor() |
1402 | : hasTrivialDestructor()) && |
1403 | (!isLambda() || LangOpts.CPlusPlus17) && |
1404 | !hasNonLiteralTypeFieldsOrBases() && |
1405 | (isAggregate() || isLambda() || |
1406 | hasConstexprNonCopyMoveConstructor() || |
1407 | hasTrivialDefaultConstructor()); |
1408 | } |
1409 | |
1410 | |
1411 | bool isStructural() const { |
1412 | return isLiteral() && data().StructuralIfLiteral; |
1413 | } |
1414 | |
1415 | |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | |
1421 | |
1422 | |
1423 | |
1424 | |
1425 | |
1426 | |
1427 | |
1428 | |
1429 | |
1430 | |
1431 | |
1432 | |
1433 | |
1434 | CXXRecordDecl *getInstantiatedFromMemberClass() const; |
1435 | |
1436 | |
1437 | |
1438 | |
1439 | MemberSpecializationInfo *getMemberSpecializationInfo() const; |
1440 | |
1441 | |
1442 | |
1443 | void setInstantiationOfMemberClass(CXXRecordDecl *RD, |
1444 | TemplateSpecializationKind TSK); |
1445 | |
1446 | |
1447 | |
1448 | |
1449 | |
1450 | |
1451 | |
1452 | |
1453 | |
1454 | |
1455 | |
1456 | |
1457 | ClassTemplateDecl *getDescribedClassTemplate() const; |
1458 | |
1459 | void setDescribedClassTemplate(ClassTemplateDecl *Template); |
1460 | |
1461 | |
1462 | |
1463 | |
1464 | TemplateSpecializationKind getTemplateSpecializationKind() const; |
1465 | |
1466 | |
1467 | void setTemplateSpecializationKind(TemplateSpecializationKind TSK); |
1468 | |
1469 | |
1470 | |
1471 | const CXXRecordDecl *getTemplateInstantiationPattern() const; |
1472 | |
1473 | CXXRecordDecl *getTemplateInstantiationPattern() { |
1474 | return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this) |
1475 | ->getTemplateInstantiationPattern()); |
1476 | } |
1477 | |
1478 | |
1479 | CXXDestructorDecl *getDestructor() const; |
1480 | |
1481 | |
1482 | |
1483 | bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; } |
1484 | |
1485 | |
1486 | |
1487 | const FunctionDecl *isLocalClass() const { |
1488 | if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext())) |
1489 | return RD->isLocalClass(); |
1490 | |
1491 | return dyn_cast<FunctionDecl>(getDeclContext()); |
1492 | } |
1493 | |
1494 | FunctionDecl *isLocalClass() { |
1495 | return const_cast<FunctionDecl*>( |
1496 | const_cast<const CXXRecordDecl*>(this)->isLocalClass()); |
1497 | } |
1498 | |
1499 | |
1500 | |
1501 | bool isCurrentInstantiation(const DeclContext *CurContext) const; |
1502 | |
1503 | |
1504 | |
1505 | |
1506 | |
1507 | |
1508 | |
1509 | |
1510 | |
1511 | |
1512 | |
1513 | bool isDerivedFrom(const CXXRecordDecl *Base) const; |
1514 | |
1515 | |
1516 | |
1517 | |
1518 | |
1519 | |
1520 | |
1521 | |
1522 | |
1523 | |
1524 | |
1525 | |
1526 | |
1527 | |
1528 | |
1529 | |
1530 | |
1531 | bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; |
1532 | |
1533 | |
1534 | |
1535 | |
1536 | |
1537 | |
1538 | |
1539 | |
1540 | |
1541 | |
1542 | |
1543 | |
1544 | |
1545 | |
1546 | bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const; |
1547 | |
1548 | |
1549 | |
1550 | bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const; |
1551 | |
1552 | |
1553 | |
1554 | |
1555 | |
1556 | |
1557 | using ForallBasesCallback = |
1558 | llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>; |
1559 | |
1560 | |
1561 | |
1562 | |
1563 | |
1564 | |
1565 | |
1566 | |
1567 | |
1568 | bool forallBases(ForallBasesCallback BaseMatches) const; |
1569 | |
1570 | |
1571 | |
1572 | |
1573 | |
1574 | |
1575 | |
1576 | |
1577 | |
1578 | |
1579 | |
1580 | using BaseMatchesCallback = |
1581 | llvm::function_ref<bool(const CXXBaseSpecifier *Specifier, |
1582 | CXXBasePath &Path)>; |
1583 | |
1584 | |
1585 | |
1586 | |
1587 | |
1588 | |
1589 | |
1590 | |
1591 | |
1592 | |
1593 | |
1594 | |
1595 | |
1596 | |
1597 | |
1598 | |
1599 | |
1600 | |
1601 | |
1602 | |
1603 | |
1604 | |
1605 | bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, |
1606 | bool LookupInDependent = false) const; |
1607 | |
1608 | |
1609 | |
1610 | |
1611 | |
1612 | |
1613 | |
1614 | |
1615 | static bool FindBaseClass(const CXXBaseSpecifier *Specifier, |
1616 | CXXBasePath &Path, const CXXRecordDecl *BaseRecord); |
1617 | |
1618 | |
1619 | |
1620 | |
1621 | |
1622 | |
1623 | |
1624 | |
1625 | |
1626 | |
1627 | static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier, |
1628 | CXXBasePath &Path, |
1629 | const CXXRecordDecl *BaseRecord); |
1630 | |
1631 | |
1632 | |
1633 | |
1634 | void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const; |
1635 | |
1636 | |
1637 | void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const; |
1638 | |
1639 | |
1640 | |
1641 | |
1642 | |
1643 | |
1644 | |
1645 | bool hasMemberName(DeclarationName N) const; |
1646 | |
1647 | |
1648 | |
1649 | |
1650 | |
1651 | std::vector<const NamedDecl *> |
1652 | lookupDependentName(DeclarationName Name, |
1653 | llvm::function_ref<bool(const NamedDecl *ND)> Filter); |
1654 | |
1655 | |
1656 | |
1657 | |
1658 | void viewInheritance(ASTContext& Context) const; |
1659 | |
1660 | |
1661 | |
1662 | static AccessSpecifier MergeAccess(AccessSpecifier PathAccess, |
1663 | AccessSpecifier DeclAccess) { |
1664 | assert(DeclAccess != AS_none); |
1665 | if (DeclAccess == AS_private) return AS_none; |
1666 | return (PathAccess > DeclAccess ? PathAccess : DeclAccess); |
1667 | } |
1668 | |
1669 | |
1670 | |
1671 | void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD); |
1672 | |
1673 | void setTrivialForCallFlags(CXXMethodDecl *MD); |
1674 | |
1675 | |
1676 | void completeDefinition() override; |
1677 | |
1678 | |
1679 | |
1680 | |
1681 | |
1682 | |
1683 | |
1684 | |
1685 | void completeDefinition(CXXFinalOverriderMap *FinalOverriders); |
1686 | |
1687 | |
1688 | |
1689 | |
1690 | |
1691 | |
1692 | |
1693 | |
1694 | bool mayBeAbstract() const; |
1695 | |
1696 | |
1697 | |
1698 | bool isEffectivelyFinal() const; |
1699 | |
1700 | |
1701 | |
1702 | |
1703 | |
1704 | |
1705 | |
1706 | unsigned getLambdaManglingNumber() const { |
1707 | assert(isLambda() && "Not a lambda closure type!"); |
1708 | return getLambdaData().ManglingNumber; |
1709 | } |
1710 | |
1711 | |
1712 | |
1713 | bool hasKnownLambdaInternalLinkage() const { |
1714 | assert(isLambda() && "Not a lambda closure type!"); |
1715 | return getLambdaData().HasKnownInternalLinkage; |
1716 | } |
1717 | |
1718 | |
1719 | |
1720 | |
1721 | |
1722 | |
1723 | |
1724 | |
1725 | |
1726 | |
1727 | Decl *getLambdaContextDecl() const; |
1728 | |
1729 | |
1730 | |
1731 | void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl, |
1732 | bool HasKnownInternalLinkage = false) { |
1733 | assert(isLambda() && "Not a lambda closure type!"); |
1734 | getLambdaData().ManglingNumber = ManglingNumber; |
1735 | getLambdaData().ContextDecl = ContextDecl; |
1736 | getLambdaData().HasKnownInternalLinkage = HasKnownInternalLinkage; |
1737 | } |
1738 | |
1739 | |
1740 | void setDeviceLambdaManglingNumber(unsigned Num) const; |
1741 | |
1742 | |
1743 | unsigned getDeviceLambdaManglingNumber() const; |
1744 | |
1745 | |
1746 | MSInheritanceModel getMSInheritanceModel() const; |
1747 | |
1748 | |
1749 | MSInheritanceModel calculateInheritanceModel() const; |
1750 | |
1751 | |
1752 | |
1753 | |
1754 | |
1755 | |
1756 | |
1757 | bool nullFieldOffsetIsZero() const; |
1758 | |
1759 | |
1760 | |
1761 | MSVtorDispMode getMSVtorDispMode() const; |
1762 | |
1763 | |
1764 | |
1765 | |
1766 | |
1767 | |
1768 | |
1769 | |
1770 | |
1771 | |
1772 | |
1773 | |
1774 | bool isDependentLambda() const { |
1775 | return isLambda() && getLambdaData().Dependent; |
1776 | } |
1777 | |
1778 | TypeSourceInfo *getLambdaTypeInfo() const { |
1779 | return getLambdaData().MethodTyInfo; |
1780 | } |
1781 | |
1782 | |
1783 | |
1784 | bool isInterfaceLike() const; |
1785 | |
1786 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1787 | static bool classofKind(Kind K) { |
1788 | return K >= firstCXXRecord && K <= lastCXXRecord; |
1789 | } |
1790 | void markAbstract() { data().Abstract = true; } |
1791 | }; |
1792 | |
1793 | |
1794 | |
1795 | class ExplicitSpecifier { |
1796 | llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{ |
1797 | nullptr, ExplicitSpecKind::ResolvedFalse}; |
1798 | |
1799 | public: |
1800 | ExplicitSpecifier() = default; |
1801 | ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind) |
1802 | : ExplicitSpec(Expression, Kind) {} |
1803 | ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); } |
1804 | const Expr *getExpr() const { return ExplicitSpec.getPointer(); } |
1805 | Expr *getExpr() { return ExplicitSpec.getPointer(); } |
1806 | |
1807 | |
1808 | bool isSpecified() const { |
1809 | return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse || |
1810 | ExplicitSpec.getPointer(); |
1811 | } |
1812 | |
1813 | |
1814 | |
1815 | bool isEquivalent(const ExplicitSpecifier Other) const; |
1816 | |
1817 | |
1818 | |
1819 | bool isExplicit() const { |
1820 | return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue; |
1821 | } |
1822 | |
1823 | |
1824 | bool isInvalid() const { |
1825 | return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved && |
1826 | !ExplicitSpec.getPointer(); |
1827 | } |
1828 | void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); } |
1829 | void setExpr(Expr *E) { ExplicitSpec.setPointer(E); } |
1830 | |
1831 | static ExplicitSpecifier getFromDecl(FunctionDecl *Function); |
1832 | static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) { |
1833 | return getFromDecl(const_cast<FunctionDecl *>(Function)); |
1834 | } |
1835 | static ExplicitSpecifier Invalid() { |
1836 | return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved); |
1837 | } |
1838 | }; |
1839 | |
1840 | |
1841 | |
1842 | |
1843 | |
1844 | |
1845 | |
1846 | |
1847 | |
1848 | |
1849 | |
1850 | class CXXDeductionGuideDecl : public FunctionDecl { |
1851 | void anchor() override; |
1852 | |
1853 | private: |
1854 | CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1855 | ExplicitSpecifier ES, |
1856 | const DeclarationNameInfo &NameInfo, QualType T, |
1857 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
1858 | CXXConstructorDecl *Ctor) |
1859 | : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo, |
1860 | SC_None, false, ConstexprSpecKind::Unspecified), |
1861 | Ctor(Ctor), ExplicitSpec(ES) { |
1862 | if (EndLocation.isValid()) |
1863 | setRangeEnd(EndLocation); |
1864 | setIsCopyDeductionCandidate(false); |
1865 | } |
1866 | |
1867 | CXXConstructorDecl *Ctor; |
1868 | ExplicitSpecifier ExplicitSpec; |
1869 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
1870 | |
1871 | public: |
1872 | friend class ASTDeclReader; |
1873 | friend class ASTDeclWriter; |
1874 | |
1875 | static CXXDeductionGuideDecl * |
1876 | Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
1877 | ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, |
1878 | TypeSourceInfo *TInfo, SourceLocation EndLocation, |
1879 | CXXConstructorDecl *Ctor = nullptr); |
1880 | |
1881 | static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1882 | |
1883 | ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; } |
1884 | const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; } |
1885 | |
1886 | |
1887 | bool isExplicit() const { return ExplicitSpec.isExplicit(); } |
1888 | |
1889 | |
1890 | TemplateDecl *getDeducedTemplate() const { |
1891 | return getDeclName().getCXXDeductionGuideTemplate(); |
1892 | } |
1893 | |
1894 | |
1895 | |
1896 | CXXConstructorDecl *getCorrespondingConstructor() const { |
1897 | return Ctor; |
1898 | } |
1899 | |
1900 | void setIsCopyDeductionCandidate(bool isCDC = true) { |
1901 | FunctionDeclBits.IsCopyDeductionCandidate = isCDC; |
1902 | } |
1903 | |
1904 | bool isCopyDeductionCandidate() const { |
1905 | return FunctionDeclBits.IsCopyDeductionCandidate; |
1906 | } |
1907 | |
1908 | |
1909 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1910 | static bool classofKind(Kind K) { return K == CXXDeductionGuide; } |
1911 | }; |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | |
1918 | |
1919 | |
1920 | |
1921 | |
1922 | |
1923 | |
1924 | |
1925 | |
1926 | class RequiresExprBodyDecl : public Decl, public DeclContext { |
1927 | RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc) |
1928 | : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {} |
1929 | |
1930 | public: |
1931 | friend class ASTDeclReader; |
1932 | friend class ASTDeclWriter; |
1933 | |
1934 | static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC, |
1935 | SourceLocation StartLoc); |
1936 | |
1937 | static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1938 | |
1939 | |
1940 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
1941 | static bool classofKind(Kind K) { return K == RequiresExprBody; } |
1942 | }; |
1943 | |
1944 | |
1945 | |
1946 | |
1947 | |
1948 | class CXXMethodDecl : public FunctionDecl { |
1949 | void anchor() override; |
1950 | |
1951 | protected: |
1952 | CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD, |
1953 | SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, |
1954 | QualType T, TypeSourceInfo *TInfo, StorageClass SC, |
1955 | bool isInline, ConstexprSpecKind ConstexprKind, |
1956 | SourceLocation EndLocation, |
1957 | Expr *TrailingRequiresClause = nullptr) |
1958 | : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, isInline, |
1959 | ConstexprKind, TrailingRequiresClause) { |
1960 | if (EndLocation.isValid()) |
1961 | setRangeEnd(EndLocation); |
1962 | } |
1963 | |
1964 | public: |
1965 | static CXXMethodDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
1966 | SourceLocation StartLoc, |
1967 | const DeclarationNameInfo &NameInfo, QualType T, |
1968 | TypeSourceInfo *TInfo, StorageClass SC, |
1969 | bool isInline, ConstexprSpecKind ConstexprKind, |
1970 | SourceLocation EndLocation, |
1971 | Expr *TrailingRequiresClause = nullptr); |
1972 | |
1973 | static CXXMethodDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
1974 | |
1975 | bool isStatic() const; |
1976 | bool isInstance() const { return !isStatic(); } |
1977 | |
1978 | |
1979 | |
1980 | static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) { |
1981 | |
1982 | |
1983 | |
1984 | |
1985 | |
1986 | return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete || |
1987 | OOK == OO_Array_Delete; |
1988 | } |
1989 | |
1990 | bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); } |
1991 | bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); } |
1992 | |
1993 | bool isVirtual() const { |
1994 | CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
1995 | |
1996 | |
1997 | |
1998 | if (CD->isVirtualAsWritten() || CD->isPure()) |
1999 | return true; |
2000 | |
2001 | return CD->size_overridden_methods() != 0; |
2002 | } |
2003 | |
2004 | |
2005 | |
2006 | |
2007 | |
2008 | |
2009 | CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext); |
2010 | |
2011 | const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, |
2012 | bool IsAppleKext) const { |
2013 | return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod( |
2014 | Base, IsAppleKext); |
2015 | } |
2016 | |
2017 | |
2018 | |
2019 | |
2020 | |
2021 | |
2022 | |
2023 | |
2024 | bool isUsualDeallocationFunction( |
2025 | SmallVectorImpl<const FunctionDecl *> &PreventedBy) const; |
2026 | |
2027 | |
2028 | |
2029 | bool isCopyAssignmentOperator() const; |
2030 | |
2031 | |
2032 | bool isMoveAssignmentOperator() const; |
2033 | |
2034 | CXXMethodDecl *getCanonicalDecl() override { |
2035 | return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl()); |
2036 | } |
2037 | const CXXMethodDecl *getCanonicalDecl() const { |
2038 | return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl(); |
2039 | } |
2040 | |
2041 | CXXMethodDecl *getMostRecentDecl() { |
2042 | return cast<CXXMethodDecl>( |
2043 | static_cast<FunctionDecl *>(this)->getMostRecentDecl()); |
2044 | } |
2045 | const CXXMethodDecl *getMostRecentDecl() const { |
2046 | return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl(); |
2047 | } |
2048 | |
2049 | void addOverriddenMethod(const CXXMethodDecl *MD); |
2050 | |
2051 | using method_iterator = const CXXMethodDecl *const *; |
2052 | |
2053 | method_iterator begin_overridden_methods() const; |
2054 | method_iterator end_overridden_methods() const; |
2055 | unsigned size_overridden_methods() const; |
2056 | |
2057 | using overridden_method_range = llvm::iterator_range< |
2058 | llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>; |
2059 | |
2060 | overridden_method_range overridden_methods() const; |
2061 | |
2062 | |
2063 | |
2064 | const CXXRecordDecl *getParent() const { |
2065 | return cast<CXXRecordDecl>(FunctionDecl::getParent()); |
2066 | } |
2067 | |
2068 | |
2069 | |
2070 | CXXRecordDecl *getParent() { |
2071 | return const_cast<CXXRecordDecl *>( |
2072 | cast<CXXRecordDecl>(FunctionDecl::getParent())); |
2073 | } |
2074 | |
2075 | |
2076 | |
2077 | |
2078 | |
2079 | |
2080 | |
2081 | QualType getThisType() const; |
2082 | |
2083 | |
2084 | |
2085 | |
2086 | QualType getThisObjectType() const; |
2087 | |
2088 | static QualType getThisType(const FunctionProtoType *FPT, |
2089 | const CXXRecordDecl *Decl); |
2090 | |
2091 | static QualType getThisObjectType(const FunctionProtoType *FPT, |
2092 | const CXXRecordDecl *Decl); |
2093 | |
2094 | Qualifiers getMethodQualifiers() const { |
2095 | return getType()->castAs<FunctionProtoType>()->getMethodQuals(); |
2096 | } |
2097 | |
2098 | |
2099 | |
2100 | |
2101 | |
2102 | |
2103 | |
2104 | |
2105 | |
2106 | |
2107 | |
2108 | |
2109 | RefQualifierKind getRefQualifier() const { |
2110 | return getType()->castAs<FunctionProtoType>()->getRefQualifier(); |
2111 | } |
2112 | |
2113 | bool hasInlineBody() const; |
2114 | |
2115 | |
2116 | |
2117 | |
2118 | |
2119 | |
2120 | |
2121 | |
2122 | bool isLambdaStaticInvoker() const; |
2123 | |
2124 | |
2125 | |
2126 | |
2127 | |
2128 | |
2129 | CXXMethodDecl * |
2130 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2131 | bool MayBeBase = false); |
2132 | |
2133 | const CXXMethodDecl * |
2134 | getCorrespondingMethodInClass(const CXXRecordDecl *RD, |
2135 | bool MayBeBase = false) const { |
2136 | return const_cast<CXXMethodDecl *>(this) |
2137 | ->getCorrespondingMethodInClass(RD, MayBeBase); |
2138 | } |
2139 | |
2140 | |
2141 | |
2142 | CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2143 | bool MayBeBase = false); |
2144 | const CXXMethodDecl * |
2145 | getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD, |
2146 | bool MayBeBase = false) const { |
2147 | return const_cast<CXXMethodDecl *>(this) |
2148 | ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase); |
2149 | } |
2150 | |
2151 | |
2152 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2153 | static bool classofKind(Kind K) { |
2154 | return K >= firstCXXMethod && K <= lastCXXMethod; |
2155 | } |
2156 | }; |
2157 | |
2158 | |
2159 | |
2160 | |
2161 | |
2162 | |
2163 | |
2164 | |
2165 | |
2166 | |
2167 | |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | |
2173 | class CXXCtorInitializer final { |
2174 | |
2175 | |
2176 | |
2177 | llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *> |
2178 | Initializee; |
2179 | |
2180 | |
2181 | |
2182 | Stmt *Init; |
2183 | |
2184 | |
2185 | |
2186 | |
2187 | |
2188 | |
2189 | |
2190 | SourceLocation MemberOrEllipsisLocation; |
2191 | |
2192 | |
2193 | SourceLocation LParenLoc; |
2194 | |
2195 | |
2196 | SourceLocation RParenLoc; |
2197 | |
2198 | |
2199 | |
2200 | unsigned IsDelegating : 1; |
2201 | |
2202 | |
2203 | |
2204 | unsigned IsVirtual : 1; |
2205 | |
2206 | |
2207 | |
2208 | unsigned IsWritten : 1; |
2209 | |
2210 | |
2211 | |
2212 | unsigned SourceOrder : 13; |
2213 | |
2214 | public: |
2215 | |
2216 | explicit |
2217 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual, |
2218 | SourceLocation L, Expr *Init, SourceLocation R, |
2219 | SourceLocation EllipsisLoc); |
2220 | |
2221 | |
2222 | explicit |
2223 | CXXCtorInitializer(ASTContext &Context, FieldDecl *Member, |
2224 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2225 | SourceLocation R); |
2226 | |
2227 | |
2228 | explicit |
2229 | CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member, |
2230 | SourceLocation MemberLoc, SourceLocation L, Expr *Init, |
2231 | SourceLocation R); |
2232 | |
2233 | |
2234 | explicit |
2235 | CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, |
2236 | SourceLocation L, Expr *Init, SourceLocation R); |
2237 | |
2238 | |
2239 | int64_t getID(const ASTContext &Context) const; |
2240 | |
2241 | |
2242 | bool isBaseInitializer() const { |
2243 | return Initializee.is<TypeSourceInfo*>() && !IsDelegating; |
2244 | } |
2245 | |
2246 | |
2247 | |
2248 | bool isMemberInitializer() const { return Initializee.is<FieldDecl*>(); } |
2249 | |
2250 | bool isAnyMemberInitializer() const { |
2251 | return isMemberInitializer() || isIndirectMemberInitializer(); |
2252 | } |
2253 | |
2254 | bool isIndirectMemberInitializer() const { |
2255 | return Initializee.is<IndirectFieldDecl*>(); |
2256 | } |
2257 | |
2258 | |
2259 | |
2260 | |
2261 | |
2262 | |
2263 | |
2264 | bool isInClassMemberInitializer() const { |
2265 | return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass; |
2266 | } |
2267 | |
2268 | |
2269 | |
2270 | bool isDelegatingInitializer() const { |
2271 | return Initializee.is<TypeSourceInfo*>() && IsDelegating; |
2272 | } |
2273 | |
2274 | |
2275 | bool isPackExpansion() const { |
2276 | return isBaseInitializer() && MemberOrEllipsisLocation.isValid(); |
2277 | } |
2278 | |
2279 | |
2280 | SourceLocation getEllipsisLoc() const { |
2281 | if (!isPackExpansion()) |
2282 | return {}; |
2283 | return MemberOrEllipsisLocation; |
2284 | } |
2285 | |
2286 | |
2287 | |
2288 | |
2289 | TypeLoc getBaseClassLoc() const; |
2290 | |
2291 | |
2292 | |
2293 | const Type *getBaseClass() const; |
2294 | |
2295 | |
2296 | bool isBaseVirtual() const { |
2297 | assert(isBaseInitializer() && "Must call this on base initializer!"); |
2298 | |
2299 | return IsVirtual; |
2300 | } |
2301 | |
2302 | |
2303 | |
2304 | TypeSourceInfo *getTypeSourceInfo() const { |
2305 | return Initializee.dyn_cast<TypeSourceInfo *>(); |
2306 | } |
2307 | |
2308 | |
2309 | |
2310 | FieldDecl *getMember() const { |
2311 | if (isMemberInitializer()) |
2312 | return Initializee.get<FieldDecl*>(); |
2313 | return nullptr; |
2314 | } |
2315 | |
2316 | FieldDecl *getAnyMember() const { |
2317 | if (isMemberInitializer()) |
2318 | return Initializee.get<FieldDecl*>(); |
2319 | if (isIndirectMemberInitializer()) |
2320 | return Initializee.get<IndirectFieldDecl*>()->getAnonField(); |
2321 | return nullptr; |
2322 | } |
2323 | |
2324 | IndirectFieldDecl *getIndirectMember() const { |
2325 | if (isIndirectMemberInitializer()) |
2326 | return Initializee.get<IndirectFieldDecl*>(); |
2327 | return nullptr; |
2328 | } |
2329 | |
2330 | SourceLocation getMemberLocation() const { |
2331 | return MemberOrEllipsisLocation; |
2332 | } |
2333 | |
2334 | |
2335 | SourceLocation getSourceLocation() const; |
2336 | |
2337 | |
2338 | SourceRange getSourceRange() const LLVM_READONLY; |
2339 | |
2340 | |
2341 | |
2342 | bool isWritten() const { return IsWritten; } |
2343 | |
2344 | |
2345 | |
2346 | int getSourceOrder() const { |
2347 | return IsWritten ? static_cast<int>(SourceOrder) : -1; |
2348 | } |
2349 | |
2350 | |
2351 | |
2352 | |
2353 | |
2354 | |
2355 | |
2356 | |
2357 | void setSourceOrder(int Pos) { |
2358 | assert(!IsWritten && |
2359 | "setSourceOrder() used on implicit initializer"); |
2360 | assert(SourceOrder == 0 && |
2361 | "calling twice setSourceOrder() on the same initializer"); |
2362 | assert(Pos >= 0 && |
2363 | "setSourceOrder() used to make an initializer implicit"); |
2364 | IsWritten = true; |
2365 | SourceOrder = static_cast<unsigned>(Pos); |
2366 | } |
2367 | |
2368 | SourceLocation getLParenLoc() const { return LParenLoc; } |
2369 | SourceLocation getRParenLoc() const { return RParenLoc; } |
2370 | |
2371 | |
2372 | Expr *getInit() const { return static_cast<Expr *>(Init); } |
2373 | }; |
2374 | |
2375 | |
2376 | class InheritedConstructor { |
2377 | ConstructorUsingShadowDecl *Shadow = nullptr; |
2378 | CXXConstructorDecl *BaseCtor = nullptr; |
2379 | |
2380 | public: |
2381 | InheritedConstructor() = default; |
2382 | InheritedConstructor(ConstructorUsingShadowDecl *Shadow, |
2383 | CXXConstructorDecl *BaseCtor) |
2384 | : Shadow(Shadow), BaseCtor(BaseCtor) {} |
2385 | |
2386 | explicit operator bool() const { return Shadow; } |
2387 | |
2388 | ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; } |
2389 | CXXConstructorDecl *getConstructor() const { return BaseCtor; } |
2390 | }; |
2391 | |
2392 | |
2393 | |
2394 | |
2395 | |
2396 | |
2397 | |
2398 | |
2399 | |
2400 | |
2401 | |
2402 | class CXXConstructorDecl final |
2403 | : public CXXMethodDecl, |
2404 | private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor, |
2405 | ExplicitSpecifier> { |
2406 | |
2407 | |
2408 | |
2409 | |
2410 | |
2411 | |
2412 | LazyCXXCtorInitializersPtr CtorInitializers; |
2413 | |
2414 | CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2415 | const DeclarationNameInfo &NameInfo, QualType T, |
2416 | TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool isInline, |
2417 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2418 | InheritedConstructor Inherited, |
2419 | Expr *TrailingRequiresClause); |
2420 | |
2421 | void anchor() override; |
2422 | |
2423 | size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const { |
2424 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2425 | } |
2426 | size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const { |
2427 | return CXXConstructorDeclBits.HasTrailingExplicitSpecifier; |
2428 | } |
2429 | |
2430 | ExplicitSpecifier getExplicitSpecifierInternal() const { |
2431 | if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier) |
2432 | return *getTrailingObjects<ExplicitSpecifier>(); |
2433 | return ExplicitSpecifier( |
2434 | nullptr, CXXConstructorDeclBits.IsSimpleExplicit |
2435 | ? ExplicitSpecKind::ResolvedTrue |
2436 | : ExplicitSpecKind::ResolvedFalse); |
2437 | } |
2438 | |
2439 | enum TrailingAllocKind { |
2440 | TAKInheritsConstructor = 1, |
2441 | TAKHasTailExplicit = 1 << 1, |
2442 | }; |
2443 | |
2444 | uint64_t getTrailingAllocKind() const { |
2445 | return numTrailingObjects(OverloadToken<InheritedConstructor>()) | |
2446 | (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1); |
2447 | } |
2448 | |
2449 | public: |
2450 | friend class ASTDeclReader; |
2451 | friend class ASTDeclWriter; |
2452 | friend TrailingObjects; |
2453 | |
2454 | static CXXConstructorDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
2455 | uint64_t AllocKind); |
2456 | static CXXConstructorDecl * |
2457 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2458 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2459 | ExplicitSpecifier ES, bool isInline, bool isImplicitlyDeclared, |
2460 | ConstexprSpecKind ConstexprKind, |
2461 | InheritedConstructor Inherited = InheritedConstructor(), |
2462 | Expr *TrailingRequiresClause = nullptr); |
2463 | |
2464 | void setExplicitSpecifier(ExplicitSpecifier ES) { |
2465 | assert((!ES.getExpr() || |
2466 | CXXConstructorDeclBits.HasTrailingExplicitSpecifier) && |
2467 | "cannot set this explicit specifier. no trail-allocated space for " |
2468 | "explicit"); |
2469 | if (ES.getExpr()) |
2470 | *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES; |
2471 | else |
2472 | CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit(); |
2473 | } |
2474 | |
2475 | ExplicitSpecifier getExplicitSpecifier() { |
2476 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2477 | } |
2478 | const ExplicitSpecifier getExplicitSpecifier() const { |
2479 | return getCanonicalDecl()->getExplicitSpecifierInternal(); |
2480 | } |
2481 | |
2482 | |
2483 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2484 | |
2485 | |
2486 | using init_iterator = CXXCtorInitializer **; |
2487 | |
2488 | |
2489 | using init_const_iterator = CXXCtorInitializer *const *; |
2490 | |
2491 | using init_range = llvm::iterator_range<init_iterator>; |
2492 | using init_const_range = llvm::iterator_range<init_const_iterator>; |
2493 | |
2494 | init_range inits() { return init_range(init_begin(), init_end()); } |
2495 | init_const_range inits() const { |
2496 | return init_const_range(init_begin(), init_end()); |
2497 | } |
2498 | |
2499 | |
2500 | init_iterator init_begin() { |
2501 | const auto *ConstThis = this; |
2502 | return const_cast<init_iterator>(ConstThis->init_begin()); |
2503 | } |
2504 | |
2505 | |
2506 | init_const_iterator init_begin() const; |
2507 | |
2508 | |
2509 | init_iterator init_end() { |
2510 | return init_begin() + getNumCtorInitializers(); |
2511 | } |
2512 | |
2513 | |
2514 | init_const_iterator init_end() const { |
2515 | return init_begin() + getNumCtorInitializers(); |
2516 | } |
2517 | |
2518 | using init_reverse_iterator = std::reverse_iterator<init_iterator>; |
2519 | using init_const_reverse_iterator = |
2520 | std::reverse_iterator<init_const_iterator>; |
2521 | |
2522 | init_reverse_iterator init_rbegin() { |
2523 | return init_reverse_iterator(init_end()); |
2524 | } |
2525 | init_const_reverse_iterator init_rbegin() const { |
2526 | return init_const_reverse_iterator(init_end()); |
2527 | } |
2528 | |
2529 | init_reverse_iterator init_rend() { |
2530 | return init_reverse_iterator(init_begin()); |
2531 | } |
2532 | init_const_reverse_iterator init_rend() const { |
2533 | return init_const_reverse_iterator(init_begin()); |
2534 | } |
2535 | |
2536 | |
2537 | |
2538 | unsigned getNumCtorInitializers() const { |
2539 | return CXXConstructorDeclBits.NumCtorInitializers; |
2540 | } |
2541 | |
2542 | void setNumCtorInitializers(unsigned numCtorInitializers) { |
2543 | CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers; |
2544 | |
2545 | |
2546 | |
2547 | assert(CXXConstructorDeclBits.NumCtorInitializers == |
2548 | numCtorInitializers && "NumCtorInitializers overflow!"); |
2549 | } |
2550 | |
2551 | void setCtorInitializers(CXXCtorInitializer **Initializers) { |
2552 | CtorInitializers = Initializers; |
2553 | } |
2554 | |
2555 | |
2556 | bool isDelegatingConstructor() const { |
2557 | return (getNumCtorInitializers() == 1) && |
2558 | init_begin()[0]->isDelegatingInitializer(); |
2559 | } |
2560 | |
2561 | |
2562 | CXXConstructorDecl *getTargetConstructor() const; |
2563 | |
2564 | |
2565 | |
2566 | |
2567 | bool isDefaultConstructor() const; |
2568 | |
2569 | |
2570 | |
2571 | |
2572 | |
2573 | |
2574 | |
2575 | |
2576 | |
2577 | |
2578 | |
2579 | |
2580 | |
2581 | |
2582 | bool isCopyConstructor(unsigned &TypeQuals) const; |
2583 | |
2584 | |
2585 | |
2586 | |
2587 | bool isCopyConstructor() const { |
2588 | unsigned TypeQuals = 0; |
2589 | return isCopyConstructor(TypeQuals); |
2590 | } |
2591 | |
2592 | |
2593 | |
2594 | |
2595 | |
2596 | |
2597 | bool isMoveConstructor(unsigned &TypeQuals) const; |
2598 | |
2599 | |
2600 | |
2601 | bool isMoveConstructor() const { |
2602 | unsigned TypeQuals = 0; |
2603 | return isMoveConstructor(TypeQuals); |
2604 | } |
2605 | |
2606 | |
2607 | |
2608 | |
2609 | |
2610 | bool isCopyOrMoveConstructor(unsigned &TypeQuals) const; |
2611 | |
2612 | |
2613 | bool isCopyOrMoveConstructor() const { |
2614 | unsigned Quals; |
2615 | return isCopyOrMoveConstructor(Quals); |
2616 | } |
2617 | |
2618 | |
2619 | |
2620 | |
2621 | bool isConvertingConstructor(bool AllowExplicit) const; |
2622 | |
2623 | |
2624 | |
2625 | |
2626 | bool isSpecializationCopyingObject() const; |
2627 | |
2628 | |
2629 | |
2630 | bool isInheritingConstructor() const { |
2631 | return CXXConstructorDeclBits.IsInheritingConstructor; |
2632 | } |
2633 | |
2634 | |
2635 | |
2636 | void setInheritingConstructor(bool isIC = true) { |
2637 | CXXConstructorDeclBits.IsInheritingConstructor = isIC; |
2638 | } |
2639 | |
2640 | |
2641 | InheritedConstructor getInheritedConstructor() const { |
2642 | return isInheritingConstructor() ? |
2643 | *getTrailingObjects<InheritedConstructor>() : InheritedConstructor(); |
2644 | } |
2645 | |
2646 | CXXConstructorDecl *getCanonicalDecl() override { |
2647 | return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl()); |
2648 | } |
2649 | const CXXConstructorDecl *getCanonicalDecl() const { |
2650 | return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl(); |
2651 | } |
2652 | |
2653 | |
2654 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2655 | static bool classofKind(Kind K) { return K == CXXConstructor; } |
2656 | }; |
2657 | |
2658 | |
2659 | |
2660 | |
2661 | |
2662 | |
2663 | |
2664 | |
2665 | |
2666 | |
2667 | |
2668 | class CXXDestructorDecl : public CXXMethodDecl { |
2669 | friend class ASTDeclReader; |
2670 | friend class ASTDeclWriter; |
2671 | |
2672 | |
2673 | |
2674 | FunctionDecl *OperatorDelete = nullptr; |
2675 | Expr *OperatorDeleteThisArg = nullptr; |
2676 | |
2677 | CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2678 | const DeclarationNameInfo &NameInfo, QualType T, |
2679 | TypeSourceInfo *TInfo, bool isInline, |
2680 | bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, |
2681 | Expr *TrailingRequiresClause = nullptr) |
2682 | : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo, |
2683 | SC_None, isInline, ConstexprKind, SourceLocation(), |
2684 | TrailingRequiresClause) { |
2685 | setImplicit(isImplicitlyDeclared); |
2686 | } |
2687 | |
2688 | void anchor() override; |
2689 | |
2690 | public: |
2691 | static CXXDestructorDecl *Create(ASTContext &C, CXXRecordDecl *RD, |
2692 | SourceLocation StartLoc, |
2693 | const DeclarationNameInfo &NameInfo, |
2694 | QualType T, TypeSourceInfo *TInfo, |
2695 | bool isInline, bool isImplicitlyDeclared, |
2696 | ConstexprSpecKind ConstexprKind, |
2697 | Expr *TrailingRequiresClause = nullptr); |
2698 | static CXXDestructorDecl *CreateDeserialized(ASTContext & C, unsigned ID); |
2699 | |
2700 | void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg); |
2701 | |
2702 | const FunctionDecl *getOperatorDelete() const { |
2703 | return getCanonicalDecl()->OperatorDelete; |
2704 | } |
2705 | |
2706 | Expr *getOperatorDeleteThisArg() const { |
2707 | return getCanonicalDecl()->OperatorDeleteThisArg; |
2708 | } |
2709 | |
2710 | CXXDestructorDecl *getCanonicalDecl() override { |
2711 | return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl()); |
2712 | } |
2713 | const CXXDestructorDecl *getCanonicalDecl() const { |
2714 | return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl(); |
2715 | } |
2716 | |
2717 | |
2718 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2719 | static bool classofKind(Kind K) { return K == CXXDestructor; } |
2720 | }; |
2721 | |
2722 | |
2723 | |
2724 | |
2725 | |
2726 | |
2727 | |
2728 | |
2729 | |
2730 | |
2731 | |
2732 | class CXXConversionDecl : public CXXMethodDecl { |
2733 | CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2734 | const DeclarationNameInfo &NameInfo, QualType T, |
2735 | TypeSourceInfo *TInfo, bool isInline, ExplicitSpecifier ES, |
2736 | ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, |
2737 | Expr *TrailingRequiresClause = nullptr) |
2738 | : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo, |
2739 | SC_None, isInline, ConstexprKind, EndLocation, |
2740 | TrailingRequiresClause), |
2741 | ExplicitSpec(ES) {} |
2742 | void anchor() override; |
2743 | |
2744 | ExplicitSpecifier ExplicitSpec; |
2745 | |
2746 | public: |
2747 | friend class ASTDeclReader; |
2748 | friend class ASTDeclWriter; |
2749 | |
2750 | static CXXConversionDecl * |
2751 | Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, |
2752 | const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, |
2753 | bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, |
2754 | SourceLocation EndLocation, Expr *TrailingRequiresClause = nullptr); |
2755 | static CXXConversionDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2756 | |
2757 | ExplicitSpecifier getExplicitSpecifier() { |
2758 | return getCanonicalDecl()->ExplicitSpec; |
2759 | } |
2760 | |
2761 | const ExplicitSpecifier getExplicitSpecifier() const { |
2762 | return getCanonicalDecl()->ExplicitSpec; |
2763 | } |
2764 | |
2765 | |
2766 | bool isExplicit() const { return getExplicitSpecifier().isExplicit(); } |
2767 | void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; } |
2768 | |
2769 | |
2770 | QualType getConversionType() const { |
2771 | return getType()->castAs<FunctionType>()->getReturnType(); |
2772 | } |
2773 | |
2774 | |
2775 | |
2776 | bool isLambdaToBlockPointerConversion() const; |
2777 | |
2778 | CXXConversionDecl *getCanonicalDecl() override { |
2779 | return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl()); |
2780 | } |
2781 | const CXXConversionDecl *getCanonicalDecl() const { |
2782 | return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl(); |
2783 | } |
2784 | |
2785 | |
2786 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2787 | static bool classofKind(Kind K) { return K == CXXConversion; } |
2788 | }; |
2789 | |
2790 | |
2791 | |
2792 | |
2793 | |
2794 | |
2795 | |
2796 | class LinkageSpecDecl : public Decl, public DeclContext { |
2797 | virtual void anchor(); |
2798 | |
2799 | |
2800 | public: |
2801 | |
2802 | |
2803 | |
2804 | |
2805 | enum LanguageIDs { lang_c = 1, lang_cxx = 2 }; |
2806 | |
2807 | private: |
2808 | |
2809 | SourceLocation ExternLoc; |
2810 | |
2811 | |
2812 | SourceLocation RBraceLoc; |
2813 | |
2814 | LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc, |
2815 | SourceLocation LangLoc, LanguageIDs lang, bool HasBraces); |
2816 | |
2817 | public: |
2818 | static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC, |
2819 | SourceLocation ExternLoc, |
2820 | SourceLocation LangLoc, LanguageIDs Lang, |
2821 | bool HasBraces); |
2822 | static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2823 | |
2824 | |
2825 | LanguageIDs getLanguage() const { |
2826 | return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language); |
2827 | } |
2828 | |
2829 | |
2830 | void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; } |
2831 | |
2832 | |
2833 | |
2834 | bool hasBraces() const { |
2835 | assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces); |
2836 | return LinkageSpecDeclBits.HasBraces; |
2837 | } |
2838 | |
2839 | SourceLocation getExternLoc() const { return ExternLoc; } |
2840 | SourceLocation getRBraceLoc() const { return RBraceLoc; } |
2841 | void setExternLoc(SourceLocation L) { ExternLoc = L; } |
2842 | void setRBraceLoc(SourceLocation L) { |
2843 | RBraceLoc = L; |
2844 | LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid(); |
2845 | } |
2846 | |
2847 | SourceLocation getEndLoc() const LLVM_READONLY { |
2848 | if (hasBraces()) |
2849 | return getRBraceLoc(); |
2850 | |
2851 | |
2852 | return decls_empty() ? getLocation() : decls_begin()->getEndLoc(); |
2853 | } |
2854 | |
2855 | SourceRange getSourceRange() const override LLVM_READONLY { |
2856 | return SourceRange(ExternLoc, getEndLoc()); |
2857 | } |
2858 | |
2859 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2860 | static bool classofKind(Kind K) { return K == LinkageSpec; } |
2861 | |
2862 | static DeclContext *castToDeclContext(const LinkageSpecDecl *D) { |
2863 | return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D)); |
2864 | } |
2865 | |
2866 | static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) { |
2867 | return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC)); |
2868 | } |
2869 | }; |
2870 | |
2871 | |
2872 | |
2873 | |
2874 | |
2875 | |
2876 | |
2877 | |
2878 | |
2879 | |
2880 | |
2881 | class UsingDirectiveDecl : public NamedDecl { |
2882 | |
2883 | SourceLocation UsingLoc; |
2884 | |
2885 | |
2886 | SourceLocation NamespaceLoc; |
2887 | |
2888 | |
2889 | NestedNameSpecifierLoc QualifierLoc; |
2890 | |
2891 | |
2892 | NamedDecl *NominatedNamespace; |
2893 | |
2894 | |
2895 | |
2896 | DeclContext *CommonAncestor; |
2897 | |
2898 | UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc, |
2899 | SourceLocation NamespcLoc, |
2900 | NestedNameSpecifierLoc QualifierLoc, |
2901 | SourceLocation IdentLoc, |
2902 | NamedDecl *Nominated, |
2903 | DeclContext *CommonAncestor) |
2904 | : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc), |
2905 | NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc), |
2906 | NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {} |
2907 | |
2908 | |
2909 | |
2910 | |
2911 | |
2912 | static DeclarationName getName() { |
2913 | return DeclarationName::getUsingDirectiveName(); |
2914 | } |
2915 | |
2916 | void anchor() override; |
2917 | |
2918 | public: |
2919 | friend class ASTDeclReader; |
2920 | |
2921 | |
2922 | friend class DeclContext; |
2923 | |
2924 | |
2925 | |
2926 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
2927 | |
2928 | |
2929 | |
2930 | NestedNameSpecifier *getQualifier() const { |
2931 | return QualifierLoc.getNestedNameSpecifier(); |
2932 | } |
2933 | |
2934 | NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; } |
2935 | const NamedDecl *getNominatedNamespaceAsWritten() const { |
2936 | return NominatedNamespace; |
2937 | } |
2938 | |
2939 | |
2940 | NamespaceDecl *getNominatedNamespace(); |
2941 | |
2942 | const NamespaceDecl *getNominatedNamespace() const { |
2943 | return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace(); |
2944 | } |
2945 | |
2946 | |
2947 | |
2948 | DeclContext *getCommonAncestor() { return CommonAncestor; } |
2949 | const DeclContext *getCommonAncestor() const { return CommonAncestor; } |
2950 | |
2951 | |
2952 | SourceLocation getUsingLoc() const { return UsingLoc; } |
2953 | |
2954 | |
2955 | |
2956 | SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; } |
2957 | |
2958 | |
2959 | SourceLocation getIdentLocation() const { return getLocation(); } |
2960 | |
2961 | static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC, |
2962 | SourceLocation UsingLoc, |
2963 | SourceLocation NamespaceLoc, |
2964 | NestedNameSpecifierLoc QualifierLoc, |
2965 | SourceLocation IdentLoc, |
2966 | NamedDecl *Nominated, |
2967 | DeclContext *CommonAncestor); |
2968 | static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
2969 | |
2970 | SourceRange getSourceRange() const override LLVM_READONLY { |
2971 | return SourceRange(UsingLoc, getLocation()); |
2972 | } |
2973 | |
2974 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
2975 | static bool classofKind(Kind K) { return K == UsingDirective; } |
2976 | }; |
2977 | |
2978 | |
2979 | |
2980 | |
2981 | |
2982 | |
2983 | |
2984 | |
2985 | class NamespaceAliasDecl : public NamedDecl, |
2986 | public Redeclarable<NamespaceAliasDecl> { |
2987 | friend class ASTDeclReader; |
2988 | |
2989 | |
2990 | SourceLocation NamespaceLoc; |
2991 | |
2992 | |
2993 | |
2994 | |
2995 | SourceLocation IdentLoc; |
2996 | |
2997 | |
2998 | NestedNameSpecifierLoc QualifierLoc; |
2999 | |
3000 | |
3001 | |
3002 | NamedDecl *Namespace; |
3003 | |
3004 | NamespaceAliasDecl(ASTContext &C, DeclContext *DC, |
3005 | SourceLocation NamespaceLoc, SourceLocation AliasLoc, |
3006 | IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc, |
3007 | SourceLocation IdentLoc, NamedDecl *Namespace) |
3008 | : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C), |
3009 | NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc), |
3010 | QualifierLoc(QualifierLoc), Namespace(Namespace) {} |
3011 | |
3012 | void anchor() override; |
3013 | |
3014 | using redeclarable_base = Redeclarable<NamespaceAliasDecl>; |
3015 | |
3016 | NamespaceAliasDecl *getNextRedeclarationImpl() override; |
3017 | NamespaceAliasDecl *getPreviousDeclImpl() override; |
3018 | NamespaceAliasDecl *getMostRecentDeclImpl() override; |
3019 | |
3020 | public: |
3021 | static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC, |
3022 | SourceLocation NamespaceLoc, |
3023 | SourceLocation AliasLoc, |
3024 | IdentifierInfo *Alias, |
3025 | NestedNameSpecifierLoc QualifierLoc, |
3026 | SourceLocation IdentLoc, |
3027 | NamedDecl *Namespace); |
3028 | |
3029 | static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3030 | |
3031 | using redecl_range = redeclarable_base::redecl_range; |
3032 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3033 | |
3034 | using redeclarable_base::redecls_begin; |
3035 | using redeclarable_base::redecls_end; |
3036 | using redeclarable_base::redecls; |
3037 | using redeclarable_base::getPreviousDecl; |
3038 | using redeclarable_base::getMostRecentDecl; |
3039 | |
3040 | NamespaceAliasDecl *getCanonicalDecl() override { |
3041 | return getFirstDecl(); |
3042 | } |
3043 | const NamespaceAliasDecl *getCanonicalDecl() const { |
3044 | return getFirstDecl(); |
3045 | } |
3046 | |
3047 | |
3048 | |
3049 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3050 | |
3051 | |
3052 | |
3053 | NestedNameSpecifier *getQualifier() const { |
3054 | return QualifierLoc.getNestedNameSpecifier(); |
3055 | } |
3056 | |
3057 | |
3058 | NamespaceDecl *getNamespace() { |
3059 | if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace)) |
3060 | return AD->getNamespace(); |
3061 | |
3062 | return cast<NamespaceDecl>(Namespace); |
3063 | } |
3064 | |
3065 | const NamespaceDecl *getNamespace() const { |
3066 | return const_cast<NamespaceAliasDecl *>(this)->getNamespace(); |
3067 | } |
3068 | |
3069 | |
3070 | |
3071 | SourceLocation getAliasLoc() const { return getLocation(); } |
3072 | |
3073 | |
3074 | SourceLocation getNamespaceLoc() const { return NamespaceLoc; } |
3075 | |
3076 | |
3077 | SourceLocation getTargetNameLoc() const { return IdentLoc; } |
3078 | |
3079 | |
3080 | |
3081 | NamedDecl *getAliasedNamespace() const { return Namespace; } |
3082 | |
3083 | SourceRange getSourceRange() const override LLVM_READONLY { |
3084 | return SourceRange(NamespaceLoc, IdentLoc); |
3085 | } |
3086 | |
3087 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3088 | static bool classofKind(Kind K) { return K == NamespaceAlias; } |
3089 | }; |
3090 | |
3091 | |
3092 | |
3093 | class LifetimeExtendedTemporaryDecl final |
3094 | : public Decl, |
3095 | public Mergeable<LifetimeExtendedTemporaryDecl> { |
3096 | friend class MaterializeTemporaryExpr; |
3097 | friend class ASTDeclReader; |
3098 | |
3099 | Stmt *ExprWithTemporary = nullptr; |
3100 | |
3101 | |
3102 | |
3103 | ValueDecl *ExtendingDecl = nullptr; |
3104 | unsigned ManglingNumber; |
3105 | |
3106 | mutable APValue *Value = nullptr; |
3107 | |
3108 | virtual void anchor(); |
3109 | |
3110 | LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling) |
3111 | : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(), |
3112 | EDecl->getLocation()), |
3113 | ExprWithTemporary(Temp), ExtendingDecl(EDecl), |
3114 | ManglingNumber(Mangling) {} |
3115 | |
3116 | LifetimeExtendedTemporaryDecl(EmptyShell) |
3117 | : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {} |
3118 | |
3119 | public: |
3120 | static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec, |
3121 | unsigned Mangling) { |
3122 | return new (EDec->getASTContext(), EDec->getDeclContext()) |
3123 | LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling); |
3124 | } |
3125 | static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C, |
3126 | unsigned ID) { |
3127 | return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{}); |
3128 | } |
3129 | |
3130 | ValueDecl *getExtendingDecl() { return ExtendingDecl; } |
3131 | const ValueDecl *getExtendingDecl() const { return ExtendingDecl; } |
3132 | |
3133 | |
3134 | StorageDuration getStorageDuration() const; |
3135 | |
3136 | |
3137 | |
3138 | |
3139 | |
3140 | |
3141 | Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); } |
3142 | const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); } |
3143 | |
3144 | unsigned getManglingNumber() const { return ManglingNumber; } |
3145 | |
3146 | |
3147 | |
3148 | APValue *getOrCreateValue(bool MayCreate) const; |
3149 | |
3150 | APValue *getValue() const { return Value; } |
3151 | |
3152 | |
3153 | Stmt::child_range childrenExpr() { |
3154 | return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3155 | } |
3156 | |
3157 | Stmt::const_child_range childrenExpr() const { |
3158 | return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1); |
3159 | } |
3160 | |
3161 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3162 | static bool classofKind(Kind K) { |
3163 | return K == Decl::LifetimeExtendedTemporary; |
3164 | } |
3165 | }; |
3166 | |
3167 | |
3168 | |
3169 | |
3170 | |
3171 | |
3172 | |
3173 | |
3174 | |
3175 | |
3176 | |
3177 | |
3178 | |
3179 | |
3180 | |
3181 | |
3182 | |
3183 | |
3184 | |
3185 | |
3186 | class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> { |
3187 | friend class BaseUsingDecl; |
3188 | |
3189 | |
3190 | NamedDecl *Underlying = nullptr; |
3191 | |
3192 | |
3193 | |
3194 | NamedDecl *UsingOrNextShadow = nullptr; |
3195 | |
3196 | void anchor() override; |
3197 | |
3198 | using redeclarable_base = Redeclarable<UsingShadowDecl>; |
3199 | |
3200 | UsingShadowDecl *getNextRedeclarationImpl() override { |
3201 | return getNextRedeclaration(); |
3202 | } |
3203 | |
3204 | UsingShadowDecl *getPreviousDeclImpl() override { |
3205 | return getPreviousDecl(); |
3206 | } |
3207 | |
3208 | UsingShadowDecl *getMostRecentDeclImpl() override { |
3209 | return getMostRecentDecl(); |
3210 | } |
3211 | |
3212 | protected: |
3213 | UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3214 | DeclarationName Name, BaseUsingDecl *Introducer, |
3215 | NamedDecl *Target); |
3216 | UsingShadowDecl(Kind K, ASTContext &C, EmptyShell); |
3217 | |
3218 | public: |
3219 | friend class ASTDeclReader; |
3220 | friend class ASTDeclWriter; |
3221 | |
3222 | static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3223 | SourceLocation Loc, DeclarationName Name, |
3224 | BaseUsingDecl *Introducer, NamedDecl *Target) { |
3225 | return new (C, DC) |
3226 | UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target); |
3227 | } |
3228 | |
3229 | static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3230 | |
3231 | using redecl_range = redeclarable_base::redecl_range; |
3232 | using redecl_iterator = redeclarable_base::redecl_iterator; |
3233 | |
3234 | using redeclarable_base::redecls_begin; |
3235 | using redeclarable_base::redecls_end; |
3236 | using redeclarable_base::redecls; |
3237 | using redeclarable_base::getPreviousDecl; |
3238 | using redeclarable_base::getMostRecentDecl; |
3239 | using redeclarable_base::isFirstDecl; |
3240 | |
3241 | UsingShadowDecl *getCanonicalDecl() override { |
3242 | return getFirstDecl(); |
3243 | } |
3244 | const UsingShadowDecl *getCanonicalDecl() const { |
3245 | return getFirstDecl(); |
3246 | } |
3247 | |
3248 | |
3249 | |
3250 | NamedDecl *getTargetDecl() const { return Underlying; } |
3251 | |
3252 | |
3253 | |
3254 | void setTargetDecl(NamedDecl *ND) { |
3255 | assert(ND && "Target decl is null!"); |
3256 | Underlying = ND; |
3257 | |
3258 | |
3259 | IdentifierNamespace = |
3260 | ND->getIdentifierNamespace() & |
3261 | ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern); |
3262 | } |
3263 | |
3264 | |
3265 | |
3266 | BaseUsingDecl *getIntroducer() const; |
3267 | |
3268 | |
3269 | |
3270 | UsingShadowDecl *getNextUsingShadowDecl() const { |
3271 | return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow); |
3272 | } |
3273 | |
3274 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3275 | static bool classofKind(Kind K) { |
3276 | return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow; |
3277 | } |
3278 | }; |
3279 | |
3280 | |
3281 | |
3282 | |
3283 | class BaseUsingDecl : public NamedDecl { |
3284 | |
3285 | |
3286 | |
3287 | |
3288 | |
3289 | llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow; |
3290 | |
3291 | protected: |
3292 | BaseUsingDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N) |
3293 | : NamedDecl(DK, DC, L, N), FirstUsingShadow(nullptr, 0) {} |
3294 | |
3295 | private: |
3296 | void anchor() override; |
3297 | |
3298 | protected: |
3299 | |
3300 | bool getShadowFlag() const { return FirstUsingShadow.getInt(); } |
3301 | |
3302 | |
3303 | void setShadowFlag(bool V) { FirstUsingShadow.setInt(V); } |
3304 | |
3305 | public: |
3306 | friend class ASTDeclReader; |
3307 | friend class ASTDeclWriter; |
3308 | |
3309 | |
3310 | |
3311 | class shadow_iterator { |
3312 | |
3313 | UsingShadowDecl *Current = nullptr; |
3314 | |
3315 | public: |
3316 | using value_type = UsingShadowDecl *; |
3317 | using reference = UsingShadowDecl *; |
3318 | using pointer = UsingShadowDecl *; |
3319 | using iterator_category = std::forward_iterator_tag; |
3320 | using difference_type = std::ptrdiff_t; |
3321 | |
3322 | shadow_iterator() = default; |
3323 | explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {} |
3324 | |
3325 | reference operator*() const { return Current; } |
3326 | pointer operator->() const { return Current; } |
3327 | |
3328 | shadow_iterator &operator++() { |
3329 | Current = Current->getNextUsingShadowDecl(); |
3330 | return *this; |
3331 | } |
3332 | |
3333 | shadow_iterator operator++(int) { |
3334 | shadow_iterator tmp(*this); |
3335 | ++(*this); |
3336 | return tmp; |
3337 | } |
3338 | |
3339 | friend bool operator==(shadow_iterator x, shadow_iterator y) { |
3340 | return x.Current == y.Current; |
3341 | } |
3342 | friend bool operator!=(shadow_iterator x, shadow_iterator y) { |
3343 | return x.Current != y.Current; |
3344 | } |
3345 | }; |
3346 | |
3347 | using shadow_range = llvm::iterator_range<shadow_iterator>; |
3348 | |
3349 | shadow_range shadows() const { |
3350 | return shadow_range(shadow_begin(), shadow_end()); |
3351 | } |
3352 | |
3353 | shadow_iterator shadow_begin() const { |
3354 | return shadow_iterator(FirstUsingShadow.getPointer()); |
3355 | } |
3356 | |
3357 | shadow_iterator shadow_end() const { return shadow_iterator(); } |
3358 | |
3359 | |
3360 | |
3361 | unsigned shadow_size() const { |
3362 | return std::distance(shadow_begin(), shadow_end()); |
3363 | } |
3364 | |
3365 | void addShadowDecl(UsingShadowDecl *S); |
3366 | void removeShadowDecl(UsingShadowDecl *S); |
3367 | |
3368 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3369 | static bool classofKind(Kind K) { return K == Using || K == UsingEnum; } |
3370 | }; |
3371 | |
3372 | |
3373 | |
3374 | |
3375 | |
3376 | |
3377 | |
3378 | class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> { |
3379 | |
3380 | SourceLocation UsingLocation; |
3381 | |
3382 | |
3383 | NestedNameSpecifierLoc QualifierLoc; |
3384 | |
3385 | |
3386 | |
3387 | DeclarationNameLoc DNLoc; |
3388 | |
3389 | UsingDecl(DeclContext *DC, SourceLocation UL, |
3390 | NestedNameSpecifierLoc QualifierLoc, |
3391 | const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword) |
3392 | : BaseUsingDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()), |
3393 | UsingLocation(UL), QualifierLoc(QualifierLoc), |
3394 | DNLoc(NameInfo.getInfo()) { |
3395 | setShadowFlag(HasTypenameKeyword); |
3396 | } |
3397 | |
3398 | void anchor() override; |
3399 | |
3400 | public: |
3401 | friend class ASTDeclReader; |
3402 | friend class ASTDeclWriter; |
3403 | |
3404 | |
3405 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3406 | |
3407 | |
3408 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3409 | |
3410 | |
3411 | |
3412 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3413 | |
3414 | |
3415 | NestedNameSpecifier *getQualifier() const { |
3416 | return QualifierLoc.getNestedNameSpecifier(); |
3417 | } |
3418 | |
3419 | DeclarationNameInfo getNameInfo() const { |
3420 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3421 | } |
3422 | |
3423 | |
3424 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3425 | |
3426 | |
3427 | bool hasTypename() const { return getShadowFlag(); } |
3428 | |
3429 | |
3430 | void setTypename(bool TN) { setShadowFlag(TN); } |
3431 | |
3432 | static UsingDecl *Create(ASTContext &C, DeclContext *DC, |
3433 | SourceLocation UsingL, |
3434 | NestedNameSpecifierLoc QualifierLoc, |
3435 | const DeclarationNameInfo &NameInfo, |
3436 | bool HasTypenameKeyword); |
3437 | |
3438 | static UsingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3439 | |
3440 | SourceRange getSourceRange() const override LLVM_READONLY; |
3441 | |
3442 | |
3443 | UsingDecl *getCanonicalDecl() override { |
3444 | return cast<UsingDecl>(getFirstDecl()); |
3445 | } |
3446 | const UsingDecl *getCanonicalDecl() const { |
3447 | return cast<UsingDecl>(getFirstDecl()); |
3448 | } |
3449 | |
3450 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3451 | static bool classofKind(Kind K) { return K == Using; } |
3452 | }; |
3453 | |
3454 | |
3455 | |
3456 | |
3457 | |
3458 | |
3459 | |
3460 | |
3461 | |
3462 | |
3463 | |
3464 | class ConstructorUsingShadowDecl final : public UsingShadowDecl { |
3465 | |
3466 | |
3467 | |
3468 | ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr; |
3469 | |
3470 | |
3471 | |
3472 | |
3473 | |
3474 | ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr; |
3475 | |
3476 | |
3477 | |
3478 | |
3479 | unsigned IsVirtual : 1; |
3480 | |
3481 | ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc, |
3482 | UsingDecl *Using, NamedDecl *Target, |
3483 | bool TargetInVirtualBase) |
3484 | : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc, |
3485 | Using->getDeclName(), Using, |
3486 | Target->getUnderlyingDecl()), |
3487 | NominatedBaseClassShadowDecl( |
3488 | dyn_cast<ConstructorUsingShadowDecl>(Target)), |
3489 | ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl), |
3490 | IsVirtual(TargetInVirtualBase) { |
3491 | |
3492 | |
3493 | |
3494 | if (NominatedBaseClassShadowDecl && |
3495 | NominatedBaseClassShadowDecl->constructsVirtualBase()) { |
3496 | ConstructedBaseClassShadowDecl = |
3497 | NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl; |
3498 | IsVirtual = true; |
3499 | } |
3500 | } |
3501 | |
3502 | ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty) |
3503 | : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {} |
3504 | |
3505 | void anchor() override; |
3506 | |
3507 | public: |
3508 | friend class ASTDeclReader; |
3509 | friend class ASTDeclWriter; |
3510 | |
3511 | static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC, |
3512 | SourceLocation Loc, |
3513 | UsingDecl *Using, NamedDecl *Target, |
3514 | bool IsVirtual); |
3515 | static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C, |
3516 | unsigned ID); |
3517 | |
3518 | |
3519 | |
3520 | UsingDecl *getIntroducer() const { |
3521 | return cast<UsingDecl>(UsingShadowDecl::getIntroducer()); |
3522 | } |
3523 | |
3524 | |
3525 | |
3526 | |
3527 | const CXXRecordDecl *getParent() const { |
3528 | return cast<CXXRecordDecl>(getDeclContext()); |
3529 | } |
3530 | CXXRecordDecl *getParent() { |
3531 | return cast<CXXRecordDecl>(getDeclContext()); |
3532 | } |
3533 | |
3534 | |
3535 | |
3536 | |
3537 | |
3538 | ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const { |
3539 | return NominatedBaseClassShadowDecl; |
3540 | } |
3541 | |
3542 | |
3543 | |
3544 | ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const { |
3545 | return ConstructedBaseClassShadowDecl; |
3546 | } |
3547 | |
3548 | |
3549 | |
3550 | CXXRecordDecl *getNominatedBaseClass() const; |
3551 | |
3552 | |
3553 | |
3554 | CXXRecordDecl *getConstructedBaseClass() const { |
3555 | return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl |
3556 | ? ConstructedBaseClassShadowDecl |
3557 | : getTargetDecl()) |
3558 | ->getDeclContext()); |
3559 | } |
3560 | |
3561 | |
3562 | |
3563 | bool constructsVirtualBase() const { |
3564 | return IsVirtual; |
3565 | } |
3566 | |
3567 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3568 | static bool classofKind(Kind K) { return K == ConstructorUsingShadow; } |
3569 | }; |
3570 | |
3571 | |
3572 | |
3573 | |
3574 | |
3575 | |
3576 | |
3577 | |
3578 | class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> { |
3579 | |
3580 | SourceLocation UsingLocation; |
3581 | |
3582 | |
3583 | SourceLocation EnumLocation; |
3584 | |
3585 | |
3586 | EnumDecl *Enum; |
3587 | |
3588 | UsingEnumDecl(DeclContext *DC, DeclarationName DN, SourceLocation UL, |
3589 | SourceLocation EL, SourceLocation NL, EnumDecl *ED) |
3590 | : BaseUsingDecl(UsingEnum, DC, NL, DN), UsingLocation(UL), |
3591 | EnumLocation(EL), Enum(ED) {} |
3592 | |
3593 | void anchor() override; |
3594 | |
3595 | public: |
3596 | friend class ASTDeclReader; |
3597 | friend class ASTDeclWriter; |
3598 | |
3599 | |
3600 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3601 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3602 | |
3603 | |
3604 | SourceLocation getEnumLoc() const { return EnumLocation; } |
3605 | void setEnumLoc(SourceLocation L) { EnumLocation = L; } |
3606 | |
3607 | public: |
3608 | EnumDecl *getEnumDecl() const { return Enum; } |
3609 | |
3610 | static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC, |
3611 | SourceLocation UsingL, SourceLocation EnumL, |
3612 | SourceLocation NameL, EnumDecl *ED); |
3613 | |
3614 | static UsingEnumDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3615 | |
3616 | SourceRange getSourceRange() const override LLVM_READONLY; |
3617 | |
3618 | |
3619 | UsingEnumDecl *getCanonicalDecl() override { |
3620 | return cast<UsingEnumDecl>(getFirstDecl()); |
3621 | } |
3622 | const UsingEnumDecl *getCanonicalDecl() const { |
3623 | return cast<UsingEnumDecl>(getFirstDecl()); |
3624 | } |
3625 | |
3626 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3627 | static bool classofKind(Kind K) { return K == UsingEnum; } |
3628 | }; |
3629 | |
3630 | |
3631 | |
3632 | |
3633 | |
3634 | |
3635 | |
3636 | |
3637 | |
3638 | |
3639 | |
3640 | |
3641 | |
3642 | |
3643 | class UsingPackDecl final |
3644 | : public NamedDecl, public Mergeable<UsingPackDecl>, |
3645 | private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> { |
3646 | |
3647 | |
3648 | NamedDecl *InstantiatedFrom; |
3649 | |
3650 | |
3651 | unsigned NumExpansions; |
3652 | |
3653 | UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom, |
3654 | ArrayRef<NamedDecl *> UsingDecls) |
3655 | : NamedDecl(UsingPack, DC, |
3656 | InstantiatedFrom ? InstantiatedFrom->getLocation() |
3657 | : SourceLocation(), |
3658 | InstantiatedFrom ? InstantiatedFrom->getDeclName() |
3659 | : DeclarationName()), |
3660 | InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) { |
3661 | std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(), |
3662 | getTrailingObjects<NamedDecl *>()); |
3663 | } |
3664 | |
3665 | void anchor() override; |
3666 | |
3667 | public: |
3668 | friend class ASTDeclReader; |
3669 | friend class ASTDeclWriter; |
3670 | friend TrailingObjects; |
3671 | |
3672 | |
3673 | |
3674 | |
3675 | NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; } |
3676 | |
3677 | |
3678 | |
3679 | ArrayRef<NamedDecl *> expansions() const { |
3680 | return llvm::makeArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions); |
3681 | } |
3682 | |
3683 | static UsingPackDecl *Create(ASTContext &C, DeclContext *DC, |
3684 | NamedDecl *InstantiatedFrom, |
3685 | ArrayRef<NamedDecl *> UsingDecls); |
3686 | |
3687 | static UsingPackDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
3688 | unsigned NumExpansions); |
3689 | |
3690 | SourceRange getSourceRange() const override LLVM_READONLY { |
3691 | return InstantiatedFrom->getSourceRange(); |
3692 | } |
3693 | |
3694 | UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); } |
3695 | const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); } |
3696 | |
3697 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3698 | static bool classofKind(Kind K) { return K == UsingPack; } |
3699 | }; |
3700 | |
3701 | |
3702 | |
3703 | |
3704 | |
3705 | |
3706 | |
3707 | |
3708 | |
3709 | |
3710 | |
3711 | |
3712 | class UnresolvedUsingValueDecl : public ValueDecl, |
3713 | public Mergeable<UnresolvedUsingValueDecl> { |
3714 | |
3715 | SourceLocation UsingLocation; |
3716 | |
3717 | |
3718 | SourceLocation EllipsisLoc; |
3719 | |
3720 | |
3721 | NestedNameSpecifierLoc QualifierLoc; |
3722 | |
3723 | |
3724 | |
3725 | DeclarationNameLoc DNLoc; |
3726 | |
3727 | UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty, |
3728 | SourceLocation UsingLoc, |
3729 | NestedNameSpecifierLoc QualifierLoc, |
3730 | const DeclarationNameInfo &NameInfo, |
3731 | SourceLocation EllipsisLoc) |
3732 | : ValueDecl(UnresolvedUsingValue, DC, |
3733 | NameInfo.getLoc(), NameInfo.getName(), Ty), |
3734 | UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc), |
3735 | QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {} |
3736 | |
3737 | void anchor() override; |
3738 | |
3739 | public: |
3740 | friend class ASTDeclReader; |
3741 | friend class ASTDeclWriter; |
3742 | |
3743 | |
3744 | SourceLocation getUsingLoc() const { return UsingLocation; } |
3745 | |
3746 | |
3747 | void setUsingLoc(SourceLocation L) { UsingLocation = L; } |
3748 | |
3749 | |
3750 | bool isAccessDeclaration() const { return UsingLocation.isInvalid(); } |
3751 | |
3752 | |
3753 | |
3754 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3755 | |
3756 | |
3757 | NestedNameSpecifier *getQualifier() const { |
3758 | return QualifierLoc.getNestedNameSpecifier(); |
3759 | } |
3760 | |
3761 | DeclarationNameInfo getNameInfo() const { |
3762 | return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc); |
3763 | } |
3764 | |
3765 | |
3766 | bool isPackExpansion() const { |
3767 | return EllipsisLoc.isValid(); |
3768 | } |
3769 | |
3770 | |
3771 | SourceLocation getEllipsisLoc() const { |
3772 | return EllipsisLoc; |
3773 | } |
3774 | |
3775 | static UnresolvedUsingValueDecl * |
3776 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3777 | NestedNameSpecifierLoc QualifierLoc, |
3778 | const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc); |
3779 | |
3780 | static UnresolvedUsingValueDecl * |
3781 | CreateDeserialized(ASTContext &C, unsigned ID); |
3782 | |
3783 | SourceRange getSourceRange() const override LLVM_READONLY; |
3784 | |
3785 | |
3786 | UnresolvedUsingValueDecl *getCanonicalDecl() override { |
3787 | return getFirstDecl(); |
3788 | } |
3789 | const UnresolvedUsingValueDecl *getCanonicalDecl() const { |
3790 | return getFirstDecl(); |
3791 | } |
3792 | |
3793 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3794 | static bool classofKind(Kind K) { return K == UnresolvedUsingValue; } |
3795 | }; |
3796 | |
3797 | |
3798 | |
3799 | |
3800 | |
3801 | |
3802 | |
3803 | |
3804 | |
3805 | |
3806 | |
3807 | |
3808 | class UnresolvedUsingTypenameDecl |
3809 | : public TypeDecl, |
3810 | public Mergeable<UnresolvedUsingTypenameDecl> { |
3811 | friend class ASTDeclReader; |
3812 | |
3813 | |
3814 | SourceLocation TypenameLocation; |
3815 | |
3816 | |
3817 | SourceLocation EllipsisLoc; |
3818 | |
3819 | |
3820 | NestedNameSpecifierLoc QualifierLoc; |
3821 | |
3822 | UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc, |
3823 | SourceLocation TypenameLoc, |
3824 | NestedNameSpecifierLoc QualifierLoc, |
3825 | SourceLocation TargetNameLoc, |
3826 | IdentifierInfo *TargetName, |
3827 | SourceLocation EllipsisLoc) |
3828 | : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName, |
3829 | UsingLoc), |
3830 | TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc), |
3831 | QualifierLoc(QualifierLoc) {} |
3832 | |
3833 | void anchor() override; |
3834 | |
3835 | public: |
3836 | |
3837 | SourceLocation getUsingLoc() const { return getBeginLoc(); } |
3838 | |
3839 | |
3840 | SourceLocation getTypenameLoc() const { return TypenameLocation; } |
3841 | |
3842 | |
3843 | |
3844 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } |
3845 | |
3846 | |
3847 | NestedNameSpecifier *getQualifier() const { |
3848 | return QualifierLoc.getNestedNameSpecifier(); |
3849 | } |
3850 | |
3851 | DeclarationNameInfo getNameInfo() const { |
3852 | return DeclarationNameInfo(getDeclName(), getLocation()); |
3853 | } |
3854 | |
3855 | |
3856 | bool isPackExpansion() const { |
3857 | return EllipsisLoc.isValid(); |
3858 | } |
3859 | |
3860 | |
3861 | SourceLocation getEllipsisLoc() const { |
3862 | return EllipsisLoc; |
3863 | } |
3864 | |
3865 | static UnresolvedUsingTypenameDecl * |
3866 | Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc, |
3867 | SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc, |
3868 | SourceLocation TargetNameLoc, DeclarationName TargetName, |
3869 | SourceLocation EllipsisLoc); |
3870 | |
3871 | static UnresolvedUsingTypenameDecl * |
3872 | CreateDeserialized(ASTContext &C, unsigned ID); |
3873 | |
3874 | |
3875 | UnresolvedUsingTypenameDecl *getCanonicalDecl() override { |
3876 | return getFirstDecl(); |
3877 | } |
3878 | const UnresolvedUsingTypenameDecl *getCanonicalDecl() const { |
3879 | return getFirstDecl(); |
3880 | } |
3881 | |
3882 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3883 | static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; } |
3884 | }; |
3885 | |
3886 | |
3887 | |
3888 | |
3889 | |
3890 | |
3891 | class UnresolvedUsingIfExistsDecl final : public NamedDecl { |
3892 | UnresolvedUsingIfExistsDecl(DeclContext *DC, SourceLocation Loc, |
3893 | DeclarationName Name); |
3894 | |
3895 | void anchor() override; |
3896 | |
3897 | public: |
3898 | static UnresolvedUsingIfExistsDecl *Create(ASTContext &Ctx, DeclContext *DC, |
3899 | SourceLocation Loc, |
3900 | DeclarationName Name); |
3901 | static UnresolvedUsingIfExistsDecl *CreateDeserialized(ASTContext &Ctx, |
3902 | unsigned ID); |
3903 | |
3904 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3905 | static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; } |
3906 | }; |
3907 | |
3908 | |
3909 | class StaticAssertDecl : public Decl { |
3910 | llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed; |
3911 | StringLiteral *Message; |
3912 | SourceLocation RParenLoc; |
3913 | |
3914 | StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc, |
3915 | Expr *AssertExpr, StringLiteral *Message, |
3916 | SourceLocation RParenLoc, bool Failed) |
3917 | : Decl(StaticAssert, DC, StaticAssertLoc), |
3918 | AssertExprAndFailed(AssertExpr, Failed), Message(Message), |
3919 | RParenLoc(RParenLoc) {} |
3920 | |
3921 | virtual void anchor(); |
3922 | |
3923 | public: |
3924 | friend class ASTDeclReader; |
3925 | |
3926 | static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC, |
3927 | SourceLocation StaticAssertLoc, |
3928 | Expr *AssertExpr, StringLiteral *Message, |
3929 | SourceLocation RParenLoc, bool Failed); |
3930 | static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3931 | |
3932 | Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); } |
3933 | const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); } |
3934 | |
3935 | StringLiteral *getMessage() { return Message; } |
3936 | const StringLiteral *getMessage() const { return Message; } |
3937 | |
3938 | bool isFailed() const { return AssertExprAndFailed.getInt(); } |
3939 | |
3940 | SourceLocation getRParenLoc() const { return RParenLoc; } |
3941 | |
3942 | SourceRange getSourceRange() const override LLVM_READONLY { |
3943 | return SourceRange(getLocation(), getRParenLoc()); |
3944 | } |
3945 | |
3946 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
3947 | static bool classofKind(Kind K) { return K == StaticAssert; } |
3948 | }; |
3949 | |
3950 | |
3951 | |
3952 | |
3953 | |
3954 | |
3955 | |
3956 | |
3957 | |
3958 | class BindingDecl : public ValueDecl { |
3959 | |
3960 | ValueDecl *Decomp; |
3961 | |
3962 | |
3963 | |
3964 | |
3965 | Expr *Binding = nullptr; |
3966 | |
3967 | BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id) |
3968 | : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {} |
3969 | |
3970 | void anchor() override; |
3971 | |
3972 | public: |
3973 | friend class ASTDeclReader; |
3974 | |
3975 | static BindingDecl *Create(ASTContext &C, DeclContext *DC, |
3976 | SourceLocation IdLoc, IdentifierInfo *Id); |
3977 | static BindingDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
3978 | |
3979 | |
3980 | |
3981 | |
3982 | Expr *getBinding() const { return Binding; } |
3983 | |
3984 | |
3985 | |
3986 | ValueDecl *getDecomposedDecl() const { return Decomp; } |
3987 | |
3988 | |
3989 | |
3990 | VarDecl *getHoldingVar() const; |
3991 | |
3992 | |
3993 | |
3994 | |
3995 | void setBinding(QualType DeclaredType, Expr *Binding) { |
3996 | setType(DeclaredType); |
3997 | this->Binding = Binding; |
3998 | } |
3999 | |
4000 | |
4001 | void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; } |
4002 | |
4003 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4004 | static bool classofKind(Kind K) { return K == Decl::Binding; } |
4005 | }; |
4006 | |
4007 | |
4008 | |
4009 | |
4010 | |
4011 | |
4012 | |
4013 | |
4014 | |
4015 | class DecompositionDecl final |
4016 | : public VarDecl, |
4017 | private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> { |
4018 | |
4019 | unsigned NumBindings; |
4020 | |
4021 | DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, |
4022 | SourceLocation LSquareLoc, QualType T, |
4023 | TypeSourceInfo *TInfo, StorageClass SC, |
4024 | ArrayRef<BindingDecl *> Bindings) |
4025 | : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo, |
4026 | SC), |
4027 | NumBindings(Bindings.size()) { |
4028 | std::uninitialized_copy(Bindings.begin(), Bindings.end(), |
4029 | getTrailingObjects<BindingDecl *>()); |
4030 | for (auto *B : Bindings) |
4031 | B->setDecomposedDecl(this); |
4032 | } |
4033 | |
4034 | void anchor() override; |
4035 | |
4036 | public: |
4037 | friend class ASTDeclReader; |
4038 | friend TrailingObjects; |
4039 | |
4040 | static DecompositionDecl *Create(ASTContext &C, DeclContext *DC, |
4041 | SourceLocation StartLoc, |
4042 | SourceLocation LSquareLoc, |
4043 | QualType T, TypeSourceInfo *TInfo, |
4044 | StorageClass S, |
4045 | ArrayRef<BindingDecl *> Bindings); |
4046 | static DecompositionDecl *CreateDeserialized(ASTContext &C, unsigned ID, |
4047 | unsigned NumBindings); |
4048 | |
4049 | ArrayRef<BindingDecl *> bindings() const { |
4050 | return llvm::makeArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings); |
4051 | } |
4052 | |
4053 | void printName(raw_ostream &os) const override; |
4054 | |
4055 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4056 | static bool classofKind(Kind K) { return K == Decomposition; } |
4057 | }; |
4058 | |
4059 | |
4060 | |
4061 | |
4062 | |
4063 | |
4064 | |
4065 | |
4066 | |
4067 | |
4068 | |
4069 | |
4070 | |
4071 | |
4072 | |
4073 | |
4074 | |
4075 | |
4076 | |
4077 | |
4078 | |
4079 | |
4080 | |
4081 | |
4082 | |
4083 | |
4084 | |
4085 | |
4086 | class MSPropertyDecl : public DeclaratorDecl { |
4087 | IdentifierInfo *GetterId, *SetterId; |
4088 | |
4089 | MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N, |
4090 | QualType T, TypeSourceInfo *TInfo, SourceLocation StartL, |
4091 | IdentifierInfo *Getter, IdentifierInfo *Setter) |
4092 | : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), |
4093 | GetterId(Getter), SetterId(Setter) {} |
4094 | |
4095 | void anchor() override; |
4096 | public: |
4097 | friend class ASTDeclReader; |
4098 | |
4099 | static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC, |
4100 | SourceLocation L, DeclarationName N, QualType T, |
4101 | TypeSourceInfo *TInfo, SourceLocation StartL, |
4102 | IdentifierInfo *Getter, IdentifierInfo *Setter); |
4103 | static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4104 | |
4105 | static bool classof(const Decl *D) { return D->getKind() == MSProperty; } |
4106 | |
4107 | bool hasGetter() const { return GetterId != nullptr; } |
4108 | IdentifierInfo* getGetterId() const { return GetterId; } |
4109 | bool hasSetter() const { return SetterId != nullptr; } |
4110 | IdentifierInfo* getSetterId() const { return SetterId; } |
4111 | }; |
4112 | |
4113 | |
4114 | |
4115 | struct MSGuidDeclParts { |
4116 | |
4117 | uint32_t Part1; |
4118 | |
4119 | uint16_t Part2; |
4120 | |
4121 | uint16_t Part3; |
4122 | |
4123 | uint8_t Part4And5[8]; |
4124 | |
4125 | uint64_t getPart4And5AsUint64() const { |
4126 | uint64_t Val; |
4127 | memcpy(&Val, &Part4And5, sizeof(Part4And5)); |
4128 | return Val; |
4129 | } |
4130 | }; |
4131 | |
4132 | |
4133 | |
4134 | |
4135 | |
4136 | |
4137 | |
4138 | class MSGuidDecl : public ValueDecl, |
4139 | public Mergeable<MSGuidDecl>, |
4140 | public llvm::FoldingSetNode { |
4141 | public: |
4142 | using Parts = MSGuidDeclParts; |
4143 | |
4144 | private: |
4145 | |
4146 | Parts PartVal; |
4147 | |
4148 | |
4149 | |
4150 | mutable APValue APVal; |
4151 | |
4152 | void anchor() override; |
4153 | |
4154 | MSGuidDecl(DeclContext *DC, QualType T, Parts P); |
4155 | |
4156 | static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P); |
4157 | static MSGuidDecl *CreateDeserialized(ASTContext &C, unsigned ID); |
4158 | |
4159 | |
4160 | friend class ASTContext; |
4161 | friend class ASTReader; |
4162 | friend class ASTDeclReader; |
4163 | |
4164 | public: |
4165 | |
4166 | void printName(llvm::raw_ostream &OS) const override; |
4167 | |
4168 | |
4169 | Parts getParts() const { return PartVal; } |
4170 | |
4171 | |
4172 | |
4173 | |
4174 | APValue &getAsAPValue() const; |
4175 | |
4176 | static void Profile(llvm::FoldingSetNodeID &ID, Parts P) { |
4177 | ID.AddInteger(P.Part1); |
4178 | ID.AddInteger(P.Part2); |
4179 | ID.AddInteger(P.Part3); |
4180 | ID.AddInteger(P.getPart4And5AsUint64()); |
4181 | } |
4182 | void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); } |
4183 | |
4184 | static bool classof(const Decl *D) { return classofKind(D->getKind()); } |
4185 | static bool classofKind(Kind K) { return K == Decl::MSGuid; } |
4186 | }; |
4187 | |
4188 | |
4189 | |
4190 | const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, |
4191 | AccessSpecifier AS); |
4192 | |
4193 | } |
4194 | |
4195 | #endif // LLVM_CLANG_AST_DECLCXX_H |