Chromium Code Reviews| Index: pkg/compiler/lib/src/kernel/world_builder.dart |
| diff --git a/pkg/compiler/lib/src/kernel/world_builder.dart b/pkg/compiler/lib/src/kernel/world_builder.dart |
| index 994508ee68673ef1aa6d3b913b8a7cd64015f58a..4577d8216717d1d592e41de220cf90db965a4347 100644 |
| --- a/pkg/compiler/lib/src/kernel/world_builder.dart |
| +++ b/pkg/compiler/lib/src/kernel/world_builder.dart |
| @@ -66,17 +66,11 @@ class KernelWorldBuilder extends KernelElementAdapterMixin { |
| // TODO(johnniwinther): Change this to a list of 'KMemberData' class if we |
|
Siggi Cherem (dart-lang)
2017/04/24 19:39:39
remove TODO?
Johnni Winther
2017/04/25 08:20:44
Done.
|
| // need more data for members. |
| - List<ir.Member> _memberList = <ir.Member>[]; |
| + List<_MemberData> _memberList = <_MemberData>[]; |
| Map<ir.Member, KConstructor> _constructorMap = <ir.Member, KConstructor>{}; |
| - Map<KConstructor, ConstantConstructor> _constructorConstantMap = |
| - <KConstructor, ConstantConstructor>{}; |
| - |
| Map<ir.Procedure, KFunction> _methodMap = <ir.Procedure, KFunction>{}; |
| - |
| Map<ir.Field, KField> _fieldMap = <ir.Field, KField>{}; |
| - Map<KField, ConstantExpression> _fieldConstantMap = |
| - <KField, ConstantExpression>{}; |
| Map<ir.TreeNode, KLocalFunction> _localFunctionMap = |
| <ir.TreeNode, KLocalFunction>{}; |
| @@ -250,20 +244,23 @@ class KernelWorldBuilder extends KernelElementAdapterMixin { |
| Name name = getName(node.name); |
| bool isExternal = node.isExternal; |
| + ir.FunctionNode functionNode; |
| if (node is ir.Constructor) { |
| + functionNode = node.function; |
| constructor = new KGenerativeConstructor(memberIndex, enclosingClass, |
| - name, _getParameterStructure(node.function), |
| + name, _getParameterStructure(functionNode), |
| isExternal: isExternal, isConst: node.isConst); |
| } else if (node is ir.Procedure) { |
| + functionNode = node.function; |
| constructor = new KFactoryConstructor(memberIndex, enclosingClass, name, |
| - _getParameterStructure(node.function), |
| + _getParameterStructure(functionNode), |
| isExternal: isExternal, isConst: node.isConst); |
| } else { |
| // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. |
| throw new SpannableAssertionFailure( |
| NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); |
| } |
| - _memberList.add(node); |
| + _memberList.add(new _ConstructorData(node, functionNode)); |
| return constructor; |
| }); |
| } |
| @@ -309,7 +306,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin { |
| isAbstract: isAbstract); |
| break; |
| } |
| - _memberList.add(node); |
| + _memberList.add(new _FunctionData(node, node.function)); |
| return function; |
| }); |
| } |
| @@ -327,7 +324,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin { |
| } |
| Name name = getName(node.name); |
| bool isStatic = node.isStatic; |
| - _memberList.add(node); |
| + _memberList.add(new _FieldData(node)); |
| return new KField(memberIndex, library, enclosingClass, name, |
| isStatic: isStatic, |
| isAssignable: node.isMutable, |
| @@ -569,34 +566,22 @@ class KernelWorldBuilder extends KernelElementAdapterMixin { |
| FunctionEntity getConstructor(ir.Member node) => _getConstructor(node); |
| ConstantConstructor _getConstructorConstant(KConstructor constructor) { |
| - return _constructorConstantMap.putIfAbsent(constructor, () { |
| - ir.Member node = _memberList[constructor.memberIndex]; |
| - if (node is ir.Constructor && node.isConst) { |
| - return new Constantifier(this).computeConstantConstructor(node); |
| - } |
| - throw new SpannableAssertionFailure( |
| - constructor, |
| - "Unexpected constructor $constructor in " |
| - "KernelWorldBuilder._getConstructorConstant"); |
| - }); |
| + _ConstructorData data = _memberList[constructor.memberIndex]; |
| + return data.getConstructorConstant(this, constructor); |
| } |
| ConstantExpression _getFieldConstant(KField field) { |
| - return _fieldConstantMap.putIfAbsent(field, () { |
| - ir.Field node = _memberList[field.memberIndex]; |
| - if (node.isConst) { |
| - return new Constantifier(this).visit(node.initializer); |
| - } |
| - throw new SpannableAssertionFailure( |
| - field, |
| - "Unexpected field $field in " |
| - "KernelWorldBuilder._getConstructorConstant"); |
| - }); |
| + _FieldData data = _memberList[field.memberIndex]; |
| + return data.getFieldConstant(this, field); |
| + } |
| + |
| + FunctionType _getFunctionType(KFunction function) { |
| + _FunctionData data = _memberList[function.memberIndex]; |
| + return data.getFunctionType(this); |
| } |
| ResolutionImpact computeWorldImpact(KMember member) { |
| - ir.Member node = _memberList[member.memberIndex]; |
| - return buildKernelImpact(node, this); |
| + return _memberList[member.memberIndex].getWorldImpact(this); |
| } |
| } |
| @@ -782,6 +767,81 @@ class KClassEnv { |
| } |
| } |
| +class _MemberData { |
| + final ir.Member node; |
| + |
| + _MemberData(this.node); |
| + |
| + ResolutionImpact getWorldImpact(KernelWorldBuilder worldBuilder) { |
| + return buildKernelImpact(node, worldBuilder); |
| + } |
| +} |
| + |
| +class _FunctionData extends _MemberData { |
| + final ir.FunctionNode functionNode; |
| + FunctionType _type; |
| + CallStructure _callStructure; |
| + |
| + _FunctionData(ir.Member node, this.functionNode) : super(node); |
| + |
| + FunctionType getFunctionType(KernelWorldBuilder worldBuilder) { |
| + return _type ??= worldBuilder.getFunctionType(functionNode); |
| + } |
| + |
| + CallStructure get callStructure { |
| + return _callStructure ??= new CallStructure( |
| + functionNode.positionalParameters.length + |
| + functionNode.namedParameters.length, |
| + functionNode.namedParameters.map((d) => d.name).toList()); |
| + } |
| +} |
| + |
| +class _ConstructorData extends _FunctionData { |
| + ConstantConstructor _constantConstructor; |
| + |
| + _ConstructorData(ir.Member node, ir.FunctionNode functionNode) |
| + : super(node, functionNode); |
| + |
| + ConstantConstructor getConstructorConstant( |
| + KernelWorldBuilder worldBuilder, KConstructor constructor) { |
| + if (_constantConstructor == null) { |
| + if (node is ir.Constructor && constructor.isConst) { |
| + _constantConstructor = |
| + new Constantifier(worldBuilder).computeConstantConstructor(node); |
| + } else { |
| + throw new SpannableAssertionFailure( |
| + constructor, |
| + "Unexpected constructor $constructor in " |
| + "KernelWorldBuilder._getConstructorConstant"); |
| + } |
| + } |
| + return _constantConstructor; |
| + } |
| +} |
| + |
| +class _FieldData extends _MemberData { |
| + ConstantExpression _constant; |
| + |
| + _FieldData(ir.Field node) : super(node); |
| + |
| + ir.Field get node => super.node; |
| + |
| + ConstantExpression getFieldConstant( |
| + KernelWorldBuilder worldBuilder, KField field) { |
| + if (_constant == null) { |
| + if (node.isConst) { |
| + _constant = new Constantifier(worldBuilder).visit(node.initializer); |
| + } else { |
| + throw new SpannableAssertionFailure( |
| + field, |
| + "Unexpected field $field in " |
| + "KernelWorldBuilder._getConstructorConstant"); |
| + } |
| + } |
| + return _constant; |
| + } |
| +} |
| + |
| class KernelElementEnvironment implements ElementEnvironment { |
| final KernelWorldBuilder worldBuilder; |
| @@ -828,7 +888,7 @@ class KernelElementEnvironment implements ElementEnvironment { |
| @override |
| FunctionType getFunctionType(KFunction function) { |
| - throw new UnimplementedError('KernelElementEnvironment.getFunctionType'); |
| + return worldBuilder._getFunctionType(function); |
| } |
| @override |
| @@ -925,20 +985,9 @@ class KernelElementEnvironment implements ElementEnvironment { |
| @override |
| CallStructure getCallStructure(KFunction function) { |
| - ir.Member member = worldBuilder._memberList[function.memberIndex]; |
| - ir.FunctionNode functionNode; |
| - if (member is ir.Procedure) { |
| - functionNode = member.function; |
| - } else if (member is ir.Constructor) { |
| - functionNode = member.function; |
| - } else { |
| - throw new SpannableAssertionFailure( |
| - function, "Unexpected function node ${member} for $function."); |
| - } |
| - return new CallStructure( |
| - functionNode.positionalParameters.length + |
| - functionNode.namedParameters.length, |
| - functionNode.namedParameters.map((d) => d.name).toList()); |
| + _FunctionData data = worldBuilder._memberList[function.memberIndex]; |
| + ; |
|
Siggi Cherem (dart-lang)
2017/04/24 19:39:39
remove :)
Johnni Winther
2017/04/25 08:20:44
That was a load-bearing semicolon ;)
|
| + return data.callStructure; |
| } |
| @override |