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 import '../common.dart'; | 5 import '../common.dart'; |
6 import '../elements/elements.dart'; | 6 import '../elements/elements.dart'; |
7 import '../elements/entities.dart'; | 7 import '../elements/entities.dart'; |
8 import '../elements/types.dart'; | 8 import '../elements/types.dart'; |
9 import '../tree/nodes.dart' as ast; | 9 import '../tree/nodes.dart' as ast; |
10 import '../types/masks.dart'; | 10 import '../types/masks.dart'; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 TypeInformation newType = new NarrowTypeInformation(receiver, otherType); | 283 TypeInformation newType = new NarrowTypeInformation(receiver, otherType); |
284 allocatedTypes.add(newType); | 284 allocatedTypes.add(newType); |
285 return newType; | 285 return newType; |
286 } | 286 } |
287 | 287 |
288 /** | 288 /** |
289 * Returns the intersection between [type] and [annotation]. | 289 * Returns the intersection between [type] and [annotation]. |
290 * [isNullable] indicates whether the annotation implies a null | 290 * [isNullable] indicates whether the annotation implies a null |
291 * type. | 291 * type. |
292 */ | 292 */ |
293 TypeInformation narrowType( | 293 TypeInformation narrowType(TypeInformation type, DartType annotation, |
294 TypeInformation type, DartType annotation, | |
295 {bool isNullable: true}) { | 294 {bool isNullable: true}) { |
296 if (annotation.treatAsDynamic) return type; | 295 if (annotation.treatAsDynamic) return type; |
297 if (annotation.isVoid) return type; | 296 if (annotation.isVoid) return type; |
298 TypeMask otherType; | 297 TypeMask otherType; |
299 if (annotation.isInterfaceType) { | 298 if (annotation.isInterfaceType) { |
300 InterfaceType interface = annotation; | 299 InterfaceType interface = annotation; |
301 if (interface.element == closedWorld.commonElements.objectClass) { | 300 if (interface.element == closedWorld.commonElements.objectClass) { |
302 if (isNullable) { | 301 if (isNullable) { |
303 return type; | 302 return type; |
304 } | 303 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 338 |
340 ParameterTypeInformation getInferredTypeOfParameter( | 339 ParameterTypeInformation getInferredTypeOfParameter( |
341 ParameterElement parameter) { | 340 ParameterElement parameter) { |
342 parameter = parameter.implementation; | 341 parameter = parameter.implementation; |
343 | 342 |
344 ParameterTypeInformation createTypeInformation() { | 343 ParameterTypeInformation createTypeInformation() { |
345 if (parameter.functionDeclaration.isLocal) { | 344 if (parameter.functionDeclaration.isLocal) { |
346 LocalFunctionElement localFunction = parameter.functionDeclaration; | 345 LocalFunctionElement localFunction = parameter.functionDeclaration; |
347 MethodElement callMethod = localFunction.callMethod; | 346 MethodElement callMethod = localFunction.callMethod; |
348 return new ParameterTypeInformation.localFunction( | 347 return new ParameterTypeInformation.localFunction( |
349 getInferredTypeOfMember(callMethod), | 348 getInferredTypeOfMember(callMethod), parameter, callMethod); |
350 parameter, | |
351 callMethod); | |
352 } else if (parameter.functionDeclaration.isInstanceMember) { | 349 } else if (parameter.functionDeclaration.isInstanceMember) { |
353 MethodElement method = parameter.functionDeclaration; | 350 MethodElement method = parameter.functionDeclaration; |
354 return new ParameterTypeInformation.instanceMember( | 351 return new ParameterTypeInformation.instanceMember( |
355 getInferredTypeOfMember(method), | 352 getInferredTypeOfMember(method), |
356 parameter, | 353 parameter, |
357 method, | 354 method, |
358 new ParameterAssignments()); | 355 new ParameterAssignments()); |
359 } else { | 356 } else { |
360 MethodElement method = parameter.functionDeclaration; | 357 MethodElement method = parameter.functionDeclaration; |
361 return new ParameterTypeInformation.static( | 358 return new ParameterTypeInformation.static( |
362 getInferredTypeOfMember(method), parameter, method); | 359 getInferredTypeOfMember(method), parameter, method); |
363 } | 360 } |
364 } | 361 } |
365 | 362 |
366 return parameterTypeInformations.putIfAbsent(parameter, () { | 363 return parameterTypeInformations.putIfAbsent(parameter, () { |
367 ParameterTypeInformation typeInformation = createTypeInformation(); | 364 ParameterTypeInformation typeInformation = createTypeInformation(); |
368 _orderedTypeInformations.add(typeInformation); | 365 _orderedTypeInformations.add(typeInformation); |
369 return typeInformation; | 366 return typeInformation; |
370 }); | 367 }); |
371 } | 368 } |
372 | 369 |
373 MemberTypeInformation getInferredTypeOfMember(MemberElement member) { | 370 MemberTypeInformation getInferredTypeOfMember(MemberElement member) { |
374 member = member.implementation; | 371 member = member.implementation; |
375 return memberTypeInformations.putIfAbsent(member, () { | 372 return memberTypeInformations.putIfAbsent(member, () { |
376 MemberTypeInformation typeInformation = new MemberTypeInformation(member); | 373 MemberTypeInformation typeInformation; |
| 374 if (member.isField) { |
| 375 typeInformation = new FieldTypeInformation(member); |
| 376 } else if (member.isGetter) { |
| 377 typeInformation = new GetterTypeInformation(member); |
| 378 } else if (member.isSetter) { |
| 379 typeInformation = new SetterTypeInformation(member); |
| 380 } else if (member.isFunction) { |
| 381 typeInformation = new MethodTypeInformation(member); |
| 382 } else { |
| 383 ConstructorElement constructor = member; |
| 384 if (constructor.isFactoryConstructor) { |
| 385 typeInformation = new FactoryConstructorTypeInformation(member); |
| 386 } else { |
| 387 typeInformation = new GenerativeConstructorTypeInformation(member); |
| 388 } |
| 389 } |
377 _orderedTypeInformations.add(typeInformation); | 390 _orderedTypeInformations.add(typeInformation); |
378 return typeInformation; | 391 return typeInformation; |
379 }); | 392 }); |
380 } | 393 } |
381 | 394 |
382 /** | 395 /** |
383 * Returns the internal inferrer representation for [mask]. | 396 * Returns the internal inferrer representation for [mask]. |
384 */ | 397 */ |
385 ConcreteTypeInformation getConcreteTypeFor(TypeMask mask) { | 398 ConcreteTypeInformation getConcreteTypeFor(TypeMask mask) { |
386 assert(mask != null); | 399 assert(mask != null); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 TypeMask newType = null; | 618 TypeMask newType = null; |
606 for (TypeMask mask in list) { | 619 for (TypeMask mask in list) { |
607 newType = newType == null ? mask : newType.union(mask, closedWorld); | 620 newType = newType == null ? mask : newType.union(mask, closedWorld); |
608 // Likewise - stop early if we already reach dynamic. | 621 // Likewise - stop early if we already reach dynamic. |
609 if (newType.containsAll(closedWorld)) return dynamicType; | 622 if (newType.containsAll(closedWorld)) return dynamicType; |
610 } | 623 } |
611 | 624 |
612 return newType ?? const TypeMask.nonNullEmpty(); | 625 return newType ?? const TypeMask.nonNullEmpty(); |
613 } | 626 } |
614 } | 627 } |
OLD | NEW |