| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #include "clang/Parse/Parser.h" |
| 15 | #include "clang/Parse/ParseDiagnostic.h" |
| 16 | #include "clang/Sema/ParsedTemplate.h" |
| 17 | using namespace clang; |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | bool Parser::isCXXDeclarationStatement() { |
| 50 | switch (Tok.getKind()) { |
| 51 | |
| 52 | case tok::kw_asm: |
| 53 | |
| 54 | case tok::kw_namespace: |
| 55 | |
| 56 | |
| 57 | case tok::kw_using: |
| 58 | |
| 59 | case tok::kw_static_assert: |
| 60 | case tok::kw__Static_assert: |
| 61 | return true; |
| 62 | |
| 63 | default: |
| 64 | return isCXXSimpleDeclaration(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | bool Parser::isCXXSimpleDeclaration(bool AllowForRangeDecl) { |
| 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 | bool InvalidAsDeclaration = false; |
| 114 | TPResult TPR = isCXXDeclarationSpecifier(TPResult::False, |
| 115 | &InvalidAsDeclaration); |
| 116 | if (TPR != TPResult::Ambiguous) |
| 117 | return TPR != TPResult::False; |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | if (InvalidAsDeclaration) |
| 126 | return false; |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | { |
| 136 | RevertingTentativeParsingAction PA(*this); |
| 137 | TPR = TryParseSimpleDeclaration(AllowForRangeDecl); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | if (TPR == TPResult::Error) |
| 142 | return true; |
| 143 | |
| 144 | |
| 145 | if (TPR == TPResult::Ambiguous) |
| 146 | TPR = TPResult::True; |
| 147 | |
| 148 | assert(TPR == TPResult::True || TPR == TPResult::False); |
| 149 | return TPR == TPResult::True; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | |
| 154 | Parser::TPResult Parser::TryConsumeDeclarationSpecifier() { |
| 155 | switch (Tok.getKind()) { |
| 156 | case tok::kw__Atomic: |
| 157 | if (NextToken().isNot(tok::l_paren)) { |
| 158 | ConsumeToken(); |
| 159 | break; |
| 160 | } |
| 161 | LLVM_FALLTHROUGH; |
| 162 | case tok::kw_typeof: |
| 163 | case tok::kw___attribute: |
| 164 | case tok::kw___underlying_type: { |
| 165 | ConsumeToken(); |
| 166 | if (Tok.isNot(tok::l_paren)) |
| 167 | return TPResult::Error; |
| 168 | ConsumeParen(); |
| 169 | if (!SkipUntil(tok::r_paren)) |
| 170 | return TPResult::Error; |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | case tok::kw_class: |
| 175 | case tok::kw_struct: |
| 176 | case tok::kw_union: |
| 177 | case tok::kw___interface: |
| 178 | case tok::kw_enum: |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | ConsumeToken(); |
| 187 | |
| 188 | |
| 189 | while (Tok.isOneOf(tok::l_square, tok::kw___attribute, tok::kw___declspec, |
| 190 | tok::kw_alignas)) { |
| 191 | if (Tok.is(tok::l_square)) { |
| 192 | ConsumeBracket(); |
| 193 | if (!SkipUntil(tok::r_square)) |
| 194 | return TPResult::Error; |
| 195 | } else { |
| 196 | ConsumeToken(); |
| 197 | if (Tok.isNot(tok::l_paren)) |
| 198 | return TPResult::Error; |
| 199 | ConsumeParen(); |
| 200 | if (!SkipUntil(tok::r_paren)) |
| 201 | return TPResult::Error; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if (Tok.isOneOf(tok::identifier, tok::coloncolon, tok::kw_decltype, |
| 206 | tok::annot_template_id) && |
| 207 | TryAnnotateCXXScopeToken()) |
| 208 | return TPResult::Error; |
| 209 | if (Tok.is(tok::annot_cxxscope)) |
| 210 | ConsumeAnnotationToken(); |
| 211 | if (Tok.is(tok::identifier)) |
| 212 | ConsumeToken(); |
| 213 | else if (Tok.is(tok::annot_template_id)) |
| 214 | ConsumeAnnotationToken(); |
| 215 | else |
| 216 | return TPResult::Error; |
| 217 | break; |
| 218 | |
| 219 | case tok::annot_cxxscope: |
| 220 | ConsumeAnnotationToken(); |
| 221 | LLVM_FALLTHROUGH; |
| 222 | default: |
| 223 | ConsumeAnyToken(); |
| 224 | |
| 225 | if (getLangOpts().ObjC && Tok.is(tok::less)) |
| 226 | return TryParseProtocolQualifiers(); |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | return TPResult::Ambiguous; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | Parser::TPResult Parser::TryParseSimpleDeclaration(bool AllowForRangeDecl) { |
| 242 | if (TryConsumeDeclarationSpecifier() == TPResult::Error) |
| 243 | return TPResult::Error; |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | if (Tok.isNot(tok::l_paren)) { |
| 249 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 250 | if (TPR == TPResult::Ambiguous) |
| 251 | return TPResult::True; |
| 252 | if (TPR == TPResult::True || TPR == TPResult::Error) |
| 253 | return TPR; |
| 254 | assert(TPR == TPResult::False); |
| 255 | } |
| 256 | |
| 257 | TPResult TPR = TryParseInitDeclaratorList(); |
| 258 | if (TPR != TPResult::Ambiguous) |
| 259 | return TPR; |
| 260 | |
| 261 | if (Tok.isNot(tok::semi) && (!AllowForRangeDecl || Tok.isNot(tok::colon))) |
| 262 | return TPResult::False; |
| 263 | |
| 264 | return TPResult::Ambiguous; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | Parser::TPResult Parser::TryParseInitDeclaratorList() { |
| 295 | while (1) { |
| 296 | |
| 297 | TPResult TPR = TryParseDeclarator(false); |
| 298 | if (TPR != TPResult::Ambiguous) |
| 299 | return TPR; |
| 300 | |
| 301 | |
| 302 | if (Tok.isOneOf(tok::kw_asm, tok::kw___attribute)) |
| 303 | return TPResult::True; |
| 304 | |
| 305 | |
| 306 | if (Tok.is(tok::l_paren)) { |
| 307 | |
| 308 | ConsumeParen(); |
| 309 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
| 310 | return TPResult::Error; |
| 311 | } else if (Tok.is(tok::l_brace)) { |
| 312 | |
| 313 | |
| 314 | return TPResult::True; |
| 315 | } else if (Tok.is(tok::equal) || isTokIdentifier_in()) { |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | return TPResult::True; |
| 333 | } |
| 334 | |
| 335 | if (!TryConsumeToken(tok::comma)) |
| 336 | break; |
| 337 | } |
| 338 | |
| 339 | return TPResult::Ambiguous; |
| 340 | } |
| 341 | |
| 342 | struct Parser::ConditionDeclarationOrInitStatementState { |
| 343 | Parser &P; |
| 344 | bool CanBeExpression = true; |
| 345 | bool CanBeCondition = true; |
| 346 | bool CanBeInitStatement; |
| 347 | bool CanBeForRangeDecl; |
| 348 | |
| 349 | ConditionDeclarationOrInitStatementState(Parser &P, bool CanBeInitStatement, |
| 350 | bool CanBeForRangeDecl) |
| 351 | : P(P), CanBeInitStatement(CanBeInitStatement), |
| 352 | CanBeForRangeDecl(CanBeForRangeDecl) {} |
| 353 | |
| 354 | bool resolved() { |
| 355 | return CanBeExpression + CanBeCondition + CanBeInitStatement + |
| 356 | CanBeForRangeDecl < 2; |
| 357 | } |
| 358 | |
| 359 | void markNotExpression() { |
| 360 | CanBeExpression = false; |
| 361 | |
| 362 | if (!resolved()) { |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | RevertingTentativeParsingAction PA(P); |
| 368 | if (CanBeForRangeDecl) { |
| 369 | |
| 370 | |
| 371 | while (true) { |
| 372 | unsigned QuestionColonDepth = 0; |
| 373 | P.SkipUntil({tok::r_paren, tok::semi, tok::question, tok::colon}, |
| 374 | StopBeforeMatch); |
| 375 | if (P.Tok.is(tok::question)) |
| 376 | ++QuestionColonDepth; |
| 377 | else if (P.Tok.is(tok::colon)) { |
| 378 | if (QuestionColonDepth) |
| 379 | --QuestionColonDepth; |
| 380 | else { |
| 381 | CanBeCondition = CanBeInitStatement = false; |
| 382 | return; |
| 383 | } |
| 384 | } else { |
| 385 | CanBeForRangeDecl = false; |
| 386 | break; |
| 387 | } |
| 388 | P.ConsumeToken(); |
| 389 | } |
| 390 | } else { |
| 391 | |
| 392 | P.SkipUntil(tok::r_paren, tok::semi, StopBeforeMatch); |
| 393 | } |
| 394 | if (P.Tok.isNot(tok::r_paren)) |
| 395 | CanBeCondition = CanBeForRangeDecl = false; |
| 396 | if (P.Tok.isNot(tok::semi)) |
| 397 | CanBeInitStatement = false; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | bool markNotCondition() { |
| 402 | CanBeCondition = false; |
| 403 | return resolved(); |
| 404 | } |
| 405 | |
| 406 | bool markNotForRangeDecl() { |
| 407 | CanBeForRangeDecl = false; |
| 408 | return resolved(); |
| 409 | } |
| 410 | |
| 411 | bool update(TPResult IsDecl) { |
| 412 | switch (IsDecl) { |
| 413 | case TPResult::True: |
| 414 | markNotExpression(); |
| 415 | (0) . __assert_fail ("resolved() && \"can't continue after tentative parsing bails out\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 415, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(resolved() && "can't continue after tentative parsing bails out"); |
| 416 | break; |
| 417 | case TPResult::False: |
| 418 | CanBeCondition = CanBeInitStatement = CanBeForRangeDecl = false; |
| 419 | break; |
| 420 | case TPResult::Ambiguous: |
| 421 | break; |
| 422 | case TPResult::Error: |
| 423 | CanBeExpression = CanBeCondition = CanBeInitStatement = |
| 424 | CanBeForRangeDecl = false; |
| 425 | break; |
| 426 | } |
| 427 | return resolved(); |
| 428 | } |
| 429 | |
| 430 | ConditionOrInitStatement result() const { |
| 431 | (0) . __assert_fail ("CanBeExpression + CanBeCondition + CanBeInitStatement + CanBeForRangeDecl < 2 && \"result called but not yet resolved\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 433, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CanBeExpression + CanBeCondition + CanBeInitStatement + |
| 432 | (0) . __assert_fail ("CanBeExpression + CanBeCondition + CanBeInitStatement + CanBeForRangeDecl < 2 && \"result called but not yet resolved\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 433, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> CanBeForRangeDecl < 2 && |
| 433 | (0) . __assert_fail ("CanBeExpression + CanBeCondition + CanBeInitStatement + CanBeForRangeDecl < 2 && \"result called but not yet resolved\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 433, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "result called but not yet resolved"); |
| 434 | if (CanBeExpression) |
| 435 | return ConditionOrInitStatement::Expression; |
| 436 | if (CanBeCondition) |
| 437 | return ConditionOrInitStatement::ConditionDecl; |
| 438 | if (CanBeInitStatement) |
| 439 | return ConditionOrInitStatement::InitStmtDecl; |
| 440 | if (CanBeForRangeDecl) |
| 441 | return ConditionOrInitStatement::ForRangeDecl; |
| 442 | return ConditionOrInitStatement::Error; |
| 443 | } |
| 444 | }; |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | Parser::ConditionOrInitStatement |
| 464 | Parser::isCXXConditionDeclarationOrInitStatement(bool CanBeInitStatement, |
| 465 | bool CanBeForRangeDecl) { |
| 466 | ConditionDeclarationOrInitStatementState State(*this, CanBeInitStatement, |
| 467 | CanBeForRangeDecl); |
| 468 | |
| 469 | if (State.update(isCXXDeclarationSpecifier())) |
| 470 | return State.result(); |
| 471 | |
| 472 | |
| 473 | RevertingTentativeParsingAction PA(*this); |
| 474 | |
| 475 | |
| 476 | if (State.update(TryConsumeDeclarationSpecifier())) |
| 477 | return State.result(); |
| 478 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Expected '('\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 478, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 479 | |
| 480 | while (true) { |
| 481 | |
| 482 | if (State.update(TryParseDeclarator(false))) |
| 483 | return State.result(); |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | if (Tok.isOneOf(tok::equal, tok::kw_asm, tok::kw___attribute) || |
| 489 | (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace))) { |
| 490 | State.markNotExpression(); |
| 491 | return State.result(); |
| 492 | } |
| 493 | |
| 494 | |
| 495 | if (State.CanBeForRangeDecl && Tok.is(tok::colon)) |
| 496 | return ConditionOrInitStatement::ForRangeDecl; |
| 497 | |
| 498 | |
| 499 | |
| 500 | if (State.markNotCondition()) |
| 501 | return State.result(); |
| 502 | |
| 503 | |
| 504 | if (State.markNotForRangeDecl()) |
| 505 | return State.result(); |
| 506 | |
| 507 | |
| 508 | |
| 509 | if (Tok.is(tok::l_paren)) { |
| 510 | ConsumeParen(); |
| 511 | SkipUntil(tok::r_paren, StopAtSemi); |
| 512 | } |
| 513 | |
| 514 | if (!TryConsumeToken(tok::comma)) |
| 515 | break; |
| 516 | } |
| 517 | |
| 518 | |
| 519 | if (State.CanBeCondition && Tok.is(tok::r_paren)) |
| 520 | return ConditionOrInitStatement::ConditionDecl; |
| 521 | else if (State.CanBeInitStatement && Tok.is(tok::semi)) |
| 522 | return ConditionOrInitStatement::InitStmtDecl; |
| 523 | else |
| 524 | return ConditionOrInitStatement::Expression; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | bool Parser::isCXXTypeId(TentativeCXXTypeIdContext Context, bool &isAmbiguous) { |
| 545 | |
| 546 | isAmbiguous = false; |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 556 | if (TPR != TPResult::Ambiguous) |
| 557 | return TPR != TPResult::False; |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | RevertingTentativeParsingAction PA(*this); |
| 567 | |
| 568 | |
| 569 | TryConsumeDeclarationSpecifier(); |
| 570 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Expected '('\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 570, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 571 | |
| 572 | |
| 573 | TPR = TryParseDeclarator(true, false); |
| 574 | |
| 575 | |
| 576 | if (TPR == TPResult::Error) |
| 577 | TPR = TPResult::True; |
| 578 | |
| 579 | if (TPR == TPResult::Ambiguous) { |
| 580 | |
| 581 | |
| 582 | if (Context == TypeIdInParens && Tok.is(tok::r_paren)) { |
| 583 | TPR = TPResult::True; |
| 584 | isAmbiguous = true; |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | } else if (Context == TypeIdAsTemplateArgument && |
| 591 | (Tok.isOneOf(tok::greater, tok::comma) || |
| 592 | (getLangOpts().CPlusPlus11 && |
| 593 | (Tok.is(tok::greatergreater) || |
| 594 | (Tok.is(tok::ellipsis) && |
| 595 | NextToken().isOneOf(tok::greater, tok::greatergreater, |
| 596 | tok::comma)))))) { |
| 597 | TPR = TPResult::True; |
| 598 | isAmbiguous = true; |
| 599 | |
| 600 | } else |
| 601 | TPR = TPResult::False; |
| 602 | } |
| 603 | |
| 604 | assert(TPR == TPResult::True || TPR == TPResult::False); |
| 605 | return TPR == TPResult::True; |
| 606 | } |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | Parser::CXX11AttributeKind |
| 642 | Parser::isCXX11AttributeSpecifier(bool Disambiguate, |
| 643 | bool OuterMightBeMessageSend) { |
| 644 | if (Tok.is(tok::kw_alignas)) |
| 645 | return CAK_AttributeSpecifier; |
| 646 | |
| 647 | if (Tok.isNot(tok::l_square) || NextToken().isNot(tok::l_square)) |
| 648 | return CAK_NotAttributeSpecifier; |
| 649 | |
| 650 | |
| 651 | if (!Disambiguate && !getLangOpts().ObjC) |
| 652 | return CAK_AttributeSpecifier; |
| 653 | |
| 654 | RevertingTentativeParsingAction PA(*this); |
| 655 | |
| 656 | |
| 657 | ConsumeBracket(); |
| 658 | |
| 659 | |
| 660 | if (!getLangOpts().ObjC) { |
| 661 | ConsumeBracket(); |
| 662 | |
| 663 | bool IsAttribute = SkipUntil(tok::r_square); |
| 664 | IsAttribute &= Tok.is(tok::r_square); |
| 665 | |
| 666 | return IsAttribute ? CAK_AttributeSpecifier : CAK_InvalidAttributeSpecifier; |
| 667 | } |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | LambdaIntroducer Intro; |
| 682 | if (!TryParseLambdaIntroducer(Intro)) { |
| 683 | |
| 684 | bool IsAttribute = Tok.is(tok::r_square); |
| 685 | |
| 686 | if (IsAttribute) |
| 687 | |
| 688 | return CAK_AttributeSpecifier; |
| 689 | |
| 690 | if (OuterMightBeMessageSend) |
| 691 | |
| 692 | return CAK_NotAttributeSpecifier; |
| 693 | |
| 694 | |
| 695 | return CAK_InvalidAttributeSpecifier; |
| 696 | } |
| 697 | |
| 698 | ConsumeBracket(); |
| 699 | |
| 700 | |
| 701 | |
| 702 | bool IsAttribute = true; |
| 703 | while (Tok.isNot(tok::r_square)) { |
| 704 | if (Tok.is(tok::comma)) { |
| 705 | |
| 706 | return CAK_AttributeSpecifier; |
| 707 | } |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | SourceLocation Loc; |
| 715 | if (!TryParseCXX11AttributeIdentifier(Loc)) { |
| 716 | IsAttribute = false; |
| 717 | break; |
| 718 | } |
| 719 | if (Tok.is(tok::coloncolon)) { |
| 720 | ConsumeToken(); |
| 721 | if (!TryParseCXX11AttributeIdentifier(Loc)) { |
| 722 | IsAttribute = false; |
| 723 | break; |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | |
| 728 | if (Tok.is(tok::l_paren)) { |
| 729 | ConsumeParen(); |
| 730 | if (!SkipUntil(tok::r_paren)) { |
| 731 | IsAttribute = false; |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | TryConsumeToken(tok::ellipsis); |
| 737 | |
| 738 | if (!TryConsumeToken(tok::comma)) |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | |
| 743 | if (IsAttribute) { |
| 744 | if (Tok.is(tok::r_square)) { |
| 745 | ConsumeBracket(); |
| 746 | IsAttribute = Tok.is(tok::r_square); |
| 747 | } else { |
| 748 | IsAttribute = false; |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | if (IsAttribute) |
| 753 | |
| 754 | return CAK_AttributeSpecifier; |
| 755 | |
| 756 | |
| 757 | return CAK_NotAttributeSpecifier; |
| 758 | } |
| 759 | |
| 760 | Parser::TPResult Parser::TryParsePtrOperatorSeq() { |
| 761 | while (true) { |
| 762 | if (Tok.isOneOf(tok::coloncolon, tok::identifier)) |
| 763 | if (TryAnnotateCXXScopeToken(true)) |
| 764 | return TPResult::Error; |
| 765 | |
| 766 | if (Tok.isOneOf(tok::star, tok::amp, tok::caret, tok::ampamp) || |
| 767 | (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) { |
| 768 | |
| 769 | ConsumeAnyToken(); |
| 770 | while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw_restrict, |
| 771 | tok::kw__Nonnull, tok::kw__Nullable, |
| 772 | tok::kw__Null_unspecified)) |
| 773 | ConsumeToken(); |
| 774 | } else { |
| 775 | return TPResult::True; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | Parser::TPResult Parser::TryParseOperatorId() { |
| 799 | assert(Tok.is(tok::kw_operator)); |
| 800 | ConsumeToken(); |
| 801 | |
| 802 | |
| 803 | switch (Tok.getKind()) { |
| 804 | case tok::kw_new: case tok::kw_delete: |
| 805 | ConsumeToken(); |
| 806 | if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) { |
| 807 | ConsumeBracket(); |
| 808 | ConsumeBracket(); |
| 809 | } |
| 810 | return TPResult::True; |
| 811 | |
| 812 | #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemOnly) \ |
| 813 | case tok::Token: |
| 814 | #define OVERLOADED_OPERATOR_MULTI(Name, Spelling, Unary, Binary, MemOnly) |
| 815 | #include "clang/Basic/OperatorKinds.def" |
| 816 | ConsumeToken(); |
| 817 | return TPResult::True; |
| 818 | |
| 819 | case tok::l_square: |
| 820 | if (NextToken().is(tok::r_square)) { |
| 821 | ConsumeBracket(); |
| 822 | ConsumeBracket(); |
| 823 | return TPResult::True; |
| 824 | } |
| 825 | break; |
| 826 | |
| 827 | case tok::l_paren: |
| 828 | if (NextToken().is(tok::r_paren)) { |
| 829 | ConsumeParen(); |
| 830 | ConsumeParen(); |
| 831 | return TPResult::True; |
| 832 | } |
| 833 | break; |
| 834 | |
| 835 | default: |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | |
| 840 | if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) { |
| 841 | bool FoundUDSuffix = false; |
| 842 | do { |
| 843 | FoundUDSuffix |= Tok.hasUDSuffix(); |
| 844 | ConsumeStringToken(); |
| 845 | } while (isTokenStringLiteral()); |
| 846 | |
| 847 | if (!FoundUDSuffix) { |
| 848 | if (Tok.is(tok::identifier)) |
| 849 | ConsumeToken(); |
| 850 | else |
| 851 | return TPResult::Error; |
| 852 | } |
| 853 | return TPResult::True; |
| 854 | } |
| 855 | |
| 856 | |
| 857 | bool AnyDeclSpecifiers = false; |
| 858 | while (true) { |
| 859 | TPResult TPR = isCXXDeclarationSpecifier(); |
| 860 | if (TPR == TPResult::Error) |
| 861 | return TPR; |
| 862 | if (TPR == TPResult::False) { |
| 863 | if (!AnyDeclSpecifiers) |
| 864 | return TPResult::Error; |
| 865 | break; |
| 866 | } |
| 867 | if (TryConsumeDeclarationSpecifier() == TPResult::Error) |
| 868 | return TPResult::Error; |
| 869 | AnyDeclSpecifiers = true; |
| 870 | } |
| 871 | return TryParsePtrOperatorSeq(); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | Parser::TPResult Parser::TryParseDeclarator(bool mayBeAbstract, |
| 928 | bool mayHaveIdentifier, |
| 929 | bool mayHaveDirectInit) { |
| 930 | |
| 931 | |
| 932 | |
| 933 | if (TryParsePtrOperatorSeq() == TPResult::Error) |
| 934 | return TPResult::Error; |
| 935 | |
| 936 | |
| 937 | |
| 938 | if (Tok.is(tok::ellipsis)) |
| 939 | ConsumeToken(); |
| 940 | |
| 941 | if ((Tok.isOneOf(tok::identifier, tok::kw_operator) || |
| 942 | (Tok.is(tok::annot_cxxscope) && (NextToken().is(tok::identifier) || |
| 943 | NextToken().is(tok::kw_operator)))) && |
| 944 | mayHaveIdentifier) { |
| 945 | |
| 946 | if (Tok.is(tok::annot_cxxscope)) |
| 947 | ConsumeAnnotationToken(); |
| 948 | else if (Tok.is(tok::identifier)) |
| 949 | TentativelyDeclaredIdentifiers.push_back(Tok.getIdentifierInfo()); |
| 950 | if (Tok.is(tok::kw_operator)) { |
| 951 | if (TryParseOperatorId() == TPResult::Error) |
| 952 | return TPResult::Error; |
| 953 | } else |
| 954 | ConsumeToken(); |
| 955 | } else if (Tok.is(tok::l_paren)) { |
| 956 | ConsumeParen(); |
| 957 | if (mayBeAbstract && |
| 958 | (Tok.is(tok::r_paren) || |
| 959 | |
| 960 | (Tok.is(tok::ellipsis) && NextToken().is(tok::r_paren)) || |
| 961 | isDeclarationSpecifier())) { |
| 962 | |
| 963 | |
| 964 | TPResult TPR = TryParseFunctionDeclarator(); |
| 965 | if (TPR != TPResult::Ambiguous) |
| 966 | return TPR; |
| 967 | } else { |
| 968 | |
| 969 | |
| 970 | |
| 971 | if (Tok.isOneOf(tok::kw___attribute, tok::kw___declspec, tok::kw___cdecl, |
| 972 | tok::kw___stdcall, tok::kw___fastcall, tok::kw___thiscall, |
| 973 | tok::kw___regcall, tok::kw___vectorcall)) |
| 974 | return TPResult::True; |
| 975 | TPResult TPR = TryParseDeclarator(mayBeAbstract, mayHaveIdentifier); |
| 976 | if (TPR != TPResult::Ambiguous) |
| 977 | return TPR; |
| 978 | if (Tok.isNot(tok::r_paren)) |
| 979 | return TPResult::False; |
| 980 | ConsumeParen(); |
| 981 | } |
| 982 | } else if (!mayBeAbstract) { |
| 983 | return TPResult::False; |
| 984 | } |
| 985 | |
| 986 | if (mayHaveDirectInit) |
| 987 | return TPResult::Ambiguous; |
| 988 | |
| 989 | while (1) { |
| 990 | TPResult TPR(TPResult::Ambiguous); |
| 991 | |
| 992 | if (Tok.is(tok::l_paren)) { |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | if (!mayBeAbstract && !isCXXFunctionDeclarator()) |
| 998 | break; |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | ConsumeParen(); |
| 1003 | TPR = TryParseFunctionDeclarator(); |
| 1004 | } else if (Tok.is(tok::l_square)) { |
| 1005 | |
| 1006 | |
| 1007 | TPR = TryParseBracketDeclarator(); |
| 1008 | } else { |
| 1009 | break; |
| 1010 | } |
| 1011 | |
| 1012 | if (TPR != TPResult::Ambiguous) |
| 1013 | return TPR; |
| 1014 | } |
| 1015 | |
| 1016 | return TPResult::Ambiguous; |
| 1017 | } |
| 1018 | |
| 1019 | Parser::TPResult |
| 1020 | Parser::isExpressionOrTypeSpecifierSimple(tok::TokenKind Kind) { |
| 1021 | switch (Kind) { |
| 1022 | |
| 1023 | case tok::numeric_constant: |
| 1024 | case tok::char_constant: |
| 1025 | case tok::wide_char_constant: |
| 1026 | case tok::utf8_char_constant: |
| 1027 | case tok::utf16_char_constant: |
| 1028 | case tok::utf32_char_constant: |
| 1029 | case tok::string_literal: |
| 1030 | case tok::wide_string_literal: |
| 1031 | case tok::utf8_string_literal: |
| 1032 | case tok::utf16_string_literal: |
| 1033 | case tok::utf32_string_literal: |
| 1034 | case tok::l_square: |
| 1035 | case tok::l_paren: |
| 1036 | case tok::amp: |
| 1037 | case tok::ampamp: |
| 1038 | case tok::star: |
| 1039 | case tok::plus: |
| 1040 | case tok::plusplus: |
| 1041 | case tok::minus: |
| 1042 | case tok::minusminus: |
| 1043 | case tok::tilde: |
| 1044 | case tok::exclaim: |
| 1045 | case tok::kw_sizeof: |
| 1046 | case tok::kw___func__: |
| 1047 | case tok::kw_const_cast: |
| 1048 | case tok::kw_delete: |
| 1049 | case tok::kw_dynamic_cast: |
| 1050 | case tok::kw_false: |
| 1051 | case tok::kw_new: |
| 1052 | case tok::kw_operator: |
| 1053 | case tok::kw_reinterpret_cast: |
| 1054 | case tok::kw_static_cast: |
| 1055 | case tok::kw_this: |
| 1056 | case tok::kw_throw: |
| 1057 | case tok::kw_true: |
| 1058 | case tok::kw_typeid: |
| 1059 | case tok::kw_alignof: |
| 1060 | case tok::kw_noexcept: |
| 1061 | case tok::kw_nullptr: |
| 1062 | case tok::kw__Alignof: |
| 1063 | case tok::kw___null: |
| 1064 | case tok::kw___alignof: |
| 1065 | case tok::kw___builtin_choose_expr: |
| 1066 | case tok::kw___builtin_offsetof: |
| 1067 | case tok::kw___builtin_va_arg: |
| 1068 | case tok::kw___imag: |
| 1069 | case tok::kw___real: |
| 1070 | case tok::kw___FUNCTION__: |
| 1071 | case tok::kw___FUNCDNAME__: |
| 1072 | case tok::kw___FUNCSIG__: |
| 1073 | case tok::kw_L__FUNCTION__: |
| 1074 | case tok::kw_L__FUNCSIG__: |
| 1075 | case tok::kw___PRETTY_FUNCTION__: |
| 1076 | case tok::kw___uuidof: |
| 1077 | #define TYPE_TRAIT(N,Spelling,K) \ |
| 1078 | case tok::kw_##Spelling: |
| 1079 | #include "clang/Basic/TokenKinds.def" |
| 1080 | return TPResult::True; |
| 1081 | |
| 1082 | |
| 1083 | case tok::kw_char: |
| 1084 | case tok::kw_const: |
| 1085 | case tok::kw_double: |
| 1086 | case tok::kw__Float16: |
| 1087 | case tok::kw___float128: |
| 1088 | case tok::kw_enum: |
| 1089 | case tok::kw_half: |
| 1090 | case tok::kw_float: |
| 1091 | case tok::kw_int: |
| 1092 | case tok::kw_long: |
| 1093 | case tok::kw___int64: |
| 1094 | case tok::kw___int128: |
| 1095 | case tok::kw_restrict: |
| 1096 | case tok::kw_short: |
| 1097 | case tok::kw_signed: |
| 1098 | case tok::kw_struct: |
| 1099 | case tok::kw_union: |
| 1100 | case tok::kw_unsigned: |
| 1101 | case tok::kw_void: |
| 1102 | case tok::kw_volatile: |
| 1103 | case tok::kw__Bool: |
| 1104 | case tok::kw__Complex: |
| 1105 | case tok::kw_class: |
| 1106 | case tok::kw_typename: |
| 1107 | case tok::kw_wchar_t: |
| 1108 | case tok::kw_char8_t: |
| 1109 | case tok::kw_char16_t: |
| 1110 | case tok::kw_char32_t: |
| 1111 | case tok::kw__Decimal32: |
| 1112 | case tok::kw__Decimal64: |
| 1113 | case tok::kw__Decimal128: |
| 1114 | case tok::kw___interface: |
| 1115 | case tok::kw___thread: |
| 1116 | case tok::kw_thread_local: |
| 1117 | case tok::kw__Thread_local: |
| 1118 | case tok::kw_typeof: |
| 1119 | case tok::kw___underlying_type: |
| 1120 | case tok::kw___cdecl: |
| 1121 | case tok::kw___stdcall: |
| 1122 | case tok::kw___fastcall: |
| 1123 | case tok::kw___thiscall: |
| 1124 | case tok::kw___regcall: |
| 1125 | case tok::kw___vectorcall: |
| 1126 | case tok::kw___unaligned: |
| 1127 | case tok::kw___vector: |
| 1128 | case tok::kw___pixel: |
| 1129 | case tok::kw___bool: |
| 1130 | case tok::kw__Atomic: |
| 1131 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 1132 | #include "clang/Basic/OpenCLImageTypes.def" |
| 1133 | case tok::kw___unknown_anytype: |
| 1134 | return TPResult::False; |
| 1135 | |
| 1136 | default: |
| 1137 | break; |
| 1138 | } |
| 1139 | |
| 1140 | return TPResult::Ambiguous; |
| 1141 | } |
| 1142 | |
| 1143 | bool Parser::isTentativelyDeclared(IdentifierInfo *II) { |
| 1144 | return std::find(TentativelyDeclaredIdentifiers.begin(), |
| 1145 | TentativelyDeclaredIdentifiers.end(), II) |
| 1146 | != TentativelyDeclaredIdentifiers.end(); |
| 1147 | } |
| 1148 | |
| 1149 | namespace { |
| 1150 | class TentativeParseCCC final : public CorrectionCandidateCallback { |
| 1151 | public: |
| 1152 | TentativeParseCCC(const Token &Next) { |
| 1153 | WantRemainingKeywords = false; |
| 1154 | WantTypeSpecifiers = Next.isOneOf(tok::l_paren, tok::r_paren, tok::greater, |
| 1155 | tok::l_brace, tok::identifier); |
| 1156 | } |
| 1157 | |
| 1158 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1159 | |
| 1160 | |
| 1161 | if (Candidate.isResolved() && !Candidate.isKeyword() && |
| 1162 | llvm::all_of(Candidate, |
| 1163 | [](NamedDecl *ND) { return ND->isCXXInstanceMember(); })) |
| 1164 | return false; |
| 1165 | |
| 1166 | return CorrectionCandidateCallback::ValidateCandidate(Candidate); |
| 1167 | } |
| 1168 | |
| 1169 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
| 1170 | return llvm::make_unique<TentativeParseCCC>(*this); |
| 1171 | } |
| 1172 | }; |
| 1173 | } |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | Parser::TPResult |
| 1281 | Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult, |
| 1282 | bool *HasMissingTypename) { |
| 1283 | switch (Tok.getKind()) { |
| 1284 | case tok::identifier: { |
| 1285 | |
| 1286 | |
| 1287 | if (TryAltiVecVectorToken()) |
| 1288 | return TPResult::True; |
| 1289 | |
| 1290 | const Token &Next = NextToken(); |
| 1291 | |
| 1292 | if (!getLangOpts().ObjC && Next.is(tok::identifier)) |
| 1293 | return TPResult::True; |
| 1294 | |
| 1295 | if (Next.isNot(tok::coloncolon) && Next.isNot(tok::less)) { |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | TentativeParseCCC CCC(Next); |
| 1301 | switch (TryAnnotateName(false , &CCC)) { |
| 1302 | case ANK_Error: |
| 1303 | return TPResult::Error; |
| 1304 | case ANK_TentativeDecl: |
| 1305 | return TPResult::False; |
| 1306 | case ANK_TemplateName: |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | if (getLangOpts().CPlusPlus17) { |
| 1312 | if (TryAnnotateTypeOrScopeToken()) |
| 1313 | return TPResult::Error; |
| 1314 | if (Tok.isNot(tok::identifier)) |
| 1315 | break; |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | return GreaterThanIsOperator ? TPResult::True : TPResult::False; |
| 1321 | case ANK_Unresolved: |
| 1322 | return HasMissingTypename ? TPResult::Ambiguous : TPResult::False; |
| 1323 | case ANK_Success: |
| 1324 | break; |
| 1325 | } |
| 1326 | (0) . __assert_fail ("Tok.isNot(tok..identifier) && \"TryAnnotateName succeeded without producing an annotation\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 1327, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isNot(tok::identifier) && |
| 1327 | (0) . __assert_fail ("Tok.isNot(tok..identifier) && \"TryAnnotateName succeeded without producing an annotation\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 1327, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "TryAnnotateName succeeded without producing an annotation"); |
| 1328 | } else { |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | if (TryAnnotateTypeOrScopeToken()) |
| 1334 | return TPResult::Error; |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | if (Tok.is(tok::identifier)) |
| 1339 | return TPResult::False; |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename); |
| 1344 | } |
| 1345 | |
| 1346 | case tok::kw_typename: |
| 1347 | |
| 1348 | |
| 1349 | if (TryAnnotateTypeOrScopeToken()) |
| 1350 | return TPResult::Error; |
| 1351 | return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename); |
| 1352 | |
| 1353 | case tok::coloncolon: { |
| 1354 | const Token &Next = NextToken(); |
| 1355 | if (Next.isOneOf(tok::kw_new, |
| 1356 | tok::kw_delete)) |
| 1357 | return TPResult::False; |
| 1358 | LLVM_FALLTHROUGH; |
| 1359 | } |
| 1360 | case tok::kw___super: |
| 1361 | case tok::kw_decltype: |
| 1362 | |
| 1363 | |
| 1364 | if (TryAnnotateTypeOrScopeToken()) |
| 1365 | return TPResult::Error; |
| 1366 | return isCXXDeclarationSpecifier(BracedCastResult, HasMissingTypename); |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | case tok::kw_friend: |
| 1376 | case tok::kw_typedef: |
| 1377 | case tok::kw_constexpr: |
| 1378 | |
| 1379 | case tok::kw_register: |
| 1380 | case tok::kw_static: |
| 1381 | case tok::kw_extern: |
| 1382 | case tok::kw_mutable: |
| 1383 | case tok::kw_auto: |
| 1384 | case tok::kw___thread: |
| 1385 | case tok::kw_thread_local: |
| 1386 | case tok::kw__Thread_local: |
| 1387 | |
| 1388 | case tok::kw_inline: |
| 1389 | case tok::kw_virtual: |
| 1390 | case tok::kw_explicit: |
| 1391 | |
| 1392 | |
| 1393 | case tok::kw___module_private__: |
| 1394 | |
| 1395 | |
| 1396 | case tok::kw___unknown_anytype: |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | case tok::kw_class: |
| 1409 | case tok::kw_struct: |
| 1410 | case tok::kw_union: |
| 1411 | case tok::kw___interface: |
| 1412 | |
| 1413 | case tok::kw_enum: |
| 1414 | |
| 1415 | case tok::kw_const: |
| 1416 | case tok::kw_volatile: |
| 1417 | return TPResult::True; |
| 1418 | |
| 1419 | |
| 1420 | case tok::kw_private: |
| 1421 | if (!getLangOpts().OpenCL) |
| 1422 | return TPResult::False; |
| 1423 | LLVM_FALLTHROUGH; |
| 1424 | case tok::kw___private: |
| 1425 | case tok::kw___local: |
| 1426 | case tok::kw___global: |
| 1427 | case tok::kw___constant: |
| 1428 | case tok::kw___generic: |
| 1429 | |
| 1430 | case tok::kw___read_only: |
| 1431 | case tok::kw___write_only: |
| 1432 | case tok::kw___read_write: |
| 1433 | |
| 1434 | |
| 1435 | case tok::kw_restrict: |
| 1436 | case tok::kw__Complex: |
| 1437 | case tok::kw___attribute: |
| 1438 | case tok::kw___auto_type: |
| 1439 | return TPResult::True; |
| 1440 | |
| 1441 | |
| 1442 | case tok::kw___declspec: |
| 1443 | case tok::kw___cdecl: |
| 1444 | case tok::kw___stdcall: |
| 1445 | case tok::kw___fastcall: |
| 1446 | case tok::kw___thiscall: |
| 1447 | case tok::kw___regcall: |
| 1448 | case tok::kw___vectorcall: |
| 1449 | case tok::kw___w64: |
| 1450 | case tok::kw___sptr: |
| 1451 | case tok::kw___uptr: |
| 1452 | case tok::kw___ptr64: |
| 1453 | case tok::kw___ptr32: |
| 1454 | case tok::kw___forceinline: |
| 1455 | case tok::kw___unaligned: |
| 1456 | case tok::kw__Nonnull: |
| 1457 | case tok::kw__Nullable: |
| 1458 | case tok::kw__Null_unspecified: |
| 1459 | case tok::kw___kindof: |
| 1460 | return TPResult::True; |
| 1461 | |
| 1462 | |
| 1463 | case tok::kw___pascal: |
| 1464 | return TPResult::True; |
| 1465 | |
| 1466 | |
| 1467 | case tok::kw___vector: |
| 1468 | return TPResult::True; |
| 1469 | |
| 1470 | case tok::annot_template_id: { |
| 1471 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 1472 | if (TemplateId->Kind != TNK_Type_template) |
| 1473 | return TPResult::False; |
| 1474 | CXXScopeSpec SS; |
| 1475 | AnnotateTemplateIdTokenAsType(); |
| 1476 | assert(Tok.is(tok::annot_typename)); |
| 1477 | goto case_typename; |
| 1478 | } |
| 1479 | |
| 1480 | case tok::annot_cxxscope: |
| 1481 | |
| 1482 | if (TryAnnotateTypeOrScopeToken()) |
| 1483 | return TPResult::Error; |
| 1484 | if (!Tok.is(tok::annot_typename)) { |
| 1485 | |
| 1486 | |
| 1487 | if (Tok.is(tok::annot_cxxscope) && NextToken().is(tok::identifier)) { |
| 1488 | CXXScopeSpec SS; |
| 1489 | Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), |
| 1490 | Tok.getAnnotationRange(), |
| 1491 | SS); |
| 1492 | if (SS.getScopeRep() && SS.getScopeRep()->isDependent()) { |
| 1493 | RevertingTentativeParsingAction PA(*this); |
| 1494 | ConsumeAnnotationToken(); |
| 1495 | ConsumeToken(); |
| 1496 | bool isIdentifier = Tok.is(tok::identifier); |
| 1497 | TPResult TPR = TPResult::False; |
| 1498 | if (!isIdentifier) |
| 1499 | TPR = isCXXDeclarationSpecifier(BracedCastResult, |
| 1500 | HasMissingTypename); |
| 1501 | |
| 1502 | if (isIdentifier || |
| 1503 | TPR == TPResult::True || TPR == TPResult::Error) |
| 1504 | return TPResult::Error; |
| 1505 | |
| 1506 | if (HasMissingTypename) { |
| 1507 | |
| 1508 | |
| 1509 | *HasMissingTypename = true; |
| 1510 | return TPResult::Ambiguous; |
| 1511 | } else { |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | if (getLangOpts().MSVCCompat) { |
| 1516 | if (((Tok.is(tok::amp) || Tok.is(tok::star)) && |
| 1517 | (NextToken().is(tok::r_paren) || |
| 1518 | NextToken().is(tok::greater))) || |
| 1519 | (Tok.is(tok::ampamp) && NextToken().is(tok::greater))) |
| 1520 | return TPResult::True; |
| 1521 | } |
| 1522 | } |
| 1523 | } else { |
| 1524 | |
| 1525 | |
| 1526 | switch (TryAnnotateName(false )) { |
| 1527 | case ANK_Error: |
| 1528 | return TPResult::Error; |
| 1529 | case ANK_TentativeDecl: |
| 1530 | return TPResult::False; |
| 1531 | case ANK_TemplateName: |
| 1532 | |
| 1533 | |
| 1534 | if (getLangOpts().CPlusPlus17) { |
| 1535 | if (TryAnnotateTypeOrScopeToken()) |
| 1536 | return TPResult::Error; |
| 1537 | if (Tok.isNot(tok::identifier)) |
| 1538 | break; |
| 1539 | } |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | return (getLangOpts().CPlusPlus17 || GreaterThanIsOperator) |
| 1545 | ? TPResult::True |
| 1546 | : TPResult::False; |
| 1547 | case ANK_Unresolved: |
| 1548 | return HasMissingTypename ? TPResult::Ambiguous |
| 1549 | : TPResult::False; |
| 1550 | case ANK_Success: |
| 1551 | break; |
| 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | assert(Tok.isNot(tok::annot_cxxscope) || |
| 1556 | NextToken().isNot(tok::identifier)); |
| 1557 | return isCXXDeclarationSpecifier(BracedCastResult, |
| 1558 | HasMissingTypename); |
| 1559 | } |
| 1560 | } |
| 1561 | return TPResult::False; |
| 1562 | } |
| 1563 | |
| 1564 | LLVM_FALLTHROUGH; |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | |
| 1570 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | case tok::annot_typename: |
| 1585 | case_typename: |
| 1586 | |
| 1587 | if (getLangOpts().ObjC && NextToken().is(tok::less)) { |
| 1588 | |
| 1589 | RevertingTentativeParsingAction PA(*this); |
| 1590 | ConsumeAnyToken(); |
| 1591 | |
| 1592 | TPResult TPR = TryParseProtocolQualifiers(); |
| 1593 | bool isFollowedByParen = Tok.is(tok::l_paren); |
| 1594 | bool isFollowedByBrace = Tok.is(tok::l_brace); |
| 1595 | |
| 1596 | if (TPR == TPResult::Error) |
| 1597 | return TPResult::Error; |
| 1598 | |
| 1599 | if (isFollowedByParen) |
| 1600 | return TPResult::Ambiguous; |
| 1601 | |
| 1602 | if (getLangOpts().CPlusPlus11 && isFollowedByBrace) |
| 1603 | return BracedCastResult; |
| 1604 | |
| 1605 | return TPResult::True; |
| 1606 | } |
| 1607 | LLVM_FALLTHROUGH; |
| 1608 | |
| 1609 | case tok::kw_char: |
| 1610 | case tok::kw_wchar_t: |
| 1611 | case tok::kw_char8_t: |
| 1612 | case tok::kw_char16_t: |
| 1613 | case tok::kw_char32_t: |
| 1614 | case tok::kw_bool: |
| 1615 | case tok::kw_short: |
| 1616 | case tok::kw_int: |
| 1617 | case tok::kw_long: |
| 1618 | case tok::kw___int64: |
| 1619 | case tok::kw___int128: |
| 1620 | case tok::kw_signed: |
| 1621 | case tok::kw_unsigned: |
| 1622 | case tok::kw_half: |
| 1623 | case tok::kw_float: |
| 1624 | case tok::kw_double: |
| 1625 | case tok::kw__Float16: |
| 1626 | case tok::kw___float128: |
| 1627 | case tok::kw_void: |
| 1628 | case tok::annot_decltype: |
| 1629 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 1630 | #include "clang/Basic/OpenCLImageTypes.def" |
| 1631 | if (NextToken().is(tok::l_paren)) |
| 1632 | return TPResult::Ambiguous; |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | if (getLangOpts().CPlusPlus11 && NextToken().is(tok::l_brace)) |
| 1641 | return BracedCastResult; |
| 1642 | |
| 1643 | if (isStartOfObjCClassMessageMissingOpenBracket()) |
| 1644 | return TPResult::False; |
| 1645 | |
| 1646 | return TPResult::True; |
| 1647 | |
| 1648 | |
| 1649 | case tok::kw_typeof: { |
| 1650 | if (NextToken().isNot(tok::l_paren)) |
| 1651 | return TPResult::True; |
| 1652 | |
| 1653 | RevertingTentativeParsingAction PA(*this); |
| 1654 | |
| 1655 | TPResult TPR = TryParseTypeofSpecifier(); |
| 1656 | bool isFollowedByParen = Tok.is(tok::l_paren); |
| 1657 | bool isFollowedByBrace = Tok.is(tok::l_brace); |
| 1658 | |
| 1659 | if (TPR == TPResult::Error) |
| 1660 | return TPResult::Error; |
| 1661 | |
| 1662 | if (isFollowedByParen) |
| 1663 | return TPResult::Ambiguous; |
| 1664 | |
| 1665 | if (getLangOpts().CPlusPlus11 && isFollowedByBrace) |
| 1666 | return BracedCastResult; |
| 1667 | |
| 1668 | return TPResult::True; |
| 1669 | } |
| 1670 | |
| 1671 | |
| 1672 | case tok::kw___underlying_type: |
| 1673 | return TPResult::True; |
| 1674 | |
| 1675 | |
| 1676 | case tok::kw__Atomic: |
| 1677 | return TPResult::True; |
| 1678 | |
| 1679 | default: |
| 1680 | return TPResult::False; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | bool Parser::isCXXDeclarationSpecifierAType() { |
| 1685 | switch (Tok.getKind()) { |
| 1686 | |
| 1687 | case tok::annot_decltype: |
| 1688 | case tok::annot_template_id: |
| 1689 | case tok::annot_typename: |
| 1690 | case tok::kw_typeof: |
| 1691 | case tok::kw___underlying_type: |
| 1692 | return true; |
| 1693 | |
| 1694 | |
| 1695 | case tok::kw_class: |
| 1696 | case tok::kw_struct: |
| 1697 | case tok::kw_union: |
| 1698 | case tok::kw___interface: |
| 1699 | case tok::kw_enum: |
| 1700 | return true; |
| 1701 | |
| 1702 | |
| 1703 | case tok::kw_char: |
| 1704 | case tok::kw_wchar_t: |
| 1705 | case tok::kw_char8_t: |
| 1706 | case tok::kw_char16_t: |
| 1707 | case tok::kw_char32_t: |
| 1708 | case tok::kw_bool: |
| 1709 | case tok::kw_short: |
| 1710 | case tok::kw_int: |
| 1711 | case tok::kw_long: |
| 1712 | case tok::kw___int64: |
| 1713 | case tok::kw___int128: |
| 1714 | case tok::kw_signed: |
| 1715 | case tok::kw_unsigned: |
| 1716 | case tok::kw_half: |
| 1717 | case tok::kw_float: |
| 1718 | case tok::kw_double: |
| 1719 | case tok::kw__Float16: |
| 1720 | case tok::kw___float128: |
| 1721 | case tok::kw_void: |
| 1722 | case tok::kw___unknown_anytype: |
| 1723 | case tok::kw___auto_type: |
| 1724 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 1725 | #include "clang/Basic/OpenCLImageTypes.def" |
| 1726 | return true; |
| 1727 | |
| 1728 | case tok::kw_auto: |
| 1729 | return getLangOpts().CPlusPlus11; |
| 1730 | |
| 1731 | case tok::kw__Atomic: |
| 1732 | |
| 1733 | return NextToken().is(tok::l_paren); |
| 1734 | |
| 1735 | default: |
| 1736 | return false; |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | Parser::TPResult Parser::TryParseTypeofSpecifier() { |
| 1745 | (0) . __assert_fail ("Tok.is(tok..kw_typeof) && \"Expected 'typeof'!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 1745, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw_typeof) && "Expected 'typeof'!"); |
| 1746 | ConsumeToken(); |
| 1747 | |
| 1748 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Expected '('\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 1748, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Expected '('"); |
| 1749 | |
| 1750 | ConsumeParen(); |
| 1751 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
| 1752 | return TPResult::Error; |
| 1753 | |
| 1754 | return TPResult::Ambiguous; |
| 1755 | } |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | Parser::TPResult Parser::TryParseProtocolQualifiers() { |
| 1760 | (0) . __assert_fail ("Tok.is(tok..less) && \"Expected '<' for qualifier list\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseTentative.cpp", 1760, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::less) && "Expected '<' for qualifier list"); |
| 1761 | ConsumeToken(); |
| 1762 | do { |
| 1763 | if (Tok.isNot(tok::identifier)) |
| 1764 | return TPResult::Error; |
| 1765 | ConsumeToken(); |
| 1766 | |
| 1767 | if (Tok.is(tok::comma)) { |
| 1768 | ConsumeToken(); |
| 1769 | continue; |
| 1770 | } |
| 1771 | |
| 1772 | if (Tok.is(tok::greater)) { |
| 1773 | ConsumeToken(); |
| 1774 | return TPResult::Ambiguous; |
| 1775 | } |
| 1776 | } while (false); |
| 1777 | |
| 1778 | return TPResult::Error; |
| 1779 | } |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | bool Parser::isCXXFunctionDeclarator(bool *IsAmbiguous) { |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | RevertingTentativeParsingAction PA(*this); |
| 1803 | |
| 1804 | ConsumeParen(); |
| 1805 | bool InvalidAsDeclaration = false; |
| 1806 | TPResult TPR = TryParseParameterDeclarationClause(&InvalidAsDeclaration); |
| 1807 | if (TPR == TPResult::Ambiguous) { |
| 1808 | if (Tok.isNot(tok::r_paren)) |
| 1809 | TPR = TPResult::False; |
| 1810 | else { |
| 1811 | const Token &Next = NextToken(); |
| 1812 | if (Next.isOneOf(tok::amp, tok::ampamp, tok::kw_const, tok::kw_volatile, |
| 1813 | tok::kw_throw, tok::kw_noexcept, tok::l_square, |
| 1814 | tok::l_brace, tok::kw_try, tok::equal, tok::arrow) || |
| 1815 | isCXX11VirtSpecifier(Next)) |
| 1816 | |
| 1817 | |
| 1818 | |
| 1819 | TPR = TPResult::True; |
| 1820 | else if (InvalidAsDeclaration) |
| 1821 | |
| 1822 | TPR = TPResult::False; |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | if (IsAmbiguous && TPR == TPResult::Ambiguous) |
| 1827 | *IsAmbiguous = true; |
| 1828 | |
| 1829 | |
| 1830 | return TPR != TPResult::False; |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | |
| 1846 | |
| 1847 | |
| 1848 | |
| 1849 | |
| 1850 | Parser::TPResult |
| 1851 | Parser::TryParseParameterDeclarationClause(bool *InvalidAsDeclaration, |
| 1852 | bool VersusTemplateArgument) { |
| 1853 | |
| 1854 | if (Tok.is(tok::r_paren)) |
| 1855 | return TPResult::Ambiguous; |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | while (1) { |
| 1865 | |
| 1866 | if (Tok.is(tok::ellipsis)) { |
| 1867 | ConsumeToken(); |
| 1868 | if (Tok.is(tok::r_paren)) |
| 1869 | return TPResult::True; |
| 1870 | else |
| 1871 | return TPResult::False; |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | if (isCXX11AttributeSpecifier(, |
| 1876 | )) |
| 1877 | return TPResult::True; |
| 1878 | |
| 1879 | ParsedAttributes attrs(AttrFactory); |
| 1880 | MaybeParseMicrosoftAttributes(attrs); |
| 1881 | |
| 1882 | |
| 1883 | |
| 1884 | |
| 1885 | TPResult TPR = isCXXDeclarationSpecifier(TPResult::False, |
| 1886 | InvalidAsDeclaration); |
| 1887 | |
| 1888 | if (VersusTemplateArgument && TPR == TPResult::True) { |
| 1889 | |
| 1890 | |
| 1891 | bool SeenType = false; |
| 1892 | do { |
| 1893 | SeenType |= isCXXDeclarationSpecifierAType(); |
| 1894 | if (TryConsumeDeclarationSpecifier() == TPResult::Error) |
| 1895 | return TPResult::Error; |
| 1896 | |
| 1897 | |
| 1898 | if (SeenType && Tok.is(tok::identifier)) |
| 1899 | return TPResult::True; |
| 1900 | |
| 1901 | TPR = isCXXDeclarationSpecifier(TPResult::False, |
| 1902 | InvalidAsDeclaration); |
| 1903 | if (TPR == TPResult::Error) |
| 1904 | return TPR; |
| 1905 | } while (TPR != TPResult::False); |
| 1906 | } else if (TPR == TPResult::Ambiguous) { |
| 1907 | |
| 1908 | if (TryConsumeDeclarationSpecifier() == TPResult::Error) |
| 1909 | return TPResult::Error; |
| 1910 | } else |
| 1911 | return TPR; |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | TPR = TryParseDeclarator(true); |
| 1916 | if (TPR != TPResult::Ambiguous) |
| 1917 | return TPR; |
| 1918 | |
| 1919 | |
| 1920 | if (Tok.is(tok::kw___attribute)) |
| 1921 | return TPResult::True; |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | if (VersusTemplateArgument) |
| 1934 | return Tok.isOneOf(tok::equal, tok::r_paren) ? TPResult::True |
| 1935 | : TPResult::False; |
| 1936 | |
| 1937 | if (Tok.is(tok::equal)) { |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | if (!SkipUntil(tok::comma, tok::r_paren, StopAtSemi | StopBeforeMatch)) |
| 1942 | return TPResult::Error; |
| 1943 | } |
| 1944 | |
| 1945 | if (Tok.is(tok::ellipsis)) { |
| 1946 | ConsumeToken(); |
| 1947 | if (Tok.is(tok::r_paren)) |
| 1948 | return TPResult::True; |
| 1949 | else |
| 1950 | return TPResult::False; |
| 1951 | } |
| 1952 | |
| 1953 | if (!TryConsumeToken(tok::comma)) |
| 1954 | break; |
| 1955 | } |
| 1956 | |
| 1957 | return TPResult::Ambiguous; |
| 1958 | } |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | |
| 1972 | Parser::TPResult Parser::TryParseFunctionDeclarator() { |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | TPResult TPR = TryParseParameterDeclarationClause(); |
| 1977 | if (TPR == TPResult::Ambiguous && Tok.isNot(tok::r_paren)) |
| 1978 | TPR = TPResult::False; |
| 1979 | |
| 1980 | if (TPR == TPResult::False || TPR == TPResult::Error) |
| 1981 | return TPR; |
| 1982 | |
| 1983 | |
| 1984 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
| 1985 | return TPResult::Error; |
| 1986 | |
| 1987 | |
| 1988 | while (Tok.isOneOf(tok::kw_const, tok::kw_volatile, tok::kw___unaligned, |
| 1989 | tok::kw_restrict)) |
| 1990 | ConsumeToken(); |
| 1991 | |
| 1992 | |
| 1993 | if (Tok.isOneOf(tok::amp, tok::ampamp)) |
| 1994 | ConsumeToken(); |
| 1995 | |
| 1996 | |
| 1997 | if (Tok.is(tok::kw_throw)) { |
| 1998 | ConsumeToken(); |
| 1999 | if (Tok.isNot(tok::l_paren)) |
| 2000 | return TPResult::Error; |
| 2001 | |
| 2002 | |
| 2003 | ConsumeParen(); |
| 2004 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
| 2005 | return TPResult::Error; |
| 2006 | } |
| 2007 | if (Tok.is(tok::kw_noexcept)) { |
| 2008 | ConsumeToken(); |
| 2009 | |
| 2010 | if (Tok.is(tok::l_paren)) { |
| 2011 | |
| 2012 | ConsumeParen(); |
| 2013 | if (!SkipUntil(tok::r_paren, StopAtSemi)) |
| 2014 | return TPResult::Error; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | return TPResult::Ambiguous; |
| 2019 | } |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | Parser::TPResult Parser::TryParseBracketDeclarator() { |
| 2024 | ConsumeBracket(); |
| 2025 | if (!SkipUntil(tok::r_square, StopAtSemi)) |
| 2026 | return TPResult::Error; |
| 2027 | |
| 2028 | return TPResult::Ambiguous; |
| 2029 | } |
| 2030 | |