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

Side by Side Diff: src/parser.cc

Issue 1066933005: Use ExpressionClassifier for bindings. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed webkit test issues Created 5 years, 8 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
« no previous file with comments | « no previous file | src/preparser.h » ('j') | src/preparser.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/bailout-reason.h" 9 #include "src/bailout-reason.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 if (ok) ok = Check(Token::RPAREN); 1144 if (ok) ok = Check(Token::RPAREN);
1145 } else { 1145 } else {
1146 // BindingIdentifier 1146 // BindingIdentifier
1147 ParseFormalParameter(scope, &error_locs, has_rest, &ok); 1147 ParseFormalParameter(scope, &error_locs, has_rest, &ok);
1148 } 1148 }
1149 1149
1150 if (ok) { 1150 if (ok) {
1151 ExpressionClassifier classifier; 1151 ExpressionClassifier classifier;
1152 Expression* expression = ParseArrowFunctionLiteral( 1152 Expression* expression = ParseArrowFunctionLiteral(
1153 scope, error_locs, has_rest, &classifier, &ok); 1153 scope, error_locs, has_rest, &classifier, &ok);
1154 // TODO(dslomov): report error if not a valid expression. 1154 ValidateExpression(&classifier, &ok);
1155 if (ok) { 1155 if (ok) {
1156 // Scanning must end at the same position that was recorded 1156 // Scanning must end at the same position that was recorded
1157 // previously. If not, parsing has been interrupted due to a stack 1157 // previously. If not, parsing has been interrupted due to a stack
1158 // overflow, at which point the partially parsed arrow function 1158 // overflow, at which point the partially parsed arrow function
1159 // concise body happens to be a valid expression. This is a problem 1159 // concise body happens to be a valid expression. This is a problem
1160 // only for arrow functions with single expression bodies, since there 1160 // only for arrow functions with single expression bodies, since there
1161 // is no end token such as "}" for normal functions. 1161 // is no end token such as "}" for normal functions.
1162 if (scanner()->location().end_pos == shared_info->end_position()) { 1162 if (scanner()->location().end_pos == shared_info->end_position()) {
1163 // The pre-parser saw an arrow function here, so the full parser 1163 // The pre-parser saw an arrow function here, so the full parser
1164 // must produce a FunctionLiteral. 1164 // must produce a FunctionLiteral.
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 1623
1624 case Token::CLASS: 1624 case Token::CLASS:
1625 // TODO(ES6): Support parsing anonymous class declarations here. 1625 // TODO(ES6): Support parsing anonymous class declarations here.
1626 result = ParseClassDeclaration(&names, CHECK_OK); 1626 result = ParseClassDeclaration(&names, CHECK_OK);
1627 break; 1627 break;
1628 1628
1629 default: { 1629 default: {
1630 int pos = peek_position(); 1630 int pos = peek_position();
1631 ExpressionClassifier classifier; 1631 ExpressionClassifier classifier;
1632 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK); 1632 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK);
1633 // TODO(dslomov): report error if not a valid expression. 1633 ValidateExpression(&classifier, CHECK_OK);
1634 1634
1635 ExpectSemicolon(CHECK_OK); 1635 ExpectSemicolon(CHECK_OK);
1636 result = factory()->NewExpressionStatement(expr, pos); 1636 result = factory()->NewExpressionStatement(expr, pos);
1637 break; 1637 break;
1638 } 1638 }
1639 } 1639 }
1640 1640
1641 const AstRawString* default_string = ast_value_factory()->default_string(); 1641 const AstRawString* default_string = ast_value_factory()->default_string();
1642 1642
1643 DCHECK_LE(names.length(), 1); 1643 DCHECK_LE(names.length(), 1);
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 int nvars = 0; // the number of variables declared 2383 int nvars = 0; // the number of variables declared
2384 int bindings_start = peek_position(); 2384 int bindings_start = peek_position();
2385 const AstRawString* name = NULL; 2385 const AstRawString* name = NULL;
2386 const AstRawString* first_name = NULL; 2386 const AstRawString* first_name = NULL;
2387 bool is_for_iteration_variable; 2387 bool is_for_iteration_variable;
2388 do { 2388 do {
2389 if (fni_ != NULL) fni_->Enter(); 2389 if (fni_ != NULL) fni_->Enter();
2390 2390
2391 // Parse variable name. 2391 // Parse variable name.
2392 if (nvars > 0) Consume(Token::COMMA); 2392 if (nvars > 0) Consume(Token::COMMA);
2393 name = ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 2393
2394 {
2395 ExpressionClassifier pattern_classifier;
2396 Token::Value next = peek();
2397 Expression* pattern =
2398 ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
2399 ValidateBindingPattern(&pattern_classifier, CHECK_OK);
2400 if (pattern->IsVariableProxy() &&
2401 pattern->AsVariableProxy()->IsValidReferenceExpression()) {
2402 scope_->RemoveUnresolved(pattern->AsVariableProxy());
2403 name = pattern->AsVariableProxy()->raw_name();
2404 } else {
2405 ReportUnexpectedToken(next);
2406 *ok = false;
2407 return nullptr;
2408 }
2409 }
2410
2394 if (!first_name) first_name = name; 2411 if (!first_name) first_name = name;
2395 Scanner::Location variable_loc = scanner()->location(); 2412 Scanner::Location variable_loc = scanner()->location();
2396 if (fni_ != NULL) fni_->PushVariableName(name); 2413 if (fni_ != NULL) fni_->PushVariableName(name);
2397 2414
2398 // Declare variable. 2415 // Declare variable.
2399 // Note that we *always* must treat the initial value via a separate init 2416 // Note that we *always* must treat the initial value via a separate init
2400 // assignment for variables and constants because the value must be assigned 2417 // assignment for variables and constants because the value must be assigned
2401 // when the variable is encountered in the source. But the variable/constant 2418 // when the variable is encountered in the source. But the variable/constant
2402 // is declared (and set to 'undefined') upon entering the function within 2419 // is declared (and set to 'undefined') upon entering the function within
2403 // which the variable or constant is declared. Only function variables have 2420 // which the variable or constant is declared. Only function variables have
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2462 Expression* value = NULL; 2479 Expression* value = NULL;
2463 int pos = -1; 2480 int pos = -1;
2464 // Harmony consts have non-optional initializers. 2481 // Harmony consts have non-optional initializers.
2465 if (peek() == Token::ASSIGN || 2482 if (peek() == Token::ASSIGN ||
2466 (mode == CONST && !is_for_iteration_variable)) { 2483 (mode == CONST && !is_for_iteration_variable)) {
2467 Expect(Token::ASSIGN, CHECK_OK); 2484 Expect(Token::ASSIGN, CHECK_OK);
2468 pos = position(); 2485 pos = position();
2469 ExpressionClassifier classifier; 2486 ExpressionClassifier classifier;
2470 value = ParseAssignmentExpression(var_context != kForStatement, 2487 value = ParseAssignmentExpression(var_context != kForStatement,
2471 &classifier, CHECK_OK); 2488 &classifier, CHECK_OK);
2472 // TODO(dslomov): check that expression is valid. 2489 ValidateExpression(&classifier, CHECK_OK);
2473 variable_loc.end_pos = scanner()->location().end_pos; 2490 variable_loc.end_pos = scanner()->location().end_pos;
2474 2491
2475 if (first_initializer_loc && !first_initializer_loc->IsValid()) { 2492 if (first_initializer_loc && !first_initializer_loc->IsValid()) {
2476 *first_initializer_loc = variable_loc; 2493 *first_initializer_loc = variable_loc;
2477 } 2494 }
2478 2495
2479 // Don't infer if it is "a = function(){...}();"-like expression. 2496 // Don't infer if it is "a = function(){...}();"-like expression.
2480 if (fni_ != NULL && 2497 if (fni_ != NULL &&
2481 value->AsCall() == NULL && 2498 value->AsCall() == NULL &&
2482 value->AsCallNew() == NULL) { 2499 value->AsCallNew() == NULL) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2653 if (is_strong(language_mode()) && 2670 if (is_strong(language_mode()) &&
2654 i::IsConstructor(function_state_->kind())) { 2671 i::IsConstructor(function_state_->kind())) {
2655 bool is_this = peek() == Token::THIS; 2672 bool is_this = peek() == Token::THIS;
2656 Expression* expr; 2673 Expression* expr;
2657 ExpressionClassifier classifier; 2674 ExpressionClassifier classifier;
2658 if (is_this) { 2675 if (is_this) {
2659 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK); 2676 expr = ParseStrongInitializationExpression(&classifier, CHECK_OK);
2660 } else { 2677 } else {
2661 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK); 2678 expr = ParseStrongSuperCallExpression(&classifier, CHECK_OK);
2662 } 2679 }
2663 // TODO(dslomov): report error if not a valid expression. 2680 ValidateExpression(&classifier, CHECK_OK);
2664 switch (peek()) { 2681 switch (peek()) {
2665 case Token::SEMICOLON: 2682 case Token::SEMICOLON:
2666 Consume(Token::SEMICOLON); 2683 Consume(Token::SEMICOLON);
2667 break; 2684 break;
2668 case Token::RBRACE: 2685 case Token::RBRACE:
2669 case Token::EOS: 2686 case Token::EOS:
2670 break; 2687 break;
2671 default: 2688 default:
2672 if (!scanner()->HasAnyLineTerminatorBeforeNext()) { 2689 if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
2673 ReportMessageAt(function_state_->this_location(), 2690 ReportMessageAt(function_state_->this_location(),
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after
4382 proxy, CONST, block_scope, pos, is_class_declaration, 4399 proxy, CONST, block_scope, pos, is_class_declaration,
4383 scope_->class_declaration_group_start()); 4400 scope_->class_declaration_group_start());
4384 Declare(declaration, true, CHECK_OK); 4401 Declare(declaration, true, CHECK_OK);
4385 } 4402 }
4386 4403
4387 Expression* extends = NULL; 4404 Expression* extends = NULL;
4388 if (Check(Token::EXTENDS)) { 4405 if (Check(Token::EXTENDS)) {
4389 block_scope->set_start_position(scanner()->location().end_pos); 4406 block_scope->set_start_position(scanner()->location().end_pos);
4390 ExpressionClassifier classifier; 4407 ExpressionClassifier classifier;
4391 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK); 4408 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK);
4392 // TODO(dslomov): report error if not a valid expression. 4409 ValidateExpression(&classifier, CHECK_OK);
4393 } else { 4410 } else {
4394 block_scope->set_start_position(scanner()->location().end_pos); 4411 block_scope->set_start_position(scanner()->location().end_pos);
4395 } 4412 }
4396 4413
4397 4414
4398 ClassLiteralChecker checker(this); 4415 ClassLiteralChecker checker(this);
4399 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); 4416 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
4400 FunctionLiteral* constructor = NULL; 4417 FunctionLiteral* constructor = NULL;
4401 bool has_seen_constructor = false; 4418 bool has_seen_constructor = false;
4402 4419
4403 Expect(Token::LBRACE, CHECK_OK); 4420 Expect(Token::LBRACE, CHECK_OK);
4404 4421
4405 const bool has_extends = extends != nullptr; 4422 const bool has_extends = extends != nullptr;
4406 while (peek() != Token::RBRACE) { 4423 while (peek() != Token::RBRACE) {
4407 if (Check(Token::SEMICOLON)) continue; 4424 if (Check(Token::SEMICOLON)) continue;
4408 if (fni_ != NULL) fni_->Enter(); 4425 if (fni_ != NULL) fni_->Enter();
4409 const bool in_class = true; 4426 const bool in_class = true;
4410 const bool is_static = false; 4427 const bool is_static = false;
4411 bool is_computed_name = false; // Classes do not care about computed 4428 bool is_computed_name = false; // Classes do not care about computed
4412 // property names here. 4429 // property names here.
4413 ExpressionClassifier classifier; 4430 ExpressionClassifier classifier;
4414 ObjectLiteral::Property* property = ParsePropertyDefinition( 4431 ObjectLiteral::Property* property = ParsePropertyDefinition(
4415 &checker, in_class, has_extends, is_static, &is_computed_name, 4432 &checker, in_class, has_extends, is_static, &is_computed_name,
4416 &has_seen_constructor, &classifier, CHECK_OK); 4433 &has_seen_constructor, &classifier, CHECK_OK);
4417 // TODO(dslomov): report error if not a valid expression. 4434 ValidateExpression(&classifier, CHECK_OK);
4418 4435
4419 if (has_seen_constructor && constructor == NULL) { 4436 if (has_seen_constructor && constructor == NULL) {
4420 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4437 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4421 DCHECK_NOT_NULL(constructor); 4438 DCHECK_NOT_NULL(constructor);
4422 } else { 4439 } else {
4423 properties->Add(property, zone()); 4440 properties->Add(property, zone());
4424 } 4441 }
4425 4442
4426 if (fni_ != NULL) { 4443 if (fni_ != NULL) {
4427 fni_->Infer(); 4444 fni_->Infer();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4459 4476
4460 int pos = peek_position(); 4477 int pos = peek_position();
4461 Expect(Token::MOD, CHECK_OK); 4478 Expect(Token::MOD, CHECK_OK);
4462 // Allow "eval" or "arguments" for backward compatibility. 4479 // Allow "eval" or "arguments" for backward compatibility.
4463 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers, 4480 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers,
4464 CHECK_OK); 4481 CHECK_OK);
4465 Scanner::Location spread_pos; 4482 Scanner::Location spread_pos;
4466 ExpressionClassifier classifier; 4483 ExpressionClassifier classifier;
4467 ZoneList<Expression*>* args = 4484 ZoneList<Expression*>* args =
4468 ParseArguments(&spread_pos, &classifier, CHECK_OK); 4485 ParseArguments(&spread_pos, &classifier, CHECK_OK);
4469 // TODO(dslomov): report error if not a valid expression. 4486 ValidateExpression(&classifier, CHECK_OK);
4470 4487
4471 DCHECK(!spread_pos.IsValid()); 4488 DCHECK(!spread_pos.IsValid());
4472 4489
4473 if (extension_ != NULL) { 4490 if (extension_ != NULL) {
4474 // The extension structures are only accessible while parsing the 4491 // The extension structures are only accessible while parsing the
4475 // very first time not when reparsing because of lazy compilation. 4492 // very first time not when reparsing because of lazy compilation.
4476 scope_->DeclarationScope()->ForceEagerCompilation(); 4493 scope_->DeclarationScope()->ForceEagerCompilation();
4477 } 4494 }
4478 4495
4479 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4496 const Runtime::Function* function = Runtime::FunctionForName(name->string());
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
5836 5853
5837 Expression* Parser::SpreadCallNew(Expression* function, 5854 Expression* Parser::SpreadCallNew(Expression* function,
5838 ZoneList<v8::internal::Expression*>* args, 5855 ZoneList<v8::internal::Expression*>* args,
5839 int pos) { 5856 int pos) {
5840 args->InsertAt(0, function, zone()); 5857 args->InsertAt(0, function, zone());
5841 5858
5842 return factory()->NewCallRuntime( 5859 return factory()->NewCallRuntime(
5843 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5860 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5844 } 5861 }
5845 } } // namespace v8::internal 5862 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/preparser.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698