| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | #include "clang/Parse/Parser.h" |
| 24 | #include "clang/AST/ASTContext.h" |
| 25 | #include "clang/Basic/PrettyStackTrace.h" |
| 26 | #include "clang/Parse/RAIIObjectsForParser.h" |
| 27 | #include "clang/Sema/DeclSpec.h" |
| 28 | #include "clang/Sema/ParsedTemplate.h" |
| 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/TypoCorrection.h" |
| 31 | #include "llvm/ADT/SmallVector.h" |
| 32 | using namespace clang; |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 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 | ExprResult Parser::ParseExpression(TypeCastState isTypeCast) { |
| 123 | ExprResult LHS(ParseAssignmentExpression(isTypeCast)); |
| 124 | return ParseRHSOfBinaryExpression(LHS, prec::Comma); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | ExprResult |
| 133 | Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) { |
| 134 | ExprResult LHS(ParseObjCAtExpression(AtLoc)); |
| 135 | return ParseRHSOfBinaryExpression(LHS, prec::Comma); |
| 136 | } |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | ExprResult |
| 142 | Parser::ParseExpressionWithLeadingExtension(SourceLocation ExtLoc) { |
| 143 | ExprResult LHS(true); |
| 144 | { |
| 145 | |
| 146 | ExtensionRAIIObject O(Diags); |
| 147 | |
| 148 | LHS = ParseCastExpression(false); |
| 149 | } |
| 150 | |
| 151 | if (!LHS.isInvalid()) |
| 152 | LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__, |
| 153 | LHS.get()); |
| 154 | |
| 155 | return ParseRHSOfBinaryExpression(LHS, prec::Comma); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | ExprResult Parser::ParseAssignmentExpression(TypeCastState isTypeCast) { |
| 160 | if (Tok.is(tok::code_completion)) { |
| 161 | Actions.CodeCompleteExpression(getCurScope(), |
| 162 | PreferredType.get(Tok.getLocation())); |
| 163 | cutOffParsing(); |
| 164 | return ExprError(); |
| 165 | } |
| 166 | |
| 167 | if (Tok.is(tok::kw_throw)) |
| 168 | return ParseThrowExpression(); |
| 169 | if (Tok.is(tok::kw_co_yield)) |
| 170 | return ParseCoyieldExpression(); |
| 171 | |
| 172 | ExprResult LHS = ParseCastExpression(, |
| 173 | , |
| 174 | isTypeCast); |
| 175 | return ParseRHSOfBinaryExpression(LHS, prec::Assignment); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | ExprResult |
| 188 | Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc, |
| 189 | SourceLocation SuperLoc, |
| 190 | ParsedType ReceiverType, |
| 191 | Expr *ReceiverExpr) { |
| 192 | ExprResult R |
| 193 | = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc, |
| 194 | ReceiverType, ReceiverExpr); |
| 195 | R = ParsePostfixExpressionSuffix(R); |
| 196 | return ParseRHSOfBinaryExpression(R, prec::Assignment); |
| 197 | } |
| 198 | |
| 199 | ExprResult |
| 200 | Parser::ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast) { |
| 201 | (0) . __assert_fail ("Actions.ExprEvalContexts.back().Context == Sema..ExpressionEvaluationContext..ConstantEvaluated && \"Call this function only if your ExpressionEvaluationContext is \" \"already ConstantEvaluated\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 204, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Actions.ExprEvalContexts.back().Context == |
| 202 | (0) . __assert_fail ("Actions.ExprEvalContexts.back().Context == Sema..ExpressionEvaluationContext..ConstantEvaluated && \"Call this function only if your ExpressionEvaluationContext is \" \"already ConstantEvaluated\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 204, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> Sema::ExpressionEvaluationContext::ConstantEvaluated && |
| 203 | (0) . __assert_fail ("Actions.ExprEvalContexts.back().Context == Sema..ExpressionEvaluationContext..ConstantEvaluated && \"Call this function only if your ExpressionEvaluationContext is \" \"already ConstantEvaluated\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 204, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Call this function only if your ExpressionEvaluationContext is " |
| 204 | (0) . __assert_fail ("Actions.ExprEvalContexts.back().Context == Sema..ExpressionEvaluationContext..ConstantEvaluated && \"Call this function only if your ExpressionEvaluationContext is \" \"already ConstantEvaluated\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 204, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "already ConstantEvaluated"); |
| 205 | ExprResult LHS(ParseCastExpression(false, false, isTypeCast)); |
| 206 | ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 207 | return Actions.ActOnConstantExpression(Res); |
| 208 | } |
| 209 | |
| 210 | ExprResult Parser::ParseConstantExpression(TypeCastState isTypeCast) { |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | EnterExpressionEvaluationContext ConstantEvaluated( |
| 216 | Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 217 | return ParseConstantExpressionInExprEvalContext(isTypeCast); |
| 218 | } |
| 219 | |
| 220 | ExprResult Parser::ParseCaseExpression(SourceLocation CaseLoc) { |
| 221 | EnterExpressionEvaluationContext ConstantEvaluated( |
| 222 | Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 223 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 224 | ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 225 | return Actions.ActOnCaseExpr(CaseLoc, Res); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | ExprResult Parser::ParseConstraintExpression() { |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | ExprResult LHS(ParseCastExpression()); |
| 241 | ExprResult Res(ParseRHSOfBinaryExpression(LHS, prec::LogicalOr)); |
| 242 | |
| 243 | return Res; |
| 244 | } |
| 245 | |
| 246 | bool Parser::isNotExpressionStart() { |
| 247 | tok::TokenKind K = Tok.getKind(); |
| 248 | if (K == tok::l_brace || K == tok::r_brace || |
| 249 | K == tok::kw_for || K == tok::kw_while || |
| 250 | K == tok::kw_if || K == tok::kw_else || |
| 251 | K == tok::kw_goto || K == tok::kw_try) |
| 252 | return true; |
| 253 | |
| 254 | return isKnownToBeDeclarationSpecifier(); |
| 255 | } |
| 256 | |
| 257 | bool Parser::isFoldOperator(prec::Level Level) const { |
| 258 | return Level > prec::Unknown && Level != prec::Conditional && |
| 259 | Level != prec::Spaceship; |
| 260 | } |
| 261 | |
| 262 | bool Parser::isFoldOperator(tok::TokenKind Kind) const { |
| 263 | return isFoldOperator(getBinOpPrecedence(Kind, GreaterThanIsOperator, true)); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | |
| 268 | ExprResult |
| 269 | Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) { |
| 270 | prec::Level NextTokPrec = getBinOpPrecedence(Tok.getKind(), |
| 271 | GreaterThanIsOperator, |
| 272 | getLangOpts().CPlusPlus11); |
| 273 | SourceLocation ColonLoc; |
| 274 | |
| 275 | auto SavedType = PreferredType; |
| 276 | while (1) { |
| 277 | |
| 278 | PreferredType = SavedType; |
| 279 | |
| 280 | |
| 281 | |
| 282 | if (NextTokPrec < MinPrec) |
| 283 | return LHS; |
| 284 | |
| 285 | |
| 286 | Token OpToken = Tok; |
| 287 | ConsumeToken(); |
| 288 | |
| 289 | if (OpToken.is(tok::caretcaret)) { |
| 290 | return ExprError(Diag(Tok, diag::err_opencl_logical_exclusive_or)); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | |
| 295 | if (OpToken.isOneOf(tok::comma, tok::greater, tok::greatergreater, |
| 296 | tok::greatergreatergreater) && |
| 297 | checkPotentialAngleBracketDelimiter(OpToken)) |
| 298 | return ExprError(); |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | if (OpToken.is(tok::comma) && isNotExpressionStart()) { |
| 306 | PP.EnterToken(Tok); |
| 307 | Tok = OpToken; |
| 308 | return LHS; |
| 309 | } |
| 310 | |
| 311 | |
| 312 | |
| 313 | if (isFoldOperator(NextTokPrec) && Tok.is(tok::ellipsis)) { |
| 314 | |
| 315 | |
| 316 | PP.EnterToken(Tok); |
| 317 | Tok = OpToken; |
| 318 | return LHS; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | if (getLangOpts().ObjC && getLangOpts().CPlusPlus && |
| 327 | Tok.isOneOf(tok::colon, tok::r_square) && |
| 328 | OpToken.getIdentifierInfo() != nullptr) { |
| 329 | PP.EnterToken(Tok); |
| 330 | Tok = OpToken; |
| 331 | return LHS; |
| 332 | } |
| 333 | |
| 334 | |
| 335 | ExprResult TernaryMiddle(true); |
| 336 | if (NextTokPrec == prec::Conditional) { |
| 337 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 338 | |
| 339 | SourceLocation BraceLoc = Tok.getLocation(); |
| 340 | TernaryMiddle = ParseBraceInitializer(); |
| 341 | if (!TernaryMiddle.isInvalid()) { |
| 342 | Diag(BraceLoc, diag::err_init_list_bin_op) |
| 343 | << 1 << PP.getSpelling(OpToken) |
| 344 | << Actions.getExprRange(TernaryMiddle.get()); |
| 345 | TernaryMiddle = ExprError(); |
| 346 | } |
| 347 | } else if (Tok.isNot(tok::colon)) { |
| 348 | |
| 349 | ColonProtectionRAIIObject X(*this); |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | TernaryMiddle = ParseExpression(); |
| 356 | } else { |
| 357 | |
| 358 | |
| 359 | TernaryMiddle = nullptr; |
| 360 | Diag(Tok, diag::ext_gnu_conditional_expr); |
| 361 | } |
| 362 | |
| 363 | if (TernaryMiddle.isInvalid()) { |
| 364 | Actions.CorrectDelayedTyposInExpr(LHS); |
| 365 | LHS = ExprError(); |
| 366 | TernaryMiddle = nullptr; |
| 367 | } |
| 368 | |
| 369 | if (!TryConsumeToken(tok::colon, ColonLoc)) { |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | SourceLocation FILoc = Tok.getLocation(); |
| 375 | const char *FIText = ": "; |
| 376 | const SourceManager &SM = PP.getSourceManager(); |
| 377 | if (FILoc.isFileID() || PP.isAtStartOfMacroExpansion(FILoc, &FILoc)) { |
| 378 | assert(FILoc.isFileID()); |
| 379 | bool IsInvalid = false; |
| 380 | const char *SourcePtr = |
| 381 | SM.getCharacterData(FILoc.getLocWithOffset(-1), &IsInvalid); |
| 382 | if (!IsInvalid && *SourcePtr == ' ') { |
| 383 | SourcePtr = |
| 384 | SM.getCharacterData(FILoc.getLocWithOffset(-2), &IsInvalid); |
| 385 | if (!IsInvalid && *SourcePtr == ' ') { |
| 386 | FILoc = FILoc.getLocWithOffset(-1); |
| 387 | FIText = ":"; |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | Diag(Tok, diag::err_expected) |
| 393 | << tok::colon << FixItHint::CreateInsertion(FILoc, FIText); |
| 394 | Diag(OpToken, diag::note_matching) << tok::question; |
| 395 | ColonLoc = Tok.getLocation(); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | PreferredType.enterBinary(Actions, Tok.getLocation(), LHS.get(), |
| 400 | OpToken.getKind()); |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | ExprResult RHS; |
| 412 | bool RHSIsInitList = false; |
| 413 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 414 | RHS = ParseBraceInitializer(); |
| 415 | RHSIsInitList = true; |
| 416 | } else if (getLangOpts().CPlusPlus && NextTokPrec <= prec::Conditional) |
| 417 | RHS = ParseAssignmentExpression(); |
| 418 | else |
| 419 | RHS = ParseCastExpression(false); |
| 420 | |
| 421 | if (RHS.isInvalid()) { |
| 422 | |
| 423 | |
| 424 | Actions.CorrectDelayedTyposInExpr(LHS); |
| 425 | if (TernaryMiddle.isUsable()) |
| 426 | TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle); |
| 427 | LHS = ExprError(); |
| 428 | } |
| 429 | |
| 430 | |
| 431 | |
| 432 | prec::Level ThisPrec = NextTokPrec; |
| 433 | NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator, |
| 434 | getLangOpts().CPlusPlus11); |
| 435 | |
| 436 | |
| 437 | bool isRightAssoc = ThisPrec == prec::Conditional || |
| 438 | ThisPrec == prec::Assignment; |
| 439 | |
| 440 | |
| 441 | |
| 442 | if (ThisPrec < NextTokPrec || |
| 443 | (ThisPrec == NextTokPrec && isRightAssoc)) { |
| 444 | if (!RHS.isInvalid() && RHSIsInitList) { |
| 445 | Diag(Tok, diag::err_init_list_bin_op) |
| 446 | << << PP.getSpelling(Tok) << Actions.getExprRange(RHS.get()); |
| 447 | RHS = ExprError(); |
| 448 | } |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | RHS = ParseRHSOfBinaryExpression(RHS, |
| 455 | static_cast<prec::Level>(ThisPrec + !isRightAssoc)); |
| 456 | RHSIsInitList = false; |
| 457 | |
| 458 | if (RHS.isInvalid()) { |
| 459 | |
| 460 | |
| 461 | Actions.CorrectDelayedTyposInExpr(LHS); |
| 462 | if (TernaryMiddle.isUsable()) |
| 463 | TernaryMiddle = Actions.CorrectDelayedTyposInExpr(TernaryMiddle); |
| 464 | LHS = ExprError(); |
| 465 | } |
| 466 | |
| 467 | NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator, |
| 468 | getLangOpts().CPlusPlus11); |
| 469 | } |
| 470 | |
| 471 | if (!RHS.isInvalid() && RHSIsInitList) { |
| 472 | if (ThisPrec == prec::Assignment) { |
| 473 | Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists) |
| 474 | << Actions.getExprRange(RHS.get()); |
| 475 | } else if (ColonLoc.isValid()) { |
| 476 | Diag(ColonLoc, diag::err_init_list_bin_op) |
| 477 | << << ":" |
| 478 | << Actions.getExprRange(RHS.get()); |
| 479 | LHS = ExprError(); |
| 480 | } else { |
| 481 | Diag(OpToken, diag::err_init_list_bin_op) |
| 482 | << << PP.getSpelling(OpToken) |
| 483 | << Actions.getExprRange(RHS.get()); |
| 484 | LHS = ExprError(); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | ExprResult OrigLHS = LHS; |
| 489 | if (!LHS.isInvalid()) { |
| 490 | |
| 491 | if (TernaryMiddle.isInvalid()) { |
| 492 | |
| 493 | |
| 494 | |
| 495 | if (!GreaterThanIsOperator && OpToken.is(tok::greatergreater)) |
| 496 | SuggestParentheses(OpToken.getLocation(), |
| 497 | diag::warn_cxx11_right_shift_in_template_arg, |
| 498 | SourceRange(Actions.getExprRange(LHS.get()).getBegin(), |
| 499 | Actions.getExprRange(RHS.get()).getEnd())); |
| 500 | |
| 501 | LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(), |
| 502 | OpToken.getKind(), LHS.get(), RHS.get()); |
| 503 | |
| 504 | } else { |
| 505 | LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc, |
| 506 | LHS.get(), TernaryMiddle.get(), |
| 507 | RHS.get()); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | if (!getLangOpts().CPlusPlus) |
| 512 | continue; |
| 513 | } |
| 514 | |
| 515 | |
| 516 | if (LHS.isInvalid()) { |
| 517 | Actions.CorrectDelayedTyposInExpr(OrigLHS); |
| 518 | Actions.CorrectDelayedTyposInExpr(TernaryMiddle); |
| 519 | Actions.CorrectDelayedTyposInExpr(RHS); |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | ExprResult Parser::ParseCastExpression(bool isUnaryExpression, |
| 531 | bool isAddressOfOperand, |
| 532 | TypeCastState isTypeCast, |
| 533 | bool isVectorLiteral) { |
| 534 | bool NotCastExpr; |
| 535 | ExprResult Res = ParseCastExpression(isUnaryExpression, |
| 536 | isAddressOfOperand, |
| 537 | NotCastExpr, |
| 538 | isTypeCast, |
| 539 | isVectorLiteral); |
| 540 | if (NotCastExpr) |
| 541 | Diag(Tok, diag::err_expected_expression); |
| 542 | return Res; |
| 543 | } |
| 544 | |
| 545 | namespace { |
| 546 | class CastExpressionIdValidator final : public CorrectionCandidateCallback { |
| 547 | public: |
| 548 | CastExpressionIdValidator(Token Next, bool AllowTypes, bool AllowNonTypes) |
| 549 | : NextToken(Next), AllowNonTypes(AllowNonTypes) { |
| 550 | WantTypeSpecifiers = WantFunctionLikeCasts = AllowTypes; |
| 551 | } |
| 552 | |
| 553 | bool ValidateCandidate(const TypoCorrection &candidate) override { |
| 554 | NamedDecl *ND = candidate.getCorrectionDecl(); |
| 555 | if (!ND) |
| 556 | return candidate.isKeyword(); |
| 557 | |
| 558 | if (isa<TypeDecl>(ND)) |
| 559 | return WantTypeSpecifiers; |
| 560 | |
| 561 | if (!AllowNonTypes || !CorrectionCandidateCallback::ValidateCandidate(candidate)) |
| 562 | return false; |
| 563 | |
| 564 | if (!NextToken.isOneOf(tok::equal, tok::arrow, tok::period)) |
| 565 | return true; |
| 566 | |
| 567 | for (auto *C : candidate) { |
| 568 | NamedDecl *ND = C->getUnderlyingDecl(); |
| 569 | if (isa<ValueDecl>(ND) && !isa<FunctionDecl>(ND)) |
| 570 | return true; |
| 571 | } |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
| 576 | return llvm::make_unique<CastExpressionIdValidator>(*this); |
| 577 | } |
| 578 | |
| 579 | private: |
| 580 | Token NextToken; |
| 581 | bool AllowNonTypes; |
| 582 | }; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 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 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | ExprResult Parser::ParseCastExpression(bool isUnaryExpression, |
| 761 | bool isAddressOfOperand, |
| 762 | bool &NotCastExpr, |
| 763 | TypeCastState isTypeCast, |
| 764 | bool isVectorLiteral) { |
| 765 | ExprResult Res; |
| 766 | tok::TokenKind SavedKind = Tok.getKind(); |
| 767 | auto SavedType = PreferredType; |
| 768 | NotCastExpr = false; |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | switch (SavedKind) { |
| 782 | case tok::l_paren: { |
| 783 | |
| 784 | |
| 785 | ParenParseOption ParenExprType = |
| 786 | (isUnaryExpression && !getLangOpts().CPlusPlus) ? CompoundLiteral |
| 787 | : CastExpr; |
| 788 | ParsedType CastTy; |
| 789 | SourceLocation RParenLoc; |
| 790 | Res = ParseParenExpression(ParenExprType, false, |
| 791 | isTypeCast == IsTypeCast, CastTy, RParenLoc); |
| 792 | |
| 793 | if (isVectorLiteral) |
| 794 | return Res; |
| 795 | |
| 796 | switch (ParenExprType) { |
| 797 | case SimpleExpr: break; |
| 798 | case CompoundStmt: break; |
| 799 | case CompoundLiteral: |
| 800 | |
| 801 | |
| 802 | break; |
| 803 | case CastExpr: |
| 804 | |
| 805 | |
| 806 | return Res; |
| 807 | case FoldExpr: |
| 808 | |
| 809 | |
| 810 | break; |
| 811 | } |
| 812 | |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | |
| 817 | case tok::numeric_constant: |
| 818 | |
| 819 | |
| 820 | |
| 821 | Res = Actions.ActOnNumericConstant(Tok, ()); |
| 822 | ConsumeToken(); |
| 823 | break; |
| 824 | |
| 825 | case tok::kw_true: |
| 826 | case tok::kw_false: |
| 827 | Res = ParseCXXBoolLiteral(); |
| 828 | break; |
| 829 | |
| 830 | case tok::kw___objc_yes: |
| 831 | case tok::kw___objc_no: |
| 832 | return ParseObjCBoolLiteral(); |
| 833 | |
| 834 | case tok::kw_nullptr: |
| 835 | Diag(Tok, diag::warn_cxx98_compat_nullptr); |
| 836 | return Actions.ActOnCXXNullPtrLiteral(ConsumeToken()); |
| 837 | |
| 838 | case tok::annot_primary_expr: |
| 839 | (0) . __assert_fail ("Res.get() == nullptr && \"Stray primary-expression annotation?\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 839, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Res.get() == nullptr && "Stray primary-expression annotation?"); |
| 840 | Res = getExprAnnotation(Tok); |
| 841 | ConsumeAnnotationToken(); |
| 842 | if (!Res.isInvalid() && Tok.is(tok::less)) |
| 843 | checkPotentialAngleBracket(Res); |
| 844 | break; |
| 845 | |
| 846 | case tok::kw___super: |
| 847 | case tok::kw_decltype: |
| 848 | |
| 849 | if (TryAnnotateTypeOrScopeToken()) |
| 850 | return ExprError(); |
| 851 | assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super)); |
| 852 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand); |
| 853 | |
| 854 | case tok::identifier: { |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | if (getLangOpts().CPlusPlus) { |
| 860 | |
| 861 | |
| 862 | const Token &Next = NextToken(); |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | if (Next.is(tok::l_paren) && |
| 868 | Tok.is(tok::identifier) && |
| 869 | Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) { |
| 870 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 871 | |
| 872 | if (RevertibleTypeTraits.empty()) { |
| 873 | #define RTT_JOIN(X,Y) X##Y |
| 874 | #define REVERTIBLE_TYPE_TRAIT(Name) \ |
| 875 | RevertibleTypeTraits[PP.getIdentifierInfo(#Name)] \ |
| 876 | = RTT_JOIN(tok::kw_,Name) |
| 877 | |
| 878 | REVERTIBLE_TYPE_TRAIT(__is_abstract); |
| 879 | REVERTIBLE_TYPE_TRAIT(__is_aggregate); |
| 880 | REVERTIBLE_TYPE_TRAIT(__is_arithmetic); |
| 881 | REVERTIBLE_TYPE_TRAIT(__is_array); |
| 882 | REVERTIBLE_TYPE_TRAIT(__is_assignable); |
| 883 | REVERTIBLE_TYPE_TRAIT(__is_base_of); |
| 884 | REVERTIBLE_TYPE_TRAIT(__is_class); |
| 885 | REVERTIBLE_TYPE_TRAIT(__is_complete_type); |
| 886 | REVERTIBLE_TYPE_TRAIT(__is_compound); |
| 887 | REVERTIBLE_TYPE_TRAIT(__is_const); |
| 888 | REVERTIBLE_TYPE_TRAIT(__is_constructible); |
| 889 | REVERTIBLE_TYPE_TRAIT(__is_convertible); |
| 890 | REVERTIBLE_TYPE_TRAIT(__is_convertible_to); |
| 891 | REVERTIBLE_TYPE_TRAIT(__is_destructible); |
| 892 | REVERTIBLE_TYPE_TRAIT(__is_empty); |
| 893 | REVERTIBLE_TYPE_TRAIT(__is_enum); |
| 894 | REVERTIBLE_TYPE_TRAIT(__is_floating_point); |
| 895 | REVERTIBLE_TYPE_TRAIT(__is_final); |
| 896 | REVERTIBLE_TYPE_TRAIT(__is_function); |
| 897 | REVERTIBLE_TYPE_TRAIT(__is_fundamental); |
| 898 | REVERTIBLE_TYPE_TRAIT(__is_integral); |
| 899 | REVERTIBLE_TYPE_TRAIT(__is_interface_class); |
| 900 | REVERTIBLE_TYPE_TRAIT(__is_literal); |
| 901 | REVERTIBLE_TYPE_TRAIT(__is_lvalue_expr); |
| 902 | REVERTIBLE_TYPE_TRAIT(__is_lvalue_reference); |
| 903 | REVERTIBLE_TYPE_TRAIT(__is_member_function_pointer); |
| 904 | REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer); |
| 905 | REVERTIBLE_TYPE_TRAIT(__is_member_pointer); |
| 906 | REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable); |
| 907 | REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible); |
| 908 | REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible); |
| 909 | REVERTIBLE_TYPE_TRAIT(__is_object); |
| 910 | REVERTIBLE_TYPE_TRAIT(__is_pod); |
| 911 | REVERTIBLE_TYPE_TRAIT(__is_pointer); |
| 912 | REVERTIBLE_TYPE_TRAIT(__is_polymorphic); |
| 913 | REVERTIBLE_TYPE_TRAIT(__is_reference); |
| 914 | REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr); |
| 915 | REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference); |
| 916 | REVERTIBLE_TYPE_TRAIT(__is_same); |
| 917 | REVERTIBLE_TYPE_TRAIT(__is_scalar); |
| 918 | REVERTIBLE_TYPE_TRAIT(__is_sealed); |
| 919 | REVERTIBLE_TYPE_TRAIT(__is_signed); |
| 920 | REVERTIBLE_TYPE_TRAIT(__is_standard_layout); |
| 921 | REVERTIBLE_TYPE_TRAIT(__is_trivial); |
| 922 | REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable); |
| 923 | REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible); |
| 924 | REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable); |
| 925 | REVERTIBLE_TYPE_TRAIT(__is_union); |
| 926 | REVERTIBLE_TYPE_TRAIT(__is_unsigned); |
| 927 | REVERTIBLE_TYPE_TRAIT(__is_void); |
| 928 | REVERTIBLE_TYPE_TRAIT(__is_volatile); |
| 929 | #undef REVERTIBLE_TYPE_TRAIT |
| 930 | #undef RTT_JOIN |
| 931 | } |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | llvm::SmallDenseMap<IdentifierInfo *, tok::TokenKind>::iterator Known |
| 937 | = RevertibleTypeTraits.find(II); |
| 938 | if (Known != RevertibleTypeTraits.end()) { |
| 939 | Tok.setKind(Known->second); |
| 940 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand, |
| 941 | NotCastExpr, isTypeCast); |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | if ((!ColonIsSacred && Next.is(tok::colon)) || |
| 946 | Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren, |
| 947 | tok::l_brace)) { |
| 948 | |
| 949 | if (TryAnnotateTypeOrScopeToken()) |
| 950 | return ExprError(); |
| 951 | if (!Tok.is(tok::identifier)) |
| 952 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | |
| 957 | |
| 958 | IdentifierInfo &II = *Tok.getIdentifierInfo(); |
| 959 | SourceLocation ILoc = ConsumeToken(); |
| 960 | |
| 961 | |
| 962 | if (getLangOpts().ObjC && Tok.is(tok::period) && |
| 963 | (Actions.getTypeName(II, ILoc, getCurScope()) || |
| 964 | |
| 965 | (&II == Ident_super && getCurScope()->isInObjcMethodScope()))) { |
| 966 | ConsumeToken(); |
| 967 | |
| 968 | if (Tok.is(tok::code_completion) && &II != Ident_super) { |
| 969 | Actions.CodeCompleteObjCClassPropertyRefExpr( |
| 970 | getCurScope(), II, ILoc, ExprStatementTokLoc == ILoc); |
| 971 | cutOffParsing(); |
| 972 | return ExprError(); |
| 973 | } |
| 974 | |
| 975 | if (Tok.isNot(tok::identifier) && |
| 976 | !(getLangOpts().CPlusPlus && Tok.is(tok::kw_class))) { |
| 977 | Diag(Tok, diag::err_expected_property_name); |
| 978 | return ExprError(); |
| 979 | } |
| 980 | IdentifierInfo &PropertyName = *Tok.getIdentifierInfo(); |
| 981 | SourceLocation PropertyLoc = ConsumeToken(); |
| 982 | |
| 983 | Res = Actions.ActOnClassPropertyRefExpr(II, PropertyName, |
| 984 | ILoc, PropertyLoc); |
| 985 | break; |
| 986 | } |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | if (getLangOpts().ObjC && &II == Ident_super && !InMessageExpression && |
| 993 | getCurScope()->isInObjcMethodScope() && |
| 994 | ((Tok.is(tok::identifier) && |
| 995 | (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) || |
| 996 | Tok.is(tok::code_completion))) { |
| 997 | Res = ParseObjCMessageExpressionBody(SourceLocation(), ILoc, nullptr, |
| 998 | nullptr); |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | if (getLangOpts().ObjC && |
| 1008 | ((Tok.is(tok::identifier) && !InMessageExpression) || |
| 1009 | Tok.is(tok::code_completion))) { |
| 1010 | const Token& Next = NextToken(); |
| 1011 | if (Tok.is(tok::code_completion) || |
| 1012 | Next.is(tok::colon) || Next.is(tok::r_square)) |
| 1013 | if (ParsedType Typ = Actions.getTypeName(II, ILoc, getCurScope())) |
| 1014 | if (Typ.get()->isObjCObjectOrInterfaceType()) { |
| 1015 | |
| 1016 | DeclSpec DS(AttrFactory); |
| 1017 | DS.SetRangeStart(ILoc); |
| 1018 | DS.SetRangeEnd(ILoc); |
| 1019 | const char *PrevSpec = nullptr; |
| 1020 | unsigned DiagID; |
| 1021 | DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ, |
| 1022 | Actions.getASTContext().getPrintingPolicy()); |
| 1023 | |
| 1024 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 1025 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), |
| 1026 | DeclaratorInfo); |
| 1027 | if (Ty.isInvalid()) |
| 1028 | break; |
| 1029 | |
| 1030 | Res = ParseObjCMessageExpressionBody(SourceLocation(), |
| 1031 | SourceLocation(), |
| 1032 | Ty.get(), nullptr); |
| 1033 | break; |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | if (isAddressOfOperand && isPostfixExpressionSuffixStart()) |
| 1039 | isAddressOfOperand = false; |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | UnqualifiedId Name; |
| 1045 | CXXScopeSpec ScopeSpec; |
| 1046 | SourceLocation TemplateKWLoc; |
| 1047 | Token Replacement; |
| 1048 | CastExpressionIdValidator Validator( |
| 1049 | , |
| 1050 | != NotTypeCast, |
| 1051 | != IsTypeCast); |
| 1052 | Validator.IsAddressOfOperand = isAddressOfOperand; |
| 1053 | if (Tok.isOneOf(tok::periodstar, tok::arrowstar)) { |
| 1054 | Validator.WantExpressionKeywords = false; |
| 1055 | Validator.WantRemainingKeywords = false; |
| 1056 | } else { |
| 1057 | Validator.WantRemainingKeywords = Tok.isNot(tok::r_paren); |
| 1058 | } |
| 1059 | Name.setIdentifier(&II, ILoc); |
| 1060 | Res = Actions.ActOnIdExpression( |
| 1061 | getCurScope(), ScopeSpec, TemplateKWLoc, Name, Tok.is(tok::l_paren), |
| 1062 | isAddressOfOperand, &Validator, |
| 1063 | , |
| 1064 | Tok.is(tok::r_paren) ? nullptr : &Replacement); |
| 1065 | if (!Res.isInvalid() && Res.isUnset()) { |
| 1066 | UnconsumeToken(Replacement); |
| 1067 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand, |
| 1068 | NotCastExpr, isTypeCast); |
| 1069 | } |
| 1070 | if (!Res.isInvalid() && Tok.is(tok::less)) |
| 1071 | checkPotentialAngleBracket(Res); |
| 1072 | break; |
| 1073 | } |
| 1074 | case tok::char_constant: |
| 1075 | case tok::wide_char_constant: |
| 1076 | case tok::utf8_char_constant: |
| 1077 | case tok::utf16_char_constant: |
| 1078 | case tok::utf32_char_constant: |
| 1079 | Res = Actions.ActOnCharacterConstant(Tok, ()); |
| 1080 | ConsumeToken(); |
| 1081 | break; |
| 1082 | case tok::kw___func__: |
| 1083 | case tok::kw___FUNCTION__: |
| 1084 | case tok::kw___FUNCDNAME__: |
| 1085 | case tok::kw___FUNCSIG__: |
| 1086 | case tok::kw_L__FUNCTION__: |
| 1087 | case tok::kw_L__FUNCSIG__: |
| 1088 | case tok::kw___PRETTY_FUNCTION__: |
| 1089 | Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind); |
| 1090 | ConsumeToken(); |
| 1091 | break; |
| 1092 | case tok::string_literal: |
| 1093 | case tok::wide_string_literal: |
| 1094 | case tok::utf8_string_literal: |
| 1095 | case tok::utf16_string_literal: |
| 1096 | case tok::utf32_string_literal: |
| 1097 | Res = ParseStringLiteralExpression(true); |
| 1098 | break; |
| 1099 | case tok::kw__Generic: |
| 1100 | Res = ParseGenericSelectionExpression(); |
| 1101 | break; |
| 1102 | case tok::kw___builtin_available: |
| 1103 | return ParseAvailabilityCheckExpr(Tok.getLocation()); |
| 1104 | case tok::kw___builtin_va_arg: |
| 1105 | case tok::kw___builtin_offsetof: |
| 1106 | case tok::kw___builtin_choose_expr: |
| 1107 | case tok::kw___builtin_astype: |
| 1108 | case tok::kw___builtin_convertvector: |
| 1109 | return ParseBuiltinPrimaryExpression(); |
| 1110 | case tok::kw___null: |
| 1111 | return Actions.ActOnGNUNullExpr(ConsumeToken()); |
| 1112 | |
| 1113 | case tok::plusplus: |
| 1114 | case tok::minusminus: { |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | Token SavedTok = Tok; |
| 1120 | ConsumeToken(); |
| 1121 | |
| 1122 | PreferredType.enterUnary(Actions, Tok.getLocation(), SavedTok.getKind(), |
| 1123 | SavedTok.getLocation()); |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | Res = ParseCastExpression(!getLangOpts().CPlusPlus, |
| 1128 | , NotCastExpr, |
| 1129 | NotTypeCast); |
| 1130 | if (NotCastExpr) { |
| 1131 | |
| 1132 | |
| 1133 | assert(Res.isInvalid()); |
| 1134 | UnconsumeToken(SavedTok); |
| 1135 | return ExprError(); |
| 1136 | } |
| 1137 | if (!Res.isInvalid()) |
| 1138 | Res = Actions.ActOnUnaryOp(getCurScope(), SavedTok.getLocation(), |
| 1139 | SavedKind, Res.get()); |
| 1140 | return Res; |
| 1141 | } |
| 1142 | case tok::amp: { |
| 1143 | |
| 1144 | SourceLocation SavedLoc = ConsumeToken(); |
| 1145 | PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc); |
| 1146 | Res = ParseCastExpression(false, true); |
| 1147 | if (!Res.isInvalid()) |
| 1148 | Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); |
| 1149 | return Res; |
| 1150 | } |
| 1151 | |
| 1152 | case tok::star: |
| 1153 | case tok::plus: |
| 1154 | case tok::minus: |
| 1155 | case tok::tilde: |
| 1156 | case tok::exclaim: |
| 1157 | case tok::kw___real: |
| 1158 | case tok::kw___imag: { |
| 1159 | SourceLocation SavedLoc = ConsumeToken(); |
| 1160 | PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc); |
| 1161 | Res = ParseCastExpression(false); |
| 1162 | if (!Res.isInvalid()) |
| 1163 | Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); |
| 1164 | return Res; |
| 1165 | } |
| 1166 | |
| 1167 | case tok::kw_co_await: { |
| 1168 | SourceLocation CoawaitLoc = ConsumeToken(); |
| 1169 | Res = ParseCastExpression(false); |
| 1170 | if (!Res.isInvalid()) |
| 1171 | Res = Actions.ActOnCoawaitExpr(getCurScope(), CoawaitLoc, Res.get()); |
| 1172 | return Res; |
| 1173 | } |
| 1174 | |
| 1175 | case tok::kw___extension__:{ |
| 1176 | |
| 1177 | ExtensionRAIIObject O(Diags); |
| 1178 | SourceLocation SavedLoc = ConsumeToken(); |
| 1179 | Res = ParseCastExpression(false); |
| 1180 | if (!Res.isInvalid()) |
| 1181 | Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); |
| 1182 | return Res; |
| 1183 | } |
| 1184 | case tok::kw__Alignof: |
| 1185 | if (!getLangOpts().C11) |
| 1186 | Diag(Tok, diag::ext_c11_alignment) << Tok.getName(); |
| 1187 | LLVM_FALLTHROUGH; |
| 1188 | case tok::kw_alignof: |
| 1189 | case tok::kw___alignof: |
| 1190 | |
| 1191 | case tok::kw_sizeof: |
| 1192 | |
| 1193 | case tok::kw_vec_step: |
| 1194 | |
| 1195 | case tok::kw___builtin_omp_required_simd_align: |
| 1196 | return ParseUnaryExprOrTypeTraitExpression(); |
| 1197 | case tok::ampamp: { |
| 1198 | SourceLocation AmpAmpLoc = ConsumeToken(); |
| 1199 | if (Tok.isNot(tok::identifier)) |
| 1200 | return ExprError(Diag(Tok, diag::err_expected) << tok::identifier); |
| 1201 | |
| 1202 | if (getCurScope()->getFnParent() == nullptr) |
| 1203 | return ExprError(Diag(Tok, diag::err_address_of_label_outside_fn)); |
| 1204 | |
| 1205 | Diag(AmpAmpLoc, diag::ext_gnu_address_of_label); |
| 1206 | LabelDecl *LD = Actions.LookupOrCreateLabel(Tok.getIdentifierInfo(), |
| 1207 | Tok.getLocation()); |
| 1208 | Res = Actions.ActOnAddrLabel(AmpAmpLoc, Tok.getLocation(), LD); |
| 1209 | ConsumeToken(); |
| 1210 | return Res; |
| 1211 | } |
| 1212 | case tok::kw_const_cast: |
| 1213 | case tok::kw_dynamic_cast: |
| 1214 | case tok::kw_reinterpret_cast: |
| 1215 | case tok::kw_static_cast: |
| 1216 | Res = ParseCXXCasts(); |
| 1217 | break; |
| 1218 | case tok::kw_typeid: |
| 1219 | Res = ParseCXXTypeid(); |
| 1220 | break; |
| 1221 | case tok::kw___uuidof: |
| 1222 | Res = ParseCXXUuidof(); |
| 1223 | break; |
| 1224 | case tok::kw_this: |
| 1225 | Res = ParseCXXThis(); |
| 1226 | break; |
| 1227 | |
| 1228 | case tok::annot_typename: |
| 1229 | if (isStartOfObjCClassMessageMissingOpenBracket()) { |
| 1230 | ParsedType Type = getTypeAnnotation(Tok); |
| 1231 | |
| 1232 | |
| 1233 | DeclSpec DS(AttrFactory); |
| 1234 | DS.SetRangeStart(Tok.getLocation()); |
| 1235 | DS.SetRangeEnd(Tok.getLastLoc()); |
| 1236 | |
| 1237 | const char *PrevSpec = nullptr; |
| 1238 | unsigned DiagID; |
| 1239 | DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(), |
| 1240 | PrevSpec, DiagID, Type, |
| 1241 | Actions.getASTContext().getPrintingPolicy()); |
| 1242 | |
| 1243 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 1244 | TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 1245 | if (Ty.isInvalid()) |
| 1246 | break; |
| 1247 | |
| 1248 | ConsumeAnnotationToken(); |
| 1249 | Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), |
| 1250 | Ty.get(), nullptr); |
| 1251 | break; |
| 1252 | } |
| 1253 | LLVM_FALLTHROUGH; |
| 1254 | |
| 1255 | case tok::annot_decltype: |
| 1256 | case tok::kw_char: |
| 1257 | case tok::kw_wchar_t: |
| 1258 | case tok::kw_char8_t: |
| 1259 | case tok::kw_char16_t: |
| 1260 | case tok::kw_char32_t: |
| 1261 | case tok::kw_bool: |
| 1262 | case tok::kw_short: |
| 1263 | case tok::kw_int: |
| 1264 | case tok::kw_long: |
| 1265 | case tok::kw___int64: |
| 1266 | case tok::kw___int128: |
| 1267 | case tok::kw_signed: |
| 1268 | case tok::kw_unsigned: |
| 1269 | case tok::kw_half: |
| 1270 | case tok::kw_float: |
| 1271 | case tok::kw_double: |
| 1272 | case tok::kw__Float16: |
| 1273 | case tok::kw___float128: |
| 1274 | case tok::kw_void: |
| 1275 | case tok::kw_typename: |
| 1276 | case tok::kw_typeof: |
| 1277 | case tok::kw___vector: |
| 1278 | #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
| 1279 | #include "clang/Basic/OpenCLImageTypes.def" |
| 1280 | { |
| 1281 | if (!getLangOpts().CPlusPlus) { |
| 1282 | Diag(Tok, diag::err_expected_expression); |
| 1283 | return ExprError(); |
| 1284 | } |
| 1285 | |
| 1286 | if (SavedKind == tok::kw_typename) { |
| 1287 | |
| 1288 | |
| 1289 | if (TryAnnotateTypeOrScopeToken()) |
| 1290 | return ExprError(); |
| 1291 | |
| 1292 | if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) |
| 1293 | |
| 1294 | |
| 1295 | return ExprError(); |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | DeclSpec DS(AttrFactory); |
| 1302 | |
| 1303 | ParseCXXSimpleTypeSpecifier(DS); |
| 1304 | if (Tok.isNot(tok::l_paren) && |
| 1305 | (!getLangOpts().CPlusPlus11 || Tok.isNot(tok::l_brace))) |
| 1306 | return ExprError(Diag(Tok, diag::err_expected_lparen_after_type) |
| 1307 | << DS.getSourceRange()); |
| 1308 | |
| 1309 | if (Tok.is(tok::l_brace)) |
| 1310 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 1311 | |
| 1312 | Res = ParseCXXTypeConstructExpression(DS); |
| 1313 | break; |
| 1314 | } |
| 1315 | |
| 1316 | case tok::annot_cxxscope: { |
| 1317 | |
| 1318 | |
| 1319 | if (TryAnnotateTypeOrScopeToken()) |
| 1320 | return ExprError(); |
| 1321 | if (!Tok.is(tok::annot_cxxscope)) |
| 1322 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand, |
| 1323 | NotCastExpr, isTypeCast); |
| 1324 | |
| 1325 | Token Next = NextToken(); |
| 1326 | if (Next.is(tok::annot_template_id)) { |
| 1327 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Next); |
| 1328 | if (TemplateId->Kind == TNK_Type_template) { |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | CXXScopeSpec SS; |
| 1333 | ParseOptionalCXXScopeSpecifier(SS, nullptr, |
| 1334 | ); |
| 1335 | AnnotateTemplateIdTokenAsType(); |
| 1336 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand, |
| 1337 | NotCastExpr, isTypeCast); |
| 1338 | } |
| 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | Res = ParseCXXIdExpression(isAddressOfOperand); |
| 1343 | break; |
| 1344 | } |
| 1345 | |
| 1346 | case tok::annot_template_id: { |
| 1347 | TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok); |
| 1348 | if (TemplateId->Kind == TNK_Type_template) { |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | AnnotateTemplateIdTokenAsType(); |
| 1353 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand, |
| 1354 | NotCastExpr, isTypeCast); |
| 1355 | } |
| 1356 | |
| 1357 | |
| 1358 | LLVM_FALLTHROUGH; |
| 1359 | } |
| 1360 | |
| 1361 | case tok::kw_operator: |
| 1362 | Res = ParseCXXIdExpression(isAddressOfOperand); |
| 1363 | break; |
| 1364 | |
| 1365 | case tok::coloncolon: { |
| 1366 | |
| 1367 | |
| 1368 | if (TryAnnotateTypeOrScopeToken()) |
| 1369 | return ExprError(); |
| 1370 | if (!Tok.is(tok::coloncolon)) |
| 1371 | return ParseCastExpression(isUnaryExpression, isAddressOfOperand); |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | SourceLocation CCLoc = ConsumeToken(); |
| 1376 | if (Tok.is(tok::kw_new)) |
| 1377 | return ParseCXXNewExpression(true, CCLoc); |
| 1378 | if (Tok.is(tok::kw_delete)) |
| 1379 | return ParseCXXDeleteExpression(true, CCLoc); |
| 1380 | |
| 1381 | |
| 1382 | Diag(CCLoc, diag::err_expected_expression); |
| 1383 | return ExprError(); |
| 1384 | } |
| 1385 | |
| 1386 | case tok::kw_new: |
| 1387 | return ParseCXXNewExpression(false, Tok.getLocation()); |
| 1388 | |
| 1389 | case tok::kw_delete: |
| 1390 | return ParseCXXDeleteExpression(false, Tok.getLocation()); |
| 1391 | |
| 1392 | case tok::kw_noexcept: { |
| 1393 | Diag(Tok, diag::warn_cxx98_compat_noexcept_expr); |
| 1394 | SourceLocation KeyLoc = ConsumeToken(); |
| 1395 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1396 | |
| 1397 | if (T.expectAndConsume(diag::err_expected_lparen_after, "noexcept")) |
| 1398 | return ExprError(); |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | EnterExpressionEvaluationContext Unevaluated( |
| 1403 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
| 1404 | ExprResult Result = ParseExpression(); |
| 1405 | |
| 1406 | T.consumeClose(); |
| 1407 | |
| 1408 | if (!Result.isInvalid()) |
| 1409 | Result = Actions.ActOnNoexceptExpr(KeyLoc, T.getOpenLocation(), |
| 1410 | Result.get(), T.getCloseLocation()); |
| 1411 | return Result; |
| 1412 | } |
| 1413 | |
| 1414 | #define TYPE_TRAIT(N,Spelling,K) \ |
| 1415 | case tok::kw_##Spelling: |
| 1416 | #include "clang/Basic/TokenKinds.def" |
| 1417 | return ParseTypeTrait(); |
| 1418 | |
| 1419 | case tok::kw___array_rank: |
| 1420 | case tok::kw___array_extent: |
| 1421 | return ParseArrayTypeTrait(); |
| 1422 | |
| 1423 | case tok::kw___is_lvalue_expr: |
| 1424 | case tok::kw___is_rvalue_expr: |
| 1425 | return ParseExpressionTrait(); |
| 1426 | |
| 1427 | case tok::at: { |
| 1428 | SourceLocation AtLoc = ConsumeToken(); |
| 1429 | return ParseObjCAtExpression(AtLoc); |
| 1430 | } |
| 1431 | case tok::caret: |
| 1432 | Res = ParseBlockLiteralExpression(); |
| 1433 | break; |
| 1434 | case tok::code_completion: { |
| 1435 | Actions.CodeCompleteExpression(getCurScope(), |
| 1436 | PreferredType.get(Tok.getLocation())); |
| 1437 | cutOffParsing(); |
| 1438 | return ExprError(); |
| 1439 | } |
| 1440 | case tok::l_square: |
| 1441 | if (getLangOpts().CPlusPlus11) { |
| 1442 | if (getLangOpts().ObjC) { |
| 1443 | |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | |
| 1448 | Res = TryParseLambdaExpression(); |
| 1449 | if (!Res.isInvalid() && !Res.get()) |
| 1450 | Res = ParseObjCMessageExpression(); |
| 1451 | break; |
| 1452 | } |
| 1453 | Res = ParseLambdaExpression(); |
| 1454 | break; |
| 1455 | } |
| 1456 | if (getLangOpts().ObjC) { |
| 1457 | Res = ParseObjCMessageExpression(); |
| 1458 | break; |
| 1459 | } |
| 1460 | LLVM_FALLTHROUGH; |
| 1461 | default: |
| 1462 | NotCastExpr = true; |
| 1463 | return ExprError(); |
| 1464 | } |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | PreferredType = SavedType; |
| 1472 | Res = ParsePostfixExpressionSuffix(Res); |
| 1473 | if (getLangOpts().OpenCL) |
| 1474 | if (Expr *PostfixExpr = Res.get()) { |
| 1475 | QualType Ty = PostfixExpr->getType(); |
| 1476 | if (!Ty.isNull() && Ty->isFunctionType()) { |
| 1477 | Diag(PostfixExpr->getExprLoc(), |
| 1478 | diag::err_opencl_taking_function_address_parser); |
| 1479 | return ExprError(); |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | return Res; |
| 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | ExprResult |
| 1507 | Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { |
| 1508 | |
| 1509 | |
| 1510 | SourceLocation Loc; |
| 1511 | auto SavedType = PreferredType; |
| 1512 | while (1) { |
| 1513 | |
| 1514 | PreferredType = SavedType; |
| 1515 | switch (Tok.getKind()) { |
| 1516 | case tok::code_completion: |
| 1517 | if (InMessageExpression) |
| 1518 | return LHS; |
| 1519 | |
| 1520 | Actions.CodeCompletePostfixExpression( |
| 1521 | getCurScope(), LHS, PreferredType.get(Tok.getLocation())); |
| 1522 | cutOffParsing(); |
| 1523 | return ExprError(); |
| 1524 | |
| 1525 | case tok::identifier: |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | if (getLangOpts().ObjC && !InMessageExpression && |
| 1530 | (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) { |
| 1531 | LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), |
| 1532 | nullptr, LHS.get()); |
| 1533 | break; |
| 1534 | } |
| 1535 | |
| 1536 | LLVM_FALLTHROUGH; |
| 1537 | |
| 1538 | default: |
| 1539 | return LHS; |
| 1540 | case tok::l_square: { |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | if (getLangOpts().ObjC && Tok.isAtStartOfLine() && |
| 1548 | isSimpleObjCMessageExpression()) |
| 1549 | return LHS; |
| 1550 | |
| 1551 | |
| 1552 | |
| 1553 | if (CheckProhibitedCXX11Attribute()) { |
| 1554 | (void)Actions.CorrectDelayedTyposInExpr(LHS); |
| 1555 | return ExprError(); |
| 1556 | } |
| 1557 | |
| 1558 | BalancedDelimiterTracker T(*this, tok::l_square); |
| 1559 | T.consumeOpen(); |
| 1560 | Loc = T.getOpenLocation(); |
| 1561 | ExprResult Idx, Length; |
| 1562 | SourceLocation ColonLoc; |
| 1563 | PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get()); |
| 1564 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 1565 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 1566 | Idx = ParseBraceInitializer(); |
| 1567 | } else if (getLangOpts().OpenMP) { |
| 1568 | ColonProtectionRAIIObject RAII(*this); |
| 1569 | |
| 1570 | if (!Tok.is(tok::colon)) { |
| 1571 | |
| 1572 | Idx = ParseExpression(); |
| 1573 | } |
| 1574 | if (Tok.is(tok::colon)) { |
| 1575 | |
| 1576 | ColonLoc = ConsumeToken(); |
| 1577 | if (Tok.isNot(tok::r_square)) |
| 1578 | Length = ParseExpression(); |
| 1579 | } |
| 1580 | } else |
| 1581 | Idx = ParseExpression(); |
| 1582 | |
| 1583 | SourceLocation RLoc = Tok.getLocation(); |
| 1584 | |
| 1585 | ExprResult OrigLHS = LHS; |
| 1586 | if (!LHS.isInvalid() && !Idx.isInvalid() && !Length.isInvalid() && |
| 1587 | Tok.is(tok::r_square)) { |
| 1588 | if (ColonLoc.isValid()) { |
| 1589 | LHS = Actions.ActOnOMPArraySectionExpr(LHS.get(), Loc, Idx.get(), |
| 1590 | ColonLoc, Length.get(), RLoc); |
| 1591 | } else { |
| 1592 | LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc, |
| 1593 | Idx.get(), RLoc); |
| 1594 | } |
| 1595 | } else { |
| 1596 | LHS = ExprError(); |
| 1597 | } |
| 1598 | if (LHS.isInvalid()) { |
| 1599 | (void)Actions.CorrectDelayedTyposInExpr(OrigLHS); |
| 1600 | (void)Actions.CorrectDelayedTyposInExpr(Idx); |
| 1601 | (void)Actions.CorrectDelayedTyposInExpr(Length); |
| 1602 | LHS = ExprError(); |
| 1603 | Idx = ExprError(); |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | T.consumeClose(); |
| 1608 | break; |
| 1609 | } |
| 1610 | |
| 1611 | case tok::l_paren: |
| 1612 | case tok::lesslessless: { |
| 1613 | |
| 1614 | tok::TokenKind OpKind = Tok.getKind(); |
| 1615 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 1616 | |
| 1617 | Expr *ExecConfig = nullptr; |
| 1618 | |
| 1619 | BalancedDelimiterTracker PT(*this, tok::l_paren); |
| 1620 | |
| 1621 | if (OpKind == tok::lesslessless) { |
| 1622 | ExprVector ExecConfigExprs; |
| 1623 | CommaLocsTy ExecConfigCommaLocs; |
| 1624 | SourceLocation OpenLoc = ConsumeToken(); |
| 1625 | |
| 1626 | if (ParseSimpleExpressionList(ExecConfigExprs, ExecConfigCommaLocs)) { |
| 1627 | (void)Actions.CorrectDelayedTyposInExpr(LHS); |
| 1628 | LHS = ExprError(); |
| 1629 | } |
| 1630 | |
| 1631 | SourceLocation CloseLoc; |
| 1632 | if (TryConsumeToken(tok::greatergreatergreater, CloseLoc)) { |
| 1633 | } else if (LHS.isInvalid()) { |
| 1634 | SkipUntil(tok::greatergreatergreater, StopAtSemi); |
| 1635 | } else { |
| 1636 | |
| 1637 | Diag(Tok, diag::err_expected) << tok::greatergreatergreater; |
| 1638 | Diag(OpenLoc, diag::note_matching) << tok::lesslessless; |
| 1639 | SkipUntil(tok::greatergreatergreater, StopAtSemi); |
| 1640 | LHS = ExprError(); |
| 1641 | } |
| 1642 | |
| 1643 | if (!LHS.isInvalid()) { |
| 1644 | if (ExpectAndConsume(tok::l_paren)) |
| 1645 | LHS = ExprError(); |
| 1646 | else |
| 1647 | Loc = PrevTokLocation; |
| 1648 | } |
| 1649 | |
| 1650 | if (!LHS.isInvalid()) { |
| 1651 | ExprResult ECResult = Actions.ActOnCUDAExecConfigExpr(getCurScope(), |
| 1652 | OpenLoc, |
| 1653 | ExecConfigExprs, |
| 1654 | CloseLoc); |
| 1655 | if (ECResult.isInvalid()) |
| 1656 | LHS = ExprError(); |
| 1657 | else |
| 1658 | ExecConfig = ECResult.get(); |
| 1659 | } |
| 1660 | } else { |
| 1661 | PT.consumeOpen(); |
| 1662 | Loc = PT.getOpenLocation(); |
| 1663 | } |
| 1664 | |
| 1665 | ExprVector ArgExprs; |
| 1666 | CommaLocsTy CommaLocs; |
| 1667 | auto RunSignatureHelp = [&]() -> QualType { |
| 1668 | QualType PreferredType = Actions.ProduceCallSignatureHelp( |
| 1669 | getCurScope(), LHS.get(), ArgExprs, PT.getOpenLocation()); |
| 1670 | CalledSignatureHelp = true; |
| 1671 | return PreferredType; |
| 1672 | }; |
| 1673 | if (OpKind == tok::l_paren || !LHS.isInvalid()) { |
| 1674 | if (Tok.isNot(tok::r_paren)) { |
| 1675 | if (ParseExpressionList(ArgExprs, CommaLocs, [&] { |
| 1676 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
| 1677 | RunSignatureHelp); |
| 1678 | })) { |
| 1679 | (void)Actions.CorrectDelayedTyposInExpr(LHS); |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
| 1685 | RunSignatureHelp(); |
| 1686 | LHS = ExprError(); |
| 1687 | } else if (LHS.isInvalid()) { |
| 1688 | for (auto &E : ArgExprs) |
| 1689 | Actions.CorrectDelayedTyposInExpr(E); |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | if (LHS.isInvalid()) { |
| 1696 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1697 | } else if (Tok.isNot(tok::r_paren)) { |
| 1698 | bool HadDelayedTypo = false; |
| 1699 | if (Actions.CorrectDelayedTyposInExpr(LHS).get() != LHS.get()) |
| 1700 | HadDelayedTypo = true; |
| 1701 | for (auto &E : ArgExprs) |
| 1702 | if (Actions.CorrectDelayedTyposInExpr(E).get() != E) |
| 1703 | HadDelayedTypo = true; |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | if (HadDelayedTypo) |
| 1708 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1709 | else |
| 1710 | PT.consumeClose(); |
| 1711 | LHS = ExprError(); |
| 1712 | } else { |
| 1713 | (0) . __assert_fail ("(ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&& \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1715, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert((ArgExprs.size() == 0 || |
| 1714 | (0) . __assert_fail ("(ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&& \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1715, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> ArgExprs.size()-1 == CommaLocs.size())&& |
| 1715 | (0) . __assert_fail ("(ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&& \"Unexpected number of commas!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1715, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Unexpected number of commas!"); |
| 1716 | LHS = Actions.ActOnCallExpr(getCurScope(), LHS.get(), Loc, |
| 1717 | ArgExprs, Tok.getLocation(), |
| 1718 | ExecConfig); |
| 1719 | PT.consumeClose(); |
| 1720 | } |
| 1721 | |
| 1722 | break; |
| 1723 | } |
| 1724 | case tok::arrow: |
| 1725 | case tok::period: { |
| 1726 | |
| 1727 | |
| 1728 | tok::TokenKind OpKind = Tok.getKind(); |
| 1729 | SourceLocation OpLoc = ConsumeToken(); |
| 1730 | |
| 1731 | CXXScopeSpec SS; |
| 1732 | ParsedType ObjectType; |
| 1733 | bool MayBePseudoDestructor = false; |
| 1734 | Expr* OrigLHS = !LHS.isInvalid() ? LHS.get() : nullptr; |
| 1735 | |
| 1736 | PreferredType.enterMemAccess(Actions, Tok.getLocation(), OrigLHS); |
| 1737 | |
| 1738 | if (getLangOpts().CPlusPlus && !LHS.isInvalid()) { |
| 1739 | Expr *Base = OrigLHS; |
| 1740 | const Type* BaseType = Base->getType().getTypePtrOrNull(); |
| 1741 | if (BaseType && Tok.is(tok::l_paren) && |
| 1742 | (BaseType->isFunctionType() || |
| 1743 | BaseType->isSpecificPlaceholderType(BuiltinType::BoundMember))) { |
| 1744 | Diag(OpLoc, diag::err_function_is_not_record) |
| 1745 | << OpKind << Base->getSourceRange() |
| 1746 | << FixItHint::CreateRemoval(OpLoc); |
| 1747 | return ParsePostfixExpressionSuffix(Base); |
| 1748 | } |
| 1749 | |
| 1750 | LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base, |
| 1751 | OpLoc, OpKind, ObjectType, |
| 1752 | MayBePseudoDestructor); |
| 1753 | if (LHS.isInvalid()) |
| 1754 | break; |
| 1755 | |
| 1756 | ParseOptionalCXXScopeSpecifier(SS, ObjectType, |
| 1757 | , |
| 1758 | &MayBePseudoDestructor); |
| 1759 | if (SS.isNotEmpty()) |
| 1760 | ObjectType = nullptr; |
| 1761 | } |
| 1762 | |
| 1763 | if (Tok.is(tok::code_completion)) { |
| 1764 | tok::TokenKind CorrectedOpKind = |
| 1765 | OpKind == tok::arrow ? tok::period : tok::arrow; |
| 1766 | ExprResult CorrectedLHS(); |
| 1767 | if (getLangOpts().CPlusPlus && OrigLHS) { |
| 1768 | const bool DiagsAreSuppressed = Diags.getSuppressAllDiagnostics(); |
| 1769 | Diags.setSuppressAllDiagnostics(true); |
| 1770 | CorrectedLHS = Actions.ActOnStartCXXMemberReference( |
| 1771 | getCurScope(), OrigLHS, OpLoc, CorrectedOpKind, ObjectType, |
| 1772 | MayBePseudoDestructor); |
| 1773 | Diags.setSuppressAllDiagnostics(DiagsAreSuppressed); |
| 1774 | } |
| 1775 | |
| 1776 | Expr *Base = LHS.get(); |
| 1777 | Expr *CorrectedBase = CorrectedLHS.get(); |
| 1778 | if (!CorrectedBase && !getLangOpts().CPlusPlus) |
| 1779 | CorrectedBase = Base; |
| 1780 | |
| 1781 | |
| 1782 | Actions.CodeCompleteMemberReferenceExpr( |
| 1783 | getCurScope(), Base, CorrectedBase, OpLoc, OpKind == tok::arrow, |
| 1784 | Base && ExprStatementTokLoc == Base->getBeginLoc(), |
| 1785 | PreferredType.get(Tok.getLocation())); |
| 1786 | |
| 1787 | cutOffParsing(); |
| 1788 | return ExprError(); |
| 1789 | } |
| 1790 | |
| 1791 | if (MayBePseudoDestructor && !LHS.isInvalid()) { |
| 1792 | LHS = ParseCXXPseudoDestructor(LHS.get(), OpLoc, OpKind, SS, |
| 1793 | ObjectType); |
| 1794 | break; |
| 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | SourceLocation TemplateKWLoc; |
| 1805 | UnqualifiedId Name; |
| 1806 | if (getLangOpts().ObjC && OpKind == tok::period && |
| 1807 | Tok.is(tok::kw_class)) { |
| 1808 | |
| 1809 | |
| 1810 | |
| 1811 | |
| 1812 | |
| 1813 | |
| 1814 | |
| 1815 | IdentifierInfo *Id = Tok.getIdentifierInfo(); |
| 1816 | SourceLocation Loc = ConsumeToken(); |
| 1817 | Name.setIdentifier(Id, Loc); |
| 1818 | } else if (ParseUnqualifiedId(SS, |
| 1819 | , |
| 1820 | , |
| 1821 | |
| 1822 | getLangOpts().MicrosoftExt && |
| 1823 | SS.isNotEmpty(), |
| 1824 | , |
| 1825 | ObjectType, &TemplateKWLoc, Name)) { |
| 1826 | (void)Actions.CorrectDelayedTyposInExpr(LHS); |
| 1827 | LHS = ExprError(); |
| 1828 | } |
| 1829 | |
| 1830 | if (!LHS.isInvalid()) |
| 1831 | LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.get(), OpLoc, |
| 1832 | OpKind, SS, TemplateKWLoc, Name, |
| 1833 | CurParsedObjCImpl ? CurParsedObjCImpl->Dcl |
| 1834 | : nullptr); |
| 1835 | if (!LHS.isInvalid() && Tok.is(tok::less)) |
| 1836 | checkPotentialAngleBracket(LHS); |
| 1837 | break; |
| 1838 | } |
| 1839 | case tok::plusplus: |
| 1840 | case tok::minusminus: |
| 1841 | if (!LHS.isInvalid()) { |
| 1842 | LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(), |
| 1843 | Tok.getKind(), LHS.get()); |
| 1844 | } |
| 1845 | ConsumeToken(); |
| 1846 | break; |
| 1847 | } |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | ExprResult |
| 1875 | Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, |
| 1876 | bool &isCastExpr, |
| 1877 | ParsedType &CastTy, |
| 1878 | SourceRange &CastRange) { |
| 1879 | |
| 1880 | (0) . __assert_fail ("OpTok.isOneOf(tok..kw_typeof, tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a typeof/sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1883, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof, |
| 1881 | (0) . __assert_fail ("OpTok.isOneOf(tok..kw_typeof, tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a typeof/sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1883, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step, |
| 1882 | (0) . __assert_fail ("OpTok.isOneOf(tok..kw_typeof, tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a typeof/sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1883, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> tok::kw___builtin_omp_required_simd_align) && |
| 1883 | (0) . __assert_fail ("OpTok.isOneOf(tok..kw_typeof, tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a typeof/sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1883, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not a typeof/sizeof/alignof/vec_step expression!"); |
| 1884 | |
| 1885 | ExprResult Operand; |
| 1886 | |
| 1887 | |
| 1888 | if (Tok.isNot(tok::l_paren)) { |
| 1889 | |
| 1890 | |
| 1891 | if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof, |
| 1892 | tok::kw__Alignof)) { |
| 1893 | if (isTypeIdUnambiguously()) { |
| 1894 | DeclSpec DS(AttrFactory); |
| 1895 | ParseSpecifierQualifierList(DS); |
| 1896 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 1897 | ParseDeclarator(DeclaratorInfo); |
| 1898 | |
| 1899 | SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation()); |
| 1900 | SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); |
| 1901 | Diag(LParenLoc, diag::err_expected_parentheses_around_typename) |
| 1902 | << OpTok.getName() |
| 1903 | << FixItHint::CreateInsertion(LParenLoc, "(") |
| 1904 | << FixItHint::CreateInsertion(RParenLoc, ")"); |
| 1905 | isCastExpr = true; |
| 1906 | return ExprEmpty(); |
| 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | isCastExpr = false; |
| 1911 | if (OpTok.is(tok::kw_typeof) && !getLangOpts().CPlusPlus) { |
| 1912 | Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo() |
| 1913 | << tok::l_paren; |
| 1914 | return ExprError(); |
| 1915 | } |
| 1916 | |
| 1917 | Operand = ParseCastExpression(true); |
| 1918 | } else { |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | ParenParseOption ExprType = CastExpr; |
| 1924 | SourceLocation LParenLoc = Tok.getLocation(), RParenLoc; |
| 1925 | |
| 1926 | Operand = ParseParenExpression(ExprType, true, |
| 1927 | false, CastTy, RParenLoc); |
| 1928 | CastRange = SourceRange(LParenLoc, RParenLoc); |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | if (ExprType == CastExpr) { |
| 1933 | isCastExpr = true; |
| 1934 | return ExprEmpty(); |
| 1935 | } |
| 1936 | |
| 1937 | if (getLangOpts().CPlusPlus || OpTok.isNot(tok::kw_typeof)) { |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | if (!Operand.isInvalid()) |
| 1943 | Operand = ParsePostfixExpressionSuffix(Operand.get()); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | |
| 1948 | isCastExpr = false; |
| 1949 | return Operand; |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | ExprResult Parser::ParseUnaryExprOrTypeTraitExpression() { |
| 1966 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1969, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof, |
| 1967 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1969, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> tok::kw__Alignof, tok::kw_vec_step, |
| 1968 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1969, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> tok::kw___builtin_omp_required_simd_align) && |
| 1969 | (0) . __assert_fail ("Tok.isOneOf(tok..kw_sizeof, tok..kw___alignof, tok..kw_alignof, tok..kw__Alignof, tok..kw_vec_step, tok..kw___builtin_omp_required_simd_align) && \"Not a sizeof/alignof/vec_step expression!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 1969, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "Not a sizeof/alignof/vec_step expression!"); |
| 1970 | Token OpTok = Tok; |
| 1971 | ConsumeToken(); |
| 1972 | |
| 1973 | |
| 1974 | if (Tok.is(tok::ellipsis) && OpTok.is(tok::kw_sizeof)) { |
| 1975 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 1976 | SourceLocation LParenLoc, RParenLoc; |
| 1977 | IdentifierInfo *Name = nullptr; |
| 1978 | SourceLocation NameLoc; |
| 1979 | if (Tok.is(tok::l_paren)) { |
| 1980 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 1981 | T.consumeOpen(); |
| 1982 | LParenLoc = T.getOpenLocation(); |
| 1983 | if (Tok.is(tok::identifier)) { |
| 1984 | Name = Tok.getIdentifierInfo(); |
| 1985 | NameLoc = ConsumeToken(); |
| 1986 | T.consumeClose(); |
| 1987 | RParenLoc = T.getCloseLocation(); |
| 1988 | if (RParenLoc.isInvalid()) |
| 1989 | RParenLoc = PP.getLocForEndOfToken(NameLoc); |
| 1990 | } else { |
| 1991 | Diag(Tok, diag::err_expected_parameter_pack); |
| 1992 | SkipUntil(tok::r_paren, StopAtSemi); |
| 1993 | } |
| 1994 | } else if (Tok.is(tok::identifier)) { |
| 1995 | Name = Tok.getIdentifierInfo(); |
| 1996 | NameLoc = ConsumeToken(); |
| 1997 | LParenLoc = PP.getLocForEndOfToken(EllipsisLoc); |
| 1998 | RParenLoc = PP.getLocForEndOfToken(NameLoc); |
| 1999 | Diag(LParenLoc, diag::err_paren_sizeof_parameter_pack) |
| 2000 | << Name |
| 2001 | << FixItHint::CreateInsertion(LParenLoc, "(") |
| 2002 | << FixItHint::CreateInsertion(RParenLoc, ")"); |
| 2003 | } else { |
| 2004 | Diag(Tok, diag::err_sizeof_parameter_pack); |
| 2005 | } |
| 2006 | |
| 2007 | if (!Name) |
| 2008 | return ExprError(); |
| 2009 | |
| 2010 | EnterExpressionEvaluationContext Unevaluated( |
| 2011 | Actions, Sema::ExpressionEvaluationContext::Unevaluated, |
| 2012 | Sema::ReuseLambdaContextDecl); |
| 2013 | |
| 2014 | return Actions.ActOnSizeofParameterPackExpr(getCurScope(), |
| 2015 | OpTok.getLocation(), |
| 2016 | *Name, NameLoc, |
| 2017 | RParenLoc); |
| 2018 | } |
| 2019 | |
| 2020 | if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof)) |
| 2021 | Diag(OpTok, diag::warn_cxx98_compat_alignof); |
| 2022 | |
| 2023 | EnterExpressionEvaluationContext Unevaluated( |
| 2024 | Actions, Sema::ExpressionEvaluationContext::Unevaluated, |
| 2025 | Sema::ReuseLambdaContextDecl); |
| 2026 | |
| 2027 | bool isCastExpr; |
| 2028 | ParsedType CastTy; |
| 2029 | SourceRange CastRange; |
| 2030 | ExprResult Operand = ParseExprAfterUnaryExprOrTypeTrait(OpTok, |
| 2031 | isCastExpr, |
| 2032 | CastTy, |
| 2033 | CastRange); |
| 2034 | |
| 2035 | UnaryExprOrTypeTrait ExprKind = UETT_SizeOf; |
| 2036 | if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof)) |
| 2037 | ExprKind = UETT_AlignOf; |
| 2038 | else if (OpTok.is(tok::kw___alignof)) |
| 2039 | ExprKind = UETT_PreferredAlignOf; |
| 2040 | else if (OpTok.is(tok::kw_vec_step)) |
| 2041 | ExprKind = UETT_VecStep; |
| 2042 | else if (OpTok.is(tok::kw___builtin_omp_required_simd_align)) |
| 2043 | ExprKind = UETT_OpenMPRequiredSimdAlign; |
| 2044 | |
| 2045 | if (isCastExpr) |
| 2046 | return Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(), |
| 2047 | ExprKind, |
| 2048 | , |
| 2049 | CastTy.getAsOpaquePtr(), |
| 2050 | CastRange); |
| 2051 | |
| 2052 | if (OpTok.isOneOf(tok::kw_alignof, tok::kw__Alignof)) |
| 2053 | Diag(OpTok, diag::ext_alignof_expr) << OpTok.getIdentifierInfo(); |
| 2054 | |
| 2055 | |
| 2056 | if (!Operand.isInvalid()) |
| 2057 | Operand = Actions.ActOnUnaryExprOrTypeTraitExpr(OpTok.getLocation(), |
| 2058 | ExprKind, |
| 2059 | , |
| 2060 | Operand.get(), |
| 2061 | CastRange); |
| 2062 | return Operand; |
| 2063 | } |
| 2064 | |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | ExprResult Parser::ParseBuiltinPrimaryExpression() { |
| 2082 | ExprResult Res; |
| 2083 | const IdentifierInfo *BuiltinII = Tok.getIdentifierInfo(); |
| 2084 | |
| 2085 | tok::TokenKind T = Tok.getKind(); |
| 2086 | SourceLocation StartLoc = ConsumeToken(); |
| 2087 | |
| 2088 | |
| 2089 | if (Tok.isNot(tok::l_paren)) |
| 2090 | return ExprError(Diag(Tok, diag::err_expected_after) << BuiltinII |
| 2091 | << tok::l_paren); |
| 2092 | |
| 2093 | BalancedDelimiterTracker PT(*this, tok::l_paren); |
| 2094 | PT.consumeOpen(); |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | switch (T) { |
| 2099 | default: llvm_unreachable("Not a builtin primary expression!"); |
| 2100 | case tok::kw___builtin_va_arg: { |
| 2101 | ExprResult Expr(ParseAssignmentExpression()); |
| 2102 | |
| 2103 | if (ExpectAndConsume(tok::comma)) { |
| 2104 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2105 | Expr = ExprError(); |
| 2106 | } |
| 2107 | |
| 2108 | TypeResult Ty = ParseTypeName(); |
| 2109 | |
| 2110 | if (Tok.isNot(tok::r_paren)) { |
| 2111 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2112 | Expr = ExprError(); |
| 2113 | } |
| 2114 | |
| 2115 | if (Expr.isInvalid() || Ty.isInvalid()) |
| 2116 | Res = ExprError(); |
| 2117 | else |
| 2118 | Res = Actions.ActOnVAArg(StartLoc, Expr.get(), Ty.get(), ConsumeParen()); |
| 2119 | break; |
| 2120 | } |
| 2121 | case tok::kw___builtin_offsetof: { |
| 2122 | SourceLocation TypeLoc = Tok.getLocation(); |
| 2123 | TypeResult Ty = ParseTypeName(); |
| 2124 | if (Ty.isInvalid()) { |
| 2125 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2126 | return ExprError(); |
| 2127 | } |
| 2128 | |
| 2129 | if (ExpectAndConsume(tok::comma)) { |
| 2130 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2131 | return ExprError(); |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | if (Tok.isNot(tok::identifier)) { |
| 2136 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 2137 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2138 | return ExprError(); |
| 2139 | } |
| 2140 | |
| 2141 | |
| 2142 | SmallVector<Sema::OffsetOfComponent, 4> Comps; |
| 2143 | |
| 2144 | Comps.push_back(Sema::OffsetOfComponent()); |
| 2145 | Comps.back().isBrackets = false; |
| 2146 | Comps.back().U.IdentInfo = Tok.getIdentifierInfo(); |
| 2147 | Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken(); |
| 2148 | |
| 2149 | |
| 2150 | while (1) { |
| 2151 | if (Tok.is(tok::period)) { |
| 2152 | |
| 2153 | Comps.push_back(Sema::OffsetOfComponent()); |
| 2154 | Comps.back().isBrackets = false; |
| 2155 | Comps.back().LocStart = ConsumeToken(); |
| 2156 | |
| 2157 | if (Tok.isNot(tok::identifier)) { |
| 2158 | Diag(Tok, diag::err_expected) << tok::identifier; |
| 2159 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2160 | return ExprError(); |
| 2161 | } |
| 2162 | Comps.back().U.IdentInfo = Tok.getIdentifierInfo(); |
| 2163 | Comps.back().LocEnd = ConsumeToken(); |
| 2164 | |
| 2165 | } else if (Tok.is(tok::l_square)) { |
| 2166 | if (CheckProhibitedCXX11Attribute()) |
| 2167 | return ExprError(); |
| 2168 | |
| 2169 | |
| 2170 | Comps.push_back(Sema::OffsetOfComponent()); |
| 2171 | Comps.back().isBrackets = true; |
| 2172 | BalancedDelimiterTracker ST(*this, tok::l_square); |
| 2173 | ST.consumeOpen(); |
| 2174 | Comps.back().LocStart = ST.getOpenLocation(); |
| 2175 | Res = ParseExpression(); |
| 2176 | if (Res.isInvalid()) { |
| 2177 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2178 | return Res; |
| 2179 | } |
| 2180 | Comps.back().U.E = Res.get(); |
| 2181 | |
| 2182 | ST.consumeClose(); |
| 2183 | Comps.back().LocEnd = ST.getCloseLocation(); |
| 2184 | } else { |
| 2185 | if (Tok.isNot(tok::r_paren)) { |
| 2186 | PT.consumeClose(); |
| 2187 | Res = ExprError(); |
| 2188 | } else if (Ty.isInvalid()) { |
| 2189 | Res = ExprError(); |
| 2190 | } else { |
| 2191 | PT.consumeClose(); |
| 2192 | Res = Actions.ActOnBuiltinOffsetOf(getCurScope(), StartLoc, TypeLoc, |
| 2193 | Ty.get(), Comps, |
| 2194 | PT.getCloseLocation()); |
| 2195 | } |
| 2196 | break; |
| 2197 | } |
| 2198 | } |
| 2199 | break; |
| 2200 | } |
| 2201 | case tok::kw___builtin_choose_expr: { |
| 2202 | ExprResult Cond(ParseAssignmentExpression()); |
| 2203 | if (Cond.isInvalid()) { |
| 2204 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2205 | return Cond; |
| 2206 | } |
| 2207 | if (ExpectAndConsume(tok::comma)) { |
| 2208 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2209 | return ExprError(); |
| 2210 | } |
| 2211 | |
| 2212 | ExprResult Expr1(ParseAssignmentExpression()); |
| 2213 | if (Expr1.isInvalid()) { |
| 2214 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2215 | return Expr1; |
| 2216 | } |
| 2217 | if (ExpectAndConsume(tok::comma)) { |
| 2218 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2219 | return ExprError(); |
| 2220 | } |
| 2221 | |
| 2222 | ExprResult Expr2(ParseAssignmentExpression()); |
| 2223 | if (Expr2.isInvalid()) { |
| 2224 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2225 | return Expr2; |
| 2226 | } |
| 2227 | if (Tok.isNot(tok::r_paren)) { |
| 2228 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2229 | return ExprError(); |
| 2230 | } |
| 2231 | Res = Actions.ActOnChooseExpr(StartLoc, Cond.get(), Expr1.get(), |
| 2232 | Expr2.get(), ConsumeParen()); |
| 2233 | break; |
| 2234 | } |
| 2235 | case tok::kw___builtin_astype: { |
| 2236 | |
| 2237 | ExprResult Expr(ParseAssignmentExpression()); |
| 2238 | if (Expr.isInvalid()) { |
| 2239 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2240 | return ExprError(); |
| 2241 | } |
| 2242 | |
| 2243 | if (ExpectAndConsume(tok::comma)) { |
| 2244 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2245 | return ExprError(); |
| 2246 | } |
| 2247 | |
| 2248 | |
| 2249 | TypeResult DestTy = ParseTypeName(); |
| 2250 | if (DestTy.isInvalid()) |
| 2251 | return ExprError(); |
| 2252 | |
| 2253 | |
| 2254 | if (Tok.isNot(tok::r_paren)) { |
| 2255 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2256 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2257 | return ExprError(); |
| 2258 | } |
| 2259 | |
| 2260 | Res = Actions.ActOnAsTypeExpr(Expr.get(), DestTy.get(), StartLoc, |
| 2261 | ConsumeParen()); |
| 2262 | break; |
| 2263 | } |
| 2264 | case tok::kw___builtin_convertvector: { |
| 2265 | |
| 2266 | ExprResult Expr(ParseAssignmentExpression()); |
| 2267 | if (Expr.isInvalid()) { |
| 2268 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2269 | return ExprError(); |
| 2270 | } |
| 2271 | |
| 2272 | if (ExpectAndConsume(tok::comma)) { |
| 2273 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2274 | return ExprError(); |
| 2275 | } |
| 2276 | |
| 2277 | |
| 2278 | TypeResult DestTy = ParseTypeName(); |
| 2279 | if (DestTy.isInvalid()) |
| 2280 | return ExprError(); |
| 2281 | |
| 2282 | |
| 2283 | if (Tok.isNot(tok::r_paren)) { |
| 2284 | Diag(Tok, diag::err_expected) << tok::r_paren; |
| 2285 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2286 | return ExprError(); |
| 2287 | } |
| 2288 | |
| 2289 | Res = Actions.ActOnConvertVectorExpr(Expr.get(), DestTy.get(), StartLoc, |
| 2290 | ConsumeParen()); |
| 2291 | break; |
| 2292 | } |
| 2293 | } |
| 2294 | |
| 2295 | if (Res.isInvalid()) |
| 2296 | return ExprError(); |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | return ParsePostfixExpressionSuffix(Res.get()); |
| 2301 | } |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | |
| 2327 | |
| 2328 | ExprResult |
| 2329 | Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, |
| 2330 | bool isTypeCast, ParsedType &CastTy, |
| 2331 | SourceLocation &RParenLoc) { |
| 2332 | (0) . __assert_fail ("Tok.is(tok..l_paren) && \"Not a paren expr!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2332, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_paren) && "Not a paren expr!"); |
| 2333 | ColonProtectionRAIIObject ColonProtection(*this, false); |
| 2334 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2335 | if (T.consumeOpen()) |
| 2336 | return ExprError(); |
| 2337 | SourceLocation OpenLoc = T.getOpenLocation(); |
| 2338 | |
| 2339 | PreferredType.enterParenExpr(Tok.getLocation(), OpenLoc); |
| 2340 | |
| 2341 | ExprResult Result(true); |
| 2342 | bool isAmbiguousTypeId; |
| 2343 | CastTy = nullptr; |
| 2344 | |
| 2345 | if (Tok.is(tok::code_completion)) { |
| 2346 | Actions.CodeCompleteExpression( |
| 2347 | getCurScope(), PreferredType.get(Tok.getLocation()), |
| 2348 | ExprType >= CompoundLiteral); |
| 2349 | cutOffParsing(); |
| 2350 | return ExprError(); |
| 2351 | } |
| 2352 | |
| 2353 | |
| 2354 | bool BridgeCast = (getLangOpts().ObjC && |
| 2355 | Tok.isOneOf(tok::kw___bridge, |
| 2356 | tok::kw___bridge_transfer, |
| 2357 | tok::kw___bridge_retained, |
| 2358 | tok::kw___bridge_retain)); |
| 2359 | if (BridgeCast && !getLangOpts().ObjCAutoRefCount) { |
| 2360 | if (!TryConsumeToken(tok::kw___bridge)) { |
| 2361 | StringRef BridgeCastName = Tok.getName(); |
| 2362 | SourceLocation BridgeKeywordLoc = ConsumeToken(); |
| 2363 | if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc)) |
| 2364 | Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc) |
| 2365 | << BridgeCastName |
| 2366 | << FixItHint::CreateReplacement(BridgeKeywordLoc, ""); |
| 2367 | } |
| 2368 | BridgeCast = false; |
| 2369 | } |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) { |
| 2374 | Diag(Tok, diag::ext_gnu_statement_expr); |
| 2375 | |
| 2376 | if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) { |
| 2377 | Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope)); |
| 2378 | } else { |
| 2379 | |
| 2380 | |
| 2381 | |
| 2382 | DeclContext *CodeDC = Actions.CurContext; |
| 2383 | while (CodeDC->isRecord() || isa<EnumDecl>(CodeDC)) { |
| 2384 | CodeDC = CodeDC->getParent(); |
| 2385 | (0) . __assert_fail ("CodeDC && !CodeDC->isFileContext() && \"statement expr not in code context\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2386, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(CodeDC && !CodeDC->isFileContext() && |
| 2386 | (0) . __assert_fail ("CodeDC && !CodeDC->isFileContext() && \"statement expr not in code context\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2386, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true"> "statement expr not in code context"); |
| 2387 | } |
| 2388 | Sema::ContextRAII SavedContext(Actions, CodeDC, ); |
| 2389 | |
| 2390 | Actions.ActOnStartStmtExpr(); |
| 2391 | |
| 2392 | StmtResult Stmt(ParseCompoundStatement(true)); |
| 2393 | ExprType = CompoundStmt; |
| 2394 | |
| 2395 | |
| 2396 | if (!Stmt.isInvalid()) { |
| 2397 | Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.get(), Tok.getLocation()); |
| 2398 | } else { |
| 2399 | Actions.ActOnStmtExprError(); |
| 2400 | } |
| 2401 | } |
| 2402 | } else if (ExprType >= CompoundLiteral && BridgeCast) { |
| 2403 | tok::TokenKind tokenKind = Tok.getKind(); |
| 2404 | SourceLocation BridgeKeywordLoc = ConsumeToken(); |
| 2405 | |
| 2406 | |
| 2407 | ObjCBridgeCastKind Kind; |
| 2408 | if (tokenKind == tok::kw___bridge) |
| 2409 | Kind = OBC_Bridge; |
| 2410 | else if (tokenKind == tok::kw___bridge_transfer) |
| 2411 | Kind = OBC_BridgeTransfer; |
| 2412 | else if (tokenKind == tok::kw___bridge_retained) |
| 2413 | Kind = OBC_BridgeRetained; |
| 2414 | else { |
| 2415 | |
| 2416 | |
| 2417 | assert(tokenKind == tok::kw___bridge_retain); |
| 2418 | Kind = OBC_BridgeRetained; |
| 2419 | if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc)) |
| 2420 | Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain) |
| 2421 | << FixItHint::CreateReplacement(BridgeKeywordLoc, |
| 2422 | "__bridge_retained"); |
| 2423 | } |
| 2424 | |
| 2425 | TypeResult Ty = ParseTypeName(); |
| 2426 | T.consumeClose(); |
| 2427 | ColonProtection.restore(); |
| 2428 | RParenLoc = T.getCloseLocation(); |
| 2429 | |
| 2430 | PreferredType.enterTypeCast(Tok.getLocation(), Ty.get().get()); |
| 2431 | ExprResult SubExpr = ParseCastExpression(); |
| 2432 | |
| 2433 | if (Ty.isInvalid() || SubExpr.isInvalid()) |
| 2434 | return ExprError(); |
| 2435 | |
| 2436 | return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind, |
| 2437 | BridgeKeywordLoc, Ty.get(), |
| 2438 | RParenLoc, SubExpr.get()); |
| 2439 | } else if (ExprType >= CompoundLiteral && |
| 2440 | isTypeIdInParens(isAmbiguousTypeId)) { |
| 2441 | |
| 2442 | |
| 2443 | |
| 2444 | |
| 2445 | |
| 2446 | |
| 2447 | |
| 2448 | |
| 2449 | if (isAmbiguousTypeId && !stopIfCastExpr) { |
| 2450 | ExprResult res = ParseCXXAmbiguousParenExpression(ExprType, CastTy, T, |
| 2451 | ColonProtection); |
| 2452 | RParenLoc = T.getCloseLocation(); |
| 2453 | return res; |
| 2454 | } |
| 2455 | |
| 2456 | |
| 2457 | DeclSpec DS(AttrFactory); |
| 2458 | ParseSpecifierQualifierList(DS); |
| 2459 | Declarator DeclaratorInfo(DS, DeclaratorContext::TypeNameContext); |
| 2460 | ParseDeclarator(DeclaratorInfo); |
| 2461 | |
| 2462 | |
| 2463 | |
| 2464 | |
| 2465 | if (!DeclaratorInfo.isInvalidType() && Tok.is(tok::identifier) && |
| 2466 | !InMessageExpression && getLangOpts().ObjC && |
| 2467 | (NextToken().is(tok::colon) || NextToken().is(tok::r_square))) { |
| 2468 | TypeResult Ty; |
| 2469 | { |
| 2470 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 2471 | Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 2472 | } |
| 2473 | Result = ParseObjCMessageExpressionBody(SourceLocation(), |
| 2474 | SourceLocation(), |
| 2475 | Ty.get(), nullptr); |
| 2476 | } else { |
| 2477 | |
| 2478 | T.consumeClose(); |
| 2479 | ColonProtection.restore(); |
| 2480 | RParenLoc = T.getCloseLocation(); |
| 2481 | if (Tok.is(tok::l_brace)) { |
| 2482 | ExprType = CompoundLiteral; |
| 2483 | TypeResult Ty; |
| 2484 | { |
| 2485 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 2486 | Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 2487 | } |
| 2488 | return ParseCompoundLiteralExpression(Ty.get(), OpenLoc, RParenLoc); |
| 2489 | } |
| 2490 | |
| 2491 | if (Tok.is(tok::l_paren)) { |
| 2492 | |
| 2493 | if (getLangOpts().OpenCL) |
| 2494 | { |
| 2495 | TypeResult Ty; |
| 2496 | { |
| 2497 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 2498 | Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 2499 | } |
| 2500 | if(Ty.isInvalid()) |
| 2501 | { |
| 2502 | return ExprError(); |
| 2503 | } |
| 2504 | QualType QT = Ty.get().get().getCanonicalType(); |
| 2505 | if (QT->isVectorType()) |
| 2506 | { |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | |
| 2511 | |
| 2512 | Result = ParseCastExpression(, |
| 2513 | , |
| 2514 | , |
| 2515 | ); |
| 2516 | |
| 2517 | if (!Result.isInvalid()) { |
| 2518 | Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc, |
| 2519 | DeclaratorInfo, CastTy, |
| 2520 | RParenLoc, Result.get()); |
| 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | if (!Result.isInvalid()) { |
| 2525 | Result = ParsePostfixExpressionSuffix(Result); |
| 2526 | } |
| 2527 | |
| 2528 | return Result; |
| 2529 | } |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | if (ExprType == CastExpr) { |
| 2534 | |
| 2535 | |
| 2536 | if (DeclaratorInfo.isInvalidType()) |
| 2537 | return ExprError(); |
| 2538 | |
| 2539 | |
| 2540 | |
| 2541 | if (stopIfCastExpr) { |
| 2542 | TypeResult Ty; |
| 2543 | { |
| 2544 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 2545 | Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
| 2546 | } |
| 2547 | CastTy = Ty.get(); |
| 2548 | return ExprResult(); |
| 2549 | } |
| 2550 | |
| 2551 | |
| 2552 | if (Tok.is(tok::identifier) && getLangOpts().ObjC && |
| 2553 | Tok.getIdentifierInfo() == Ident_super && |
| 2554 | getCurScope()->isInObjcMethodScope() && |
| 2555 | GetLookAheadToken(1).isNot(tok::period)) { |
| 2556 | Diag(Tok.getLocation(), diag::err_illegal_super_cast) |
| 2557 | << SourceRange(OpenLoc, RParenLoc); |
| 2558 | return ExprError(); |
| 2559 | } |
| 2560 | |
| 2561 | PreferredType.enterTypeCast(Tok.getLocation(), CastTy.get()); |
| 2562 | |
| 2563 | |
| 2564 | Result = ParseCastExpression(, |
| 2565 | , |
| 2566 | ); |
| 2567 | if (!Result.isInvalid()) { |
| 2568 | Result = Actions.ActOnCastExpr(getCurScope(), OpenLoc, |
| 2569 | DeclaratorInfo, CastTy, |
| 2570 | RParenLoc, Result.get()); |
| 2571 | } |
| 2572 | return Result; |
| 2573 | } |
| 2574 | |
| 2575 | Diag(Tok, diag::err_expected_lbrace_in_compound_literal); |
| 2576 | return ExprError(); |
| 2577 | } |
| 2578 | } else if (ExprType >= FoldExpr && Tok.is(tok::ellipsis) && |
| 2579 | isFoldOperator(NextToken().getKind())) { |
| 2580 | ExprType = FoldExpr; |
| 2581 | return ParseFoldExpression(ExprResult(), T); |
| 2582 | } else if (isTypeCast) { |
| 2583 | |
| 2584 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 2585 | |
| 2586 | ExprVector ArgExprs; |
| 2587 | CommaLocsTy CommaLocs; |
| 2588 | |
| 2589 | if (!ParseSimpleExpressionList(ArgExprs, CommaLocs)) { |
| 2590 | |
| 2591 | |
| 2592 | if (ExprType >= FoldExpr && ArgExprs.size() == 1 && |
| 2593 | isFoldOperator(Tok.getKind()) && NextToken().is(tok::ellipsis)) { |
| 2594 | ExprType = FoldExpr; |
| 2595 | return ParseFoldExpression(ArgExprs[0], T); |
| 2596 | } |
| 2597 | |
| 2598 | ExprType = SimpleExpr; |
| 2599 | Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(), |
| 2600 | ArgExprs); |
| 2601 | } |
| 2602 | } else { |
| 2603 | InMessageExpressionRAIIObject InMessage(*this, false); |
| 2604 | |
| 2605 | Result = ParseExpression(MaybeTypeCast); |
| 2606 | if (!getLangOpts().CPlusPlus && MaybeTypeCast && Result.isUsable()) { |
| 2607 | |
| 2608 | |
| 2609 | Result = Actions.CorrectDelayedTyposInExpr(Result); |
| 2610 | } |
| 2611 | |
| 2612 | if (ExprType >= FoldExpr && isFoldOperator(Tok.getKind()) && |
| 2613 | NextToken().is(tok::ellipsis)) { |
| 2614 | ExprType = FoldExpr; |
| 2615 | return ParseFoldExpression(Result, T); |
| 2616 | } |
| 2617 | ExprType = SimpleExpr; |
| 2618 | |
| 2619 | |
| 2620 | if (!Result.isInvalid() && Tok.is(tok::r_paren)) |
| 2621 | Result = |
| 2622 | Actions.ActOnParenExpr(OpenLoc, Tok.getLocation(), Result.get()); |
| 2623 | } |
| 2624 | |
| 2625 | |
| 2626 | if (Result.isInvalid()) { |
| 2627 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2628 | return ExprError(); |
| 2629 | } |
| 2630 | |
| 2631 | T.consumeClose(); |
| 2632 | RParenLoc = T.getCloseLocation(); |
| 2633 | return Result; |
| 2634 | } |
| 2635 | |
| 2636 | |
| 2637 | |
| 2638 | |
| 2639 | |
| 2640 | |
| 2641 | |
| 2642 | |
| 2643 | |
| 2644 | ExprResult |
| 2645 | Parser::ParseCompoundLiteralExpression(ParsedType Ty, |
| 2646 | SourceLocation LParenLoc, |
| 2647 | SourceLocation RParenLoc) { |
| 2648 | (0) . __assert_fail ("Tok.is(tok..l_brace) && \"Not a compound literal!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2648, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::l_brace) && "Not a compound literal!"); |
| 2649 | if (!getLangOpts().C99) |
| 2650 | Diag(LParenLoc, diag::ext_c99_compound_literal); |
| 2651 | ExprResult Result = ParseInitializer(); |
| 2652 | if (!Result.isInvalid() && Ty) |
| 2653 | return Actions.ActOnCompoundLiteral(LParenLoc, Ty, RParenLoc, Result.get()); |
| 2654 | return Result; |
| 2655 | } |
| 2656 | |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | |
| 2664 | |
| 2665 | Parser::ParseStringLiteralExpression(bool AllowUserDefinedLiteral) { |
| 2666 | (0) . __assert_fail ("isTokenStringLiteral() && \"Not a string literal!\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2666, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isTokenStringLiteral() && "Not a string literal!"); |
| 2667 | |
| 2668 | |
| 2669 | |
| 2670 | SmallVector<Token, 4> StringToks; |
| 2671 | |
| 2672 | do { |
| 2673 | StringToks.push_back(Tok); |
| 2674 | ConsumeStringToken(); |
| 2675 | } while (isTokenStringLiteral()); |
| 2676 | |
| 2677 | |
| 2678 | return Actions.ActOnStringLiteral(StringToks, |
| 2679 | AllowUserDefinedLiteral ? getCurScope() |
| 2680 | : nullptr); |
| 2681 | } |
| 2682 | |
| 2683 | |
| 2684 | |
| 2685 | |
| 2686 | |
| 2687 | |
| 2688 | |
| 2689 | |
| 2690 | |
| 2691 | |
| 2692 | |
| 2693 | |
| 2694 | |
| 2695 | |
| 2696 | ExprResult Parser::ParseGenericSelectionExpression() { |
| 2697 | (0) . __assert_fail ("Tok.is(tok..kw__Generic) && \"_Generic keyword expected\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2697, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::kw__Generic) && "_Generic keyword expected"); |
| 2698 | SourceLocation KeyLoc = ConsumeToken(); |
| 2699 | |
| 2700 | if (!getLangOpts().C11) |
| 2701 | Diag(KeyLoc, diag::ext_c11_generic_selection); |
| 2702 | |
| 2703 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 2704 | if (T.expectAndConsume()) |
| 2705 | return ExprError(); |
| 2706 | |
| 2707 | ExprResult ControllingExpr; |
| 2708 | { |
| 2709 | |
| 2710 | |
| 2711 | EnterExpressionEvaluationContext Unevaluated( |
| 2712 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
| 2713 | ControllingExpr = |
| 2714 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 2715 | if (ControllingExpr.isInvalid()) { |
| 2716 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2717 | return ExprError(); |
| 2718 | } |
| 2719 | } |
| 2720 | |
| 2721 | if (ExpectAndConsume(tok::comma)) { |
| 2722 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2723 | return ExprError(); |
| 2724 | } |
| 2725 | |
| 2726 | SourceLocation DefaultLoc; |
| 2727 | TypeVector Types; |
| 2728 | ExprVector Exprs; |
| 2729 | do { |
| 2730 | ParsedType Ty; |
| 2731 | if (Tok.is(tok::kw_default)) { |
| 2732 | |
| 2733 | |
| 2734 | if (!DefaultLoc.isInvalid()) { |
| 2735 | Diag(Tok, diag::err_duplicate_default_assoc); |
| 2736 | Diag(DefaultLoc, diag::note_previous_default_assoc); |
| 2737 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2738 | return ExprError(); |
| 2739 | } |
| 2740 | DefaultLoc = ConsumeToken(); |
| 2741 | Ty = nullptr; |
| 2742 | } else { |
| 2743 | ColonProtectionRAIIObject X(*this); |
| 2744 | TypeResult TR = ParseTypeName(); |
| 2745 | if (TR.isInvalid()) { |
| 2746 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2747 | return ExprError(); |
| 2748 | } |
| 2749 | Ty = TR.get(); |
| 2750 | } |
| 2751 | Types.push_back(Ty); |
| 2752 | |
| 2753 | if (ExpectAndConsume(tok::colon)) { |
| 2754 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2755 | return ExprError(); |
| 2756 | } |
| 2757 | |
| 2758 | |
| 2759 | |
| 2760 | ExprResult ER( |
| 2761 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression())); |
| 2762 | if (ER.isInvalid()) { |
| 2763 | SkipUntil(tok::r_paren, StopAtSemi); |
| 2764 | return ExprError(); |
| 2765 | } |
| 2766 | Exprs.push_back(ER.get()); |
| 2767 | } while (TryConsumeToken(tok::comma)); |
| 2768 | |
| 2769 | T.consumeClose(); |
| 2770 | if (T.getCloseLocation().isInvalid()) |
| 2771 | return ExprError(); |
| 2772 | |
| 2773 | return Actions.ActOnGenericSelectionExpr(KeyLoc, DefaultLoc, |
| 2774 | T.getCloseLocation(), |
| 2775 | ControllingExpr.get(), |
| 2776 | Types, Exprs); |
| 2777 | } |
| 2778 | |
| 2779 | |
| 2780 | |
| 2781 | |
| 2782 | |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | Parser::ParseFoldExpression(ExprResult LHS, |
| 2788 | BalancedDelimiterTracker &T) { |
| 2789 | if (LHS.isInvalid()) { |
| 2790 | T.skipToEnd(); |
| 2791 | return true; |
| 2792 | } |
| 2793 | |
| 2794 | tok::TokenKind Kind = tok::unknown; |
| 2795 | SourceLocation FirstOpLoc; |
| 2796 | if (LHS.isUsable()) { |
| 2797 | Kind = Tok.getKind(); |
| 2798 | (0) . __assert_fail ("isFoldOperator(Kind) && \"missing fold-operator\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2798, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(isFoldOperator(Kind) && "missing fold-operator"); |
| 2799 | FirstOpLoc = ConsumeToken(); |
| 2800 | } |
| 2801 | |
| 2802 | (0) . __assert_fail ("Tok.is(tok..ellipsis) && \"not a fold-expression\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2802, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::ellipsis) && "not a fold-expression"); |
| 2803 | SourceLocation EllipsisLoc = ConsumeToken(); |
| 2804 | |
| 2805 | ExprResult RHS; |
| 2806 | if (Tok.isNot(tok::r_paren)) { |
| 2807 | if (!isFoldOperator(Tok.getKind())) |
| 2808 | return Diag(Tok.getLocation(), diag::err_expected_fold_operator); |
| 2809 | |
| 2810 | if (Kind != tok::unknown && Tok.getKind() != Kind) |
| 2811 | Diag(Tok.getLocation(), diag::err_fold_operator_mismatch) |
| 2812 | << SourceRange(FirstOpLoc); |
| 2813 | Kind = Tok.getKind(); |
| 2814 | ConsumeToken(); |
| 2815 | |
| 2816 | RHS = ParseExpression(); |
| 2817 | if (RHS.isInvalid()) { |
| 2818 | T.skipToEnd(); |
| 2819 | return true; |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | Diag(EllipsisLoc, getLangOpts().CPlusPlus17 |
| 2824 | ? diag::warn_cxx14_compat_fold_expression |
| 2825 | : diag::ext_fold_expression); |
| 2826 | |
| 2827 | T.consumeClose(); |
| 2828 | return Actions.ActOnCXXFoldExpr(T.getOpenLocation(), LHS.get(), Kind, |
| 2829 | EllipsisLoc, RHS.get(), T.getCloseLocation()); |
| 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | |
| 2834 | |
| 2835 | |
| 2836 | |
| 2837 | |
| 2838 | |
| 2839 | |
| 2840 | |
| 2841 | |
| 2842 | |
| 2843 | |
| 2844 | |
| 2845 | |
| 2846 | |
| 2847 | |
| 2848 | |
| 2849 | |
| 2850 | |
| 2851 | |
| 2852 | |
| 2853 | |
| 2854 | bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, |
| 2855 | SmallVectorImpl<SourceLocation> &CommaLocs, |
| 2856 | llvm::function_ref<void()> ExpressionStarts) { |
| 2857 | bool SawError = false; |
| 2858 | while (1) { |
| 2859 | if (ExpressionStarts) |
| 2860 | ExpressionStarts(); |
| 2861 | |
| 2862 | ExprResult Expr; |
| 2863 | if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 2864 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 2865 | Expr = ParseBraceInitializer(); |
| 2866 | } else |
| 2867 | Expr = ParseAssignmentExpression(); |
| 2868 | |
| 2869 | if (Tok.is(tok::ellipsis)) |
| 2870 | Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken()); |
| 2871 | if (Expr.isInvalid()) { |
| 2872 | SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch); |
| 2873 | SawError = true; |
| 2874 | } else { |
| 2875 | Exprs.push_back(Expr.get()); |
| 2876 | } |
| 2877 | |
| 2878 | if (Tok.isNot(tok::comma)) |
| 2879 | break; |
| 2880 | |
| 2881 | Token Comma = Tok; |
| 2882 | CommaLocs.push_back(ConsumeToken()); |
| 2883 | |
| 2884 | checkPotentialAngleBracketDelimiter(Comma); |
| 2885 | } |
| 2886 | if (SawError) { |
| 2887 | |
| 2888 | |
| 2889 | for (auto &E : Exprs) { |
| 2890 | ExprResult Expr = Actions.CorrectDelayedTyposInExpr(E); |
| 2891 | if (Expr.isUsable()) E = Expr.get(); |
| 2892 | } |
| 2893 | } |
| 2894 | return SawError; |
| 2895 | } |
| 2896 | |
| 2897 | |
| 2898 | |
| 2899 | |
| 2900 | |
| 2901 | |
| 2902 | |
| 2903 | |
| 2904 | |
| 2905 | bool |
| 2906 | Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs, |
| 2907 | SmallVectorImpl<SourceLocation> &CommaLocs) { |
| 2908 | while (1) { |
| 2909 | ExprResult Expr = ParseAssignmentExpression(); |
| 2910 | if (Expr.isInvalid()) |
| 2911 | return true; |
| 2912 | |
| 2913 | Exprs.push_back(Expr.get()); |
| 2914 | |
| 2915 | if (Tok.isNot(tok::comma)) |
| 2916 | return false; |
| 2917 | |
| 2918 | |
| 2919 | Token Comma = Tok; |
| 2920 | CommaLocs.push_back(ConsumeToken()); |
| 2921 | |
| 2922 | checkPotentialAngleBracketDelimiter(Comma); |
| 2923 | } |
| 2924 | } |
| 2925 | |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | |
| 2931 | |
| 2932 | void Parser::ParseBlockId(SourceLocation CaretLoc) { |
| 2933 | if (Tok.is(tok::code_completion)) { |
| 2934 | Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type); |
| 2935 | return cutOffParsing(); |
| 2936 | } |
| 2937 | |
| 2938 | |
| 2939 | DeclSpec DS(AttrFactory); |
| 2940 | ParseSpecifierQualifierList(DS); |
| 2941 | |
| 2942 | |
| 2943 | Declarator DeclaratorInfo(DS, DeclaratorContext::BlockLiteralContext); |
| 2944 | DeclaratorInfo.setFunctionDefinitionKind(FDK_Definition); |
| 2945 | ParseDeclarator(DeclaratorInfo); |
| 2946 | |
| 2947 | MaybeParseGNUAttributes(DeclaratorInfo); |
| 2948 | |
| 2949 | |
| 2950 | Actions.ActOnBlockArguments(CaretLoc, DeclaratorInfo, getCurScope()); |
| 2951 | } |
| 2952 | |
| 2953 | |
| 2954 | |
| 2955 | |
| 2956 | |
| 2957 | |
| 2958 | |
| 2959 | |
| 2960 | |
| 2961 | |
| 2962 | |
| 2963 | ExprResult Parser::ParseBlockLiteralExpression() { |
| 2964 | (0) . __assert_fail ("Tok.is(tok..caret) && \"block literal starts with ^\"", "/home/seafit/code_projects/clang_source/clang/lib/Parse/ParseExpr.cpp", 2964, __PRETTY_FUNCTION__))" file_link="../../../include/assert.h.html#88" macro="true">assert(Tok.is(tok::caret) && "block literal starts with ^"); |
| 2965 | SourceLocation CaretLoc = ConsumeToken(); |
| 2966 | |
| 2967 | PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), CaretLoc, |
| 2968 | "block literal parsing"); |
| 2969 | |
| 2970 | |
| 2971 | |
| 2972 | |
| 2973 | |
| 2974 | ParseScope BlockScope(this, Scope::BlockScope | Scope::FnScope | |
| 2975 | Scope::CompoundStmtScope | Scope::DeclScope); |
| 2976 | |
| 2977 | |
| 2978 | Actions.ActOnBlockStart(CaretLoc, getCurScope()); |
| 2979 | |
| 2980 | |
| 2981 | DeclSpec DS(AttrFactory); |
| 2982 | Declarator ParamInfo(DS, DeclaratorContext::BlockLiteralContext); |
| 2983 | ParamInfo.setFunctionDefinitionKind(FDK_Definition); |
| 2984 | |
| 2985 | |
| 2986 | ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation())); |
| 2987 | |
| 2988 | |
| 2989 | |
| 2990 | if (Tok.is(tok::l_paren)) { |
| 2991 | ParseParenDeclarator(ParamInfo); |
| 2992 | |
| 2993 | |
| 2994 | |
| 2995 | SourceLocation Tmp = ParamInfo.getSourceRange().getEnd(); |
| 2996 | ParamInfo.SetIdentifier(nullptr, CaretLoc); |
| 2997 | ParamInfo.SetRangeEnd(Tmp); |
| 2998 | if (ParamInfo.isInvalidType()) { |
| 2999 | |
| 3000 | |
| 3001 | |
| 3002 | Actions.ActOnBlockError(CaretLoc, getCurScope()); |
| 3003 | return ExprError(); |
| 3004 | } |
| 3005 | |
| 3006 | MaybeParseGNUAttributes(ParamInfo); |
| 3007 | |
| 3008 | |
| 3009 | Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope()); |
| 3010 | } else if (!Tok.is(tok::l_brace)) { |
| 3011 | ParseBlockId(CaretLoc); |
| 3012 | } else { |
| 3013 | |
| 3014 | SourceLocation NoLoc; |
| 3015 | ParamInfo.AddTypeInfo( |
| 3016 | DeclaratorChunk::getFunction(, |
| 3017 | , |
| 3018 | NoLoc, |
| 3019 | , |
| 3020 | , |
| 3021 | NoLoc, |
| 3022 | NoLoc, |
| 3023 | , |
| 3024 | NoLoc, |
| 3025 | NoLoc, EST_None, |
| 3026 | SourceRange(), |
| 3027 | , |
| 3028 | , |
| 3029 | , |
| 3030 | , |
| 3031 | , |
| 3032 | None, CaretLoc, |
| 3033 | CaretLoc, ParamInfo), |
| 3034 | CaretLoc); |
| 3035 | |
| 3036 | MaybeParseGNUAttributes(ParamInfo); |
| 3037 | |
| 3038 | |
| 3039 | Actions.ActOnBlockArguments(CaretLoc, ParamInfo, getCurScope()); |
| 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | ExprResult Result(true); |
| 3044 | if (!Tok.is(tok::l_brace)) { |
| 3045 | |
| 3046 | Diag(Tok, diag::err_expected_expression); |
| 3047 | Actions.ActOnBlockError(CaretLoc, getCurScope()); |
| 3048 | return ExprError(); |
| 3049 | } |
| 3050 | |
| 3051 | StmtResult Stmt(ParseCompoundStatementBody()); |
| 3052 | BlockScope.Exit(); |
| 3053 | if (!Stmt.isInvalid()) |
| 3054 | Result = Actions.ActOnBlockStmtExpr(CaretLoc, Stmt.get(), getCurScope()); |
| 3055 | else |
| 3056 | Actions.ActOnBlockError(CaretLoc, getCurScope()); |
| 3057 | return Result; |
| 3058 | } |
| 3059 | |
| 3060 | |
| 3061 | |
| 3062 | |
| 3063 | |
| 3064 | ExprResult Parser::ParseObjCBoolLiteral() { |
| 3065 | tok::TokenKind Kind = Tok.getKind(); |
| 3066 | return Actions.ActOnObjCBoolLiteral(ConsumeToken(), Kind); |
| 3067 | } |
| 3068 | |
| 3069 | |
| 3070 | |
| 3071 | static bool CheckAvailabilitySpecList(Parser &P, |
| 3072 | ArrayRef<AvailabilitySpec> AvailSpecs) { |
| 3073 | llvm::SmallSet<StringRef, 4> Platforms; |
| 3074 | bool HasOtherPlatformSpec = false; |
| 3075 | bool Valid = true; |
| 3076 | for (const auto &Spec : AvailSpecs) { |
| 3077 | if (Spec.isOtherPlatformSpec()) { |
| 3078 | if (HasOtherPlatformSpec) { |
| 3079 | P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_star); |
| 3080 | Valid = false; |
| 3081 | } |
| 3082 | |
| 3083 | HasOtherPlatformSpec = true; |
| 3084 | continue; |
| 3085 | } |
| 3086 | |
| 3087 | bool Inserted = Platforms.insert(Spec.getPlatform()).second; |
| 3088 | if (!Inserted) { |
| 3089 | |
| 3090 | |
| 3091 | |
| 3092 | StringRef Platform = Spec.getPlatform(); |
| 3093 | P.Diag(Spec.getBeginLoc(), diag::err_availability_query_repeated_platform) |
| 3094 | << Spec.getEndLoc() << Platform; |
| 3095 | Valid = false; |
| 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | if (!HasOtherPlatformSpec) { |
| 3100 | SourceLocation InsertWildcardLoc = AvailSpecs.back().getEndLoc(); |
| 3101 | P.Diag(InsertWildcardLoc, diag::err_availability_query_wildcard_required) |
| 3102 | << FixItHint::CreateInsertion(InsertWildcardLoc, ", *"); |
| 3103 | return true; |
| 3104 | } |
| 3105 | |
| 3106 | return !Valid; |
| 3107 | } |
| 3108 | |
| 3109 | |
| 3110 | |
| 3111 | |
| 3112 | |
| 3113 | |
| 3114 | Optional<AvailabilitySpec> Parser::ParseAvailabilitySpec() { |
| 3115 | if (Tok.is(tok::star)) { |
| 3116 | return AvailabilitySpec(ConsumeToken()); |
| 3117 | } else { |
| 3118 | |
| 3119 | if (Tok.is(tok::code_completion)) { |
| 3120 | Actions.CodeCompleteAvailabilityPlatformName(); |
| 3121 | cutOffParsing(); |
| 3122 | return None; |
| 3123 | } |
| 3124 | if (Tok.isNot(tok::identifier)) { |
| 3125 | Diag(Tok, diag::err_avail_query_expected_platform_name); |
| 3126 | return None; |
| 3127 | } |
| 3128 | |
| 3129 | IdentifierLoc *PlatformIdentifier = ParseIdentifierLoc(); |
| 3130 | SourceRange VersionRange; |
| 3131 | VersionTuple Version = ParseVersionTuple(VersionRange); |
| 3132 | |
| 3133 | if (Version.empty()) |
| 3134 | return None; |
| 3135 | |
| 3136 | StringRef GivenPlatform = PlatformIdentifier->Ident->getName(); |
| 3137 | StringRef Platform = |
| 3138 | AvailabilityAttr::canonicalizePlatformName(GivenPlatform); |
| 3139 | |
| 3140 | if (AvailabilityAttr::getPrettyPlatformName(Platform).empty()) { |
| 3141 | Diag(PlatformIdentifier->Loc, |
| 3142 | diag::err_avail_query_unrecognized_platform_name) |
| 3143 | << GivenPlatform; |
| 3144 | return None; |
| 3145 | } |
| 3146 | |
| 3147 | return AvailabilitySpec(Version, Platform, PlatformIdentifier->Loc, |
| 3148 | VersionRange.getEnd()); |
| 3149 | } |
| 3150 | } |
| 3151 | |
| 3152 | ExprResult Parser::ParseAvailabilityCheckExpr(SourceLocation BeginLoc) { |
| 3153 | assert(Tok.is(tok::kw___builtin_available) || |
| 3154 | Tok.isObjCAtKeyword(tok::objc_available)); |
| 3155 | |
| 3156 | |
| 3157 | ConsumeToken(); |
| 3158 | |
| 3159 | BalancedDelimiterTracker Parens(*this, tok::l_paren); |
| 3160 | if (Parens.expectAndConsume()) |
| 3161 | return ExprError(); |
| 3162 | |
| 3163 | SmallVector<AvailabilitySpec, 4> AvailSpecs; |
| 3164 | bool HasError = false; |
| 3165 | while (true) { |
| 3166 | Optional<AvailabilitySpec> Spec = ParseAvailabilitySpec(); |
| 3167 | if (!Spec) |
| 3168 | HasError = true; |
| 3169 | else |
| 3170 | AvailSpecs.push_back(*Spec); |
| 3171 | |
| 3172 | if (!TryConsumeToken(tok::comma)) |
| 3173 | break; |
| 3174 | } |
| 3175 | |
| 3176 | if (HasError) { |
| 3177 | SkipUntil(tok::r_paren, StopAtSemi); |
| 3178 | return ExprError(); |
| 3179 | } |
| 3180 | |
| 3181 | CheckAvailabilitySpecList(*this, AvailSpecs); |
| 3182 | |
| 3183 | if (Parens.consumeClose()) |
| 3184 | return ExprError(); |
| 3185 | |
| 3186 | return Actions.ActOnObjCAvailabilityCheckExpr(AvailSpecs, BeginLoc, |
| 3187 | Parens.getCloseLocation()); |
| 3188 | } |
| 3189 | |