DeclSpec.h revision 9dc71d2fddcd283e07d45f3894c8559e2f7dd9a7
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, 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(TSS_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 596 bool SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, 597 unsigned &DiagID); 598 599 bool isFriendSpecified() const { return Friend_specified; } 600 SourceLocation getFriendSpecLoc() const { return FriendLoc; } 601 602 bool isConstexprSpecified() const { return Constexpr_specified; } 603 SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; } 604 605 AttributePool &getAttributePool() const { 606 return Attrs.getPool(); 607 } 608 609 /// AddAttributes - contatenates two attribute lists. 610 /// The GCC attribute syntax allows for the following: 611 /// 612 /// short __attribute__(( unused, deprecated )) 613 /// int __attribute__(( may_alias, aligned(16) )) var; 614 /// 615 /// This declares 4 attributes using 2 lists. The following syntax is 616 /// also allowed and equivalent to the previous declaration. 617 /// 618 /// short __attribute__((unused)) __attribute__((deprecated)) 619 /// int __attribute__((may_alias)) __attribute__((aligned(16))) var; 620 /// 621 void addAttributes(AttributeList *AL) { 622 Attrs.addAll(AL); 623 } 624 void setAttributes(AttributeList *AL) { 625 Attrs.set(AL); 626 } 627 628 bool hasAttributes() const { return !Attrs.empty(); } 629 630 ParsedAttributes &getAttributes() { return Attrs; } 631 const ParsedAttributes &getAttributes() const { return Attrs; } 632 633 /// TakeAttributes - Return the current attribute list and remove them from 634 /// the DeclSpec so that it doesn't own them. 635 ParsedAttributes takeAttributes() { 636 // The non-const "copy" constructor clears the operand automatically. 637 return Attrs; 638 } 639 640 void takeAttributesFrom(ParsedAttributes &attrs) { 641 Attrs.takeAllFrom(attrs); 642 } 643 644 typedef Decl * const *ProtocolQualifierListTy; 645 ProtocolQualifierListTy getProtocolQualifiers() const { 646 return ProtocolQualifiers; 647 } 648 SourceLocation *getProtocolLocs() const { return ProtocolLocs; } 649 unsigned getNumProtocolQualifiers() const { 650 return NumProtocolQualifiers; 651 } 652 SourceLocation getProtocolLAngleLoc() const { return ProtocolLAngleLoc; } 653 void setProtocolQualifiers(Decl * const *Protos, unsigned NP, 654 SourceLocation *ProtoLocs, 655 SourceLocation LAngleLoc); 656 657 /// Finish - This does final analysis of the declspec, issuing diagnostics for 658 /// things like "_Imaginary" (lacking an FP type). After calling this method, 659 /// DeclSpec is guaranteed self-consistent, even if an error occurred. 660 void Finish(Diagnostic &D, Preprocessor &PP); 661 662 const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const { 663 return writtenBS; 664 } 665 666 ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; } 667 void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; } 668 669 /// isMissingDeclaratorOk - This checks if this DeclSpec can stand alone, 670 /// without a Declarator. Only tag declspecs can stand alone. 671 bool isMissingDeclaratorOk(); 672}; 673 674/// ObjCDeclSpec - This class captures information about 675/// "declaration specifiers" specific to objective-c 676class ObjCDeclSpec { 677public: 678 /// ObjCDeclQualifier - Qualifier used on types in method 679 /// declarations. Not all combinations are sensible. Parameters 680 /// can be one of { in, out, inout } with one of { bycopy, byref }. 681 /// Returns can either be { oneway } or not. 682 /// 683 /// This should be kept in sync with Decl::ObjCDeclQualifier. 684 enum ObjCDeclQualifier { 685 DQ_None = 0x0, 686 DQ_In = 0x1, 687 DQ_Inout = 0x2, 688 DQ_Out = 0x4, 689 DQ_Bycopy = 0x8, 690 DQ_Byref = 0x10, 691 DQ_Oneway = 0x20 692 }; 693 694 /// PropertyAttributeKind - list of property attributes. 695 enum ObjCPropertyAttributeKind { 696 DQ_PR_noattr = 0x0, 697 DQ_PR_readonly = 0x01, 698 DQ_PR_getter = 0x02, 699 DQ_PR_assign = 0x04, 700 DQ_PR_readwrite = 0x08, 701 DQ_PR_retain = 0x10, 702 DQ_PR_copy = 0x20, 703 DQ_PR_nonatomic = 0x40, 704 DQ_PR_setter = 0x80, 705 DQ_PR_atomic = 0x100, 706 DQ_PR_weak = 0x200, 707 DQ_PR_strong = 0x400, 708 DQ_PR_unsafe_unretained = 0x800 709 }; 710 711 712 ObjCDeclSpec() 713 : objcDeclQualifier(DQ_None), PropertyAttributes(DQ_PR_noattr), 714 GetterName(0), SetterName(0) { } 715 ObjCDeclQualifier getObjCDeclQualifier() const { return objcDeclQualifier; } 716 void setObjCDeclQualifier(ObjCDeclQualifier DQVal) { 717 objcDeclQualifier = (ObjCDeclQualifier) (objcDeclQualifier | DQVal); 718 } 719 720 ObjCPropertyAttributeKind getPropertyAttributes() const { 721 return ObjCPropertyAttributeKind(PropertyAttributes); 722 } 723 void setPropertyAttributes(ObjCPropertyAttributeKind PRVal) { 724 PropertyAttributes = 725 (ObjCPropertyAttributeKind)(PropertyAttributes | PRVal); 726 } 727 728 const IdentifierInfo *getGetterName() const { return GetterName; } 729 IdentifierInfo *getGetterName() { return GetterName; } 730 void setGetterName(IdentifierInfo *name) { GetterName = name; } 731 732 const IdentifierInfo *getSetterName() const { return SetterName; } 733 IdentifierInfo *getSetterName() { return SetterName; } 734 void setSetterName(IdentifierInfo *name) { SetterName = name; } 735private: 736 // FIXME: These two are unrelated and mutially exclusive. So perhaps 737 // we can put them in a union to reflect their mutual exclusiveness 738 // (space saving is negligible). 739 ObjCDeclQualifier objcDeclQualifier : 6; 740 741 // NOTE: VC++ treats enums as signed, avoid using ObjCPropertyAttributeKind 742 unsigned PropertyAttributes : 12; 743 IdentifierInfo *GetterName; // getter name of NULL if no getter 744 IdentifierInfo *SetterName; // setter name of NULL if no setter 745}; 746 747/// \brief Represents a C++ unqualified-id that has been parsed. 748class UnqualifiedId { 749private: 750 const UnqualifiedId &operator=(const UnqualifiedId &); // DO NOT IMPLEMENT 751 752public: 753 /// \brief Describes the kind of unqualified-id parsed. 754 enum IdKind { 755 /// \brief An identifier. 756 IK_Identifier, 757 /// \brief An overloaded operator name, e.g., operator+. 758 IK_OperatorFunctionId, 759 /// \brief A conversion function name, e.g., operator int. 760 IK_ConversionFunctionId, 761 /// \brief A user-defined literal name, e.g., operator "" _i. 762 IK_LiteralOperatorId, 763 /// \brief A constructor name. 764 IK_ConstructorName, 765 /// \brief A constructor named via a template-id. 766 IK_ConstructorTemplateId, 767 /// \brief A destructor name. 768 IK_DestructorName, 769 /// \brief A template-id, e.g., f<int>. 770 IK_TemplateId 771 } Kind; 772 773 /// \brief Anonymous union that holds extra data associated with the 774 /// parsed unqualified-id. 775 union { 776 /// \brief When Kind == IK_Identifier, the parsed identifier, or when Kind 777 /// == IK_UserLiteralId, the identifier suffix. 778 IdentifierInfo *Identifier; 779 780 /// \brief When Kind == IK_OperatorFunctionId, the overloaded operator 781 /// that we parsed. 782 struct { 783 /// \brief The kind of overloaded operator. 784 OverloadedOperatorKind Operator; 785 786 /// \brief The source locations of the individual tokens that name 787 /// the operator, e.g., the "new", "[", and "]" tokens in 788 /// operator new []. 789 /// 790 /// Different operators have different numbers of tokens in their name, 791 /// up to three. Any remaining source locations in this array will be 792 /// set to an invalid value for operators with fewer than three tokens. 793 unsigned SymbolLocations[3]; 794 } OperatorFunctionId; 795 796 /// \brief When Kind == IK_ConversionFunctionId, the type that the 797 /// conversion function names. 798 UnionParsedType ConversionFunctionId; 799 800 /// \brief When Kind == IK_ConstructorName, the class-name of the type 801 /// whose constructor is being referenced. 802 UnionParsedType ConstructorName; 803 804 /// \brief When Kind == IK_DestructorName, the type referred to by the 805 /// class-name. 806 UnionParsedType DestructorName; 807 808 /// \brief When Kind == IK_TemplateId or IK_ConstructorTemplateId, 809 /// the template-id annotation that contains the template name and 810 /// template arguments. 811 TemplateIdAnnotation *TemplateId; 812 }; 813 814 /// \brief The location of the first token that describes this unqualified-id, 815 /// which will be the location of the identifier, "operator" keyword, 816 /// tilde (for a destructor), or the template name of a template-id. 817 SourceLocation StartLocation; 818 819 /// \brief The location of the last token that describes this unqualified-id. 820 SourceLocation EndLocation; 821 822 UnqualifiedId() : Kind(IK_Identifier), Identifier(0) { } 823 824 /// \brief Do not use this copy constructor. It is temporary, and only 825 /// exists because we are holding FieldDeclarators in a SmallVector when we 826 /// don't actually need them. 827 /// 828 /// FIXME: Kill this copy constructor. 829 UnqualifiedId(const UnqualifiedId &Other) 830 : Kind(IK_Identifier), Identifier(Other.Identifier), 831 StartLocation(Other.StartLocation), EndLocation(Other.EndLocation) { 832 assert(Other.Kind == IK_Identifier && "Cannot copy non-identifiers"); 833 } 834 835 /// \brief Destroy this unqualified-id. 836 ~UnqualifiedId() { clear(); } 837 838 /// \brief Clear out this unqualified-id, setting it to default (invalid) 839 /// state. 840 void clear(); 841 842 /// \brief Determine whether this unqualified-id refers to a valid name. 843 bool isValid() const { return StartLocation.isValid(); } 844 845 /// \brief Determine whether this unqualified-id refers to an invalid name. 846 bool isInvalid() const { return !isValid(); } 847 848 /// \brief Determine what kind of name we have. 849 IdKind getKind() const { return Kind; } 850 851 /// \brief Specify that this unqualified-id was parsed as an identifier. 852 /// 853 /// \param Id the parsed identifier. 854 /// \param IdLoc the location of the parsed identifier. 855 void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc) { 856 Kind = IK_Identifier; 857 Identifier = const_cast<IdentifierInfo *>(Id); 858 StartLocation = EndLocation = IdLoc; 859 } 860 861 /// \brief Specify that this unqualified-id was parsed as an 862 /// operator-function-id. 863 /// 864 /// \param OperatorLoc the location of the 'operator' keyword. 865 /// 866 /// \param Op the overloaded operator. 867 /// 868 /// \param SymbolLocations the locations of the individual operator symbols 869 /// in the operator. 870 void setOperatorFunctionId(SourceLocation OperatorLoc, 871 OverloadedOperatorKind Op, 872 SourceLocation SymbolLocations[3]); 873 874 /// \brief Specify that this unqualified-id was parsed as a 875 /// conversion-function-id. 876 /// 877 /// \param OperatorLoc the location of the 'operator' keyword. 878 /// 879 /// \param Ty the type to which this conversion function is converting. 880 /// 881 /// \param EndLoc the location of the last token that makes up the type name. 882 void setConversionFunctionId(SourceLocation OperatorLoc, 883 ParsedType Ty, 884 SourceLocation EndLoc) { 885 Kind = IK_ConversionFunctionId; 886 StartLocation = OperatorLoc; 887 EndLocation = EndLoc; 888 ConversionFunctionId = Ty; 889 } 890 891 /// \brief Specific that this unqualified-id was parsed as a 892 /// literal-operator-id. 893 /// 894 /// \param Id the parsed identifier. 895 /// 896 /// \param OpLoc the location of the 'operator' keyword. 897 /// 898 /// \param IdLoc the location of the identifier. 899 void setLiteralOperatorId(const IdentifierInfo *Id, SourceLocation OpLoc, 900 SourceLocation IdLoc) { 901 Kind = IK_LiteralOperatorId; 902 Identifier = const_cast<IdentifierInfo *>(Id); 903 StartLocation = OpLoc; 904 EndLocation = IdLoc; 905 } 906 907 /// \brief Specify that this unqualified-id was parsed as a constructor name. 908 /// 909 /// \param ClassType the class type referred to by the constructor name. 910 /// 911 /// \param ClassNameLoc the location of the class name. 912 /// 913 /// \param EndLoc the location of the last token that makes up the type name. 914 void setConstructorName(ParsedType ClassType, 915 SourceLocation ClassNameLoc, 916 SourceLocation EndLoc) { 917 Kind = IK_ConstructorName; 918 StartLocation = ClassNameLoc; 919 EndLocation = EndLoc; 920 ConstructorName = ClassType; 921 } 922 923 /// \brief Specify that this unqualified-id was parsed as a 924 /// template-id that names a constructor. 925 /// 926 /// \param TemplateId the template-id annotation that describes the parsed 927 /// template-id. This UnqualifiedId instance will take ownership of the 928 /// \p TemplateId and will free it on destruction. 929 void setConstructorTemplateId(TemplateIdAnnotation *TemplateId); 930 931 /// \brief Specify that this unqualified-id was parsed as a destructor name. 932 /// 933 /// \param TildeLoc the location of the '~' that introduces the destructor 934 /// name. 935 /// 936 /// \param ClassType the name of the class referred to by the destructor name. 937 void setDestructorName(SourceLocation TildeLoc, 938 ParsedType ClassType, 939 SourceLocation EndLoc) { 940 Kind = IK_DestructorName; 941 StartLocation = TildeLoc; 942 EndLocation = EndLoc; 943 DestructorName = ClassType; 944 } 945 946 /// \brief Specify that this unqualified-id was parsed as a template-id. 947 /// 948 /// \param TemplateId the template-id annotation that describes the parsed 949 /// template-id. This UnqualifiedId instance will take ownership of the 950 /// \p TemplateId and will free it on destruction. 951 void setTemplateId(TemplateIdAnnotation *TemplateId); 952 953 /// \brief Return the source range that covers this unqualified-id. 954 SourceRange getSourceRange() const { 955 return SourceRange(StartLocation, EndLocation); 956 } 957}; 958 959/// CachedTokens - A set of tokens that has been cached for later 960/// parsing. 961typedef llvm::SmallVector<Token, 4> CachedTokens; 962 963/// DeclaratorChunk - One instance of this struct is used for each type in a 964/// declarator that is parsed. 965/// 966/// This is intended to be a small value object. 967struct DeclaratorChunk { 968 enum { 969 Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren 970 } Kind; 971 972 /// Loc - The place where this type was defined. 973 SourceLocation Loc; 974 /// EndLoc - If valid, the place where this chunck ends. 975 SourceLocation EndLoc; 976 977 struct TypeInfoCommon { 978 AttributeList *AttrList; 979 }; 980 981 struct PointerTypeInfo : TypeInfoCommon { 982 /// The type qualifiers: const/volatile/restrict. 983 unsigned TypeQuals : 3; 984 985 /// The location of the const-qualifier, if any. 986 unsigned ConstQualLoc; 987 988 /// The location of the volatile-qualifier, if any. 989 unsigned VolatileQualLoc; 990 991 /// The location of the restrict-qualifier, if any. 992 unsigned RestrictQualLoc; 993 994 void destroy() { 995 } 996 }; 997 998 struct ReferenceTypeInfo : TypeInfoCommon { 999 /// The type qualifier: restrict. [GNU] C++ extension 1000 bool HasRestrict : 1; 1001 /// True if this is an lvalue reference, false if it's an rvalue reference. 1002 bool LValueRef : 1; 1003 void destroy() { 1004 } 1005 }; 1006 1007 struct ArrayTypeInfo : TypeInfoCommon { 1008 /// The type qualifiers for the array: const/volatile/restrict. 1009 unsigned TypeQuals : 3; 1010 1011 /// True if this dimension included the 'static' keyword. 1012 bool hasStatic : 1; 1013 1014 /// True if this dimension was [*]. In this case, NumElts is null. 1015 bool isStar : 1; 1016 1017 /// This is the size of the array, or null if [] or [*] was specified. 1018 /// Since the parser is multi-purpose, and we don't want to impose a root 1019 /// expression class on all clients, NumElts is untyped. 1020 Expr *NumElts; 1021 1022 void destroy() {} 1023 }; 1024 1025 /// ParamInfo - An array of paraminfo objects is allocated whenever a function 1026 /// declarator is parsed. There are two interesting styles of arguments here: 1027 /// K&R-style identifier lists and parameter type lists. K&R-style identifier 1028 /// lists will have information about the identifier, but no type information. 1029 /// Parameter type lists will have type info (if the actions module provides 1030 /// it), but may have null identifier info: e.g. for 'void foo(int X, int)'. 1031 struct ParamInfo { 1032 IdentifierInfo *Ident; 1033 SourceLocation IdentLoc; 1034 Decl *Param; 1035 1036 /// DefaultArgTokens - When the parameter's default argument 1037 /// cannot be parsed immediately (because it occurs within the 1038 /// declaration of a member function), it will be stored here as a 1039 /// sequence of tokens to be parsed once the class definition is 1040 /// complete. Non-NULL indicates that there is a default argument. 1041 CachedTokens *DefaultArgTokens; 1042 1043 ParamInfo() {} 1044 ParamInfo(IdentifierInfo *ident, SourceLocation iloc, 1045 Decl *param, 1046 CachedTokens *DefArgTokens = 0) 1047 : Ident(ident), IdentLoc(iloc), Param(param), 1048 DefaultArgTokens(DefArgTokens) {} 1049 }; 1050 1051 struct TypeAndRange { 1052 ParsedType Ty; 1053 SourceRange Range; 1054 }; 1055 1056 struct FunctionTypeInfo : TypeInfoCommon { 1057 /// hasPrototype - This is true if the function had at least one typed 1058 /// argument. If the function is () or (a,b,c), then it has no prototype, 1059 /// and is treated as a K&R-style function. 1060 unsigned hasPrototype : 1; 1061 1062 /// isVariadic - If this function has a prototype, and if that 1063 /// proto ends with ',...)', this is true. When true, EllipsisLoc 1064 /// contains the location of the ellipsis. 1065 unsigned isVariadic : 1; 1066 1067 /// \brief Whether the ref-qualifier (if any) is an lvalue reference. 1068 /// Otherwise, it's an rvalue reference. 1069 unsigned RefQualifierIsLValueRef : 1; 1070 1071 /// The type qualifiers: const/volatile/restrict. 1072 /// The qualifier bitmask values are the same as in QualType. 1073 unsigned TypeQuals : 3; 1074 1075 /// ExceptionSpecType - An ExceptionSpecificationType value. 1076 unsigned ExceptionSpecType : 3; 1077 1078 /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo. 1079 unsigned DeleteArgInfo : 1; 1080 1081 /// When isVariadic is true, the location of the ellipsis in the source. 1082 unsigned EllipsisLoc; 1083 1084 /// NumArgs - This is the number of formal arguments provided for the 1085 /// declarator. 1086 unsigned NumArgs; 1087 1088 /// NumExceptions - This is the number of types in the dynamic-exception- 1089 /// decl, if the function has one. 1090 unsigned NumExceptions; 1091 1092 /// \brief The location of the ref-qualifier, if any. 1093 /// 1094 /// If this is an invalid location, there is no ref-qualifier. 1095 unsigned RefQualifierLoc; 1096 1097 /// \brief When ExceptionSpecType isn't EST_None or EST_Delayed, the 1098 /// location of the keyword introducing the spec. 1099 unsigned ExceptionSpecLoc; 1100 1101 /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that 1102 /// describe the arguments for this function declarator. This is null if 1103 /// there are no arguments specified. 1104 ParamInfo *ArgInfo; 1105 1106 union { 1107 /// \brief Pointer to a new[]'d array of TypeAndRange objects that 1108 /// contain the types in the function's dynamic exception specification 1109 /// and their locations, if there is one. 1110 TypeAndRange *Exceptions; 1111 1112 /// \brief Pointer to the expression in the noexcept-specifier of this 1113 /// function, if it has one. 1114 Expr *NoexceptExpr; 1115 }; 1116 1117 /// TrailingReturnType - If this isn't null, it's the trailing return type 1118 /// specified. This is actually a ParsedType, but stored as void* to 1119 /// allow union storage. 1120 void *TrailingReturnType; 1121 1122 /// freeArgs - reset the argument list to having zero arguments. This is 1123 /// used in various places for error recovery. 1124 void freeArgs() { 1125 if (DeleteArgInfo) { 1126 delete[] ArgInfo; 1127 DeleteArgInfo = false; 1128 } 1129 NumArgs = 0; 1130 } 1131 1132 void destroy() { 1133 if (DeleteArgInfo) 1134 delete[] ArgInfo; 1135 if (getExceptionSpecType() == EST_Dynamic) 1136 delete[] Exceptions; 1137 } 1138 1139 /// isKNRPrototype - Return true if this is a K&R style identifier list, 1140 /// like "void foo(a,b,c)". In a function definition, this will be followed 1141 /// by the argument type definitions. 1142 bool isKNRPrototype() const { 1143 return !hasPrototype && NumArgs != 0; 1144 } 1145 1146 SourceLocation getEllipsisLoc() const { 1147 return SourceLocation::getFromRawEncoding(EllipsisLoc); 1148 } 1149 SourceLocation getExceptionSpecLoc() const { 1150 return SourceLocation::getFromRawEncoding(ExceptionSpecLoc); 1151 } 1152 1153 /// \brief Retrieve the location of the ref-qualifier, if any. 1154 SourceLocation getRefQualifierLoc() const { 1155 return SourceLocation::getFromRawEncoding(RefQualifierLoc); 1156 } 1157 1158 /// \brief Determine whether this function declaration contains a 1159 /// ref-qualifier. 1160 bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); } 1161 1162 /// \brief Get the type of exception specification this function has. 1163 ExceptionSpecificationType getExceptionSpecType() const { 1164 return static_cast<ExceptionSpecificationType>(ExceptionSpecType); 1165 } 1166 }; 1167 1168 struct BlockPointerTypeInfo : TypeInfoCommon { 1169 /// For now, sema will catch these as invalid. 1170 /// The type qualifiers: const/volatile/restrict. 1171 unsigned TypeQuals : 3; 1172 1173 void destroy() { 1174 } 1175 }; 1176 1177 struct MemberPointerTypeInfo : TypeInfoCommon { 1178 /// The type qualifiers: const/volatile/restrict. 1179 unsigned TypeQuals : 3; 1180 // CXXScopeSpec has a constructor, so it can't be a direct member. 1181 // So we need some pointer-aligned storage and a bit of trickery. 1182 union { 1183 void *Aligner; 1184 char Mem[sizeof(CXXScopeSpec)]; 1185 } ScopeMem; 1186 CXXScopeSpec &Scope() { 1187 return *reinterpret_cast<CXXScopeSpec*>(ScopeMem.Mem); 1188 } 1189 const CXXScopeSpec &Scope() const { 1190 return *reinterpret_cast<const CXXScopeSpec*>(ScopeMem.Mem); 1191 } 1192 void destroy() { 1193 Scope().~CXXScopeSpec(); 1194 } 1195 }; 1196 1197 union { 1198 TypeInfoCommon Common; 1199 PointerTypeInfo Ptr; 1200 ReferenceTypeInfo Ref; 1201 ArrayTypeInfo Arr; 1202 FunctionTypeInfo Fun; 1203 BlockPointerTypeInfo Cls; 1204 MemberPointerTypeInfo Mem; 1205 }; 1206 1207 void destroy() { 1208 switch (Kind) { 1209 default: assert(0 && "Unknown decl type!"); 1210 case DeclaratorChunk::Function: return Fun.destroy(); 1211 case DeclaratorChunk::Pointer: return Ptr.destroy(); 1212 case DeclaratorChunk::BlockPointer: return Cls.destroy(); 1213 case DeclaratorChunk::Reference: return Ref.destroy(); 1214 case DeclaratorChunk::Array: return Arr.destroy(); 1215 case DeclaratorChunk::MemberPointer: return Mem.destroy(); 1216 case DeclaratorChunk::Paren: return; 1217 } 1218 } 1219 1220 /// getAttrs - If there are attributes applied to this declaratorchunk, return 1221 /// them. 1222 const AttributeList *getAttrs() const { 1223 return Common.AttrList; 1224 } 1225 1226 AttributeList *&getAttrListRef() { 1227 return Common.AttrList; 1228 } 1229 1230 /// getPointer - Return a DeclaratorChunk for a pointer. 1231 /// 1232 static DeclaratorChunk getPointer(unsigned TypeQuals, SourceLocation Loc, 1233 SourceLocation ConstQualLoc, 1234 SourceLocation VolatileQualLoc, 1235 SourceLocation RestrictQualLoc) { 1236 DeclaratorChunk I; 1237 I.Kind = Pointer; 1238 I.Loc = Loc; 1239 I.Ptr.TypeQuals = TypeQuals; 1240 I.Ptr.ConstQualLoc = ConstQualLoc.getRawEncoding(); 1241 I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding(); 1242 I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding(); 1243 I.Ptr.AttrList = 0; 1244 return I; 1245 } 1246 1247 /// getReference - Return a DeclaratorChunk for a reference. 1248 /// 1249 static DeclaratorChunk getReference(unsigned TypeQuals, SourceLocation Loc, 1250 bool lvalue) { 1251 DeclaratorChunk I; 1252 I.Kind = Reference; 1253 I.Loc = Loc; 1254 I.Ref.HasRestrict = (TypeQuals & DeclSpec::TQ_restrict) != 0; 1255 I.Ref.LValueRef = lvalue; 1256 I.Ref.AttrList = 0; 1257 return I; 1258 } 1259 1260 /// getArray - Return a DeclaratorChunk for an array. 1261 /// 1262 static DeclaratorChunk getArray(unsigned TypeQuals, 1263 bool isStatic, bool isStar, Expr *NumElts, 1264 SourceLocation LBLoc, SourceLocation RBLoc) { 1265 DeclaratorChunk I; 1266 I.Kind = Array; 1267 I.Loc = LBLoc; 1268 I.EndLoc = RBLoc; 1269 I.Arr.AttrList = 0; 1270 I.Arr.TypeQuals = TypeQuals; 1271 I.Arr.hasStatic = isStatic; 1272 I.Arr.isStar = isStar; 1273 I.Arr.NumElts = NumElts; 1274 return I; 1275 } 1276 1277 /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. 1278 /// "TheDeclarator" is the declarator that this will be added to. 1279 static DeclaratorChunk getFunction(bool hasProto, bool isVariadic, 1280 SourceLocation EllipsisLoc, 1281 ParamInfo *ArgInfo, unsigned NumArgs, 1282 unsigned TypeQuals, 1283 bool RefQualifierIsLvalueRef, 1284 SourceLocation RefQualifierLoc, 1285 ExceptionSpecificationType ESpecType, 1286 SourceLocation ESpecLoc, 1287 ParsedType *Exceptions, 1288 SourceRange *ExceptionRanges, 1289 unsigned NumExceptions, 1290 Expr *NoexceptExpr, 1291 SourceLocation LocalRangeBegin, 1292 SourceLocation LocalRangeEnd, 1293 Declarator &TheDeclarator, 1294 ParsedType TrailingReturnType = 1295 ParsedType()); 1296 1297 /// getBlockPointer - Return a DeclaratorChunk for a block. 1298 /// 1299 static DeclaratorChunk getBlockPointer(unsigned TypeQuals, 1300 SourceLocation Loc) { 1301 DeclaratorChunk I; 1302 I.Kind = BlockPointer; 1303 I.Loc = Loc; 1304 I.Cls.TypeQuals = TypeQuals; 1305 I.Cls.AttrList = 0; 1306 return I; 1307 } 1308 1309 static DeclaratorChunk getMemberPointer(const CXXScopeSpec &SS, 1310 unsigned TypeQuals, 1311 SourceLocation Loc) { 1312 DeclaratorChunk I; 1313 I.Kind = MemberPointer; 1314 I.Loc = Loc; 1315 I.Mem.TypeQuals = TypeQuals; 1316 I.Mem.AttrList = 0; 1317 new (I.Mem.ScopeMem.Mem) CXXScopeSpec(SS); 1318 return I; 1319 } 1320 1321 /// getParen - Return a DeclaratorChunk for a paren. 1322 /// 1323 static DeclaratorChunk getParen(SourceLocation LParenLoc, 1324 SourceLocation RParenLoc) { 1325 DeclaratorChunk I; 1326 I.Kind = Paren; 1327 I.Loc = LParenLoc; 1328 I.EndLoc = RParenLoc; 1329 I.Common.AttrList = 0; 1330 return I; 1331 } 1332 1333}; 1334 1335/// Declarator - Information about one declarator, including the parsed type 1336/// information and the identifier. When the declarator is fully formed, this 1337/// is turned into the appropriate Decl object. 1338/// 1339/// Declarators come in two types: normal declarators and abstract declarators. 1340/// Abstract declarators are used when parsing types, and don't have an 1341/// identifier. Normal declarators do have ID's. 1342/// 1343/// Instances of this class should be a transient object that lives on the 1344/// stack, not objects that are allocated in large quantities on the heap. 1345class Declarator { 1346public: 1347 enum TheContext { 1348 FileContext, // File scope declaration. 1349 PrototypeContext, // Within a function prototype. 1350 ObjCPrototypeContext,// Within a method prototype. 1351 KNRTypeListContext, // K&R type definition list for formals. 1352 TypeNameContext, // Abstract declarator for types. 1353 MemberContext, // Struct/Union field. 1354 BlockContext, // Declaration within a block in a function. 1355 ForContext, // Declaration within first part of a for loop. 1356 ConditionContext, // Condition declaration in a C++ if/switch/while/for. 1357 TemplateParamContext,// Within a template parameter list. 1358 CXXNewContext, // C++ new-expression. 1359 CXXCatchContext, // C++ catch exception-declaration 1360 ObjCCatchContext, // Objective-C catch exception-declaration 1361 BlockLiteralContext, // Block literal declarator. 1362 TemplateTypeArgContext, // Template type argument. 1363 AliasDeclContext, // C++0x alias-declaration. 1364 AliasTemplateContext // C++0x alias-declaration template. 1365 }; 1366 1367private: 1368 const DeclSpec &DS; 1369 CXXScopeSpec SS; 1370 UnqualifiedId Name; 1371 SourceRange Range; 1372 1373 /// Context - Where we are parsing this declarator. 1374 /// 1375 TheContext Context; 1376 1377 /// DeclTypeInfo - This holds each type that the declarator includes as it is 1378 /// parsed. This is pushed from the identifier out, which means that element 1379 /// #0 will be the most closely bound to the identifier, and 1380 /// DeclTypeInfo.back() will be the least closely bound. 1381 llvm::SmallVector<DeclaratorChunk, 8> DeclTypeInfo; 1382 1383 /// InvalidType - Set by Sema::GetTypeForDeclarator(). 1384 bool InvalidType : 1; 1385 1386 /// GroupingParens - Set by Parser::ParseParenDeclarator(). 1387 bool GroupingParens : 1; 1388 1389 /// Attrs - Attributes. 1390 ParsedAttributes Attrs; 1391 1392 /// AsmLabel - The asm label, if specified. 1393 Expr *AsmLabel; 1394 1395 /// InlineParams - This is a local array used for the first function decl 1396 /// chunk to avoid going to the heap for the common case when we have one 1397 /// function chunk in the declarator. 1398 DeclaratorChunk::ParamInfo InlineParams[16]; 1399 bool InlineParamsUsed; 1400 1401 /// Extension - true if the declaration is preceded by __extension__. 1402 bool Extension : 1; 1403 1404 /// \brief If provided, the source location of the ellipsis used to describe 1405 /// this declarator as a parameter pack. 1406 SourceLocation EllipsisLoc; 1407 1408 friend struct DeclaratorChunk; 1409 1410public: 1411 Declarator(const DeclSpec &ds, TheContext C) 1412 : DS(ds), Range(ds.getSourceRange()), Context(C), 1413 InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error), 1414 GroupingParens(false), Attrs(ds.getAttributePool().getFactory()), 1415 AsmLabel(0), InlineParamsUsed(false), Extension(false) { 1416 } 1417 1418 ~Declarator() { 1419 clear(); 1420 } 1421 1422 /// getDeclSpec - Return the declaration-specifier that this declarator was 1423 /// declared with. 1424 const DeclSpec &getDeclSpec() const { return DS; } 1425 1426 /// getMutableDeclSpec - Return a non-const version of the DeclSpec. This 1427 /// should be used with extreme care: declspecs can often be shared between 1428 /// multiple declarators, so mutating the DeclSpec affects all of the 1429 /// Declarators. This should only be done when the declspec is known to not 1430 /// be shared or when in error recovery etc. 1431 DeclSpec &getMutableDeclSpec() { return const_cast<DeclSpec &>(DS); } 1432 1433 AttributePool &getAttributePool() const { 1434 return Attrs.getPool(); 1435 } 1436 1437 /// getCXXScopeSpec - Return the C++ scope specifier (global scope or 1438 /// nested-name-specifier) that is part of the declarator-id. 1439 const CXXScopeSpec &getCXXScopeSpec() const { return SS; } 1440 CXXScopeSpec &getCXXScopeSpec() { return SS; } 1441 1442 /// \brief Retrieve the name specified by this declarator. 1443 UnqualifiedId &getName() { return Name; } 1444 1445 TheContext getContext() const { return Context; } 1446 1447 bool isPrototypeContext() const { 1448 return (Context == PrototypeContext || Context == ObjCPrototypeContext); 1449 } 1450 1451 /// getSourceRange - Get the source range that spans this declarator. 1452 const SourceRange &getSourceRange() const { return Range; } 1453 1454 void SetSourceRange(SourceRange R) { Range = R; } 1455 /// SetRangeBegin - Set the start of the source range to Loc, unless it's 1456 /// invalid. 1457 void SetRangeBegin(SourceLocation Loc) { 1458 if (!Loc.isInvalid()) 1459 Range.setBegin(Loc); 1460 } 1461 /// SetRangeEnd - Set the end of the source range to Loc, unless it's invalid. 1462 void SetRangeEnd(SourceLocation Loc) { 1463 if (!Loc.isInvalid()) 1464 Range.setEnd(Loc); 1465 } 1466 /// ExtendWithDeclSpec - Extend the declarator source range to include the 1467 /// given declspec, unless its location is invalid. Adopts the range start if 1468 /// the current range start is invalid. 1469 void ExtendWithDeclSpec(const DeclSpec &DS) { 1470 const SourceRange &SR = DS.getSourceRange(); 1471 if (Range.getBegin().isInvalid()) 1472 Range.setBegin(SR.getBegin()); 1473 if (!SR.getEnd().isInvalid()) 1474 Range.setEnd(SR.getEnd()); 1475 } 1476 1477 /// clear - Reset the contents of this Declarator. 1478 void clear() { 1479 SS.clear(); 1480 Name.clear(); 1481 Range = DS.getSourceRange(); 1482 1483 for (unsigned i = 0, e = DeclTypeInfo.size(); i != e; ++i) 1484 DeclTypeInfo[i].destroy(); 1485 DeclTypeInfo.clear(); 1486 Attrs.clear(); 1487 AsmLabel = 0; 1488 InlineParamsUsed = false; 1489 } 1490 1491 /// mayOmitIdentifier - Return true if the identifier is either optional or 1492 /// not allowed. This is true for typenames, prototypes, and template 1493 /// parameter lists. 1494 bool mayOmitIdentifier() const { 1495 switch (Context) { 1496 case FileContext: 1497 case KNRTypeListContext: 1498 case MemberContext: 1499 case BlockContext: 1500 case ForContext: 1501 case ConditionContext: 1502 return false; 1503 1504 case TypeNameContext: 1505 case AliasDeclContext: 1506 case AliasTemplateContext: 1507 case PrototypeContext: 1508 case ObjCPrototypeContext: 1509 case TemplateParamContext: 1510 case CXXNewContext: 1511 case CXXCatchContext: 1512 case ObjCCatchContext: 1513 case BlockLiteralContext: 1514 case TemplateTypeArgContext: 1515 return true; 1516 } 1517 llvm_unreachable("unknown context kind!"); 1518 } 1519 1520 /// mayHaveIdentifier - Return true if the identifier is either optional or 1521 /// required. This is true for normal declarators and prototypes, but not 1522 /// typenames. 1523 bool mayHaveIdentifier() const { 1524 switch (Context) { 1525 case FileContext: 1526 case KNRTypeListContext: 1527 case MemberContext: 1528 case BlockContext: 1529 case ForContext: 1530 case ConditionContext: 1531 case PrototypeContext: 1532 case TemplateParamContext: 1533 case CXXCatchContext: 1534 case ObjCCatchContext: 1535 return true; 1536 1537 case TypeNameContext: 1538 case CXXNewContext: 1539 case AliasDeclContext: 1540 case AliasTemplateContext: 1541 case ObjCPrototypeContext: 1542 case BlockLiteralContext: 1543 case TemplateTypeArgContext: 1544 return false; 1545 } 1546 llvm_unreachable("unknown context kind!"); 1547 } 1548 1549 /// mayBeFollowedByCXXDirectInit - Return true if the declarator can be 1550 /// followed by a C++ direct initializer, e.g. "int x(1);". 1551 bool mayBeFollowedByCXXDirectInit() const { 1552 if (hasGroupingParens()) return false; 1553 1554 switch (Context) { 1555 case FileContext: 1556 case BlockContext: 1557 case ForContext: 1558 return true; 1559 1560 case KNRTypeListContext: 1561 case MemberContext: 1562 case ConditionContext: 1563 case PrototypeContext: 1564 case ObjCPrototypeContext: 1565 case TemplateParamContext: 1566 case CXXCatchContext: 1567 case ObjCCatchContext: 1568 case TypeNameContext: 1569 case CXXNewContext: 1570 case AliasDeclContext: 1571 case AliasTemplateContext: 1572 case BlockLiteralContext: 1573 case TemplateTypeArgContext: 1574 return false; 1575 } 1576 llvm_unreachable("unknown context kind!"); 1577 } 1578 1579 /// isPastIdentifier - Return true if we have parsed beyond the point where 1580 /// the 1581 bool isPastIdentifier() const { return Name.isValid(); } 1582 1583 /// hasName - Whether this declarator has a name, which might be an 1584 /// identifier (accessible via getIdentifier()) or some kind of 1585 /// special C++ name (constructor, destructor, etc.). 1586 bool hasName() const { 1587 return Name.getKind() != UnqualifiedId::IK_Identifier || Name.Identifier; 1588 } 1589 1590 IdentifierInfo *getIdentifier() const { 1591 if (Name.getKind() == UnqualifiedId::IK_Identifier) 1592 return Name.Identifier; 1593 1594 return 0; 1595 } 1596 SourceLocation getIdentifierLoc() const { return Name.StartLocation; } 1597 1598 /// \brief Set the name of this declarator to be the given identifier. 1599 void SetIdentifier(IdentifierInfo *Id, SourceLocation IdLoc) { 1600 Name.setIdentifier(Id, IdLoc); 1601 } 1602 1603 /// AddTypeInfo - Add a chunk to this declarator. Also extend the range to 1604 /// EndLoc, which should be the last token of the chunk. 1605 void AddTypeInfo(const DeclaratorChunk &TI, 1606 ParsedAttributes &attrs, 1607 SourceLocation EndLoc) { 1608 DeclTypeInfo.push_back(TI); 1609 DeclTypeInfo.back().getAttrListRef() = attrs.getList(); 1610 getAttributePool().takeAllFrom(attrs.getPool()); 1611 1612 if (!EndLoc.isInvalid()) 1613 SetRangeEnd(EndLoc); 1614 } 1615 1616 /// AddInnermostTypeInfo - Add a new innermost chunk to this declarator. 1617 void AddInnermostTypeInfo(const DeclaratorChunk &TI) { 1618 DeclTypeInfo.insert(DeclTypeInfo.begin(), TI); 1619 } 1620 1621 /// getNumTypeObjects() - Return the number of types applied to this 1622 /// declarator. 1623 unsigned getNumTypeObjects() const { return DeclTypeInfo.size(); } 1624 1625 /// Return the specified TypeInfo from this declarator. TypeInfo #0 is 1626 /// closest to the identifier. 1627 const DeclaratorChunk &getTypeObject(unsigned i) const { 1628 assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 1629 return DeclTypeInfo[i]; 1630 } 1631 DeclaratorChunk &getTypeObject(unsigned i) { 1632 assert(i < DeclTypeInfo.size() && "Invalid type chunk"); 1633 return DeclTypeInfo[i]; 1634 } 1635 1636 void DropFirstTypeObject() 1637 { 1638 assert(!DeclTypeInfo.empty() && "No type chunks to drop."); 1639 DeclTypeInfo.front().destroy(); 1640 DeclTypeInfo.erase(DeclTypeInfo.begin()); 1641 } 1642 1643 /// isArrayOfUnknownBound - This method returns true if the declarator 1644 /// is a declarator for an array of unknown bound (looking through 1645 /// parentheses). 1646 bool isArrayOfUnknownBound() const { 1647 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1648 switch (DeclTypeInfo[i].Kind) { 1649 case DeclaratorChunk::Paren: 1650 continue; 1651 case DeclaratorChunk::Function: 1652 case DeclaratorChunk::Pointer: 1653 case DeclaratorChunk::Reference: 1654 case DeclaratorChunk::BlockPointer: 1655 case DeclaratorChunk::MemberPointer: 1656 return false; 1657 case DeclaratorChunk::Array: 1658 return !DeclTypeInfo[i].Arr.NumElts; 1659 } 1660 llvm_unreachable("Invalid type chunk"); 1661 return false; 1662 } 1663 return false; 1664 } 1665 1666 /// isFunctionDeclarator - This method returns true if the declarator 1667 /// is a function declarator (looking through parentheses). 1668 /// If true is returned, then the reference type parameter idx is 1669 /// assigned with the index of the declaration chunk. 1670 bool isFunctionDeclarator(unsigned& idx) const { 1671 for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { 1672 switch (DeclTypeInfo[i].Kind) { 1673 case DeclaratorChunk::Function: 1674 idx = i; 1675 return true; 1676 case DeclaratorChunk::Paren: 1677 continue; 1678 case DeclaratorChunk::Pointer: 1679 case DeclaratorChunk::Reference: 1680 case DeclaratorChunk::Array: 1681 case DeclaratorChunk::BlockPointer: 1682 case DeclaratorChunk::MemberPointer: 1683 return false; 1684 } 1685 llvm_unreachable("Invalid type chunk"); 1686 return false; 1687 } 1688 return false; 1689 } 1690 1691 /// isFunctionDeclarator - Once this declarator is fully parsed and formed, 1692 /// this method returns true if the identifier is a function declarator 1693 /// (looking through parentheses). 1694 bool isFunctionDeclarator() const { 1695 unsigned index; 1696 return isFunctionDeclarator(index); 1697 } 1698 1699 /// getFunctionTypeInfo - Retrieves the function type info object 1700 /// (looking through parentheses). 1701 DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() { 1702 assert(isFunctionDeclarator() && "Not a function declarator!"); 1703 unsigned index = 0; 1704 isFunctionDeclarator(index); 1705 return DeclTypeInfo[index].Fun; 1706 } 1707 1708 /// getFunctionTypeInfo - Retrieves the function type info object 1709 /// (looking through parentheses). 1710 const DeclaratorChunk::FunctionTypeInfo &getFunctionTypeInfo() const { 1711 return const_cast<Declarator*>(this)->getFunctionTypeInfo(); 1712 } 1713 1714 /// \brief Determine whether the declaration that will be produced from 1715 /// this declaration will be a function. 1716 /// 1717 /// A declaration can declare a function even if the declarator itself 1718 /// isn't a function declarator, if the type specifier refers to a function 1719 /// type. This routine checks for both cases. 1720 bool isDeclarationOfFunction() const; 1721 1722 /// takeAttributes - Takes attributes from the given parsed-attributes 1723 /// set and add them to this declarator. 1724 /// 1725 /// These examples both add 3 attributes to "var": 1726 /// short int var __attribute__((aligned(16),common,deprecated)); 1727 /// short int x, __attribute__((aligned(16)) var 1728 /// __attribute__((common,deprecated)); 1729 /// 1730 /// Also extends the range of the declarator. 1731 void takeAttributes(ParsedAttributes &attrs, SourceLocation lastLoc) { 1732 Attrs.takeAllFrom(attrs); 1733 1734 if (!lastLoc.isInvalid()) 1735 SetRangeEnd(lastLoc); 1736 } 1737 1738 const AttributeList *getAttributes() const { return Attrs.getList(); } 1739 AttributeList *getAttributes() { return Attrs.getList(); } 1740 1741 AttributeList *&getAttrListRef() { return Attrs.getListRef(); } 1742 1743 /// hasAttributes - do we contain any attributes? 1744 bool hasAttributes() const { 1745 if (getAttributes() || getDeclSpec().hasAttributes()) return true; 1746 for (unsigned i = 0, e = getNumTypeObjects(); i != e; ++i) 1747 if (getTypeObject(i).getAttrs()) 1748 return true; 1749 return false; 1750 } 1751 1752 void setAsmLabel(Expr *E) { AsmLabel = E; } 1753 Expr *getAsmLabel() const { return AsmLabel; } 1754 1755 void setExtension(bool Val = true) { Extension = Val; } 1756 bool getExtension() const { return Extension; } 1757 1758 void setInvalidType(bool Val = true) { InvalidType = Val; } 1759 bool isInvalidType() const { 1760 return InvalidType || DS.getTypeSpecType() == DeclSpec::TST_error; 1761 } 1762 1763 void setGroupingParens(bool flag) { GroupingParens = flag; } 1764 bool hasGroupingParens() const { return GroupingParens; } 1765 1766 bool hasEllipsis() const { return EllipsisLoc.isValid(); } 1767 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 1768 void setEllipsisLoc(SourceLocation EL) { EllipsisLoc = EL; } 1769}; 1770 1771/// FieldDeclarator - This little struct is used to capture information about 1772/// structure field declarators, which is basically just a bitfield size. 1773struct FieldDeclarator { 1774 Declarator D; 1775 Expr *BitfieldSize; 1776 explicit FieldDeclarator(DeclSpec &DS) : D(DS, Declarator::MemberContext) { 1777 BitfieldSize = 0; 1778 } 1779}; 1780 1781/// VirtSpecifiers - Represents a C++0x virt-specifier-seq. 1782class VirtSpecifiers { 1783public: 1784 enum Specifier { 1785 VS_None = 0, 1786 VS_Override = 1, 1787 VS_Final = 2 1788 }; 1789 1790 VirtSpecifiers() : Specifiers(0) { } 1791 1792 bool SetSpecifier(Specifier VS, SourceLocation Loc, 1793 const char *&PrevSpec); 1794 1795 bool isOverrideSpecified() const { return Specifiers & VS_Override; } 1796 SourceLocation getOverrideLoc() const { return VS_overrideLoc; } 1797 1798 bool isFinalSpecified() const { return Specifiers & VS_Final; } 1799 SourceLocation getFinalLoc() const { return VS_finalLoc; } 1800 1801 void clear() { Specifiers = 0; } 1802 1803 static const char *getSpecifierName(Specifier VS); 1804 1805 SourceLocation getLastLocation() const { return LastLocation; } 1806 1807private: 1808 unsigned Specifiers; 1809 1810 SourceLocation VS_overrideLoc, VS_finalLoc; 1811 SourceLocation LastLocation; 1812}; 1813 1814} // end namespace clang 1815 1816#endif 1817