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

Side by Side Diff: src/parser.cc

Issue 10836132: Force eager compilation of parenthesized functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 608
609 609
610 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 610 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
611 Handle<String> source, 611 Handle<String> source,
612 ZoneScope* zone_scope) { 612 ZoneScope* zone_scope) {
613 ASSERT(top_scope_ == NULL); 613 ASSERT(top_scope_ == NULL);
614 ASSERT(target_stack_ == NULL); 614 ASSERT(target_stack_ == NULL);
615 if (pre_data_ != NULL) pre_data_->Initialize(); 615 if (pre_data_ != NULL) pre_data_->Initialize();
616 616
617 // Compute the parsing mode. 617 // Compute the parsing mode.
618 mode_ = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY; 618 Mode mode = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY;
619 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 619 if (allow_natives_syntax_ || extension_ != NULL) mode = PARSE_EAGERLY;
620 ParsingModeScope parsing_mode(this, mode);
620 621
621 Handle<String> no_name = isolate()->factory()->empty_symbol(); 622 Handle<String> no_name = isolate()->factory()->empty_symbol();
622 623
623 FunctionLiteral* result = NULL; 624 FunctionLiteral* result = NULL;
624 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); 625 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE);
625 info->SetGlobalScope(scope); 626 info->SetGlobalScope(scope);
626 if (info->is_eval()) { 627 if (info->is_eval()) {
627 Handle<SharedFunctionInfo> shared = info->shared_info(); 628 Handle<SharedFunctionInfo> shared = info->shared_info();
628 if (!info->is_global() && (shared.is_null() || shared->is_function())) { 629 if (!info->is_global() && (shared.is_null() || shared->is_function())) {
629 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope, 630 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope,
(...skipping 25 matching lines...) Expand all
655 top_scope_, 656 top_scope_,
656 body, 657 body,
657 function_state.materialized_literal_count(), 658 function_state.materialized_literal_count(),
658 function_state.expected_property_count(), 659 function_state.expected_property_count(),
659 function_state.handler_count(), 660 function_state.handler_count(),
660 function_state.only_simple_this_property_assignments(), 661 function_state.only_simple_this_property_assignments(),
661 function_state.this_property_assignments(), 662 function_state.this_property_assignments(),
662 0, 663 0,
663 FunctionLiteral::kNoDuplicateParameters, 664 FunctionLiteral::kNoDuplicateParameters,
664 FunctionLiteral::ANONYMOUS_EXPRESSION, 665 FunctionLiteral::ANONYMOUS_EXPRESSION,
665 FunctionLiteral::kGlobalOrEval); 666 FunctionLiteral::kGlobalOrEval,
667 FunctionLiteral::kNotParenthesized);
666 result->set_ast_properties(factory()->visitor()->ast_properties()); 668 result->set_ast_properties(factory()->visitor()->ast_properties());
667 } else if (stack_overflow_) { 669 } else if (stack_overflow_) {
668 isolate()->StackOverflow(); 670 isolate()->StackOverflow();
669 } 671 }
670 } 672 }
671 673
672 // Make sure the target stack is empty. 674 // Make sure the target stack is empty.
673 ASSERT(target_stack_ == NULL); 675 ASSERT(target_stack_ == NULL);
674 676
675 // If there was a syntax error we have to get rid of the AST 677 // If there was a syntax error we have to get rid of the AST
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ZoneScope* zone_scope) { 718 ZoneScope* zone_scope) {
717 Handle<SharedFunctionInfo> shared_info = info()->shared_info(); 719 Handle<SharedFunctionInfo> shared_info = info()->shared_info();
718 scanner_.Initialize(source); 720 scanner_.Initialize(source);
719 ASSERT(top_scope_ == NULL); 721 ASSERT(top_scope_ == NULL);
720 ASSERT(target_stack_ == NULL); 722 ASSERT(target_stack_ == NULL);
721 723
722 Handle<String> name(String::cast(shared_info->name())); 724 Handle<String> name(String::cast(shared_info->name()));
723 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 725 fni_ = new(zone()) FuncNameInferrer(isolate(), zone());
724 fni_->PushEnclosingName(name); 726 fni_->PushEnclosingName(name);
725 727
726 mode_ = PARSE_EAGERLY; 728 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
727 729
728 // Place holder for the result. 730 // Place holder for the result.
729 FunctionLiteral* result = NULL; 731 FunctionLiteral* result = NULL;
730 732
731 { 733 {
732 // Parse the function literal. 734 // Parse the function literal.
733 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); 735 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE);
734 info()->SetGlobalScope(scope); 736 info()->SetGlobalScope(scope);
735 if (!info()->closure().is_null()) { 737 if (!info()->closure().is_null()) {
736 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, 738 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope,
(...skipping 3743 matching lines...) Expand 10 before | Expand all | Expand 10 after
4480 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) 4482 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE)
4481 : NewScope(top_scope_, FUNCTION_SCOPE); 4483 : NewScope(top_scope_, FUNCTION_SCOPE);
4482 ZoneList<Statement*>* body = NULL; 4484 ZoneList<Statement*>* body = NULL;
4483 int materialized_literal_count = -1; 4485 int materialized_literal_count = -1;
4484 int expected_property_count = -1; 4486 int expected_property_count = -1;
4485 int handler_count = 0; 4487 int handler_count = 0;
4486 bool only_simple_this_property_assignments; 4488 bool only_simple_this_property_assignments;
4487 Handle<FixedArray> this_property_assignments; 4489 Handle<FixedArray> this_property_assignments;
4488 FunctionLiteral::ParameterFlag duplicate_parameters = 4490 FunctionLiteral::ParameterFlag duplicate_parameters =
4489 FunctionLiteral::kNoDuplicateParameters; 4491 FunctionLiteral::kNoDuplicateParameters;
4492 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_
4493 ? FunctionLiteral::kIsParenthesized
4494 : FunctionLiteral::kNotParenthesized;
4490 AstProperties ast_properties; 4495 AstProperties ast_properties;
4491 // Parse function body. 4496 // Parse function body.
4492 { FunctionState function_state(this, scope, isolate()); 4497 { FunctionState function_state(this, scope, isolate());
4493 top_scope_->SetScopeName(function_name); 4498 top_scope_->SetScopeName(function_name);
4494 4499
4495 // FormalParameterList :: 4500 // FormalParameterList ::
4496 // '(' (Identifier)*[','] ')' 4501 // '(' (Identifier)*[','] ')'
4497 Expect(Token::LPAREN, CHECK_OK); 4502 Expect(Token::LPAREN, CHECK_OK);
4498 scope->set_start_position(scanner().location().beg_pos); 4503 scope->set_start_position(scanner().location().beg_pos);
4499 Scanner::Location name_loc = Scanner::Location::invalid(); 4504 Scanner::Location name_loc = Scanner::Location::invalid();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
4628 scope->end_position() - function_block_pos); 4633 scope->end_position() - function_block_pos);
4629 materialized_literal_count = logger.literals(); 4634 materialized_literal_count = logger.literals();
4630 expected_property_count = logger.properties(); 4635 expected_property_count = logger.properties();
4631 top_scope_->SetLanguageMode(logger.language_mode()); 4636 top_scope_->SetLanguageMode(logger.language_mode());
4632 only_simple_this_property_assignments = false; 4637 only_simple_this_property_assignments = false;
4633 this_property_assignments = isolate()->factory()->empty_fixed_array(); 4638 this_property_assignments = isolate()->factory()->empty_fixed_array();
4634 } 4639 }
4635 } 4640 }
4636 4641
4637 if (!is_lazily_compiled) { 4642 if (!is_lazily_compiled) {
4643 ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
4638 body = new(zone()) ZoneList<Statement*>(8, zone()); 4644 body = new(zone()) ZoneList<Statement*>(8, zone());
4639 if (fvar != NULL) { 4645 if (fvar != NULL) {
4640 VariableProxy* fproxy = top_scope_->NewUnresolved( 4646 VariableProxy* fproxy = top_scope_->NewUnresolved(
4641 factory(), function_name, Interface::NewConst()); 4647 factory(), function_name, Interface::NewConst());
4642 fproxy->BindTo(fvar); 4648 fproxy->BindTo(fvar);
4643 body->Add(factory()->NewExpressionStatement( 4649 body->Add(factory()->NewExpressionStatement(
4644 factory()->NewAssignment(fvar_init_op, 4650 factory()->NewAssignment(fvar_init_op,
4645 fproxy, 4651 fproxy,
4646 factory()->NewThisFunction(), 4652 factory()->NewThisFunction(),
4647 RelocInfo::kNoPosition)), 4653 RelocInfo::kNoPosition)),
4648 zone()); 4654 zone());
4649 } 4655 }
4650 ParseSourceElements(body, Token::RBRACE, false, CHECK_OK); 4656 ParseSourceElements(body, Token::RBRACE, false, CHECK_OK);
4651 4657
4652 materialized_literal_count = function_state.materialized_literal_count(); 4658 materialized_literal_count = function_state.materialized_literal_count();
4653 expected_property_count = function_state.expected_property_count(); 4659 expected_property_count = function_state.expected_property_count();
4654 handler_count = function_state.handler_count(); 4660 handler_count = function_state.handler_count();
4655 only_simple_this_property_assignments = 4661 only_simple_this_property_assignments =
4656 function_state.only_simple_this_property_assignments(); 4662 function_state.only_simple_this_property_assignments();
4657 this_property_assignments = function_state.this_property_assignments(); 4663 this_property_assignments = function_state.this_property_assignments();
4658 4664
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4718 scope, 4724 scope,
4719 body, 4725 body,
4720 materialized_literal_count, 4726 materialized_literal_count,
4721 expected_property_count, 4727 expected_property_count,
4722 handler_count, 4728 handler_count,
4723 only_simple_this_property_assignments, 4729 only_simple_this_property_assignments,
4724 this_property_assignments, 4730 this_property_assignments,
4725 num_parameters, 4731 num_parameters,
4726 duplicate_parameters, 4732 duplicate_parameters,
4727 type, 4733 type,
4728 FunctionLiteral::kIsFunction); 4734 FunctionLiteral::kIsFunction,
4735 parenthesized);
4729 function_literal->set_function_token_position(function_token_position); 4736 function_literal->set_function_token_position(function_token_position);
4730 function_literal->set_ast_properties(&ast_properties); 4737 function_literal->set_ast_properties(&ast_properties);
4731 4738
4732 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 4739 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
4733 return function_literal; 4740 return function_literal;
4734 } 4741 }
4735 4742
4736 4743
4737 preparser::PreParser::PreParseResult Parser::LazyParseFunctionLiteral( 4744 preparser::PreParser::PreParseResult Parser::LazyParseFunctionLiteral(
4738 SingletonLogger* logger) { 4745 SingletonLogger* logger) {
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after
6076 ASSERT(info->isolate()->has_pending_exception()); 6083 ASSERT(info->isolate()->has_pending_exception());
6077 } else { 6084 } else {
6078 result = parser.ParseProgram(); 6085 result = parser.ParseProgram();
6079 } 6086 }
6080 } 6087 }
6081 info->SetFunction(result); 6088 info->SetFunction(result);
6082 return (result != NULL); 6089 return (result != NULL);
6083 } 6090 }
6084 6091
6085 } } // namespace v8::internal 6092 } } // namespace v8::internal
OLDNEW
« src/ast.h ('K') | « src/parser.h ('k') | test/cctest/test-func-name-inference.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698