| 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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-visitor.h" | 9 #include "src/ast/ast-expression-visitor.h" |
| 10 #include "src/ast/ast-literal-reindexer.h" | 10 #include "src/ast/ast-literal-reindexer.h" |
| (...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 | 1569 |
| 1570 case Token::CLASS: | 1570 case Token::CLASS: |
| 1571 // TODO(ES6): Support parsing anonymous class declarations here. | 1571 // TODO(ES6): Support parsing anonymous class declarations here. |
| 1572 result = ParseClassDeclaration(&names, CHECK_OK); | 1572 result = ParseClassDeclaration(&names, CHECK_OK); |
| 1573 break; | 1573 break; |
| 1574 | 1574 |
| 1575 default: { | 1575 default: { |
| 1576 int pos = peek_position(); | 1576 int pos = peek_position(); |
| 1577 ExpressionClassifier classifier; | 1577 ExpressionClassifier classifier; |
| 1578 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK); | 1578 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK); |
| 1579 ValidateExpression(&classifier, CHECK_OK); | 1579 expr = ParserTraits::RewriteNonPattern(expr, &classifier, CHECK_OK); |
| 1580 | 1580 |
| 1581 ExpectSemicolon(CHECK_OK); | 1581 ExpectSemicolon(CHECK_OK); |
| 1582 result = factory()->NewExpressionStatement(expr, pos); | 1582 result = factory()->NewExpressionStatement(expr, pos); |
| 1583 break; | 1583 break; |
| 1584 } | 1584 } |
| 1585 } | 1585 } |
| 1586 | 1586 |
| 1587 const AstRawString* default_string = ast_value_factory()->default_string(); | 1587 const AstRawString* default_string = ast_value_factory()->default_string(); |
| 1588 | 1588 |
| 1589 DCHECK_LE(names.length(), 1); | 1589 DCHECK_LE(names.length(), 1); |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2388 } | 2388 } |
| 2389 | 2389 |
| 2390 Expression* value = NULL; | 2390 Expression* value = NULL; |
| 2391 // Harmony consts have non-optional initializers. | 2391 // Harmony consts have non-optional initializers. |
| 2392 int initializer_position = RelocInfo::kNoPosition; | 2392 int initializer_position = RelocInfo::kNoPosition; |
| 2393 if (Check(Token::ASSIGN)) { | 2393 if (Check(Token::ASSIGN)) { |
| 2394 ExpressionClassifier classifier; | 2394 ExpressionClassifier classifier; |
| 2395 value = ParseAssignmentExpression(var_context != kForStatement, | 2395 value = ParseAssignmentExpression(var_context != kForStatement, |
| 2396 &classifier, ok); | 2396 &classifier, ok); |
| 2397 if (!*ok) return; | 2397 if (!*ok) return; |
| 2398 ValidateExpression(&classifier, ok); | 2398 value = ParserTraits::RewriteNonPattern(value, &classifier, ok); |
| 2399 if (!*ok) return; | 2399 if (!*ok) return; |
| 2400 variable_loc.end_pos = scanner()->location().end_pos; | 2400 variable_loc.end_pos = scanner()->location().end_pos; |
| 2401 | 2401 |
| 2402 if (!parsing_result->first_initializer_loc.IsValid()) { | 2402 if (!parsing_result->first_initializer_loc.IsValid()) { |
| 2403 parsing_result->first_initializer_loc = variable_loc; | 2403 parsing_result->first_initializer_loc = variable_loc; |
| 2404 } | 2404 } |
| 2405 | 2405 |
| 2406 // Don't infer if it is "a = function(){...}();"-like expression. | 2406 // Don't infer if it is "a = function(){...}();"-like expression. |
| 2407 if (single_name) { | 2407 if (single_name) { |
| 2408 if (fni_ != NULL && value->AsCall() == NULL && | 2408 if (fni_ != NULL && value->AsCall() == NULL && |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2499 if (is_strong(language_mode()) && | 2499 if (is_strong(language_mode()) && |
| 2500 IsClassConstructor(function_state_->kind())) { | 2500 IsClassConstructor(function_state_->kind())) { |
| 2501 bool is_this = peek() == Token::THIS; | 2501 bool is_this = peek() == Token::THIS; |
| 2502 Expression* expr; | 2502 Expression* expr; |
| 2503 ExpressionClassifier classifier; | 2503 ExpressionClassifier classifier; |
| 2504 if (is_this) { | 2504 if (is_this) { |
| 2505 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); | 2505 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); |
| 2506 } else { | 2506 } else { |
| 2507 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); | 2507 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); |
| 2508 } | 2508 } |
| 2509 ValidateExpression(&classifier, CHECK_OK); | 2509 expr = ParserTraits::RewriteNonPattern(expr, &classifier, CHECK_OK); |
| 2510 switch (peek()) { | 2510 switch (peek()) { |
| 2511 case Token::SEMICOLON: | 2511 case Token::SEMICOLON: |
| 2512 Consume(Token::SEMICOLON); | 2512 Consume(Token::SEMICOLON); |
| 2513 break; | 2513 break; |
| 2514 case Token::RBRACE: | 2514 case Token::RBRACE: |
| 2515 case Token::EOS: | 2515 case Token::EOS: |
| 2516 break; | 2516 break; |
| 2517 default: | 2517 default: |
| 2518 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { | 2518 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { |
| 2519 ReportMessageAt(function_state_->this_location(), | 2519 ReportMessageAt(function_state_->this_location(), |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3720 | 3720 |
| 3721 bool is_for_each = CheckInOrOf(&mode, ok); | 3721 bool is_for_each = CheckInOrOf(&mode, ok); |
| 3722 if (!*ok) return nullptr; | 3722 if (!*ok) return nullptr; |
| 3723 bool is_destructuring = | 3723 bool is_destructuring = |
| 3724 is_for_each && allow_harmony_destructuring_assignment() && | 3724 is_for_each && allow_harmony_destructuring_assignment() && |
| 3725 (expression->IsArrayLiteral() || expression->IsObjectLiteral()); | 3725 (expression->IsArrayLiteral() || expression->IsObjectLiteral()); |
| 3726 | 3726 |
| 3727 if (is_destructuring) { | 3727 if (is_destructuring) { |
| 3728 ValidateAssignmentPattern(&classifier, CHECK_OK); | 3728 ValidateAssignmentPattern(&classifier, CHECK_OK); |
| 3729 } else { | 3729 } else { |
| 3730 ValidateExpression(&classifier, CHECK_OK); | 3730 expression = |
| 3731 ParserTraits::RewriteNonPattern(expression, &classifier, CHECK_OK); |
| 3731 } | 3732 } |
| 3732 | 3733 |
| 3733 if (is_for_each) { | 3734 if (is_for_each) { |
| 3734 if (!is_destructuring) { | 3735 if (!is_destructuring) { |
| 3735 expression = this->CheckAndRewriteReferenceExpression( | 3736 expression = this->CheckAndRewriteReferenceExpression( |
| 3736 expression, lhs_beg_pos, lhs_end_pos, | 3737 expression, lhs_beg_pos, lhs_end_pos, |
| 3737 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); | 3738 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); |
| 3738 } | 3739 } |
| 3739 | 3740 |
| 3740 ForEachStatement* loop = | 3741 ForEachStatement* loop = |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4769 FuncNameInferrer::State fni_state(fni_); | 4770 FuncNameInferrer::State fni_state(fni_); |
| 4770 const bool in_class = true; | 4771 const bool in_class = true; |
| 4771 const bool is_static = false; | 4772 const bool is_static = false; |
| 4772 bool is_computed_name = false; // Classes do not care about computed | 4773 bool is_computed_name = false; // Classes do not care about computed |
| 4773 // property names here. | 4774 // property names here. |
| 4774 ExpressionClassifier classifier; | 4775 ExpressionClassifier classifier; |
| 4775 const AstRawString* name = nullptr; | 4776 const AstRawString* name = nullptr; |
| 4776 ObjectLiteral::Property* property = ParsePropertyDefinition( | 4777 ObjectLiteral::Property* property = ParsePropertyDefinition( |
| 4777 &checker, in_class, has_extends, is_static, &is_computed_name, | 4778 &checker, in_class, has_extends, is_static, &is_computed_name, |
| 4778 &has_seen_constructor, &classifier, &name, CHECK_OK); | 4779 &has_seen_constructor, &classifier, &name, CHECK_OK); |
| 4779 property = ParserTraits::RewriteObjectLiteralProperty(property, &classifier, | 4780 property = ParserTraits::RewriteNonPatternObjectLiteralProperty( |
| 4780 CHECK_OK); | 4781 property, &classifier, CHECK_OK); |
| 4781 | 4782 |
| 4782 if (has_seen_constructor && constructor == NULL) { | 4783 if (has_seen_constructor && constructor == NULL) { |
| 4783 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4784 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
| 4784 DCHECK_NOT_NULL(constructor); | 4785 DCHECK_NOT_NULL(constructor); |
| 4785 } else { | 4786 } else { |
| 4786 properties->Add(property, zone()); | 4787 properties->Add(property, zone()); |
| 4787 } | 4788 } |
| 4788 | 4789 |
| 4789 if (fni_ != NULL) fni_->Infer(); | 4790 if (fni_ != NULL) fni_->Infer(); |
| 4790 | 4791 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4821 | 4822 |
| 4822 int pos = peek_position(); | 4823 int pos = peek_position(); |
| 4823 Expect(Token::MOD, CHECK_OK); | 4824 Expect(Token::MOD, CHECK_OK); |
| 4824 // Allow "eval" or "arguments" for backward compatibility. | 4825 // Allow "eval" or "arguments" for backward compatibility. |
| 4825 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers, | 4826 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers, |
| 4826 CHECK_OK); | 4827 CHECK_OK); |
| 4827 Scanner::Location spread_pos; | 4828 Scanner::Location spread_pos; |
| 4828 ExpressionClassifier classifier; | 4829 ExpressionClassifier classifier; |
| 4829 ZoneList<Expression*>* args = | 4830 ZoneList<Expression*>* args = |
| 4830 ParseArguments(&spread_pos, &classifier, CHECK_OK); | 4831 ParseArguments(&spread_pos, &classifier, CHECK_OK); |
| 4831 ValidateExpression(&classifier, CHECK_OK); | 4832 args = RewriteNonPatternArguments(args, &classifier, CHECK_OK); |
| 4832 | 4833 |
| 4833 DCHECK(!spread_pos.IsValid()); | 4834 DCHECK(!spread_pos.IsValid()); |
| 4834 | 4835 |
| 4835 if (extension_ != NULL) { | 4836 if (extension_ != NULL) { |
| 4836 // The extension structures are only accessible while parsing the | 4837 // The extension structures are only accessible while parsing the |
| 4837 // very first time not when reparsing because of lazy compilation. | 4838 // very first time not when reparsing because of lazy compilation. |
| 4838 scope_->DeclarationScope()->ForceEagerCompilation(); | 4839 scope_->DeclarationScope()->ForceEagerCompilation(); |
| 4839 } | 4840 } |
| 4840 | 4841 |
| 4841 const Runtime::Function* function = Runtime::FunctionForName(name->string()); | 4842 const Runtime::Function* function = Runtime::FunctionForName(name->string()); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5391 parser_->RewriteDestructuringAssignments(); | 5392 parser_->RewriteDestructuringAssignments(); |
| 5392 } | 5393 } |
| 5393 | 5394 |
| 5394 | 5395 |
| 5395 Expression* ParserTraits::RewriteNonPattern( | 5396 Expression* ParserTraits::RewriteNonPattern( |
| 5396 Expression* expr, const ExpressionClassifier* classifier, bool* ok) { | 5397 Expression* expr, const ExpressionClassifier* classifier, bool* ok) { |
| 5397 return parser_->RewriteNonPattern(expr, classifier, ok); | 5398 return parser_->RewriteNonPattern(expr, classifier, ok); |
| 5398 } | 5399 } |
| 5399 | 5400 |
| 5400 | 5401 |
| 5401 ObjectLiteralProperty* ParserTraits::RewriteObjectLiteralProperty( | 5402 ZoneList<Expression*>* ParserTraits::RewriteNonPatternArguments( |
| 5402 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, | 5403 ZoneList<Expression*>* args, const ExpressionClassifier* classifier, |
| 5403 bool* ok) { | 5404 bool* ok) { |
| 5404 return parser_->RewriteObjectLiteralProperty(property, classifier, ok); | 5405 return parser_->RewriteNonPatternArguments(args, classifier, ok); |
| 5405 } | 5406 } |
| 5406 | 5407 |
| 5407 | 5408 |
| 5409 ObjectLiteralProperty* ParserTraits::RewriteNonPatternObjectLiteralProperty( |
| 5410 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, |
| 5411 bool* ok) { |
| 5412 return parser_->RewriteNonPatternObjectLiteralProperty(property, classifier, |
| 5413 ok); |
| 5414 } |
| 5415 |
| 5416 |
| 5408 Expression* Parser::RewriteNonPattern(Expression* expr, | 5417 Expression* Parser::RewriteNonPattern(Expression* expr, |
| 5409 const ExpressionClassifier* classifier, | 5418 const ExpressionClassifier* classifier, |
| 5410 bool* ok) { | 5419 bool* ok) { |
| 5411 // For the time being, this does no rewriting at all. | 5420 // For the time being, this does no rewriting at all. |
| 5412 ValidateExpression(classifier, ok); | 5421 ValidateExpression(classifier, ok); |
| 5413 return expr; | 5422 return expr; |
| 5414 } | 5423 } |
| 5415 | 5424 |
| 5416 | 5425 |
| 5417 ObjectLiteralProperty* Parser::RewriteObjectLiteralProperty( | 5426 ZoneList<Expression*>* Parser::RewriteNonPatternArguments( |
| 5427 ZoneList<Expression*>* args, const ExpressionClassifier* classifier, |
| 5428 bool* ok) { |
| 5429 // For the time being, this does no rewriting at all. |
| 5430 ValidateExpression(classifier, ok); |
| 5431 return args; |
| 5432 } |
| 5433 |
| 5434 |
| 5435 ObjectLiteralProperty* Parser::RewriteNonPatternObjectLiteralProperty( |
| 5418 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, | 5436 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, |
| 5419 bool* ok) { | 5437 bool* ok) { |
| 5420 if (property != nullptr) { | 5438 if (property != nullptr) { |
| 5421 Expression* key = RewriteNonPattern(property->key(), classifier, ok); | 5439 Expression* key = RewriteNonPattern(property->key(), classifier, ok); |
| 5422 property->set_key(key); | 5440 property->set_key(key); |
| 5423 Expression* value = RewriteNonPattern(property->value(), classifier, ok); | 5441 Expression* value = RewriteNonPattern(property->value(), classifier, ok); |
| 5424 property->set_value(value); | 5442 property->set_value(value); |
| 5425 } | 5443 } |
| 5426 return property; | 5444 return property; |
| 5427 } | 5445 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5487 auto class_literal = value->AsClassLiteral(); | 5505 auto class_literal = value->AsClassLiteral(); |
| 5488 if (class_literal->raw_name() == nullptr) { | 5506 if (class_literal->raw_name() == nullptr) { |
| 5489 class_literal->set_raw_name(name); | 5507 class_literal->set_raw_name(name); |
| 5490 } | 5508 } |
| 5491 } | 5509 } |
| 5492 } | 5510 } |
| 5493 | 5511 |
| 5494 | 5512 |
| 5495 } // namespace internal | 5513 } // namespace internal |
| 5496 } // namespace v8 | 5514 } // namespace v8 |
| OLD | NEW |