Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 @override | 671 @override |
| 672 String get displayName => name; | 672 String get displayName => name; |
| 673 | 673 |
| 674 @override | 674 @override |
| 675 ClassElement get enclosingElement { | 675 ClassElement get enclosingElement { |
| 676 return _definingType.element; | 676 return _definingType.element; |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 | 679 |
| 680 /** | 680 /** |
| 681 * Local function element representing the intializer for a variable that has | |
| 682 * been resynthesized from a summary. The actual element won't be constructed | |
| 683 * until it is requested. But properties [context] and [enclosingElement] can | |
| 684 * be used without creating the actual element. | |
| 685 */ | |
| 686 class _DeferredInitializerElement extends FunctionElementHandle { | |
| 687 /** | |
| 688 * The variable element containing this element. | |
| 689 */ | |
| 690 final VariableElement _enclosingElement; | |
|
scheglov
2016/02/18 21:53:51
We could do
@override
final VariableElement enclo
Paul Berry
2016/02/18 22:14:23
Done.
| |
| 691 | |
| 692 _DeferredInitializerElement(this._enclosingElement) : super(null, null); | |
| 693 | |
| 694 @override | |
| 695 FunctionElement get actualElement => _enclosingElement.initializer; | |
| 696 | |
| 697 @override | |
| 698 AnalysisContext get context => _enclosingElement.context; | |
| 699 | |
| 700 @override | |
| 701 VariableElement get enclosingElement => _enclosingElement; | |
| 702 | |
| 703 @override | |
| 704 ElementLocation get location => actualElement.location; | |
| 705 } | |
| 706 | |
| 707 /** | |
| 708 * Local function element that has been resynthesized from a summary. The | |
| 709 * actual element won't be constructed until it is requested. But properties | |
| 710 * [context] and [enclosingElement] can be used without creating the actual | |
| 711 * element. | |
| 712 */ | |
| 713 class _DeferredLocalFunctionElement extends FunctionElementHandle { | |
| 714 /** | |
| 715 * The executable element containing this element. | |
| 716 */ | |
| 717 final ExecutableElement _enclosingElement; | |
| 718 | |
| 719 /** | |
| 720 * The index of this function within [ExecutableElement.functions]. | |
| 721 */ | |
| 722 final int _localIndex; | |
| 723 | |
| 724 _DeferredLocalFunctionElement(this._enclosingElement, this._localIndex) | |
| 725 : super(null, null); | |
| 726 | |
| 727 @override | |
| 728 FunctionElement get actualElement { | |
| 729 ExecutableElement enclosingElement = _enclosingElement; | |
| 730 if (enclosingElement is PropertyAccessorElement && enclosingElement.isSynthe tic) { | |
| 731 return enclosingElement.variable.initializer; | |
| 732 } else { | |
| 733 return _enclosingElement.functions[_localIndex]; | |
| 734 } | |
| 735 } | |
| 736 | |
| 737 @override | |
| 738 AnalysisContext get context => _enclosingElement.context; | |
| 739 | |
| 740 @override | |
| 741 ExecutableElement get enclosingElement => _enclosingElement; | |
| 742 | |
| 743 @override | |
| 744 ElementLocation get location => actualElement.location; | |
| 745 } | |
| 746 | |
| 747 /** | |
| 748 * Local variable element that has been resynthesized from a summary. The | |
| 749 * actual element won't be constructed until it is requested. But properties | |
| 750 * [context] and [enclosingElement] can be used without creating the actual | |
| 751 * element. | |
| 752 */ | |
| 753 class _DeferredLocalVariableElement extends LocalVariableElementHandle { | |
| 754 /** | |
| 755 * The executable element containing this element. | |
| 756 */ | |
| 757 final ExecutableElement _enclosingElement; | |
| 758 | |
| 759 /** | |
| 760 * The index of this variable within [ExecutableElement.localVariables]. | |
| 761 */ | |
| 762 final int _localIndex; | |
| 763 | |
| 764 _DeferredLocalVariableElement(this._enclosingElement, this._localIndex) | |
| 765 : super(null, null); | |
| 766 | |
| 767 @override | |
| 768 LocalVariableElement get actualElement => | |
| 769 _enclosingElement.localVariables[_localIndex]; | |
| 770 | |
| 771 @override | |
| 772 AnalysisContext get context => _enclosingElement.context; | |
| 773 | |
| 774 @override | |
| 775 ExecutableElement get enclosingElement => _enclosingElement; | |
| 776 | |
| 777 @override | |
| 778 ElementLocation get location => actualElement.location; | |
| 779 } | |
| 780 | |
| 781 /** | |
| 681 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the | 782 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the |
| 682 * elements in a single library from that library's summary. | 783 * elements in a single library from that library's summary. |
| 683 */ | 784 */ |
| 684 class _LibraryResynthesizer { | 785 class _LibraryResynthesizer { |
| 685 /** | 786 /** |
| 686 * The [SummaryResynthesizer] which is being used to obtain summaries. | 787 * The [SummaryResynthesizer] which is being used to obtain summaries. |
| 687 */ | 788 */ |
| 688 final SummaryResynthesizer summaryResynthesizer; | 789 final SummaryResynthesizer summaryResynthesizer; |
| 689 | 790 |
| 690 /** | 791 /** |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 case ReferenceKind.topLevelPropertyAccessor: | 1315 case ReferenceKind.topLevelPropertyAccessor: |
| 1215 return new PropertyAccessorElementHandle( | 1316 return new PropertyAccessorElementHandle( |
| 1216 summaryResynthesizer, location); | 1317 summaryResynthesizer, location); |
| 1217 case ReferenceKind.constructor: | 1318 case ReferenceKind.constructor: |
| 1218 case ReferenceKind.function: | 1319 case ReferenceKind.function: |
| 1219 case ReferenceKind.propertyAccessor: | 1320 case ReferenceKind.propertyAccessor: |
| 1220 case ReferenceKind.method: | 1321 case ReferenceKind.method: |
| 1221 case ReferenceKind.length: | 1322 case ReferenceKind.length: |
| 1222 case ReferenceKind.prefix: | 1323 case ReferenceKind.prefix: |
| 1223 case ReferenceKind.unresolved: | 1324 case ReferenceKind.unresolved: |
| 1325 case ReferenceKind.variable: | |
| 1224 // Should never happen. Exported names never refer to import prefixes, | 1326 // Should never happen. Exported names never refer to import prefixes, |
| 1225 // and they always refer to defined top-level entities. | 1327 // and they always refer to defined top-level entities. |
| 1226 throw new StateError('Unexpected export name kind: ${exportName.kind}'); | 1328 throw new StateError('Unexpected export name kind: ${exportName.kind}'); |
| 1227 } | 1329 } |
| 1228 } | 1330 } |
| 1229 | 1331 |
| 1230 /** | 1332 /** |
| 1231 * Build the export namespace for the library by aggregating together its | 1333 * Build the export namespace for the library by aggregating together its |
| 1232 * [publicNamespace] and [exportNames]. | 1334 * [publicNamespace] and [exportNames]. |
| 1233 */ | 1335 */ |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1941 element = new FunctionElementHandle(summaryResynthesizer, location); | 2043 element = new FunctionElementHandle(summaryResynthesizer, location); |
| 1942 break; | 2044 break; |
| 1943 case ReferenceKind.topLevelPropertyAccessor: | 2045 case ReferenceKind.topLevelPropertyAccessor: |
| 1944 element = new PropertyAccessorElementHandle( | 2046 element = new PropertyAccessorElementHandle( |
| 1945 summaryResynthesizer, location); | 2047 summaryResynthesizer, location); |
| 1946 break; | 2048 break; |
| 1947 case ReferenceKind.typedef: | 2049 case ReferenceKind.typedef: |
| 1948 element = new FunctionTypeAliasElementHandle( | 2050 element = new FunctionTypeAliasElementHandle( |
| 1949 summaryResynthesizer, location); | 2051 summaryResynthesizer, location); |
| 1950 break; | 2052 break; |
| 2053 case ReferenceKind.variable: | |
| 2054 Element enclosingElement = enclosingInfo.element; | |
| 2055 if (enclosingElement is ExecutableElement) { | |
| 2056 element = new _DeferredLocalVariableElement( | |
| 2057 enclosingElement, linkedReference.localIndex); | |
| 2058 } else { | |
| 2059 throw new StateError('Unexpected element enclosing variable:' | |
| 2060 ' ${enclosingElement.runtimeType}'); | |
| 2061 } | |
| 2062 break; | |
| 1951 case ReferenceKind.function: | 2063 case ReferenceKind.function: |
| 2064 Element enclosingElement = enclosingInfo.element; | |
| 2065 if (enclosingElement is VariableElement) { | |
| 2066 element = new _DeferredInitializerElement(enclosingElement); | |
| 2067 } else if (enclosingElement is ExecutableElement) { | |
| 2068 element = new _DeferredLocalFunctionElement( | |
| 2069 enclosingElement, linkedReference.localIndex); | |
| 2070 } else { | |
| 2071 throw new StateError('Unexpected element enclosing function:' | |
| 2072 ' ${enclosingElement.runtimeType}'); | |
| 2073 } | |
| 2074 break; | |
| 1952 case ReferenceKind.prefix: | 2075 case ReferenceKind.prefix: |
| 1953 case ReferenceKind.unresolved: | 2076 case ReferenceKind.unresolved: |
| 1954 break; | 2077 break; |
| 1955 } | 2078 } |
| 1956 } | 2079 } |
| 1957 referenceInfos[i] = new _ReferenceInfo( | 2080 referenceInfos[i] = new _ReferenceInfo( |
| 1958 enclosingInfo, name, element, type, numTypeParameters); | 2081 enclosingInfo, name, element, type, numTypeParameters); |
| 1959 } | 2082 } |
| 1960 } | 2083 } |
| 1961 | 2084 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2230 } | 2353 } |
| 2231 : () => this.element; | 2354 : () => this.element; |
| 2232 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2355 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2233 // isInstantiated? | 2356 // isInstantiated? |
| 2234 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2357 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2235 } else { | 2358 } else { |
| 2236 return null; | 2359 return null; |
| 2237 } | 2360 } |
| 2238 } | 2361 } |
| 2239 } | 2362 } |
| OLD | NEW |