| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 compiler.src.inferrer.type_graph_nodes; | 5 library compiler.src.inferrer.type_graph_nodes; |
| 6 | 6 |
| 7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
| 8 | 8 |
| 9 import '../common.dart'; | 9 import '../common.dart'; |
| 10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 * code, and native fields do not have Dart assignments, we just | 341 * code, and native fields do not have Dart assignments, we just |
| 342 * trust their type annotation. | 342 * trust their type annotation. |
| 343 * | 343 * |
| 344 */ | 344 */ |
| 345 abstract class ElementTypeInformation extends TypeInformation { | 345 abstract class ElementTypeInformation extends TypeInformation { |
| 346 final Element _element; | 346 final Element _element; |
| 347 | 347 |
| 348 /// Marker to disable inference for closures in [handleSpecialCases]. | 348 /// Marker to disable inference for closures in [handleSpecialCases]. |
| 349 bool disableInferenceForClosures = true; | 349 bool disableInferenceForClosures = true; |
| 350 | 350 |
| 351 factory ElementTypeInformation(Element element, TypeSystem types) { | |
| 352 if (element.isParameter) { | |
| 353 ParameterElement parameter = element; | |
| 354 if (parameter.functionDeclaration.isLocal) { | |
| 355 return new ParameterTypeInformation._localFunction(element, types); | |
| 356 } else if (parameter.functionDeclaration.isInstanceMember) { | |
| 357 return new ParameterTypeInformation._instanceMember(element, types); | |
| 358 } | |
| 359 return new ParameterTypeInformation._static(element, types); | |
| 360 } | |
| 361 return new MemberTypeInformation(element); | |
| 362 } | |
| 363 | |
| 364 ElementTypeInformation._internal(MemberTypeInformation context, this._element) | 351 ElementTypeInformation._internal(MemberTypeInformation context, this._element) |
| 365 : super(context); | 352 : super(context); |
| 366 ElementTypeInformation._withAssignments( | 353 ElementTypeInformation._withAssignments(MemberTypeInformation context, |
| 367 MemberTypeInformation context, this._element, assignments) | 354 this._element, ParameterAssignments assignments) |
| 368 : super.withAssignments(context, assignments); | 355 : super.withAssignments(context, assignments); |
| 369 | 356 |
| 370 String getInferredSignature(TypeSystem types); | 357 String getInferredSignature(TypeSystem types); |
| 371 | 358 |
| 372 String get debugName; | 359 String get debugName; |
| 373 } | 360 } |
| 374 | 361 |
| 375 /** | 362 /** |
| 376 * A node representing members in the broadest sense: | 363 * A node representing members in the broadest sense: |
| 377 * | 364 * |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 * - Initializing formals | 582 * - Initializing formals |
| 596 * | 583 * |
| 597 * These should never be created directly but instead are constructed by | 584 * These should never be created directly but instead are constructed by |
| 598 * the [ElementTypeInformation] factory. | 585 * the [ElementTypeInformation] factory. |
| 599 */ | 586 */ |
| 600 class ParameterTypeInformation extends ElementTypeInformation { | 587 class ParameterTypeInformation extends ElementTypeInformation { |
| 601 ParameterElement get _parameter => super._element; | 588 ParameterElement get _parameter => super._element; |
| 602 final FunctionElement _declaration; | 589 final FunctionElement _declaration; |
| 603 final MethodElement _method; | 590 final MethodElement _method; |
| 604 | 591 |
| 605 ParameterTypeInformation._internal(MemberTypeInformation context, | 592 ParameterTypeInformation.localFunction(MemberTypeInformation context, |
| 606 ParameterElement parameter, this._declaration, this._method) | 593 ParameterElement parameter, this._declaration, this._method) |
| 607 : super._internal(context, parameter); | 594 : super._internal(context, parameter); |
| 608 | 595 |
| 609 factory ParameterTypeInformation._static( | 596 ParameterTypeInformation.static( |
| 610 ParameterElement element, TypeSystem types) { | 597 MemberTypeInformation context, ParameterElement parameter, this._method) |
| 611 MethodElement method = element.functionDeclaration; | 598 : this._declaration = _method, |
| 612 assert(!method.isInstanceMember); | 599 super._internal(context, parameter); |
| 613 return new ParameterTypeInformation._internal( | |
| 614 types.getInferredTypeOfMember(method), element, method, method); | |
| 615 } | |
| 616 | 600 |
| 617 factory ParameterTypeInformation._localFunction( | 601 ParameterTypeInformation.instanceMember( |
| 618 ParameterElement element, TypeSystem types) { | 602 MemberTypeInformation context, |
| 619 LocalFunctionElement localFunction = element.functionDeclaration; | 603 ParameterElement parameter, |
| 620 MethodElement callMethod = localFunction.callMethod; | 604 this._method, |
| 621 return new ParameterTypeInformation._internal( | 605 ParameterAssignments assignments) |
| 622 types.getInferredTypeOfMember(callMethod), | 606 : this._declaration = _method, |
| 623 element, | 607 super._withAssignments(context, parameter, assignments); |
| 624 localFunction, | |
| 625 callMethod); | |
| 626 } | |
| 627 | |
| 628 ParameterTypeInformation._instanceMember( | |
| 629 ParameterElement element, TypeSystem types) | |
| 630 : _declaration = element.functionDeclaration, | |
| 631 _method = element.functionDeclaration, | |
| 632 super._withAssignments( | |
| 633 types.getInferredTypeOfMember( | |
| 634 element.functionDeclaration as MethodElement), | |
| 635 element, | |
| 636 new ParameterAssignments()) { | |
| 637 assert(element.functionDeclaration.isInstanceMember); | |
| 638 } | |
| 639 | 608 |
| 640 MethodElement get method => _method; | 609 MethodElement get method => _method; |
| 641 | 610 |
| 642 Local get parameter => _parameter; | 611 Local get parameter => _parameter; |
| 643 | 612 |
| 644 String get debugName => '$parameter'; | 613 String get debugName => '$parameter'; |
| 645 | 614 |
| 646 bool isTearOffClosureParameter = false; | 615 bool isTearOffClosureParameter = false; |
| 647 | 616 |
| 648 void tagAsTearOffClosureParameter(InferrerEngine inferrer) { | 617 void tagAsTearOffClosureParameter(InferrerEngine inferrer) { |
| (...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 // TODO(ngeoffray): Narrow to bound. | 1797 // TODO(ngeoffray): Narrow to bound. |
| 1829 return type; | 1798 return type; |
| 1830 } else { | 1799 } else { |
| 1831 ResolutionInterfaceType interfaceType = annotation; | 1800 ResolutionInterfaceType interfaceType = annotation; |
| 1832 otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld); | 1801 otherType = new TypeMask.nonNullSubtype(interfaceType.element, closedWorld); |
| 1833 } | 1802 } |
| 1834 if (isNullable) otherType = otherType.nullable(); | 1803 if (isNullable) otherType = otherType.nullable(); |
| 1835 if (type == null) return otherType; | 1804 if (type == null) return otherType; |
| 1836 return type.intersection(otherType, closedWorld); | 1805 return type.intersection(otherType, closedWorld); |
| 1837 } | 1806 } |
| OLD | NEW |