1 //===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// 9 /// \file 10 /// This file defines the classes used to store parsed information about 11 /// declaration-specifiers and declarators. 12 /// 13 /// \verbatim 14 /// static const int volatile x, *y, *(*(*z)[10])(const void *x); 15 /// ------------------------- - -- --------------------------- 16 /// declaration-specifiers \ | / 17 /// declarators 18 /// \endverbatim 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/STLExtras.h" 36 #include "llvm/ADT/SmallVector.h" 37 #include "llvm/Support/Compiler.h" 38 #include "llvm/Support/ErrorHandling.h" 39 #include <optional> 40 41 namespace clang { 42 class ASTContext; 43 class CXXRecordDecl; 44 class TypeLoc; 45 class LangOptions; 46 class IdentifierInfo; 47 class NamespaceAliasDecl; 48 class NamespaceDecl; 49 class ObjCDeclSpec; 50 class Sema; 51 class Declarator; 52 struct TemplateIdAnnotation; 53 54 /// Represents a C++ nested-name-specifier or a global scope specifier. 55 /// 56 /// These can be in 3 states: 57 /// 1) Not present, identified by isEmpty() 58 /// 2) Present, identified by isNotEmpty() 59 /// 2.a) Valid, identified by isValid() 60 /// 2.b) Invalid, identified by isInvalid(). 61 /// 62 /// isSet() is deprecated because it mostly corresponded to "valid" but was 63 /// often used as if it meant "present". 64 /// 65 /// The actual scope is described by getScopeRep(). 66 /// 67 /// If the kind of getScopeRep() is TypeSpec then TemplateParamLists may be empty 68 /// or contain the template parameter lists attached to the current declaration. 69 /// Consider the following example: 70 /// template <class T> void SomeType<T>::some_method() {} 71 /// If CXXScopeSpec refers to SomeType<T> then TemplateParamLists will contain 72 /// a single element referring to template <class T>. 73 74 class CXXScopeSpec { 75 SourceRange Range; 76 NestedNameSpecifierLocBuilder Builder; 77 ArrayRef<TemplateParameterList *> TemplateParamLists; 78 79 public: 80 SourceRange getRange() const { return Range; } 81 void setRange(SourceRange R) { Range = R; } 82 void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } 83 void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } 84 SourceLocation getBeginLoc() const { return Range.getBegin(); } 85 SourceLocation getEndLoc() const { return Range.getEnd(); } 86 87 void setTemplateParamLists(ArrayRef<TemplateParameterList *> L) { 88 TemplateParamLists = L; 89 } 90 ArrayRef<TemplateParameterList *> getTemplateParamLists() const { 91 return TemplateParamLists; 92 } 93 94 /// Retrieve the representation of the nested-name-specifier. 95 NestedNameSpecifier *getScopeRep() const { 96 return Builder.getRepresentation(); 97 } 98 99 /// Extend the current nested-name-specifier by another 100 /// nested-name-specifier component of the form 'type::'. 101 /// 102 /// \param Context The AST context in which this nested-name-specifier 103 /// resides. 104 /// 105 /// \param TemplateKWLoc The location of the 'template' keyword, if present. 106 /// 107 /// \param TL The TypeLoc that describes the type preceding the '::'. 108 /// 109 /// \param ColonColonLoc The location of the trailing '::'. 110 void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, 111 SourceLocation ColonColonLoc); 112 113 /// Extend the current nested-name-specifier by another 114 /// nested-name-specifier component of the form 'identifier::'. 115 /// 116 /// \param Context The AST context in which this nested-name-specifier 117 /// resides. 118 /// 119 /// \param Identifier The identifier. 120 /// 121 /// \param IdentifierLoc The location of the identifier. 122 /// 123 /// \param ColonColonLoc The location of the trailing '::'. 124 void Extend(ASTContext &Context, IdentifierInfo *Identifier, 125 SourceLocation IdentifierLoc, SourceLocation ColonColonLoc); 126 127 /// Extend the current nested-name-specifier by another 128 /// nested-name-specifier component of the form 'namespace::'. 129 /// 130 /// \param Context The AST context in which this nested-name-specifier 131 /// resides. 132 /// 133 /// \param Namespace The namespace. 134 /// 135 /// \param NamespaceLoc The location of the namespace name. 136 /// 137 /// \param ColonColonLoc The location of the trailing '::'. 138 void Extend(ASTContext &Context, NamespaceDecl *Namespace, 139 SourceLocation NamespaceLoc, SourceLocation ColonColonLoc); 140 141 /// Extend the current nested-name-specifier by another 142 /// nested-name-specifier component of the form 'namespace-alias::'. 143 /// 144 /// \param Context The AST context in which this nested-name-specifier 145 /// resides. 146 /// 147 /// \param Alias The namespace alias. 148 /// 149 /// \param AliasLoc The location of the namespace alias 150 /// name. 151 /// 152 /// \param ColonColonLoc The location of the trailing '::'. 153 void Extend(ASTContext &Context, NamespaceAliasDecl *Alias, 154 SourceLocation AliasLoc, SourceLocation ColonColonLoc); 155 156 /// Turn this (empty) nested-name-specifier into the global 157 /// nested-name-specifier '::'. 158 void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc); 159 160 /// Turns this (empty) nested-name-specifier into '__super' 161 /// nested-name-specifier. 162 /// 163 /// \param Context The AST context in which this nested-name-specifier 164 /// resides. 165 /// 166 /// \param RD The declaration of the class in which nested-name-specifier 167 /// appeared. 168 /// 169 /// \param SuperLoc The location of the '__super' keyword. 170 /// name. 171 /// 172 /// \param ColonColonLoc The location of the trailing '::'. 173 void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, 174 SourceLocation SuperLoc, SourceLocation ColonColonLoc); 175 176 /// Make a new nested-name-specifier from incomplete source-location 177 /// information. 178 /// 179 /// FIXME: This routine should be used very, very rarely, in cases where we 180 /// need to synthesize a nested-name-specifier. Most code should instead use 181 /// \c Adopt() with a proper \c NestedNameSpecifierLoc. 182 void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, 183 SourceRange R); 184 185 /// Adopt an existing nested-name-specifier (with source-range 186 /// information). 187 void Adopt(NestedNameSpecifierLoc Other); 188 189 /// Retrieve a nested-name-specifier with location information, copied 190 /// into the given AST context. 191 /// 192 /// \param Context The context into which this nested-name-specifier will be 193 /// copied. 194 NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const; 195 196 /// Retrieve the location of the name in the last qualifier 197 /// in this nested name specifier. 198 /// 199 /// For example, the location of \c bar 200 /// in 201 /// \verbatim 202 /// \::foo::bar<0>:: 203 /// ^~~ 204 /// \endverbatim 205 SourceLocation getLastQualifierNameLoc() const; 206 207 /// No scope specifier. 208 bool isEmpty() const { return Range.isInvalid() && getScopeRep() == nullptr; } 209 /// A scope specifier is present, but may be valid or invalid. 210 bool isNotEmpty() const { return !isEmpty(); } 211 212 /// An error occurred during parsing of the scope specifier. 213 bool isInvalid() const { return Range.isValid() && getScopeRep() == nullptr; } 214 /// A scope specifier is present, and it refers to a real scope. 215 bool isValid() const { return getScopeRep() != nullptr; } 216 217 /// Indicate that this nested-name-specifier is invalid. 218 void SetInvalid(SourceRange R) { 219 assert(R.isValid() && "Must have a valid source range"); 220 if (Range.getBegin().isInvalid()) 221 Range.setBegin(R.getBegin()); 222 Range.setEnd(R.getEnd()); 223 Builder.Clear(); 224 } 225 226 /// Deprecated. Some call sites intend isNotEmpty() while others intend 227 /// isValid(). 228 bool isSet() const { return getScopeRep() != nullptr; } 229 230 void clear() { 231 Range = SourceRange(); 232 Builder.Clear(); 233 } 234 235 /// Retrieve the data associated with the source-location information. 236 char *location_data() const { return Builder.getBuffer().first; } 237 238 /// Retrieve the size of the data associated with source-location 239 /// information. 240 unsigned location_size() const { return Builder.getBuffer().second; } 241 }; 242 243 /// Captures information about "declaration specifiers". 244 /// 245 /// "Declaration specifiers" encompasses storage-class-specifiers, 246 /// type-specifiers, type-qualifiers, and function-specifiers. 247 class DeclSpec { 248 public: 249 /// storage-class-specifier 250 /// \note The order of these enumerators is important for diagnostics. 251 enum SCS { 252 SCS_unspecified = 0, 253 SCS_typedef, 254 SCS_extern, 255 SCS_static, 256 SCS_auto, 257 SCS_register, 258 SCS_private_extern, 259 SCS_mutable 260 }; 261 262 // Import thread storage class specifier enumeration and constants. 263 // These can be combined with SCS_extern and SCS_static. 264 typedef ThreadStorageClassSpecifier TSCS; 265 static const TSCS TSCS_unspecified = clang::TSCS_unspecified; 266 static const TSCS TSCS___thread = clang::TSCS___thread; 267 static const TSCS TSCS_thread_local = clang::TSCS_thread_local; 268 static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local; 269 270 enum TSC { 271 TSC_unspecified, 272 TSC_imaginary, // Unsupported 273 TSC_complex 274 }; 275 276 // Import type specifier type enumeration and constants. 277 typedef TypeSpecifierType TST; 278 static const TST TST_unspecified = clang::TST_unspecified; 279 static const TST TST_void = clang::TST_void; 280 static const TST TST_char = clang::TST_char; 281 static const TST TST_wchar = clang::TST_wchar; 282 static const TST TST_char8 = clang::TST_char8; 283 static const TST TST_char16 = clang::TST_char16; 284 static const TST TST_char32 = clang::TST_char32; 285 static const TST TST_int = clang::TST_int; 286 static const TST TST_int128 = clang::TST_int128; 287 static const TST TST_bitint = clang::TST_bitint; 288 static const TST TST_half = clang::TST_half; 289 static const TST TST_BFloat16 = clang::TST_BFloat16; 290 static const TST TST_float = clang::TST_float; 291 static const TST TST_double = clang::TST_double; 292 static const TST TST_float16 = clang::TST_Float16; 293 static const TST TST_accum = clang::TST_Accum; 294 static const TST TST_fract = clang::TST_Fract; 295 static const TST TST_float128 = clang::TST_float128; 296 static const TST TST_ibm128 = clang::TST_ibm128; 297 static const TST TST_bool = clang::TST_bool; 298 static const TST TST_decimal32 = clang::TST_decimal32; 299 static const TST TST_decimal64 = clang::TST_decimal64; 300 static const TST TST_decimal128 = clang::TST_decimal128; 301 static const TST TST_enum = clang::TST_enum; 302 static const TST TST_union = clang::TST_union; 303 static const TST TST_struct = clang::TST_struct; 304 static const TST TST_interface = clang::TST_interface; 305 static const TST TST_class = clang::TST_class; 306 static const TST TST_typename = clang::TST_typename; 307 static const TST TST_typeofType = clang::TST_typeofType; 308 static const TST TST_typeofExpr = clang::TST_typeofExpr; 309 static const TST TST_typeof_unqualType = clang::TST_typeof_unqualType; 310 static const TST TST_typeof_unqualExpr = clang::TST_typeof_unqualExpr; 311 static const TST TST_decltype = clang::TST_decltype; 312 static const TST TST_decltype_auto = clang::TST_decltype_auto; 313 static const TST TST_typename_pack_indexing = 314 clang::TST_typename_pack_indexing; 315 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \ 316 static const TST TST_##Trait = clang::TST_##Trait; 317 #include "clang/Basic/TransformTypeTraits.def" 318 static const TST TST_auto = clang::TST_auto; 319 static const TST TST_auto_type = clang::TST_auto_type; 320 static const TST TST_unknown_anytype = clang::TST_unknown_anytype; 321 static const TST TST_atomic = clang::TST_atomic; 322 #define GENERIC_IMAGE_TYPE(ImgType, Id) \ 323 static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t; 324 #include "clang/Basic/OpenCLImageTypes.def" 325 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \ 326 static const TST TST_##Name = clang::TST_##Name; 327 #include "clang/Basic/HLSLIntangibleTypes.def" 328 static const TST TST_error = clang::TST_error; 329 330 // type-qualifiers 331 enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ. 332 TQ_unspecified = 0, 333 TQ_const = 1, 334 TQ_restrict = 2, 335 TQ_volatile = 4, 336 TQ_unaligned = 8, 337 // This has no corresponding Qualifiers::TQ value, because it's not treated 338 // as a qualifier in our type system. 339 TQ_atomic = 16 340 }; 341 342 /// ParsedSpecifiers - Flags to query which specifiers were applied. This is 343 /// returned by getParsedSpecifiers. 344 enum ParsedSpecifiers { 345 PQ_None = 0, 346 PQ_StorageClassSpecifier = 1, 347 PQ_TypeSpecifier = 2, 348 PQ_TypeQualifier = 4, 349 PQ_FunctionSpecifier = 8 350 // FIXME: Attributes should be included here. 351 }; 352 353 enum FriendSpecified : bool { No, Yes }; 354 355 private: 356 // storage-class-specifier 357 LLVM_PREFERRED_TYPE(SCS) 358 unsigned StorageClassSpec : 3; 359 LLVM_PREFERRED_TYPE(TSCS) 360 unsigned ThreadStorageClassSpec : 2; 361 LLVM_PREFERRED_TYPE(bool) 362 unsigned SCS_extern_in_linkage_spec : 1; 363 364 // type-specifier 365 LLVM_PREFERRED_TYPE(TypeSpecifierWidth) 366 unsigned TypeSpecWidth : 2; 367 LLVM_PREFERRED_TYPE(TSC) 368 unsigned TypeSpecComplex : 2; 369 LLVM_PREFERRED_TYPE(TypeSpecifierSign) 370 unsigned TypeSpecSign : 2; 371 LLVM_PREFERRED_TYPE(TST) 372 unsigned TypeSpecType : 7; 373 LLVM_PREFERRED_TYPE(bool) 374 unsigned TypeAltiVecVector : 1; 375 LLVM_PREFERRED_TYPE(bool) 376 unsigned TypeAltiVecPixel : 1; 377 LLVM_PREFERRED_TYPE(bool) 378 unsigned TypeAltiVecBool : 1; 379 LLVM_PREFERRED_TYPE(bool) 380 unsigned TypeSpecOwned : 1; 381 LLVM_PREFERRED_TYPE(bool) 382 unsigned TypeSpecPipe : 1; 383 LLVM_PREFERRED_TYPE(bool) 384 unsigned TypeSpecSat : 1; 385 LLVM_PREFERRED_TYPE(bool) 386 unsigned ConstrainedAuto : 1; 387 388 // type-qualifiers 389 LLVM_PREFERRED_TYPE(TQ) 390 unsigned TypeQualifiers : 5; // Bitwise OR of TQ. 391 392 // function-specifier 393 LLVM_PREFERRED_TYPE(bool) 394 unsigned FS_inline_specified : 1; 395 LLVM_PREFERRED_TYPE(bool) 396 unsigned FS_forceinline_specified: 1; 397 LLVM_PREFERRED_TYPE(bool) 398 unsigned FS_virtual_specified : 1; 399 LLVM_PREFERRED_TYPE(bool) 400 unsigned FS_noreturn_specified : 1; 401 402 // friend-specifier 403 LLVM_PREFERRED_TYPE(bool) 404 unsigned FriendSpecifiedFirst : 1; 405 406 // constexpr-specifier 407 LLVM_PREFERRED_TYPE(ConstexprSpecKind) 408 unsigned ConstexprSpecifier : 2; 409 410 union { 411 UnionParsedType TypeRep; 412 Decl *DeclRep; 413 Expr *ExprRep; 414 TemplateIdAnnotation *TemplateIdRep; 415 }; 416 Expr *PackIndexingExpr = nullptr; 417 418 /// ExplicitSpecifier - Store information about explicit spicifer. 419 ExplicitSpecifier FS_explicit_specifier; 420 421 // attributes. 422 ParsedAttributes Attrs; 423 424 // Scope specifier for the type spec, if applicable. 425 CXXScopeSpec TypeScope; 426 427 // SourceLocation info. These are null if the item wasn't specified or if 428 // the setting was synthesized. 429 SourceRange Range; 430 431 SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc; 432 SourceRange TSWRange; 433 SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc, EllipsisLoc; 434 /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union, 435 /// typename, then this is the location of the named type (if present); 436 /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and 437 /// TSTNameLoc provides source range info for tag types. 438 SourceLocation TSTNameLoc; 439 SourceRange TypeofParensRange; 440 SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc, 441 TQ_unalignedLoc; 442 SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc; 443 SourceLocation FS_explicitCloseParenLoc; 444 SourceLocation FS_forceinlineLoc; 445 SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc; 446 SourceLocation TQ_pipeLoc; 447 448 WrittenBuiltinSpecs writtenBS; 449 void SaveWrittenBuiltinSpecs(); 450 451 ObjCDeclSpec *ObjCQualifiers; 452 453 static bool isTypeRep(TST T) { 454 return T == TST_atomic || T == TST_typename || T == TST_typeofType || 455 T == TST_typeof_unqualType || isTransformTypeTrait(T) || 456 T == TST_typename_pack_indexing; 457 } 458 static bool isExprRep(TST T) { 459 return T == TST_typeofExpr || T == TST_typeof_unqualExpr || 460 T == TST_decltype || T == TST_bitint; 461 } 462 static bool isTemplateIdRep(TST T) { 463 return (T == TST_auto || T == TST_decltype_auto); 464 } 465 466 DeclSpec(const DeclSpec &) = delete; 467 void operator=(const DeclSpec &) = delete; 468 public: 469 static bool isDeclRep(TST T) { 470 return (T == TST_enum || T == TST_struct || 471 T == TST_interface || T == TST_union || 472 T == TST_class); 473 } 474 static bool isTransformTypeTrait(TST T) { 475 constexpr std::array<TST, 16> Traits = { 476 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait, 477 #include "clang/Basic/TransformTypeTraits.def" 478 }; 479 480 return T >= Traits.front() && T <= Traits.back(); 481 } 482 483 DeclSpec(AttributeFactory &attrFactory) 484 : StorageClassSpec(SCS_unspecified), 485 ThreadStorageClassSpec(TSCS_unspecified), 486 SCS_extern_in_linkage_spec(false), 487 TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)), 488 TypeSpecComplex(TSC_unspecified), 489 TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)), 490 TypeSpecType(TST_unspecified), TypeAltiVecVector(false), 491 TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false), 492 TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false), 493 TypeQualifiers(TQ_unspecified), FS_inline_specified(false), 494 FS_forceinline_specified(false), FS_virtual_specified(false), 495 FS_noreturn_specified(false), FriendSpecifiedFirst(false), 496 ConstexprSpecifier( 497 static_cast<unsigned>(ConstexprSpecKind::Unspecified)), 498 Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {} 499 500 // storage-class-specifier 501 SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; } 502 TSCS getThreadStorageClassSpec() const { 503 return (TSCS)ThreadStorageClassSpec; 504 } 505 bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; } 506 void setExternInLinkageSpec(bool Value) { 507 SCS_extern_in_linkage_spec = Value; 508 } 509 510 SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; } 511 SourceLocation getThreadStorageClassSpecLoc() const { 512 return ThreadStorageClassSpecLoc; 513 } 514 515 void ClearStorageClassSpecs() { 516 StorageClassSpec = DeclSpec::SCS_unspecified; 517 ThreadStorageClassSpec = DeclSpec::TSCS_unspecified; 518 SCS_extern_in_linkage_spec = false; 519 StorageClassSpecLoc = SourceLocation(); 520 ThreadStorageClassSpecLoc = SourceLocation(); 521 } 522 523 void ClearTypeSpecType() { 524 TypeSpecType = DeclSpec::TST_unspecified; 525 TypeSpecOwned = false; 526 TSTLoc = SourceLocation(); 527 } 528 529 // type-specifier 530 TypeSpecifierWidth getTypeSpecWidth() const { 531 return static_cast<TypeSpecifierWidth>(TypeSpecWidth); 532 } 533 TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; } 534 TypeSpecifierSign getTypeSpecSign() const { 535 return static_cast<TypeSpecifierSign>(TypeSpecSign); 536 } 537 TST getTypeSpecType() const { return (TST)TypeSpecType; } 538 bool isTypeAltiVecVector() const { return TypeAltiVecVector; } 539 bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; } 540 bool isTypeAltiVecBool() const { return TypeAltiVecBool; } 541 bool isTypeSpecOwned() const { return TypeSpecOwned; } 542 bool isTypeRep() const { return isTypeRep((TST) TypeSpecType); } 543 bool isTypeSpecPipe() const { return TypeSpecPipe; } 544 bool isTypeSpecSat() const { return TypeSpecSat; } 545 bool isConstrainedAuto() const { return ConstrainedAuto; } 546 547 ParsedType getRepAsType() const { 548 assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type"); 549 return TypeRep; 550 } 551 Decl *getRepAsDecl() const { 552 assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl"); 553 return DeclRep; 554 } 555 Expr *getRepAsExpr() const { 556 assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr"); 557 return ExprRep; 558 } 559 560 Expr *getPackIndexingExpr() const { 561 assert(TypeSpecType == TST_typename_pack_indexing && 562 "DeclSpec is not a pack indexing expr"); 563 return PackIndexingExpr; 564 } 565 566 TemplateIdAnnotation *getRepAsTemplateId() const { 567 assert(isTemplateIdRep((TST) TypeSpecType) && 568 "DeclSpec does not store a template id"); 569 return TemplateIdRep; 570 } 571 CXXScopeSpec &getTypeSpecScope() { return TypeScope; } 572 const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; } 573 574 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 575 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } 576 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } 577 578 SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); } 579 SourceRange getTypeSpecWidthRange() const { return TSWRange; } 580 SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; } 581 SourceLocation getTypeSpecSignLoc() const { return TSSLoc; } 582 SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } 583 SourceLocation getAltiVecLoc() const { return AltiVecLoc; } 584 SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; } 585 586 SourceLocation getTypeSpecTypeNameLoc() const { 587 assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) || 588 isExprRep((TST)TypeSpecType)); 589 return TSTNameLoc; 590 } 591 592 SourceRange getTypeofParensRange() const { return TypeofParensRange; } 593 void setTypeArgumentRange(SourceRange range) { TypeofParensRange = range; } 594 595 bool hasAutoTypeSpec() const { 596 return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type || 597 TypeSpecType == TST_decltype_auto); 598 } 599 600 bool hasTagDefinition() const; 601 602 /// Turn a type-specifier-type into a string like "_Bool" or "union". 603 static const char *getSpecifierName(DeclSpec::TST T, 604 const PrintingPolicy &Policy); 605 static const char *getSpecifierName(DeclSpec::TQ Q); 606 static const char *getSpecifierName(TypeSpecifierSign S); 607 static const char *getSpecifierName(DeclSpec::TSC C); 608 static const char *getSpecifierName(TypeSpecifierWidth W); 609 static const char *getSpecifierName(DeclSpec::SCS S); 610 static const char *getSpecifierName(DeclSpec::TSCS S); 611 static const char *getSpecifierName(ConstexprSpecKind C); 612 613 // type-qualifiers 614 615 /// getTypeQualifiers - Return a set of TQs. 616 unsigned getTypeQualifiers() const { return TypeQualifiers; } 617 SourceLocation getConstSpecLoc() const { return TQ_constLoc; } 618 SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; } 619 SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; } 620 SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; } 621 SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; } 622 SourceLocation getPipeLoc() const { return TQ_pipeLoc; } 623 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 624 625 /// Clear out all of the type qualifiers. 626 void ClearTypeQualifiers() { 627 TypeQualifiers = 0; 628 TQ_constLoc = SourceLocation(); 629 TQ_restrictLoc = SourceLocation(); 630 TQ_volatileLoc = SourceLocation(); 631 TQ_atomicLoc = SourceLocation(); 632 TQ_unalignedLoc = SourceLocation(); 633 TQ_pipeLoc = SourceLocation(); 634 } 635 636 // function-specifier 637 bool isInlineSpecified() const { 638 return FS_inline_specified | FS_forceinline_specified; 639 } 640 SourceLocation getInlineSpecLoc() const { 641 return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc; 642 } 643 644 ExplicitSpecifier getExplicitSpecifier() const { 645 return FS_explicit_specifier; 646 } 647 648 bool isVirtualSpecified() const { return FS_virtual_specified; } 649 SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; } 650 651 bool hasExplicitSpecifier() const { 652 return FS_explicit_specifier.isSpecified(); 653 } 654 SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; } 655 SourceRange getExplicitSpecRange() const { 656 return FS_explicit_specifier.getExpr() 657 ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc) 658 : SourceRange(FS_explicitLoc); 659 } 660 661 bool isNoreturnSpecified() const { return FS_noreturn_specified; } 662 SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; } 663 664 void ClearFunctionSpecs() { 665 FS_inline_specified = false; 666 FS_inlineLoc = SourceLocation(); 667 FS_forceinline_specified = false; 668 FS_forceinlineLoc = SourceLocation(); 669 FS_virtual_specified = false; 670 FS_virtualLoc = SourceLocation(); 671 FS_explicit_specifier = ExplicitSpecifier(); 672 FS_explicitLoc = SourceLocation(); 673 FS_explicitCloseParenLoc = SourceLocation(); 674 FS_noreturn_specified = false; 675 FS_noreturnLoc = SourceLocation(); 676 } 677 678 /// This method calls the passed in handler on each CVRU qual being 679 /// set. 680 /// Handle - a handler to be invoked. 681 void forEachCVRUQualifier( 682 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle); 683 684 /// This method calls the passed in handler on each qual being 685 /// set. 686 /// Handle - a handler to be invoked. 687 void forEachQualifier( 688 llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle); 689 690 /// Return true if any type-specifier has been found. 691 bool hasTypeSpecifier() const { 692 return getTypeSpecType() != DeclSpec::TST_unspecified || 693 getTypeSpecWidth() != TypeSpecifierWidth::Unspecified || 694 getTypeSpecComplex() != DeclSpec::TSC_unspecified || 695 getTypeSpecSign() != TypeSpecifierSign::Unspecified; 696 } 697 698 /// Return a bitmask of which flavors of specifiers this 699 /// DeclSpec includes. 700 unsigned getParsedSpecifiers() const; 701 702 /// isEmpty - Return true if this declaration specifier is completely empty: 703 /// no tokens were parsed in the production of it. 704 bool isEmpty() const { 705 return getParsedSpecifiers() == DeclSpec::PQ_None; 706 } 707 708 void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); } 709 void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); } 710 711 /// These methods set the specified attribute of the DeclSpec and 712 /// return false if there was no error. If an error occurs (for 713 /// example, if we tried to set "auto" on a spec with "extern" 714 /// already set), they return true and set PrevSpec and DiagID 715 /// such that 716 /// Diag(Loc, DiagID) << PrevSpec; 717 /// will yield a useful result. 718 /// 719 /// TODO: use a more general approach that still allows these 720 /// diagnostics to be ignored when desired. 721 bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, 722 const char *&PrevSpec, unsigned &DiagID, 723 const PrintingPolicy &Policy); 724 bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, 725 const char *&PrevSpec, unsigned &DiagID); 726 bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, 727 const char *&PrevSpec, unsigned &DiagID, 728 const PrintingPolicy &Policy); 729 bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, 730 unsigned &DiagID); 731 bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, 732 const char *&PrevSpec, unsigned &DiagID); 733 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 734 unsigned &DiagID, const PrintingPolicy &Policy); 735 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 736 unsigned &DiagID, ParsedType Rep, 737 const PrintingPolicy &Policy); 738 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 739 unsigned &DiagID, TypeResult Rep, 740 const PrintingPolicy &Policy) { 741 if (Rep.isInvalid()) 742 return SetTypeSpecError(); 743 return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep.get(), Policy); 744 } 745 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 746 unsigned &DiagID, Decl *Rep, bool Owned, 747 const PrintingPolicy &Policy); 748 bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, 749 SourceLocation TagNameLoc, const char *&PrevSpec, 750 unsigned &DiagID, ParsedType Rep, 751 const PrintingPolicy &Policy); 752 bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, 753 SourceLocation TagNameLoc, const char *&PrevSpec, 754 unsigned &DiagID, Decl *Rep, bool Owned, 755 const PrintingPolicy &Policy); 756 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 757 unsigned &DiagID, TemplateIdAnnotation *Rep, 758 const PrintingPolicy &Policy); 759 760 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 761 unsigned &DiagID, Expr *Rep, 762 const PrintingPolicy &policy); 763 bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, 764 const char *&PrevSpec, unsigned &DiagID, 765 const PrintingPolicy &Policy); 766 bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, 767 const char *&PrevSpec, unsigned &DiagID, 768 const PrintingPolicy &Policy); 769 bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, 770 const char *&PrevSpec, unsigned &DiagID, 771 const PrintingPolicy &Policy); 772 bool SetTypePipe(bool isPipe, SourceLocation Loc, 773 const char *&PrevSpec, unsigned &DiagID, 774 const PrintingPolicy &Policy); 775 bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, 776 const char *&PrevSpec, unsigned &DiagID, 777 const PrintingPolicy &Policy); 778 bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec, 779 unsigned &DiagID); 780 781 void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack); 782 783 bool SetTypeSpecError(); 784 void UpdateDeclRep(Decl *Rep) { 785 assert(isDeclRep((TST) TypeSpecType)); 786 DeclRep = Rep; 787 } 788 void UpdateTypeRep(ParsedType Rep) { 789 assert(isTypeRep((TST) TypeSpecType)); 790 TypeRep = Rep; 791 } 792 void UpdateExprRep(Expr *Rep) { 793 assert(isExprRep((TST) TypeSpecType)); 794 ExprRep = Rep; 795 } 796 797 bool SetTypeQual(TQ T, SourceLocation Loc); 798 799 bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, 800 unsigned &DiagID, const LangOptions &Lang); 801 802 bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, 803 unsigned &DiagID); 804 bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, 805 unsigned &DiagID); 806 bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, 807 unsigned &DiagID); 808 bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, 809 unsigned &DiagID, ExplicitSpecifier ExplicitSpec, 810 SourceLocation CloseParenLoc); 811 bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, 812 unsigned &DiagID); 813 814 bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, 815 unsigned &DiagID); 816 bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, 817 unsigned &DiagID); 818 bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, 819 const char *&PrevSpec, unsigned &DiagID); 820 821 FriendSpecified isFriendSpecified() const { 822 return static_cast<FriendSpecified>(FriendLoc.isValid()); 823 } 824 825 bool isFriendSpecifiedFirst() const { return FriendSpecifiedFirst; } 826 827 SourceLocation getFriendSpecLoc() const { return FriendLoc; } 828 829 bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); } 830 SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; } 831 832 ConstexprSpecKind getConstexprSpecifier() const { 833 return ConstexprSpecKind(ConstexprSpecifier); 834 } 835 836 SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; } 837 bool hasConstexprSpecifier() const { 838 return getConstexprSpecifier() != ConstexprSpecKind::Unspecified; 839 } 840 841 void ClearConstexprSpec() { 842 ConstexprSpecifier = static_cast<unsigned>(ConstexprSpecKind::Unspecified); 843 ConstexprLoc = SourceLocation(); 844 } 845 846 AttributePool &getAttributePool() const { 847 return Attrs.getPool(); 848 } 849 850 /// Concatenates two attribute lists. 851 /// 852 /// The GCC attribute syntax allows for the following: 853 /// 854 /// \code 855 /// short __attribute__(( unused, deprecated )) 856 /// int __attribute__(( may_alias, aligned(16) )) var; 857 /// \endcode 858 /// 859 /// This declares 4 attributes using 2 lists. The following syntax is 860 /// also allowed and equivalent to the previous declaration. 861 /// 862 /// \code 863 /// short __attribute__((unused)) __attribute__((deprecated)) 864 /// int __attribute__((may_alias)) __attribute__((aligned(16))) var; 865 /// \endcode 866 /// 867 void addAttributes(const ParsedAttributesView &AL) { 868 Attrs.addAll(AL.begin(), AL.end()); 869 } 870 871 bool hasAttributes() const { return !Attrs.empty(); } 872 873 ParsedAttributes &getAttributes() { return Attrs; } 874 const ParsedAttributes &getAttributes() const { return Attrs; } 875 876 void takeAttributesFrom(ParsedAttributes &attrs) { 877 Attrs.takeAllFrom(attrs); 878 } 879 880 /// Finish - This does final analysis of the declspec, issuing diagnostics for 881 /// things like "_Complex" (lacking an FP type). After calling this method, 882 /// DeclSpec is guaranteed self-consistent, even if an error occurred. 883 void Finish(Sema &S, const PrintingPolicy &Policy); 884 885 const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { 886 return writtenBS; 887 } 888 889 ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; } 890 void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; } 891 892 /// Checks if this DeclSpec can stand alone, without a Declarator. 893 /// 894 /// Only tag declspecs can stand alone. 895 bool isMissingDeclaratorOk(); 896 }; 897 898 /// Captures information about "declaration specifiers" specific to 899 /// Objective-C. 900 class ObjCDeclSpec { 901 public: 902 /// ObjCDeclQualifier - Qualifier used on types in method 903 /// declarations. Not all combinations are sensible. Parameters 904 /// can be one of { in, out, inout } with one of { bycopy, byref }. 905 /// Returns can either be { oneway } or not. 906 /// 907 /// This should be kept in sync with Decl::ObjCDeclQualifier. 908 enum ObjCDeclQualifier { 909 DQ_None = 0x0, 910 DQ_In = 0x1, 911 DQ_Inout = 0x2, 912 DQ_Out = 0x4, 913 DQ_Bycopy = 0x8, 914 DQ_Byref = 0x10, 915 DQ_Oneway = 0x20, 916 DQ_CSNullability = 0x40 917 }; 918 919 ObjCDeclSpec() 920 : objcDeclQualifier(DQ_None), 921 PropertyAttributes(ObjCPropertyAttribute::kind_noattr), Nullability(0), 922 GetterName(nullptr), SetterName(nullptr) {} 923 924 ObjCDeclQualifier getObjCDeclQualifier() const { 925 return (ObjCDeclQualifier)objcDeclQualifier; 926 } 927 void setObjCDeclQualifier(ObjCDeclQualifier DQVal) { 928 objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal); 929 } 930 void clearObjCDeclQualifier(ObjCDeclQualifier DQVal) { 931 objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier & ~DQVal); 932 } 933 934 ObjCPropertyAttribute::Kind getPropertyAttributes() const { 935 return ObjCPropertyAttribute::Kind(PropertyAttributes); 936 } 937 void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) { 938 PropertyAttributes = 939 (ObjCPropertyAttribute::Kind)(PropertyAttributes | PRVal); 940 } 941 942 NullabilityKind getNullability() const { 943 assert( 944 ((getObjCDeclQualifier() & DQ_CSNullability) || 945 (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) && 946 "Objective-C declspec doesn't have nullability"); 947 return static_cast<NullabilityKind>(Nullability); 948 } 949 950 SourceLocation getNullabilityLoc() const { 951 assert( 952 ((getObjCDeclQualifier() & DQ_CSNullability) || 953 (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) && 954 "Objective-C declspec doesn't have nullability"); 955 return NullabilityLoc; 956 } 957 958 void setNullability(SourceLocation loc, NullabilityKind kind) { 959 assert( 960 ((getObjCDeclQualifier() & DQ_CSNullability) || 961 (getPropertyAttributes() & ObjCPropertyAttribute::kind_nullability)) && 962 "Set the nullability declspec or property attribute first"); 963 Nullability = static_cast<unsigned>(kind); 964 NullabilityLoc = loc; 965 } 966 967 const IdentifierInfo *getGetterName() const { return GetterName; } 968 IdentifierInfo *getGetterName() { return GetterName; } 969 SourceLocation getGetterNameLoc() const { return GetterNameLoc; } 970 void setGetterName(IdentifierInfo *name, SourceLocation loc) { 971 GetterName = name; 972 GetterNameLoc = loc; 973 } 974 975 const IdentifierInfo *getSetterName() const { return SetterName; } 976 IdentifierInfo *getSetterName() { return SetterName; } 977 SourceLocation getSetterNameLoc() const { return SetterNameLoc; } 978 void setSetterName(IdentifierInfo *name, SourceLocation loc) { 979 SetterName = name; 980 SetterNameLoc = loc; 981 } 982 983 private: 984 // FIXME: These two are unrelated and mutually exclusive. So perhaps 985 // we can put them in a union to reflect their mutual exclusivity 986 // (space saving is negligible). 987 unsigned objcDeclQualifier : 7; 988 989 // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttribute::Kind 990 unsigned PropertyAttributes : NumObjCPropertyAttrsBits; 991 992 unsigned Nullability : 2; 993 994 SourceLocation NullabilityLoc; 995 996 IdentifierInfo *GetterName; // getter name or NULL if no getter 997 IdentifierInfo *SetterName; // setter name or NULL if no setter 998 SourceLocation GetterNameLoc; // location of the getter attribute's value 999 SourceLocation SetterNameLoc; // location of the setter attribute's value 1000 1001 }; 1002 1003 /// Describes the kind of unqualified-id parsed. 1004 enum class UnqualifiedIdKind { 1005 /// An identifier. 1006 IK_Identifier, 1007 /// An overloaded operator name, e.g., operator+. 1008 IK_OperatorFunctionId, 1009 /// A conversion function name, e.g., operator int. 1010 IK_ConversionFunctionId, 1011 /// A user-defined literal name, e.g., operator "" _i. 1012 IK_LiteralOperatorId, 1013 /// A constructor name. 1014 IK_ConstructorName, 1015 /// A constructor named via a template-id. 1016 IK_ConstructorTemplateId, 1017 /// A destructor name. 1018 IK_DestructorName, 1019 /// A template-id, e.g., f<int>. 1020 IK_TemplateId, 1021 /// An implicit 'self' parameter 1022 IK_ImplicitSelfParam, 1023 /// A deduction-guide name (a template-name) 1024 IK_DeductionGuideName 1025 }; 1026 1027 /// Represents a C++ unqualified-id that has been parsed. 1028 class UnqualifiedId { 1029 private: 1030 UnqualifiedId(const UnqualifiedId &Other) = delete; 1031 const UnqualifiedId &operator=(const UnqualifiedId &) = delete; 1032 1033 /// Describes the kind of unqualified-id parsed. 1034 UnqualifiedIdKind Kind; 1035 1036 public: 1037 struct OFI { 1038 /// The kind of overloaded operator. 1039 OverloadedOperatorKind Operator; 1040 1041 /// The source locations of the individual tokens that name 1042 /// the operator, e.g., the "new", "[", and "]" tokens in 1043 /// operator new []. 1044 /// 1045 /// Different operators have different numbers of tokens in their name, 1046 /// up to three. Any remaining source locations in this array will be 1047 /// set to an invalid value for operators with fewer than three tokens. 1048 SourceLocation SymbolLocations[3]; 1049 }; 1050 1051 /// Anonymous union that holds extra data associated with the 1052 /// parsed unqualified-id. 1053 union { 1054 /// When Kind == IK_Identifier, the parsed identifier, or when 1055 /// Kind == IK_UserLiteralId, the identifier suffix. 1056 const IdentifierInfo *Identifier; 1057 1058 /// When Kind == IK_OperatorFunctionId, the overloaded operator 1059 /// that we parsed. 1060 struct OFI OperatorFunctionId; 1061 1062 /// When Kind == IK_ConversionFunctionId, the type that the 1063 /// conversion function names. 1064 UnionParsedType ConversionFunctionId; 1065 1066 /// When Kind == IK_ConstructorName, the class-name of the type 1067 /// whose constructor is being referenced. 1068 UnionParsedType ConstructorName; 1069 1070 /// When Kind == IK_DestructorName, the type referred to by the 1071 /// class-name. 1072 UnionParsedType DestructorName; 1073 1074 /// When Kind == IK_DeductionGuideName, the parsed template-name. 1075 UnionParsedTemplateTy TemplateName; 1076 1077 /// When Kind == IK_TemplateId or IK_ConstructorTemplateId, 1078 /// the template-id annotation that contains the template name and 1079 /// template arguments. 1080 TemplateIdAnnotation *TemplateId; 1081 }; 1082 1083 /// The location of the first token that describes this unqualified-id, 1084 /// which will be the location of the identifier, "operator" keyword, 1085 /// tilde (for a destructor), or the template name of a template-id. 1086 SourceLocation StartLocation; 1087 1088 /// The location of the last token that describes this unqualified-id. 1089 SourceLocation EndLocation; 1090 1091 UnqualifiedId() 1092 : Kind(UnqualifiedIdKind::IK_Identifier), Identifier(nullptr) {} 1093 1094 /// Clear out this unqualified-id, setting it to default (invalid) 1095 /// state. 1096 void clear() { 1097 Kind = UnqualifiedIdKind::IK_Identifier; 1098 Identifier = nullptr; 1099 StartLocation = SourceLocation(); 1100 EndLocation = SourceLocation(); 1101 } 1102 1103 /// Determine whether this unqualified-id refers to a valid name. 1104 bool isValid() const { return StartLocation.isValid(); } 1105 1106 /// Determine whether this unqualified-id refers to an invalid name. 1107 bool isInvalid() const { return !isValid(); } 1108 1109 /// Determine what kind of name we have. 1110 UnqualifiedIdKind getKind() const { return Kind; } 1111 1112 /// Specify that this unqualified-id was parsed as an identifier. 1113 /// 1114 /// \param Id the parsed identifier. 1115 /// \param IdLoc the location of the parsed identifier. 1116 void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { 1117 Kind = UnqualifiedIdKind::IK_Identifier; 1118 Identifier = Id; 1119 StartLocation = EndLocation = IdLoc; 1120 } 1121 1122 /// Specify that this unqualified-id was parsed as an 1123 /// operator-function-id. 1124 /// 1125 /// \param OperatorLoc the location of the 'operator' keyword. 1126 /// 1127 /// \param Op the overloaded operator. 1128 /// 1129 /// \param SymbolLocations the locations of the individual operator symbols 1130 /// in the operator. 1131 void setOperatorFunctionId(SourceLocation OperatorLoc, 1132 OverloadedOperatorKind Op, 1133 SourceLocation SymbolLocations[3]); 1134 1135 /// Specify that this unqualified-id was parsed as a 1136 /// conversion-function-id. 1137 /// 1138 /// \param OperatorLoc the location of the 'operator' keyword. 1139 /// 1140 /// \param Ty the type to which this conversion function is converting. 1141 /// 1142 /// \param EndLoc the location of the last token that makes up the type name. 1143 void setConversionFunctionId(SourceLocation OperatorLoc, 1144 ParsedType Ty, 1145 SourceLocation EndLoc) { 1146 Kind = UnqualifiedIdKind::IK_ConversionFunctionId; 1147 StartLocation = OperatorLoc; 1148 EndLocation = EndLoc; 1149 ConversionFunctionId = Ty; 1150 } 1151 1152 /// Specific that this unqualified-id was parsed as a 1153 /// literal-operator-id. 1154 /// 1155 /// \param Id the parsed identifier. 1156 /// 1157 /// \param OpLoc the location of the 'operator' keyword. 1158 /// 1159 /// \param IdLoc the location of the identifier. 1160 void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, 1161 SourceLocation IdLoc) { 1162 Kind = UnqualifiedIdKind::IK_LiteralOperatorId; 1163 Identifier = Id; 1164 StartLocation = OpLoc; 1165 EndLocation = IdLoc; 1166 } 1167 1168 /// Specify that this unqualified-id was parsed as a constructor name. 1169 /// 1170 /// \param ClassType the class type referred to by the constructor name. 1171 /// 1172 /// \param ClassNameLoc the location of the class name. 1173 /// 1174 /// \param EndLoc the location of the last token that makes up the type name. 1175 void setConstructorName(ParsedType ClassType, 1176 SourceLocation ClassNameLoc, 1177 SourceLocation EndLoc) { 1178 Kind = UnqualifiedIdKind::IK_ConstructorName; 1179 StartLocation = ClassNameLoc; 1180 EndLocation = EndLoc; 1181 ConstructorName = ClassType; 1182 } 1183 1184 /// Specify that this unqualified-id was parsed as a 1185 /// template-id that names a constructor. 1186 /// 1187 /// \param TemplateId the template-id annotation that describes the parsed 1188 /// template-id. This UnqualifiedId instance will take ownership of the 1189 /// \p TemplateId and will free it on destruction. 1190 void setConstructorTemplateId(TemplateIdAnnotation *TemplateId); 1191 1192 /// Specify that this unqualified-id was parsed as a destructor name. 1193 /// 1194 /// \param TildeLoc the location of the '~' that introduces the destructor 1195 /// name. 1196 /// 1197 /// \param ClassType the name of the class referred to by the destructor name. 1198 void setDestructorName(SourceLocation TildeLoc, 1199 ParsedType ClassType, 1200 SourceLocation EndLoc) { 1201 Kind = UnqualifiedIdKind::IK_DestructorName; 1202 StartLocation = TildeLoc; 1203 EndLocation = EndLoc; 1204 DestructorName = ClassType; 1205 } 1206 1207 /// Specify that this unqualified-id was parsed as a template-id. 1208 /// 1209 /// \param TemplateId the template-id annotation that describes the parsed 1210 /// template-id. This UnqualifiedId instance will take ownership of the 1211 /// \p TemplateId and will free it on destruction. 1212 void setTemplateId(TemplateIdAnnotation *TemplateId); 1213 1214 /// Specify that this unqualified-id was parsed as a template-name for 1215 /// a deduction-guide. 1216 /// 1217 /// \param Template The parsed template-name. 1218 /// \param TemplateLoc The location of the parsed template-name. 1219 void setDeductionGuideName(ParsedTemplateTy Template, 1220 SourceLocation TemplateLoc) { 1221 Kind = UnqualifiedIdKind::IK_DeductionGuideName; 1222 TemplateName = Template; 1223 StartLocation = EndLocation = TemplateLoc; 1224 } 1225 1226 /// Specify that this unqualified-id is an implicit 'self' 1227 /// parameter. 1228 /// 1229 /// \param Id the identifier. 1230 void setImplicitSelfParam(const IdentifierInfo *Id) { 1231 Kind = UnqualifiedIdKind::IK_ImplicitSelfParam; 1232 Identifier = Id; 1233 StartLocation = EndLocation = SourceLocation(); 1234 } 1235 1236 /// Return the source range that covers this unqualified-id. 1237 SourceRange getSourceRange() const LLVM_READONLY { 1238 return SourceRange(StartLocation, EndLocation); 1239 } 1240 SourceLocation getBeginLoc() const LLVM_READONLY { return StartLocation; } 1241 SourceLocation getEndLoc() const LLVM_READONLY { return EndLocation; } 1242 }; 1243 1244 /// A set of tokens that has been cached for later parsing. 1245 typedef SmallVector<Token, 4> CachedTokens; 1246 1247 /// One instance of this struct is used for each type in a 1248 /// declarator that is parsed. 1249 /// 1250 /// This is intended to be a small value object. 1251 struct DeclaratorChunk { 1252 DeclaratorChunk() {}; 1253 1254 enum { 1255 Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe 1256 } Kind; 1257 1258 /// Loc - The place where this type was defined. 1259 SourceLocation Loc; 1260 /// EndLoc - If valid, the place where this chunck ends. 1261 SourceLocation EndLoc; 1262 1263 SourceRange getSourceRange() const { 1264 if (EndLoc.isInvalid()) 1265 return SourceRange(Loc, Loc); 1266 return SourceRange(Loc, EndLoc); 1267 } 1268 1269 ParsedAttributesView AttrList; 1270 1271 struct PointerTypeInfo { 1272 /// The type qualifiers: const/volatile/restrict/unaligned/atomic. 1273 LLVM_PREFERRED_TYPE(DeclSpec::TQ) 1274 unsigned TypeQuals : 5; 1275 1276 /// The location of the const-qualifier, if any. 1277 SourceLocation ConstQualLoc; 1278 1279 /// The location of the volatile-qualifier, if any. 1280 SourceLocation VolatileQualLoc; 1281 1282 /// The location of the restrict-qualifier, if any. 1283 SourceLocation RestrictQualLoc; 1284 1285 /// The location of the _Atomic-qualifier, if any. 1286 SourceLocation AtomicQualLoc; 1287 1288 /// The location of the __unaligned-qualifier, if any. 1289 SourceLocation UnalignedQualLoc; 1290 1291 void destroy() { 1292 } 1293 }; 1294 1295 struct ReferenceTypeInfo { 1296 /// The type qualifier: restrict. [GNU] C++ extension 1297 bool HasRestrict : 1; 1298 /// True if this is an lvalue reference, false if it's an rvalue reference. 1299 bool LValueRef : 1; 1300 void destroy() { 1301 } 1302 }; 1303 1304 struct ArrayTypeInfo { 1305 /// The type qualifiers for the array: 1306 /// const/volatile/restrict/__unaligned/_Atomic. 1307 LLVM_PREFERRED_TYPE(DeclSpec::TQ) 1308 unsigned TypeQuals : 5; 1309 1310 /// True if this dimension included the 'static' keyword. 1311 LLVM_PREFERRED_TYPE(bool) 1312 unsigned hasStatic : 1; 1313 1314 /// True if this dimension was [*]. In this case, NumElts is null. 1315 LLVM_PREFERRED_TYPE(bool) 1316 unsigned isStar : 1; 1317 1318 /// This is the size of the array, or null if [] or [*] was specified. 1319 /// Since the parser is multi-purpose, and we don't want to impose a root 1320 /// expression class on all clients, NumElts is untyped. 1321 Expr *NumElts; 1322 1323 void destroy() {} 1324 }; 1325 1326 /// ParamInfo - An array of paraminfo objects is allocated whenever a function 1327 /// declarator is parsed. There are two interesting styles of parameters 1328 /// here: 1329 /// K&R-style identifier lists and parameter type lists. K&R-style identifier 1330 /// lists will have information about the identifier, but no type information. 1331 /// Parameter type lists will have type info (if the actions module provides 1332 /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'. 1333 struct ParamInfo { 1334 const IdentifierInfo *Ident; 1335 SourceLocation IdentLoc; 1336 Decl *Param; 1337 1338 /// DefaultArgTokens - When the parameter's default argument 1339 /// cannot be parsed immediately (because it occurs within the 1340 /// declaration of a member function), it will be stored here as a 1341 /// sequence of tokens to be parsed once the class definition is 1342 /// complete. Non-NULL indicates that there is a default argument. 1343 std::unique_ptr<CachedTokens> DefaultArgTokens; 1344 1345 ParamInfo() = default; 1346 ParamInfo(const IdentifierInfo *ident, SourceLocation iloc, Decl *param, 1347 std::unique_ptr<CachedTokens> DefArgTokens = nullptr) 1348 : Ident(ident), IdentLoc(iloc), Param(param), 1349 DefaultArgTokens(std::move(DefArgTokens)) {} 1350 }; 1351 1352 struct TypeAndRange { 1353 ParsedType Ty; 1354 SourceRange Range; 1355 }; 1356 1357 struct FunctionTypeInfo { 1358 /// hasPrototype - This is true if the function had at least one typed 1359 /// parameter. If the function is () or (a,b,c), then it has no prototype, 1360 /// and is treated as a K&R-style function. 1361 LLVM_PREFERRED_TYPE(bool) 1362 unsigned hasPrototype : 1; 1363 1364 /// isVariadic - If this function has a prototype, and if that 1365 /// proto ends with ',...)', this is true. When true, EllipsisLoc 1366 /// contains the location of the ellipsis. 1367 LLVM_PREFERRED_TYPE(bool) 1368 unsigned isVariadic : 1; 1369 1370 /// Can this declaration be a constructor-style initializer? 1371 LLVM_PREFERRED_TYPE(bool) 1372 unsigned isAmbiguous : 1; 1373 1374 /// Whether the ref-qualifier (if any) is an lvalue reference. 1375 /// Otherwise, it's an rvalue reference. 1376 LLVM_PREFERRED_TYPE(bool) 1377 unsigned RefQualifierIsLValueRef : 1; 1378 1379 /// ExceptionSpecType - An ExceptionSpecificationType value. 1380 LLVM_PREFERRED_TYPE(ExceptionSpecificationType) 1381 unsigned ExceptionSpecType : 4; 1382 1383 /// DeleteParams - If this is true, we need to delete[] Params. 1384 LLVM_PREFERRED_TYPE(bool) 1385 unsigned DeleteParams : 1; 1386 1387 /// HasTrailingReturnType - If this is true, a trailing return type was 1388 /// specified. 1389 LLVM_PREFERRED_TYPE(bool) 1390 unsigned HasTrailingReturnType : 1; 1391 1392 /// The location of the left parenthesis in the source. 1393 SourceLocation LParenLoc; 1394 1395 /// When isVariadic is true, the location of the ellipsis in the source. 1396 SourceLocation EllipsisLoc; 1397 1398 /// The location of the right parenthesis in the source. 1399 SourceLocation RParenLoc; 1400 1401 /// NumParams - This is the number of formal parameters specified by the 1402 /// declarator. 1403 unsigned NumParams; 1404 1405 /// NumExceptionsOrDecls - This is the number of types in the 1406 /// dynamic-exception-decl, if the function has one. In C, this is the 1407 /// number of declarations in the function prototype. 1408 unsigned NumExceptionsOrDecls; 1409 1410 /// The location of the ref-qualifier, if any. 1411 /// 1412 /// If this is an invalid location, there is no ref-qualifier. 1413 SourceLocation RefQualifierLoc; 1414 1415 /// The location of the 'mutable' qualifer in a lambda-declarator, if 1416 /// any. 1417 SourceLocation MutableLoc; 1418 1419 /// The beginning location of the exception specification, if any. 1420 SourceLocation ExceptionSpecLocBeg; 1421 1422 /// The end location of the exception specification, if any. 1423 SourceLocation ExceptionSpecLocEnd; 1424 1425 /// Params - This is a pointer to a new[]'d array of ParamInfo objects that 1426 /// describe the parameters specified by this function declarator. null if 1427 /// there are no parameters specified. 1428 ParamInfo *Params; 1429 1430 /// DeclSpec for the function with the qualifier related info. 1431 DeclSpec *MethodQualifiers; 1432 1433 /// AttributeFactory for the MethodQualifiers. 1434 AttributeFactory *QualAttrFactory; 1435 1436 union { 1437 /// Pointer to a new[]'d array of TypeAndRange objects that 1438 /// contain the types in the function's dynamic exception specification 1439 /// and their locations, if there is one. 1440 TypeAndRange *Exceptions; 1441 1442 /// Pointer to the expression in the noexcept-specifier of this 1443 /// function, if it has one. 1444 Expr *NoexceptExpr; 1445 1446 /// Pointer to the cached tokens for an exception-specification 1447 /// that has not yet been parsed. 1448 CachedTokens *ExceptionSpecTokens; 1449 1450 /// Pointer to a new[]'d array of declarations that need to be available 1451 /// for lookup inside the function body, if one exists. Does not exist in 1452 /// C++. 1453 NamedDecl **DeclsInPrototype; 1454 }; 1455 1456 /// If HasTrailingReturnType is true, this is the trailing return 1457 /// type specified. 1458 UnionParsedType TrailingReturnType; 1459 1460 /// If HasTrailingReturnType is true, this is the location of the trailing 1461 /// return type. 1462 SourceLocation TrailingReturnTypeLoc; 1463 1464 /// Reset the parameter list to having zero parameters. 1465 /// 1466 /// This is used in various places for error recovery. 1467 void freeParams() { 1468 for (unsigned I = 0; I < NumParams; ++I) 1469 Params[I].DefaultArgTokens.reset(); 1470 if (DeleteParams) { 1471 delete[] Params; 1472 DeleteParams = false; 1473 } 1474 NumParams = 0; 1475 } 1476 1477 void destroy() { 1478 freeParams(); 1479 delete QualAttrFactory; 1480 delete MethodQualifiers; 1481 switch (getExceptionSpecType()) { 1482 default: 1483 break; 1484 case EST_Dynamic: 1485 delete[] Exceptions; 1486 break; 1487 case EST_Unparsed: 1488 delete ExceptionSpecTokens; 1489 break; 1490 case EST_None: 1491 if (NumExceptionsOrDecls != 0) 1492 delete[] DeclsInPrototype; 1493 break; 1494 } 1495 } 1496 1497 DeclSpec &getOrCreateMethodQualifiers() { 1498 if (!MethodQualifiers) { 1499 QualAttrFactory = new AttributeFactory(); 1500 MethodQualifiers = new DeclSpec(*QualAttrFactory); 1501 } 1502 return *MethodQualifiers; 1503 } 1504 1505 /// isKNRPrototype - Return true if this is a K&R style identifier list, 1506 /// like "void foo(a,b,c)". In a function definition, this will be followed 1507 /// by the parameter type definitions. 1508 bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; } 1509 1510 SourceLocation getLParenLoc() const { return LParenLoc; } 1511 1512 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 1513 1514 SourceLocation getRParenLoc() const { return RParenLoc; } 1515 1516 SourceLocation getExceptionSpecLocBeg() const { 1517 return ExceptionSpecLocBeg; 1518 } 1519 1520 SourceLocation getExceptionSpecLocEnd() const { 1521 return ExceptionSpecLocEnd; 1522 } 1523 1524 SourceRange getExceptionSpecRange() const { 1525 return SourceRange(getExceptionSpecLocBeg(), getExceptionSpecLocEnd()); 1526 } 1527 1528 /// Retrieve the location of the ref-qualifier, if any. 1529 SourceLocation getRefQualifierLoc() const { return RefQualifierLoc; } 1530 1531 /// Retrieve the location of the 'const' qualifier. 1532 SourceLocation getConstQualifierLoc() const { 1533 assert(MethodQualifiers); 1534 return MethodQualifiers->getConstSpecLoc(); 1535 } 1536 1537 /// Retrieve the location of the 'volatile' qualifier. 1538 SourceLocation getVolatileQualifierLoc() const { 1539 assert(MethodQualifiers); 1540 return MethodQualifiers->getVolatileSpecLoc(); 1541 } 1542 1543 /// Retrieve the location of the 'restrict' qualifier. 1544 SourceLocation getRestrictQualifierLoc() const { 1545 assert(MethodQualifiers); 1546 return MethodQualifiers->getRestrictSpecLoc(); 1547 } 1548 1549 /// Retrieve the location of the 'mutable' qualifier, if any. 1550 SourceLocation getMutableLoc() const { return MutableLoc; } 1551 1552 /// Determine whether this function declaration contains a 1553 /// ref-qualifier. 1554 bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); } 1555 1556 /// Determine whether this lambda-declarator contains a 'mutable' 1557 /// qualifier. 1558 bool hasMutableQualifier() const { return getMutableLoc().isValid(); } 1559 1560 /// Determine whether this method has qualifiers. 1561 bool hasMethodTypeQualifiers() const { 1562 return MethodQualifiers && (MethodQualifiers->getTypeQualifiers() || 1563 MethodQualifiers->getAttributes().size()); 1564 } 1565 1566 /// Get the type of exception specification this function has. 1567 ExceptionSpecificationType getExceptionSpecType() const { 1568 return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 1569 } 1570 1571 /// Get the number of dynamic exception specifications. 1572 unsigned getNumExceptions() const { 1573 assert(ExceptionSpecType != EST_None); 1574 return NumExceptionsOrDecls; 1575 } 1576 1577 /// Get the non-parameter decls defined within this function 1578 /// prototype. Typically these are tag declarations. 1579 ArrayRef<NamedDecl *> getDeclsInPrototype() const { 1580 assert(ExceptionSpecType == EST_None); 1581 return llvm::ArrayRef(DeclsInPrototype, NumExceptionsOrDecls); 1582 } 1583 1584 /// Determine whether this function declarator had a 1585 /// trailing-return-type. 1586 bool hasTrailingReturnType() const { return HasTrailingReturnType; } 1587 1588 /// Get the trailing-return-type for this function declarator. 1589 ParsedType getTrailingReturnType() const { 1590 assert(HasTrailingReturnType); 1591 return TrailingReturnType; 1592 } 1593 1594 /// Get the trailing-return-type location for this function declarator. 1595 SourceLocation getTrailingReturnTypeLoc() const { 1596 assert(HasTrailingReturnType); 1597 return TrailingReturnTypeLoc; 1598 } 1599 }; 1600 1601 struct BlockPointerTypeInfo { 1602 /// For now, sema will catch these as invalid. 1603 /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic. 1604 LLVM_PREFERRED_TYPE(DeclSpec::TQ) 1605 unsigned TypeQuals : 5; 1606 1607 void destroy() { 1608 } 1609 }; 1610 1611 struct MemberPointerTypeInfo { 1612 /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic. 1613 LLVM_PREFERRED_TYPE(DeclSpec::TQ) 1614 unsigned TypeQuals : 5; 1615 /// Location of the '*' token. 1616 SourceLocation StarLoc; 1617 // CXXScopeSpec has a constructor, so it can't be a direct member. 1618 // So we need some pointer-aligned storage and a bit of trickery. 1619 alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)]; 1620 CXXScopeSpec &Scope() { 1621 return *reinterpret_cast<CXXScopeSpec *>(ScopeMem); 1622 } 1623 const CXXScopeSpec &Scope() const { 1624 return *reinterpret_cast<const CXXScopeSpec *>(ScopeMem); 1625 } 1626 void destroy() { 1627 Scope().~CXXScopeSpec(); 1628 } 1629 }; 1630 1631 struct PipeTypeInfo { 1632 /// The access writes. 1633 unsigned AccessWrites : 3; 1634 1635 void destroy() {} 1636 }; 1637 1638 union { 1639 PointerTypeInfo Ptr; 1640 ReferenceTypeInfo Ref; 1641 ArrayTypeInfo Arr; 1642 FunctionTypeInfo Fun; 1643 BlockPointerTypeInfo Cls; 1644 MemberPointerTypeInfo Mem; 1645 PipeTypeInfo PipeInfo; 1646 }; 1647 1648 void destroy() { 1649 switch (Kind) { 1650 case DeclaratorChunk::Function: return Fun.destroy(); 1651 case DeclaratorChunk::Pointer: return Ptr.destroy(); 1652 case DeclaratorChunk::BlockPointer: return Cls.destroy(); 1653 case DeclaratorChunk::Reference: return Ref.destroy(); 1654 case DeclaratorChunk::Array: return Arr.destroy(); 1655 case DeclaratorChunk::MemberPointer: return Mem.destroy(); 1656 case DeclaratorChunk::Paren: return; 1657 case DeclaratorChunk::Pipe: return PipeInfo.destroy(); 1658 } 1659 } 1660 1661 /// If there are attributes applied to this declaratorchunk, return 1662 /// them. 1663 const ParsedAttributesView &getAttrs() const { return AttrList; } 1664 ParsedAttributesView &getAttrs() { return AttrList; } 1665 1666 /// Return a DeclaratorChunk for a pointer. 1667 static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, 1668 SourceLocation ConstQualLoc, 1669 SourceLocation VolatileQualLoc, 1670 SourceLocation RestrictQualLoc, 1671 SourceLocation AtomicQualLoc, 1672 SourceLocation UnalignedQualLoc) { 1673 DeclaratorChunk I; 1674 I.Kind = Pointer; 1675 I.Loc = Loc; 1676 new (&I.Ptr) PointerTypeInfo; 1677 I.Ptr.TypeQuals = TypeQuals; 1678 I.Ptr.ConstQualLoc = ConstQualLoc; 1679 I.Ptr.VolatileQualLoc = VolatileQualLoc; 1680 I.Ptr.RestrictQualLoc = RestrictQualLoc; 1681 I.Ptr.AtomicQualLoc = AtomicQualLoc; 1682 I.Ptr.UnalignedQualLoc = UnalignedQualLoc; 1683 return I; 1684 } 1685 1686 /// Return a DeclaratorChunk for a reference. 1687 static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, 1688 bool lvalue) { 1689 DeclaratorChunk I; 1690 I.Kind = Reference; 1691 I.Loc = Loc; 1692 I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0; 1693 I.Ref.LValueRef = lvalue; 1694 return I; 1695 } 1696 1697 /// Return a DeclaratorChunk for an array. 1698 static DeclaratorChunk getArray(unsigned TypeQuals, 1699 bool isStatic, bool isStar, Expr *NumElts, 1700 SourceLocation LBLoc, SourceLocation RBLoc) { 1701 DeclaratorChunk I; 1702 I.Kind = Array; 1703 I.Loc = LBLoc; 1704 I.EndLoc = RBLoc; 1705 I.Arr.TypeQuals = TypeQuals; 1706 I.Arr.hasStatic = isStatic; 1707 I.Arr.isStar = isStar; 1708 I.Arr.NumElts = NumElts; 1709 return I; 1710 } 1711 1712 /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. 1713 /// "TheDeclarator" is the declarator that this will be added to. 1714 static DeclaratorChunk getFunction(bool HasProto, 1715 bool IsAmbiguous, 1716 SourceLocation LParenLoc, 1717 ParamInfo *Params, unsigned NumParams, 1718 SourceLocation EllipsisLoc, 1719 SourceLocation RParenLoc, 1720 bool RefQualifierIsLvalueRef, 1721 SourceLocation RefQualifierLoc, 1722 SourceLocation MutableLoc, 1723 ExceptionSpecificationType ESpecType, 1724 SourceRange ESpecRange, 1725 ParsedType *Exceptions, 1726 SourceRange *ExceptionRanges, 1727 unsigned NumExceptions, 1728 Expr *NoexceptExpr, 1729 CachedTokens *ExceptionSpecTokens, 1730 ArrayRef<NamedDecl *> DeclsInPrototype, 1731 SourceLocation LocalRangeBegin, 1732 SourceLocation LocalRangeEnd, 1733 Declarator &TheDeclarator, 1734 TypeResult TrailingReturnType = 1735 TypeResult(), 1736 SourceLocation TrailingReturnTypeLoc = 1737 SourceLocation(), 1738 DeclSpec *MethodQualifiers = nullptr); 1739 1740 /// Return a DeclaratorChunk for a block. 1741 static DeclaratorChunk getBlockPointer(unsigned TypeQuals, 1742 SourceLocation Loc) { 1743 DeclaratorChunk I; 1744 I.Kind = BlockPointer; 1745 I.Loc = Loc; 1746 I.Cls.TypeQuals = TypeQuals; 1747 return I; 1748 } 1749 1750 /// Return a DeclaratorChunk for a block. 1751 static DeclaratorChunk getPipe(unsigned TypeQuals, 1752 SourceLocation Loc) { 1753 DeclaratorChunk I; 1754 I.Kind = Pipe; 1755 I.Loc = Loc; 1756 I.Cls.TypeQuals = TypeQuals; 1757 return I; 1758 } 1759 1760 static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, 1761 unsigned TypeQuals, 1762 SourceLocation StarLoc, 1763 SourceLocation EndLoc) { 1764 DeclaratorChunk I; 1765 I.Kind = MemberPointer; 1766 I.Loc = SS.getBeginLoc(); 1767 I.EndLoc = EndLoc; 1768 new (&I.Mem) MemberPointerTypeInfo; 1769 I.Mem.StarLoc = StarLoc; 1770 I.Mem.TypeQuals = TypeQuals; 1771 new (I.Mem.ScopeMem) CXXScopeSpec(SS); 1772 return I; 1773 } 1774 1775 /// Return a DeclaratorChunk for a paren. 1776 static DeclaratorChunk getParen(SourceLocation LParenLoc, 1777 SourceLocation RParenLoc) { 1778 DeclaratorChunk I; 1779 I.Kind = Paren; 1780 I.Loc = LParenLoc; 1781 I.EndLoc = RParenLoc; 1782 return I; 1783 } 1784 1785 bool isParen() const { 1786 return Kind == Paren; 1787 } 1788 }; 1789 1790 /// A parsed C++17 decomposition declarator of the form 1791 /// '[' identifier-list ']' 1792 class DecompositionDeclarator { 1793 public: 1794 struct Binding { 1795 IdentifierInfo *Name; 1796 SourceLocation NameLoc; 1797 std::optional<ParsedAttributes> Attrs; 1798 SourceLocation EllipsisLoc; 1799 }; 1800 1801 private: 1802 /// The locations of the '[' and ']' tokens. 1803 SourceLocation LSquareLoc, RSquareLoc; 1804 1805 /// The bindings. 1806 Binding *Bindings; 1807 unsigned NumBindings : 31; 1808 LLVM_PREFERRED_TYPE(bool) 1809 unsigned DeleteBindings : 1; 1810 1811 friend class Declarator; 1812 1813 public: 1814 DecompositionDeclarator() 1815 : Bindings(nullptr), NumBindings(0), DeleteBindings(false) {} 1816 DecompositionDeclarator(const DecompositionDeclarator &G) = delete; 1817 DecompositionDeclarator &operator=(const DecompositionDeclarator &G) = delete; 1818 ~DecompositionDeclarator() { clear(); } 1819 1820 void clear() { 1821 LSquareLoc = RSquareLoc = SourceLocation(); 1822 if (DeleteBindings) 1823 delete[] Bindings; 1824 else 1825 llvm::for_each(llvm::MutableArrayRef(Bindings, NumBindings), 1826 [](Binding &B) { B.Attrs.reset(); }); 1827 Bindings = nullptr; 1828 NumBindings = 0; 1829 DeleteBindings = false; 1830 } 1831 1832 ArrayRef<Binding> bindings() const { 1833 return llvm::ArrayRef(Bindings, NumBindings); 1834 } 1835 1836 bool isSet() const { return LSquareLoc.isValid(); } 1837 1838 SourceLocation getLSquareLoc() const { return LSquareLoc; } 1839 SourceLocation getRSquareLoc() const { return RSquareLoc; } 1840 SourceRange getSourceRange() const { 1841 return SourceRange(LSquareLoc, RSquareLoc); 1842 } 1843 }; 1844 1845 /// Described the kind of function definition (if any) provided for 1846 /// a function. 1847 enum class FunctionDefinitionKind { 1848 Declaration, 1849 Definition, 1850 Defaulted, 1851 Deleted 1852 }; 1853 1854 enum class DeclaratorContext { 1855 File, // File scope declaration. 1856 Prototype, // Within a function prototype. 1857 ObjCResult, // An ObjC method result type. 1858 ObjCParameter, // An ObjC method parameter type. 1859 KNRTypeList, // K&R type definition list for formals. 1860 TypeName, // Abstract declarator for types. 1861 FunctionalCast, // Type in a C++ functional cast expression. 1862 Member, // Struct/Union field. 1863 Block, // Declaration within a block in a function. 1864 ForInit, // Declaration within first part of a for loop. 1865 SelectionInit, // Declaration within optional init stmt of if/switch. 1866 Condition, // Condition declaration in a C++ if/switch/while/for. 1867 TemplateParam, // Within a template parameter list. 1868 CXXNew, // C++ new-expression. 1869 CXXCatch, // C++ catch exception-declaration 1870 ObjCCatch, // Objective-C catch exception-declaration 1871 BlockLiteral, // Block literal declarator. 1872 LambdaExpr, // Lambda-expression declarator. 1873 LambdaExprParameter, // Lambda-expression parameter declarator. 1874 ConversionId, // C++ conversion-type-id. 1875 TrailingReturn, // C++11 trailing-type-specifier. 1876 TrailingReturnVar, // C++11 trailing-type-specifier for variable. 1877 TemplateArg, // Any template argument (in template argument list). 1878 TemplateTypeArg, // Template type argument (in default argument). 1879 AliasDecl, // C++11 alias-declaration. 1880 AliasTemplate, // C++11 alias-declaration template. 1881 RequiresExpr, // C++2a requires-expression. 1882 Association // C11 _Generic selection expression association. 1883 }; 1884 1885 // Describes whether the current context is a context where an implicit 1886 // typename is allowed (C++2a [temp.res]p5]). 1887 enum class ImplicitTypenameContext { 1888 No, 1889 Yes, 1890 }; 1891 1892 /// Information about one declarator, including the parsed type 1893 /// information and the identifier. 1894 /// 1895 /// When the declarator is fully formed, this is turned into the appropriate 1896 /// Decl object. 1897 /// 1898 /// Declarators come in two types: normal declarators and abstract declarators. 1899 /// Abstract declarators are used when parsing types, and don't have an 1900 /// identifier. Normal declarators do have ID's. 1901 /// 1902 /// Instances of this class should be a transient object that lives on the 1903 /// stack, not objects that are allocated in large quantities on the heap. 1904 class Declarator { 1905 1906 private: 1907 const DeclSpec &DS; 1908 CXXScopeSpec SS; 1909 UnqualifiedId Name; 1910 SourceRange Range; 1911 1912 /// Where we are parsing this declarator. 1913 DeclaratorContext Context; 1914 1915 /// The C++17 structured binding, if any. This is an alternative to a Name. 1916 DecompositionDeclarator BindingGroup; 1917 1918 /// DeclTypeInfo - This holds each type that the declarator includes as it is 1919 /// parsed. This is pushed from the identifier out, which means that element 1920 /// #0 will be the most closely bound to the identifier, and 1921 /// DeclTypeInfo.back() will be the least closely bound. 1922 SmallVector<DeclaratorChunk, 8> DeclTypeInfo; 1923 1924 /// InvalidType - Set by Sema::GetTypeForDeclarator(). 1925 LLVM_PREFERRED_TYPE(bool) 1926 unsigned InvalidType : 1; 1927 1928 /// GroupingParens - Set by Parser::ParseParenDeclarator(). 1929 LLVM_PREFERRED_TYPE(bool) 1930 unsigned GroupingParens : 1; 1931 1932 /// FunctionDefinition - Is this Declarator for a function or member 1933 /// definition and, if so, what kind? 1934 /// 1935 /// Actually a FunctionDefinitionKind. 1936 LLVM_PREFERRED_TYPE(FunctionDefinitionKind) 1937 unsigned FunctionDefinition : 2; 1938 1939 /// Is this Declarator a redeclaration? 1940 LLVM_PREFERRED_TYPE(bool) 1941 unsigned Redeclaration : 1; 1942 1943 /// true if the declaration is preceded by \c __extension__. 1944 LLVM_PREFERRED_TYPE(bool) 1945 unsigned Extension : 1; 1946 1947 /// Indicates whether this is an Objective-C instance variable. 1948 LLVM_PREFERRED_TYPE(bool) 1949 unsigned ObjCIvar : 1; 1950 1951 /// Indicates whether this is an Objective-C 'weak' property. 1952 LLVM_PREFERRED_TYPE(bool) 1953 unsigned ObjCWeakProperty : 1; 1954 1955 /// Indicates whether the InlineParams / InlineBindings storage has been used. 1956 LLVM_PREFERRED_TYPE(bool) 1957 unsigned InlineStorageUsed : 1; 1958 1959 /// Indicates whether this declarator has an initializer. 1960 LLVM_PREFERRED_TYPE(bool) 1961 unsigned HasInitializer : 1; 1962 1963 /// Attributes attached to the declarator. 1964 ParsedAttributes Attrs; 1965 1966 /// Attributes attached to the declaration. See also documentation for the 1967 /// corresponding constructor parameter. 1968 const ParsedAttributesView &DeclarationAttrs; 1969 1970 /// The asm label, if specified. 1971 Expr *AsmLabel; 1972 1973 /// \brief The constraint-expression specified by the trailing 1974 /// requires-clause, or null if no such clause was specified. 1975 Expr *TrailingRequiresClause; 1976 1977 /// If this declarator declares a template, its template parameter lists. 1978 ArrayRef<TemplateParameterList *> TemplateParameterLists; 1979 1980 /// If the declarator declares an abbreviated function template, the innermost 1981 /// template parameter list containing the invented and explicit template 1982 /// parameters (if any). 1983 TemplateParameterList *InventedTemplateParameterList; 1984 1985 #ifndef _MSC_VER 1986 union { 1987 #endif 1988 /// InlineParams - This is a local array used for the first function decl 1989 /// chunk to avoid going to the heap for the common case when we have one 1990 /// function chunk in the declarator. 1991 DeclaratorChunk::ParamInfo InlineParams[16]; 1992 DecompositionDeclarator::Binding InlineBindings[16]; 1993 #ifndef _MSC_VER 1994 }; 1995 #endif 1996 1997 /// If this is the second or subsequent declarator in this declaration, 1998 /// the location of the comma before this declarator. 1999 SourceLocation CommaLoc; 2000 2001 /// If provided, the source location of the ellipsis used to describe 2002 /// this declarator as a parameter pack. 2003 SourceLocation EllipsisLoc; 2004 2005 Expr *PackIndexingExpr; 2006 2007 friend struct DeclaratorChunk; 2008 2009 public: 2010 /// `DS` and `DeclarationAttrs` must outlive the `Declarator`. In particular, 2011 /// take care not to pass temporary objects for these parameters. 2012 /// 2013 /// `DeclarationAttrs` contains [[]] attributes from the 2014 /// attribute-specifier-seq at the beginning of a declaration, which appertain 2015 /// to the declared entity itself. Attributes with other syntax (e.g. GNU) 2016 /// should not be placed in this attribute list; if they occur at the 2017 /// beginning of a declaration, they apply to the `DeclSpec` and should be 2018 /// attached to that instead. 2019 /// 2020 /// Here is an example of an attribute associated with a declaration: 2021 /// 2022 /// [[deprecated]] int x, y; 2023 /// 2024 /// This attribute appertains to all of the entities declared in the 2025 /// declaration, i.e. `x` and `y` in this case. 2026 Declarator(const DeclSpec &DS, const ParsedAttributesView &DeclarationAttrs, 2027 DeclaratorContext C) 2028 : DS(DS), Range(DS.getSourceRange()), Context(C), 2029 InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), 2030 GroupingParens(false), FunctionDefinition(static_cast<unsigned>( 2031 FunctionDefinitionKind::Declaration)), 2032 Redeclaration(false), Extension(false), ObjCIvar(false), 2033 ObjCWeakProperty(false), InlineStorageUsed(false), 2034 HasInitializer(false), Attrs(DS.getAttributePool().getFactory()), 2035 DeclarationAttrs(DeclarationAttrs), AsmLabel(nullptr), 2036 TrailingRequiresClause(nullptr), 2037 InventedTemplateParameterList(nullptr) { 2038 assert(llvm::all_of(DeclarationAttrs, 2039 [](const ParsedAttr &AL) { 2040 return (AL.isStandardAttributeSyntax() || 2041 AL.isRegularKeywordAttribute()); 2042 }) && 2043 "DeclarationAttrs may only contain [[]] and keyword attributes"); 2044 } 2045 2046 ~Declarator() { 2047 clear(); 2048 } 2049 /// getDeclSpec - Return the declaration-specifier that this declarator was 2050 /// declared with. 2051 const DeclSpec &getDeclSpec() const { return DS; } 2052 2053 /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This 2054 /// should be used with extreme care: declspecs can often be shared between 2055 /// multiple declarators, so mutating the DeclSpec affects all of the 2056 /// Declarators. This should only be done when the declspec is known to not 2057 /// be shared or when in error recovery etc. 2058 DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); } 2059 2060 AttributePool &getAttributePool() const { 2061 return Attrs.getPool(); 2062 } 2063 2064 /// getCXXScopeSpec - Return the C++ scope specifier (global scope or 2065 /// nested-name-specifier) that is part of the declarator-id. 2066 const CXXScopeSpec &getCXXScopeSpec() const { return SS; } 2067 CXXScopeSpec &getCXXScopeSpec() { return SS; } 2068 2069 /// Retrieve the name specified by this declarator. 2070 UnqualifiedId &getName() { return Name; } 2071 2072 const DecompositionDeclarator &getDecompositionDeclarator() const { 2073 return BindingGroup; 2074 } 2075 2076 DeclaratorContext getContext() const { return Context; } 2077 2078 bool isPrototypeContext() const { 2079 return (Context == DeclaratorContext::Prototype || 2080 Context == DeclaratorContext::ObjCParameter || 2081 Context == DeclaratorContext::ObjCResult || 2082 Context == DeclaratorContext::LambdaExprParameter); 2083 } 2084 2085 /// Get the source range that spans this declarator. 2086 SourceRange getSourceRange() const LLVM_READONLY { return Range; } 2087 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); } 2088 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); } 2089 2090 void SetSourceRange(SourceRange R) { Range = R; } 2091 /// SetRangeBegin - Set the start of the source range to Loc, unless it's 2092 /// invalid. 2093 void SetRangeBegin(SourceLocation Loc) { 2094 if (!Loc.isInvalid()) 2095 Range.setBegin(Loc); 2096 } 2097 /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid. 2098 void SetRangeEnd(SourceLocation Loc) { 2099 if (!Loc.isInvalid()) 2100 Range.setEnd(Loc); 2101 } 2102 /// ExtendWithDeclSpec - Extend the declarator source range to include the 2103 /// given declspec, unless its location is invalid. Adopts the range start if 2104 /// the current range start is invalid. 2105 void ExtendWithDeclSpec(const DeclSpec &DS) { 2106 SourceRange SR = DS.getSourceRange(); 2107 if (Range.getBegin().isInvalid()) 2108 Range.setBegin(SR.getBegin()); 2109 if (!SR.getEnd().isInvalid()) 2110 Range.setEnd(SR.getEnd()); 2111 } 2112 2113 /// Reset the contents of this Declarator. 2114 void clear() { 2115 SS.clear(); 2116 Name.clear(); 2117 Range = DS.getSourceRange(); 2118 BindingGroup.clear(); 2119 2120 for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i) 2121 DeclTypeInfo[i].destroy(); 2122 DeclTypeInfo.clear(); 2123 Attrs.clear(); 2124 AsmLabel = nullptr; 2125 InlineStorageUsed = false; 2126 HasInitializer = false; 2127 ObjCIvar = false; 2128 ObjCWeakProperty = false; 2129 CommaLoc = SourceLocation(); 2130 EllipsisLoc = SourceLocation(); 2131 PackIndexingExpr = nullptr; 2132 } 2133 2134 /// mayOmitIdentifier - Return true if the identifier is either optional or 2135 /// not allowed. This is true for typenames, prototypes, and template 2136 /// parameter lists. 2137 bool mayOmitIdentifier() const { 2138 switch (Context) { 2139 case DeclaratorContext::File: 2140 case DeclaratorContext::KNRTypeList: 2141 case DeclaratorContext::Member: 2142 case DeclaratorContext::Block: 2143 case DeclaratorContext::ForInit: 2144 case DeclaratorContext::SelectionInit: 2145 case DeclaratorContext::Condition: 2146 return false; 2147 2148 case DeclaratorContext::TypeName: 2149 case DeclaratorContext::FunctionalCast: 2150 case DeclaratorContext::AliasDecl: 2151 case DeclaratorContext::AliasTemplate: 2152 case DeclaratorContext::Prototype: 2153 case DeclaratorContext::LambdaExprParameter: 2154 case DeclaratorContext::ObjCParameter: 2155 case DeclaratorContext::ObjCResult: 2156 case DeclaratorContext::TemplateParam: 2157 case DeclaratorContext::CXXNew: 2158 case DeclaratorContext::CXXCatch: 2159 case DeclaratorContext::ObjCCatch: 2160 case DeclaratorContext::BlockLiteral: 2161 case DeclaratorContext::LambdaExpr: 2162 case DeclaratorContext::ConversionId: 2163 case DeclaratorContext::TemplateArg: 2164 case DeclaratorContext::TemplateTypeArg: 2165 case DeclaratorContext::TrailingReturn: 2166 case DeclaratorContext::TrailingReturnVar: 2167 case DeclaratorContext::RequiresExpr: 2168 case DeclaratorContext::Association: 2169 return true; 2170 } 2171 llvm_unreachable("unknown context kind!"); 2172 } 2173 2174 /// mayHaveIdentifier - Return true if the identifier is either optional or 2175 /// required. This is true for normal declarators and prototypes, but not 2176 /// typenames. 2177 bool mayHaveIdentifier() const { 2178 switch (Context) { 2179 case DeclaratorContext::File: 2180 case DeclaratorContext::KNRTypeList: 2181 case DeclaratorContext::Member: 2182 case DeclaratorContext::Block: 2183 case DeclaratorContext::ForInit: 2184 case DeclaratorContext::SelectionInit: 2185 case DeclaratorContext::Condition: 2186 case DeclaratorContext::Prototype: 2187 case DeclaratorContext::LambdaExprParameter: 2188 case DeclaratorContext::TemplateParam: 2189 case DeclaratorContext::CXXCatch: 2190 case DeclaratorContext::ObjCCatch: 2191 case DeclaratorContext::RequiresExpr: 2192 return true; 2193 2194 case DeclaratorContext::TypeName: 2195 case DeclaratorContext::FunctionalCast: 2196 case DeclaratorContext::CXXNew: 2197 case DeclaratorContext::AliasDecl: 2198 case DeclaratorContext::AliasTemplate: 2199 case DeclaratorContext::ObjCParameter: 2200 case DeclaratorContext::ObjCResult: 2201 case DeclaratorContext::BlockLiteral: 2202 case DeclaratorContext::LambdaExpr: 2203 case DeclaratorContext::ConversionId: 2204 case DeclaratorContext::TemplateArg: 2205 case DeclaratorContext::TemplateTypeArg: 2206 case DeclaratorContext::TrailingReturn: 2207 case DeclaratorContext::TrailingReturnVar: 2208 case DeclaratorContext::Association: 2209 return false; 2210 } 2211 llvm_unreachable("unknown context kind!"); 2212 } 2213 2214 /// Return true if the context permits a C++17 decomposition declarator. 2215 bool mayHaveDecompositionDeclarator() const { 2216 switch (Context) { 2217 case DeclaratorContext::File: 2218 // FIXME: It's not clear that the proposal meant to allow file-scope 2219 // structured bindings, but it does. 2220 case DeclaratorContext::Block: 2221 case DeclaratorContext::ForInit: 2222 case DeclaratorContext::SelectionInit: 2223 case DeclaratorContext::Condition: 2224 return true; 2225 2226 case DeclaratorContext::Member: 2227 case DeclaratorContext::Prototype: 2228 case DeclaratorContext::TemplateParam: 2229 case DeclaratorContext::RequiresExpr: 2230 // Maybe one day... 2231 return false; 2232 2233 // These contexts don't allow any kind of non-abstract declarator. 2234 case DeclaratorContext::KNRTypeList: 2235 case DeclaratorContext::TypeName: 2236 case DeclaratorContext::FunctionalCast: 2237 case DeclaratorContext::AliasDecl: 2238 case DeclaratorContext::AliasTemplate: 2239 case DeclaratorContext::LambdaExprParameter: 2240 case DeclaratorContext::ObjCParameter: 2241 case DeclaratorContext::ObjCResult: 2242 case DeclaratorContext::CXXNew: 2243 case DeclaratorContext::CXXCatch: 2244 case DeclaratorContext::ObjCCatch: 2245 case DeclaratorContext::BlockLiteral: 2246 case DeclaratorContext::LambdaExpr: 2247 case DeclaratorContext::ConversionId: 2248 case DeclaratorContext::TemplateArg: 2249 case DeclaratorContext::TemplateTypeArg: 2250 case DeclaratorContext::TrailingReturn: 2251 case DeclaratorContext::TrailingReturnVar: 2252 case DeclaratorContext::Association: 2253 return false; 2254 } 2255 llvm_unreachable("unknown context kind!"); 2256 } 2257 2258 /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be 2259 /// followed by a C++ direct initializer, e.g. "int x(1);". 2260 bool mayBeFollowedByCXXDirectInit() const { 2261 if (hasGroupingParens()) return false; 2262 2263 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 2264 return false; 2265 2266 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern && 2267 Context != DeclaratorContext::File) 2268 return false; 2269 2270 // Special names can't have direct initializers. 2271 if (Name.getKind() != UnqualifiedIdKind::IK_Identifier) 2272 return false; 2273 2274 switch (Context) { 2275 case DeclaratorContext::File: 2276 case DeclaratorContext::Block: 2277 case DeclaratorContext::ForInit: 2278 case DeclaratorContext::SelectionInit: 2279 case DeclaratorContext::TrailingReturnVar: 2280 return true; 2281 2282 case DeclaratorContext::Condition: 2283 // This may not be followed by a direct initializer, but it can't be a 2284 // function declaration either, and we'd prefer to perform a tentative 2285 // parse in order to produce the right diagnostic. 2286 return true; 2287 2288 case DeclaratorContext::KNRTypeList: 2289 case DeclaratorContext::Member: 2290 case DeclaratorContext::Prototype: 2291 case DeclaratorContext::LambdaExprParameter: 2292 case DeclaratorContext::ObjCParameter: 2293 case DeclaratorContext::ObjCResult: 2294 case DeclaratorContext::TemplateParam: 2295 case DeclaratorContext::CXXCatch: 2296 case DeclaratorContext::ObjCCatch: 2297 case DeclaratorContext::TypeName: 2298 case DeclaratorContext::FunctionalCast: // FIXME 2299 case DeclaratorContext::CXXNew: 2300 case DeclaratorContext::AliasDecl: 2301 case DeclaratorContext::AliasTemplate: 2302 case DeclaratorContext::BlockLiteral: 2303 case DeclaratorContext::LambdaExpr: 2304 case DeclaratorContext::ConversionId: 2305 case DeclaratorContext::TemplateArg: 2306 case DeclaratorContext::TemplateTypeArg: 2307 case DeclaratorContext::TrailingReturn: 2308 case DeclaratorContext::RequiresExpr: 2309 case DeclaratorContext::Association: 2310 return false; 2311 } 2312 llvm_unreachable("unknown context kind!"); 2313 } 2314 2315 /// isPastIdentifier - Return true if we have parsed beyond the point where 2316 /// the name would appear. (This may happen even if we haven't actually parsed 2317 /// a name, perhaps because this context doesn't require one.) 2318 bool isPastIdentifier() const { return Name.isValid(); } 2319 2320 /// hasName - Whether this declarator has a name, which might be an 2321 /// identifier (accessible via getIdentifier()) or some kind of 2322 /// special C++ name (constructor, destructor, etc.), or a structured 2323 /// binding (which is not exactly a name, but occupies the same position). 2324 bool hasName() const { 2325 return Name.getKind() != UnqualifiedIdKind::IK_Identifier || 2326 Name.Identifier || isDecompositionDeclarator(); 2327 } 2328 2329 /// Return whether this declarator is a decomposition declarator. 2330 bool isDecompositionDeclarator() const { 2331 return BindingGroup.isSet(); 2332 } 2333 2334 const IdentifierInfo *getIdentifier() const { 2335 if (Name.getKind() == UnqualifiedIdKind::IK_Identifier) 2336 return Name.Identifier; 2337 2338 return nullptr; 2339 } 2340 SourceLocation getIdentifierLoc() const { return Name.StartLocation; } 2341 2342 /// Set the name of this declarator to be the given identifier. 2343 void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { 2344 Name.setIdentifier(Id, IdLoc); 2345 } 2346 2347 /// Set the decomposition bindings for this declarator. 2348 void setDecompositionBindings( 2349 SourceLocation LSquareLoc, 2350 MutableArrayRef<DecompositionDeclarator::Binding> Bindings, 2351 SourceLocation RSquareLoc); 2352 2353 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 2354 /// EndLoc, which should be the last token of the chunk. 2355 /// This function takes attrs by R-Value reference because it takes ownership 2356 /// of those attributes from the parameter. 2357 void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, 2358 SourceLocation EndLoc) { 2359 DeclTypeInfo.push_back(TI); 2360 DeclTypeInfo.back().getAttrs().addAll(attrs.begin(), attrs.end()); 2361 getAttributePool().takeAllFrom(attrs.getPool()); 2362 2363 if (!EndLoc.isInvalid()) 2364 SetRangeEnd(EndLoc); 2365 } 2366 2367 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 2368 /// EndLoc, which should be the last token of the chunk. This overload is for 2369 /// copying a 'chunk' from another declarator, so it takes the pool that the 2370 /// other Declarator owns so that it can 'take' the attributes from it. 2371 void AddTypeInfo(const DeclaratorChunk &TI, AttributePool &OtherPool, 2372 SourceLocation EndLoc) { 2373 DeclTypeInfo.push_back(TI); 2374 getAttributePool().takeFrom(DeclTypeInfo.back().getAttrs(), OtherPool); 2375 2376 if (!EndLoc.isInvalid()) 2377 SetRangeEnd(EndLoc); 2378 } 2379 2380 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 2381 /// EndLoc, which should be the last token of the chunk. 2382 void AddTypeInfo(const DeclaratorChunk &TI, SourceLocation EndLoc) { 2383 DeclTypeInfo.push_back(TI); 2384 2385 assert(TI.AttrList.empty() && 2386 "Cannot add a declarator chunk with attributes with this overload"); 2387 2388 if (!EndLoc.isInvalid()) 2389 SetRangeEnd(EndLoc); 2390 } 2391 2392 /// Add a new innermost chunk to this declarator. 2393 void AddInnermostTypeInfo(const DeclaratorChunk &TI) { 2394 DeclTypeInfo.insert(DeclTypeInfo.begin(), TI); 2395 } 2396 2397 /// Return the number of types applied to this declarator. 2398 unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); } 2399 2400 /// Return the specified TypeInfo from this declarator. TypeInfo #0 is 2401 /// closest to the identifier. 2402 const DeclaratorChunk &getTypeObject(unsigned i) const { 2403 assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 2404 return DeclTypeInfo[i]; 2405 } 2406 DeclaratorChunk &getTypeObject(unsigned i) { 2407 assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 2408 return DeclTypeInfo[i]; 2409 } 2410 2411 typedef SmallVectorImpl<DeclaratorChunk>::const_iterator type_object_iterator; 2412 typedef llvm::iterator_range<type_object_iterator> type_object_range; 2413 2414 /// Returns the range of type objects, from the identifier outwards. 2415 type_object_range type_objects() const { 2416 return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end()); 2417 } 2418 2419 void DropFirstTypeObject() { 2420 assert(!DeclTypeInfo.empty() && "No type chunks to drop."); 2421 DeclTypeInfo.front().destroy(); 2422 DeclTypeInfo.erase(DeclTypeInfo.begin()); 2423 } 2424 2425 /// Return the innermost (closest to the declarator) chunk of this 2426 /// declarator that is not a parens chunk, or null if there are no 2427 /// non-parens chunks. 2428 const DeclaratorChunk *getInnermostNonParenChunk() const { 2429 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 2430 if (!DeclTypeInfo[i].isParen()) 2431 return &DeclTypeInfo[i]; 2432 } 2433 return nullptr; 2434 } 2435 2436 /// Return the outermost (furthest from the declarator) chunk of 2437 /// this declarator that is not a parens chunk, or null if there are 2438 /// no non-parens chunks. 2439 const DeclaratorChunk *getOutermostNonParenChunk() const { 2440 for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) { 2441 if (!DeclTypeInfo[i-1].isParen()) 2442 return &DeclTypeInfo[i-1]; 2443 } 2444 return nullptr; 2445 } 2446 2447 /// isArrayOfUnknownBound - This method returns true if the declarator 2448 /// is a declarator for an array of unknown bound (looking through 2449 /// parentheses). 2450 bool isArrayOfUnknownBound() const { 2451 const DeclaratorChunk *chunk = getInnermostNonParenChunk(); 2452 return (chunk && chunk->Kind == DeclaratorChunk::Array && 2453 !chunk->Arr.NumElts); 2454 } 2455 2456 /// isFunctionDeclarator - This method returns true if the declarator 2457 /// is a function declarator (looking through parentheses). 2458 /// If true is returned, then the reference type parameter idx is 2459 /// assigned with the index of the declaration chunk. 2460 bool isFunctionDeclarator(unsigned& idx) const { 2461 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 2462 switch (DeclTypeInfo[i].Kind) { 2463 case DeclaratorChunk::Function: 2464 idx = i; 2465 return true; 2466 case DeclaratorChunk::Paren: 2467 continue; 2468 case DeclaratorChunk::Pointer: 2469 case DeclaratorChunk::Reference: 2470 case DeclaratorChunk::Array: 2471 case DeclaratorChunk::BlockPointer: 2472 case DeclaratorChunk::MemberPointer: 2473 case DeclaratorChunk::Pipe: 2474 return false; 2475 } 2476 llvm_unreachable("Invalid type chunk"); 2477 } 2478 return false; 2479 } 2480 2481 /// isFunctionDeclarator - Once this declarator is fully parsed and formed, 2482 /// this method returns true if the identifier is a function declarator 2483 /// (looking through parentheses). 2484 bool isFunctionDeclarator() const { 2485 unsigned index; 2486 return isFunctionDeclarator(index); 2487 } 2488 2489 /// getFunctionTypeInfo - Retrieves the function type info object 2490 /// (looking through parentheses). 2491 DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() { 2492 assert(isFunctionDeclarator() && "Not a function declarator!"); 2493 unsigned index = 0; 2494 isFunctionDeclarator(index); 2495 return DeclTypeInfo[index].Fun; 2496 } 2497 2498 /// getFunctionTypeInfo - Retrieves the function type info object 2499 /// (looking through parentheses). 2500 const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const { 2501 return const_cast<Declarator*>(this)->getFunctionTypeInfo(); 2502 } 2503 2504 /// Determine whether the declaration that will be produced from 2505 /// this declaration will be a function. 2506 /// 2507 /// A declaration can declare a function even if the declarator itself 2508 /// isn't a function declarator, if the type specifier refers to a function 2509 /// type. This routine checks for both cases. 2510 bool isDeclarationOfFunction() const; 2511 2512 /// Return true if this declaration appears in a context where a 2513 /// function declarator would be a function declaration. 2514 bool isFunctionDeclarationContext() const { 2515 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 2516 return false; 2517 2518 switch (Context) { 2519 case DeclaratorContext::File: 2520 case DeclaratorContext::Member: 2521 case DeclaratorContext::Block: 2522 case DeclaratorContext::ForInit: 2523 case DeclaratorContext::SelectionInit: 2524 return true; 2525 2526 case DeclaratorContext::Condition: 2527 case DeclaratorContext::KNRTypeList: 2528 case DeclaratorContext::TypeName: 2529 case DeclaratorContext::FunctionalCast: 2530 case DeclaratorContext::AliasDecl: 2531 case DeclaratorContext::AliasTemplate: 2532 case DeclaratorContext::Prototype: 2533 case DeclaratorContext::LambdaExprParameter: 2534 case DeclaratorContext::ObjCParameter: 2535 case DeclaratorContext::ObjCResult: 2536 case DeclaratorContext::TemplateParam: 2537 case DeclaratorContext::CXXNew: 2538 case DeclaratorContext::CXXCatch: 2539 case DeclaratorContext::ObjCCatch: 2540 case DeclaratorContext::BlockLiteral: 2541 case DeclaratorContext::LambdaExpr: 2542 case DeclaratorContext::ConversionId: 2543 case DeclaratorContext::TemplateArg: 2544 case DeclaratorContext::TemplateTypeArg: 2545 case DeclaratorContext::TrailingReturn: 2546 case DeclaratorContext::TrailingReturnVar: 2547 case DeclaratorContext::RequiresExpr: 2548 case DeclaratorContext::Association: 2549 return false; 2550 } 2551 llvm_unreachable("unknown context kind!"); 2552 } 2553 2554 /// Determine whether this declaration appears in a context where an 2555 /// expression could appear. 2556 bool isExpressionContext() const { 2557 switch (Context) { 2558 case DeclaratorContext::File: 2559 case DeclaratorContext::KNRTypeList: 2560 case DeclaratorContext::Member: 2561 2562 // FIXME: sizeof(...) permits an expression. 2563 case DeclaratorContext::TypeName: 2564 2565 case DeclaratorContext::FunctionalCast: 2566 case DeclaratorContext::AliasDecl: 2567 case DeclaratorContext::AliasTemplate: 2568 case DeclaratorContext::Prototype: 2569 case DeclaratorContext::LambdaExprParameter: 2570 case DeclaratorContext::ObjCParameter: 2571 case DeclaratorContext::ObjCResult: 2572 case DeclaratorContext::TemplateParam: 2573 case DeclaratorContext::CXXNew: 2574 case DeclaratorContext::CXXCatch: 2575 case DeclaratorContext::ObjCCatch: 2576 case DeclaratorContext::BlockLiteral: 2577 case DeclaratorContext::LambdaExpr: 2578 case DeclaratorContext::ConversionId: 2579 case DeclaratorContext::TrailingReturn: 2580 case DeclaratorContext::TrailingReturnVar: 2581 case DeclaratorContext::TemplateTypeArg: 2582 case DeclaratorContext::RequiresExpr: 2583 case DeclaratorContext::Association: 2584 return false; 2585 2586 case DeclaratorContext::Block: 2587 case DeclaratorContext::ForInit: 2588 case DeclaratorContext::SelectionInit: 2589 case DeclaratorContext::Condition: 2590 case DeclaratorContext::TemplateArg: 2591 return true; 2592 } 2593 2594 llvm_unreachable("unknown context kind!"); 2595 } 2596 2597 /// Return true if a function declarator at this position would be a 2598 /// function declaration. 2599 bool isFunctionDeclaratorAFunctionDeclaration() const { 2600 if (!isFunctionDeclarationContext()) 2601 return false; 2602 2603 for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I) 2604 if (getTypeObject(I).Kind != DeclaratorChunk::Paren) 2605 return false; 2606 2607 return true; 2608 } 2609 2610 /// Determine whether a trailing return type was written (at any 2611 /// level) within this declarator. 2612 bool hasTrailingReturnType() const { 2613 for (const auto &Chunk : type_objects()) 2614 if (Chunk.Kind == DeclaratorChunk::Function && 2615 Chunk.Fun.hasTrailingReturnType()) 2616 return true; 2617 return false; 2618 } 2619 /// Get the trailing return type appearing (at any level) within this 2620 /// declarator. 2621 ParsedType getTrailingReturnType() const { 2622 for (const auto &Chunk : type_objects()) 2623 if (Chunk.Kind == DeclaratorChunk::Function && 2624 Chunk.Fun.hasTrailingReturnType()) 2625 return Chunk.Fun.getTrailingReturnType(); 2626 return ParsedType(); 2627 } 2628 2629 /// \brief Sets a trailing requires clause for this declarator. 2630 void setTrailingRequiresClause(Expr *TRC) { 2631 TrailingRequiresClause = TRC; 2632 2633 SetRangeEnd(TRC->getEndLoc()); 2634 } 2635 2636 /// \brief Sets a trailing requires clause for this declarator. 2637 Expr *getTrailingRequiresClause() { 2638 return TrailingRequiresClause; 2639 } 2640 2641 /// \brief Determine whether a trailing requires clause was written in this 2642 /// declarator. 2643 bool hasTrailingRequiresClause() const { 2644 return TrailingRequiresClause != nullptr; 2645 } 2646 2647 /// Sets the template parameter lists that preceded the declarator. 2648 void setTemplateParameterLists(ArrayRef<TemplateParameterList *> TPLs) { 2649 TemplateParameterLists = TPLs; 2650 } 2651 2652 /// The template parameter lists that preceded the declarator. 2653 ArrayRef<TemplateParameterList *> getTemplateParameterLists() const { 2654 return TemplateParameterLists; 2655 } 2656 2657 /// Sets the template parameter list generated from the explicit template 2658 /// parameters along with any invented template parameters from 2659 /// placeholder-typed parameters. 2660 void setInventedTemplateParameterList(TemplateParameterList *Invented) { 2661 InventedTemplateParameterList = Invented; 2662 } 2663 2664 /// The template parameter list generated from the explicit template 2665 /// parameters along with any invented template parameters from 2666 /// placeholder-typed parameters, if there were any such parameters. 2667 TemplateParameterList * getInventedTemplateParameterList() const { 2668 return InventedTemplateParameterList; 2669 } 2670 2671 /// takeAttributes - Takes attributes from the given parsed-attributes 2672 /// set and add them to this declarator. 2673 /// 2674 /// These examples both add 3 attributes to "var": 2675 /// short int var __attribute__((aligned(16),common,deprecated)); 2676 /// short int x, __attribute__((aligned(16)) var 2677 /// __attribute__((common,deprecated)); 2678 /// 2679 /// Also extends the range of the declarator. 2680 void takeAttributes(ParsedAttributes &attrs) { 2681 Attrs.takeAllFrom(attrs); 2682 2683 if (attrs.Range.getEnd().isValid()) 2684 SetRangeEnd(attrs.Range.getEnd()); 2685 } 2686 2687 const ParsedAttributes &getAttributes() const { return Attrs; } 2688 ParsedAttributes &getAttributes() { return Attrs; } 2689 2690 const ParsedAttributesView &getDeclarationAttributes() const { 2691 return DeclarationAttrs; 2692 } 2693 2694 /// hasAttributes - do we contain any attributes? 2695 bool hasAttributes() const { 2696 if (!getAttributes().empty() || !getDeclarationAttributes().empty() || 2697 getDeclSpec().hasAttributes()) 2698 return true; 2699 for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i) 2700 if (!getTypeObject(i).getAttrs().empty()) 2701 return true; 2702 return false; 2703 } 2704 2705 void setAsmLabel(Expr *E) { AsmLabel = E; } 2706 Expr *getAsmLabel() const { return AsmLabel; } 2707 2708 void setExtension(bool Val = true) { Extension = Val; } 2709 bool getExtension() const { return Extension; } 2710 2711 void setObjCIvar(bool Val = true) { ObjCIvar = Val; } 2712 bool isObjCIvar() const { return ObjCIvar; } 2713 2714 void setObjCWeakProperty(bool Val = true) { ObjCWeakProperty = Val; } 2715 bool isObjCWeakProperty() const { return ObjCWeakProperty; } 2716 2717 void setInvalidType(bool Val = true) { InvalidType = Val; } 2718 bool isInvalidType() const { 2719 return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error; 2720 } 2721 2722 void setGroupingParens(bool flag) { GroupingParens = flag; } 2723 bool hasGroupingParens() const { return GroupingParens; } 2724 2725 bool isFirstDeclarator() const { return !CommaLoc.isValid(); } 2726 SourceLocation getCommaLoc() const { return CommaLoc; } 2727 void setCommaLoc(SourceLocation CL) { CommaLoc = CL; } 2728 2729 bool hasEllipsis() const { return EllipsisLoc.isValid(); } 2730 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 2731 void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } 2732 2733 bool hasPackIndexing() const { return PackIndexingExpr != nullptr; } 2734 Expr *getPackIndexingExpr() const { return PackIndexingExpr; } 2735 void setPackIndexingExpr(Expr *PI) { PackIndexingExpr = PI; } 2736 2737 void setFunctionDefinitionKind(FunctionDefinitionKind Val) { 2738 FunctionDefinition = static_cast<unsigned>(Val); 2739 } 2740 2741 bool isFunctionDefinition() const { 2742 return getFunctionDefinitionKind() != FunctionDefinitionKind::Declaration; 2743 } 2744 2745 FunctionDefinitionKind getFunctionDefinitionKind() const { 2746 return (FunctionDefinitionKind)FunctionDefinition; 2747 } 2748 2749 void setHasInitializer(bool Val = true) { HasInitializer = Val; } 2750 bool hasInitializer() const { return HasInitializer; } 2751 2752 /// Returns true if this declares a real member and not a friend. 2753 bool isFirstDeclarationOfMember() { 2754 return getContext() == DeclaratorContext::Member && 2755 !getDeclSpec().isFriendSpecified(); 2756 } 2757 2758 /// Returns true if this declares a static member. This cannot be called on a 2759 /// declarator outside of a MemberContext because we won't know until 2760 /// redeclaration time if the decl is static. 2761 bool isStaticMember(); 2762 2763 bool isExplicitObjectMemberFunction(); 2764 2765 /// Returns true if this declares a constructor or a destructor. 2766 bool isCtorOrDtor(); 2767 2768 void setRedeclaration(bool Val) { Redeclaration = Val; } 2769 bool isRedeclaration() const { return Redeclaration; } 2770 }; 2771 2772 /// This little struct is used to capture information about 2773 /// structure field declarators, which is basically just a bitfield size. 2774 struct FieldDeclarator { 2775 Declarator D; 2776 Expr *BitfieldSize; 2777 explicit FieldDeclarator(const DeclSpec &DS, 2778 const ParsedAttributes &DeclarationAttrs) 2779 : D(DS, DeclarationAttrs, DeclaratorContext::Member), 2780 BitfieldSize(nullptr) {} 2781 }; 2782 2783 /// Represents a C++11 virt-specifier-seq. 2784 class VirtSpecifiers { 2785 public: 2786 enum Specifier { 2787 VS_None = 0, 2788 VS_Override = 1, 2789 VS_Final = 2, 2790 VS_Sealed = 4, 2791 // Represents the __final keyword, which is legal for gcc in pre-C++11 mode. 2792 VS_GNU_Final = 8, 2793 VS_Abstract = 16 2794 }; 2795 2796 VirtSpecifiers() = default; 2797 2798 bool SetSpecifier(Specifier VS, SourceLocation Loc, 2799 const char *&PrevSpec); 2800 2801 bool isUnset() const { return Specifiers == 0; } 2802 2803 bool isOverrideSpecified() const { return Specifiers & VS_Override; } 2804 SourceLocation getOverrideLoc() const { return VS_overrideLoc; } 2805 2806 bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed | VS_GNU_Final); } 2807 bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; } 2808 SourceLocation getFinalLoc() const { return VS_finalLoc; } 2809 SourceLocation getAbstractLoc() const { return VS_abstractLoc; } 2810 2811 void clear() { Specifiers = 0; } 2812 2813 static const char *getSpecifierName(Specifier VS); 2814 2815 SourceLocation getFirstLocation() const { return FirstLocation; } 2816 SourceLocation getLastLocation() const { return LastLocation; } 2817 Specifier getLastSpecifier() const { return LastSpecifier; } 2818 2819 private: 2820 unsigned Specifiers = 0; 2821 Specifier LastSpecifier = VS_None; 2822 2823 SourceLocation VS_overrideLoc, VS_finalLoc, VS_abstractLoc; 2824 SourceLocation FirstLocation; 2825 SourceLocation LastLocation; 2826 }; 2827 2828 enum class LambdaCaptureInitKind { 2829 NoInit, //!< [a] 2830 CopyInit, //!< [a = b], [a = {b}] 2831 DirectInit, //!< [a(b)] 2832 ListInit //!< [a{b}] 2833 }; 2834 2835 /// Represents a complete lambda introducer. 2836 struct LambdaIntroducer { 2837 /// An individual capture in a lambda introducer. 2838 struct LambdaCapture { 2839 LambdaCaptureKind Kind; 2840 SourceLocation Loc; 2841 IdentifierInfo *Id; 2842 SourceLocation EllipsisLoc; 2843 LambdaCaptureInitKind InitKind; 2844 ExprResult Init; 2845 ParsedType InitCaptureType; 2846 SourceRange ExplicitRange; 2847 2848 LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc, 2849 IdentifierInfo *Id, SourceLocation EllipsisLoc, 2850 LambdaCaptureInitKind InitKind, ExprResult Init, 2851 ParsedType InitCaptureType, 2852 SourceRange ExplicitRange) 2853 : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc), 2854 InitKind(InitKind), Init(Init), InitCaptureType(InitCaptureType), 2855 ExplicitRange(ExplicitRange) {} 2856 }; 2857 2858 SourceRange Range; 2859 SourceLocation DefaultLoc; 2860 LambdaCaptureDefault Default = LCD_None; 2861 SmallVector<LambdaCapture, 4> Captures; 2862 2863 LambdaIntroducer() = default; 2864 2865 bool hasLambdaCapture() const { 2866 return Captures.size() > 0 || Default != LCD_None; 2867 } 2868 2869 /// Append a capture in a lambda introducer. 2870 void addCapture(LambdaCaptureKind Kind, 2871 SourceLocation Loc, 2872 IdentifierInfo* Id, 2873 SourceLocation EllipsisLoc, 2874 LambdaCaptureInitKind InitKind, 2875 ExprResult Init, 2876 ParsedType InitCaptureType, 2877 SourceRange ExplicitRange) { 2878 Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init, 2879 InitCaptureType, ExplicitRange)); 2880 } 2881 }; 2882 2883 struct InventedTemplateParameterInfo { 2884 /// The number of parameters in the template parameter list that were 2885 /// explicitly specified by the user, as opposed to being invented by use 2886 /// of an auto parameter. 2887 unsigned NumExplicitTemplateParams = 0; 2888 2889 /// If this is a generic lambda or abbreviated function template, use this 2890 /// as the depth of each 'auto' parameter, during initial AST construction. 2891 unsigned AutoTemplateParameterDepth = 0; 2892 2893 /// Store the list of the template parameters for a generic lambda or an 2894 /// abbreviated function template. 2895 /// If this is a generic lambda or abbreviated function template, this holds 2896 /// the explicit template parameters followed by the auto parameters 2897 /// converted into TemplateTypeParmDecls. 2898 /// It can be used to construct the generic lambda or abbreviated template's 2899 /// template parameter list during initial AST construction. 2900 SmallVector<NamedDecl*, 4> TemplateParams; 2901 }; 2902 2903 } // end namespace clang 2904 2905 #endif // LLVM_CLANG_SEMA_DECLSPEC_H 2906