Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 2974803002: Store FunctionType(s) of local functions by value. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 FunctionElement get actualElement => enclosingElement.initializer; 780 FunctionElement get actualElement => enclosingElement.initializer;
781 781
782 @override 782 @override
783 AnalysisContext get context => enclosingElement.context; 783 AnalysisContext get context => enclosingElement.context;
784 784
785 @override 785 @override
786 ElementLocation get location => actualElement.location; 786 ElementLocation get location => actualElement.location;
787 } 787 }
788 788
789 /** 789 /**
790 * Local function element that has been resynthesized from a summary. The
791 * actual element won't be constructed until it is requested. But properties
792 * [context] and [enclosingElement] can be used without creating the actual
793 * element.
794 */
795 class _DeferredLocalFunctionElement extends FunctionElementHandle {
796 /**
797 * The executable element containing this element.
798 */
799 @override
800 final ExecutableElement enclosingElement;
801
802 /**
803 * The index of this function within [ExecutableElement.functions].
804 */
805 final int _localIndex;
806
807 _DeferredLocalFunctionElement(this.enclosingElement, this._localIndex)
808 : super(null, null);
809
810 @override
811 FunctionElement get actualElement {
812 ExecutableElement enclosingElement = this.enclosingElement;
813 if (enclosingElement is PropertyAccessorElement &&
814 enclosingElement.isSynthetic) {
815 return enclosingElement.variable.initializer;
816 } else {
817 return enclosingElement.functions[_localIndex];
818 }
819 }
820
821 @override
822 AnalysisContext get context => enclosingElement.context;
823
824 @override
825 ElementLocation get location => actualElement.location;
826 }
827
828 /**
829 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the 790 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the
830 * elements in a single library from that library's summary. 791 * elements in a single library from that library's summary.
831 */ 792 */
832 class _LibraryResynthesizer { 793 class _LibraryResynthesizer {
833 /** 794 /**
834 * The [SummaryResynthesizer] which is being used to obtain summaries. 795 * The [SummaryResynthesizer] which is being used to obtain summaries.
835 */ 796 */
836 final SummaryResynthesizer summaryResynthesizer; 797 final SummaryResynthesizer summaryResynthesizer;
837 798
838 /** 799 /**
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 break; 1816 break;
1856 case ReferenceKind.genericFunctionTypedef: 1817 case ReferenceKind.genericFunctionTypedef:
1857 element = new GenericTypeAliasElementHandle( 1818 element = new GenericTypeAliasElementHandle(
1858 summaryResynthesizer, location); 1819 summaryResynthesizer, location);
1859 isDeclarableType = true; 1820 isDeclarableType = true;
1860 break; 1821 break;
1861 case ReferenceKind.function: 1822 case ReferenceKind.function:
1862 Element enclosingElement = enclosingInfo.element; 1823 Element enclosingElement = enclosingInfo.element;
1863 if (enclosingElement is VariableElement) { 1824 if (enclosingElement is VariableElement) {
1864 element = new _DeferredInitializerElement(enclosingElement); 1825 element = new _DeferredInitializerElement(enclosingElement);
1865 } else if (enclosingElement is ExecutableElement) {
1866 element = new _DeferredLocalFunctionElement(
1867 enclosingElement, linkedReference.localIndex);
1868 } else { 1826 } else {
1869 throw new StateError('Unexpected element enclosing function:' 1827 throw new StateError('Unexpected element enclosing function:'
1870 ' ${enclosingElement.runtimeType}'); 1828 ' ${enclosingElement.runtimeType}');
1871 } 1829 }
1872 break; 1830 break;
1873 case ReferenceKind.prefix: 1831 case ReferenceKind.prefix:
1874 element = new PrefixElementHandle(summaryResynthesizer, location); 1832 element = new PrefixElementHandle(summaryResynthesizer, location);
1875 break; 1833 break;
1876 case ReferenceKind.variable: 1834 case ReferenceKind.variable:
1877 case ReferenceKind.unresolved: 1835 case ReferenceKind.unresolved:
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 static String _getElementIdentifier(String name, ReferenceKind kind) { 1929 static String _getElementIdentifier(String name, ReferenceKind kind) {
1972 if (kind == ReferenceKind.topLevelPropertyAccessor || 1930 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1973 kind == ReferenceKind.propertyAccessor) { 1931 kind == ReferenceKind.propertyAccessor) {
1974 if (!name.endsWith('=')) { 1932 if (!name.endsWith('=')) {
1975 return name + '?'; 1933 return name + '?';
1976 } 1934 }
1977 } 1935 }
1978 return name; 1936 return name;
1979 } 1937 }
1980 } 1938 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698