Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: src/parsing/parser.cc

Issue 2233473002: Redirect most NewUnresolved calls over Parser (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 auto constructor_args_name = ast_value_factory()->empty_string(); 268 auto constructor_args_name = ast_value_factory()->empty_string();
269 bool is_duplicate; 269 bool is_duplicate;
270 bool is_rest = true; 270 bool is_rest = true;
271 bool is_optional = false; 271 bool is_optional = false;
272 Variable* constructor_args = function_scope->DeclareParameter( 272 Variable* constructor_args = function_scope->DeclareParameter(
273 constructor_args_name, TEMPORARY, is_optional, is_rest, &is_duplicate, 273 constructor_args_name, TEMPORARY, is_optional, is_rest, &is_duplicate,
274 ast_value_factory()); 274 ast_value_factory());
275 275
276 ZoneList<Expression*>* args = 276 ZoneList<Expression*>* args =
277 new (zone()) ZoneList<Expression*>(2, zone()); 277 new (zone()) ZoneList<Expression*>(2, zone());
278 VariableProxy* this_function_proxy = this->scope()->NewUnresolved( 278 VariableProxy* this_function_proxy =
279 factory(), ast_value_factory()->this_function_string(), 279 NewUnresolved(ast_value_factory()->this_function_string(), pos);
280 Variable::NORMAL, pos);
281 ZoneList<Expression*>* tmp = 280 ZoneList<Expression*>* tmp =
282 new (zone()) ZoneList<Expression*>(1, zone()); 281 new (zone()) ZoneList<Expression*>(1, zone());
283 tmp->Add(this_function_proxy, zone()); 282 tmp->Add(this_function_proxy, zone());
284 Expression* super_constructor = factory()->NewCallRuntime( 283 Expression* super_constructor = factory()->NewCallRuntime(
285 Runtime::kInlineGetSuperConstructor, tmp, pos); 284 Runtime::kInlineGetSuperConstructor, tmp, pos);
286 args->Add(super_constructor, zone()); 285 args->Add(super_constructor, zone());
287 Spread* spread_args = factory()->NewSpread( 286 Spread* spread_args = factory()->NewSpread(
288 factory()->NewVariableProxy(constructor_args), pos, pos); 287 factory()->NewVariableProxy(constructor_args), pos, pos);
289 ZoneList<Expression*>* spread_args_expr = 288 ZoneList<Expression*>* spread_args_expr =
290 new (zone()) ZoneList<Expression*>(1, zone()); 289 new (zone()) ZoneList<Expression*>(1, zone());
291 spread_args_expr->Add(spread_args, zone()); 290 spread_args_expr->Add(spread_args, zone());
292 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone()); 291 args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone());
293 VariableProxy* new_target_proxy = this->scope()->NewUnresolved( 292 VariableProxy* new_target_proxy =
294 factory(), ast_value_factory()->new_target_string(), Variable::NORMAL, 293 NewUnresolved(ast_value_factory()->new_target_string(), pos);
295 pos);
296 args->Add(new_target_proxy, zone()); 294 args->Add(new_target_proxy, zone());
297 CallRuntime* call = factory()->NewCallRuntime( 295 CallRuntime* call = factory()->NewCallRuntime(
298 Context::REFLECT_CONSTRUCT_INDEX, args, pos); 296 Context::REFLECT_CONSTRUCT_INDEX, args, pos);
299 body->Add(factory()->NewReturnStatement(call, pos), zone()); 297 body->Add(factory()->NewReturnStatement(call, pos), zone());
300 } 298 }
301 299
302 materialized_literal_count = function_state.materialized_literal_count(); 300 materialized_literal_count = function_state.materialized_literal_count();
303 expected_property_count = function_state.expected_property_count(); 301 expected_property_count = function_state.expected_property_count();
304 } 302 }
305 303
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 char array[100]; 681 char array[100];
684 const char* string = DoubleToCString(double_value, ArrayVector(array)); 682 const char* string = DoubleToCString(double_value, ArrayVector(array));
685 return parser_->ast_value_factory()->GetOneByteString(string); 683 return parser_->ast_value_factory()->GetOneByteString(string);
686 } 684 }
687 685
688 686
689 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { 687 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
690 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); 688 return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
691 } 689 }
692 690
693 Expression* ParserTraits::ThisExpression(AstNodeFactory* factory, int pos) { 691 Expression* ParserTraits::ThisExpression(int pos) {
694 return parser_->scope()->NewUnresolved( 692 return parser_->NewUnresolved(parser_->ast_value_factory()->this_string(),
695 factory, parser_->ast_value_factory()->this_string(), Variable::THIS, pos, 693 pos, pos + 4, Variable::THIS);
696 pos + 4);
697 } 694 }
698 695
699 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory, 696 Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
700 int pos) { 697 int pos) {
701 // this_function[home_object_symbol] 698 // this_function[home_object_symbol]
702 VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved( 699 VariableProxy* this_function_proxy = parser_->NewUnresolved(
703 factory, parser_->ast_value_factory()->this_function_string(), 700 parser_->ast_value_factory()->this_function_string(), pos);
704 Variable::NORMAL, pos);
705 Expression* home_object_symbol_literal = 701 Expression* home_object_symbol_literal =
706 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition); 702 factory->NewSymbolLiteral("home_object_symbol", kNoSourcePosition);
707 Expression* home_object = factory->NewProperty( 703 Expression* home_object = factory->NewProperty(
708 this_function_proxy, home_object_symbol_literal, pos); 704 this_function_proxy, home_object_symbol_literal, pos);
709 return factory->NewSuperPropertyReference( 705 return factory->NewSuperPropertyReference(
710 ThisExpression(factory, pos)->AsVariableProxy(), home_object, pos); 706 ThisExpression(pos)->AsVariableProxy(), home_object, pos);
711 } 707 }
712 708
713 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory, 709 Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
714 int pos) { 710 int pos) {
715 VariableProxy* new_target_proxy = parser_->scope()->NewUnresolved( 711 VariableProxy* new_target_proxy = parser_->NewUnresolved(
716 factory, parser_->ast_value_factory()->new_target_string(), 712 parser_->ast_value_factory()->new_target_string(), pos);
717 Variable::NORMAL, pos); 713 VariableProxy* this_function_proxy = parser_->NewUnresolved(
718 VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved( 714 parser_->ast_value_factory()->this_function_string(), pos);
719 factory, parser_->ast_value_factory()->this_function_string(), 715 return factory->NewSuperCallReference(ThisExpression(pos)->AsVariableProxy(),
720 Variable::NORMAL, pos); 716 new_target_proxy, this_function_proxy,
721 return factory->NewSuperCallReference( 717 pos);
722 ThisExpression(factory, pos)->AsVariableProxy(), new_target_proxy,
723 this_function_proxy, pos);
724 } 718 }
725 719
726 Expression* ParserTraits::NewTargetExpression(AstNodeFactory* factory, 720 Expression* ParserTraits::NewTargetExpression(int pos) {
727 int pos) {
728 static const int kNewTargetStringLength = 10; 721 static const int kNewTargetStringLength = 10;
729 auto proxy = parser_->scope()->NewUnresolved( 722 auto proxy =
730 factory, parser_->ast_value_factory()->new_target_string(), 723 parser_->NewUnresolved(parser_->ast_value_factory()->new_target_string(),
731 Variable::NORMAL, pos, pos + kNewTargetStringLength); 724 pos, pos + kNewTargetStringLength);
732 proxy->set_is_new_target(); 725 proxy->set_is_new_target();
733 return proxy; 726 return proxy;
734 } 727 }
735 728
736 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory, 729 Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory,
737 int pos) { 730 int pos) {
738 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator). 731 // We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator).
739 Zone* zone = parser_->zone(); 732 Zone* zone = parser_->zone();
740 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone); 733 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(1, zone);
741 VariableProxy* generator = factory->NewVariableProxy( 734 VariableProxy* generator = factory->NewVariableProxy(
(...skipping 22 matching lines...) Expand all
764 bool has_dot = scanner->ContainsDot(); 757 bool has_dot = scanner->ContainsDot();
765 double value = scanner->DoubleValue(); 758 double value = scanner->DoubleValue();
766 return factory->NewNumberLiteral(value, pos, has_dot); 759 return factory->NewNumberLiteral(value, pos, has_dot);
767 } 760 }
768 default: 761 default:
769 DCHECK(false); 762 DCHECK(false);
770 } 763 }
771 return NULL; 764 return NULL;
772 } 765 }
773 766
774
775 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, 767 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
776 int start_position, 768 int start_position,
777 int end_position, 769 int end_position) {
778 AstNodeFactory* factory) {
779 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); 770 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
780 return parser_->scope()->NewUnresolved(factory, name, Variable::NORMAL, 771 return parser_->NewUnresolved(name, start_position, end_position);
781 start_position, end_position);
782 } 772 }
783 773
784 774
785 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, 775 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner,
786 AstNodeFactory* factory) { 776 AstNodeFactory* factory) {
787 const AstRawString* symbol = GetSymbol(scanner); 777 const AstRawString* symbol = GetSymbol(scanner);
788 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); 778 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol);
789 return factory->NewStringLiteral(symbol, pos); 779 return factory->NewStringLiteral(symbol, pos);
790 } 780 }
791 781
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 1932
1943 case Token::TRY: 1933 case Token::TRY:
1944 return ParseTryStatement(ok); 1934 return ParseTryStatement(ok);
1945 1935
1946 default: 1936 default:
1947 UNREACHABLE(); 1937 UNREACHABLE();
1948 return NULL; 1938 return NULL;
1949 } 1939 }
1950 } 1940 }
1951 1941
1942 VariableProxy* Parser::NewUnresolved(const AstRawString* name, int begin_pos,
1943 int end_pos, Variable::Kind kind) {
1944 return scope()->NewUnresolved(factory(), name, begin_pos, end_pos, kind);
1945 }
1952 1946
1953 VariableProxy* Parser::NewUnresolved(const AstRawString* name, 1947 VariableProxy* Parser::NewUnresolved(const AstRawString* name) {
1954 VariableMode mode) { 1948 return scope()->NewUnresolved(factory(), name, scanner()->location().beg_pos,
1955 // If we are inside a function, a declaration of a 'var' variable is a 1949 scanner()->location().end_pos);
1956 // truly local variable, and the scope of the variable is always the function
1957 // scope.
1958 // Let/const variables are always added to the immediately enclosing scope.
1959 Scope* scope =
1960 IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope();
1961 return scope->NewUnresolved(factory(), name, Variable::NORMAL,
1962 scanner()->location().beg_pos,
1963 scanner()->location().end_pos);
1964 } 1950 }
1965 1951
1966 InitializationFlag Parser::DefaultInitializationFlag(VariableMode mode) { 1952 InitializationFlag Parser::DefaultInitializationFlag(VariableMode mode) {
1967 DCHECK(IsDeclaredVariableMode(mode)); 1953 DCHECK(IsDeclaredVariableMode(mode));
1968 return mode == VAR ? kCreatedInitialized : kNeedsInitialization; 1954 return mode == VAR ? kCreatedInitialized : kNeedsInitialization;
1969 } 1955 }
1970 1956
1971 Declaration* Parser::DeclareVariable(const AstRawString* name, 1957 Declaration* Parser::DeclareVariable(const AstRawString* name,
1972 VariableMode mode, int pos, bool* ok) { 1958 VariableMode mode, int pos, bool* ok) {
1973 return DeclareVariable(name, mode, DefaultInitializationFlag(mode), pos, ok); 1959 return DeclareVariable(name, mode, DefaultInitializationFlag(mode), pos, ok);
1974 } 1960 }
1975 1961
1976 Declaration* Parser::DeclareVariable(const AstRawString* name, 1962 Declaration* Parser::DeclareVariable(const AstRawString* name,
1977 VariableMode mode, InitializationFlag init, 1963 VariableMode mode, InitializationFlag init,
1978 int pos, bool* ok) { 1964 int pos, bool* ok) {
1979 DCHECK_NOT_NULL(name); 1965 DCHECK_NOT_NULL(name);
1980 VariableProxy* proxy = NewUnresolved(name, mode); 1966 Scope* scope =
1967 IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope();
Toon Verwaest 2016/08/10 06:47:53 Now only declarations need to use the mode to choo
1968 VariableProxy* proxy =
1969 scope->NewUnresolved(factory(), name, scanner()->location().beg_pos,
1970 scanner()->location().end_pos);
1981 Declaration* declaration = 1971 Declaration* declaration =
1982 factory()->NewVariableDeclaration(proxy, mode, scope(), pos); 1972 factory()->NewVariableDeclaration(proxy, mode, this->scope(), pos);
1983 Declare(declaration, DeclarationDescriptor::NORMAL, init, CHECK_OK); 1973 Declare(declaration, DeclarationDescriptor::NORMAL, init, CHECK_OK);
1984 return declaration; 1974 return declaration;
1985 } 1975 }
1986 1976
1987 Variable* Parser::Declare(Declaration* declaration, 1977 Variable* Parser::Declare(Declaration* declaration,
1988 DeclarationDescriptor::Kind declaration_kind, 1978 DeclarationDescriptor::Kind declaration_kind,
1989 InitializationFlag init, bool* ok, Scope* scope) { 1979 InitializationFlag init, bool* ok, Scope* scope) {
1990 VariableProxy* proxy = declaration->proxy(); 1980 VariableProxy* proxy = declaration->proxy();
1991 DCHECK(proxy->raw_name() != NULL); 1981 DCHECK(proxy->raw_name() != NULL);
1992 const AstRawString* name = proxy->raw_name(); 1982 const AstRawString* name = proxy->raw_name();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 is_generator ? FunctionKind::kGeneratorFunction 2193 is_generator ? FunctionKind::kGeneratorFunction
2204 : is_async ? FunctionKind::kAsyncFunction 2194 : is_async ? FunctionKind::kAsyncFunction
2205 : FunctionKind::kNormalFunction, 2195 : FunctionKind::kNormalFunction,
2206 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK); 2196 pos, FunctionLiteral::kDeclaration, language_mode(), CHECK_OK);
2207 2197
2208 // In ES6, a function behaves as a lexical binding, except in 2198 // In ES6, a function behaves as a lexical binding, except in
2209 // a script scope, or the initial scope of eval or another function. 2199 // a script scope, or the initial scope of eval or another function.
2210 VariableMode mode = 2200 VariableMode mode =
2211 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET 2201 (!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
2212 : VAR; 2202 : VAR;
2213 VariableProxy* proxy = NewUnresolved(variable_name, mode); 2203 VariableProxy* proxy = NewUnresolved(variable_name);
2214 Declaration* declaration = 2204 Declaration* declaration =
2215 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos); 2205 factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos);
2216 Declare(declaration, DeclarationDescriptor::NORMAL, kCreatedInitialized, 2206 Declare(declaration, DeclarationDescriptor::NORMAL, kCreatedInitialized,
2217 CHECK_OK); 2207 CHECK_OK);
2218 if (names) names->Add(variable_name, zone()); 2208 if (names) names->Add(variable_name, zone());
2219 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition); 2209 EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
2220 // Async functions don't undergo sloppy mode block scoped hoisting, and don't 2210 // Async functions don't undergo sloppy mode block scoped hoisting, and don't
2221 // allow duplicates in a block. Both are represented by the 2211 // allow duplicates in a block. Both are represented by the
2222 // sloppy_block_function_map. Don't add them to the map for async functions. 2212 // sloppy_block_function_map. Don't add them to the map for async functions.
2223 // Generators are also supposed to be prohibited; currently doing this behind 2213 // Generators are also supposed to be prohibited; currently doing this behind
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2711 Scanner::Location loc = scanner()->location(); 2701 Scanner::Location loc = scanner()->location();
2712 2702
2713 Token::Value tok = peek(); 2703 Token::Value tok = peek();
2714 Statement* result; 2704 Statement* result;
2715 Expression* return_value; 2705 Expression* return_value;
2716 if (scanner()->HasAnyLineTerminatorBeforeNext() || 2706 if (scanner()->HasAnyLineTerminatorBeforeNext() ||
2717 tok == Token::SEMICOLON || 2707 tok == Token::SEMICOLON ||
2718 tok == Token::RBRACE || 2708 tok == Token::RBRACE ||
2719 tok == Token::EOS) { 2709 tok == Token::EOS) {
2720 if (IsSubclassConstructor(function_state_->kind())) { 2710 if (IsSubclassConstructor(function_state_->kind())) {
2721 return_value = ThisExpression(factory(), loc.beg_pos); 2711 return_value = ThisExpression(loc.beg_pos);
2722 } else { 2712 } else {
2723 return_value = GetLiteralUndefined(position()); 2713 return_value = GetLiteralUndefined(position());
2724 } 2714 }
2725 } else { 2715 } else {
2726 int pos = peek_position(); 2716 int pos = peek_position();
2727 2717
2728 if (IsSubclassConstructor(function_state_->kind())) { 2718 if (IsSubclassConstructor(function_state_->kind())) {
2729 // Because of the return code rewriting that happens in case of a subclass 2719 // Because of the return code rewriting that happens in case of a subclass
2730 // constructor we don't want to accept tail calls, therefore we don't set 2720 // constructor we don't want to accept tail calls, therefore we don't set
2731 // ReturnExprScope to kInsideValidReturnStatement here. 2721 // ReturnExprScope to kInsideValidReturnStatement here.
(...skipping 26 matching lines...) Expand all
2758 Expression* is_object_conditional = factory()->NewConditional( 2748 Expression* is_object_conditional = factory()->NewConditional(
2759 is_spec_object_call, factory()->NewVariableProxy(temp), 2749 is_spec_object_call, factory()->NewVariableProxy(temp),
2760 factory()->NewSmiLiteral(1, pos), pos); 2750 factory()->NewSmiLiteral(1, pos), pos);
2761 2751
2762 // temp === undefined 2752 // temp === undefined
2763 Expression* is_undefined = factory()->NewCompareOperation( 2753 Expression* is_undefined = factory()->NewCompareOperation(
2764 Token::EQ_STRICT, assign, 2754 Token::EQ_STRICT, assign,
2765 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); 2755 factory()->NewUndefinedLiteral(kNoSourcePosition), pos);
2766 2756
2767 // is_undefined ? this : is_object_conditional 2757 // is_undefined ? this : is_object_conditional
2768 return_value = factory()->NewConditional(is_undefined, 2758 return_value = factory()->NewConditional(
2769 ThisExpression(factory(), pos), 2759 is_undefined, ThisExpression(pos), is_object_conditional, pos);
2770 is_object_conditional, pos);
2771 } else { 2760 } else {
2772 ReturnExprScope maybe_allow_tail_calls( 2761 ReturnExprScope maybe_allow_tail_calls(
2773 function_state_, ReturnExprContext::kInsideValidReturnStatement); 2762 function_state_, ReturnExprContext::kInsideValidReturnStatement);
2774 return_value = ParseExpression(true, CHECK_OK); 2763 return_value = ParseExpression(true, CHECK_OK);
2775 2764
2776 if (allow_tailcalls() && !is_sloppy(language_mode())) { 2765 if (allow_tailcalls() && !is_sloppy(language_mode())) {
2777 // ES6 14.6.1 Static Semantics: IsInTailPosition 2766 // ES6 14.6.1 Static Semantics: IsInTailPosition
2778 function_state_->AddImplicitTailCallExpression(return_value); 2767 function_state_->AddImplicitTailCallExpression(return_value);
2779 } 2768 }
2780 } 2769 }
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
3439 factory()->NewBlock(NULL, names->length() + 4, false, kNoSourcePosition); 3428 factory()->NewBlock(NULL, names->length() + 4, false, kNoSourcePosition);
3440 3429
3441 // Add statement: let/const x = i. 3430 // Add statement: let/const x = i.
3442 outer_block->statements()->Add(init, zone()); 3431 outer_block->statements()->Add(init, zone());
3443 3432
3444 const AstRawString* temp_name = ast_value_factory()->dot_for_string(); 3433 const AstRawString* temp_name = ast_value_factory()->dot_for_string();
3445 3434
3446 // For each lexical variable x: 3435 // For each lexical variable x:
3447 // make statement: temp_x = x. 3436 // make statement: temp_x = x.
3448 for (int i = 0; i < names->length(); i++) { 3437 for (int i = 0; i < names->length(); i++) {
3449 VariableProxy* proxy = NewUnresolved(names->at(i), LET); 3438 VariableProxy* proxy = NewUnresolved(names->at(i));
3450 Variable* temp = NewTemporary(temp_name); 3439 Variable* temp = NewTemporary(temp_name);
3451 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 3440 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
3452 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy, 3441 Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy,
3453 proxy, kNoSourcePosition); 3442 proxy, kNoSourcePosition);
3454 Statement* assignment_statement = 3443 Statement* assignment_statement =
3455 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 3444 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
3456 outer_block->statements()->Add(assignment_statement, zone()); 3445 outer_block->statements()->Add(assignment_statement, zone());
3457 temps.Add(temp, zone()); 3446 temps.Add(temp, zone());
3458 } 3447 }
3459 3448
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3710 bound_names_are_lexical = 3699 bound_names_are_lexical =
3711 IsLexicalVariableMode(parsing_result.descriptor.mode); 3700 IsLexicalVariableMode(parsing_result.descriptor.mode);
3712 3701
3713 // special case for legacy for (var ... = ... in ...) 3702 // special case for legacy for (var ... = ... in ...)
3714 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() && 3703 if (!bound_names_are_lexical && decl.pattern->IsVariableProxy() &&
3715 decl.initializer != nullptr) { 3704 decl.initializer != nullptr) {
3716 DCHECK(!allow_harmony_for_in()); 3705 DCHECK(!allow_harmony_for_in());
3717 ++use_counts_[v8::Isolate::kForInInitializer]; 3706 ++use_counts_[v8::Isolate::kForInInitializer];
3718 const AstRawString* name = 3707 const AstRawString* name =
3719 decl.pattern->AsVariableProxy()->raw_name(); 3708 decl.pattern->AsVariableProxy()->raw_name();
3720 VariableProxy* single_var = NewUnresolved(name, VAR); 3709 VariableProxy* single_var = NewUnresolved(name);
3721 init_block = factory()->NewBlock( 3710 init_block = factory()->NewBlock(
3722 nullptr, 2, true, parsing_result.descriptor.declaration_pos); 3711 nullptr, 2, true, parsing_result.descriptor.declaration_pos);
3723 init_block->statements()->Add( 3712 init_block->statements()->Add(
3724 factory()->NewExpressionStatement( 3713 factory()->NewExpressionStatement(
3725 factory()->NewAssignment(Token::ASSIGN, single_var, 3714 factory()->NewAssignment(Token::ASSIGN, single_var,
3726 decl.initializer, kNoSourcePosition), 3715 decl.initializer, kNoSourcePosition),
3727 kNoSourcePosition), 3716 kNoSourcePosition),
3728 zone()); 3717 zone());
3729 } 3718 }
3730 3719
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
4753 4742
4754 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); 4743 block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
4755 block->statements()->Add(try_catch_statement, zone()); 4744 block->statements()->Add(try_catch_statement, zone());
4756 return block; 4745 return block;
4757 } 4746 }
4758 4747
4759 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { 4748 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) {
4760 DCHECK_NOT_NULL(function_state_->generator_object_variable()); 4749 DCHECK_NOT_NULL(function_state_->generator_object_variable());
4761 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); 4750 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
4762 args->Add(factory()->NewThisFunction(pos), zone()); 4751 args->Add(factory()->NewThisFunction(pos), zone());
4763 args->Add(IsArrowFunction(kind) 4752 args->Add(IsArrowFunction(kind) ? GetLiteralUndefined(pos)
4764 ? GetLiteralUndefined(pos) 4753 : ThisExpression(kNoSourcePosition),
4765 : ThisExpression(factory(), kNoSourcePosition),
4766 zone()); 4754 zone());
4767 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, 4755 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args,
4768 pos); 4756 pos);
4769 } 4757 }
4770 4758
4771 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { 4759 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) {
4772 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); 4760 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone());
4773 args->Add(value, zone()); 4761 args->Add(value, zone());
4774 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, 4762 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args,
4775 pos); 4763 pos);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
4876 } else if (IsAsyncFunction(kind)) { 4864 } else if (IsAsyncFunction(kind)) {
4877 const bool accept_IN = true; 4865 const bool accept_IN = true;
4878 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, 4866 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind,
4879 FunctionBody::Normal, accept_IN, pos, CHECK_OK); 4867 FunctionBody::Normal, accept_IN, pos, CHECK_OK);
4880 } else { 4868 } else {
4881 ParseStatementList(body, Token::RBRACE, CHECK_OK); 4869 ParseStatementList(body, Token::RBRACE, CHECK_OK);
4882 } 4870 }
4883 4871
4884 if (IsSubclassConstructor(kind)) { 4872 if (IsSubclassConstructor(kind)) {
4885 body->Add(factory()->NewReturnStatement( 4873 body->Add(factory()->NewReturnStatement(
4886 this->ThisExpression(factory(), kNoSourcePosition), 4874 this->ThisExpression(kNoSourcePosition), kNoSourcePosition),
4887 kNoSourcePosition),
4888 zone()); 4875 zone());
4889 } 4876 }
4890 } 4877 }
4891 4878
4892 Expect(Token::RBRACE, CHECK_OK); 4879 Expect(Token::RBRACE, CHECK_OK);
4893 scope()->set_end_position(scanner()->location().end_pos); 4880 scope()->set_end_position(scanner()->location().end_pos);
4894 4881
4895 if (!parameters.is_simple) { 4882 if (!parameters.is_simple) {
4896 DCHECK_NOT_NULL(inner_scope); 4883 DCHECK_NOT_NULL(inner_scope);
4897 DCHECK_EQ(function_scope, scope()); 4884 DCHECK_EQ(function_scope, scope());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
5011 } 4998 }
5012 4999
5013 BlockState block_state(&scope_state_); 5000 BlockState block_state(&scope_state_);
5014 RaiseLanguageMode(STRICT); 5001 RaiseLanguageMode(STRICT);
5015 #ifdef DEBUG 5002 #ifdef DEBUG
5016 scope()->SetScopeName(name); 5003 scope()->SetScopeName(name);
5017 #endif 5004 #endif
5018 5005
5019 VariableProxy* proxy = nullptr; 5006 VariableProxy* proxy = nullptr;
5020 if (name != nullptr) { 5007 if (name != nullptr) {
5021 proxy = NewUnresolved(name, CONST); 5008 proxy = NewUnresolved(name);
5022 // TODO(verwaest): declare via block_state. 5009 // TODO(verwaest): declare via block_state.
5023 Declaration* declaration = factory()->NewVariableDeclaration( 5010 Declaration* declaration = factory()->NewVariableDeclaration(
5024 proxy, CONST, block_state.scope(), pos); 5011 proxy, CONST, block_state.scope(), pos);
5025 Declare(declaration, DeclarationDescriptor::NORMAL, 5012 Declare(declaration, DeclarationDescriptor::NORMAL,
5026 DefaultInitializationFlag(CONST), CHECK_OK); 5013 DefaultInitializationFlag(CONST), CHECK_OK);
5027 } 5014 }
5028 5015
5029 Expression* extends = nullptr; 5016 Expression* extends = nullptr;
5030 if (Check(Token::EXTENDS)) { 5017 if (Check(Token::EXTENDS)) {
5031 block_state.set_start_position(scanner()->location().end_pos); 5018 block_state.set_start_position(scanner()->location().end_pos);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
5213 Scope* function_scope = inner_scope->outer_scope(); 5200 Scope* function_scope = inner_scope->outer_scope();
5214 DCHECK(function_scope->is_function_scope()); 5201 DCHECK(function_scope->is_function_scope());
5215 ZoneList<Declaration*>* decls = inner_scope->declarations(); 5202 ZoneList<Declaration*>* decls = inner_scope->declarations();
5216 BlockState block_state(&scope_state_, inner_scope); 5203 BlockState block_state(&scope_state_, inner_scope);
5217 for (int i = 0; i < decls->length(); ++i) { 5204 for (int i = 0; i < decls->length(); ++i) {
5218 Declaration* decl = decls->at(i); 5205 Declaration* decl = decls->at(i);
5219 if (decl->mode() != VAR || !decl->IsVariableDeclaration()) continue; 5206 if (decl->mode() != VAR || !decl->IsVariableDeclaration()) continue;
5220 const AstRawString* name = decl->proxy()->raw_name(); 5207 const AstRawString* name = decl->proxy()->raw_name();
5221 Variable* parameter = function_scope->LookupLocal(name); 5208 Variable* parameter = function_scope->LookupLocal(name);
5222 if (parameter == nullptr) continue; 5209 if (parameter == nullptr) continue;
5223 VariableProxy* to = NewUnresolved(name, VAR); 5210 VariableProxy* to = NewUnresolved(name);
5224 VariableProxy* from = factory()->NewVariableProxy(parameter); 5211 VariableProxy* from = factory()->NewVariableProxy(parameter);
5225 Expression* assignment = 5212 Expression* assignment =
5226 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition); 5213 factory()->NewAssignment(Token::ASSIGN, to, from, kNoSourcePosition);
5227 Statement* statement = 5214 Statement* statement =
5228 factory()->NewExpressionStatement(assignment, kNoSourcePosition); 5215 factory()->NewExpressionStatement(assignment, kNoSourcePosition);
5229 inner_block->statements()->InsertAt(0, statement, zone()); 5216 inner_block->statements()->InsertAt(0, statement, zone());
5230 } 5217 }
5231 } 5218 }
5232 5219
5233 void Parser::InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope, 5220 void Parser::InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope,
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
5695 Expression* super_constructor = factory()->NewCallRuntime( 5682 Expression* super_constructor = factory()->NewCallRuntime(
5696 Runtime::kInlineGetSuperConstructor, tmp, pos); 5683 Runtime::kInlineGetSuperConstructor, tmp, pos);
5697 args->InsertAt(0, super_constructor, zone()); 5684 args->InsertAt(0, super_constructor, zone());
5698 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); 5685 args->Add(function->AsSuperCallReference()->new_target_var(), zone());
5699 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, 5686 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args,
5700 pos); 5687 pos);
5701 } else { 5688 } else {
5702 if (function->IsProperty()) { 5689 if (function->IsProperty()) {
5703 // Method calls 5690 // Method calls
5704 if (function->AsProperty()->IsSuperAccess()) { 5691 if (function->AsProperty()->IsSuperAccess()) {
5705 Expression* home = ThisExpression(factory(), kNoSourcePosition); 5692 Expression* home = ThisExpression(kNoSourcePosition);
5706 args->InsertAt(0, function, zone()); 5693 args->InsertAt(0, function, zone());
5707 args->InsertAt(1, home, zone()); 5694 args->InsertAt(1, home, zone());
5708 } else { 5695 } else {
5709 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); 5696 Variable* temp = NewTemporary(ast_value_factory()->empty_string());
5710 VariableProxy* obj = factory()->NewVariableProxy(temp); 5697 VariableProxy* obj = factory()->NewVariableProxy(temp);
5711 Assignment* assign_obj = factory()->NewAssignment( 5698 Assignment* assign_obj = factory()->NewAssignment(
5712 Token::ASSIGN, obj, function->AsProperty()->obj(), 5699 Token::ASSIGN, obj, function->AsProperty()->obj(),
5713 kNoSourcePosition); 5700 kNoSourcePosition);
5714 function = factory()->NewProperty( 5701 function = factory()->NewProperty(
5715 assign_obj, function->AsProperty()->key(), kNoSourcePosition); 5702 assign_obj, function->AsProperty()->key(), kNoSourcePosition);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
5936 5923
5937 Expression* Parser::RewriteAssignExponentiation(Expression* left, 5924 Expression* Parser::RewriteAssignExponentiation(Expression* left,
5938 Expression* right, int pos) { 5925 Expression* right, int pos) {
5939 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); 5926 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone());
5940 if (left->IsVariableProxy()) { 5927 if (left->IsVariableProxy()) {
5941 VariableProxy* lhs = left->AsVariableProxy(); 5928 VariableProxy* lhs = left->AsVariableProxy();
5942 5929
5943 Expression* result; 5930 Expression* result;
5944 DCHECK_NOT_NULL(lhs->raw_name()); 5931 DCHECK_NOT_NULL(lhs->raw_name());
5945 result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(), 5932 result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
5946 lhs->end_position(), factory()); 5933 lhs->end_position());
5947 args->Add(left, zone()); 5934 args->Add(left, zone());
5948 args->Add(right, zone()); 5935 args->Add(right, zone());
5949 Expression* call = 5936 Expression* call =
5950 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos); 5937 factory()->NewCallRuntime(Context::MATH_POW_INDEX, args, pos);
5951 return factory()->NewAssignment(Token::ASSIGN, result, call, pos); 5938 return factory()->NewAssignment(Token::ASSIGN, result, call, pos);
5952 } else if (left->IsProperty()) { 5939 } else if (left->IsProperty()) {
5953 Property* prop = left->AsProperty(); 5940 Property* prop = left->AsProperty();
5954 auto temp_obj = NewTemporary(ast_value_factory()->empty_string()); 5941 auto temp_obj = NewTemporary(ast_value_factory()->empty_string());
5955 auto temp_key = NewTemporary(ast_value_factory()->empty_string()); 5942 auto temp_key = NewTemporary(ast_value_factory()->empty_string());
5956 Expression* assign_obj = factory()->NewAssignment( 5943 Expression* assign_obj = factory()->NewAssignment(
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
7091 node->Print(Isolate::Current()); 7078 node->Print(Isolate::Current());
7092 } 7079 }
7093 #endif // DEBUG 7080 #endif // DEBUG
7094 7081
7095 #undef CHECK_OK 7082 #undef CHECK_OK
7096 #undef CHECK_OK_VOID 7083 #undef CHECK_OK_VOID
7097 #undef CHECK_FAILED 7084 #undef CHECK_FAILED
7098 7085
7099 } // namespace internal 7086 } // namespace internal
7100 } // namespace v8 7087 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | src/parsing/pattern-rewriter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698