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 4888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4899 scope_->class_declaration_group_start()); | 4899 scope_->class_declaration_group_start()); |
4900 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 4900 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
4901 } | 4901 } |
4902 | 4902 |
4903 Expression* extends = NULL; | 4903 Expression* extends = NULL; |
4904 if (Check(Token::EXTENDS)) { | 4904 if (Check(Token::EXTENDS)) { |
4905 block_scope->set_start_position(scanner()->location().end_pos); | 4905 block_scope->set_start_position(scanner()->location().end_pos); |
4906 ExpressionClassifier classifier; | 4906 ExpressionClassifier classifier; |
4907 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); | 4907 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); |
4908 ValidateExpression(&classifier, CHECK_OK); | 4908 ValidateExpression(&classifier, CHECK_OK); |
| 4909 extends = ParserTraits::RewriteExpression(extends); |
4909 } else { | 4910 } else { |
4910 block_scope->set_start_position(scanner()->location().end_pos); | 4911 block_scope->set_start_position(scanner()->location().end_pos); |
4911 } | 4912 } |
4912 | 4913 |
4913 | 4914 |
4914 ClassLiteralChecker checker(this); | 4915 ClassLiteralChecker checker(this); |
4915 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); | 4916 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); |
4916 FunctionLiteral* constructor = NULL; | 4917 FunctionLiteral* constructor = NULL; |
4917 bool has_seen_constructor = false; | 4918 bool has_seen_constructor = false; |
4918 | 4919 |
4919 Expect(Token::LBRACE, CHECK_OK); | 4920 Expect(Token::LBRACE, CHECK_OK); |
4920 | 4921 |
4921 const bool has_extends = extends != nullptr; | 4922 const bool has_extends = extends != nullptr; |
4922 while (peek() != Token::RBRACE) { | 4923 while (peek() != Token::RBRACE) { |
4923 if (Check(Token::SEMICOLON)) continue; | 4924 if (Check(Token::SEMICOLON)) continue; |
4924 FuncNameInferrer::State fni_state(fni_); | 4925 FuncNameInferrer::State fni_state(fni_); |
4925 const bool in_class = true; | 4926 const bool in_class = true; |
4926 const bool is_static = false; | 4927 const bool is_static = false; |
4927 bool is_computed_name = false; // Classes do not care about computed | 4928 bool is_computed_name = false; // Classes do not care about computed |
4928 // property names here. | 4929 // property names here. |
4929 ExpressionClassifier classifier; | 4930 ExpressionClassifier classifier; |
4930 const AstRawString* name = nullptr; | 4931 const AstRawString* name = nullptr; |
4931 ObjectLiteral::Property* property = ParsePropertyDefinition( | 4932 ObjectLiteral::Property* property = ParsePropertyDefinition( |
4932 &checker, in_class, has_extends, is_static, &is_computed_name, | 4933 &checker, in_class, has_extends, is_static, &is_computed_name, |
4933 &has_seen_constructor, &classifier, &name, CHECK_OK); | 4934 &has_seen_constructor, &classifier, &name, CHECK_OK); |
4934 ValidateExpression(&classifier, CHECK_OK); | 4935 ValidateExpression(&classifier, CHECK_OK); |
| 4936 property = ParserTraits::RewriteObjectLiteralProperty(property); |
4935 | 4937 |
4936 if (has_seen_constructor && constructor == NULL) { | 4938 if (has_seen_constructor && constructor == NULL) { |
4937 constructor = GetPropertyValue(property)->AsFunctionLiteral(); | 4939 constructor = GetPropertyValue(property)->AsFunctionLiteral(); |
4938 DCHECK_NOT_NULL(constructor); | 4940 DCHECK_NOT_NULL(constructor); |
4939 } else { | 4941 } else { |
4940 properties->Add(property, zone()); | 4942 properties->Add(property, zone()); |
4941 } | 4943 } |
4942 | 4944 |
4943 if (fni_ != NULL) fni_->Infer(); | 4945 if (fni_ != NULL) fni_->Infer(); |
4944 | 4946 |
(...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6493 SetLanguageMode(scope_, | 6495 SetLanguageMode(scope_, |
6494 static_cast<LanguageMode>(scope_->language_mode() | mode)); | 6496 static_cast<LanguageMode>(scope_->language_mode() | mode)); |
6495 } | 6497 } |
6496 | 6498 |
6497 | 6499 |
6498 void ParserTraits::RewriteDestructuringAssignments() { | 6500 void ParserTraits::RewriteDestructuringAssignments() { |
6499 parser_->RewriteDestructuringAssignments(); | 6501 parser_->RewriteDestructuringAssignments(); |
6500 } | 6502 } |
6501 | 6503 |
6502 | 6504 |
| 6505 Expression* ParserTraits::RewriteExpression(Expression* expr) { |
| 6506 return parser_->RewriteExpression(expr); |
| 6507 } |
| 6508 |
| 6509 |
| 6510 ObjectLiteralProperty* ParserTraits::RewriteObjectLiteralProperty( |
| 6511 ObjectLiteralProperty* property) { |
| 6512 return parser_->RewriteObjectLiteralProperty(property); |
| 6513 } |
| 6514 |
| 6515 |
| 6516 Expression* Parser::RewriteExpression(Expression* expr) { |
| 6517 // TODO(nikolaos): For the time being, this does no rewriting at all. |
| 6518 return expr; |
| 6519 } |
| 6520 |
| 6521 |
| 6522 ObjectLiteralProperty* Parser::RewriteObjectLiteralProperty( |
| 6523 ObjectLiteralProperty* property) { |
| 6524 if (property != nullptr) { |
| 6525 Expression* key = RewriteExpression(property->key()); |
| 6526 property->set_key(key); |
| 6527 Expression* value = RewriteExpression(property->value()); |
| 6528 property->set_value(value); |
| 6529 } |
| 6530 return property; |
| 6531 } |
| 6532 |
| 6533 |
6503 void Parser::RewriteDestructuringAssignments() { | 6534 void Parser::RewriteDestructuringAssignments() { |
6504 FunctionState* func = function_state_; | 6535 FunctionState* func = function_state_; |
6505 if (!allow_harmony_destructuring_assignment()) return; | 6536 if (!allow_harmony_destructuring_assignment()) return; |
6506 const List<DestructuringAssignment>& assignments = | 6537 const List<DestructuringAssignment>& assignments = |
6507 func->destructuring_assignments_to_rewrite(); | 6538 func->destructuring_assignments_to_rewrite(); |
6508 for (int i = assignments.length() - 1; i >= 0; --i) { | 6539 for (int i = assignments.length() - 1; i >= 0; --i) { |
6509 // Rewrite list in reverse, so that nested assignment patterns are rewritten | 6540 // Rewrite list in reverse, so that nested assignment patterns are rewritten |
6510 // correctly. | 6541 // correctly. |
6511 DestructuringAssignment pair = assignments.at(i); | 6542 DestructuringAssignment pair = assignments.at(i); |
6512 RewritableAssignmentExpression* to_rewrite = | 6543 RewritableAssignmentExpression* to_rewrite = |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6560 auto class_literal = value->AsClassLiteral(); | 6591 auto class_literal = value->AsClassLiteral(); |
6561 if (class_literal->raw_name() == nullptr) { | 6592 if (class_literal->raw_name() == nullptr) { |
6562 class_literal->set_raw_name(name); | 6593 class_literal->set_raw_name(name); |
6563 } | 6594 } |
6564 } | 6595 } |
6565 } | 6596 } |
6566 | 6597 |
6567 | 6598 |
6568 } // namespace internal | 6599 } // namespace internal |
6569 } // namespace v8 | 6600 } // namespace v8 |
OLD | NEW |