| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of tree_ir.optimization; | 5 part of tree_ir.optimization; |
| 6 | 6 |
| 7 /// Rewrites logical expressions to be more compact in the Tree IR. | 7 /// Rewrites logical expressions to be more compact in the Tree IR. |
| 8 /// | 8 /// |
| 9 /// In this class an expression is said to occur in "boolean context" if | 9 /// In this class an expression is said to occur in "boolean context" if |
| 10 /// its result is immediately applied to boolean conversion. | 10 /// its result is immediately applied to boolean conversion. |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 308 |
| 309 return node; | 309 return node; |
| 310 } | 310 } |
| 311 | 311 |
| 312 Expression visitLogicalOperator(LogicalOperator node) { | 312 Expression visitLogicalOperator(LogicalOperator node) { |
| 313 node.left = makeCondition(node.left, true); | 313 node.left = makeCondition(node.left, true); |
| 314 node.right = makeCondition(node.right, true); | 314 node.right = makeCondition(node.right, true); |
| 315 return node; | 315 return node; |
| 316 } | 316 } |
| 317 | 317 |
| 318 Statement visitSetField(SetField node) { |
| 319 node.object = visitExpression(node.object); |
| 320 node.value = visitExpression(node.value); |
| 321 node.next = visitStatement(node.next); |
| 322 return node; |
| 323 } |
| 324 |
| 325 Expression visitGetField(GetField node) { |
| 326 node.object = visitExpression(node.object); |
| 327 return node; |
| 328 } |
| 329 |
| 330 Expression visitCreateBox(CreateBox node) { |
| 331 return node; |
| 332 } |
| 333 |
| 334 Expression visitCreateClosureClass(CreateClosureClass node) { |
| 335 _rewriteList(node.arguments); |
| 336 return node; |
| 337 } |
| 338 |
| 318 /// True if the given expression is known to evaluate to a boolean. | 339 /// True if the given expression is known to evaluate to a boolean. |
| 319 /// This will not recursively traverse [Conditional] expressions, but if | 340 /// This will not recursively traverse [Conditional] expressions, but if |
| 320 /// applied to the result of [visitExpression] conditionals will have been | 341 /// applied to the result of [visitExpression] conditionals will have been |
| 321 /// rewritten anyway. | 342 /// rewritten anyway. |
| 322 bool isBooleanValued(Expression e) { | 343 bool isBooleanValued(Expression e) { |
| 323 return isTrue(e) || isFalse(e) || e is Not || e is LogicalOperator; | 344 return isTrue(e) || isFalse(e) || e is Not || e is LogicalOperator; |
| 324 } | 345 } |
| 325 | 346 |
| 326 /// Rewrite an expression that was originally processed in a non-boolean | 347 /// Rewrite an expression that was originally processed in a non-boolean |
| 327 /// context. | 348 /// context. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 482 } |
| 462 | 483 |
| 463 /// Destructively updates each entry of [l] with the result of visiting it. | 484 /// Destructively updates each entry of [l] with the result of visiting it. |
| 464 void _rewriteList(List<Expression> l) { | 485 void _rewriteList(List<Expression> l) { |
| 465 for (int i = 0; i < l.length; i++) { | 486 for (int i = 0; i < l.length; i++) { |
| 466 l[i] = visitExpression(l[i]); | 487 l[i] = visitExpression(l[i]); |
| 467 } | 488 } |
| 468 } | 489 } |
| 469 } | 490 } |
| 470 | 491 |
| OLD | NEW |