Chromium Code Reviews| 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 '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../constants/values.dart' show PrimitiveConstantValue; | 9 import '../constants/values.dart' show PrimitiveConstantValue; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2016 | 2016 |
| 2017 /// Creates a type test or type cast of [receiver] against [type]. | 2017 /// Creates a type test or type cast of [receiver] against [type]. |
| 2018 /// | 2018 /// |
| 2019 /// Set [isTypeTest] to `true` to create a type test and furthermore set | 2019 /// Set [isTypeTest] to `true` to create a type test and furthermore set |
| 2020 /// [isNotCheck] to `true` to create a negated type test. | 2020 /// [isNotCheck] to `true` to create a negated type test. |
| 2021 ir.Primitive buildTypeOperator(ir.Primitive receiver, | 2021 ir.Primitive buildTypeOperator(ir.Primitive receiver, |
| 2022 DartType type, | 2022 DartType type, |
| 2023 {bool isTypeTest: false, | 2023 {bool isTypeTest: false, |
| 2024 bool isNotCheck: false}); | 2024 bool isNotCheck: false}); |
| 2025 | 2025 |
| 2026 /// Creates a type test checking whether [value] is null. | |
| 2027 ir.Primitive buildChecknull(ir.Primitive value); | |
| 2028 | |
| 2026 /// Create a lazy and/or expression. [leftValue] is the value of the left | 2029 /// Create a lazy and/or expression. [leftValue] is the value of the left |
| 2027 /// operand and [buildRightValue] is called to process the value of the right | 2030 /// operand and [buildRightValue] is called to process the value of the right |
| 2028 /// operand in the context of its own [IrBuilder]. | 2031 /// operand in the context of its own [IrBuilder]. |
| 2029 ir.Primitive buildLogicalOperator( | 2032 ir.Primitive buildLogicalOperator( |
| 2030 ir.Primitive leftValue, | 2033 ir.Primitive leftValue, |
| 2031 ir.Primitive buildRightValue(IrBuilder builder), | 2034 ir.Primitive buildRightValue(IrBuilder builder), |
| 2032 {bool isLazyOr: false}) { | 2035 {bool isLazyOr: false}) { |
| 2033 // e0 && e1 is translated as if e0 ? (e1 == true) : false. | 2036 // e0 && e1 is translated as if e0 ? (e1 == true) : false. |
| 2034 // e0 || e1 is translated as if e0 ? true : (e1 == true). | 2037 // e0 || e1 is translated as if e0 ? true : (e1 == true). |
| 2035 // The translation must convert both e0 and e1 to booleans and handle | 2038 // The translation must convert both e0 and e1 to booleans and handle |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2316 DartType type, | 2319 DartType type, |
| 2317 {bool isTypeTest: false, | 2320 {bool isTypeTest: false, |
| 2318 bool isNotCheck: false}) { | 2321 bool isNotCheck: false}) { |
| 2319 assert(isOpen); | 2322 assert(isOpen); |
| 2320 assert(isTypeTest != null); | 2323 assert(isTypeTest != null); |
| 2321 assert(!isNotCheck || isTypeTest); | 2324 assert(!isNotCheck || isTypeTest); |
| 2322 ir.Primitive check = _continueWithExpression( | 2325 ir.Primitive check = _continueWithExpression( |
| 2323 (k) => new ir.TypeOperator(receiver, type, k, isTypeTest: isTypeTest )); | 2326 (k) => new ir.TypeOperator(receiver, type, k, isTypeTest: isTypeTest )); |
| 2324 return isNotCheck ? buildNegation(check) : check; | 2327 return isNotCheck ? buildNegation(check) : check; |
| 2325 } | 2328 } |
| 2329 | |
| 2330 @override | |
| 2331 ir.Primitive buildCheckNull(ir.Primitive value) { | |
|
Johnni Winther
2015/05/29 10:23:24
Move the implementation to IrBuilder.
Siggi Cherem (dart-lang)
2015/05/29 18:14:05
After addressing Kevin's comment, this moved just
| |
| 2332 assert(isOpen); | |
| 2333 return addPrimitive(new ir.Identical(value, buildNullConstant())); | |
|
Kevin Millikin (Google)
2015/05/29 11:02:03
Identical is a 'JS specific' IR primitive, which m
Siggi Cherem (dart-lang)
2015/05/29 18:14:05
Great points - I moved most of the implementation
Siggi Cherem (dart-lang)
2015/05/29 19:02:02
Just synced and noticed that DartIrBuilder is gone
| |
| 2334 } | |
| 2326 } | 2335 } |
| 2327 | 2336 |
| 2328 /// State shared between JsIrBuilders within the same function. | 2337 /// State shared between JsIrBuilders within the same function. |
| 2329 /// | 2338 /// |
| 2330 /// Note that this is not shared between builders of nested functions. | 2339 /// Note that this is not shared between builders of nested functions. |
| 2331 class JsIrBuilderSharedState { | 2340 class JsIrBuilderSharedState { |
| 2332 /// Maps boxed locals to their location. These locals are not part of | 2341 /// Maps boxed locals to their location. These locals are not part of |
| 2333 /// the environment. | 2342 /// the environment. |
| 2334 final Map<Local, ClosureLocation> boxedVariables = {}; | 2343 final Map<Local, ClosureLocation> boxedVariables = {}; |
| 2335 | 2344 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2688 assert(isTypeTest != null); | 2697 assert(isTypeTest != null); |
| 2689 assert(!isNotCheck || isTypeTest); | 2698 assert(!isNotCheck || isTypeTest); |
| 2690 ir.Primitive interceptor = | 2699 ir.Primitive interceptor = |
| 2691 addPrimitive(new ir.Interceptor(receiver, program.interceptedClasses)); | 2700 addPrimitive(new ir.Interceptor(receiver, program.interceptedClasses)); |
| 2692 ir.Primitive check = _continueWithExpression( | 2701 ir.Primitive check = _continueWithExpression( |
| 2693 (k) => new ir.TypeOperator(interceptor, type, k, | 2702 (k) => new ir.TypeOperator(interceptor, type, k, |
| 2694 isTypeTest: isTypeTest)); | 2703 isTypeTest: isTypeTest)); |
| 2695 return isNotCheck ? buildNegation(check) : check; | 2704 return isNotCheck ? buildNegation(check) : check; |
| 2696 } | 2705 } |
| 2697 | 2706 |
| 2707 @override | |
| 2708 ir.Primitive buildCheckNull(ir.Primitive value) { | |
|
Johnni Winther
2015/05/29 10:23:24
Remove this.
Siggi Cherem (dart-lang)
2015/05/29 18:14:05
Acknowledged.
| |
| 2709 assert(isOpen); | |
| 2710 return addPrimitive(new ir.Identical(value, buildNullConstant())); | |
|
Kevin Millikin (Google)
2015/05/29 11:02:03
This is completely safe, but since buildNullConsta
Siggi Cherem (dart-lang)
2015/05/29 18:14:05
Done.
| |
| 2711 } | |
| 2698 } | 2712 } |
| 2699 | 2713 |
| 2700 | 2714 |
| 2701 /// Location of a variable relative to a given closure. | 2715 /// Location of a variable relative to a given closure. |
| 2702 class ClosureLocation { | 2716 class ClosureLocation { |
| 2703 /// If not `null`, this location is [box].[field]. | 2717 /// If not `null`, this location is [box].[field]. |
| 2704 /// The location of [box] can be obtained separately from an | 2718 /// The location of [box] can be obtained separately from an |
| 2705 /// enclosing [ClosureEnvironment] or [ClosureScope]. | 2719 /// enclosing [ClosureEnvironment] or [ClosureScope]. |
| 2706 /// If `null`, then the location is [field] on the enclosing function object. | 2720 /// If `null`, then the location is [field] on the enclosing function object. |
| 2707 final BoxLocal box; | 2721 final BoxLocal box; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2769 } | 2783 } |
| 2770 | 2784 |
| 2771 /// Synthetic parameter to a JavaScript factory method that takes the type | 2785 /// Synthetic parameter to a JavaScript factory method that takes the type |
| 2772 /// argument given for the type variable [variable]. | 2786 /// argument given for the type variable [variable]. |
| 2773 class TypeInformationParameter implements Local { | 2787 class TypeInformationParameter implements Local { |
| 2774 final TypeVariableElement variable; | 2788 final TypeVariableElement variable; |
| 2775 final ExecutableElement executableContext; | 2789 final ExecutableElement executableContext; |
| 2776 TypeInformationParameter(this.variable, this.executableContext); | 2790 TypeInformationParameter(this.variable, this.executableContext); |
| 2777 String get name => variable.name; | 2791 String get name => variable.name; |
| 2778 } | 2792 } |
| OLD | NEW |