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.world_builder; | 5 library dart2js.kernel.world_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/backend_api.dart'; | 10 import '../common/backend_api.dart'; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 return _getTypeVariable(cls.typeParameters[index]); | 186 return _getTypeVariable(cls.typeParameters[index]); |
187 } else { | 187 } else { |
188 return new KTypeVariable(_getMethod(procedure), node.name, index); | 188 return new KTypeVariable(_getMethod(procedure), node.name, index); |
189 } | 189 } |
190 } | 190 } |
191 } | 191 } |
192 throw new UnsupportedError('Unsupported type parameter type node $node.'); | 192 throw new UnsupportedError('Unsupported type parameter type node $node.'); |
193 }); | 193 }); |
194 } | 194 } |
195 | 195 |
| 196 ParameterStructure _getParameterStructure(ir.FunctionNode node) { |
| 197 // TODO(johnniwinther): Cache the computed function type. |
| 198 int requiredParameters = node.requiredParameterCount; |
| 199 int positionalParameters = node.positionalParameters.length; |
| 200 List<String> namedParameters = |
| 201 node.namedParameters.map((p) => p.name).toList()..sort(); |
| 202 return new ParameterStructure( |
| 203 requiredParameters, positionalParameters, namedParameters); |
| 204 } |
| 205 |
196 KConstructor _getConstructor(ir.Member node) { | 206 KConstructor _getConstructor(ir.Member node) { |
197 return _constructorMap.putIfAbsent(node, () { | 207 return _constructorMap.putIfAbsent(node, () { |
198 int memberIndex = _memberList.length; | 208 int memberIndex = _memberList.length; |
199 KConstructor constructor; | 209 KConstructor constructor; |
200 KClass enclosingClass = _getClass(node.enclosingClass); | 210 KClass enclosingClass = _getClass(node.enclosingClass); |
201 Name name = getName(node.name); | 211 Name name = getName(node.name); |
202 bool isExternal = node.isExternal; | 212 bool isExternal = node.isExternal; |
| 213 |
203 if (node is ir.Constructor) { | 214 if (node is ir.Constructor) { |
204 constructor = new KGenerativeConstructor( | 215 constructor = new KGenerativeConstructor(memberIndex, enclosingClass, |
205 memberIndex, enclosingClass, name, | 216 name, _getParameterStructure(node.function), |
206 isExternal: isExternal, isConst: node.isConst); | 217 isExternal: isExternal, isConst: node.isConst); |
207 } else if (node is ir.Procedure) { | 218 } else if (node is ir.Procedure) { |
208 constructor = new KFactoryConstructor(memberIndex, enclosingClass, name, | 219 constructor = new KFactoryConstructor(memberIndex, enclosingClass, name, |
| 220 _getParameterStructure(node.function), |
209 isExternal: isExternal, isConst: node.isConst); | 221 isExternal: isExternal, isConst: node.isConst); |
210 } else { | 222 } else { |
211 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. | 223 // TODO(johnniwinther): Convert `node.location` to a [SourceSpan]. |
212 throw new SpannableAssertionFailure( | 224 throw new SpannableAssertionFailure( |
213 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); | 225 NO_LOCATION_SPANNABLE, "Unexpected constructor node: ${node}."); |
214 } | 226 } |
215 _memberList.add(node); | 227 _memberList.add(node); |
216 return constructor; | 228 return constructor; |
217 }); | 229 }); |
218 } | 230 } |
(...skipping 19 matching lines...) Expand all Loading... |
238 throw new UnsupportedError("Cannot create method from factory."); | 250 throw new UnsupportedError("Cannot create method from factory."); |
239 case ir.ProcedureKind.Getter: | 251 case ir.ProcedureKind.Getter: |
240 function = new KGetter(memberIndex, library, enclosingClass, name, | 252 function = new KGetter(memberIndex, library, enclosingClass, name, |
241 isStatic: isStatic, | 253 isStatic: isStatic, |
242 isExternal: isExternal, | 254 isExternal: isExternal, |
243 isAbstract: isAbstract); | 255 isAbstract: isAbstract); |
244 break; | 256 break; |
245 case ir.ProcedureKind.Method: | 257 case ir.ProcedureKind.Method: |
246 case ir.ProcedureKind.Operator: | 258 case ir.ProcedureKind.Operator: |
247 function = new KMethod(memberIndex, library, enclosingClass, name, | 259 function = new KMethod(memberIndex, library, enclosingClass, name, |
| 260 _getParameterStructure(node.function), |
248 isStatic: isStatic, | 261 isStatic: isStatic, |
249 isExternal: isExternal, | 262 isExternal: isExternal, |
250 isAbstract: isAbstract); | 263 isAbstract: isAbstract); |
251 break; | 264 break; |
252 case ir.ProcedureKind.Setter: | 265 case ir.ProcedureKind.Setter: |
253 function = new KSetter( | 266 function = new KSetter( |
254 memberIndex, library, enclosingClass, getName(node.name).setter, | 267 memberIndex, library, enclosingClass, getName(node.name).setter, |
255 isStatic: isStatic, | 268 isStatic: isStatic, |
256 isExternal: isExternal, | 269 isExternal: isExternal, |
257 isAbstract: isAbstract); | 270 isAbstract: isAbstract); |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 } | 927 } |
915 | 928 |
916 InterfaceType getMixinTypeForClass(KClass cls) { | 929 InterfaceType getMixinTypeForClass(KClass cls) { |
917 KClassEnv env = builder._classEnvs[cls.classIndex]; | 930 KClassEnv env = builder._classEnvs[cls.classIndex]; |
918 ir.Supertype mixedInType = env.cls.mixedInType; | 931 ir.Supertype mixedInType = env.cls.mixedInType; |
919 if (mixedInType == null) return null; | 932 if (mixedInType == null) return null; |
920 return builder.createInterfaceType( | 933 return builder.createInterfaceType( |
921 mixedInType.classNode, mixedInType.typeArguments); | 934 mixedInType.classNode, mixedInType.typeArguments); |
922 } | 935 } |
923 } | 936 } |
OLD | NEW |