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

Side by Side Diff: src/parser.cc

Issue 1065983005: Introduce "expression classifier" to the parser. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
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 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 result = ParseFunctionDeclaration(&names, CHECK_OK); 1604 result = ParseFunctionDeclaration(&names, CHECK_OK);
1605 break; 1605 break;
1606 1606
1607 case Token::CLASS: 1607 case Token::CLASS:
1608 // TODO(ES6): Support parsing anonymous class declarations here. 1608 // TODO(ES6): Support parsing anonymous class declarations here.
1609 result = ParseClassDeclaration(&names, CHECK_OK); 1609 result = ParseClassDeclaration(&names, CHECK_OK);
1610 break; 1610 break;
1611 1611
1612 default: { 1612 default: {
1613 int pos = peek_position(); 1613 int pos = peek_position();
1614 Expression* expr = ParseAssignmentExpression(true, CHECK_OK); 1614 ExpressionClassifier classifier;
1615 Expression* expr = ParseAssignmentExpression(true, &classifier, CHECK_OK);
1616 // TODO(dslomov): report error if not a valid expression.
1617
1615 ExpectSemicolon(CHECK_OK); 1618 ExpectSemicolon(CHECK_OK);
1616 result = factory()->NewExpressionStatement(expr, pos); 1619 result = factory()->NewExpressionStatement(expr, pos);
1617 break; 1620 break;
1618 } 1621 }
1619 } 1622 }
1620 1623
1621 const AstRawString* default_string = ast_value_factory()->default_string(); 1624 const AstRawString* default_string = ast_value_factory()->default_string();
1622 1625
1623 DCHECK_LE(names.length(), 1); 1626 DCHECK_LE(names.length(), 1);
1624 if (names.length() == 1) { 1627 if (names.length() == 1) {
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 // Declare() call above). 2421 // Declare() call above).
2419 2422
2420 Scope* initialization_scope = is_const ? declaration_scope : scope_; 2423 Scope* initialization_scope = is_const ? declaration_scope : scope_;
2421 Expression* value = NULL; 2424 Expression* value = NULL;
2422 int pos = -1; 2425 int pos = -1;
2423 // Harmony consts have non-optional initializers. 2426 // Harmony consts have non-optional initializers.
2424 if (peek() == Token::ASSIGN || 2427 if (peek() == Token::ASSIGN ||
2425 (mode == CONST && !is_for_iteration_variable)) { 2428 (mode == CONST && !is_for_iteration_variable)) {
2426 Expect(Token::ASSIGN, CHECK_OK); 2429 Expect(Token::ASSIGN, CHECK_OK);
2427 pos = position(); 2430 pos = position();
2428 value = ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); 2431 ExpressionClassifier classifier;
2432 value = ParseAssignmentExpression(var_context != kForStatement,
2433 &classifier, CHECK_OK);
2434 // TODO(dslomov): check that expression is valid.
2429 variable_loc.end_pos = scanner()->location().end_pos; 2435 variable_loc.end_pos = scanner()->location().end_pos;
2430 2436
2431 if (first_initializer_loc && !first_initializer_loc->IsValid()) { 2437 if (first_initializer_loc && !first_initializer_loc->IsValid()) {
2432 *first_initializer_loc = variable_loc; 2438 *first_initializer_loc = variable_loc;
2433 } 2439 }
2434 2440
2435 // Don't infer if it is "a = function(){...}();"-like expression. 2441 // Don't infer if it is "a = function(){...}();"-like expression.
2436 if (fni_ != NULL && 2442 if (fni_ != NULL &&
2437 value->AsCall() == NULL && 2443 value->AsCall() == NULL &&
2438 value->AsCallNew() == NULL) { 2444 value->AsCallNew() == NULL) {
(...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after
4330 if (name != NULL) { 4336 if (name != NULL) {
4331 proxy = NewUnresolved(name, CONST); 4337 proxy = NewUnresolved(name, CONST);
4332 Declaration* declaration = 4338 Declaration* declaration =
4333 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos); 4339 factory()->NewVariableDeclaration(proxy, CONST, block_scope, pos);
4334 Declare(declaration, true, CHECK_OK); 4340 Declare(declaration, true, CHECK_OK);
4335 } 4341 }
4336 4342
4337 Expression* extends = NULL; 4343 Expression* extends = NULL;
4338 if (Check(Token::EXTENDS)) { 4344 if (Check(Token::EXTENDS)) {
4339 block_scope->set_start_position(scanner()->location().end_pos); 4345 block_scope->set_start_position(scanner()->location().end_pos);
4340 extends = ParseLeftHandSideExpression(CHECK_OK); 4346 ExpressionClassifier classifier;
4347 extends = ParseLeftHandSideExpression(&classifier, CHECK_OK);
4348 // TODO(dslomov): report error if not a valid expression.
4341 } else { 4349 } else {
4342 block_scope->set_start_position(scanner()->location().end_pos); 4350 block_scope->set_start_position(scanner()->location().end_pos);
4343 } 4351 }
4344 4352
4345 4353
4346 ClassLiteralChecker checker(this); 4354 ClassLiteralChecker checker(this);
4347 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone()); 4355 ZoneList<ObjectLiteral::Property*>* properties = NewPropertyList(4, zone());
4348 FunctionLiteral* constructor = NULL; 4356 FunctionLiteral* constructor = NULL;
4349 bool has_seen_constructor = false; 4357 bool has_seen_constructor = false;
4350 4358
4351 Expect(Token::LBRACE, CHECK_OK); 4359 Expect(Token::LBRACE, CHECK_OK);
4352 4360
4353 const bool has_extends = extends != nullptr; 4361 const bool has_extends = extends != nullptr;
4354 while (peek() != Token::RBRACE) { 4362 while (peek() != Token::RBRACE) {
4355 if (Check(Token::SEMICOLON)) continue; 4363 if (Check(Token::SEMICOLON)) continue;
4356 if (fni_ != NULL) fni_->Enter(); 4364 if (fni_ != NULL) fni_->Enter();
4357 const bool in_class = true; 4365 const bool in_class = true;
4358 const bool is_static = false; 4366 const bool is_static = false;
4359 bool is_computed_name = false; // Classes do not care about computed 4367 bool is_computed_name = false; // Classes do not care about computed
4360 // property names here. 4368 // property names here.
4369 ExpressionClassifier classifier;
4361 ObjectLiteral::Property* property = ParsePropertyDefinition( 4370 ObjectLiteral::Property* property = ParsePropertyDefinition(
4362 &checker, in_class, has_extends, is_static, &is_computed_name, 4371 &checker, in_class, has_extends, is_static, &is_computed_name,
4363 &has_seen_constructor, CHECK_OK); 4372 &has_seen_constructor, &classifier, CHECK_OK);
4373 // TODO(dslomov): report error if not a valid expression.
4364 4374
4365 if (has_seen_constructor && constructor == NULL) { 4375 if (has_seen_constructor && constructor == NULL) {
4366 constructor = GetPropertyValue(property)->AsFunctionLiteral(); 4376 constructor = GetPropertyValue(property)->AsFunctionLiteral();
4367 DCHECK_NOT_NULL(constructor); 4377 DCHECK_NOT_NULL(constructor);
4368 } else { 4378 } else {
4369 properties->Add(property, zone()); 4379 properties->Add(property, zone());
4370 } 4380 }
4371 4381
4372 if (fni_ != NULL) { 4382 if (fni_ != NULL) {
4373 fni_->Infer(); 4383 fni_->Infer();
(...skipping 28 matching lines...) Expand all
4402 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4412 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4403 // CallRuntime :: 4413 // CallRuntime ::
4404 // '%' Identifier Arguments 4414 // '%' Identifier Arguments
4405 4415
4406 int pos = peek_position(); 4416 int pos = peek_position();
4407 Expect(Token::MOD, CHECK_OK); 4417 Expect(Token::MOD, CHECK_OK);
4408 // Allow "eval" or "arguments" for backward compatibility. 4418 // Allow "eval" or "arguments" for backward compatibility.
4409 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers, 4419 const AstRawString* name = ParseIdentifier(kAllowRestrictedIdentifiers,
4410 CHECK_OK); 4420 CHECK_OK);
4411 Scanner::Location spread_pos; 4421 Scanner::Location spread_pos;
4412 ZoneList<Expression*>* args = ParseArguments(&spread_pos, CHECK_OK); 4422 ExpressionClassifier classifier;
4423 ZoneList<Expression*>* args =
4424 ParseArguments(&spread_pos, &classifier, CHECK_OK);
4425 // TODO(dslomov): report error if not a valid expression.
4413 4426
4414 DCHECK(!spread_pos.IsValid()); 4427 DCHECK(!spread_pos.IsValid());
4415 4428
4416 if (extension_ != NULL) { 4429 if (extension_ != NULL) {
4417 // The extension structures are only accessible while parsing the 4430 // The extension structures are only accessible while parsing the
4418 // very first time not when reparsing because of lazy compilation. 4431 // very first time not when reparsing because of lazy compilation.
4419 scope_->DeclarationScope()->ForceEagerCompilation(); 4432 scope_->DeclarationScope()->ForceEagerCompilation();
4420 } 4433 }
4421 4434
4422 const Runtime::Function* function = Runtime::FunctionForName(name->string()); 4435 const Runtime::Function* function = Runtime::FunctionForName(name->string());
(...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after
5779 5792
5780 Expression* Parser::SpreadCallNew(Expression* function, 5793 Expression* Parser::SpreadCallNew(Expression* function,
5781 ZoneList<v8::internal::Expression*>* args, 5794 ZoneList<v8::internal::Expression*>* args,
5782 int pos) { 5795 int pos) {
5783 args->InsertAt(0, function, zone()); 5796 args->InsertAt(0, function, zone());
5784 5797
5785 return factory()->NewCallRuntime( 5798 return factory()->NewCallRuntime(
5786 ast_value_factory()->reflect_construct_string(), NULL, args, pos); 5799 ast_value_factory()->reflect_construct_string(), NULL, args, pos);
5787 } 5800 }
5788 } } // namespace v8::internal 5801 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/preparser.h » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698