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

Side by Side Diff: src/parser.cc

Issue 10534139: One Zone per CompilationInfo. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename CompilationInfoZone to ZoneWithCompilationInfo Created 8 years, 6 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
« no previous file with comments | « src/parser.h ('k') | src/rewriter.cc » ('j') | no next file with comments »
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 // 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 Isolate* isolate) 486 Isolate* isolate)
487 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), 487 : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
488 next_handler_index_(0), 488 next_handler_index_(0),
489 expected_property_count_(0), 489 expected_property_count_(0),
490 only_simple_this_property_assignments_(false), 490 only_simple_this_property_assignments_(false),
491 this_property_assignments_(isolate->factory()->empty_fixed_array()), 491 this_property_assignments_(isolate->factory()->empty_fixed_array()),
492 parser_(parser), 492 parser_(parser),
493 outer_function_state_(parser->current_function_state_), 493 outer_function_state_(parser->current_function_state_),
494 outer_scope_(parser->top_scope_), 494 outer_scope_(parser->top_scope_),
495 saved_ast_node_id_(isolate->ast_node_id()), 495 saved_ast_node_id_(isolate->ast_node_id()),
496 factory_(isolate) { 496 factory_(isolate, parser->zone()) {
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 if (outer_function_state_ != NULL) { 506 if (outer_function_state_ != NULL) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if ((parser_flags & kLanguageModeMask) == EXTENDED_MODE) { 558 if ((parser_flags & kLanguageModeMask) == EXTENDED_MODE) {
559 scanner().SetHarmonyScoping(true); 559 scanner().SetHarmonyScoping(true);
560 } 560 }
561 if ((parser_flags & kAllowModules) != 0) { 561 if ((parser_flags & kAllowModules) != 0) {
562 scanner().SetHarmonyModules(true); 562 scanner().SetHarmonyModules(true);
563 } 563 }
564 } 564 }
565 565
566 566
567 FunctionLiteral* Parser::ParseProgram(CompilationInfo* info) { 567 FunctionLiteral* Parser::ParseProgram(CompilationInfo* info) {
568 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT); 568 ZoneScope zone_scope(info->zone(), DONT_DELETE_ON_EXIT);
569 569
570 HistogramTimerScope timer(isolate()->counters()->parse()); 570 HistogramTimerScope timer(isolate()->counters()->parse());
571 Handle<String> source(String::cast(script_->source())); 571 Handle<String> source(String::cast(script_->source()));
572 isolate()->counters()->total_parse_size()->Increment(source->length()); 572 isolate()->counters()->total_parse_size()->Increment(source->length());
573 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); 573 fni_ = new(zone()) FuncNameInferrer(isolate(), zone());
574 574
575 // Initialize parser state. 575 // Initialize parser state.
576 source->TryFlatten(); 576 source->TryFlatten();
577 if (source->IsExternalTwoByteString()) { 577 if (source->IsExternalTwoByteString()) {
578 // Notice that the stream is destroyed at the end of the branch block. 578 // Notice that the stream is destroyed at the end of the branch block.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 ASSERT(target_stack_ == NULL); 656 ASSERT(target_stack_ == NULL);
657 657
658 // If there was a syntax error we have to get rid of the AST 658 // If there was a syntax error we have to get rid of the AST
659 // and it is not safe to do so before the scope has been deleted. 659 // and it is not safe to do so before the scope has been deleted.
660 if (result == NULL) zone_scope->DeleteOnExit(); 660 if (result == NULL) zone_scope->DeleteOnExit();
661 return result; 661 return result;
662 } 662 }
663 663
664 664
665 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) { 665 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) {
666 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT); 666 ZoneScope zone_scope(info->zone(), DONT_DELETE_ON_EXIT);
667 HistogramTimerScope timer(isolate()->counters()->parse_lazy()); 667 HistogramTimerScope timer(isolate()->counters()->parse_lazy());
668 Handle<String> source(String::cast(script_->source())); 668 Handle<String> source(String::cast(script_->source()));
669 isolate()->counters()->total_parse_size()->Increment(source->length()); 669 isolate()->counters()->total_parse_size()->Increment(source->length());
670 670
671 Handle<SharedFunctionInfo> shared_info = info->shared_info(); 671 Handle<SharedFunctionInfo> shared_info = info->shared_info();
672 // Initialize parser state. 672 // Initialize parser state.
673 source->TryFlatten(); 673 source->TryFlatten();
674 if (source->IsExternalTwoByteString()) { 674 if (source->IsExternalTwoByteString()) {
675 ExternalTwoByteStringUtf16CharacterStream stream( 675 ExternalTwoByteStringUtf16CharacterStream stream(
676 Handle<ExternalTwoByteString>::cast(source), 676 Handle<ExternalTwoByteString>::cast(source),
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 } 1244 }
1245 } 1245 }
1246 } 1246 }
1247 1247
1248 1248
1249 Block* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { 1249 Block* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) {
1250 // ModuleDeclaration: 1250 // ModuleDeclaration:
1251 // 'module' Identifier Module 1251 // 'module' Identifier Module
1252 1252
1253 // Create new block with one expected declaration. 1253 // Create new block with one expected declaration.
1254 Block* block = factory()->NewBlock(NULL, 1, true, zone()); 1254 Block* block = factory()->NewBlock(NULL, 1, true);
1255 Handle<String> name = ParseIdentifier(CHECK_OK); 1255 Handle<String> name = ParseIdentifier(CHECK_OK);
1256 1256
1257 #ifdef DEBUG 1257 #ifdef DEBUG
1258 if (FLAG_print_interface_details) 1258 if (FLAG_print_interface_details)
1259 PrintF("# Module %s...\n", name->ToAsciiArray()); 1259 PrintF("# Module %s...\n", name->ToAsciiArray());
1260 #endif 1260 #endif
1261 1261
1262 Module* module = ParseModule(CHECK_OK); 1262 Module* module = ParseModule(CHECK_OK);
1263 VariableProxy* proxy = NewUnresolved(name, LET, module->interface()); 1263 VariableProxy* proxy = NewUnresolved(name, LET, module->interface());
1264 Declaration* declaration = 1264 Declaration* declaration =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1307 }
1308 } 1308 }
1309 } 1309 }
1310 1310
1311 1311
1312 Module* Parser::ParseModuleLiteral(bool* ok) { 1312 Module* Parser::ParseModuleLiteral(bool* ok) {
1313 // Module: 1313 // Module:
1314 // '{' ModuleElement '}' 1314 // '{' ModuleElement '}'
1315 1315
1316 // Construct block expecting 16 statements. 1316 // Construct block expecting 16 statements.
1317 Block* body = factory()->NewBlock(NULL, 16, false, zone()); 1317 Block* body = factory()->NewBlock(NULL, 16, false);
1318 #ifdef DEBUG 1318 #ifdef DEBUG
1319 if (FLAG_print_interface_details) PrintF("# Literal "); 1319 if (FLAG_print_interface_details) PrintF("# Literal ");
1320 #endif 1320 #endif
1321 Scope* scope = NewScope(top_scope_, MODULE_SCOPE); 1321 Scope* scope = NewScope(top_scope_, MODULE_SCOPE);
1322 1322
1323 Expect(Token::LBRACE, CHECK_OK); 1323 Expect(Token::LBRACE, CHECK_OK);
1324 scope->set_start_position(scanner().location().beg_pos); 1324 scope->set_start_position(scanner().location().beg_pos);
1325 scope->SetLanguageMode(EXTENDED_MODE); 1325 scope->SetLanguageMode(EXTENDED_MODE);
1326 1326
1327 { 1327 {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 name = ParseIdentifierName(CHECK_OK); 1461 name = ParseIdentifierName(CHECK_OK);
1462 names.Add(name, zone()); 1462 names.Add(name, zone());
1463 } 1463 }
1464 1464
1465 ExpectContextualKeyword("from", CHECK_OK); 1465 ExpectContextualKeyword("from", CHECK_OK);
1466 Module* module = ParseModuleSpecifier(CHECK_OK); 1466 Module* module = ParseModuleSpecifier(CHECK_OK);
1467 ExpectSemicolon(CHECK_OK); 1467 ExpectSemicolon(CHECK_OK);
1468 1468
1469 // Generate a separate declaration for each identifier. 1469 // Generate a separate declaration for each identifier.
1470 // TODO(ES6): once we implement destructuring, make that one declaration. 1470 // TODO(ES6): once we implement destructuring, make that one declaration.
1471 Block* block = factory()->NewBlock(NULL, 1, true, zone()); 1471 Block* block = factory()->NewBlock(NULL, 1, true);
1472 for (int i = 0; i < names.length(); ++i) { 1472 for (int i = 0; i < names.length(); ++i) {
1473 #ifdef DEBUG 1473 #ifdef DEBUG
1474 if (FLAG_print_interface_details) 1474 if (FLAG_print_interface_details)
1475 PrintF("# Import %s ", names[i]->ToAsciiArray()); 1475 PrintF("# Import %s ", names[i]->ToAsciiArray());
1476 #endif 1476 #endif
1477 Interface* interface = Interface::NewUnknown(zone()); 1477 Interface* interface = Interface::NewUnknown(zone());
1478 module->interface()->Add(names[i], interface, zone(), ok); 1478 module->interface()->Add(names[i], interface, zone(), ok);
1479 if (!*ok) { 1479 if (!*ok) {
1480 #ifdef DEBUG 1480 #ifdef DEBUG
1481 if (FLAG_print_interfaces) { 1481 if (FLAG_print_interfaces) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 case Token::THROW: 1676 case Token::THROW:
1677 stmt = ParseThrowStatement(ok); 1677 stmt = ParseThrowStatement(ok);
1678 break; 1678 break;
1679 1679
1680 case Token::TRY: { 1680 case Token::TRY: {
1681 // NOTE: It is somewhat complicated to have labels on 1681 // NOTE: It is somewhat complicated to have labels on
1682 // try-statements. When breaking out of a try-finally statement, 1682 // try-statements. When breaking out of a try-finally statement,
1683 // one must take great care not to treat it as a 1683 // one must take great care not to treat it as a
1684 // fall-through. It is much easier just to wrap the entire 1684 // fall-through. It is much easier just to wrap the entire
1685 // try-statement in a statement block and put the labels there 1685 // try-statement in a statement block and put the labels there
1686 Block* result = factory()->NewBlock(labels, 1, false, zone()); 1686 Block* result = factory()->NewBlock(labels, 1, false);
1687 Target target(&this->target_stack_, result); 1687 Target target(&this->target_stack_, result);
1688 TryStatement* statement = ParseTryStatement(CHECK_OK); 1688 TryStatement* statement = ParseTryStatement(CHECK_OK);
1689 if (statement) { 1689 if (statement) {
1690 statement->set_statement_pos(statement_pos); 1690 statement->set_statement_pos(statement_pos);
1691 } 1691 }
1692 if (result) result->AddStatement(statement, zone()); 1692 if (result) result->AddStatement(statement, zone());
1693 return result; 1693 return result;
1694 } 1694 }
1695 1695
1696 case Token::FUNCTION: { 1696 case Token::FUNCTION: {
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1989 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1989 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1990 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); 1990 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok);
1991 1991
1992 // Block :: 1992 // Block ::
1993 // '{' Statement* '}' 1993 // '{' Statement* '}'
1994 1994
1995 // Note that a Block does not introduce a new execution scope! 1995 // Note that a Block does not introduce a new execution scope!
1996 // (ECMA-262, 3rd, 12.2) 1996 // (ECMA-262, 3rd, 12.2)
1997 // 1997 //
1998 // Construct block expecting 16 statements. 1998 // Construct block expecting 16 statements.
1999 Block* result = factory()->NewBlock(labels, 16, false, zone()); 1999 Block* result = factory()->NewBlock(labels, 16, false);
2000 Target target(&this->target_stack_, result); 2000 Target target(&this->target_stack_, result);
2001 Expect(Token::LBRACE, CHECK_OK); 2001 Expect(Token::LBRACE, CHECK_OK);
2002 InitializationBlockFinder block_finder(top_scope_, target_stack_); 2002 InitializationBlockFinder block_finder(top_scope_, target_stack_);
2003 while (peek() != Token::RBRACE) { 2003 while (peek() != Token::RBRACE) {
2004 Statement* stat = ParseStatement(NULL, CHECK_OK); 2004 Statement* stat = ParseStatement(NULL, CHECK_OK);
2005 if (stat && !stat->IsEmpty()) { 2005 if (stat && !stat->IsEmpty()) {
2006 result->AddStatement(stat, zone()); 2006 result->AddStatement(stat, zone());
2007 block_finder.Update(stat); 2007 block_finder.Update(stat);
2008 } 2008 }
2009 } 2009 }
2010 Expect(Token::RBRACE, CHECK_OK); 2010 Expect(Token::RBRACE, CHECK_OK);
2011 return result; 2011 return result;
2012 } 2012 }
2013 2013
2014 2014
2015 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 2015 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) {
2016 // The harmony mode uses block elements instead of statements. 2016 // The harmony mode uses block elements instead of statements.
2017 // 2017 //
2018 // Block :: 2018 // Block ::
2019 // '{' BlockElement* '}' 2019 // '{' BlockElement* '}'
2020 2020
2021 // Construct block expecting 16 statements. 2021 // Construct block expecting 16 statements.
2022 Block* body = factory()->NewBlock(labels, 16, false, zone()); 2022 Block* body = factory()->NewBlock(labels, 16, false);
2023 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); 2023 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE);
2024 2024
2025 // Parse the statements and collect escaping labels. 2025 // Parse the statements and collect escaping labels.
2026 Expect(Token::LBRACE, CHECK_OK); 2026 Expect(Token::LBRACE, CHECK_OK);
2027 block_scope->set_start_position(scanner().location().beg_pos); 2027 block_scope->set_start_position(scanner().location().beg_pos);
2028 { BlockState block_state(this, block_scope); 2028 { BlockState block_state(this, block_scope);
2029 TargetCollector collector(zone()); 2029 TargetCollector collector(zone());
2030 Target target(&this->target_stack_, &collector); 2030 Target target(&this->target_stack_, &collector);
2031 Target target_body(&this->target_stack_, body); 2031 Target target_body(&this->target_stack_, body);
2032 InitializationBlockFinder block_finder(top_scope_, target_stack_); 2032 InitializationBlockFinder block_finder(top_scope_, target_stack_);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 // Scope declaration, and rewrite the source-level initialization into an 2169 // Scope declaration, and rewrite the source-level initialization into an
2170 // assignment statement. We use a block to collect multiple assignments. 2170 // assignment statement. We use a block to collect multiple assignments.
2171 // 2171 //
2172 // We mark the block as initializer block because we don't want the 2172 // We mark the block as initializer block because we don't want the
2173 // rewriter to add a '.result' assignment to such a block (to get compliant 2173 // rewriter to add a '.result' assignment to such a block (to get compliant
2174 // behavior for code such as print(eval('var x = 7')), and for cosmetic 2174 // behavior for code such as print(eval('var x = 7')), and for cosmetic
2175 // reasons when pretty-printing. Also, unless an assignment (initialization) 2175 // reasons when pretty-printing. Also, unless an assignment (initialization)
2176 // is inside an initializer block, it is ignored. 2176 // is inside an initializer block, it is ignored.
2177 // 2177 //
2178 // Create new block with one expected declaration. 2178 // Create new block with one expected declaration.
2179 Block* block = factory()->NewBlock(NULL, 1, true, zone()); 2179 Block* block = factory()->NewBlock(NULL, 1, true);
2180 int nvars = 0; // the number of variables declared 2180 int nvars = 0; // the number of variables declared
2181 Handle<String> name; 2181 Handle<String> name;
2182 do { 2182 do {
2183 if (fni_ != NULL) fni_->Enter(); 2183 if (fni_ != NULL) fni_->Enter();
2184 2184
2185 // Parse variable name. 2185 // Parse variable name.
2186 if (nvars > 0) Consume(Token::COMMA); 2186 if (nvars > 0) Consume(Token::COMMA);
2187 name = ParseIdentifier(CHECK_OK); 2187 name = ParseIdentifier(CHECK_OK);
2188 if (fni_ != NULL) fni_->PushVariableName(name); 2188 if (fni_ != NULL) fni_->PushVariableName(name);
2189 2189
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2780 // to: 2780 // to:
2781 // 'try { try B0 catch B1 } finally B2' 2781 // 'try { try B0 catch B1 } finally B2'
2782 2782
2783 if (catch_block != NULL && finally_block != NULL) { 2783 if (catch_block != NULL && finally_block != NULL) {
2784 // If we have both, create an inner try/catch. 2784 // If we have both, create an inner try/catch.
2785 ASSERT(catch_scope != NULL && catch_variable != NULL); 2785 ASSERT(catch_scope != NULL && catch_variable != NULL);
2786 int index = current_function_state_->NextHandlerIndex(); 2786 int index = current_function_state_->NextHandlerIndex();
2787 TryCatchStatement* statement = factory()->NewTryCatchStatement( 2787 TryCatchStatement* statement = factory()->NewTryCatchStatement(
2788 index, try_block, catch_scope, catch_variable, catch_block); 2788 index, try_block, catch_scope, catch_variable, catch_block);
2789 statement->set_escaping_targets(try_collector.targets()); 2789 statement->set_escaping_targets(try_collector.targets());
2790 try_block = factory()->NewBlock(NULL, 1, false, zone()); 2790 try_block = factory()->NewBlock(NULL, 1, false);
2791 try_block->AddStatement(statement, zone()); 2791 try_block->AddStatement(statement, zone());
2792 catch_block = NULL; // Clear to indicate it's been handled. 2792 catch_block = NULL; // Clear to indicate it's been handled.
2793 } 2793 }
2794 2794
2795 TryStatement* result = NULL; 2795 TryStatement* result = NULL;
2796 if (catch_block != NULL) { 2796 if (catch_block != NULL) {
2797 ASSERT(finally_block == NULL); 2797 ASSERT(finally_block == NULL);
2798 ASSERT(catch_scope != NULL && catch_variable != NULL); 2798 ASSERT(catch_scope != NULL && catch_variable != NULL);
2799 int index = current_function_state_->NextHandlerIndex(); 2799 int index = current_function_state_->NextHandlerIndex();
2800 result = factory()->NewTryCatchStatement( 2800 result = factory()->NewTryCatchStatement(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); 2886 VariableProxy* each = top_scope_->NewUnresolved(factory(), name);
2887 ForInStatement* loop = factory()->NewForInStatement(labels); 2887 ForInStatement* loop = factory()->NewForInStatement(labels);
2888 Target target(&this->target_stack_, loop); 2888 Target target(&this->target_stack_, loop);
2889 2889
2890 Expect(Token::IN, CHECK_OK); 2890 Expect(Token::IN, CHECK_OK);
2891 Expression* enumerable = ParseExpression(true, CHECK_OK); 2891 Expression* enumerable = ParseExpression(true, CHECK_OK);
2892 Expect(Token::RPAREN, CHECK_OK); 2892 Expect(Token::RPAREN, CHECK_OK);
2893 2893
2894 Statement* body = ParseStatement(NULL, CHECK_OK); 2894 Statement* body = ParseStatement(NULL, CHECK_OK);
2895 loop->Initialize(each, enumerable, body); 2895 loop->Initialize(each, enumerable, body);
2896 Block* result = factory()->NewBlock(NULL, 2, false, zone()); 2896 Block* result = factory()->NewBlock(NULL, 2, false);
2897 result->AddStatement(variable_statement, zone()); 2897 result->AddStatement(variable_statement, zone());
2898 result->AddStatement(loop, zone()); 2898 result->AddStatement(loop, zone());
2899 top_scope_ = saved_scope; 2899 top_scope_ = saved_scope;
2900 for_scope->set_end_position(scanner().location().end_pos); 2900 for_scope->set_end_position(scanner().location().end_pos);
2901 for_scope = for_scope->FinalizeBlockScope(); 2901 for_scope = for_scope->FinalizeBlockScope();
2902 ASSERT(for_scope == NULL); 2902 ASSERT(for_scope == NULL);
2903 // Parsed for-in loop w/ variable/const declaration. 2903 // Parsed for-in loop w/ variable/const declaration.
2904 return result; 2904 return result;
2905 } else { 2905 } else {
2906 init = variable_statement; 2906 init = variable_statement;
(...skipping 25 matching lines...) Expand all
2932 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); 2932 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
2933 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); 2933 VariableProxy* each = top_scope_->NewUnresolved(factory(), name);
2934 ForInStatement* loop = factory()->NewForInStatement(labels); 2934 ForInStatement* loop = factory()->NewForInStatement(labels);
2935 Target target(&this->target_stack_, loop); 2935 Target target(&this->target_stack_, loop);
2936 2936
2937 Expect(Token::IN, CHECK_OK); 2937 Expect(Token::IN, CHECK_OK);
2938 Expression* enumerable = ParseExpression(true, CHECK_OK); 2938 Expression* enumerable = ParseExpression(true, CHECK_OK);
2939 Expect(Token::RPAREN, CHECK_OK); 2939 Expect(Token::RPAREN, CHECK_OK);
2940 2940
2941 Statement* body = ParseStatement(NULL, CHECK_OK); 2941 Statement* body = ParseStatement(NULL, CHECK_OK);
2942 Block* body_block = factory()->NewBlock(NULL, 3, false, zone()); 2942 Block* body_block = factory()->NewBlock(NULL, 3, false);
2943 Assignment* assignment = factory()->NewAssignment( 2943 Assignment* assignment = factory()->NewAssignment(
2944 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); 2944 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition);
2945 Statement* assignment_statement = 2945 Statement* assignment_statement =
2946 factory()->NewExpressionStatement(assignment); 2946 factory()->NewExpressionStatement(assignment);
2947 body_block->AddStatement(variable_statement, zone()); 2947 body_block->AddStatement(variable_statement, zone());
2948 body_block->AddStatement(assignment_statement, zone()); 2948 body_block->AddStatement(assignment_statement, zone());
2949 body_block->AddStatement(body, zone()); 2949 body_block->AddStatement(body, zone());
2950 loop->Initialize(temp_proxy, enumerable, body_block); 2950 loop->Initialize(temp_proxy, enumerable, body_block);
2951 top_scope_ = saved_scope; 2951 top_scope_ = saved_scope;
2952 for_scope->set_end_position(scanner().location().end_pos); 2952 for_scope->set_end_position(scanner().location().end_pos);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3021 // 3021 //
3022 // for (let x = i; c; n) b 3022 // for (let x = i; c; n) b
3023 // 3023 //
3024 // into 3024 // into
3025 // 3025 //
3026 // { 3026 // {
3027 // let x = i; 3027 // let x = i;
3028 // for (; c; n) b 3028 // for (; c; n) b
3029 // } 3029 // }
3030 ASSERT(init != NULL); 3030 ASSERT(init != NULL);
3031 Block* result = factory()->NewBlock(NULL, 2, false, zone()); 3031 Block* result = factory()->NewBlock(NULL, 2, false);
3032 result->AddStatement(init, zone()); 3032 result->AddStatement(init, zone());
3033 result->AddStatement(loop, zone()); 3033 result->AddStatement(loop, zone());
3034 result->set_scope(for_scope); 3034 result->set_scope(for_scope);
3035 if (loop) loop->Initialize(NULL, cond, next, body); 3035 if (loop) loop->Initialize(NULL, cond, next, body);
3036 return result; 3036 return result;
3037 } else { 3037 } else {
3038 if (loop) loop->Initialize(init, cond, next, body); 3038 if (loop) loop->Initialize(init, cond, next, body);
3039 return loop; 3039 return loop;
3040 } 3040 }
3041 } 3041 }
(...skipping 2017 matching lines...) Expand 10 before | Expand all | Expand 10 after
5059 factory()->NewCallRuntime(constructor, NULL, args); 5059 factory()->NewCallRuntime(constructor, NULL, args);
5060 return factory()->NewThrow(call_constructor, scanner().location().beg_pos); 5060 return factory()->NewThrow(call_constructor, scanner().location().beg_pos);
5061 } 5061 }
5062 5062
5063 // ---------------------------------------------------------------------------- 5063 // ----------------------------------------------------------------------------
5064 // Regular expressions 5064 // Regular expressions
5065 5065
5066 5066
5067 RegExpParser::RegExpParser(FlatStringReader* in, 5067 RegExpParser::RegExpParser(FlatStringReader* in,
5068 Handle<String>* error, 5068 Handle<String>* error,
5069 bool multiline) 5069 bool multiline,
5070 Zone* zone)
5070 : isolate_(Isolate::Current()), 5071 : isolate_(Isolate::Current()),
5072 zone_(zone),
5071 error_(error), 5073 error_(error),
5072 captures_(NULL), 5074 captures_(NULL),
5073 in_(in), 5075 in_(in),
5074 current_(kEndMarker), 5076 current_(kEndMarker),
5075 next_pos_(0), 5077 next_pos_(0),
5076 capture_count_(0), 5078 capture_count_(0),
5077 has_more_(true), 5079 has_more_(true),
5078 multiline_(multiline), 5080 multiline_(multiline),
5079 simple_(false), 5081 simple_(false),
5080 contains_anchor_(false), 5082 contains_anchor_(false),
(...skipping 10 matching lines...) Expand all
5091 return kEndMarker; 5093 return kEndMarker;
5092 } 5094 }
5093 } 5095 }
5094 5096
5095 5097
5096 void RegExpParser::Advance() { 5098 void RegExpParser::Advance() {
5097 if (next_pos_ < in()->length()) { 5099 if (next_pos_ < in()->length()) {
5098 StackLimitCheck check(isolate()); 5100 StackLimitCheck check(isolate());
5099 if (check.HasOverflowed()) { 5101 if (check.HasOverflowed()) {
5100 ReportError(CStrVector(Isolate::kStackOverflowMessage)); 5102 ReportError(CStrVector(Isolate::kStackOverflowMessage));
5101 } else if (isolate()->zone()->excess_allocation()) { 5103 } else if (zone()->excess_allocation()) {
5102 ReportError(CStrVector("Regular expression too large")); 5104 ReportError(CStrVector("Regular expression too large"));
5103 } else { 5105 } else {
5104 current_ = in()->Get(next_pos_); 5106 current_ = in()->Get(next_pos_);
5105 next_pos_++; 5107 next_pos_++;
5106 } 5108 }
5107 } else { 5109 } else {
5108 current_ = kEndMarker; 5110 current_ = kEndMarker;
5109 has_more_ = false; 5111 has_more_ = false;
5110 } 5112 }
5111 } 5113 }
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
5993 if (FLAG_lazy && (extension == NULL)) { 5995 if (FLAG_lazy && (extension == NULL)) {
5994 flags |= kAllowLazy; 5996 flags |= kAllowLazy;
5995 } 5997 }
5996 CompleteParserRecorder recorder; 5998 CompleteParserRecorder recorder;
5997 return DoPreParse(source, flags, &recorder); 5999 return DoPreParse(source, flags, &recorder);
5998 } 6000 }
5999 6001
6000 6002
6001 bool RegExpParser::ParseRegExp(FlatStringReader* input, 6003 bool RegExpParser::ParseRegExp(FlatStringReader* input,
6002 bool multiline, 6004 bool multiline,
6003 RegExpCompileData* result) { 6005 RegExpCompileData* result,
6006 Zone* zone) {
6004 ASSERT(result != NULL); 6007 ASSERT(result != NULL);
6005 RegExpParser parser(input, &result->error, multiline); 6008 RegExpParser parser(input, &result->error, multiline, zone);
6006 RegExpTree* tree = parser.ParsePattern(); 6009 RegExpTree* tree = parser.ParsePattern();
6007 if (parser.failed()) { 6010 if (parser.failed()) {
6008 ASSERT(tree == NULL); 6011 ASSERT(tree == NULL);
6009 ASSERT(!result->error.is_null()); 6012 ASSERT(!result->error.is_null());
6010 } else { 6013 } else {
6011 ASSERT(tree != NULL); 6014 ASSERT(tree != NULL);
6012 ASSERT(result->error.is_null()); 6015 ASSERT(result->error.is_null());
6013 result->tree = tree; 6016 result->tree = tree;
6014 int capture_count = parser.captures_started(); 6017 int capture_count = parser.captures_started();
6015 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; 6018 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
(...skipping 15 matching lines...) Expand all
6031 } 6034 }
6032 if (!info->is_native() && FLAG_harmony_modules) { 6035 if (!info->is_native() && FLAG_harmony_modules) {
6033 parsing_flags |= kAllowModules; 6036 parsing_flags |= kAllowModules;
6034 } 6037 }
6035 if (FLAG_allow_natives_syntax || info->is_native()) { 6038 if (FLAG_allow_natives_syntax || info->is_native()) {
6036 // We require %identifier(..) syntax. 6039 // We require %identifier(..) syntax.
6037 parsing_flags |= kAllowNativesSyntax; 6040 parsing_flags |= kAllowNativesSyntax;
6038 } 6041 }
6039 if (info->is_lazy()) { 6042 if (info->is_lazy()) {
6040 ASSERT(!info->is_eval()); 6043 ASSERT(!info->is_eval());
6041 Parser parser(script, parsing_flags, NULL, NULL, info->isolate()->zone()); 6044 Parser parser(script, parsing_flags, NULL, NULL, info->zone());
6042 if (info->shared_info()->is_function()) { 6045 if (info->shared_info()->is_function()) {
6043 result = parser.ParseLazy(info); 6046 result = parser.ParseLazy(info);
6044 } else { 6047 } else {
6045 result = parser.ParseProgram(info); 6048 result = parser.ParseProgram(info);
6046 } 6049 }
6047 } else { 6050 } else {
6048 ScriptDataImpl* pre_data = info->pre_parse_data(); 6051 ScriptDataImpl* pre_data = info->pre_parse_data();
6049 Parser parser(script, parsing_flags, info->extension(), pre_data, 6052 Parser parser(script, parsing_flags, info->extension(), pre_data,
6050 info->isolate()->zone()); 6053 info->zone());
6051 if (pre_data != NULL && pre_data->has_error()) { 6054 if (pre_data != NULL && pre_data->has_error()) {
6052 Scanner::Location loc = pre_data->MessageLocation(); 6055 Scanner::Location loc = pre_data->MessageLocation();
6053 const char* message = pre_data->BuildMessage(); 6056 const char* message = pre_data->BuildMessage();
6054 Vector<const char*> args = pre_data->BuildArgs(); 6057 Vector<const char*> args = pre_data->BuildArgs();
6055 parser.ReportMessageAt(loc, message, args); 6058 parser.ReportMessageAt(loc, message, args);
6056 DeleteArray(message); 6059 DeleteArray(message);
6057 for (int i = 0; i < args.length(); i++) { 6060 for (int i = 0; i < args.length(); i++) {
6058 DeleteArray(args[i]); 6061 DeleteArray(args[i]);
6059 } 6062 }
6060 DeleteArray(args.start()); 6063 DeleteArray(args.start());
6061 ASSERT(info->isolate()->has_pending_exception()); 6064 ASSERT(info->isolate()->has_pending_exception());
6062 } else { 6065 } else {
6063 result = parser.ParseProgram(info); 6066 result = parser.ParseProgram(info);
6064 } 6067 }
6065 } 6068 }
6066 info->SetFunction(result); 6069 info->SetFunction(result);
6067 return (result != NULL); 6070 return (result != NULL);
6068 } 6071 }
6069 6072
6070 } } // namespace v8::internal 6073 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698