| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; | 134 native.BehaviorBuilder get nativeBehaviorBuilder => _nativeBehaviorBuilder; |
| 135 | 135 |
| 136 @override | 136 @override |
| 137 ConstantValue computeConstantValue(ConstantExpression constant, | 137 ConstantValue computeConstantValue(ConstantExpression constant, |
| 138 {bool requireConstant: true}) { | 138 {bool requireConstant: true}) { |
| 139 return _constantEnvironment.getConstantValue(constant); | 139 return _constantEnvironment.getConstantValue(constant); |
| 140 } | 140 } |
| 141 | 141 |
| 142 @override | 142 @override |
| 143 ConstantValue getFieldConstantValue(ir.Field field) { | 143 ConstantValue getFieldConstantValue(ir.Field field) { |
| 144 // TODO(johnniwinther): Cache the result in [_FieldData]. |
| 144 return getConstantValue(field.initializer, requireConstant: field.isConst); | 145 return getConstantValue(field.initializer, requireConstant: field.isConst); |
| 145 } | 146 } |
| 146 | 147 |
| 147 LibraryEntity lookupLibrary(Uri uri) { | 148 LibraryEntity lookupLibrary(Uri uri) { |
| 148 _KLibraryEnv libraryEnv = _env.lookupLibrary(uri); | 149 _KLibraryEnv libraryEnv = _env.lookupLibrary(uri); |
| 149 if (libraryEnv == null) return null; | 150 if (libraryEnv == null) return null; |
| 150 return _getLibrary(libraryEnv.library, libraryEnv); | 151 return _getLibrary(libraryEnv.library, libraryEnv); |
| 151 } | 152 } |
| 152 | 153 |
| 153 KLibrary _getLibrary(ir.Library node, [_KLibraryEnv libraryEnv]) { | 154 KLibrary _getLibrary(ir.Library node, [_KLibraryEnv libraryEnv]) { |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 | 667 |
| 667 @override | 668 @override |
| 668 Local getLocalFunction(ir.TreeNode node) => _getLocal(node); | 669 Local getLocalFunction(ir.TreeNode node) => _getLocal(node); |
| 669 | 670 |
| 670 @override | 671 @override |
| 671 ClassEntity getClass(ir.Class node) => _getClass(node); | 672 ClassEntity getClass(ir.Class node) => _getClass(node); |
| 672 | 673 |
| 673 @override | 674 @override |
| 674 FieldEntity getField(ir.Field node) => _getField(node); | 675 FieldEntity getField(ir.Field node) => _getField(node); |
| 675 | 676 |
| 677 bool hasConstantFieldInitializer(KField field) { |
| 678 _FieldData data = _memberList[field.memberIndex]; |
| 679 return getFieldConstantValue(data.node) != null; |
| 680 } |
| 681 |
| 676 TypeVariableEntity getTypeVariable(ir.TypeParameter node) => | 682 TypeVariableEntity getTypeVariable(ir.TypeParameter node) => |
| 677 _getTypeVariable(node); | 683 _getTypeVariable(node); |
| 678 | 684 |
| 679 @override | 685 @override |
| 680 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); | 686 FunctionEntity getMethod(ir.Procedure node) => _getMethod(node); |
| 681 | 687 |
| 688 void forEachParameter(KFunction function, |
| 689 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 690 _FunctionData data = _memberList[function.memberIndex]; |
| 691 data.forEachParameter(this, f); |
| 692 } |
| 693 |
| 682 @override | 694 @override |
| 683 MemberEntity getMember(ir.Member node) { | 695 MemberEntity getMember(ir.Member node) { |
| 684 if (node is ir.Field) { | 696 if (node is ir.Field) { |
| 685 return _getField(node); | 697 return _getField(node); |
| 686 } else if (node is ir.Constructor) { | 698 } else if (node is ir.Constructor) { |
| 687 return _getConstructor(node); | 699 return _getConstructor(node); |
| 688 } else if (node is ir.Procedure) { | 700 } else if (node is ir.Procedure) { |
| 689 if (node.kind == ir.ProcedureKind.Factory) { | 701 if (node.kind == ir.ProcedureKind.Factory) { |
| 690 return _getConstructor(node); | 702 return _getConstructor(node); |
| 691 } else { | 703 } else { |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 | 1071 |
| 1060 class _FunctionData extends _MemberData { | 1072 class _FunctionData extends _MemberData { |
| 1061 final ir.FunctionNode functionNode; | 1073 final ir.FunctionNode functionNode; |
| 1062 FunctionType _type; | 1074 FunctionType _type; |
| 1063 | 1075 |
| 1064 _FunctionData(ir.Member node, this.functionNode) : super(node); | 1076 _FunctionData(ir.Member node, this.functionNode) : super(node); |
| 1065 | 1077 |
| 1066 FunctionType getFunctionType(KernelToElementMapImpl elementMap) { | 1078 FunctionType getFunctionType(KernelToElementMapImpl elementMap) { |
| 1067 return _type ??= elementMap.getFunctionType(functionNode); | 1079 return _type ??= elementMap.getFunctionType(functionNode); |
| 1068 } | 1080 } |
| 1081 |
| 1082 void forEachParameter(KernelToElementMap elementMap, |
| 1083 void f(DartType type, String name, ConstantValue defaultValue)) { |
| 1084 void handleParameter(ir.VariableDeclaration node, {bool isOptional: true}) { |
| 1085 DartType type = elementMap.getDartType(node.type); |
| 1086 String name = node.name; |
| 1087 ConstantValue defaultValue; |
| 1088 if (isOptional) { |
| 1089 if (node.initializer != null) { |
| 1090 defaultValue = elementMap.getConstantValue(node.initializer); |
| 1091 } else { |
| 1092 defaultValue = new NullConstantValue(); |
| 1093 } |
| 1094 } |
| 1095 f(type, name, defaultValue); |
| 1096 } |
| 1097 |
| 1098 for (int i = 0; i < functionNode.positionalParameters.length; i++) { |
| 1099 handleParameter(functionNode.positionalParameters[i], |
| 1100 isOptional: i < functionNode.requiredParameterCount); |
| 1101 } |
| 1102 functionNode.namedParameters.forEach(handleParameter); |
| 1103 } |
| 1069 } | 1104 } |
| 1070 | 1105 |
| 1071 class _ConstructorData extends _FunctionData { | 1106 class _ConstructorData extends _FunctionData { |
| 1072 ConstantConstructor _constantConstructor; | 1107 ConstantConstructor _constantConstructor; |
| 1073 | 1108 |
| 1074 _ConstructorData(ir.Member node, ir.FunctionNode functionNode) | 1109 _ConstructorData(ir.Member node, ir.FunctionNode functionNode) |
| 1075 : super(node, functionNode); | 1110 : super(node, functionNode); |
| 1076 | 1111 |
| 1077 ConstantConstructor getConstructorConstant( | 1112 ConstantConstructor getConstructorConstant( |
| 1078 KernelToElementMapImpl elementMap, KConstructor constructor) { | 1113 KernelToElementMapImpl elementMap, KConstructor constructor) { |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 return node.isExternal && | 1733 return node.isExternal && |
| 1699 !elementMap.isForeignLibrary(node.enclosingLibrary); | 1734 !elementMap.isForeignLibrary(node.enclosingLibrary); |
| 1700 } | 1735 } |
| 1701 | 1736 |
| 1702 @override | 1737 @override |
| 1703 bool isJsInteropMember(MemberEntity element) { | 1738 bool isJsInteropMember(MemberEntity element) { |
| 1704 // TODO(johnniwinther): Compute this. | 1739 // TODO(johnniwinther): Compute this. |
| 1705 return false; | 1740 return false; |
| 1706 } | 1741 } |
| 1707 } | 1742 } |
| OLD | NEW |