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

Side by Side Diff: src/parser.cc

Issue 10443114: Progress towards making Zones independent of Isolates and Threads. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nits and rebase on current bleeding_edge 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/runtime.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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 private: 81 private:
82 Element* top() { return top_; } 82 Element* top() { return top_; }
83 void set_top(Element* value) { top_ = value; } 83 void set_top(Element* value) { top_ = value; }
84 Element* top_; 84 Element* top_;
85 bool* ok_; 85 bool* ok_;
86 }; 86 };
87 87
88 88
89 RegExpBuilder::RegExpBuilder() 89 RegExpBuilder::RegExpBuilder(Zone* zone)
90 : zone_(Isolate::Current()->zone()), 90 : zone_(zone),
91 pending_empty_(false), 91 pending_empty_(false),
92 characters_(NULL), 92 characters_(NULL),
93 terms_(), 93 terms_(),
94 alternatives_() 94 alternatives_()
95 #ifdef DEBUG 95 #ifdef DEBUG
96 , last_added_(ADD_NONE) 96 , last_added_(ADD_NONE)
97 #endif 97 #endif
98 {} 98 {}
99 99
100 100
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 ((void)0 528 ((void)0
529 #define DUMMY ) // to make indentation work 529 #define DUMMY ) // to make indentation work
530 #undef DUMMY 530 #undef DUMMY
531 531
532 // ---------------------------------------------------------------------------- 532 // ----------------------------------------------------------------------------
533 // Implementation of Parser 533 // Implementation of Parser
534 534
535 Parser::Parser(Handle<Script> script, 535 Parser::Parser(Handle<Script> script,
536 int parser_flags, 536 int parser_flags,
537 v8::Extension* extension, 537 v8::Extension* extension,
538 ScriptDataImpl* pre_data) 538 ScriptDataImpl* pre_data,
539 Zone* zone)
539 : isolate_(script->GetIsolate()), 540 : isolate_(script->GetIsolate()),
540 symbol_cache_(pre_data ? pre_data->symbol_count() : 0), 541 symbol_cache_(pre_data ? pre_data->symbol_count() : 0),
541 script_(script), 542 script_(script),
542 scanner_(isolate_->unicode_cache()), 543 scanner_(isolate_->unicode_cache()),
543 reusable_preparser_(NULL), 544 reusable_preparser_(NULL),
544 top_scope_(NULL), 545 top_scope_(NULL),
545 current_function_state_(NULL), 546 current_function_state_(NULL),
546 target_stack_(NULL), 547 target_stack_(NULL),
547 extension_(extension), 548 extension_(extension),
548 pre_data_(pre_data), 549 pre_data_(pre_data),
549 fni_(NULL), 550 fni_(NULL),
550 allow_natives_syntax_((parser_flags & kAllowNativesSyntax) != 0), 551 allow_natives_syntax_((parser_flags & kAllowNativesSyntax) != 0),
551 allow_lazy_((parser_flags & kAllowLazy) != 0), 552 allow_lazy_((parser_flags & kAllowLazy) != 0),
552 allow_modules_((parser_flags & kAllowModules) != 0), 553 allow_modules_((parser_flags & kAllowModules) != 0),
553 stack_overflow_(false), 554 stack_overflow_(false),
554 parenthesized_function_(false) { 555 parenthesized_function_(false),
556 zone_(zone) {
555 isolate_->set_ast_node_id(0); 557 isolate_->set_ast_node_id(0);
556 if ((parser_flags & kLanguageModeMask) == EXTENDED_MODE) { 558 if ((parser_flags & kLanguageModeMask) == EXTENDED_MODE) {
557 scanner().SetHarmonyScoping(true); 559 scanner().SetHarmonyScoping(true);
558 } 560 }
559 if ((parser_flags & kAllowModules) != 0) { 561 if ((parser_flags & kAllowModules) != 0) {
560 scanner().SetHarmonyModules(true); 562 scanner().SetHarmonyModules(true);
561 } 563 }
562 } 564 }
563 565
564 566
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 { 1320 {
1319 BlockState block_state(this, scope); 1321 BlockState block_state(this, scope);
1320 TargetCollector collector; 1322 TargetCollector collector;
1321 Target target(&this->target_stack_, &collector); 1323 Target target(&this->target_stack_, &collector);
1322 Target target_body(&this->target_stack_, body); 1324 Target target_body(&this->target_stack_, body);
1323 InitializationBlockFinder block_finder(top_scope_, target_stack_); 1325 InitializationBlockFinder block_finder(top_scope_, target_stack_);
1324 1326
1325 while (peek() != Token::RBRACE) { 1327 while (peek() != Token::RBRACE) {
1326 Statement* stat = ParseModuleElement(NULL, CHECK_OK); 1328 Statement* stat = ParseModuleElement(NULL, CHECK_OK);
1327 if (stat && !stat->IsEmpty()) { 1329 if (stat && !stat->IsEmpty()) {
1328 body->AddStatement(stat); 1330 body->AddStatement(stat, zone());
1329 block_finder.Update(stat); 1331 block_finder.Update(stat);
1330 } 1332 }
1331 } 1333 }
1332 } 1334 }
1333 1335
1334 Expect(Token::RBRACE, CHECK_OK); 1336 Expect(Token::RBRACE, CHECK_OK);
1335 scope->set_end_position(scanner().location().end_pos); 1337 scope->set_end_position(scanner().location().end_pos);
1336 body->set_scope(scope); 1338 body->set_scope(scope);
1337 1339
1338 // Instance objects have to be created ahead of time (before code generation 1340 // Instance objects have to be created ahead of time (before code generation
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 // try-statements. When breaking out of a try-finally statement, 1672 // try-statements. When breaking out of a try-finally statement,
1671 // one must take great care not to treat it as a 1673 // one must take great care not to treat it as a
1672 // fall-through. It is much easier just to wrap the entire 1674 // fall-through. It is much easier just to wrap the entire
1673 // try-statement in a statement block and put the labels there 1675 // try-statement in a statement block and put the labels there
1674 Block* result = factory()->NewBlock(labels, 1, false); 1676 Block* result = factory()->NewBlock(labels, 1, false);
1675 Target target(&this->target_stack_, result); 1677 Target target(&this->target_stack_, result);
1676 TryStatement* statement = ParseTryStatement(CHECK_OK); 1678 TryStatement* statement = ParseTryStatement(CHECK_OK);
1677 if (statement) { 1679 if (statement) {
1678 statement->set_statement_pos(statement_pos); 1680 statement->set_statement_pos(statement_pos);
1679 } 1681 }
1680 if (result) result->AddStatement(statement); 1682 if (result) result->AddStatement(statement, zone());
1681 return result; 1683 return result;
1682 } 1684 }
1683 1685
1684 case Token::FUNCTION: { 1686 case Token::FUNCTION: {
1685 // FunctionDeclaration is only allowed in the context of SourceElements 1687 // FunctionDeclaration is only allowed in the context of SourceElements
1686 // (Ecma 262 5th Edition, clause 14): 1688 // (Ecma 262 5th Edition, clause 14):
1687 // SourceElement: 1689 // SourceElement:
1688 // Statement 1690 // Statement
1689 // FunctionDeclaration 1691 // FunctionDeclaration
1690 // Common language extension is to allow function declaration in place 1692 // Common language extension is to allow function declaration in place
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 // (ECMA-262, 3rd, 12.2) 1986 // (ECMA-262, 3rd, 12.2)
1985 // 1987 //
1986 // Construct block expecting 16 statements. 1988 // Construct block expecting 16 statements.
1987 Block* result = factory()->NewBlock(labels, 16, false); 1989 Block* result = factory()->NewBlock(labels, 16, false);
1988 Target target(&this->target_stack_, result); 1990 Target target(&this->target_stack_, result);
1989 Expect(Token::LBRACE, CHECK_OK); 1991 Expect(Token::LBRACE, CHECK_OK);
1990 InitializationBlockFinder block_finder(top_scope_, target_stack_); 1992 InitializationBlockFinder block_finder(top_scope_, target_stack_);
1991 while (peek() != Token::RBRACE) { 1993 while (peek() != Token::RBRACE) {
1992 Statement* stat = ParseStatement(NULL, CHECK_OK); 1994 Statement* stat = ParseStatement(NULL, CHECK_OK);
1993 if (stat && !stat->IsEmpty()) { 1995 if (stat && !stat->IsEmpty()) {
1994 result->AddStatement(stat); 1996 result->AddStatement(stat, zone());
1995 block_finder.Update(stat); 1997 block_finder.Update(stat);
1996 } 1998 }
1997 } 1999 }
1998 Expect(Token::RBRACE, CHECK_OK); 2000 Expect(Token::RBRACE, CHECK_OK);
1999 return result; 2001 return result;
2000 } 2002 }
2001 2003
2002 2004
2003 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { 2005 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) {
2004 // The harmony mode uses block elements instead of statements. 2006 // The harmony mode uses block elements instead of statements.
(...skipping 10 matching lines...) Expand all
2015 block_scope->set_start_position(scanner().location().beg_pos); 2017 block_scope->set_start_position(scanner().location().beg_pos);
2016 { BlockState block_state(this, block_scope); 2018 { BlockState block_state(this, block_scope);
2017 TargetCollector collector; 2019 TargetCollector collector;
2018 Target target(&this->target_stack_, &collector); 2020 Target target(&this->target_stack_, &collector);
2019 Target target_body(&this->target_stack_, body); 2021 Target target_body(&this->target_stack_, body);
2020 InitializationBlockFinder block_finder(top_scope_, target_stack_); 2022 InitializationBlockFinder block_finder(top_scope_, target_stack_);
2021 2023
2022 while (peek() != Token::RBRACE) { 2024 while (peek() != Token::RBRACE) {
2023 Statement* stat = ParseBlockElement(NULL, CHECK_OK); 2025 Statement* stat = ParseBlockElement(NULL, CHECK_OK);
2024 if (stat && !stat->IsEmpty()) { 2026 if (stat && !stat->IsEmpty()) {
2025 body->AddStatement(stat); 2027 body->AddStatement(stat, zone());
2026 block_finder.Update(stat); 2028 block_finder.Update(stat);
2027 } 2029 }
2028 } 2030 }
2029 } 2031 }
2030 Expect(Token::RBRACE, CHECK_OK); 2032 Expect(Token::RBRACE, CHECK_OK);
2031 block_scope->set_end_position(scanner().location().end_pos); 2033 block_scope->set_end_position(scanner().location().end_pos);
2032 block_scope = block_scope->FinalizeBlockScope(); 2034 block_scope = block_scope->FinalizeBlockScope();
2033 body->set_scope(block_scope); 2035 body->set_scope(block_scope);
2034 return body; 2036 return body;
2035 } 2037 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 // Construct the call to Runtime_InitializeVarGlobal 2324 // Construct the call to Runtime_InitializeVarGlobal
2323 // and add it to the initialization statement block. 2325 // and add it to the initialization statement block.
2324 // Note that the function does different things depending on 2326 // Note that the function does different things depending on
2325 // the number of arguments (2 or 3). 2327 // the number of arguments (2 or 3).
2326 initialize = factory()->NewCallRuntime( 2328 initialize = factory()->NewCallRuntime(
2327 isolate()->factory()->InitializeVarGlobal_symbol(), 2329 isolate()->factory()->InitializeVarGlobal_symbol(),
2328 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), 2330 Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
2329 arguments); 2331 arguments);
2330 } 2332 }
2331 2333
2332 block->AddStatement(factory()->NewExpressionStatement(initialize)); 2334 block->AddStatement(factory()->NewExpressionStatement(initialize),
2335 zone());
2333 } else if (needs_init) { 2336 } else if (needs_init) {
2334 // Constant initializations always assign to the declared constant which 2337 // Constant initializations always assign to the declared constant which
2335 // is always at the function scope level. This is only relevant for 2338 // is always at the function scope level. This is only relevant for
2336 // dynamically looked-up variables and constants (the start context for 2339 // dynamically looked-up variables and constants (the start context for
2337 // constant lookups is always the function context, while it is the top 2340 // constant lookups is always the function context, while it is the top
2338 // context for var declared variables). Sigh... 2341 // context for var declared variables). Sigh...
2339 // For 'let' and 'const' declared variables in harmony mode the 2342 // For 'let' and 'const' declared variables in harmony mode the
2340 // initialization also always assigns to the declared variable. 2343 // initialization also always assigns to the declared variable.
2341 ASSERT(proxy != NULL); 2344 ASSERT(proxy != NULL);
2342 ASSERT(proxy->var() != NULL); 2345 ASSERT(proxy->var() != NULL);
2343 ASSERT(value != NULL); 2346 ASSERT(value != NULL);
2344 Assignment* assignment = 2347 Assignment* assignment =
2345 factory()->NewAssignment(init_op, proxy, value, position); 2348 factory()->NewAssignment(init_op, proxy, value, position);
2346 block->AddStatement(factory()->NewExpressionStatement(assignment)); 2349 block->AddStatement(factory()->NewExpressionStatement(assignment),
2350 zone());
2347 value = NULL; 2351 value = NULL;
2348 } 2352 }
2349 2353
2350 // Add an assignment node to the initialization statement block if we still 2354 // Add an assignment node to the initialization statement block if we still
2351 // have a pending initialization value. 2355 // have a pending initialization value.
2352 if (value != NULL) { 2356 if (value != NULL) {
2353 ASSERT(mode == VAR); 2357 ASSERT(mode == VAR);
2354 // 'var' initializations are simply assignments (with all the consequences 2358 // 'var' initializations are simply assignments (with all the consequences
2355 // if they are inside a 'with' statement - they may change a 'with' object 2359 // if they are inside a 'with' statement - they may change a 'with' object
2356 // property). 2360 // property).
2357 VariableProxy* proxy = 2361 VariableProxy* proxy =
2358 initialization_scope->NewUnresolved(factory(), name); 2362 initialization_scope->NewUnresolved(factory(), name);
2359 Assignment* assignment = 2363 Assignment* assignment =
2360 factory()->NewAssignment(init_op, proxy, value, position); 2364 factory()->NewAssignment(init_op, proxy, value, position);
2361 block->AddStatement(factory()->NewExpressionStatement(assignment)); 2365 block->AddStatement(factory()->NewExpressionStatement(assignment),
2366 zone());
2362 } 2367 }
2363 2368
2364 if (fni_ != NULL) fni_->Leave(); 2369 if (fni_ != NULL) fni_->Leave();
2365 } while (peek() == Token::COMMA); 2370 } while (peek() == Token::COMMA);
2366 2371
2367 // If there was a single non-const declaration, return it in the output 2372 // If there was a single non-const declaration, return it in the output
2368 // parameter for possible use by for/in. 2373 // parameter for possible use by for/in.
2369 if (nvars == 1 && !is_const) { 2374 if (nvars == 1 && !is_const) {
2370 *out = name; 2375 *out = name;
2371 } 2376 }
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
2762 // 'try { try B0 catch B1 } finally B2' 2767 // 'try { try B0 catch B1 } finally B2'
2763 2768
2764 if (catch_block != NULL && finally_block != NULL) { 2769 if (catch_block != NULL && finally_block != NULL) {
2765 // If we have both, create an inner try/catch. 2770 // If we have both, create an inner try/catch.
2766 ASSERT(catch_scope != NULL && catch_variable != NULL); 2771 ASSERT(catch_scope != NULL && catch_variable != NULL);
2767 int index = current_function_state_->NextHandlerIndex(); 2772 int index = current_function_state_->NextHandlerIndex();
2768 TryCatchStatement* statement = factory()->NewTryCatchStatement( 2773 TryCatchStatement* statement = factory()->NewTryCatchStatement(
2769 index, try_block, catch_scope, catch_variable, catch_block); 2774 index, try_block, catch_scope, catch_variable, catch_block);
2770 statement->set_escaping_targets(try_collector.targets()); 2775 statement->set_escaping_targets(try_collector.targets());
2771 try_block = factory()->NewBlock(NULL, 1, false); 2776 try_block = factory()->NewBlock(NULL, 1, false);
2772 try_block->AddStatement(statement); 2777 try_block->AddStatement(statement, zone());
2773 catch_block = NULL; // Clear to indicate it's been handled. 2778 catch_block = NULL; // Clear to indicate it's been handled.
2774 } 2779 }
2775 2780
2776 TryStatement* result = NULL; 2781 TryStatement* result = NULL;
2777 if (catch_block != NULL) { 2782 if (catch_block != NULL) {
2778 ASSERT(finally_block == NULL); 2783 ASSERT(finally_block == NULL);
2779 ASSERT(catch_scope != NULL && catch_variable != NULL); 2784 ASSERT(catch_scope != NULL && catch_variable != NULL);
2780 int index = current_function_state_->NextHandlerIndex(); 2785 int index = current_function_state_->NextHandlerIndex();
2781 result = factory()->NewTryCatchStatement( 2786 result = factory()->NewTryCatchStatement(
2782 index, try_block, catch_scope, catch_variable, catch_block); 2787 index, try_block, catch_scope, catch_variable, catch_block);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2868 ForInStatement* loop = factory()->NewForInStatement(labels); 2873 ForInStatement* loop = factory()->NewForInStatement(labels);
2869 Target target(&this->target_stack_, loop); 2874 Target target(&this->target_stack_, loop);
2870 2875
2871 Expect(Token::IN, CHECK_OK); 2876 Expect(Token::IN, CHECK_OK);
2872 Expression* enumerable = ParseExpression(true, CHECK_OK); 2877 Expression* enumerable = ParseExpression(true, CHECK_OK);
2873 Expect(Token::RPAREN, CHECK_OK); 2878 Expect(Token::RPAREN, CHECK_OK);
2874 2879
2875 Statement* body = ParseStatement(NULL, CHECK_OK); 2880 Statement* body = ParseStatement(NULL, CHECK_OK);
2876 loop->Initialize(each, enumerable, body); 2881 loop->Initialize(each, enumerable, body);
2877 Block* result = factory()->NewBlock(NULL, 2, false); 2882 Block* result = factory()->NewBlock(NULL, 2, false);
2878 result->AddStatement(variable_statement); 2883 result->AddStatement(variable_statement, zone());
2879 result->AddStatement(loop); 2884 result->AddStatement(loop, zone());
2880 top_scope_ = saved_scope; 2885 top_scope_ = saved_scope;
2881 for_scope->set_end_position(scanner().location().end_pos); 2886 for_scope->set_end_position(scanner().location().end_pos);
2882 for_scope = for_scope->FinalizeBlockScope(); 2887 for_scope = for_scope->FinalizeBlockScope();
2883 ASSERT(for_scope == NULL); 2888 ASSERT(for_scope == NULL);
2884 // Parsed for-in loop w/ variable/const declaration. 2889 // Parsed for-in loop w/ variable/const declaration.
2885 return result; 2890 return result;
2886 } else { 2891 } else {
2887 init = variable_statement; 2892 init = variable_statement;
2888 } 2893 }
2889 } else if (peek() == Token::LET) { 2894 } else if (peek() == Token::LET) {
(...skipping 28 matching lines...) Expand all
2918 Expect(Token::IN, CHECK_OK); 2923 Expect(Token::IN, CHECK_OK);
2919 Expression* enumerable = ParseExpression(true, CHECK_OK); 2924 Expression* enumerable = ParseExpression(true, CHECK_OK);
2920 Expect(Token::RPAREN, CHECK_OK); 2925 Expect(Token::RPAREN, CHECK_OK);
2921 2926
2922 Statement* body = ParseStatement(NULL, CHECK_OK); 2927 Statement* body = ParseStatement(NULL, CHECK_OK);
2923 Block* body_block = factory()->NewBlock(NULL, 3, false); 2928 Block* body_block = factory()->NewBlock(NULL, 3, false);
2924 Assignment* assignment = factory()->NewAssignment( 2929 Assignment* assignment = factory()->NewAssignment(
2925 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); 2930 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition);
2926 Statement* assignment_statement = 2931 Statement* assignment_statement =
2927 factory()->NewExpressionStatement(assignment); 2932 factory()->NewExpressionStatement(assignment);
2928 body_block->AddStatement(variable_statement); 2933 body_block->AddStatement(variable_statement, zone());
2929 body_block->AddStatement(assignment_statement); 2934 body_block->AddStatement(assignment_statement, zone());
2930 body_block->AddStatement(body); 2935 body_block->AddStatement(body, zone());
2931 loop->Initialize(temp_proxy, enumerable, body_block); 2936 loop->Initialize(temp_proxy, enumerable, body_block);
2932 top_scope_ = saved_scope; 2937 top_scope_ = saved_scope;
2933 for_scope->set_end_position(scanner().location().end_pos); 2938 for_scope->set_end_position(scanner().location().end_pos);
2934 for_scope = for_scope->FinalizeBlockScope(); 2939 for_scope = for_scope->FinalizeBlockScope();
2935 body_block->set_scope(for_scope); 2940 body_block->set_scope(for_scope);
2936 // Parsed for-in loop w/ let declaration. 2941 // Parsed for-in loop w/ let declaration.
2937 return loop; 2942 return loop;
2938 2943
2939 } else { 2944 } else {
2940 init = variable_statement; 2945 init = variable_statement;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 // for (let x = i; c; n) b 3008 // for (let x = i; c; n) b
3004 // 3009 //
3005 // into 3010 // into
3006 // 3011 //
3007 // { 3012 // {
3008 // let x = i; 3013 // let x = i;
3009 // for (; c; n) b 3014 // for (; c; n) b
3010 // } 3015 // }
3011 ASSERT(init != NULL); 3016 ASSERT(init != NULL);
3012 Block* result = factory()->NewBlock(NULL, 2, false); 3017 Block* result = factory()->NewBlock(NULL, 2, false);
3013 result->AddStatement(init); 3018 result->AddStatement(init, zone());
3014 result->AddStatement(loop); 3019 result->AddStatement(loop, zone());
3015 result->set_scope(for_scope); 3020 result->set_scope(for_scope);
3016 if (loop) loop->Initialize(NULL, cond, next, body); 3021 if (loop) loop->Initialize(NULL, cond, next, body);
3017 return result; 3022 return result;
3018 } else { 3023 } else {
3019 if (loop) loop->Initialize(init, cond, next, body); 3024 if (loop) loop->Initialize(init, cond, next, body);
3020 return loop; 3025 return loop;
3021 } 3026 }
3022 } 3027 }
3023 3028
3024 3029
(...skipping 2114 matching lines...) Expand 10 before | Expand all | Expand 10 after
5139 // Alternative | Disjunction 5144 // Alternative | Disjunction
5140 // Alternative :: 5145 // Alternative ::
5141 // [empty] 5146 // [empty]
5142 // Term Alternative 5147 // Term Alternative
5143 // Term :: 5148 // Term ::
5144 // Assertion 5149 // Assertion
5145 // Atom 5150 // Atom
5146 // Atom Quantifier 5151 // Atom Quantifier
5147 RegExpTree* RegExpParser::ParseDisjunction() { 5152 RegExpTree* RegExpParser::ParseDisjunction() {
5148 // Used to store current state while parsing subexpressions. 5153 // Used to store current state while parsing subexpressions.
5149 RegExpParserState initial_state(NULL, INITIAL, 0); 5154 RegExpParserState initial_state(NULL, INITIAL, 0, zone());
5150 RegExpParserState* stored_state = &initial_state; 5155 RegExpParserState* stored_state = &initial_state;
5151 // Cache the builder in a local variable for quick access. 5156 // Cache the builder in a local variable for quick access.
5152 RegExpBuilder* builder = initial_state.builder(); 5157 RegExpBuilder* builder = initial_state.builder();
5153 while (true) { 5158 while (true) {
5154 switch (current()) { 5159 switch (current()) {
5155 case kEndMarker: 5160 case kEndMarker:
5156 if (stored_state->IsSubexpression()) { 5161 if (stored_state->IsSubexpression()) {
5157 // Inside a parenthesized group when hitting end of input. 5162 // Inside a parenthesized group when hitting end of input.
5158 ReportError(CStrVector("Unterminated group") CHECK_FAILED); 5163 ReportError(CStrVector("Unterminated group") CHECK_FAILED);
5159 } 5164 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5259 } else { 5264 } else {
5260 if (captures_ == NULL) { 5265 if (captures_ == NULL) {
5261 captures_ = new(zone()) ZoneList<RegExpCapture*>(2); 5266 captures_ = new(zone()) ZoneList<RegExpCapture*>(2);
5262 } 5267 }
5263 if (captures_started() >= kMaxCaptures) { 5268 if (captures_started() >= kMaxCaptures) {
5264 ReportError(CStrVector("Too many captures") CHECK_FAILED); 5269 ReportError(CStrVector("Too many captures") CHECK_FAILED);
5265 } 5270 }
5266 captures_->Add(NULL); 5271 captures_->Add(NULL);
5267 } 5272 }
5268 // Store current state and begin new disjunction parsing. 5273 // Store current state and begin new disjunction parsing.
5269 stored_state = new(zone()) RegExpParserState(stored_state, 5274 stored_state = new(zone()) RegExpParserState(stored_state, type,
5270 type, 5275 captures_started(), zone());
5271 captures_started());
5272 builder = stored_state->builder(); 5276 builder = stored_state->builder();
5273 continue; 5277 continue;
5274 } 5278 }
5275 case '[': { 5279 case '[': {
5276 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); 5280 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED);
5277 builder->AddAtom(atom); 5281 builder->AddAtom(atom);
5278 break; 5282 break;
5279 } 5283 }
5280 // Atom :: 5284 // Atom ::
5281 // \ AtomEscape 5285 // \ AtomEscape
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
6013 } 6017 }
6014 if (!info->is_native() && FLAG_harmony_modules) { 6018 if (!info->is_native() && FLAG_harmony_modules) {
6015 parsing_flags |= kAllowModules; 6019 parsing_flags |= kAllowModules;
6016 } 6020 }
6017 if (FLAG_allow_natives_syntax || info->is_native()) { 6021 if (FLAG_allow_natives_syntax || info->is_native()) {
6018 // We require %identifier(..) syntax. 6022 // We require %identifier(..) syntax.
6019 parsing_flags |= kAllowNativesSyntax; 6023 parsing_flags |= kAllowNativesSyntax;
6020 } 6024 }
6021 if (info->is_lazy()) { 6025 if (info->is_lazy()) {
6022 ASSERT(!info->is_eval()); 6026 ASSERT(!info->is_eval());
6023 Parser parser(script, parsing_flags, NULL, NULL); 6027 Parser parser(script, parsing_flags, NULL, NULL, info->isolate()->zone());
6024 if (info->shared_info()->is_function()) { 6028 if (info->shared_info()->is_function()) {
6025 result = parser.ParseLazy(info); 6029 result = parser.ParseLazy(info);
6026 } else { 6030 } else {
6027 result = parser.ParseProgram(info); 6031 result = parser.ParseProgram(info);
6028 } 6032 }
6029 } else { 6033 } else {
6030 ScriptDataImpl* pre_data = info->pre_parse_data(); 6034 ScriptDataImpl* pre_data = info->pre_parse_data();
6031 Parser parser(script, parsing_flags, info->extension(), pre_data); 6035 Parser parser(script, parsing_flags, info->extension(), pre_data,
6036 info->isolate()->zone());
6032 if (pre_data != NULL && pre_data->has_error()) { 6037 if (pre_data != NULL && pre_data->has_error()) {
6033 Scanner::Location loc = pre_data->MessageLocation(); 6038 Scanner::Location loc = pre_data->MessageLocation();
6034 const char* message = pre_data->BuildMessage(); 6039 const char* message = pre_data->BuildMessage();
6035 Vector<const char*> args = pre_data->BuildArgs(); 6040 Vector<const char*> args = pre_data->BuildArgs();
6036 parser.ReportMessageAt(loc, message, args); 6041 parser.ReportMessageAt(loc, message, args);
6037 DeleteArray(message); 6042 DeleteArray(message);
6038 for (int i = 0; i < args.length(); i++) { 6043 for (int i = 0; i < args.length(); i++) {
6039 DeleteArray(args[i]); 6044 DeleteArray(args[i]);
6040 } 6045 }
6041 DeleteArray(args.start()); 6046 DeleteArray(args.start());
6042 ASSERT(info->isolate()->has_pending_exception()); 6047 ASSERT(info->isolate()->has_pending_exception());
6043 } else { 6048 } else {
6044 result = parser.ParseProgram(info); 6049 result = parser.ParseProgram(info);
6045 } 6050 }
6046 } 6051 }
6047 info->SetFunction(result); 6052 info->SetFunction(result);
6048 return (result != NULL); 6053 return (result != NULL);
6049 } 6054 }
6050 6055
6051 } } // namespace v8::internal 6056 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698