| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'package:js_runtime/shared/embedded_names.dart'; |
| 5 import 'package:kernel/ast.dart' as ir; | 6 import 'package:kernel/ast.dart' as ir; |
| 6 | 7 |
| 7 import '../closure.dart'; | 8 import '../closure.dart'; |
| 8 import '../common.dart'; | 9 import '../common.dart'; |
| 9 import '../compiler.dart'; | 10 import '../compiler.dart'; |
| 10 import '../constants/expressions.dart'; | 11 import '../constants/expressions.dart'; |
| 11 import '../constants/values.dart'; | 12 import '../constants/values.dart'; |
| 12 import '../common_elements.dart'; | 13 import '../common_elements.dart'; |
| 13 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
| 14 import '../elements/entities.dart'; | 15 import '../elements/entities.dart'; |
| 15 import '../elements/jumps.dart'; | 16 import '../elements/jumps.dart'; |
| 16 import '../elements/modelx.dart'; | 17 import '../elements/modelx.dart'; |
| 17 import '../elements/resolution_types.dart'; | 18 import '../elements/resolution_types.dart'; |
| 18 import '../elements/types.dart'; | 19 import '../elements/types.dart'; |
| 20 import '../js/js.dart' as js; |
| 19 import '../js_backend/js_backend.dart'; | 21 import '../js_backend/js_backend.dart'; |
| 20 import '../kernel/element_map.dart'; | 22 import '../kernel/element_map.dart'; |
| 21 import '../kernel/kernel.dart'; | 23 import '../kernel/kernel.dart'; |
| 22 import '../native/native.dart' as native; | 24 import '../native/native.dart' as native; |
| 23 import '../resolution/tree_elements.dart'; | 25 import '../resolution/tree_elements.dart'; |
| 24 import '../tree/tree.dart' as ast; | 26 import '../tree/tree.dart' as ast; |
| 25 import '../types/masks.dart'; | 27 import '../types/masks.dart'; |
| 26 import '../types/types.dart'; | 28 import '../types/types.dart'; |
| 27 import '../universe/selector.dart'; | 29 import '../universe/selector.dart'; |
| 28 import '../world.dart'; | 30 import '../world.dart'; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 {bool isContinueTarget: false}) { | 234 {bool isContinueTarget: false}) { |
| 233 return _jumpTargets.putIfAbsent(node, () { | 235 return _jumpTargets.putIfAbsent(node, () { |
| 234 if (node is ir.LabeledStatement && _jumpTargets.containsKey(node.body)) { | 236 if (node is ir.LabeledStatement && _jumpTargets.containsKey(node.body)) { |
| 235 return _jumpTargets[node.body]; | 237 return _jumpTargets[node.body]; |
| 236 } | 238 } |
| 237 return new KernelJumpTarget(node, this, | 239 return new KernelJumpTarget(node, this, |
| 238 makeContinueLabel: isContinueTarget); | 240 makeContinueLabel: isContinueTarget); |
| 239 }); | 241 }); |
| 240 } | 242 } |
| 241 | 243 |
| 244 js.Name getNameForJsGetName(ir.Node argument, ConstantValue constant) { |
| 245 int index = _extractEnumIndexFromConstantValue( |
| 246 constant, _compiler.resolution.commonElements.jsGetNameEnum); |
| 247 if (index == null) return null; |
| 248 return _backend.namer |
| 249 .getNameForJsGetName(getNode(argument), JsGetName.values[index]); |
| 250 } |
| 251 |
| 252 js.Template getJsBuiltinTemplate(ConstantValue constant) { |
| 253 int index = _extractEnumIndexFromConstantValue( |
| 254 constant, _compiler.resolution.commonElements.jsBuiltinEnum); |
| 255 if (index == null) return null; |
| 256 return _backend.emitter.builtinTemplateFor(JsBuiltin.values[index]); |
| 257 } |
| 258 |
| 259 int _extractEnumIndexFromConstantValue( |
| 260 ConstantValue constant, ClassEntity classElement) { |
| 261 if (constant is ConstructedConstantValue) { |
| 262 if (constant.type.element == classElement) { |
| 263 assert(constant.fields.length == 1 || constant.fields.length == 2); |
| 264 ConstantValue indexConstant = constant.fields.values.first; |
| 265 if (indexConstant is IntConstantValue) { |
| 266 return indexConstant.primitiveValue; |
| 267 } |
| 268 } |
| 269 } |
| 270 return null; |
| 271 } |
| 272 |
| 242 DartType getDartType(ir.DartType type) { | 273 DartType getDartType(ir.DartType type) { |
| 243 return _typeConverter.convert(type); | 274 return _typeConverter.convert(type); |
| 244 } | 275 } |
| 245 | 276 |
| 246 List<DartType> getDartTypes(List<ir.DartType> types) { | 277 List<DartType> getDartTypes(List<ir.DartType> types) { |
| 247 return types.map(getDartType).toList(); | 278 return types.map(getDartType).toList(); |
| 248 } | 279 } |
| 249 | 280 |
| 250 /// Computes the function type corresponding the signature of [node]. | 281 /// Computes the function type corresponding the signature of [node]. |
| 251 FunctionType getFunctionType(ir.FunctionNode node) { | 282 FunctionType getFunctionType(ir.FunctionNode node) { |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { | 643 TypeMask selectorTypeOf(Selector selector, TypeMask mask) { |
| 613 return TypeMaskFactory.inferredTypeForSelector( | 644 return TypeMaskFactory.inferredTypeForSelector( |
| 614 selector, mask, _globalInferenceResults); | 645 selector, mask, _globalInferenceResults); |
| 615 } | 646 } |
| 616 | 647 |
| 617 TypeMask typeFromNativeBehavior( | 648 TypeMask typeFromNativeBehavior( |
| 618 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { | 649 native.NativeBehavior nativeBehavior, ClosedWorld closedWorld) { |
| 619 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); | 650 return TypeMaskFactory.fromNativeBehavior(nativeBehavior, closedWorld); |
| 620 } | 651 } |
| 621 } | 652 } |
| OLD | NEW |