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

Side by Side Diff: src/parser.cc

Issue 8961: Merge change list off bleeding_edge into toiger branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/toiger/
Patch Set: Created 12 years, 1 month 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/macro-assembler-ia32.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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // Parser support 189 // Parser support
190 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode, 190 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode,
191 FunctionLiteral* fun, 191 FunctionLiteral* fun,
192 bool resolve, 192 bool resolve,
193 bool* ok) = 0; 193 bool* ok) = 0;
194 194
195 bool TargetStackContainsLabel(Handle<String> label); 195 bool TargetStackContainsLabel(Handle<String> label);
196 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); 196 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok);
197 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); 197 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok);
198 198
199 void RegisterLabelUse(Label* label, int index); 199 void RegisterTargetUse(JumpTarget* target, int index);
200 200
201 // Create a number literal. 201 // Create a number literal.
202 Literal* NewNumberLiteral(double value); 202 Literal* NewNumberLiteral(double value);
203 203
204 // Generate AST node that throw a ReferenceError with the given type. 204 // Generate AST node that throw a ReferenceError with the given type.
205 Expression* NewThrowReferenceError(Handle<String> type); 205 Expression* NewThrowReferenceError(Handle<String> type);
206 206
207 // Generate AST node that throw a SyntaxError with the given 207 // Generate AST node that throw a SyntaxError with the given
208 // type. The first argument may be null (in the handle sense) in 208 // type. The first argument may be null (in the handle sense) in
209 // which case no arguments are passed to the constructor. 209 // which case no arguments are passed to the constructor.
(...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 } 1565 }
1566 1566
1567 Expression* expr = ParseExpression(true, CHECK_OK); 1567 Expression* expr = ParseExpression(true, CHECK_OK);
1568 ExpectSemicolon(CHECK_OK); 1568 ExpectSemicolon(CHECK_OK);
1569 return NEW(ReturnStatement(expr)); 1569 return NEW(ReturnStatement(expr));
1570 } 1570 }
1571 1571
1572 1572
1573 Block* Parser::WithHelper(Expression* obj, ZoneStringList* labels, bool* ok) { 1573 Block* Parser::WithHelper(Expression* obj, ZoneStringList* labels, bool* ok) {
1574 // Parse the statement and collect escaping labels. 1574 // Parse the statement and collect escaping labels.
1575 ZoneList<Label*>* label_list = NEW(ZoneList<Label*>(0)); 1575 ZoneList<JumpTarget*>* target_list = NEW(ZoneList<JumpTarget*>(0));
1576 LabelCollector collector(label_list); 1576 TargetCollector collector(target_list);
1577 Statement* stat; 1577 Statement* stat;
1578 { Target target(this, &collector); 1578 { Target target(this, &collector);
1579 with_nesting_level_++; 1579 with_nesting_level_++;
1580 top_scope_->RecordWithStatement(); 1580 top_scope_->RecordWithStatement();
1581 stat = ParseStatement(labels, CHECK_OK); 1581 stat = ParseStatement(labels, CHECK_OK);
1582 with_nesting_level_--; 1582 with_nesting_level_--;
1583 } 1583 }
1584 // Create resulting block with two statements. 1584 // Create resulting block with two statements.
1585 // 1: Evaluate the with expression. 1585 // 1: Evaluate the with expression.
1586 // 2: The try-finally block evaluating the body. 1586 // 2: The try-finally block evaluating the body.
1587 Block* result = NEW(Block(NULL, 2, false)); 1587 Block* result = NEW(Block(NULL, 2, false));
1588 1588
1589 if (result) { 1589 if (result != NULL) {
1590 result->AddStatement(NEW(WithEnterStatement(obj))); 1590 result->AddStatement(NEW(WithEnterStatement(obj)));
1591 1591
1592 // Create body block. 1592 // Create body block.
1593 Block* body = NEW(Block(NULL, 1, false)); 1593 Block* body = NEW(Block(NULL, 1, false));
1594 body->AddStatement(stat); 1594 body->AddStatement(stat);
1595 1595
1596 // Create exit block. 1596 // Create exit block.
1597 Block* exit = NEW(Block(NULL, 1, false)); 1597 Block* exit = NEW(Block(NULL, 1, false));
1598 exit->AddStatement(NEW(WithExitStatement())); 1598 exit->AddStatement(NEW(WithExitStatement()));
1599 1599
1600 // Return a try-finally statement. 1600 // Return a try-finally statement.
1601 TryFinally* wrapper = NEW(TryFinally(body, exit)); 1601 TryFinally* wrapper = NEW(TryFinally(body, exit));
1602 wrapper->set_escaping_labels(collector.labels()); 1602 wrapper->set_escaping_targets(collector.targets());
1603 result->AddStatement(wrapper); 1603 result->AddStatement(wrapper);
1604 return result;
1605 } else {
1606 return NULL;
1607 } 1604 }
1605 return result;
1608 } 1606 }
1609 1607
1610 1608
1611 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) { 1609 Statement* Parser::ParseWithStatement(ZoneStringList* labels, bool* ok) {
1612 // WithStatement :: 1610 // WithStatement ::
1613 // 'with' '(' Expression ')' Statement 1611 // 'with' '(' Expression ')' Statement
1614 1612
1615 // We do not allow the use of 'with' statements in the internal JS 1613 // We do not allow the use of 'with' statements in the internal JS
1616 // code. If 'with' statements were allowed, the simplified setup of 1614 // code. If 'with' statements were allowed, the simplified setup of
1617 // the runtime context chain would allow access to properties in the 1615 // the runtime context chain would allow access to properties in the
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 // 'try' Block Catch Finally 1736 // 'try' Block Catch Finally
1739 // 1737 //
1740 // Catch :: 1738 // Catch ::
1741 // 'catch' '(' Identifier ')' Block 1739 // 'catch' '(' Identifier ')' Block
1742 // 1740 //
1743 // Finally :: 1741 // Finally ::
1744 // 'finally' Block 1742 // 'finally' Block
1745 1743
1746 Expect(Token::TRY, CHECK_OK); 1744 Expect(Token::TRY, CHECK_OK);
1747 1745
1748 ZoneList<Label*>* label_list = NEW(ZoneList<Label*>(0)); 1746 ZoneList<JumpTarget*>* target_list = NEW(ZoneList<JumpTarget*>(0));
1749 LabelCollector collector(label_list); 1747 TargetCollector collector(target_list);
1750 Block* try_block; 1748 Block* try_block;
1751 1749
1752 { Target target(this, &collector); 1750 { Target target(this, &collector);
1753 try_block = ParseBlock(NULL, CHECK_OK); 1751 try_block = ParseBlock(NULL, CHECK_OK);
1754 } 1752 }
1755 1753
1756 Block* catch_block = NULL; 1754 Block* catch_block = NULL;
1757 VariableProxy* catch_var = NULL; 1755 VariableProxy* catch_var = NULL;
1758 Block* finally_block = NULL; 1756 Block* finally_block = NULL;
1759 1757
1760 Token::Value tok = peek(); 1758 Token::Value tok = peek();
1761 if (tok != Token::CATCH && tok != Token::FINALLY) { 1759 if (tok != Token::CATCH && tok != Token::FINALLY) {
1762 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); 1760 ReportMessage("no_catch_or_finally", Vector<const char*>::empty());
1763 *ok = false; 1761 *ok = false;
1764 return NULL; 1762 return NULL;
1765 } 1763 }
1766 1764
1767 // If we can break out from the catch block and there is a finally block, 1765 // If we can break out from the catch block and there is a finally block,
1768 // then we will need to collect labels from the catch block. Since we don't 1766 // then we will need to collect jump targets from the catch block. Since
1769 // know yet if there will be a finally block, we always collect the labels. 1767 // we don't know yet if there will be a finally block, we always collect
1770 ZoneList<Label*>* catch_label_list = NEW(ZoneList<Label*>(0)); 1768 // the jump targets.
1771 LabelCollector catch_collector(catch_label_list); 1769 ZoneList<JumpTarget*>* catch_target_list = NEW(ZoneList<JumpTarget*>(0));
1770 TargetCollector catch_collector(catch_target_list);
1772 bool has_catch = false; 1771 bool has_catch = false;
1773 if (tok == Token::CATCH) { 1772 if (tok == Token::CATCH) {
1774 has_catch = true; 1773 has_catch = true;
1775 Consume(Token::CATCH); 1774 Consume(Token::CATCH);
1776 1775
1777 Expect(Token::LPAREN, CHECK_OK); 1776 Expect(Token::LPAREN, CHECK_OK);
1778 Handle<String> name = ParseIdentifier(CHECK_OK); 1777 Handle<String> name = ParseIdentifier(CHECK_OK);
1779 Expect(Token::RPAREN, CHECK_OK); 1778 Expect(Token::RPAREN, CHECK_OK);
1780 1779
1781 if (peek() == Token::LBRACE) { 1780 if (peek() == Token::LBRACE) {
(...skipping 18 matching lines...) Expand all
1800 finally_block = ParseBlock(NULL, CHECK_OK); 1799 finally_block = ParseBlock(NULL, CHECK_OK);
1801 } 1800 }
1802 1801
1803 // Simplify the AST nodes by converting: 1802 // Simplify the AST nodes by converting:
1804 // 'try { } catch { } finally { }' 1803 // 'try { } catch { } finally { }'
1805 // to: 1804 // to:
1806 // 'try { try { } catch { } } finally { }' 1805 // 'try { try { } catch { } } finally { }'
1807 1806
1808 if (!is_pre_parsing_ && catch_block != NULL && finally_block != NULL) { 1807 if (!is_pre_parsing_ && catch_block != NULL && finally_block != NULL) {
1809 TryCatch* statement = NEW(TryCatch(try_block, catch_var, catch_block)); 1808 TryCatch* statement = NEW(TryCatch(try_block, catch_var, catch_block));
1810 statement->set_escaping_labels(collector.labels()); 1809 statement->set_escaping_targets(collector.targets());
1811 try_block = NEW(Block(NULL, 1, false)); 1810 try_block = NEW(Block(NULL, 1, false));
1812 try_block->AddStatement(statement); 1811 try_block->AddStatement(statement);
1813 catch_block = NULL; 1812 catch_block = NULL;
1814 } 1813 }
1815 1814
1816 TryStatement* result = NULL; 1815 TryStatement* result = NULL;
1817 if (!is_pre_parsing_) { 1816 if (!is_pre_parsing_) {
1818 if (catch_block != NULL) { 1817 if (catch_block != NULL) {
1819 ASSERT(finally_block == NULL); 1818 ASSERT(finally_block == NULL);
1820 result = NEW(TryCatch(try_block, catch_var, catch_block)); 1819 result = NEW(TryCatch(try_block, catch_var, catch_block));
1821 result->set_escaping_labels(collector.labels()); 1820 result->set_escaping_targets(collector.targets());
1822 } else { 1821 } else {
1823 ASSERT(finally_block != NULL); 1822 ASSERT(finally_block != NULL);
1824 result = NEW(TryFinally(try_block, finally_block)); 1823 result = NEW(TryFinally(try_block, finally_block));
1825 // Add the labels of the try block and the catch block. 1824 // Add the jump targets of the try block and the catch block.
1826 for (int i = 0; i < collector.labels()->length(); i++) { 1825 for (int i = 0; i < collector.targets()->length(); i++) {
1827 catch_collector.labels()->Add(collector.labels()->at(i)); 1826 catch_collector.targets()->Add(collector.targets()->at(i));
1828 } 1827 }
1829 result->set_escaping_labels(catch_collector.labels()); 1828 result->set_escaping_targets(catch_collector.targets());
1830 } 1829 }
1831 } 1830 }
1832 1831
1833 return result; 1832 return result;
1834 } 1833 }
1835 1834
1836 1835
1837 LoopStatement* Parser::ParseDoStatement(ZoneStringList* labels, bool* ok) { 1836 LoopStatement* Parser::ParseDoStatement(ZoneStringList* labels, bool* ok) {
1838 // DoStatement :: 1837 // DoStatement ::
1839 // 'do' Statement 'while' '(' Expression ')' ';' 1838 // 'do' Statement 'while' '(' Expression ')' ';'
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 3065
3067 3066
3068 BreakableStatement* Parser::LookupBreakTarget(Handle<String> label, bool* ok) { 3067 BreakableStatement* Parser::LookupBreakTarget(Handle<String> label, bool* ok) {
3069 bool anonymous = label.is_null(); 3068 bool anonymous = label.is_null();
3070 for (int i = target_stack_->length(); i-- > 0;) { 3069 for (int i = target_stack_->length(); i-- > 0;) {
3071 BreakableStatement* stat = target_stack_->at(i)->AsBreakableStatement(); 3070 BreakableStatement* stat = target_stack_->at(i)->AsBreakableStatement();
3072 if (stat == NULL) continue; 3071 if (stat == NULL) continue;
3073 3072
3074 if ((anonymous && stat->is_target_for_anonymous()) || 3073 if ((anonymous && stat->is_target_for_anonymous()) ||
3075 (!anonymous && ContainsLabel(stat->labels(), label))) { 3074 (!anonymous && ContainsLabel(stat->labels(), label))) {
3076 RegisterLabelUse(stat->break_target(), i); 3075 RegisterTargetUse(stat->break_target(), i);
3077 return stat; 3076 return stat;
3078 } 3077 }
3079 } 3078 }
3080 return NULL; 3079 return NULL;
3081 } 3080 }
3082 3081
3083 3082
3084 IterationStatement* Parser::LookupContinueTarget(Handle<String> label, 3083 IterationStatement* Parser::LookupContinueTarget(Handle<String> label,
3085 bool* ok) { 3084 bool* ok) {
3086 bool anonymous = label.is_null(); 3085 bool anonymous = label.is_null();
3087 for (int i = target_stack_->length(); i-- > 0;) { 3086 for (int i = target_stack_->length(); i-- > 0;) {
3088 IterationStatement* stat = target_stack_->at(i)->AsIterationStatement(); 3087 IterationStatement* stat = target_stack_->at(i)->AsIterationStatement();
3089 if (stat == NULL) continue; 3088 if (stat == NULL) continue;
3090 3089
3091 ASSERT(stat->is_target_for_anonymous()); 3090 ASSERT(stat->is_target_for_anonymous());
3092 if (anonymous || ContainsLabel(stat->labels(), label)) { 3091 if (anonymous || ContainsLabel(stat->labels(), label)) {
3093 RegisterLabelUse(stat->continue_target(), i); 3092 RegisterTargetUse(stat->continue_target(), i);
3094 return stat; 3093 return stat;
3095 } 3094 }
3096 } 3095 }
3097 return NULL; 3096 return NULL;
3098 } 3097 }
3099 3098
3100 3099
3101 void Parser::RegisterLabelUse(Label* label, int index) { 3100 void Parser::RegisterTargetUse(JumpTarget* target, int index) {
3102 // Register that a label found at the given index in the target 3101 // Register that a jump target found at the given index in the target
3103 // stack has been used from the top of the target stack. Add the 3102 // stack has been used from the top of the target stack. Add the jump
3104 // label to any LabelCollectors passed on the stack. 3103 // target to any TargetCollectors passed on the stack.
3105 for (int i = target_stack_->length(); i-- > index;) { 3104 for (int i = target_stack_->length(); i-- > index;) {
3106 LabelCollector* collector = target_stack_->at(i)->AsLabelCollector(); 3105 TargetCollector* collector = target_stack_->at(i)->AsTargetCollector();
3107 if (collector != NULL) collector->AddLabel(label); 3106 if (collector != NULL) collector->AddTarget(target);
3108 } 3107 }
3109 } 3108 }
3110 3109
3111 3110
3112 Literal* Parser::NewNumberLiteral(double number) { 3111 Literal* Parser::NewNumberLiteral(double number) {
3113 return NEW(Literal(Factory::NewNumber(number, TENURED))); 3112 return NEW(Literal(Factory::NewNumber(number, TENURED)));
3114 } 3113 }
3115 3114
3116 3115
3117 Expression* Parser::NewThrowReferenceError(Handle<String> type) { 3116 Expression* Parser::NewThrowReferenceError(Handle<String> type) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3254 start_position, 3253 start_position,
3255 is_expression); 3254 is_expression);
3256 return result; 3255 return result;
3257 } 3256 }
3258 3257
3259 3258
3260 #undef NEW 3259 #undef NEW
3261 3260
3262 3261
3263 } } // namespace v8::internal 3262 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/macro-assembler-ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698