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