| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.ir_builder; | 5 library dart2js.ir_builder; |
| 6 | 6 |
| 7 import '../compile_time_constants.dart' show BackendConstantEnvironment; | 7 import '../compile_time_constants.dart' show BackendConstantEnvironment; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; | 9 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 2557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 if (type.isObject || type.isDynamic) { | 2568 if (type.isObject || type.isDynamic) { |
| 2569 // `x is Object` and `x is dynamic` are always true, even if x is null. | 2569 // `x is Object` and `x is dynamic` are always true, even if x is null. |
| 2570 return buildBooleanConstant(true); | 2570 return buildBooleanConstant(true); |
| 2571 } | 2571 } |
| 2572 if (type is InterfaceType && type.element == program.nullClass) { | 2572 if (type is InterfaceType && type.element == program.nullClass) { |
| 2573 // `x is Null` is true if and only if x is null. | 2573 // `x is Null` is true if and only if x is null. |
| 2574 return _buildCheckNull(value); | 2574 return _buildCheckNull(value); |
| 2575 } | 2575 } |
| 2576 return addPrimitive(new ir.TypeTest(value, type, typeArguments)); | 2576 return addPrimitive(new ir.TypeTest(value, type, typeArguments)); |
| 2577 } else { | 2577 } else { |
| 2578 if (type.isObject || type.isDynamic) { |
| 2579 // `x as Object` and `x as dynamic` are the same as `x`. |
| 2580 return value; |
| 2581 } |
| 2578 return _continueWithExpression( | 2582 return _continueWithExpression( |
| 2579 (k) => new ir.TypeCast(value, type, typeArguments, k)); | 2583 (k) => new ir.TypeCast(value, type, typeArguments, k)); |
| 2580 } | 2584 } |
| 2581 } | 2585 } |
| 2582 | 2586 |
| 2583 /// Create an if-null expression. This is equivalent to a conditional | 2587 /// Create an if-null expression. This is equivalent to a conditional |
| 2584 /// expression whose result is either [value] if [value] is not null, or | 2588 /// expression whose result is either [value] if [value] is not null, or |
| 2585 /// `right` if [value] is null. Only when [value] is null, [buildRight] is | 2589 /// `right` if [value] is null. Only when [value] is null, [buildRight] is |
| 2586 /// evaluated to produce the `right` value. | 2590 /// evaluated to produce the `right` value. |
| 2587 ir.Primitive buildIfNull(ir.Primitive value, | 2591 ir.Primitive buildIfNull(ir.Primitive value, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2686 } | 2690 } |
| 2687 | 2691 |
| 2688 class SwitchCaseInfo { | 2692 class SwitchCaseInfo { |
| 2689 final List<ir.Primitive> constants = <ir.Primitive>[]; | 2693 final List<ir.Primitive> constants = <ir.Primitive>[]; |
| 2690 final SubbuildFunction buildBody; | 2694 final SubbuildFunction buildBody; |
| 2691 | 2695 |
| 2692 SwitchCaseInfo(this.buildBody); | 2696 SwitchCaseInfo(this.buildBody); |
| 2693 | 2697 |
| 2694 void addConstant(ir.Primitive constant) => constants.add(constant); | 2698 void addConstant(ir.Primitive constant) => constants.add(constant); |
| 2695 } | 2699 } |
| OLD | NEW |