OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:collection' show Queue; | 6 import 'dart:collection' show Queue; |
7 | 7 |
8 import 'package:kernel/ast.dart' as ir; | 8 import 'package:kernel/ast.dart' as ir; |
9 import 'package:kernel/checks.dart' show CheckParentPointers; | 9 import 'package:kernel/checks.dart' show CheckParentPointers; |
10 | 10 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 ir.Class classNode = new ir.Class( | 185 ir.Class classNode = new ir.Class( |
186 name: name, | 186 name: name, |
187 isAbstract: cls.isAbstract, | 187 isAbstract: cls.isAbstract, |
188 typeParameters: null, | 188 typeParameters: null, |
189 implementedTypes: null, | 189 implementedTypes: null, |
190 constructors: null, | 190 constructors: null, |
191 procedures: null, | 191 procedures: null, |
192 fields: null); | 192 fields: null); |
193 addWork(cls, () { | 193 addWork(cls, () { |
194 if (cls.supertype != null) { | 194 if (cls.supertype != null) { |
195 classNode.supertype = supertypeToIr(cls.supertype); | 195 classNode.supertype = interfaceTypeToIr(cls.supertype); |
196 } | 196 } |
197 if (cls.isMixinApplication) { | 197 if (cls.isMixinApplication) { |
198 MixinApplicationElement mixinApplication = cls; | 198 MixinApplicationElement mixinApplication = cls; |
199 classNode.mixedInType = supertypeToIr(mixinApplication.mixinType); | 199 classNode.mixedInType = interfaceTypeToIr(mixinApplication.mixinType); |
200 } | 200 } |
201 classNode.parent = libraryToIr(cls.library); | 201 classNode.parent = libraryToIr(cls.library); |
202 if (cls.isUnnamedMixinApplication) { | 202 if (cls.isUnnamedMixinApplication) { |
203 classNode.enclosingLibrary.addClass(classNode); | 203 classNode.enclosingLibrary.addClass(classNode); |
204 } | 204 } |
205 cls.implementation | 205 cls.implementation |
206 .forEachMember((ClassElement enclosingClass, Element member) { | 206 .forEachMember((ClassElement enclosingClass, Element member) { |
207 if (member.enclosingClass.declaration != cls) { | 207 if (member.enclosingClass.declaration != cls) { |
208 // TODO(het): figure out why impact_test triggers this | 208 // TODO(het): figure out why impact_test triggers this |
209 //internalError(cls, "`$member` isn't mine."); | 209 //internalError(cls, "`$member` isn't mine."); |
210 } else if (member.isConstructor) { | 210 } else if (member.isConstructor) { |
211 ConstructorElement constructor = member; | 211 ConstructorElement constructor = member; |
212 ir.Member memberNode = functionToIr(member); | 212 ir.Member memberNode = functionToIr(member); |
213 if (!constructor.isRedirectingFactory) { | 213 if (!constructor.isRedirectingFactory) { |
214 classNode.addMember(memberNode); | 214 classNode.addMember(memberNode); |
215 } | 215 } |
216 } else if (member.isFunction || member.isAccessor) { | 216 } else if (member.isFunction || member.isAccessor) { |
217 classNode.addMember(functionToIr(member)); | 217 classNode.addMember(functionToIr(member)); |
218 } else if (member.isField) { | 218 } else if (member.isField) { |
219 classNode.addMember(fieldToIr(member)); | 219 classNode.addMember(fieldToIr(member)); |
220 } else { | 220 } else { |
221 internalError(member, "Unhandled class member: $member"); | 221 internalError(member, "Unhandled class member: $member"); |
222 } | 222 } |
223 }); | 223 }); |
224 classNode.typeParameters.addAll(typeVariablesToIr(cls.typeVariables)); | 224 classNode.typeParameters.addAll(typeVariablesToIr(cls.typeVariables)); |
225 for (ir.Supertype supertype | 225 for (ir.InterfaceType interface |
226 in supertypesToIr(cls.interfaces.reverse().toList())) { | 226 in typesToIr(cls.interfaces.reverse().toList())) { |
227 if (supertype != classNode.mixedInType) { | 227 if (interface != classNode.mixedInType) { |
228 classNode.implementedTypes.add(supertype); | 228 classNode.implementedTypes.add(interface); |
229 } | 229 } |
230 } | 230 } |
231 addWork(cls, () { | 231 addWork(cls, () { |
232 addDefaultInstanceFieldInitializers(classNode); | 232 addDefaultInstanceFieldInitializers(classNode); |
233 }); | 233 }); |
234 }); | 234 }); |
235 addWork(cls.declaration, () { | 235 addWork(cls.declaration, () { |
236 for (MetadataAnnotation metadata in cls.declaration.metadata) { | 236 for (MetadataAnnotation metadata in cls.declaration.metadata) { |
237 classNode.addAnnotation( | 237 classNode.addAnnotation( |
238 const ConstantVisitor().visit(metadata.constant, this)); | 238 const ConstantVisitor().visit(metadata.constant, this)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 277 |
278 ir.InterfaceType interfaceTypeToIr(InterfaceType type) { | 278 ir.InterfaceType interfaceTypeToIr(InterfaceType type) { |
279 ir.Class cls = classToIr(type.element); | 279 ir.Class cls = classToIr(type.element); |
280 if (type.typeArguments.isEmpty) { | 280 if (type.typeArguments.isEmpty) { |
281 return cls.rawType; | 281 return cls.rawType; |
282 } else { | 282 } else { |
283 return new ir.InterfaceType(cls, typesToIr(type.typeArguments)); | 283 return new ir.InterfaceType(cls, typesToIr(type.typeArguments)); |
284 } | 284 } |
285 } | 285 } |
286 | 286 |
287 ir.Supertype supertypeToIr(InterfaceType type) { | |
288 ir.Class cls = classToIr(type.element); | |
289 if (type.typeArguments.isEmpty) { | |
290 return cls.asRawSupertype; | |
291 } else { | |
292 return new ir.Supertype(cls, typesToIr(type.typeArguments)); | |
293 } | |
294 } | |
295 | |
296 // TODO(ahe): Remove this method when dart2js support generic type arguments. | 287 // TODO(ahe): Remove this method when dart2js support generic type arguments. |
297 List<ir.TypeParameter> typeParametersNotImplemented() { | 288 List<ir.TypeParameter> typeParametersNotImplemented() { |
298 return const <ir.TypeParameter>[]; | 289 return const <ir.TypeParameter>[]; |
299 } | 290 } |
300 | 291 |
301 ir.FunctionType functionTypeToIr(FunctionType type) { | 292 ir.FunctionType functionTypeToIr(FunctionType type) { |
302 List<ir.TypeParameter> typeParameters = typeParametersNotImplemented(); | 293 List<ir.TypeParameter> typeParameters = typeParametersNotImplemented(); |
303 int requiredParameterCount = type.parameterTypes.length; | 294 int requiredParameterCount = type.parameterTypes.length; |
304 List<ir.DartType> positionalParameters = | 295 List<ir.DartType> positionalParameters = |
305 new List<ir.DartType>.from(typesToIr(type.parameterTypes)) | 296 new List<ir.DartType>.from(typesToIr(type.parameterTypes)) |
306 ..addAll(typesToIr(type.optionalParameterTypes)); | 297 ..addAll(typesToIr(type.optionalParameterTypes)); |
307 List<ir.NamedType> namedParameters = new List<ir.NamedType>.generate( | 298 Map<String, ir.DartType> namedParameters = <String, ir.DartType>{}; |
308 type.namedParameters.length, | 299 for (int i = 0; i < type.namedParameters.length; i++) { |
309 (i) => new ir.NamedType( | 300 namedParameters[type.namedParameters[i]] = |
310 type.namedParameters[i], typeToIr(type.namedParameterTypes[i]))); | 301 typeToIr(type.namedParameterTypes[i]); |
| 302 } |
311 ir.DartType returnType = typeToIr(type.returnType); | 303 ir.DartType returnType = typeToIr(type.returnType); |
312 | 304 |
313 return new ir.FunctionType(positionalParameters, returnType, | 305 return new ir.FunctionType(positionalParameters, returnType, |
314 namedParameters: namedParameters, | 306 namedParameters: namedParameters, |
315 typeParameters: typeParameters, | 307 typeParameters: typeParameters, |
316 requiredParameterCount: requiredParameterCount); | 308 requiredParameterCount: requiredParameterCount); |
317 } | 309 } |
318 | 310 |
319 ir.TypeParameterType typeVariableTypeToIr(TypeVariableType type) { | 311 ir.TypeParameterType typeVariableTypeToIr(TypeVariableType type) { |
320 return new ir.TypeParameterType(typeVariableToIr(type.element)); | 312 return new ir.TypeParameterType(typeVariableToIr(type.element)); |
321 } | 313 } |
322 | 314 |
323 List<ir.DartType> typesToIr(List<DartType> types) { | 315 List<ir.DartType> typesToIr(List<DartType> types) { |
324 List<ir.DartType> result = new List<ir.DartType>(types.length); | 316 List<ir.DartType> result = new List<ir.DartType>(types.length); |
325 for (int i = 0; i < types.length; i++) { | 317 for (int i = 0; i < types.length; i++) { |
326 result[i] = typeToIr(types[i]); | 318 result[i] = typeToIr(types[i]); |
327 } | 319 } |
328 return result; | 320 return result; |
329 } | 321 } |
330 | 322 |
331 List<ir.Supertype> supertypesToIr(List<InterfaceType> types) { | |
332 List<ir.Supertype> result = new List<ir.Supertype>(types.length); | |
333 for (int i = 0; i < types.length; i++) { | |
334 result[i] = supertypeToIr(types[i]); | |
335 } | |
336 return result; | |
337 } | |
338 | |
339 ir.DartType typeToIr(DartType type) { | 323 ir.DartType typeToIr(DartType type) { |
340 switch (type.kind) { | 324 switch (type.kind) { |
341 case TypeKind.FUNCTION: | 325 case TypeKind.FUNCTION: |
342 return functionTypeToIr(type); | 326 return functionTypeToIr(type); |
343 | 327 |
344 case TypeKind.INTERFACE: | 328 case TypeKind.INTERFACE: |
345 return interfaceTypeToIr(type); | 329 return interfaceTypeToIr(type); |
346 | 330 |
347 case TypeKind.STATEMENT: | 331 case TypeKind.STATEMENT: |
348 throw "Internal error: statement type: $type."; | 332 throw "Internal error: statement type: $type."; |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 } | 738 } |
755 | 739 |
756 class ConstructorTarget { | 740 class ConstructorTarget { |
757 final ConstructorElement element; | 741 final ConstructorElement element; |
758 final DartType type; | 742 final DartType type; |
759 | 743 |
760 ConstructorTarget(this.element, this.type); | 744 ConstructorTarget(this.element, this.type); |
761 | 745 |
762 String toString() => "ConstructorTarget($element, $type)"; | 746 String toString() => "ConstructorTarget($element, $type)"; |
763 } | 747 } |
OLD | NEW |