Mercurial > hg > CbC > CbC_llvm
comparison clang/lib/Parse/ParseExpr.cpp @ 239:173fe712db74
merge LLVM16
author | kono |
---|---|
date | Wed, 09 Nov 2022 18:03:41 +0900 |
parents | 5f20bc1ed4ff c4bab56944e8 |
children | ca573705d418 |
comparison
equal
deleted
inserted
replaced
238:8222e65f95b1 | 239:173fe712db74 |
---|---|
398 GreaterThanIsOperator, | 398 GreaterThanIsOperator, |
399 getLangOpts().CPlusPlus11); | 399 getLangOpts().CPlusPlus11); |
400 SourceLocation ColonLoc; | 400 SourceLocation ColonLoc; |
401 | 401 |
402 auto SavedType = PreferredType; | 402 auto SavedType = PreferredType; |
403 while (1) { | 403 while (true) { |
404 // Every iteration may rely on a preferred type for the whole expression. | 404 // Every iteration may rely on a preferred type for the whole expression. |
405 PreferredType = SavedType; | 405 PreferredType = SavedType; |
406 // If this token has a lower precedence than we are allowed to parse (e.g. | 406 // If this token has a lower precedence than we are allowed to parse (e.g. |
407 // because we are called recursively, or because the token is not a binop), | 407 // because we are called recursively, or because the token is not a binop), |
408 // then we are done! | 408 // then we are done! |
789 /// assign-expr ')' | 789 /// assign-expr ')' |
790 /// [GNU] '__builtin_FILE' '(' ')' | 790 /// [GNU] '__builtin_FILE' '(' ')' |
791 /// [GNU] '__builtin_FUNCTION' '(' ')' | 791 /// [GNU] '__builtin_FUNCTION' '(' ')' |
792 /// [GNU] '__builtin_LINE' '(' ')' | 792 /// [GNU] '__builtin_LINE' '(' ')' |
793 /// [CLANG] '__builtin_COLUMN' '(' ')' | 793 /// [CLANG] '__builtin_COLUMN' '(' ')' |
794 /// [GNU] '__builtin_source_location' '(' ')' | |
794 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' | 795 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' |
795 /// [GNU] '__null' | 796 /// [GNU] '__null' |
796 /// [OBJC] '[' objc-message-expr ']' | 797 /// [OBJC] '[' objc-message-expr ']' |
797 /// [OBJC] '\@selector' '(' objc-selector-arg ')' | 798 /// [OBJC] '\@selector' '(' objc-selector-arg ')' |
798 /// [OBJC] '\@protocol' '(' identifier ')' | 799 /// [OBJC] '\@protocol' '(' identifier ')' |
940 // If this expression is limited to being a unary-expression, the paren can | 941 // If this expression is limited to being a unary-expression, the paren can |
941 // not start a cast expression. | 942 // not start a cast expression. |
942 ParenParseOption ParenExprType; | 943 ParenParseOption ParenExprType; |
943 switch (ParseKind) { | 944 switch (ParseKind) { |
944 case CastParseKind::UnaryExprOnly: | 945 case CastParseKind::UnaryExprOnly: |
945 if (!getLangOpts().CPlusPlus) | 946 assert(getLangOpts().CPlusPlus && "not possible to get here in C"); |
946 ParenExprType = CompoundLiteral; | 947 [[fallthrough]]; |
947 LLVM_FALLTHROUGH; | |
948 case CastParseKind::AnyCastExpr: | 948 case CastParseKind::AnyCastExpr: |
949 ParenExprType = ParenParseOption::CastExpr; | 949 ParenExprType = ParenParseOption::CastExpr; |
950 break; | 950 break; |
951 case CastParseKind::PrimaryExprOnly: | 951 case CastParseKind::PrimaryExprOnly: |
952 ParenExprType = FoldExpr; | 952 ParenExprType = FoldExpr; |
1001 case tok::kw___objc_no: | 1001 case tok::kw___objc_no: |
1002 Res = ParseObjCBoolLiteral(); | 1002 Res = ParseObjCBoolLiteral(); |
1003 break; | 1003 break; |
1004 | 1004 |
1005 case tok::kw_nullptr: | 1005 case tok::kw_nullptr: |
1006 Diag(Tok, diag::warn_cxx98_compat_nullptr); | 1006 if (getLangOpts().CPlusPlus) |
1007 Diag(Tok, diag::warn_cxx98_compat_nullptr); | |
1008 else | |
1009 Diag(Tok, getLangOpts().C2x ? diag::warn_c17_compat_nullptr | |
1010 : diag::ext_c_nullptr); | |
1011 | |
1007 Res = Actions.ActOnCXXNullPtrLiteral(ConsumeToken()); | 1012 Res = Actions.ActOnCXXNullPtrLiteral(ConsumeToken()); |
1008 break; | 1013 break; |
1009 | 1014 |
1010 case tok::annot_primary_expr: | 1015 case tok::annot_primary_expr: |
1011 case tok::annot_overload_set: | 1016 case tok::annot_overload_set: |
1035 return ExprError(); | 1040 return ExprError(); |
1036 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super)); | 1041 assert(Tok.isNot(tok::kw_decltype) && Tok.isNot(tok::kw___super)); |
1037 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast, | 1042 return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast, |
1038 isVectorLiteral, NotPrimaryExpression); | 1043 isVectorLiteral, NotPrimaryExpression); |
1039 | 1044 |
1040 case tok::identifier: { // primary-expression: identifier | 1045 case tok::identifier: |
1041 // unqualified-id: identifier | 1046 ParseIdentifier: { // primary-expression: identifier |
1042 // constant: enumeration-constant | 1047 // unqualified-id: identifier |
1048 // constant: enumeration-constant | |
1043 // Turn a potentially qualified name into a annot_typename or | 1049 // Turn a potentially qualified name into a annot_typename or |
1044 // annot_cxxscope if it would be valid. This handles things like x::y, etc. | 1050 // annot_cxxscope if it would be valid. This handles things like x::y, etc. |
1045 if (getLangOpts().CPlusPlus) { | 1051 if (getLangOpts().CPlusPlus) { |
1046 // Avoid the unnecessary parse-time lookup in the common case | 1052 // Avoid the unnecessary parse-time lookup in the common case |
1047 // where the syntax forbids a type. | 1053 // where the syntax forbids a type. |
1065 REVERTIBLE_TYPE_TRAIT(__is_aggregate); | 1071 REVERTIBLE_TYPE_TRAIT(__is_aggregate); |
1066 REVERTIBLE_TYPE_TRAIT(__is_arithmetic); | 1072 REVERTIBLE_TYPE_TRAIT(__is_arithmetic); |
1067 REVERTIBLE_TYPE_TRAIT(__is_array); | 1073 REVERTIBLE_TYPE_TRAIT(__is_array); |
1068 REVERTIBLE_TYPE_TRAIT(__is_assignable); | 1074 REVERTIBLE_TYPE_TRAIT(__is_assignable); |
1069 REVERTIBLE_TYPE_TRAIT(__is_base_of); | 1075 REVERTIBLE_TYPE_TRAIT(__is_base_of); |
1076 REVERTIBLE_TYPE_TRAIT(__is_bounded_array); | |
1070 REVERTIBLE_TYPE_TRAIT(__is_class); | 1077 REVERTIBLE_TYPE_TRAIT(__is_class); |
1071 REVERTIBLE_TYPE_TRAIT(__is_complete_type); | 1078 REVERTIBLE_TYPE_TRAIT(__is_complete_type); |
1072 REVERTIBLE_TYPE_TRAIT(__is_compound); | 1079 REVERTIBLE_TYPE_TRAIT(__is_compound); |
1073 REVERTIBLE_TYPE_TRAIT(__is_const); | 1080 REVERTIBLE_TYPE_TRAIT(__is_const); |
1074 REVERTIBLE_TYPE_TRAIT(__is_constructible); | 1081 REVERTIBLE_TYPE_TRAIT(__is_constructible); |
1090 REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer); | 1097 REVERTIBLE_TYPE_TRAIT(__is_member_object_pointer); |
1091 REVERTIBLE_TYPE_TRAIT(__is_member_pointer); | 1098 REVERTIBLE_TYPE_TRAIT(__is_member_pointer); |
1092 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable); | 1099 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable); |
1093 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible); | 1100 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible); |
1094 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible); | 1101 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible); |
1102 REVERTIBLE_TYPE_TRAIT(__is_nullptr); | |
1095 REVERTIBLE_TYPE_TRAIT(__is_object); | 1103 REVERTIBLE_TYPE_TRAIT(__is_object); |
1096 REVERTIBLE_TYPE_TRAIT(__is_pod); | 1104 REVERTIBLE_TYPE_TRAIT(__is_pod); |
1097 REVERTIBLE_TYPE_TRAIT(__is_pointer); | 1105 REVERTIBLE_TYPE_TRAIT(__is_pointer); |
1098 REVERTIBLE_TYPE_TRAIT(__is_polymorphic); | 1106 REVERTIBLE_TYPE_TRAIT(__is_polymorphic); |
1099 REVERTIBLE_TYPE_TRAIT(__is_reference); | 1107 REVERTIBLE_TYPE_TRAIT(__is_reference); |
1108 REVERTIBLE_TYPE_TRAIT(__is_referenceable); | |
1100 REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr); | 1109 REVERTIBLE_TYPE_TRAIT(__is_rvalue_expr); |
1101 REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference); | 1110 REVERTIBLE_TYPE_TRAIT(__is_rvalue_reference); |
1102 REVERTIBLE_TYPE_TRAIT(__is_same); | 1111 REVERTIBLE_TYPE_TRAIT(__is_same); |
1103 REVERTIBLE_TYPE_TRAIT(__is_scalar); | 1112 REVERTIBLE_TYPE_TRAIT(__is_scalar); |
1113 REVERTIBLE_TYPE_TRAIT(__is_scoped_enum); | |
1104 REVERTIBLE_TYPE_TRAIT(__is_sealed); | 1114 REVERTIBLE_TYPE_TRAIT(__is_sealed); |
1105 REVERTIBLE_TYPE_TRAIT(__is_signed); | 1115 REVERTIBLE_TYPE_TRAIT(__is_signed); |
1106 REVERTIBLE_TYPE_TRAIT(__is_standard_layout); | 1116 REVERTIBLE_TYPE_TRAIT(__is_standard_layout); |
1107 REVERTIBLE_TYPE_TRAIT(__is_trivial); | 1117 REVERTIBLE_TYPE_TRAIT(__is_trivial); |
1108 REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable); | 1118 REVERTIBLE_TYPE_TRAIT(__is_trivially_assignable); |
1109 REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible); | 1119 REVERTIBLE_TYPE_TRAIT(__is_trivially_constructible); |
1110 REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable); | 1120 REVERTIBLE_TYPE_TRAIT(__is_trivially_copyable); |
1121 REVERTIBLE_TYPE_TRAIT(__is_unbounded_array); | |
1111 REVERTIBLE_TYPE_TRAIT(__is_union); | 1122 REVERTIBLE_TYPE_TRAIT(__is_union); |
1112 REVERTIBLE_TYPE_TRAIT(__is_unsigned); | 1123 REVERTIBLE_TYPE_TRAIT(__is_unsigned); |
1113 REVERTIBLE_TYPE_TRAIT(__is_void); | 1124 REVERTIBLE_TYPE_TRAIT(__is_void); |
1114 REVERTIBLE_TYPE_TRAIT(__is_volatile); | 1125 REVERTIBLE_TYPE_TRAIT(__is_volatile); |
1126 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) \ | |
1127 REVERTIBLE_TYPE_TRAIT(RTT_JOIN(__, Trait)); | |
1128 #include "clang/Basic/TransformTypeTraits.def" | |
1115 #undef REVERTIBLE_TYPE_TRAIT | 1129 #undef REVERTIBLE_TYPE_TRAIT |
1116 #undef RTT_JOIN | 1130 #undef RTT_JOIN |
1117 } | 1131 } |
1118 | 1132 |
1119 // If we find that this is in fact the name of a type trait, | 1133 // If we find that this is in fact the name of a type trait, |
1140 NotCastExpr, isTypeCast, | 1154 NotCastExpr, isTypeCast, |
1141 isVectorLiteral, | 1155 isVectorLiteral, |
1142 NotPrimaryExpression); | 1156 NotPrimaryExpression); |
1143 } | 1157 } |
1144 } | 1158 } |
1145 | |
1146 #ifndef noCbC | |
1147 if(NeedPrototypeDeclaration(Tok)){ | |
1148 CreatePrototypeDeclaration(); | |
1149 } | |
1150 #endif | |
1151 | 1159 |
1152 // Consume the identifier so that we can see if it is followed by a '(' or | 1160 // Consume the identifier so that we can see if it is followed by a '(' or |
1153 // '.'. | 1161 // '.'. |
1154 IdentifierInfo &II = *Tok.getIdentifierInfo(); | 1162 IdentifierInfo &II = *Tok.getIdentifierInfo(); |
1155 SourceLocation ILoc = ConsumeToken(); | 1163 SourceLocation ILoc = ConsumeToken(); |
1215 const char *PrevSpec = nullptr; | 1223 const char *PrevSpec = nullptr; |
1216 unsigned DiagID; | 1224 unsigned DiagID; |
1217 DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ, | 1225 DS.SetTypeSpecType(TST_typename, ILoc, PrevSpec, DiagID, Typ, |
1218 Actions.getASTContext().getPrintingPolicy()); | 1226 Actions.getASTContext().getPrintingPolicy()); |
1219 | 1227 |
1220 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); | 1228 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), |
1229 DeclaratorContext::TypeName); | |
1221 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), | 1230 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), |
1222 DeclaratorInfo); | 1231 DeclaratorInfo); |
1223 if (Ty.isInvalid()) | 1232 if (Ty.isInvalid()) |
1224 break; | 1233 break; |
1225 | 1234 |
1307 case tok::kw___builtin_convertvector: | 1316 case tok::kw___builtin_convertvector: |
1308 case tok::kw___builtin_COLUMN: | 1317 case tok::kw___builtin_COLUMN: |
1309 case tok::kw___builtin_FILE: | 1318 case tok::kw___builtin_FILE: |
1310 case tok::kw___builtin_FUNCTION: | 1319 case tok::kw___builtin_FUNCTION: |
1311 case tok::kw___builtin_LINE: | 1320 case tok::kw___builtin_LINE: |
1321 case tok::kw___builtin_source_location: | |
1312 if (NotPrimaryExpression) | 1322 if (NotPrimaryExpression) |
1313 *NotPrimaryExpression = true; | 1323 *NotPrimaryExpression = true; |
1314 // This parses the complete suffix; we can return early. | 1324 // This parses the complete suffix; we can return early. |
1315 return ParseBuiltinPrimaryExpression(); | 1325 return ParseBuiltinPrimaryExpression(); |
1316 case tok::kw___null: | 1326 case tok::kw___null: |
1358 if (NotPrimaryExpression) | 1368 if (NotPrimaryExpression) |
1359 *NotPrimaryExpression = true; | 1369 *NotPrimaryExpression = true; |
1360 // Special treatment because of member pointers | 1370 // Special treatment because of member pointers |
1361 SourceLocation SavedLoc = ConsumeToken(); | 1371 SourceLocation SavedLoc = ConsumeToken(); |
1362 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc); | 1372 PreferredType.enterUnary(Actions, Tok.getLocation(), tok::amp, SavedLoc); |
1363 Res = ParseCastExpression(AnyCastExpr, true); | 1373 |
1374 Res = ParseCastExpression(AnyCastExpr, /*isAddressOfOperand=*/true); | |
1364 if (!Res.isInvalid()) { | 1375 if (!Res.isInvalid()) { |
1365 Expr *Arg = Res.get(); | 1376 Expr *Arg = Res.get(); |
1366 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg); | 1377 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg); |
1367 if (Res.isInvalid()) | 1378 if (Res.isInvalid()) |
1368 Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(), | 1379 Res = Actions.CreateRecoveryExpr(Tok.getLocation(), Arg->getEndLoc(), |
1383 SourceLocation SavedLoc = ConsumeToken(); | 1394 SourceLocation SavedLoc = ConsumeToken(); |
1384 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc); | 1395 PreferredType.enterUnary(Actions, Tok.getLocation(), SavedKind, SavedLoc); |
1385 Res = ParseCastExpression(AnyCastExpr); | 1396 Res = ParseCastExpression(AnyCastExpr); |
1386 if (!Res.isInvalid()) { | 1397 if (!Res.isInvalid()) { |
1387 Expr *Arg = Res.get(); | 1398 Expr *Arg = Res.get(); |
1388 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg); | 1399 Res = Actions.ActOnUnaryOp(getCurScope(), SavedLoc, SavedKind, Arg, |
1400 isAddressOfOperand); | |
1389 if (Res.isInvalid()) | 1401 if (Res.isInvalid()) |
1390 Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg); | 1402 Res = Actions.CreateRecoveryExpr(SavedLoc, Arg->getEndLoc(), Arg); |
1391 } | 1403 } |
1392 return Res; | 1404 return Res; |
1393 } | 1405 } |
1414 return Res; | 1426 return Res; |
1415 } | 1427 } |
1416 case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')' | 1428 case tok::kw__Alignof: // unary-expression: '_Alignof' '(' type-name ')' |
1417 if (!getLangOpts().C11) | 1429 if (!getLangOpts().C11) |
1418 Diag(Tok, diag::ext_c11_feature) << Tok.getName(); | 1430 Diag(Tok, diag::ext_c11_feature) << Tok.getName(); |
1419 LLVM_FALLTHROUGH; | 1431 [[fallthrough]]; |
1420 case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')' | 1432 case tok::kw_alignof: // unary-expression: 'alignof' '(' type-id ')' |
1421 case tok::kw___alignof: // unary-expression: '__alignof' unary-expression | 1433 case tok::kw___alignof: // unary-expression: '__alignof' unary-expression |
1422 // unary-expression: '__alignof' '(' type-name ')' | 1434 // unary-expression: '__alignof' '(' type-name ')' |
1423 case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression | 1435 case tok::kw_sizeof: // unary-expression: 'sizeof' unary-expression |
1424 // unary-expression: 'sizeof' '(' type-name ')' | 1436 // unary-expression: 'sizeof' '(' type-name ')' |
1492 unsigned DiagID; | 1504 unsigned DiagID; |
1493 DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(), | 1505 DS.SetTypeSpecType(TST_typename, Tok.getAnnotationEndLoc(), |
1494 PrevSpec, DiagID, Type, | 1506 PrevSpec, DiagID, Type, |
1495 Actions.getASTContext().getPrintingPolicy()); | 1507 Actions.getASTContext().getPrintingPolicy()); |
1496 | 1508 |
1497 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); | 1509 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), |
1510 DeclaratorContext::TypeName); | |
1498 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); | 1511 TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo); |
1499 if (Ty.isInvalid()) | 1512 if (Ty.isInvalid()) |
1500 break; | 1513 break; |
1501 | 1514 |
1502 ConsumeAnnotationToken(); | 1515 ConsumeAnnotationToken(); |
1503 Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), | 1516 Res = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), |
1504 Ty.get(), nullptr); | 1517 Ty.get(), nullptr); |
1505 break; | 1518 break; |
1506 } | 1519 } |
1507 LLVM_FALLTHROUGH; | 1520 [[fallthrough]]; |
1508 | 1521 |
1509 case tok::annot_decltype: | 1522 case tok::annot_decltype: |
1510 case tok::kw_char: | 1523 case tok::kw_char: |
1511 case tok::kw_wchar_t: | 1524 case tok::kw_wchar_t: |
1512 case tok::kw_char8_t: | 1525 case tok::kw_char8_t: |
1517 case tok::kw_int: | 1530 case tok::kw_int: |
1518 case tok::kw_long: | 1531 case tok::kw_long: |
1519 case tok::kw___int64: | 1532 case tok::kw___int64: |
1520 case tok::kw___int128: | 1533 case tok::kw___int128: |
1521 case tok::kw__ExtInt: | 1534 case tok::kw__ExtInt: |
1535 case tok::kw__BitInt: | |
1522 case tok::kw_signed: | 1536 case tok::kw_signed: |
1523 case tok::kw_unsigned: | 1537 case tok::kw_unsigned: |
1524 case tok::kw_half: | 1538 case tok::kw_half: |
1525 case tok::kw_float: | 1539 case tok::kw_float: |
1526 case tok::kw_double: | 1540 case tok::kw_double: |
1527 case tok::kw___bf16: | 1541 case tok::kw___bf16: |
1528 case tok::kw__Float16: | 1542 case tok::kw__Float16: |
1529 case tok::kw___float128: | 1543 case tok::kw___float128: |
1544 case tok::kw___ibm128: | |
1530 case tok::kw_void: | 1545 case tok::kw_void: |
1546 case tok::kw_auto: | |
1531 case tok::kw_typename: | 1547 case tok::kw_typename: |
1532 case tok::kw_typeof: | 1548 case tok::kw_typeof: |
1533 case tok::kw___vector: | 1549 case tok::kw___vector: |
1534 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: | 1550 #define GENERIC_IMAGE_TYPE(ImgType, Id) case tok::kw_##ImgType##_t: |
1535 #include "clang/Basic/OpenCLImageTypes.def" | 1551 #include "clang/Basic/OpenCLImageTypes.def" |
1590 // We have a qualified template-id that we know refers to a | 1606 // We have a qualified template-id that we know refers to a |
1591 // type, translate it into a type and continue parsing as a | 1607 // type, translate it into a type and continue parsing as a |
1592 // cast expression. | 1608 // cast expression. |
1593 CXXScopeSpec SS; | 1609 CXXScopeSpec SS; |
1594 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr, | 1610 ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr, |
1595 /*ObjectHadErrors=*/false, | 1611 /*ObjectHasErrors=*/false, |
1596 /*EnteringContext=*/false); | 1612 /*EnteringContext=*/false); |
1597 AnnotateTemplateIdTokenAsType(SS); | 1613 AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::Yes); |
1598 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr, | 1614 return ParseCastExpression(ParseKind, isAddressOfOperand, NotCastExpr, |
1599 isTypeCast, isVectorLiteral, | 1615 isTypeCast, isVectorLiteral, |
1600 NotPrimaryExpression); | 1616 NotPrimaryExpression); |
1601 } | 1617 } |
1602 } | 1618 } |
1611 if (TemplateId->Kind == TNK_Type_template) { | 1627 if (TemplateId->Kind == TNK_Type_template) { |
1612 // We have a template-id that we know refers to a type, | 1628 // We have a template-id that we know refers to a type, |
1613 // translate it into a type and continue parsing as a cast | 1629 // translate it into a type and continue parsing as a cast |
1614 // expression. | 1630 // expression. |
1615 CXXScopeSpec SS; | 1631 CXXScopeSpec SS; |
1616 AnnotateTemplateIdTokenAsType(SS); | 1632 AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::Yes); |
1617 return ParseCastExpression(ParseKind, isAddressOfOperand, | 1633 return ParseCastExpression(ParseKind, isAddressOfOperand, |
1618 NotCastExpr, isTypeCast, isVectorLiteral, | 1634 NotCastExpr, isTypeCast, isVectorLiteral, |
1619 NotPrimaryExpression); | 1635 NotPrimaryExpression); |
1620 } | 1636 } |
1621 | 1637 |
1622 // Fall through to treat the template-id as an id-expression. | 1638 // Fall through to treat the template-id as an id-expression. |
1623 LLVM_FALLTHROUGH; | 1639 [[fallthrough]]; |
1624 } | 1640 } |
1625 | 1641 |
1626 case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id | 1642 case tok::kw_operator: // [C++] id-expression: operator/conversion-function-id |
1627 Res = ParseCXXIdExpression(isAddressOfOperand); | 1643 Res = ParseCXXIdExpression(isAddressOfOperand); |
1628 break; | 1644 break; |
1736 cutOffParsing(); | 1752 cutOffParsing(); |
1737 Actions.CodeCompleteExpression(getCurScope(), | 1753 Actions.CodeCompleteExpression(getCurScope(), |
1738 PreferredType.get(Tok.getLocation())); | 1754 PreferredType.get(Tok.getLocation())); |
1739 return ExprError(); | 1755 return ExprError(); |
1740 } | 1756 } |
1741 #ifndef noCbC | 1757 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait: |
1742 case tok::kw__CbC_return: | 1758 #include "clang/Basic/TransformTypeTraits.def" |
1743 Res = Prepare__retForGotoWithTheEnvExpr(); | 1759 // HACK: libstdc++ uses some of the transform-type-traits as alias |
1744 break; | 1760 // templates, so we need to work around this. |
1745 case tok::kw__CbC_environment: | 1761 if (!NextToken().is(tok::l_paren)) { |
1746 Res = Prepare__envForGotoWithTheEnvExpr(); | 1762 Tok.setKind(tok::identifier); |
1747 break; | 1763 Diag(Tok, diag::ext_keyword_as_ident) |
1748 #endif | 1764 << Tok.getIdentifierInfo()->getName() << 0; |
1765 goto ParseIdentifier; | |
1766 } | |
1767 goto ExpectedExpression; | |
1749 case tok::l_square: | 1768 case tok::l_square: |
1750 if (getLangOpts().CPlusPlus11) { | 1769 if (getLangOpts().CPlusPlus11) { |
1751 if (getLangOpts().ObjC) { | 1770 if (getLangOpts().ObjC) { |
1752 // C++11 lambda expressions and Objective-C message sends both start with a | 1771 // C++11 lambda expressions and Objective-C message sends both start with a |
1753 // square bracket. There are three possibilities here: | 1772 // square bracket. There are three possibilities here: |
1769 } | 1788 } |
1770 if (getLangOpts().ObjC) { | 1789 if (getLangOpts().ObjC) { |
1771 Res = ParseObjCMessageExpression(); | 1790 Res = ParseObjCMessageExpression(); |
1772 break; | 1791 break; |
1773 } | 1792 } |
1774 LLVM_FALLTHROUGH; | 1793 [[fallthrough]]; |
1775 default: | 1794 default: |
1795 ExpectedExpression: | |
1776 NotCastExpr = true; | 1796 NotCastExpr = true; |
1777 return ExprError(); | 1797 return ExprError(); |
1778 } | 1798 } |
1779 | 1799 |
1780 // Check to see whether Res is a function designator only. If it is and we | 1800 // Check to see whether Res is a function designator only. If it is and we |
1800 // "expected ';'" or similar is probably the right diagnostic here. Let | 1820 // "expected ';'" or similar is probably the right diagnostic here. Let |
1801 // the caller decide what to do. | 1821 // the caller decide what to do. |
1802 if (Tok.isAtStartOfLine()) | 1822 if (Tok.isAtStartOfLine()) |
1803 return Res; | 1823 return Res; |
1804 | 1824 |
1805 LLVM_FALLTHROUGH; | 1825 [[fallthrough]]; |
1806 case tok::period: | 1826 case tok::period: |
1807 case tok::arrow: | 1827 case tok::arrow: |
1808 break; | 1828 break; |
1809 | 1829 |
1810 default: | 1830 default: |
1845 /// \verbatim | 1865 /// \verbatim |
1846 /// postfix-expression: [C99 6.5.2] | 1866 /// postfix-expression: [C99 6.5.2] |
1847 /// primary-expression | 1867 /// primary-expression |
1848 /// postfix-expression '[' expression ']' | 1868 /// postfix-expression '[' expression ']' |
1849 /// postfix-expression '[' braced-init-list ']' | 1869 /// postfix-expression '[' braced-init-list ']' |
1870 /// postfix-expression '[' expression-list [opt] ']' [C++2b 12.4.5] | |
1850 /// postfix-expression '(' argument-expression-list[opt] ')' | 1871 /// postfix-expression '(' argument-expression-list[opt] ')' |
1851 /// postfix-expression '.' identifier | 1872 /// postfix-expression '.' identifier |
1852 /// postfix-expression '->' identifier | 1873 /// postfix-expression '->' identifier |
1853 /// postfix-expression '++' | 1874 /// postfix-expression '++' |
1854 /// postfix-expression '--' | 1875 /// postfix-expression '--' |
1863 Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { | 1884 Parser::ParsePostfixExpressionSuffix(ExprResult LHS) { |
1864 // Now that the primary-expression piece of the postfix-expression has been | 1885 // Now that the primary-expression piece of the postfix-expression has been |
1865 // parsed, see if there are any postfix-expression pieces here. | 1886 // parsed, see if there are any postfix-expression pieces here. |
1866 SourceLocation Loc; | 1887 SourceLocation Loc; |
1867 auto SavedType = PreferredType; | 1888 auto SavedType = PreferredType; |
1868 while (1) { | 1889 while (true) { |
1869 // Each iteration relies on preferred type for the whole expression. | 1890 // Each iteration relies on preferred type for the whole expression. |
1870 PreferredType = SavedType; | 1891 PreferredType = SavedType; |
1871 switch (Tok.getKind()) { | 1892 switch (Tok.getKind()) { |
1872 case tok::code_completion: | 1893 case tok::code_completion: |
1873 if (InMessageExpression) | 1894 if (InMessageExpression) |
1887 LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), | 1908 LHS = ParseObjCMessageExpressionBody(SourceLocation(), SourceLocation(), |
1888 nullptr, LHS.get()); | 1909 nullptr, LHS.get()); |
1889 break; | 1910 break; |
1890 } | 1911 } |
1891 // Fall through; this isn't a message send. | 1912 // Fall through; this isn't a message send. |
1892 LLVM_FALLTHROUGH; | 1913 [[fallthrough]]; |
1893 | 1914 |
1894 default: // Not a postfix-expression suffix. | 1915 default: // Not a postfix-expression suffix. |
1895 return LHS; | 1916 return LHS; |
1896 case tok::l_square: { // postfix-expression: p-e '[' expression ']' | 1917 case tok::l_square: { // postfix-expression: p-e '[' expression ']' |
1897 // If we have a array postfix expression that starts on a new line and | 1918 // If we have a array postfix expression that starts on a new line and |
1908 // reserved for attributes. | 1929 // reserved for attributes. |
1909 if (CheckProhibitedCXX11Attribute()) { | 1930 if (CheckProhibitedCXX11Attribute()) { |
1910 (void)Actions.CorrectDelayedTyposInExpr(LHS); | 1931 (void)Actions.CorrectDelayedTyposInExpr(LHS); |
1911 return ExprError(); | 1932 return ExprError(); |
1912 } | 1933 } |
1913 | |
1914 BalancedDelimiterTracker T(*this, tok::l_square); | 1934 BalancedDelimiterTracker T(*this, tok::l_square); |
1915 T.consumeOpen(); | 1935 T.consumeOpen(); |
1916 Loc = T.getOpenLocation(); | 1936 Loc = T.getOpenLocation(); |
1917 ExprResult Idx, Length, Stride; | 1937 ExprResult Length, Stride; |
1918 SourceLocation ColonLocFirst, ColonLocSecond; | 1938 SourceLocation ColonLocFirst, ColonLocSecond; |
1939 ExprVector ArgExprs; | |
1940 bool HasError = false; | |
1919 PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get()); | 1941 PreferredType.enterSubscript(Actions, Tok.getLocation(), LHS.get()); |
1920 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { | 1942 |
1921 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); | 1943 // We try to parse a list of indexes in all language mode first |
1922 Idx = ParseBraceInitializer(); | 1944 // and, in we find 0 or one index, we try to parse an OpenMP array |
1923 } else if (getLangOpts().OpenMP) { | 1945 // section. This allow us to support C++2b multi dimensional subscript and |
1946 // OpenMp sections in the same language mode. | |
1947 if (!getLangOpts().OpenMP || Tok.isNot(tok::colon)) { | |
1948 if (!getLangOpts().CPlusPlus2b) { | |
1949 ExprResult Idx; | |
1950 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { | |
1951 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); | |
1952 Idx = ParseBraceInitializer(); | |
1953 } else { | |
1954 Idx = ParseExpression(); // May be a comma expression | |
1955 } | |
1956 LHS = Actions.CorrectDelayedTyposInExpr(LHS); | |
1957 Idx = Actions.CorrectDelayedTyposInExpr(Idx); | |
1958 if (Idx.isInvalid()) { | |
1959 HasError = true; | |
1960 } else { | |
1961 ArgExprs.push_back(Idx.get()); | |
1962 } | |
1963 } else if (Tok.isNot(tok::r_square)) { | |
1964 CommaLocsTy CommaLocs; | |
1965 if (ParseExpressionList(ArgExprs, CommaLocs)) { | |
1966 LHS = Actions.CorrectDelayedTyposInExpr(LHS); | |
1967 HasError = true; | |
1968 } | |
1969 assert( | |
1970 (ArgExprs.empty() || ArgExprs.size() == CommaLocs.size() + 1) && | |
1971 "Unexpected number of commas!"); | |
1972 } | |
1973 } | |
1974 | |
1975 if (ArgExprs.size() <= 1 && getLangOpts().OpenMP) { | |
1924 ColonProtectionRAIIObject RAII(*this); | 1976 ColonProtectionRAIIObject RAII(*this); |
1925 // Parse [: or [ expr or [ expr : | |
1926 if (!Tok.is(tok::colon)) { | |
1927 // [ expr | |
1928 Idx = ParseExpression(); | |
1929 } | |
1930 if (Tok.is(tok::colon)) { | 1977 if (Tok.is(tok::colon)) { |
1931 // Consume ':' | 1978 // Consume ':' |
1932 ColonLocFirst = ConsumeToken(); | 1979 ColonLocFirst = ConsumeToken(); |
1933 if (Tok.isNot(tok::r_square) && | 1980 if (Tok.isNot(tok::r_square) && |
1934 (getLangOpts().OpenMP < 50 || | 1981 (getLangOpts().OpenMP < 50 || |
1935 ((Tok.isNot(tok::colon) && getLangOpts().OpenMP >= 50)))) | 1982 ((Tok.isNot(tok::colon) && getLangOpts().OpenMP >= 50)))) { |
1936 Length = ParseExpression(); | 1983 Length = ParseExpression(); |
1984 Length = Actions.CorrectDelayedTyposInExpr(Length); | |
1985 } | |
1937 } | 1986 } |
1938 if (getLangOpts().OpenMP >= 50 && | 1987 if (getLangOpts().OpenMP >= 50 && |
1939 (OMPClauseKind == llvm::omp::Clause::OMPC_to || | 1988 (OMPClauseKind == llvm::omp::Clause::OMPC_to || |
1940 OMPClauseKind == llvm::omp::Clause::OMPC_from) && | 1989 OMPClauseKind == llvm::omp::Clause::OMPC_from) && |
1941 Tok.is(tok::colon)) { | 1990 Tok.is(tok::colon)) { |
1943 ColonLocSecond = ConsumeToken(); | 1992 ColonLocSecond = ConsumeToken(); |
1944 if (Tok.isNot(tok::r_square)) { | 1993 if (Tok.isNot(tok::r_square)) { |
1945 Stride = ParseExpression(); | 1994 Stride = ParseExpression(); |
1946 } | 1995 } |
1947 } | 1996 } |
1948 } else | 1997 } |
1949 Idx = ParseExpression(); | |
1950 | 1998 |
1951 SourceLocation RLoc = Tok.getLocation(); | 1999 SourceLocation RLoc = Tok.getLocation(); |
1952 | |
1953 LHS = Actions.CorrectDelayedTyposInExpr(LHS); | 2000 LHS = Actions.CorrectDelayedTyposInExpr(LHS); |
1954 Idx = Actions.CorrectDelayedTyposInExpr(Idx); | 2001 |
1955 Length = Actions.CorrectDelayedTyposInExpr(Length); | 2002 if (!LHS.isInvalid() && !HasError && !Length.isInvalid() && |
1956 if (!LHS.isInvalid() && !Idx.isInvalid() && !Length.isInvalid() && | |
1957 !Stride.isInvalid() && Tok.is(tok::r_square)) { | 2003 !Stride.isInvalid() && Tok.is(tok::r_square)) { |
1958 if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) { | 2004 if (ColonLocFirst.isValid() || ColonLocSecond.isValid()) { |
1959 LHS = Actions.ActOnOMPArraySectionExpr( | 2005 LHS = Actions.ActOnOMPArraySectionExpr( |
1960 LHS.get(), Loc, Idx.get(), ColonLocFirst, ColonLocSecond, | 2006 LHS.get(), Loc, ArgExprs.empty() ? nullptr : ArgExprs[0], |
1961 Length.get(), Stride.get(), RLoc); | 2007 ColonLocFirst, ColonLocSecond, Length.get(), Stride.get(), RLoc); |
1962 } else { | 2008 } else { |
1963 LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc, | 2009 LHS = Actions.ActOnArraySubscriptExpr(getCurScope(), LHS.get(), Loc, |
1964 Idx.get(), RLoc); | 2010 ArgExprs, RLoc); |
1965 } | 2011 } |
1966 } else { | 2012 } else { |
1967 LHS = ExprError(); | 2013 LHS = ExprError(); |
1968 Idx = ExprError(); | |
1969 } | 2014 } |
1970 | 2015 |
1971 // Match the ']'. | 2016 // Match the ']'. |
1972 T.consumeClose(); | 2017 T.consumeClose(); |
1973 break; | 2018 break; |
2029 | 2074 |
2030 ExprVector ArgExprs; | 2075 ExprVector ArgExprs; |
2031 CommaLocsTy CommaLocs; | 2076 CommaLocsTy CommaLocs; |
2032 auto RunSignatureHelp = [&]() -> QualType { | 2077 auto RunSignatureHelp = [&]() -> QualType { |
2033 QualType PreferredType = Actions.ProduceCallSignatureHelp( | 2078 QualType PreferredType = Actions.ProduceCallSignatureHelp( |
2034 getCurScope(), LHS.get(), ArgExprs, PT.getOpenLocation()); | 2079 LHS.get(), ArgExprs, PT.getOpenLocation()); |
2035 CalledSignatureHelp = true; | 2080 CalledSignatureHelp = true; |
2036 return PreferredType; | 2081 return PreferredType; |
2037 }; | 2082 }; |
2038 if (OpKind == tok::l_paren || !LHS.isInvalid()) { | 2083 if (OpKind == tok::l_paren || !LHS.isInvalid()) { |
2039 if (Tok.isNot(tok::r_paren)) { | 2084 if (Tok.isNot(tok::r_paren)) { |
2251 /// | 2296 /// |
2252 /// [GNU] typeof-specifier: | 2297 /// [GNU] typeof-specifier: |
2253 /// typeof ( expressions ) | 2298 /// typeof ( expressions ) |
2254 /// typeof ( type-name ) | 2299 /// typeof ( type-name ) |
2255 /// [GNU/C++] typeof unary-expression | 2300 /// [GNU/C++] typeof unary-expression |
2301 /// [C2x] typeof-specifier: | |
2302 /// typeof '(' typeof-specifier-argument ')' | |
2303 /// typeof_unqual '(' typeof-specifier-argument ')' | |
2304 /// | |
2305 /// typeof-specifier-argument: | |
2306 /// expression | |
2307 /// type-name | |
2256 /// | 2308 /// |
2257 /// [OpenCL 1.1 6.11.12] vec_step built-in function: | 2309 /// [OpenCL 1.1 6.11.12] vec_step built-in function: |
2258 /// vec_step ( expressions ) | 2310 /// vec_step ( expressions ) |
2259 /// vec_step ( type-name ) | 2311 /// vec_step ( type-name ) |
2260 /// \endverbatim | 2312 /// \endverbatim |
2262 Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, | 2314 Parser::ParseExprAfterUnaryExprOrTypeTrait(const Token &OpTok, |
2263 bool &isCastExpr, | 2315 bool &isCastExpr, |
2264 ParsedType &CastTy, | 2316 ParsedType &CastTy, |
2265 SourceRange &CastRange) { | 2317 SourceRange &CastRange) { |
2266 | 2318 |
2267 assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_sizeof, tok::kw___alignof, | 2319 assert(OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual, tok::kw_sizeof, |
2268 tok::kw_alignof, tok::kw__Alignof, tok::kw_vec_step, | 2320 tok::kw___alignof, tok::kw_alignof, tok::kw__Alignof, |
2321 tok::kw_vec_step, | |
2269 tok::kw___builtin_omp_required_simd_align) && | 2322 tok::kw___builtin_omp_required_simd_align) && |
2270 "Not a typeof/sizeof/alignof/vec_step expression!"); | 2323 "Not a typeof/sizeof/alignof/vec_step expression!"); |
2271 | 2324 |
2272 ExprResult Operand; | 2325 ExprResult Operand; |
2273 | 2326 |
2278 if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof, | 2331 if (OpTok.isOneOf(tok::kw_sizeof, tok::kw___alignof, tok::kw_alignof, |
2279 tok::kw__Alignof)) { | 2332 tok::kw__Alignof)) { |
2280 if (isTypeIdUnambiguously()) { | 2333 if (isTypeIdUnambiguously()) { |
2281 DeclSpec DS(AttrFactory); | 2334 DeclSpec DS(AttrFactory); |
2282 ParseSpecifierQualifierList(DS); | 2335 ParseSpecifierQualifierList(DS); |
2283 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); | 2336 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), |
2337 DeclaratorContext::TypeName); | |
2284 ParseDeclarator(DeclaratorInfo); | 2338 ParseDeclarator(DeclaratorInfo); |
2285 | 2339 |
2286 SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation()); | 2340 SourceLocation LParenLoc = PP.getLocForEndOfToken(OpTok.getLocation()); |
2287 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); | 2341 SourceLocation RParenLoc = PP.getLocForEndOfToken(PrevTokLocation); |
2288 if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) { | 2342 if (LParenLoc.isInvalid() || RParenLoc.isInvalid()) { |
2298 return ExprEmpty(); | 2352 return ExprEmpty(); |
2299 } | 2353 } |
2300 } | 2354 } |
2301 | 2355 |
2302 isCastExpr = false; | 2356 isCastExpr = false; |
2303 if (OpTok.is(tok::kw_typeof) && !getLangOpts().CPlusPlus) { | 2357 if (OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual) && |
2358 !getLangOpts().CPlusPlus) { | |
2304 Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo() | 2359 Diag(Tok, diag::err_expected_after) << OpTok.getIdentifierInfo() |
2305 << tok::l_paren; | 2360 << tok::l_paren; |
2306 return ExprError(); | 2361 return ExprError(); |
2307 } | 2362 } |
2308 | 2363 |
2324 if (ExprType == CastExpr) { | 2379 if (ExprType == CastExpr) { |
2325 isCastExpr = true; | 2380 isCastExpr = true; |
2326 return ExprEmpty(); | 2381 return ExprEmpty(); |
2327 } | 2382 } |
2328 | 2383 |
2329 if (getLangOpts().CPlusPlus || OpTok.isNot(tok::kw_typeof)) { | 2384 if (getLangOpts().CPlusPlus || |
2385 !OpTok.isOneOf(tok::kw_typeof, tok::kw_typeof_unqual)) { | |
2330 // GNU typeof in C requires the expression to be parenthesized. Not so for | 2386 // GNU typeof in C requires the expression to be parenthesized. Not so for |
2331 // sizeof/alignof or in C++. Therefore, the parenthesized expression is | 2387 // sizeof/alignof or in C++. Therefore, the parenthesized expression is |
2332 // the start of a unary-expression, but doesn't include any postfix | 2388 // the start of a unary-expression, but doesn't include any postfix |
2333 // pieces. Parse these now if present. | 2389 // pieces. Parse these now if present. |
2334 if (!Operand.isInvalid()) | 2390 if (!Operand.isInvalid()) |
2343 | 2399 |
2344 /// Parse a __builtin_sycl_unique_stable_name expression. Accepts a type-id as | 2400 /// Parse a __builtin_sycl_unique_stable_name expression. Accepts a type-id as |
2345 /// a parameter. | 2401 /// a parameter. |
2346 ExprResult Parser::ParseSYCLUniqueStableNameExpression() { | 2402 ExprResult Parser::ParseSYCLUniqueStableNameExpression() { |
2347 assert(Tok.is(tok::kw___builtin_sycl_unique_stable_name) && | 2403 assert(Tok.is(tok::kw___builtin_sycl_unique_stable_name) && |
2348 "Not __bulitin_sycl_unique_stable_name"); | 2404 "Not __builtin_sycl_unique_stable_name"); |
2349 | 2405 |
2350 SourceLocation OpLoc = ConsumeToken(); | 2406 SourceLocation OpLoc = ConsumeToken(); |
2351 BalancedDelimiterTracker T(*this, tok::l_paren); | 2407 BalancedDelimiterTracker T(*this, tok::l_paren); |
2352 | 2408 |
2353 // __builtin_sycl_unique_stable_name expressions are always parenthesized. | 2409 // __builtin_sycl_unique_stable_name expressions are always parenthesized. |
2492 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' | 2548 /// [GNU] '__builtin_types_compatible_p' '(' type-name ',' type-name ')' |
2493 /// [GNU] '__builtin_FILE' '(' ')' | 2549 /// [GNU] '__builtin_FILE' '(' ')' |
2494 /// [GNU] '__builtin_FUNCTION' '(' ')' | 2550 /// [GNU] '__builtin_FUNCTION' '(' ')' |
2495 /// [GNU] '__builtin_LINE' '(' ')' | 2551 /// [GNU] '__builtin_LINE' '(' ')' |
2496 /// [CLANG] '__builtin_COLUMN' '(' ')' | 2552 /// [CLANG] '__builtin_COLUMN' '(' ')' |
2553 /// [GNU] '__builtin_source_location' '(' ')' | |
2497 /// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')' | 2554 /// [OCL] '__builtin_astype' '(' assignment-expression ',' type-name ')' |
2498 /// | 2555 /// |
2499 /// [GNU] offsetof-member-designator: | 2556 /// [GNU] offsetof-member-designator: |
2500 /// [GNU] identifier | 2557 /// [GNU] identifier |
2501 /// [GNU] offsetof-member-designator '.' identifier | 2558 /// [GNU] offsetof-member-designator '.' identifier |
2568 Comps.back().isBrackets = false; | 2625 Comps.back().isBrackets = false; |
2569 Comps.back().U.IdentInfo = Tok.getIdentifierInfo(); | 2626 Comps.back().U.IdentInfo = Tok.getIdentifierInfo(); |
2570 Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken(); | 2627 Comps.back().LocStart = Comps.back().LocEnd = ConsumeToken(); |
2571 | 2628 |
2572 // FIXME: This loop leaks the index expressions on error. | 2629 // FIXME: This loop leaks the index expressions on error. |
2573 while (1) { | 2630 while (true) { |
2574 if (Tok.is(tok::period)) { | 2631 if (Tok.is(tok::period)) { |
2575 // offsetof-member-designator: offsetof-member-designator '.' identifier | 2632 // offsetof-member-designator: offsetof-member-designator '.' identifier |
2576 Comps.push_back(Sema::OffsetOfComponent()); | 2633 Comps.push_back(Sema::OffsetOfComponent()); |
2577 Comps.back().isBrackets = false; | 2634 Comps.back().isBrackets = false; |
2578 Comps.back().LocStart = ConsumeToken(); | 2635 Comps.back().LocStart = ConsumeToken(); |
2714 break; | 2771 break; |
2715 } | 2772 } |
2716 case tok::kw___builtin_COLUMN: | 2773 case tok::kw___builtin_COLUMN: |
2717 case tok::kw___builtin_FILE: | 2774 case tok::kw___builtin_FILE: |
2718 case tok::kw___builtin_FUNCTION: | 2775 case tok::kw___builtin_FUNCTION: |
2719 case tok::kw___builtin_LINE: { | 2776 case tok::kw___builtin_LINE: |
2777 case tok::kw___builtin_source_location: { | |
2720 // Attempt to consume the r-paren. | 2778 // Attempt to consume the r-paren. |
2721 if (Tok.isNot(tok::r_paren)) { | 2779 if (Tok.isNot(tok::r_paren)) { |
2722 Diag(Tok, diag::err_expected) << tok::r_paren; | 2780 Diag(Tok, diag::err_expected) << tok::r_paren; |
2723 SkipUntil(tok::r_paren, StopAtSemi); | 2781 SkipUntil(tok::r_paren, StopAtSemi); |
2724 return ExprError(); | 2782 return ExprError(); |
2731 return SourceLocExpr::Function; | 2789 return SourceLocExpr::Function; |
2732 case tok::kw___builtin_LINE: | 2790 case tok::kw___builtin_LINE: |
2733 return SourceLocExpr::Line; | 2791 return SourceLocExpr::Line; |
2734 case tok::kw___builtin_COLUMN: | 2792 case tok::kw___builtin_COLUMN: |
2735 return SourceLocExpr::Column; | 2793 return SourceLocExpr::Column; |
2794 case tok::kw___builtin_source_location: | |
2795 return SourceLocExpr::SourceLocStruct; | |
2736 default: | 2796 default: |
2737 llvm_unreachable("invalid keyword"); | 2797 llvm_unreachable("invalid keyword"); |
2738 } | 2798 } |
2739 }(); | 2799 }(); |
2740 Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen()); | 2800 Res = Actions.ActOnSourceLocExpr(Kind, StartLoc, ConsumeParen()); |
2848 } | 2908 } |
2849 | 2909 |
2850 // None of these cases should fall through with an invalid Result | 2910 // None of these cases should fall through with an invalid Result |
2851 // unless they've already reported an error. | 2911 // unless they've already reported an error. |
2852 if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) { | 2912 if (ExprType >= CompoundStmt && Tok.is(tok::l_brace)) { |
2853 Diag(Tok, diag::ext_gnu_statement_expr); | 2913 Diag(Tok, OpenLoc.isMacroID() ? diag::ext_gnu_statement_expr_macro |
2914 : diag::ext_gnu_statement_expr); | |
2854 | 2915 |
2855 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin); | 2916 checkCompoundToken(OpenLoc, tok::l_paren, CompoundToken::StmtExprBegin); |
2856 | 2917 |
2857 if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) { | 2918 if (!getCurScope()->getFnParent() && !getCurScope()->getBlockParent()) { |
2858 Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope)); | 2919 Result = ExprError(Diag(OpenLoc, diag::err_stmtexpr_file_scope)); |
2936 } | 2997 } |
2937 | 2998 |
2938 // Parse the type declarator. | 2999 // Parse the type declarator. |
2939 DeclSpec DS(AttrFactory); | 3000 DeclSpec DS(AttrFactory); |
2940 ParseSpecifierQualifierList(DS); | 3001 ParseSpecifierQualifierList(DS); |
2941 Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName); | 3002 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), |
3003 DeclaratorContext::TypeName); | |
2942 ParseDeclarator(DeclaratorInfo); | 3004 ParseDeclarator(DeclaratorInfo); |
2943 | 3005 |
2944 // If our type is followed by an identifier and either ':' or ']', then | 3006 // If our type is followed by an identifier and either ':' or ']', then |
2945 // this is probably an Objective-C message send where the leading '[' is | 3007 // this is probably an Objective-C message send where the leading '[' is |
2946 // missing. Recover as if that were the case. | 3008 // missing. Recover as if that were the case. |
3253 } | 3315 } |
3254 DefaultLoc = ConsumeToken(); | 3316 DefaultLoc = ConsumeToken(); |
3255 Ty = nullptr; | 3317 Ty = nullptr; |
3256 } else { | 3318 } else { |
3257 ColonProtectionRAIIObject X(*this); | 3319 ColonProtectionRAIIObject X(*this); |
3258 TypeResult TR = ParseTypeName(); | 3320 TypeResult TR = ParseTypeName(nullptr, DeclaratorContext::Association); |
3259 if (TR.isInvalid()) { | 3321 if (TR.isInvalid()) { |
3260 SkipUntil(tok::r_paren, StopAtSemi); | 3322 SkipUntil(tok::r_paren, StopAtSemi); |
3261 return ExprError(); | 3323 return ExprError(); |
3262 } | 3324 } |
3263 Ty = TR.get(); | 3325 Ty = TR.get(); |
3366 /// [C++0x] assignment-expression | 3428 /// [C++0x] assignment-expression |
3367 /// [C++0x] braced-init-list | 3429 /// [C++0x] braced-init-list |
3368 /// \endverbatim | 3430 /// \endverbatim |
3369 bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, | 3431 bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs, |
3370 SmallVectorImpl<SourceLocation> &CommaLocs, | 3432 SmallVectorImpl<SourceLocation> &CommaLocs, |
3371 llvm::function_ref<void()> ExpressionStarts) { | 3433 llvm::function_ref<void()> ExpressionStarts, |
3434 bool FailImmediatelyOnInvalidExpr, | |
3435 bool EarlyTypoCorrection) { | |
3372 bool SawError = false; | 3436 bool SawError = false; |
3373 while (1) { | 3437 while (true) { |
3374 if (ExpressionStarts) | 3438 if (ExpressionStarts) |
3375 ExpressionStarts(); | 3439 ExpressionStarts(); |
3376 | 3440 |
3377 ExprResult Expr; | 3441 ExprResult Expr; |
3378 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { | 3442 if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
3379 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); | 3443 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
3380 Expr = ParseBraceInitializer(); | 3444 Expr = ParseBraceInitializer(); |
3381 } | 3445 } else |
3382 #ifndef noCbC | |
3383 else if (Tok.is(tok::kw__CbC_return)){ | |
3384 Expr = Prepare__retForGotoWithTheEnvExpr(); | |
3385 } | |
3386 else if (Tok.is(tok::kw__CbC_environment)){ | |
3387 Expr = Prepare__envForGotoWithTheEnvExpr(); | |
3388 } | |
3389 else if (Tok.is(tok::identifier) && NeedPrototypeDeclaration(Tok)){ // check code segment declaration. | |
3390 CreatePrototypeDeclaration(); | |
3391 Expr = ParseAssignmentExpression(); | 3446 Expr = ParseAssignmentExpression(); |
3392 } | 3447 |
3393 #endif | 3448 if (EarlyTypoCorrection) |
3394 else | 3449 Expr = Actions.CorrectDelayedTyposInExpr(Expr); |
3395 Expr = ParseAssignmentExpression(); | |
3396 | 3450 |
3397 if (Tok.is(tok::ellipsis)) | 3451 if (Tok.is(tok::ellipsis)) |
3398 Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken()); | 3452 Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken()); |
3399 else if (Tok.is(tok::code_completion)) { | 3453 else if (Tok.is(tok::code_completion)) { |
3400 // There's nothing to suggest in here as we parsed a full expression. | 3454 // There's nothing to suggest in here as we parsed a full expression. |
3405 SawError = true; | 3459 SawError = true; |
3406 cutOffParsing(); | 3460 cutOffParsing(); |
3407 break; | 3461 break; |
3408 } | 3462 } |
3409 if (Expr.isInvalid()) { | 3463 if (Expr.isInvalid()) { |
3464 SawError = true; | |
3465 if (FailImmediatelyOnInvalidExpr) | |
3466 break; | |
3410 SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch); | 3467 SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch); |
3411 SawError = true; | |
3412 } else { | 3468 } else { |
3413 Exprs.push_back(Expr.get()); | 3469 Exprs.push_back(Expr.get()); |
3414 } | 3470 } |
3415 | 3471 |
3416 if (Tok.isNot(tok::comma)) | 3472 if (Tok.isNot(tok::comma)) |
3441 /// simple-expression-list , assignment-expression | 3497 /// simple-expression-list , assignment-expression |
3442 /// \endverbatim | 3498 /// \endverbatim |
3443 bool | 3499 bool |
3444 Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs, | 3500 Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs, |
3445 SmallVectorImpl<SourceLocation> &CommaLocs) { | 3501 SmallVectorImpl<SourceLocation> &CommaLocs) { |
3446 while (1) { | 3502 while (true) { |
3447 ExprResult Expr = ParseAssignmentExpression(); | 3503 ExprResult Expr = ParseAssignmentExpression(); |
3448 if (Expr.isInvalid()) | 3504 if (Expr.isInvalid()) |
3449 return true; | 3505 return true; |
3450 | 3506 |
3451 Exprs.push_back(Expr.get()); | 3507 Exprs.push_back(Expr.get()); |
3452 | 3508 |
3453 if (Tok.isNot(tok::comma)) | 3509 // We might be parsing the LHS of a fold-expression. If we reached the fold |
3510 // operator, stop. | |
3511 if (Tok.isNot(tok::comma) || NextToken().is(tok::ellipsis)) | |
3454 return false; | 3512 return false; |
3455 | 3513 |
3456 // Move to the next argument, remember where the comma was. | 3514 // Move to the next argument, remember where the comma was. |
3457 Token Comma = Tok; | 3515 Token Comma = Tok; |
3458 CommaLocs.push_back(ConsumeToken()); | 3516 CommaLocs.push_back(ConsumeToken()); |
3477 // Parse the specifier-qualifier-list piece. | 3535 // Parse the specifier-qualifier-list piece. |
3478 DeclSpec DS(AttrFactory); | 3536 DeclSpec DS(AttrFactory); |
3479 ParseSpecifierQualifierList(DS); | 3537 ParseSpecifierQualifierList(DS); |
3480 | 3538 |
3481 // Parse the block-declarator. | 3539 // Parse the block-declarator. |
3482 Declarator DeclaratorInfo(DS, DeclaratorContext::BlockLiteral); | 3540 Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), |
3541 DeclaratorContext::BlockLiteral); | |
3483 DeclaratorInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); | 3542 DeclaratorInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); |
3484 ParseDeclarator(DeclaratorInfo); | 3543 ParseDeclarator(DeclaratorInfo); |
3485 | 3544 |
3486 MaybeParseGNUAttributes(DeclaratorInfo); | 3545 MaybeParseGNUAttributes(DeclaratorInfo); |
3487 | 3546 |
3516 // Inform sema that we are starting a block. | 3575 // Inform sema that we are starting a block. |
3517 Actions.ActOnBlockStart(CaretLoc, getCurScope()); | 3576 Actions.ActOnBlockStart(CaretLoc, getCurScope()); |
3518 | 3577 |
3519 // Parse the return type if present. | 3578 // Parse the return type if present. |
3520 DeclSpec DS(AttrFactory); | 3579 DeclSpec DS(AttrFactory); |
3521 Declarator ParamInfo(DS, DeclaratorContext::BlockLiteral); | 3580 Declarator ParamInfo(DS, ParsedAttributesView::none(), |
3581 DeclaratorContext::BlockLiteral); | |
3522 ParamInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); | 3582 ParamInfo.setFunctionDefinitionKind(FunctionDefinitionKind::Definition); |
3523 // FIXME: Since the return type isn't actually parsed, it can't be used to | 3583 // FIXME: Since the return type isn't actually parsed, it can't be used to |
3524 // fill ParamInfo with an initial valid range, so do it manually. | 3584 // fill ParamInfo with an initial valid range, so do it manually. |
3525 ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation())); | 3585 ParamInfo.SetSourceRange(SourceRange(Tok.getLocation(), Tok.getLocation())); |
3526 | 3586 |