| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/parsing/rewriter.h" | 5 #include "src/parsing/rewriter.h" |
| 6 | 6 |
| 7 #include "src/ast/ast.h" | 7 #include "src/ast/ast.h" |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser.h" | 9 #include "src/parsing/parser.h" |
| 10 | 10 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 bool set_after = is_set_; | 141 bool set_after = is_set_; |
| 142 Visit(node->then_statement()); | 142 Visit(node->then_statement()); |
| 143 node->set_then_statement(replacement_); | 143 node->set_then_statement(replacement_); |
| 144 bool set_in_then = is_set_; | 144 bool set_in_then = is_set_; |
| 145 is_set_ = set_after; | 145 is_set_ = set_after; |
| 146 Visit(node->else_statement()); | 146 Visit(node->else_statement()); |
| 147 node->set_else_statement(replacement_); | 147 node->set_else_statement(replacement_); |
| 148 is_set_ = is_set_ && set_in_then; | 148 is_set_ = is_set_ && set_in_then; |
| 149 replacement_ = node; | 149 replacement_ = node; |
| 150 | 150 |
| 151 if (FLAG_harmony_completion && !is_set_) { | 151 if (!is_set_) { |
| 152 is_set_ = true; | 152 is_set_ = true; |
| 153 replacement_ = AssignUndefinedBefore(node); | 153 replacement_ = AssignUndefinedBefore(node); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 void Processor::VisitIterationStatement(IterationStatement* node) { | 158 void Processor::VisitIterationStatement(IterationStatement* node) { |
| 159 // Rewrite the body. | 159 // Rewrite the body. |
| 160 bool set_after = is_set_; | 160 bool set_after = is_set_; |
| 161 is_set_ = false; // We are in a loop, so we can't rely on [set_after]. | 161 is_set_ = false; // We are in a loop, so we can't rely on [set_after]. |
| 162 Visit(node->body()); | 162 Visit(node->body()); |
| 163 node->set_body(replacement_); | 163 node->set_body(replacement_); |
| 164 is_set_ = is_set_ && set_after; | 164 is_set_ = is_set_ && set_after; |
| 165 replacement_ = node; | 165 replacement_ = node; |
| 166 | 166 |
| 167 if (FLAG_harmony_completion && !is_set_) { | 167 if (!is_set_) { |
| 168 is_set_ = true; | 168 is_set_ = true; |
| 169 replacement_ = AssignUndefinedBefore(node); | 169 replacement_ = AssignUndefinedBefore(node); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 void Processor::VisitDoWhileStatement(DoWhileStatement* node) { | 174 void Processor::VisitDoWhileStatement(DoWhileStatement* node) { |
| 175 VisitIterationStatement(node); | 175 VisitIterationStatement(node); |
| 176 } | 176 } |
| 177 | 177 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 201 bool set_after = is_set_; | 201 bool set_after = is_set_; |
| 202 Visit(node->try_block()); | 202 Visit(node->try_block()); |
| 203 node->set_try_block(static_cast<Block*>(replacement_)); | 203 node->set_try_block(static_cast<Block*>(replacement_)); |
| 204 bool set_in_try = is_set_; | 204 bool set_in_try = is_set_; |
| 205 is_set_ = set_after; | 205 is_set_ = set_after; |
| 206 Visit(node->catch_block()); | 206 Visit(node->catch_block()); |
| 207 node->set_catch_block(static_cast<Block*>(replacement_)); | 207 node->set_catch_block(static_cast<Block*>(replacement_)); |
| 208 is_set_ = is_set_ && set_in_try; | 208 is_set_ = is_set_ && set_in_try; |
| 209 replacement_ = node; | 209 replacement_ = node; |
| 210 | 210 |
| 211 if (FLAG_harmony_completion && !is_set_) { | 211 if (!is_set_) { |
| 212 is_set_ = true; | 212 is_set_ = true; |
| 213 replacement_ = AssignUndefinedBefore(node); | 213 replacement_ = AssignUndefinedBefore(node); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 | 217 |
| 218 void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) { | 218 void Processor::VisitTryFinallyStatement(TryFinallyStatement* node) { |
| 219 // Rewrite both try and finally block (in reverse order). | 219 // Rewrite both try and finally block (in reverse order). |
| 220 bool set_after = is_set_; | 220 bool set_after = is_set_; |
| 221 is_set_ = true; // Don't normally need to assign in finally block. | 221 is_set_ = true; // Don't normally need to assign in finally block. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 238 zone()); | 238 zone()); |
| 239 node->finally_block()->statements()->Add( | 239 node->finally_block()->statements()->Add( |
| 240 factory()->NewExpressionStatement(restore, RelocInfo::kNoPosition), | 240 factory()->NewExpressionStatement(restore, RelocInfo::kNoPosition), |
| 241 zone()); | 241 zone()); |
| 242 } | 242 } |
| 243 is_set_ = set_after; | 243 is_set_ = set_after; |
| 244 Visit(node->try_block()); | 244 Visit(node->try_block()); |
| 245 node->set_try_block(replacement_->AsBlock()); | 245 node->set_try_block(replacement_->AsBlock()); |
| 246 replacement_ = node; | 246 replacement_ = node; |
| 247 | 247 |
| 248 if (FLAG_harmony_completion && !is_set_) { | 248 if (!is_set_) { |
| 249 is_set_ = true; | 249 is_set_ = true; |
| 250 replacement_ = AssignUndefinedBefore(node); | 250 replacement_ = AssignUndefinedBefore(node); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 | 254 |
| 255 void Processor::VisitSwitchStatement(SwitchStatement* node) { | 255 void Processor::VisitSwitchStatement(SwitchStatement* node) { |
| 256 // Rewrite statements in all case clauses (in reverse order). | 256 // Rewrite statements in all case clauses (in reverse order). |
| 257 ZoneList<CaseClause*>* clauses = node->cases(); | 257 ZoneList<CaseClause*>* clauses = node->cases(); |
| 258 bool set_after = is_set_; | 258 bool set_after = is_set_; |
| 259 for (int i = clauses->length() - 1; i >= 0; --i) { | 259 for (int i = clauses->length() - 1; i >= 0; --i) { |
| 260 CaseClause* clause = clauses->at(i); | 260 CaseClause* clause = clauses->at(i); |
| 261 Process(clause->statements()); | 261 Process(clause->statements()); |
| 262 } | 262 } |
| 263 is_set_ = is_set_ && set_after; | 263 is_set_ = is_set_ && set_after; |
| 264 replacement_ = node; | 264 replacement_ = node; |
| 265 | 265 |
| 266 if (FLAG_harmony_completion && !is_set_) { | 266 if (!is_set_) { |
| 267 is_set_ = true; | 267 is_set_ = true; |
| 268 replacement_ = AssignUndefinedBefore(node); | 268 replacement_ = AssignUndefinedBefore(node); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 | 272 |
| 273 void Processor::VisitContinueStatement(ContinueStatement* node) { | 273 void Processor::VisitContinueStatement(ContinueStatement* node) { |
| 274 is_set_ = false; | 274 is_set_ = false; |
| 275 replacement_ = node; | 275 replacement_ = node; |
| 276 } | 276 } |
| 277 | 277 |
| 278 | 278 |
| 279 void Processor::VisitBreakStatement(BreakStatement* node) { | 279 void Processor::VisitBreakStatement(BreakStatement* node) { |
| 280 is_set_ = false; | 280 is_set_ = false; |
| 281 replacement_ = node; | 281 replacement_ = node; |
| 282 } | 282 } |
| 283 | 283 |
| 284 | 284 |
| 285 void Processor::VisitWithStatement(WithStatement* node) { | 285 void Processor::VisitWithStatement(WithStatement* node) { |
| 286 Visit(node->statement()); | 286 Visit(node->statement()); |
| 287 node->set_statement(replacement_); | 287 node->set_statement(replacement_); |
| 288 replacement_ = node; | 288 replacement_ = node; |
| 289 | 289 |
| 290 if (FLAG_harmony_completion && !is_set_) { | 290 if (!is_set_) { |
| 291 is_set_ = true; | 291 is_set_ = true; |
| 292 replacement_ = AssignUndefinedBefore(node); | 292 replacement_ = AssignUndefinedBefore(node); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 | 296 |
| 297 void Processor::VisitSloppyBlockFunctionStatement( | 297 void Processor::VisitSloppyBlockFunctionStatement( |
| 298 SloppyBlockFunctionStatement* node) { | 298 SloppyBlockFunctionStatement* node) { |
| 299 Visit(node->statement()); | 299 Visit(node->statement()); |
| 300 node->set_statement(replacement_); | 300 node->set_statement(replacement_); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 processor.SetResult(undef), expr->position()); | 394 processor.SetResult(undef), expr->position()); |
| 395 body->Add(completion, factory->zone()); | 395 body->Add(completion, factory->zone()); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 return true; | 398 return true; |
| 399 } | 399 } |
| 400 | 400 |
| 401 | 401 |
| 402 } // namespace internal | 402 } // namespace internal |
| 403 } // namespace v8 | 403 } // namespace v8 |
| OLD | NEW |