| 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 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 | 1305 |
| 1306 case Token::LPAREN: { | 1306 case Token::LPAREN: { |
| 1307 // Arrow function formal parameters are either a single identifier or a | 1307 // Arrow function formal parameters are either a single identifier or a |
| 1308 // list of BindingPattern productions enclosed in parentheses. | 1308 // list of BindingPattern productions enclosed in parentheses. |
| 1309 // Parentheses are not valid on the LHS of a BindingPattern, so we use the | 1309 // Parentheses are not valid on the LHS of a BindingPattern, so we use the |
| 1310 // is_valid_binding_pattern() check to detect multiple levels of | 1310 // is_valid_binding_pattern() check to detect multiple levels of |
| 1311 // parenthesization. | 1311 // parenthesization. |
| 1312 if (!classifier->is_valid_binding_pattern()) { | 1312 if (!classifier->is_valid_binding_pattern()) { |
| 1313 ArrowFormalParametersUnexpectedToken(classifier); | 1313 ArrowFormalParametersUnexpectedToken(classifier); |
| 1314 } | 1314 } |
| 1315 BindingPatternUnexpectedToken(classifier); | 1315 classifier->RecordPatternError(scanner()->peek_location(), |
| 1316 MessageTemplate::kUnexpectedToken, |
| 1317 Token::String(Token::LPAREN)); |
| 1316 Consume(Token::LPAREN); | 1318 Consume(Token::LPAREN); |
| 1317 if (Check(Token::RPAREN)) { | 1319 if (Check(Token::RPAREN)) { |
| 1318 // ()=>x. The continuation that looks for the => is in | 1320 // ()=>x. The continuation that looks for the => is in |
| 1319 // ParseAssignmentExpression. | 1321 // ParseAssignmentExpression. |
| 1320 classifier->RecordExpressionError(scanner()->location(), | 1322 classifier->RecordExpressionError(scanner()->location(), |
| 1321 MessageTemplate::kUnexpectedToken, | 1323 MessageTemplate::kUnexpectedToken, |
| 1322 Token::String(Token::RPAREN)); | 1324 Token::String(Token::RPAREN)); |
| 1323 classifier->RecordBindingPatternError(scanner()->location(), | 1325 classifier->RecordBindingPatternError(scanner()->location(), |
| 1324 MessageTemplate::kUnexpectedToken, | 1326 MessageTemplate::kUnexpectedToken, |
| 1325 Token::String(Token::RPAREN)); | 1327 Token::String(Token::RPAREN)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1349 } | 1351 } |
| 1350 Expect(Token::RPAREN, CHECK_OK); | 1352 Expect(Token::RPAREN, CHECK_OK); |
| 1351 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); | 1353 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); |
| 1352 } | 1354 } |
| 1353 // Heuristically try to detect immediately called functions before | 1355 // Heuristically try to detect immediately called functions before |
| 1354 // seeing the call parentheses. | 1356 // seeing the call parentheses. |
| 1355 parenthesized_function_ = (peek() == Token::FUNCTION); | 1357 parenthesized_function_ = (peek() == Token::FUNCTION); |
| 1356 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, | 1358 ExpressionT expr = this->ParseExpression(true, kIsPossibleArrowFormals, |
| 1357 classifier, CHECK_OK); | 1359 classifier, CHECK_OK); |
| 1358 Expect(Token::RPAREN, CHECK_OK); | 1360 Expect(Token::RPAREN, CHECK_OK); |
| 1359 if (peek() != Token::ARROW) { | |
| 1360 expr->set_is_parenthesized(); | |
| 1361 } | |
| 1362 return expr; | 1361 return expr; |
| 1363 } | 1362 } |
| 1364 | 1363 |
| 1365 case Token::CLASS: { | 1364 case Token::CLASS: { |
| 1366 BindingPatternUnexpectedToken(classifier); | 1365 BindingPatternUnexpectedToken(classifier); |
| 1367 Consume(Token::CLASS); | 1366 Consume(Token::CLASS); |
| 1368 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { | 1367 if (!allow_harmony_sloppy() && is_sloppy(language_mode())) { |
| 1369 ReportMessage(MessageTemplate::kSloppyLexical); | 1368 ReportMessage(MessageTemplate::kSloppyLexical); |
| 1370 *ok = false; | 1369 *ok = false; |
| 1371 return this->EmptyExpression(); | 1370 return this->EmptyExpression(); |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2018 | 2017 |
| 2019 // "expression" was not itself an arrow function parameter list, but it might | 2018 // "expression" was not itself an arrow function parameter list, but it might |
| 2020 // form part of one. Propagate speculative formal parameter error locations. | 2019 // form part of one. Propagate speculative formal parameter error locations. |
| 2021 classifier->Accumulate( | 2020 classifier->Accumulate( |
| 2022 arrow_formals_classifier, | 2021 arrow_formals_classifier, |
| 2023 ExpressionClassifier::StandardProductions | | 2022 ExpressionClassifier::StandardProductions | |
| 2024 ExpressionClassifier::FormalParametersProductions | | 2023 ExpressionClassifier::FormalParametersProductions | |
| 2025 ExpressionClassifier::CoverInitializedNameProduction); | 2024 ExpressionClassifier::CoverInitializedNameProduction); |
| 2026 | 2025 |
| 2027 bool maybe_pattern = | 2026 bool maybe_pattern = |
| 2028 (expression->IsObjectLiteral() || expression->IsArrayLiteral()) && | 2027 expression->IsObjectLiteral() || expression->IsArrayLiteral(); |
| 2029 !expression->is_parenthesized(); | |
| 2030 | 2028 |
| 2031 if (!Token::IsAssignmentOp(peek())) { | 2029 if (!Token::IsAssignmentOp(peek())) { |
| 2032 // Parsed conditional expression only (no assignment). | 2030 // Parsed conditional expression only (no assignment). |
| 2033 if (maybe_pattern_element) { | 2031 if (maybe_pattern_element) { |
| 2034 CheckDestructuringElement(expression, classifier, lhs_beg_pos, | 2032 CheckDestructuringElement(expression, classifier, lhs_beg_pos, |
| 2035 scanner()->location().end_pos); | 2033 scanner()->location().end_pos); |
| 2036 } | 2034 } |
| 2037 return expression; | 2035 return expression; |
| 2038 } | 2036 } |
| 2039 | 2037 |
| (...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3307 | 3305 |
| 3308 template <typename Traits> | 3306 template <typename Traits> |
| 3309 void ParserBase<Traits>::CheckDestructuringElement( | 3307 void ParserBase<Traits>::CheckDestructuringElement( |
| 3310 ExpressionT expression, ExpressionClassifier* classifier, int begin, | 3308 ExpressionT expression, ExpressionClassifier* classifier, int begin, |
| 3311 int end) { | 3309 int end) { |
| 3312 static const MessageTemplate::Template message = | 3310 static const MessageTemplate::Template message = |
| 3313 MessageTemplate::kInvalidDestructuringTarget; | 3311 MessageTemplate::kInvalidDestructuringTarget; |
| 3314 const Scanner::Location location(begin, end); | 3312 const Scanner::Location location(begin, end); |
| 3315 if (expression->IsArrayLiteral() || expression->IsObjectLiteral() || | 3313 if (expression->IsArrayLiteral() || expression->IsObjectLiteral() || |
| 3316 expression->IsAssignment()) { | 3314 expression->IsAssignment()) { |
| 3317 if (expression->is_parenthesized()) { | |
| 3318 classifier->RecordPatternError(location, message); | |
| 3319 } | |
| 3320 return; | 3315 return; |
| 3321 } | 3316 } |
| 3322 | 3317 |
| 3323 if (expression->IsProperty()) { | 3318 if (expression->IsProperty()) { |
| 3324 classifier->RecordBindingPatternError(location, message); | 3319 classifier->RecordBindingPatternError(location, message); |
| 3325 } else if (!this->IsAssignableIdentifier(expression)) { | 3320 } else if (!this->IsAssignableIdentifier(expression)) { |
| 3326 classifier->RecordPatternError(location, message); | 3321 classifier->RecordPatternError(location, message); |
| 3327 } | 3322 } |
| 3328 } | 3323 } |
| 3329 | 3324 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3382 return; | 3377 return; |
| 3383 } | 3378 } |
| 3384 has_seen_constructor_ = true; | 3379 has_seen_constructor_ = true; |
| 3385 return; | 3380 return; |
| 3386 } | 3381 } |
| 3387 } | 3382 } |
| 3388 } // namespace internal | 3383 } // namespace internal |
| 3389 } // namespace v8 | 3384 } // namespace v8 |
| 3390 | 3385 |
| 3391 #endif // V8_PARSING_PARSER_BASE_H | 3386 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |