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

Side by Side Diff: src/parser.cc

Issue 9187005: Enable optimization of top-level code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: fixed problem with eval code, addressed comments Created 8 years, 10 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 factory_(isolate) { 496 factory_(isolate) {
497 parser->top_scope_ = scope; 497 parser->top_scope_ = scope;
498 parser->current_function_state_ = this; 498 parser->current_function_state_ = this;
499 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1); 499 isolate->set_ast_node_id(AstNode::kDeclarationsId + 1);
500 } 500 }
501 501
502 502
503 Parser::FunctionState::~FunctionState() { 503 Parser::FunctionState::~FunctionState() {
504 parser_->top_scope_ = outer_scope_; 504 parser_->top_scope_ = outer_scope_;
505 parser_->current_function_state_ = outer_function_state_; 505 parser_->current_function_state_ = outer_function_state_;
506 parser_->isolate()->set_ast_node_id(saved_ast_node_id_); 506 if (outer_function_state_ != NULL) {
507 parser_->isolate()->set_ast_node_id(saved_ast_node_id_);
508 }
507 } 509 }
508 510
509 511
510 // ---------------------------------------------------------------------------- 512 // ----------------------------------------------------------------------------
511 // The CHECK_OK macro is a convenient macro to enforce error 513 // The CHECK_OK macro is a convenient macro to enforce error
512 // handling for functions that may fail (by returning !*ok). 514 // handling for functions that may fail (by returning !*ok).
513 // 515 //
514 // CAUTION: This macro appends extra statements after a call, 516 // CAUTION: This macro appends extra statements after a call,
515 // thus it must never be used where only a single statement 517 // thus it must never be used where only a single statement
516 // is correct (e.g. an if statement branch w/o braces)! 518 // is correct (e.g. an if statement branch w/o braces)!
(...skipping 26 matching lines...) Expand all
543 current_function_state_(NULL), 545 current_function_state_(NULL),
544 target_stack_(NULL), 546 target_stack_(NULL),
545 extension_(extension), 547 extension_(extension),
546 pre_data_(pre_data), 548 pre_data_(pre_data),
547 fni_(NULL), 549 fni_(NULL),
548 allow_natives_syntax_((parser_flags & kAllowNativesSyntax) != 0), 550 allow_natives_syntax_((parser_flags & kAllowNativesSyntax) != 0),
549 allow_lazy_((parser_flags & kAllowLazy) != 0), 551 allow_lazy_((parser_flags & kAllowLazy) != 0),
550 allow_modules_((parser_flags & kAllowModules) != 0), 552 allow_modules_((parser_flags & kAllowModules) != 0),
551 stack_overflow_(false), 553 stack_overflow_(false),
552 parenthesized_function_(false) { 554 parenthesized_function_(false) {
553 AstNode::ResetIds(); 555 isolate_->set_ast_node_id(0);
554 if ((parser_flags & kLanguageModeMask) == EXTENDED_MODE) { 556 if ((parser_flags & kLanguageModeMask) == EXTENDED_MODE) {
555 scanner().SetHarmonyScoping(true); 557 scanner().SetHarmonyScoping(true);
556 } 558 }
557 if ((parser_flags & kAllowModules) != 0) { 559 if ((parser_flags & kAllowModules) != 0) {
558 scanner().SetHarmonyModules(true); 560 scanner().SetHarmonyModules(true);
559 } 561 }
560 } 562 }
561 563
562 564
563 FunctionLiteral* Parser::ParseProgram(CompilationInfo* info) { 565 FunctionLiteral* Parser::ParseProgram(CompilationInfo* info) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 597
596 // Compute the parsing mode. 598 // Compute the parsing mode.
597 mode_ = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY; 599 mode_ = (FLAG_lazy && allow_lazy_) ? PARSE_LAZILY : PARSE_EAGERLY;
598 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 600 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
599 601
600 Handle<String> no_name = isolate()->factory()->empty_symbol(); 602 Handle<String> no_name = isolate()->factory()->empty_symbol();
601 603
602 FunctionLiteral* result = NULL; 604 FunctionLiteral* result = NULL;
603 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); 605 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE);
604 info->SetGlobalScope(scope); 606 info->SetGlobalScope(scope);
605 if (!info->is_global()) { 607 if (!info->is_global() &&
608 (info->shared_info().is_null() || info->shared_info()->is_function())) {
606 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope); 609 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope);
607 scope = NewScope(scope, EVAL_SCOPE); 610 scope = NewScope(scope, EVAL_SCOPE);
608 } 611 }
609 scope->set_start_position(0); 612 scope->set_start_position(0);
610 scope->set_end_position(source->length()); 613 scope->set_end_position(source->length());
611 FunctionState function_state(this, scope, isolate()); 614 FunctionState function_state(this, scope, isolate());
612 top_scope_->SetLanguageMode(info->language_mode()); 615 top_scope_->SetLanguageMode(info->language_mode());
613 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); 616 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16);
614 bool ok = true; 617 bool ok = true;
615 int beg_loc = scanner().location().beg_pos; 618 int beg_loc = scanner().location().beg_pos;
(...skipping 10 matching lines...) Expand all
626 result = factory()->NewFunctionLiteral( 629 result = factory()->NewFunctionLiteral(
627 no_name, 630 no_name,
628 top_scope_, 631 top_scope_,
629 body, 632 body,
630 function_state.materialized_literal_count(), 633 function_state.materialized_literal_count(),
631 function_state.expected_property_count(), 634 function_state.expected_property_count(),
632 function_state.handler_count(), 635 function_state.handler_count(),
633 function_state.only_simple_this_property_assignments(), 636 function_state.only_simple_this_property_assignments(),
634 function_state.this_property_assignments(), 637 function_state.this_property_assignments(),
635 0, 638 0,
636 false, // Does not have duplicate parameters. 639 FunctionLiteral::kNoDuplicateParameters,
637 FunctionLiteral::ANONYMOUS_EXPRESSION, 640 FunctionLiteral::ANONYMOUS_EXPRESSION,
638 false); // Top-level literal doesn't count for the AST's properties. 641 FunctionLiteral::kGlobalOrEval);
639 result->set_ast_properties(factory()->visitor()->ast_properties()); 642 result->set_ast_properties(factory()->visitor()->ast_properties());
640 } else if (stack_overflow_) { 643 } else if (stack_overflow_) {
641 isolate()->StackOverflow(); 644 isolate()->StackOverflow();
642 } 645 }
643 } 646 }
644 647
645 // Make sure the target stack is empty. 648 // Make sure the target stack is empty.
646 ASSERT(target_stack_ == NULL); 649 ASSERT(target_stack_ == NULL);
647 650
648 // If there was a syntax error we have to get rid of the AST 651 // If there was a syntax error we have to get rid of the AST
(...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 // are not hoisted. 4011 // are not hoisted.
4009 Scope* scope = (type == FunctionLiteral::DECLARATION && !is_extended_mode()) 4012 Scope* scope = (type == FunctionLiteral::DECLARATION && !is_extended_mode())
4010 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE) 4013 ? NewScope(top_scope_->DeclarationScope(), FUNCTION_SCOPE)
4011 : NewScope(top_scope_, FUNCTION_SCOPE); 4014 : NewScope(top_scope_, FUNCTION_SCOPE);
4012 ZoneList<Statement*>* body = NULL; 4015 ZoneList<Statement*>* body = NULL;
4013 int materialized_literal_count = -1; 4016 int materialized_literal_count = -1;
4014 int expected_property_count = -1; 4017 int expected_property_count = -1;
4015 int handler_count = 0; 4018 int handler_count = 0;
4016 bool only_simple_this_property_assignments; 4019 bool only_simple_this_property_assignments;
4017 Handle<FixedArray> this_property_assignments; 4020 Handle<FixedArray> this_property_assignments;
4018 bool has_duplicate_parameters = false; 4021 FunctionLiteral::ParameterFlag duplicate_parameters =
4022 FunctionLiteral::kNoDuplicateParameters;
4019 AstProperties ast_properties; 4023 AstProperties ast_properties;
4020 // Parse function body. 4024 // Parse function body.
4021 { FunctionState function_state(this, scope, isolate()); 4025 { FunctionState function_state(this, scope, isolate());
4022 top_scope_->SetScopeName(function_name); 4026 top_scope_->SetScopeName(function_name);
4023 4027
4024 // FormalParameterList :: 4028 // FormalParameterList ::
4025 // '(' (Identifier)*[','] ')' 4029 // '(' (Identifier)*[','] ')'
4026 Expect(Token::LPAREN, CHECK_OK); 4030 Expect(Token::LPAREN, CHECK_OK);
4027 scope->set_start_position(scanner().location().beg_pos); 4031 scope->set_start_position(scanner().location().beg_pos);
4028 Scanner::Location name_loc = Scanner::Location::invalid(); 4032 Scanner::Location name_loc = Scanner::Location::invalid();
4029 Scanner::Location dupe_loc = Scanner::Location::invalid(); 4033 Scanner::Location dupe_loc = Scanner::Location::invalid();
4030 Scanner::Location reserved_loc = Scanner::Location::invalid(); 4034 Scanner::Location reserved_loc = Scanner::Location::invalid();
4031 4035
4032 bool done = (peek() == Token::RPAREN); 4036 bool done = (peek() == Token::RPAREN);
4033 while (!done) { 4037 while (!done) {
4034 bool is_strict_reserved = false; 4038 bool is_strict_reserved = false;
4035 Handle<String> param_name = 4039 Handle<String> param_name =
4036 ParseIdentifierOrStrictReservedWord(&is_strict_reserved, 4040 ParseIdentifierOrStrictReservedWord(&is_strict_reserved,
4037 CHECK_OK); 4041 CHECK_OK);
4038 4042
4039 // Store locations for possible future error reports. 4043 // Store locations for possible future error reports.
4040 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) { 4044 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) {
4041 name_loc = scanner().location(); 4045 name_loc = scanner().location();
4042 } 4046 }
4043 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { 4047 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) {
4044 has_duplicate_parameters = true; 4048 duplicate_parameters = FunctionLiteral::kHasDuplicateParameters;
4045 dupe_loc = scanner().location(); 4049 dupe_loc = scanner().location();
4046 } 4050 }
4047 if (!reserved_loc.IsValid() && is_strict_reserved) { 4051 if (!reserved_loc.IsValid() && is_strict_reserved) {
4048 reserved_loc = scanner().location(); 4052 reserved_loc = scanner().location();
4049 } 4053 }
4050 4054
4051 top_scope_->DeclareParameter(param_name, is_extended_mode() ? LET : VAR); 4055 top_scope_->DeclareParameter(param_name, is_extended_mode() ? LET : VAR);
4052 num_parameters++; 4056 num_parameters++;
4053 if (num_parameters > kMaxNumFunctionParameters) { 4057 if (num_parameters > kMaxNumFunctionParameters) {
4054 ReportMessageAt(scanner().location(), "too_many_parameters", 4058 ReportMessageAt(scanner().location(), "too_many_parameters",
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
4245 FunctionLiteral* function_literal = 4249 FunctionLiteral* function_literal =
4246 factory()->NewFunctionLiteral(function_name, 4250 factory()->NewFunctionLiteral(function_name,
4247 scope, 4251 scope,
4248 body, 4252 body,
4249 materialized_literal_count, 4253 materialized_literal_count,
4250 expected_property_count, 4254 expected_property_count,
4251 handler_count, 4255 handler_count,
4252 only_simple_this_property_assignments, 4256 only_simple_this_property_assignments,
4253 this_property_assignments, 4257 this_property_assignments,
4254 num_parameters, 4258 num_parameters,
4255 has_duplicate_parameters, 4259 duplicate_parameters,
4256 type, 4260 type,
4257 true); 4261 FunctionLiteral::kIsFunction);
4258 function_literal->set_function_token_position(function_token_position); 4262 function_literal->set_function_token_position(function_token_position);
4259 function_literal->set_ast_properties(&ast_properties); 4263 function_literal->set_ast_properties(&ast_properties);
4260 4264
4261 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal); 4265 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
4262 return function_literal; 4266 return function_literal;
4263 } 4267 }
4264 4268
4265 4269
4266 preparser::PreParser::PreParseResult Parser::LazyParseFunctionLiteral( 4270 preparser::PreParser::PreParseResult Parser::LazyParseFunctionLiteral(
4267 SingletonLogger* logger) { 4271 SingletonLogger* logger) {
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
5587 if (!info->is_native() && FLAG_harmony_modules) { 5591 if (!info->is_native() && FLAG_harmony_modules) {
5588 parsing_flags |= kAllowModules; 5592 parsing_flags |= kAllowModules;
5589 } 5593 }
5590 if (FLAG_allow_natives_syntax || info->is_native()) { 5594 if (FLAG_allow_natives_syntax || info->is_native()) {
5591 // We require %identifier(..) syntax. 5595 // We require %identifier(..) syntax.
5592 parsing_flags |= kAllowNativesSyntax; 5596 parsing_flags |= kAllowNativesSyntax;
5593 } 5597 }
5594 if (info->is_lazy()) { 5598 if (info->is_lazy()) {
5595 ASSERT(!info->is_eval()); 5599 ASSERT(!info->is_eval());
5596 Parser parser(script, parsing_flags, NULL, NULL); 5600 Parser parser(script, parsing_flags, NULL, NULL);
5597 result = parser.ParseLazy(info); 5601 if (info->shared_info()->is_function()) {
5602 result = parser.ParseLazy(info);
5603 } else {
5604 result = parser.ParseProgram(info);
5605 }
5598 } else { 5606 } else {
5599 ScriptDataImpl* pre_data = info->pre_parse_data(); 5607 ScriptDataImpl* pre_data = info->pre_parse_data();
5600 Parser parser(script, parsing_flags, info->extension(), pre_data); 5608 Parser parser(script, parsing_flags, info->extension(), pre_data);
5601 if (pre_data != NULL && pre_data->has_error()) { 5609 if (pre_data != NULL && pre_data->has_error()) {
5602 Scanner::Location loc = pre_data->MessageLocation(); 5610 Scanner::Location loc = pre_data->MessageLocation();
5603 const char* message = pre_data->BuildMessage(); 5611 const char* message = pre_data->BuildMessage();
5604 Vector<const char*> args = pre_data->BuildArgs(); 5612 Vector<const char*> args = pre_data->BuildArgs();
5605 parser.ReportMessageAt(loc, message, args); 5613 parser.ReportMessageAt(loc, message, args);
5606 DeleteArray(message); 5614 DeleteArray(message);
5607 for (int i = 0; i < args.length(); i++) { 5615 for (int i = 0; i < args.length(); i++) {
5608 DeleteArray(args[i]); 5616 DeleteArray(args[i]);
5609 } 5617 }
5610 DeleteArray(args.start()); 5618 DeleteArray(args.start());
5611 ASSERT(info->isolate()->has_pending_exception()); 5619 ASSERT(info->isolate()->has_pending_exception());
5612 } else { 5620 } else {
5613 result = parser.ParseProgram(info); 5621 result = parser.ParseProgram(info);
5614 } 5622 }
5615 } 5623 }
5616 info->SetFunction(result); 5624 info->SetFunction(result);
5617 return (result != NULL); 5625 return (result != NULL);
5618 } 5626 }
5619 5627
5620 } } // namespace v8::internal 5628 } } // namespace v8::internal
OLDNEW
« src/compiler.cc ('K') | « src/objects-inl.h ('k') | src/runtime-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698