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