Chromium Code Reviews| 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 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 return factory()->NewEmptyParentheses(beg_pos); | 1322 return factory()->NewEmptyParentheses(beg_pos); |
| 1323 } else if (Check(Token::ELLIPSIS)) { | 1323 } else if (Check(Token::ELLIPSIS)) { |
| 1324 // (...x)=>x. The continuation that looks for the => is in | 1324 // (...x)=>x. The continuation that looks for the => is in |
| 1325 // ParseAssignmentExpression. | 1325 // ParseAssignmentExpression. |
| 1326 int ellipsis_pos = position(); | 1326 int ellipsis_pos = position(); |
| 1327 int expr_pos = peek_position(); | 1327 int expr_pos = peek_position(); |
| 1328 classifier->RecordExpressionError(scanner()->location(), | 1328 classifier->RecordExpressionError(scanner()->location(), |
| 1329 MessageTemplate::kUnexpectedToken, | 1329 MessageTemplate::kUnexpectedToken, |
| 1330 Token::String(Token::ELLIPSIS)); | 1330 Token::String(Token::ELLIPSIS)); |
| 1331 classifier->RecordNonSimpleParameter(); | 1331 classifier->RecordNonSimpleParameter(); |
| 1332 ExpressionT expr = | 1332 ExpressionT expr = this->ParseAssignmentExpression( |
| 1333 this->ParseAssignmentExpression(true, classifier, CHECK_OK); | 1333 true, kIsPossibleArrowFormals, classifier, CHECK_OK); |
| 1334 if (!this->IsIdentifier(expr) && !expr->IsObjectLiteral() && | |
| 1335 !expr->IsArrayLiteral()) { | |
| 1336 classifier->RecordArrowFormalParametersError( | |
| 1337 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), | |
| 1338 MessageTemplate::kInvalidRestParameter); | |
| 1339 } | |
| 1334 if (peek() == Token::COMMA) { | 1340 if (peek() == Token::COMMA) { |
| 1335 ReportMessageAt(scanner()->peek_location(), | 1341 ReportMessageAt(scanner()->peek_location(), |
| 1336 MessageTemplate::kParamAfterRest); | 1342 MessageTemplate::kParamAfterRest); |
| 1337 *ok = false; | 1343 *ok = false; |
| 1338 return this->EmptyExpression(); | 1344 return this->EmptyExpression(); |
| 1339 } | 1345 } |
| 1340 Expect(Token::RPAREN, CHECK_OK); | 1346 Expect(Token::RPAREN, CHECK_OK); |
| 1341 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); | 1347 return factory()->NewSpread(expr, ellipsis_pos, expr_pos); |
| 1342 } | 1348 } |
| 1343 // Heuristically try to detect immediately called functions before | 1349 // Heuristically try to detect immediately called functions before |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1439 bool seen_rest = false; | 1445 bool seen_rest = false; |
| 1440 while (peek() == Token::COMMA) { | 1446 while (peek() == Token::COMMA) { |
| 1441 if (seen_rest) { | 1447 if (seen_rest) { |
| 1442 // At this point the production can't possibly be valid, but we don't know | 1448 // At this point the production can't possibly be valid, but we don't know |
| 1443 // which error to signal. | 1449 // which error to signal. |
| 1444 classifier->RecordArrowFormalParametersError( | 1450 classifier->RecordArrowFormalParametersError( |
| 1445 scanner()->peek_location(), MessageTemplate::kParamAfterRest); | 1451 scanner()->peek_location(), MessageTemplate::kParamAfterRest); |
| 1446 } | 1452 } |
| 1447 Consume(Token::COMMA); | 1453 Consume(Token::COMMA); |
| 1448 bool is_rest = false; | 1454 bool is_rest = false; |
| 1455 int ellipsis_pos; | |
|
adamk
2016/02/01 23:15:59
I think this is a dup of "pos", below.
caitp (gmail)
2016/02/01 23:19:37
Acknowledged.
| |
| 1449 if (peek() == Token::ELLIPSIS) { | 1456 if (peek() == Token::ELLIPSIS) { |
| 1450 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only | 1457 // 'x, y, ...z' in CoverParenthesizedExpressionAndArrowParameterList only |
| 1451 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a | 1458 // as the formal parameters of'(x, y, ...z) => foo', and is not itself a |
| 1452 // valid expression or binding pattern. | 1459 // valid expression or binding pattern. |
| 1460 ellipsis_pos = peek_position(); | |
| 1453 ExpressionUnexpectedToken(classifier); | 1461 ExpressionUnexpectedToken(classifier); |
| 1454 BindingPatternUnexpectedToken(classifier); | 1462 BindingPatternUnexpectedToken(classifier); |
| 1455 Consume(Token::ELLIPSIS); | 1463 Consume(Token::ELLIPSIS); |
| 1456 seen_rest = is_rest = true; | 1464 seen_rest = is_rest = true; |
| 1457 } | 1465 } |
| 1458 int pos = position(), expr_pos = peek_position(); | 1466 int pos = position(), expr_pos = peek_position(); |
| 1459 ExpressionT right = this->ParseAssignmentExpression( | 1467 ExpressionT right = this->ParseAssignmentExpression( |
| 1460 accept_IN, flags, &binding_classifier, CHECK_OK); | 1468 accept_IN, flags, &binding_classifier, CHECK_OK); |
| 1461 if (is_rest) right = factory()->NewSpread(right, pos, expr_pos); | 1469 if (is_rest) { |
| 1470 if (!this->IsIdentifier(right) && !right->IsObjectLiteral() && | |
| 1471 !right->IsArrayLiteral()) { | |
| 1472 classifier->RecordArrowFormalParametersError( | |
| 1473 Scanner::Location(ellipsis_pos, scanner()->location().end_pos), | |
| 1474 MessageTemplate::kInvalidRestParameter); | |
| 1475 } | |
| 1476 right = factory()->NewSpread(right, pos, expr_pos); | |
| 1477 } | |
| 1462 is_simple_parameter_list = | 1478 is_simple_parameter_list = |
| 1463 is_simple_parameter_list && this->IsIdentifier(right); | 1479 is_simple_parameter_list && this->IsIdentifier(right); |
| 1464 classifier->Accumulate(binding_classifier, | 1480 classifier->Accumulate(binding_classifier, |
| 1465 ExpressionClassifier::AllProductions); | 1481 ExpressionClassifier::AllProductions); |
| 1466 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); | 1482 result = factory()->NewBinaryOperation(Token::COMMA, result, right, pos); |
| 1467 } | 1483 } |
| 1468 if (!is_simple_parameter_list || seen_rest) { | 1484 if (!is_simple_parameter_list || seen_rest) { |
| 1469 classifier->RecordNonSimpleParameter(); | 1485 classifier->RecordNonSimpleParameter(); |
| 1470 } | 1486 } |
| 1471 | 1487 |
| (...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3364 return; | 3380 return; |
| 3365 } | 3381 } |
| 3366 has_seen_constructor_ = true; | 3382 has_seen_constructor_ = true; |
| 3367 return; | 3383 return; |
| 3368 } | 3384 } |
| 3369 } | 3385 } |
| 3370 } // namespace internal | 3386 } // namespace internal |
| 3371 } // namespace v8 | 3387 } // namespace v8 |
| 3372 | 3388 |
| 3373 #endif // V8_PARSING_PARSER_BASE_H | 3389 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |