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