comparison clang/lib/Parse/ParseExpr.cpp @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children f935e5e0dbe7 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
623 SuggestParentheses(OpToken.getLocation(), 623 SuggestParentheses(OpToken.getLocation(),
624 diag::warn_cxx11_right_shift_in_template_arg, 624 diag::warn_cxx11_right_shift_in_template_arg,
625 SourceRange(Actions.getExprRange(LHS.get()).getBegin(), 625 SourceRange(Actions.getExprRange(LHS.get()).getBegin(),
626 Actions.getExprRange(RHS.get()).getEnd())); 626 Actions.getExprRange(RHS.get()).getEnd()));
627 627
628 LHS = Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(), 628 ExprResult BinOp =
629 OpToken.getKind(), LHS.get(), RHS.get()); 629 Actions.ActOnBinOp(getCurScope(), OpToken.getLocation(),
630 630 OpToken.getKind(), LHS.get(), RHS.get());
631 if (BinOp.isInvalid())
632 BinOp = Actions.CreateRecoveryExpr(LHS.get()->getBeginLoc(),
633 RHS.get()->getEndLoc(),
634 {LHS.get(), RHS.get()});
635
636 LHS = BinOp;
631 } else { 637 } else {
632 LHS = Actions.ActOnConditionalOp(OpToken.getLocation(), ColonLoc, 638 ExprResult CondOp = Actions.ActOnConditionalOp(
633 LHS.get(), TernaryMiddle.get(), 639 OpToken.getLocation(), ColonLoc, LHS.get(), TernaryMiddle.get(),
634 RHS.get()); 640 RHS.get());
641 if (CondOp.isInvalid()) {
642 std::vector<clang::Expr *> Args;
643 // TernaryMiddle can be null for the GNU conditional expr extension.
644 if (TernaryMiddle.get())
645 Args = {LHS.get(), TernaryMiddle.get(), RHS.get()};
646 else
647 Args = {LHS.get(), RHS.get()};
648 CondOp = Actions.CreateRecoveryExpr(LHS.get()->getBeginLoc(),
649 RHS.get()->getEndLoc(), Args);
650 }
651
652 LHS = CondOp;
635 } 653 }
636 // In this case, ActOnBinOp or ActOnConditionalOp performed the 654 // In this case, ActOnBinOp or ActOnConditionalOp performed the
637 // CorrectDelayedTyposInExpr check. 655 // CorrectDelayedTyposInExpr check.
638 if (!getLangOpts().CPlusPlus) 656 if (!getLangOpts().CPlusPlus)
639 continue; 657 continue;
1004 if (TryAnnotateTypeOrScopeToken()) 1022 if (TryAnnotateTypeOrScopeToken())
1005 return ExprError(); 1023 return ExprError();
1006 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super)); 1024 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super));
1007 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast, 1025 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
1008 isVectorLiteral, NotPrimaryExpression); 1026 isVectorLiteral, NotPrimaryExpression);
1009 1027
1010 case tok::identifier: { // primary-expression: identifier 1028 case tok::identifier: { // primary-expression: identifier
1011 // unqualified-id: identifier 1029 // unqualified-id: identifier
1012 // constant: enumeration-constant 1030 // constant: enumeration-constant
1013 // Turn a potentially qualified name into a annot_typename or 1031 // Turn a potentially qualified name into a annot_typename or
1014 // annot_cxxscope if it would be valid. This handles things like x::y, etc. 1032 // annot_cxxscope if it would be valid. This handles things like x::y, etc.
1303 // so put the token back where we found it. 1321 // so put the token back where we found it.
1304 assert(Res.isInvalid()); 1322 assert(Res.isInvalid());
1305 UnconsumeToken(SavedTok); 1323 UnconsumeToken(SavedTok);
1306 return ExprError(); 1324 return ExprError();
1307 } 1325 }
1308 if (!Res.isInvalid()) 1326 if (!Res.isInvalid()) {
1327 Expr *Arg = Res.get();
1309 Res = Actions.ActOnUnaryOp(getCurScope(), SavedTok.getLocation(), 1328 Res = Actions.ActOnUnaryOp(getCurScope(), SavedTok.getLocation(),
1310 SavedKind, Res.get()); 1329 SavedKind, Arg);
1330 if (Res.isInvalid())
1331 Res = Actions.CreateRecoveryExpr(SavedTok.getLocation(),
1332 Arg->getEndLoc(), Arg);
1333 }
1311 return Res; 1334 return Res;
1312 } 1335 }
1313 case tok::amp: { // unary-expression: '&' cast-expression 1336 case tok::amp: { // unary-expression: '&' cast-expression
1314 if (NotPrimaryExpression) 1337 if (NotPrimaryExpression)
1315 *NotPrimaryExpression = true; 1338 *NotPrimaryExpression = true;
1316 // Special treatment because of member pointers 1339 // Special treatment because of member pointers
1317 SourceLocation SavedLoc = ConsumeToken(); 1340 SourceLocation SavedLoc = ConsumeToken();
1318 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc); 1341 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc);
1319 Res = ParseCastExpression(AnyCastExpr, true); 1342 Res = ParseCastExpression(AnyCastExpr, true);
1320 if (!Res.isInvalid()) 1343 if (!Res.isInvalid()) {
1321 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); 1344 Expr *Arg = Res.get();
1345 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg);
1346 if (Res.isInvalid())
1347 Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(),
1348 Arg);
1349 }
1322 return Res; 1350 return Res;
1323 } 1351 }
1324 1352
1325 case tok::star: // unary-expression: '*' cast-expression 1353 case tok::star: // unary-expression: '*' cast-expression
1326 case tok::plus: // unary-expression: '+' cast-expression 1354 case tok::plus: // unary-expression: '+' cast-expression
1332 if (NotPrimaryExpression) 1360 if (NotPrimaryExpression)
1333 *NotPrimaryExpression = true; 1361 *NotPrimaryExpression = true;
1334 SourceLocation SavedLoc = ConsumeToken(); 1362 SourceLocation SavedLoc = ConsumeToken();
1335 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc); 1363 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc);
1336 Res = ParseCastExpression(AnyCastExpr); 1364 Res = ParseCastExpression(AnyCastExpr);
1337 if (!Res.isInvalid()) 1365 if (!Res.isInvalid()) {
1338 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Res.get()); 1366 Expr *Arg = Res.get();
1367 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg);
1368 if (Res.isInvalid())
1369 Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg);
1370 }
1339 return Res; 1371 return Res;
1340 } 1372 }
1341 1373
1342 case tok::kw_co_await: { // unary-expression: 'co_await' cast-expression 1374 case tok::kw_co_await: { // unary-expression: 'co_await' cast-expression
1343 if (NotPrimaryExpression) 1375 if (NotPrimaryExpression)
1394 } 1426 }
1395 case tok::kw_const_cast: 1427 case tok::kw_const_cast:
1396 case tok::kw_dynamic_cast: 1428 case tok::kw_dynamic_cast:
1397 case tok::kw_reinterpret_cast: 1429 case tok::kw_reinterpret_cast:
1398 case tok::kw_static_cast: 1430 case tok::kw_static_cast:
1431 case tok::kw_addrspace_cast:
1399 if (NotPrimaryExpression) 1432 if (NotPrimaryExpression)
1400 *NotPrimaryExpression = true; 1433 *NotPrimaryExpression = true;
1401 Res = ParseCXXCasts(); 1434 Res = ParseCXXCasts();
1402 break; 1435 break;
1403 case tok::kw___builtin_bit_cast: 1436 case tok::kw___builtin_bit_cast:
1416 Res = ParseCXXUuidof(); 1449 Res = ParseCXXUuidof();
1417 break; 1450 break;
1418 case tok::kw_this: 1451 case tok::kw_this:
1419 Res = ParseCXXThis(); 1452 Res = ParseCXXThis();
1420 break; 1453 break;
1421 1454 case tok::kw___builtin_unique_stable_name:
1455 Res = ParseUniqueStableNameExpression();
1456 break;
1422 case tok::annot_typename: 1457 case tok::annot_typename:
1423 if (isStartOfObjCClassMessageMissingOpenBracket()) { 1458 if (isStartOfObjCClassMessageMissingOpenBracket()) {
1424 ParsedType Type = getTypeAnnotation(Tok); 1459 TypeResult Type = getTypeAnnotation(Tok);
1425 1460
1426 // Fake up a Declarator to use with ActOnTypeName. 1461 // Fake up a Declarator to use with ActOnTypeName.
1427 DeclSpec DS(AttrFactory); 1462 DeclSpec DS(AttrFactory);
1428 DS.SetRangeStart(Tok.getLocation()); 1463 DS.SetRangeStart(Tok.getLocation());
1429 DS.SetRangeEnd(Tok.getLastLoc()); 1464 DS.SetRangeEnd(Tok.getLastLoc());
1456 case tok::kw_short: 1491 case tok::kw_short:
1457 case tok::kw_int: 1492 case tok::kw_int:
1458 case tok::kw_long: 1493 case tok::kw_long:
1459 case tok::kw___int64: 1494 case tok::kw___int64:
1460 case tok::kw___int128: 1495 case tok::kw___int128:
1496 case tok::kw__ExtInt:
1461 case tok::kw_signed: 1497 case tok::kw_signed:
1462 case tok::kw_unsigned: 1498 case tok::kw_unsigned:
1463 case tok::kw_half: 1499 case tok::kw_half:
1464 case tok::kw_float: 1500 case tok::kw_float:
1465 case tok::kw_double: 1501 case tok::kw_double:
1527 if (TemplateId->Kind == TNK_Type_template) { 1563 if (TemplateId->Kind == TNK_Type_template) {
1528 // We have a qualified template-id that we know refers to a 1564 // We have a qualified template-id that we know refers to a
1529 // type, translate it into a type and continue parsing as a 1565 // type, translate it into a type and continue parsing as a
1530 // cast expression. 1566 // cast expression.
1531 CXXScopeSpec SS; 1567 CXXScopeSpec SS;
1532 ParseOptionalCXXScopeSpecifier(SS, nullptr, 1568 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
1569 /*ObjectHadErrors=*/false,
1533 /*EnteringContext=*/false); 1570 /*EnteringContext=*/false);
1534 AnnotateTemplateIdTokenAsType(SS); 1571 AnnotateTemplateIdTokenAsType(SS);
1535 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr, 1572 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr,
1536 isTypeCast, isVectorLiteral, 1573 isTypeCast, isVectorLiteral,
1537 NotPrimaryExpression); 1574 NotPrimaryExpression);
1938 SkipUntil(tok::r_paren, StopAtSemi); 1975 SkipUntil(tok::r_paren, StopAtSemi);
1939 else 1976 else
1940 PT.consumeClose(); 1977 PT.consumeClose();
1941 LHS = ExprError(); 1978 LHS = ExprError();
1942 } else { 1979 } else {
1943 assert((ArgExprs.size() == 0 || 1980 assert(
1944 ArgExprs.size()-1 == CommaLocs.size())&& 1981 (ArgExprs.size() == 0 || ArgExprs.size() - 1 == CommaLocs.size()) &&
1945 "Unexpected number of commas!"); 1982 "Unexpected number of commas!");
1946 LHS = Actions.ActOnCallExpr(getCurScope(), LHS.get(), Loc, 1983 Expr *Fn = LHS.get();
1947 ArgExprs, Tok.getLocation(), 1984 SourceLocation RParLoc = Tok.getLocation();
1985 LHS = Actions.ActOnCallExpr(getCurScope(), Fn, Loc, ArgExprs, RParLoc,
1948 ExecConfig); 1986 ExecConfig);
1987 if (LHS.isInvalid()) {
1988 ArgExprs.insert(ArgExprs.begin(), Fn);
1989 LHS =
1990 Actions.CreateRecoveryExpr(Fn->getBeginLoc(), RParLoc, ArgExprs);
1991 }
1949 PT.consumeClose(); 1992 PT.consumeClose();
1950 } 1993 }
1951 1994
1952 break; 1995 break;
1953 } 1996 }
1975 << OpKind << Base->getSourceRange() 2018 << OpKind << Base->getSourceRange()
1976 << FixItHint::CreateRemoval(OpLoc); 2019 << FixItHint::CreateRemoval(OpLoc);
1977 return ParsePostfixExpressionSuffix(Base); 2020 return ParsePostfixExpressionSuffix(Base);
1978 } 2021 }
1979 2022
1980 LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base, 2023 LHS = Actions.ActOnStartCXXMemberReference(getCurScope(), Base, OpLoc,
1981 OpLoc, OpKind, ObjectType, 2024 OpKind, ObjectType,
1982 MayBePseudoDestructor); 2025 MayBePseudoDestructor);
1983 if (LHS.isInvalid()) 2026 if (LHS.isInvalid()) {
2027 // Clang will try to perform expression based completion as a
2028 // fallback, which is confusing in case of member references. So we
2029 // stop here without any completions.
2030 if (Tok.is(tok::code_completion)) {
2031 cutOffParsing();
2032 return ExprError();
2033 }
1984 break; 2034 break;
1985 2035 }
1986 ParseOptionalCXXScopeSpecifier(SS, ObjectType, 2036 ParseOptionalCXXScopeSpecifier(
1987 /*EnteringContext=*/false, 2037 SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
1988 &MayBePseudoDestructor); 2038 /*EnteringContext=*/false, &MayBePseudoDestructor);
1989 if (SS.isNotEmpty()) 2039 if (SS.isNotEmpty())
1990 ObjectType = nullptr; 2040 ObjectType = nullptr;
1991 } 2041 }
1992 2042
1993 if (Tok.is(tok::code_completion)) { 2043 if (Tok.is(tok::code_completion)) {
2043 // such a common method name. For other C++ keywords that are 2093 // such a common method name. For other C++ keywords that are
2044 // Objective-C method names, one must use the message send syntax. 2094 // Objective-C method names, one must use the message send syntax.
2045 IdentifierInfo *Id = Tok.getIdentifierInfo(); 2095 IdentifierInfo *Id = Tok.getIdentifierInfo();
2046 SourceLocation Loc = ConsumeToken(); 2096 SourceLocation Loc = ConsumeToken();
2047 Name.setIdentifier(Id, Loc); 2097 Name.setIdentifier(Id, Loc);
2048 } else if (ParseUnqualifiedId(SS, 2098 } else if (ParseUnqualifiedId(
2049 /*EnteringContext=*/false, 2099 SS, ObjectType, LHS.get() && LHS.get()->containsErrors(),
2050 /*AllowDestructorName=*/true, 2100 /*EnteringContext=*/false,
2051 /*AllowConstructorName=*/ 2101 /*AllowDestructorName=*/true,
2052 getLangOpts().MicrosoftExt && 2102 /*AllowConstructorName=*/
2053 SS.isNotEmpty(), 2103 getLangOpts().MicrosoftExt && SS.isNotEmpty(),
2054 /*AllowDeductionGuide=*/false, 2104 /*AllowDeductionGuide=*/false, &TemplateKWLoc, Name)) {
2055 ObjectType, &TemplateKWLoc, Name)) {
2056 (void)Actions.CorrectDelayedTyposInExpr(LHS); 2105 (void)Actions.CorrectDelayedTyposInExpr(LHS);
2057 LHS = ExprError(); 2106 LHS = ExprError();
2058 } 2107 }
2059 2108
2060 if (!LHS.isInvalid()) 2109 if (!LHS.isInvalid())
2061 LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.get(), OpLoc, 2110 LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.get(), OpLoc,
2062 OpKind, SS, TemplateKWLoc, Name, 2111 OpKind, SS, TemplateKWLoc, Name,
2063 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl 2112 CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
2064 : nullptr); 2113 : nullptr);
2065 if (!LHS.isInvalid() && Tok.is(tok::less)) 2114 if (!LHS.isInvalid()) {
2066 checkPotentialAngleBracket(LHS); 2115 if (Tok.is(tok::less))
2116 checkPotentialAngleBracket(LHS);
2117 } else if (OrigLHS && Name.isValid()) {
2118 // Preserve the LHS if the RHS is an invalid member.
2119 LHS = Actions.CreateRecoveryExpr(OrigLHS->getBeginLoc(),
2120 Name.getEndLoc(), {OrigLHS});
2121 }
2067 break; 2122 break;
2068 } 2123 }
2069 case tok::plusplus: // postfix-expression: postfix-expression '++' 2124 case tok::plusplus: // postfix-expression: postfix-expression '++'
2070 case tok::minusminus: // postfix-expression: postfix-expression '--' 2125 case tok::minusminus: // postfix-expression: postfix-expression '--'
2071 if (!LHS.isInvalid()) { 2126 if (!LHS.isInvalid()) {
2127 Expr *Arg = LHS.get();
2072 LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(), 2128 LHS = Actions.ActOnPostfixUnaryOp(getCurScope(), Tok.getLocation(),
2073 Tok.getKind(), LHS.get()); 2129 Tok.getKind(), Arg);
2130 if (LHS.isInvalid())
2131 LHS = Actions.CreateRecoveryExpr(Arg->getBeginLoc(),
2132 Tok.getLocation(), Arg);
2074 } 2133 }
2075 ConsumeToken(); 2134 ConsumeToken();
2076 break; 2135 break;
2077 } 2136 }
2078 } 2137 }
2177 // If we get here, the operand to the typeof/sizeof/alignof was an expression. 2236 // If we get here, the operand to the typeof/sizeof/alignof was an expression.
2178 isCastExpr = false; 2237 isCastExpr = false;
2179 return Operand; 2238 return Operand;
2180 } 2239 }
2181 2240
2241
2242 ExprResult Parser::ParseUniqueStableNameExpression() {
2243 assert(Tok.is(tok::kw___builtin_unique_stable_name) &&
2244 "Not __bulitin_unique_stable_name");
2245
2246 SourceLocation OpLoc = ConsumeToken();
2247 BalancedDelimiterTracker T(*this, tok::l_paren);
2248
2249 // typeid expressions are always parenthesized.
2250 if (T.expectAndConsume(diag::err_expected_lparen_after,
2251 "__builtin_unique_stable_name"))
2252 return ExprError();
2253
2254 if (isTypeIdInParens()) {
2255 TypeResult Ty = ParseTypeName();
2256 T.consumeClose();
2257
2258 if (Ty.isInvalid())
2259 return ExprError();
2260
2261 return Actions.ActOnUniqueStableNameExpr(OpLoc, T.getOpenLocation(),
2262 T.getCloseLocation(), Ty.get());
2263 }
2264
2265 EnterExpressionEvaluationContext Unevaluated(
2266 Actions, Sema::ExpressionEvaluationContext::Unevaluated);
2267 ExprResult Result = ParseExpression();
2268
2269 if (Result.isInvalid()) {
2270 SkipUntil(tok::r_paren, StopAtSemi);
2271 return Result;
2272 }
2273
2274 T.consumeClose();
2275 return Actions.ActOnUniqueStableNameExpr(OpLoc, T.getOpenLocation(),
2276 T.getCloseLocation(), Result.get());
2277 }
2182 2278
2183 /// Parse a sizeof or alignof expression. 2279 /// Parse a sizeof or alignof expression.
2184 /// 2280 ///
2185 /// \verbatim 2281 /// \verbatim
2186 /// unary-expression: [C99 6.5.3] 2282 /// unary-expression: [C99 6.5.3]
2559 // These can be followed by postfix-expr pieces because they are 2655 // These can be followed by postfix-expr pieces because they are
2560 // primary-expressions. 2656 // primary-expressions.
2561 return ParsePostfixExpressionSuffix(Res.get()); 2657 return ParsePostfixExpressionSuffix(Res.get());
2562 } 2658 }
2563 2659
2660 bool Parser::tryParseOpenMPArrayShapingCastPart() {
2661 assert(Tok.is(tok::l_square) && "Expected open bracket");
2662 bool ErrorFound = true;
2663 TentativeParsingAction TPA(*this);
2664 do {
2665 if (Tok.isNot(tok::l_square))
2666 break;
2667 // Consume '['
2668 ConsumeBracket();
2669 // Skip inner expression.
2670 while (!SkipUntil(tok::r_square, tok::annot_pragma_openmp_end,
2671 StopAtSemi | StopBeforeMatch))
2672 ;
2673 if (Tok.isNot(tok::r_square))
2674 break;
2675 // Consume ']'
2676 ConsumeBracket();
2677 // Found ')' - done.
2678 if (Tok.is(tok::r_paren)) {
2679 ErrorFound = false;
2680 break;
2681 }
2682 } while (Tok.isNot(tok::annot_pragma_openmp_end));
2683 TPA.Revert();
2684 return !ErrorFound;
2685 }
2686
2564 /// ParseParenExpression - This parses the unit that starts with a '(' token, 2687 /// ParseParenExpression - This parses the unit that starts with a '(' token,
2565 /// based on what is allowed by ExprType. The actual thing parsed is returned 2688 /// based on what is allowed by ExprType. The actual thing parsed is returned
2566 /// in ExprType. If stopIfCastExpr is true, it will only return the parsed type, 2689 /// in ExprType. If stopIfCastExpr is true, it will only return the parsed type,
2567 /// not the parsed cast-expression. 2690 /// not the parsed cast-expression.
2568 /// 2691 ///
2583 /// fold-expression: [C++1z] 2706 /// fold-expression: [C++1z]
2584 /// '(' cast-expression fold-operator '...' ')' 2707 /// '(' cast-expression fold-operator '...' ')'
2585 /// '(' '...' fold-operator cast-expression ')' 2708 /// '(' '...' fold-operator cast-expression ')'
2586 /// '(' cast-expression fold-operator '...' 2709 /// '(' cast-expression fold-operator '...'
2587 /// fold-operator cast-expression ')' 2710 /// fold-operator cast-expression ')'
2711 /// [OPENMP] Array shaping operation
2712 /// '(' '[' expression ']' { '[' expression ']' } cast-expression
2588 /// \endverbatim 2713 /// \endverbatim
2589 ExprResult 2714 ExprResult
2590 Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, 2715 Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
2591 bool isTypeCast, ParsedType &CastTy, 2716 bool isTypeCast, ParsedType &CastTy,
2592 SourceLocation &RParenLoc) { 2717 SourceLocation &RParenLoc) {
2653 StmtResult Stmt(ParseCompoundStatement(true)); 2778 StmtResult Stmt(ParseCompoundStatement(true));
2654 ExprType = CompoundStmt; 2779 ExprType = CompoundStmt;
2655 2780
2656 // If the substmt parsed correctly, build the AST node. 2781 // If the substmt parsed correctly, build the AST node.
2657 if (!Stmt.isInvalid()) { 2782 if (!Stmt.isInvalid()) {
2658 Result = Actions.ActOnStmtExpr(OpenLoc, Stmt.get(), Tok.getLocation()); 2783 Result = Actions.ActOnStmtExpr(getCurScope(), OpenLoc, Stmt.get(),
2784 Tok.getLocation());
2659 } else { 2785 } else {
2660 Actions.ActOnStmtExprError(); 2786 Actions.ActOnStmtExprError();
2661 } 2787 }
2662 } 2788 }
2663 } else if (ExprType >= CompoundLiteral && BridgeCast) { 2789 } else if (ExprType >= CompoundLiteral && BridgeCast) {
2688 ColonProtection.restore(); 2814 ColonProtection.restore();
2689 RParenLoc = T.getCloseLocation(); 2815 RParenLoc = T.getCloseLocation();
2690 2816
2691 PreferredType.enterTypeCast(Tok.getLocation(), Ty.get().get()); 2817 PreferredType.enterTypeCast(Tok.getLocation(), Ty.get().get());
2692 ExprResult SubExpr = ParseCastExpression(AnyCastExpr); 2818 ExprResult SubExpr = ParseCastExpression(AnyCastExpr);
2693 2819
2694 if (Ty.isInvalid() || SubExpr.isInvalid()) 2820 if (Ty.isInvalid() || SubExpr.isInvalid())
2695 return ExprError(); 2821 return ExprError();
2696 2822
2697 return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind, 2823 return Actions.ActOnObjCBridgedCast(getCurScope(), OpenLoc, Kind,
2698 BridgeKeywordLoc, Ty.get(), 2824 BridgeKeywordLoc, Ty.get(),
2858 2984
2859 ExprType = SimpleExpr; 2985 ExprType = SimpleExpr;
2860 Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(), 2986 Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
2861 ArgExprs); 2987 ArgExprs);
2862 } 2988 }
2989 } else if (getLangOpts().OpenMP >= 50 && OpenMPDirectiveParsing &&
2990 ExprType == CastExpr && Tok.is(tok::l_square) &&
2991 tryParseOpenMPArrayShapingCastPart()) {
2992 bool ErrorFound = false;
2993 SmallVector<Expr *, 4> OMPDimensions;
2994 SmallVector<SourceRange, 4> OMPBracketsRanges;
2995 do {
2996 BalancedDelimiterTracker TS(*this, tok::l_square);
2997 TS.consumeOpen();
2998 ExprResult NumElements =
2999 Actions.CorrectDelayedTyposInExpr(ParseExpression());
3000 if (!NumElements.isUsable()) {
3001 ErrorFound = true;
3002 while (!SkipUntil(tok::r_square, tok::r_paren,
3003 StopAtSemi | StopBeforeMatch))
3004 ;
3005 }
3006 TS.consumeClose();
3007 OMPDimensions.push_back(NumElements.get());
3008 OMPBracketsRanges.push_back(TS.getRange());
3009 } while (Tok.isNot(tok::r_paren));
3010 // Match the ')'.
3011 T.consumeClose();
3012 RParenLoc = T.getCloseLocation();
3013 Result = Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression());
3014 if (ErrorFound) {
3015 Result = ExprError();
3016 } else if (!Result.isInvalid()) {
3017 Result = Actions.ActOnOMPArrayShapingExpr(
3018 Result.get(), OpenLoc, RParenLoc, OMPDimensions, OMPBracketsRanges);
3019 }
3020 return Result;
2863 } else { 3021 } else {
2864 InMessageExpressionRAIIObject InMessage(*this, false); 3022 InMessageExpressionRAIIObject InMessage(*this, false);
2865 3023
2866 Result = ParseExpression(MaybeTypeCast); 3024 Result = ParseExpression(MaybeTypeCast);
2867 if (!getLangOpts().CPlusPlus && MaybeTypeCast && Result.isUsable()) { 3025 if (!getLangOpts().CPlusPlus && MaybeTypeCast && Result.isUsable()) {