clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name SemaCXXScopeSpec.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/libclangSema/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangSema/obj/../include/clang/Sema -I /usr/src/gnu/usr.bin/clang/libclangSema/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangSema/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangSema/../include -I /usr/src/gnu/usr.bin/clang/libclangSema/obj -I /usr/src/gnu/usr.bin/clang/libclangSema/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/libclangSema/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/libclangSema/../../../llvm/clang/lib/Sema/SemaCXXScopeSpec.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | #include "TypeLocBuilder.h" |
14 | #include "clang/AST/ASTContext.h" |
15 | #include "clang/AST/DeclTemplate.h" |
16 | #include "clang/AST/ExprCXX.h" |
17 | #include "clang/AST/NestedNameSpecifier.h" |
18 | #include "clang/Basic/PartialDiagnostic.h" |
19 | #include "clang/Sema/DeclSpec.h" |
20 | #include "clang/Sema/Lookup.h" |
21 | #include "clang/Sema/SemaInternal.h" |
22 | #include "clang/Sema/Template.h" |
23 | #include "llvm/ADT/STLExtras.h" |
24 | using namespace clang; |
25 | |
26 | |
27 | static CXXRecordDecl *getCurrentInstantiationOf(QualType T, |
28 | DeclContext *CurContext) { |
29 | if (T.isNull()) |
30 | return nullptr; |
31 | |
32 | const Type *Ty = T->getCanonicalTypeInternal().getTypePtr(); |
33 | if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) { |
34 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl()); |
35 | if (!Record->isDependentContext() || |
36 | Record->isCurrentInstantiation(CurContext)) |
37 | return Record; |
38 | |
39 | return nullptr; |
40 | } else if (isa<InjectedClassNameType>(Ty)) |
41 | return cast<InjectedClassNameType>(Ty)->getDecl(); |
42 | else |
43 | return nullptr; |
44 | } |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | DeclContext *Sema::computeDeclContext(QualType T) { |
54 | if (!T->isDependentType()) |
55 | if (const TagType *Tag = T->getAs<TagType>()) |
56 | return Tag->getDecl(); |
57 | |
58 | return ::getCurrentInstantiationOf(T, CurContext); |
59 | } |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | DeclContext *Sema::computeDeclContext(const CXXScopeSpec &SS, |
75 | bool EnteringContext) { |
76 | if (!SS.isSet() || SS.isInvalid()) |
| 3 | | Calling 'CXXScopeSpec::isSet' | |
|
| 6 | | Returning from 'CXXScopeSpec::isSet' | |
|
| 7 | | Calling 'CXXScopeSpec::isInvalid' | |
|
| 9 | | Returning from 'CXXScopeSpec::isInvalid' | |
|
| |
77 | return nullptr; |
78 | |
79 | NestedNameSpecifier *NNS = SS.getScopeRep(); |
80 | if (NNS->isDependent()) { |
| 11 | | Assuming the condition is false | |
|
| |
81 | |
82 | |
83 | if (CXXRecordDecl *Record = getCurrentInstantiationOf(NNS)) |
84 | return Record; |
85 | |
86 | if (EnteringContext) { |
87 | const Type *NNSType = NNS->getAsType(); |
88 | if (!NNSType) { |
89 | return nullptr; |
90 | } |
91 | |
92 | |
93 | NNSType = Context.getCanonicalType(NNSType); |
94 | if (const TemplateSpecializationType *SpecType |
95 | = NNSType->getAs<TemplateSpecializationType>()) { |
96 | |
97 | |
98 | |
99 | if (ClassTemplateDecl *ClassTemplate |
100 | = dyn_cast_or_null<ClassTemplateDecl>( |
101 | SpecType->getTemplateName().getAsTemplateDecl())) { |
102 | QualType ContextType |
103 | = Context.getCanonicalType(QualType(SpecType, 0)); |
104 | |
105 | |
106 | |
107 | |
108 | QualType Injected |
109 | = ClassTemplate->getInjectedClassNameSpecialization(); |
110 | if (Context.hasSameType(Injected, ContextType)) |
111 | return ClassTemplate->getTemplatedDecl(); |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | if (ClassTemplatePartialSpecializationDecl *PartialSpec |
118 | = ClassTemplate->findPartialSpecialization(ContextType)) { |
119 | |
120 | |
121 | |
122 | assert(!isSFINAEContext() && |
123 | "partial specialization scope specifier in SFINAE context?"); |
124 | if (!hasVisibleDeclaration(PartialSpec)) |
125 | diagnoseMissingImport(SS.getLastQualifierNameLoc(), PartialSpec, |
126 | MissingImportKind::PartialSpecialization, |
127 | true); |
128 | return PartialSpec; |
129 | } |
130 | } |
131 | } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) { |
132 | |
133 | return RecordT->getDecl(); |
134 | } |
135 | } |
136 | |
137 | return nullptr; |
138 | } |
139 | |
140 | switch (NNS->getKind()) { |
| 13 | | Control jumps to 'case TypeSpecWithTemplate:' at line 151 | |
|
141 | case NestedNameSpecifier::Identifier: |
142 | llvm_unreachable("Dependent nested-name-specifier has no DeclContext"); |
143 | |
144 | case NestedNameSpecifier::Namespace: |
145 | return NNS->getAsNamespace(); |
146 | |
147 | case NestedNameSpecifier::NamespaceAlias: |
148 | return NNS->getAsNamespaceAlias()->getNamespace(); |
149 | |
150 | case NestedNameSpecifier::TypeSpec: |
151 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
152 | const TagType *Tag = NNS->getAsType()->getAs<TagType>(); |
| 14 | | Assuming the object is not a 'TagType' | |
|
| 15 | | 'Tag' initialized to a null pointer value | |
|
153 | assert(Tag && "Non-tag type in nested-name-specifier"); |
154 | return Tag->getDecl(); |
| 16 | | Called C++ object pointer is null |
|
155 | } |
156 | |
157 | case NestedNameSpecifier::Global: |
158 | return Context.getTranslationUnitDecl(); |
159 | |
160 | case NestedNameSpecifier::Super: |
161 | return NNS->getAsRecordDecl(); |
162 | } |
163 | |
164 | llvm_unreachable("Invalid NestedNameSpecifier::Kind!"); |
165 | } |
166 | |
167 | bool Sema::isDependentScopeSpecifier(const CXXScopeSpec &SS) { |
168 | if (!SS.isSet() || SS.isInvalid()) |
169 | return false; |
170 | |
171 | return SS.getScopeRep()->isDependent(); |
172 | } |
173 | |
174 | |
175 | |
176 | |
177 | |
178 | |
179 | CXXRecordDecl *Sema::getCurrentInstantiationOf(NestedNameSpecifier *NNS) { |
180 | assert(getLangOpts().CPlusPlus && "Only callable in C++"); |
181 | assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed"); |
182 | |
183 | if (!NNS->getAsType()) |
184 | return nullptr; |
185 | |
186 | QualType T = QualType(NNS->getAsType(), 0); |
187 | return ::getCurrentInstantiationOf(T, CurContext); |
188 | } |
189 | |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | |
198 | |
199 | bool Sema::RequireCompleteDeclContext(CXXScopeSpec &SS, |
200 | DeclContext *DC) { |
201 | assert(DC && "given null context"); |
202 | |
203 | TagDecl *tag = dyn_cast<TagDecl>(DC); |
204 | |
205 | |
206 | |
207 | |
208 | if (!tag || tag->isDependentContext()) |
209 | return false; |
210 | |
211 | |
212 | QualType type = Context.getTypeDeclType(tag); |
213 | tag = type->getAsTagDecl(); |
214 | |
215 | |
216 | |
217 | if (tag->isBeingDefined()) |
218 | return false; |
219 | |
220 | SourceLocation loc = SS.getLastQualifierNameLoc(); |
221 | if (loc.isInvalid()) loc = SS.getRange().getBegin(); |
222 | |
223 | |
224 | if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec, |
225 | SS.getRange())) { |
226 | SS.SetInvalid(SS.getRange()); |
227 | return true; |
228 | } |
229 | |
230 | if (auto *EnumD = dyn_cast<EnumDecl>(tag)) |
231 | |
232 | |
233 | return RequireCompleteEnumDecl(EnumD, loc, &SS); |
234 | |
235 | return false; |
236 | } |
237 | |
238 | |
239 | |
240 | |
241 | bool Sema::RequireCompleteEnumDecl(EnumDecl *EnumD, SourceLocation L, |
242 | CXXScopeSpec *SS) { |
243 | if (EnumD->isCompleteDefinition()) { |
244 | |
245 | NamedDecl *SuggestedDef = nullptr; |
246 | if (!hasVisibleDefinition(EnumD, &SuggestedDef, |
247 | false)) { |
248 | |
249 | |
250 | bool TreatAsComplete = !isSFINAEContext(); |
251 | diagnoseMissingImport(L, SuggestedDef, MissingImportKind::Definition, |
252 | TreatAsComplete); |
253 | return !TreatAsComplete; |
254 | } |
255 | return false; |
256 | } |
257 | |
258 | |
259 | |
260 | if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) { |
261 | MemberSpecializationInfo *MSI = EnumD->getMemberSpecializationInfo(); |
262 | if (MSI->getTemplateSpecializationKind() != TSK_ExplicitSpecialization) { |
263 | if (InstantiateEnum(L, EnumD, Pattern, |
264 | getTemplateInstantiationArgs(EnumD), |
265 | TSK_ImplicitInstantiation)) { |
266 | if (SS) |
267 | SS->SetInvalid(SS->getRange()); |
268 | return true; |
269 | } |
270 | return false; |
271 | } |
272 | } |
273 | |
274 | if (SS) { |
275 | Diag(L, diag::err_incomplete_nested_name_spec) |
276 | << QualType(EnumD->getTypeForDecl(), 0) << SS->getRange(); |
277 | SS->SetInvalid(SS->getRange()); |
278 | } else { |
279 | Diag(L, diag::err_incomplete_enum) << QualType(EnumD->getTypeForDecl(), 0); |
280 | Diag(EnumD->getLocation(), diag::note_declared_at); |
281 | } |
282 | |
283 | return true; |
284 | } |
285 | |
286 | bool Sema::ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, |
287 | CXXScopeSpec &SS) { |
288 | SS.MakeGlobal(Context, CCLoc); |
289 | return false; |
290 | } |
291 | |
292 | bool Sema::ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
293 | SourceLocation ColonColonLoc, |
294 | CXXScopeSpec &SS) { |
295 | CXXRecordDecl *RD = nullptr; |
296 | for (Scope *S = getCurScope(); S; S = S->getParent()) { |
297 | if (S->isFunctionScope()) { |
298 | if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity())) |
299 | RD = MD->getParent(); |
300 | break; |
301 | } |
302 | if (S->isClassScope()) { |
303 | RD = cast<CXXRecordDecl>(S->getEntity()); |
304 | break; |
305 | } |
306 | } |
307 | |
308 | if (!RD) { |
309 | Diag(SuperLoc, diag::err_invalid_super_scope); |
310 | return true; |
311 | } else if (RD->isLambda()) { |
312 | Diag(SuperLoc, diag::err_super_in_lambda_unsupported); |
313 | return true; |
314 | } else if (RD->getNumBases() == 0) { |
315 | Diag(SuperLoc, diag::err_no_base_classes) << RD->getName(); |
316 | return true; |
317 | } |
318 | |
319 | SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc); |
320 | return false; |
321 | } |
322 | |
323 | |
324 | |
325 | |
326 | |
327 | |
328 | bool Sema::isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
329 | bool *IsExtension) { |
330 | if (!SD) |
331 | return false; |
332 | |
333 | SD = SD->getUnderlyingDecl(); |
334 | |
335 | |
336 | if (isa<NamespaceDecl>(SD)) |
337 | return true; |
338 | |
339 | if (!isa<TypeDecl>(SD)) |
340 | return false; |
341 | |
342 | |
343 | |
344 | QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD)); |
345 | if (T->isDependentType()) |
346 | return true; |
347 | if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) { |
348 | if (TD->getUnderlyingType()->isRecordType()) |
349 | return true; |
350 | if (TD->getUnderlyingType()->isEnumeralType()) { |
351 | if (Context.getLangOpts().CPlusPlus11) |
352 | return true; |
353 | if (IsExtension) |
354 | *IsExtension = true; |
355 | } |
356 | } else if (isa<RecordDecl>(SD)) { |
357 | return true; |
358 | } else if (isa<EnumDecl>(SD)) { |
359 | if (Context.getLangOpts().CPlusPlus11) |
360 | return true; |
361 | if (IsExtension) |
362 | *IsExtension = true; |
363 | } |
364 | |
365 | return false; |
366 | } |
367 | |
368 | |
369 | |
370 | |
371 | |
372 | NamedDecl *Sema::FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS) { |
373 | if (!S || !NNS) |
374 | return nullptr; |
375 | |
376 | while (NNS->getPrefix()) |
377 | NNS = NNS->getPrefix(); |
378 | |
379 | if (NNS->getKind() != NestedNameSpecifier::Identifier) |
380 | return nullptr; |
381 | |
382 | LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(), |
383 | LookupNestedNameSpecifierName); |
384 | LookupName(Found, S); |
385 | assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet"); |
386 | |
387 | if (!Found.isSingleResult()) |
388 | return nullptr; |
389 | |
390 | NamedDecl *Result = Found.getFoundDecl(); |
391 | if (isAcceptableNestedNameSpecifier(Result)) |
392 | return Result; |
393 | |
394 | return nullptr; |
395 | } |
396 | |
397 | bool Sema::isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, |
398 | NestedNameSpecInfo &IdInfo) { |
399 | QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType); |
400 | LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc, |
401 | LookupNestedNameSpecifierName); |
402 | |
403 | |
404 | DeclContext *LookupCtx = nullptr; |
405 | bool isDependent = false; |
406 | if (!ObjectType.isNull()) { |
407 | |
408 | |
409 | assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist"); |
410 | LookupCtx = computeDeclContext(ObjectType); |
411 | isDependent = ObjectType->isDependentType(); |
412 | } else if (SS.isSet()) { |
413 | |
414 | |
415 | LookupCtx = computeDeclContext(SS, false); |
416 | isDependent = isDependentScopeSpecifier(SS); |
417 | Found.setContextRange(SS.getRange()); |
418 | } |
419 | |
420 | if (LookupCtx) { |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | |
427 | if (!LookupCtx->isDependentContext() && |
428 | RequireCompleteDeclContext(SS, LookupCtx)) |
429 | return false; |
430 | |
431 | LookupQualifiedName(Found, LookupCtx); |
432 | } else if (isDependent) { |
433 | return false; |
434 | } else { |
435 | LookupName(Found, S); |
436 | } |
437 | Found.suppressDiagnostics(); |
438 | |
439 | return Found.getAsSingle<NamespaceDecl>(); |
440 | } |
441 | |
442 | namespace { |
443 | |
444 | |
445 | |
446 | class NestedNameSpecifierValidatorCCC final |
447 | : public CorrectionCandidateCallback { |
448 | public: |
449 | explicit NestedNameSpecifierValidatorCCC(Sema &SRef) |
450 | : SRef(SRef) {} |
451 | |
452 | bool ValidateCandidate(const TypoCorrection &candidate) override { |
453 | return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl()); |
454 | } |
455 | |
456 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
457 | return std::make_unique<NestedNameSpecifierValidatorCCC>(*this); |
458 | } |
459 | |
460 | private: |
461 | Sema &SRef; |
462 | }; |
463 | |
464 | } |
465 | |
466 | |
467 | |
468 | |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | |
475 | |
476 | |
477 | |
478 | |
479 | |
480 | |
481 | |
482 | |
483 | |
484 | |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | |
491 | |
492 | |
493 | |
494 | |
495 | |
496 | |
497 | bool Sema::BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, |
498 | bool EnteringContext, CXXScopeSpec &SS, |
499 | NamedDecl *ScopeLookupResult, |
500 | bool ErrorRecoveryLookup, |
501 | bool *IsCorrectedToColon, |
502 | bool OnlyNamespace) { |
503 | if (IdInfo.Identifier->isEditorPlaceholder()) |
504 | return true; |
505 | LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc, |
506 | OnlyNamespace ? LookupNamespaceName |
507 | : LookupNestedNameSpecifierName); |
508 | QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType); |
509 | |
510 | |
511 | DeclContext *LookupCtx = nullptr; |
512 | bool isDependent = false; |
513 | if (IsCorrectedToColon) |
514 | *IsCorrectedToColon = false; |
515 | if (!ObjectType.isNull()) { |
516 | |
517 | |
518 | assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist"); |
519 | LookupCtx = computeDeclContext(ObjectType); |
520 | isDependent = ObjectType->isDependentType(); |
521 | } else if (SS.isSet()) { |
522 | |
523 | |
524 | LookupCtx = computeDeclContext(SS, EnteringContext); |
525 | isDependent = isDependentScopeSpecifier(SS); |
526 | Found.setContextRange(SS.getRange()); |
527 | } |
528 | |
529 | bool ObjectTypeSearchedInScope = false; |
530 | if (LookupCtx) { |
531 | |
532 | |
533 | |
534 | |
535 | |
536 | |
537 | if (!LookupCtx->isDependentContext() && |
538 | RequireCompleteDeclContext(SS, LookupCtx)) |
539 | return true; |
540 | |
541 | LookupQualifiedName(Found, LookupCtx); |
542 | |
543 | if (!ObjectType.isNull() && Found.empty()) { |
544 | |
545 | |
546 | |
547 | |
548 | |
549 | |
550 | |
551 | |
552 | |
553 | |
554 | |
555 | |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | |
563 | |
564 | if (S) |
565 | LookupName(Found, S); |
566 | else if (ScopeLookupResult) |
567 | Found.addDecl(ScopeLookupResult); |
568 | |
569 | ObjectTypeSearchedInScope = true; |
570 | } |
571 | } else if (!isDependent) { |
572 | |
573 | LookupName(Found, S); |
574 | } |
575 | |
576 | if (Found.isAmbiguous()) |
577 | return true; |
578 | |
579 | |
580 | |
581 | if (Found.empty() && isDependent && |
582 | !(LookupCtx && LookupCtx->isRecord() && |
583 | (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() || |
584 | !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) { |
585 | |
586 | if (ErrorRecoveryLookup) |
587 | return true; |
588 | |
589 | |
590 | |
591 | |
592 | |
593 | SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc); |
594 | return false; |
595 | } |
596 | |
597 | if (Found.empty() && !ErrorRecoveryLookup) { |
598 | |
599 | |
600 | LookupResult R(*this, Found.getLookupNameInfo(), LookupOrdinaryName); |
601 | if (LookupCtx) |
602 | LookupQualifiedName(R, LookupCtx); |
603 | else if (S && !isDependent) |
604 | LookupName(R, S); |
605 | if (!R.empty()) { |
606 | |
607 | R.suppressDiagnostics(); |
608 | |
609 | |
610 | if (IsCorrectedToColon) { |
611 | *IsCorrectedToColon = true; |
612 | Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class) |
613 | << IdInfo.Identifier << getLangOpts().CPlusPlus |
614 | << FixItHint::CreateReplacement(IdInfo.CCLoc, ":"); |
615 | if (NamedDecl *ND = R.getAsSingle<NamedDecl>()) |
616 | Diag(ND->getLocation(), diag::note_declared_at); |
617 | return true; |
618 | } |
619 | |
620 | Diag(R.getNameLoc(), OnlyNamespace |
621 | ? unsigned(diag::err_expected_namespace_name) |
622 | : unsigned(diag::err_expected_class_or_namespace)) |
623 | << IdInfo.Identifier << getLangOpts().CPlusPlus; |
624 | if (NamedDecl *ND = R.getAsSingle<NamedDecl>()) |
625 | Diag(ND->getLocation(), diag::note_entity_declared_at) |
626 | << IdInfo.Identifier; |
627 | return true; |
628 | } |
629 | } |
630 | |
631 | if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) { |
632 | |
633 | |
634 | DeclarationName Name = Found.getLookupName(); |
635 | Found.clear(); |
636 | NestedNameSpecifierValidatorCCC CCC(*this); |
637 | if (TypoCorrection Corrected = CorrectTypo( |
638 | Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC, |
639 | CTK_ErrorRecovery, LookupCtx, EnteringContext)) { |
640 | if (LookupCtx) { |
641 | bool DroppedSpecifier = |
642 | Corrected.WillReplaceSpecifier() && |
643 | Name.getAsString() == Corrected.getAsString(getLangOpts()); |
644 | if (DroppedSpecifier) |
645 | SS.clear(); |
646 | diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest) |
647 | << Name << LookupCtx << DroppedSpecifier |
648 | << SS.getRange()); |
649 | } else |
650 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
651 | << Name); |
652 | |
653 | if (Corrected.getCorrectionSpecifier()) |
654 | SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(), |
655 | SourceRange(Found.getNameLoc())); |
656 | |
657 | if (NamedDecl *ND = Corrected.getFoundDecl()) |
658 | Found.addDecl(ND); |
659 | Found.setLookupName(Corrected.getCorrection()); |
660 | } else { |
661 | Found.setLookupName(IdInfo.Identifier); |
662 | } |
663 | } |
664 | |
665 | NamedDecl *SD = |
666 | Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr; |
667 | bool IsExtension = false; |
668 | bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension); |
669 | if (!AcceptSpec && IsExtension) { |
670 | AcceptSpec = true; |
671 | Diag(IdInfo.IdentifierLoc, diag::ext_nested_name_spec_is_enum); |
672 | } |
673 | if (AcceptSpec) { |
674 | if (!ObjectType.isNull() && !ObjectTypeSearchedInScope && |
675 | !getLangOpts().CPlusPlus11) { |
676 | |
677 | |
678 | |
679 | |
680 | |
681 | |
682 | |
683 | |
684 | |
685 | |
686 | NamedDecl *OuterDecl; |
687 | if (S) { |
688 | LookupResult FoundOuter(*this, IdInfo.Identifier, IdInfo.IdentifierLoc, |
689 | LookupNestedNameSpecifierName); |
690 | LookupName(FoundOuter, S); |
691 | OuterDecl = FoundOuter.getAsSingle<NamedDecl>(); |
692 | } else |
693 | OuterDecl = ScopeLookupResult; |
694 | |
695 | if (isAcceptableNestedNameSpecifier(OuterDecl) && |
696 | OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() && |
697 | (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) || |
698 | !Context.hasSameType( |
699 | Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)), |
700 | Context.getTypeDeclType(cast<TypeDecl>(SD))))) { |
701 | if (ErrorRecoveryLookup) |
702 | return true; |
703 | |
704 | Diag(IdInfo.IdentifierLoc, |
705 | diag::err_nested_name_member_ref_lookup_ambiguous) |
706 | << IdInfo.Identifier; |
707 | Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type) |
708 | << ObjectType; |
709 | Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope); |
710 | |
711 | |
712 | |
713 | } |
714 | } |
715 | |
716 | if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD)) |
717 | MarkAnyDeclReferenced(TD->getLocation(), TD, false); |
718 | |
719 | |
720 | |
721 | if (ErrorRecoveryLookup) |
722 | return false; |
723 | |
724 | |
725 | DiagnoseUseOfDecl(SD, IdInfo.CCLoc); |
726 | |
727 | if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) { |
728 | SS.Extend(Context, Namespace, IdInfo.IdentifierLoc, IdInfo.CCLoc); |
729 | return false; |
730 | } |
731 | |
732 | if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) { |
733 | SS.Extend(Context, Alias, IdInfo.IdentifierLoc, IdInfo.CCLoc); |
734 | return false; |
735 | } |
736 | |
737 | QualType T = |
738 | Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl())); |
739 | TypeLocBuilder TLB; |
740 | if (isa<InjectedClassNameType>(T)) { |
741 | InjectedClassNameTypeLoc InjectedTL |
742 | = TLB.push<InjectedClassNameTypeLoc>(T); |
743 | InjectedTL.setNameLoc(IdInfo.IdentifierLoc); |
744 | } else if (isa<RecordType>(T)) { |
745 | RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T); |
746 | RecordTL.setNameLoc(IdInfo.IdentifierLoc); |
747 | } else if (isa<TypedefType>(T)) { |
748 | TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T); |
749 | TypedefTL.setNameLoc(IdInfo.IdentifierLoc); |
750 | } else if (isa<EnumType>(T)) { |
751 | EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T); |
752 | EnumTL.setNameLoc(IdInfo.IdentifierLoc); |
753 | } else if (isa<TemplateTypeParmType>(T)) { |
754 | TemplateTypeParmTypeLoc TemplateTypeTL |
755 | = TLB.push<TemplateTypeParmTypeLoc>(T); |
756 | TemplateTypeTL.setNameLoc(IdInfo.IdentifierLoc); |
757 | } else if (isa<UnresolvedUsingType>(T)) { |
758 | UnresolvedUsingTypeLoc UnresolvedTL |
759 | = TLB.push<UnresolvedUsingTypeLoc>(T); |
760 | UnresolvedTL.setNameLoc(IdInfo.IdentifierLoc); |
761 | } else if (isa<SubstTemplateTypeParmType>(T)) { |
762 | SubstTemplateTypeParmTypeLoc TL |
763 | = TLB.push<SubstTemplateTypeParmTypeLoc>(T); |
764 | TL.setNameLoc(IdInfo.IdentifierLoc); |
765 | } else if (isa<SubstTemplateTypeParmPackType>(T)) { |
766 | SubstTemplateTypeParmPackTypeLoc TL |
767 | = TLB.push<SubstTemplateTypeParmPackTypeLoc>(T); |
768 | TL.setNameLoc(IdInfo.IdentifierLoc); |
769 | } else { |
770 | llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier"); |
771 | } |
772 | |
773 | if (T->isEnumeralType()) |
774 | Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec); |
775 | |
776 | SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T), |
777 | IdInfo.CCLoc); |
778 | return false; |
779 | } |
780 | |
781 | |
782 | |
783 | if (ErrorRecoveryLookup) |
784 | return true; |
785 | |
786 | |
787 | |
788 | |
789 | if (Found.empty()) { |
790 | Found.clear(LookupOrdinaryName); |
791 | LookupName(Found, S); |
792 | } |
793 | |
794 | |
795 | |
796 | |
797 | |
798 | |
799 | |
800 | |
801 | |
802 | |
803 | |
804 | |
805 | |
806 | |
807 | |
808 | |
809 | |
810 | |
811 | if (getLangOpts().MSVCCompat) { |
812 | DeclContext *DC = LookupCtx ? LookupCtx : CurContext; |
813 | if (DC->isDependentContext() && DC->isFunctionOrMethod()) { |
814 | CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent()); |
815 | if (ContainingClass && ContainingClass->hasAnyDependentBases()) { |
816 | Diag(IdInfo.IdentifierLoc, |
817 | diag::ext_undeclared_unqual_id_with_dependent_base) |
818 | << IdInfo.Identifier << ContainingClass; |
819 | SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, |
820 | IdInfo.CCLoc); |
821 | return false; |
822 | } |
823 | } |
824 | } |
825 | |
826 | if (!Found.empty()) { |
827 | if (TypeDecl *TD = Found.getAsSingle<TypeDecl>()) |
828 | Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace) |
829 | << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus; |
830 | else { |
831 | Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace) |
832 | << IdInfo.Identifier << getLangOpts().CPlusPlus; |
833 | if (NamedDecl *ND = Found.getAsSingle<NamedDecl>()) |
834 | Diag(ND->getLocation(), diag::note_entity_declared_at) |
835 | << IdInfo.Identifier; |
836 | } |
837 | } else if (SS.isSet()) |
838 | Diag(IdInfo.IdentifierLoc, diag::err_no_member) << IdInfo.Identifier |
839 | << LookupCtx << SS.getRange(); |
840 | else |
841 | Diag(IdInfo.IdentifierLoc, diag::err_undeclared_var_use) |
842 | << IdInfo.Identifier; |
843 | |
844 | return true; |
845 | } |
846 | |
847 | bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, |
848 | bool EnteringContext, CXXScopeSpec &SS, |
849 | bool ErrorRecoveryLookup, |
850 | bool *IsCorrectedToColon, |
851 | bool OnlyNamespace) { |
852 | if (SS.isInvalid()) |
853 | return true; |
854 | |
855 | return BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS, |
856 | nullptr, false, |
857 | IsCorrectedToColon, OnlyNamespace); |
858 | } |
859 | |
860 | bool Sema::ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
861 | const DeclSpec &DS, |
862 | SourceLocation ColonColonLoc) { |
863 | if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error) |
864 | return true; |
865 | |
866 | assert(DS.getTypeSpecType() == DeclSpec::TST_decltype); |
867 | |
868 | QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc()); |
869 | if (T.isNull()) |
870 | return true; |
871 | |
872 | if (!T->isDependentType() && !T->getAs<TagType>()) { |
873 | Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace) |
874 | << T << getLangOpts().CPlusPlus; |
875 | return true; |
876 | } |
877 | |
878 | TypeLocBuilder TLB; |
879 | DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T); |
880 | DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc()); |
881 | SS.Extend(Context, SourceLocation(), TLB.getTypeLocInContext(Context, T), |
882 | ColonColonLoc); |
883 | return false; |
884 | } |
885 | |
886 | |
887 | |
888 | |
889 | |
890 | |
891 | |
892 | bool Sema::IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
893 | NestedNameSpecInfo &IdInfo, |
894 | bool EnteringContext) { |
895 | if (SS.isInvalid()) |
896 | return false; |
897 | |
898 | return !BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS, |
899 | nullptr, true); |
900 | } |
901 | |
902 | bool Sema::ActOnCXXNestedNameSpecifier(Scope *S, |
903 | CXXScopeSpec &SS, |
904 | SourceLocation TemplateKWLoc, |
905 | TemplateTy OpaqueTemplate, |
906 | SourceLocation TemplateNameLoc, |
907 | SourceLocation LAngleLoc, |
908 | ASTTemplateArgsPtr TemplateArgsIn, |
909 | SourceLocation RAngleLoc, |
910 | SourceLocation CCLoc, |
911 | bool EnteringContext) { |
912 | if (SS.isInvalid()) |
913 | return true; |
914 | |
915 | TemplateName Template = OpaqueTemplate.get(); |
916 | |
917 | |
918 | TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc); |
919 | translateTemplateArguments(TemplateArgsIn, TemplateArgs); |
920 | |
921 | DependentTemplateName *DTN = Template.getAsDependentTemplateName(); |
922 | if (DTN && DTN->isIdentifier()) { |
923 | |
924 | |
925 | assert(DTN->getQualifier() == SS.getScopeRep()); |
926 | QualType T = Context.getDependentTemplateSpecializationType(ETK_None, |
927 | DTN->getQualifier(), |
928 | DTN->getIdentifier(), |
929 | TemplateArgs); |
930 | |
931 | |
932 | TypeLocBuilder Builder; |
933 | DependentTemplateSpecializationTypeLoc SpecTL |
934 | = Builder.push<DependentTemplateSpecializationTypeLoc>(T); |
935 | SpecTL.setElaboratedKeywordLoc(SourceLocation()); |
936 | SpecTL.setQualifierLoc(SS.getWithLocInContext(Context)); |
937 | SpecTL.setTemplateKeywordLoc(TemplateKWLoc); |
938 | SpecTL.setTemplateNameLoc(TemplateNameLoc); |
939 | SpecTL.setLAngleLoc(LAngleLoc); |
940 | SpecTL.setRAngleLoc(RAngleLoc); |
941 | for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) |
942 | SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo()); |
943 | |
944 | SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T), |
945 | CCLoc); |
946 | return false; |
947 | } |
948 | |
949 | |
950 | |
951 | if (Template.getAsAssumedTemplateName() && |
952 | resolveAssumedTemplateNameAsType(S, Template, TemplateNameLoc)) |
953 | return true; |
954 | |
955 | TemplateDecl *TD = Template.getAsTemplateDecl(); |
956 | if (Template.getAsOverloadedTemplate() || DTN || |
957 | isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) { |
958 | SourceRange R(TemplateNameLoc, RAngleLoc); |
959 | if (SS.getRange().isValid()) |
960 | R.setBegin(SS.getRange().getBegin()); |
961 | |
962 | Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier) |
963 | << (TD && isa<VarTemplateDecl>(TD)) << Template << R; |
964 | NoteAllFoundTemplates(Template); |
965 | return true; |
966 | } |
967 | |
968 | |
969 | |
970 | QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
971 | if (T.isNull()) |
972 | return true; |
973 | |
974 | |
975 | |
976 | if (!T->isDependentType() && !T->getAs<TagType>()) { |
977 | Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T; |
978 | NoteAllFoundTemplates(Template); |
979 | return true; |
980 | } |
981 | |
982 | |
983 | TypeLocBuilder Builder; |
984 | TemplateSpecializationTypeLoc SpecTL |
985 | = Builder.push<TemplateSpecializationTypeLoc>(T); |
986 | SpecTL.setTemplateKeywordLoc(TemplateKWLoc); |
987 | SpecTL.setTemplateNameLoc(TemplateNameLoc); |
988 | SpecTL.setLAngleLoc(LAngleLoc); |
989 | SpecTL.setRAngleLoc(RAngleLoc); |
990 | for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I) |
991 | SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo()); |
992 | |
993 | |
994 | SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T), |
995 | CCLoc); |
996 | return false; |
997 | } |
998 | |
999 | namespace { |
1000 | |
1001 | |
1002 | struct NestedNameSpecifierAnnotation { |
1003 | NestedNameSpecifier *NNS; |
1004 | }; |
1005 | } |
1006 | |
1007 | void *Sema::SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS) { |
1008 | if (SS.isEmpty() || SS.isInvalid()) |
1009 | return nullptr; |
1010 | |
1011 | void *Mem = Context.Allocate( |
1012 | (sizeof(NestedNameSpecifierAnnotation) + SS.location_size()), |
1013 | alignof(NestedNameSpecifierAnnotation)); |
1014 | NestedNameSpecifierAnnotation *Annotation |
1015 | = new (Mem) NestedNameSpecifierAnnotation; |
1016 | Annotation->NNS = SS.getScopeRep(); |
1017 | memcpy(Annotation + 1, SS.location_data(), SS.location_size()); |
1018 | return Annotation; |
1019 | } |
1020 | |
1021 | void Sema::RestoreNestedNameSpecifierAnnotation(void *AnnotationPtr, |
1022 | SourceRange AnnotationRange, |
1023 | CXXScopeSpec &SS) { |
1024 | if (!AnnotationPtr) { |
1025 | SS.SetInvalid(AnnotationRange); |
1026 | return; |
1027 | } |
1028 | |
1029 | NestedNameSpecifierAnnotation *Annotation |
1030 | = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr); |
1031 | SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1)); |
1032 | } |
1033 | |
1034 | bool Sema::ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { |
1035 | assert(SS.isSet() && "Parser passed invalid CXXScopeSpec."); |
1036 | |
1037 | |
1038 | |
1039 | if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext)) |
1040 | return false; |
1041 | |
1042 | NestedNameSpecifier *Qualifier = SS.getScopeRep(); |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | |
1053 | |
1054 | |
1055 | |
1056 | |
1057 | |
1058 | switch (Qualifier->getKind()) { |
1059 | case NestedNameSpecifier::Global: |
1060 | case NestedNameSpecifier::Namespace: |
1061 | case NestedNameSpecifier::NamespaceAlias: |
1062 | |
1063 | |
1064 | return CurContext->getRedeclContext()->isFileContext(); |
1065 | |
1066 | case NestedNameSpecifier::Identifier: |
1067 | case NestedNameSpecifier::TypeSpec: |
1068 | case NestedNameSpecifier::TypeSpecWithTemplate: |
1069 | case NestedNameSpecifier::Super: |
1070 | |
1071 | return true; |
1072 | } |
1073 | |
1074 | llvm_unreachable("Invalid NestedNameSpecifier::Kind!"); |
1075 | } |
1076 | |
1077 | |
1078 | |
1079 | |
1080 | |
1081 | |
1082 | |
1083 | bool Sema::ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS) { |
1084 | assert(SS.isSet() && "Parser passed invalid CXXScopeSpec."); |
1085 | |
1086 | if (SS.isInvalid()) return true; |
| |
1087 | |
1088 | DeclContext *DC = computeDeclContext(SS, true); |
| 2 | | Calling 'Sema::computeDeclContext' | |
|
1089 | if (!DC) return true; |
1090 | |
1091 | |
1092 | |
1093 | if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC)) |
1094 | return true; |
1095 | |
1096 | EnterDeclaratorContext(S, DC); |
1097 | |
1098 | |
1099 | if (DC->isDependentContext()) |
1100 | RebuildNestedNameSpecifierInCurrentInstantiation(SS); |
1101 | |
1102 | return false; |
1103 | } |
1104 | |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | void Sema::ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { |
1111 | assert(SS.isSet() && "Parser passed invalid CXXScopeSpec."); |
1112 | if (SS.isInvalid()) |
1113 | return; |
1114 | assert(!SS.isInvalid() && computeDeclContext(SS, true) && |
1115 | "exiting declarator scope we never really entered"); |
1116 | ExitDeclaratorContext(S); |
1117 | } |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | #ifndef LLVM_CLANG_SEMA_DECLSPEC_H |
23 | #define LLVM_CLANG_SEMA_DECLSPEC_H |
24 | |
25 | #include "clang/AST/DeclCXX.h" |
26 | #include "clang/AST/DeclObjCCommon.h" |
27 | #include "clang/AST/NestedNameSpecifier.h" |
28 | #include "clang/Basic/ExceptionSpecificationType.h" |
29 | #include "clang/Basic/Lambda.h" |
30 | #include "clang/Basic/OperatorKinds.h" |
31 | #include "clang/Basic/Specifiers.h" |
32 | #include "clang/Lex/Token.h" |
33 | #include "clang/Sema/Ownership.h" |
34 | #include "clang/Sema/ParsedAttr.h" |
35 | #include "llvm/ADT/SmallVector.h" |
36 | #include "llvm/Support/Compiler.h" |
37 | #include "llvm/Support/ErrorHandling.h" |
38 | |
39 | namespace clang { |
40 | class ASTContext; |
41 | class CXXRecordDecl; |
42 | class TypeLoc; |
43 | class LangOptions; |
44 | class IdentifierInfo; |
45 | class NamespaceAliasDecl; |
46 | class NamespaceDecl; |
47 | class ObjCDeclSpec; |
48 | class Sema; |
49 | class Declarator; |
50 | struct TemplateIdAnnotation; |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | class CXXScopeSpec { |
65 | SourceRange Range; |
66 | NestedNameSpecifierLocBuilder Builder; |
67 | |
68 | public: |
69 | SourceRange getRange() const { return Range; } |
70 | void setRange(SourceRange R) { Range = R; } |
71 | void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } |
72 | void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } |
73 | SourceLocation getBeginLoc() const { return Range.getBegin(); } |
74 | SourceLocation getEndLoc() const { return Range.getEnd(); } |
75 | |
76 | |
77 | NestedNameSpecifier *getScopeRep() const { |
78 | return Builder.getRepresentation(); |
79 | } |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, |
93 | SourceLocation ColonColonLoc); |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | void Extend(ASTContext &Context, IdentifierInfo *Identifier, |
107 | SourceLocation IdentifierLoc, SourceLocation ColonColonLoc); |
108 | |
109 | |
110 | |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 | |
120 | void Extend(ASTContext &Context, NamespaceDecl *Namespace, |
121 | SourceLocation NamespaceLoc, SourceLocation ColonColonLoc); |
122 | |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |
135 | void Extend(ASTContext &Context, NamespaceAliasDecl *Alias, |
136 | SourceLocation AliasLoc, SourceLocation ColonColonLoc); |
137 | |
138 | |
139 | |
140 | void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc); |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |
149 | |
150 | |
151 | |
152 | |
153 | |
154 | |
155 | void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, |
156 | SourceLocation SuperLoc, SourceLocation ColonColonLoc); |
157 | |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, |
165 | SourceRange R); |
166 | |
167 | |
168 | |
169 | void Adopt(NestedNameSpecifierLoc Other); |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const; |
177 | |
178 | |
179 | |
180 | |
181 | |
182 | |
183 | |
184 | |
185 | |
186 | |
187 | SourceLocation getLastQualifierNameLoc() const; |
188 | |
189 | |
190 | bool isEmpty() const { return Range.isInvalid() && getScopeRep() == nullptr; } |
191 | |
192 | bool isNotEmpty() const { return !isEmpty(); } |
193 | |
194 | |
195 | bool isInvalid() const { return Range.isValid() && getScopeRep() == nullptr; } |
| 8 | | Returning zero, which participates in a condition later | |
|
196 | |
197 | bool isValid() const { return getScopeRep() != nullptr; } |
198 | |
199 | |
200 | void SetInvalid(SourceRange R) { |
201 | assert(R.isValid() && "Must have a valid source range"); |
202 | if (Range.getBegin().isInvalid()) |
203 | Range.setBegin(R.getBegin()); |
204 | Range.setEnd(R.getEnd()); |
205 | Builder.Clear(); |
206 | } |
207 | |
208 | |
209 | |
210 | bool isSet() const { return getScopeRep() != nullptr; } |
| 4 | | Assuming the condition is true | |
|
| 5 | | Returning the value 1, which participates in a condition later | |
|
211 | |
212 | void clear() { |
213 | Range = SourceRange(); |
214 | Builder.Clear(); |
215 | } |
216 | |
217 | |
218 | char *location_data() const { return Builder.getBuffer().first; } |
219 | |
220 | |
221 | |
222 | unsigned location_size() const { return Builder.getBuffer().second; } |
223 | }; |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | class DeclSpec { |
230 | public: |
231 | |
232 | |
233 | enum SCS { |
234 | SCS_unspecified = 0, |
235 | SCS_typedef, |
236 | SCS_extern, |
237 | SCS_static, |
238 | SCS_auto, |
239 | SCS_register, |
240 | SCS_private_extern, |
241 | SCS_mutable |
242 | }; |
243 | |
244 | |
245 | |
246 | typedef ThreadStorageClassSpecifier TSCS; |
247 | static const TSCS TSCS_unspecified = clang::TSCS_unspecified; |
248 | static const TSCS TSCS___thread = clang::TSCS___thread; |
249 | static const TSCS TSCS_thread_local = clang::TSCS_thread_local; |
250 | static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local; |
251 | |
252 | enum TSC { |
253 | TSC_unspecified, |
254 | TSC_imaginary, |
255 | TSC_complex |
256 | }; |
257 | |
258 | |
259 | typedef TypeSpecifierType TST; |
260 | static const TST TST_unspecified = clang::TST_unspecified; |
261 | static const TST TST_void = clang::TST_void; |
262 | static const TST TST_char = clang::TST_char; |
263 | static const TST TST_wchar = clang::TST_wchar; |
264 | static const TST TST_char8 = clang::TST_char8; |
265 | static const TST TST_char16 = clang::TST_char16; |
266 | static const TST TST_char32 = clang::TST_char32; |
267 | static const TST TST_int = clang::TST_int; |
268 | static const TST TST_int128 = clang::TST_int128; |
269 | static const TST TST_extint = clang::TST_extint; |
270 | static const TST TST_half = clang::TST_half; |
271 | static const TST TST_BFloat16 = clang::TST_BFloat16; |
272 | static const TST TST_float = clang::TST_float; |
273 | static const TST TST_double = clang::TST_double; |
274 | static const TST TST_float16 = clang::TST_Float16; |
275 | static const TST TST_accum = clang::TST_Accum; |
276 | static const TST TST_fract = clang::TST_Fract; |
277 | static const TST TST_float128 = clang::TST_float128; |
278 | static const TST TST_bool = clang::TST_bool; |
279 | static const TST TST_decimal32 = clang::TST_decimal32; |
280 | static const TST TST_decimal64 = clang::TST_decimal64; |
281 | static const TST TST_decimal128 = clang::TST_decimal128; |
282 | static const TST TST_enum = clang::TST_enum; |
283 | static const TST TST_union = clang::TST_union; |
284 | static const TST TST_struct = clang::TST_struct; |
285 | static const TST TST_interface = clang::TST_interface; |
286 | static const TST TST_class = clang::TST_class; |
287 | static const TST TST_typename = clang::TST_typename; |
288 | static const TST TST_typeofType = clang::TST_typeofType; |
289 | static const TST TST_typeofExpr = clang::TST_typeofExpr; |
290 | static const TST TST_decltype = clang::TST_decltype; |
291 | static const TST TST_decltype_auto = clang::TST_decltype_auto; |
292 | static const TST TST_underlyingType = clang::TST_underlyingType; |
293 | static const TST TST_auto = clang::TST_auto; |
294 | static const TST TST_auto_type = clang::TST_auto_type; |
295 | static const TST TST_unknown_anytype = clang::TST_unknown_anytype; |
296 | static const TST TST_atomic = clang::TST_atomic; |
297 | #define GENERIC_IMAGE_TYPE(ImgType, Id) \ |
298 | static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t; |
299 | #include "clang/Basic/OpenCLImageTypes.def" |
300 | static const TST TST_error = clang::TST_error; |
301 | |
302 | |
303 | enum TQ { |
304 | TQ_unspecified = 0, |
305 | TQ_const = 1, |
306 | TQ_restrict = 2, |
307 | TQ_volatile = 4, |
308 | TQ_unaligned = 8, |
309 | |
310 | |
311 | TQ_atomic = 16 |
312 | }; |
313 | |
314 | |
315 | |
316 | enum ParsedSpecifiers { |
317 | PQ_None = 0, |
318 | PQ_StorageClassSpecifier = 1, |
319 | PQ_TypeSpecifier = 2, |
320 | PQ_TypeQualifier = 4, |
321 | PQ_FunctionSpecifier = 8 |
322 | |
323 | }; |
324 | |
325 | private: |
326 | |
327 | unsigned StorageClassSpec : 3; |
328 | unsigned ThreadStorageClassSpec : 2; |
329 | unsigned SCS_extern_in_linkage_spec : 1; |
330 | |
331 | |
332 | unsigned TypeSpecWidth : 2; |
333 | unsigned TypeSpecComplex : 2; |
334 | unsigned TypeSpecSign : 2; |
335 | unsigned TypeSpecType : 6; |
336 | unsigned TypeAltiVecVector : 1; |
337 | unsigned TypeAltiVecPixel : 1; |
338 | unsigned TypeAltiVecBool : 1; |
339 | unsigned TypeSpecOwned : 1; |
340 | unsigned TypeSpecPipe : 1; |
341 | unsigned TypeSpecSat : 1; |
342 | unsigned ConstrainedAuto : 1; |
343 | |
344 | |
345 | unsigned TypeQualifiers : 5; |
346 | |
347 | |
348 | unsigned FS_inline_specified : 1; |
349 | unsigned FS_forceinline_specified: 1; |
350 | unsigned FS_virtual_specified : 1; |
351 | unsigned FS_noreturn_specified : 1; |
352 | |
353 | |
354 | unsigned Friend_specified : 1; |
355 | |
356 | |
357 | unsigned ConstexprSpecifier : 2; |
358 | |
359 | union { |
360 | UnionParsedType TypeRep; |
361 | Decl *DeclRep; |
362 | Expr *ExprRep; |
363 | TemplateIdAnnotation *TemplateIdRep; |
364 | }; |
365 | |
366 | |
367 | ExplicitSpecifier FS_explicit_specifier; |
368 | |
369 | |
370 | ParsedAttributes Attrs; |
371 | |
372 | |
373 | CXXScopeSpec TypeScope; |
374 | |
375 | |
376 | |
377 | SourceRange Range; |
378 | |
379 | SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc; |
380 | SourceRange TSWRange; |
381 | SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc; |
382 | |
383 | |
384 | |
385 | |
386 | SourceLocation TSTNameLoc; |
387 | SourceRange TypeofParensRange; |
388 | SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, |
389 | TQ_unalignedLoc; |
390 | SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc; |
391 | SourceLocation FS_explicitCloseParenLoc; |
392 | SourceLocation FS_forceinlineLoc; |
393 | SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc; |
394 | SourceLocation TQ_pipeLoc; |
395 | |
396 | WrittenBuiltinSpecs writtenBS; |
397 | void SaveWrittenBuiltinSpecs(); |
398 | |
399 | ObjCDeclSpec *ObjCQualifiers; |
400 | |
401 | static bool isTypeRep(TST T) { |
402 | return (T == TST_typename || T == TST_typeofType || |
403 | T == TST_underlyingType || T == TST_atomic); |
404 | } |
405 | static bool isExprRep(TST T) { |
406 | return (T == TST_typeofExpr || T == TST_decltype || T == TST_extint); |
407 | } |
408 | static bool isTemplateIdRep(TST T) { |
409 | return (T == TST_auto || T == TST_decltype_auto); |
410 | } |
411 | |
412 | DeclSpec(const DeclSpec &) = delete; |
413 | void operator=(const DeclSpec &) = delete; |
414 | public: |
415 | static bool isDeclRep(TST T) { |
416 | return (T == TST_enum || T == TST_struct || |
417 | T == TST_interface || T == TST_union || |
418 | T == TST_class); |
419 | } |
420 | |
421 | DeclSpec(AttributeFactory &attrFactory) |
422 | : StorageClassSpec(SCS_unspecified), |
423 | ThreadStorageClassSpec(TSCS_unspecified), |
424 | SCS_extern_in_linkage_spec(false), |
425 | TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)), |
426 | TypeSpecComplex(TSC_unspecified), |
427 | TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)), |
428 | TypeSpecType(TST_unspecified), TypeAltiVecVector(false), |
429 | TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false), |
430 | TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false), |
431 | TypeQualifiers(TQ_unspecified), FS_inline_specified(false), |
432 | FS_forceinline_specified(false), FS_virtual_specified(false), |
433 | FS_noreturn_specified(false), Friend_specified(false), |
434 | ConstexprSpecifier( |
435 | static_cast<unsigned>(ConstexprSpecKind::Unspecified)), |
436 | FS_explicit_specifier(), Attrs(attrFactory), writtenBS(), |
437 | ObjCQualifiers(nullptr) {} |
438 | |
439 | |
440 | SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; } |
441 | TSCS getThreadStorageClassSpec() const { |
442 | return (TSCS)ThreadStorageClassSpec; |
443 | } |
444 | bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; } |
445 | void setExternInLinkageSpec(bool Value) { |
446 | SCS_extern_in_linkage_spec = Value; |
447 | } |
448 | |
449 | SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; } |
450 | SourceLocation getThreadStorageClassSpecLoc() const { |
451 | return ThreadStorageClassSpecLoc; |
452 | } |
453 | |
454 | void ClearStorageClassSpecs() { |
455 | StorageClassSpec = DeclSpec::SCS_unspecified; |
456 | ThreadStorageClassSpec = DeclSpec::TSCS_unspecified; |
457 | SCS_extern_in_linkage_spec = false; |
458 | StorageClassSpecLoc = SourceLocation(); |
459 | ThreadStorageClassSpecLoc = SourceLocation(); |
460 | } |
461 | |
462 | void ClearTypeSpecType() { |
463 | TypeSpecType = DeclSpec::TST_unspecified; |
464 | TypeSpecOwned = false; |
465 | TSTLoc = SourceLocation(); |
466 | } |
467 | |
468 | |
469 | TypeSpecifierWidth getTypeSpecWidth() const { |
470 | return static_cast<TypeSpecifierWidth>(TypeSpecWidth); |
471 | } |
472 | TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; } |
473 | TypeSpecifierSign getTypeSpecSign() const { |
474 | return static_cast<TypeSpecifierSign>(TypeSpecSign); |
475 | } |
476 | TST getTypeSpecType() const { return (TST)TypeSpecType; } |
477 | bool isTypeAltiVecVector() const { return TypeAltiVecVector; } |
478 | bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; } |
479 | bool isTypeAltiVecBool() const { return TypeAltiVecBool; } |
480 | bool isTypeSpecOwned() const { return TypeSpecOwned; } |
481 | bool isTypeRep() const { return isTypeRep((TST) TypeSpecType); } |
482 | bool isTypeSpecPipe() const { return TypeSpecPipe; } |
483 | bool isTypeSpecSat() const { return TypeSpecSat; } |
484 | bool isConstrainedAuto() const { return ConstrainedAuto; } |
485 | |
486 | ParsedType getRepAsType() const { |
487 | assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type"); |
488 | return TypeRep; |
489 | } |
490 | Decl *getRepAsDecl() const { |
491 | assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl"); |
492 | return DeclRep; |
493 | } |
494 | Expr *getRepAsExpr() const { |
495 | assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr"); |
496 | return ExprRep; |
497 | } |
498 | TemplateIdAnnotation *getRepAsTemplateId() const { |
499 | assert(isTemplateIdRep((TST) TypeSpecType) && |
500 | "DeclSpec does not store a template id"); |
501 | return TemplateIdRep; |
502 | } |
503 | CXXScopeSpec &getTypeSpecScope() { return TypeScope; } |
504 | const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; } |
505 | |
506 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
507 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
508 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
509 | |
510 | SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); } |
511 | SourceRange getTypeSpecWidthRange() const { return TSWRange; } |
512 | SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; } |
513 | SourceLocation getTypeSpecSignLoc() const { return TSSLoc; } |
514 | SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } |
515 | SourceLocation getAltiVecLoc() const { return AltiVecLoc; } |
516 | SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; } |
517 | |
518 | SourceLocation getTypeSpecTypeNameLoc() const { |
519 | assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename); |
520 | return TSTNameLoc; |
521 | } |
522 | |
523 | SourceRange getTypeofParensRange() const { return TypeofParensRange; } |
524 | void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; } |
525 | |
526 | bool hasAutoTypeSpec() const { |
527 | return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type || |
528 | TypeSpecType == TST_decltype_auto); |
529 | } |
530 | |
531 | bool hasTagDefinition() const; |
532 | |
533 | |
534 | static const char *getSpecifierName(DeclSpec::TST T, |
535 | const PrintingPolicy &Policy); |
536 | static const char *getSpecifierName(DeclSpec::TQ Q); |
537 | static const char *getSpecifierName(TypeSpecifierSign S); |
538 | static const char *getSpecifierName(DeclSpec::TSC C); |
539 | static const char *getSpecifierName(TypeSpecifierWidth W); |
540 | static const char *getSpecifierName(DeclSpec::SCS S); |
541 | static const char *getSpecifierName(DeclSpec::TSCS S); |
542 | static const char *getSpecifierName(ConstexprSpecKind C); |
543 | |
544 | |
545 | |
546 | |
547 | unsigned getTypeQualifiers() const { return TypeQualifiers; } |
548 | SourceLocation getConstSpecLoc() const { return TQ_constLoc; } |
549 | SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; } |
550 | SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; } |
551 | SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; } |
552 | SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; } |
553 | SourceLocation getPipeLoc() const { return TQ_pipeLoc; } |
554 | |
555 | |
556 | void ClearTypeQualifiers() { |
557 | TypeQualifiers = 0; |
558 | TQ_constLoc = SourceLocation(); |
559 | TQ_restrictLoc = SourceLocation(); |
560 | TQ_volatileLoc = SourceLocation(); |
561 | TQ_atomicLoc = SourceLocation(); |
562 | TQ_unalignedLoc = SourceLocation(); |
563 | TQ_pipeLoc = SourceLocation(); |
564 | } |
565 | |
566 | |
567 | bool isInlineSpecified() const { |
568 | return FS_inline_specified | FS_forceinline_specified; |
569 | } |
570 | SourceLocation getInlineSpecLoc() const { |
571 | return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc; |
572 | } |
573 | |
574 | ExplicitSpecifier getExplicitSpecifier() const { |
575 | return FS_explicit_specifier; |
576 | } |
577 | |
578 | bool isVirtualSpecified() const { return FS_virtual_specified; } |
579 | SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; } |
580 | |
581 | bool hasExplicitSpecifier() const { |
582 | return FS_explicit_specifier.isSpecified(); |
583 | } |
584 | SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; } |
585 | SourceRange getExplicitSpecRange() const { |
586 | return FS_explicit_specifier.getExpr() |
587 | ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc) |
588 | : SourceRange(FS_explicitLoc); |
589 | } |
590 | |
591 | bool isNoreturnSpecified() const { return FS_noreturn_specified; } |
592 | SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; } |
593 | |
594 | void ClearFunctionSpecs() { |
595 | FS_inline_specified = false; |
596 | FS_inlineLoc = SourceLocation(); |
597 | FS_forceinline_specified = false; |
598 | FS_forceinlineLoc = SourceLocation(); |
599 | FS_virtual_specified = false; |
600 | FS_virtualLoc = SourceLocation(); |
601 | FS_explicit_specifier = ExplicitSpecifier(); |
602 | FS_explicitLoc = SourceLocation(); |
603 | FS_explicitCloseParenLoc = SourceLocation(); |
604 | FS_noreturn_specified = false; |
605 | FS_noreturnLoc = SourceLocation(); |
606 | } |
607 | |
608 | |
609 | |
610 | |
611 | void forEachCVRUQualifier( |
612 | llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle); |
613 | |
614 | |
615 | |
616 | |
617 | void forEachQualifier( |
618 | llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle); |
619 | |
620 | |
621 | bool hasTypeSpecifier() const { |
622 | return getTypeSpecType() != DeclSpec::TST_unspecified || |
623 | getTypeSpecWidth() != TypeSpecifierWidth::Unspecified || |
624 | getTypeSpecComplex() != DeclSpec::TSC_unspecified || |
625 | getTypeSpecSign() != TypeSpecifierSign::Unspecified; |
626 | } |
627 | |
628 | |
629 | |
630 | unsigned getParsedSpecifiers() const; |
631 | |
632 | |
633 | |
634 | bool isEmpty() const { |
635 | return getParsedSpecifiers() == DeclSpec::PQ_None; |
636 | } |
637 | |
638 | void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); } |
639 | void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); } |
640 | |
641 | |
642 | |
643 | |
644 | |
645 | |
646 | |
647 | |
648 | |
649 | |
650 | |
651 | bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, |
652 | const char *&PrevSpec, unsigned &DiagID, |
653 | const PrintingPolicy &Policy); |
654 | bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, |
655 | const char *&PrevSpec, unsigned &DiagID); |
656 | bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, |
657 | const char *&PrevSpec, unsigned &DiagID, |
658 | const PrintingPolicy &Policy); |
659 | bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, |
660 | unsigned &DiagID); |
661 | bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, |
662 | const char *&PrevSpec, unsigned &DiagID); |
663 | bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
664 | unsigned &DiagID, const PrintingPolicy &Policy); |
665 | bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
666 | unsigned &DiagID, ParsedType Rep, |
667 | const PrintingPolicy &Policy); |
668 | bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
669 | unsigned &DiagID, TypeResult Rep, |
670 | const PrintingPolicy &Policy) { |
671 | if (Rep.isInvalid()) |
672 | return SetTypeSpecError(); |
673 | return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep.get(), Policy); |
674 | } |
675 | bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
676 | unsigned &DiagID, Decl *Rep, bool Owned, |
677 | const PrintingPolicy &Policy); |
678 | bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
679 | SourceLocation TagNameLoc, const char *&PrevSpec, |
680 | unsigned &DiagID, ParsedType Rep, |
681 | const PrintingPolicy &Policy); |
682 | bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
683 | SourceLocation TagNameLoc, const char *&PrevSpec, |
684 | unsigned &DiagID, Decl *Rep, bool Owned, |
685 | const PrintingPolicy &Policy); |
686 | bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
687 | unsigned &DiagID, TemplateIdAnnotation *Rep, |
688 | const PrintingPolicy &Policy); |
689 | |
690 | bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, |
691 | unsigned &DiagID, Expr *Rep, |
692 | const PrintingPolicy &policy); |
693 | bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, |
694 | const char *&PrevSpec, unsigned &DiagID, |
695 | const PrintingPolicy &Policy); |
696 | bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, |
697 | const char *&PrevSpec, unsigned &DiagID, |
698 | const PrintingPolicy &Policy); |
699 | bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, |
700 | const char *&PrevSpec, unsigned &DiagID, |
701 | const PrintingPolicy &Policy); |
702 | bool SetTypePipe(bool isPipe, SourceLocation Loc, |
703 | const char *&PrevSpec, unsigned &DiagID, |
704 | const PrintingPolicy &Policy); |
705 | bool SetExtIntType(SourceLocation KWLoc, Expr *BitWidth, |
706 | const char *&PrevSpec, unsigned &DiagID, |
707 | const PrintingPolicy &Policy); |
708 | bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, |
709 | unsigned &DiagID); |
710 | bool SetTypeSpecError(); |
711 | void UpdateDeclRep(Decl *Rep) { |
712 | assert(isDeclRep((TST) TypeSpecType)); |
713 | DeclRep = Rep; |
714 | } |
715 | void UpdateTypeRep(ParsedType Rep) { |
716 | assert(isTypeRep((TST) TypeSpecType)); |
717 | TypeRep = Rep; |
718 | } |
719 | void UpdateExprRep(Expr *Rep) { |
720 | assert(isExprRep((TST) TypeSpecType)); |
721 | ExprRep = Rep; |
722 | } |
723 | |
724 | bool SetTypeQual(TQ T, SourceLocation Loc); |
725 | |
726 | bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
727 | unsigned &DiagID, const LangOptions &Lang); |
728 | |
729 | bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, |
730 | unsigned &DiagID); |
731 | bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, |
732 | unsigned &DiagID); |
733 | bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, |
734 | unsigned &DiagID); |
735 | bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, |
736 | unsigned &DiagID, ExplicitSpecifier ExplicitSpec, |
737 | SourceLocation CloseParenLoc); |
738 | bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, |
739 | unsigned &DiagID); |
740 | |
741 | bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
742 | unsigned &DiagID); |
743 | bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, |
744 | unsigned &DiagID); |
745 | bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, |
746 | const char *&PrevSpec, unsigned &DiagID); |
747 | |
748 | bool isFriendSpecified() const { return Friend_specified; } |
749 | SourceLocation getFriendSpecLoc() const { return FriendLoc; } |
750 | |
751 | bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); } |
752 | SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; } |
753 | |
754 | ConstexprSpecKind getConstexprSpecifier() const { |
755 | return ConstexprSpecKind(ConstexprSpecifier); |
756 | } |
757 | |
758 | SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; } |
759 | bool hasConstexprSpecifier() const { |
760 | return getConstexprSpecifier() != ConstexprSpecKind::Unspecified; |
761 | } |
762 | |
763 | void ClearConstexprSpec() { |
764 | ConstexprSpecifier = static_cast<unsigned>(ConstexprSpecKind::Unspecified); |
765 | ConstexprLoc = SourceLocation(); |
766 | } |
767 | |
768 | AttributePool &getAttributePool() const { |
769 | return Attrs.getPool(); |
770 | } |
771 | |
772 | |
773 | |
774 | |
775 | |
776 | |
777 | |
778 | |
779 | |
780 | |
781 | |
782 | |
783 | |
784 | |
785 | |
786 | |
787 | |
788 | |
789 | void addAttributes(ParsedAttributesView &AL) { |
790 | Attrs.addAll(AL.begin(), AL.end()); |
791 | } |
792 | |
793 | bool hasAttributes() const { return !Attrs.empty(); } |
794 | |
795 | ParsedAttributes &getAttributes() { return Attrs; } |
796 | const ParsedAttributes &getAttributes() const { return Attrs; } |
797 | |
798 | void takeAttributesFrom(ParsedAttributes &attrs) { |
799 | Attrs.takeAllFrom(attrs); |
800 | } |
801 | |
802 | |
803 | |
804 | |
805 | void Finish(Sema &S, const PrintingPolicy &Policy); |
806 | |
807 | const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { |
808 | return writtenBS; |
809 | } |
810 | |
811 | ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; } |
812 | void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; } |
813 | |
814 | |
815 | |
816 | |
817 | bool isMissingDeclaratorOk(); |
818 | }; |
819 | |
820 | |
821 | |
822 | class ObjCDeclSpec { |
823 | public: |
824 | |
825 | |
826 | |
827 | |
828 | |
829 | |
830 | enum ObjCDeclQualifier { |
831 | DQ_None = 0x0, |
832 | DQ_In = 0x1, |
833 | DQ_Inout = 0x2, |
834 | DQ_Out = 0x4, |
835 | DQ_Bycopy = 0x8, |
836 | DQ_Byref = 0x10, |
837 | DQ_Oneway = 0x20, |
838 | DQ_CSNullability = 0x40 |
839 | }; |
840 | |
841 | ObjCDeclSpec() |
842 | : objcDeclQualifier(DQ_None), |
843 | PropertyAttributes(ObjCPropertyAttribute::kind_noattr), Nullability(0), |
844 | GetterName(nullptr), SetterName(nullptr) {} |
845 | |
846 | ObjCDeclQualifier getObjCDeclQualifier() const { |
847 | return (ObjCDeclQualifier)objcDeclQualifier; |
848 | } |
849 | void setObjCDeclQualifier(ObjCDeclQualifier DQVal) { |
850 | objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal); |
851 | } |
852 | void clearObjCDeclQualifier(ObjCDeclQualifier DQVal) { |
853 | objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier & ~DQVal); |
854 | } |
855 | |
856 | ObjCPropertyAttribute::Kind getPropertyAttributes() const { |
857 | return ObjCPropertyAttribute::Kind(PropertyAttributes); |
858 | } |
859 | void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) { |
860 | PropertyAttributes = |
861 | (ObjCPropertyAttribute::Kind)(PropertyAttributes | PRVal); |
862 | } |
863 | |
864 | NullabilityKind getNullability() const { |
865 | assert( |
866 | ((getObjCDeclQualifier() & DQ_CSNullability) || |
867 | (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) && |
868 | "Objective-C declspec doesn't have nullability"); |
869 | return static_cast<NullabilityKind>(Nullability); |
870 | } |
871 | |
872 | SourceLocation getNullabilityLoc() const { |
873 | assert( |
874 | ((getObjCDeclQualifier() & DQ_CSNullability) || |
875 | (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) && |
876 | "Objective-C declspec doesn't have nullability"); |
877 | return NullabilityLoc; |
878 | } |
879 | |
880 | void setNullability(SourceLocation loc, NullabilityKind kind) { |
881 | assert( |
882 | ((getObjCDeclQualifier() & DQ_CSNullability) || |
883 | (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) && |
884 | "Set the nullability declspec or property attribute first"); |
885 | Nullability = static_cast<unsigned>(kind); |
886 | NullabilityLoc = loc; |
887 | } |
888 | |
889 | const IdentifierInfo *getGetterName() const { return GetterName; } |
890 | IdentifierInfo *getGetterName() { return GetterName; } |
891 | SourceLocation getGetterNameLoc() const { return GetterNameLoc; } |
892 | void setGetterName(IdentifierInfo *name, SourceLocation loc) { |
893 | GetterName = name; |
894 | GetterNameLoc = loc; |
895 | } |
896 | |
897 | const IdentifierInfo *getSetterName() const { return SetterName; } |
898 | IdentifierInfo *getSetterName() { return SetterName; } |
899 | SourceLocation getSetterNameLoc() const { return SetterNameLoc; } |
900 | void setSetterName(IdentifierInfo *name, SourceLocation loc) { |
901 | SetterName = name; |
902 | SetterNameLoc = loc; |
903 | } |
904 | |
905 | private: |
906 | |
907 | |
908 | |
909 | unsigned objcDeclQualifier : 7; |
910 | |
911 | |
912 | unsigned PropertyAttributes : NumObjCPropertyAttrsBits; |
913 | |
914 | unsigned Nullability : 2; |
915 | |
916 | SourceLocation NullabilityLoc; |
917 | |
918 | IdentifierInfo *GetterName; |
919 | IdentifierInfo *SetterName; |
920 | SourceLocation GetterNameLoc; |
921 | SourceLocation SetterNameLoc; |
922 | |
923 | }; |
924 | |
925 | |
926 | enum class UnqualifiedIdKind { |
927 | |
928 | IK_Identifier, |
929 | |
930 | IK_OperatorFunctionId, |
931 | |
932 | IK_ConversionFunctionId, |
933 | |
934 | IK_LiteralOperatorId, |
935 | |
936 | IK_ConstructorName, |
937 | |
938 | IK_ConstructorTemplateId, |
939 | |
940 | IK_DestructorName, |
941 | |
942 | IK_TemplateId, |
943 | |
944 | IK_ImplicitSelfParam, |
945 | |
946 | IK_DeductionGuideName |
947 | }; |
948 | |
949 | |
950 | class UnqualifiedId { |
951 | private: |
952 | UnqualifiedId(const UnqualifiedId &Other) = delete; |
953 | const UnqualifiedId &operator=(const UnqualifiedId &) = delete; |
954 | |
955 | public: |
956 | |
957 | UnqualifiedIdKind Kind; |
958 | |
959 | struct OFI { |
960 | |
961 | OverloadedOperatorKind Operator; |
962 | |
963 | |
964 | |
965 | |
966 | |
967 | |
968 | |
969 | |
970 | SourceLocation SymbolLocations[3]; |
971 | }; |
972 | |
973 | |
974 | |
975 | union { |
976 | |
977 | |
978 | IdentifierInfo *Identifier; |
979 | |
980 | |
981 | |
982 | struct OFI OperatorFunctionId; |
983 | |
984 | |
985 | |
986 | UnionParsedType ConversionFunctionId; |
987 | |
988 | |
989 | |
990 | UnionParsedType ConstructorName; |
991 | |
992 | |
993 | |
994 | UnionParsedType DestructorName; |
995 | |
996 | |
997 | UnionParsedTemplateTy TemplateName; |
998 | |
999 | |
1000 | |
1001 | |
1002 | TemplateIdAnnotation *TemplateId; |
1003 | }; |
1004 | |
1005 | |
1006 | |
1007 | |
1008 | SourceLocation StartLocation; |
1009 | |
1010 | |
1011 | SourceLocation EndLocation; |
1012 | |
1013 | UnqualifiedId() |
1014 | : Kind(UnqualifiedIdKind::IK_Identifier), Identifier(nullptr) {} |
1015 | |
1016 | |
1017 | |
1018 | void clear() { |
1019 | Kind = UnqualifiedIdKind::IK_Identifier; |
1020 | Identifier = nullptr; |
1021 | StartLocation = SourceLocation(); |
1022 | EndLocation = SourceLocation(); |
1023 | } |
1024 | |
1025 | |
1026 | bool isValid() const { return StartLocation.isValid(); } |
1027 | |
1028 | |
1029 | bool isInvalid() const { return !isValid(); } |
1030 | |
1031 | |
1032 | UnqualifiedIdKind getKind() const { return Kind; } |
1033 | |
1034 | |
1035 | |
1036 | |
1037 | |
1038 | void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { |
1039 | Kind = UnqualifiedIdKind::IK_Identifier; |
1040 | Identifier = const_cast<IdentifierInfo *>(Id); |
1041 | StartLocation = EndLocation = IdLoc; |
1042 | } |
1043 | |
1044 | |
1045 | |
1046 | |
1047 | |
1048 | |
1049 | |
1050 | |
1051 | |
1052 | |
1053 | void setOperatorFunctionId(SourceLocation OperatorLoc, |
1054 | OverloadedOperatorKind Op, |
1055 | SourceLocation SymbolLocations[3]); |
1056 | |
1057 | |
1058 | |
1059 | |
1060 | |
1061 | |
1062 | |
1063 | |
1064 | |
1065 | void setConversionFunctionId(SourceLocation OperatorLoc, |
1066 | ParsedType Ty, |
1067 | SourceLocation EndLoc) { |
1068 | Kind = UnqualifiedIdKind::IK_ConversionFunctionId; |
1069 | StartLocation = OperatorLoc; |
1070 | EndLocation = EndLoc; |
1071 | ConversionFunctionId = Ty; |
1072 | } |
1073 | |
1074 | |
1075 | |
1076 | |
1077 | |
1078 | |
1079 | |
1080 | |
1081 | |
1082 | void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, |
1083 | SourceLocation IdLoc) { |
1084 | Kind = UnqualifiedIdKind::IK_LiteralOperatorId; |
1085 | Identifier = const_cast<IdentifierInfo *>(Id); |
1086 | StartLocation = OpLoc; |
1087 | EndLocation = IdLoc; |
1088 | } |
1089 | |
1090 | |
1091 | |
1092 | |
1093 | |
1094 | |
1095 | |
1096 | |
1097 | void setConstructorName(ParsedType ClassType, |
1098 | SourceLocation ClassNameLoc, |
1099 | SourceLocation EndLoc) { |
1100 | Kind = UnqualifiedIdKind::IK_ConstructorName; |
1101 | StartLocation = ClassNameLoc; |
1102 | EndLocation = EndLoc; |
1103 | ConstructorName = ClassType; |
1104 | } |
1105 | |
1106 | |
1107 | |
1108 | |
1109 | |
1110 | |
1111 | |
1112 | void setConstructorTemplateId(TemplateIdAnnotation *TemplateId); |
1113 | |
1114 | |
1115 | |
1116 | |
1117 | |
1118 | |
1119 | |
1120 | void setDestructorName(SourceLocation TildeLoc, |
1121 | ParsedType ClassType, |
1122 | SourceLocation EndLoc) { |
1123 | Kind = UnqualifiedIdKind::IK_DestructorName; |
1124 | StartLocation = TildeLoc; |
1125 | EndLocation = EndLoc; |
1126 | DestructorName = ClassType; |
1127 | } |
1128 | |
1129 | |
1130 | |
1131 | |
1132 | |
1133 | |
1134 | void setTemplateId(TemplateIdAnnotation *TemplateId); |
1135 | |
1136 | |
1137 | |
1138 | |
1139 | |
1140 | |
1141 | void setDeductionGuideName(ParsedTemplateTy Template, |
1142 | SourceLocation TemplateLoc) { |
1143 | Kind = UnqualifiedIdKind::IK_DeductionGuideName; |
1144 | TemplateName = Template; |
1145 | StartLocation = EndLocation = TemplateLoc; |
1146 | } |
1147 | |
1148 | |
1149 | |
1150 | |
1151 | |
1152 | void setImplicitSelfParam(const IdentifierInfo *Id) { |
1153 | Kind = UnqualifiedIdKind::IK_ImplicitSelfParam; |
1154 | Identifier = const_cast<IdentifierInfo *>(Id); |
1155 | StartLocation = EndLocation = SourceLocation(); |
1156 | } |
1157 | |
1158 | |
1159 | SourceRange getSourceRange() const LLVM_READONLY { |
1160 | return SourceRange(StartLocation, EndLocation); |
1161 | } |
1162 | SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; } |
1163 | SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; } |
1164 | }; |
1165 | |
1166 | |
1167 | typedef SmallVector<Token, 4> CachedTokens; |
1168 | |
1169 | |
1170 | |
1171 | |
1172 | |
1173 | struct DeclaratorChunk { |
1174 | DeclaratorChunk() {}; |
1175 | |
1176 | enum { |
1177 | Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe |
1178 | } Kind; |
1179 | |
1180 | |
1181 | SourceLocation Loc; |
1182 | |
1183 | SourceLocation EndLoc; |
1184 | |
1185 | SourceRange getSourceRange() const { |
1186 | if (EndLoc.isInvalid()) |
1187 | return SourceRange(Loc, Loc); |
1188 | return SourceRange(Loc, EndLoc); |
1189 | } |
1190 | |
1191 | ParsedAttributesView AttrList; |
1192 | |
1193 | struct PointerTypeInfo { |
1194 | |
1195 | unsigned TypeQuals : 5; |
1196 | |
1197 | |
1198 | SourceLocation ConstQualLoc; |
1199 | |
1200 | |
1201 | SourceLocation VolatileQualLoc; |
1202 | |
1203 | |
1204 | SourceLocation RestrictQualLoc; |
1205 | |
1206 | |
1207 | SourceLocation AtomicQualLoc; |
1208 | |
1209 | |
1210 | SourceLocation UnalignedQualLoc; |
1211 | |
1212 | void destroy() { |
1213 | } |
1214 | }; |
1215 | |
1216 | struct ReferenceTypeInfo { |
1217 | |
1218 | bool HasRestrict : 1; |
1219 | |
1220 | bool LValueRef : 1; |
1221 | void destroy() { |
1222 | } |
1223 | }; |
1224 | |
1225 | struct ArrayTypeInfo { |
1226 | |
1227 | |
1228 | unsigned TypeQuals : 5; |
1229 | |
1230 | |
1231 | unsigned hasStatic : 1; |
1232 | |
1233 | |
1234 | unsigned isStar : 1; |
1235 | |
1236 | |
1237 | |
1238 | |
1239 | Expr *NumElts; |
1240 | |
1241 | void destroy() {} |
1242 | }; |
1243 | |
1244 | |
1245 | |
1246 | |
1247 | |
1248 | |
1249 | |
1250 | |
1251 | struct ParamInfo { |
1252 | IdentifierInfo *Ident; |
1253 | SourceLocation IdentLoc; |
1254 | Decl *Param; |
1255 | |
1256 | |
1257 | |
1258 | |
1259 | |
1260 | |
1261 | std::unique_ptr<CachedTokens> DefaultArgTokens; |
1262 | |
1263 | ParamInfo() = default; |
1264 | ParamInfo(IdentifierInfo *ident, SourceLocation iloc, |
1265 | Decl *param, |
1266 | std::unique_ptr<CachedTokens> DefArgTokens = nullptr) |
1267 | : Ident(ident), IdentLoc(iloc), Param(param), |
1268 | DefaultArgTokens(std::move(DefArgTokens)) {} |
1269 | }; |
1270 | |
1271 | struct TypeAndRange { |
1272 | ParsedType Ty; |
1273 | SourceRange Range; |
1274 | }; |
1275 | |
1276 | struct FunctionTypeInfo { |
1277 | |
1278 | |
1279 | |
1280 | unsigned hasPrototype : 1; |
1281 | |
1282 | |
1283 | |
1284 | |
1285 | unsigned isVariadic : 1; |
1286 | |
1287 | |
1288 | unsigned isAmbiguous : 1; |
1289 | |
1290 | |
1291 | |
1292 | unsigned RefQualifierIsLValueRef : 1; |
1293 | |
1294 | |
1295 | unsigned ExceptionSpecType : 4; |
1296 | |
1297 | |
1298 | unsigned DeleteParams : 1; |
1299 | |
1300 | |
1301 | |
1302 | unsigned HasTrailingReturnType : 1; |
1303 | |
1304 | |
1305 | SourceLocation LParenLoc; |
1306 | |
1307 | |
1308 | SourceLocation EllipsisLoc; |
1309 | |
1310 | |
1311 | SourceLocation RParenLoc; |
1312 | |
1313 | |
1314 | |
1315 | unsigned NumParams; |
1316 | |
1317 | |
1318 | |
1319 | |
1320 | unsigned NumExceptionsOrDecls; |
1321 | |
1322 | |
1323 | |
1324 | |
1325 | SourceLocation RefQualifierLoc; |
1326 | |
1327 | |
1328 | |
1329 | SourceLocation MutableLoc; |
1330 | |
1331 | |
1332 | SourceLocation ExceptionSpecLocBeg; |
1333 | |
1334 | |
1335 | SourceLocation ExceptionSpecLocEnd; |
1336 | |
1337 | |
1338 | |
1339 | |
1340 | ParamInfo *Params; |
1341 | |
1342 | |
1343 | DeclSpec *MethodQualifiers; |
1344 | |
1345 | |
1346 | AttributeFactory *QualAttrFactory; |
1347 | |
1348 | union { |
1349 | |
1350 | |
1351 | |
1352 | TypeAndRange *Exceptions; |
1353 | |
1354 | |
1355 | |
1356 | Expr *NoexceptExpr; |
1357 | |
1358 | |
1359 | |
1360 | CachedTokens *ExceptionSpecTokens; |
1361 | |
1362 | |
1363 | |
1364 | |
1365 | NamedDecl **DeclsInPrototype; |
1366 | }; |
1367 | |
1368 | |
1369 | |
1370 | UnionParsedType TrailingReturnType; |
1371 | |
1372 | |
1373 | |
1374 | SourceLocation TrailingReturnTypeLoc; |
1375 | |
1376 | |
1377 | |
1378 | |
1379 | void freeParams() { |
1380 | for (unsigned I = 0; I < NumParams; ++I) |
1381 | Params[I].DefaultArgTokens.reset(); |
1382 | if (DeleteParams) { |
1383 | delete[] Params; |
1384 | DeleteParams = false; |
1385 | } |
1386 | NumParams = 0; |
1387 | } |
1388 | |
1389 | void destroy() { |
1390 | freeParams(); |
1391 | delete QualAttrFactory; |
1392 | delete MethodQualifiers; |
1393 | switch (getExceptionSpecType()) { |
1394 | default: |
1395 | break; |
1396 | case EST_Dynamic: |
1397 | delete[] Exceptions; |
1398 | break; |
1399 | case EST_Unparsed: |
1400 | delete ExceptionSpecTokens; |
1401 | break; |
1402 | case EST_None: |
1403 | if (NumExceptionsOrDecls != 0) |
1404 | delete[] DeclsInPrototype; |
1405 | break; |
1406 | } |
1407 | } |
1408 | |
1409 | DeclSpec &getOrCreateMethodQualifiers() { |
1410 | if (!MethodQualifiers) { |
1411 | QualAttrFactory = new AttributeFactory(); |
1412 | MethodQualifiers = new DeclSpec(*QualAttrFactory); |
1413 | } |
1414 | return *MethodQualifiers; |
1415 | } |
1416 | |
1417 | |
1418 | |
1419 | |
1420 | bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; } |
1421 | |
1422 | SourceLocation getLParenLoc() const { return LParenLoc; } |
1423 | |
1424 | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } |
1425 | |
1426 | SourceLocation getRParenLoc() const { return RParenLoc; } |
1427 | |
1428 | SourceLocation getExceptionSpecLocBeg() const { |
1429 | return ExceptionSpecLocBeg; |
1430 | } |
1431 | |
1432 | SourceLocation getExceptionSpecLocEnd() const { |
1433 | return ExceptionSpecLocEnd; |
1434 | } |
1435 | |
1436 | SourceRange getExceptionSpecRange() const { |
1437 | return SourceRange(getExceptionSpecLocBeg(), getExceptionSpecLocEnd()); |
1438 | } |
1439 | |
1440 | |
1441 | SourceLocation getRefQualifierLoc() const { return RefQualifierLoc; } |
1442 | |
1443 | |
1444 | SourceLocation getConstQualifierLoc() const { |
1445 | assert(MethodQualifiers); |
1446 | return MethodQualifiers->getConstSpecLoc(); |
1447 | } |
1448 | |
1449 | |
1450 | SourceLocation getVolatileQualifierLoc() const { |
1451 | assert(MethodQualifiers); |
1452 | return MethodQualifiers->getVolatileSpecLoc(); |
1453 | } |
1454 | |
1455 | |
1456 | SourceLocation getRestrictQualifierLoc() const { |
1457 | assert(MethodQualifiers); |
1458 | return MethodQualifiers->getRestrictSpecLoc(); |
1459 | } |
1460 | |
1461 | |
1462 | SourceLocation getMutableLoc() const { return MutableLoc; } |
1463 | |
1464 | |
1465 | |
1466 | bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); } |
1467 | |
1468 | |
1469 | |
1470 | bool hasMutableQualifier() const { return getMutableLoc().isValid(); } |
1471 | |
1472 | |
1473 | bool hasMethodTypeQualifiers() const { |
1474 | return MethodQualifiers && (MethodQualifiers->getTypeQualifiers() || |
1475 | MethodQualifiers->getAttributes().size()); |
1476 | } |
1477 | |
1478 | |
1479 | ExceptionSpecificationType getExceptionSpecType() const { |
1480 | return static_cast<ExceptionSpecificationType>(ExceptionSpecType); |
1481 | } |
1482 | |
1483 | |
1484 | unsigned getNumExceptions() const { |
1485 | assert(ExceptionSpecType != EST_None); |
1486 | return NumExceptionsOrDecls; |
1487 | } |
1488 | |
1489 | |
1490 | |
1491 | ArrayRef<NamedDecl *> getDeclsInPrototype() const { |
1492 | assert(ExceptionSpecType == EST_None); |
1493 | return llvm::makeArrayRef(DeclsInPrototype, NumExceptionsOrDecls); |
1494 | } |
1495 | |
1496 | |
1497 | |
1498 | bool hasTrailingReturnType() const { return HasTrailingReturnType; } |
1499 | |
1500 | |
1501 | ParsedType getTrailingReturnType() const { |
1502 | assert(HasTrailingReturnType); |
1503 | return TrailingReturnType; |
1504 | } |
1505 | |
1506 | |
1507 | SourceLocation getTrailingReturnTypeLoc() const { |
1508 | assert(HasTrailingReturnType); |
1509 | return TrailingReturnTypeLoc; |
1510 | } |
1511 | }; |
1512 | |
1513 | struct BlockPointerTypeInfo { |
1514 | |
1515 | |
1516 | unsigned TypeQuals : 5; |
1517 | |
1518 | void destroy() { |
1519 | } |
1520 | }; |
1521 | |
1522 | struct MemberPointerTypeInfo { |
1523 | |
1524 | unsigned TypeQuals : 5; |
1525 | |
1526 | SourceLocation StarLoc; |
1527 | |
1528 | |
1529 | alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)]; |
1530 | CXXScopeSpec &Scope() { |
1531 | return *reinterpret_cast<CXXScopeSpec *>(ScopeMem); |
1532 | } |
1533 | const CXXScopeSpec &Scope() const { |
1534 | return *reinterpret_cast<const CXXScopeSpec *>(ScopeMem); |
1535 | } |
1536 | void destroy() { |
1537 | Scope().~CXXScopeSpec(); |
1538 | } |
1539 | }; |
1540 | |
1541 | struct PipeTypeInfo { |
1542 | |
1543 | unsigned AccessWrites : 3; |
1544 | |
1545 | void destroy() {} |
1546 | }; |
1547 | |
1548 | union { |
1549 | PointerTypeInfo Ptr; |
1550 | ReferenceTypeInfo Ref; |
1551 | ArrayTypeInfo Arr; |
1552 | FunctionTypeInfo Fun; |
1553 | BlockPointerTypeInfo Cls; |
1554 | MemberPointerTypeInfo Mem; |
1555 | PipeTypeInfo PipeInfo; |
1556 | }; |
1557 | |
1558 | void destroy() { |
1559 | switch (Kind) { |
1560 | case DeclaratorChunk::Function: return Fun.destroy(); |
1561 | case DeclaratorChunk::Pointer: return Ptr.destroy(); |
1562 | case DeclaratorChunk::BlockPointer: return Cls.destroy(); |
1563 | case DeclaratorChunk::Reference: return Ref.destroy(); |
1564 | case DeclaratorChunk::Array: return Arr.destroy(); |
1565 | case DeclaratorChunk::MemberPointer: return Mem.destroy(); |
1566 | case DeclaratorChunk::Paren: return; |
1567 | case DeclaratorChunk::Pipe: return PipeInfo.destroy(); |
1568 | } |
1569 | } |
1570 | |
1571 | |
1572 | |
1573 | const ParsedAttributesView &getAttrs() const { return AttrList; } |
1574 | ParsedAttributesView &getAttrs() { return AttrList; } |
1575 | |
1576 | |
1577 | static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, |
1578 | SourceLocation ConstQualLoc, |
1579 | SourceLocation VolatileQualLoc, |
1580 | SourceLocation RestrictQualLoc, |
1581 | SourceLocation AtomicQualLoc, |
1582 | SourceLocation UnalignedQualLoc) { |
1583 | DeclaratorChunk I; |
1584 | I.Kind = Pointer; |
1585 | I.Loc = Loc; |
1586 | new (&I.Ptr) PointerTypeInfo; |
1587 | I.Ptr.TypeQuals = TypeQuals; |
1588 | I.Ptr.ConstQualLoc = ConstQualLoc; |
1589 | I.Ptr.VolatileQualLoc = VolatileQualLoc; |
1590 | I.Ptr.RestrictQualLoc = RestrictQualLoc; |
1591 | I.Ptr.AtomicQualLoc = AtomicQualLoc; |
1592 | I.Ptr.UnalignedQualLoc = UnalignedQualLoc; |
1593 | return I; |
1594 | } |
1595 | |
1596 | |
1597 | static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, |
1598 | bool lvalue) { |
1599 | DeclaratorChunk I; |
1600 | I.Kind = Reference; |
1601 | I.Loc = Loc; |
1602 | I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0; |
1603 | I.Ref.LValueRef = lvalue; |
1604 | return I; |
1605 | } |
1606 | |
1607 | |
1608 | static DeclaratorChunk getArray(unsigned TypeQuals, |
1609 | bool isStatic, bool isStar, Expr *NumElts, |
1610 | SourceLocation LBLoc, SourceLocation RBLoc) { |
1611 | DeclaratorChunk I; |
1612 | I.Kind = Array; |
1613 | I.Loc = LBLoc; |
1614 | I.EndLoc = RBLoc; |
1615 | I.Arr.TypeQuals = TypeQuals; |
1616 | I.Arr.hasStatic = isStatic; |
1617 | I.Arr.isStar = isStar; |
1618 | I.Arr.NumElts = NumElts; |
1619 | return I; |
1620 | } |
1621 | |
1622 | |
1623 | |
1624 | static DeclaratorChunk getFunction(bool HasProto, |
1625 | bool IsAmbiguous, |
1626 | SourceLocation LParenLoc, |
1627 | ParamInfo *Params, unsigned NumParams, |
1628 | SourceLocation EllipsisLoc, |
1629 | SourceLocation RParenLoc, |
1630 | bool RefQualifierIsLvalueRef, |
1631 | SourceLocation RefQualifierLoc, |
1632 | SourceLocation MutableLoc, |
1633 | ExceptionSpecificationType ESpecType, |
1634 | SourceRange ESpecRange, |
1635 | ParsedType *Exceptions, |
1636 | SourceRange *ExceptionRanges, |
1637 | unsigned NumExceptions, |
1638 | Expr *NoexceptExpr, |
1639 | CachedTokens *ExceptionSpecTokens, |
1640 | ArrayRef<NamedDecl *> DeclsInPrototype, |
1641 | SourceLocation LocalRangeBegin, |
1642 | SourceLocation LocalRangeEnd, |
1643 | Declarator &TheDeclarator, |
1644 | TypeResult TrailingReturnType = |
1645 | TypeResult(), |
1646 | SourceLocation TrailingReturnTypeLoc = |
1647 | SourceLocation(), |
1648 | DeclSpec *MethodQualifiers = nullptr); |
1649 | |
1650 | |
1651 | static DeclaratorChunk getBlockPointer(unsigned TypeQuals, |
1652 | SourceLocation Loc) { |
1653 | DeclaratorChunk I; |
1654 | I.Kind = BlockPointer; |
1655 | I.Loc = Loc; |
1656 | I.Cls.TypeQuals = TypeQuals; |
1657 | return I; |
1658 | } |
1659 | |
1660 | |
1661 | static DeclaratorChunk getPipe(unsigned TypeQuals, |
1662 | SourceLocation Loc) { |
1663 | DeclaratorChunk I; |
1664 | I.Kind = Pipe; |
1665 | I.Loc = Loc; |
1666 | I.Cls.TypeQuals = TypeQuals; |
1667 | return I; |
1668 | } |
1669 | |
1670 | static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, |
1671 | unsigned TypeQuals, |
1672 | SourceLocation StarLoc, |
1673 | SourceLocation EndLoc) { |
1674 | DeclaratorChunk I; |
1675 | I.Kind = MemberPointer; |
1676 | I.Loc = SS.getBeginLoc(); |
1677 | I.EndLoc = EndLoc; |
1678 | new (&I.Mem) MemberPointerTypeInfo; |
1679 | I.Mem.StarLoc = StarLoc; |
1680 | I.Mem.TypeQuals = TypeQuals; |
1681 | new (I.Mem.ScopeMem) CXXScopeSpec(SS); |
1682 | return I; |
1683 | } |
1684 | |
1685 | |
1686 | static DeclaratorChunk getParen(SourceLocation LParenLoc, |
1687 | SourceLocation RParenLoc) { |
1688 | DeclaratorChunk I; |
1689 | I.Kind = Paren; |
1690 | I.Loc = LParenLoc; |
1691 | I.EndLoc = RParenLoc; |
1692 | return I; |
1693 | } |
1694 | |
1695 | bool isParen() const { |
1696 | return Kind == Paren; |
1697 | } |
1698 | }; |
1699 | |
1700 | |
1701 | |
1702 | class DecompositionDeclarator { |
1703 | public: |
1704 | struct Binding { |
1705 | IdentifierInfo *Name; |
1706 | SourceLocation NameLoc; |
1707 | }; |
1708 | |
1709 | private: |
1710 | |
1711 | SourceLocation LSquareLoc, RSquareLoc; |
1712 | |
1713 | |
1714 | Binding *Bindings; |
1715 | unsigned NumBindings : 31; |
1716 | unsigned DeleteBindings : 1; |
1717 | |
1718 | friend class Declarator; |
1719 | |
1720 | public: |
1721 | DecompositionDeclarator() |
1722 | : Bindings(nullptr), NumBindings(0), DeleteBindings(false) {} |
1723 | DecompositionDeclarator(const DecompositionDeclarator &G) = delete; |
1724 | DecompositionDeclarator &operator=(const DecompositionDeclarator &G) = delete; |
1725 | ~DecompositionDeclarator() { |
1726 | if (DeleteBindings) |
1727 | delete[] Bindings; |
1728 | } |
1729 | |
1730 | void clear() { |
1731 | LSquareLoc = RSquareLoc = SourceLocation(); |
1732 | if (DeleteBindings) |
1733 | delete[] Bindings; |
1734 | Bindings = nullptr; |
1735 | NumBindings = 0; |
1736 | DeleteBindings = false; |
1737 | } |
1738 | |
1739 | ArrayRef<Binding> bindings() const { |
1740 | return llvm::makeArrayRef(Bindings, NumBindings); |
1741 | } |
1742 | |
1743 | bool isSet() const { return LSquareLoc.isValid(); } |
1744 | |
1745 | SourceLocation getLSquareLoc() const { return LSquareLoc; } |
1746 | SourceLocation getRSquareLoc() const { return RSquareLoc; } |
1747 | SourceRange getSourceRange() const { |
1748 | return SourceRange(LSquareLoc, RSquareLoc); |
1749 | } |
1750 | }; |
1751 | |
1752 | |
1753 | |
1754 | enum class FunctionDefinitionKind { |
1755 | Declaration, |
1756 | Definition, |
1757 | Defaulted, |
1758 | Deleted |
1759 | }; |
1760 | |
1761 | enum class DeclaratorContext { |
1762 | File, |
1763 | Prototype, |
1764 | ObjCResult, |
1765 | ObjCParameter, |
1766 | KNRTypeList, |
1767 | TypeName, |
1768 | FunctionalCast, |
1769 | Member, |
1770 | Block, |
1771 | ForInit, |
1772 | SelectionInit, |
1773 | Condition, |
1774 | TemplateParam, |
1775 | CXXNew, |
1776 | CXXCatch, |
1777 | ObjCCatch, |
1778 | BlockLiteral, |
1779 | LambdaExpr, |
1780 | LambdaExprParameter, |
1781 | ConversionId, |
1782 | TrailingReturn, |
1783 | TrailingReturnVar, |
1784 | TemplateArg, |
1785 | TemplateTypeArg, |
1786 | AliasDecl, |
1787 | AliasTemplate, |
1788 | RequiresExpr |
1789 | }; |
1790 | |
1791 | |
1792 | |
1793 | |
1794 | |
1795 | |
1796 | |
1797 | |
1798 | |
1799 | |
1800 | |
1801 | |
1802 | |
1803 | class Declarator { |
1804 | |
1805 | private: |
1806 | const DeclSpec &DS; |
1807 | CXXScopeSpec SS; |
1808 | UnqualifiedId Name; |
1809 | SourceRange Range; |
1810 | |
1811 | |
1812 | DeclaratorContext Context; |
1813 | |
1814 | |
1815 | DecompositionDeclarator BindingGroup; |
1816 | |
1817 | |
1818 | |
1819 | |
1820 | |
1821 | SmallVector<DeclaratorChunk, 8> DeclTypeInfo; |
1822 | |
1823 | |
1824 | unsigned InvalidType : 1; |
1825 | |
1826 | |
1827 | unsigned GroupingParens : 1; |
1828 | |
1829 | |
1830 | |
1831 | |
1832 | |
1833 | unsigned FunctionDefinition : 2; |
1834 | |
1835 | |
1836 | unsigned Redeclaration : 1; |
1837 | |
1838 | |
1839 | unsigned Extension : 1; |
1840 | |
1841 | |
1842 | unsigned ObjCIvar : 1; |
1843 | |
1844 | |
1845 | unsigned ObjCWeakProperty : 1; |
1846 | |
1847 | |
1848 | unsigned InlineStorageUsed : 1; |
1849 | |
1850 | |
1851 | unsigned HasInitializer : 1; |
1852 | |
1853 | |
1854 | ParsedAttributes Attrs; |
1855 | |
1856 | |
1857 | Expr *AsmLabel; |
1858 | |
1859 | |
1860 | |
1861 | Expr *TrailingRequiresClause; |
1862 | |
1863 | |
1864 | ArrayRef<TemplateParameterList *> TemplateParameterLists; |
1865 | |
1866 | |
1867 | |
1868 | |
1869 | TemplateParameterList *InventedTemplateParameterList; |
1870 | |
1871 | #ifndef _MSC_VER |
1872 | union { |
1873 | #endif |
1874 | |
1875 | |
1876 | |
1877 | DeclaratorChunk::ParamInfo InlineParams[16]; |
1878 | DecompositionDeclarator::Binding InlineBindings[16]; |
1879 | #ifndef _MSC_VER |
1880 | }; |
1881 | #endif |
1882 | |
1883 | |
1884 | |
1885 | SourceLocation CommaLoc; |
1886 | |
1887 | |
1888 | |
1889 | SourceLocation EllipsisLoc; |
1890 | |
1891 | friend struct DeclaratorChunk; |
1892 | |
1893 | public: |
1894 | Declarator(const DeclSpec &ds, DeclaratorContext C) |
1895 | : DS(ds), Range(ds.getSourceRange()), Context(C), |
1896 | InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), |
1897 | GroupingParens(false), FunctionDefinition(static_cast<unsigned>( |
1898 | FunctionDefinitionKind::Declaration)), |
1899 | Redeclaration(false), Extension(false), ObjCIvar(false), |
1900 | ObjCWeakProperty(false), InlineStorageUsed(false), |
1901 | HasInitializer(false), Attrs(ds.getAttributePool().getFactory()), |
1902 | AsmLabel(nullptr), TrailingRequiresClause(nullptr), |
1903 | InventedTemplateParameterList(nullptr) {} |
1904 | |
1905 | ~Declarator() { |
1906 | clear(); |
1907 | } |
1908 | |
1909 | |
1910 | const DeclSpec &getDeclSpec() const { return DS; } |
1911 | |
1912 | |
1913 | |
1914 | |
1915 | |
1916 | |
1917 | DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); } |
1918 | |
1919 | AttributePool &getAttributePool() const { |
1920 | return Attrs.getPool(); |
1921 | } |
1922 | |
1923 | |
1924 | |
1925 | const CXXScopeSpec &getCXXScopeSpec() const { return SS; } |
1926 | CXXScopeSpec &getCXXScopeSpec() { return SS; } |
1927 | |
1928 | |
1929 | UnqualifiedId &getName() { return Name; } |
1930 | |
1931 | const DecompositionDeclarator &getDecompositionDeclarator() const { |
1932 | return BindingGroup; |
1933 | } |
1934 | |
1935 | DeclaratorContext getContext() const { return Context; } |
1936 | |
1937 | bool isPrototypeContext() const { |
1938 | return (Context == DeclaratorContext::Prototype || |
1939 | Context == DeclaratorContext::ObjCParameter || |
1940 | Context == DeclaratorContext::ObjCResult || |
1941 | Context == DeclaratorContext::LambdaExprParameter); |
1942 | } |
1943 | |
1944 | |
1945 | SourceRange getSourceRange() const LLVM_READONLY { return Range; } |
1946 | SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } |
1947 | SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } |
1948 | |
1949 | void SetSourceRange(SourceRange R) { Range = R; } |
1950 | |
1951 | |
1952 | void SetRangeBegin(SourceLocation Loc) { |
1953 | if (!Loc.isInvalid()) |
1954 | Range.setBegin(Loc); |
1955 | } |
1956 | |
1957 | void SetRangeEnd(SourceLocation Loc) { |
1958 | if (!Loc.isInvalid()) |
1959 | Range.setEnd(Loc); |
1960 | } |
1961 | |
1962 | |
1963 | |
1964 | void ExtendWithDeclSpec(const DeclSpec &DS) { |
1965 | SourceRange SR = DS.getSourceRange(); |
1966 | if (Range.getBegin().isInvalid()) |
1967 | Range.setBegin(SR.getBegin()); |
1968 | if (!SR.getEnd().isInvalid()) |
1969 | Range.setEnd(SR.getEnd()); |
1970 | } |
1971 | |
1972 | |
1973 | void clear() { |
1974 | SS.clear(); |
1975 | Name.clear(); |
1976 | Range = DS.getSourceRange(); |
1977 | BindingGroup.clear(); |
1978 | |
1979 | for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i) |
1980 | DeclTypeInfo[i].destroy(); |
1981 | DeclTypeInfo.clear(); |
1982 | Attrs.clear(); |
1983 | AsmLabel = nullptr; |
1984 | InlineStorageUsed = false; |
1985 | HasInitializer = false; |
1986 | ObjCIvar = false; |
1987 | ObjCWeakProperty = false; |
1988 | CommaLoc = SourceLocation(); |
1989 | EllipsisLoc = SourceLocation(); |
1990 | } |
1991 | |
1992 | |
1993 | |
1994 | |
1995 | bool mayOmitIdentifier() const { |
1996 | switch (Context) { |
1997 | case DeclaratorContext::File: |
1998 | case DeclaratorContext::KNRTypeList: |
1999 | case DeclaratorContext::Member: |
2000 | case DeclaratorContext::Block: |
2001 | case DeclaratorContext::ForInit: |
2002 | case DeclaratorContext::SelectionInit: |
2003 | case DeclaratorContext::Condition: |
2004 | return false; |
2005 | |
2006 | case DeclaratorContext::TypeName: |
2007 | case DeclaratorContext::FunctionalCast: |
2008 | case DeclaratorContext::AliasDecl: |
2009 | case DeclaratorContext::AliasTemplate: |
2010 | case DeclaratorContext::Prototype: |
2011 | case DeclaratorContext::LambdaExprParameter: |
2012 | case DeclaratorContext::ObjCParameter: |
2013 | case DeclaratorContext::ObjCResult: |
2014 | case DeclaratorContext::TemplateParam: |
2015 | case DeclaratorContext::CXXNew: |
2016 | case DeclaratorContext::CXXCatch: |
2017 | case DeclaratorContext::ObjCCatch: |
2018 | case DeclaratorContext::BlockLiteral: |
2019 | case DeclaratorContext::LambdaExpr: |
2020 | case DeclaratorContext::ConversionId: |
2021 | case DeclaratorContext::TemplateArg: |
2022 | case DeclaratorContext::TemplateTypeArg: |
2023 | case DeclaratorContext::TrailingReturn: |
2024 | case DeclaratorContext::TrailingReturnVar: |
2025 | case DeclaratorContext::RequiresExpr: |
2026 | return true; |
2027 | } |
2028 | llvm_unreachable("unknown context kind!"); |
2029 | } |
2030 | |
2031 | |
2032 | |
2033 | |
2034 | bool mayHaveIdentifier() const { |
2035 | switch (Context) { |
2036 | case DeclaratorContext::File: |
2037 | case DeclaratorContext::KNRTypeList: |
2038 | case DeclaratorContext::Member: |
2039 | case DeclaratorContext::Block: |
2040 | case DeclaratorContext::ForInit: |
2041 | case DeclaratorContext::SelectionInit: |
2042 | case DeclaratorContext::Condition: |
2043 | case DeclaratorContext::Prototype: |
2044 | case DeclaratorContext::LambdaExprParameter: |
2045 | case DeclaratorContext::TemplateParam: |
2046 | case DeclaratorContext::CXXCatch: |
2047 | case DeclaratorContext::ObjCCatch: |
2048 | case DeclaratorContext::RequiresExpr: |
2049 | return true; |
2050 | |
2051 | case DeclaratorContext::TypeName: |
2052 | case DeclaratorContext::FunctionalCast: |
2053 | case DeclaratorContext::CXXNew: |
2054 | case DeclaratorContext::AliasDecl: |
2055 | case DeclaratorContext::AliasTemplate: |
2056 | case DeclaratorContext::ObjCParameter: |
2057 | case DeclaratorContext::ObjCResult: |
2058 | case DeclaratorContext::BlockLiteral: |
2059 | case DeclaratorContext::LambdaExpr: |
2060 | case DeclaratorContext::ConversionId: |
2061 | case DeclaratorContext::TemplateArg: |
2062 | case DeclaratorContext::TemplateTypeArg: |
2063 | case DeclaratorContext::TrailingReturn: |
2064 | case DeclaratorContext::TrailingReturnVar: |
2065 | return false; |
2066 | } |
2067 | llvm_unreachable("unknown context kind!"); |
2068 | } |
2069 | |
2070 | |
2071 | bool mayHaveDecompositionDeclarator() const { |
2072 | switch (Context) { |
2073 | case DeclaratorContext::File: |
2074 | |
2075 | |
2076 | case DeclaratorContext::Block: |
2077 | case DeclaratorContext::ForInit: |
2078 | case DeclaratorContext::SelectionInit: |
2079 | case DeclaratorContext::Condition: |
2080 | return true; |
2081 | |
2082 | case DeclaratorContext::Member: |
2083 | case DeclaratorContext::Prototype: |
2084 | case DeclaratorContext::TemplateParam: |
2085 | case DeclaratorContext::RequiresExpr: |
2086 | |
2087 | return false; |
2088 | |
2089 | |
2090 | case DeclaratorContext::KNRTypeList: |
2091 | case DeclaratorContext::TypeName: |
2092 | case DeclaratorContext::FunctionalCast: |
2093 | case DeclaratorContext::AliasDecl: |
2094 | case DeclaratorContext::AliasTemplate: |
2095 | case DeclaratorContext::LambdaExprParameter: |
2096 | case DeclaratorContext::ObjCParameter: |
2097 | case DeclaratorContext::ObjCResult: |
2098 | case DeclaratorContext::CXXNew: |
2099 | case DeclaratorContext::CXXCatch: |
2100 | case DeclaratorContext::ObjCCatch: |
2101 | case DeclaratorContext::BlockLiteral: |
2102 | case DeclaratorContext::LambdaExpr: |
2103 | case DeclaratorContext::ConversionId: |
2104 | case DeclaratorContext::TemplateArg: |
2105 | case DeclaratorContext::TemplateTypeArg: |
2106 | case DeclaratorContext::TrailingReturn: |
2107 | case DeclaratorContext::TrailingReturnVar: |
2108 | return false; |
2109 | } |
2110 | llvm_unreachable("unknown context kind!"); |
2111 | } |
2112 | |
2113 | |
2114 | |
2115 | bool mayBeFollowedByCXXDirectInit() const { |
2116 | if (hasGroupingParens()) return false; |
2117 | |
2118 | if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) |
2119 | return false; |
2120 | |
2121 | if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern && |
2122 | Context != DeclaratorContext::File) |
2123 | return false; |
2124 | |
2125 | |
2126 | if (Name.getKind() != UnqualifiedIdKind::IK_Identifier) |
2127 | return false; |
2128 | |
2129 | switch (Context) { |
2130 | case DeclaratorContext::File: |
2131 | case DeclaratorContext::Block: |
2132 | case DeclaratorContext::ForInit: |
2133 | case DeclaratorContext::SelectionInit: |
2134 | case DeclaratorContext::TrailingReturnVar: |
2135 | return true; |
2136 | |
2137 | case DeclaratorContext::Condition: |
2138 | |
2139 | |
2140 | |
2141 | return true; |
2142 | |
2143 | case DeclaratorContext::KNRTypeList: |
2144 | case DeclaratorContext::Member: |
2145 | case DeclaratorContext::Prototype: |
2146 | case DeclaratorContext::LambdaExprParameter: |
2147 | case DeclaratorContext::ObjCParameter: |
2148 | case DeclaratorContext::ObjCResult: |
2149 | case DeclaratorContext::TemplateParam: |
2150 | case DeclaratorContext::CXXCatch: |
2151 | case DeclaratorContext::ObjCCatch: |
2152 | case DeclaratorContext::TypeName: |
2153 | case DeclaratorContext::FunctionalCast: |
2154 | case DeclaratorContext::CXXNew: |
2155 | case DeclaratorContext::AliasDecl: |
2156 | case DeclaratorContext::AliasTemplate: |
2157 | case DeclaratorContext::BlockLiteral: |
2158 | case DeclaratorContext::LambdaExpr: |
2159 | case DeclaratorContext::ConversionId: |
2160 | case DeclaratorContext::TemplateArg: |
2161 | case DeclaratorContext::TemplateTypeArg: |
2162 | case DeclaratorContext::TrailingReturn: |
2163 | case DeclaratorContext::RequiresExpr: |
2164 | return false; |
2165 | } |
2166 | llvm_unreachable("unknown context kind!"); |
2167 | } |
2168 | |
2169 | |
2170 | |
2171 | |
2172 | bool isPastIdentifier() const { return Name.isValid(); } |
2173 | |
2174 | |
2175 | |
2176 | |
2177 | |
2178 | bool hasName() const { |
2179 | return Name.getKind() != UnqualifiedIdKind::IK_Identifier || |
2180 | Name.Identifier || isDecompositionDeclarator(); |
2181 | } |
2182 | |
2183 | |
2184 | bool isDecompositionDeclarator() const { |
2185 | return BindingGroup.isSet(); |
2186 | } |
2187 | |
2188 | IdentifierInfo *getIdentifier() const { |
2189 | if (Name.getKind() == UnqualifiedIdKind::IK_Identifier) |
2190 | return Name.Identifier; |
2191 | |
2192 | return nullptr; |
2193 | } |
2194 | SourceLocation getIdentifierLoc() const { return Name.StartLocation; } |
2195 | |
2196 | |
2197 | void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) { |
2198 | Name.setIdentifier(Id, IdLoc); |
2199 | } |
2200 | |
2201 | |
2202 | void |
2203 | setDecompositionBindings(SourceLocation LSquareLoc, |
2204 | ArrayRef<DecompositionDeclarator::Binding> Bindings, |
2205 | SourceLocation RSquareLoc); |
2206 | |
2207 | |
2208 | |
2209 | |
2210 | |
2211 | void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, |
2212 | SourceLocation EndLoc) { |
2213 | DeclTypeInfo.push_back(TI); |
2214 | DeclTypeInfo.back().getAttrs().addAll(attrs.begin(), attrs.end()); |
2215 | getAttributePool().takeAllFrom(attrs.getPool()); |
2216 | |
2217 | if (!EndLoc.isInvalid()) |
2218 | SetRangeEnd(EndLoc); |
2219 | } |
2220 | |
2221 | |
2222 | |
2223 | void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) { |
2224 | DeclTypeInfo.push_back(TI); |
2225 | |
2226 | if (!EndLoc.isInvalid()) |
2227 | SetRangeEnd(EndLoc); |
2228 | } |
2229 | |
2230 | |
2231 | void AddInnermostTypeInfo(const DeclaratorChunk &TI) { |
2232 | DeclTypeInfo.insert(DeclTypeInfo.begin(), TI); |
2233 | } |
2234 | |
2235 | |
2236 | unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); } |
2237 | |
2238 | |
2239 | |
2240 | const DeclaratorChunk &getTypeObject(unsigned i) const { |
2241 | assert(i < DeclTypeInfo.size() && "Invalid type chunk"); |
2242 | return DeclTypeInfo[i]; |
2243 | } |
2244 | DeclaratorChunk &getTypeObject(unsigned i) { |
2245 | assert(i < DeclTypeInfo.size() && "Invalid type chunk"); |
2246 | return DeclTypeInfo[i]; |
2247 | } |
2248 | |
2249 | typedef SmallVectorImpl<DeclaratorChunk>::const_iterator type_object_iterator; |
2250 | typedef llvm::iterator_range<type_object_iterator> type_object_range; |
2251 | |
2252 | |
2253 | type_object_range type_objects() const { |
2254 | return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end()); |
2255 | } |
2256 | |
2257 | void DropFirstTypeObject() { |
2258 | assert(!DeclTypeInfo.empty() && "No type chunks to drop."); |
2259 | DeclTypeInfo.front().destroy(); |
2260 | DeclTypeInfo.erase(DeclTypeInfo.begin()); |
2261 | } |
2262 | |
2263 | |
2264 | |
2265 | |
2266 | const DeclaratorChunk *getInnermostNonParenChunk() const { |
2267 | for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { |
2268 | if (!DeclTypeInfo[i].isParen()) |
2269 | return &DeclTypeInfo[i]; |
2270 | } |
2271 | return nullptr; |
2272 | } |
2273 | |
2274 | |
2275 | |
2276 | |
2277 | const DeclaratorChunk *getOutermostNonParenChunk() const { |
2278 | for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) { |
2279 | if (!DeclTypeInfo[i-1].isParen()) |
2280 | return &DeclTypeInfo[i-1]; |
2281 | } |
2282 | return nullptr; |
2283 | } |
2284 | |
2285 | |
2286 | |
2287 | |
2288 | bool isArrayOfUnknownBound() const { |
2289 | const DeclaratorChunk *chunk = getInnermostNonParenChunk(); |
2290 | return (chunk && chunk->Kind == DeclaratorChunk::Array && |
2291 | !chunk->Arr.NumElts); |
2292 | } |
2293 | |
2294 | |
2295 | |
2296 | |
2297 | |
2298 | bool isFunctionDeclarator(unsigned& idx) const { |
2299 | for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { |
2300 | switch (DeclTypeInfo[i].Kind) { |
2301 | case DeclaratorChunk::Function: |
2302 | idx = i; |
2303 | return true; |
2304 | case DeclaratorChunk::Paren: |
2305 | continue; |
2306 | case DeclaratorChunk::Pointer: |
2307 | case DeclaratorChunk::Reference: |
2308 | case DeclaratorChunk::Array: |
2309 | case DeclaratorChunk::BlockPointer: |
2310 | case DeclaratorChunk::MemberPointer: |
2311 | case DeclaratorChunk::Pipe: |
2312 | return false; |
2313 | } |
2314 | llvm_unreachable("Invalid type chunk"); |
2315 | } |
2316 | return false; |
2317 | } |
2318 | |
2319 | |
2320 | |
2321 | |
2322 | bool isFunctionDeclarator() const { |
2323 | unsigned index; |
2324 | return isFunctionDeclarator(index); |
2325 | } |
2326 | |
2327 | |
2328 | |
2329 | DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() { |
2330 | assert(isFunctionDeclarator() && "Not a function declarator!"); |
2331 | unsigned index = 0; |
2332 | isFunctionDeclarator(index); |
2333 | return DeclTypeInfo[index].Fun; |
2334 | } |
2335 | |
2336 | |
2337 | |
2338 | const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const { |
2339 | return const_cast<Declarator*>(this)->getFunctionTypeInfo(); |
2340 | } |
2341 | |
2342 | |
2343 | |
2344 | |
2345 | |
2346 | |
2347 | |
2348 | bool isDeclarationOfFunction() const; |
2349 | |
2350 | |
2351 | |
2352 | bool isFunctionDeclarationContext() const { |
2353 | if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) |
2354 | return false; |
2355 | |
2356 | switch (Context) { |
2357 | case DeclaratorContext::File: |
2358 | case DeclaratorContext::Member: |
2359 | case DeclaratorContext::Block: |
2360 | case DeclaratorContext::ForInit: |
2361 | case DeclaratorContext::SelectionInit: |
2362 | return true; |
2363 | |
2364 | case DeclaratorContext::Condition: |
2365 | case DeclaratorContext::KNRTypeList: |
2366 | case DeclaratorContext::TypeName: |
2367 | case DeclaratorContext::FunctionalCast: |
2368 | case DeclaratorContext::AliasDecl: |
2369 | case DeclaratorContext::AliasTemplate: |
2370 | case DeclaratorContext::Prototype: |
2371 | case DeclaratorContext::LambdaExprParameter: |
2372 | case DeclaratorContext::ObjCParameter: |
2373 | case DeclaratorContext::ObjCResult: |
2374 | case DeclaratorContext::TemplateParam: |
2375 | case DeclaratorContext::CXXNew: |
2376 | case DeclaratorContext::CXXCatch: |
2377 | case DeclaratorContext::ObjCCatch: |
2378 | case DeclaratorContext::BlockLiteral: |
2379 | case DeclaratorContext::LambdaExpr: |
2380 | case DeclaratorContext::ConversionId: |
2381 | case DeclaratorContext::TemplateArg: |
2382 | case DeclaratorContext::TemplateTypeArg: |
2383 | case DeclaratorContext::TrailingReturn: |
2384 | case DeclaratorContext::TrailingReturnVar: |
2385 | case DeclaratorContext::RequiresExpr: |
2386 | return false; |
2387 | } |
2388 | llvm_unreachable("unknown context kind!"); |
2389 | } |
2390 | |
2391 | |
2392 | |
2393 | bool isExpressionContext() const { |
2394 | switch (Context) { |
2395 | case DeclaratorContext::File: |
2396 | case DeclaratorContext::KNRTypeList: |
2397 | case DeclaratorContext::Member: |
2398 | |
2399 | |
2400 | case DeclaratorContext::TypeName: |
2401 | |
2402 | case DeclaratorContext::FunctionalCast: |
2403 | case DeclaratorContext::AliasDecl: |
2404 | case DeclaratorContext::AliasTemplate: |
2405 | case DeclaratorContext::Prototype: |
2406 | case DeclaratorContext::LambdaExprParameter: |
2407 | case DeclaratorContext::ObjCParameter: |
2408 | case DeclaratorContext::ObjCResult: |
2409 | case DeclaratorContext::TemplateParam: |
2410 | case DeclaratorContext::CXXNew: |
2411 | case DeclaratorContext::CXXCatch: |
2412 | case DeclaratorContext::ObjCCatch: |
2413 | case DeclaratorContext::BlockLiteral: |
2414 | case DeclaratorContext::LambdaExpr: |
2415 | case DeclaratorContext::ConversionId: |
2416 | case DeclaratorContext::TrailingReturn: |
2417 | case DeclaratorContext::TrailingReturnVar: |
2418 | case DeclaratorContext::TemplateTypeArg: |
2419 | case DeclaratorContext::RequiresExpr: |
2420 | return false; |
2421 | |
2422 | case DeclaratorContext::Block: |
2423 | case DeclaratorContext::ForInit: |
2424 | case DeclaratorContext::SelectionInit: |
2425 | case DeclaratorContext::Condition: |
2426 | case DeclaratorContext::TemplateArg: |
2427 | return true; |
2428 | } |
2429 | |
2430 | llvm_unreachable("unknown context kind!"); |
2431 | } |
2432 | |
2433 | |
2434 | |
2435 | bool isFunctionDeclaratorAFunctionDeclaration() const { |
2436 | if (!isFunctionDeclarationContext()) |
2437 | return false; |
2438 | |
2439 | for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I) |
2440 | if (getTypeObject(I).Kind != DeclaratorChunk::Paren) |
2441 | return false; |
2442 | |
2443 | return true; |
2444 | } |
2445 | |
2446 | |
2447 | |
2448 | bool hasTrailingReturnType() const { |
2449 | for (const auto &Chunk : type_objects()) |
2450 | if (Chunk.Kind == DeclaratorChunk::Function && |
2451 | Chunk.Fun.hasTrailingReturnType()) |
2452 | return true; |
2453 | return false; |
2454 | } |
2455 | |
2456 | |
2457 | ParsedType getTrailingReturnType() const { |
2458 | for (const auto &Chunk : type_objects()) |
2459 | if (Chunk.Kind == DeclaratorChunk::Function && |
2460 | Chunk.Fun.hasTrailingReturnType()) |
2461 | return Chunk.Fun.getTrailingReturnType(); |
2462 | return ParsedType(); |
2463 | } |
2464 | |
2465 | |
2466 | void setTrailingRequiresClause(Expr *TRC) { |
2467 | TrailingRequiresClause = TRC; |
2468 | |
2469 | SetRangeEnd(TRC->getEndLoc()); |
2470 | } |
2471 | |
2472 | |
2473 | Expr *getTrailingRequiresClause() { |
2474 | return TrailingRequiresClause; |
2475 | } |
2476 | |
2477 | |
2478 | |
2479 | bool hasTrailingRequiresClause() const { |
2480 | return TrailingRequiresClause != nullptr; |
2481 | } |
2482 | |
2483 | |
2484 | void setTemplateParameterLists(ArrayRef<TemplateParameterList *> TPLs) { |
2485 | TemplateParameterLists = TPLs; |
2486 | } |
2487 | |
2488 | |
2489 | ArrayRef<TemplateParameterList *> getTemplateParameterLists() const { |
2490 | return TemplateParameterLists; |
2491 | } |
2492 | |
2493 | |
2494 | |
2495 | |
2496 | void setInventedTemplateParameterList(TemplateParameterList *Invented) { |
2497 | InventedTemplateParameterList = Invented; |
2498 | } |
2499 | |
2500 | |
2501 | |
2502 | |
2503 | TemplateParameterList * getInventedTemplateParameterList() const { |
2504 | return InventedTemplateParameterList; |
2505 | } |
2506 | |
2507 | |
2508 | |
2509 | |
2510 | |
2511 | |
2512 | |
2513 | |
2514 | |
2515 | |
2516 | void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) { |
2517 | Attrs.takeAllFrom(attrs); |
2518 | |
2519 | if (!lastLoc.isInvalid()) |
2520 | SetRangeEnd(lastLoc); |
2521 | } |
2522 | |
2523 | const ParsedAttributes &getAttributes() const { return Attrs; } |
2524 | ParsedAttributes &getAttributes() { return Attrs; } |
2525 | |
2526 | |
2527 | bool hasAttributes() const { |
2528 | if (!getAttributes().empty() || getDeclSpec().hasAttributes()) |
2529 | return true; |
2530 | for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i) |
2531 | if (!getTypeObject(i).getAttrs().empty()) |
2532 | return true; |
2533 | return false; |
2534 | } |
2535 | |
2536 | |
2537 | |
2538 | void getCXX11AttributeRanges(SmallVectorImpl<SourceRange> &Ranges) { |
2539 | for (const ParsedAttr &AL : Attrs) |
2540 | if (AL.isCXX11Attribute()) |
2541 | Ranges.push_back(AL.getRange()); |
2542 | } |
2543 | |
2544 | void setAsmLabel(Expr *E) { AsmLabel = E; } |
2545 | Expr *getAsmLabel() const { return AsmLabel; } |
2546 | |
2547 | void setExtension(bool Val = true) { Extension = Val; } |
2548 | bool getExtension() const { return Extension; } |
2549 | |
2550 | void setObjCIvar(bool Val = true) { ObjCIvar = Val; } |
2551 | bool isObjCIvar() const { return ObjCIvar; } |
2552 | |
2553 | void setObjCWeakProperty(bool Val = true) { ObjCWeakProperty = Val; } |
2554 | bool isObjCWeakProperty() const { return ObjCWeakProperty; } |
2555 | |
2556 | void setInvalidType(bool Val = true) { InvalidType = Val; } |
2557 | bool isInvalidType() const { |
2558 | return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error; |
2559 | } |
2560 | |
2561 | void setGroupingParens(bool flag) { GroupingParens = flag; } |
2562 | bool hasGroupingParens() const { return GroupingParens; } |
2563 | |
2564 | bool isFirstDeclarator() const { return !CommaLoc.isValid(); } |
2565 | SourceLocation getCommaLoc() const { return CommaLoc; } |
2566 | void setCommaLoc(SourceLocation CL) { CommaLoc = CL; } |
2567 | |
2568 | bool hasEllipsis() const { return EllipsisLoc.isValid(); } |
2569 | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } |
2570 | void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } |
2571 | |
2572 | void setFunctionDefinitionKind(FunctionDefinitionKind Val) { |
2573 | FunctionDefinition = static_cast<unsigned>(Val); |
2574 | } |
2575 | |
2576 | bool isFunctionDefinition() const { |
2577 | return getFunctionDefinitionKind() != FunctionDefinitionKind::Declaration; |
2578 | } |
2579 | |
2580 | FunctionDefinitionKind getFunctionDefinitionKind() const { |
2581 | return (FunctionDefinitionKind)FunctionDefinition; |
2582 | } |
2583 | |
2584 | void setHasInitializer(bool Val = true) { HasInitializer = Val; } |
2585 | bool hasInitializer() const { return HasInitializer; } |
2586 | |
2587 | |
2588 | bool isFirstDeclarationOfMember() { |
2589 | return getContext() == DeclaratorContext::Member && |
2590 | !getDeclSpec().isFriendSpecified(); |
2591 | } |
2592 | |
2593 | |
2594 | |
2595 | |
2596 | bool isStaticMember(); |
2597 | |
2598 | |
2599 | bool isCtorOrDtor(); |
2600 | |
2601 | void setRedeclaration(bool Val) { Redeclaration = Val; } |
2602 | bool isRedeclaration() const { return Redeclaration; } |
2603 | }; |
2604 | |
2605 | |
2606 | |
2607 | struct FieldDeclarator { |
2608 | Declarator D; |
2609 | Expr *BitfieldSize; |
2610 | explicit FieldDeclarator(const DeclSpec &DS) |
2611 | : D(DS, DeclaratorContext::Member), BitfieldSize(nullptr) {} |
2612 | }; |
2613 | |
2614 | |
2615 | class VirtSpecifiers { |
2616 | public: |
2617 | enum Specifier { |
2618 | VS_None = 0, |
2619 | VS_Override = 1, |
2620 | VS_Final = 2, |
2621 | VS_Sealed = 4, |
2622 | |
2623 | VS_GNU_Final = 8, |
2624 | VS_Abstract = 16 |
2625 | }; |
2626 | |
2627 | VirtSpecifiers() : Specifiers(0), LastSpecifier(VS_None) { } |
2628 | |
2629 | bool SetSpecifier(Specifier VS, SourceLocation Loc, |
2630 | const char *&PrevSpec); |
2631 | |
2632 | bool isUnset() const { return Specifiers == 0; } |
2633 | |
2634 | bool isOverrideSpecified() const { return Specifiers & VS_Override; } |
2635 | SourceLocation getOverrideLoc() const { return VS_overrideLoc; } |
2636 | |
2637 | bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed | VS_GNU_Final); } |
2638 | bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; } |
2639 | SourceLocation getFinalLoc() const { return VS_finalLoc; } |
2640 | SourceLocation getAbstractLoc() const { return VS_abstractLoc; } |
2641 | |
2642 | void clear() { Specifiers = 0; } |
2643 | |
2644 | static const char *getSpecifierName(Specifier VS); |
2645 | |
2646 | SourceLocation getFirstLocation() const { return FirstLocation; } |
2647 | SourceLocation getLastLocation() const { return LastLocation; } |
2648 | Specifier getLastSpecifier() const { return LastSpecifier; } |
2649 | |
2650 | private: |
2651 | unsigned Specifiers; |
2652 | Specifier LastSpecifier; |
2653 | |
2654 | SourceLocation VS_overrideLoc, VS_finalLoc, VS_abstractLoc; |
2655 | SourceLocation FirstLocation; |
2656 | SourceLocation LastLocation; |
2657 | }; |
2658 | |
2659 | enum class LambdaCaptureInitKind { |
2660 | NoInit, |
2661 | CopyInit, |
2662 | DirectInit, |
2663 | ListInit |
2664 | }; |
2665 | |
2666 | |
2667 | struct LambdaIntroducer { |
2668 | |
2669 | struct LambdaCapture { |
2670 | LambdaCaptureKind Kind; |
2671 | SourceLocation Loc; |
2672 | IdentifierInfo *Id; |
2673 | SourceLocation EllipsisLoc; |
2674 | LambdaCaptureInitKind InitKind; |
2675 | ExprResult Init; |
2676 | ParsedType InitCaptureType; |
2677 | SourceRange ExplicitRange; |
2678 | |
2679 | LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc, |
2680 | IdentifierInfo *Id, SourceLocation EllipsisLoc, |
2681 | LambdaCaptureInitKind InitKind, ExprResult Init, |
2682 | ParsedType InitCaptureType, |
2683 | SourceRange ExplicitRange) |
2684 | : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc), |
2685 | InitKind(InitKind), Init(Init), InitCaptureType(InitCaptureType), |
2686 | ExplicitRange(ExplicitRange) {} |
2687 | }; |
2688 | |
2689 | SourceRange Range; |
2690 | SourceLocation DefaultLoc; |
2691 | LambdaCaptureDefault Default; |
2692 | SmallVector<LambdaCapture, 4> Captures; |
2693 | |
2694 | LambdaIntroducer() |
2695 | : Default(LCD_None) {} |
2696 | |
2697 | |
2698 | void addCapture(LambdaCaptureKind Kind, |
2699 | SourceLocation Loc, |
2700 | IdentifierInfo* Id, |
2701 | SourceLocation EllipsisLoc, |
2702 | LambdaCaptureInitKind InitKind, |
2703 | ExprResult Init, |
2704 | ParsedType InitCaptureType, |
2705 | SourceRange ExplicitRange) { |
2706 | Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init, |
2707 | InitCaptureType, ExplicitRange)); |
2708 | } |
2709 | }; |
2710 | |
2711 | struct InventedTemplateParameterInfo { |
2712 | |
2713 | |
2714 | |
2715 | unsigned NumExplicitTemplateParams = 0; |
2716 | |
2717 | |
2718 | |
2719 | unsigned AutoTemplateParameterDepth = 0; |
2720 | |
2721 | |
2722 | |
2723 | |
2724 | |
2725 | |
2726 | |
2727 | |
2728 | SmallVector<NamedDecl*, 4> TemplateParams; |
2729 | }; |
2730 | |
2731 | } |
2732 | |
2733 | #endif // LLVM_CLANG_SEMA_DECLSPEC_H |