| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "clang/Parse/Parser.h" |
| 14 | #include "clang/Parse/RAIIObjectsForParser.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/DeclTemplate.h" |
| 17 | #include "clang/AST/PrettyDeclStackTrace.h" |
| 18 | #include "clang/Basic/AddressSpaces.h" |
| 19 | #include "clang/Basic/Attributes.h" |
| 20 | #include "clang/Basic/CharInfo.h" |
| 21 | #include "clang/Basic/TargetInfo.h" |
| 22 | #include "clang/Parse/ParseDiagnostic.h" |
| 23 | #include "clang/Sema/Lookup.h" |
| 24 | #include "clang/Sema/ParsedTemplate.h" |
| 25 | #include "clang/Sema/Scope.h" |
| 26 | #include "llvm/ADT/Optional.h" |
| 27 | #include "llvm/ADT/SmallSet.h" |
| 28 | #include "llvm/ADT/SmallString.h" |
| 29 | #include "llvm/ADT/StringSwitch.h" |
| 30 | |
| 31 | using namespace clang; |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | TypeResult Parser::ParseTypeName(SourceRange *Range, |
| 43 | DeclaratorContext Context, |
| 44 | AccessSpecifier AS, |
| 45 | Decl **OwnedType, |
| 46 | ParsedAttributes *Attrs) { |
| 47 | DeclSpecContext DSC = getDeclSpecContextFromDeclaratorContext(Context); |
| 48 | if (DSC == DeclSpecContext::DSC_normal) |
| 49 | DSC = DeclSpecContext::DSC_type_specifier; |
| 50 | |
| 51 | |
| 52 | DeclSpec DS(AttrFactory); |
| 53 | if (Attrs) |
| 54 | DS.addAttributes(*Attrs); |
| 55 | ParseSpecifierQualifierList(DS, AS, DSC); |
| 56 | if (OwnedType) |
| 57 | *OwnedType = DS.isTypeSpecOwned() ? DS.getRepAsDecl() : nullptr; |
| 58 | |
| 59 | |
| 60 | Declarator DeclaratorInfo(DS, Context); |
| 61 | ParseDeclarator(DeclaratorInfo); |
| 62 | if (Range) |
| 63 | *Range = DeclaratorInfo.getSourceRange(); |
| 64 | |
| 65 | if (DeclaratorInfo.isInvalidType()) |
| 66 | return true; |
| 67 | |
| 68 | return Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | static StringRef normalizeAttrName(StringRef Name) { |
| 73 | if (Name.size() >= 4 && Name.startswith("__") && Name.endswith("__")) |
| 74 | return Name.drop_front(2).drop_back(2); |
| 75 | return Name; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | static bool isAttributeLateParsed(const IdentifierInfo &II) { |
| 81 | #define CLANG_ATTR_LATE_PARSED_LIST |
| 82 | return llvm::StringSwitch<bool>(normalizeAttrName(II.getName())) |
| 83 | #include "clang/Parse/AttrParserStringSwitches.inc" |
| 84 | .Default(false); |
| 85 | #undef CLANG_ATTR_LATE_PARSED_LIST |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | void Parser::ParseGNUAttributes(ParsedAttributes &attrs, |
| 130 | SourceLocation *endLoc, |
| 131 | LateParsedAttrList *LateAttrs, |
| 132 | Declarator *D) { |
| 133 | (0) . __assert_fail ("Tok.is(tok..kw___attribute) && \"Not a GNU attribute list!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 133, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw___attribute) && "Not a GNU attribute list!"); |
| 134 | |
| 135 | while (Tok.is(tok::kw___attribute)) { |
| 136 | ConsumeToken(); |
| 137 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, |
| 138 | "attribute")) { |
| 139 | SkipUntil(tok::r_paren, StopAtSemi); |
| 140 | return; |
| 141 | } |
| 142 | if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, "(")) { |
| 143 | SkipUntil(tok::r_paren, StopAtSemi); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | while (true) { |
| 148 | |
| 149 | if (TryConsumeToken(tok::comma)) |
| 150 | continue; |
| 151 | |
| 152 | |
| 153 | if (Tok.isAnnotation()) |
| 154 | break; |
| 155 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 156 | if (!AttrName) |
| 157 | break; |
| 158 | |
| 159 | SourceLocation AttrNameLoc = ConsumeToken(); |
| 160 | |
| 161 | if (Tok.isNot(tok::l_paren)) { |
| 162 | attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 163 | ParsedAttr::AS_GNU); |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | if (!LateAttrs || !isAttributeLateParsed(*AttrName)) { |
| 169 | ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc, nullptr, |
| 170 | SourceLocation(), ParsedAttr::AS_GNU, D); |
| 171 | continue; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | LateParsedAttribute *LA = |
| 176 | new LateParsedAttribute(this, *AttrName, AttrNameLoc); |
| 177 | LateAttrs->push_back(LA); |
| 178 | |
| 179 | |
| 180 | |
| 181 | if (!ClassStack.empty() && !LateAttrs->parseSoon()) |
| 182 | getCurrentClass().LateParsedDeclarations.push_back(LA); |
| 183 | |
| 184 | |
| 185 | |
| 186 | LA->Toks.push_back(Tok); |
| 187 | ConsumeParen(); |
| 188 | |
| 189 | ConsumeAndStoreUntil(tok::r_paren, LA->Toks, ); |
| 190 | |
| 191 | Token Eof; |
| 192 | Eof.startToken(); |
| 193 | Eof.setLocation(Tok.getLocation()); |
| 194 | LA->Toks.push_back(Eof); |
| 195 | } |
| 196 | |
| 197 | if (ExpectAndConsume(tok::r_paren)) |
| 198 | SkipUntil(tok::r_paren, StopAtSemi); |
| 199 | SourceLocation Loc = Tok.getLocation(); |
| 200 | if (ExpectAndConsume(tok::r_paren)) |
| 201 | SkipUntil(tok::r_paren, StopAtSemi); |
| 202 | if (endLoc) |
| 203 | *endLoc = Loc; |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | |
| 208 | static bool attributeHasIdentifierArg(const IdentifierInfo &II) { |
| 209 | #define CLANG_ATTR_IDENTIFIER_ARG_LIST |
| 210 | return llvm::StringSwitch<bool>(normalizeAttrName(II.getName())) |
| 211 | #include "clang/Parse/AttrParserStringSwitches.inc" |
| 212 | .Default(false); |
| 213 | #undef CLANG_ATTR_IDENTIFIER_ARG_LIST |
| 214 | } |
| 215 | |
| 216 | |
| 217 | static bool attributeHasVariadicIdentifierArg(const IdentifierInfo &II) { |
| 218 | #define CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST |
| 219 | return llvm::StringSwitch<bool>(normalizeAttrName(II.getName())) |
| 220 | #include "clang/Parse/AttrParserStringSwitches.inc" |
| 221 | .Default(false); |
| 222 | #undef CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST |
| 223 | } |
| 224 | |
| 225 | |
| 226 | static bool attributeTreatsKeywordThisAsIdentifier(const IdentifierInfo &II) { |
| 227 | #define CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST |
| 228 | return llvm::StringSwitch<bool>(normalizeAttrName(II.getName())) |
| 229 | #include "clang/Parse/AttrParserStringSwitches.inc" |
| 230 | .Default(false); |
| 231 | #undef CLANG_ATTR_THIS_ISA_IDENTIFIER_ARG_LIST |
| 232 | } |
| 233 | |
| 234 | |
| 235 | static bool attributeIsTypeArgAttr(const IdentifierInfo &II) { |
| 236 | #define CLANG_ATTR_TYPE_ARG_LIST |
| 237 | return llvm::StringSwitch<bool>(normalizeAttrName(II.getName())) |
| 238 | #include "clang/Parse/AttrParserStringSwitches.inc" |
| 239 | .Default(false); |
| 240 | #undef CLANG_ATTR_TYPE_ARG_LIST |
| 241 | } |
| 242 | |
| 243 | |
| 244 | |
| 245 | static bool attributeParsedArgsUnevaluated(const IdentifierInfo &II) { |
| 246 | #define CLANG_ATTR_ARG_CONTEXT_LIST |
| 247 | return llvm::StringSwitch<bool>(normalizeAttrName(II.getName())) |
| 248 | #include "clang/Parse/AttrParserStringSwitches.inc" |
| 249 | .Default(false); |
| 250 | #undef CLANG_ATTR_ARG_CONTEXT_LIST |
| 251 | } |
| 252 | |
| 253 | IdentifierLoc *Parser::ParseIdentifierLoc() { |
| 254 | (0) . __assert_fail ("Tok.is(tok..identifier) && \"expected an identifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 254, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::identifier) && "expected an identifier"); |
| 255 | IdentifierLoc *IL = IdentifierLoc::create(Actions.Context, |
| 256 | Tok.getLocation(), |
| 257 | Tok.getIdentifierInfo()); |
| 258 | ConsumeToken(); |
| 259 | return IL; |
| 260 | } |
| 261 | |
| 262 | void Parser::ParseAttributeWithTypeArg(IdentifierInfo &AttrName, |
| 263 | SourceLocation AttrNameLoc, |
| 264 | ParsedAttributes &Attrs, |
| 265 | SourceLocation *EndLoc, |
| 266 | IdentifierInfo *ScopeName, |
| 267 | SourceLocation ScopeLoc, |
| 268 | ParsedAttr::Syntax Syntax) { |
| 269 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 270 | Parens.consumeOpen(); |
| 271 | |
| 272 | TypeResult T; |
| 273 | if (Tok.isNot(tok::r_paren)) |
| 274 | T = ParseTypeName(); |
| 275 | |
| 276 | if (Parens.consumeClose()) |
| 277 | return; |
| 278 | |
| 279 | if (T.isInvalid()) |
| 280 | return; |
| 281 | |
| 282 | if (T.isUsable()) |
| 283 | Attrs.addNewTypeAttr(&AttrName, |
| 284 | SourceRange(AttrNameLoc, Parens.getCloseLocation()), |
| 285 | ScopeName, ScopeLoc, T.get(), Syntax); |
| 286 | else |
| 287 | Attrs.addNew(&AttrName, SourceRange(AttrNameLoc, Parens.getCloseLocation()), |
| 288 | ScopeName, ScopeLoc, nullptr, 0, Syntax); |
| 289 | } |
| 290 | |
| 291 | unsigned Parser::ParseAttributeArgsCommon( |
| 292 | IdentifierInfo *AttrName, SourceLocation AttrNameLoc, |
| 293 | ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, |
| 294 | SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { |
| 295 | |
| 296 | ConsumeParen(); |
| 297 | |
| 298 | bool ChangeKWThisToIdent = attributeTreatsKeywordThisAsIdentifier(*AttrName); |
| 299 | |
| 300 | |
| 301 | if (ChangeKWThisToIdent && Tok.is(tok::kw_this)) |
| 302 | Tok.setKind(tok::identifier); |
| 303 | |
| 304 | ArgsVector ArgExprs; |
| 305 | if (Tok.is(tok::identifier)) { |
| 306 | |
| 307 | bool IsIdentifierArg = attributeHasIdentifierArg(*AttrName) || |
| 308 | attributeHasVariadicIdentifierArg(*AttrName); |
| 309 | ParsedAttr::Kind AttrKind = |
| 310 | ParsedAttr::getKind(AttrName, ScopeName, Syntax); |
| 311 | |
| 312 | |
| 313 | |
| 314 | if (AttrKind == ParsedAttr::UnknownAttribute || |
| 315 | AttrKind == ParsedAttr::IgnoredAttribute) { |
| 316 | const Token &Next = NextToken(); |
| 317 | IsIdentifierArg = Next.isOneOf(tok::r_paren, tok::comma); |
| 318 | } |
| 319 | |
| 320 | if (IsIdentifierArg) |
| 321 | ArgExprs.push_back(ParseIdentifierLoc()); |
| 322 | } |
| 323 | |
| 324 | if (!ArgExprs.empty() ? Tok.is(tok::comma) : Tok.isNot(tok::r_paren)) { |
| 325 | |
| 326 | if (!ArgExprs.empty()) |
| 327 | ConsumeToken(); |
| 328 | |
| 329 | |
| 330 | do { |
| 331 | |
| 332 | if (ChangeKWThisToIdent && Tok.is(tok::kw_this)) |
| 333 | Tok.setKind(tok::identifier); |
| 334 | |
| 335 | ExprResult ArgExpr; |
| 336 | if (Tok.is(tok::identifier) && |
| 337 | attributeHasVariadicIdentifierArg(*AttrName)) { |
| 338 | ArgExprs.push_back(ParseIdentifierLoc()); |
| 339 | } else { |
| 340 | bool Uneval = attributeParsedArgsUnevaluated(*AttrName); |
| 341 | EnterExpressionEvaluationContext Unevaluated( |
| 342 | Actions, |
| 343 | Uneval ? Sema::ExpressionEvaluationContext::Unevaluated |
| 344 | : Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 345 | |
| 346 | ExprResult ArgExpr( |
| 347 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression())); |
| 348 | if (ArgExpr.isInvalid()) { |
| 349 | SkipUntil(tok::r_paren, StopAtSemi); |
| 350 | return 0; |
| 351 | } |
| 352 | ArgExprs.push_back(ArgExpr.get()); |
| 353 | } |
| 354 | |
| 355 | } while (TryConsumeToken(tok::comma)); |
| 356 | } |
| 357 | |
| 358 | SourceLocation RParen = Tok.getLocation(); |
| 359 | if (!ExpectAndConsume(tok::r_paren)) { |
| 360 | SourceLocation AttrLoc = ScopeLoc.isValid() ? ScopeLoc : AttrNameLoc; |
| 361 | Attrs.addNew(AttrName, SourceRange(AttrLoc, RParen), ScopeName, ScopeLoc, |
| 362 | ArgExprs.data(), ArgExprs.size(), Syntax); |
| 363 | } |
| 364 | |
| 365 | if (EndLoc) |
| 366 | *EndLoc = RParen; |
| 367 | |
| 368 | return static_cast<unsigned>(ArgExprs.size()); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | |
| 373 | void Parser::ParseGNUAttributeArgs(IdentifierInfo *AttrName, |
| 374 | SourceLocation AttrNameLoc, |
| 375 | ParsedAttributes &Attrs, |
| 376 | SourceLocation *EndLoc, |
| 377 | IdentifierInfo *ScopeName, |
| 378 | SourceLocation ScopeLoc, |
| 379 | ParsedAttr::Syntax Syntax, |
| 380 | Declarator *D) { |
| 381 | |
| 382 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Attribute arg list not starting with '('\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 382, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); |
| 383 | |
| 384 | ParsedAttr::Kind AttrKind = |
| 385 | ParsedAttr::getKind(AttrName, ScopeName, Syntax); |
| 386 | |
| 387 | if (AttrKind == ParsedAttr::AT_Availability) { |
| 388 | ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, |
| 389 | ScopeLoc, Syntax); |
| 390 | return; |
| 391 | } else if (AttrKind == ParsedAttr::AT_ExternalSourceSymbol) { |
| 392 | ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, |
| 393 | ScopeName, ScopeLoc, Syntax); |
| 394 | return; |
| 395 | } else if (AttrKind == ParsedAttr::AT_ObjCBridgeRelated) { |
| 396 | ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, |
| 397 | ScopeName, ScopeLoc, Syntax); |
| 398 | return; |
| 399 | } else if (AttrKind == ParsedAttr::AT_TypeTagForDatatype) { |
| 400 | ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, |
| 401 | ScopeName, ScopeLoc, Syntax); |
| 402 | return; |
| 403 | } else if (attributeIsTypeArgAttr(*AttrName)) { |
| 404 | ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, |
| 405 | ScopeLoc, Syntax); |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | |
| 411 | llvm::Optional<ParseScope> PrototypeScope; |
| 412 | if (normalizeAttrName(AttrName->getName()) == "enable_if" && |
| 413 | D && D->isFunctionDeclarator()) { |
| 414 | DeclaratorChunk::FunctionTypeInfo FTI = D->getFunctionTypeInfo(); |
| 415 | PrototypeScope.emplace(this, Scope::FunctionPrototypeScope | |
| 416 | Scope::FunctionDeclarationScope | |
| 417 | Scope::DeclScope); |
| 418 | for (unsigned i = 0; i != FTI.NumParams; ++i) { |
| 419 | ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param); |
| 420 | Actions.ActOnReenterCXXMethodParameter(getCurScope(), Param); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, |
| 425 | ScopeLoc, Syntax); |
| 426 | } |
| 427 | |
| 428 | unsigned Parser::ParseClangAttributeArgs( |
| 429 | IdentifierInfo *AttrName, SourceLocation AttrNameLoc, |
| 430 | ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, |
| 431 | SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { |
| 432 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Attribute arg list not starting with '('\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 432, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); |
| 433 | |
| 434 | ParsedAttr::Kind AttrKind = |
| 435 | ParsedAttr::getKind(AttrName, ScopeName, Syntax); |
| 436 | |
| 437 | switch (AttrKind) { |
| 438 | default: |
| 439 | return ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, |
| 440 | ScopeName, ScopeLoc, Syntax); |
| 441 | case ParsedAttr::AT_ExternalSourceSymbol: |
| 442 | ParseExternalSourceSymbolAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, |
| 443 | ScopeName, ScopeLoc, Syntax); |
| 444 | break; |
| 445 | case ParsedAttr::AT_Availability: |
| 446 | ParseAvailabilityAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, |
| 447 | ScopeLoc, Syntax); |
| 448 | break; |
| 449 | case ParsedAttr::AT_ObjCBridgeRelated: |
| 450 | ParseObjCBridgeRelatedAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, |
| 451 | ScopeName, ScopeLoc, Syntax); |
| 452 | break; |
| 453 | case ParsedAttr::AT_TypeTagForDatatype: |
| 454 | ParseTypeTagForDatatypeAttribute(*AttrName, AttrNameLoc, Attrs, EndLoc, |
| 455 | ScopeName, ScopeLoc, Syntax); |
| 456 | break; |
| 457 | } |
| 458 | return !Attrs.empty() ? Attrs.begin()->getNumArgs() : 0; |
| 459 | } |
| 460 | |
| 461 | bool Parser::ParseMicrosoftDeclSpecArgs(IdentifierInfo *AttrName, |
| 462 | SourceLocation AttrNameLoc, |
| 463 | ParsedAttributes &Attrs) { |
| 464 | |
| 465 | |
| 466 | if (!hasAttribute(AttrSyntax::Declspec, nullptr, AttrName, |
| 467 | getTargetInfo(), getLangOpts())) { |
| 468 | |
| 469 | ConsumeParen(); |
| 470 | SkipUntil(tok::r_paren); |
| 471 | return false; |
| 472 | } |
| 473 | |
| 474 | SourceLocation OpenParenLoc = Tok.getLocation(); |
| 475 | |
| 476 | if (AttrName->getName() == "property") { |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 482 | T.expectAndConsume(diag::err_expected_lparen_after, |
| 483 | AttrName->getNameStart(), tok::r_paren); |
| 484 | |
| 485 | enum AccessorKind { |
| 486 | AK_Invalid = -1, |
| 487 | AK_Put = 0, |
| 488 | AK_Get = 1 |
| 489 | }; |
| 490 | IdentifierInfo *AccessorNames[] = {nullptr, nullptr}; |
| 491 | bool HasInvalidAccessor = false; |
| 492 | |
| 493 | |
| 494 | while (true) { |
| 495 | |
| 496 | if (!Tok.is(tok::identifier)) { |
| 497 | |
| 498 | if (Tok.is(tok::r_paren) && !HasInvalidAccessor && |
| 499 | AccessorNames[AK_Put] == nullptr && |
| 500 | AccessorNames[AK_Get] == nullptr) { |
| 501 | Diag(AttrNameLoc, diag::err_ms_property_no_getter_or_putter); |
| 502 | break; |
| 503 | } |
| 504 | |
| 505 | Diag(Tok.getLocation(), diag::err_ms_property_unknown_accessor); |
| 506 | break; |
| 507 | } |
| 508 | |
| 509 | AccessorKind Kind; |
| 510 | SourceLocation KindLoc = Tok.getLocation(); |
| 511 | StringRef KindStr = Tok.getIdentifierInfo()->getName(); |
| 512 | if (KindStr == "get") { |
| 513 | Kind = AK_Get; |
| 514 | } else if (KindStr == "put") { |
| 515 | Kind = AK_Put; |
| 516 | |
| 517 | |
| 518 | } else if (KindStr == "set") { |
| 519 | Diag(KindLoc, diag::err_ms_property_has_set_accessor) |
| 520 | << FixItHint::CreateReplacement(KindLoc, "put"); |
| 521 | Kind = AK_Put; |
| 522 | |
| 523 | |
| 524 | |
| 525 | } else if (NextToken().is(tok::comma) || NextToken().is(tok::r_paren)) { |
| 526 | Diag(KindLoc, diag::err_ms_property_missing_accessor_kind); |
| 527 | ConsumeToken(); |
| 528 | HasInvalidAccessor = true; |
| 529 | goto next_property_accessor; |
| 530 | |
| 531 | |
| 532 | } else { |
| 533 | Diag(KindLoc, diag::err_ms_property_unknown_accessor); |
| 534 | HasInvalidAccessor = true; |
| 535 | Kind = AK_Invalid; |
| 536 | |
| 537 | |
| 538 | if (!NextToken().is(tok::equal)) |
| 539 | break; |
| 540 | } |
| 541 | |
| 542 | |
| 543 | ConsumeToken(); |
| 544 | |
| 545 | |
| 546 | if (!TryConsumeToken(tok::equal)) { |
| 547 | Diag(Tok.getLocation(), diag::err_ms_property_expected_equal) |
| 548 | << KindStr; |
| 549 | break; |
| 550 | } |
| 551 | |
| 552 | |
| 553 | if (!Tok.is(tok::identifier)) { |
| 554 | Diag(Tok.getLocation(), diag::err_ms_property_expected_accessor_name); |
| 555 | break; |
| 556 | } |
| 557 | |
| 558 | if (Kind == AK_Invalid) { |
| 559 | |
| 560 | } else if (AccessorNames[Kind] != nullptr) { |
| 561 | |
| 562 | Diag(KindLoc, diag::err_ms_property_duplicate_accessor) << KindStr; |
| 563 | } else { |
| 564 | AccessorNames[Kind] = Tok.getIdentifierInfo(); |
| 565 | } |
| 566 | ConsumeToken(); |
| 567 | |
| 568 | next_property_accessor: |
| 569 | |
| 570 | if (TryConsumeToken(tok::comma)) |
| 571 | continue; |
| 572 | |
| 573 | |
| 574 | if (Tok.is(tok::r_paren)) |
| 575 | break; |
| 576 | |
| 577 | Diag(Tok.getLocation(), diag::err_ms_property_expected_comma_or_rparen); |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | |
| 582 | if (!HasInvalidAccessor) |
| 583 | Attrs.addNewPropertyAttr(AttrName, AttrNameLoc, nullptr, SourceLocation(), |
| 584 | AccessorNames[AK_Get], AccessorNames[AK_Put], |
| 585 | ParsedAttr::AS_Declspec); |
| 586 | T.skipToEnd(); |
| 587 | return !HasInvalidAccessor; |
| 588 | } |
| 589 | |
| 590 | unsigned NumArgs = |
| 591 | ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, nullptr, nullptr, |
| 592 | SourceLocation(), ParsedAttr::AS_Declspec); |
| 593 | |
| 594 | |
| 595 | |
| 596 | if (!Attrs.empty() && Attrs.begin()->getMaxArgs() && !NumArgs) { |
| 597 | Diag(OpenParenLoc, diag::err_attribute_requires_arguments) << AttrName; |
| 598 | return false; |
| 599 | } |
| 600 | return true; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | void Parser::ParseMicrosoftDeclSpecs(ParsedAttributes &Attrs, |
| 610 | SourceLocation *End) { |
| 611 | (0) . __assert_fail ("getLangOpts().DeclSpecKeyword && \"__declspec keyword is not enabled\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 611, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getLangOpts().DeclSpecKeyword && "__declspec keyword is not enabled"); |
| 612 | (0) . __assert_fail ("Tok.is(tok..kw___declspec) && \"Not a declspec!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 612, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw___declspec) && "Not a declspec!"); |
| 613 | |
| 614 | while (Tok.is(tok::kw___declspec)) { |
| 615 | ConsumeToken(); |
| 616 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 617 | if (T.expectAndConsume(diag::err_expected_lparen_after, "__declspec", |
| 618 | tok::r_paren)) |
| 619 | return; |
| 620 | |
| 621 | |
| 622 | |
| 623 | while (Tok.isNot(tok::r_paren)) { |
| 624 | |
| 625 | if (TryConsumeToken(tok::comma)) |
| 626 | continue; |
| 627 | |
| 628 | |
| 629 | |
| 630 | bool IsString = Tok.getKind() == tok::string_literal; |
| 631 | if (!IsString && Tok.getKind() != tok::identifier && |
| 632 | Tok.getKind() != tok::kw_restrict) { |
| 633 | Diag(Tok, diag::err_ms_declspec_type); |
| 634 | T.skipToEnd(); |
| 635 | return; |
| 636 | } |
| 637 | |
| 638 | IdentifierInfo *AttrName; |
| 639 | SourceLocation AttrNameLoc; |
| 640 | if (IsString) { |
| 641 | SmallString<8> StrBuffer; |
| 642 | bool Invalid = false; |
| 643 | StringRef Str = PP.getSpelling(Tok, StrBuffer, &Invalid); |
| 644 | if (Invalid) { |
| 645 | T.skipToEnd(); |
| 646 | return; |
| 647 | } |
| 648 | AttrName = PP.getIdentifierInfo(Str); |
| 649 | AttrNameLoc = ConsumeStringToken(); |
| 650 | } else { |
| 651 | AttrName = Tok.getIdentifierInfo(); |
| 652 | AttrNameLoc = ConsumeToken(); |
| 653 | } |
| 654 | |
| 655 | bool AttrHandled = false; |
| 656 | |
| 657 | |
| 658 | if (Tok.is(tok::l_paren)) |
| 659 | AttrHandled = ParseMicrosoftDeclSpecArgs(AttrName, AttrNameLoc, Attrs); |
| 660 | else if (AttrName->getName() == "property") |
| 661 | |
| 662 | Diag(Tok.getLocation(), diag::err_expected_lparen_after) |
| 663 | << AttrName->getName(); |
| 664 | |
| 665 | if (!AttrHandled) |
| 666 | Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 667 | ParsedAttr::AS_Declspec); |
| 668 | } |
| 669 | T.consumeClose(); |
| 670 | if (End) |
| 671 | *End = T.getCloseLocation(); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | void Parser::ParseMicrosoftTypeAttributes(ParsedAttributes &attrs) { |
| 676 | |
| 677 | while (true) { |
| 678 | switch (Tok.getKind()) { |
| 679 | case tok::kw___fastcall: |
| 680 | case tok::kw___stdcall: |
| 681 | case tok::kw___thiscall: |
| 682 | case tok::kw___regcall: |
| 683 | case tok::kw___cdecl: |
| 684 | case tok::kw___vectorcall: |
| 685 | case tok::kw___ptr64: |
| 686 | case tok::kw___w64: |
| 687 | case tok::kw___ptr32: |
| 688 | case tok::kw___sptr: |
| 689 | case tok::kw___uptr: { |
| 690 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 691 | SourceLocation AttrNameLoc = ConsumeToken(); |
| 692 | attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 693 | ParsedAttr::AS_Keyword); |
| 694 | break; |
| 695 | } |
| 696 | default: |
| 697 | return; |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | void Parser::DiagnoseAndSkipExtendedMicrosoftTypeAttributes() { |
| 703 | SourceLocation StartLoc = Tok.getLocation(); |
| 704 | SourceLocation EndLoc = SkipExtendedMicrosoftTypeAttributes(); |
| 705 | |
| 706 | if (EndLoc.isValid()) { |
| 707 | SourceRange Range(StartLoc, EndLoc); |
| 708 | Diag(StartLoc, diag::warn_microsoft_qualifiers_ignored) << Range; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | SourceLocation Parser::SkipExtendedMicrosoftTypeAttributes() { |
| 713 | SourceLocation EndLoc; |
| 714 | |
| 715 | while (true) { |
| 716 | switch (Tok.getKind()) { |
| 717 | case tok::kw_const: |
| 718 | case tok::kw_volatile: |
| 719 | case tok::kw___fastcall: |
| 720 | case tok::kw___stdcall: |
| 721 | case tok::kw___thiscall: |
| 722 | case tok::kw___cdecl: |
| 723 | case tok::kw___vectorcall: |
| 724 | case tok::kw___ptr32: |
| 725 | case tok::kw___ptr64: |
| 726 | case tok::kw___w64: |
| 727 | case tok::kw___unaligned: |
| 728 | case tok::kw___sptr: |
| 729 | case tok::kw___uptr: |
| 730 | EndLoc = ConsumeToken(); |
| 731 | break; |
| 732 | default: |
| 733 | return EndLoc; |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | void Parser::ParseBorlandTypeAttributes(ParsedAttributes &attrs) { |
| 739 | |
| 740 | while (Tok.is(tok::kw___pascal)) { |
| 741 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 742 | SourceLocation AttrNameLoc = ConsumeToken(); |
| 743 | attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 744 | ParsedAttr::AS_Keyword); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | void Parser::ParseOpenCLKernelAttributes(ParsedAttributes &attrs) { |
| 749 | |
| 750 | while (Tok.is(tok::kw___kernel)) { |
| 751 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 752 | SourceLocation AttrNameLoc = ConsumeToken(); |
| 753 | attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 754 | ParsedAttr::AS_Keyword); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | void Parser::ParseOpenCLQualifiers(ParsedAttributes &Attrs) { |
| 759 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 760 | SourceLocation AttrNameLoc = Tok.getLocation(); |
| 761 | Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 762 | ParsedAttr::AS_Keyword); |
| 763 | } |
| 764 | |
| 765 | void Parser::ParseNullabilityTypeSpecifiers(ParsedAttributes &attrs) { |
| 766 | |
| 767 | while (true) { |
| 768 | switch (Tok.getKind()) { |
| 769 | case tok::kw__Nonnull: |
| 770 | case tok::kw__Nullable: |
| 771 | case tok::kw__Null_unspecified: { |
| 772 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 773 | SourceLocation AttrNameLoc = ConsumeToken(); |
| 774 | if (!getLangOpts().ObjC) |
| 775 | Diag(AttrNameLoc, diag::ext_nullability) |
| 776 | << AttrName; |
| 777 | attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0, |
| 778 | ParsedAttr::AS_Keyword); |
| 779 | break; |
| 780 | } |
| 781 | default: |
| 782 | return; |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | static bool VersionNumberSeparator(const char Separator) { |
| 788 | return (Separator == '.' || Separator == '_'); |
| 789 | } |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | VersionTuple Parser::ParseVersionTuple(SourceRange &Range) { |
| 800 | Range = SourceRange(Tok.getLocation(), Tok.getEndLoc()); |
| 801 | |
| 802 | if (!Tok.is(tok::numeric_constant)) { |
| 803 | Diag(Tok, diag::err_expected_version); |
| 804 | SkipUntil(tok::comma, tok::r_paren, |
| 805 | StopAtSemi | StopBeforeMatch | StopAtCodeCompletion); |
| 806 | return VersionTuple(); |
| 807 | } |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | SmallString<512> Buffer; |
| 814 | Buffer.resize(Tok.getLength()+1); |
| 815 | const char *ThisTokBegin = &Buffer[0]; |
| 816 | |
| 817 | |
| 818 | bool Invalid = false; |
| 819 | unsigned ActualLength = PP.getSpelling(Tok, ThisTokBegin, &Invalid); |
| 820 | if (Invalid) |
| 821 | return VersionTuple(); |
| 822 | |
| 823 | |
| 824 | unsigned AfterMajor = 0; |
| 825 | unsigned Major = 0; |
| 826 | while (AfterMajor < ActualLength && isDigit(ThisTokBegin[AfterMajor])) { |
| 827 | Major = Major * 10 + ThisTokBegin[AfterMajor] - '0'; |
| 828 | ++AfterMajor; |
| 829 | } |
| 830 | |
| 831 | if (AfterMajor == 0) { |
| 832 | Diag(Tok, diag::err_expected_version); |
| 833 | SkipUntil(tok::comma, tok::r_paren, |
| 834 | StopAtSemi | StopBeforeMatch | StopAtCodeCompletion); |
| 835 | return VersionTuple(); |
| 836 | } |
| 837 | |
| 838 | if (AfterMajor == ActualLength) { |
| 839 | ConsumeToken(); |
| 840 | |
| 841 | |
| 842 | if (Major == 0) { |
| 843 | Diag(Tok, diag::err_zero_version); |
| 844 | return VersionTuple(); |
| 845 | } |
| 846 | |
| 847 | return VersionTuple(Major); |
| 848 | } |
| 849 | |
| 850 | const char AfterMajorSeparator = ThisTokBegin[AfterMajor]; |
| 851 | if (!VersionNumberSeparator(AfterMajorSeparator) |
| 852 | || (AfterMajor + 1 == ActualLength)) { |
| 853 | Diag(Tok, diag::err_expected_version); |
| 854 | SkipUntil(tok::comma, tok::r_paren, |
| 855 | StopAtSemi | StopBeforeMatch | StopAtCodeCompletion); |
| 856 | return VersionTuple(); |
| 857 | } |
| 858 | |
| 859 | |
| 860 | unsigned AfterMinor = AfterMajor + 1; |
| 861 | unsigned Minor = 0; |
| 862 | while (AfterMinor < ActualLength && isDigit(ThisTokBegin[AfterMinor])) { |
| 863 | Minor = Minor * 10 + ThisTokBegin[AfterMinor] - '0'; |
| 864 | ++AfterMinor; |
| 865 | } |
| 866 | |
| 867 | if (AfterMinor == ActualLength) { |
| 868 | ConsumeToken(); |
| 869 | |
| 870 | |
| 871 | if (Major == 0 && Minor == 0) { |
| 872 | Diag(Tok, diag::err_zero_version); |
| 873 | return VersionTuple(); |
| 874 | } |
| 875 | |
| 876 | return VersionTuple(Major, Minor); |
| 877 | } |
| 878 | |
| 879 | const char AfterMinorSeparator = ThisTokBegin[AfterMinor]; |
| 880 | |
| 881 | if (!VersionNumberSeparator(AfterMinorSeparator)) { |
| 882 | Diag(Tok, diag::err_expected_version); |
| 883 | SkipUntil(tok::comma, tok::r_paren, |
| 884 | StopAtSemi | StopBeforeMatch | StopAtCodeCompletion); |
| 885 | return VersionTuple(); |
| 886 | } |
| 887 | |
| 888 | |
| 889 | if (AfterMajorSeparator != AfterMinorSeparator) |
| 890 | Diag(Tok, diag::warn_expected_consistent_version_separator); |
| 891 | |
| 892 | |
| 893 | unsigned AfterSubminor = AfterMinor + 1; |
| 894 | unsigned Subminor = 0; |
| 895 | while (AfterSubminor < ActualLength && isDigit(ThisTokBegin[AfterSubminor])) { |
| 896 | Subminor = Subminor * 10 + ThisTokBegin[AfterSubminor] - '0'; |
| 897 | ++AfterSubminor; |
| 898 | } |
| 899 | |
| 900 | if (AfterSubminor != ActualLength) { |
| 901 | Diag(Tok, diag::err_expected_version); |
| 902 | SkipUntil(tok::comma, tok::r_paren, |
| 903 | StopAtSemi | StopBeforeMatch | StopAtCodeCompletion); |
| 904 | return VersionTuple(); |
| 905 | } |
| 906 | ConsumeToken(); |
| 907 | return VersionTuple(Major, Minor, Subminor); |
| 908 | } |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | void Parser::ParseAvailabilityAttribute(IdentifierInfo &Availability, |
| 936 | SourceLocation AvailabilityLoc, |
| 937 | ParsedAttributes &attrs, |
| 938 | SourceLocation *endLoc, |
| 939 | IdentifierInfo *ScopeName, |
| 940 | SourceLocation ScopeLoc, |
| 941 | ParsedAttr::Syntax Syntax) { |
| 942 | enum { Introduced, Deprecated, Obsoleted, Unknown }; |
| 943 | AvailabilityChange Changes[Unknown]; |
| 944 | ExprResult MessageExpr, ReplacementExpr; |
| 945 | |
| 946 | |
| 947 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 948 | if (T.consumeOpen()) { |
| 949 | Diag(Tok, diag::err_expected) << tok::l_paren; |
| 950 | return; |
| 951 | } |
| 952 | |
| 953 | |
| 954 | if (Tok.isNot(tok::identifier)) { |
| 955 | Diag(Tok, diag::err_availability_expected_platform); |
| 956 | SkipUntil(tok::r_paren, StopAtSemi); |
| 957 | return; |
| 958 | } |
| 959 | IdentifierLoc *Platform = ParseIdentifierLoc(); |
| 960 | if (const IdentifierInfo *const Ident = Platform->Ident) { |
| 961 | |
| 962 | if (Ident->getName() == "macosx") |
| 963 | Platform->Ident = PP.getIdentifierInfo("macos"); |
| 964 | |
| 965 | |
| 966 | else if (Ident->getName() == "macosx_app_extension") |
| 967 | Platform->Ident = PP.getIdentifierInfo("macos_app_extension"); |
| 968 | else |
| 969 | Platform->Ident = PP.getIdentifierInfo( |
| 970 | AvailabilityAttr::canonicalizePlatformName(Ident->getName())); |
| 971 | } |
| 972 | |
| 973 | |
| 974 | if (ExpectAndConsume(tok::comma)) { |
| 975 | SkipUntil(tok::r_paren, StopAtSemi); |
| 976 | return; |
| 977 | } |
| 978 | |
| 979 | |
| 980 | |
| 981 | if (!Ident_introduced) { |
| 982 | Ident_introduced = PP.getIdentifierInfo("introduced"); |
| 983 | Ident_deprecated = PP.getIdentifierInfo("deprecated"); |
| 984 | Ident_obsoleted = PP.getIdentifierInfo("obsoleted"); |
| 985 | Ident_unavailable = PP.getIdentifierInfo("unavailable"); |
| 986 | Ident_message = PP.getIdentifierInfo("message"); |
| 987 | Ident_strict = PP.getIdentifierInfo("strict"); |
| 988 | Ident_replacement = PP.getIdentifierInfo("replacement"); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | |
| 993 | SourceLocation UnavailableLoc, StrictLoc; |
| 994 | do { |
| 995 | if (Tok.isNot(tok::identifier)) { |
| 996 | Diag(Tok, diag::err_availability_expected_change); |
| 997 | SkipUntil(tok::r_paren, StopAtSemi); |
| 998 | return; |
| 999 | } |
| 1000 | IdentifierInfo *Keyword = Tok.getIdentifierInfo(); |
| 1001 | SourceLocation KeywordLoc = ConsumeToken(); |
| 1002 | |
| 1003 | if (Keyword == Ident_strict) { |
| 1004 | if (StrictLoc.isValid()) { |
| 1005 | Diag(KeywordLoc, diag::err_availability_redundant) |
| 1006 | << Keyword << SourceRange(StrictLoc); |
| 1007 | } |
| 1008 | StrictLoc = KeywordLoc; |
| 1009 | continue; |
| 1010 | } |
| 1011 | |
| 1012 | if (Keyword == Ident_unavailable) { |
| 1013 | if (UnavailableLoc.isValid()) { |
| 1014 | Diag(KeywordLoc, diag::err_availability_redundant) |
| 1015 | << Keyword << SourceRange(UnavailableLoc); |
| 1016 | } |
| 1017 | UnavailableLoc = KeywordLoc; |
| 1018 | continue; |
| 1019 | } |
| 1020 | |
| 1021 | if (Keyword == Ident_deprecated && Platform->Ident && |
| 1022 | Platform->Ident->isStr("swift")) { |
| 1023 | |
| 1024 | if (Changes[Deprecated].KeywordLoc.isValid()) { |
| 1025 | Diag(KeywordLoc, diag::err_availability_redundant) |
| 1026 | << Keyword |
| 1027 | << SourceRange(Changes[Deprecated].KeywordLoc); |
| 1028 | } |
| 1029 | |
| 1030 | Changes[Deprecated].KeywordLoc = KeywordLoc; |
| 1031 | |
| 1032 | Changes[Deprecated].Version = VersionTuple(1); |
| 1033 | continue; |
| 1034 | } |
| 1035 | |
| 1036 | if (Tok.isNot(tok::equal)) { |
| 1037 | Diag(Tok, diag::err_expected_after) << Keyword << tok::equal; |
| 1038 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1039 | return; |
| 1040 | } |
| 1041 | ConsumeToken(); |
| 1042 | if (Keyword == Ident_message || Keyword == Ident_replacement) { |
| 1043 | if (Tok.isNot(tok::string_literal)) { |
| 1044 | Diag(Tok, diag::err_expected_string_literal) |
| 1045 | << ; |
| 1046 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1047 | return; |
| 1048 | } |
| 1049 | if (Keyword == Ident_message) |
| 1050 | MessageExpr = ParseStringLiteralExpression(); |
| 1051 | else |
| 1052 | ReplacementExpr = ParseStringLiteralExpression(); |
| 1053 | |
| 1054 | if (StringLiteral *MessageStringLiteral = |
| 1055 | cast_or_null<StringLiteral>(MessageExpr.get())) { |
| 1056 | if (MessageStringLiteral->getCharByteWidth() != 1) { |
| 1057 | Diag(MessageStringLiteral->getSourceRange().getBegin(), |
| 1058 | diag::err_expected_string_literal) |
| 1059 | << 2; |
| 1060 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1061 | return; |
| 1062 | } |
| 1063 | } |
| 1064 | if (Keyword == Ident_message) |
| 1065 | break; |
| 1066 | else |
| 1067 | continue; |
| 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | if ((Keyword == Ident_introduced || Keyword == Ident_deprecated) && |
| 1073 | Tok.is(tok::identifier)) { |
| 1074 | IdentifierInfo *NA = Tok.getIdentifierInfo(); |
| 1075 | if (NA->getName() == "NA") { |
| 1076 | ConsumeToken(); |
| 1077 | if (Keyword == Ident_introduced) |
| 1078 | UnavailableLoc = KeywordLoc; |
| 1079 | continue; |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | SourceRange VersionRange; |
| 1084 | VersionTuple Version = ParseVersionTuple(VersionRange); |
| 1085 | |
| 1086 | if (Version.empty()) { |
| 1087 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1088 | return; |
| 1089 | } |
| 1090 | |
| 1091 | unsigned Index; |
| 1092 | if (Keyword == Ident_introduced) |
| 1093 | Index = Introduced; |
| 1094 | else if (Keyword == Ident_deprecated) |
| 1095 | Index = Deprecated; |
| 1096 | else if (Keyword == Ident_obsoleted) |
| 1097 | Index = Obsoleted; |
| 1098 | else |
| 1099 | Index = Unknown; |
| 1100 | |
| 1101 | if (Index < Unknown) { |
| 1102 | if (!Changes[Index].KeywordLoc.isInvalid()) { |
| 1103 | Diag(KeywordLoc, diag::err_availability_redundant) |
| 1104 | << Keyword |
| 1105 | << SourceRange(Changes[Index].KeywordLoc, |
| 1106 | Changes[Index].VersionRange.getEnd()); |
| 1107 | } |
| 1108 | |
| 1109 | Changes[Index].KeywordLoc = KeywordLoc; |
| 1110 | Changes[Index].Version = Version; |
| 1111 | Changes[Index].VersionRange = VersionRange; |
| 1112 | } else { |
| 1113 | Diag(KeywordLoc, diag::err_availability_unknown_change) |
| 1114 | << Keyword << VersionRange; |
| 1115 | } |
| 1116 | |
| 1117 | } while (TryConsumeToken(tok::comma)); |
| 1118 | |
| 1119 | |
| 1120 | if (T.consumeClose()) |
| 1121 | return; |
| 1122 | |
| 1123 | if (endLoc) |
| 1124 | *endLoc = T.getCloseLocation(); |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | if (UnavailableLoc.isValid()) { |
| 1129 | bool Complained = false; |
| 1130 | for (unsigned Index = Introduced; Index != Unknown; ++Index) { |
| 1131 | if (Changes[Index].KeywordLoc.isValid()) { |
| 1132 | if (!Complained) { |
| 1133 | Diag(UnavailableLoc, diag::warn_availability_and_unavailable) |
| 1134 | << SourceRange(Changes[Index].KeywordLoc, |
| 1135 | Changes[Index].VersionRange.getEnd()); |
| 1136 | Complained = true; |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | Changes[Index] = AvailabilityChange(); |
| 1141 | } |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | attrs.addNew(&Availability, |
| 1147 | SourceRange(AvailabilityLoc, T.getCloseLocation()), |
| 1148 | ScopeName, ScopeLoc, |
| 1149 | Platform, |
| 1150 | Changes[Introduced], |
| 1151 | Changes[Deprecated], |
| 1152 | Changes[Obsoleted], |
| 1153 | UnavailableLoc, MessageExpr.get(), |
| 1154 | Syntax, StrictLoc, ReplacementExpr.get()); |
| 1155 | } |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | void Parser::ParseExternalSourceSymbolAttribute( |
| 1171 | IdentifierInfo &ExternalSourceSymbol, SourceLocation Loc, |
| 1172 | ParsedAttributes &Attrs, SourceLocation *EndLoc, IdentifierInfo *ScopeName, |
| 1173 | SourceLocation ScopeLoc, ParsedAttr::Syntax Syntax) { |
| 1174 | |
| 1175 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1176 | if (T.expectAndConsume()) |
| 1177 | return; |
| 1178 | |
| 1179 | |
| 1180 | if (!Ident_language) { |
| 1181 | Ident_language = PP.getIdentifierInfo("language"); |
| 1182 | Ident_defined_in = PP.getIdentifierInfo("defined_in"); |
| 1183 | Ident_generated_declaration = PP.getIdentifierInfo("generated_declaration"); |
| 1184 | } |
| 1185 | |
| 1186 | ExprResult Language; |
| 1187 | bool HasLanguage = false; |
| 1188 | ExprResult DefinedInExpr; |
| 1189 | bool HasDefinedIn = false; |
| 1190 | IdentifierLoc *GeneratedDeclaration = nullptr; |
| 1191 | |
| 1192 | |
| 1193 | do { |
| 1194 | if (Tok.isNot(tok::identifier)) { |
| 1195 | Diag(Tok, diag::err_external_source_symbol_expected_keyword); |
| 1196 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1197 | return; |
| 1198 | } |
| 1199 | |
| 1200 | SourceLocation KeywordLoc = Tok.getLocation(); |
| 1201 | IdentifierInfo *Keyword = Tok.getIdentifierInfo(); |
| 1202 | if (Keyword == Ident_generated_declaration) { |
| 1203 | if (GeneratedDeclaration) { |
| 1204 | Diag(Tok, diag::err_external_source_symbol_duplicate_clause) << Keyword; |
| 1205 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1206 | return; |
| 1207 | } |
| 1208 | GeneratedDeclaration = ParseIdentifierLoc(); |
| 1209 | continue; |
| 1210 | } |
| 1211 | |
| 1212 | if (Keyword != Ident_language && Keyword != Ident_defined_in) { |
| 1213 | Diag(Tok, diag::err_external_source_symbol_expected_keyword); |
| 1214 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1215 | return; |
| 1216 | } |
| 1217 | |
| 1218 | ConsumeToken(); |
| 1219 | if (ExpectAndConsume(tok::equal, diag::err_expected_after, |
| 1220 | Keyword->getName())) { |
| 1221 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1222 | return; |
| 1223 | } |
| 1224 | |
| 1225 | bool HadLanguage = HasLanguage, HadDefinedIn = HasDefinedIn; |
| 1226 | if (Keyword == Ident_language) |
| 1227 | HasLanguage = true; |
| 1228 | else |
| 1229 | HasDefinedIn = true; |
| 1230 | |
| 1231 | if (Tok.isNot(tok::string_literal)) { |
| 1232 | Diag(Tok, diag::err_expected_string_literal) |
| 1233 | << 3 |
| 1234 | << (Keyword != Ident_language); |
| 1235 | SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch); |
| 1236 | continue; |
| 1237 | } |
| 1238 | if (Keyword == Ident_language) { |
| 1239 | if (HadLanguage) { |
| 1240 | Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause) |
| 1241 | << Keyword; |
| 1242 | ParseStringLiteralExpression(); |
| 1243 | continue; |
| 1244 | } |
| 1245 | Language = ParseStringLiteralExpression(); |
| 1246 | } else { |
| 1247 | (0) . __assert_fail ("Keyword == Ident_defined_in && \"Invalid clause keyword!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 1247, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Keyword == Ident_defined_in && "Invalid clause keyword!"); |
| 1248 | if (HadDefinedIn) { |
| 1249 | Diag(KeywordLoc, diag::err_external_source_symbol_duplicate_clause) |
| 1250 | << Keyword; |
| 1251 | ParseStringLiteralExpression(); |
| 1252 | continue; |
| 1253 | } |
| 1254 | DefinedInExpr = ParseStringLiteralExpression(); |
| 1255 | } |
| 1256 | } while (TryConsumeToken(tok::comma)); |
| 1257 | |
| 1258 | |
| 1259 | if (T.consumeClose()) |
| 1260 | return; |
| 1261 | if (EndLoc) |
| 1262 | *EndLoc = T.getCloseLocation(); |
| 1263 | |
| 1264 | ArgsUnion Args[] = {Language.get(), DefinedInExpr.get(), |
| 1265 | GeneratedDeclaration}; |
| 1266 | Attrs.addNew(&ExternalSourceSymbol, SourceRange(Loc, T.getCloseLocation()), |
| 1267 | ScopeName, ScopeLoc, Args, llvm::array_lengthof(Args), Syntax); |
| 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | void Parser::ParseObjCBridgeRelatedAttribute(IdentifierInfo &ObjCBridgeRelated, |
| 1282 | SourceLocation ObjCBridgeRelatedLoc, |
| 1283 | ParsedAttributes &attrs, |
| 1284 | SourceLocation *endLoc, |
| 1285 | IdentifierInfo *ScopeName, |
| 1286 | SourceLocation ScopeLoc, |
| 1287 | ParsedAttr::Syntax Syntax) { |
| 1288 | |
| 1289 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1290 | if (T.consumeOpen()) { |
| 1291 | Diag(Tok, diag::err_expected) << tok::l_paren; |
| 1292 | return; |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | if (Tok.isNot(tok::identifier)) { |
| 1297 | Diag(Tok, diag::err_objcbridge_related_expected_related_class); |
| 1298 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1299 | return; |
| 1300 | } |
| 1301 | IdentifierLoc *RelatedClass = ParseIdentifierLoc(); |
| 1302 | if (ExpectAndConsume(tok::comma)) { |
| 1303 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1304 | return; |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | IdentifierLoc *ClassMethod = nullptr; |
| 1311 | if (Tok.is(tok::identifier)) { |
| 1312 | ClassMethod = ParseIdentifierLoc(); |
| 1313 | if (!TryConsumeToken(tok::colon)) { |
| 1314 | Diag(Tok, diag::err_objcbridge_related_selector_name); |
| 1315 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1316 | return; |
| 1317 | } |
| 1318 | } |
| 1319 | if (!TryConsumeToken(tok::comma)) { |
| 1320 | if (Tok.is(tok::colon)) |
| 1321 | Diag(Tok, diag::err_objcbridge_related_selector_name); |
| 1322 | else |
| 1323 | Diag(Tok, diag::err_expected) << tok::comma; |
| 1324 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1325 | return; |
| 1326 | } |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | IdentifierLoc *InstanceMethod = nullptr; |
| 1331 | if (Tok.is(tok::identifier)) |
| 1332 | InstanceMethod = ParseIdentifierLoc(); |
| 1333 | else if (Tok.isNot(tok::r_paren)) { |
| 1334 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 1335 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1336 | return; |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | if (T.consumeClose()) |
| 1341 | return; |
| 1342 | |
| 1343 | if (endLoc) |
| 1344 | *endLoc = T.getCloseLocation(); |
| 1345 | |
| 1346 | |
| 1347 | attrs.addNew(&ObjCBridgeRelated, |
| 1348 | SourceRange(ObjCBridgeRelatedLoc, T.getCloseLocation()), |
| 1349 | ScopeName, ScopeLoc, |
| 1350 | RelatedClass, |
| 1351 | ClassMethod, |
| 1352 | InstanceMethod, |
| 1353 | Syntax); |
| 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | void Parser::LateParsedDeclaration::ParseLexedAttributes() {} |
| 1360 | |
| 1361 | void Parser::LateParsedClass::ParseLexedAttributes() { |
| 1362 | Self->ParseLexedAttributes(*Class); |
| 1363 | } |
| 1364 | |
| 1365 | void Parser::LateParsedAttribute::ParseLexedAttributes() { |
| 1366 | Self->ParseLexedAttribute(*this, true, false); |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | void Parser::ParseLexedAttributes(ParsingClass &Class) { |
| 1372 | |
| 1373 | |
| 1374 | bool HasTemplateScope = !Class.TopLevelClass && Class.TemplateScope; |
| 1375 | ParseScope ClassTemplateScope(this, Scope::TemplateParamScope, |
| 1376 | HasTemplateScope); |
| 1377 | if (HasTemplateScope) |
| 1378 | Actions.ActOnReenterTemplateScope(getCurScope(), Class.TagOrTemplate); |
| 1379 | |
| 1380 | |
| 1381 | bool AlreadyHasClassScope = Class.TopLevelClass; |
| 1382 | unsigned ScopeFlags = Scope::ClassScope|Scope::DeclScope; |
| 1383 | ParseScope ClassScope(this, ScopeFlags, !AlreadyHasClassScope); |
| 1384 | ParseScopeFlags ClassScopeFlags(this, ScopeFlags, AlreadyHasClassScope); |
| 1385 | |
| 1386 | |
| 1387 | if (!AlreadyHasClassScope) |
| 1388 | Actions.ActOnStartDelayedMemberDeclarations(getCurScope(), |
| 1389 | Class.TagOrTemplate); |
| 1390 | if (!Class.LateParsedDeclarations.empty()) { |
| 1391 | for (unsigned i = 0, ni = Class.LateParsedDeclarations.size(); i < ni; ++i){ |
| 1392 | Class.LateParsedDeclarations[i]->ParseLexedAttributes(); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | if (!AlreadyHasClassScope) |
| 1397 | Actions.ActOnFinishDelayedMemberDeclarations(getCurScope(), |
| 1398 | Class.TagOrTemplate); |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D, |
| 1403 | bool EnterScope, bool OnDefinition) { |
| 1404 | (0) . __assert_fail ("LAs.parseSoon() && \"Attribute list should be marked for immediate parsing.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 1405, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(LAs.parseSoon() && |
| 1405 | (0) . __assert_fail ("LAs.parseSoon() && \"Attribute list should be marked for immediate parsing.\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 1405, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Attribute list should be marked for immediate parsing."); |
| 1406 | for (unsigned i = 0, ni = LAs.size(); i < ni; ++i) { |
| 1407 | if (D) |
| 1408 | LAs[i]->addDecl(D); |
| 1409 | ParseLexedAttribute(*LAs[i], EnterScope, OnDefinition); |
| 1410 | delete LAs[i]; |
| 1411 | } |
| 1412 | LAs.clear(); |
| 1413 | } |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | void Parser::ParseLexedAttribute(LateParsedAttribute &LA, |
| 1421 | bool EnterScope, bool OnDefinition) { |
| 1422 | |
| 1423 | |
| 1424 | Token AttrEnd; |
| 1425 | AttrEnd.startToken(); |
| 1426 | AttrEnd.setKind(tok::eof); |
| 1427 | AttrEnd.setLocation(Tok.getLocation()); |
| 1428 | AttrEnd.setEofData(LA.Toks.data()); |
| 1429 | LA.Toks.push_back(AttrEnd); |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | LA.Toks.push_back(Tok); |
| 1434 | PP.EnterTokenStream(LA.Toks, true); |
| 1435 | |
| 1436 | ConsumeAnyToken(); |
| 1437 | |
| 1438 | ParsedAttributes Attrs(AttrFactory); |
| 1439 | SourceLocation endLoc; |
| 1440 | |
| 1441 | if (LA.Decls.size() > 0) { |
| 1442 | Decl *D = LA.Decls[0]; |
| 1443 | NamedDecl *ND = dyn_cast<NamedDecl>(D); |
| 1444 | RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext()); |
| 1445 | |
| 1446 | |
| 1447 | Sema::CXXThisScopeRAII ThisScope(Actions, RD, Qualifiers(), |
| 1448 | ND && ND->isCXXInstanceMember()); |
| 1449 | |
| 1450 | if (LA.Decls.size() == 1) { |
| 1451 | |
| 1452 | bool HasTemplateScope = EnterScope && D->isTemplateDecl(); |
| 1453 | ParseScope TempScope(this, Scope::TemplateParamScope, HasTemplateScope); |
| 1454 | if (HasTemplateScope) |
| 1455 | Actions.ActOnReenterTemplateScope(Actions.CurScope, D); |
| 1456 | |
| 1457 | |
| 1458 | bool HasFunScope = EnterScope && D->isFunctionOrFunctionTemplate(); |
| 1459 | ParseScope FnScope( |
| 1460 | this, Scope::FnScope | Scope::DeclScope | Scope::CompoundStmtScope, |
| 1461 | HasFunScope); |
| 1462 | if (HasFunScope) |
| 1463 | Actions.ActOnReenterFunctionContext(Actions.CurScope, D); |
| 1464 | |
| 1465 | ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc, |
| 1466 | nullptr, SourceLocation(), ParsedAttr::AS_GNU, |
| 1467 | nullptr); |
| 1468 | |
| 1469 | if (HasFunScope) { |
| 1470 | Actions.ActOnExitFunctionContext(); |
| 1471 | FnScope.Exit(); |
| 1472 | } |
| 1473 | if (HasTemplateScope) { |
| 1474 | TempScope.Exit(); |
| 1475 | } |
| 1476 | } else { |
| 1477 | |
| 1478 | |
| 1479 | ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, &endLoc, |
| 1480 | nullptr, SourceLocation(), ParsedAttr::AS_GNU, |
| 1481 | nullptr); |
| 1482 | } |
| 1483 | } else { |
| 1484 | Diag(Tok, diag::warn_attribute_no_decl) << LA.AttrName.getName(); |
| 1485 | } |
| 1486 | |
| 1487 | if (OnDefinition && !Attrs.empty() && !Attrs.begin()->isCXX11Attribute() && |
| 1488 | Attrs.begin()->isKnownToGCC()) |
| 1489 | Diag(Tok, diag::warn_attribute_on_function_definition) |
| 1490 | << &LA.AttrName; |
| 1491 | |
| 1492 | for (unsigned i = 0, ni = LA.Decls.size(); i < ni; ++i) |
| 1493 | Actions.ActOnFinishDelayedAttribute(getCurScope(), LA.Decls[i], Attrs); |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | while (Tok.isNot(tok::eof)) |
| 1498 | ConsumeAnyToken(); |
| 1499 | |
| 1500 | if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData()) |
| 1501 | ConsumeAnyToken(); |
| 1502 | } |
| 1503 | |
| 1504 | void Parser::ParseTypeTagForDatatypeAttribute(IdentifierInfo &AttrName, |
| 1505 | SourceLocation AttrNameLoc, |
| 1506 | ParsedAttributes &Attrs, |
| 1507 | SourceLocation *EndLoc, |
| 1508 | IdentifierInfo *ScopeName, |
| 1509 | SourceLocation ScopeLoc, |
| 1510 | ParsedAttr::Syntax Syntax) { |
| 1511 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Attribute arg list not starting with '('\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 1511, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Attribute arg list not starting with '('"); |
| 1512 | |
| 1513 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1514 | T.consumeOpen(); |
| 1515 | |
| 1516 | if (Tok.isNot(tok::identifier)) { |
| 1517 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 1518 | T.skipToEnd(); |
| 1519 | return; |
| 1520 | } |
| 1521 | IdentifierLoc *ArgumentKind = ParseIdentifierLoc(); |
| 1522 | |
| 1523 | if (ExpectAndConsume(tok::comma)) { |
| 1524 | T.skipToEnd(); |
| 1525 | return; |
| 1526 | } |
| 1527 | |
| 1528 | SourceRange MatchingCTypeRange; |
| 1529 | TypeResult MatchingCType = ParseTypeName(&MatchingCTypeRange); |
| 1530 | if (MatchingCType.isInvalid()) { |
| 1531 | T.skipToEnd(); |
| 1532 | return; |
| 1533 | } |
| 1534 | |
| 1535 | bool LayoutCompatible = false; |
| 1536 | bool MustBeNull = false; |
| 1537 | while (TryConsumeToken(tok::comma)) { |
| 1538 | if (Tok.isNot(tok::identifier)) { |
| 1539 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 1540 | T.skipToEnd(); |
| 1541 | return; |
| 1542 | } |
| 1543 | IdentifierInfo *Flag = Tok.getIdentifierInfo(); |
| 1544 | if (Flag->isStr("layout_compatible")) |
| 1545 | LayoutCompatible = true; |
| 1546 | else if (Flag->isStr("must_be_null")) |
| 1547 | MustBeNull = true; |
| 1548 | else { |
| 1549 | Diag(Tok, diag::err_type_safety_unknown_flag) << Flag; |
| 1550 | T.skipToEnd(); |
| 1551 | return; |
| 1552 | } |
| 1553 | ConsumeToken(); |
| 1554 | } |
| 1555 | |
| 1556 | if (!T.consumeClose()) { |
| 1557 | Attrs.addNewTypeTagForDatatype(&AttrName, AttrNameLoc, ScopeName, ScopeLoc, |
| 1558 | ArgumentKind, MatchingCType.get(), |
| 1559 | LayoutCompatible, MustBeNull, Syntax); |
| 1560 | } |
| 1561 | |
| 1562 | if (EndLoc) |
| 1563 | *EndLoc = T.getCloseLocation(); |
| 1564 | } |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | bool Parser::DiagnoseProhibitedCXX11Attribute() { |
| 1575 | assert(Tok.is(tok::l_square) && NextToken().is(tok::l_square)); |
| 1576 | |
| 1577 | switch (isCXX11AttributeSpecifier()) { |
| 1578 | case CAK_NotAttributeSpecifier: |
| 1579 | |
| 1580 | return false; |
| 1581 | |
| 1582 | case CAK_InvalidAttributeSpecifier: |
| 1583 | Diag(Tok.getLocation(), diag::err_l_square_l_square_not_attribute); |
| 1584 | return false; |
| 1585 | |
| 1586 | case CAK_AttributeSpecifier: |
| 1587 | |
| 1588 | SourceLocation BeginLoc = ConsumeBracket(); |
| 1589 | ConsumeBracket(); |
| 1590 | SkipUntil(tok::r_square); |
| 1591 | (0) . __assert_fail ("Tok.is(tok..r_square) && \"isCXX11AttributeSpecifier lied\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 1591, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::r_square) && "isCXX11AttributeSpecifier lied"); |
| 1592 | SourceLocation EndLoc = ConsumeBracket(); |
| 1593 | Diag(BeginLoc, diag::err_attributes_not_allowed) |
| 1594 | << SourceRange(BeginLoc, EndLoc); |
| 1595 | return true; |
| 1596 | } |
| 1597 | llvm_unreachable("All cases handled above."); |
| 1598 | } |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | void Parser::DiagnoseMisplacedCXX11Attribute(ParsedAttributesWithRange &Attrs, |
| 1605 | SourceLocation CorrectLocation) { |
| 1606 | assert((Tok.is(tok::l_square) && NextToken().is(tok::l_square)) || |
| 1607 | Tok.is(tok::kw_alignas)); |
| 1608 | |
| 1609 | |
| 1610 | SourceLocation Loc = Tok.getLocation(); |
| 1611 | ParseCXX11Attributes(Attrs); |
| 1612 | CharSourceRange AttrRange(SourceRange(Loc, Attrs.Range.getEnd()), true); |
| 1613 | |
| 1614 | Diag(Loc, diag::err_attributes_not_allowed) |
| 1615 | << FixItHint::CreateInsertionFromRange(CorrectLocation, AttrRange) |
| 1616 | << FixItHint::CreateRemoval(AttrRange); |
| 1617 | } |
| 1618 | |
| 1619 | void Parser::DiagnoseProhibitedAttributes( |
| 1620 | const SourceRange &Range, const SourceLocation CorrectLocation) { |
| 1621 | if (CorrectLocation.isValid()) { |
| 1622 | CharSourceRange AttrRange(Range, true); |
| 1623 | Diag(CorrectLocation, diag::err_attributes_misplaced) |
| 1624 | << FixItHint::CreateInsertionFromRange(CorrectLocation, AttrRange) |
| 1625 | << FixItHint::CreateRemoval(AttrRange); |
| 1626 | } else |
| 1627 | Diag(Range.getBegin(), diag::err_attributes_not_allowed) << Range; |
| 1628 | } |
| 1629 | |
| 1630 | void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs, |
| 1631 | unsigned DiagID) { |
| 1632 | for (const ParsedAttr &AL : Attrs) { |
| 1633 | if (!AL.isCXX11Attribute() && !AL.isC2xAttribute()) |
| 1634 | continue; |
| 1635 | if (AL.getKind() == ParsedAttr::UnknownAttribute) |
| 1636 | Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) << AL.getName(); |
| 1637 | else { |
| 1638 | Diag(AL.getLoc(), DiagID) << AL.getName(); |
| 1639 | AL.setInvalid(); |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | void Parser::stripTypeAttributesOffDeclSpec(ParsedAttributesWithRange &Attrs, |
| 1652 | DeclSpec &DS, |
| 1653 | Sema::TagUseKind TUK) { |
| 1654 | if (TUK == Sema::TUK_Reference) |
| 1655 | return; |
| 1656 | |
| 1657 | llvm::SmallVector<ParsedAttr *, 1> ToBeMoved; |
| 1658 | |
| 1659 | for (ParsedAttr &AL : DS.getAttributes()) { |
| 1660 | if ((AL.getKind() == ParsedAttr::AT_Aligned && |
| 1661 | AL.isDeclspecAttribute()) || |
| 1662 | AL.isMicrosoftAttribute()) |
| 1663 | ToBeMoved.push_back(&AL); |
| 1664 | } |
| 1665 | |
| 1666 | for (ParsedAttr *AL : ToBeMoved) { |
| 1667 | DS.getAttributes().remove(AL); |
| 1668 | Attrs.addAtEnd(AL); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | Parser::DeclGroupPtrTy Parser::ParseDeclaration(DeclaratorContext Context, |
| 1689 | SourceLocation &DeclEnd, |
| 1690 | ParsedAttributesWithRange &attrs) { |
| 1691 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
| 1692 | |
| 1693 | |
| 1694 | ObjCDeclContextSwitch ObjCDC(*this); |
| 1695 | |
| 1696 | Decl *SingleDecl = nullptr; |
| 1697 | switch (Tok.getKind()) { |
| 1698 | case tok::kw_template: |
| 1699 | case tok::kw_export: |
| 1700 | ProhibitAttributes(attrs); |
| 1701 | SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd, attrs); |
| 1702 | break; |
| 1703 | case tok::kw_inline: |
| 1704 | |
| 1705 | if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_namespace)) { |
| 1706 | ProhibitAttributes(attrs); |
| 1707 | SourceLocation InlineLoc = ConsumeToken(); |
| 1708 | return ParseNamespace(Context, DeclEnd, InlineLoc); |
| 1709 | } |
| 1710 | return ParseSimpleDeclaration(Context, DeclEnd, attrs, |
| 1711 | true); |
| 1712 | case tok::kw_namespace: |
| 1713 | ProhibitAttributes(attrs); |
| 1714 | return ParseNamespace(Context, DeclEnd); |
| 1715 | case tok::kw_using: |
| 1716 | return ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(), |
| 1717 | DeclEnd, attrs); |
| 1718 | case tok::kw_static_assert: |
| 1719 | case tok::kw__Static_assert: |
| 1720 | ProhibitAttributes(attrs); |
| 1721 | SingleDecl = ParseStaticAssertDeclaration(DeclEnd); |
| 1722 | break; |
| 1723 | default: |
| 1724 | return ParseSimpleDeclaration(Context, DeclEnd, attrs, true); |
| 1725 | } |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | return Actions.ConvertDeclToDeclGroup(SingleDecl); |
| 1730 | } |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | |
| 1739 | |
| 1740 | |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | Parser::DeclGroupPtrTy |
| 1750 | Parser::ParseSimpleDeclaration(DeclaratorContext Context, |
| 1751 | SourceLocation &DeclEnd, |
| 1752 | ParsedAttributesWithRange &Attrs, |
| 1753 | bool RequireSemi, ForRangeInit *FRI) { |
| 1754 | |
| 1755 | ParsingDeclSpec DS(*this); |
| 1756 | |
| 1757 | DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context); |
| 1758 | ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none, DSContext); |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | if (DS.hasTagDefinition() && |
| 1763 | DiagnoseMissingSemiAfterTagDefinition(DS, AS_none, DSContext)) |
| 1764 | return nullptr; |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | if (Tok.is(tok::semi)) { |
| 1769 | ProhibitAttributes(Attrs); |
| 1770 | DeclEnd = Tok.getLocation(); |
| 1771 | if (RequireSemi) ConsumeToken(); |
| 1772 | RecordDecl *AnonRecord = nullptr; |
| 1773 | Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, |
| 1774 | DS, AnonRecord); |
| 1775 | DS.complete(TheDecl); |
| 1776 | if (AnonRecord) { |
| 1777 | Decl* decls[] = {AnonRecord, TheDecl}; |
| 1778 | return Actions.BuildDeclaratorGroup(decls); |
| 1779 | } |
| 1780 | return Actions.ConvertDeclToDeclGroup(TheDecl); |
| 1781 | } |
| 1782 | |
| 1783 | DS.takeAttributesFrom(Attrs); |
| 1784 | return ParseDeclGroup(DS, Context, &DeclEnd, FRI); |
| 1785 | } |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | bool Parser::MightBeDeclarator(DeclaratorContext Context) { |
| 1790 | switch (Tok.getKind()) { |
| 1791 | case tok::annot_cxxscope: |
| 1792 | case tok::annot_template_id: |
| 1793 | case tok::caret: |
| 1794 | case tok::code_completion: |
| 1795 | case tok::coloncolon: |
| 1796 | case tok::ellipsis: |
| 1797 | case tok::kw___attribute: |
| 1798 | case tok::kw_operator: |
| 1799 | case tok::l_paren: |
| 1800 | case tok::star: |
| 1801 | return true; |
| 1802 | |
| 1803 | case tok::amp: |
| 1804 | case tok::ampamp: |
| 1805 | return getLangOpts().CPlusPlus; |
| 1806 | |
| 1807 | case tok::l_square: |
| 1808 | return Context == DeclaratorContext::MemberContext && |
| 1809 | getLangOpts().CPlusPlus11 && NextToken().is(tok::l_square); |
| 1810 | |
| 1811 | case tok::colon: |
| 1812 | return Context == DeclaratorContext::MemberContext || |
| 1813 | getLangOpts().CPlusPlus; |
| 1814 | |
| 1815 | case tok::identifier: |
| 1816 | switch (NextToken().getKind()) { |
| 1817 | case tok::code_completion: |
| 1818 | case tok::coloncolon: |
| 1819 | case tok::comma: |
| 1820 | case tok::equal: |
| 1821 | case tok::equalequal: |
| 1822 | case tok::kw_alignas: |
| 1823 | case tok::kw_asm: |
| 1824 | case tok::kw___attribute: |
| 1825 | case tok::l_brace: |
| 1826 | case tok::l_paren: |
| 1827 | case tok::l_square: |
| 1828 | case tok::less: |
| 1829 | case tok::r_brace: |
| 1830 | case tok::r_paren: |
| 1831 | case tok::r_square: |
| 1832 | case tok::semi: |
| 1833 | return true; |
| 1834 | |
| 1835 | case tok::colon: |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | return Context == DeclaratorContext::MemberContext || |
| 1840 | (getLangOpts().CPlusPlus && |
| 1841 | Context == DeclaratorContext::FileContext); |
| 1842 | |
| 1843 | case tok::identifier: |
| 1844 | return getLangOpts().CPlusPlus11 && isCXX11VirtSpecifier(NextToken()); |
| 1845 | |
| 1846 | default: |
| 1847 | return false; |
| 1848 | } |
| 1849 | |
| 1850 | default: |
| 1851 | return false; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | void Parser::SkipMalformedDecl() { |
| 1859 | while (true) { |
| 1860 | switch (Tok.getKind()) { |
| 1861 | case tok::l_brace: |
| 1862 | |
| 1863 | |
| 1864 | ConsumeBrace(); |
| 1865 | SkipUntil(tok::r_brace); |
| 1866 | if (Tok.isOneOf(tok::comma, tok::l_brace, tok::kw_try)) { |
| 1867 | |
| 1868 | continue; |
| 1869 | } |
| 1870 | TryConsumeToken(tok::semi); |
| 1871 | return; |
| 1872 | |
| 1873 | case tok::l_square: |
| 1874 | ConsumeBracket(); |
| 1875 | SkipUntil(tok::r_square); |
| 1876 | continue; |
| 1877 | |
| 1878 | case tok::l_paren: |
| 1879 | ConsumeParen(); |
| 1880 | SkipUntil(tok::r_paren); |
| 1881 | continue; |
| 1882 | |
| 1883 | case tok::r_brace: |
| 1884 | return; |
| 1885 | |
| 1886 | case tok::semi: |
| 1887 | ConsumeToken(); |
| 1888 | return; |
| 1889 | |
| 1890 | case tok::kw_inline: |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | if (Tok.isAtStartOfLine() && NextToken().is(tok::kw_namespace) && |
| 1895 | (!ParsingInObjCContainer || CurParsedObjCImpl)) |
| 1896 | return; |
| 1897 | break; |
| 1898 | |
| 1899 | case tok::kw_namespace: |
| 1900 | |
| 1901 | |
| 1902 | |
| 1903 | if (Tok.isAtStartOfLine() && |
| 1904 | (!ParsingInObjCContainer || CurParsedObjCImpl)) |
| 1905 | return; |
| 1906 | break; |
| 1907 | |
| 1908 | case tok::at: |
| 1909 | |
| 1910 | if (NextToken().isObjCAtKeyword(tok::objc_end) && |
| 1911 | ParsingInObjCContainer) |
| 1912 | return; |
| 1913 | break; |
| 1914 | |
| 1915 | case tok::minus: |
| 1916 | case tok::plus: |
| 1917 | |
| 1918 | if (Tok.isAtStartOfLine() && ParsingInObjCContainer) |
| 1919 | return; |
| 1920 | break; |
| 1921 | |
| 1922 | case tok::eof: |
| 1923 | case tok::annot_module_begin: |
| 1924 | case tok::annot_module_end: |
| 1925 | case tok::annot_module_include: |
| 1926 | return; |
| 1927 | |
| 1928 | default: |
| 1929 | break; |
| 1930 | } |
| 1931 | |
| 1932 | ConsumeAnyToken(); |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, |
| 1940 | DeclaratorContext Context, |
| 1941 | SourceLocation *DeclEnd, |
| 1942 | ForRangeInit *FRI) { |
| 1943 | |
| 1944 | ParsingDeclarator D(*this, DS, Context); |
| 1945 | ParseDeclarator(D); |
| 1946 | |
| 1947 | |
| 1948 | if (!D.hasName() && !D.mayOmitIdentifier()) { |
| 1949 | SkipMalformedDecl(); |
| 1950 | return nullptr; |
| 1951 | } |
| 1952 | |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | LateParsedAttrList LateParsedAttrs(true); |
| 1957 | if (D.isFunctionDeclarator()) { |
| 1958 | MaybeParseGNUAttributes(D, &LateParsedAttrs); |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | if (Tok.is(tok::kw__Noreturn)) { |
| 1964 | SourceLocation Loc = ConsumeToken(); |
| 1965 | const char *PrevSpec; |
| 1966 | unsigned DiagID; |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | bool Fixit = !DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID); |
| 1971 | MaybeParseGNUAttributes(D, &LateParsedAttrs); |
| 1972 | Fixit &= Tok.isOneOf(tok::semi, tok::l_brace, tok::kw_try); |
| 1973 | |
| 1974 | Diag(Loc, diag::err_c11_noreturn_misplaced) |
| 1975 | << (Fixit ? FixItHint::CreateRemoval(Loc) : FixItHint()) |
| 1976 | << (Fixit ? FixItHint::CreateInsertion(D.getBeginLoc(), "_Noreturn ") |
| 1977 | : FixItHint()); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | |
| 1982 | if (D.isFunctionDeclarator() && |
| 1983 | |
| 1984 | |
| 1985 | |
| 1986 | !isDeclarationAfterDeclarator()) { |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | |
| 1991 | if (Context == DeclaratorContext::FileContext) { |
| 1992 | if (isStartOfFunctionDefinition(D)) { |
| 1993 | if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 1994 | Diag(Tok, diag::err_function_declared_typedef); |
| 1995 | |
| 1996 | |
| 1997 | DS.ClearStorageClassSpecs(); |
| 1998 | } |
| 1999 | |
| 2000 | Decl *TheDecl = |
| 2001 | ParseFunctionDefinition(D, ParsedTemplateInfo(), &LateParsedAttrs); |
| 2002 | return Actions.ConvertDeclToDeclGroup(TheDecl); |
| 2003 | } |
| 2004 | |
| 2005 | if (isDeclarationSpecifier()) { |
| 2006 | |
| 2007 | |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | |
| 2012 | } else { |
| 2013 | Diag(Tok, diag::err_expected_fn_body); |
| 2014 | SkipUntil(tok::semi); |
| 2015 | return nullptr; |
| 2016 | } |
| 2017 | } else { |
| 2018 | if (Tok.is(tok::l_brace)) { |
| 2019 | Diag(Tok, diag::err_function_definition_not_allowed); |
| 2020 | SkipMalformedDecl(); |
| 2021 | return nullptr; |
| 2022 | } |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | if (ParseAsmAttributesAfterDeclarator(D)) |
| 2027 | return nullptr; |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | if (FRI && (Tok.is(tok::colon) || isTokIdentifier_in())) { |
| 2036 | bool IsForRangeLoop = false; |
| 2037 | if (TryConsumeToken(tok::colon, FRI->ColonLoc)) { |
| 2038 | IsForRangeLoop = true; |
| 2039 | if (Tok.is(tok::l_brace)) |
| 2040 | FRI->RangeExpr = ParseBraceInitializer(); |
| 2041 | else |
| 2042 | FRI->RangeExpr = ParseExpression(); |
| 2043 | } |
| 2044 | |
| 2045 | Decl *ThisDecl = Actions.ActOnDeclarator(getCurScope(), D); |
| 2046 | if (IsForRangeLoop) { |
| 2047 | Actions.ActOnCXXForRangeDecl(ThisDecl); |
| 2048 | } else { |
| 2049 | |
| 2050 | if (auto *VD = dyn_cast_or_null<VarDecl>(ThisDecl)) |
| 2051 | VD->setObjCForDecl(true); |
| 2052 | } |
| 2053 | Actions.FinalizeDeclaration(ThisDecl); |
| 2054 | D.complete(ThisDecl); |
| 2055 | return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, ThisDecl); |
| 2056 | } |
| 2057 | |
| 2058 | SmallVector<Decl *, 8> DeclsInGroup; |
| 2059 | Decl *FirstDecl = ParseDeclarationAfterDeclaratorAndAttributes( |
| 2060 | D, ParsedTemplateInfo(), FRI); |
| 2061 | if (LateParsedAttrs.size() > 0) |
| 2062 | ParseLexedAttributeList(LateParsedAttrs, FirstDecl, true, false); |
| 2063 | D.complete(FirstDecl); |
| 2064 | if (FirstDecl) |
| 2065 | DeclsInGroup.push_back(FirstDecl); |
| 2066 | |
| 2067 | bool ExpectSemi = Context != DeclaratorContext::ForContext; |
| 2068 | |
| 2069 | |
| 2070 | |
| 2071 | SourceLocation CommaLoc; |
| 2072 | while (TryConsumeToken(tok::comma, CommaLoc)) { |
| 2073 | if (Tok.isAtStartOfLine() && ExpectSemi && !MightBeDeclarator(Context)) { |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | Diag(CommaLoc, diag::err_expected_semi_declaration) |
| 2078 | << FixItHint::CreateReplacement(CommaLoc, ";"); |
| 2079 | ExpectSemi = false; |
| 2080 | break; |
| 2081 | } |
| 2082 | |
| 2083 | |
| 2084 | D.clear(); |
| 2085 | D.setCommaLoc(CommaLoc); |
| 2086 | |
| 2087 | |
| 2088 | |
| 2089 | |
| 2090 | |
| 2091 | |
| 2092 | |
| 2093 | |
| 2094 | MaybeParseGNUAttributes(D); |
| 2095 | |
| 2096 | |
| 2097 | if (getLangOpts().MicrosoftExt) |
| 2098 | DiagnoseAndSkipExtendedMicrosoftTypeAttributes(); |
| 2099 | |
| 2100 | ParseDeclarator(D); |
| 2101 | if (!D.isInvalidType()) { |
| 2102 | Decl *ThisDecl = ParseDeclarationAfterDeclarator(D); |
| 2103 | D.complete(ThisDecl); |
| 2104 | if (ThisDecl) |
| 2105 | DeclsInGroup.push_back(ThisDecl); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | if (DeclEnd) |
| 2110 | *DeclEnd = Tok.getLocation(); |
| 2111 | |
| 2112 | if (ExpectSemi && |
| 2113 | ExpectAndConsumeSemi(Context == DeclaratorContext::FileContext |
| 2114 | ? diag::err_invalid_token_after_toplevel_declarator |
| 2115 | : diag::err_expected_semi_declaration)) { |
| 2116 | |
| 2117 | |
| 2118 | |
| 2119 | if (!isDeclarationSpecifier()) { |
| 2120 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
| 2121 | TryConsumeToken(tok::semi); |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | return Actions.FinalizeDeclaratorGroup(getCurScope(), DS, DeclsInGroup); |
| 2126 | } |
| 2127 | |
| 2128 | |
| 2129 | |
| 2130 | bool Parser::ParseAsmAttributesAfterDeclarator(Declarator &D) { |
| 2131 | |
| 2132 | if (Tok.is(tok::kw_asm)) { |
| 2133 | SourceLocation Loc; |
| 2134 | ExprResult AsmLabel(ParseSimpleAsm(&Loc)); |
| 2135 | if (AsmLabel.isInvalid()) { |
| 2136 | SkipUntil(tok::semi, StopBeforeMatch); |
| 2137 | return true; |
| 2138 | } |
| 2139 | |
| 2140 | D.setAsmLabel(AsmLabel.get()); |
| 2141 | D.SetRangeEnd(Loc); |
| 2142 | } |
| 2143 | |
| 2144 | MaybeParseGNUAttributes(D); |
| 2145 | return false; |
| 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | |
| 2150 | |
| 2151 | |
| 2152 | |
| 2153 | |
| 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | Decl *Parser::ParseDeclarationAfterDeclarator( |
| 2171 | Declarator &D, const ParsedTemplateInfo &TemplateInfo) { |
| 2172 | if (ParseAsmAttributesAfterDeclarator(D)) |
| 2173 | return nullptr; |
| 2174 | |
| 2175 | return ParseDeclarationAfterDeclaratorAndAttributes(D, TemplateInfo); |
| 2176 | } |
| 2177 | |
| 2178 | Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes( |
| 2179 | Declarator &D, const ParsedTemplateInfo &TemplateInfo, ForRangeInit *FRI) { |
| 2180 | |
| 2181 | struct InitializerScopeRAII { |
| 2182 | Parser &P; |
| 2183 | Declarator &D; |
| 2184 | Decl *ThisDecl; |
| 2185 | |
| 2186 | InitializerScopeRAII(Parser &P, Declarator &D, Decl *ThisDecl) |
| 2187 | : P(P), D(D), ThisDecl(ThisDecl) { |
| 2188 | if (ThisDecl && P.getLangOpts().CPlusPlus) { |
| 2189 | Scope *S = nullptr; |
| 2190 | if (D.getCXXScopeSpec().isSet()) { |
| 2191 | P.EnterScope(0); |
| 2192 | S = P.getCurScope(); |
| 2193 | } |
| 2194 | P.Actions.ActOnCXXEnterDeclInitializer(S, ThisDecl); |
| 2195 | } |
| 2196 | } |
| 2197 | ~InitializerScopeRAII() { pop(); } |
| 2198 | void pop() { |
| 2199 | if (ThisDecl && P.getLangOpts().CPlusPlus) { |
| 2200 | Scope *S = nullptr; |
| 2201 | if (D.getCXXScopeSpec().isSet()) |
| 2202 | S = P.getCurScope(); |
| 2203 | P.Actions.ActOnCXXExitDeclInitializer(S, ThisDecl); |
| 2204 | if (S) |
| 2205 | P.ExitScope(); |
| 2206 | } |
| 2207 | ThisDecl = nullptr; |
| 2208 | } |
| 2209 | }; |
| 2210 | |
| 2211 | |
| 2212 | Decl *ThisDecl = nullptr; |
| 2213 | switch (TemplateInfo.Kind) { |
| 2214 | case ParsedTemplateInfo::NonTemplate: |
| 2215 | ThisDecl = Actions.ActOnDeclarator(getCurScope(), D); |
| 2216 | break; |
| 2217 | |
| 2218 | case ParsedTemplateInfo::Template: |
| 2219 | case ParsedTemplateInfo::ExplicitSpecialization: { |
| 2220 | ThisDecl = Actions.ActOnTemplateDeclarator(getCurScope(), |
| 2221 | *TemplateInfo.TemplateParams, |
| 2222 | D); |
| 2223 | if (VarTemplateDecl *VT = dyn_cast_or_null<VarTemplateDecl>(ThisDecl)) |
| 2224 | |
| 2225 | |
| 2226 | ThisDecl = VT->getTemplatedDecl(); |
| 2227 | break; |
| 2228 | } |
| 2229 | case ParsedTemplateInfo::ExplicitInstantiation: { |
| 2230 | if (Tok.is(tok::semi)) { |
| 2231 | DeclResult ThisRes = Actions.ActOnExplicitInstantiation( |
| 2232 | getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, D); |
| 2233 | if (ThisRes.isInvalid()) { |
| 2234 | SkipUntil(tok::semi, StopBeforeMatch); |
| 2235 | return nullptr; |
| 2236 | } |
| 2237 | ThisDecl = ThisRes.get(); |
| 2238 | } else { |
| 2239 | |
| 2240 | |
| 2241 | |
| 2242 | if (D.getName().getKind() != UnqualifiedIdKind::IK_TemplateId) { |
| 2243 | |
| 2244 | |
| 2245 | Diag(Tok, diag::err_template_defn_explicit_instantiation) |
| 2246 | << 2 << FixItHint::CreateRemoval(TemplateInfo.TemplateLoc); |
| 2247 | ThisDecl = Actions.ActOnDeclarator(getCurScope(), D); |
| 2248 | } else { |
| 2249 | SourceLocation LAngleLoc = |
| 2250 | PP.getLocForEndOfToken(TemplateInfo.TemplateLoc); |
| 2251 | Diag(D.getIdentifierLoc(), |
| 2252 | diag::err_explicit_instantiation_with_definition) |
| 2253 | << SourceRange(TemplateInfo.TemplateLoc) |
| 2254 | << FixItHint::CreateInsertion(LAngleLoc, "<>"); |
| 2255 | |
| 2256 | |
| 2257 | TemplateParameterLists FakedParamLists; |
| 2258 | FakedParamLists.push_back(Actions.ActOnTemplateParameterList( |
| 2259 | 0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None, |
| 2260 | LAngleLoc, nullptr)); |
| 2261 | |
| 2262 | ThisDecl = |
| 2263 | Actions.ActOnTemplateDeclarator(getCurScope(), FakedParamLists, D); |
| 2264 | } |
| 2265 | } |
| 2266 | break; |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | if (isTokenEqualOrEqualTypo()) { |
| 2273 | SourceLocation EqualLoc = ConsumeToken(); |
| 2274 | |
| 2275 | if (Tok.is(tok::kw_delete)) { |
| 2276 | if (D.isFunctionDeclarator()) |
| 2277 | Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) |
| 2278 | << 1 ; |
| 2279 | else |
| 2280 | Diag(ConsumeToken(), diag::err_deleted_non_function); |
| 2281 | } else if (Tok.is(tok::kw_default)) { |
| 2282 | if (D.isFunctionDeclarator()) |
| 2283 | Diag(ConsumeToken(), diag::err_default_delete_in_multiple_declaration) |
| 2284 | << 0 ; |
| 2285 | else |
| 2286 | Diag(ConsumeToken(), diag::err_default_special_members); |
| 2287 | } else { |
| 2288 | InitializerScopeRAII InitScope(*this, D, ThisDecl); |
| 2289 | |
| 2290 | if (Tok.is(tok::code_completion)) { |
| 2291 | Actions.CodeCompleteInitializer(getCurScope(), ThisDecl); |
| 2292 | Actions.FinalizeDeclaration(ThisDecl); |
| 2293 | cutOffParsing(); |
| 2294 | return nullptr; |
| 2295 | } |
| 2296 | |
| 2297 | PreferredType.enterVariableInit(Tok.getLocation(), ThisDecl); |
| 2298 | ExprResult Init = ParseInitializer(); |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | if (Tok.is(tok::r_paren) && FRI && D.isFirstDeclarator()) { |
| 2303 | Diag(EqualLoc, diag::err_single_decl_assign_in_for_range) |
| 2304 | << FixItHint::CreateReplacement(EqualLoc, ":"); |
| 2305 | |
| 2306 | |
| 2307 | FRI->ColonLoc = EqualLoc; |
| 2308 | Init = ExprError(); |
| 2309 | FRI->RangeExpr = Init; |
| 2310 | } |
| 2311 | |
| 2312 | InitScope.pop(); |
| 2313 | |
| 2314 | if (Init.isInvalid()) { |
| 2315 | SmallVector<tok::TokenKind, 2> StopTokens; |
| 2316 | StopTokens.push_back(tok::comma); |
| 2317 | if (D.getContext() == DeclaratorContext::ForContext || |
| 2318 | D.getContext() == DeclaratorContext::InitStmtContext) |
| 2319 | StopTokens.push_back(tok::r_paren); |
| 2320 | SkipUntil(StopTokens, StopAtSemi | StopBeforeMatch); |
| 2321 | Actions.ActOnInitializerError(ThisDecl); |
| 2322 | } else |
| 2323 | Actions.AddInitializerToDecl(ThisDecl, Init.get(), |
| 2324 | ); |
| 2325 | } |
| 2326 | } else if (Tok.is(tok::l_paren)) { |
| 2327 | |
| 2328 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2329 | T.consumeOpen(); |
| 2330 | |
| 2331 | ExprVector Exprs; |
| 2332 | CommaLocsTy CommaLocs; |
| 2333 | |
| 2334 | InitializerScopeRAII InitScope(*this, D, ThisDecl); |
| 2335 | |
| 2336 | auto ThisVarDecl = dyn_cast_or_null<VarDecl>(ThisDecl); |
| 2337 | auto RunSignatureHelp = [&]() { |
| 2338 | QualType PreferredType = Actions.ProduceConstructorSignatureHelp( |
| 2339 | getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(), |
| 2340 | ThisDecl->getLocation(), Exprs, T.getOpenLocation()); |
| 2341 | CalledSignatureHelp = true; |
| 2342 | return PreferredType; |
| 2343 | }; |
| 2344 | auto SetPreferredType = [&] { |
| 2345 | PreferredType.enterFunctionArgument(Tok.getLocation(), RunSignatureHelp); |
| 2346 | }; |
| 2347 | |
| 2348 | llvm::function_ref<void()> ExpressionStarts; |
| 2349 | if (ThisVarDecl) { |
| 2350 | |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | ExpressionStarts = SetPreferredType; |
| 2355 | } |
| 2356 | if (ParseExpressionList(Exprs, CommaLocs, ExpressionStarts)) { |
| 2357 | if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) { |
| 2358 | Actions.ProduceConstructorSignatureHelp( |
| 2359 | getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(), |
| 2360 | ThisDecl->getLocation(), Exprs, T.getOpenLocation()); |
| 2361 | CalledSignatureHelp = true; |
| 2362 | } |
| 2363 | Actions.ActOnInitializerError(ThisDecl); |
| 2364 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2365 | } else { |
| 2366 | |
| 2367 | T.consumeClose(); |
| 2368 | |
| 2369 | (0) . __assert_fail ("!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() && \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2370, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() && |
| 2370 | (0) . __assert_fail ("!Exprs.empty() && Exprs.size()-1 == CommaLocs.size() && \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2370, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unexpected number of commas!"); |
| 2371 | |
| 2372 | InitScope.pop(); |
| 2373 | |
| 2374 | ExprResult Initializer = Actions.ActOnParenListExpr(T.getOpenLocation(), |
| 2375 | T.getCloseLocation(), |
| 2376 | Exprs); |
| 2377 | Actions.AddInitializerToDecl(ThisDecl, Initializer.get(), |
| 2378 | ); |
| 2379 | } |
| 2380 | } else if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace) && |
| 2381 | (!CurParsedObjCImpl || !D.isFunctionDeclarator())) { |
| 2382 | |
| 2383 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 2384 | |
| 2385 | InitializerScopeRAII InitScope(*this, D, ThisDecl); |
| 2386 | |
| 2387 | ExprResult Init(ParseBraceInitializer()); |
| 2388 | |
| 2389 | InitScope.pop(); |
| 2390 | |
| 2391 | if (Init.isInvalid()) { |
| 2392 | Actions.ActOnInitializerError(ThisDecl); |
| 2393 | } else |
| 2394 | Actions.AddInitializerToDecl(ThisDecl, Init.get(), ); |
| 2395 | |
| 2396 | } else { |
| 2397 | Actions.ActOnUninitializedDecl(ThisDecl); |
| 2398 | } |
| 2399 | |
| 2400 | Actions.FinalizeDeclaration(ThisDecl); |
| 2401 | |
| 2402 | return ThisDecl; |
| 2403 | } |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | void Parser::ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS, |
| 2412 | DeclSpecContext DSC) { |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC); |
| 2417 | |
| 2418 | |
| 2419 | unsigned Specs = DS.getParsedSpecifiers(); |
| 2420 | if (isTypeSpecifier(DSC) && !DS.hasTypeSpecifier()) { |
| 2421 | Diag(Tok, diag::err_expected_type); |
| 2422 | DS.SetTypeSpecError(); |
| 2423 | } else if (Specs == DeclSpec::PQ_None && !DS.hasAttributes()) { |
| 2424 | Diag(Tok, diag::err_typename_requires_specqual); |
| 2425 | if (!DS.hasTypeSpecifier()) |
| 2426 | DS.SetTypeSpecError(); |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | if (Specs & DeclSpec::PQ_StorageClassSpecifier) { |
| 2431 | if (DS.getStorageClassSpecLoc().isValid()) |
| 2432 | Diag(DS.getStorageClassSpecLoc(),diag::err_typename_invalid_storageclass); |
| 2433 | else |
| 2434 | Diag(DS.getThreadStorageClassSpecLoc(), |
| 2435 | diag::err_typename_invalid_storageclass); |
| 2436 | DS.ClearStorageClassSpecs(); |
| 2437 | } |
| 2438 | |
| 2439 | |
| 2440 | if (Specs & DeclSpec::PQ_FunctionSpecifier) { |
| 2441 | if (DS.isInlineSpecified()) |
| 2442 | Diag(DS.getInlineSpecLoc(), diag::err_typename_invalid_functionspec); |
| 2443 | if (DS.isVirtualSpecified()) |
| 2444 | Diag(DS.getVirtualSpecLoc(), diag::err_typename_invalid_functionspec); |
| 2445 | if (DS.isExplicitSpecified()) |
| 2446 | Diag(DS.getExplicitSpecLoc(), diag::err_typename_invalid_functionspec); |
| 2447 | DS.ClearFunctionSpecs(); |
| 2448 | } |
| 2449 | |
| 2450 | |
| 2451 | if (DS.isConstexprSpecified() && DSC != DeclSpecContext::DSC_condition) { |
| 2452 | Diag(DS.getConstexprSpecLoc(), diag::err_typename_invalid_constexpr); |
| 2453 | DS.ClearConstexprSpec(); |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | |
| 2458 | |
| 2459 | |
| 2460 | |
| 2461 | |
| 2462 | |
| 2463 | |
| 2464 | |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | |
| 2473 | |
| 2474 | |
| 2475 | static bool isValidAfterIdentifierInDeclarator(const Token &T) { |
| 2476 | return T.isOneOf(tok::l_square, tok::l_paren, tok::r_paren, tok::semi, |
| 2477 | tok::comma, tok::equal, tok::kw_asm, tok::l_brace, |
| 2478 | tok::colon); |
| 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | |
| 2488 | |
| 2489 | |
| 2490 | bool Parser::ParseImplicitInt(DeclSpec &DS, CXXScopeSpec *SS, |
| 2491 | const ParsedTemplateInfo &TemplateInfo, |
| 2492 | AccessSpecifier AS, DeclSpecContext DSC, |
| 2493 | ParsedAttributesWithRange &Attrs) { |
| 2494 | (0) . __assert_fail ("Tok.is(tok..identifier) && \"should have identifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2494, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::identifier) && "should have identifier"); |
| 2495 | |
| 2496 | SourceLocation Loc = Tok.getLocation(); |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | |
| 2506 | |
| 2507 | |
| 2508 | |
| 2509 | (0) . __assert_fail ("!DS.hasTypeSpecifier() && \"Type specifier checked above\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2509, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!DS.hasTypeSpecifier() && "Type specifier checked above"); |
| 2510 | |
| 2511 | |
| 2512 | |
| 2513 | |
| 2514 | |
| 2515 | |
| 2516 | if (!isTypeSpecifier(DSC) && !getLangOpts().CPlusPlus && |
| 2517 | isValidAfterIdentifierInDeclarator(NextToken())) { |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | return false; |
| 2522 | } |
| 2523 | |
| 2524 | if (getLangOpts().CPlusPlus && |
| 2525 | DS.getStorageClassSpec() == DeclSpec::SCS_auto) { |
| 2526 | |
| 2527 | |
| 2528 | if (SS) |
| 2529 | AnnotateScopeToken(*SS, ); |
| 2530 | return false; |
| 2531 | } |
| 2532 | |
| 2533 | if (getLangOpts().CPlusPlus && (!SS || SS->isEmpty()) && |
| 2534 | getLangOpts().MSVCCompat) { |
| 2535 | |
| 2536 | |
| 2537 | |
| 2538 | if (ParsedType T = Actions.ActOnMSVCUnknownTypeName( |
| 2539 | *Tok.getIdentifierInfo(), Tok.getLocation(), |
| 2540 | DSC == DeclSpecContext::DSC_template_type_arg)) { |
| 2541 | const char *PrevSpec; |
| 2542 | unsigned DiagID; |
| 2543 | DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, T, |
| 2544 | Actions.getASTContext().getPrintingPolicy()); |
| 2545 | DS.SetRangeEnd(Tok.getLocation()); |
| 2546 | ConsumeToken(); |
| 2547 | return false; |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | |
| 2552 | |
| 2553 | |
| 2554 | |
| 2555 | |
| 2556 | |
| 2557 | if (SS == nullptr) { |
| 2558 | const char *TagName = nullptr, *FixitTagName = nullptr; |
| 2559 | tok::TokenKind TagKind = tok::unknown; |
| 2560 | |
| 2561 | switch (Actions.isTagName(*Tok.getIdentifierInfo(), getCurScope())) { |
| 2562 | default: break; |
| 2563 | case DeclSpec::TST_enum: |
| 2564 | TagName="enum" ; FixitTagName = "enum " ; TagKind=tok::kw_enum ;break; |
| 2565 | case DeclSpec::TST_union: |
| 2566 | TagName="union" ; FixitTagName = "union " ;TagKind=tok::kw_union ;break; |
| 2567 | case DeclSpec::TST_struct: |
| 2568 | TagName="struct"; FixitTagName = "struct ";TagKind=tok::kw_struct;break; |
| 2569 | case DeclSpec::TST_interface: |
| 2570 | TagName="__interface"; FixitTagName = "__interface "; |
| 2571 | TagKind=tok::kw___interface;break; |
| 2572 | case DeclSpec::TST_class: |
| 2573 | TagName="class" ; FixitTagName = "class " ;TagKind=tok::kw_class ;break; |
| 2574 | } |
| 2575 | |
| 2576 | if (TagName) { |
| 2577 | IdentifierInfo *TokenName = Tok.getIdentifierInfo(); |
| 2578 | LookupResult R(Actions, TokenName, SourceLocation(), |
| 2579 | Sema::LookupOrdinaryName); |
| 2580 | |
| 2581 | Diag(Loc, diag::err_use_of_tag_name_without_tag) |
| 2582 | << TokenName << TagName << getLangOpts().CPlusPlus |
| 2583 | << FixItHint::CreateInsertion(Tok.getLocation(), FixitTagName); |
| 2584 | |
| 2585 | if (Actions.LookupParsedName(R, getCurScope(), SS)) { |
| 2586 | for (LookupResult::iterator I = R.begin(), IEnd = R.end(); |
| 2587 | I != IEnd; ++I) |
| 2588 | Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type) |
| 2589 | << TokenName << TagName; |
| 2590 | } |
| 2591 | |
| 2592 | |
| 2593 | if (TagKind == tok::kw_enum) |
| 2594 | ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, |
| 2595 | DeclSpecContext::DSC_normal); |
| 2596 | else |
| 2597 | ParseClassSpecifier(TagKind, Loc, DS, TemplateInfo, AS, |
| 2598 | false, |
| 2599 | DeclSpecContext::DSC_normal, Attrs); |
| 2600 | return true; |
| 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | |
| 2606 | if (!isTypeSpecifier(DSC) && (!SS || DSC == DeclSpecContext::DSC_top_level || |
| 2607 | DSC == DeclSpecContext::DSC_class)) { |
| 2608 | |
| 2609 | |
| 2610 | switch (NextToken().getKind()) { |
| 2611 | case tok::l_paren: { |
| 2612 | |
| 2613 | |
| 2614 | |
| 2615 | |
| 2616 | |
| 2617 | |
| 2618 | TentativeParsingAction PA(*this); |
| 2619 | ConsumeToken(); |
| 2620 | TPResult TPR = TryParseDeclarator(); |
| 2621 | PA.Revert(); |
| 2622 | |
| 2623 | if (TPR != TPResult::False) { |
| 2624 | |
| 2625 | |
| 2626 | break; |
| 2627 | } |
| 2628 | |
| 2629 | |
| 2630 | |
| 2631 | if (DSC == DeclSpecContext::DSC_class || |
| 2632 | (DSC == DeclSpecContext::DSC_top_level && SS)) { |
| 2633 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 2634 | if (Actions.isCurrentClassNameTypo(II, SS)) { |
| 2635 | Diag(Loc, diag::err_constructor_bad_name) |
| 2636 | << Tok.getIdentifierInfo() << II |
| 2637 | << FixItHint::CreateReplacement(Tok.getLocation(), II->getName()); |
| 2638 | Tok.setIdentifierInfo(II); |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | LLVM_FALLTHROUGH; |
| 2643 | } |
| 2644 | case tok::comma: |
| 2645 | case tok::equal: |
| 2646 | case tok::kw_asm: |
| 2647 | case tok::l_brace: |
| 2648 | case tok::l_square: |
| 2649 | case tok::semi: |
| 2650 | |
| 2651 | |
| 2652 | if (SS) |
| 2653 | AnnotateScopeToken(*SS, ); |
| 2654 | return false; |
| 2655 | |
| 2656 | default: |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | break; |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | |
| 2665 | |
| 2666 | ParsedType T; |
| 2667 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 2668 | bool IsTemplateName = getLangOpts().CPlusPlus && NextToken().is(tok::less); |
| 2669 | Actions.DiagnoseUnknownTypeName(II, Loc, getCurScope(), SS, T, |
| 2670 | IsTemplateName); |
| 2671 | if (T) { |
| 2672 | |
| 2673 | |
| 2674 | |
| 2675 | const char *PrevSpec; |
| 2676 | unsigned DiagID; |
| 2677 | DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID, T, |
| 2678 | Actions.getASTContext().getPrintingPolicy()); |
| 2679 | DS.SetRangeEnd(Tok.getLocation()); |
| 2680 | ConsumeToken(); |
| 2681 | |
| 2682 | return true; |
| 2683 | } else if (II != Tok.getIdentifierInfo()) { |
| 2684 | |
| 2685 | Tok.setKind(II->getTokenID()); |
| 2686 | |
| 2687 | return true; |
| 2688 | } |
| 2689 | |
| 2690 | |
| 2691 | DS.SetTypeSpecError(); |
| 2692 | DS.SetRangeEnd(Tok.getLocation()); |
| 2693 | ConsumeToken(); |
| 2694 | |
| 2695 | |
| 2696 | if (IsTemplateName) { |
| 2697 | SourceLocation LAngle, RAngle; |
| 2698 | TemplateArgList Args; |
| 2699 | ParseTemplateIdAfterTemplateName(true, LAngle, Args, RAngle); |
| 2700 | } |
| 2701 | |
| 2702 | |
| 2703 | |
| 2704 | |
| 2705 | return false; |
| 2706 | } |
| 2707 | |
| 2708 | |
| 2709 | |
| 2710 | |
| 2711 | |
| 2712 | |
| 2713 | Parser::DeclSpecContext |
| 2714 | Parser::getDeclSpecContextFromDeclaratorContext(DeclaratorContext Context) { |
| 2715 | if (Context == DeclaratorContext::MemberContext) |
| 2716 | return DeclSpecContext::DSC_class; |
| 2717 | if (Context == DeclaratorContext::FileContext) |
| 2718 | return DeclSpecContext::DSC_top_level; |
| 2719 | if (Context == DeclaratorContext::TemplateParamContext) |
| 2720 | return DeclSpecContext::DSC_template_param; |
| 2721 | if (Context == DeclaratorContext::TemplateArgContext || |
| 2722 | Context == DeclaratorContext::TemplateTypeArgContext) |
| 2723 | return DeclSpecContext::DSC_template_type_arg; |
| 2724 | if (Context == DeclaratorContext::TrailingReturnContext || |
| 2725 | Context == DeclaratorContext::TrailingReturnVarContext) |
| 2726 | return DeclSpecContext::DSC_trailing; |
| 2727 | if (Context == DeclaratorContext::AliasDeclContext || |
| 2728 | Context == DeclaratorContext::AliasTemplateContext) |
| 2729 | return DeclSpecContext::DSC_alias_declaration; |
| 2730 | return DeclSpecContext::DSC_normal; |
| 2731 | } |
| 2732 | |
| 2733 | |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | |
| 2738 | |
| 2739 | |
| 2740 | |
| 2741 | |
| 2742 | ExprResult Parser::ParseAlignArgument(SourceLocation Start, |
| 2743 | SourceLocation &EllipsisLoc) { |
| 2744 | ExprResult ER; |
| 2745 | if (isTypeIdInParens()) { |
| 2746 | SourceLocation TypeLoc = Tok.getLocation(); |
| 2747 | ParsedType Ty = ParseTypeName().get(); |
| 2748 | SourceRange TypeRange(Start, Tok.getLocation()); |
| 2749 | ER = Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, |
| 2750 | Ty.getAsOpaquePtr(), TypeRange); |
| 2751 | } else |
| 2752 | ER = ParseConstantExpression(); |
| 2753 | |
| 2754 | if (getLangOpts().CPlusPlus11) |
| 2755 | TryConsumeToken(tok::ellipsis, EllipsisLoc); |
| 2756 | |
| 2757 | return ER; |
| 2758 | } |
| 2759 | |
| 2760 | |
| 2761 | |
| 2762 | |
| 2763 | |
| 2764 | |
| 2765 | |
| 2766 | |
| 2767 | |
| 2768 | void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, |
| 2769 | SourceLocation *EndLoc) { |
| 2770 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_alignas, tok..kw__Alignas) && \"Not an alignment-specifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2771, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::kw_alignas, tok::kw__Alignas) && |
| 2771 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_alignas, tok..kw__Alignas) && \"Not an alignment-specifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2771, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not an alignment-specifier!"); |
| 2772 | |
| 2773 | IdentifierInfo *KWName = Tok.getIdentifierInfo(); |
| 2774 | SourceLocation KWLoc = ConsumeToken(); |
| 2775 | |
| 2776 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2777 | if (T.expectAndConsume()) |
| 2778 | return; |
| 2779 | |
| 2780 | SourceLocation EllipsisLoc; |
| 2781 | ExprResult ArgExpr = ParseAlignArgument(T.getOpenLocation(), EllipsisLoc); |
| 2782 | if (ArgExpr.isInvalid()) { |
| 2783 | T.skipToEnd(); |
| 2784 | return; |
| 2785 | } |
| 2786 | |
| 2787 | T.consumeClose(); |
| 2788 | if (EndLoc) |
| 2789 | *EndLoc = T.getCloseLocation(); |
| 2790 | |
| 2791 | ArgsVector ArgExprs; |
| 2792 | ArgExprs.push_back(ArgExpr.get()); |
| 2793 | Attrs.addNew(KWName, KWLoc, nullptr, KWLoc, ArgExprs.data(), 1, |
| 2794 | ParsedAttr::AS_Keyword, EllipsisLoc); |
| 2795 | } |
| 2796 | |
| 2797 | |
| 2798 | |
| 2799 | |
| 2800 | |
| 2801 | |
| 2802 | |
| 2803 | |
| 2804 | bool |
| 2805 | Parser::DiagnoseMissingSemiAfterTagDefinition(DeclSpec &DS, AccessSpecifier AS, |
| 2806 | DeclSpecContext DSContext, |
| 2807 | LateParsedAttrList *LateAttrs) { |
| 2808 | (0) . __assert_fail ("DS.hasTagDefinition() && \"shouldn't call this\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 2808, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(DS.hasTagDefinition() && "shouldn't call this"); |
| 2809 | |
| 2810 | bool EnteringContext = (DSContext == DeclSpecContext::DSC_class || |
| 2811 | DSContext == DeclSpecContext::DSC_top_level); |
| 2812 | |
| 2813 | if (getLangOpts().CPlusPlus && |
| 2814 | Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype, |
| 2815 | tok::annot_template_id) && |
| 2816 | TryAnnotateCXXScopeToken(EnteringContext)) { |
| 2817 | SkipMalformedDecl(); |
| 2818 | return true; |
| 2819 | } |
| 2820 | |
| 2821 | bool HasScope = Tok.is(tok::annot_cxxscope); |
| 2822 | |
| 2823 | Token AfterScope = HasScope ? NextToken() : Tok; |
| 2824 | |
| 2825 | |
| 2826 | |
| 2827 | bool MightBeDeclarator = true; |
| 2828 | if (Tok.isOneOf(tok::kw_typename, tok::annot_typename)) { |
| 2829 | |
| 2830 | MightBeDeclarator = false; |
| 2831 | } else if (AfterScope.is(tok::annot_template_id)) { |
| 2832 | |
| 2833 | |
| 2834 | TemplateIdAnnotation *Annot = |
| 2835 | static_cast<TemplateIdAnnotation *>(AfterScope.getAnnotationValue()); |
| 2836 | if (Annot->Kind == TNK_Type_template) |
| 2837 | MightBeDeclarator = false; |
| 2838 | } else if (AfterScope.is(tok::identifier)) { |
| 2839 | const Token &Next = HasScope ? GetLookAheadToken(2) : NextToken(); |
| 2840 | |
| 2841 | |
| 2842 | |
| 2843 | if (Next.isOneOf(tok::star, tok::amp, tok::ampamp, tok::identifier, |
| 2844 | tok::annot_cxxscope, tok::coloncolon)) { |
| 2845 | |
| 2846 | MightBeDeclarator = false; |
| 2847 | } else if (HasScope) { |
| 2848 | |
| 2849 | |
| 2850 | |
| 2851 | CXXScopeSpec SS; |
| 2852 | Actions.RestoreNestedNameSpecifierAnnotation( |
| 2853 | Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS); |
| 2854 | IdentifierInfo *Name = AfterScope.getIdentifierInfo(); |
| 2855 | Sema::NameClassification Classification = Actions.ClassifyName( |
| 2856 | getCurScope(), SS, Name, AfterScope.getLocation(), Next, |
| 2857 | , ); |
| 2858 | switch (Classification.getKind()) { |
| 2859 | case Sema::NC_Error: |
| 2860 | SkipMalformedDecl(); |
| 2861 | return true; |
| 2862 | |
| 2863 | case Sema::NC_Keyword: |
| 2864 | case Sema::NC_NestedNameSpecifier: |
| 2865 | llvm_unreachable("typo correction and nested name specifiers not " |
| 2866 | "possible here"); |
| 2867 | |
| 2868 | case Sema::NC_Type: |
| 2869 | case Sema::NC_TypeTemplate: |
| 2870 | |
| 2871 | MightBeDeclarator = false; |
| 2872 | break; |
| 2873 | |
| 2874 | case Sema::NC_Unknown: |
| 2875 | case Sema::NC_Expression: |
| 2876 | case Sema::NC_VarTemplate: |
| 2877 | case Sema::NC_FunctionTemplate: |
| 2878 | |
| 2879 | break; |
| 2880 | } |
| 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | if (MightBeDeclarator) |
| 2885 | return false; |
| 2886 | |
| 2887 | const PrintingPolicy &PPol = Actions.getASTContext().getPrintingPolicy(); |
| 2888 | Diag(PP.getLocForEndOfToken(DS.getRepAsDecl()->getEndLoc()), |
| 2889 | diag::err_expected_after) |
| 2890 | << DeclSpec::getSpecifierName(DS.getTypeSpecType(), PPol) << tok::semi; |
| 2891 | |
| 2892 | |
| 2893 | |
| 2894 | |
| 2895 | |
| 2896 | |
| 2897 | |
| 2898 | |
| 2899 | DS.ClearTypeSpecType(); |
| 2900 | ParsedTemplateInfo NotATemplate; |
| 2901 | ParseDeclarationSpecifiers(DS, NotATemplate, AS, DSContext, LateAttrs); |
| 2902 | return false; |
| 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | |
| 2907 | static void SetupFixedPointError(const LangOptions &LangOpts, |
| 2908 | const char *&PrevSpec, unsigned &DiagID, |
| 2909 | bool &isInvalid) { |
| 2910 | assert(!LangOpts.FixedPoint); |
| 2911 | DiagID = diag::err_fixed_point_not_enabled; |
| 2912 | PrevSpec = ""; |
| 2913 | isInvalid = true; |
| 2914 | } |
| 2915 | |
| 2916 | |
| 2917 | |
| 2918 | |
| 2919 | |
| 2920 | |
| 2921 | |
| 2922 | |
| 2923 | |
| 2924 | |
| 2925 | |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | |
| 2931 | |
| 2932 | |
| 2933 | |
| 2934 | |
| 2935 | |
| 2936 | |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | |
| 2941 | |
| 2942 | |
| 2943 | void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, |
| 2944 | const ParsedTemplateInfo &TemplateInfo, |
| 2945 | AccessSpecifier AS, |
| 2946 | DeclSpecContext DSContext, |
| 2947 | LateParsedAttrList *LateAttrs) { |
| 2948 | if (DS.getSourceRange().isInvalid()) { |
| 2949 | |
| 2950 | |
| 2951 | |
| 2952 | DS.SetRangeStart(Tok.getLocation()); |
| 2953 | DS.SetRangeEnd(SourceLocation()); |
| 2954 | } |
| 2955 | |
| 2956 | bool EnteringContext = (DSContext == DeclSpecContext::DSC_class || |
| 2957 | DSContext == DeclSpecContext::DSC_top_level); |
| 2958 | bool AttrsLastTime = false; |
| 2959 | ParsedAttributesWithRange attrs(AttrFactory); |
| 2960 | |
| 2961 | PrintingPolicy Policy = Actions.getPrintingPolicy(); |
| 2962 | while (1) { |
| 2963 | bool isInvalid = false; |
| 2964 | bool isStorageClass = false; |
| 2965 | const char *PrevSpec = nullptr; |
| 2966 | unsigned DiagID = 0; |
| 2967 | |
| 2968 | |
| 2969 | |
| 2970 | |
| 2971 | |
| 2972 | |
| 2973 | |
| 2974 | |
| 2975 | if (getLangOpts().MSVCCompat && Tok.is(tok::kw__Atomic) && |
| 2976 | DS.getStorageClassSpec() == clang::DeclSpec::SCS_typedef && |
| 2977 | !DS.hasTypeSpecifier() && GetLookAheadToken(1).is(tok::less)) |
| 2978 | Tok.setKind(tok::identifier); |
| 2979 | |
| 2980 | SourceLocation Loc = Tok.getLocation(); |
| 2981 | |
| 2982 | switch (Tok.getKind()) { |
| 2983 | default: |
| 2984 | DoneWithDeclSpec: |
| 2985 | if (!AttrsLastTime) |
| 2986 | ProhibitAttributes(attrs); |
| 2987 | else { |
| 2988 | |
| 2989 | |
| 2990 | |
| 2991 | ProhibitCXX11Attributes(attrs, diag::err_attribute_not_type_attr); |
| 2992 | |
| 2993 | DS.takeAttributesFrom(attrs); |
| 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | |
| 2998 | DS.Finish(Actions, Policy); |
| 2999 | return; |
| 3000 | |
| 3001 | case tok::l_square: |
| 3002 | case tok::kw_alignas: |
| 3003 | if (!standardAttributesAllowed() || !isCXX11AttributeSpecifier()) |
| 3004 | goto DoneWithDeclSpec; |
| 3005 | |
| 3006 | ProhibitAttributes(attrs); |
| 3007 | |
| 3008 | |
| 3009 | |
| 3010 | attrs.clear(); |
| 3011 | attrs.Range = SourceRange(); |
| 3012 | |
| 3013 | ParseCXX11Attributes(attrs); |
| 3014 | AttrsLastTime = true; |
| 3015 | continue; |
| 3016 | |
| 3017 | case tok::code_completion: { |
| 3018 | Sema::ParserCompletionContext CCC = Sema::PCC_Namespace; |
| 3019 | if (DS.hasTypeSpecifier()) { |
| 3020 | bool AllowNonIdentifiers |
| 3021 | = (getCurScope()->getFlags() & (Scope::ControlScope | |
| 3022 | Scope::BlockScope | |
| 3023 | Scope::TemplateParamScope | |
| 3024 | Scope::FunctionPrototypeScope | |
| 3025 | Scope::AtCatchScope)) == 0; |
| 3026 | bool AllowNestedNameSpecifiers |
| 3027 | = DSContext == DeclSpecContext::DSC_top_level || |
| 3028 | (DSContext == DeclSpecContext::DSC_class && DS.isFriendSpecified()); |
| 3029 | |
| 3030 | Actions.CodeCompleteDeclSpec(getCurScope(), DS, |
| 3031 | AllowNonIdentifiers, |
| 3032 | AllowNestedNameSpecifiers); |
| 3033 | return cutOffParsing(); |
| 3034 | } |
| 3035 | |
| 3036 | if (getCurScope()->getFnParent() || getCurScope()->getBlockParent()) |
| 3037 | CCC = Sema::PCC_LocalDeclarationSpecifiers; |
| 3038 | else if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate) |
| 3039 | CCC = DSContext == DeclSpecContext::DSC_class ? Sema::PCC_MemberTemplate |
| 3040 | : Sema::PCC_Template; |
| 3041 | else if (DSContext == DeclSpecContext::DSC_class) |
| 3042 | CCC = Sema::PCC_Class; |
| 3043 | else if (CurParsedObjCImpl) |
| 3044 | CCC = Sema::PCC_ObjCImplementation; |
| 3045 | |
| 3046 | Actions.CodeCompleteOrdinaryName(getCurScope(), CCC); |
| 3047 | return cutOffParsing(); |
| 3048 | } |
| 3049 | |
| 3050 | case tok::coloncolon: |
| 3051 | |
| 3052 | if (TryAnnotateCXXScopeToken(EnteringContext)) { |
| 3053 | if (!DS.hasTypeSpecifier()) |
| 3054 | DS.SetTypeSpecError(); |
| 3055 | goto DoneWithDeclSpec; |
| 3056 | } |
| 3057 | if (Tok.is(tok::coloncolon)) |
| 3058 | goto DoneWithDeclSpec; |
| 3059 | continue; |
| 3060 | |
| 3061 | case tok::annot_cxxscope: { |
| 3062 | if (DS.hasTypeSpecifier() || DS.isTypeAltiVecVector()) |
| 3063 | goto DoneWithDeclSpec; |
| 3064 | |
| 3065 | CXXScopeSpec SS; |
| 3066 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
| 3067 | Tok.getAnnotationRange(), |
| 3068 | SS); |
| 3069 | |
| 3070 | |
| 3071 | Token Next = NextToken(); |
| 3072 | if (Next.is(tok::annot_template_id) && |
| 3073 | static_cast<TemplateIdAnnotation *>(Next.getAnnotationValue()) |
| 3074 | ->Kind == TNK_Type_template) { |
| 3075 | |
| 3076 | |
| 3077 | |
| 3078 | |
| 3079 | |
| 3080 | |
| 3081 | |
| 3082 | |
| 3083 | |
| 3084 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next); |
| 3085 | if ((DSContext == DeclSpecContext::DSC_top_level || |
| 3086 | DSContext == DeclSpecContext::DSC_class) && |
| 3087 | TemplateId->Name && |
| 3088 | Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS) && |
| 3089 | isConstructorDeclarator( false)) { |
| 3090 | |
| 3091 | |
| 3092 | |
| 3093 | |
| 3094 | goto DoneWithDeclSpec; |
| 3095 | } |
| 3096 | |
| 3097 | DS.getTypeSpecScope() = SS; |
| 3098 | ConsumeAnnotationToken(); |
| 3099 | (0) . __assert_fail ("Tok.is(tok..annot_template_id) && \"ParseOptionalCXXScopeSpecifier not working\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 3100, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::annot_template_id) && |
| 3100 | (0) . __assert_fail ("Tok.is(tok..annot_template_id) && \"ParseOptionalCXXScopeSpecifier not working\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 3100, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "ParseOptionalCXXScopeSpecifier not working"); |
| 3101 | AnnotateTemplateIdTokenAsType(); |
| 3102 | continue; |
| 3103 | } |
| 3104 | |
| 3105 | if (Next.is(tok::annot_typename)) { |
| 3106 | DS.getTypeSpecScope() = SS; |
| 3107 | ConsumeAnnotationToken(); |
| 3108 | if (Tok.getAnnotationValue()) { |
| 3109 | ParsedType T = getTypeAnnotation(Tok); |
| 3110 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, |
| 3111 | Tok.getAnnotationEndLoc(), |
| 3112 | PrevSpec, DiagID, T, Policy); |
| 3113 | if (isInvalid) |
| 3114 | break; |
| 3115 | } |
| 3116 | else |
| 3117 | DS.SetTypeSpecError(); |
| 3118 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
| 3119 | ConsumeAnnotationToken(); |
| 3120 | } |
| 3121 | |
| 3122 | if (Next.isNot(tok::identifier)) |
| 3123 | goto DoneWithDeclSpec; |
| 3124 | |
| 3125 | |
| 3126 | |
| 3127 | |
| 3128 | if ((DSContext == DeclSpecContext::DSC_top_level || |
| 3129 | DSContext == DeclSpecContext::DSC_class) && |
| 3130 | Actions.isCurrentClassName(*Next.getIdentifierInfo(), getCurScope(), |
| 3131 | &SS) && |
| 3132 | isConstructorDeclarator( false)) |
| 3133 | goto DoneWithDeclSpec; |
| 3134 | |
| 3135 | ParsedType TypeRep = |
| 3136 | Actions.getTypeName(*Next.getIdentifierInfo(), Next.getLocation(), |
| 3137 | getCurScope(), &SS, false, false, nullptr, |
| 3138 | , |
| 3139 | , |
| 3140 | isClassTemplateDeductionContext(DSContext)); |
| 3141 | |
| 3142 | |
| 3143 | |
| 3144 | |
| 3145 | |
| 3146 | if (!TypeRep) { |
| 3147 | |
| 3148 | ConsumeAnnotationToken(); |
| 3149 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 3150 | if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) { |
| 3151 | if (!Attrs.empty()) { |
| 3152 | AttrsLastTime = true; |
| 3153 | attrs.takeAllFrom(Attrs); |
| 3154 | } |
| 3155 | continue; |
| 3156 | } |
| 3157 | goto DoneWithDeclSpec; |
| 3158 | } |
| 3159 | |
| 3160 | DS.getTypeSpecScope() = SS; |
| 3161 | ConsumeAnnotationToken(); |
| 3162 | |
| 3163 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, |
| 3164 | DiagID, TypeRep, Policy); |
| 3165 | if (isInvalid) |
| 3166 | break; |
| 3167 | |
| 3168 | DS.SetRangeEnd(Tok.getLocation()); |
| 3169 | ConsumeToken(); |
| 3170 | |
| 3171 | continue; |
| 3172 | } |
| 3173 | |
| 3174 | case tok::annot_typename: { |
| 3175 | |
| 3176 | |
| 3177 | if (DS.hasTypeSpecifier() && DS.hasTagDefinition()) |
| 3178 | goto DoneWithDeclSpec; |
| 3179 | |
| 3180 | if (Tok.getAnnotationValue()) { |
| 3181 | ParsedType T = getTypeAnnotation(Tok); |
| 3182 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, |
| 3183 | DiagID, T, Policy); |
| 3184 | } else |
| 3185 | DS.SetTypeSpecError(); |
| 3186 | |
| 3187 | if (isInvalid) |
| 3188 | break; |
| 3189 | |
| 3190 | DS.SetRangeEnd(Tok.getAnnotationEndLoc()); |
| 3191 | ConsumeAnnotationToken(); |
| 3192 | |
| 3193 | continue; |
| 3194 | } |
| 3195 | |
| 3196 | case tok::kw___is_signed: |
| 3197 | |
| 3198 | |
| 3199 | |
| 3200 | |
| 3201 | |
| 3202 | |
| 3203 | |
| 3204 | if (DS.getTypeSpecType() == TST_bool && |
| 3205 | DS.getTypeQualifiers() == DeclSpec::TQ_const && |
| 3206 | DS.getStorageClassSpec() == DeclSpec::SCS_static) |
| 3207 | TryKeywordIdentFallback(true); |
| 3208 | |
| 3209 | |
| 3210 | goto DoneWithDeclSpec; |
| 3211 | |
| 3212 | |
| 3213 | case tok::kw___super: |
| 3214 | case tok::kw_decltype: |
| 3215 | case tok::identifier: { |
| 3216 | |
| 3217 | |
| 3218 | |
| 3219 | if (DS.hasTypeSpecifier()) |
| 3220 | goto DoneWithDeclSpec; |
| 3221 | |
| 3222 | |
| 3223 | |
| 3224 | |
| 3225 | |
| 3226 | if (!getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) && |
| 3227 | Tok.getIdentifierInfo()->getName().equals("__declspec")) { |
| 3228 | Diag(Loc, diag::err_ms_attributes_not_enabled); |
| 3229 | |
| 3230 | |
| 3231 | |
| 3232 | if (NextToken().is(tok::l_paren)) { |
| 3233 | |
| 3234 | ConsumeToken(); |
| 3235 | |
| 3236 | |
| 3237 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 3238 | if (T.consumeOpen()) { |
| 3239 | (0) . __assert_fail ("false && \"Not a left paren?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 3239, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(false && "Not a left paren?"); |
| 3240 | return; |
| 3241 | } |
| 3242 | T.skipToEnd(); |
| 3243 | continue; |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | |
| 3248 | |
| 3249 | if (getLangOpts().CPlusPlus) { |
| 3250 | if (TryAnnotateCXXScopeToken(EnteringContext)) { |
| 3251 | DS.SetTypeSpecError(); |
| 3252 | goto DoneWithDeclSpec; |
| 3253 | } |
| 3254 | if (!Tok.is(tok::identifier)) |
| 3255 | continue; |
| 3256 | } |
| 3257 | |
| 3258 | |
| 3259 | if (TryAltiVecToken(DS, Loc, PrevSpec, DiagID, isInvalid)) |
| 3260 | break; |
| 3261 | |
| 3262 | |
| 3263 | |
| 3264 | if (DS.isTypeAltiVecVector()) |
| 3265 | goto DoneWithDeclSpec; |
| 3266 | |
| 3267 | if (DSContext == DeclSpecContext::DSC_objc_method_result && |
| 3268 | isObjCInstancetype()) { |
| 3269 | ParsedType TypeRep = Actions.ActOnObjCInstanceType(Loc); |
| 3270 | assert(TypeRep); |
| 3271 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, |
| 3272 | DiagID, TypeRep, Policy); |
| 3273 | if (isInvalid) |
| 3274 | break; |
| 3275 | |
| 3276 | DS.SetRangeEnd(Loc); |
| 3277 | ConsumeToken(); |
| 3278 | continue; |
| 3279 | } |
| 3280 | |
| 3281 | |
| 3282 | |
| 3283 | if (getLangOpts().CPlusPlus && DSContext == DeclSpecContext::DSC_class && |
| 3284 | Actions.isCurrentClassName(*Tok.getIdentifierInfo(), getCurScope()) && |
| 3285 | isConstructorDeclarator()) |
| 3286 | goto DoneWithDeclSpec; |
| 3287 | |
| 3288 | ParsedType TypeRep = Actions.getTypeName( |
| 3289 | *Tok.getIdentifierInfo(), Tok.getLocation(), getCurScope(), nullptr, |
| 3290 | false, false, nullptr, false, false, |
| 3291 | isClassTemplateDeductionContext(DSContext)); |
| 3292 | |
| 3293 | |
| 3294 | |
| 3295 | if (!TypeRep) { |
| 3296 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 3297 | if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) { |
| 3298 | if (!Attrs.empty()) { |
| 3299 | AttrsLastTime = true; |
| 3300 | attrs.takeAllFrom(Attrs); |
| 3301 | } |
| 3302 | continue; |
| 3303 | } |
| 3304 | goto DoneWithDeclSpec; |
| 3305 | } |
| 3306 | |
| 3307 | |
| 3308 | |
| 3309 | if (getLangOpts().CPlusPlus17 && |
| 3310 | (DSContext == DeclSpecContext::DSC_class || |
| 3311 | DSContext == DeclSpecContext::DSC_top_level) && |
| 3312 | Actions.isDeductionGuideName(getCurScope(), *Tok.getIdentifierInfo(), |
| 3313 | Tok.getLocation()) && |
| 3314 | isConstructorDeclarator( true, |
| 3315 | true)) |
| 3316 | goto DoneWithDeclSpec; |
| 3317 | |
| 3318 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, |
| 3319 | DiagID, TypeRep, Policy); |
| 3320 | if (isInvalid) |
| 3321 | break; |
| 3322 | |
| 3323 | DS.SetRangeEnd(Tok.getLocation()); |
| 3324 | ConsumeToken(); |
| 3325 | |
| 3326 | |
| 3327 | |
| 3328 | |
| 3329 | if (Tok.is(tok::less) && getLangOpts().ObjC) { |
| 3330 | SourceLocation NewEndLoc; |
| 3331 | TypeResult NewTypeRep = parseObjCTypeArgsAndProtocolQualifiers( |
| 3332 | Loc, TypeRep, , |
| 3333 | NewEndLoc); |
| 3334 | if (NewTypeRep.isUsable()) { |
| 3335 | DS.UpdateTypeRep(NewTypeRep.get()); |
| 3336 | DS.SetRangeEnd(NewEndLoc); |
| 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | |
| 3341 | |
| 3342 | continue; |
| 3343 | } |
| 3344 | |
| 3345 | |
| 3346 | case tok::annot_template_id: { |
| 3347 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 3348 | if (TemplateId->Kind != TNK_Type_template) { |
| 3349 | |
| 3350 | |
| 3351 | goto DoneWithDeclSpec; |
| 3352 | } |
| 3353 | |
| 3354 | |
| 3355 | |
| 3356 | |
| 3357 | if (getLangOpts().CPlusPlus && DSContext == DeclSpecContext::DSC_class && |
| 3358 | Actions.isCurrentClassName(*TemplateId->Name, getCurScope()) && |
| 3359 | isConstructorDeclarator(TemplateId->SS.isEmpty())) |
| 3360 | goto DoneWithDeclSpec; |
| 3361 | |
| 3362 | |
| 3363 | |
| 3364 | AnnotateTemplateIdTokenAsType(); |
| 3365 | continue; |
| 3366 | } |
| 3367 | |
| 3368 | |
| 3369 | case tok::kw___attribute: |
| 3370 | ParseGNUAttributes(DS.getAttributes(), nullptr, LateAttrs); |
| 3371 | continue; |
| 3372 | |
| 3373 | |
| 3374 | case tok::kw___declspec: |
| 3375 | ParseMicrosoftDeclSpecs(DS.getAttributes()); |
| 3376 | continue; |
| 3377 | |
| 3378 | |
| 3379 | case tok::kw___forceinline: { |
| 3380 | isInvalid = DS.setFunctionSpecForceInline(Loc, PrevSpec, DiagID); |
| 3381 | IdentifierInfo *AttrName = Tok.getIdentifierInfo(); |
| 3382 | SourceLocation AttrNameLoc = Tok.getLocation(); |
| 3383 | DS.getAttributes().addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, |
| 3384 | nullptr, 0, ParsedAttr::AS_Keyword); |
| 3385 | break; |
| 3386 | } |
| 3387 | |
| 3388 | case tok::kw___unaligned: |
| 3389 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID, |
| 3390 | getLangOpts()); |
| 3391 | break; |
| 3392 | |
| 3393 | case tok::kw___sptr: |
| 3394 | case tok::kw___uptr: |
| 3395 | case tok::kw___ptr64: |
| 3396 | case tok::kw___ptr32: |
| 3397 | case tok::kw___w64: |
| 3398 | case tok::kw___cdecl: |
| 3399 | case tok::kw___stdcall: |
| 3400 | case tok::kw___fastcall: |
| 3401 | case tok::kw___thiscall: |
| 3402 | case tok::kw___regcall: |
| 3403 | case tok::kw___vectorcall: |
| 3404 | ParseMicrosoftTypeAttributes(DS.getAttributes()); |
| 3405 | continue; |
| 3406 | |
| 3407 | |
| 3408 | case tok::kw___pascal: |
| 3409 | ParseBorlandTypeAttributes(DS.getAttributes()); |
| 3410 | continue; |
| 3411 | |
| 3412 | |
| 3413 | case tok::kw___kernel: |
| 3414 | ParseOpenCLKernelAttributes(DS.getAttributes()); |
| 3415 | continue; |
| 3416 | |
| 3417 | |
| 3418 | case tok::kw__Nonnull: |
| 3419 | case tok::kw__Nullable: |
| 3420 | case tok::kw__Null_unspecified: |
| 3421 | ParseNullabilityTypeSpecifiers(DS.getAttributes()); |
| 3422 | continue; |
| 3423 | |
| 3424 | |
| 3425 | case tok::kw___kindof: |
| 3426 | DS.getAttributes().addNew(Tok.getIdentifierInfo(), Loc, nullptr, Loc, |
| 3427 | nullptr, 0, ParsedAttr::AS_Keyword); |
| 3428 | (void)ConsumeToken(); |
| 3429 | continue; |
| 3430 | |
| 3431 | |
| 3432 | case tok::kw_typedef: |
| 3433 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_typedef, Loc, |
| 3434 | PrevSpec, DiagID, Policy); |
| 3435 | isStorageClass = true; |
| 3436 | break; |
| 3437 | case tok::kw_extern: |
| 3438 | if (DS.getThreadStorageClassSpec() == DeclSpec::TSCS___thread) |
| 3439 | Diag(Tok, diag::ext_thread_before) << "extern"; |
| 3440 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_extern, Loc, |
| 3441 | PrevSpec, DiagID, Policy); |
| 3442 | isStorageClass = true; |
| 3443 | break; |
| 3444 | case tok::kw___private_extern__: |
| 3445 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_private_extern, |
| 3446 | Loc, PrevSpec, DiagID, Policy); |
| 3447 | isStorageClass = true; |
| 3448 | break; |
| 3449 | case tok::kw_static: |
| 3450 | if (DS.getThreadStorageClassSpec() == DeclSpec::TSCS___thread) |
| 3451 | Diag(Tok, diag::ext_thread_before) << "static"; |
| 3452 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_static, Loc, |
| 3453 | PrevSpec, DiagID, Policy); |
| 3454 | isStorageClass = true; |
| 3455 | break; |
| 3456 | case tok::kw_auto: |
| 3457 | if (getLangOpts().CPlusPlus11) { |
| 3458 | if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { |
| 3459 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc, |
| 3460 | PrevSpec, DiagID, Policy); |
| 3461 | if (!isInvalid) |
| 3462 | Diag(Tok, diag::ext_auto_storage_class) |
| 3463 | << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc()); |
| 3464 | } else |
| 3465 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, |
| 3466 | DiagID, Policy); |
| 3467 | } else |
| 3468 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_auto, Loc, |
| 3469 | PrevSpec, DiagID, Policy); |
| 3470 | isStorageClass = true; |
| 3471 | break; |
| 3472 | case tok::kw___auto_type: |
| 3473 | Diag(Tok, diag::ext_auto_type); |
| 3474 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_auto_type, Loc, PrevSpec, |
| 3475 | DiagID, Policy); |
| 3476 | break; |
| 3477 | case tok::kw_register: |
| 3478 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_register, Loc, |
| 3479 | PrevSpec, DiagID, Policy); |
| 3480 | isStorageClass = true; |
| 3481 | break; |
| 3482 | case tok::kw_mutable: |
| 3483 | isInvalid = DS.SetStorageClassSpec(Actions, DeclSpec::SCS_mutable, Loc, |
| 3484 | PrevSpec, DiagID, Policy); |
| 3485 | isStorageClass = true; |
| 3486 | break; |
| 3487 | case tok::kw___thread: |
| 3488 | isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS___thread, Loc, |
| 3489 | PrevSpec, DiagID); |
| 3490 | isStorageClass = true; |
| 3491 | break; |
| 3492 | case tok::kw_thread_local: |
| 3493 | isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS_thread_local, Loc, |
| 3494 | PrevSpec, DiagID); |
| 3495 | isStorageClass = true; |
| 3496 | break; |
| 3497 | case tok::kw__Thread_local: |
| 3498 | isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS__Thread_local, |
| 3499 | Loc, PrevSpec, DiagID); |
| 3500 | isStorageClass = true; |
| 3501 | break; |
| 3502 | |
| 3503 | |
| 3504 | case tok::kw_inline: |
| 3505 | isInvalid = DS.setFunctionSpecInline(Loc, PrevSpec, DiagID); |
| 3506 | break; |
| 3507 | case tok::kw_virtual: |
| 3508 | |
| 3509 | if (getLangOpts().OpenCLCPlusPlus) { |
| 3510 | DiagID = diag::err_openclcxx_virtual_function; |
| 3511 | PrevSpec = Tok.getIdentifierInfo()->getNameStart(); |
| 3512 | isInvalid = true; |
| 3513 | } |
| 3514 | else { |
| 3515 | isInvalid = DS.setFunctionSpecVirtual(Loc, PrevSpec, DiagID); |
| 3516 | } |
| 3517 | break; |
| 3518 | case tok::kw_explicit: |
| 3519 | isInvalid = DS.setFunctionSpecExplicit(Loc, PrevSpec, DiagID); |
| 3520 | break; |
| 3521 | case tok::kw__Noreturn: |
| 3522 | if (!getLangOpts().C11) |
| 3523 | Diag(Loc, diag::ext_c11_noreturn); |
| 3524 | isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID); |
| 3525 | break; |
| 3526 | |
| 3527 | |
| 3528 | case tok::kw__Alignas: |
| 3529 | if (!getLangOpts().C11) |
| 3530 | Diag(Tok, diag::ext_c11_alignment) << Tok.getName(); |
| 3531 | ParseAlignmentSpecifier(DS.getAttributes()); |
| 3532 | continue; |
| 3533 | |
| 3534 | |
| 3535 | case tok::kw_friend: |
| 3536 | if (DSContext == DeclSpecContext::DSC_class) |
| 3537 | isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID); |
| 3538 | else { |
| 3539 | PrevSpec = ""; |
| 3540 | DiagID = diag::err_friend_invalid_in_context; |
| 3541 | isInvalid = true; |
| 3542 | } |
| 3543 | break; |
| 3544 | |
| 3545 | |
| 3546 | case tok::kw___module_private__: |
| 3547 | isInvalid = DS.setModulePrivateSpec(Loc, PrevSpec, DiagID); |
| 3548 | break; |
| 3549 | |
| 3550 | |
| 3551 | case tok::kw_constexpr: |
| 3552 | isInvalid = DS.SetConstexprSpec(Loc, PrevSpec, DiagID); |
| 3553 | break; |
| 3554 | |
| 3555 | |
| 3556 | case tok::kw_short: |
| 3557 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, |
| 3558 | DiagID, Policy); |
| 3559 | break; |
| 3560 | case tok::kw_long: |
| 3561 | if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) |
| 3562 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, |
| 3563 | DiagID, Policy); |
| 3564 | else |
| 3565 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, |
| 3566 | DiagID, Policy); |
| 3567 | break; |
| 3568 | case tok::kw___int64: |
| 3569 | isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, |
| 3570 | DiagID, Policy); |
| 3571 | break; |
| 3572 | case tok::kw_signed: |
| 3573 | isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, |
| 3574 | DiagID); |
| 3575 | break; |
| 3576 | case tok::kw_unsigned: |
| 3577 | isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_unsigned, Loc, PrevSpec, |
| 3578 | DiagID); |
| 3579 | break; |
| 3580 | case tok::kw__Complex: |
| 3581 | isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_complex, Loc, PrevSpec, |
| 3582 | DiagID); |
| 3583 | break; |
| 3584 | case tok::kw__Imaginary: |
| 3585 | isInvalid = DS.SetTypeSpecComplex(DeclSpec::TSC_imaginary, Loc, PrevSpec, |
| 3586 | DiagID); |
| 3587 | break; |
| 3588 | case tok::kw_void: |
| 3589 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, |
| 3590 | DiagID, Policy); |
| 3591 | break; |
| 3592 | case tok::kw_char: |
| 3593 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, |
| 3594 | DiagID, Policy); |
| 3595 | break; |
| 3596 | case tok::kw_int: |
| 3597 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, |
| 3598 | DiagID, Policy); |
| 3599 | break; |
| 3600 | case tok::kw___int128: |
| 3601 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, |
| 3602 | DiagID, Policy); |
| 3603 | break; |
| 3604 | case tok::kw_half: |
| 3605 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, |
| 3606 | DiagID, Policy); |
| 3607 | break; |
| 3608 | case tok::kw_float: |
| 3609 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, |
| 3610 | DiagID, Policy); |
| 3611 | break; |
| 3612 | case tok::kw_double: |
| 3613 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, |
| 3614 | DiagID, Policy); |
| 3615 | break; |
| 3616 | case tok::kw__Float16: |
| 3617 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, |
| 3618 | DiagID, Policy); |
| 3619 | break; |
| 3620 | case tok::kw__Accum: |
| 3621 | if (!getLangOpts().FixedPoint) { |
| 3622 | SetupFixedPointError(getLangOpts(), PrevSpec, DiagID, isInvalid); |
| 3623 | } else { |
| 3624 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_accum, Loc, PrevSpec, |
| 3625 | DiagID, Policy); |
| 3626 | } |
| 3627 | break; |
| 3628 | case tok::kw__Fract: |
| 3629 | if (!getLangOpts().FixedPoint) { |
| 3630 | SetupFixedPointError(getLangOpts(), PrevSpec, DiagID, isInvalid); |
| 3631 | } else { |
| 3632 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_fract, Loc, PrevSpec, |
| 3633 | DiagID, Policy); |
| 3634 | } |
| 3635 | break; |
| 3636 | case tok::kw__Sat: |
| 3637 | if (!getLangOpts().FixedPoint) { |
| 3638 | SetupFixedPointError(getLangOpts(), PrevSpec, DiagID, isInvalid); |
| 3639 | } else { |
| 3640 | isInvalid = DS.SetTypeSpecSat(Loc, PrevSpec, DiagID); |
| 3641 | } |
| 3642 | break; |
| 3643 | case tok::kw___float128: |
| 3644 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, |
| 3645 | DiagID, Policy); |
| 3646 | break; |
| 3647 | case tok::kw_wchar_t: |
| 3648 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, |
| 3649 | DiagID, Policy); |
| 3650 | break; |
| 3651 | case tok::kw_char8_t: |
| 3652 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char8, Loc, PrevSpec, |
| 3653 | DiagID, Policy); |
| 3654 | break; |
| 3655 | case tok::kw_char16_t: |
| 3656 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, |
| 3657 | DiagID, Policy); |
| 3658 | break; |
| 3659 | case tok::kw_char32_t: |
| 3660 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, |
| 3661 | DiagID, Policy); |
| 3662 | break; |
| 3663 | case tok::kw_bool: |
| 3664 | case tok::kw__Bool: |
| 3665 | if (Tok.is(tok::kw_bool) && |
| 3666 | DS.getTypeSpecType() != DeclSpec::TST_unspecified && |
| 3667 | DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { |
| 3668 | PrevSpec = ""; |
| 3669 | DiagID = diag::err_bool_redeclaration; |
| 3670 | |
| 3671 | Tok.setKind(tok::identifier); |
| 3672 | isInvalid = true; |
| 3673 | } else { |
| 3674 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, |
| 3675 | DiagID, Policy); |
| 3676 | } |
| 3677 | break; |
| 3678 | case tok::kw__Decimal32: |
| 3679 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal32, Loc, PrevSpec, |
| 3680 | DiagID, Policy); |
| 3681 | break; |
| 3682 | case tok::kw__Decimal64: |
| 3683 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal64, Loc, PrevSpec, |
| 3684 | DiagID, Policy); |
| 3685 | break; |
| 3686 | case tok::kw__Decimal128: |
| 3687 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_decimal128, Loc, PrevSpec, |
| 3688 | DiagID, Policy); |
| 3689 | break; |
| 3690 | case tok::kw___vector: |
| 3691 | isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID, Policy); |
| 3692 | break; |
| 3693 | case tok::kw___pixel: |
| 3694 | isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID, Policy); |
| 3695 | break; |
| 3696 | case tok::kw___bool: |
| 3697 | isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy); |
| 3698 | break; |
| 3699 | case tok::kw_pipe: |
| 3700 | if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200)) { |
| 3701 | |
| 3702 | |
| 3703 | Tok.getIdentifierInfo()->revertTokenIDToIdentifier(); |
| 3704 | goto DoneWithDeclSpec; |
| 3705 | } |
| 3706 | isInvalid = DS.SetTypePipe(true, Loc, PrevSpec, DiagID, Policy); |
| 3707 | break; |
| 3708 | #define GENERIC_IMAGE_TYPE(ImgType, Id) \ |
| 3709 | case tok::kw_##ImgType##_t: \ |
| 3710 | isInvalid = DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, \ |
| 3711 | DiagID, Policy); \ |
| 3712 | break; |
| 3713 | #include "clang/Basic/OpenCLImageTypes.def" |
| 3714 | case tok::kw___unknown_anytype: |
| 3715 | isInvalid = DS.SetTypeSpecType(TST_unknown_anytype, Loc, |
| 3716 | PrevSpec, DiagID, Policy); |
| 3717 | break; |
| 3718 | |
| 3719 | |
| 3720 | case tok::kw_class: |
| 3721 | case tok::kw_struct: |
| 3722 | case tok::kw___interface: |
| 3723 | case tok::kw_union: { |
| 3724 | tok::TokenKind Kind = Tok.getKind(); |
| 3725 | ConsumeToken(); |
| 3726 | |
| 3727 | |
| 3728 | |
| 3729 | |
| 3730 | ParsedAttributesWithRange Attributes(AttrFactory); |
| 3731 | ParseClassSpecifier(Kind, Loc, DS, TemplateInfo, AS, |
| 3732 | EnteringContext, DSContext, Attributes); |
| 3733 | |
| 3734 | |
| 3735 | |
| 3736 | if (!Attributes.empty()) { |
| 3737 | AttrsLastTime = true; |
| 3738 | attrs.takeAllFrom(Attributes); |
| 3739 | } |
| 3740 | continue; |
| 3741 | } |
| 3742 | |
| 3743 | |
| 3744 | case tok::kw_enum: |
| 3745 | ConsumeToken(); |
| 3746 | ParseEnumSpecifier(Loc, DS, TemplateInfo, AS, DSContext); |
| 3747 | continue; |
| 3748 | |
| 3749 | |
| 3750 | case tok::kw_const: |
| 3751 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_const, Loc, PrevSpec, DiagID, |
| 3752 | getLangOpts()); |
| 3753 | break; |
| 3754 | case tok::kw_volatile: |
| 3755 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID, |
| 3756 | getLangOpts()); |
| 3757 | break; |
| 3758 | case tok::kw_restrict: |
| 3759 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID, |
| 3760 | getLangOpts()); |
| 3761 | break; |
| 3762 | |
| 3763 | |
| 3764 | case tok::kw_typename: |
| 3765 | if (TryAnnotateTypeOrScopeToken()) { |
| 3766 | DS.SetTypeSpecError(); |
| 3767 | goto DoneWithDeclSpec; |
| 3768 | } |
| 3769 | if (!Tok.is(tok::kw_typename)) |
| 3770 | continue; |
| 3771 | break; |
| 3772 | |
| 3773 | |
| 3774 | case tok::kw_typeof: |
| 3775 | ParseTypeofSpecifier(DS); |
| 3776 | continue; |
| 3777 | |
| 3778 | case tok::annot_decltype: |
| 3779 | ParseDecltypeSpecifier(DS); |
| 3780 | continue; |
| 3781 | |
| 3782 | case tok::annot_pragma_pack: |
| 3783 | HandlePragmaPack(); |
| 3784 | continue; |
| 3785 | |
| 3786 | case tok::annot_pragma_ms_pragma: |
| 3787 | HandlePragmaMSPragma(); |
| 3788 | continue; |
| 3789 | |
| 3790 | case tok::annot_pragma_ms_vtordisp: |
| 3791 | HandlePragmaMSVtorDisp(); |
| 3792 | continue; |
| 3793 | |
| 3794 | case tok::annot_pragma_ms_pointers_to_members: |
| 3795 | HandlePragmaMSPointersToMembers(); |
| 3796 | continue; |
| 3797 | |
| 3798 | case tok::kw___underlying_type: |
| 3799 | ParseUnderlyingTypeSpecifier(DS); |
| 3800 | continue; |
| 3801 | |
| 3802 | case tok::kw__Atomic: |
| 3803 | |
| 3804 | |
| 3805 | |
| 3806 | |
| 3807 | if (NextToken().is(tok::l_paren)) { |
| 3808 | ParseAtomicSpecifier(DS); |
| 3809 | continue; |
| 3810 | } |
| 3811 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_atomic, Loc, PrevSpec, DiagID, |
| 3812 | getLangOpts()); |
| 3813 | break; |
| 3814 | |
| 3815 | |
| 3816 | case tok::kw___generic: |
| 3817 | |
| 3818 | |
| 3819 | if (Actions.getLangOpts().OpenCLVersion < 200 && |
| 3820 | !Actions.getLangOpts().OpenCLCPlusPlus) { |
| 3821 | DiagID = diag::err_opencl_unknown_type_specifier; |
| 3822 | PrevSpec = Tok.getIdentifierInfo()->getNameStart(); |
| 3823 | isInvalid = true; |
| 3824 | break; |
| 3825 | }; |
| 3826 | LLVM_FALLTHROUGH; |
| 3827 | case tok::kw_private: |
| 3828 | case tok::kw___private: |
| 3829 | case tok::kw___global: |
| 3830 | case tok::kw___local: |
| 3831 | case tok::kw___constant: |
| 3832 | |
| 3833 | case tok::kw___read_only: |
| 3834 | case tok::kw___write_only: |
| 3835 | case tok::kw___read_write: |
| 3836 | ParseOpenCLQualifiers(DS.getAttributes()); |
| 3837 | break; |
| 3838 | |
| 3839 | case tok::less: |
| 3840 | |
| 3841 | |
| 3842 | |
| 3843 | if (DS.hasTypeSpecifier() || !getLangOpts().ObjC) |
| 3844 | goto DoneWithDeclSpec; |
| 3845 | |
| 3846 | SourceLocation StartLoc = Tok.getLocation(); |
| 3847 | SourceLocation EndLoc; |
| 3848 | TypeResult Type = parseObjCProtocolQualifierType(EndLoc); |
| 3849 | if (Type.isUsable()) { |
| 3850 | if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, StartLoc, |
| 3851 | PrevSpec, DiagID, Type.get(), |
| 3852 | Actions.getASTContext().getPrintingPolicy())) |
| 3853 | Diag(StartLoc, DiagID) << PrevSpec; |
| 3854 | |
| 3855 | DS.SetRangeEnd(EndLoc); |
| 3856 | } else { |
| 3857 | DS.SetTypeSpecError(); |
| 3858 | } |
| 3859 | |
| 3860 | |
| 3861 | |
| 3862 | continue; |
| 3863 | } |
| 3864 | |
| 3865 | if (isInvalid) { |
| 3866 | (0) . __assert_fail ("PrevSpec && \"Method did not return previous specifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 3866, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PrevSpec && "Method did not return previous specifier!"); |
| 3867 | assert(DiagID); |
| 3868 | |
| 3869 | if (DiagID == diag::ext_duplicate_declspec || |
| 3870 | DiagID == diag::ext_warn_duplicate_declspec) |
| 3871 | Diag(Tok, DiagID) |
| 3872 | << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation()); |
| 3873 | else if (DiagID == diag::err_opencl_unknown_type_specifier) { |
| 3874 | Diag(Tok, DiagID) << getLangOpts().OpenCLCPlusPlus |
| 3875 | << getLangOpts().getOpenCLVersionTuple().getAsString() |
| 3876 | << PrevSpec << isStorageClass; |
| 3877 | } else |
| 3878 | Diag(Tok, DiagID) << PrevSpec; |
| 3879 | } |
| 3880 | |
| 3881 | DS.SetRangeEnd(Tok.getLocation()); |
| 3882 | if (DiagID != diag::err_bool_redeclaration) |
| 3883 | |
| 3884 | ConsumeAnyToken(); |
| 3885 | |
| 3886 | AttrsLastTime = false; |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | |
| 3891 | |
| 3892 | |
| 3893 | |
| 3894 | |
| 3895 | |
| 3896 | |
| 3897 | |
| 3898 | |
| 3899 | |
| 3900 | |
| 3901 | |
| 3902 | |
| 3903 | |
| 3904 | |
| 3905 | |
| 3906 | |
| 3907 | |
| 3908 | |
| 3909 | |
| 3910 | |
| 3911 | void Parser::ParseStructDeclaration( |
| 3912 | ParsingDeclSpec &DS, |
| 3913 | llvm::function_ref<void(ParsingFieldDeclarator &)> FieldsCallback) { |
| 3914 | |
| 3915 | if (Tok.is(tok::kw___extension__)) { |
| 3916 | |
| 3917 | ExtensionRAIIObject O(Diags); |
| 3918 | ConsumeToken(); |
| 3919 | return ParseStructDeclaration(DS, FieldsCallback); |
| 3920 | } |
| 3921 | |
| 3922 | |
| 3923 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 3924 | MaybeParseCXX11Attributes(Attrs); |
| 3925 | DS.takeAttributesFrom(Attrs); |
| 3926 | |
| 3927 | |
| 3928 | ParseSpecifierQualifierList(DS); |
| 3929 | |
| 3930 | |
| 3931 | |
| 3932 | if (Tok.is(tok::semi)) { |
| 3933 | RecordDecl *AnonRecord = nullptr; |
| 3934 | Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, |
| 3935 | DS, AnonRecord); |
| 3936 | (0) . __assert_fail ("!AnonRecord && \"Did not expect anonymous struct or union here\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 3936, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!AnonRecord && "Did not expect anonymous struct or union here"); |
| 3937 | DS.complete(TheDecl); |
| 3938 | return; |
| 3939 | } |
| 3940 | |
| 3941 | |
| 3942 | bool FirstDeclarator = true; |
| 3943 | SourceLocation CommaLoc; |
| 3944 | while (1) { |
| 3945 | ParsingFieldDeclarator DeclaratorInfo(*this, DS); |
| 3946 | DeclaratorInfo.D.setCommaLoc(CommaLoc); |
| 3947 | |
| 3948 | |
| 3949 | if (!FirstDeclarator) |
| 3950 | MaybeParseGNUAttributes(DeclaratorInfo.D); |
| 3951 | |
| 3952 | |
| 3953 | |
| 3954 | if (Tok.isNot(tok::colon)) { |
| 3955 | |
| 3956 | ColonProtectionRAIIObject X(*this); |
| 3957 | ParseDeclarator(DeclaratorInfo.D); |
| 3958 | } else |
| 3959 | DeclaratorInfo.D.SetIdentifier(nullptr, Tok.getLocation()); |
| 3960 | |
| 3961 | if (TryConsumeToken(tok::colon)) { |
| 3962 | ExprResult Res(ParseConstantExpression()); |
| 3963 | if (Res.isInvalid()) |
| 3964 | SkipUntil(tok::semi, StopBeforeMatch); |
| 3965 | else |
| 3966 | DeclaratorInfo.BitfieldSize = Res.get(); |
| 3967 | } |
| 3968 | |
| 3969 | |
| 3970 | MaybeParseGNUAttributes(DeclaratorInfo.D); |
| 3971 | |
| 3972 | |
| 3973 | FieldsCallback(DeclaratorInfo); |
| 3974 | |
| 3975 | |
| 3976 | |
| 3977 | if (!TryConsumeToken(tok::comma, CommaLoc)) |
| 3978 | return; |
| 3979 | |
| 3980 | FirstDeclarator = false; |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | |
| 3985 | |
| 3986 | |
| 3987 | |
| 3988 | |
| 3989 | |
| 3990 | |
| 3991 | |
| 3992 | |
| 3993 | |
| 3994 | void Parser::ParseStructUnionBody(SourceLocation RecordLoc, |
| 3995 | unsigned TagType, Decl *TagDecl) { |
| 3996 | PrettyDeclStackTraceEntry CrashInfo(Actions.Context, TagDecl, RecordLoc, |
| 3997 | "parsing struct/union body"); |
| 3998 | (0) . __assert_fail ("!getLangOpts().CPlusPlus && \"C++ declarations not supported\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 3998, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!getLangOpts().CPlusPlus && "C++ declarations not supported"); |
| 3999 | |
| 4000 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 4001 | if (T.consumeOpen()) |
| 4002 | return; |
| 4003 | |
| 4004 | ParseScope StructScope(this, Scope::ClassScope|Scope::DeclScope); |
| 4005 | Actions.ActOnTagStartDefinition(getCurScope(), TagDecl); |
| 4006 | |
| 4007 | SmallVector<Decl *, 32> FieldDecls; |
| 4008 | |
| 4009 | |
| 4010 | while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) && |
| 4011 | Tok.isNot(tok::eof)) { |
| 4012 | |
| 4013 | |
| 4014 | |
| 4015 | if (Tok.is(tok::semi)) { |
| 4016 | ConsumeExtraSemi(InsideStruct, TagType); |
| 4017 | continue; |
| 4018 | } |
| 4019 | |
| 4020 | |
| 4021 | if (Tok.is(tok::kw__Static_assert)) { |
| 4022 | SourceLocation DeclEnd; |
| 4023 | ParseStaticAssertDeclaration(DeclEnd); |
| 4024 | continue; |
| 4025 | } |
| 4026 | |
| 4027 | if (Tok.is(tok::annot_pragma_pack)) { |
| 4028 | HandlePragmaPack(); |
| 4029 | continue; |
| 4030 | } |
| 4031 | |
| 4032 | if (Tok.is(tok::annot_pragma_align)) { |
| 4033 | HandlePragmaAlign(); |
| 4034 | continue; |
| 4035 | } |
| 4036 | |
| 4037 | if (Tok.is(tok::annot_pragma_openmp)) { |
| 4038 | |
| 4039 | AccessSpecifier AS = AS_none; |
| 4040 | ParsedAttributesWithRange Attrs(AttrFactory); |
| 4041 | (void)ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs); |
| 4042 | continue; |
| 4043 | } |
| 4044 | |
| 4045 | if (!Tok.is(tok::at)) { |
| 4046 | auto CFieldCallback = [&](ParsingFieldDeclarator &FD) { |
| 4047 | |
| 4048 | Decl *Field = |
| 4049 | Actions.ActOnField(getCurScope(), TagDecl, |
| 4050 | FD.D.getDeclSpec().getSourceRange().getBegin(), |
| 4051 | FD.D, FD.BitfieldSize); |
| 4052 | FieldDecls.push_back(Field); |
| 4053 | FD.complete(Field); |
| 4054 | }; |
| 4055 | |
| 4056 | |
| 4057 | ParsingDeclSpec DS(*this); |
| 4058 | ParseStructDeclaration(DS, CFieldCallback); |
| 4059 | } else { |
| 4060 | ConsumeToken(); |
| 4061 | if (!Tok.isObjCAtKeyword(tok::objc_defs)) { |
| 4062 | Diag(Tok, diag::err_unexpected_at); |
| 4063 | SkipUntil(tok::semi); |
| 4064 | continue; |
| 4065 | } |
| 4066 | ConsumeToken(); |
| 4067 | ExpectAndConsume(tok::l_paren); |
| 4068 | if (!Tok.is(tok::identifier)) { |
| 4069 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 4070 | SkipUntil(tok::semi); |
| 4071 | continue; |
| 4072 | } |
| 4073 | SmallVector<Decl *, 16> Fields; |
| 4074 | Actions.ActOnDefs(getCurScope(), TagDecl, Tok.getLocation(), |
| 4075 | Tok.getIdentifierInfo(), Fields); |
| 4076 | FieldDecls.insert(FieldDecls.end(), Fields.begin(), Fields.end()); |
| 4077 | ConsumeToken(); |
| 4078 | ExpectAndConsume(tok::r_paren); |
| 4079 | } |
| 4080 | |
| 4081 | if (TryConsumeToken(tok::semi)) |
| 4082 | continue; |
| 4083 | |
| 4084 | if (Tok.is(tok::r_brace)) { |
| 4085 | ExpectAndConsume(tok::semi, diag::ext_expected_semi_decl_list); |
| 4086 | break; |
| 4087 | } |
| 4088 | |
| 4089 | ExpectAndConsume(tok::semi, diag::err_expected_semi_decl_list); |
| 4090 | |
| 4091 | SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch); |
| 4092 | |
| 4093 | TryConsumeToken(tok::semi); |
| 4094 | } |
| 4095 | |
| 4096 | T.consumeClose(); |
| 4097 | |
| 4098 | ParsedAttributes attrs(AttrFactory); |
| 4099 | |
| 4100 | MaybeParseGNUAttributes(attrs); |
| 4101 | |
| 4102 | Actions.ActOnFields(getCurScope(), RecordLoc, TagDecl, FieldDecls, |
| 4103 | T.getOpenLocation(), T.getCloseLocation(), attrs); |
| 4104 | StructScope.Exit(); |
| 4105 | Actions.ActOnTagFinishDefinition(getCurScope(), TagDecl, T.getRange()); |
| 4106 | } |
| 4107 | |
| 4108 | |
| 4109 | |
| 4110 | |
| 4111 | |
| 4112 | |
| 4113 | |
| 4114 | |
| 4115 | |
| 4116 | |
| 4117 | |
| 4118 | |
| 4119 | |
| 4120 | |
| 4121 | |
| 4122 | |
| 4123 | |
| 4124 | |
| 4125 | |
| 4126 | |
| 4127 | |
| 4128 | |
| 4129 | |
| 4130 | |
| 4131 | |
| 4132 | |
| 4133 | |
| 4134 | |
| 4135 | |
| 4136 | |
| 4137 | |
| 4138 | void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, |
| 4139 | const ParsedTemplateInfo &TemplateInfo, |
| 4140 | AccessSpecifier AS, DeclSpecContext DSC) { |
| 4141 | |
| 4142 | if (Tok.is(tok::code_completion)) { |
| 4143 | |
| 4144 | Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum); |
| 4145 | return cutOffParsing(); |
| 4146 | } |
| 4147 | |
| 4148 | |
| 4149 | ParsedAttributesWithRange attrs(AttrFactory); |
| 4150 | MaybeParseGNUAttributes(attrs); |
| 4151 | MaybeParseCXX11Attributes(attrs); |
| 4152 | MaybeParseMicrosoftDeclSpecs(attrs); |
| 4153 | |
| 4154 | SourceLocation ScopedEnumKWLoc; |
| 4155 | bool IsScopedUsingClassTag = false; |
| 4156 | |
| 4157 | |
| 4158 | if (Tok.isOneOf(tok::kw_class, tok::kw_struct)) { |
| 4159 | Diag(Tok, getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_scoped_enum |
| 4160 | : diag::ext_scoped_enum); |
| 4161 | IsScopedUsingClassTag = Tok.is(tok::kw_class); |
| 4162 | ScopedEnumKWLoc = ConsumeToken(); |
| 4163 | |
| 4164 | |
| 4165 | |
| 4166 | ProhibitAttributes(attrs); |
| 4167 | |
| 4168 | |
| 4169 | MaybeParseGNUAttributes(attrs); |
| 4170 | MaybeParseCXX11Attributes(attrs); |
| 4171 | MaybeParseMicrosoftDeclSpecs(attrs); |
| 4172 | } |
| 4173 | |
| 4174 | |
| 4175 | |
| 4176 | |
| 4177 | |
| 4178 | |
| 4179 | |
| 4180 | bool shouldDelayDiagsInTag = |
| 4181 | (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation || |
| 4182 | TemplateInfo.Kind == ParsedTemplateInfo::ExplicitSpecialization); |
| 4183 | SuppressAccessChecks diagsFromTag(*this, shouldDelayDiagsInTag); |
| 4184 | |
| 4185 | |
| 4186 | bool AllowDeclaration = DSC != DeclSpecContext::DSC_trailing; |
| 4187 | |
| 4188 | CXXScopeSpec &SS = DS.getTypeSpecScope(); |
| 4189 | if (getLangOpts().CPlusPlus) { |
| 4190 | |
| 4191 | |
| 4192 | ColonProtectionRAIIObject X(*this, AllowDeclaration); |
| 4193 | |
| 4194 | CXXScopeSpec Spec; |
| 4195 | if (ParseOptionalCXXScopeSpecifier(Spec, nullptr, |
| 4196 | )) |
| 4197 | return; |
| 4198 | |
| 4199 | if (Spec.isSet() && Tok.isNot(tok::identifier)) { |
| 4200 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 4201 | if (Tok.isNot(tok::l_brace)) { |
| 4202 | |
| 4203 | |
| 4204 | SkipUntil(tok::comma, StopAtSemi); |
| 4205 | return; |
| 4206 | } |
| 4207 | } |
| 4208 | |
| 4209 | SS = Spec; |
| 4210 | } |
| 4211 | |
| 4212 | |
| 4213 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) && |
| 4214 | !(AllowDeclaration && Tok.is(tok::colon))) { |
| 4215 | Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace; |
| 4216 | |
| 4217 | |
| 4218 | SkipUntil(tok::comma, StopAtSemi); |
| 4219 | return; |
| 4220 | } |
| 4221 | |
| 4222 | |
| 4223 | IdentifierInfo *Name = nullptr; |
| 4224 | SourceLocation NameLoc; |
| 4225 | if (Tok.is(tok::identifier)) { |
| 4226 | Name = Tok.getIdentifierInfo(); |
| 4227 | NameLoc = ConsumeToken(); |
| 4228 | } |
| 4229 | |
| 4230 | if (!Name && ScopedEnumKWLoc.isValid()) { |
| 4231 | |
| 4232 | |
| 4233 | Diag(Tok, diag::err_scoped_enum_missing_identifier); |
| 4234 | ScopedEnumKWLoc = SourceLocation(); |
| 4235 | IsScopedUsingClassTag = false; |
| 4236 | } |
| 4237 | |
| 4238 | |
| 4239 | |
| 4240 | if (shouldDelayDiagsInTag) |
| 4241 | diagsFromTag.done(); |
| 4242 | |
| 4243 | TypeResult BaseType; |
| 4244 | |
| 4245 | |
| 4246 | bool CanBeBitfield = getCurScope()->getFlags() & Scope::ClassScope; |
| 4247 | if (AllowDeclaration && Tok.is(tok::colon)) { |
| 4248 | bool PossibleBitfield = false; |
| 4249 | if (CanBeBitfield) { |
| 4250 | |
| 4251 | |
| 4252 | |
| 4253 | |
| 4254 | |
| 4255 | |
| 4256 | |
| 4257 | EnterExpressionEvaluationContext Unevaluated( |
| 4258 | Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 4259 | TPResult TPR = isExpressionOrTypeSpecifierSimple(NextToken().getKind()); |
| 4260 | |
| 4261 | |
| 4262 | if (TPR == TPResult::True) |
| 4263 | PossibleBitfield = true; |
| 4264 | |
| 4265 | |
| 4266 | |
| 4267 | |
| 4268 | else if (TPR == TPResult::False && |
| 4269 | GetLookAheadToken(2).getKind() == tok::semi) { |
| 4270 | |
| 4271 | ConsumeToken(); |
| 4272 | } else { |
| 4273 | |
| 4274 | |
| 4275 | |
| 4276 | TentativeParsingAction TPA(*this); |
| 4277 | |
| 4278 | |
| 4279 | ConsumeToken(); |
| 4280 | |
| 4281 | |
| 4282 | |
| 4283 | |
| 4284 | |
| 4285 | |
| 4286 | |
| 4287 | if ((getLangOpts().CPlusPlus && |
| 4288 | isCXXDeclarationSpecifier(TPResult::True) != TPResult::True) || |
| 4289 | (!getLangOpts().CPlusPlus && !isDeclarationSpecifier(true))) { |
| 4290 | |
| 4291 | PossibleBitfield = true; |
| 4292 | TPA.Revert(); |
| 4293 | } else { |
| 4294 | |
| 4295 | TPA.Commit(); |
| 4296 | } |
| 4297 | } |
| 4298 | } else { |
| 4299 | |
| 4300 | ConsumeToken(); |
| 4301 | } |
| 4302 | |
| 4303 | if (!PossibleBitfield) { |
| 4304 | SourceRange Range; |
| 4305 | BaseType = ParseTypeName(&Range); |
| 4306 | |
| 4307 | if (!getLangOpts().ObjC) { |
| 4308 | if (getLangOpts().CPlusPlus11) |
| 4309 | Diag(StartLoc, diag::warn_cxx98_compat_enum_fixed_underlying_type); |
| 4310 | else if (getLangOpts().CPlusPlus) |
| 4311 | Diag(StartLoc, diag::ext_cxx11_enum_fixed_underlying_type); |
| 4312 | else if (getLangOpts().MicrosoftExt) |
| 4313 | Diag(StartLoc, diag::ext_ms_c_enum_fixed_underlying_type); |
| 4314 | else |
| 4315 | Diag(StartLoc, diag::ext_clang_c_enum_fixed_underlying_type); |
| 4316 | } |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | |
| 4321 | |
| 4322 | |
| 4323 | |
| 4324 | |
| 4325 | |
| 4326 | |
| 4327 | |
| 4328 | |
| 4329 | |
| 4330 | Sema::TagUseKind TUK; |
| 4331 | if (!AllowDeclaration) { |
| 4332 | TUK = Sema::TUK_Reference; |
| 4333 | } else if (Tok.is(tok::l_brace)) { |
| 4334 | if (DS.isFriendSpecified()) { |
| 4335 | Diag(Tok.getLocation(), diag::err_friend_decl_defines_type) |
| 4336 | << SourceRange(DS.getFriendSpecLoc()); |
| 4337 | ConsumeBrace(); |
| 4338 | SkipUntil(tok::r_brace, StopAtSemi); |
| 4339 | TUK = Sema::TUK_Friend; |
| 4340 | } else { |
| 4341 | TUK = Sema::TUK_Definition; |
| 4342 | } |
| 4343 | } else if (!isTypeSpecifier(DSC) && |
| 4344 | (Tok.is(tok::semi) || |
| 4345 | (Tok.isAtStartOfLine() && |
| 4346 | !isValidAfterTypeSpecifier(CanBeBitfield)))) { |
| 4347 | TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration; |
| 4348 | if (Tok.isNot(tok::semi)) { |
| 4349 | |
| 4350 | ExpectAndConsume(tok::semi, diag::err_expected_after, "enum"); |
| 4351 | PP.EnterToken(Tok); |
| 4352 | Tok.setKind(tok::semi); |
| 4353 | } |
| 4354 | } else { |
| 4355 | TUK = Sema::TUK_Reference; |
| 4356 | } |
| 4357 | |
| 4358 | |
| 4359 | |
| 4360 | if (TUK == Sema::TUK_Reference && shouldDelayDiagsInTag) { |
| 4361 | diagsFromTag.redelay(); |
| 4362 | } |
| 4363 | |
| 4364 | MultiTemplateParamsArg TParams; |
| 4365 | if (TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate && |
| 4366 | TUK != Sema::TUK_Reference) { |
| 4367 | if (!getLangOpts().CPlusPlus11 || !SS.isSet()) { |
| 4368 | |
| 4369 | Diag(Tok, diag::err_enum_template); |
| 4370 | SkipUntil(tok::comma, StopAtSemi); |
| 4371 | return; |
| 4372 | } |
| 4373 | |
| 4374 | if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) { |
| 4375 | |
| 4376 | DS.SetTypeSpecError(); |
| 4377 | Diag(StartLoc, diag::err_explicit_instantiation_enum); |
| 4378 | return; |
| 4379 | } |
| 4380 | |
| 4381 | (0) . __assert_fail ("TemplateInfo.TemplateParams && \"no template parameters\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 4381, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TemplateInfo.TemplateParams && "no template parameters"); |
| 4382 | TParams = MultiTemplateParamsArg(TemplateInfo.TemplateParams->data(), |
| 4383 | TemplateInfo.TemplateParams->size()); |
| 4384 | } |
| 4385 | |
| 4386 | if (TUK == Sema::TUK_Reference) |
| 4387 | ProhibitAttributes(attrs); |
| 4388 | |
| 4389 | if (!Name && TUK != Sema::TUK_Definition) { |
| 4390 | Diag(Tok, diag::err_enumerator_unnamed_no_def); |
| 4391 | |
| 4392 | |
| 4393 | SkipUntil(tok::comma, StopAtSemi); |
| 4394 | return; |
| 4395 | } |
| 4396 | |
| 4397 | stripTypeAttributesOffDeclSpec(attrs, DS, TUK); |
| 4398 | |
| 4399 | Sema::SkipBodyInfo SkipBody; |
| 4400 | if (!Name && TUK == Sema::TUK_Definition && Tok.is(tok::l_brace) && |
| 4401 | NextToken().is(tok::identifier)) |
| 4402 | SkipBody = Actions.shouldSkipAnonEnumBody(getCurScope(), |
| 4403 | NextToken().getIdentifierInfo(), |
| 4404 | NextToken().getLocation()); |
| 4405 | |
| 4406 | bool Owned = false; |
| 4407 | bool IsDependent = false; |
| 4408 | const char *PrevSpec = nullptr; |
| 4409 | unsigned DiagID; |
| 4410 | Decl *TagDecl = Actions.ActOnTag( |
| 4411 | getCurScope(), DeclSpec::TST_enum, TUK, StartLoc, SS, Name, NameLoc, |
| 4412 | attrs, AS, DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent, |
| 4413 | ScopedEnumKWLoc, IsScopedUsingClassTag, BaseType, |
| 4414 | DSC == DeclSpecContext::DSC_type_specifier, |
| 4415 | DSC == DeclSpecContext::DSC_template_param || |
| 4416 | DSC == DeclSpecContext::DSC_template_type_arg, |
| 4417 | &SkipBody); |
| 4418 | |
| 4419 | if (SkipBody.ShouldSkip) { |
| 4420 | (0) . __assert_fail ("TUK == Sema..TUK_Definition && \"can only skip a definition\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 4420, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(TUK == Sema::TUK_Definition && "can only skip a definition"); |
| 4421 | |
| 4422 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 4423 | T.consumeOpen(); |
| 4424 | T.skipToEnd(); |
| 4425 | |
| 4426 | if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, |
| 4427 | NameLoc.isValid() ? NameLoc : StartLoc, |
| 4428 | PrevSpec, DiagID, TagDecl, Owned, |
| 4429 | Actions.getASTContext().getPrintingPolicy())) |
| 4430 | Diag(StartLoc, DiagID) << PrevSpec; |
| 4431 | return; |
| 4432 | } |
| 4433 | |
| 4434 | if (IsDependent) { |
| 4435 | |
| 4436 | |
| 4437 | if (!Name) { |
| 4438 | DS.SetTypeSpecError(); |
| 4439 | Diag(Tok, diag::err_expected_type_name_after_typename); |
| 4440 | return; |
| 4441 | } |
| 4442 | |
| 4443 | TypeResult Type = Actions.ActOnDependentTag( |
| 4444 | getCurScope(), DeclSpec::TST_enum, TUK, SS, Name, StartLoc, NameLoc); |
| 4445 | if (Type.isInvalid()) { |
| 4446 | DS.SetTypeSpecError(); |
| 4447 | return; |
| 4448 | } |
| 4449 | |
| 4450 | if (DS.SetTypeSpecType(DeclSpec::TST_typename, StartLoc, |
| 4451 | NameLoc.isValid() ? NameLoc : StartLoc, |
| 4452 | PrevSpec, DiagID, Type.get(), |
| 4453 | Actions.getASTContext().getPrintingPolicy())) |
| 4454 | Diag(StartLoc, DiagID) << PrevSpec; |
| 4455 | |
| 4456 | return; |
| 4457 | } |
| 4458 | |
| 4459 | if (!TagDecl) { |
| 4460 | |
| 4461 | |
| 4462 | if (Tok.is(tok::l_brace) && TUK != Sema::TUK_Reference) { |
| 4463 | ConsumeBrace(); |
| 4464 | SkipUntil(tok::r_brace, StopAtSemi); |
| 4465 | } |
| 4466 | |
| 4467 | DS.SetTypeSpecError(); |
| 4468 | return; |
| 4469 | } |
| 4470 | |
| 4471 | if (Tok.is(tok::l_brace) && TUK != Sema::TUK_Reference) { |
| 4472 | Decl *D = SkipBody.CheckSameAsPrevious ? SkipBody.New : TagDecl; |
| 4473 | ParseEnumBody(StartLoc, D); |
| 4474 | if (SkipBody.CheckSameAsPrevious && |
| 4475 | !Actions.ActOnDuplicateDefinition(DS, TagDecl, SkipBody)) { |
| 4476 | DS.SetTypeSpecError(); |
| 4477 | return; |
| 4478 | } |
| 4479 | } |
| 4480 | |
| 4481 | if (DS.SetTypeSpecType(DeclSpec::TST_enum, StartLoc, |
| 4482 | NameLoc.isValid() ? NameLoc : StartLoc, |
| 4483 | PrevSpec, DiagID, TagDecl, Owned, |
| 4484 | Actions.getASTContext().getPrintingPolicy())) |
| 4485 | Diag(StartLoc, DiagID) << PrevSpec; |
| 4486 | } |
| 4487 | |
| 4488 | |
| 4489 | |
| 4490 | |
| 4491 | |
| 4492 | |
| 4493 | |
| 4494 | |
| 4495 | |
| 4496 | |
| 4497 | |
| 4498 | void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) { |
| 4499 | |
| 4500 | ParseScope EnumScope(this, Scope::DeclScope | Scope::EnumScope); |
| 4501 | Actions.ActOnTagStartDefinition(getCurScope(), EnumDecl); |
| 4502 | |
| 4503 | BalancedDelimiterTracker T(*this, tok::l_brace); |
| 4504 | T.consumeOpen(); |
| 4505 | |
| 4506 | |
| 4507 | if (Tok.is(tok::r_brace) && !getLangOpts().CPlusPlus) |
| 4508 | Diag(Tok, diag::err_empty_enum); |
| 4509 | |
| 4510 | SmallVector<Decl *, 32> EnumConstantDecls; |
| 4511 | SmallVector<SuppressAccessChecks, 32> EnumAvailabilityDiags; |
| 4512 | |
| 4513 | Decl *LastEnumConstDecl = nullptr; |
| 4514 | |
| 4515 | |
| 4516 | while (Tok.isNot(tok::r_brace)) { |
| 4517 | |
| 4518 | |
| 4519 | if (Tok.isNot(tok::identifier)) { |
| 4520 | Diag(Tok.getLocation(), diag::err_expected) << tok::identifier; |
| 4521 | if (SkipUntil(tok::comma, tok::r_brace, StopBeforeMatch) && |
| 4522 | TryConsumeToken(tok::comma)) |
| 4523 | continue; |
| 4524 | break; |
| 4525 | } |
| 4526 | IdentifierInfo *Ident = Tok.getIdentifierInfo(); |
| 4527 | SourceLocation IdentLoc = ConsumeToken(); |
| 4528 | |
| 4529 | |
| 4530 | ParsedAttributesWithRange attrs(AttrFactory); |
| 4531 | MaybeParseGNUAttributes(attrs); |
| 4532 | ProhibitAttributes(attrs); |
| 4533 | if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) { |
| 4534 | if (getLangOpts().CPlusPlus) |
| 4535 | Diag(Tok.getLocation(), getLangOpts().CPlusPlus17 |
| 4536 | ? diag::warn_cxx14_compat_ns_enum_attribute |
| 4537 | : diag::ext_ns_enum_attribute) |
| 4538 | << 1 ; |
| 4539 | ParseCXX11Attributes(attrs); |
| 4540 | } |
| 4541 | |
| 4542 | SourceLocation EqualLoc; |
| 4543 | ExprResult AssignedVal; |
| 4544 | EnumAvailabilityDiags.emplace_back(*this); |
| 4545 | |
| 4546 | if (TryConsumeToken(tok::equal, EqualLoc)) { |
| 4547 | AssignedVal = ParseConstantExpression(); |
| 4548 | if (AssignedVal.isInvalid()) |
| 4549 | SkipUntil(tok::comma, tok::r_brace, StopBeforeMatch); |
| 4550 | } |
| 4551 | |
| 4552 | |
| 4553 | Decl *EnumConstDecl = Actions.ActOnEnumConstant( |
| 4554 | getCurScope(), EnumDecl, LastEnumConstDecl, IdentLoc, Ident, attrs, |
| 4555 | EqualLoc, AssignedVal.get()); |
| 4556 | EnumAvailabilityDiags.back().done(); |
| 4557 | |
| 4558 | EnumConstantDecls.push_back(EnumConstDecl); |
| 4559 | LastEnumConstDecl = EnumConstDecl; |
| 4560 | |
| 4561 | if (Tok.is(tok::identifier)) { |
| 4562 | |
| 4563 | SourceLocation Loc = getEndOfPreviousToken(); |
| 4564 | Diag(Loc, diag::err_enumerator_list_missing_comma) |
| 4565 | << FixItHint::CreateInsertion(Loc, ", "); |
| 4566 | continue; |
| 4567 | } |
| 4568 | |
| 4569 | |
| 4570 | |
| 4571 | SourceLocation CommaLoc; |
| 4572 | if (Tok.isNot(tok::r_brace) && !TryConsumeToken(tok::comma, CommaLoc)) { |
| 4573 | if (EqualLoc.isValid()) |
| 4574 | Diag(Tok.getLocation(), diag::err_expected_either) << tok::r_brace |
| 4575 | << tok::comma; |
| 4576 | else |
| 4577 | Diag(Tok.getLocation(), diag::err_expected_end_of_enumerator); |
| 4578 | if (SkipUntil(tok::comma, tok::r_brace, StopBeforeMatch)) { |
| 4579 | if (TryConsumeToken(tok::comma, CommaLoc)) |
| 4580 | continue; |
| 4581 | } else { |
| 4582 | break; |
| 4583 | } |
| 4584 | } |
| 4585 | |
| 4586 | |
| 4587 | if (Tok.is(tok::r_brace) && CommaLoc.isValid()) { |
| 4588 | if (!getLangOpts().C99 && !getLangOpts().CPlusPlus11) |
| 4589 | Diag(CommaLoc, getLangOpts().CPlusPlus ? |
| 4590 | diag::ext_enumerator_list_comma_cxx : |
| 4591 | diag::ext_enumerator_list_comma_c) |
| 4592 | << FixItHint::CreateRemoval(CommaLoc); |
| 4593 | else if (getLangOpts().CPlusPlus11) |
| 4594 | Diag(CommaLoc, diag::warn_cxx98_compat_enumerator_list_comma) |
| 4595 | << FixItHint::CreateRemoval(CommaLoc); |
| 4596 | break; |
| 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | |
| 4601 | T.consumeClose(); |
| 4602 | |
| 4603 | |
| 4604 | ParsedAttributes attrs(AttrFactory); |
| 4605 | MaybeParseGNUAttributes(attrs); |
| 4606 | |
| 4607 | Actions.ActOnEnumBody(StartLoc, T.getRange(), EnumDecl, EnumConstantDecls, |
| 4608 | getCurScope(), attrs); |
| 4609 | |
| 4610 | |
| 4611 | assert(EnumConstantDecls.size() == EnumAvailabilityDiags.size()); |
| 4612 | for (size_t i = 0, e = EnumConstantDecls.size(); i != e; ++i) { |
| 4613 | ParsingDeclRAIIObject PD(*this, ParsingDeclRAIIObject::NoParent); |
| 4614 | EnumAvailabilityDiags[i].redelay(); |
| 4615 | PD.complete(EnumConstantDecls[i]); |
| 4616 | } |
| 4617 | |
| 4618 | EnumScope.Exit(); |
| 4619 | Actions.ActOnTagFinishDefinition(getCurScope(), EnumDecl, T.getRange()); |
| 4620 | |
| 4621 | |
| 4622 | |
| 4623 | bool CanBeBitfield = getCurScope()->getFlags() & Scope::ClassScope; |
| 4624 | if (!isValidAfterTypeSpecifier(CanBeBitfield)) { |
| 4625 | ExpectAndConsume(tok::semi, diag::err_expected_after, "enum"); |
| 4626 | |
| 4627 | |
| 4628 | |
| 4629 | PP.EnterToken(Tok); |
| 4630 | Tok.setKind(tok::semi); |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | |
| 4635 | |
| 4636 | |
| 4637 | bool Parser::isKnownToBeTypeSpecifier(const Token &Tok) const { |
| 4638 | switch (Tok.getKind()) { |
| 4639 | default: return false; |
| 4640 | |
| 4641 | case tok::kw_short: |
| 4642 | case tok::kw_long: |
| 4643 | case tok::kw___int64: |
| 4644 | case tok::kw___int128: |
| 4645 | case tok::kw_signed: |
| 4646 | case tok::kw_unsigned: |
| 4647 | case tok::kw__Complex: |
| 4648 | case tok::kw__Imaginary: |
| 4649 | case tok::kw_void: |
| 4650 | case tok::kw_char: |
| 4651 | case tok::kw_wchar_t: |
| 4652 | case tok::kw_char8_t: |
| 4653 | case tok::kw_char16_t: |
| 4654 | case tok::kw_char32_t: |
| 4655 | case tok::kw_int: |
| 4656 | case tok::kw_half: |
| 4657 | case tok::kw_float: |
| 4658 | case tok::kw_double: |
| 4659 | case tok::kw__Accum: |
| 4660 | case tok::kw__Fract: |
| 4661 | case tok::kw__Float16: |
| 4662 | case tok::kw___float128: |
| 4663 | case tok::kw_bool: |
| 4664 | case tok::kw__Bool: |
| 4665 | case tok::kw__Decimal32: |
| 4666 | case tok::kw__Decimal64: |
| 4667 | case tok::kw__Decimal128: |
| 4668 | case tok::kw___vector: |
| 4669 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 4670 | #include "clang/Basic/OpenCLImageTypes.def" |
| 4671 | |
| 4672 | |
| 4673 | case tok::kw_class: |
| 4674 | case tok::kw_struct: |
| 4675 | case tok::kw___interface: |
| 4676 | case tok::kw_union: |
| 4677 | |
| 4678 | case tok::kw_enum: |
| 4679 | |
| 4680 | |
| 4681 | case tok::annot_typename: |
| 4682 | return true; |
| 4683 | } |
| 4684 | } |
| 4685 | |
| 4686 | |
| 4687 | |
| 4688 | bool Parser::isTypeSpecifierQualifier() { |
| 4689 | switch (Tok.getKind()) { |
| 4690 | default: return false; |
| 4691 | |
| 4692 | case tok::identifier: |
| 4693 | if (TryAltiVecVectorToken()) |
| 4694 | return true; |
| 4695 | LLVM_FALLTHROUGH; |
| 4696 | case tok::kw_typename: |
| 4697 | |
| 4698 | |
| 4699 | if (TryAnnotateTypeOrScopeToken()) |
| 4700 | return true; |
| 4701 | if (Tok.is(tok::identifier)) |
| 4702 | return false; |
| 4703 | return isTypeSpecifierQualifier(); |
| 4704 | |
| 4705 | case tok::coloncolon: |
| 4706 | if (NextToken().is(tok::kw_new) || |
| 4707 | NextToken().is(tok::kw_delete)) |
| 4708 | return false; |
| 4709 | |
| 4710 | if (TryAnnotateTypeOrScopeToken()) |
| 4711 | return true; |
| 4712 | return isTypeSpecifierQualifier(); |
| 4713 | |
| 4714 | |
| 4715 | case tok::kw___attribute: |
| 4716 | |
| 4717 | case tok::kw_typeof: |
| 4718 | |
| 4719 | |
| 4720 | case tok::kw_short: |
| 4721 | case tok::kw_long: |
| 4722 | case tok::kw___int64: |
| 4723 | case tok::kw___int128: |
| 4724 | case tok::kw_signed: |
| 4725 | case tok::kw_unsigned: |
| 4726 | case tok::kw__Complex: |
| 4727 | case tok::kw__Imaginary: |
| 4728 | case tok::kw_void: |
| 4729 | case tok::kw_char: |
| 4730 | case tok::kw_wchar_t: |
| 4731 | case tok::kw_char8_t: |
| 4732 | case tok::kw_char16_t: |
| 4733 | case tok::kw_char32_t: |
| 4734 | case tok::kw_int: |
| 4735 | case tok::kw_half: |
| 4736 | case tok::kw_float: |
| 4737 | case tok::kw_double: |
| 4738 | case tok::kw__Accum: |
| 4739 | case tok::kw__Fract: |
| 4740 | case tok::kw__Float16: |
| 4741 | case tok::kw___float128: |
| 4742 | case tok::kw_bool: |
| 4743 | case tok::kw__Bool: |
| 4744 | case tok::kw__Decimal32: |
| 4745 | case tok::kw__Decimal64: |
| 4746 | case tok::kw__Decimal128: |
| 4747 | case tok::kw___vector: |
| 4748 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 4749 | #include "clang/Basic/OpenCLImageTypes.def" |
| 4750 | |
| 4751 | |
| 4752 | case tok::kw_class: |
| 4753 | case tok::kw_struct: |
| 4754 | case tok::kw___interface: |
| 4755 | case tok::kw_union: |
| 4756 | |
| 4757 | case tok::kw_enum: |
| 4758 | |
| 4759 | |
| 4760 | case tok::kw_const: |
| 4761 | case tok::kw_volatile: |
| 4762 | case tok::kw_restrict: |
| 4763 | case tok::kw__Sat: |
| 4764 | |
| 4765 | |
| 4766 | case tok::kw___unknown_anytype: |
| 4767 | |
| 4768 | |
| 4769 | case tok::annot_typename: |
| 4770 | return true; |
| 4771 | |
| 4772 | |
| 4773 | case tok::less: |
| 4774 | return getLangOpts().ObjC; |
| 4775 | |
| 4776 | case tok::kw___cdecl: |
| 4777 | case tok::kw___stdcall: |
| 4778 | case tok::kw___fastcall: |
| 4779 | case tok::kw___thiscall: |
| 4780 | case tok::kw___regcall: |
| 4781 | case tok::kw___vectorcall: |
| 4782 | case tok::kw___w64: |
| 4783 | case tok::kw___ptr64: |
| 4784 | case tok::kw___ptr32: |
| 4785 | case tok::kw___pascal: |
| 4786 | case tok::kw___unaligned: |
| 4787 | |
| 4788 | case tok::kw__Nonnull: |
| 4789 | case tok::kw__Nullable: |
| 4790 | case tok::kw__Null_unspecified: |
| 4791 | |
| 4792 | case tok::kw___kindof: |
| 4793 | |
| 4794 | case tok::kw___private: |
| 4795 | case tok::kw___local: |
| 4796 | case tok::kw___global: |
| 4797 | case tok::kw___constant: |
| 4798 | case tok::kw___generic: |
| 4799 | case tok::kw___read_only: |
| 4800 | case tok::kw___read_write: |
| 4801 | case tok::kw___write_only: |
| 4802 | return true; |
| 4803 | |
| 4804 | case tok::kw_private: |
| 4805 | return getLangOpts().OpenCL; |
| 4806 | |
| 4807 | |
| 4808 | case tok::kw__Atomic: |
| 4809 | return true; |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | |
| 4814 | |
| 4815 | |
| 4816 | |
| 4817 | |
| 4818 | bool Parser::isDeclarationSpecifier(bool DisambiguatingWithExpression) { |
| 4819 | switch (Tok.getKind()) { |
| 4820 | default: return false; |
| 4821 | |
| 4822 | case tok::kw_pipe: |
| 4823 | return getLangOpts().OpenCL && (getLangOpts().OpenCLVersion >= 200); |
| 4824 | |
| 4825 | case tok::identifier: |
| 4826 | |
| 4827 | if (getLangOpts().ObjC && NextToken().is(tok::period)) |
| 4828 | return false; |
| 4829 | if (TryAltiVecVectorToken()) |
| 4830 | return true; |
| 4831 | LLVM_FALLTHROUGH; |
| 4832 | case tok::kw_decltype: |
| 4833 | case tok::kw_typename: |
| 4834 | |
| 4835 | |
| 4836 | if (TryAnnotateTypeOrScopeToken()) |
| 4837 | return true; |
| 4838 | if (Tok.is(tok::identifier)) |
| 4839 | return false; |
| 4840 | |
| 4841 | |
| 4842 | |
| 4843 | |
| 4844 | |
| 4845 | |
| 4846 | if (DisambiguatingWithExpression && |
| 4847 | isStartOfObjCClassMessageMissingOpenBracket()) |
| 4848 | return false; |
| 4849 | |
| 4850 | return isDeclarationSpecifier(); |
| 4851 | |
| 4852 | case tok::coloncolon: |
| 4853 | if (NextToken().is(tok::kw_new) || |
| 4854 | NextToken().is(tok::kw_delete)) |
| 4855 | return false; |
| 4856 | |
| 4857 | |
| 4858 | |
| 4859 | if (TryAnnotateTypeOrScopeToken()) |
| 4860 | return true; |
| 4861 | return isDeclarationSpecifier(); |
| 4862 | |
| 4863 | |
| 4864 | case tok::kw_typedef: |
| 4865 | case tok::kw_extern: |
| 4866 | case tok::kw___private_extern__: |
| 4867 | case tok::kw_static: |
| 4868 | case tok::kw_auto: |
| 4869 | case tok::kw___auto_type: |
| 4870 | case tok::kw_register: |
| 4871 | case tok::kw___thread: |
| 4872 | case tok::kw_thread_local: |
| 4873 | case tok::kw__Thread_local: |
| 4874 | |
| 4875 | |
| 4876 | case tok::kw___module_private__: |
| 4877 | |
| 4878 | |
| 4879 | case tok::kw___unknown_anytype: |
| 4880 | |
| 4881 | |
| 4882 | case tok::kw_short: |
| 4883 | case tok::kw_long: |
| 4884 | case tok::kw___int64: |
| 4885 | case tok::kw___int128: |
| 4886 | case tok::kw_signed: |
| 4887 | case tok::kw_unsigned: |
| 4888 | case tok::kw__Complex: |
| 4889 | case tok::kw__Imaginary: |
| 4890 | case tok::kw_void: |
| 4891 | case tok::kw_char: |
| 4892 | case tok::kw_wchar_t: |
| 4893 | case tok::kw_char8_t: |
| 4894 | case tok::kw_char16_t: |
| 4895 | case tok::kw_char32_t: |
| 4896 | |
| 4897 | case tok::kw_int: |
| 4898 | case tok::kw_half: |
| 4899 | case tok::kw_float: |
| 4900 | case tok::kw_double: |
| 4901 | case tok::kw__Accum: |
| 4902 | case tok::kw__Fract: |
| 4903 | case tok::kw__Float16: |
| 4904 | case tok::kw___float128: |
| 4905 | case tok::kw_bool: |
| 4906 | case tok::kw__Bool: |
| 4907 | case tok::kw__Decimal32: |
| 4908 | case tok::kw__Decimal64: |
| 4909 | case tok::kw__Decimal128: |
| 4910 | case tok::kw___vector: |
| 4911 | |
| 4912 | |
| 4913 | case tok::kw_class: |
| 4914 | case tok::kw_struct: |
| 4915 | case tok::kw_union: |
| 4916 | case tok::kw___interface: |
| 4917 | |
| 4918 | case tok::kw_enum: |
| 4919 | |
| 4920 | |
| 4921 | case tok::kw_const: |
| 4922 | case tok::kw_volatile: |
| 4923 | case tok::kw_restrict: |
| 4924 | case tok::kw__Sat: |
| 4925 | |
| 4926 | |
| 4927 | case tok::kw_inline: |
| 4928 | case tok::kw_virtual: |
| 4929 | case tok::kw_explicit: |
| 4930 | case tok::kw__Noreturn: |
| 4931 | |
| 4932 | |
| 4933 | case tok::kw__Alignas: |
| 4934 | |
| 4935 | |
| 4936 | case tok::kw_friend: |
| 4937 | |
| 4938 | |
| 4939 | case tok::kw__Static_assert: |
| 4940 | |
| 4941 | |
| 4942 | case tok::kw_typeof: |
| 4943 | |
| 4944 | |
| 4945 | case tok::kw___attribute: |
| 4946 | |
| 4947 | |
| 4948 | case tok::annot_decltype: |
| 4949 | case tok::kw_constexpr: |
| 4950 | |
| 4951 | |
| 4952 | case tok::kw__Atomic: |
| 4953 | return true; |
| 4954 | |
| 4955 | |
| 4956 | case tok::less: |
| 4957 | return getLangOpts().ObjC; |
| 4958 | |
| 4959 | |
| 4960 | case tok::annot_typename: |
| 4961 | return !DisambiguatingWithExpression || |
| 4962 | !isStartOfObjCClassMessageMissingOpenBracket(); |
| 4963 | |
| 4964 | case tok::kw___declspec: |
| 4965 | case tok::kw___cdecl: |
| 4966 | case tok::kw___stdcall: |
| 4967 | case tok::kw___fastcall: |
| 4968 | case tok::kw___thiscall: |
| 4969 | case tok::kw___regcall: |
| 4970 | case tok::kw___vectorcall: |
| 4971 | case tok::kw___w64: |
| 4972 | case tok::kw___sptr: |
| 4973 | case tok::kw___uptr: |
| 4974 | case tok::kw___ptr64: |
| 4975 | case tok::kw___ptr32: |
| 4976 | case tok::kw___forceinline: |
| 4977 | case tok::kw___pascal: |
| 4978 | case tok::kw___unaligned: |
| 4979 | |
| 4980 | case tok::kw__Nonnull: |
| 4981 | case tok::kw__Nullable: |
| 4982 | case tok::kw__Null_unspecified: |
| 4983 | |
| 4984 | case tok::kw___kindof: |
| 4985 | |
| 4986 | case tok::kw___private: |
| 4987 | case tok::kw___local: |
| 4988 | case tok::kw___global: |
| 4989 | case tok::kw___constant: |
| 4990 | case tok::kw___generic: |
| 4991 | case tok::kw___read_only: |
| 4992 | case tok::kw___read_write: |
| 4993 | case tok::kw___write_only: |
| 4994 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 4995 | #include "clang/Basic/OpenCLImageTypes.def" |
| 4996 | |
| 4997 | return true; |
| 4998 | |
| 4999 | case tok::kw_private: |
| 5000 | return getLangOpts().OpenCL; |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | bool Parser::isConstructorDeclarator(bool IsUnqualified, bool DeductionGuide) { |
| 5005 | TentativeParsingAction TPA(*this); |
| 5006 | |
| 5007 | |
| 5008 | CXXScopeSpec SS; |
| 5009 | if (ParseOptionalCXXScopeSpecifier(SS, nullptr, |
| 5010 | )) { |
| 5011 | TPA.Revert(); |
| 5012 | return false; |
| 5013 | } |
| 5014 | |
| 5015 | |
| 5016 | if (Tok.is(tok::identifier)) { |
| 5017 | |
| 5018 | |
| 5019 | ConsumeToken(); |
| 5020 | } else if (Tok.is(tok::annot_template_id)) { |
| 5021 | ConsumeAnnotationToken(); |
| 5022 | } else { |
| 5023 | TPA.Revert(); |
| 5024 | return false; |
| 5025 | } |
| 5026 | |
| 5027 | |
| 5028 | |
| 5029 | SkipCXX11Attributes(); |
| 5030 | |
| 5031 | |
| 5032 | if (Tok.isNot(tok::l_paren)) { |
| 5033 | TPA.Revert(); |
| 5034 | return false; |
| 5035 | } |
| 5036 | ConsumeParen(); |
| 5037 | |
| 5038 | |
| 5039 | |
| 5040 | if (Tok.is(tok::r_paren) || |
| 5041 | (Tok.is(tok::ellipsis) && NextToken().is(tok::r_paren))) { |
| 5042 | TPA.Revert(); |
| 5043 | return true; |
| 5044 | } |
| 5045 | |
| 5046 | |
| 5047 | |
| 5048 | if (getLangOpts().CPlusPlus11 && |
| 5049 | isCXX11AttributeSpecifier( false, |
| 5050 | true)) { |
| 5051 | TPA.Revert(); |
| 5052 | return true; |
| 5053 | } |
| 5054 | |
| 5055 | |
| 5056 | DeclaratorScopeObj DeclScopeObj(*this, SS); |
| 5057 | if (SS.isSet() && Actions.ShouldEnterDeclaratorScope(getCurScope(), SS)) |
| 5058 | DeclScopeObj.EnterDeclaratorScope(); |
| 5059 | |
| 5060 | |
| 5061 | ParsedAttributes Attrs(AttrFactory); |
| 5062 | MaybeParseMicrosoftAttributes(Attrs); |
| 5063 | |
| 5064 | |
| 5065 | |
| 5066 | |
| 5067 | bool IsConstructor = false; |
| 5068 | if (isDeclarationSpecifier()) |
| 5069 | IsConstructor = true; |
| 5070 | else if (Tok.is(tok::identifier) || |
| 5071 | (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier))) { |
| 5072 | |
| 5073 | |
| 5074 | |
| 5075 | |
| 5076 | if (Tok.is(tok::annot_cxxscope)) |
| 5077 | ConsumeAnnotationToken(); |
| 5078 | ConsumeToken(); |
| 5079 | |
| 5080 | |
| 5081 | |
| 5082 | |
| 5083 | switch (Tok.getKind()) { |
| 5084 | case tok::l_paren: |
| 5085 | |
| 5086 | case tok::l_square: |
| 5087 | |
| 5088 | |
| 5089 | case tok::coloncolon: |
| 5090 | |
| 5091 | |
| 5092 | |
| 5093 | |
| 5094 | break; |
| 5095 | |
| 5096 | case tok::r_paren: |
| 5097 | |
| 5098 | |
| 5099 | |
| 5100 | |
| 5101 | ConsumeParen(); |
| 5102 | SkipCXX11Attributes(); |
| 5103 | |
| 5104 | if (DeductionGuide) { |
| 5105 | |
| 5106 | IsConstructor = Tok.is(tok::arrow); |
| 5107 | break; |
| 5108 | } |
| 5109 | if (Tok.is(tok::colon) || Tok.is(tok::kw_try)) { |
| 5110 | |
| 5111 | |
| 5112 | |
| 5113 | IsConstructor = true; |
| 5114 | } |
| 5115 | if (Tok.is(tok::semi) || Tok.is(tok::l_brace)) { |
| 5116 | |
| 5117 | |
| 5118 | |
| 5119 | |
| 5120 | |
| 5121 | |
| 5122 | |
| 5123 | |
| 5124 | |
| 5125 | |
| 5126 | |
| 5127 | |
| 5128 | IsConstructor = IsUnqualified; |
| 5129 | } |
| 5130 | break; |
| 5131 | |
| 5132 | default: |
| 5133 | IsConstructor = true; |
| 5134 | break; |
| 5135 | } |
| 5136 | } |
| 5137 | |
| 5138 | TPA.Revert(); |
| 5139 | return IsConstructor; |
| 5140 | } |
| 5141 | |
| 5142 | |
| 5143 | |
| 5144 | |
| 5145 | |
| 5146 | |
| 5147 | |
| 5148 | |
| 5149 | |
| 5150 | |
| 5151 | |
| 5152 | |
| 5153 | |
| 5154 | void Parser::ParseTypeQualifierListOpt( |
| 5155 | DeclSpec &DS, unsigned AttrReqs, bool AtomicAllowed, |
| 5156 | bool IdentifierRequired, |
| 5157 | Optional<llvm::function_ref<void()>> CodeCompletionHandler) { |
| 5158 | if (standardAttributesAllowed() && (AttrReqs & AR_CXX11AttributesParsed) && |
| 5159 | isCXX11AttributeSpecifier()) { |
| 5160 | ParsedAttributesWithRange attrs(AttrFactory); |
| 5161 | ParseCXX11Attributes(attrs); |
| 5162 | DS.takeAttributesFrom(attrs); |
| 5163 | } |
| 5164 | |
| 5165 | SourceLocation EndLoc; |
| 5166 | |
| 5167 | while (1) { |
| 5168 | bool isInvalid = false; |
| 5169 | const char *PrevSpec = nullptr; |
| 5170 | unsigned DiagID = 0; |
| 5171 | SourceLocation Loc = Tok.getLocation(); |
| 5172 | |
| 5173 | switch (Tok.getKind()) { |
| 5174 | case tok::code_completion: |
| 5175 | if (CodeCompletionHandler) |
| 5176 | (*CodeCompletionHandler)(); |
| 5177 | else |
| 5178 | Actions.CodeCompleteTypeQualifiers(DS); |
| 5179 | return cutOffParsing(); |
| 5180 | |
| 5181 | case tok::kw_const: |
| 5182 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_const , Loc, PrevSpec, DiagID, |
| 5183 | getLangOpts()); |
| 5184 | break; |
| 5185 | case tok::kw_volatile: |
| 5186 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_volatile, Loc, PrevSpec, DiagID, |
| 5187 | getLangOpts()); |
| 5188 | break; |
| 5189 | case tok::kw_restrict: |
| 5190 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_restrict, Loc, PrevSpec, DiagID, |
| 5191 | getLangOpts()); |
| 5192 | break; |
| 5193 | case tok::kw__Atomic: |
| 5194 | if (!AtomicAllowed) |
| 5195 | goto DoneWithTypeQuals; |
| 5196 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_atomic, Loc, PrevSpec, DiagID, |
| 5197 | getLangOpts()); |
| 5198 | break; |
| 5199 | |
| 5200 | |
| 5201 | case tok::kw_private: |
| 5202 | if (!getLangOpts().OpenCL) |
| 5203 | goto DoneWithTypeQuals; |
| 5204 | LLVM_FALLTHROUGH; |
| 5205 | case tok::kw___private: |
| 5206 | case tok::kw___global: |
| 5207 | case tok::kw___local: |
| 5208 | case tok::kw___constant: |
| 5209 | case tok::kw___generic: |
| 5210 | case tok::kw___read_only: |
| 5211 | case tok::kw___write_only: |
| 5212 | case tok::kw___read_write: |
| 5213 | ParseOpenCLQualifiers(DS.getAttributes()); |
| 5214 | break; |
| 5215 | |
| 5216 | case tok::kw___unaligned: |
| 5217 | isInvalid = DS.SetTypeQual(DeclSpec::TQ_unaligned, Loc, PrevSpec, DiagID, |
| 5218 | getLangOpts()); |
| 5219 | break; |
| 5220 | case tok::kw___uptr: |
| 5221 | |
| 5222 | |
| 5223 | if ((AttrReqs & AR_DeclspecAttributesParsed) && !getLangOpts().CPlusPlus && |
| 5224 | IdentifierRequired && DS.isEmpty() && NextToken().is(tok::semi)) { |
| 5225 | if (TryKeywordIdentFallback(false)) |
| 5226 | continue; |
| 5227 | } |
| 5228 | LLVM_FALLTHROUGH; |
| 5229 | case tok::kw___sptr: |
| 5230 | case tok::kw___w64: |
| 5231 | case tok::kw___ptr64: |
| 5232 | case tok::kw___ptr32: |
| 5233 | case tok::kw___cdecl: |
| 5234 | case tok::kw___stdcall: |
| 5235 | case tok::kw___fastcall: |
| 5236 | case tok::kw___thiscall: |
| 5237 | case tok::kw___regcall: |
| 5238 | case tok::kw___vectorcall: |
| 5239 | if (AttrReqs & AR_DeclspecAttributesParsed) { |
| 5240 | ParseMicrosoftTypeAttributes(DS.getAttributes()); |
| 5241 | continue; |
| 5242 | } |
| 5243 | goto DoneWithTypeQuals; |
| 5244 | case tok::kw___pascal: |
| 5245 | if (AttrReqs & AR_VendorAttributesParsed) { |
| 5246 | ParseBorlandTypeAttributes(DS.getAttributes()); |
| 5247 | continue; |
| 5248 | } |
| 5249 | goto DoneWithTypeQuals; |
| 5250 | |
| 5251 | |
| 5252 | case tok::kw__Nonnull: |
| 5253 | case tok::kw__Nullable: |
| 5254 | case tok::kw__Null_unspecified: |
| 5255 | ParseNullabilityTypeSpecifiers(DS.getAttributes()); |
| 5256 | continue; |
| 5257 | |
| 5258 | |
| 5259 | case tok::kw___kindof: |
| 5260 | DS.getAttributes().addNew(Tok.getIdentifierInfo(), Loc, nullptr, Loc, |
| 5261 | nullptr, 0, ParsedAttr::AS_Keyword); |
| 5262 | (void)ConsumeToken(); |
| 5263 | continue; |
| 5264 | |
| 5265 | case tok::kw___attribute: |
| 5266 | if (AttrReqs & AR_GNUAttributesParsedAndRejected) |
| 5267 | |
| 5268 | Diag(Tok, diag::err_attributes_not_allowed); |
| 5269 | |
| 5270 | |
| 5271 | |
| 5272 | if (AttrReqs & AR_GNUAttributesParsed || |
| 5273 | AttrReqs & AR_GNUAttributesParsedAndRejected) { |
| 5274 | ParseGNUAttributes(DS.getAttributes()); |
| 5275 | continue; |
| 5276 | } |
| 5277 | |
| 5278 | LLVM_FALLTHROUGH; |
| 5279 | default: |
| 5280 | DoneWithTypeQuals: |
| 5281 | |
| 5282 | |
| 5283 | DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy()); |
| 5284 | if (EndLoc.isValid()) |
| 5285 | DS.SetRangeEnd(EndLoc); |
| 5286 | return; |
| 5287 | } |
| 5288 | |
| 5289 | |
| 5290 | if (isInvalid) { |
| 5291 | (0) . __assert_fail ("PrevSpec && \"Method did not return previous specifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5291, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(PrevSpec && "Method did not return previous specifier!"); |
| 5292 | Diag(Tok, DiagID) << PrevSpec; |
| 5293 | } |
| 5294 | EndLoc = ConsumeToken(); |
| 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | |
| 5299 | |
| 5300 | void Parser::ParseDeclarator(Declarator &D) { |
| 5301 | |
| 5302 | |
| 5303 | ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator); |
| 5304 | } |
| 5305 | |
| 5306 | static bool isPtrOperatorToken(tok::TokenKind Kind, const LangOptions &Lang, |
| 5307 | DeclaratorContext TheContext) { |
| 5308 | if (Kind == tok::star || Kind == tok::caret) |
| 5309 | return true; |
| 5310 | |
| 5311 | if ((Kind == tok::kw_pipe) && Lang.OpenCL && (Lang.OpenCLVersion >= 200)) |
| 5312 | return true; |
| 5313 | |
| 5314 | if (!Lang.CPlusPlus) |
| 5315 | return false; |
| 5316 | |
| 5317 | if (Kind == tok::amp) |
| 5318 | return true; |
| 5319 | |
| 5320 | |
| 5321 | |
| 5322 | |
| 5323 | |
| 5324 | |
| 5325 | if (Kind == tok::ampamp) |
| 5326 | return Lang.CPlusPlus11 || |
| 5327 | (TheContext != DeclaratorContext::ConversionIdContext && |
| 5328 | TheContext != DeclaratorContext::CXXNewContext); |
| 5329 | |
| 5330 | return false; |
| 5331 | } |
| 5332 | |
| 5333 | |
| 5334 | static bool isPipeDeclerator(const Declarator &D) { |
| 5335 | const unsigned NumTypes = D.getNumTypeObjects(); |
| 5336 | |
| 5337 | for (unsigned Idx = 0; Idx != NumTypes; ++Idx) |
| 5338 | if (DeclaratorChunk::Pipe == D.getTypeObject(Idx).Kind) |
| 5339 | return true; |
| 5340 | |
| 5341 | return false; |
| 5342 | } |
| 5343 | |
| 5344 | |
| 5345 | |
| 5346 | |
| 5347 | |
| 5348 | |
| 5349 | |
| 5350 | |
| 5351 | |
| 5352 | |
| 5353 | |
| 5354 | |
| 5355 | |
| 5356 | |
| 5357 | |
| 5358 | |
| 5359 | |
| 5360 | |
| 5361 | |
| 5362 | |
| 5363 | |
| 5364 | |
| 5365 | |
| 5366 | |
| 5367 | |
| 5368 | |
| 5369 | void Parser::ParseDeclaratorInternal(Declarator &D, |
| 5370 | DirectDeclParseFunction DirectDeclParser) { |
| 5371 | if (Diags.hasAllExtensionsSilenced()) |
| 5372 | D.setExtension(); |
| 5373 | |
| 5374 | |
| 5375 | |
| 5376 | |
| 5377 | if (getLangOpts().CPlusPlus && |
| 5378 | (Tok.is(tok::coloncolon) || Tok.is(tok::kw_decltype) || |
| 5379 | (Tok.is(tok::identifier) && |
| 5380 | (NextToken().is(tok::coloncolon) || NextToken().is(tok::less))) || |
| 5381 | Tok.is(tok::annot_cxxscope))) { |
| 5382 | bool EnteringContext = |
| 5383 | D.getContext() == DeclaratorContext::FileContext || |
| 5384 | D.getContext() == DeclaratorContext::MemberContext; |
| 5385 | CXXScopeSpec SS; |
| 5386 | ParseOptionalCXXScopeSpecifier(SS, nullptr, EnteringContext); |
| 5387 | |
| 5388 | if (SS.isNotEmpty()) { |
| 5389 | if (Tok.isNot(tok::star)) { |
| 5390 | |
| 5391 | if (D.mayHaveIdentifier()) |
| 5392 | D.getCXXScopeSpec() = SS; |
| 5393 | else |
| 5394 | AnnotateScopeToken(SS, true); |
| 5395 | |
| 5396 | if (DirectDeclParser) |
| 5397 | (this->*DirectDeclParser)(D); |
| 5398 | return; |
| 5399 | } |
| 5400 | |
| 5401 | SourceLocation Loc = ConsumeToken(); |
| 5402 | D.SetRangeEnd(Loc); |
| 5403 | DeclSpec DS(AttrFactory); |
| 5404 | ParseTypeQualifierListOpt(DS); |
| 5405 | D.ExtendWithDeclSpec(DS); |
| 5406 | |
| 5407 | |
| 5408 | ParseDeclaratorInternal(D, DirectDeclParser); |
| 5409 | |
| 5410 | |
| 5411 | |
| 5412 | D.AddTypeInfo(DeclaratorChunk::getMemberPointer( |
| 5413 | SS, DS.getTypeQualifiers(), DS.getEndLoc()), |
| 5414 | std::move(DS.getAttributes()), |
| 5415 | SourceLocation()); |
| 5416 | return; |
| 5417 | } |
| 5418 | } |
| 5419 | |
| 5420 | tok::TokenKind Kind = Tok.getKind(); |
| 5421 | |
| 5422 | if (D.getDeclSpec().isTypeSpecPipe() && !isPipeDeclerator(D)) { |
| 5423 | DeclSpec DS(AttrFactory); |
| 5424 | ParseTypeQualifierListOpt(DS); |
| 5425 | |
| 5426 | D.AddTypeInfo( |
| 5427 | DeclaratorChunk::getPipe(DS.getTypeQualifiers(), DS.getPipeLoc()), |
| 5428 | std::move(DS.getAttributes()), SourceLocation()); |
| 5429 | } |
| 5430 | |
| 5431 | |
| 5432 | if (!isPtrOperatorToken(Kind, getLangOpts(), D.getContext())) { |
| 5433 | if (DirectDeclParser) |
| 5434 | (this->*DirectDeclParser)(D); |
| 5435 | return; |
| 5436 | } |
| 5437 | |
| 5438 | |
| 5439 | |
| 5440 | SourceLocation Loc = ConsumeToken(); |
| 5441 | D.SetRangeEnd(Loc); |
| 5442 | |
| 5443 | if (Kind == tok::star || Kind == tok::caret) { |
| 5444 | |
| 5445 | DeclSpec DS(AttrFactory); |
| 5446 | |
| 5447 | |
| 5448 | |
| 5449 | unsigned Reqs = AR_CXX11AttributesParsed | AR_DeclspecAttributesParsed | |
| 5450 | ((D.getContext() != DeclaratorContext::CXXNewContext) |
| 5451 | ? AR_GNUAttributesParsed |
| 5452 | : AR_GNUAttributesParsedAndRejected); |
| 5453 | ParseTypeQualifierListOpt(DS, Reqs, true, !D.mayOmitIdentifier()); |
| 5454 | D.ExtendWithDeclSpec(DS); |
| 5455 | |
| 5456 | |
| 5457 | ParseDeclaratorInternal(D, DirectDeclParser); |
| 5458 | if (Kind == tok::star) |
| 5459 | |
| 5460 | D.AddTypeInfo(DeclaratorChunk::getPointer( |
| 5461 | DS.getTypeQualifiers(), Loc, DS.getConstSpecLoc(), |
| 5462 | DS.getVolatileSpecLoc(), DS.getRestrictSpecLoc(), |
| 5463 | DS.getAtomicSpecLoc(), DS.getUnalignedSpecLoc()), |
| 5464 | std::move(DS.getAttributes()), SourceLocation()); |
| 5465 | else |
| 5466 | |
| 5467 | D.AddTypeInfo( |
| 5468 | DeclaratorChunk::getBlockPointer(DS.getTypeQualifiers(), Loc), |
| 5469 | std::move(DS.getAttributes()), SourceLocation()); |
| 5470 | } else { |
| 5471 | |
| 5472 | DeclSpec DS(AttrFactory); |
| 5473 | |
| 5474 | |
| 5475 | |
| 5476 | if (Kind == tok::ampamp) |
| 5477 | Diag(Loc, getLangOpts().CPlusPlus11 ? |
| 5478 | diag::warn_cxx98_compat_rvalue_reference : |
| 5479 | diag::ext_rvalue_reference); |
| 5480 | |
| 5481 | |
| 5482 | ParseTypeQualifierListOpt(DS); |
| 5483 | D.ExtendWithDeclSpec(DS); |
| 5484 | |
| 5485 | |
| 5486 | |
| 5487 | |
| 5488 | if (DS.getTypeQualifiers() != DeclSpec::TQ_unspecified) { |
| 5489 | if (DS.getTypeQualifiers() & DeclSpec::TQ_const) |
| 5490 | Diag(DS.getConstSpecLoc(), |
| 5491 | diag::err_invalid_reference_qualifier_application) << "const"; |
| 5492 | if (DS.getTypeQualifiers() & DeclSpec::TQ_volatile) |
| 5493 | Diag(DS.getVolatileSpecLoc(), |
| 5494 | diag::err_invalid_reference_qualifier_application) << "volatile"; |
| 5495 | |
| 5496 | if (DS.getTypeQualifiers() & DeclSpec::TQ_atomic) |
| 5497 | Diag(DS.getAtomicSpecLoc(), |
| 5498 | diag::err_invalid_reference_qualifier_application) << "_Atomic"; |
| 5499 | } |
| 5500 | |
| 5501 | |
| 5502 | ParseDeclaratorInternal(D, DirectDeclParser); |
| 5503 | |
| 5504 | if (D.getNumTypeObjects() > 0) { |
| 5505 | |
| 5506 | DeclaratorChunk& InnerChunk = D.getTypeObject(D.getNumTypeObjects() - 1); |
| 5507 | if (InnerChunk.Kind == DeclaratorChunk::Reference) { |
| 5508 | if (const IdentifierInfo *II = D.getIdentifier()) |
| 5509 | Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference) |
| 5510 | << II; |
| 5511 | else |
| 5512 | Diag(InnerChunk.Loc, diag::err_illegal_decl_reference_to_reference) |
| 5513 | << "type name"; |
| 5514 | |
| 5515 | |
| 5516 | |
| 5517 | |
| 5518 | } |
| 5519 | } |
| 5520 | |
| 5521 | |
| 5522 | D.AddTypeInfo(DeclaratorChunk::getReference(DS.getTypeQualifiers(), Loc, |
| 5523 | Kind == tok::amp), |
| 5524 | std::move(DS.getAttributes()), SourceLocation()); |
| 5525 | } |
| 5526 | } |
| 5527 | |
| 5528 | |
| 5529 | |
| 5530 | |
| 5531 | |
| 5532 | static SourceLocation getMissingDeclaratorIdLoc(Declarator &D, |
| 5533 | SourceLocation Loc) { |
| 5534 | if (D.getName().StartLocation.isInvalid() && |
| 5535 | D.getName().EndLocation.isValid()) |
| 5536 | return D.getName().EndLocation; |
| 5537 | |
| 5538 | return Loc; |
| 5539 | } |
| 5540 | |
| 5541 | |
| 5542 | |
| 5543 | |
| 5544 | |
| 5545 | |
| 5546 | |
| 5547 | |
| 5548 | |
| 5549 | |
| 5550 | |
| 5551 | |
| 5552 | |
| 5553 | |
| 5554 | |
| 5555 | |
| 5556 | |
| 5557 | |
| 5558 | |
| 5559 | |
| 5560 | |
| 5561 | |
| 5562 | |
| 5563 | |
| 5564 | |
| 5565 | |
| 5566 | |
| 5567 | |
| 5568 | |
| 5569 | |
| 5570 | |
| 5571 | |
| 5572 | |
| 5573 | |
| 5574 | |
| 5575 | |
| 5576 | |
| 5577 | |
| 5578 | |
| 5579 | |
| 5580 | |
| 5581 | |
| 5582 | |
| 5583 | |
| 5584 | |
| 5585 | |
| 5586 | |
| 5587 | void Parser::ParseDirectDeclarator(Declarator &D) { |
| 5588 | DeclaratorScopeObj DeclScopeObj(*this, D.getCXXScopeSpec()); |
| 5589 | |
| 5590 | if (getLangOpts().CPlusPlus && D.mayHaveIdentifier()) { |
| 5591 | |
| 5592 | if (Tok.is(tok::l_square) && !D.mayOmitIdentifier() && |
| 5593 | D.getCXXScopeSpec().isEmpty()) |
| 5594 | return ParseDecompositionDeclarator(D); |
| 5595 | |
| 5596 | |
| 5597 | |
| 5598 | |
| 5599 | ColonProtectionRAIIObject X( |
| 5600 | *this, D.getContext() == DeclaratorContext::MemberContext || |
| 5601 | (D.getContext() == DeclaratorContext::ForContext && |
| 5602 | getLangOpts().CPlusPlus11)); |
| 5603 | |
| 5604 | |
| 5605 | if (D.getCXXScopeSpec().isEmpty()) { |
| 5606 | bool EnteringContext = |
| 5607 | D.getContext() == DeclaratorContext::FileContext || |
| 5608 | D.getContext() == DeclaratorContext::MemberContext; |
| 5609 | ParseOptionalCXXScopeSpecifier(D.getCXXScopeSpec(), nullptr, |
| 5610 | EnteringContext); |
| 5611 | } |
| 5612 | |
| 5613 | if (D.getCXXScopeSpec().isValid()) { |
| 5614 | if (Actions.ShouldEnterDeclaratorScope(getCurScope(), |
| 5615 | D.getCXXScopeSpec())) |
| 5616 | |
| 5617 | |
| 5618 | DeclScopeObj.EnterDeclaratorScope(); |
| 5619 | else if (getObjCDeclContext()) { |
| 5620 | |
| 5621 | |
| 5622 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5623 | D.setInvalidType(true); |
| 5624 | ConsumeToken(); |
| 5625 | goto PastIdentifier; |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | |
| 5630 | |
| 5631 | |
| 5632 | |
| 5633 | |
| 5634 | |
| 5635 | |
| 5636 | if (Tok.is(tok::ellipsis) && D.getCXXScopeSpec().isEmpty() && |
| 5637 | !((D.getContext() == DeclaratorContext::PrototypeContext || |
| 5638 | D.getContext() == DeclaratorContext::LambdaExprParameterContext || |
| 5639 | D.getContext() == DeclaratorContext::BlockLiteralContext) && |
| 5640 | NextToken().is(tok::r_paren) && |
| 5641 | !D.hasGroupingParens() && |
| 5642 | !Actions.containsUnexpandedParameterPacks(D) && |
| 5643 | D.getDeclSpec().getTypeSpecType() != TST_auto)) { |
| 5644 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 5645 | if (isPtrOperatorToken(Tok.getKind(), getLangOpts(), D.getContext())) { |
| 5646 | |
| 5647 | |
| 5648 | ParseDeclarator(D); |
| 5649 | if (EllipsisLoc.isValid()) |
| 5650 | DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D); |
| 5651 | return; |
| 5652 | } else |
| 5653 | D.setEllipsisLoc(EllipsisLoc); |
| 5654 | |
| 5655 | |
| 5656 | |
| 5657 | |
| 5658 | } |
| 5659 | |
| 5660 | if (Tok.isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id, |
| 5661 | tok::tilde)) { |
| 5662 | |
| 5663 | |
| 5664 | bool AllowConstructorName; |
| 5665 | bool AllowDeductionGuide; |
| 5666 | if (D.getDeclSpec().hasTypeSpecifier()) { |
| 5667 | AllowConstructorName = false; |
| 5668 | AllowDeductionGuide = false; |
| 5669 | } else if (D.getCXXScopeSpec().isSet()) { |
| 5670 | AllowConstructorName = |
| 5671 | (D.getContext() == DeclaratorContext::FileContext || |
| 5672 | D.getContext() == DeclaratorContext::MemberContext); |
| 5673 | AllowDeductionGuide = false; |
| 5674 | } else { |
| 5675 | AllowConstructorName = |
| 5676 | (D.getContext() == DeclaratorContext::MemberContext); |
| 5677 | AllowDeductionGuide = |
| 5678 | (D.getContext() == DeclaratorContext::FileContext || |
| 5679 | D.getContext() == DeclaratorContext::MemberContext); |
| 5680 | } |
| 5681 | |
| 5682 | bool HadScope = D.getCXXScopeSpec().isValid(); |
| 5683 | if (ParseUnqualifiedId(D.getCXXScopeSpec(), |
| 5684 | , |
| 5685 | , AllowConstructorName, |
| 5686 | AllowDeductionGuide, nullptr, nullptr, |
| 5687 | D.getName()) || |
| 5688 | |
| 5689 | |
| 5690 | D.getCXXScopeSpec().isInvalid()) { |
| 5691 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5692 | D.setInvalidType(true); |
| 5693 | } else { |
| 5694 | |
| 5695 | |
| 5696 | if (!HadScope && D.getCXXScopeSpec().isValid() && |
| 5697 | Actions.ShouldEnterDeclaratorScope(getCurScope(), |
| 5698 | D.getCXXScopeSpec())) |
| 5699 | DeclScopeObj.EnterDeclaratorScope(); |
| 5700 | |
| 5701 | |
| 5702 | if (D.getSourceRange().getBegin().isInvalid()) |
| 5703 | D.SetRangeBegin(D.getName().getSourceRange().getBegin()); |
| 5704 | D.SetRangeEnd(D.getName().getSourceRange().getEnd()); |
| 5705 | } |
| 5706 | goto PastIdentifier; |
| 5707 | } |
| 5708 | |
| 5709 | if (D.getCXXScopeSpec().isNotEmpty()) { |
| 5710 | |
| 5711 | Diag(PP.getLocForEndOfToken(D.getCXXScopeSpec().getEndLoc()), |
| 5712 | diag::err_expected_unqualified_id) |
| 5713 | << ; |
| 5714 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5715 | goto PastIdentifier; |
| 5716 | } |
| 5717 | } else if (Tok.is(tok::identifier) && D.mayHaveIdentifier()) { |
| 5718 | (0) . __assert_fail ("!getLangOpts().CPlusPlus && \"There's a C++-specific check for tok..identifier above\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5719, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!getLangOpts().CPlusPlus && |
| 5719 | (0) . __assert_fail ("!getLangOpts().CPlusPlus && \"There's a C++-specific check for tok..identifier above\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5719, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "There's a C++-specific check for tok::identifier above"); |
| 5720 | (0) . __assert_fail ("Tok.getIdentifierInfo() && \"Not an identifier?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5720, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.getIdentifierInfo() && "Not an identifier?"); |
| 5721 | D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 5722 | D.SetRangeEnd(Tok.getLocation()); |
| 5723 | ConsumeToken(); |
| 5724 | goto PastIdentifier; |
| 5725 | } else if (Tok.is(tok::identifier) && !D.mayHaveIdentifier()) { |
| 5726 | |
| 5727 | |
| 5728 | |
| 5729 | bool DiagnoseIdentifier = false; |
| 5730 | if (D.hasGroupingParens()) |
| 5731 | |
| 5732 | |
| 5733 | DiagnoseIdentifier = true; |
| 5734 | else if (D.getContext() == DeclaratorContext::TemplateArgContext) |
| 5735 | |
| 5736 | DiagnoseIdentifier = |
| 5737 | NextToken().isOneOf(tok::comma, tok::greater, tok::greatergreater); |
| 5738 | else if (D.getContext() == DeclaratorContext::AliasDeclContext || |
| 5739 | D.getContext() == DeclaratorContext::AliasTemplateContext) |
| 5740 | |
| 5741 | DiagnoseIdentifier = NextToken().isOneOf(tok::comma, tok::semi); |
| 5742 | else if ((D.getContext() == DeclaratorContext::TrailingReturnContext || |
| 5743 | D.getContext() == DeclaratorContext::TrailingReturnVarContext) && |
| 5744 | !isCXX11VirtSpecifier(Tok)) |
| 5745 | DiagnoseIdentifier = NextToken().isOneOf( |
| 5746 | tok::comma, tok::semi, tok::equal, tok::l_brace, tok::kw_try); |
| 5747 | if (DiagnoseIdentifier) { |
| 5748 | Diag(Tok.getLocation(), diag::err_unexpected_unqualified_id) |
| 5749 | << FixItHint::CreateRemoval(Tok.getLocation()); |
| 5750 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5751 | ConsumeToken(); |
| 5752 | goto PastIdentifier; |
| 5753 | } |
| 5754 | } |
| 5755 | |
| 5756 | if (Tok.is(tok::l_paren)) { |
| 5757 | |
| 5758 | |
| 5759 | |
| 5760 | if (D.mayOmitIdentifier() && D.mayBeFollowedByCXXDirectInit()) { |
| 5761 | RevertingTentativeParsingAction PA(*this); |
| 5762 | if (TryParseDeclarator(true, D.mayHaveIdentifier(), true) == |
| 5763 | TPResult::False) { |
| 5764 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5765 | goto PastIdentifier; |
| 5766 | } |
| 5767 | } |
| 5768 | |
| 5769 | |
| 5770 | |
| 5771 | |
| 5772 | ParseParenDeclarator(D); |
| 5773 | |
| 5774 | |
| 5775 | |
| 5776 | |
| 5777 | if (D.getCXXScopeSpec().isSet()) { |
| 5778 | |
| 5779 | |
| 5780 | if (!D.isInvalidType() && |
| 5781 | Actions.ShouldEnterDeclaratorScope(getCurScope(), |
| 5782 | D.getCXXScopeSpec())) |
| 5783 | |
| 5784 | |
| 5785 | DeclScopeObj.EnterDeclaratorScope(); |
| 5786 | } |
| 5787 | } else if (D.mayOmitIdentifier()) { |
| 5788 | |
| 5789 | |
| 5790 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5791 | |
| 5792 | |
| 5793 | |
| 5794 | if (D.hasEllipsis() && D.hasGroupingParens()) |
| 5795 | Diag(PP.getLocForEndOfToken(D.getEllipsisLoc()), |
| 5796 | diag::ext_abstract_pack_declarator_parens); |
| 5797 | } else { |
| 5798 | if (Tok.getKind() == tok::annot_pragma_parser_crash) |
| 5799 | LLVM_BUILTIN_TRAP; |
| 5800 | if (Tok.is(tok::l_square)) |
| 5801 | return ParseMisplacedBracketDeclarator(D); |
| 5802 | if (D.getContext() == DeclaratorContext::MemberContext) { |
| 5803 | |
| 5804 | |
| 5805 | if (getLangOpts().ObjC && getLangOpts().CPlusPlus && |
| 5806 | Tok.getIdentifierInfo() && |
| 5807 | Tok.getIdentifierInfo()->isCPlusPlusKeyword(getLangOpts())) { |
| 5808 | Diag(getMissingDeclaratorIdLoc(D, Tok.getLocation()), |
| 5809 | diag::err_expected_member_name_or_semi_objcxx_keyword) |
| 5810 | << Tok.getIdentifierInfo() |
| 5811 | << (D.getDeclSpec().isEmpty() ? SourceRange() |
| 5812 | : D.getDeclSpec().getSourceRange()); |
| 5813 | D.SetIdentifier(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 5814 | D.SetRangeEnd(Tok.getLocation()); |
| 5815 | ConsumeToken(); |
| 5816 | goto PastIdentifier; |
| 5817 | } |
| 5818 | Diag(getMissingDeclaratorIdLoc(D, Tok.getLocation()), |
| 5819 | diag::err_expected_member_name_or_semi) |
| 5820 | << (D.getDeclSpec().isEmpty() ? SourceRange() |
| 5821 | : D.getDeclSpec().getSourceRange()); |
| 5822 | } else if (getLangOpts().CPlusPlus) { |
| 5823 | if (Tok.isOneOf(tok::period, tok::arrow)) |
| 5824 | Diag(Tok, diag::err_invalid_operator_on_type) << Tok.is(tok::arrow); |
| 5825 | else { |
| 5826 | SourceLocation Loc = D.getCXXScopeSpec().getEndLoc(); |
| 5827 | if (Tok.isAtStartOfLine() && Loc.isValid()) |
| 5828 | Diag(PP.getLocForEndOfToken(Loc), diag::err_expected_unqualified_id) |
| 5829 | << getLangOpts().CPlusPlus; |
| 5830 | else |
| 5831 | Diag(getMissingDeclaratorIdLoc(D, Tok.getLocation()), |
| 5832 | diag::err_expected_unqualified_id) |
| 5833 | << getLangOpts().CPlusPlus; |
| 5834 | } |
| 5835 | } else { |
| 5836 | Diag(getMissingDeclaratorIdLoc(D, Tok.getLocation()), |
| 5837 | diag::err_expected_either) |
| 5838 | << tok::identifier << tok::l_paren; |
| 5839 | } |
| 5840 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 5841 | D.setInvalidType(true); |
| 5842 | } |
| 5843 | |
| 5844 | PastIdentifier: |
| 5845 | (0) . __assert_fail ("D.isPastIdentifier() && \"Haven't past the location of the identifier yet?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5846, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D.isPastIdentifier() && |
| 5846 | (0) . __assert_fail ("D.isPastIdentifier() && \"Haven't past the location of the identifier yet?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5846, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Haven't past the location of the identifier yet?"); |
| 5847 | |
| 5848 | |
| 5849 | if (D.hasName() && !D.getNumTypeObjects()) |
| 5850 | MaybeParseCXX11Attributes(D); |
| 5851 | |
| 5852 | while (1) { |
| 5853 | if (Tok.is(tok::l_paren)) { |
| 5854 | |
| 5855 | |
| 5856 | ParseScope PrototypeScope(this, |
| 5857 | Scope::FunctionPrototypeScope|Scope::DeclScope| |
| 5858 | (D.isFunctionDeclaratorAFunctionDeclaration() |
| 5859 | ? Scope::FunctionDeclarationScope : 0)); |
| 5860 | |
| 5861 | |
| 5862 | |
| 5863 | |
| 5864 | bool IsAmbiguous = false; |
| 5865 | if (getLangOpts().CPlusPlus && D.mayBeFollowedByCXXDirectInit()) { |
| 5866 | |
| 5867 | |
| 5868 | TentativelyDeclaredIdentifiers.push_back(D.getIdentifier()); |
| 5869 | bool IsFunctionDecl = isCXXFunctionDeclarator(&IsAmbiguous); |
| 5870 | TentativelyDeclaredIdentifiers.pop_back(); |
| 5871 | if (!IsFunctionDecl) |
| 5872 | break; |
| 5873 | } |
| 5874 | ParsedAttributes attrs(AttrFactory); |
| 5875 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 5876 | T.consumeOpen(); |
| 5877 | ParseFunctionDeclarator(D, attrs, T, IsAmbiguous); |
| 5878 | PrototypeScope.Exit(); |
| 5879 | } else if (Tok.is(tok::l_square)) { |
| 5880 | ParseBracketDeclarator(D); |
| 5881 | } else { |
| 5882 | break; |
| 5883 | } |
| 5884 | } |
| 5885 | } |
| 5886 | |
| 5887 | void Parser::ParseDecompositionDeclarator(Declarator &D) { |
| 5888 | assert(Tok.is(tok::l_square)); |
| 5889 | |
| 5890 | |
| 5891 | |
| 5892 | |
| 5893 | |
| 5894 | if (!(NextToken().is(tok::identifier) && |
| 5895 | GetLookAheadToken(2).isOneOf(tok::comma, tok::r_square)) && |
| 5896 | !(NextToken().is(tok::r_square) && |
| 5897 | GetLookAheadToken(2).isOneOf(tok::equal, tok::l_brace))) |
| 5898 | return ParseMisplacedBracketDeclarator(D); |
| 5899 | |
| 5900 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 5901 | T.consumeOpen(); |
| 5902 | |
| 5903 | SmallVector<DecompositionDeclarator::Binding, 32> Bindings; |
| 5904 | while (Tok.isNot(tok::r_square)) { |
| 5905 | if (!Bindings.empty()) { |
| 5906 | if (Tok.is(tok::comma)) |
| 5907 | ConsumeToken(); |
| 5908 | else { |
| 5909 | if (Tok.is(tok::identifier)) { |
| 5910 | SourceLocation EndLoc = getEndOfPreviousToken(); |
| 5911 | Diag(EndLoc, diag::err_expected) |
| 5912 | << tok::comma << FixItHint::CreateInsertion(EndLoc, ","); |
| 5913 | } else { |
| 5914 | Diag(Tok, diag::err_expected_comma_or_rsquare); |
| 5915 | } |
| 5916 | |
| 5917 | SkipUntil(tok::r_square, tok::comma, tok::identifier, |
| 5918 | StopAtSemi | StopBeforeMatch); |
| 5919 | if (Tok.is(tok::comma)) |
| 5920 | ConsumeToken(); |
| 5921 | else if (Tok.isNot(tok::identifier)) |
| 5922 | break; |
| 5923 | } |
| 5924 | } |
| 5925 | |
| 5926 | if (Tok.isNot(tok::identifier)) { |
| 5927 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 5928 | break; |
| 5929 | } |
| 5930 | |
| 5931 | Bindings.push_back({Tok.getIdentifierInfo(), Tok.getLocation()}); |
| 5932 | ConsumeToken(); |
| 5933 | } |
| 5934 | |
| 5935 | if (Tok.isNot(tok::r_square)) |
| 5936 | |
| 5937 | T.skipToEnd(); |
| 5938 | else { |
| 5939 | |
| 5940 | |
| 5941 | if (Bindings.empty()) |
| 5942 | Diag(Tok.getLocation(), diag::ext_decomp_decl_empty); |
| 5943 | |
| 5944 | T.consumeClose(); |
| 5945 | } |
| 5946 | |
| 5947 | return D.setDecompositionBindings(T.getOpenLocation(), Bindings, |
| 5948 | T.getCloseLocation()); |
| 5949 | } |
| 5950 | |
| 5951 | |
| 5952 | |
| 5953 | |
| 5954 | |
| 5955 | |
| 5956 | |
| 5957 | |
| 5958 | |
| 5959 | |
| 5960 | |
| 5961 | |
| 5962 | |
| 5963 | |
| 5964 | void Parser::ParseParenDeclarator(Declarator &D) { |
| 5965 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 5966 | T.consumeOpen(); |
| 5967 | |
| 5968 | (0) . __assert_fail ("!D.isPastIdentifier() && \"Should be called before passing identifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 5968, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!D.isPastIdentifier() && "Should be called before passing identifier"); |
| 5969 | |
| 5970 | |
| 5971 | |
| 5972 | |
| 5973 | |
| 5974 | |
| 5975 | |
| 5976 | |
| 5977 | |
| 5978 | |
| 5979 | |
| 5980 | ParsedAttributes attrs(AttrFactory); |
| 5981 | bool RequiresArg = false; |
| 5982 | if (Tok.is(tok::kw___attribute)) { |
| 5983 | ParseGNUAttributes(attrs); |
| 5984 | |
| 5985 | |
| 5986 | |
| 5987 | RequiresArg = true; |
| 5988 | } |
| 5989 | |
| 5990 | |
| 5991 | ParseMicrosoftTypeAttributes(attrs); |
| 5992 | |
| 5993 | |
| 5994 | if (Tok.is(tok::kw___pascal)) |
| 5995 | ParseBorlandTypeAttributes(attrs); |
| 5996 | |
| 5997 | |
| 5998 | |
| 5999 | |
| 6000 | |
| 6001 | bool isGrouping; |
| 6002 | |
| 6003 | if (!D.mayOmitIdentifier()) { |
| 6004 | |
| 6005 | |
| 6006 | isGrouping = true; |
| 6007 | } else if (Tok.is(tok::r_paren) || |
| 6008 | (getLangOpts().CPlusPlus && Tok.is(tok::ellipsis) && |
| 6009 | NextToken().is(tok::r_paren)) || |
| 6010 | isDeclarationSpecifier() || |
| 6011 | isCXX11AttributeSpecifier()) { |
| 6012 | |
| 6013 | |
| 6014 | isGrouping = false; |
| 6015 | } else { |
| 6016 | |
| 6017 | isGrouping = true; |
| 6018 | } |
| 6019 | |
| 6020 | |
| 6021 | |
| 6022 | |
| 6023 | if (isGrouping) { |
| 6024 | SourceLocation EllipsisLoc = D.getEllipsisLoc(); |
| 6025 | D.setEllipsisLoc(SourceLocation()); |
| 6026 | |
| 6027 | bool hadGroupingParens = D.hasGroupingParens(); |
| 6028 | D.setGroupingParens(true); |
| 6029 | ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator); |
| 6030 | |
| 6031 | T.consumeClose(); |
| 6032 | D.AddTypeInfo( |
| 6033 | DeclaratorChunk::getParen(T.getOpenLocation(), T.getCloseLocation()), |
| 6034 | std::move(attrs), T.getCloseLocation()); |
| 6035 | |
| 6036 | D.setGroupingParens(hadGroupingParens); |
| 6037 | |
| 6038 | |
| 6039 | if (EllipsisLoc.isValid()) |
| 6040 | DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, D); |
| 6041 | |
| 6042 | return; |
| 6043 | } |
| 6044 | |
| 6045 | |
| 6046 | |
| 6047 | |
| 6048 | |
| 6049 | D.SetIdentifier(nullptr, Tok.getLocation()); |
| 6050 | |
| 6051 | |
| 6052 | |
| 6053 | ParseScope PrototypeScope(this, |
| 6054 | Scope::FunctionPrototypeScope | Scope::DeclScope | |
| 6055 | (D.isFunctionDeclaratorAFunctionDeclaration() |
| 6056 | ? Scope::FunctionDeclarationScope : 0)); |
| 6057 | ParseFunctionDeclarator(D, attrs, T, false, RequiresArg); |
| 6058 | PrototypeScope.Exit(); |
| 6059 | } |
| 6060 | |
| 6061 | |
| 6062 | |
| 6063 | |
| 6064 | |
| 6065 | |
| 6066 | |
| 6067 | |
| 6068 | |
| 6069 | |
| 6070 | |
| 6071 | |
| 6072 | |
| 6073 | |
| 6074 | |
| 6075 | |
| 6076 | |
| 6077 | |
| 6078 | |
| 6079 | |
| 6080 | void Parser::ParseFunctionDeclarator(Declarator &D, |
| 6081 | ParsedAttributes &FirstArgAttrs, |
| 6082 | BalancedDelimiterTracker &Tracker, |
| 6083 | bool IsAmbiguous, |
| 6084 | bool RequiresArg) { |
| 6085 | (0) . __assert_fail ("getCurScope()->isFunctionPrototypeScope() && \"Should call from a Function scope\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6086, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(getCurScope()->isFunctionPrototypeScope() && |
| 6086 | (0) . __assert_fail ("getCurScope()->isFunctionPrototypeScope() && \"Should call from a Function scope\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6086, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Should call from a Function scope"); |
| 6087 | |
| 6088 | (0) . __assert_fail ("D.isPastIdentifier() && \"Should not call before identifier!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6088, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(D.isPastIdentifier() && "Should not call before identifier!"); |
| 6089 | |
| 6090 | |
| 6091 | |
| 6092 | bool HasProto = false; |
| 6093 | |
| 6094 | SmallVector<DeclaratorChunk::ParamInfo, 16> ParamInfo; |
| 6095 | |
| 6096 | SourceLocation EllipsisLoc; |
| 6097 | |
| 6098 | DeclSpec DS(AttrFactory); |
| 6099 | bool RefQualifierIsLValueRef = true; |
| 6100 | SourceLocation RefQualifierLoc; |
| 6101 | ExceptionSpecificationType ESpecType = EST_None; |
| 6102 | SourceRange ESpecRange; |
| 6103 | SmallVector<ParsedType, 2> DynamicExceptions; |
| 6104 | SmallVector<SourceRange, 2> DynamicExceptionRanges; |
| 6105 | ExprResult NoexceptExpr; |
| 6106 | CachedTokens *ExceptionSpecTokens = nullptr; |
| 6107 | ParsedAttributesWithRange FnAttrs(AttrFactory); |
| 6108 | TypeResult TrailingReturnType; |
| 6109 | |
| 6110 | |
| 6111 | |
| 6112 | |
| 6113 | SourceLocation StartLoc, LocalEndLoc, EndLoc; |
| 6114 | SourceLocation LParenLoc, RParenLoc; |
| 6115 | LParenLoc = Tracker.getOpenLocation(); |
| 6116 | StartLoc = LParenLoc; |
| 6117 | |
| 6118 | if (isFunctionDeclaratorIdentifierList()) { |
| 6119 | if (RequiresArg) |
| 6120 | Diag(Tok, diag::err_argument_required_after_attribute); |
| 6121 | |
| 6122 | ParseFunctionDeclaratorIdentifierList(D, ParamInfo); |
| 6123 | |
| 6124 | Tracker.consumeClose(); |
| 6125 | RParenLoc = Tracker.getCloseLocation(); |
| 6126 | LocalEndLoc = RParenLoc; |
| 6127 | EndLoc = RParenLoc; |
| 6128 | |
| 6129 | |
| 6130 | |
| 6131 | MaybeParseCXX11Attributes(FnAttrs); |
| 6132 | ProhibitAttributes(FnAttrs); |
| 6133 | } else { |
| 6134 | if (Tok.isNot(tok::r_paren)) |
| 6135 | ParseParameterDeclarationClause(D, FirstArgAttrs, ParamInfo, |
| 6136 | EllipsisLoc); |
| 6137 | else if (RequiresArg) |
| 6138 | Diag(Tok, diag::err_argument_required_after_attribute); |
| 6139 | |
| 6140 | HasProto = ParamInfo.size() || getLangOpts().CPlusPlus |
| 6141 | || getLangOpts().OpenCL; |
| 6142 | |
| 6143 | |
| 6144 | Tracker.consumeClose(); |
| 6145 | RParenLoc = Tracker.getCloseLocation(); |
| 6146 | LocalEndLoc = RParenLoc; |
| 6147 | EndLoc = RParenLoc; |
| 6148 | |
| 6149 | if (getLangOpts().CPlusPlus) { |
| 6150 | |
| 6151 | |
| 6152 | |
| 6153 | |
| 6154 | |
| 6155 | ParseTypeQualifierListOpt(DS, AR_NoAttributesParsed, |
| 6156 | false, |
| 6157 | , |
| 6158 | llvm::function_ref<void()>([&]() { |
| 6159 | Actions.CodeCompleteFunctionQualifiers(DS, D); |
| 6160 | })); |
| 6161 | if (!DS.getSourceRange().getEnd().isInvalid()) { |
| 6162 | EndLoc = DS.getSourceRange().getEnd(); |
| 6163 | } |
| 6164 | |
| 6165 | |
| 6166 | if (ParseRefQualifier(RefQualifierIsLValueRef, RefQualifierLoc)) |
| 6167 | EndLoc = RefQualifierLoc; |
| 6168 | |
| 6169 | |
| 6170 | |
| 6171 | |
| 6172 | |
| 6173 | |
| 6174 | |
| 6175 | |
| 6176 | bool IsCXX11MemberFunction = |
| 6177 | getLangOpts().CPlusPlus11 && |
| 6178 | D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef && |
| 6179 | (D.getContext() == DeclaratorContext::MemberContext |
| 6180 | ? !D.getDeclSpec().isFriendSpecified() |
| 6181 | : D.getContext() == DeclaratorContext::FileContext && |
| 6182 | D.getCXXScopeSpec().isValid() && |
| 6183 | Actions.CurContext->isRecord()); |
| 6184 | |
| 6185 | Qualifiers Q = Qualifiers::fromCVRUMask(DS.getTypeQualifiers()); |
| 6186 | if (D.getDeclSpec().isConstexprSpecified() && !getLangOpts().CPlusPlus14) |
| 6187 | Q.addConst(); |
| 6188 | |
| 6189 | |
| 6190 | |
| 6191 | |
| 6192 | |
| 6193 | if (getLangOpts().OpenCLCPlusPlus) { |
| 6194 | for (ParsedAttr &attr : DS.getAttributes()) { |
| 6195 | LangAS ASIdx = attr.asOpenCLLangAS(); |
| 6196 | if (ASIdx != LangAS::Default) { |
| 6197 | Q.addAddressSpace(ASIdx); |
| 6198 | break; |
| 6199 | } |
| 6200 | } |
| 6201 | } |
| 6202 | |
| 6203 | Sema::CXXThisScopeRAII ThisScope( |
| 6204 | Actions, dyn_cast<CXXRecordDecl>(Actions.CurContext), Q, |
| 6205 | IsCXX11MemberFunction); |
| 6206 | |
| 6207 | |
| 6208 | bool Delayed = D.isFirstDeclarationOfMember() && |
| 6209 | D.isFunctionDeclaratorAFunctionDeclaration(); |
| 6210 | if (Delayed && Actions.isLibstdcxxEagerExceptionSpecHack(D) && |
| 6211 | GetLookAheadToken(0).is(tok::kw_noexcept) && |
| 6212 | GetLookAheadToken(1).is(tok::l_paren) && |
| 6213 | GetLookAheadToken(2).is(tok::kw_noexcept) && |
| 6214 | GetLookAheadToken(3).is(tok::l_paren) && |
| 6215 | GetLookAheadToken(4).is(tok::identifier) && |
| 6216 | GetLookAheadToken(4).getIdentifierInfo()->isStr("swap")) { |
| 6217 | |
| 6218 | |
| 6219 | |
| 6220 | |
| 6221 | |
| 6222 | |
| 6223 | |
| 6224 | |
| 6225 | Delayed = false; |
| 6226 | } |
| 6227 | ESpecType = tryParseExceptionSpecification(Delayed, |
| 6228 | ESpecRange, |
| 6229 | DynamicExceptions, |
| 6230 | DynamicExceptionRanges, |
| 6231 | NoexceptExpr, |
| 6232 | ExceptionSpecTokens); |
| 6233 | if (ESpecType != EST_None) |
| 6234 | EndLoc = ESpecRange.getEnd(); |
| 6235 | |
| 6236 | |
| 6237 | |
| 6238 | MaybeParseCXX11Attributes(FnAttrs); |
| 6239 | |
| 6240 | |
| 6241 | LocalEndLoc = EndLoc; |
| 6242 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::arrow)) { |
| 6243 | Diag(Tok, diag::warn_cxx98_compat_trailing_return_type); |
| 6244 | if (D.getDeclSpec().getTypeSpecType() == TST_auto) |
| 6245 | StartLoc = D.getDeclSpec().getTypeSpecTypeLoc(); |
| 6246 | LocalEndLoc = Tok.getLocation(); |
| 6247 | SourceRange Range; |
| 6248 | TrailingReturnType = |
| 6249 | ParseTrailingReturnType(Range, D.mayBeFollowedByCXXDirectInit()); |
| 6250 | EndLoc = Range.getEnd(); |
| 6251 | } |
| 6252 | } else if (standardAttributesAllowed()) { |
| 6253 | MaybeParseCXX11Attributes(FnAttrs); |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | |
| 6258 | |
| 6259 | |
| 6260 | |
| 6261 | SmallVector<NamedDecl *, 0> DeclsInPrototype; |
| 6262 | if (getCurScope()->getFlags() & Scope::FunctionDeclarationScope && |
| 6263 | !getLangOpts().CPlusPlus) { |
| 6264 | for (Decl *D : getCurScope()->decls()) { |
| 6265 | NamedDecl *ND = dyn_cast<NamedDecl>(D); |
| 6266 | if (!ND || isa<ParmVarDecl>(ND)) |
| 6267 | continue; |
| 6268 | DeclsInPrototype.push_back(ND); |
| 6269 | } |
| 6270 | } |
| 6271 | |
| 6272 | |
| 6273 | D.AddTypeInfo(DeclaratorChunk::getFunction( |
| 6274 | HasProto, IsAmbiguous, LParenLoc, ParamInfo.data(), |
| 6275 | ParamInfo.size(), EllipsisLoc, RParenLoc, |
| 6276 | RefQualifierIsLValueRef, RefQualifierLoc, |
| 6277 | SourceLocation(), |
| 6278 | ESpecType, ESpecRange, DynamicExceptions.data(), |
| 6279 | DynamicExceptionRanges.data(), DynamicExceptions.size(), |
| 6280 | NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr, |
| 6281 | ExceptionSpecTokens, DeclsInPrototype, StartLoc, |
| 6282 | LocalEndLoc, D, TrailingReturnType, &DS), |
| 6283 | std::move(FnAttrs), EndLoc); |
| 6284 | } |
| 6285 | |
| 6286 | |
| 6287 | |
| 6288 | bool Parser::ParseRefQualifier(bool &RefQualifierIsLValueRef, |
| 6289 | SourceLocation &RefQualifierLoc) { |
| 6290 | if (Tok.isOneOf(tok::amp, tok::ampamp)) { |
| 6291 | Diag(Tok, getLangOpts().CPlusPlus11 ? |
| 6292 | diag::warn_cxx98_compat_ref_qualifier : |
| 6293 | diag::ext_ref_qualifier); |
| 6294 | |
| 6295 | RefQualifierIsLValueRef = Tok.is(tok::amp); |
| 6296 | RefQualifierLoc = ConsumeToken(); |
| 6297 | return true; |
| 6298 | } |
| 6299 | return false; |
| 6300 | } |
| 6301 | |
| 6302 | |
| 6303 | |
| 6304 | |
| 6305 | |
| 6306 | |
| 6307 | bool Parser::isFunctionDeclaratorIdentifierList() { |
| 6308 | return !getLangOpts().CPlusPlus |
| 6309 | && Tok.is(tok::identifier) |
| 6310 | && !TryAltiVecVectorToken() |
| 6311 | |
| 6312 | |
| 6313 | && (TryAnnotateTypeOrScopeToken() || !Tok.is(tok::annot_typename)) |
| 6314 | |
| 6315 | |
| 6316 | |
| 6317 | |
| 6318 | |
| 6319 | |
| 6320 | |
| 6321 | |
| 6322 | |
| 6323 | |
| 6324 | |
| 6325 | |
| 6326 | && (!Tok.is(tok::eof) && |
| 6327 | (NextToken().is(tok::comma) || NextToken().is(tok::r_paren))); |
| 6328 | } |
| 6329 | |
| 6330 | |
| 6331 | |
| 6332 | |
| 6333 | |
| 6334 | |
| 6335 | |
| 6336 | |
| 6337 | |
| 6338 | |
| 6339 | void Parser::ParseFunctionDeclaratorIdentifierList( |
| 6340 | Declarator &D, |
| 6341 | SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo) { |
| 6342 | |
| 6343 | |
| 6344 | |
| 6345 | |
| 6346 | if (!D.getIdentifier()) |
| 6347 | Diag(Tok, diag::ext_ident_list_in_param); |
| 6348 | |
| 6349 | |
| 6350 | llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar; |
| 6351 | |
| 6352 | do { |
| 6353 | |
| 6354 | if (Tok.isNot(tok::identifier)) { |
| 6355 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 6356 | SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch); |
| 6357 | |
| 6358 | ParamInfo.clear(); |
| 6359 | return; |
| 6360 | } |
| 6361 | |
| 6362 | IdentifierInfo *ParmII = Tok.getIdentifierInfo(); |
| 6363 | |
| 6364 | |
| 6365 | if (Actions.getTypeName(*ParmII, Tok.getLocation(), getCurScope())) |
| 6366 | Diag(Tok, diag::err_unexpected_typedef_ident) << ParmII; |
| 6367 | |
| 6368 | |
| 6369 | if (!ParamsSoFar.insert(ParmII).second) { |
| 6370 | Diag(Tok, diag::err_param_redefinition) << ParmII; |
| 6371 | } else { |
| 6372 | |
| 6373 | ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 6374 | Tok.getLocation(), |
| 6375 | nullptr)); |
| 6376 | } |
| 6377 | |
| 6378 | |
| 6379 | ConsumeToken(); |
| 6380 | |
| 6381 | } while (TryConsumeToken(tok::comma)); |
| 6382 | } |
| 6383 | |
| 6384 | |
| 6385 | |
| 6386 | |
| 6387 | |
| 6388 | |
| 6389 | |
| 6390 | |
| 6391 | |
| 6392 | |
| 6393 | |
| 6394 | |
| 6395 | |
| 6396 | |
| 6397 | |
| 6398 | |
| 6399 | |
| 6400 | |
| 6401 | |
| 6402 | |
| 6403 | |
| 6404 | |
| 6405 | |
| 6406 | |
| 6407 | |
| 6408 | |
| 6409 | |
| 6410 | |
| 6411 | |
| 6412 | |
| 6413 | |
| 6414 | |
| 6415 | void Parser::ParseParameterDeclarationClause( |
| 6416 | Declarator &D, |
| 6417 | ParsedAttributes &FirstArgAttrs, |
| 6418 | SmallVectorImpl<DeclaratorChunk::ParamInfo> &ParamInfo, |
| 6419 | SourceLocation &EllipsisLoc) { |
| 6420 | do { |
| 6421 | |
| 6422 | |
| 6423 | if (TryConsumeToken(tok::ellipsis, EllipsisLoc)) |
| 6424 | break; |
| 6425 | |
| 6426 | |
| 6427 | |
| 6428 | DeclSpec DS(AttrFactory); |
| 6429 | |
| 6430 | |
| 6431 | MaybeParseCXX11Attributes(DS.getAttributes()); |
| 6432 | |
| 6433 | |
| 6434 | MaybeParseMicrosoftAttributes(DS.getAttributes()); |
| 6435 | |
| 6436 | SourceLocation DSStart = Tok.getLocation(); |
| 6437 | |
| 6438 | |
| 6439 | |
| 6440 | |
| 6441 | |
| 6442 | |
| 6443 | DS.takeAttributesFrom(FirstArgAttrs); |
| 6444 | |
| 6445 | ParseDeclarationSpecifiers(DS); |
| 6446 | |
| 6447 | |
| 6448 | |
| 6449 | |
| 6450 | |
| 6451 | Declarator ParmDeclarator( |
| 6452 | DS, D.getContext() == DeclaratorContext::LambdaExprContext |
| 6453 | ? DeclaratorContext::LambdaExprParameterContext |
| 6454 | : DeclaratorContext::PrototypeContext); |
| 6455 | ParseDeclarator(ParmDeclarator); |
| 6456 | |
| 6457 | |
| 6458 | MaybeParseGNUAttributes(ParmDeclarator); |
| 6459 | |
| 6460 | |
| 6461 | IdentifierInfo *ParmII = ParmDeclarator.getIdentifier(); |
| 6462 | |
| 6463 | |
| 6464 | |
| 6465 | std::unique_ptr<CachedTokens> DefArgToks; |
| 6466 | |
| 6467 | |
| 6468 | |
| 6469 | if (DS.isEmpty() && ParmDeclarator.getIdentifier() == nullptr && |
| 6470 | ParmDeclarator.getNumTypeObjects() == 0) { |
| 6471 | |
| 6472 | Diag(DSStart, diag::err_missing_param); |
| 6473 | } else { |
| 6474 | |
| 6475 | |
| 6476 | |
| 6477 | |
| 6478 | |
| 6479 | if (Tok.is(tok::ellipsis) && |
| 6480 | (NextToken().isNot(tok::r_paren) || |
| 6481 | (!ParmDeclarator.getEllipsisLoc().isValid() && |
| 6482 | !Actions.isUnexpandedParameterPackPermitted())) && |
| 6483 | Actions.containsUnexpandedParameterPacks(ParmDeclarator)) |
| 6484 | DiagnoseMisplacedEllipsisInDeclarator(ConsumeToken(), ParmDeclarator); |
| 6485 | |
| 6486 | |
| 6487 | |
| 6488 | Decl *Param = Actions.ActOnParamDeclarator(getCurScope(), ParmDeclarator); |
| 6489 | |
| 6490 | |
| 6491 | |
| 6492 | |
| 6493 | if (Tok.is(tok::equal)) { |
| 6494 | SourceLocation EqualLoc = Tok.getLocation(); |
| 6495 | |
| 6496 | |
| 6497 | if (D.getContext() == DeclaratorContext::MemberContext) { |
| 6498 | |
| 6499 | |
| 6500 | |
| 6501 | DefArgToks.reset(new CachedTokens); |
| 6502 | |
| 6503 | SourceLocation ArgStartLoc = NextToken().getLocation(); |
| 6504 | if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) { |
| 6505 | DefArgToks.reset(); |
| 6506 | Actions.ActOnParamDefaultArgumentError(Param, EqualLoc); |
| 6507 | } else { |
| 6508 | Actions.ActOnParamUnparsedDefaultArgument(Param, EqualLoc, |
| 6509 | ArgStartLoc); |
| 6510 | } |
| 6511 | } else { |
| 6512 | |
| 6513 | ConsumeToken(); |
| 6514 | |
| 6515 | |
| 6516 | |
| 6517 | EnterExpressionEvaluationContext Eval( |
| 6518 | Actions, |
| 6519 | Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed, |
| 6520 | Param); |
| 6521 | |
| 6522 | ExprResult DefArgResult; |
| 6523 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 6524 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 6525 | DefArgResult = ParseBraceInitializer(); |
| 6526 | } else |
| 6527 | DefArgResult = ParseAssignmentExpression(); |
| 6528 | DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult); |
| 6529 | if (DefArgResult.isInvalid()) { |
| 6530 | Actions.ActOnParamDefaultArgumentError(Param, EqualLoc); |
| 6531 | SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch); |
| 6532 | } else { |
| 6533 | |
| 6534 | Actions.ActOnParamDefaultArgument(Param, EqualLoc, |
| 6535 | DefArgResult.get()); |
| 6536 | } |
| 6537 | } |
| 6538 | } |
| 6539 | |
| 6540 | ParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII, |
| 6541 | ParmDeclarator.getIdentifierLoc(), |
| 6542 | Param, std::move(DefArgToks))); |
| 6543 | } |
| 6544 | |
| 6545 | if (TryConsumeToken(tok::ellipsis, EllipsisLoc)) { |
| 6546 | if (!getLangOpts().CPlusPlus) { |
| 6547 | |
| 6548 | |
| 6549 | Diag(EllipsisLoc, diag::err_missing_comma_before_ellipsis) |
| 6550 | << FixItHint::CreateInsertion(EllipsisLoc, ", "); |
| 6551 | } else if (ParmDeclarator.getEllipsisLoc().isValid() || |
| 6552 | Actions.containsUnexpandedParameterPacks(ParmDeclarator)) { |
| 6553 | |
| 6554 | |
| 6555 | SourceLocation ParmEllipsis = ParmDeclarator.getEllipsisLoc(); |
| 6556 | Diag(EllipsisLoc, diag::warn_misplaced_ellipsis_vararg) |
| 6557 | << ParmEllipsis.isValid() << ParmEllipsis; |
| 6558 | if (ParmEllipsis.isValid()) { |
| 6559 | Diag(ParmEllipsis, |
| 6560 | diag::note_misplaced_ellipsis_vararg_existing_ellipsis); |
| 6561 | } else { |
| 6562 | Diag(ParmDeclarator.getIdentifierLoc(), |
| 6563 | diag::note_misplaced_ellipsis_vararg_add_ellipsis) |
| 6564 | << FixItHint::CreateInsertion(ParmDeclarator.getIdentifierLoc(), |
| 6565 | "...") |
| 6566 | << !ParmDeclarator.hasName(); |
| 6567 | } |
| 6568 | Diag(EllipsisLoc, diag::note_misplaced_ellipsis_vararg_add_comma) |
| 6569 | << FixItHint::CreateInsertion(EllipsisLoc, ", "); |
| 6570 | } |
| 6571 | |
| 6572 | |
| 6573 | break; |
| 6574 | } |
| 6575 | |
| 6576 | |
| 6577 | } while (TryConsumeToken(tok::comma)); |
| 6578 | } |
| 6579 | |
| 6580 | |
| 6581 | |
| 6582 | |
| 6583 | |
| 6584 | |
| 6585 | |
| 6586 | |
| 6587 | void Parser::ParseBracketDeclarator(Declarator &D) { |
| 6588 | if (CheckProhibitedCXX11Attribute()) |
| 6589 | return; |
| 6590 | |
| 6591 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 6592 | T.consumeOpen(); |
| 6593 | |
| 6594 | |
| 6595 | |
| 6596 | if (Tok.getKind() == tok::r_square) { |
| 6597 | T.consumeClose(); |
| 6598 | ParsedAttributes attrs(AttrFactory); |
| 6599 | MaybeParseCXX11Attributes(attrs); |
| 6600 | |
| 6601 | |
| 6602 | D.AddTypeInfo(DeclaratorChunk::getArray(0, false, false, nullptr, |
| 6603 | T.getOpenLocation(), |
| 6604 | T.getCloseLocation()), |
| 6605 | std::move(attrs), T.getCloseLocation()); |
| 6606 | return; |
| 6607 | } else if (Tok.getKind() == tok::numeric_constant && |
| 6608 | GetLookAheadToken(1).is(tok::r_square)) { |
| 6609 | |
| 6610 | ExprResult ExprRes(Actions.ActOnNumericConstant(Tok, getCurScope())); |
| 6611 | ConsumeToken(); |
| 6612 | |
| 6613 | T.consumeClose(); |
| 6614 | ParsedAttributes attrs(AttrFactory); |
| 6615 | MaybeParseCXX11Attributes(attrs); |
| 6616 | |
| 6617 | |
| 6618 | D.AddTypeInfo(DeclaratorChunk::getArray(0, false, false, ExprRes.get(), |
| 6619 | T.getOpenLocation(), |
| 6620 | T.getCloseLocation()), |
| 6621 | std::move(attrs), T.getCloseLocation()); |
| 6622 | return; |
| 6623 | } else if (Tok.getKind() == tok::code_completion) { |
| 6624 | Actions.CodeCompleteBracketDeclarator(getCurScope()); |
| 6625 | return cutOffParsing(); |
| 6626 | } |
| 6627 | |
| 6628 | |
| 6629 | SourceLocation StaticLoc; |
| 6630 | TryConsumeToken(tok::kw_static, StaticLoc); |
| 6631 | |
| 6632 | |
| 6633 | |
| 6634 | DeclSpec DS(AttrFactory); |
| 6635 | ParseTypeQualifierListOpt(DS, AR_CXX11AttributesParsed); |
| 6636 | |
| 6637 | |
| 6638 | |
| 6639 | if (!StaticLoc.isValid()) |
| 6640 | TryConsumeToken(tok::kw_static, StaticLoc); |
| 6641 | |
| 6642 | |
| 6643 | bool isStar = false; |
| 6644 | ExprResult NumElements; |
| 6645 | |
| 6646 | |
| 6647 | |
| 6648 | |
| 6649 | |
| 6650 | if (Tok.is(tok::star) && GetLookAheadToken(1).is(tok::r_square)) { |
| 6651 | ConsumeToken(); |
| 6652 | |
| 6653 | if (StaticLoc.isValid()) { |
| 6654 | Diag(StaticLoc, diag::err_unspecified_vla_size_with_static); |
| 6655 | StaticLoc = SourceLocation(); |
| 6656 | } |
| 6657 | isStar = true; |
| 6658 | } else if (Tok.isNot(tok::r_square)) { |
| 6659 | |
| 6660 | |
| 6661 | |
| 6662 | |
| 6663 | |
| 6664 | |
| 6665 | |
| 6666 | if (getLangOpts().CPlusPlus) { |
| 6667 | NumElements = ParseConstantExpression(); |
| 6668 | } else { |
| 6669 | EnterExpressionEvaluationContext Unevaluated( |
| 6670 | Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6671 | NumElements = |
| 6672 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 6673 | } |
| 6674 | } else { |
| 6675 | if (StaticLoc.isValid()) { |
| 6676 | Diag(StaticLoc, diag::err_unspecified_size_with_static); |
| 6677 | StaticLoc = SourceLocation(); |
| 6678 | } |
| 6679 | } |
| 6680 | |
| 6681 | |
| 6682 | if (NumElements.isInvalid()) { |
| 6683 | D.setInvalidType(true); |
| 6684 | |
| 6685 | SkipUntil(tok::r_square, StopAtSemi); |
| 6686 | return; |
| 6687 | } |
| 6688 | |
| 6689 | T.consumeClose(); |
| 6690 | |
| 6691 | MaybeParseCXX11Attributes(DS.getAttributes()); |
| 6692 | |
| 6693 | |
| 6694 | D.AddTypeInfo( |
| 6695 | DeclaratorChunk::getArray(DS.getTypeQualifiers(), StaticLoc.isValid(), |
| 6696 | isStar, NumElements.get(), T.getOpenLocation(), |
| 6697 | T.getCloseLocation()), |
| 6698 | std::move(DS.getAttributes()), T.getCloseLocation()); |
| 6699 | } |
| 6700 | |
| 6701 | |
| 6702 | void Parser::ParseMisplacedBracketDeclarator(Declarator &D) { |
| 6703 | (0) . __assert_fail ("Tok.is(tok..l_square) && \"Missing opening bracket\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6703, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_square) && "Missing opening bracket"); |
| 6704 | (0) . __assert_fail ("!D.mayOmitIdentifier() && \"Declarator cannot omit identifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6704, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(!D.mayOmitIdentifier() && "Declarator cannot omit identifier"); |
| 6705 | |
| 6706 | SourceLocation StartBracketLoc = Tok.getLocation(); |
| 6707 | Declarator TempDeclarator(D.getDeclSpec(), D.getContext()); |
| 6708 | |
| 6709 | while (Tok.is(tok::l_square)) { |
| 6710 | ParseBracketDeclarator(TempDeclarator); |
| 6711 | } |
| 6712 | |
| 6713 | |
| 6714 | |
| 6715 | |
| 6716 | if (Tok.is(tok::semi)) |
| 6717 | D.getName().EndLocation = StartBracketLoc; |
| 6718 | |
| 6719 | SourceLocation SuggestParenLoc = Tok.getLocation(); |
| 6720 | |
| 6721 | |
| 6722 | ParseDeclaratorInternal(D, &Parser::ParseDirectDeclarator); |
| 6723 | |
| 6724 | |
| 6725 | |
| 6726 | |
| 6727 | if (TempDeclarator.getNumTypeObjects() == 0) |
| 6728 | return; |
| 6729 | |
| 6730 | |
| 6731 | bool NeedParens = false; |
| 6732 | if (D.getNumTypeObjects() != 0) { |
| 6733 | switch (D.getTypeObject(D.getNumTypeObjects() - 1).Kind) { |
| 6734 | case DeclaratorChunk::Pointer: |
| 6735 | case DeclaratorChunk::Reference: |
| 6736 | case DeclaratorChunk::BlockPointer: |
| 6737 | case DeclaratorChunk::MemberPointer: |
| 6738 | case DeclaratorChunk::Pipe: |
| 6739 | NeedParens = true; |
| 6740 | break; |
| 6741 | case DeclaratorChunk::Array: |
| 6742 | case DeclaratorChunk::Function: |
| 6743 | case DeclaratorChunk::Paren: |
| 6744 | break; |
| 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | if (NeedParens) { |
| 6749 | |
| 6750 | SourceLocation EndLoc = PP.getLocForEndOfToken(D.getEndLoc()); |
| 6751 | D.AddTypeInfo(DeclaratorChunk::getParen(SuggestParenLoc, EndLoc), |
| 6752 | SourceLocation()); |
| 6753 | } |
| 6754 | |
| 6755 | |
| 6756 | for (unsigned i = 0, e = TempDeclarator.getNumTypeObjects(); i < e; ++i) { |
| 6757 | const DeclaratorChunk &Chunk = TempDeclarator.getTypeObject(i); |
| 6758 | D.AddTypeInfo(Chunk, SourceLocation()); |
| 6759 | } |
| 6760 | |
| 6761 | |
| 6762 | |
| 6763 | if (!D.getIdentifier() && !NeedParens) |
| 6764 | return; |
| 6765 | |
| 6766 | SourceLocation EndBracketLoc = TempDeclarator.getEndLoc(); |
| 6767 | |
| 6768 | |
| 6769 | SourceRange BracketRange(StartBracketLoc, EndBracketLoc); |
| 6770 | SourceLocation EndLoc = PP.getLocForEndOfToken(D.getEndLoc()); |
| 6771 | |
| 6772 | if (NeedParens) { |
| 6773 | Diag(EndLoc, diag::err_brackets_go_after_unqualified_id) |
| 6774 | << getLangOpts().CPlusPlus |
| 6775 | << FixItHint::CreateInsertion(SuggestParenLoc, "(") |
| 6776 | << FixItHint::CreateInsertion(EndLoc, ")") |
| 6777 | << FixItHint::CreateInsertionFromRange( |
| 6778 | EndLoc, CharSourceRange(BracketRange, true)) |
| 6779 | << FixItHint::CreateRemoval(BracketRange); |
| 6780 | } else { |
| 6781 | Diag(EndLoc, diag::err_brackets_go_after_unqualified_id) |
| 6782 | << getLangOpts().CPlusPlus |
| 6783 | << FixItHint::CreateInsertionFromRange( |
| 6784 | EndLoc, CharSourceRange(BracketRange, true)) |
| 6785 | << FixItHint::CreateRemoval(BracketRange); |
| 6786 | } |
| 6787 | } |
| 6788 | |
| 6789 | |
| 6790 | |
| 6791 | |
| 6792 | |
| 6793 | |
| 6794 | void Parser::ParseTypeofSpecifier(DeclSpec &DS) { |
| 6795 | (0) . __assert_fail ("Tok.is(tok..kw_typeof) && \"Not a typeof specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6795, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_typeof) && "Not a typeof specifier"); |
| 6796 | Token OpTok = Tok; |
| 6797 | SourceLocation StartLoc = ConsumeToken(); |
| 6798 | |
| 6799 | const bool hasParens = Tok.is(tok::l_paren); |
| 6800 | |
| 6801 | EnterExpressionEvaluationContext Unevaluated( |
| 6802 | Actions, Sema::ExpressionEvaluationContext::Unevaluated, |
| 6803 | Sema::ReuseLambdaContextDecl); |
| 6804 | |
| 6805 | bool isCastExpr; |
| 6806 | ParsedType CastTy; |
| 6807 | SourceRange CastRange; |
| 6808 | ExprResult Operand = Actions.CorrectDelayedTyposInExpr( |
| 6809 | ParseExprAfterUnaryExprOrTypeTrait(OpTok, isCastExpr, CastTy, CastRange)); |
| 6810 | if (hasParens) |
| 6811 | DS.setTypeofParensRange(CastRange); |
| 6812 | |
| 6813 | if (CastRange.getEnd().isInvalid()) |
| 6814 | |
| 6815 | DS.SetRangeEnd(Tok.getLocation()); |
| 6816 | else |
| 6817 | DS.SetRangeEnd(CastRange.getEnd()); |
| 6818 | |
| 6819 | if (isCastExpr) { |
| 6820 | if (!CastTy) { |
| 6821 | DS.SetTypeSpecError(); |
| 6822 | return; |
| 6823 | } |
| 6824 | |
| 6825 | const char *PrevSpec = nullptr; |
| 6826 | unsigned DiagID; |
| 6827 | |
| 6828 | if (DS.SetTypeSpecType(DeclSpec::TST_typeofType, StartLoc, PrevSpec, |
| 6829 | DiagID, CastTy, |
| 6830 | Actions.getASTContext().getPrintingPolicy())) |
| 6831 | Diag(StartLoc, DiagID) << PrevSpec; |
| 6832 | return; |
| 6833 | } |
| 6834 | |
| 6835 | |
| 6836 | if (Operand.isInvalid()) { |
| 6837 | DS.SetTypeSpecError(); |
| 6838 | return; |
| 6839 | } |
| 6840 | |
| 6841 | |
| 6842 | Operand = Actions.HandleExprEvaluationContextForTypeof(Operand.get()); |
| 6843 | if (Operand.isInvalid()) { |
| 6844 | DS.SetTypeSpecError(); |
| 6845 | return; |
| 6846 | } |
| 6847 | |
| 6848 | const char *PrevSpec = nullptr; |
| 6849 | unsigned DiagID; |
| 6850 | |
| 6851 | if (DS.SetTypeSpecType(DeclSpec::TST_typeofExpr, StartLoc, PrevSpec, |
| 6852 | DiagID, Operand.get(), |
| 6853 | Actions.getASTContext().getPrintingPolicy())) |
| 6854 | Diag(StartLoc, DiagID) << PrevSpec; |
| 6855 | } |
| 6856 | |
| 6857 | |
| 6858 | |
| 6859 | |
| 6860 | void Parser::ParseAtomicSpecifier(DeclSpec &DS) { |
| 6861 | (0) . __assert_fail ("Tok.is(tok..kw__Atomic) && NextToken().is(tok..l_paren) && \"Not an atomic specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6862, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw__Atomic) && NextToken().is(tok::l_paren) && |
| 6862 | (0) . __assert_fail ("Tok.is(tok..kw__Atomic) && NextToken().is(tok..l_paren) && \"Not an atomic specifier\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseDecl.cpp", 6862, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not an atomic specifier"); |
| 6863 | |
| 6864 | SourceLocation StartLoc = ConsumeToken(); |
| 6865 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 6866 | if (T.consumeOpen()) |
| 6867 | return; |
| 6868 | |
| 6869 | TypeResult Result = ParseTypeName(); |
| 6870 | if (Result.isInvalid()) { |
| 6871 | SkipUntil(tok::r_paren, StopAtSemi); |
| 6872 | return; |
| 6873 | } |
| 6874 | |
| 6875 | |
| 6876 | T.consumeClose(); |
| 6877 | |
| 6878 | if (T.getCloseLocation().isInvalid()) |
| 6879 | return; |
| 6880 | |
| 6881 | DS.setTypeofParensRange(T.getRange()); |
| 6882 | DS.SetRangeEnd(T.getCloseLocation()); |
| 6883 | |
| 6884 | const char *PrevSpec = nullptr; |
| 6885 | unsigned DiagID; |
| 6886 | if (DS.SetTypeSpecType(DeclSpec::TST_atomic, StartLoc, PrevSpec, |
| 6887 | DiagID, Result.get(), |
| 6888 | Actions.getASTContext().getPrintingPolicy())) |
| 6889 | Diag(StartLoc, DiagID) << PrevSpec; |
| 6890 | } |
| 6891 | |
| 6892 | |
| 6893 | |
| 6894 | bool Parser::TryAltiVecVectorTokenOutOfLine() { |
| 6895 | Token Next = NextToken(); |
| 6896 | switch (Next.getKind()) { |
| 6897 | default: return false; |
| 6898 | case tok::kw_short: |
| 6899 | case tok::kw_long: |
| 6900 | case tok::kw_signed: |
| 6901 | case tok::kw_unsigned: |
| 6902 | case tok::kw_void: |
| 6903 | case tok::kw_char: |
| 6904 | case tok::kw_int: |
| 6905 | case tok::kw_float: |
| 6906 | case tok::kw_double: |
| 6907 | case tok::kw_bool: |
| 6908 | case tok::kw___bool: |
| 6909 | case tok::kw___pixel: |
| 6910 | Tok.setKind(tok::kw___vector); |
| 6911 | return true; |
| 6912 | case tok::identifier: |
| 6913 | if (Next.getIdentifierInfo() == Ident_pixel) { |
| 6914 | Tok.setKind(tok::kw___vector); |
| 6915 | return true; |
| 6916 | } |
| 6917 | if (Next.getIdentifierInfo() == Ident_bool) { |
| 6918 | Tok.setKind(tok::kw___vector); |
| 6919 | return true; |
| 6920 | } |
| 6921 | return false; |
| 6922 | } |
| 6923 | } |
| 6924 | |
| 6925 | bool Parser::TryAltiVecTokenOutOfLine(DeclSpec &DS, SourceLocation Loc, |
| 6926 | const char *&PrevSpec, unsigned &DiagID, |
| 6927 | bool &isInvalid) { |
| 6928 | const PrintingPolicy &Policy = Actions.getASTContext().getPrintingPolicy(); |
| 6929 | if (Tok.getIdentifierInfo() == Ident_vector) { |
| 6930 | Token Next = NextToken(); |
| 6931 | switch (Next.getKind()) { |
| 6932 | case tok::kw_short: |
| 6933 | case tok::kw_long: |
| 6934 | case tok::kw_signed: |
| 6935 | case tok::kw_unsigned: |
| 6936 | case tok::kw_void: |
| 6937 | case tok::kw_char: |
| 6938 | case tok::kw_int: |
| 6939 | case tok::kw_float: |
| 6940 | case tok::kw_double: |
| 6941 | case tok::kw_bool: |
| 6942 | case tok::kw___bool: |
| 6943 | case tok::kw___pixel: |
| 6944 | isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID, Policy); |
| 6945 | return true; |
| 6946 | case tok::identifier: |
| 6947 | if (Next.getIdentifierInfo() == Ident_pixel) { |
| 6948 | isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID,Policy); |
| 6949 | return true; |
| 6950 | } |
| 6951 | if (Next.getIdentifierInfo() == Ident_bool) { |
| 6952 | isInvalid = DS.SetTypeAltiVecVector(true, Loc, PrevSpec, DiagID,Policy); |
| 6953 | return true; |
| 6954 | } |
| 6955 | break; |
| 6956 | default: |
| 6957 | break; |
| 6958 | } |
| 6959 | } else if ((Tok.getIdentifierInfo() == Ident_pixel) && |
| 6960 | DS.isTypeAltiVecVector()) { |
| 6961 | isInvalid = DS.SetTypeAltiVecPixel(true, Loc, PrevSpec, DiagID, Policy); |
| 6962 | return true; |
| 6963 | } else if ((Tok.getIdentifierInfo() == Ident_bool) && |
| 6964 | DS.isTypeAltiVecVector()) { |
| 6965 | isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy); |
| 6966 | return true; |
| 6967 | } |
| 6968 | return false; |
| 6969 | } |
| 6970 | |