| 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 '../closure.dart' as closure; | 7 import '../closure.dart' as closure; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart' show | 9 import '../common/names.dart' show |
| 10 Names, | 10 Names, |
| (...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 code = "$code = ${argumentTemplates.single}"; | 2055 code = "$code = ${argumentTemplates.single}"; |
| 2056 } else { | 2056 } else { |
| 2057 assert(argumentTemplates.isEmpty); | 2057 assert(argumentTemplates.isEmpty); |
| 2058 assert(function.kind == ElementKind.GETTER); | 2058 assert(function.kind == ElementKind.GETTER); |
| 2059 } | 2059 } |
| 2060 // Generate the [ForeignCode] expression and a return statement to return | 2060 // Generate the [ForeignCode] expression and a return statement to return |
| 2061 // its value. | 2061 // its value. |
| 2062 ir.Primitive value = buildForeignCode( | 2062 ir.Primitive value = buildForeignCode( |
| 2063 js.js.uncachedExpressionTemplate(code), | 2063 js.js.uncachedExpressionTemplate(code), |
| 2064 arguments, | 2064 arguments, |
| 2065 behavior); | 2065 behavior, |
| 2066 type: program.getTypeMaskForNativeFunction(function)); |
| 2066 buildReturn(value: value, sourceInformation: source); | 2067 buildReturn(value: value, sourceInformation: source); |
| 2067 } | 2068 } |
| 2068 | 2069 |
| 2069 /// Create a blocks of [statements] by applying [build] to all reachable | 2070 /// Create a blocks of [statements] by applying [build] to all reachable |
| 2070 /// statements. The first statement is assumed to be reachable. | 2071 /// statements. The first statement is assumed to be reachable. |
| 2071 // TODO(johnniwinther): Type [statements] as `Iterable` when `NodeList` uses | 2072 // TODO(johnniwinther): Type [statements] as `Iterable` when `NodeList` uses |
| 2072 // `List` instead of `Link`. | 2073 // `List` instead of `Link`. |
| 2073 void buildBlock(var statements, BuildFunction build) { | 2074 void buildBlock(var statements, BuildFunction build) { |
| 2074 // Build(Block(stamements), C) = C' | 2075 // Build(Block(stamements), C) = C' |
| 2075 // where C' = statements.fold(Build, C) | 2076 // where C' = statements.fold(Build, C) |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2627 } | 2628 } |
| 2628 | 2629 |
| 2629 ir.Primitive buildInvocationMirror(Selector selector, | 2630 ir.Primitive buildInvocationMirror(Selector selector, |
| 2630 List<ir.Primitive> arguments) { | 2631 List<ir.Primitive> arguments) { |
| 2631 return addPrimitive(new ir.CreateInvocationMirror(selector, arguments)); | 2632 return addPrimitive(new ir.CreateInvocationMirror(selector, arguments)); |
| 2632 } | 2633 } |
| 2633 | 2634 |
| 2634 ir.Primitive buildForeignCode(js.Template codeTemplate, | 2635 ir.Primitive buildForeignCode(js.Template codeTemplate, |
| 2635 List<ir.Primitive> arguments, | 2636 List<ir.Primitive> arguments, |
| 2636 NativeBehavior behavior, | 2637 NativeBehavior behavior, |
| 2637 {Element dependency}) { | 2638 {Element dependency, |
| 2639 TypeMask type}) { |
| 2638 assert(behavior != null); | 2640 assert(behavior != null); |
| 2639 TypeMask type = program.getTypeMaskForForeign(behavior); | 2641 if (type == null) { |
| 2642 type = program.getTypeMaskForForeign(behavior); |
| 2643 } |
| 2640 ir.Primitive result = addPrimitive(new ir.ForeignCode( | 2644 ir.Primitive result = addPrimitive(new ir.ForeignCode( |
| 2641 codeTemplate, | 2645 codeTemplate, |
| 2642 type, | 2646 type, |
| 2643 arguments, | 2647 arguments, |
| 2644 behavior, | 2648 behavior, |
| 2645 dependency: dependency)); | 2649 dependency: dependency)); |
| 2646 if (!codeTemplate.isExpression) { | 2650 if (!codeTemplate.isExpression) { |
| 2647 // Close the term if this is a "throw" expression or native body. | 2651 // Close the term if this is a "throw" expression or native body. |
| 2648 add(new ir.Unreachable()); | 2652 add(new ir.Unreachable()); |
| 2649 _current = null; | 2653 _current = null; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2834 } | 2838 } |
| 2835 | 2839 |
| 2836 class SwitchCaseInfo { | 2840 class SwitchCaseInfo { |
| 2837 final List<ir.Primitive> constants = <ir.Primitive>[]; | 2841 final List<ir.Primitive> constants = <ir.Primitive>[]; |
| 2838 final SubbuildFunction buildBody; | 2842 final SubbuildFunction buildBody; |
| 2839 | 2843 |
| 2840 SwitchCaseInfo(this.buildBody); | 2844 SwitchCaseInfo(this.buildBody); |
| 2841 | 2845 |
| 2842 void addConstant(ir.Primitive constant) => constants.add(constant); | 2846 void addConstant(ir.Primitive constant) => constants.add(constant); |
| 2843 } | 2847 } |
| OLD | NEW |