| 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 | 8 |
| 9 import '../closure.dart' show BoxLocal, ThisLocal; | 9 import '../closure.dart' show BoxLocal, ThisLocal; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 _forEachClassMember(data.supertype.element, f); | 690 _forEachClassMember(data.supertype.element, f); |
| 691 } | 691 } |
| 692 } | 692 } |
| 693 | 693 |
| 694 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { | 694 ConstantConstructor _getConstructorConstant(IndexedConstructor constructor) { |
| 695 assert(checkFamily(constructor)); | 695 assert(checkFamily(constructor)); |
| 696 ConstructorData data = _memberData[constructor.memberIndex]; | 696 ConstructorData data = _memberData[constructor.memberIndex]; |
| 697 return data.getConstructorConstant(this, constructor); | 697 return data.getConstructorConstant(this, constructor); |
| 698 } | 698 } |
| 699 | 699 |
| 700 ConstantExpression _getFieldConstant(IndexedField field) { | 700 ConstantExpression _getFieldConstantExpression(IndexedField field) { |
| 701 assert(checkFamily(field)); | 701 assert(checkFamily(field)); |
| 702 FieldData data = _memberData[field.memberIndex]; | 702 FieldData data = _memberData[field.memberIndex]; |
| 703 return data.getFieldConstant(this, field); | 703 return data.getFieldConstantExpression(this); |
| 704 } | 704 } |
| 705 | 705 |
| 706 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { | 706 InterfaceType _asInstanceOf(InterfaceType type, ClassEntity cls) { |
| 707 assert(checkFamily(cls)); | 707 assert(checkFamily(cls)); |
| 708 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); | 708 OrderedTypeSet orderedTypeSet = _getOrderedTypeSet(type.element); |
| 709 InterfaceType supertype = | 709 InterfaceType supertype = |
| 710 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); | 710 orderedTypeSet.asInstanceOf(cls, _getHierarchyDepth(cls)); |
| 711 if (supertype != null) { | 711 if (supertype != null) { |
| 712 supertype = _substByContext(supertype, type); | 712 supertype = _substByContext(supertype, type); |
| 713 } | 713 } |
| (...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 return _elementMap._substByContext(base, target); | 1643 return _elementMap._substByContext(base, target); |
| 1644 } | 1644 } |
| 1645 | 1645 |
| 1646 @override | 1646 @override |
| 1647 ConstantConstructor getConstructorConstant(ConstructorEntity constructor) { | 1647 ConstantConstructor getConstructorConstant(ConstructorEntity constructor) { |
| 1648 return _elementMap._getConstructorConstant(constructor); | 1648 return _elementMap._getConstructorConstant(constructor); |
| 1649 } | 1649 } |
| 1650 | 1650 |
| 1651 @override | 1651 @override |
| 1652 ConstantExpression getFieldConstant(FieldEntity field) { | 1652 ConstantExpression getFieldConstant(FieldEntity field) { |
| 1653 return _elementMap._getFieldConstant(field); | 1653 return _elementMap._getFieldConstantExpression(field); |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 @override | 1656 @override |
| 1657 ConstantExpression getLocalConstant(Local local) { | 1657 ConstantExpression getLocalConstant(Local local) { |
| 1658 throw new UnimplementedError("_EvaluationEnvironment.getLocalConstant"); | 1658 throw new UnimplementedError("_EvaluationEnvironment.getLocalConstant"); |
| 1659 } | 1659 } |
| 1660 | 1660 |
| 1661 @override | 1661 @override |
| 1662 String readFromEnvironment(String name) { | 1662 String readFromEnvironment(String name) { |
| 1663 return _environment.valueOf(name); | 1663 return _environment.valueOf(name); |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2132 MemberDefinition getMemberDefinition(MemberEntity member) { | 2132 MemberDefinition getMemberDefinition(MemberEntity member) { |
| 2133 return _getMemberDefinition(member); | 2133 return _getMemberDefinition(member); |
| 2134 } | 2134 } |
| 2135 | 2135 |
| 2136 @override | 2136 @override |
| 2137 ClassDefinition getClassDefinition(ClassEntity cls) { | 2137 ClassDefinition getClassDefinition(ClassEntity cls) { |
| 2138 return _getClassDefinition(cls); | 2138 return _getClassDefinition(cls); |
| 2139 } | 2139 } |
| 2140 | 2140 |
| 2141 @override | 2141 @override |
| 2142 ConstantValue getFieldConstantValue(ir.Field field) { | 2142 ConstantValue getFieldConstantValue(covariant IndexedField field) { |
| 2143 // TODO(johnniwinther): Cache the result in [FieldData]. | 2143 assert(checkFamily(field)); |
| 2144 return getConstantValue(field.initializer, | 2144 FieldData data = _memberData[field.memberIndex]; |
| 2145 requireConstant: field.isConst, implicitNull: !field.isConst); | 2145 return data.getFieldConstantValue(this); |
| 2146 } | 2146 } |
| 2147 | 2147 |
| 2148 bool hasConstantFieldInitializer(covariant IndexedField field) { | 2148 bool hasConstantFieldInitializer(covariant IndexedField field) { |
| 2149 assert(checkFamily(field)); |
| 2149 FieldData data = _memberData[field.memberIndex]; | 2150 FieldData data = _memberData[field.memberIndex]; |
| 2150 return getFieldConstantValue(data.definition.node) != null; | 2151 return data.hasConstantFieldInitializer(this); |
| 2151 } | 2152 } |
| 2152 | 2153 |
| 2153 ConstantValue getConstantFieldInitializer(covariant IndexedField field) { | 2154 ConstantValue getConstantFieldInitializer(covariant IndexedField field) { |
| 2155 assert(checkFamily(field)); |
| 2154 FieldData data = _memberData[field.memberIndex]; | 2156 FieldData data = _memberData[field.memberIndex]; |
| 2155 ConstantValue value = getFieldConstantValue(data.definition.node); | 2157 return data.getConstantFieldInitializer(this); |
| 2156 assert(value != null, | |
| 2157 failedAt(field, "Field $field doesn't have a constant initial value.")); | |
| 2158 return value; | |
| 2159 } | 2158 } |
| 2160 | 2159 |
| 2161 void forEachParameter(covariant IndexedFunction function, | 2160 void forEachParameter(covariant IndexedFunction function, |
| 2162 void f(DartType type, String name, ConstantValue defaultValue)) { | 2161 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 2163 FunctionData data = _memberData[function.memberIndex]; | 2162 FunctionData data = _memberData[function.memberIndex]; |
| 2164 data.forEachParameter(this, f); | 2163 data.forEachParameter(this, f); |
| 2165 } | 2164 } |
| 2166 | 2165 |
| 2167 void _forEachConstructorBody( | 2166 void _forEachConstructorBody( |
| 2168 IndexedClass cls, void f(ConstructorBodyEntity member)) { | 2167 IndexedClass cls, void f(ConstructorBodyEntity member)) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 /// | 2333 /// |
| 2335 /// These names are not used in generated code, just as element name. | 2334 /// These names are not used in generated code, just as element name. |
| 2336 String _getClosureVariableName(String name, int id) { | 2335 String _getClosureVariableName(String name, int id) { |
| 2337 return "_captured_${name}_$id"; | 2336 return "_captured_${name}_$id"; |
| 2338 } | 2337 } |
| 2339 | 2338 |
| 2340 String getDeferredUri(ir.LibraryDependency node) { | 2339 String getDeferredUri(ir.LibraryDependency node) { |
| 2341 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2340 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
| 2342 } | 2341 } |
| 2343 } | 2342 } |
| OLD | NEW |