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-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 FunctionLiteral* ParserTraits::ParseFunctionLiteral( | 787 FunctionLiteral* ParserTraits::ParseFunctionLiteral( |
788 const AstRawString* name, Scanner::Location function_name_location, | 788 const AstRawString* name, Scanner::Location function_name_location, |
789 FunctionNameValidity function_name_validity, FunctionKind kind, | 789 FunctionNameValidity function_name_validity, FunctionKind kind, |
790 int function_token_position, FunctionLiteral::FunctionType type, | 790 int function_token_position, FunctionLiteral::FunctionType type, |
791 LanguageMode language_mode, bool* ok) { | 791 LanguageMode language_mode, bool* ok) { |
792 return parser_->ParseFunctionLiteral( | 792 return parser_->ParseFunctionLiteral( |
793 name, function_name_location, function_name_validity, kind, | 793 name, function_name_location, function_name_validity, kind, |
794 function_token_position, type, language_mode, ok); | 794 function_token_position, type, language_mode, ok); |
795 } | 795 } |
796 | 796 |
797 ClassLiteral* ParserTraits::ParseClassLiteral( | 797 Expression* ParserTraits::ParseClassLiteral( |
798 Type::ExpressionClassifier* classifier, const AstRawString* name, | 798 Type::ExpressionClassifier* classifier, const AstRawString* name, |
799 Scanner::Location class_name_location, bool name_is_strict_reserved, | 799 Scanner::Location class_name_location, bool name_is_strict_reserved, |
800 int pos, bool* ok) { | 800 int pos, bool* ok) { |
801 return parser_->ParseClassLiteral(classifier, name, class_name_location, | 801 return parser_->ParseClassLiteral(classifier, name, class_name_location, |
802 name_is_strict_reserved, pos, ok); | 802 name_is_strict_reserved, pos, ok); |
803 } | 803 } |
804 | 804 |
805 void ParserTraits::MarkTailPosition(Expression* expression) { | 805 void ParserTraits::MarkTailPosition(Expression* expression) { |
806 expression->MarkTail(); | 806 expression->MarkTail(); |
807 } | 807 } |
(...skipping 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2259 const AstRawString* variable_name; | 2259 const AstRawString* variable_name; |
2260 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) { | 2260 if (default_export && (peek() == Token::EXTENDS || peek() == Token::LBRACE)) { |
2261 name = ast_value_factory()->default_string(); | 2261 name = ast_value_factory()->default_string(); |
2262 is_strict_reserved = false; | 2262 is_strict_reserved = false; |
2263 variable_name = ast_value_factory()->star_default_star_string(); | 2263 variable_name = ast_value_factory()->star_default_star_string(); |
2264 } else { | 2264 } else { |
2265 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); | 2265 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved, CHECK_OK); |
2266 variable_name = name; | 2266 variable_name = name; |
2267 } | 2267 } |
2268 | 2268 |
2269 ClassLiteral* value = ParseClassLiteral(nullptr, name, scanner()->location(), | 2269 Expression* value = ParseClassLiteral(nullptr, name, scanner()->location(), |
2270 is_strict_reserved, pos, CHECK_OK); | 2270 is_strict_reserved, pos, CHECK_OK); |
2271 | 2271 |
2272 VariableProxy* proxy = NewUnresolved(variable_name, LET); | 2272 VariableProxy* proxy = NewUnresolved(variable_name, LET); |
2273 Declaration* declaration = | 2273 Declaration* declaration = |
2274 factory()->NewVariableDeclaration(proxy, LET, scope(), pos); | 2274 factory()->NewVariableDeclaration(proxy, LET, scope(), pos); |
2275 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 2275 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); |
2276 proxy->var()->set_initializer_position(position()); | 2276 proxy->var()->set_initializer_position(position()); |
2277 Assignment* assignment = | 2277 Assignment* assignment = |
2278 factory()->NewAssignment(Token::INIT, proxy, value, pos); | 2278 factory()->NewAssignment(Token::INIT, proxy, value, pos); |
2279 Statement* assignment_statement = | 2279 Statement* assignment_statement = |
2280 factory()->NewExpressionStatement(assignment, kNoSourcePosition); | 2280 factory()->NewExpressionStatement(assignment, kNoSourcePosition); |
(...skipping 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 param_scope->set_start_position(descriptor.initialization_pos); | 4714 param_scope->set_start_position(descriptor.initialization_pos); |
4715 param_scope->set_end_position(parameter.initializer_end_position); | 4715 param_scope->set_end_position(parameter.initializer_end_position); |
4716 param_scope->RecordEvalCall(); | 4716 param_scope->RecordEvalCall(); |
4717 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 4717 param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
4718 param_block->set_scope(param_scope); | 4718 param_block->set_scope(param_scope); |
4719 descriptor.hoist_scope = scope(); | 4719 descriptor.hoist_scope = scope(); |
4720 // Pass the appropriate scope in so that PatternRewriter can appropriately | 4720 // Pass the appropriate scope in so that PatternRewriter can appropriately |
4721 // rewrite inner initializers of the pattern to param_scope | 4721 // rewrite inner initializers of the pattern to param_scope |
4722 descriptor.scope = param_scope; | 4722 descriptor.scope = param_scope; |
4723 // Rewrite the outer initializer to point to param_scope | 4723 // Rewrite the outer initializer to point to param_scope |
4724 ReparentParameterExpressionScope(stack_limit(), initial_value, | 4724 ReparentParameterExpressionScope(stack_limit(), initial_value, scope(), |
4725 param_scope); | 4725 param_scope); |
4726 } | 4726 } |
4727 | 4727 |
4728 { | 4728 { |
4729 BlockState block_state(&scope_state_, param_scope); | 4729 BlockState block_state(&scope_state_, param_scope); |
4730 DeclarationParsingResult::Declaration decl( | 4730 DeclarationParsingResult::Declaration decl( |
4731 parameter.pattern, initializer_position, initial_value); | 4731 parameter.pattern, initializer_position, initial_value); |
4732 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, | 4732 PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor, |
4733 &decl, nullptr, CHECK_OK); | 4733 &decl, nullptr, CHECK_OK); |
4734 } | 4734 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4994 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( | 4994 PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction( |
4995 language_mode(), function_state_->kind(), | 4995 language_mode(), function_state_->kind(), |
4996 scope()->has_simple_parameters(), parsing_module_, logger, bookmark, | 4996 scope()->has_simple_parameters(), parsing_module_, logger, bookmark, |
4997 use_counts_); | 4997 use_counts_); |
4998 if (pre_parse_timer_ != NULL) { | 4998 if (pre_parse_timer_ != NULL) { |
4999 pre_parse_timer_->Stop(); | 4999 pre_parse_timer_->Stop(); |
5000 } | 5000 } |
5001 return result; | 5001 return result; |
5002 } | 5002 } |
5003 | 5003 |
5004 ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier, | 5004 Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier, |
5005 const AstRawString* name, | 5005 const AstRawString* name, |
5006 Scanner::Location class_name_location, | 5006 Scanner::Location class_name_location, |
5007 bool name_is_strict_reserved, int pos, | 5007 bool name_is_strict_reserved, int pos, |
5008 bool* ok) { | 5008 bool* ok) { |
5009 // All parts of a ClassDeclaration and ClassExpression are strict code. | 5009 // All parts of a ClassDeclaration and ClassExpression are strict code. |
5010 if (name_is_strict_reserved) { | 5010 if (name_is_strict_reserved) { |
5011 ReportMessageAt(class_name_location, | 5011 ReportMessageAt(class_name_location, |
5012 MessageTemplate::kUnexpectedStrictReserved); | 5012 MessageTemplate::kUnexpectedStrictReserved); |
5013 *ok = false; | 5013 *ok = false; |
5014 return NULL; | 5014 return NULL; |
5015 } | 5015 } |
5016 if (IsEvalOrArguments(name)) { | 5016 if (IsEvalOrArguments(name)) { |
5017 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); | 5017 ReportMessageAt(class_name_location, MessageTemplate::kStrictEvalArguments); |
5018 *ok = false; | 5018 *ok = false; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5100 | 5100 |
5101 // Note that we do not finalize this block scope because it is | 5101 // Note that we do not finalize this block scope because it is |
5102 // used as a sentinel value indicating an anonymous class. | 5102 // used as a sentinel value indicating an anonymous class. |
5103 block_scope->set_end_position(end_pos); | 5103 block_scope->set_end_position(end_pos); |
5104 | 5104 |
5105 if (name != NULL) { | 5105 if (name != NULL) { |
5106 DCHECK_NOT_NULL(proxy); | 5106 DCHECK_NOT_NULL(proxy); |
5107 proxy->var()->set_initializer_position(end_pos); | 5107 proxy->var()->set_initializer_position(end_pos); |
5108 } | 5108 } |
5109 | 5109 |
5110 return factory()->NewClassLiteral(block_scope, proxy, extends, constructor, | 5110 Block* do_block = factory()->NewBlock(nullptr, 1, false, pos); |
5111 properties, pos, end_pos); | 5111 do_block->set_scope(block_scope); |
| 5112 Variable* result_var = |
| 5113 block_scope->NewTemporary(ast_value_factory()->empty_string()); |
| 5114 DoExpression* do_expr = factory()->NewDoExpression(do_block, result_var, pos); |
| 5115 |
| 5116 ClassLiteral* class_literal = factory()->NewClassLiteral( |
| 5117 proxy, extends, constructor, properties, pos, end_pos); |
| 5118 |
| 5119 do_block->statements()->Add( |
| 5120 factory()->NewExpressionStatement(class_literal, pos), zone()); |
| 5121 do_expr->set_represented_function(constructor); |
| 5122 Rewriter::Rewrite(this, do_expr, ast_value_factory()); |
| 5123 |
| 5124 return do_expr; |
5112 } | 5125 } |
5113 | 5126 |
5114 | 5127 |
5115 Expression* Parser::ParseV8Intrinsic(bool* ok) { | 5128 Expression* Parser::ParseV8Intrinsic(bool* ok) { |
5116 // CallRuntime :: | 5129 // CallRuntime :: |
5117 // '%' Identifier Arguments | 5130 // '%' Identifier Arguments |
5118 | 5131 |
5119 int pos = peek_position(); | 5132 int pos = peek_position(); |
5120 Expect(Token::MOD, CHECK_OK); | 5133 Expect(Token::MOD, CHECK_OK); |
5121 // Allow "eval" or "arguments" for backward compatibility. | 5134 // Allow "eval" or "arguments" for backward compatibility. |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6095 | 6108 |
6096 | 6109 |
6097 void ParserTraits::SetFunctionName(Expression* value, | 6110 void ParserTraits::SetFunctionName(Expression* value, |
6098 const AstRawString* name) { | 6111 const AstRawString* name) { |
6099 DCHECK_NOT_NULL(name); | 6112 DCHECK_NOT_NULL(name); |
6100 if (!value->IsAnonymousFunctionDefinition()) return; | 6113 if (!value->IsAnonymousFunctionDefinition()) return; |
6101 auto function = value->AsFunctionLiteral(); | 6114 auto function = value->AsFunctionLiteral(); |
6102 if (function != nullptr) { | 6115 if (function != nullptr) { |
6103 function->set_raw_name(name); | 6116 function->set_raw_name(name); |
6104 } else { | 6117 } else { |
6105 DCHECK(value->IsClassLiteral()); | 6118 DCHECK(value->IsDoExpression()); |
6106 value->AsClassLiteral()->constructor()->set_raw_name(name); | 6119 value->AsDoExpression()->represented_function()->set_raw_name(name); |
6107 } | 6120 } |
6108 } | 6121 } |
6109 | 6122 |
6110 | 6123 |
6111 // Desugaring of yield* | 6124 // Desugaring of yield* |
6112 // ==================== | 6125 // ==================== |
6113 // | 6126 // |
6114 // With the help of do-expressions and function.sent, we desugar yield* into a | 6127 // With the help of do-expressions and function.sent, we desugar yield* into a |
6115 // loop containing a "raw" yield (a yield that doesn't wrap an iterator result | 6128 // loop containing a "raw" yield (a yield that doesn't wrap an iterator result |
6116 // object around its argument). Concretely, "yield* iterable" turns into | 6129 // object around its argument). Concretely, "yield* iterable" turns into |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7077 node->Print(Isolate::Current()); | 7090 node->Print(Isolate::Current()); |
7078 } | 7091 } |
7079 #endif // DEBUG | 7092 #endif // DEBUG |
7080 | 7093 |
7081 #undef CHECK_OK | 7094 #undef CHECK_OK |
7082 #undef CHECK_OK_VOID | 7095 #undef CHECK_OK_VOID |
7083 #undef CHECK_FAILED | 7096 #undef CHECK_FAILED |
7084 | 7097 |
7085 } // namespace internal | 7098 } // namespace internal |
7086 } // namespace v8 | 7099 } // namespace v8 |
OLD | NEW |