1 //===--- DeclSpec.h - Parsed declaration specifiers -------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// \brief This file defines the classes used to store parsed information about 12 /// declaration-specifiers and declarators. 13 /// 14 /// \verbatim 15 /// static const int volatile x, *y, *(*(*z)[10])(const void *x); 16 /// ------------------------- - -- --------------------------- 17 /// declaration-specifiers \ | / 18 /// declarators 19 /// \endverbatim 20 /// 21 //===----------------------------------------------------------------------===// 22 23 #ifndef LLVM_CLANG_SEMA_DECLSPEC_H 24 #define LLVM_CLANG_SEMA_DECLSPEC_H 25 26 #include "clang/AST/NestedNameSpecifier.h" 27 #include "clang/Basic/ExceptionSpecificationType.h" 28 #include "clang/Basic/Lambda.h" 29 #include "clang/Basic/OperatorKinds.h" 30 #include "clang/Basic/Specifiers.h" 31 #include "clang/Lex/Token.h" 32 #include "clang/Sema/AttributeList.h" 33 #include "clang/Sema/Ownership.h" 34 #include "llvm/ADT/SmallVector.h" 35 #include "llvm/Support/Compiler.h" 36 #include "llvm/Support/ErrorHandling.h" 37 38 namespace clang { 39 class ASTContext; 40 class CXXRecordDecl; 41 class TypeLoc; 42 class LangOptions; 43 class DiagnosticsEngine; 44 class IdentifierInfo; 45 class NamespaceAliasDecl; 46 class NamespaceDecl; 47 class NestedNameSpecifier; 48 class NestedNameSpecifierLoc; 49 class ObjCDeclSpec; 50 class Preprocessor; 51 class Sema; 52 class Declarator; 53 struct TemplateIdAnnotation; 54 55 /// \brief Represents a C++ nested-name-specifier or a global scope specifier. 56 /// 57 /// These can be in 3 states: 58 /// 1) Not present, identified by isEmpty() 59 /// 2) Present, identified by isNotEmpty() 60 /// 2.a) Valid, identified by isValid() 61 /// 2.b) Invalid, identified by isInvalid(). 62 /// 63 /// isSet() is deprecated because it mostly corresponded to "valid" but was 64 /// often used as if it meant "present". 65 /// 66 /// The actual scope is described by getScopeRep(). 67 class CXXScopeSpec { 68 SourceRange Range; 69 NestedNameSpecifierLocBuilder Builder; 70 71 public: getRange()72 const SourceRange &getRange() const { return Range; } setRange(const SourceRange & R)73 void setRange(const SourceRange &R) { Range = R; } setBeginLoc(SourceLocation Loc)74 void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } setEndLoc(SourceLocation Loc)75 void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } getBeginLoc()76 SourceLocation getBeginLoc() const { return Range.getBegin(); } getEndLoc()77 SourceLocation getEndLoc() const { return Range.getEnd(); } 78 79 /// \brief Retrieve the representation of the nested-name-specifier. getScopeRep()80 NestedNameSpecifier *getScopeRep() const { 81 return Builder.getRepresentation(); 82 } 83 84 /// \brief Extend the current nested-name-specifier by another 85 /// nested-name-specifier component of the form 'type::'. 86 /// 87 /// \param Context The AST context in which this nested-name-specifier 88 /// resides. 89 /// 90 /// \param TemplateKWLoc The location of the 'template' keyword, if present. 91 /// 92 /// \param TL The TypeLoc that describes the type preceding the '::'. 93 /// 94 /// \param ColonColonLoc The location of the trailing '::'. 95 void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, 96 SourceLocation ColonColonLoc); 97 98 /// \brief Extend the current nested-name-specifier by another 99 /// nested-name-specifier component of the form 'identifier::'. 100 /// 101 /// \param Context The AST context in which this nested-name-specifier 102 /// resides. 103 /// 104 /// \param Identifier The identifier. 105 /// 106 /// \param IdentifierLoc The location of the identifier. 107 /// 108 /// \param ColonColonLoc The location of the trailing '::'. 109 void Extend(ASTContext &Context, IdentifierInfo *Identifier, 110 SourceLocation IdentifierLoc, SourceLocation ColonColonLoc); 111 112 /// \brief Extend the current nested-name-specifier by another 113 /// nested-name-specifier component of the form 'namespace::'. 114 /// 115 /// \param Context The AST context in which this nested-name-specifier 116 /// resides. 117 /// 118 /// \param Namespace The namespace. 119 /// 120 /// \param NamespaceLoc The location of the namespace name. 121 /// 122 /// \param ColonColonLoc The location of the trailing '::'. 123 void Extend(ASTContext &Context, NamespaceDecl *Namespace, 124 SourceLocation NamespaceLoc, SourceLocation ColonColonLoc); 125 126 /// \brief Extend the current nested-name-specifier by another 127 /// nested-name-specifier component of the form 'namespace-alias::'. 128 /// 129 /// \param Context The AST context in which this nested-name-specifier 130 /// resides. 131 /// 132 /// \param Alias The namespace alias. 133 /// 134 /// \param AliasLoc The location of the namespace alias 135 /// name. 136 /// 137 /// \param ColonColonLoc The location of the trailing '::'. 138 void Extend(ASTContext &Context, NamespaceAliasDecl *Alias, 139 SourceLocation AliasLoc, SourceLocation ColonColonLoc); 140 141 /// \brief Turn this (empty) nested-name-specifier into the global 142 /// nested-name-specifier '::'. 143 void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc); 144 145 /// \brief Turns this (empty) nested-name-specifier into '__super' 146 /// nested-name-specifier. 147 /// 148 /// \param Context The AST context in which this nested-name-specifier 149 /// resides. 150 /// 151 /// \param RD The declaration of the class in which nested-name-specifier 152 /// appeared. 153 /// 154 /// \param SuperLoc The location of the '__super' keyword. 155 /// name. 156 /// 157 /// \param ColonColonLoc The location of the trailing '::'. 158 void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, 159 SourceLocation SuperLoc, SourceLocation ColonColonLoc); 160 161 /// \brief Make a new nested-name-specifier from incomplete source-location 162 /// information. 163 /// 164 /// FIXME: This routine should be used very, very rarely, in cases where we 165 /// need to synthesize a nested-name-specifier. Most code should instead use 166 /// \c Adopt() with a proper \c NestedNameSpecifierLoc. 167 void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, 168 SourceRange R); 169 170 /// \brief Adopt an existing nested-name-specifier (with source-range 171 /// information). 172 void Adopt(NestedNameSpecifierLoc Other); 173 174 /// \brief Retrieve a nested-name-specifier with location information, copied 175 /// into the given AST context. 176 /// 177 /// \param Context The context into which this nested-name-specifier will be 178 /// copied. 179 NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const; 180 181 /// \brief Retrieve the location of the name in the last qualifier 182 /// in this nested name specifier. 183 /// 184 /// For example, the location of \c bar 185 /// in 186 /// \verbatim 187 /// \::foo::bar<0>:: 188 /// ^~~ 189 /// \endverbatim 190 SourceLocation getLastQualifierNameLoc() const; 191 192 /// No scope specifier. isEmpty()193 bool isEmpty() const { return !Range.isValid(); } 194 /// A scope specifier is present, but may be valid or invalid. isNotEmpty()195 bool isNotEmpty() const { return !isEmpty(); } 196 197 /// An error occurred during parsing of the scope specifier. isInvalid()198 bool isInvalid() const { return isNotEmpty() && getScopeRep() == nullptr; } 199 /// A scope specifier is present, and it refers to a real scope. isValid()200 bool isValid() const { return isNotEmpty() && getScopeRep() != nullptr; } 201 202 /// \brief Indicate that this nested-name-specifier is invalid. SetInvalid(SourceRange R)203 void SetInvalid(SourceRange R) { 204 assert(R.isValid() && "Must have a valid source range"); 205 if (Range.getBegin().isInvalid()) 206 Range.setBegin(R.getBegin()); 207 Range.setEnd(R.getEnd()); 208 Builder.Clear(); 209 } 210 211 /// Deprecated. Some call sites intend isNotEmpty() while others intend 212 /// isValid(). isSet()213 bool isSet() const { return getScopeRep() != nullptr; } 214 clear()215 void clear() { 216 Range = SourceRange(); 217 Builder.Clear(); 218 } 219 220 /// \brief Retrieve the data associated with the source-location information. location_data()221 char *location_data() const { return Builder.getBuffer().first; } 222 223 /// \brief Retrieve the size of the data associated with source-location 224 /// information. location_size()225 unsigned location_size() const { return Builder.getBuffer().second; } 226 }; 227 228 /// \brief Captures information about "declaration specifiers". 229 /// 230 /// "Declaration specifiers" encompasses storage-class-specifiers, 231 /// type-specifiers, type-qualifiers, and function-specifiers. 232 class DeclSpec { 233 public: 234 /// \brief storage-class-specifier 235 /// \note The order of these enumerators is important for diagnostics. 236 enum SCS { 237 SCS_unspecified = 0, 238 SCS_typedef, 239 SCS_extern, 240 SCS_static, 241 SCS_auto, 242 SCS_register, 243 SCS_private_extern, 244 SCS_mutable 245 }; 246 247 // Import thread storage class specifier enumeration and constants. 248 // These can be combined with SCS_extern and SCS_static. 249 typedef ThreadStorageClassSpecifier TSCS; 250 static const TSCS TSCS_unspecified = clang::TSCS_unspecified; 251 static const TSCS TSCS___thread = clang::TSCS___thread; 252 static const TSCS TSCS_thread_local = clang::TSCS_thread_local; 253 static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local; 254 255 // Import type specifier width enumeration and constants. 256 typedef TypeSpecifierWidth TSW; 257 static const TSW TSW_unspecified = clang::TSW_unspecified; 258 static const TSW TSW_short = clang::TSW_short; 259 static const TSW TSW_long = clang::TSW_long; 260 static const TSW TSW_longlong = clang::TSW_longlong; 261 262 enum TSC { 263 TSC_unspecified, 264 TSC_imaginary, 265 TSC_complex 266 }; 267 268 // Import type specifier sign enumeration and constants. 269 typedef TypeSpecifierSign TSS; 270 static const TSS TSS_unspecified = clang::TSS_unspecified; 271 static const TSS TSS_signed = clang::TSS_signed; 272 static const TSS TSS_unsigned = clang::TSS_unsigned; 273 274 // Import type specifier type enumeration and constants. 275 typedef TypeSpecifierType TST; 276 static const TST TST_unspecified = clang::TST_unspecified; 277 static const TST TST_void = clang::TST_void; 278 static const TST TST_char = clang::TST_char; 279 static const TST TST_wchar = clang::TST_wchar; 280 static const TST TST_char16 = clang::TST_char16; 281 static const TST TST_char32 = clang::TST_char32; 282 static const TST TST_int = clang::TST_int; 283 static const TST TST_int128 = clang::TST_int128; 284 static const TST TST_half = clang::TST_half; 285 static const TST TST_float = clang::TST_float; 286 static const TST TST_double = clang::TST_double; 287 static const TST TST_bool = clang::TST_bool; 288 static const TST TST_decimal32 = clang::TST_decimal32; 289 static const TST TST_decimal64 = clang::TST_decimal64; 290 static const TST TST_decimal128 = clang::TST_decimal128; 291 static const TST TST_enum = clang::TST_enum; 292 static const TST TST_union = clang::TST_union; 293 static const TST TST_struct = clang::TST_struct; 294 static const TST TST_interface = clang::TST_interface; 295 static const TST TST_class = clang::TST_class; 296 static const TST TST_typename = clang::TST_typename; 297 static const TST TST_typeofType = clang::TST_typeofType; 298 static const TST TST_typeofExpr = clang::TST_typeofExpr; 299 static const TST TST_decltype = clang::TST_decltype; 300 static const TST TST_decltype_auto = clang::TST_decltype_auto; 301 static const TST TST_underlyingType = clang::TST_underlyingType; 302 static const TST TST_auto = clang::TST_auto; 303 static const TST TST_unknown_anytype = clang::TST_unknown_anytype; 304 static const TST TST_atomic = clang::TST_atomic; 305 static const TST TST_error = clang::TST_error; 306 307 // type-qualifiers 308 enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ. 309 TQ_unspecified = 0, 310 TQ_const = 1, 311 TQ_restrict = 2, 312 TQ_volatile = 4, 313 // This has no corresponding Qualifiers::TQ value, because it's not treated 314 // as a qualifier in our type system. 315 TQ_atomic = 8 316 }; 317 318 /// ParsedSpecifiers - Flags to query which specifiers were applied. This is 319 /// returned by getParsedSpecifiers. 320 enum ParsedSpecifiers { 321 PQ_None = 0, 322 PQ_StorageClassSpecifier = 1, 323 PQ_TypeSpecifier = 2, 324 PQ_TypeQualifier = 4, 325 PQ_FunctionSpecifier = 8 326 }; 327 328 private: 329 // storage-class-specifier 330 /*SCS*/unsigned StorageClassSpec : 3; 331 /*TSCS*/unsigned ThreadStorageClassSpec : 2; 332 unsigned SCS_extern_in_linkage_spec : 1; 333 334 // type-specifier 335 /*TSW*/unsigned TypeSpecWidth : 2; 336 /*TSC*/unsigned TypeSpecComplex : 2; 337 /*TSS*/unsigned TypeSpecSign : 2; 338 /*TST*/unsigned TypeSpecType : 6; 339 unsigned TypeAltiVecVector : 1; 340 unsigned TypeAltiVecPixel : 1; 341 unsigned TypeAltiVecBool : 1; 342 unsigned TypeSpecOwned : 1; 343 344 // type-qualifiers 345 unsigned TypeQualifiers : 4; // 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_explicit_specified : 1; 352 unsigned FS_noreturn_specified : 1; 353 354 // friend-specifier 355 unsigned Friend_specified : 1; 356 357 // constexpr-specifier 358 unsigned Constexpr_specified : 1; 359 360 union { 361 UnionParsedType TypeRep; 362 Decl *DeclRep; 363 Expr *ExprRep; 364 }; 365 366 // attributes. 367 ParsedAttributes Attrs; 368 369 // Scope specifier for the type spec, if applicable. 370 CXXScopeSpec TypeScope; 371 372 // List of protocol qualifiers for objective-c classes. Used for 373 // protocol-qualified interfaces "NString<foo>" and protocol-qualified id 374 // "id<foo>". 375 Decl * const *ProtocolQualifiers; 376 unsigned NumProtocolQualifiers; 377 SourceLocation ProtocolLAngleLoc; 378 SourceLocation *ProtocolLocs; 379 380 // SourceLocation info. These are null if the item wasn't specified or if 381 // the setting was synthesized. 382 SourceRange Range; 383 384 SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc; 385 SourceLocation TSWLoc, TSCLoc, TSSLoc, TSTLoc, AltiVecLoc; 386 /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union, 387 /// typename, then this is the location of the named type (if present); 388 /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and 389 /// TSTNameLoc provides source range info for tag types. 390 SourceLocation TSTNameLoc; 391 SourceRange TypeofParensRange; 392 SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc; 393 SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc; 394 SourceLocation FS_forceinlineLoc; 395 SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc; 396 397 WrittenBuiltinSpecs writtenBS; 398 void SaveWrittenBuiltinSpecs(); 399 400 ObjCDeclSpec *ObjCQualifiers; 401 isTypeRep(TST T)402 static bool isTypeRep(TST T) { 403 return (T == TST_typename || T == TST_typeofType || 404 T == TST_underlyingType || T == TST_atomic); 405 } isExprRep(TST T)406 static bool isExprRep(TST T) { 407 return (T == TST_typeofExpr || T == TST_decltype); 408 } 409 410 DeclSpec(const DeclSpec &) = delete; 411 void operator=(const DeclSpec &) = delete; 412 public: isDeclRep(TST T)413 static bool isDeclRep(TST T) { 414 return (T == TST_enum || T == TST_struct || 415 T == TST_interface || T == TST_union || 416 T == TST_class); 417 } 418 DeclSpec(AttributeFactory & attrFactory)419 DeclSpec(AttributeFactory &attrFactory) 420 : StorageClassSpec(SCS_unspecified), 421 ThreadStorageClassSpec(TSCS_unspecified), 422 SCS_extern_in_linkage_spec(false), 423 TypeSpecWidth(TSW_unspecified), 424 TypeSpecComplex(TSC_unspecified), 425 TypeSpecSign(TSS_unspecified), 426 TypeSpecType(TST_unspecified), 427 TypeAltiVecVector(false), 428 TypeAltiVecPixel(false), 429 TypeAltiVecBool(false), 430 TypeSpecOwned(false), 431 TypeQualifiers(TQ_unspecified), 432 FS_inline_specified(false), 433 FS_forceinline_specified(false), 434 FS_virtual_specified(false), 435 FS_explicit_specified(false), 436 FS_noreturn_specified(false), 437 Friend_specified(false), 438 Constexpr_specified(false), 439 Attrs(attrFactory), 440 ProtocolQualifiers(nullptr), 441 NumProtocolQualifiers(0), 442 ProtocolLocs(nullptr), 443 writtenBS(), 444 ObjCQualifiers(nullptr) { 445 } ~DeclSpec()446 ~DeclSpec() { 447 delete [] ProtocolQualifiers; 448 delete [] ProtocolLocs; 449 } 450 // storage-class-specifier getStorageClassSpec()451 SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; } getThreadStorageClassSpec()452 TSCS getThreadStorageClassSpec() const { 453 return (TSCS)ThreadStorageClassSpec; 454 } isExternInLinkageSpec()455 bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; } setExternInLinkageSpec(bool Value)456 void setExternInLinkageSpec(bool Value) { 457 SCS_extern_in_linkage_spec = Value; 458 } 459 getStorageClassSpecLoc()460 SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; } getThreadStorageClassSpecLoc()461 SourceLocation getThreadStorageClassSpecLoc() const { 462 return ThreadStorageClassSpecLoc; 463 } 464 ClearStorageClassSpecs()465 void ClearStorageClassSpecs() { 466 StorageClassSpec = DeclSpec::SCS_unspecified; 467 ThreadStorageClassSpec = DeclSpec::TSCS_unspecified; 468 SCS_extern_in_linkage_spec = false; 469 StorageClassSpecLoc = SourceLocation(); 470 ThreadStorageClassSpecLoc = SourceLocation(); 471 } 472 ClearTypeSpecType()473 void ClearTypeSpecType() { 474 TypeSpecType = DeclSpec::TST_unspecified; 475 TypeSpecOwned = false; 476 TSTLoc = SourceLocation(); 477 } 478 479 // type-specifier getTypeSpecWidth()480 TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; } getTypeSpecComplex()481 TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; } getTypeSpecSign()482 TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; } getTypeSpecType()483 TST getTypeSpecType() const { return (TST)TypeSpecType; } isTypeAltiVecVector()484 bool isTypeAltiVecVector() const { return TypeAltiVecVector; } isTypeAltiVecPixel()485 bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; } isTypeAltiVecBool()486 bool isTypeAltiVecBool() const { return TypeAltiVecBool; } isTypeSpecOwned()487 bool isTypeSpecOwned() const { return TypeSpecOwned; } getRepAsType()488 ParsedType getRepAsType() const { 489 assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type"); 490 return TypeRep; 491 } getRepAsDecl()492 Decl *getRepAsDecl() const { 493 assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl"); 494 return DeclRep; 495 } getRepAsExpr()496 Expr *getRepAsExpr() const { 497 assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr"); 498 return ExprRep; 499 } getTypeSpecScope()500 CXXScopeSpec &getTypeSpecScope() { return TypeScope; } getTypeSpecScope()501 const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; } 502 getSourceRange()503 const SourceRange &getSourceRange() const LLVM_READONLY { return Range; } getLocStart()504 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } getLocEnd()505 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 506 getTypeSpecWidthLoc()507 SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; } getTypeSpecComplexLoc()508 SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; } getTypeSpecSignLoc()509 SourceLocation getTypeSpecSignLoc() const { return TSSLoc; } getTypeSpecTypeLoc()510 SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; } getAltiVecLoc()511 SourceLocation getAltiVecLoc() const { return AltiVecLoc; } 512 getTypeSpecTypeNameLoc()513 SourceLocation getTypeSpecTypeNameLoc() const { 514 assert(isDeclRep((TST) TypeSpecType) || TypeSpecType == TST_typename); 515 return TSTNameLoc; 516 } 517 getTypeofParensRange()518 SourceRange getTypeofParensRange() const { return TypeofParensRange; } setTypeofParensRange(SourceRange range)519 void setTypeofParensRange(SourceRange range) { TypeofParensRange = range; } 520 containsPlaceholderType()521 bool containsPlaceholderType() const { 522 return TypeSpecType == TST_auto || TypeSpecType == TST_decltype_auto; 523 } 524 525 bool hasTagDefinition() const; 526 527 /// \brief Turn a type-specifier-type into a string like "_Bool" or "union". 528 static const char *getSpecifierName(DeclSpec::TST T, 529 const PrintingPolicy &Policy); 530 static const char *getSpecifierName(DeclSpec::TQ Q); 531 static const char *getSpecifierName(DeclSpec::TSS S); 532 static const char *getSpecifierName(DeclSpec::TSC C); 533 static const char *getSpecifierName(DeclSpec::TSW W); 534 static const char *getSpecifierName(DeclSpec::SCS S); 535 static const char *getSpecifierName(DeclSpec::TSCS S); 536 537 // type-qualifiers 538 539 /// getTypeQualifiers - Return a set of TQs. getTypeQualifiers()540 unsigned getTypeQualifiers() const { return TypeQualifiers; } getConstSpecLoc()541 SourceLocation getConstSpecLoc() const { return TQ_constLoc; } getRestrictSpecLoc()542 SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; } getVolatileSpecLoc()543 SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; } getAtomicSpecLoc()544 SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; } 545 546 /// \brief Clear out all of the type qualifiers. ClearTypeQualifiers()547 void ClearTypeQualifiers() { 548 TypeQualifiers = 0; 549 TQ_constLoc = SourceLocation(); 550 TQ_restrictLoc = SourceLocation(); 551 TQ_volatileLoc = SourceLocation(); 552 TQ_atomicLoc = SourceLocation(); 553 } 554 555 // function-specifier isInlineSpecified()556 bool isInlineSpecified() const { 557 return FS_inline_specified | FS_forceinline_specified; 558 } getInlineSpecLoc()559 SourceLocation getInlineSpecLoc() const { 560 return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc; 561 } 562 isVirtualSpecified()563 bool isVirtualSpecified() const { return FS_virtual_specified; } getVirtualSpecLoc()564 SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; } 565 isExplicitSpecified()566 bool isExplicitSpecified() const { return FS_explicit_specified; } getExplicitSpecLoc()567 SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; } 568 isNoreturnSpecified()569 bool isNoreturnSpecified() const { return FS_noreturn_specified; } getNoreturnSpecLoc()570 SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; } 571 ClearFunctionSpecs()572 void ClearFunctionSpecs() { 573 FS_inline_specified = false; 574 FS_inlineLoc = SourceLocation(); 575 FS_forceinline_specified = false; 576 FS_forceinlineLoc = SourceLocation(); 577 FS_virtual_specified = false; 578 FS_virtualLoc = SourceLocation(); 579 FS_explicit_specified = false; 580 FS_explicitLoc = SourceLocation(); 581 FS_noreturn_specified = false; 582 FS_noreturnLoc = SourceLocation(); 583 } 584 585 /// \brief Return true if any type-specifier has been found. hasTypeSpecifier()586 bool hasTypeSpecifier() const { 587 return getTypeSpecType() != DeclSpec::TST_unspecified || 588 getTypeSpecWidth() != DeclSpec::TSW_unspecified || 589 getTypeSpecComplex() != DeclSpec::TSC_unspecified || 590 getTypeSpecSign() != DeclSpec::TSS_unspecified; 591 } 592 593 /// \brief Return a bitmask of which flavors of specifiers this 594 /// DeclSpec includes. 595 unsigned getParsedSpecifiers() const; 596 597 /// isEmpty - Return true if this declaration specifier is completely empty: 598 /// no tokens were parsed in the production of it. isEmpty()599 bool isEmpty() const { 600 return getParsedSpecifiers() == DeclSpec::PQ_None; 601 } 602 SetRangeStart(SourceLocation Loc)603 void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); } SetRangeEnd(SourceLocation Loc)604 void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); } 605 606 /// These methods set the specified attribute of the DeclSpec and 607 /// return false if there was no error. If an error occurs (for 608 /// example, if we tried to set "auto" on a spec with "extern" 609 /// already set), they return true and set PrevSpec and DiagID 610 /// such that 611 /// Diag(Loc, DiagID) << PrevSpec; 612 /// will yield a useful result. 613 /// 614 /// TODO: use a more general approach that still allows these 615 /// diagnostics to be ignored when desired. 616 bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, 617 const char *&PrevSpec, unsigned &DiagID, 618 const PrintingPolicy &Policy); 619 bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, 620 const char *&PrevSpec, unsigned &DiagID); 621 bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec, 622 unsigned &DiagID, const PrintingPolicy &Policy); 623 bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, 624 unsigned &DiagID); 625 bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, 626 unsigned &DiagID); 627 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 628 unsigned &DiagID, const PrintingPolicy &Policy); 629 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 630 unsigned &DiagID, ParsedType Rep, 631 const PrintingPolicy &Policy); 632 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 633 unsigned &DiagID, Decl *Rep, bool Owned, 634 const PrintingPolicy &Policy); 635 bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, 636 SourceLocation TagNameLoc, const char *&PrevSpec, 637 unsigned &DiagID, ParsedType Rep, 638 const PrintingPolicy &Policy); 639 bool SetTypeSpecType(TST T, SourceLocation TagKwLoc, 640 SourceLocation TagNameLoc, const char *&PrevSpec, 641 unsigned &DiagID, Decl *Rep, bool Owned, 642 const PrintingPolicy &Policy); 643 644 bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, 645 unsigned &DiagID, Expr *Rep, 646 const PrintingPolicy &policy); 647 bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, 648 const char *&PrevSpec, unsigned &DiagID, 649 const PrintingPolicy &Policy); 650 bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, 651 const char *&PrevSpec, unsigned &DiagID, 652 const PrintingPolicy &Policy); 653 bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, 654 const char *&PrevSpec, unsigned &DiagID, 655 const PrintingPolicy &Policy); 656 bool SetTypeSpecError(); UpdateDeclRep(Decl * Rep)657 void UpdateDeclRep(Decl *Rep) { 658 assert(isDeclRep((TST) TypeSpecType)); 659 DeclRep = Rep; 660 } UpdateTypeRep(ParsedType Rep)661 void UpdateTypeRep(ParsedType Rep) { 662 assert(isTypeRep((TST) TypeSpecType)); 663 TypeRep = Rep; 664 } UpdateExprRep(Expr * Rep)665 void UpdateExprRep(Expr *Rep) { 666 assert(isExprRep((TST) TypeSpecType)); 667 ExprRep = Rep; 668 } 669 670 bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, 671 unsigned &DiagID, const LangOptions &Lang); 672 673 bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, 674 unsigned &DiagID); 675 bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec, 676 unsigned &DiagID); 677 bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, 678 unsigned &DiagID); 679 bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, 680 unsigned &DiagID); 681 bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec, 682 unsigned &DiagID); 683 684 bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, 685 unsigned &DiagID); 686 bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, 687 unsigned &DiagID); 688 bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, 689 unsigned &DiagID); 690 isFriendSpecified()691 bool isFriendSpecified() const { return Friend_specified; } getFriendSpecLoc()692 SourceLocation getFriendSpecLoc() const { return FriendLoc; } 693 isModulePrivateSpecified()694 bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); } getModulePrivateSpecLoc()695 SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; } 696 isConstexprSpecified()697 bool isConstexprSpecified() const { return Constexpr_specified; } getConstexprSpecLoc()698 SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; } 699 ClearConstexprSpec()700 void ClearConstexprSpec() { 701 Constexpr_specified = false; 702 ConstexprLoc = SourceLocation(); 703 } 704 getAttributePool()705 AttributePool &getAttributePool() const { 706 return Attrs.getPool(); 707 } 708 709 /// \brief Concatenates two attribute lists. 710 /// 711 /// The GCC attribute syntax allows for the following: 712 /// 713 /// \code 714 /// short __attribute__(( unused, deprecated )) 715 /// int __attribute__(( may_alias, aligned(16) )) var; 716 /// \endcode 717 /// 718 /// This declares 4 attributes using 2 lists. The following syntax is 719 /// also allowed and equivalent to the previous declaration. 720 /// 721 /// \code 722 /// short __attribute__((unused)) __attribute__((deprecated)) 723 /// int __attribute__((may_alias)) __attribute__((aligned(16))) var; 724 /// \endcode 725 /// addAttributes(AttributeList * AL)726 void addAttributes(AttributeList *AL) { 727 Attrs.addAll(AL); 728 } 729 hasAttributes()730 bool hasAttributes() const { return !Attrs.empty(); } 731 getAttributes()732 ParsedAttributes &getAttributes() { return Attrs; } getAttributes()733 const ParsedAttributes &getAttributes() const { return Attrs; } 734 takeAttributesFrom(ParsedAttributes & attrs)735 void takeAttributesFrom(ParsedAttributes &attrs) { 736 Attrs.takeAllFrom(attrs); 737 } 738 739 typedef Decl * const *ProtocolQualifierListTy; getProtocolQualifiers()740 ProtocolQualifierListTy getProtocolQualifiers() const { 741 return ProtocolQualifiers; 742 } getProtocolLocs()743 SourceLocation *getProtocolLocs() const { return ProtocolLocs; } getNumProtocolQualifiers()744 unsigned getNumProtocolQualifiers() const { 745 return NumProtocolQualifiers; 746 } getProtocolLAngleLoc()747 SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; } 748 void setProtocolQualifiers(Decl * const *Protos, unsigned NP, 749 SourceLocation *ProtoLocs, 750 SourceLocation LAngleLoc); 751 752 /// Finish - This does final analysis of the declspec, issuing diagnostics for 753 /// things like "_Imaginary" (lacking an FP type). After calling this method, 754 /// DeclSpec is guaranteed self-consistent, even if an error occurred. 755 void Finish(DiagnosticsEngine &D, Preprocessor &PP, 756 const PrintingPolicy &Policy); 757 getWrittenBuiltinSpecs()758 const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { 759 return writtenBS; 760 } 761 getObjCQualifiers()762 ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; } setObjCQualifiers(ObjCDeclSpec * quals)763 void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; } 764 765 /// \brief Checks if this DeclSpec can stand alone, without a Declarator. 766 /// 767 /// Only tag declspecs can stand alone. 768 bool isMissingDeclaratorOk(); 769 }; 770 771 /// \brief Captures information about "declaration specifiers" specific to 772 /// Objective-C. 773 class ObjCDeclSpec { 774 public: 775 /// ObjCDeclQualifier - Qualifier used on types in method 776 /// declarations. Not all combinations are sensible. Parameters 777 /// can be one of { in, out, inout } with one of { bycopy, byref }. 778 /// Returns can either be { oneway } or not. 779 /// 780 /// This should be kept in sync with Decl::ObjCDeclQualifier. 781 enum ObjCDeclQualifier { 782 DQ_None = 0x0, 783 DQ_In = 0x1, 784 DQ_Inout = 0x2, 785 DQ_Out = 0x4, 786 DQ_Bycopy = 0x8, 787 DQ_Byref = 0x10, 788 DQ_Oneway = 0x20 789 }; 790 791 /// PropertyAttributeKind - list of property attributes. 792 enum ObjCPropertyAttributeKind { 793 DQ_PR_noattr = 0x0, 794 DQ_PR_readonly = 0x01, 795 DQ_PR_getter = 0x02, 796 DQ_PR_assign = 0x04, 797 DQ_PR_readwrite = 0x08, 798 DQ_PR_retain = 0x10, 799 DQ_PR_copy = 0x20, 800 DQ_PR_nonatomic = 0x40, 801 DQ_PR_setter = 0x80, 802 DQ_PR_atomic = 0x100, 803 DQ_PR_weak = 0x200, 804 DQ_PR_strong = 0x400, 805 DQ_PR_unsafe_unretained = 0x800 806 }; 807 808 ObjCDeclSpec()809 ObjCDeclSpec() 810 : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr), 811 GetterName(nullptr), SetterName(nullptr) { } getObjCDeclQualifier()812 ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; } setObjCDeclQualifier(ObjCDeclQualifier DQVal)813 void setObjCDeclQualifier(ObjCDeclQualifier DQVal) { 814 objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal); 815 } 816 getPropertyAttributes()817 ObjCPropertyAttributeKind getPropertyAttributes() const { 818 return ObjCPropertyAttributeKind(PropertyAttributes); 819 } setPropertyAttributes(ObjCPropertyAttributeKind PRVal)820 void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) { 821 PropertyAttributes = 822 (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal); 823 } 824 getGetterName()825 const IdentifierInfo *getGetterName() const { return GetterName; } getGetterName()826 IdentifierInfo *getGetterName() { return GetterName; } setGetterName(IdentifierInfo * name)827 void setGetterName(IdentifierInfo *name) { GetterName = name; } 828 getSetterName()829 const IdentifierInfo *getSetterName() const { return SetterName; } getSetterName()830 IdentifierInfo *getSetterName() { return SetterName; } setSetterName(IdentifierInfo * name)831 void setSetterName(IdentifierInfo *name) { SetterName = name; } 832 833 private: 834 // FIXME: These two are unrelated and mutually exclusive. So perhaps 835 // we can put them in a union to reflect their mutual exclusivity 836 // (space saving is negligible). 837 ObjCDeclQualifier objcDeclQualifier : 6; 838 839 // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind 840 unsigned PropertyAttributes : 12; 841 IdentifierInfo *GetterName; // getter name or NULL if no getter 842 IdentifierInfo *SetterName; // setter name or NULL if no setter 843 }; 844 845 /// \brief Represents a C++ unqualified-id that has been parsed. 846 class UnqualifiedId { 847 private: 848 UnqualifiedId(const UnqualifiedId &Other) = delete; 849 const UnqualifiedId &operator=(const UnqualifiedId &) = delete; 850 851 public: 852 /// \brief Describes the kind of unqualified-id parsed. 853 enum IdKind { 854 /// \brief An identifier. 855 IK_Identifier, 856 /// \brief An overloaded operator name, e.g., operator+. 857 IK_OperatorFunctionId, 858 /// \brief A conversion function name, e.g., operator int. 859 IK_ConversionFunctionId, 860 /// \brief A user-defined literal name, e.g., operator "" _i. 861 IK_LiteralOperatorId, 862 /// \brief A constructor name. 863 IK_ConstructorName, 864 /// \brief A constructor named via a template-id. 865 IK_ConstructorTemplateId, 866 /// \brief A destructor name. 867 IK_DestructorName, 868 /// \brief A template-id, e.g., f<int>. 869 IK_TemplateId, 870 /// \brief An implicit 'self' parameter 871 IK_ImplicitSelfParam 872 } Kind; 873 874 struct OFI { 875 /// \brief The kind of overloaded operator. 876 OverloadedOperatorKind Operator; 877 878 /// \brief The source locations of the individual tokens that name 879 /// the operator, e.g., the "new", "[", and "]" tokens in 880 /// operator new []. 881 /// 882 /// Different operators have different numbers of tokens in their name, 883 /// up to three. Any remaining source locations in this array will be 884 /// set to an invalid value for operators with fewer than three tokens. 885 unsigned SymbolLocations[3]; 886 }; 887 888 /// \brief Anonymous union that holds extra data associated with the 889 /// parsed unqualified-id. 890 union { 891 /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind 892 /// == IK_UserLiteralId, the identifier suffix. 893 IdentifierInfo *Identifier; 894 895 /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator 896 /// that we parsed. 897 struct OFI OperatorFunctionId; 898 899 /// \brief When Kind == IK_ConversionFunctionId, the type that the 900 /// conversion function names. 901 UnionParsedType ConversionFunctionId; 902 903 /// \brief When Kind == IK_ConstructorName, the class-name of the type 904 /// whose constructor is being referenced. 905 UnionParsedType ConstructorName; 906 907 /// \brief When Kind == IK_DestructorName, the type referred to by the 908 /// class-name. 909 UnionParsedType DestructorName; 910 911 /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId, 912 /// the template-id annotation that contains the template name and 913 /// template arguments. 914 TemplateIdAnnotation *TemplateId; 915 }; 916 917 /// \brief The location of the first token that describes this unqualified-id, 918 /// which will be the location of the identifier, "operator" keyword, 919 /// tilde (for a destructor), or the template name of a template-id. 920 SourceLocation StartLocation; 921 922 /// \brief The location of the last token that describes this unqualified-id. 923 SourceLocation EndLocation; 924 UnqualifiedId()925 UnqualifiedId() : Kind(IK_Identifier), Identifier(nullptr) { } 926 927 /// \brief Clear out this unqualified-id, setting it to default (invalid) 928 /// state. clear()929 void clear() { 930 Kind = IK_Identifier; 931 Identifier = nullptr; 932 StartLocation = SourceLocation(); 933 EndLocation = SourceLocation(); 934 } 935 936 /// \brief Determine whether this unqualified-id refers to a valid name. isValid()937 bool isValid() const { return StartLocation.isValid(); } 938 939 /// \brief Determine whether this unqualified-id refers to an invalid name. isInvalid()940 bool isInvalid() const { return !isValid(); } 941 942 /// \brief Determine what kind of name we have. getKind()943 IdKind getKind() const { return Kind; } setKind(IdKind kind)944 void setKind(IdKind kind) { Kind = kind; } 945 946 /// \brief Specify that this unqualified-id was parsed as an identifier. 947 /// 948 /// \param Id the parsed identifier. 949 /// \param IdLoc the location of the parsed identifier. setIdentifier(const IdentifierInfo * Id,SourceLocation IdLoc)950 void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { 951 Kind = IK_Identifier; 952 Identifier = const_cast<IdentifierInfo *>(Id); 953 StartLocation = EndLocation = IdLoc; 954 } 955 956 /// \brief Specify that this unqualified-id was parsed as an 957 /// operator-function-id. 958 /// 959 /// \param OperatorLoc the location of the 'operator' keyword. 960 /// 961 /// \param Op the overloaded operator. 962 /// 963 /// \param SymbolLocations the locations of the individual operator symbols 964 /// in the operator. 965 void setOperatorFunctionId(SourceLocation OperatorLoc, 966 OverloadedOperatorKind Op, 967 SourceLocation SymbolLocations[3]); 968 969 /// \brief Specify that this unqualified-id was parsed as a 970 /// conversion-function-id. 971 /// 972 /// \param OperatorLoc the location of the 'operator' keyword. 973 /// 974 /// \param Ty the type to which this conversion function is converting. 975 /// 976 /// \param EndLoc the location of the last token that makes up the type name. setConversionFunctionId(SourceLocation OperatorLoc,ParsedType Ty,SourceLocation EndLoc)977 void setConversionFunctionId(SourceLocation OperatorLoc, 978 ParsedType Ty, 979 SourceLocation EndLoc) { 980 Kind = IK_ConversionFunctionId; 981 StartLocation = OperatorLoc; 982 EndLocation = EndLoc; 983 ConversionFunctionId = Ty; 984 } 985 986 /// \brief Specific that this unqualified-id was parsed as a 987 /// literal-operator-id. 988 /// 989 /// \param Id the parsed identifier. 990 /// 991 /// \param OpLoc the location of the 'operator' keyword. 992 /// 993 /// \param IdLoc the location of the identifier. setLiteralOperatorId(const IdentifierInfo * Id,SourceLocation OpLoc,SourceLocation IdLoc)994 void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, 995 SourceLocation IdLoc) { 996 Kind = IK_LiteralOperatorId; 997 Identifier = const_cast<IdentifierInfo *>(Id); 998 StartLocation = OpLoc; 999 EndLocation = IdLoc; 1000 } 1001 1002 /// \brief Specify that this unqualified-id was parsed as a constructor name. 1003 /// 1004 /// \param ClassType the class type referred to by the constructor name. 1005 /// 1006 /// \param ClassNameLoc the location of the class name. 1007 /// 1008 /// \param EndLoc the location of the last token that makes up the type name. setConstructorName(ParsedType ClassType,SourceLocation ClassNameLoc,SourceLocation EndLoc)1009 void setConstructorName(ParsedType ClassType, 1010 SourceLocation ClassNameLoc, 1011 SourceLocation EndLoc) { 1012 Kind = IK_ConstructorName; 1013 StartLocation = ClassNameLoc; 1014 EndLocation = EndLoc; 1015 ConstructorName = ClassType; 1016 } 1017 1018 /// \brief Specify that this unqualified-id was parsed as a 1019 /// template-id that names a constructor. 1020 /// 1021 /// \param TemplateId the template-id annotation that describes the parsed 1022 /// template-id. This UnqualifiedId instance will take ownership of the 1023 /// \p TemplateId and will free it on destruction. 1024 void setConstructorTemplateId(TemplateIdAnnotation *TemplateId); 1025 1026 /// \brief Specify that this unqualified-id was parsed as a destructor name. 1027 /// 1028 /// \param TildeLoc the location of the '~' that introduces the destructor 1029 /// name. 1030 /// 1031 /// \param ClassType the name of the class referred to by the destructor name. setDestructorName(SourceLocation TildeLoc,ParsedType ClassType,SourceLocation EndLoc)1032 void setDestructorName(SourceLocation TildeLoc, 1033 ParsedType ClassType, 1034 SourceLocation EndLoc) { 1035 Kind = IK_DestructorName; 1036 StartLocation = TildeLoc; 1037 EndLocation = EndLoc; 1038 DestructorName = ClassType; 1039 } 1040 1041 /// \brief Specify that this unqualified-id was parsed as a template-id. 1042 /// 1043 /// \param TemplateId the template-id annotation that describes the parsed 1044 /// template-id. This UnqualifiedId instance will take ownership of the 1045 /// \p TemplateId and will free it on destruction. 1046 void setTemplateId(TemplateIdAnnotation *TemplateId); 1047 1048 /// \brief Return the source range that covers this unqualified-id. getSourceRange()1049 SourceRange getSourceRange() const LLVM_READONLY { 1050 return SourceRange(StartLocation, EndLocation); 1051 } getLocStart()1052 SourceLocation getLocStart() const LLVM_READONLY { return StartLocation; } getLocEnd()1053 SourceLocation getLocEnd() const LLVM_READONLY { return EndLocation; } 1054 }; 1055 1056 /// \brief A set of tokens that has been cached for later parsing. 1057 typedef SmallVector<Token, 4> CachedTokens; 1058 1059 /// \brief One instance of this struct is used for each type in a 1060 /// declarator that is parsed. 1061 /// 1062 /// This is intended to be a small value object. 1063 struct DeclaratorChunk { 1064 enum { 1065 Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren 1066 } Kind; 1067 1068 /// Loc - The place where this type was defined. 1069 SourceLocation Loc; 1070 /// EndLoc - If valid, the place where this chunck ends. 1071 SourceLocation EndLoc; 1072 getSourceRangeDeclaratorChunk1073 SourceRange getSourceRange() const { 1074 if (EndLoc.isInvalid()) 1075 return SourceRange(Loc, Loc); 1076 return SourceRange(Loc, EndLoc); 1077 } 1078 1079 struct TypeInfoCommon { 1080 AttributeList *AttrList; 1081 }; 1082 1083 struct PointerTypeInfo : TypeInfoCommon { 1084 /// The type qualifiers: const/volatile/restrict/atomic. 1085 unsigned TypeQuals : 4; 1086 1087 /// The location of the const-qualifier, if any. 1088 unsigned ConstQualLoc; 1089 1090 /// The location of the volatile-qualifier, if any. 1091 unsigned VolatileQualLoc; 1092 1093 /// The location of the restrict-qualifier, if any. 1094 unsigned RestrictQualLoc; 1095 1096 /// The location of the _Atomic-qualifier, if any. 1097 unsigned AtomicQualLoc; 1098 destroyDeclaratorChunk::PointerTypeInfo1099 void destroy() { 1100 } 1101 }; 1102 1103 struct ReferenceTypeInfo : TypeInfoCommon { 1104 /// The type qualifier: restrict. [GNU] C++ extension 1105 bool HasRestrict : 1; 1106 /// True if this is an lvalue reference, false if it's an rvalue reference. 1107 bool LValueRef : 1; destroyDeclaratorChunk::ReferenceTypeInfo1108 void destroy() { 1109 } 1110 }; 1111 1112 struct ArrayTypeInfo : TypeInfoCommon { 1113 /// The type qualifiers for the array: const/volatile/restrict/_Atomic. 1114 unsigned TypeQuals : 4; 1115 1116 /// True if this dimension included the 'static' keyword. 1117 bool hasStatic : 1; 1118 1119 /// True if this dimension was [*]. In this case, NumElts is null. 1120 bool isStar : 1; 1121 1122 /// This is the size of the array, or null if [] or [*] was specified. 1123 /// Since the parser is multi-purpose, and we don't want to impose a root 1124 /// expression class on all clients, NumElts is untyped. 1125 Expr *NumElts; 1126 destroyDeclaratorChunk::ArrayTypeInfo1127 void destroy() {} 1128 }; 1129 1130 /// ParamInfo - An array of paraminfo objects is allocated whenever a function 1131 /// declarator is parsed. There are two interesting styles of parameters 1132 /// here: 1133 /// K&R-style identifier lists and parameter type lists. K&R-style identifier 1134 /// lists will have information about the identifier, but no type information. 1135 /// Parameter type lists will have type info (if the actions module provides 1136 /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'. 1137 struct ParamInfo { 1138 IdentifierInfo *Ident; 1139 SourceLocation IdentLoc; 1140 Decl *Param; 1141 1142 /// DefaultArgTokens - When the parameter's default argument 1143 /// cannot be parsed immediately (because it occurs within the 1144 /// declaration of a member function), it will be stored here as a 1145 /// sequence of tokens to be parsed once the class definition is 1146 /// complete. Non-NULL indicates that there is a default argument. 1147 CachedTokens *DefaultArgTokens; 1148 ParamInfoDeclaratorChunk::ParamInfo1149 ParamInfo() {} 1150 ParamInfo(IdentifierInfo *ident, SourceLocation iloc, 1151 Decl *param, 1152 CachedTokens *DefArgTokens = nullptr) IdentDeclaratorChunk::ParamInfo1153 : Ident(ident), IdentLoc(iloc), Param(param), 1154 DefaultArgTokens(DefArgTokens) {} 1155 }; 1156 1157 struct TypeAndRange { 1158 ParsedType Ty; 1159 SourceRange Range; 1160 }; 1161 1162 struct FunctionTypeInfo : TypeInfoCommon { 1163 /// hasPrototype - This is true if the function had at least one typed 1164 /// parameter. If the function is () or (a,b,c), then it has no prototype, 1165 /// and is treated as a K&R-style function. 1166 unsigned hasPrototype : 1; 1167 1168 /// isVariadic - If this function has a prototype, and if that 1169 /// proto ends with ',...)', this is true. When true, EllipsisLoc 1170 /// contains the location of the ellipsis. 1171 unsigned isVariadic : 1; 1172 1173 /// Can this declaration be a constructor-style initializer? 1174 unsigned isAmbiguous : 1; 1175 1176 /// \brief Whether the ref-qualifier (if any) is an lvalue reference. 1177 /// Otherwise, it's an rvalue reference. 1178 unsigned RefQualifierIsLValueRef : 1; 1179 1180 /// The type qualifiers: const/volatile/restrict. 1181 /// The qualifier bitmask values are the same as in QualType. 1182 unsigned TypeQuals : 3; 1183 1184 /// ExceptionSpecType - An ExceptionSpecificationType value. 1185 unsigned ExceptionSpecType : 4; 1186 1187 /// DeleteParams - If this is true, we need to delete[] Params. 1188 unsigned DeleteParams : 1; 1189 1190 /// HasTrailingReturnType - If this is true, a trailing return type was 1191 /// specified. 1192 unsigned HasTrailingReturnType : 1; 1193 1194 /// The location of the left parenthesis in the source. 1195 unsigned LParenLoc; 1196 1197 /// When isVariadic is true, the location of the ellipsis in the source. 1198 unsigned EllipsisLoc; 1199 1200 /// The location of the right parenthesis in the source. 1201 unsigned RParenLoc; 1202 1203 /// NumParams - This is the number of formal parameters specified by the 1204 /// declarator. 1205 unsigned NumParams; 1206 1207 /// NumExceptions - This is the number of types in the dynamic-exception- 1208 /// decl, if the function has one. 1209 unsigned NumExceptions; 1210 1211 /// \brief The location of the ref-qualifier, if any. 1212 /// 1213 /// If this is an invalid location, there is no ref-qualifier. 1214 unsigned RefQualifierLoc; 1215 1216 /// \brief The location of the const-qualifier, if any. 1217 /// 1218 /// If this is an invalid location, there is no const-qualifier. 1219 unsigned ConstQualifierLoc; 1220 1221 /// \brief The location of the volatile-qualifier, if any. 1222 /// 1223 /// If this is an invalid location, there is no volatile-qualifier. 1224 unsigned VolatileQualifierLoc; 1225 1226 /// \brief The location of the restrict-qualifier, if any. 1227 /// 1228 /// If this is an invalid location, there is no restrict-qualifier. 1229 unsigned RestrictQualifierLoc; 1230 1231 /// \brief The location of the 'mutable' qualifer in a lambda-declarator, if 1232 /// any. 1233 unsigned MutableLoc; 1234 1235 /// \brief The location of the keyword introducing the spec, if any. 1236 unsigned ExceptionSpecLoc; 1237 1238 /// Params - This is a pointer to a new[]'d array of ParamInfo objects that 1239 /// describe the parameters specified by this function declarator. null if 1240 /// there are no parameters specified. 1241 ParamInfo *Params; 1242 1243 union { 1244 /// \brief Pointer to a new[]'d array of TypeAndRange objects that 1245 /// contain the types in the function's dynamic exception specification 1246 /// and their locations, if there is one. 1247 TypeAndRange *Exceptions; 1248 1249 /// \brief Pointer to the expression in the noexcept-specifier of this 1250 /// function, if it has one. 1251 Expr *NoexceptExpr; 1252 1253 /// \brief Pointer to the cached tokens for an exception-specification 1254 /// that has not yet been parsed. 1255 CachedTokens *ExceptionSpecTokens; 1256 }; 1257 1258 /// \brief If HasTrailingReturnType is true, this is the trailing return 1259 /// type specified. 1260 UnionParsedType TrailingReturnType; 1261 1262 /// \brief Reset the parameter list to having zero parameters. 1263 /// 1264 /// This is used in various places for error recovery. freeParamsDeclaratorChunk::FunctionTypeInfo1265 void freeParams() { 1266 for (unsigned I = 0; I < NumParams; ++I) { 1267 delete Params[I].DefaultArgTokens; 1268 Params[I].DefaultArgTokens = nullptr; 1269 } 1270 if (DeleteParams) { 1271 delete[] Params; 1272 DeleteParams = false; 1273 } 1274 NumParams = 0; 1275 } 1276 destroyDeclaratorChunk::FunctionTypeInfo1277 void destroy() { 1278 if (DeleteParams) 1279 delete[] Params; 1280 if (getExceptionSpecType() == EST_Dynamic) 1281 delete[] Exceptions; 1282 else if (getExceptionSpecType() == EST_Unparsed) 1283 delete ExceptionSpecTokens; 1284 } 1285 1286 /// isKNRPrototype - Return true if this is a K&R style identifier list, 1287 /// like "void foo(a,b,c)". In a function definition, this will be followed 1288 /// by the parameter type definitions. isKNRPrototypeDeclaratorChunk::FunctionTypeInfo1289 bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; } 1290 getLParenLocDeclaratorChunk::FunctionTypeInfo1291 SourceLocation getLParenLoc() const { 1292 return SourceLocation::getFromRawEncoding(LParenLoc); 1293 } 1294 getEllipsisLocDeclaratorChunk::FunctionTypeInfo1295 SourceLocation getEllipsisLoc() const { 1296 return SourceLocation::getFromRawEncoding(EllipsisLoc); 1297 } 1298 getRParenLocDeclaratorChunk::FunctionTypeInfo1299 SourceLocation getRParenLoc() const { 1300 return SourceLocation::getFromRawEncoding(RParenLoc); 1301 } 1302 getExceptionSpecLocDeclaratorChunk::FunctionTypeInfo1303 SourceLocation getExceptionSpecLoc() const { 1304 return SourceLocation::getFromRawEncoding(ExceptionSpecLoc); 1305 } 1306 1307 /// \brief Retrieve the location of the ref-qualifier, if any. getRefQualifierLocDeclaratorChunk::FunctionTypeInfo1308 SourceLocation getRefQualifierLoc() const { 1309 return SourceLocation::getFromRawEncoding(RefQualifierLoc); 1310 } 1311 1312 /// \brief Retrieve the location of the 'const' qualifier, if any. getConstQualifierLocDeclaratorChunk::FunctionTypeInfo1313 SourceLocation getConstQualifierLoc() const { 1314 return SourceLocation::getFromRawEncoding(ConstQualifierLoc); 1315 } 1316 1317 /// \brief Retrieve the location of the 'volatile' qualifier, if any. getVolatileQualifierLocDeclaratorChunk::FunctionTypeInfo1318 SourceLocation getVolatileQualifierLoc() const { 1319 return SourceLocation::getFromRawEncoding(VolatileQualifierLoc); 1320 } 1321 1322 /// \brief Retrieve the location of the 'restrict' qualifier, if any. getRestrictQualifierLocDeclaratorChunk::FunctionTypeInfo1323 SourceLocation getRestrictQualifierLoc() const { 1324 return SourceLocation::getFromRawEncoding(RestrictQualifierLoc); 1325 } 1326 1327 /// \brief Retrieve the location of the 'mutable' qualifier, if any. getMutableLocDeclaratorChunk::FunctionTypeInfo1328 SourceLocation getMutableLoc() const { 1329 return SourceLocation::getFromRawEncoding(MutableLoc); 1330 } 1331 1332 /// \brief Determine whether this function declaration contains a 1333 /// ref-qualifier. hasRefQualifierDeclaratorChunk::FunctionTypeInfo1334 bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); } 1335 1336 /// \brief Determine whether this lambda-declarator contains a 'mutable' 1337 /// qualifier. hasMutableQualifierDeclaratorChunk::FunctionTypeInfo1338 bool hasMutableQualifier() const { return getMutableLoc().isValid(); } 1339 1340 /// \brief Get the type of exception specification this function has. getExceptionSpecTypeDeclaratorChunk::FunctionTypeInfo1341 ExceptionSpecificationType getExceptionSpecType() const { 1342 return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 1343 } 1344 1345 /// \brief Determine whether this function declarator had a 1346 /// trailing-return-type. hasTrailingReturnTypeDeclaratorChunk::FunctionTypeInfo1347 bool hasTrailingReturnType() const { return HasTrailingReturnType; } 1348 1349 /// \brief Get the trailing-return-type for this function declarator. getTrailingReturnTypeDeclaratorChunk::FunctionTypeInfo1350 ParsedType getTrailingReturnType() const { return TrailingReturnType; } 1351 }; 1352 1353 struct BlockPointerTypeInfo : TypeInfoCommon { 1354 /// For now, sema will catch these as invalid. 1355 /// The type qualifiers: const/volatile/restrict/_Atomic. 1356 unsigned TypeQuals : 4; 1357 destroyDeclaratorChunk::BlockPointerTypeInfo1358 void destroy() { 1359 } 1360 }; 1361 1362 struct MemberPointerTypeInfo : TypeInfoCommon { 1363 /// The type qualifiers: const/volatile/restrict/_Atomic. 1364 unsigned TypeQuals : 4; 1365 // CXXScopeSpec has a constructor, so it can't be a direct member. 1366 // So we need some pointer-aligned storage and a bit of trickery. 1367 union { 1368 void *Aligner; 1369 char Mem[sizeof(CXXScopeSpec)]; 1370 } ScopeMem; ScopeDeclaratorChunk::MemberPointerTypeInfo1371 CXXScopeSpec &Scope() { 1372 return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem); 1373 } ScopeDeclaratorChunk::MemberPointerTypeInfo1374 const CXXScopeSpec &Scope() const { 1375 return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem); 1376 } destroyDeclaratorChunk::MemberPointerTypeInfo1377 void destroy() { 1378 Scope().~CXXScopeSpec(); 1379 } 1380 }; 1381 1382 union { 1383 TypeInfoCommon Common; 1384 PointerTypeInfo Ptr; 1385 ReferenceTypeInfo Ref; 1386 ArrayTypeInfo Arr; 1387 FunctionTypeInfo Fun; 1388 BlockPointerTypeInfo Cls; 1389 MemberPointerTypeInfo Mem; 1390 }; 1391 destroyDeclaratorChunk1392 void destroy() { 1393 switch (Kind) { 1394 case DeclaratorChunk::Function: return Fun.destroy(); 1395 case DeclaratorChunk::Pointer: return Ptr.destroy(); 1396 case DeclaratorChunk::BlockPointer: return Cls.destroy(); 1397 case DeclaratorChunk::Reference: return Ref.destroy(); 1398 case DeclaratorChunk::Array: return Arr.destroy(); 1399 case DeclaratorChunk::MemberPointer: return Mem.destroy(); 1400 case DeclaratorChunk::Paren: return; 1401 } 1402 } 1403 1404 /// \brief If there are attributes applied to this declaratorchunk, return 1405 /// them. getAttrsDeclaratorChunk1406 const AttributeList *getAttrs() const { 1407 return Common.AttrList; 1408 } 1409 getAttrListRefDeclaratorChunk1410 AttributeList *&getAttrListRef() { 1411 return Common.AttrList; 1412 } 1413 1414 /// \brief Return a DeclaratorChunk for a pointer. getPointerDeclaratorChunk1415 static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, 1416 SourceLocation ConstQualLoc, 1417 SourceLocation VolatileQualLoc, 1418 SourceLocation RestrictQualLoc, 1419 SourceLocation AtomicQualLoc) { 1420 DeclaratorChunk I; 1421 I.Kind = Pointer; 1422 I.Loc = Loc; 1423 I.Ptr.TypeQuals = TypeQuals; 1424 I.Ptr.ConstQualLoc = ConstQualLoc.getRawEncoding(); 1425 I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding(); 1426 I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding(); 1427 I.Ptr.AtomicQualLoc = AtomicQualLoc.getRawEncoding(); 1428 I.Ptr.AttrList = nullptr; 1429 return I; 1430 } 1431 1432 /// \brief Return a DeclaratorChunk for a reference. getReferenceDeclaratorChunk1433 static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, 1434 bool lvalue) { 1435 DeclaratorChunk I; 1436 I.Kind = Reference; 1437 I.Loc = Loc; 1438 I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0; 1439 I.Ref.LValueRef = lvalue; 1440 I.Ref.AttrList = nullptr; 1441 return I; 1442 } 1443 1444 /// \brief Return a DeclaratorChunk for an array. getArrayDeclaratorChunk1445 static DeclaratorChunk getArray(unsigned TypeQuals, 1446 bool isStatic, bool isStar, Expr *NumElts, 1447 SourceLocation LBLoc, SourceLocation RBLoc) { 1448 DeclaratorChunk I; 1449 I.Kind = Array; 1450 I.Loc = LBLoc; 1451 I.EndLoc = RBLoc; 1452 I.Arr.AttrList = nullptr; 1453 I.Arr.TypeQuals = TypeQuals; 1454 I.Arr.hasStatic = isStatic; 1455 I.Arr.isStar = isStar; 1456 I.Arr.NumElts = NumElts; 1457 return I; 1458 } 1459 1460 /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. 1461 /// "TheDeclarator" is the declarator that this will be added to. 1462 static DeclaratorChunk getFunction(bool HasProto, 1463 bool IsAmbiguous, 1464 SourceLocation LParenLoc, 1465 ParamInfo *Params, unsigned NumParams, 1466 SourceLocation EllipsisLoc, 1467 SourceLocation RParenLoc, 1468 unsigned TypeQuals, 1469 bool RefQualifierIsLvalueRef, 1470 SourceLocation RefQualifierLoc, 1471 SourceLocation ConstQualifierLoc, 1472 SourceLocation VolatileQualifierLoc, 1473 SourceLocation RestrictQualifierLoc, 1474 SourceLocation MutableLoc, 1475 ExceptionSpecificationType ESpecType, 1476 SourceLocation ESpecLoc, 1477 ParsedType *Exceptions, 1478 SourceRange *ExceptionRanges, 1479 unsigned NumExceptions, 1480 Expr *NoexceptExpr, 1481 CachedTokens *ExceptionSpecTokens, 1482 SourceLocation LocalRangeBegin, 1483 SourceLocation LocalRangeEnd, 1484 Declarator &TheDeclarator, 1485 TypeResult TrailingReturnType = 1486 TypeResult()); 1487 1488 /// \brief Return a DeclaratorChunk for a block. getBlockPointerDeclaratorChunk1489 static DeclaratorChunk getBlockPointer(unsigned TypeQuals, 1490 SourceLocation Loc) { 1491 DeclaratorChunk I; 1492 I.Kind = BlockPointer; 1493 I.Loc = Loc; 1494 I.Cls.TypeQuals = TypeQuals; 1495 I.Cls.AttrList = nullptr; 1496 return I; 1497 } 1498 getMemberPointerDeclaratorChunk1499 static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, 1500 unsigned TypeQuals, 1501 SourceLocation Loc) { 1502 DeclaratorChunk I; 1503 I.Kind = MemberPointer; 1504 I.Loc = SS.getBeginLoc(); 1505 I.EndLoc = Loc; 1506 I.Mem.TypeQuals = TypeQuals; 1507 I.Mem.AttrList = nullptr; 1508 new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS); 1509 return I; 1510 } 1511 1512 /// \brief Return a DeclaratorChunk for a paren. getParenDeclaratorChunk1513 static DeclaratorChunk getParen(SourceLocation LParenLoc, 1514 SourceLocation RParenLoc) { 1515 DeclaratorChunk I; 1516 I.Kind = Paren; 1517 I.Loc = LParenLoc; 1518 I.EndLoc = RParenLoc; 1519 I.Common.AttrList = nullptr; 1520 return I; 1521 } 1522 isParenDeclaratorChunk1523 bool isParen() const { 1524 return Kind == Paren; 1525 } 1526 }; 1527 1528 /// \brief Described the kind of function definition (if any) provided for 1529 /// a function. 1530 enum FunctionDefinitionKind { 1531 FDK_Declaration, 1532 FDK_Definition, 1533 FDK_Defaulted, 1534 FDK_Deleted 1535 }; 1536 1537 /// \brief Information about one declarator, including the parsed type 1538 /// information and the identifier. 1539 /// 1540 /// When the declarator is fully formed, this is turned into the appropriate 1541 /// Decl object. 1542 /// 1543 /// Declarators come in two types: normal declarators and abstract declarators. 1544 /// Abstract declarators are used when parsing types, and don't have an 1545 /// identifier. Normal declarators do have ID's. 1546 /// 1547 /// Instances of this class should be a transient object that lives on the 1548 /// stack, not objects that are allocated in large quantities on the heap. 1549 class Declarator { 1550 public: 1551 enum TheContext { 1552 FileContext, // File scope declaration. 1553 PrototypeContext, // Within a function prototype. 1554 ObjCResultContext, // An ObjC method result type. 1555 ObjCParameterContext,// An ObjC method parameter type. 1556 KNRTypeListContext, // K&R type definition list for formals. 1557 TypeNameContext, // Abstract declarator for types. 1558 MemberContext, // Struct/Union field. 1559 BlockContext, // Declaration within a block in a function. 1560 ForContext, // Declaration within first part of a for loop. 1561 ConditionContext, // Condition declaration in a C++ if/switch/while/for. 1562 TemplateParamContext,// Within a template parameter list. 1563 CXXNewContext, // C++ new-expression. 1564 CXXCatchContext, // C++ catch exception-declaration 1565 ObjCCatchContext, // Objective-C catch exception-declaration 1566 BlockLiteralContext, // Block literal declarator. 1567 LambdaExprContext, // Lambda-expression declarator. 1568 LambdaExprParameterContext, // Lambda-expression parameter declarator. 1569 ConversionIdContext, // C++ conversion-type-id. 1570 TrailingReturnContext, // C++11 trailing-type-specifier. 1571 TemplateTypeArgContext, // Template type argument. 1572 AliasDeclContext, // C++11 alias-declaration. 1573 AliasTemplateContext // C++11 alias-declaration template. 1574 }; 1575 1576 private: 1577 const DeclSpec &DS; 1578 CXXScopeSpec SS; 1579 UnqualifiedId Name; 1580 SourceRange Range; 1581 1582 /// \brief Where we are parsing this declarator. 1583 TheContext Context; 1584 1585 /// DeclTypeInfo - This holds each type that the declarator includes as it is 1586 /// parsed. This is pushed from the identifier out, which means that element 1587 /// #0 will be the most closely bound to the identifier, and 1588 /// DeclTypeInfo.back() will be the least closely bound. 1589 SmallVector<DeclaratorChunk, 8> DeclTypeInfo; 1590 1591 /// InvalidType - Set by Sema::GetTypeForDeclarator(). 1592 bool InvalidType : 1; 1593 1594 /// GroupingParens - Set by Parser::ParseParenDeclarator(). 1595 bool GroupingParens : 1; 1596 1597 /// FunctionDefinition - Is this Declarator for a function or member 1598 /// definition and, if so, what kind? 1599 /// 1600 /// Actually a FunctionDefinitionKind. 1601 unsigned FunctionDefinition : 2; 1602 1603 /// \brief Is this Declarator a redeclaration? 1604 bool Redeclaration : 1; 1605 1606 /// Attrs - Attributes. 1607 ParsedAttributes Attrs; 1608 1609 /// \brief The asm label, if specified. 1610 Expr *AsmLabel; 1611 1612 /// InlineParams - This is a local array used for the first function decl 1613 /// chunk to avoid going to the heap for the common case when we have one 1614 /// function chunk in the declarator. 1615 DeclaratorChunk::ParamInfo InlineParams[16]; 1616 bool InlineParamsUsed; 1617 1618 /// \brief true if the declaration is preceded by \c __extension__. 1619 bool Extension : 1; 1620 1621 /// \brief If this is the second or subsequent declarator in this declaration, 1622 /// the location of the comma before this declarator. 1623 SourceLocation CommaLoc; 1624 1625 /// \brief If provided, the source location of the ellipsis used to describe 1626 /// this declarator as a parameter pack. 1627 SourceLocation EllipsisLoc; 1628 1629 friend struct DeclaratorChunk; 1630 1631 public: Declarator(const DeclSpec & ds,TheContext C)1632 Declarator(const DeclSpec &ds, TheContext C) 1633 : DS(ds), Range(ds.getSourceRange()), Context(C), 1634 InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), 1635 GroupingParens(false), FunctionDefinition(FDK_Declaration), 1636 Redeclaration(false), 1637 Attrs(ds.getAttributePool().getFactory()), AsmLabel(nullptr), 1638 InlineParamsUsed(false), Extension(false) { 1639 } 1640 ~Declarator()1641 ~Declarator() { 1642 clear(); 1643 } 1644 /// getDeclSpec - Return the declaration-specifier that this declarator was 1645 /// declared with. getDeclSpec()1646 const DeclSpec &getDeclSpec() const { return DS; } 1647 1648 /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This 1649 /// should be used with extreme care: declspecs can often be shared between 1650 /// multiple declarators, so mutating the DeclSpec affects all of the 1651 /// Declarators. This should only be done when the declspec is known to not 1652 /// be shared or when in error recovery etc. getMutableDeclSpec()1653 DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); } 1654 getAttributePool()1655 AttributePool &getAttributePool() const { 1656 return Attrs.getPool(); 1657 } 1658 1659 /// getCXXScopeSpec - Return the C++ scope specifier (global scope or 1660 /// nested-name-specifier) that is part of the declarator-id. getCXXScopeSpec()1661 const CXXScopeSpec &getCXXScopeSpec() const { return SS; } getCXXScopeSpec()1662 CXXScopeSpec &getCXXScopeSpec() { return SS; } 1663 1664 /// \brief Retrieve the name specified by this declarator. getName()1665 UnqualifiedId &getName() { return Name; } 1666 getContext()1667 TheContext getContext() const { return Context; } 1668 isPrototypeContext()1669 bool isPrototypeContext() const { 1670 return (Context == PrototypeContext || 1671 Context == ObjCParameterContext || 1672 Context == ObjCResultContext || 1673 Context == LambdaExprParameterContext); 1674 } 1675 1676 /// \brief Get the source range that spans this declarator. getSourceRange()1677 const SourceRange &getSourceRange() const LLVM_READONLY { return Range; } getLocStart()1678 SourceLocation getLocStart() const LLVM_READONLY { return Range.getBegin(); } getLocEnd()1679 SourceLocation getLocEnd() const LLVM_READONLY { return Range.getEnd(); } 1680 SetSourceRange(SourceRange R)1681 void SetSourceRange(SourceRange R) { Range = R; } 1682 /// SetRangeBegin - Set the start of the source range to Loc, unless it's 1683 /// invalid. SetRangeBegin(SourceLocation Loc)1684 void SetRangeBegin(SourceLocation Loc) { 1685 if (!Loc.isInvalid()) 1686 Range.setBegin(Loc); 1687 } 1688 /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid. SetRangeEnd(SourceLocation Loc)1689 void SetRangeEnd(SourceLocation Loc) { 1690 if (!Loc.isInvalid()) 1691 Range.setEnd(Loc); 1692 } 1693 /// ExtendWithDeclSpec - Extend the declarator source range to include the 1694 /// given declspec, unless its location is invalid. Adopts the range start if 1695 /// the current range start is invalid. ExtendWithDeclSpec(const DeclSpec & DS)1696 void ExtendWithDeclSpec(const DeclSpec &DS) { 1697 const SourceRange &SR = DS.getSourceRange(); 1698 if (Range.getBegin().isInvalid()) 1699 Range.setBegin(SR.getBegin()); 1700 if (!SR.getEnd().isInvalid()) 1701 Range.setEnd(SR.getEnd()); 1702 } 1703 1704 /// \brief Reset the contents of this Declarator. clear()1705 void clear() { 1706 SS.clear(); 1707 Name.clear(); 1708 Range = DS.getSourceRange(); 1709 1710 for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i) 1711 DeclTypeInfo[i].destroy(); 1712 DeclTypeInfo.clear(); 1713 Attrs.clear(); 1714 AsmLabel = nullptr; 1715 InlineParamsUsed = false; 1716 CommaLoc = SourceLocation(); 1717 EllipsisLoc = SourceLocation(); 1718 } 1719 1720 /// mayOmitIdentifier - Return true if the identifier is either optional or 1721 /// not allowed. This is true for typenames, prototypes, and template 1722 /// parameter lists. mayOmitIdentifier()1723 bool mayOmitIdentifier() const { 1724 switch (Context) { 1725 case FileContext: 1726 case KNRTypeListContext: 1727 case MemberContext: 1728 case BlockContext: 1729 case ForContext: 1730 case ConditionContext: 1731 return false; 1732 1733 case TypeNameContext: 1734 case AliasDeclContext: 1735 case AliasTemplateContext: 1736 case PrototypeContext: 1737 case LambdaExprParameterContext: 1738 case ObjCParameterContext: 1739 case ObjCResultContext: 1740 case TemplateParamContext: 1741 case CXXNewContext: 1742 case CXXCatchContext: 1743 case ObjCCatchContext: 1744 case BlockLiteralContext: 1745 case LambdaExprContext: 1746 case ConversionIdContext: 1747 case TemplateTypeArgContext: 1748 case TrailingReturnContext: 1749 return true; 1750 } 1751 llvm_unreachable("unknown context kind!"); 1752 } 1753 1754 /// mayHaveIdentifier - Return true if the identifier is either optional or 1755 /// required. This is true for normal declarators and prototypes, but not 1756 /// typenames. mayHaveIdentifier()1757 bool mayHaveIdentifier() const { 1758 switch (Context) { 1759 case FileContext: 1760 case KNRTypeListContext: 1761 case MemberContext: 1762 case BlockContext: 1763 case ForContext: 1764 case ConditionContext: 1765 case PrototypeContext: 1766 case LambdaExprParameterContext: 1767 case TemplateParamContext: 1768 case CXXCatchContext: 1769 case ObjCCatchContext: 1770 return true; 1771 1772 case TypeNameContext: 1773 case CXXNewContext: 1774 case AliasDeclContext: 1775 case AliasTemplateContext: 1776 case ObjCParameterContext: 1777 case ObjCResultContext: 1778 case BlockLiteralContext: 1779 case LambdaExprContext: 1780 case ConversionIdContext: 1781 case TemplateTypeArgContext: 1782 case TrailingReturnContext: 1783 return false; 1784 } 1785 llvm_unreachable("unknown context kind!"); 1786 } 1787 1788 /// diagnoseIdentifier - Return true if the identifier is prohibited and 1789 /// should be diagnosed (because it cannot be anything else). diagnoseIdentifier()1790 bool diagnoseIdentifier() const { 1791 switch (Context) { 1792 case FileContext: 1793 case KNRTypeListContext: 1794 case MemberContext: 1795 case BlockContext: 1796 case ForContext: 1797 case ConditionContext: 1798 case PrototypeContext: 1799 case LambdaExprParameterContext: 1800 case TemplateParamContext: 1801 case CXXCatchContext: 1802 case ObjCCatchContext: 1803 case TypeNameContext: 1804 case ConversionIdContext: 1805 case ObjCParameterContext: 1806 case ObjCResultContext: 1807 case BlockLiteralContext: 1808 case CXXNewContext: 1809 case LambdaExprContext: 1810 return false; 1811 1812 case AliasDeclContext: 1813 case AliasTemplateContext: 1814 case TemplateTypeArgContext: 1815 case TrailingReturnContext: 1816 return true; 1817 } 1818 llvm_unreachable("unknown context kind!"); 1819 } 1820 1821 /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be 1822 /// followed by a C++ direct initializer, e.g. "int x(1);". mayBeFollowedByCXXDirectInit()1823 bool mayBeFollowedByCXXDirectInit() const { 1824 if (hasGroupingParens()) return false; 1825 1826 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 1827 return false; 1828 1829 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_extern && 1830 Context != FileContext) 1831 return false; 1832 1833 // Special names can't have direct initializers. 1834 if (Name.getKind() != UnqualifiedId::IK_Identifier) 1835 return false; 1836 1837 switch (Context) { 1838 case FileContext: 1839 case BlockContext: 1840 case ForContext: 1841 return true; 1842 1843 case ConditionContext: 1844 // This may not be followed by a direct initializer, but it can't be a 1845 // function declaration either, and we'd prefer to perform a tentative 1846 // parse in order to produce the right diagnostic. 1847 return true; 1848 1849 case KNRTypeListContext: 1850 case MemberContext: 1851 case PrototypeContext: 1852 case LambdaExprParameterContext: 1853 case ObjCParameterContext: 1854 case ObjCResultContext: 1855 case TemplateParamContext: 1856 case CXXCatchContext: 1857 case ObjCCatchContext: 1858 case TypeNameContext: 1859 case CXXNewContext: 1860 case AliasDeclContext: 1861 case AliasTemplateContext: 1862 case BlockLiteralContext: 1863 case LambdaExprContext: 1864 case ConversionIdContext: 1865 case TemplateTypeArgContext: 1866 case TrailingReturnContext: 1867 return false; 1868 } 1869 llvm_unreachable("unknown context kind!"); 1870 } 1871 1872 /// isPastIdentifier - Return true if we have parsed beyond the point where 1873 /// the isPastIdentifier()1874 bool isPastIdentifier() const { return Name.isValid(); } 1875 1876 /// hasName - Whether this declarator has a name, which might be an 1877 /// identifier (accessible via getIdentifier()) or some kind of 1878 /// special C++ name (constructor, destructor, etc.). hasName()1879 bool hasName() const { 1880 return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier; 1881 } 1882 getIdentifier()1883 IdentifierInfo *getIdentifier() const { 1884 if (Name.getKind() == UnqualifiedId::IK_Identifier) 1885 return Name.Identifier; 1886 1887 return nullptr; 1888 } getIdentifierLoc()1889 SourceLocation getIdentifierLoc() const { return Name.StartLocation; } 1890 1891 /// \brief Set the name of this declarator to be the given identifier. SetIdentifier(IdentifierInfo * Id,SourceLocation IdLoc)1892 void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) { 1893 Name.setIdentifier(Id, IdLoc); 1894 } 1895 1896 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 1897 /// EndLoc, which should be the last token of the chunk. AddTypeInfo(const DeclaratorChunk & TI,ParsedAttributes & attrs,SourceLocation EndLoc)1898 void AddTypeInfo(const DeclaratorChunk &TI, 1899 ParsedAttributes &attrs, 1900 SourceLocation EndLoc) { 1901 DeclTypeInfo.push_back(TI); 1902 DeclTypeInfo.back().getAttrListRef() = attrs.getList(); 1903 getAttributePool().takeAllFrom(attrs.getPool()); 1904 1905 if (!EndLoc.isInvalid()) 1906 SetRangeEnd(EndLoc); 1907 } 1908 1909 /// \brief Add a new innermost chunk to this declarator. AddInnermostTypeInfo(const DeclaratorChunk & TI)1910 void AddInnermostTypeInfo(const DeclaratorChunk &TI) { 1911 DeclTypeInfo.insert(DeclTypeInfo.begin(), TI); 1912 } 1913 1914 /// \brief Return the number of types applied to this declarator. getNumTypeObjects()1915 unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); } 1916 1917 /// Return the specified TypeInfo from this declarator. TypeInfo #0 is 1918 /// closest to the identifier. getTypeObject(unsigned i)1919 const DeclaratorChunk &getTypeObject(unsigned i) const { 1920 assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 1921 return DeclTypeInfo[i]; 1922 } getTypeObject(unsigned i)1923 DeclaratorChunk &getTypeObject(unsigned i) { 1924 assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 1925 return DeclTypeInfo[i]; 1926 } 1927 1928 typedef SmallVectorImpl<DeclaratorChunk>::const_iterator type_object_iterator; 1929 typedef llvm::iterator_range<type_object_iterator> type_object_range; 1930 1931 /// Returns the range of type objects, from the identifier outwards. type_objects()1932 type_object_range type_objects() const { 1933 return type_object_range(DeclTypeInfo.begin(), DeclTypeInfo.end()); 1934 } 1935 DropFirstTypeObject()1936 void DropFirstTypeObject() { 1937 assert(!DeclTypeInfo.empty() && "No type chunks to drop."); 1938 DeclTypeInfo.front().destroy(); 1939 DeclTypeInfo.erase(DeclTypeInfo.begin()); 1940 } 1941 1942 /// Return the innermost (closest to the declarator) chunk of this 1943 /// declarator that is not a parens chunk, or null if there are no 1944 /// non-parens chunks. getInnermostNonParenChunk()1945 const DeclaratorChunk *getInnermostNonParenChunk() const { 1946 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1947 if (!DeclTypeInfo[i].isParen()) 1948 return &DeclTypeInfo[i]; 1949 } 1950 return nullptr; 1951 } 1952 1953 /// Return the outermost (furthest from the declarator) chunk of 1954 /// this declarator that is not a parens chunk, or null if there are 1955 /// no non-parens chunks. getOutermostNonParenChunk()1956 const DeclaratorChunk *getOutermostNonParenChunk() const { 1957 for (unsigned i = DeclTypeInfo.size(), i_end = 0; i != i_end; --i) { 1958 if (!DeclTypeInfo[i-1].isParen()) 1959 return &DeclTypeInfo[i-1]; 1960 } 1961 return nullptr; 1962 } 1963 1964 /// isArrayOfUnknownBound - This method returns true if the declarator 1965 /// is a declarator for an array of unknown bound (looking through 1966 /// parentheses). isArrayOfUnknownBound()1967 bool isArrayOfUnknownBound() const { 1968 const DeclaratorChunk *chunk = getInnermostNonParenChunk(); 1969 return (chunk && chunk->Kind == DeclaratorChunk::Array && 1970 !chunk->Arr.NumElts); 1971 } 1972 1973 /// isFunctionDeclarator - This method returns true if the declarator 1974 /// is a function declarator (looking through parentheses). 1975 /// If true is returned, then the reference type parameter idx is 1976 /// assigned with the index of the declaration chunk. isFunctionDeclarator(unsigned & idx)1977 bool isFunctionDeclarator(unsigned& idx) const { 1978 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1979 switch (DeclTypeInfo[i].Kind) { 1980 case DeclaratorChunk::Function: 1981 idx = i; 1982 return true; 1983 case DeclaratorChunk::Paren: 1984 continue; 1985 case DeclaratorChunk::Pointer: 1986 case DeclaratorChunk::Reference: 1987 case DeclaratorChunk::Array: 1988 case DeclaratorChunk::BlockPointer: 1989 case DeclaratorChunk::MemberPointer: 1990 return false; 1991 } 1992 llvm_unreachable("Invalid type chunk"); 1993 } 1994 return false; 1995 } 1996 1997 /// isFunctionDeclarator - Once this declarator is fully parsed and formed, 1998 /// this method returns true if the identifier is a function declarator 1999 /// (looking through parentheses). isFunctionDeclarator()2000 bool isFunctionDeclarator() const { 2001 unsigned index; 2002 return isFunctionDeclarator(index); 2003 } 2004 2005 /// getFunctionTypeInfo - Retrieves the function type info object 2006 /// (looking through parentheses). getFunctionTypeInfo()2007 DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() { 2008 assert(isFunctionDeclarator() && "Not a function declarator!"); 2009 unsigned index = 0; 2010 isFunctionDeclarator(index); 2011 return DeclTypeInfo[index].Fun; 2012 } 2013 2014 /// getFunctionTypeInfo - Retrieves the function type info object 2015 /// (looking through parentheses). getFunctionTypeInfo()2016 const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const { 2017 return const_cast<Declarator*>(this)->getFunctionTypeInfo(); 2018 } 2019 2020 /// \brief Determine whether the declaration that will be produced from 2021 /// this declaration will be a function. 2022 /// 2023 /// A declaration can declare a function even if the declarator itself 2024 /// isn't a function declarator, if the type specifier refers to a function 2025 /// type. This routine checks for both cases. 2026 bool isDeclarationOfFunction() const; 2027 2028 /// \brief Return true if this declaration appears in a context where a 2029 /// function declarator would be a function declaration. isFunctionDeclarationContext()2030 bool isFunctionDeclarationContext() const { 2031 if (getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) 2032 return false; 2033 2034 switch (Context) { 2035 case FileContext: 2036 case MemberContext: 2037 case BlockContext: 2038 return true; 2039 2040 case ForContext: 2041 case ConditionContext: 2042 case KNRTypeListContext: 2043 case TypeNameContext: 2044 case AliasDeclContext: 2045 case AliasTemplateContext: 2046 case PrototypeContext: 2047 case LambdaExprParameterContext: 2048 case ObjCParameterContext: 2049 case ObjCResultContext: 2050 case TemplateParamContext: 2051 case CXXNewContext: 2052 case CXXCatchContext: 2053 case ObjCCatchContext: 2054 case BlockLiteralContext: 2055 case LambdaExprContext: 2056 case ConversionIdContext: 2057 case TemplateTypeArgContext: 2058 case TrailingReturnContext: 2059 return false; 2060 } 2061 llvm_unreachable("unknown context kind!"); 2062 } 2063 2064 /// \brief Return true if a function declarator at this position would be a 2065 /// function declaration. isFunctionDeclaratorAFunctionDeclaration()2066 bool isFunctionDeclaratorAFunctionDeclaration() const { 2067 if (!isFunctionDeclarationContext()) 2068 return false; 2069 2070 for (unsigned I = 0, N = getNumTypeObjects(); I != N; ++I) 2071 if (getTypeObject(I).Kind != DeclaratorChunk::Paren) 2072 return false; 2073 2074 return true; 2075 } 2076 2077 /// takeAttributes - Takes attributes from the given parsed-attributes 2078 /// set and add them to this declarator. 2079 /// 2080 /// These examples both add 3 attributes to "var": 2081 /// short int var __attribute__((aligned(16),common,deprecated)); 2082 /// short int x, __attribute__((aligned(16)) var 2083 /// __attribute__((common,deprecated)); 2084 /// 2085 /// Also extends the range of the declarator. takeAttributes(ParsedAttributes & attrs,SourceLocation lastLoc)2086 void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) { 2087 Attrs.takeAllFrom(attrs); 2088 2089 if (!lastLoc.isInvalid()) 2090 SetRangeEnd(lastLoc); 2091 } 2092 getAttributes()2093 const AttributeList *getAttributes() const { return Attrs.getList(); } getAttributes()2094 AttributeList *getAttributes() { return Attrs.getList(); } 2095 getAttrListRef()2096 AttributeList *&getAttrListRef() { return Attrs.getListRef(); } 2097 2098 /// hasAttributes - do we contain any attributes? hasAttributes()2099 bool hasAttributes() const { 2100 if (getAttributes() || getDeclSpec().hasAttributes()) return true; 2101 for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i) 2102 if (getTypeObject(i).getAttrs()) 2103 return true; 2104 return false; 2105 } 2106 2107 /// \brief Return a source range list of C++11 attributes associated 2108 /// with the declarator. getCXX11AttributeRanges(SmallVectorImpl<SourceRange> & Ranges)2109 void getCXX11AttributeRanges(SmallVectorImpl<SourceRange> &Ranges) { 2110 AttributeList *AttrList = Attrs.getList(); 2111 while (AttrList) { 2112 if (AttrList->isCXX11Attribute()) 2113 Ranges.push_back(AttrList->getRange()); 2114 AttrList = AttrList->getNext(); 2115 } 2116 } 2117 setAsmLabel(Expr * E)2118 void setAsmLabel(Expr *E) { AsmLabel = E; } getAsmLabel()2119 Expr *getAsmLabel() const { return AsmLabel; } 2120 2121 void setExtension(bool Val = true) { Extension = Val; } getExtension()2122 bool getExtension() const { return Extension; } 2123 2124 void setInvalidType(bool Val = true) { InvalidType = Val; } isInvalidType()2125 bool isInvalidType() const { 2126 return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error; 2127 } 2128 setGroupingParens(bool flag)2129 void setGroupingParens(bool flag) { GroupingParens = flag; } hasGroupingParens()2130 bool hasGroupingParens() const { return GroupingParens; } 2131 isFirstDeclarator()2132 bool isFirstDeclarator() const { return !CommaLoc.isValid(); } getCommaLoc()2133 SourceLocation getCommaLoc() const { return CommaLoc; } setCommaLoc(SourceLocation CL)2134 void setCommaLoc(SourceLocation CL) { CommaLoc = CL; } 2135 hasEllipsis()2136 bool hasEllipsis() const { return EllipsisLoc.isValid(); } getEllipsisLoc()2137 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } setEllipsisLoc(SourceLocation EL)2138 void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } 2139 setFunctionDefinitionKind(FunctionDefinitionKind Val)2140 void setFunctionDefinitionKind(FunctionDefinitionKind Val) { 2141 FunctionDefinition = Val; 2142 } 2143 isFunctionDefinition()2144 bool isFunctionDefinition() const { 2145 return getFunctionDefinitionKind() != FDK_Declaration; 2146 } 2147 getFunctionDefinitionKind()2148 FunctionDefinitionKind getFunctionDefinitionKind() const { 2149 return (FunctionDefinitionKind)FunctionDefinition; 2150 } 2151 2152 /// Returns true if this declares a real member and not a friend. isFirstDeclarationOfMember()2153 bool isFirstDeclarationOfMember() { 2154 return getContext() == MemberContext && !getDeclSpec().isFriendSpecified(); 2155 } 2156 2157 /// Returns true if this declares a static member. This cannot be called on a 2158 /// declarator outside of a MemberContext because we won't know until 2159 /// redeclaration time if the decl is static. 2160 bool isStaticMember(); 2161 setRedeclaration(bool Val)2162 void setRedeclaration(bool Val) { Redeclaration = Val; } isRedeclaration()2163 bool isRedeclaration() const { return Redeclaration; } 2164 }; 2165 2166 /// \brief This little struct is used to capture information about 2167 /// structure field declarators, which is basically just a bitfield size. 2168 struct FieldDeclarator { 2169 Declarator D; 2170 Expr *BitfieldSize; FieldDeclaratorFieldDeclarator2171 explicit FieldDeclarator(const DeclSpec &DS) 2172 : D(DS, Declarator::MemberContext), BitfieldSize(nullptr) { } 2173 }; 2174 2175 /// \brief Represents a C++11 virt-specifier-seq. 2176 class VirtSpecifiers { 2177 public: 2178 enum Specifier { 2179 VS_None = 0, 2180 VS_Override = 1, 2181 VS_Final = 2, 2182 VS_Sealed = 4 2183 }; 2184 VirtSpecifiers()2185 VirtSpecifiers() : Specifiers(0), LastSpecifier(VS_None) { } 2186 2187 bool SetSpecifier(Specifier VS, SourceLocation Loc, 2188 const char *&PrevSpec); 2189 isUnset()2190 bool isUnset() const { return Specifiers == 0; } 2191 isOverrideSpecified()2192 bool isOverrideSpecified() const { return Specifiers & VS_Override; } getOverrideLoc()2193 SourceLocation getOverrideLoc() const { return VS_overrideLoc; } 2194 isFinalSpecified()2195 bool isFinalSpecified() const { return Specifiers & (VS_Final | VS_Sealed); } isFinalSpelledSealed()2196 bool isFinalSpelledSealed() const { return Specifiers & VS_Sealed; } getFinalLoc()2197 SourceLocation getFinalLoc() const { return VS_finalLoc; } 2198 clear()2199 void clear() { Specifiers = 0; } 2200 2201 static const char *getSpecifierName(Specifier VS); 2202 getFirstLocation()2203 SourceLocation getFirstLocation() const { return FirstLocation; } getLastLocation()2204 SourceLocation getLastLocation() const { return LastLocation; } getLastSpecifier()2205 Specifier getLastSpecifier() const { return LastSpecifier; } 2206 2207 private: 2208 unsigned Specifiers; 2209 Specifier LastSpecifier; 2210 2211 SourceLocation VS_overrideLoc, VS_finalLoc; 2212 SourceLocation FirstLocation; 2213 SourceLocation LastLocation; 2214 }; 2215 2216 /// \brief Represents a complete lambda introducer. 2217 struct LambdaIntroducer { 2218 /// \brief An individual capture in a lambda introducer. 2219 struct LambdaCapture { 2220 LambdaCaptureKind Kind; 2221 SourceLocation Loc; 2222 IdentifierInfo *Id; 2223 SourceLocation EllipsisLoc; 2224 ExprResult Init; 2225 ParsedType InitCaptureType; LambdaCaptureLambdaIntroducer::LambdaCapture2226 LambdaCapture(LambdaCaptureKind Kind, SourceLocation Loc, 2227 IdentifierInfo *Id, SourceLocation EllipsisLoc, 2228 ExprResult Init, ParsedType InitCaptureType) 2229 : Kind(Kind), Loc(Loc), Id(Id), EllipsisLoc(EllipsisLoc), Init(Init), 2230 InitCaptureType(InitCaptureType) {} 2231 }; 2232 2233 SourceRange Range; 2234 SourceLocation DefaultLoc; 2235 LambdaCaptureDefault Default; 2236 SmallVector<LambdaCapture, 4> Captures; 2237 LambdaIntroducerLambdaIntroducer2238 LambdaIntroducer() 2239 : Default(LCD_None) {} 2240 2241 /// \brief Append a capture in a lambda introducer. addCaptureLambdaIntroducer2242 void addCapture(LambdaCaptureKind Kind, 2243 SourceLocation Loc, 2244 IdentifierInfo* Id, 2245 SourceLocation EllipsisLoc, 2246 ExprResult Init, 2247 ParsedType InitCaptureType) { 2248 Captures.push_back(LambdaCapture(Kind, Loc, Id, EllipsisLoc, Init, 2249 InitCaptureType)); 2250 } 2251 }; 2252 2253 } // end namespace clang 2254 2255 #endif 2256