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