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 library logical_rewriter; | 5 library logical_rewriter; |
6 | 6 |
7 import '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
8 import 'tree_ir_nodes.dart'; | 8 import 'tree_ir_nodes.dart'; |
9 | 9 |
10 /// Rewrites logical expressions to be more compact in the Tree IR. | 10 /// Rewrites logical expressions to be more compact in the Tree IR. |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 if (e.thenExpression is Not && e.elseExpression is Not && liftNots) { | 401 if (e.thenExpression is Not && e.elseExpression is Not && liftNots) { |
402 e.thenExpression = (e.thenExpression as Not).operand; | 402 e.thenExpression = (e.thenExpression as Not).operand; |
403 e.elseExpression = (e.elseExpression as Not).operand; | 403 e.elseExpression = (e.elseExpression as Not).operand; |
404 return new Not(e); | 404 return new Not(e); |
405 } | 405 } |
406 return e; | 406 return e; |
407 } | 407 } |
408 if (e is Constant && e.value.isBool) { | 408 if (e is Constant && e.value.isBool) { |
409 // !true ==> false | 409 // !true ==> false |
410 if (!polarity) { | 410 if (!polarity) { |
411 values.BoolConstant value = e.value; | 411 values.BoolConstantValue value = e.value; |
412 return new Constant.primitive(value.negate()); | 412 return new Constant.primitive(value.negate()); |
413 } | 413 } |
414 return e; | 414 return e; |
415 } | 415 } |
416 e = visitExpression(e); | 416 e = visitExpression(e); |
417 return polarity ? e : new Not(e); | 417 return polarity ? e : new Not(e); |
418 } | 418 } |
419 | 419 |
420 bool isTrue(Expression e) { | 420 bool isTrue(Expression e) { |
421 return e is Constant && e.value.isTrue; | 421 return e is Constant && e.value.isTrue; |
(...skipping 20 matching lines...) Expand all Loading... |
442 } | 442 } |
443 | 443 |
444 /// Destructively updates each entry of [l] with the result of visiting it. | 444 /// Destructively updates each entry of [l] with the result of visiting it. |
445 void _rewriteList(List<Expression> l) { | 445 void _rewriteList(List<Expression> l) { |
446 for (int i = 0; i < l.length; i++) { | 446 for (int i = 0; i < l.length; i++) { |
447 l[i] = visitExpression(l[i]); | 447 l[i] = visitExpression(l[i]); |
448 } | 448 } |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
OLD | NEW |