DeclSpec.cpp revision b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970c
1//===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===// 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 implements semantic analysis for declaration specifiers. 11// 12//===----------------------------------------------------------------------===// 13 14#include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency! 15#include "clang/Sema/DeclSpec.h" 16#include "clang/Sema/ParsedTemplate.h" 17#include "clang/Lex/Preprocessor.h" 18#include "clang/Basic/LangOptions.h" 19#include "llvm/ADT/STLExtras.h" 20#include "llvm/Support/ErrorHandling.h" 21#include <cstring> 22using namespace clang; 23 24 25static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, 26 SourceManager &SrcMgr, unsigned DiagID) { 27 return D.Report(FullSourceLoc(Loc, SrcMgr), DiagID); 28} 29 30 31void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) { 32 assert(TemplateId && "NULL template-id annotation?"); 33 Kind = IK_TemplateId; 34 this->TemplateId = TemplateId; 35 StartLocation = TemplateId->TemplateNameLoc; 36 EndLocation = TemplateId->RAngleLoc; 37} 38 39void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) { 40 assert(TemplateId && "NULL template-id annotation?"); 41 Kind = IK_ConstructorTemplateId; 42 this->TemplateId = TemplateId; 43 StartLocation = TemplateId->TemplateNameLoc; 44 EndLocation = TemplateId->RAngleLoc; 45} 46 47/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. 48/// "TheDeclarator" is the declarator that this will be added to. 49DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic, 50 SourceLocation EllipsisLoc, 51 ParamInfo *ArgInfo, 52 unsigned NumArgs, 53 unsigned TypeQuals, 54 bool hasExceptionSpec, 55 SourceLocation ThrowLoc, 56 bool hasAnyExceptionSpec, 57 ParsedType *Exceptions, 58 SourceRange *ExceptionRanges, 59 unsigned NumExceptions, 60 SourceLocation LPLoc, 61 SourceLocation RPLoc, 62 Declarator &TheDeclarator) { 63 DeclaratorChunk I; 64 I.Kind = Function; 65 I.Loc = LPLoc; 66 I.EndLoc = RPLoc; 67 I.Fun.hasPrototype = hasProto; 68 I.Fun.isVariadic = isVariadic; 69 I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding(); 70 I.Fun.DeleteArgInfo = false; 71 I.Fun.TypeQuals = TypeQuals; 72 I.Fun.NumArgs = NumArgs; 73 I.Fun.ArgInfo = 0; 74 I.Fun.hasExceptionSpec = hasExceptionSpec; 75 I.Fun.ThrowLoc = ThrowLoc.getRawEncoding(); 76 I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec; 77 I.Fun.NumExceptions = NumExceptions; 78 I.Fun.Exceptions = 0; 79 80 // new[] an argument array if needed. 81 if (NumArgs) { 82 // If the 'InlineParams' in Declarator is unused and big enough, put our 83 // parameter list there (in an effort to avoid new/delete traffic). If it 84 // is already used (consider a function returning a function pointer) or too 85 // small (function taking too many arguments), go to the heap. 86 if (!TheDeclarator.InlineParamsUsed && 87 NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { 88 I.Fun.ArgInfo = TheDeclarator.InlineParams; 89 I.Fun.DeleteArgInfo = false; 90 TheDeclarator.InlineParamsUsed = true; 91 } else { 92 I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; 93 I.Fun.DeleteArgInfo = true; 94 } 95 memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); 96 } 97 // new[] an exception array if needed 98 if (NumExceptions) { 99 I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions]; 100 for (unsigned i = 0; i != NumExceptions; ++i) { 101 I.Fun.Exceptions[i].Ty = Exceptions[i]; 102 I.Fun.Exceptions[i].Range = ExceptionRanges[i]; 103 } 104 } 105 return I; 106} 107 108/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this 109/// declaration specifier includes. 110/// 111unsigned DeclSpec::getParsedSpecifiers() const { 112 unsigned Res = 0; 113 if (StorageClassSpec != SCS_unspecified || 114 SCS_thread_specified) 115 Res |= PQ_StorageClassSpecifier; 116 117 if (TypeQualifiers != TQ_unspecified) 118 Res |= PQ_TypeQualifier; 119 120 if (hasTypeSpecifier()) 121 Res |= PQ_TypeSpecifier; 122 123 if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified) 124 Res |= PQ_FunctionSpecifier; 125 return Res; 126} 127 128template <class T> static bool BadSpecifier(T TNew, T TPrev, 129 const char *&PrevSpec, 130 unsigned &DiagID) { 131 PrevSpec = DeclSpec::getSpecifierName(TPrev); 132 DiagID = (TNew == TPrev ? diag::ext_duplicate_declspec 133 : diag::err_invalid_decl_spec_combination); 134 return true; 135} 136 137const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { 138 switch (S) { 139 case DeclSpec::SCS_unspecified: return "unspecified"; 140 case DeclSpec::SCS_typedef: return "typedef"; 141 case DeclSpec::SCS_extern: return "extern"; 142 case DeclSpec::SCS_static: return "static"; 143 case DeclSpec::SCS_auto: return "auto"; 144 case DeclSpec::SCS_register: return "register"; 145 case DeclSpec::SCS_private_extern: return "__private_extern__"; 146 case DeclSpec::SCS_mutable: return "mutable"; 147 } 148 llvm_unreachable("Unknown typespec!"); 149} 150 151const char *DeclSpec::getSpecifierName(TSW W) { 152 switch (W) { 153 case TSW_unspecified: return "unspecified"; 154 case TSW_short: return "short"; 155 case TSW_long: return "long"; 156 case TSW_longlong: return "long long"; 157 } 158 llvm_unreachable("Unknown typespec!"); 159} 160 161const char *DeclSpec::getSpecifierName(TSC C) { 162 switch (C) { 163 case TSC_unspecified: return "unspecified"; 164 case TSC_imaginary: return "imaginary"; 165 case TSC_complex: return "complex"; 166 } 167 llvm_unreachable("Unknown typespec!"); 168} 169 170 171const char *DeclSpec::getSpecifierName(TSS S) { 172 switch (S) { 173 case TSS_unspecified: return "unspecified"; 174 case TSS_signed: return "signed"; 175 case TSS_unsigned: return "unsigned"; 176 } 177 llvm_unreachable("Unknown typespec!"); 178} 179 180const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { 181 switch (T) { 182 case DeclSpec::TST_unspecified: return "unspecified"; 183 case DeclSpec::TST_void: return "void"; 184 case DeclSpec::TST_char: return "char"; 185 case DeclSpec::TST_wchar: return "wchar_t"; 186 case DeclSpec::TST_char16: return "char16_t"; 187 case DeclSpec::TST_char32: return "char32_t"; 188 case DeclSpec::TST_int: return "int"; 189 case DeclSpec::TST_float: return "float"; 190 case DeclSpec::TST_double: return "double"; 191 case DeclSpec::TST_bool: return "_Bool"; 192 case DeclSpec::TST_decimal32: return "_Decimal32"; 193 case DeclSpec::TST_decimal64: return "_Decimal64"; 194 case DeclSpec::TST_decimal128: return "_Decimal128"; 195 case DeclSpec::TST_enum: return "enum"; 196 case DeclSpec::TST_class: return "class"; 197 case DeclSpec::TST_union: return "union"; 198 case DeclSpec::TST_struct: return "struct"; 199 case DeclSpec::TST_typename: return "type-name"; 200 case DeclSpec::TST_typeofType: 201 case DeclSpec::TST_typeofExpr: return "typeof"; 202 case DeclSpec::TST_auto: return "auto"; 203 case DeclSpec::TST_decltype: return "(decltype)"; 204 case DeclSpec::TST_error: return "(error)"; 205 } 206 llvm_unreachable("Unknown typespec!"); 207} 208 209const char *DeclSpec::getSpecifierName(TQ T) { 210 switch (T) { 211 case DeclSpec::TQ_unspecified: return "unspecified"; 212 case DeclSpec::TQ_const: return "const"; 213 case DeclSpec::TQ_restrict: return "restrict"; 214 case DeclSpec::TQ_volatile: return "volatile"; 215 } 216 llvm_unreachable("Unknown typespec!"); 217} 218 219bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, 220 const char *&PrevSpec, 221 unsigned &DiagID) { 222 if (StorageClassSpec != SCS_unspecified) { 223 // Changing storage class is allowed only if the previous one 224 // was the 'extern' that is part of a linkage specification and 225 // the new storage class is 'typedef'. 226 if (!(SCS_extern_in_linkage_spec && 227 StorageClassSpec == SCS_extern && 228 S == SCS_typedef)) 229 return BadSpecifier(S, (SCS)StorageClassSpec, PrevSpec, DiagID); 230 } 231 StorageClassSpec = S; 232 StorageClassSpecLoc = Loc; 233 assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); 234 return false; 235} 236 237bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, 238 const char *&PrevSpec, 239 unsigned &DiagID) { 240 if (SCS_thread_specified) { 241 PrevSpec = "__thread"; 242 DiagID = diag::ext_duplicate_declspec; 243 return true; 244 } 245 SCS_thread_specified = true; 246 SCS_threadLoc = Loc; 247 return false; 248} 249 250/// These methods set the specified attribute of the DeclSpec, but return true 251/// and ignore the request if invalid (e.g. "extern" then "auto" is 252/// specified). 253bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, 254 const char *&PrevSpec, 255 unsigned &DiagID) { 256 if (TypeSpecWidth != TSW_unspecified && 257 // Allow turning long -> long long. 258 (W != TSW_longlong || TypeSpecWidth != TSW_long)) 259 return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); 260 TypeSpecWidth = W; 261 TSWLoc = Loc; 262 if (TypeAltiVecVector && !TypeAltiVecBool && 263 ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) { 264 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 265 DiagID = diag::warn_vector_long_decl_spec_combination; 266 return true; 267 } 268 return false; 269} 270 271bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, 272 const char *&PrevSpec, 273 unsigned &DiagID) { 274 if (TypeSpecComplex != TSC_unspecified) 275 return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); 276 TypeSpecComplex = C; 277 TSCLoc = Loc; 278 return false; 279} 280 281bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, 282 const char *&PrevSpec, 283 unsigned &DiagID) { 284 if (TypeSpecSign != TSS_unspecified) 285 return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID); 286 TypeSpecSign = S; 287 TSSLoc = Loc; 288 return false; 289} 290 291bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, 292 const char *&PrevSpec, 293 unsigned &DiagID, 294 ParsedType Rep) { 295 assert(isTypeRep(T) && "T does not store a type"); 296 assert(Rep && "no type provided!"); 297 if (TypeSpecType != TST_unspecified) { 298 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 299 DiagID = diag::err_invalid_decl_spec_combination; 300 return true; 301 } 302 TypeSpecType = T; 303 TypeRep = Rep; 304 TSTLoc = Loc; 305 TypeSpecOwned = false; 306 return false; 307} 308 309bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, 310 const char *&PrevSpec, 311 unsigned &DiagID, 312 Expr *Rep) { 313 assert(isExprRep(T) && "T does not store an expr"); 314 assert(Rep && "no expression provided!"); 315 if (TypeSpecType != TST_unspecified) { 316 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 317 DiagID = diag::err_invalid_decl_spec_combination; 318 return true; 319 } 320 TypeSpecType = T; 321 ExprRep = Rep; 322 TSTLoc = Loc; 323 TypeSpecOwned = false; 324 return false; 325} 326 327bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, 328 const char *&PrevSpec, 329 unsigned &DiagID, 330 Decl *Rep, bool Owned) { 331 assert(isDeclRep(T) && "T does not store a decl"); 332 // Unlike the other cases, we don't assert that we actually get a decl. 333 334 if (TypeSpecType != TST_unspecified) { 335 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 336 DiagID = diag::err_invalid_decl_spec_combination; 337 return true; 338 } 339 TypeSpecType = T; 340 DeclRep = Rep; 341 TSTLoc = Loc; 342 TypeSpecOwned = Owned; 343 return false; 344} 345 346bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, 347 const char *&PrevSpec, 348 unsigned &DiagID) { 349 assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && 350 "rep required for these type-spec kinds!"); 351 if (TypeSpecType != TST_unspecified) { 352 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 353 DiagID = diag::err_invalid_decl_spec_combination; 354 return true; 355 } 356 if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { 357 TypeAltiVecBool = true; 358 TSTLoc = Loc; 359 return false; 360 } 361 TypeSpecType = T; 362 TSTLoc = Loc; 363 TypeSpecOwned = false; 364 if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { 365 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 366 DiagID = diag::err_invalid_vector_decl_spec; 367 return true; 368 } 369 return false; 370} 371 372bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, 373 const char *&PrevSpec, unsigned &DiagID) { 374 if (TypeSpecType != TST_unspecified) { 375 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 376 DiagID = diag::err_invalid_vector_decl_spec_combination; 377 return true; 378 } 379 TypeAltiVecVector = isAltiVecVector; 380 AltiVecLoc = Loc; 381 return false; 382} 383 384bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, 385 const char *&PrevSpec, unsigned &DiagID) { 386 if (!TypeAltiVecVector || TypeAltiVecPixel || 387 (TypeSpecType != TST_unspecified)) { 388 PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); 389 DiagID = diag::err_invalid_pixel_decl_spec_combination; 390 return true; 391 } 392 TypeAltiVecPixel = isAltiVecPixel; 393 TSTLoc = Loc; 394 return false; 395} 396 397bool DeclSpec::SetTypeSpecError() { 398 TypeSpecType = TST_error; 399 TSTLoc = SourceLocation(); 400 return false; 401} 402 403bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, 404 unsigned &DiagID, const LangOptions &Lang) { 405 // Duplicates turn into warnings pre-C99. 406 if ((TypeQualifiers & T) && !Lang.C99) 407 return BadSpecifier(T, T, PrevSpec, DiagID); 408 TypeQualifiers |= T; 409 410 switch (T) { 411 default: assert(0 && "Unknown type qualifier!"); 412 case TQ_const: TQ_constLoc = Loc; break; 413 case TQ_restrict: TQ_restrictLoc = Loc; break; 414 case TQ_volatile: TQ_volatileLoc = Loc; break; 415 } 416 return false; 417} 418 419bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, 420 unsigned &DiagID) { 421 // 'inline inline' is ok. 422 FS_inline_specified = true; 423 FS_inlineLoc = Loc; 424 return false; 425} 426 427bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, 428 unsigned &DiagID) { 429 // 'virtual virtual' is ok. 430 FS_virtual_specified = true; 431 FS_virtualLoc = Loc; 432 return false; 433} 434 435bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, 436 unsigned &DiagID) { 437 // 'explicit explicit' is ok. 438 FS_explicit_specified = true; 439 FS_explicitLoc = Loc; 440 return false; 441} 442 443bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, 444 unsigned &DiagID) { 445 if (Friend_specified) { 446 PrevSpec = "friend"; 447 DiagID = diag::ext_duplicate_declspec; 448 return true; 449 } 450 451 Friend_specified = true; 452 FriendLoc = Loc; 453 return false; 454} 455 456bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, 457 unsigned &DiagID) { 458 // 'constexpr constexpr' is ok. 459 Constexpr_specified = true; 460 ConstexprLoc = Loc; 461 return false; 462} 463 464void DeclSpec::setProtocolQualifiers(Decl * const *Protos, 465 unsigned NP, 466 SourceLocation *ProtoLocs, 467 SourceLocation LAngleLoc) { 468 if (NP == 0) return; 469 ProtocolQualifiers = new Decl*[NP]; 470 ProtocolLocs = new SourceLocation[NP]; 471 memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP); 472 memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP); 473 NumProtocolQualifiers = NP; 474 ProtocolLAngleLoc = LAngleLoc; 475} 476 477void DeclSpec::SaveWrittenBuiltinSpecs() { 478 writtenBS.Sign = getTypeSpecSign(); 479 writtenBS.Width = getTypeSpecWidth(); 480 writtenBS.Type = getTypeSpecType(); 481 // Search the list of attributes for the presence of a mode attribute. 482 writtenBS.ModeAttr = false; 483 AttributeList* attrs = getAttributes(); 484 while (attrs) { 485 if (attrs->getKind() == AttributeList::AT_mode) { 486 writtenBS.ModeAttr = true; 487 break; 488 } 489 attrs = attrs->getNext(); 490 } 491} 492 493void DeclSpec::SaveStorageSpecifierAsWritten() { 494 if (SCS_extern_in_linkage_spec && StorageClassSpec == SCS_extern) 495 // If 'extern' is part of a linkage specification, 496 // then it is not a storage class "as written". 497 StorageClassSpecAsWritten = SCS_unspecified; 498 else 499 StorageClassSpecAsWritten = StorageClassSpec; 500} 501 502/// Finish - This does final analysis of the declspec, rejecting things like 503/// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or 504/// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, 505/// DeclSpec is guaranteed self-consistent, even if an error occurred. 506void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) { 507 // Before possibly changing their values, save specs as written. 508 SaveWrittenBuiltinSpecs(); 509 SaveStorageSpecifierAsWritten(); 510 511 // Check the type specifier components first. 512 SourceManager &SrcMgr = PP.getSourceManager(); 513 514 // Validate and finalize AltiVec vector declspec. 515 if (TypeAltiVecVector) { 516 if (TypeAltiVecBool) { 517 // Sign specifiers are not allowed with vector bool. (PIM 2.1) 518 if (TypeSpecSign != TSS_unspecified) { 519 Diag(D, TSSLoc, SrcMgr, diag::err_invalid_vector_bool_decl_spec) 520 << getSpecifierName((TSS)TypeSpecSign); 521 } 522 523 // Only char/int are valid with vector bool. (PIM 2.1) 524 if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) && 525 (TypeSpecType != TST_int)) || TypeAltiVecPixel) { 526 Diag(D, TSTLoc, SrcMgr, diag::err_invalid_vector_bool_decl_spec) 527 << (TypeAltiVecPixel ? "__pixel" : 528 getSpecifierName((TST)TypeSpecType)); 529 } 530 531 // Only 'short' is valid with vector bool. (PIM 2.1) 532 if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short)) 533 Diag(D, TSWLoc, SrcMgr, diag::err_invalid_vector_bool_decl_spec) 534 << getSpecifierName((TSW)TypeSpecWidth); 535 536 // Elements of vector bool are interpreted as unsigned. (PIM 2.1) 537 if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) || 538 (TypeSpecWidth != TSW_unspecified)) 539 TypeSpecSign = TSS_unsigned; 540 } 541 542 if (TypeAltiVecPixel) { 543 //TODO: perform validation 544 TypeSpecType = TST_int; 545 TypeSpecSign = TSS_unsigned; 546 TypeSpecWidth = TSW_short; 547 } 548 } 549 550 // signed/unsigned are only valid with int/char/wchar_t. 551 if (TypeSpecSign != TSS_unspecified) { 552 if (TypeSpecType == TST_unspecified) 553 TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. 554 else if (TypeSpecType != TST_int && 555 TypeSpecType != TST_char && TypeSpecType != TST_wchar) { 556 Diag(D, TSSLoc, SrcMgr, diag::err_invalid_sign_spec) 557 << getSpecifierName((TST)TypeSpecType); 558 // signed double -> double. 559 TypeSpecSign = TSS_unspecified; 560 } 561 } 562 563 // Validate the width of the type. 564 switch (TypeSpecWidth) { 565 case TSW_unspecified: break; 566 case TSW_short: // short int 567 case TSW_longlong: // long long int 568 if (TypeSpecType == TST_unspecified) 569 TypeSpecType = TST_int; // short -> short int, long long -> long long int. 570 else if (TypeSpecType != TST_int) { 571 Diag(D, TSWLoc, SrcMgr, 572 TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec 573 : diag::err_invalid_longlong_spec) 574 << getSpecifierName((TST)TypeSpecType); 575 TypeSpecType = TST_int; 576 } 577 break; 578 case TSW_long: // long double, long int 579 if (TypeSpecType == TST_unspecified) 580 TypeSpecType = TST_int; // long -> long int. 581 else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { 582 Diag(D, TSWLoc, SrcMgr, diag::err_invalid_long_spec) 583 << getSpecifierName((TST)TypeSpecType); 584 TypeSpecType = TST_int; 585 } 586 break; 587 } 588 589 // TODO: if the implementation does not implement _Complex or _Imaginary, 590 // disallow their use. Need information about the backend. 591 if (TypeSpecComplex != TSC_unspecified) { 592 if (TypeSpecType == TST_unspecified) { 593 Diag(D, TSCLoc, SrcMgr, diag::ext_plain_complex) 594 << FixItHint::CreateInsertion( 595 PP.getLocForEndOfToken(getTypeSpecComplexLoc()), 596 " double"); 597 TypeSpecType = TST_double; // _Complex -> _Complex double. 598 } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { 599 // Note that this intentionally doesn't include _Complex _Bool. 600 Diag(D, TSTLoc, SrcMgr, diag::ext_integer_complex); 601 } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { 602 Diag(D, TSCLoc, SrcMgr, diag::err_invalid_complex_spec) 603 << getSpecifierName((TST)TypeSpecType); 604 TypeSpecComplex = TSC_unspecified; 605 } 606 } 607 608 // C++ [class.friend]p6: 609 // No storage-class-specifier shall appear in the decl-specifier-seq 610 // of a friend declaration. 611 if (isFriendSpecified() && getStorageClassSpec()) { 612 DeclSpec::SCS SC = getStorageClassSpec(); 613 const char *SpecName = getSpecifierName(SC); 614 615 SourceLocation SCLoc = getStorageClassSpecLoc(); 616 SourceLocation SCEndLoc = SCLoc.getFileLocWithOffset(strlen(SpecName)); 617 618 Diag(D, SCLoc, SrcMgr, diag::err_friend_storage_spec) 619 << SpecName 620 << FixItHint::CreateRemoval(SourceRange(SCLoc, SCEndLoc)); 621 622 ClearStorageClassSpecs(); 623 } 624 625 // Okay, now we can infer the real type. 626 627 // TODO: return "auto function" and other bad things based on the real type. 628 629 // 'data definition has no type or storage class'? 630} 631 632bool DeclSpec::isMissingDeclaratorOk() { 633 TST tst = getTypeSpecType(); 634 return isDeclRep(tst) && getRepAsDecl() != 0 && 635 StorageClassSpec != DeclSpec::SCS_typedef; 636} 637 638void UnqualifiedId::clear() { 639 if (Kind == IK_TemplateId) 640 TemplateId->Destroy(); 641 642 Kind = IK_Identifier; 643 Identifier = 0; 644 StartLocation = SourceLocation(); 645 EndLocation = SourceLocation(); 646} 647 648void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, 649 OverloadedOperatorKind Op, 650 SourceLocation SymbolLocations[3]) { 651 Kind = IK_OperatorFunctionId; 652 StartLocation = OperatorLoc; 653 EndLocation = OperatorLoc; 654 OperatorFunctionId.Operator = Op; 655 for (unsigned I = 0; I != 3; ++I) { 656 OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding(); 657 658 if (SymbolLocations[I].isValid()) 659 EndLocation = SymbolLocations[I]; 660 } 661} 662