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 = interfaceTypeToIr(cls.supertype); | 195 classNode.supertype = supertypeToIr(cls.supertype); |
196 } | 196 } |
197 if (cls.isMixinApplication) { | 197 if (cls.isMixinApplication) { |
198 MixinApplicationElement mixinApplication = cls; | 198 MixinApplicationElement mixinApplication = cls; |
199 classNode.mixedInType = interfaceTypeToIr(mixinApplication.mixinType); | 199 classNode.mixedInType = supertypeToIr(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.InterfaceType interface | 225 for (ir.Supertype supertype |
226 in typesToIr(cls.interfaces.reverse().toList())) { | 226 in supertypesToIr(cls.interfaces.reverse().toList())) { |
227 if (interface != classNode.mixedInType) { | 227 if (supertype != classNode.mixedInType) { |
228 classNode.implementedTypes.add(interface); | 228 classNode.implementedTypes.add(supertype); |
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 |
287 // TODO(ahe): Remove this method when dart2js support generic type arguments. | 296 // TODO(ahe): Remove this method when dart2js support generic type arguments. |
288 List<ir.TypeParameter> typeParametersNotImplemented() { | 297 List<ir.TypeParameter> typeParametersNotImplemented() { |
289 return const <ir.TypeParameter>[]; | 298 return const <ir.TypeParameter>[]; |
290 } | 299 } |
291 | 300 |
292 ir.FunctionType functionTypeToIr(FunctionType type) { | 301 ir.FunctionType functionTypeToIr(FunctionType type) { |
293 List<ir.TypeParameter> typeParameters = typeParametersNotImplemented(); | 302 List<ir.TypeParameter> typeParameters = typeParametersNotImplemented(); |
294 int requiredParameterCount = type.parameterTypes.length; | 303 int requiredParameterCount = type.parameterTypes.length; |
295 List<ir.DartType> positionalParameters = | 304 List<ir.DartType> positionalParameters = |
296 new List<ir.DartType>.from(typesToIr(type.parameterTypes)) | 305 new List<ir.DartType>.from(typesToIr(type.parameterTypes)) |
297 ..addAll(typesToIr(type.optionalParameterTypes)); | 306 ..addAll(typesToIr(type.optionalParameterTypes)); |
298 Map<String, ir.DartType> namedParameters = <String, ir.DartType>{}; | 307 List<ir.NamedType> namedParameters = new List<ir.NamedType>.generate( |
299 for (int i = 0; i < type.namedParameters.length; i++) { | 308 type.namedParameters.length, |
300 namedParameters[type.namedParameters[i]] = | 309 (i) => new ir.NamedType( |
301 typeToIr(type.namedParameterTypes[i]); | 310 type.namedParameters[i], typeToIr(type.namedParameterTypes[i]))); |
302 } | |
303 ir.DartType returnType = typeToIr(type.returnType); | 311 ir.DartType returnType = typeToIr(type.returnType); |
304 | 312 |
305 return new ir.FunctionType(positionalParameters, returnType, | 313 return new ir.FunctionType(positionalParameters, returnType, |
306 namedParameters: namedParameters, | 314 namedParameters: namedParameters, |
307 typeParameters: typeParameters, | 315 typeParameters: typeParameters, |
308 requiredParameterCount: requiredParameterCount); | 316 requiredParameterCount: requiredParameterCount); |
309 } | 317 } |
310 | 318 |
311 ir.TypeParameterType typeVariableTypeToIr(TypeVariableType type) { | 319 ir.TypeParameterType typeVariableTypeToIr(TypeVariableType type) { |
312 return new ir.TypeParameterType(typeVariableToIr(type.element)); | 320 return new ir.TypeParameterType(typeVariableToIr(type.element)); |
313 } | 321 } |
314 | 322 |
315 List<ir.DartType> typesToIr(List<DartType> types) { | 323 List<ir.DartType> typesToIr(List<DartType> types) { |
316 List<ir.DartType> result = new List<ir.DartType>(types.length); | 324 List<ir.DartType> result = new List<ir.DartType>(types.length); |
317 for (int i = 0; i < types.length; i++) { | 325 for (int i = 0; i < types.length; i++) { |
318 result[i] = typeToIr(types[i]); | 326 result[i] = typeToIr(types[i]); |
319 } | 327 } |
320 return result; | 328 return result; |
321 } | 329 } |
322 | 330 |
| 331 List<ir.Supertype> supertypesToIr(List<DartType> 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 |
323 ir.DartType typeToIr(DartType type) { | 339 ir.DartType typeToIr(DartType type) { |
324 switch (type.kind) { | 340 switch (type.kind) { |
325 case TypeKind.FUNCTION: | 341 case TypeKind.FUNCTION: |
326 return functionTypeToIr(type); | 342 return functionTypeToIr(type); |
327 | 343 |
328 case TypeKind.INTERFACE: | 344 case TypeKind.INTERFACE: |
329 return interfaceTypeToIr(type); | 345 return interfaceTypeToIr(type); |
330 | 346 |
331 case TypeKind.STATEMENT: | 347 case TypeKind.STATEMENT: |
332 throw "Internal error: statement type: $type."; | 348 throw "Internal error: statement type: $type."; |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 754 } |
739 | 755 |
740 class ConstructorTarget { | 756 class ConstructorTarget { |
741 final ConstructorElement element; | 757 final ConstructorElement element; |
742 final DartType type; | 758 final DartType type; |
743 | 759 |
744 ConstructorTarget(this.element, this.type); | 760 ConstructorTarget(this.element, this.type); |
745 | 761 |
746 String toString() => "ConstructorTarget($element, $type)"; | 762 String toString() => "ConstructorTarget($element, $type)"; |
747 } | 763 } |
OLD | NEW |