OLD | NEW |
---|---|
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 Statement* ParseContinueStatement(bool* ok); | 170 Statement* ParseContinueStatement(bool* ok); |
171 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); | 171 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); |
172 Statement* ParseReturnStatement(bool* ok); | 172 Statement* ParseReturnStatement(bool* ok); |
173 Block* WithHelper(Expression* obj, | 173 Block* WithHelper(Expression* obj, |
174 ZoneStringList* labels, | 174 ZoneStringList* labels, |
175 bool is_catch_block, | 175 bool is_catch_block, |
176 bool* ok); | 176 bool* ok); |
177 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); | 177 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); |
178 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); | 178 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); |
179 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); | 179 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); |
180 LoopStatement* ParseDoStatement(ZoneStringList* labels, bool* ok); | 180 DoWhileStatement* ParseDoWhileStatement(ZoneStringList* labels, bool* ok); |
181 LoopStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 181 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
182 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 182 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
183 Statement* ParseThrowStatement(bool* ok); | 183 Statement* ParseThrowStatement(bool* ok); |
184 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 184 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
185 TryStatement* ParseTryStatement(bool* ok); | 185 TryStatement* ParseTryStatement(bool* ok); |
186 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 186 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
187 | 187 |
188 Expression* ParseExpression(bool accept_IN, bool* ok); | 188 Expression* ParseExpression(bool accept_IN, bool* ok); |
189 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | 189 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); |
190 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); | 190 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); |
191 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 191 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1685 | 1685 |
1686 case Token::SEMICOLON: | 1686 case Token::SEMICOLON: |
1687 Next(); | 1687 Next(); |
1688 return factory()->EmptyStatement(); | 1688 return factory()->EmptyStatement(); |
1689 | 1689 |
1690 case Token::IF: | 1690 case Token::IF: |
1691 stmt = ParseIfStatement(labels, ok); | 1691 stmt = ParseIfStatement(labels, ok); |
1692 break; | 1692 break; |
1693 | 1693 |
1694 case Token::DO: | 1694 case Token::DO: |
1695 stmt = ParseDoStatement(labels, ok); | 1695 stmt = ParseDoWhileStatement(labels, ok); |
1696 break; | 1696 break; |
1697 | 1697 |
1698 case Token::WHILE: | 1698 case Token::WHILE: |
1699 stmt = ParseWhileStatement(labels, ok); | 1699 stmt = ParseWhileStatement(labels, ok); |
1700 break; | 1700 break; |
1701 | 1701 |
1702 case Token::FOR: | 1702 case Token::FOR: |
1703 stmt = ParseForStatement(labels, ok); | 1703 stmt = ParseForStatement(labels, ok); |
1704 break; | 1704 break; |
1705 | 1705 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2354 | 2354 |
2355 // Create body block. | 2355 // Create body block. |
2356 Block* body = NEW(Block(NULL, 1, false)); | 2356 Block* body = NEW(Block(NULL, 1, false)); |
2357 body->AddStatement(stat); | 2357 body->AddStatement(stat); |
2358 | 2358 |
2359 // Create exit block. | 2359 // Create exit block. |
2360 Block* exit = NEW(Block(NULL, 1, false)); | 2360 Block* exit = NEW(Block(NULL, 1, false)); |
2361 exit->AddStatement(NEW(WithExitStatement())); | 2361 exit->AddStatement(NEW(WithExitStatement())); |
2362 | 2362 |
2363 // Return a try-finally statement. | 2363 // Return a try-finally statement. |
2364 TryFinally* wrapper = NEW(TryFinally(body, exit)); | 2364 TryFinallyStatement* wrapper = NEW(TryFinallyStatement(body, exit)); |
2365 wrapper->set_escaping_targets(collector.targets()); | 2365 wrapper->set_escaping_targets(collector.targets()); |
2366 result->AddStatement(wrapper); | 2366 result->AddStatement(wrapper); |
2367 } | 2367 } |
2368 return result; | 2368 return result; |
2369 } | 2369 } |
2370 | 2370 |
2371 | 2371 |
2372 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { | 2372 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { |
2373 // WithStatement :: | 2373 // WithStatement :: |
2374 // 'with' '(' Expression ')' Statement | 2374 // 'with' '(' Expression ')' Statement |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2530 // executing the finally block. | 2530 // executing the finally block. |
2531 finally_block = ParseBlock(NULL, CHECK_OK); | 2531 finally_block = ParseBlock(NULL, CHECK_OK); |
2532 } | 2532 } |
2533 | 2533 |
2534 // Simplify the AST nodes by converting: | 2534 // Simplify the AST nodes by converting: |
2535 // 'try { } catch { } finally { }' | 2535 // 'try { } catch { } finally { }' |
2536 // to: | 2536 // to: |
2537 // 'try { try { } catch { } } finally { }' | 2537 // 'try { try { } catch { } } finally { }' |
2538 | 2538 |
2539 if (!is_pre_parsing_ && catch_block != NULL && finally_block != NULL) { | 2539 if (!is_pre_parsing_ && catch_block != NULL && finally_block != NULL) { |
2540 TryCatch* statement = NEW(TryCatch(try_block, catch_var, catch_block)); | 2540 TryCatchStatement* statement = |
2541 NEW(TryCatchStatement(try_block, catch_var, catch_block)); | |
2541 statement->set_escaping_targets(collector.targets()); | 2542 statement->set_escaping_targets(collector.targets()); |
2542 try_block = NEW(Block(NULL, 1, false)); | 2543 try_block = NEW(Block(NULL, 1, false)); |
2543 try_block->AddStatement(statement); | 2544 try_block->AddStatement(statement); |
2544 catch_block = NULL; | 2545 catch_block = NULL; |
2545 } | 2546 } |
2546 | 2547 |
2547 TryStatement* result = NULL; | 2548 TryStatement* result = NULL; |
2548 if (!is_pre_parsing_) { | 2549 if (!is_pre_parsing_) { |
2549 if (catch_block != NULL) { | 2550 if (catch_block != NULL) { |
2550 ASSERT(finally_block == NULL); | 2551 ASSERT(finally_block == NULL); |
2551 result = NEW(TryCatch(try_block, catch_var, catch_block)); | 2552 result = NEW(TryCatchStatement(try_block, catch_var, catch_block)); |
2552 result->set_escaping_targets(collector.targets()); | 2553 result->set_escaping_targets(collector.targets()); |
2553 } else { | 2554 } else { |
2554 ASSERT(finally_block != NULL); | 2555 ASSERT(finally_block != NULL); |
2555 result = NEW(TryFinally(try_block, finally_block)); | 2556 result = NEW(TryFinallyStatement(try_block, finally_block)); |
2556 // Add the jump targets of the try block and the catch block. | 2557 // Add the jump targets of the try block and the catch block. |
2557 for (int i = 0; i < collector.targets()->length(); i++) { | 2558 for (int i = 0; i < collector.targets()->length(); i++) { |
2558 catch_collector.AddTarget(collector.targets()->at(i)); | 2559 catch_collector.AddTarget(collector.targets()->at(i)); |
2559 } | 2560 } |
2560 result->set_escaping_targets(catch_collector.targets()); | 2561 result->set_escaping_targets(catch_collector.targets()); |
2561 } | 2562 } |
2562 } | 2563 } |
2563 | 2564 |
2564 return result; | 2565 return result; |
2565 } | 2566 } |
2566 | 2567 |
2567 | 2568 |
2568 LoopStatement* Parser::ParseDoStatement(ZoneStringList* labels, bool* ok) { | 2569 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, |
2570 bool* ok) { | |
2569 // DoStatement :: | 2571 // DoStatement :: |
2570 // 'do' Statement 'while' '(' Expression ')' ';' | 2572 // 'do' Statement 'while' '(' Expression ')' ';' |
2571 | 2573 |
2572 LoopStatement* loop = NEW(LoopStatement(labels, LoopStatement::DO_LOOP)); | 2574 DoWhileStatement* loop = NEW(DoWhileStatement(labels)); |
2573 Target target(this, loop); | 2575 Target target(this, loop); |
2574 | 2576 |
2575 Expect(Token::DO, CHECK_OK); | 2577 Expect(Token::DO, CHECK_OK); |
2576 Statement* body = ParseStatement(NULL, CHECK_OK); | 2578 Statement* body = ParseStatement(NULL, CHECK_OK); |
2577 Expect(Token::WHILE, CHECK_OK); | 2579 Expect(Token::WHILE, CHECK_OK); |
2578 Expect(Token::LPAREN, CHECK_OK); | 2580 Expect(Token::LPAREN, CHECK_OK); |
2579 Expression* cond = ParseExpression(true, CHECK_OK); | 2581 Expression* cond = ParseExpression(true, CHECK_OK); |
2580 Expect(Token::RPAREN, CHECK_OK); | 2582 Expect(Token::RPAREN, CHECK_OK); |
2581 | 2583 |
2582 // Allow do-statements to be terminated with and without | 2584 // Allow do-statements to be terminated with and without |
2583 // semi-colons. This allows code such as 'do;while(0)return' to | 2585 // semi-colons. This allows code such as 'do;while(0)return' to |
2584 // parse, which would not be the case if we had used the | 2586 // parse, which would not be the case if we had used the |
2585 // ExpectSemicolon() functionality here. | 2587 // ExpectSemicolon() functionality here. |
2586 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); | 2588 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); |
2587 | 2589 |
2588 if (loop) loop->Initialize(NULL, cond, NULL, body); | 2590 if (loop != NULL) loop->Initialize(cond, body); |
2589 return loop; | 2591 return loop; |
2590 } | 2592 } |
2591 | 2593 |
2592 | 2594 |
2593 LoopStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { | 2595 WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) { |
2594 // WhileStatement :: | 2596 // WhileStatement :: |
2595 // 'while' '(' Expression ')' Statement | 2597 // 'while' '(' Expression ')' Statement |
2596 | 2598 |
2597 LoopStatement* loop = NEW(LoopStatement(labels, LoopStatement::WHILE_LOOP)); | 2599 WhileStatement* loop = NEW(WhileStatement(labels)); |
2598 Target target(this, loop); | 2600 Target target(this, loop); |
2599 | 2601 |
2600 Expect(Token::WHILE, CHECK_OK); | 2602 Expect(Token::WHILE, CHECK_OK); |
2601 Expect(Token::LPAREN, CHECK_OK); | 2603 Expect(Token::LPAREN, CHECK_OK); |
2602 Expression* cond = ParseExpression(true, CHECK_OK); | 2604 Expression* cond = ParseExpression(true, CHECK_OK); |
2603 Expect(Token::RPAREN, CHECK_OK); | 2605 Expect(Token::RPAREN, CHECK_OK); |
2604 Statement* body = ParseStatement(NULL, CHECK_OK); | 2606 Statement* body = ParseStatement(NULL, CHECK_OK); |
2605 | 2607 |
2606 if (loop) loop->Initialize(NULL, cond, NULL, body); | 2608 if (loop != NULL) loop->Initialize(cond, body); |
2607 return loop; | 2609 return loop; |
2608 } | 2610 } |
2609 | 2611 |
2610 | 2612 |
2611 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { | 2613 Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { |
William Hesse
2009/10/12 11:45:35
Perhaps there should be a comment saying that this
| |
2612 // ForStatement :: | 2614 // ForStatement :: |
2613 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement | 2615 // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement |
2614 | 2616 |
2615 Statement* init = NULL; | 2617 Statement* init = NULL; |
2616 | 2618 |
2617 Expect(Token::FOR, CHECK_OK); | 2619 Expect(Token::FOR, CHECK_OK); |
2618 Expect(Token::LPAREN, CHECK_OK); | 2620 Expect(Token::LPAREN, CHECK_OK); |
2619 if (peek() != Token::SEMICOLON) { | 2621 if (peek() != Token::SEMICOLON) { |
2620 if (peek() == Token::VAR || peek() == Token::CONST) { | 2622 if (peek() == Token::VAR || peek() == Token::CONST) { |
2621 Expression* each = NULL; | 2623 Expression* each = NULL; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2669 // Parsed for-in loop. | 2671 // Parsed for-in loop. |
2670 return loop; | 2672 return loop; |
2671 | 2673 |
2672 } else { | 2674 } else { |
2673 init = NEW(ExpressionStatement(expression)); | 2675 init = NEW(ExpressionStatement(expression)); |
2674 } | 2676 } |
2675 } | 2677 } |
2676 } | 2678 } |
2677 | 2679 |
2678 // Standard 'for' loop | 2680 // Standard 'for' loop |
2679 LoopStatement* loop = NEW(LoopStatement(labels, LoopStatement::FOR_LOOP)); | 2681 ForStatement* loop = NEW(ForStatement(labels)); |
2680 Target target(this, loop); | 2682 Target target(this, loop); |
2681 | 2683 |
2682 // Parsed initializer at this point. | 2684 // Parsed initializer at this point. |
2683 Expect(Token::SEMICOLON, CHECK_OK); | 2685 Expect(Token::SEMICOLON, CHECK_OK); |
2684 | 2686 |
2685 Expression* cond = NULL; | 2687 Expression* cond = NULL; |
2686 if (peek() != Token::SEMICOLON) { | 2688 if (peek() != Token::SEMICOLON) { |
2687 cond = ParseExpression(true, CHECK_OK); | 2689 cond = ParseExpression(true, CHECK_OK); |
2688 } | 2690 } |
2689 Expect(Token::SEMICOLON, CHECK_OK); | 2691 Expect(Token::SEMICOLON, CHECK_OK); |
(...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4826 start_position, | 4828 start_position, |
4827 is_expression); | 4829 is_expression); |
4828 return result; | 4830 return result; |
4829 } | 4831 } |
4830 | 4832 |
4831 | 4833 |
4832 #undef NEW | 4834 #undef NEW |
4833 | 4835 |
4834 | 4836 |
4835 } } // namespace v8::internal | 4837 } } // namespace v8::internal |
OLD | NEW |