| 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 tree_ir.optimization.logical_rewriter; | 5 library tree_ir.optimization.logical_rewriter; | 
| 6 | 6 | 
| 7 import '../tree_ir_nodes.dart'; | 7 import '../tree_ir_nodes.dart'; | 
| 8 import 'optimization.dart' show Pass; | 8 import 'optimization.dart' show Pass; | 
| 9 import '../../constants/values.dart' as values; | 9 import '../../constants/values.dart' as values; | 
| 10 | 10 | 
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 328   } | 328   } | 
| 329 | 329 | 
| 330   /// True if the given expression is known to evaluate to a boolean. | 330   /// True if the given expression is known to evaluate to a boolean. | 
| 331   /// This will not recursively traverse [Conditional] expressions, but if | 331   /// This will not recursively traverse [Conditional] expressions, but if | 
| 332   /// applied to the result of [visitExpression] conditionals will have been | 332   /// applied to the result of [visitExpression] conditionals will have been | 
| 333   /// rewritten anyway. | 333   /// rewritten anyway. | 
| 334   bool isBooleanValued(Expression e) { | 334   bool isBooleanValued(Expression e) { | 
| 335     return isTrue(e) || | 335     return isTrue(e) || | 
| 336            isFalse(e) || | 336            isFalse(e) || | 
| 337            e is Not || | 337            e is Not || | 
| 338            e is LogicalOperator || | 338            e is LogicalOperator && isBooleanValuedLogicalOperator(e) || | 
| 339            e is ApplyBuiltinOperator && operatorReturnsBool(e.operator); | 339            e is ApplyBuiltinOperator && operatorReturnsBool(e.operator) || | 
|  | 340            e is TypeOperator && isBooleanValuedTypeOperator(e); | 
|  | 341   } | 
|  | 342 | 
|  | 343   bool isBooleanValuedLogicalOperator(LogicalOperator e) { | 
|  | 344     return isBooleanValued(e.left) && isBooleanValued(e.right); | 
| 340   } | 345   } | 
| 341 | 346 | 
| 342   /// True if the given operator always returns `true` or `false`. | 347   /// True if the given operator always returns `true` or `false`. | 
| 343   bool operatorReturnsBool(BuiltinOperator operator) { | 348   bool operatorReturnsBool(BuiltinOperator operator) { | 
| 344     switch (operator) { | 349     switch (operator) { | 
| 345       case BuiltinOperator.StrictEq: | 350       case BuiltinOperator.StrictEq: | 
| 346       case BuiltinOperator.StrictNeq: | 351       case BuiltinOperator.StrictNeq: | 
| 347       case BuiltinOperator.LooseEq: | 352       case BuiltinOperator.LooseEq: | 
| 348       case BuiltinOperator.LooseNeq: | 353       case BuiltinOperator.LooseNeq: | 
| 349       case BuiltinOperator.NumLt: | 354       case BuiltinOperator.NumLt: | 
| 350       case BuiltinOperator.NumLe: | 355       case BuiltinOperator.NumLe: | 
| 351       case BuiltinOperator.NumGt: | 356       case BuiltinOperator.NumGt: | 
| 352       case BuiltinOperator.NumGe: | 357       case BuiltinOperator.NumGe: | 
| 353       case BuiltinOperator.IsNumber: | 358       case BuiltinOperator.IsNumber: | 
| 354       case BuiltinOperator.IsNotNumber: | 359       case BuiltinOperator.IsNotNumber: | 
| 355       case BuiltinOperator.IsFloor: | 360       case BuiltinOperator.IsFloor: | 
| 356       case BuiltinOperator.IsNumberAndFloor: | 361       case BuiltinOperator.IsNumberAndFloor: | 
| 357       case BuiltinOperator.Identical: | 362       case BuiltinOperator.Identical: | 
| 358         return true; | 363         return true; | 
| 359       default: | 364       default: | 
| 360         return false; | 365         return false; | 
| 361     } | 366     } | 
| 362   } | 367   } | 
| 363 | 368 | 
|  | 369   bool isBooleanValuedTypeOperator(TypeOperator e) { | 
|  | 370     return e.isTypeTest; | 
|  | 371   } | 
|  | 372 | 
| 364   BuiltinOperator negateBuiltin(BuiltinOperator operator) { | 373   BuiltinOperator negateBuiltin(BuiltinOperator operator) { | 
| 365     switch (operator) { | 374     switch (operator) { | 
| 366       case BuiltinOperator.StrictEq: return BuiltinOperator.StrictNeq; | 375       case BuiltinOperator.StrictEq: return BuiltinOperator.StrictNeq; | 
| 367       case BuiltinOperator.StrictNeq: return BuiltinOperator.StrictEq; | 376       case BuiltinOperator.StrictNeq: return BuiltinOperator.StrictEq; | 
| 368       case BuiltinOperator.LooseEq: return BuiltinOperator.LooseNeq; | 377       case BuiltinOperator.LooseEq: return BuiltinOperator.LooseNeq; | 
| 369       case BuiltinOperator.LooseNeq: return BuiltinOperator.LooseEq; | 378       case BuiltinOperator.LooseNeq: return BuiltinOperator.LooseEq; | 
| 370       case BuiltinOperator.IsNumber: return BuiltinOperator.IsNotNumber; | 379       case BuiltinOperator.IsNumber: return BuiltinOperator.IsNotNumber; | 
| 371       case BuiltinOperator.IsNotNumber: return BuiltinOperator.IsNumber; | 380       case BuiltinOperator.IsNotNumber: return BuiltinOperator.IsNumber; | 
| 372 | 381 | 
| 373       // Because of NaN, these do not have a negated form. | 382       // Because of NaN, these do not have a negated form. | 
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 545     } else if (e1 is Assign) { | 554     } else if (e1 is Assign) { | 
| 546       return e2 is VariableUse && e1.variable == e2.variable; | 555       return e2 is VariableUse && e1.variable == e2.variable; | 
| 547     } | 556     } | 
| 548     return false; | 557     return false; | 
| 549   } | 558   } | 
| 550 | 559 | 
| 551   void destroyVariableUse(VariableUse node) { | 560   void destroyVariableUse(VariableUse node) { | 
| 552     --node.variable.readCount; | 561     --node.variable.readCount; | 
| 553   } | 562   } | 
| 554 } | 563 } | 
| 555 |  | 
| OLD | NEW | 
|---|