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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void AstOptimizer::VisitIfStatement(IfStatement* node) { | 94 void AstOptimizer::VisitIfStatement(IfStatement* node) { |
95 Visit(node->condition()); | 95 Visit(node->condition()); |
96 Visit(node->then_statement()); | 96 Visit(node->then_statement()); |
97 if (node->HasElseStatement()) { | 97 if (node->HasElseStatement()) { |
98 Visit(node->else_statement()); | 98 Visit(node->else_statement()); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 void AstOptimizer::VisitLoopStatement(LoopStatement* node) { | 103 void AstOptimizer::VisitDoWhileStatement(DoWhileStatement* node) { |
| 104 Visit(node->cond()); |
| 105 Visit(node->body()); |
| 106 } |
| 107 |
| 108 |
| 109 void AstOptimizer::VisitWhileStatement(WhileStatement* node) { |
| 110 has_function_literal_ = false; |
| 111 Visit(node->cond()); |
| 112 node->may_have_function_literal_ = has_function_literal_; |
| 113 Visit(node->body()); |
| 114 } |
| 115 |
| 116 |
| 117 void AstOptimizer::VisitForStatement(ForStatement* node) { |
104 if (node->init() != NULL) { | 118 if (node->init() != NULL) { |
105 Visit(node->init()); | 119 Visit(node->init()); |
106 } | 120 } |
107 if (node->cond() != NULL) { | 121 if (node->cond() != NULL) { |
108 has_function_literal_ = false; | 122 has_function_literal_ = false; |
109 Visit(node->cond()); | 123 Visit(node->cond()); |
110 node->may_have_function_literal_ = has_function_literal_; | 124 node->may_have_function_literal_ = has_function_literal_; |
111 } | 125 } |
112 if (node->body() != NULL) { | 126 Visit(node->body()); |
113 Visit(node->body()); | |
114 } | |
115 if (node->next() != NULL) { | 127 if (node->next() != NULL) { |
116 Visit(node->next()); | 128 Visit(node->next()); |
117 } | 129 } |
118 } | 130 } |
119 | 131 |
120 | 132 |
121 void AstOptimizer::VisitForInStatement(ForInStatement* node) { | 133 void AstOptimizer::VisitForInStatement(ForInStatement* node) { |
122 Visit(node->each()); | 134 Visit(node->each()); |
123 Visit(node->enumerable()); | 135 Visit(node->enumerable()); |
124 Visit(node->body()); | 136 Visit(node->body()); |
125 } | 137 } |
126 | 138 |
127 | 139 |
128 void AstOptimizer::VisitTryCatch(TryCatch* node) { | 140 void AstOptimizer::VisitTryCatchStatement(TryCatchStatement* node) { |
129 Visit(node->try_block()); | 141 Visit(node->try_block()); |
130 Visit(node->catch_var()); | 142 Visit(node->catch_var()); |
131 Visit(node->catch_block()); | 143 Visit(node->catch_block()); |
132 } | 144 } |
133 | 145 |
134 | 146 |
135 void AstOptimizer::VisitTryFinally(TryFinally* node) { | 147 void AstOptimizer::VisitTryFinallyStatement(TryFinallyStatement* node) { |
136 Visit(node->try_block()); | 148 Visit(node->try_block()); |
137 Visit(node->finally_block()); | 149 Visit(node->finally_block()); |
138 } | 150 } |
139 | 151 |
140 | 152 |
141 void AstOptimizer::VisitSwitchStatement(SwitchStatement* node) { | 153 void AstOptimizer::VisitSwitchStatement(SwitchStatement* node) { |
142 Visit(node->tag()); | 154 Visit(node->tag()); |
143 for (int i = 0; i < node->cases()->length(); i++) { | 155 for (int i = 0; i < node->cases()->length(); i++) { |
144 CaseClause* clause = node->cases()->at(i); | 156 CaseClause* clause = node->cases()->at(i); |
145 if (!clause->is_default()) { | 157 if (!clause->is_default()) { |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 result_assigned_ = true; | 558 result_assigned_ = true; |
547 return new Assignment(Token::ASSIGN, result_, value, | 559 return new Assignment(Token::ASSIGN, result_, value, |
548 RelocInfo::kNoPosition); | 560 RelocInfo::kNoPosition); |
549 } | 561 } |
550 | 562 |
551 // Node visitors. | 563 // Node visitors. |
552 #define DEF_VISIT(type) \ | 564 #define DEF_VISIT(type) \ |
553 virtual void Visit##type(type* node); | 565 virtual void Visit##type(type* node); |
554 AST_NODE_LIST(DEF_VISIT) | 566 AST_NODE_LIST(DEF_VISIT) |
555 #undef DEF_VISIT | 567 #undef DEF_VISIT |
| 568 |
| 569 void VisitIterationStatement(IterationStatement* stmt); |
556 }; | 570 }; |
557 | 571 |
558 | 572 |
559 void Processor::Process(ZoneList<Statement*>* statements) { | 573 void Processor::Process(ZoneList<Statement*>* statements) { |
560 for (int i = statements->length() - 1; i >= 0; --i) { | 574 for (int i = statements->length() - 1; i >= 0; --i) { |
561 Visit(statements->at(i)); | 575 Visit(statements->at(i)); |
562 } | 576 } |
563 } | 577 } |
564 | 578 |
565 | 579 |
(...skipping 23 matching lines...) Expand all Loading... |
589 // Rewrite both then and else parts (reversed). | 603 // Rewrite both then and else parts (reversed). |
590 bool save = is_set_; | 604 bool save = is_set_; |
591 Visit(node->else_statement()); | 605 Visit(node->else_statement()); |
592 bool set_after_then = is_set_; | 606 bool set_after_then = is_set_; |
593 is_set_ = save; | 607 is_set_ = save; |
594 Visit(node->then_statement()); | 608 Visit(node->then_statement()); |
595 is_set_ = is_set_ && set_after_then; | 609 is_set_ = is_set_ && set_after_then; |
596 } | 610 } |
597 | 611 |
598 | 612 |
599 | 613 void Processor::VisitIterationStatement(IterationStatement* node) { |
600 | 614 // Rewrite the body. |
601 void Processor::VisitLoopStatement(LoopStatement* node) { | |
602 // Rewrite loop body statement. | |
603 bool set_after_loop = is_set_; | 615 bool set_after_loop = is_set_; |
604 Visit(node->body()); | 616 Visit(node->body()); |
605 is_set_ = is_set_ && set_after_loop; | 617 is_set_ = is_set_ && set_after_loop; |
606 } | 618 } |
607 | 619 |
608 | 620 |
609 void Processor::VisitForInStatement(ForInStatement* node) { | 621 void Processor::VisitDoWhileStatement(DoWhileStatement* node) { |
610 // Rewrite for-in body statement. | 622 VisitIterationStatement(node); |
611 bool set_after_for = is_set_; | |
612 Visit(node->body()); | |
613 is_set_ = is_set_ && set_after_for; | |
614 } | 623 } |
615 | 624 |
616 | 625 |
617 void Processor::VisitTryCatch(TryCatch* node) { | 626 void Processor::VisitWhileStatement(WhileStatement* node) { |
| 627 VisitIterationStatement(node); |
| 628 } |
| 629 |
| 630 |
| 631 void Processor::VisitForStatement(ForStatement* node) { |
| 632 VisitIterationStatement(node); |
| 633 } |
| 634 |
| 635 |
| 636 void Processor::VisitForInStatement(ForInStatement* node) { |
| 637 VisitIterationStatement(node); |
| 638 } |
| 639 |
| 640 |
| 641 void Processor::VisitTryCatchStatement(TryCatchStatement* node) { |
618 // Rewrite both try and catch blocks (reversed order). | 642 // Rewrite both try and catch blocks (reversed order). |
619 bool set_after_catch = is_set_; | 643 bool set_after_catch = is_set_; |
620 Visit(node->catch_block()); | 644 Visit(node->catch_block()); |
621 is_set_ = is_set_ && set_after_catch; | 645 is_set_ = is_set_ && set_after_catch; |
622 bool save = in_try_; | 646 bool save = in_try_; |
623 in_try_ = true; | 647 in_try_ = true; |
624 Visit(node->try_block()); | 648 Visit(node->try_block()); |
625 in_try_ = save; | 649 in_try_ = save; |
626 } | 650 } |
627 | 651 |
628 | 652 |
629 void Processor::VisitTryFinally(TryFinally* node) { | 653 void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
630 // Rewrite both try and finally block (reversed order). | 654 // Rewrite both try and finally block (reversed order). |
631 Visit(node->finally_block()); | 655 Visit(node->finally_block()); |
632 bool save = in_try_; | 656 bool save = in_try_; |
633 in_try_ = true; | 657 in_try_ = true; |
634 Visit(node->try_block()); | 658 Visit(node->try_block()); |
635 in_try_ = save; | 659 in_try_ = save; |
636 } | 660 } |
637 | 661 |
638 | 662 |
639 void Processor::VisitSwitchStatement(SwitchStatement* node) { | 663 void Processor::VisitSwitchStatement(SwitchStatement* node) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 optimizer.Optimize(body); | 846 optimizer.Optimize(body); |
823 if (optimizer.HasStackOverflow()) { | 847 if (optimizer.HasStackOverflow()) { |
824 return false; | 848 return false; |
825 } | 849 } |
826 } | 850 } |
827 return true; | 851 return true; |
828 } | 852 } |
829 | 853 |
830 | 854 |
831 } } // namespace v8::internal | 855 } } // namespace v8::internal |
OLD | NEW |