| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
| 6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 IdentifierT ParseIdentifierName(bool* ok); | 721 IdentifierT ParseIdentifierName(bool* ok); |
| 722 | 722 |
| 723 ExpressionT ParseRegExpLiteral(bool seen_equal, | 723 ExpressionT ParseRegExpLiteral(bool seen_equal, |
| 724 ExpressionClassifier* classifier, bool* ok); | 724 ExpressionClassifier* classifier, bool* ok); |
| 725 | 725 |
| 726 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, | 726 ExpressionT ParsePrimaryExpression(ExpressionClassifier* classifier, |
| 727 bool* ok); | 727 bool* ok); |
| 728 ExpressionT ParseExpression(bool accept_IN, bool* ok); | 728 ExpressionT ParseExpression(bool accept_IN, bool* ok); |
| 729 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, | 729 ExpressionT ParseExpression(bool accept_IN, ExpressionClassifier* classifier, |
| 730 bool* ok); | 730 bool* ok); |
| 731 ExpressionT ParseExpression(bool accept_IN, int flags, | |
| 732 ExpressionClassifier* classifier, bool* ok); | |
| 733 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); | 731 ExpressionT ParseArrayLiteral(ExpressionClassifier* classifier, bool* ok); |
| 734 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, | 732 ExpressionT ParsePropertyName(IdentifierT* name, bool* is_get, bool* is_set, |
| 735 bool* is_computed_name, | 733 bool* is_computed_name, |
| 736 ExpressionClassifier* classifier, bool* ok); | 734 ExpressionClassifier* classifier, bool* ok); |
| 737 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); | 735 ExpressionT ParseObjectLiteral(ExpressionClassifier* classifier, bool* ok); |
| 738 ObjectLiteralPropertyT ParsePropertyDefinition( | 736 ObjectLiteralPropertyT ParsePropertyDefinition( |
| 739 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, | 737 ObjectLiteralCheckerBase* checker, bool in_class, bool has_extends, |
| 740 bool is_static, bool* is_computed_name, bool* has_seen_constructor, | 738 bool is_static, bool* is_computed_name, bool* has_seen_constructor, |
| 741 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); | 739 ExpressionClassifier* classifier, IdentifierT* name, bool* ok); |
| 742 typename Traits::Type::ExpressionList ParseArguments( | 740 typename Traits::Type::ExpressionList ParseArguments( |
| 743 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, | 741 Scanner::Location* first_spread_pos, ExpressionClassifier* classifier, |
| 744 bool* ok); | 742 bool* ok); |
| 745 | 743 |
| 746 enum AssignmentExpressionFlags { | 744 enum AssignmentExpressionFlags { |
| 747 kIsNormalAssignment = 0, | 745 kIsNormalAssignment, |
| 748 kIsPossiblePatternElement = 1 << 0, | 746 kIsPossiblePatternElement |
| 749 kIsPossibleArrowFormals = 1 << 1 | |
| 750 }; | 747 }; |
| 751 | 748 |
| 752 ExpressionT ParseAssignmentExpression(bool accept_IN, int flags, | 749 ExpressionT ParseAssignmentExpression(bool accept_IN, |
| 750 AssignmentExpressionFlags flags, |
| 753 ExpressionClassifier* classifier, | 751 ExpressionClassifier* classifier, |
| 754 bool* ok); | 752 bool* ok); |
| 755 ExpressionT ParseAssignmentExpression(bool accept_IN, | 753 ExpressionT ParseAssignmentExpression(bool accept_IN, |
| 756 ExpressionClassifier* classifier, | 754 ExpressionClassifier* classifier, |
| 757 bool* ok) { | 755 bool* ok) { |
| 758 return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier, | 756 return ParseAssignmentExpression(accept_IN, kIsNormalAssignment, classifier, |
| 759 ok); | 757 ok); |
| 760 } | 758 } |
| 761 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); | 759 ExpressionT ParseYieldExpression(ExpressionClassifier* classifier, bool* ok); |
| 762 ExpressionT ParseConditionalExpression(bool accept_IN, | 760 ExpressionT ParseConditionalExpression(bool accept_IN, |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1320 return factory()->NewEmptyParentheses(beg_pos); | 1318 return factory()->NewEmptyParentheses(beg_pos); |
| 1321 } else if (Check(Token::ELLIPSIS)) { | 1319 } else if (Check(Token::ELLIPSIS)) { |
| 1322 // (...x)=>x. The continuation that looks for the => is in | 1320 // (...x)=>x. The continuation that looks for the => is in |
| 1323 // ParseAssignmentExpression. | 1321 // ParseAssignmentExpression. |
| 1324 int ellipsis_pos = position(); | 1322 int ellipsis_pos = position(); |
| 1325 int expr_pos = peek_position(); | 1323 int expr_pos = peek_position(); |
| 1326 classifier->RecordExpressionError(scanner()->location(), | 1324 classifier->RecordExpressionError(scanner()->location(), |
| 1327 MessageTemplate::kUnexpectedToken, | 1325 MessageTemplate::kUnexpectedToken, |
| 1328 Token::String(Token::ELLIPSIS)); | 1326 Token::String(Token::ELLIPSIS)); |
| 1329 classifier->RecordNonSimpleParameter(); | 1327 classifier->RecordNonSimpleParameter(); |
| 1330 ExpressionT expr = this->ParseAssignmentExpression( | 1328 ExpressionT expr = |
| 1331 true, kIsPossibleArrowFormals, classifier, CHECK_OK); | 1329 this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
| 1332 if (!this->IsIdentifier(expr) && !expr->IsObjectLiteral() && | 1330 if (!this->IsIdentifier(expr) && !expr->IsObjectLiteral() && |
| 1333 !expr->IsArrayLiteral()) { | 1331 !expr->IsArrayLiteral()) { |
| 1334 classifier->RecordArrowFormalParametersError( | 1332 classifier->RecordArrowFormalParametersError( |
| 1335 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), | 1333 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), |
| 1336 MessageTemplate::kInvalidRestParameter); | 1334 MessageTemplate::kInvalidRestParameter); |
| 1337 } | 1335 } |
| 1338 if (peek() == Token::COMMA) { | 1336 if (peek() == Token::COMMA) { |
| 1339 ReportMessageAt(scanner()->peek_location(), | 1337 ReportMessageAt(scanner()->peek_location(), |
| 1340 MessageTemplate::kParamAfterRest); | 1338 MessageTemplate::kParamAfterRest); |
| 1341 *ok = false; | 1339 *ok = false; |
| 1342 return this->EmptyExpression(); | 1340 return this->EmptyExpression(); |
| 1343 } | 1341 } |
| 1344 Expect(Token::RPAREN, CHECK_OK); | 1342 Expect(Token::RPAREN, CHECK_OK); |
| 1345 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); | 1343 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); |
| 1346 } | 1344 } |
| 1347 // Heuristically try to detect immediately called functions before | 1345 // Heuristically try to detect immediately called functions before |
| 1348 // seeing the call parentheses. | 1346 // seeing the call parentheses. |
| 1349 parenthesized_function_ = (peek() == Token::FUNCTION); | 1347 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 1350 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, | 1348 ExpressionT expr = this->ParseExpression(true, classifier, CHECK_OK); |
| 1351 classifier, CHECK_OK); | |
| 1352 Expect(Token::RPAREN, CHECK_OK); | 1349 Expect(Token::RPAREN, CHECK_OK); |
| 1353 return expr; | 1350 return expr; |
| 1354 } | 1351 } |
| 1355 | 1352 |
| 1356 case Token::CLASS: { | 1353 case Token::CLASS: { |
| 1357 BindingPatternUnexpectedToken(classifier); | 1354 BindingPatternUnexpectedToken(classifier); |
| 1358 Consume(Token::CLASS); | 1355 Consume(Token::CLASS); |
| 1359 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 1356 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| 1360 ReportMessage(MessageTemplate::kSloppyLexical); | 1357 ReportMessage(MessageTemplate::kSloppyLexical); |
| 1361 *ok = false; | 1358 *ok = false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 ExpressionClassifier classifier; | 1408 ExpressionClassifier classifier; |
| 1412 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); | 1409 ExpressionT result = ParseExpression(accept_IN, &classifier, CHECK_OK); |
| 1413 result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK); | 1410 result = Traits::RewriteNonPattern(result, &classifier, CHECK_OK); |
| 1414 return result; | 1411 return result; |
| 1415 } | 1412 } |
| 1416 | 1413 |
| 1417 | 1414 |
| 1418 template <class Traits> | 1415 template <class Traits> |
| 1419 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | 1416 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( |
| 1420 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { | 1417 bool accept_IN, ExpressionClassifier* classifier, bool* ok) { |
| 1421 return ParseExpression(accept_IN, kIsNormalAssignment, classifier, ok); | |
| 1422 } | |
| 1423 | |
| 1424 | |
| 1425 template <class Traits> | |
| 1426 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseExpression( | |
| 1427 bool accept_IN, int flags, ExpressionClassifier* classifier, bool* ok) { | |
| 1428 // Expression :: | 1418 // Expression :: |
| 1429 // AssignmentExpression | 1419 // AssignmentExpression |
| 1430 // Expression ',' AssignmentExpression | 1420 // Expression ',' AssignmentExpression |
| 1431 | 1421 |
| 1432 ExpressionClassifier binding_classifier; | 1422 ExpressionClassifier binding_classifier; |
| 1433 ExpressionT result = this->ParseAssignmentExpression( | 1423 ExpressionT result = |
| 1434 accept_IN, flags, &binding_classifier, CHECK_OK); | 1424 this->ParseAssignmentExpression(accept_IN, &binding_classifier, CHECK_OK); |
| 1435 classifier->Accumulate(binding_classifier, | 1425 classifier->Accumulate(binding_classifier, |
| 1436 ExpressionClassifier::AllProductions); | 1426 ExpressionClassifier::AllProductions); |
| 1437 bool is_simple_parameter_list = this->IsIdentifier(result); | 1427 bool is_simple_parameter_list = this->IsIdentifier(result); |
| 1438 bool seen_rest = false; | 1428 bool seen_rest = false; |
| 1439 while (peek() == Token::COMMA) { | 1429 while (peek() == Token::COMMA) { |
| 1440 if (seen_rest) { | 1430 if (seen_rest) { |
| 1441 // At this point the production can't possibly be valid, but we don't know | 1431 // At this point the production can't possibly be valid, but we don't know |
| 1442 // which error to signal. | 1432 // which error to signal. |
| 1443 classifier->RecordArrowFormalParametersError( | 1433 classifier->RecordArrowFormalParametersError( |
| 1444 scanner()->peek_location(), MessageTemplate::kParamAfterRest); | 1434 scanner()->peek_location(), MessageTemplate::kParamAfterRest); |
| 1445 } | 1435 } |
| 1446 Consume(Token::COMMA); | 1436 Consume(Token::COMMA); |
| 1447 bool is_rest = false; | 1437 bool is_rest = false; |
| 1448 if (peek() == Token::ELLIPSIS) { | 1438 if (peek() == Token::ELLIPSIS) { |
| 1449 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only | 1439 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only |
| 1450 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a | 1440 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a |
| 1451 // valid expression or binding pattern. | 1441 // valid expression or binding pattern. |
| 1452 ExpressionUnexpectedToken(classifier); | 1442 ExpressionUnexpectedToken(classifier); |
| 1453 BindingPatternUnexpectedToken(classifier); | 1443 BindingPatternUnexpectedToken(classifier); |
| 1454 Consume(Token::ELLIPSIS); | 1444 Consume(Token::ELLIPSIS); |
| 1455 seen_rest = is_rest = true; | 1445 seen_rest = is_rest = true; |
| 1456 } | 1446 } |
| 1457 int pos = position(), expr_pos = peek_position(); | 1447 int pos = position(), expr_pos = peek_position(); |
| 1458 ExpressionT right = this->ParseAssignmentExpression( | 1448 ExpressionT right = this->ParseAssignmentExpression( |
| 1459 accept_IN, flags, &binding_classifier, CHECK_OK); | 1449 accept_IN, &binding_classifier, CHECK_OK); |
| 1460 if (is_rest) { | 1450 if (is_rest) { |
| 1461 if (!this->IsIdentifier(right) && !right->IsObjectLiteral() && | 1451 if (!this->IsIdentifier(right) && !right->IsObjectLiteral() && |
| 1462 !right->IsArrayLiteral()) { | 1452 !right->IsArrayLiteral()) { |
| 1463 classifier->RecordArrowFormalParametersError( | 1453 classifier->RecordArrowFormalParametersError( |
| 1464 Scanner::Location(pos, scanner()->location().end_pos), | 1454 Scanner::Location(pos, scanner()->location().end_pos), |
| 1465 MessageTemplate::kInvalidRestParameter); | 1455 MessageTemplate::kInvalidRestParameter); |
| 1466 } | 1456 } |
| 1467 right = factory()->NewSpread(right, pos, expr_pos); | 1457 right = factory()->NewSpread(right, pos, expr_pos); |
| 1468 } | 1458 } |
| 1469 is_simple_parameter_list = | 1459 is_simple_parameter_list = |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 // the parser and preparser | 1918 // the parser and preparser |
| 1929 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); | 1919 Traits::MaterializeUnspreadArgumentsLiterals(unspread_sequences_count); |
| 1930 } | 1920 } |
| 1931 | 1921 |
| 1932 return result; | 1922 return result; |
| 1933 } | 1923 } |
| 1934 | 1924 |
| 1935 // Precedence = 2 | 1925 // Precedence = 2 |
| 1936 template <class Traits> | 1926 template <class Traits> |
| 1937 typename ParserBase<Traits>::ExpressionT | 1927 typename ParserBase<Traits>::ExpressionT |
| 1938 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, | 1928 ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| 1929 AssignmentExpressionFlags flags, |
| 1939 ExpressionClassifier* classifier, | 1930 ExpressionClassifier* classifier, |
| 1940 bool* ok) { | 1931 bool* ok) { |
| 1941 // AssignmentExpression :: | 1932 // AssignmentExpression :: |
| 1942 // ConditionalExpression | 1933 // ConditionalExpression |
| 1943 // ArrowFunction | 1934 // ArrowFunction |
| 1944 // YieldExpression | 1935 // YieldExpression |
| 1945 // LeftHandSideExpression AssignmentOperator AssignmentExpression | 1936 // LeftHandSideExpression AssignmentOperator AssignmentExpression |
| 1946 bool maybe_pattern_element = flags & kIsPossiblePatternElement; | 1937 bool maybe_pattern_element = flags == kIsPossiblePatternElement; |
| 1947 bool maybe_arrow_formals = flags & kIsPossibleArrowFormals; | |
| 1948 bool is_destructuring_assignment = false; | 1938 bool is_destructuring_assignment = false; |
| 1949 int lhs_beg_pos = peek_position(); | 1939 int lhs_beg_pos = peek_position(); |
| 1950 | 1940 |
| 1951 if (peek() == Token::YIELD && is_generator()) { | 1941 if (peek() == Token::YIELD && is_generator()) { |
| 1952 return this->ParseYieldExpression(classifier, ok); | 1942 return this->ParseYieldExpression(classifier, ok); |
| 1953 } | 1943 } |
| 1954 | 1944 |
| 1955 FuncNameInferrer::State fni_state(fni_); | 1945 FuncNameInferrer::State fni_state(fni_); |
| 1956 ParserBase<Traits>::Checkpoint checkpoint(this); | 1946 ParserBase<Traits>::Checkpoint checkpoint(this); |
| 1957 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 1947 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 if (!(allow_harmony_destructuring_bind() || | 2015 if (!(allow_harmony_destructuring_bind() || |
| 2026 allow_harmony_default_parameters())) { | 2016 allow_harmony_default_parameters())) { |
| 2027 BindingPatternUnexpectedToken(classifier); | 2017 BindingPatternUnexpectedToken(classifier); |
| 2028 } | 2018 } |
| 2029 | 2019 |
| 2030 if (allow_harmony_destructuring_assignment() && maybe_pattern && | 2020 if (allow_harmony_destructuring_assignment() && maybe_pattern && |
| 2031 peek() == Token::ASSIGN) { | 2021 peek() == Token::ASSIGN) { |
| 2032 classifier->ForgiveCoverInitializedNameError(); | 2022 classifier->ForgiveCoverInitializedNameError(); |
| 2033 ValidateAssignmentPattern(classifier, CHECK_OK); | 2023 ValidateAssignmentPattern(classifier, CHECK_OK); |
| 2034 is_destructuring_assignment = true; | 2024 is_destructuring_assignment = true; |
| 2035 } else if (maybe_arrow_formals) { | 2025 } else if (allow_harmony_default_parameters() && |
| 2026 !allow_harmony_destructuring_assignment()) { |
| 2027 // TODO(adamk): This branch should be removed once the destructuring |
| 2028 // assignment and default parameter flags are removed. |
| 2036 expression = this->ClassifyAndRewriteReferenceExpression( | 2029 expression = this->ClassifyAndRewriteReferenceExpression( |
| 2037 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, | 2030 classifier, expression, lhs_beg_pos, scanner()->location().end_pos, |
| 2038 MessageTemplate::kInvalidLhsInAssignment); | 2031 MessageTemplate::kInvalidLhsInAssignment); |
| 2039 } else { | 2032 } else { |
| 2040 if (maybe_pattern_element) { | 2033 if (maybe_pattern_element) { |
| 2041 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | 2034 CheckDestructuringElement(expression, classifier, lhs_beg_pos, |
| 2042 scanner()->location().end_pos); | 2035 scanner()->location().end_pos); |
| 2043 } | 2036 } |
| 2044 expression = this->CheckAndRewriteReferenceExpression( | 2037 expression = this->CheckAndRewriteReferenceExpression( |
| 2045 expression, lhs_beg_pos, scanner()->location().end_pos, | 2038 expression, lhs_beg_pos, scanner()->location().end_pos, |
| (...skipping 1309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3355 return; | 3348 return; |
| 3356 } | 3349 } |
| 3357 has_seen_constructor_ = true; | 3350 has_seen_constructor_ = true; |
| 3358 return; | 3351 return; |
| 3359 } | 3352 } |
| 3360 } | 3353 } |
| 3361 } // namespace internal | 3354 } // namespace internal |
| 3362 } // namespace v8 | 3355 } // namespace v8 |
| 3363 | 3356 |
| 3364 #endif // V8_PARSING_PARSER_BASE_H | 3357 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |