Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.kernel.element_map; | 5 library dart2js.kernel.element_map; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
| 8 import 'package:kernel/clone.dart'; | 8 import 'package:kernel/clone.dart'; |
| 9 import 'package:kernel/type_algebra.dart'; | 9 import 'package:kernel/type_algebra.dart'; |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 import '../world.dart'; | 41 import '../world.dart'; |
| 42 import '../util/util.dart' show Link, LinkBuilder; | 42 import '../util/util.dart' show Link, LinkBuilder; |
| 43 import 'element_map.dart'; | 43 import 'element_map.dart'; |
| 44 import 'elements.dart'; | 44 import 'elements.dart'; |
| 45 | 45 |
| 46 part 'native_basic_data.dart'; | 46 part 'native_basic_data.dart'; |
| 47 part 'no_such_method_resolver.dart'; | 47 part 'no_such_method_resolver.dart'; |
| 48 part 'types.dart'; | 48 part 'types.dart'; |
| 49 | 49 |
| 50 /// Interface for kernel queries needed to implement the [CodegenWorldBuilder]. | 50 /// Interface for kernel queries needed to implement the [CodegenWorldBuilder]. |
| 51 abstract class KernelToWorldBuilder implements KernelToElementMap { | 51 abstract class KernelToWorldBuilder implements KernelToElementMapForBuilding { |
| 52 /// Returns `true` if [field] has a constant initializer. | 52 /// Returns `true` if [field] has a constant initializer. |
| 53 bool hasConstantFieldInitializer(FieldEntity field); | 53 bool hasConstantFieldInitializer(FieldEntity field); |
| 54 | 54 |
| 55 /// Returns the constant initializer for [field]. | 55 /// Returns the constant initializer for [field]. |
| 56 ConstantValue getConstantFieldInitializer(FieldEntity field); | 56 ConstantValue getConstantFieldInitializer(FieldEntity field); |
| 57 | 57 |
| 58 /// Calls [f] for each parameter of [function] providing the type and name of | 58 /// Calls [f] for each parameter of [function] providing the type and name of |
| 59 /// the parameter and the [defaultValue] if the parameter is optional. | 59 /// the parameter and the [defaultValue] if the parameter is optional. |
| 60 void forEachParameter(FunctionEntity function, | 60 void forEachParameter(FunctionEntity function, |
| 61 void f(DartType type, String name, ConstantValue defaultValue)); | 61 void f(DartType type, String name, ConstantValue defaultValue)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /// Element builder used for creating elements and types corresponding to Kernel | 64 /// Element builder used for creating elements and types corresponding to Kernel |
| 65 /// IR nodes. | 65 /// IR nodes. |
| 66 class KernelToElementMapImpl extends KernelToElementMapMixin | 66 class KernelToElementMapImpl extends KernelToElementMapMixin |
| 67 implements KernelToWorldBuilder { | 67 implements KernelToWorldBuilder, KernelToElementMapForImpact { |
| 68 final Environment _environment; | 68 final Environment _environment; |
| 69 CommonElements _commonElements; | 69 CommonElements _commonElements; |
| 70 native.BehaviorBuilder _nativeBehaviorBuilder; | 70 native.BehaviorBuilder _nativeBehaviorBuilder; |
| 71 final DiagnosticReporter reporter; | 71 final DiagnosticReporter reporter; |
| 72 ElementEnvironment _elementEnvironment; | 72 ElementEnvironment _elementEnvironment; |
| 73 DartTypeConverter _typeConverter; | 73 DartTypeConverter _typeConverter; |
| 74 KernelConstantEnvironment _constantEnvironment; | 74 KernelConstantEnvironment _constantEnvironment; |
| 75 _KernelDartTypes _types; | 75 _KernelDartTypes _types; |
| 76 | 76 |
| 77 /// Library environment. Used for fast lookup. | 77 /// Library environment. Used for fast lookup. |
| (...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1105 class _FunctionData extends _MemberData { | 1105 class _FunctionData extends _MemberData { |
| 1106 final ir.FunctionNode functionNode; | 1106 final ir.FunctionNode functionNode; |
| 1107 FunctionType _type; | 1107 FunctionType _type; |
| 1108 | 1108 |
| 1109 _FunctionData(ir.Member node, this.functionNode) : super(node); | 1109 _FunctionData(ir.Member node, this.functionNode) : super(node); |
| 1110 | 1110 |
| 1111 FunctionType getFunctionType(KernelToElementMapImpl elementMap) { | 1111 FunctionType getFunctionType(KernelToElementMapImpl elementMap) { |
| 1112 return _type ??= elementMap.getFunctionType(functionNode); | 1112 return _type ??= elementMap.getFunctionType(functionNode); |
| 1113 } | 1113 } |
| 1114 | 1114 |
| 1115 void forEachParameter(KernelToElementMap elementMap, | 1115 void forEachParameter(KernelToElementMapForBuilding elementMap, |
| 1116 void f(DartType type, String name, ConstantValue defaultValue)) { | 1116 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 1117 void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) { | 1117 void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) { |
| 1118 DartType type = elementMap.getDartType(node.type); | 1118 DartType type = elementMap.getDartType(node.type); |
| 1119 String name = node.name; | 1119 String name = node.name; |
| 1120 ConstantValue defaultValue; | 1120 ConstantValue defaultValue; |
| 1121 if (isOptional) { | 1121 if (isOptional) { |
| 1122 if (node.initializer != null) { | 1122 if (node.initializer != null) { |
| 1123 defaultValue = elementMap.getConstantValue(node.initializer); | 1123 defaultValue = elementMap.getConstantValue(node.initializer); |
| 1124 } else { | 1124 } else { |
| 1125 defaultValue = new NullConstantValue(); | 1125 defaultValue = new NullConstantValue(); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1473 | 1473 |
| 1474 NativeBasicData get nativeBasicData { | 1474 NativeBasicData get nativeBasicData { |
| 1475 throw new UnimplementedError( | 1475 throw new UnimplementedError( |
| 1476 "KernelNativeBehaviorComputer.nativeBasicData"); | 1476 "KernelNativeBehaviorComputer.nativeBasicData"); |
| 1477 } | 1477 } |
| 1478 } | 1478 } |
| 1479 | 1479 |
| 1480 /// Constant environment mapping [ConstantExpression]s to [ConstantValue]s using | 1480 /// Constant environment mapping [ConstantExpression]s to [ConstantValue]s using |
| 1481 /// [_EvaluationEnvironment] for the evaluation. | 1481 /// [_EvaluationEnvironment] for the evaluation. |
| 1482 class KernelConstantEnvironment implements ConstantEnvironment { | 1482 class KernelConstantEnvironment implements ConstantEnvironment { |
| 1483 KernelToElementMap _worldBuilder; | 1483 KernelToElementMapForBuilding _worldBuilder; |
| 1484 Map<ConstantExpression, ConstantValue> _valueMap = | 1484 Map<ConstantExpression, ConstantValue> _valueMap = |
| 1485 <ConstantExpression, ConstantValue>{}; | 1485 <ConstantExpression, ConstantValue>{}; |
| 1486 | 1486 |
| 1487 KernelConstantEnvironment(this._worldBuilder); | 1487 KernelConstantEnvironment(this._worldBuilder); |
| 1488 | 1488 |
| 1489 @override | 1489 @override |
| 1490 ConstantSystem get constantSystem => const JavaScriptConstantSystem(); | 1490 ConstantSystem get constantSystem => const JavaScriptConstantSystem(); |
| 1491 | 1491 |
| 1492 @override | 1492 @override |
| 1493 ConstantValue getConstantValueForVariable(VariableElement element) { | 1493 ConstantValue getConstantValueForVariable(VariableElement element) { |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1832 ir.Member getMemberNode(MemberEntity member) { | 1832 ir.Member getMemberNode(MemberEntity member) { |
| 1833 return _elementMap.getMemberNode(_map.toFrontendMember(member)); | 1833 return _elementMap.getMemberNode(_map.toFrontendMember(member)); |
| 1834 } | 1834 } |
| 1835 | 1835 |
| 1836 @override | 1836 @override |
| 1837 MemberEntity getMember(ir.Member node) { | 1837 MemberEntity getMember(ir.Member node) { |
| 1838 return _map.toBackendMember(_elementMap.getMember(node)); | 1838 return _map.toBackendMember(_elementMap.getMember(node)); |
| 1839 } | 1839 } |
| 1840 | 1840 |
| 1841 @override | 1841 @override |
| 1842 ConstructorEntity getSuperConstructor( | |
|
Siggi Cherem (dart-lang)
2017/06/26 18:05:41
this means that jstoelement-map doesn't need this?
Johnni Winther
2017/06/27 08:26:31
I think it might. We haven't handled explicit supe
| |
| 1843 ir.Constructor constructor, ir.Member target) { | |
| 1844 return _map | |
| 1845 .toBackendMember(_elementMap.getSuperConstructor(constructor, target)); | |
| 1846 } | |
| 1847 | |
| 1848 @override | |
| 1849 ConstructorEntity getConstructor(ir.Member node) { | 1842 ConstructorEntity getConstructor(ir.Member node) { |
| 1850 return _map.toBackendMember(_elementMap.getConstructor(node)); | 1843 return _map.toBackendMember(_elementMap.getConstructor(node)); |
| 1851 } | 1844 } |
| 1852 | 1845 |
| 1853 @override | 1846 @override |
| 1854 InterfaceType createInterfaceType( | 1847 InterfaceType createInterfaceType( |
| 1855 ir.Class cls, List<ir.DartType> typeArguments) { | 1848 ir.Class cls, List<ir.DartType> typeArguments) { |
| 1856 return _map | 1849 return _map |
| 1857 .toBackendType(_elementMap.createInterfaceType(cls, typeArguments)); | 1850 .toBackendType(_elementMap.createInterfaceType(cls, typeArguments)); |
| 1858 } | 1851 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1919 throw new UnsupportedError( | 1912 throw new UnsupportedError( |
| 1920 "JsKernelToElementMap.getConstantFieldInitializer"); | 1913 "JsKernelToElementMap.getConstantFieldInitializer"); |
| 1921 } | 1914 } |
| 1922 | 1915 |
| 1923 @override | 1916 @override |
| 1924 bool hasConstantFieldInitializer(FieldEntity field) { | 1917 bool hasConstantFieldInitializer(FieldEntity field) { |
| 1925 throw new UnsupportedError( | 1918 throw new UnsupportedError( |
| 1926 "JsKernelToElementMap.hasConstantFieldInitializer"); | 1919 "JsKernelToElementMap.hasConstantFieldInitializer"); |
| 1927 } | 1920 } |
| 1928 } | 1921 } |
| OLD | NEW |