| 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This library is capable of producing linked summaries from unlinked | 6 * This library is capable of producing linked summaries from unlinked |
| 7 * ones (or prelinked ones). It functions by building a miniature | 7 * ones (or prelinked ones). It functions by building a miniature |
| 8 * element model to represent the contents of the summaries, and then | 8 * element model to represent the contents of the summaries, and then |
| 9 * scanning the element model to gather linked information and adding | 9 * scanning the element model to gather linked information and adding |
| 10 * it to the summary data structures. | 10 * it to the summary data structures. |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 361 |
| 362 List<ConstructorElementForLink> _constructors; | 362 List<ConstructorElementForLink> _constructors; |
| 363 ConstructorElementForLink _unnamedConstructor; | 363 ConstructorElementForLink _unnamedConstructor; |
| 364 bool _unnamedConstructorComputed = false; | 364 bool _unnamedConstructorComputed = false; |
| 365 List<FieldElementForLink_ClassField> _fields; | 365 List<FieldElementForLink_ClassField> _fields; |
| 366 InterfaceType _supertype; | 366 InterfaceType _supertype; |
| 367 InterfaceType _type; | 367 InterfaceType _type; |
| 368 List<MethodElementForLink> _methods; | 368 List<MethodElementForLink> _methods; |
| 369 List<InterfaceType> _mixins; | 369 List<InterfaceType> _mixins; |
| 370 List<InterfaceType> _interfaces; | 370 List<InterfaceType> _interfaces; |
| 371 List<PropertyAccessorElement> _accessors; | 371 List<PropertyAccessorElementForLink> _accessors; |
| 372 | 372 |
| 373 ClassElementForLink_Class( | 373 ClassElementForLink_Class( |
| 374 CompilationUnitElementForLink enclosingElement, this._unlinkedClass) | 374 CompilationUnitElementForLink enclosingElement, this._unlinkedClass) |
| 375 : super(enclosingElement); | 375 : super(enclosingElement); |
| 376 | 376 |
| 377 @override | 377 @override |
| 378 List<PropertyAccessorElement> get accessors { | 378 List<PropertyAccessorElement> get accessors { |
| 379 if (_accessors == null) { | 379 if (_accessors == null) { |
| 380 _accessors = <PropertyAccessorElement>[]; | 380 _accessors = <PropertyAccessorElementForLink>[]; |
| 381 Map<String, SyntheticVariableElementForLink> syntheticVariables = | 381 Map<String, SyntheticVariableElementForLink> syntheticVariables = |
| 382 <String, SyntheticVariableElementForLink>{}; | 382 <String, SyntheticVariableElementForLink>{}; |
| 383 for (UnlinkedExecutable unlinkedExecutable | 383 for (UnlinkedExecutable unlinkedExecutable |
| 384 in _unlinkedClass.executables) { | 384 in _unlinkedClass.executables) { |
| 385 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter || | 385 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter || |
| 386 unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { | 386 unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 387 String name = unlinkedExecutable.name; | 387 String name = unlinkedExecutable.name; |
| 388 if (unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { | 388 if (unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 389 assert(name.endsWith('=')); | 389 assert(name.endsWith('=')); |
| 390 name = name.substring(0, name.length - 1); | 390 name = name.substring(0, name.length - 1); |
| 391 } | 391 } |
| 392 SyntheticVariableElementForLink syntheticVariable = syntheticVariables | 392 SyntheticVariableElementForLink syntheticVariable = syntheticVariables |
| 393 .putIfAbsent(name, () => new SyntheticVariableElementForLink()); | 393 .putIfAbsent(name, () => new SyntheticVariableElementForLink()); |
| 394 PropertyAccessorElementForLink_Executable accessor = | 394 PropertyAccessorElementForLink_Executable accessor = |
| 395 new PropertyAccessorElementForLink_Executable( | 395 new PropertyAccessorElementForLink_Executable(enclosingElement, |
| 396 this, unlinkedExecutable, syntheticVariable); | 396 this, unlinkedExecutable, syntheticVariable); |
| 397 _accessors.add(accessor); | 397 _accessors.add(accessor); |
| 398 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter) { | 398 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter) { |
| 399 syntheticVariable._getter = accessor; | 399 syntheticVariable._getter = accessor; |
| 400 } else { | 400 } else { |
| 401 syntheticVariable._setter = accessor; | 401 syntheticVariable._setter = accessor; |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 for (FieldElementForLink_ClassField field in fields) { | 405 for (FieldElementForLink_ClassField field in fields) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 /** | 692 /** |
| 693 * The absolute URI of this compilation unit. | 693 * The absolute URI of this compilation unit. |
| 694 */ | 694 */ |
| 695 final String _absoluteUri; | 695 final String _absoluteUri; |
| 696 | 696 |
| 697 List<ClassElementForLink_Class> _types; | 697 List<ClassElementForLink_Class> _types; |
| 698 Map<String, ReferenceableElementForLink> _containedNames; | 698 Map<String, ReferenceableElementForLink> _containedNames; |
| 699 List<TopLevelVariableElementForLink> _topLevelVariables; | 699 List<TopLevelVariableElementForLink> _topLevelVariables; |
| 700 List<ClassElementForLink_Enum> _enums; | 700 List<ClassElementForLink_Enum> _enums; |
| 701 List<TopLevelFunctionElementForLink> _functions; | 701 List<TopLevelFunctionElementForLink> _functions; |
| 702 List<PropertyAccessorElementForLink> _accessors; |
| 702 | 703 |
| 703 /** | 704 /** |
| 704 * Index of this unit in the list of units in the enclosing library. | 705 * Index of this unit in the list of units in the enclosing library. |
| 705 */ | 706 */ |
| 706 final int unitNum; | 707 final int unitNum; |
| 707 | 708 |
| 708 CompilationUnitElementForLink(UnlinkedUnit unlinkedUnit, this.unitNum, | 709 CompilationUnitElementForLink(UnlinkedUnit unlinkedUnit, this.unitNum, |
| 709 int numReferences, this._absoluteUri) | 710 int numReferences, this._absoluteUri) |
| 710 : _references = new List<ReferenceableElementForLink>(numReferences), | 711 : _references = new List<ReferenceableElementForLink>(numReferences), |
| 711 _unlinkedUnit = unlinkedUnit; | 712 _unlinkedUnit = unlinkedUnit; |
| 712 | 713 |
| 713 @override | 714 @override |
| 715 List<PropertyAccessorElementForLink> get accessors { |
| 716 if (_accessors == null) { |
| 717 _accessors = <PropertyAccessorElementForLink>[]; |
| 718 Map<String, SyntheticVariableElementForLink> syntheticVariables = |
| 719 <String, SyntheticVariableElementForLink>{}; |
| 720 for (UnlinkedExecutable unlinkedExecutable in _unlinkedUnit.executables) { |
| 721 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter || |
| 722 unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 723 String name = unlinkedExecutable.name; |
| 724 if (unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 725 assert(name.endsWith('=')); |
| 726 name = name.substring(0, name.length - 1); |
| 727 } |
| 728 SyntheticVariableElementForLink syntheticVariable = syntheticVariables |
| 729 .putIfAbsent(name, () => new SyntheticVariableElementForLink()); |
| 730 PropertyAccessorElementForLink_Executable accessor = |
| 731 new PropertyAccessorElementForLink_Executable( |
| 732 this, null, unlinkedExecutable, syntheticVariable); |
| 733 _accessors.add(accessor); |
| 734 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter) { |
| 735 syntheticVariable._getter = accessor; |
| 736 } else { |
| 737 syntheticVariable._setter = accessor; |
| 738 } |
| 739 } |
| 740 } |
| 741 // TODO(paulberry): also add synthetic accessors. |
| 742 } |
| 743 return _accessors; |
| 744 } |
| 745 |
| 746 @override |
| 714 LibraryElementForLink get enclosingElement; | 747 LibraryElementForLink get enclosingElement; |
| 715 | 748 |
| 716 @override | 749 @override |
| 717 List<ClassElementForLink_Enum> get enums { | 750 List<ClassElementForLink_Enum> get enums { |
| 718 if (_enums == null) { | 751 if (_enums == null) { |
| 719 _enums = <ClassElementForLink_Enum>[]; | 752 _enums = <ClassElementForLink_Enum>[]; |
| 720 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { | 753 for (UnlinkedEnum unlinkedEnum in _unlinkedUnit.enums) { |
| 721 _enums.add(new ClassElementForLink_Enum(this, unlinkedEnum)); | 754 _enums.add(new ClassElementForLink_Enum(this, unlinkedEnum)); |
| 722 } | 755 } |
| 723 } | 756 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 } | 836 } |
| 804 for (ClassElementForLink_Enum enm in enums) { | 837 for (ClassElementForLink_Enum enm in enums) { |
| 805 _containedNames[enm.name] = enm; | 838 _containedNames[enm.name] = enm; |
| 806 } | 839 } |
| 807 for (TopLevelVariableElementForLink variable in topLevelVariables) { | 840 for (TopLevelVariableElementForLink variable in topLevelVariables) { |
| 808 _containedNames[variable.name] = variable; | 841 _containedNames[variable.name] = variable; |
| 809 } | 842 } |
| 810 for (TopLevelFunctionElementForLink function in functions) { | 843 for (TopLevelFunctionElementForLink function in functions) { |
| 811 _containedNames[function.name] = function; | 844 _containedNames[function.name] = function; |
| 812 } | 845 } |
| 846 for (PropertyAccessorElementForLink accessor in accessors) { |
| 847 // TODO(paulberry): consider handling synthetic accessors and getting |
| 848 // rid of the loop above for topLevelVariables. |
| 849 if (!accessor.isSynthetic) { |
| 850 _containedNames[accessor.name] = accessor; |
| 851 } |
| 852 } |
| 813 // TODO(paulberry): fill in other top level entities (typedefs | 853 // TODO(paulberry): fill in other top level entities (typedefs |
| 814 // and executables). | 854 // and executables). |
| 815 } | 855 } |
| 816 return _containedNames.putIfAbsent( | 856 return _containedNames.putIfAbsent( |
| 817 name, () => UndefinedElementForLink.instance); | 857 name, () => UndefinedElementForLink.instance); |
| 818 } | 858 } |
| 819 | 859 |
| 820 /** | 860 /** |
| 821 * Compute the type referred to by the given linked type [slot] (interpreted | 861 * Compute the type referred to by the given linked type [slot] (interpreted |
| 822 * relative to [typeParameterContext]). If there is no inferred type in the | 862 * relative to [typeParameterContext]). If there is no inferred type in the |
| (...skipping 2654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3477 /** | 3517 /** |
| 3478 * Specialization of [PropertyAccessorElementForLink] for non-synthetic | 3518 * Specialization of [PropertyAccessorElementForLink] for non-synthetic |
| 3479 * accessors explicitly declared in the source code. | 3519 * accessors explicitly declared in the source code. |
| 3480 */ | 3520 */ |
| 3481 class PropertyAccessorElementForLink_Executable extends ExecutableElementForLink | 3521 class PropertyAccessorElementForLink_Executable extends ExecutableElementForLink |
| 3482 implements PropertyAccessorElementForLink { | 3522 implements PropertyAccessorElementForLink { |
| 3483 @override | 3523 @override |
| 3484 SyntheticVariableElementForLink variable; | 3524 SyntheticVariableElementForLink variable; |
| 3485 | 3525 |
| 3486 PropertyAccessorElementForLink_Executable( | 3526 PropertyAccessorElementForLink_Executable( |
| 3527 CompilationUnitElementForLink enclosingUnit, |
| 3487 ClassElementForLink_Class enclosingClass, | 3528 ClassElementForLink_Class enclosingClass, |
| 3488 UnlinkedExecutable unlinkedExecutable, | 3529 UnlinkedExecutable unlinkedExecutable, |
| 3489 this.variable) | 3530 this.variable) |
| 3490 : super(enclosingClass.enclosingElement, enclosingClass, | 3531 : super(enclosingUnit, enclosingClass, unlinkedExecutable); |
| 3491 unlinkedExecutable); | |
| 3492 | 3532 |
| 3493 @override | 3533 @override |
| 3494 ConstructorElementForLink get asConstructor => null; | 3534 ConstructorElementForLink get asConstructor => null; |
| 3495 | 3535 |
| 3496 @override | 3536 @override |
| 3497 ConstVariableNode get asConstVariable => null; | 3537 ConstVariableNode get asConstVariable => null; |
| 3498 | 3538 |
| 3499 @override | 3539 @override |
| 3500 DartType get asStaticType => returnType; | 3540 DartType get asStaticType => returnType; |
| 3501 | 3541 |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4394 if (type is InterfaceType) { | 4434 if (type is InterfaceType) { |
| 4395 Element result = type.lookUpGetter(name, compilationUnit.library); | 4435 Element result = type.lookUpGetter(name, compilationUnit.library); |
| 4396 result ??= type.lookUpMethod(name, compilationUnit.library); | 4436 result ??= type.lookUpMethod(name, compilationUnit.library); |
| 4397 return result; | 4437 return result; |
| 4398 } | 4438 } |
| 4399 } | 4439 } |
| 4400 // TODO(scheglov): implement for propagated types | 4440 // TODO(scheglov): implement for propagated types |
| 4401 return null; | 4441 return null; |
| 4402 } | 4442 } |
| 4403 } | 4443 } |
| OLD | NEW |