| 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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 e.thenExpression = (e.thenExpression as Not).operand; | 305 e.thenExpression = (e.thenExpression as Not).operand; |
| 306 e.elseExpression = (e.elseExpression as Not).operand; | 306 e.elseExpression = (e.elseExpression as Not).operand; |
| 307 return new Not(e); | 307 return new Not(e); |
| 308 } | 308 } |
| 309 return e; | 309 return e; |
| 310 } | 310 } |
| 311 if (e is Constant && e.value.isBool) { | 311 if (e is Constant && e.value.isBool) { |
| 312 // !true ==> false | 312 // !true ==> false |
| 313 if (!polarity) { | 313 if (!polarity) { |
| 314 values.BoolConstantValue value = e.value; | 314 values.BoolConstantValue value = e.value; |
| 315 return new Constant.primitive(value.negate()); | 315 return new Constant.bool(value.negate()); |
| 316 } | 316 } |
| 317 return e; | 317 return e; |
| 318 } | 318 } |
| 319 e = visitExpression(e); | 319 e = visitExpression(e); |
| 320 return polarity ? e : new Not(e); | 320 return polarity ? e : new Not(e); |
| 321 } | 321 } |
| 322 | 322 |
| 323 bool isTrue(Expression e) { | 323 bool isTrue(Expression e) { |
| 324 return e is Constant && e.value.isTrue; | 324 return e is Constant && e.value.isTrue; |
| 325 } | 325 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 338 | 338 |
| 339 Expression makeOr(Expression e1, Expression e2, {bool liftNots: true}) { | 339 Expression makeOr(Expression e1, Expression e2, {bool liftNots: true}) { |
| 340 if (e1 is Not && e2 is Not && liftNots) { | 340 if (e1 is Not && e2 is Not && liftNots) { |
| 341 return new Not(new LogicalOperator.and(e1.operand, e2.operand)); | 341 return new Not(new LogicalOperator.and(e1.operand, e2.operand)); |
| 342 } else { | 342 } else { |
| 343 return new LogicalOperator.or(e1, e2); | 343 return new LogicalOperator.or(e1, e2); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| OLD | NEW |