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