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

Side by Side Diff: src/parser.cc

Issue 42008: Introduce a BreakTarget subclass of JumpTarget used to represent the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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/jump-target.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // Parser support 200 // Parser support
201 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode, 201 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode,
202 FunctionLiteral* fun, 202 FunctionLiteral* fun,
203 bool resolve, 203 bool resolve,
204 bool* ok) = 0; 204 bool* ok) = 0;
205 205
206 bool TargetStackContainsLabel(Handle<String> label); 206 bool TargetStackContainsLabel(Handle<String> label);
207 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); 207 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok);
208 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); 208 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok);
209 209
210 void RegisterTargetUse(JumpTarget* target, int index); 210 void RegisterTargetUse(BreakTarget* target, int index);
211 211
212 // Create a number literal. 212 // Create a number literal.
213 Literal* NewNumberLiteral(double value); 213 Literal* NewNumberLiteral(double value);
214 214
215 // Generate AST node that throw a ReferenceError with the given type. 215 // Generate AST node that throw a ReferenceError with the given type.
216 Expression* NewThrowReferenceError(Handle<String> type); 216 Expression* NewThrowReferenceError(Handle<String> type);
217 217
218 // Generate AST node that throw a SyntaxError with the given 218 // Generate AST node that throw a SyntaxError with the given
219 // type. The first argument may be null (in the handle sense) in 219 // type. The first argument may be null (in the handle sense) in
220 // which case no arguments are passed to the constructor. 220 // which case no arguments are passed to the constructor.
(...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 ExpectSemicolon(CHECK_OK); 2045 ExpectSemicolon(CHECK_OK);
2046 return NEW(ReturnStatement(expr)); 2046 return NEW(ReturnStatement(expr));
2047 } 2047 }
2048 2048
2049 2049
2050 Block* Parser::WithHelper(Expression* obj, 2050 Block* Parser::WithHelper(Expression* obj,
2051 ZoneStringList* labels, 2051 ZoneStringList* labels,
2052 bool is_catch_block, 2052 bool is_catch_block,
2053 bool* ok) { 2053 bool* ok) {
2054 // Parse the statement and collect escaping labels. 2054 // Parse the statement and collect escaping labels.
2055 ZoneList<JumpTarget*>* target_list = NEW(ZoneList<JumpTarget*>(0)); 2055 ZoneList<BreakTarget*>* target_list = NEW(ZoneList<BreakTarget*>(0));
2056 TargetCollector collector(target_list); 2056 TargetCollector collector(target_list);
2057 Statement* stat; 2057 Statement* stat;
2058 { Target target(this, &collector); 2058 { Target target(this, &collector);
2059 with_nesting_level_++; 2059 with_nesting_level_++;
2060 top_scope_->RecordWithStatement(); 2060 top_scope_->RecordWithStatement();
2061 stat = ParseStatement(labels, CHECK_OK); 2061 stat = ParseStatement(labels, CHECK_OK);
2062 with_nesting_level_--; 2062 with_nesting_level_--;
2063 } 2063 }
2064 // Create resulting block with two statements. 2064 // Create resulting block with two statements.
2065 // 1: Evaluate the with expression. 2065 // 1: Evaluate the with expression.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 // 'try' Block Catch Finally 2190 // 'try' Block Catch Finally
2191 // 2191 //
2192 // Catch :: 2192 // Catch ::
2193 // 'catch' '(' Identifier ')' Block 2193 // 'catch' '(' Identifier ')' Block
2194 // 2194 //
2195 // Finally :: 2195 // Finally ::
2196 // 'finally' Block 2196 // 'finally' Block
2197 2197
2198 Expect(Token::TRY, CHECK_OK); 2198 Expect(Token::TRY, CHECK_OK);
2199 2199
2200 ZoneList<JumpTarget*>* target_list = NEW(ZoneList<JumpTarget*>(0)); 2200 ZoneList<BreakTarget*>* target_list = NEW(ZoneList<BreakTarget*>(0));
2201 TargetCollector collector(target_list); 2201 TargetCollector collector(target_list);
2202 Block* try_block; 2202 Block* try_block;
2203 2203
2204 { Target target(this, &collector); 2204 { Target target(this, &collector);
2205 try_block = ParseBlock(NULL, CHECK_OK); 2205 try_block = ParseBlock(NULL, CHECK_OK);
2206 } 2206 }
2207 2207
2208 Block* catch_block = NULL; 2208 Block* catch_block = NULL;
2209 VariableProxy* catch_var = NULL; 2209 VariableProxy* catch_var = NULL;
2210 Block* finally_block = NULL; 2210 Block* finally_block = NULL;
2211 2211
2212 Token::Value tok = peek(); 2212 Token::Value tok = peek();
2213 if (tok != Token::CATCH && tok != Token::FINALLY) { 2213 if (tok != Token::CATCH && tok != Token::FINALLY) {
2214 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); 2214 ReportMessage("no_catch_or_finally", Vector<const char*>::empty());
2215 *ok = false; 2215 *ok = false;
2216 return NULL; 2216 return NULL;
2217 } 2217 }
2218 2218
2219 // If we can break out from the catch block and there is a finally block, 2219 // If we can break out from the catch block and there is a finally block,
2220 // then we will need to collect jump targets from the catch block. Since 2220 // then we will need to collect jump targets from the catch block. Since
2221 // we don't know yet if there will be a finally block, we always collect 2221 // we don't know yet if there will be a finally block, we always collect
2222 // the jump targets. 2222 // the jump targets.
2223 ZoneList<JumpTarget*>* catch_target_list = NEW(ZoneList<JumpTarget*>(0)); 2223 ZoneList<BreakTarget*>* catch_target_list = NEW(ZoneList<BreakTarget*>(0));
2224 TargetCollector catch_collector(catch_target_list); 2224 TargetCollector catch_collector(catch_target_list);
2225 bool has_catch = false; 2225 bool has_catch = false;
2226 if (tok == Token::CATCH) { 2226 if (tok == Token::CATCH) {
2227 has_catch = true; 2227 has_catch = true;
2228 Consume(Token::CATCH); 2228 Consume(Token::CATCH);
2229 2229
2230 Expect(Token::LPAREN, CHECK_OK); 2230 Expect(Token::LPAREN, CHECK_OK);
2231 Handle<String> name = ParseIdentifier(CHECK_OK); 2231 Handle<String> name = ParseIdentifier(CHECK_OK);
2232 Expect(Token::RPAREN, CHECK_OK); 2232 Expect(Token::RPAREN, CHECK_OK);
2233 2233
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3573 ASSERT(stat->is_target_for_anonymous()); 3573 ASSERT(stat->is_target_for_anonymous());
3574 if (anonymous || ContainsLabel(stat->labels(), label)) { 3574 if (anonymous || ContainsLabel(stat->labels(), label)) {
3575 RegisterTargetUse(stat->continue_target(), i); 3575 RegisterTargetUse(stat->continue_target(), i);
3576 return stat; 3576 return stat;
3577 } 3577 }
3578 } 3578 }
3579 return NULL; 3579 return NULL;
3580 } 3580 }
3581 3581
3582 3582
3583 void Parser::RegisterTargetUse(JumpTarget* target, int index) { 3583 void Parser::RegisterTargetUse(BreakTarget* target, int index) {
3584 // Register that a jump target found at the given index in the target 3584 // Register that a break target found at the given index in the
3585 // stack has been used from the top of the target stack. Add the jump 3585 // target stack has been used from the top of the target stack. Add
3586 // target to any TargetCollectors passed on the stack. 3586 // the break target to any TargetCollectors passed on the stack.
3587 for (int i = target_stack_->length(); i-- > index;) { 3587 for (int i = target_stack_->length(); i-- > index;) {
3588 TargetCollector* collector = target_stack_->at(i)->AsTargetCollector(); 3588 TargetCollector* collector = target_stack_->at(i)->AsTargetCollector();
3589 if (collector != NULL) collector->AddTarget(target); 3589 if (collector != NULL) collector->AddTarget(target);
3590 } 3590 }
3591 } 3591 }
3592 3592
3593 3593
3594 Literal* Parser::NewNumberLiteral(double number) { 3594 Literal* Parser::NewNumberLiteral(double number) {
3595 return NEW(Literal(Factory::NewNumber(number, TENURED))); 3595 return NEW(Literal(Factory::NewNumber(number, TENURED)));
3596 } 3596 }
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
4563 start_position, 4563 start_position,
4564 is_expression); 4564 is_expression);
4565 return result; 4565 return result;
4566 } 4566 }
4567 4567
4568 4568
4569 #undef NEW 4569 #undef NEW
4570 4570
4571 4571
4572 } } // namespace v8::internal 4572 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jump-target.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698