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/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
11 import 'package:analyzer/src/generated/element_handle.dart'; | 11 import 'package:analyzer/src/generated/element_handle.dart'; |
12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
13 import 'package:analyzer/src/generated/resolver.dart'; | 13 import 'package:analyzer/src/generated/resolver.dart'; |
14 import 'package:analyzer/src/generated/source_io.dart'; | 14 import 'package:analyzer/src/generated/source_io.dart'; |
15 import 'package:analyzer/src/summary/format.dart'; | 15 import 'package:analyzer/src/summary/format.dart'; |
16 | 16 |
17 /** | 17 /** |
18 * Callback used by [SummaryResynthesizer] to obtain the prelinked summary for | 18 * Callback used by [SummaryResynthesizer] to obtain the linked summary for |
19 * a given URI. | 19 * a given URI. |
20 */ | 20 */ |
21 typedef PrelinkedLibrary GetPrelinkedSummaryCallback(String uri); | 21 typedef LinkedLibrary GetLinkedSummaryCallback(String uri); |
22 | 22 |
23 /** | 23 /** |
24 * Callback used by [SummaryResynthesizer] to obtain the unlinked summary for a | 24 * Callback used by [SummaryResynthesizer] to obtain the unlinked summary for a |
25 * given URI. | 25 * given URI. |
26 */ | 26 */ |
27 typedef UnlinkedUnit GetUnlinkedSummaryCallback(String uri); | 27 typedef UnlinkedUnit GetUnlinkedSummaryCallback(String uri); |
28 | 28 |
29 /** | 29 /** |
30 * Implementation of [ElementResynthesizer] used when resynthesizing an element | 30 * Implementation of [ElementResynthesizer] used when resynthesizing an element |
31 * model from summaries. | 31 * model from summaries. |
32 */ | 32 */ |
33 class SummaryResynthesizer extends ElementResynthesizer { | 33 class SummaryResynthesizer extends ElementResynthesizer { |
34 /** | 34 /** |
35 * Callback used to obtain the prelinked summary for a given URI. | 35 * Callback used to obtain the linked summary for a given URI. |
36 */ | 36 */ |
37 final GetPrelinkedSummaryCallback getPrelinkedSummary; | 37 final GetLinkedSummaryCallback getLinkedSummary; |
38 | 38 |
39 /** | 39 /** |
40 * Callback used to obtain the unlinked summary for a given URI. | 40 * Callback used to obtain the unlinked summary for a given URI. |
41 */ | 41 */ |
42 final GetUnlinkedSummaryCallback getUnlinkedSummary; | 42 final GetUnlinkedSummaryCallback getUnlinkedSummary; |
43 | 43 |
44 /** | 44 /** |
45 * Source factory used to convert URIs to [Source] objects. | 45 * Source factory used to convert URIs to [Source] objects. |
46 */ | 46 */ |
47 final SourceFactory sourceFactory; | 47 final SourceFactory sourceFactory; |
(...skipping 18 matching lines...) Expand all Loading... |
66 <String, Map<String, Map<String, Element>>>{}; | 66 <String, Map<String, Map<String, Element>>>{}; |
67 | 67 |
68 /** | 68 /** |
69 * Map of libraries which have been resynthesized from summaries. The map | 69 * Map of libraries which have been resynthesized from summaries. The map |
70 * key is the library URI. | 70 * key is the library URI. |
71 */ | 71 */ |
72 final Map<String, LibraryElement> _resynthesizedLibraries = | 72 final Map<String, LibraryElement> _resynthesizedLibraries = |
73 <String, LibraryElement>{}; | 73 <String, LibraryElement>{}; |
74 | 74 |
75 SummaryResynthesizer(AnalysisContext context, this.typeProvider, | 75 SummaryResynthesizer(AnalysisContext context, this.typeProvider, |
76 this.getPrelinkedSummary, this.getUnlinkedSummary, this.sourceFactory) | 76 this.getLinkedSummary, this.getUnlinkedSummary, this.sourceFactory) |
77 : super(context); | 77 : super(context); |
78 | 78 |
79 /** | 79 /** |
80 * Number of libraries that have been resynthesized so far. | 80 * Number of libraries that have been resynthesized so far. |
81 */ | 81 */ |
82 int get resynthesisCount => _resynthesizedLibraries.length; | 82 int get resynthesisCount => _resynthesizedLibraries.length; |
83 | 83 |
84 @override | 84 @override |
85 Element getElement(ElementLocation location) { | 85 Element getElement(ElementLocation location) { |
86 if (location.components.length == 1) { | 86 if (location.components.length == 1) { |
(...skipping 20 matching lines...) Expand all Loading... |
107 throw new UnimplementedError(location.toString()); | 107 throw new UnimplementedError(location.toString()); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 /** | 111 /** |
112 * Get the [LibraryElement] for the given [uri], resynthesizing it if it | 112 * Get the [LibraryElement] for the given [uri], resynthesizing it if it |
113 * hasn't been resynthesized already. | 113 * hasn't been resynthesized already. |
114 */ | 114 */ |
115 LibraryElement getLibraryElement(String uri) { | 115 LibraryElement getLibraryElement(String uri) { |
116 return _resynthesizedLibraries.putIfAbsent(uri, () { | 116 return _resynthesizedLibraries.putIfAbsent(uri, () { |
117 PrelinkedLibrary serializedLibrary = getPrelinkedSummary(uri); | 117 LinkedLibrary serializedLibrary = getLinkedSummary(uri); |
118 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[ | 118 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[ |
119 getUnlinkedSummary(uri) | 119 getUnlinkedSummary(uri) |
120 ]; | 120 ]; |
121 Source librarySource = _getSource(uri); | 121 Source librarySource = _getSource(uri); |
122 for (String part in serializedUnits[0].publicNamespace.parts) { | 122 for (String part in serializedUnits[0].publicNamespace.parts) { |
123 Source partSource = sourceFactory.resolveUri(librarySource, part); | 123 Source partSource = sourceFactory.resolveUri(librarySource, part); |
124 String partAbsUri = partSource.uri.toString(); | 124 String partAbsUri = partSource.uri.toString(); |
125 serializedUnits.add(getUnlinkedSummary(partAbsUri)); | 125 serializedUnits.add(getUnlinkedSummary(partAbsUri)); |
126 } | 126 } |
127 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( | 127 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( |
(...skipping 16 matching lines...) Expand all Loading... |
144 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the | 144 * An instance of [_LibraryResynthesizer] is responsible for resynthesizing the |
145 * elements in a single library from that library's summary. | 145 * elements in a single library from that library's summary. |
146 */ | 146 */ |
147 class _LibraryResynthesizer { | 147 class _LibraryResynthesizer { |
148 /** | 148 /** |
149 * The [SummaryResynthesizer] which is being used to obtain summaries. | 149 * The [SummaryResynthesizer] which is being used to obtain summaries. |
150 */ | 150 */ |
151 final SummaryResynthesizer summaryResynthesizer; | 151 final SummaryResynthesizer summaryResynthesizer; |
152 | 152 |
153 /** | 153 /** |
154 * Prelinked summary of the library to be resynthesized. | 154 * Linked summary of the library to be resynthesized. |
155 */ | 155 */ |
156 final PrelinkedLibrary prelinkedLibrary; | 156 final LinkedLibrary linkedLibrary; |
157 | 157 |
158 /** | 158 /** |
159 * Unlinked compilation units constituting the library to be resynthesized. | 159 * Unlinked compilation units constituting the library to be resynthesized. |
160 */ | 160 */ |
161 final List<UnlinkedUnit> unlinkedUnits; | 161 final List<UnlinkedUnit> unlinkedUnits; |
162 | 162 |
163 /** | 163 /** |
164 * [Source] object for the library to be resynthesized. | 164 * [Source] object for the library to be resynthesized. |
165 */ | 165 */ |
166 final Source librarySource; | 166 final Source librarySource; |
(...skipping 10 matching lines...) Expand all Loading... |
177 List<ClassElementImpl> delayedObjectSubclasses = <ClassElementImpl>[]; | 177 List<ClassElementImpl> delayedObjectSubclasses = <ClassElementImpl>[]; |
178 | 178 |
179 /** | 179 /** |
180 * [ElementHolder] into which resynthesized elements should be placed. This | 180 * [ElementHolder] into which resynthesized elements should be placed. This |
181 * object is recreated afresh for each unit in the library, and is used to | 181 * object is recreated afresh for each unit in the library, and is used to |
182 * populate the [CompilationUnitElement]. | 182 * populate the [CompilationUnitElement]. |
183 */ | 183 */ |
184 ElementHolder unitHolder; | 184 ElementHolder unitHolder; |
185 | 185 |
186 /** | 186 /** |
187 * The [PrelinkedUnit] from which elements are currently being resynthesized. | 187 * The [LinkedUnit] from which elements are currently being resynthesized. |
188 */ | 188 */ |
189 PrelinkedUnit prelinkedUnit; | 189 LinkedUnit linkedUnit; |
190 | 190 |
191 /** | 191 /** |
192 * The [UnlinkedUnit] from which elements are currently being resynthesized. | 192 * The [UnlinkedUnit] from which elements are currently being resynthesized. |
193 */ | 193 */ |
194 UnlinkedUnit unlinkedUnit; | 194 UnlinkedUnit unlinkedUnit; |
195 | 195 |
196 /** | 196 /** |
197 * Map of top level elements that have been resynthesized so far. The first | 197 * Map of top level elements that have been resynthesized so far. The first |
198 * key is the URI of the compilation unit; the second is the name of the top | 198 * key is the URI of the compilation unit; the second is the name of the top |
199 * level element. | 199 * level element. |
200 */ | 200 */ |
201 final Map<String, Map<String, Element>> resummarizedElements = | 201 final Map<String, Map<String, Element>> resummarizedElements = |
202 <String, Map<String, Element>>{}; | 202 <String, Map<String, Element>>{}; |
203 | 203 |
204 /** | 204 /** |
205 * Type parameters for the generic class, typedef, or executable currently | 205 * Type parameters for the generic class, typedef, or executable currently |
206 * being resynthesized, if any. If multiple entities with type parameters | 206 * being resynthesized, if any. If multiple entities with type parameters |
207 * are nested (e.g. a generic executable inside a generic class), this is the | 207 * are nested (e.g. a generic executable inside a generic class), this is the |
208 * concatenation of all type parameters from all declarations currently in | 208 * concatenation of all type parameters from all declarations currently in |
209 * force, with the outermost declaration appearing first. If there are no | 209 * force, with the outermost declaration appearing first. If there are no |
210 * type parameters, or we are not currently resynthesizing a class, typedef, | 210 * type parameters, or we are not currently resynthesizing a class, typedef, |
211 * or executable, then this is an empty list. | 211 * or executable, then this is an empty list. |
212 */ | 212 */ |
213 List<TypeParameterElement> currentTypeParameters = <TypeParameterElement>[]; | 213 List<TypeParameterElement> currentTypeParameters = <TypeParameterElement>[]; |
214 | 214 |
215 _LibraryResynthesizer(this.summaryResynthesizer, this.prelinkedLibrary, | 215 _LibraryResynthesizer(this.summaryResynthesizer, this.linkedLibrary, |
216 this.unlinkedUnits, this.librarySource) { | 216 this.unlinkedUnits, this.librarySource) { |
217 isCoreLibrary = librarySource.uri.toString() == 'dart:core'; | 217 isCoreLibrary = librarySource.uri.toString() == 'dart:core'; |
218 } | 218 } |
219 | 219 |
220 /** | 220 /** |
221 * Return a list of type arguments corresponding to [currentTypeParameters]. | 221 * Return a list of type arguments corresponding to [currentTypeParameters]. |
222 */ | 222 */ |
223 List<TypeParameterType> get currentTypeArguments => currentTypeParameters | 223 List<TypeParameterType> get currentTypeArguments => currentTypeParameters |
224 ?.map((TypeParameterElement param) => param.type) | 224 ?.map((TypeParameterElement param) => param.type) |
225 ?.toList(); | 225 ?.toList(); |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 serializedExportPublic.combinators.map(buildCombinator).toList(); | 521 serializedExportPublic.combinators.map(buildCombinator).toList(); |
522 exportElement.uriOffset = serializedExportNonPublic.uriOffset; | 522 exportElement.uriOffset = serializedExportNonPublic.uriOffset; |
523 exportElement.uriEnd = serializedExportNonPublic.uriEnd; | 523 exportElement.uriEnd = serializedExportNonPublic.uriEnd; |
524 return exportElement; | 524 return exportElement; |
525 } | 525 } |
526 | 526 |
527 /** | 527 /** |
528 * Build an [ElementHandle] referring to the entity referred to by the given | 528 * Build an [ElementHandle] referring to the entity referred to by the given |
529 * [exportName]. | 529 * [exportName]. |
530 */ | 530 */ |
531 ElementHandle buildExportName(PrelinkedExportName exportName) { | 531 ElementHandle buildExportName(LinkedExportName exportName) { |
532 String name = exportName.name; | 532 String name = exportName.name; |
533 if (exportName.kind == PrelinkedReferenceKind.topLevelPropertyAccessor && | 533 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor && |
534 !name.endsWith('=')) { | 534 !name.endsWith('=')) { |
535 name += '?'; | 535 name += '?'; |
536 } | 536 } |
537 ElementLocationImpl location = getReferencedLocation( | 537 ElementLocationImpl location = getReferencedLocation( |
538 prelinkedLibrary.dependencies[exportName.dependency], | 538 linkedLibrary.dependencies[exportName.dependency], |
539 exportName.unit, | 539 exportName.unit, |
540 name); | 540 name); |
541 switch (exportName.kind) { | 541 switch (exportName.kind) { |
542 case PrelinkedReferenceKind.classOrEnum: | 542 case ReferenceKind.classOrEnum: |
543 return new ClassElementHandle(summaryResynthesizer, location); | 543 return new ClassElementHandle(summaryResynthesizer, location); |
544 case PrelinkedReferenceKind.typedef: | 544 case ReferenceKind.typedef: |
545 return new FunctionTypeAliasElementHandle( | 545 return new FunctionTypeAliasElementHandle( |
546 summaryResynthesizer, location); | 546 summaryResynthesizer, location); |
547 case PrelinkedReferenceKind.topLevelFunction: | 547 case ReferenceKind.topLevelFunction: |
548 return new FunctionElementHandle(summaryResynthesizer, location); | 548 return new FunctionElementHandle(summaryResynthesizer, location); |
549 case PrelinkedReferenceKind.topLevelPropertyAccessor: | 549 case ReferenceKind.topLevelPropertyAccessor: |
550 return new PropertyAccessorElementHandle( | 550 return new PropertyAccessorElementHandle( |
551 summaryResynthesizer, location); | 551 summaryResynthesizer, location); |
552 case PrelinkedReferenceKind.prefix: | 552 case ReferenceKind.prefix: |
553 case PrelinkedReferenceKind.unresolved: | 553 case ReferenceKind.unresolved: |
554 // Should never happen. Exported names never refer to import prefixes, | 554 // Should never happen. Exported names never refer to import prefixes, |
555 // and they always refer to defined entities. | 555 // and they always refer to defined entities. |
556 throw new StateError('Unexpected export name kind: ${exportName.kind}'); | 556 throw new StateError('Unexpected export name kind: ${exportName.kind}'); |
557 } | 557 } |
558 } | 558 } |
559 | 559 |
560 /** | 560 /** |
561 * Build the export namespace for the library by aggregating together its | 561 * Build the export namespace for the library by aggregating together its |
562 * [publicNamespace] and [exportNames]. | 562 * [publicNamespace] and [exportNames]. |
563 */ | 563 */ |
564 Namespace buildExportNamespace( | 564 Namespace buildExportNamespace( |
565 Namespace publicNamespace, List<PrelinkedExportName> exportNames) { | 565 Namespace publicNamespace, List<LinkedExportName> exportNames) { |
566 HashMap<String, Element> definedNames = new HashMap<String, Element>(); | 566 HashMap<String, Element> definedNames = new HashMap<String, Element>(); |
567 // Start by populating all the public names from [publicNamespace]. | 567 // Start by populating all the public names from [publicNamespace]. |
568 publicNamespace.definedNames.forEach((String name, Element element) { | 568 publicNamespace.definedNames.forEach((String name, Element element) { |
569 definedNames[name] = element; | 569 definedNames[name] = element; |
570 }); | 570 }); |
571 // Add all the names from [exportNames]. | 571 // Add all the names from [exportNames]. |
572 for (PrelinkedExportName exportName in exportNames) { | 572 for (LinkedExportName exportName in exportNames) { |
573 definedNames.putIfAbsent( | 573 definedNames.putIfAbsent( |
574 exportName.name, () => buildExportName(exportName)); | 574 exportName.name, () => buildExportName(exportName)); |
575 } | 575 } |
576 return new Namespace(definedNames); | 576 return new Namespace(definedNames); |
577 } | 577 } |
578 | 578 |
579 /** | 579 /** |
580 * Resynthesize a [FieldElement]. | 580 * Resynthesize a [FieldElement]. |
581 */ | 581 */ |
582 FieldElement buildField(UnlinkedVariable serializedField) { | 582 FieldElement buildField(UnlinkedVariable serializedField) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 /** | 670 /** |
671 * Resynthesize an [ImportElement]. | 671 * Resynthesize an [ImportElement]. |
672 */ | 672 */ |
673 ImportElement buildImport(UnlinkedImport serializedImport, int dependency) { | 673 ImportElement buildImport(UnlinkedImport serializedImport, int dependency) { |
674 bool isSynthetic = serializedImport.isImplicit; | 674 bool isSynthetic = serializedImport.isImplicit; |
675 // TODO(paulberry): it seems problematic for the offset to be 0 for | 675 // TODO(paulberry): it seems problematic for the offset to be 0 for |
676 // non-synthetic imports, since it is used to disambiguate location. | 676 // non-synthetic imports, since it is used to disambiguate location. |
677 ImportElementImpl importElement = | 677 ImportElementImpl importElement = |
678 new ImportElementImpl(isSynthetic ? -1 : serializedImport.offset); | 678 new ImportElementImpl(isSynthetic ? -1 : serializedImport.offset); |
679 String absoluteUri = summaryResynthesizer.sourceFactory | 679 String absoluteUri = summaryResynthesizer.sourceFactory |
680 .resolveUri( | 680 .resolveUri(librarySource, linkedLibrary.dependencies[dependency].uri) |
681 librarySource, prelinkedLibrary.dependencies[dependency].uri) | |
682 .uri | 681 .uri |
683 .toString(); | 682 .toString(); |
684 importElement.importedLibrary = new LibraryElementHandle( | 683 importElement.importedLibrary = new LibraryElementHandle( |
685 summaryResynthesizer, | 684 summaryResynthesizer, |
686 new ElementLocationImpl.con3(<String>[absoluteUri])); | 685 new ElementLocationImpl.con3(<String>[absoluteUri])); |
687 if (isSynthetic) { | 686 if (isSynthetic) { |
688 importElement.synthetic = true; | 687 importElement.synthetic = true; |
689 } else { | 688 } else { |
690 importElement.uri = serializedImport.uri; | 689 importElement.uri = serializedImport.uri; |
691 importElement.uriOffset = serializedImport.uriOffset; | 690 importElement.uriOffset = serializedImport.uriOffset; |
(...skipping 25 matching lines...) Expand all Loading... |
717 buildDocumentation( | 716 buildDocumentation( |
718 libraryElement, unlinkedUnits[0].libraryDocumentationComment); | 717 libraryElement, unlinkedUnits[0].libraryDocumentationComment); |
719 CompilationUnitElementImpl definingCompilationUnit = | 718 CompilationUnitElementImpl definingCompilationUnit = |
720 new CompilationUnitElementImpl(librarySource.shortName); | 719 new CompilationUnitElementImpl(librarySource.shortName); |
721 libraryElement.definingCompilationUnit = definingCompilationUnit; | 720 libraryElement.definingCompilationUnit = definingCompilationUnit; |
722 definingCompilationUnit.source = librarySource; | 721 definingCompilationUnit.source = librarySource; |
723 definingCompilationUnit.librarySource = librarySource; | 722 definingCompilationUnit.librarySource = librarySource; |
724 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; | 723 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; |
725 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; | 724 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; |
726 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == | 725 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == |
727 prelinkedLibrary.units.length); | 726 linkedLibrary.units.length); |
728 for (int i = 1; i < prelinkedLibrary.units.length; i++) { | 727 for (int i = 1; i < linkedLibrary.units.length; i++) { |
729 CompilationUnitElementImpl part = buildPart( | 728 CompilationUnitElementImpl part = buildPart( |
730 unlinkedDefiningUnit.publicNamespace.parts[i - 1], | 729 unlinkedDefiningUnit.publicNamespace.parts[i - 1], |
731 unlinkedDefiningUnit.parts[i - 1], | 730 unlinkedDefiningUnit.parts[i - 1], |
732 unlinkedUnits[i]); | 731 unlinkedUnits[i]); |
733 parts.add(part); | 732 parts.add(part); |
734 } | 733 } |
735 libraryElement.parts = parts; | 734 libraryElement.parts = parts; |
736 List<ImportElement> imports = <ImportElement>[]; | 735 List<ImportElement> imports = <ImportElement>[]; |
737 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) { | 736 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) { |
738 imports.add(buildImport(unlinkedDefiningUnit.imports[i], | 737 imports.add(buildImport(unlinkedDefiningUnit.imports[i], |
739 prelinkedLibrary.importDependencies[i])); | 738 linkedLibrary.importDependencies[i])); |
740 } | 739 } |
741 libraryElement.imports = imports; | 740 libraryElement.imports = imports; |
742 List<ExportElement> exports = <ExportElement>[]; | 741 List<ExportElement> exports = <ExportElement>[]; |
743 assert(unlinkedDefiningUnit.exports.length == | 742 assert(unlinkedDefiningUnit.exports.length == |
744 unlinkedDefiningUnit.publicNamespace.exports.length); | 743 unlinkedDefiningUnit.publicNamespace.exports.length); |
745 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) { | 744 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) { |
746 exports.add(buildExport(unlinkedDefiningUnit.publicNamespace.exports[i], | 745 exports.add(buildExport(unlinkedDefiningUnit.publicNamespace.exports[i], |
747 unlinkedDefiningUnit.exports[i])); | 746 unlinkedDefiningUnit.exports[i])); |
748 } | 747 } |
749 libraryElement.exports = exports; | 748 libraryElement.exports = exports; |
750 populateUnit(definingCompilationUnit, 0); | 749 populateUnit(definingCompilationUnit, 0); |
751 for (int i = 0; i < parts.length; i++) { | 750 for (int i = 0; i < parts.length; i++) { |
752 populateUnit(parts[i], i + 1); | 751 populateUnit(parts[i], i + 1); |
753 } | 752 } |
754 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement); | 753 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement); |
755 // Update delayed Object class references. | 754 // Update delayed Object class references. |
756 if (isCoreLibrary) { | 755 if (isCoreLibrary) { |
757 ClassElement objectElement = libraryElement.getType('Object'); | 756 ClassElement objectElement = libraryElement.getType('Object'); |
758 assert(objectElement != null); | 757 assert(objectElement != null); |
759 for (ClassElementImpl classElement in delayedObjectSubclasses) { | 758 for (ClassElementImpl classElement in delayedObjectSubclasses) { |
760 classElement.supertype = objectElement.type; | 759 classElement.supertype = objectElement.type; |
761 } | 760 } |
762 } | 761 } |
763 // Compute namespaces. | 762 // Compute namespaces. |
764 libraryElement.publicNamespace = | 763 libraryElement.publicNamespace = |
765 new NamespaceBuilder().createPublicNamespaceForLibrary(libraryElement); | 764 new NamespaceBuilder().createPublicNamespaceForLibrary(libraryElement); |
766 libraryElement.exportNamespace = buildExportNamespace( | 765 libraryElement.exportNamespace = buildExportNamespace( |
767 libraryElement.publicNamespace, prelinkedLibrary.exportNames); | 766 libraryElement.publicNamespace, linkedLibrary.exportNames); |
768 // Find the entry point. Note: we can't use element.isEntryPoint because | 767 // Find the entry point. Note: we can't use element.isEntryPoint because |
769 // that will trigger resynthesis of exported libraries. | 768 // that will trigger resynthesis of exported libraries. |
770 Element entryPoint = | 769 Element entryPoint = |
771 libraryElement.exportNamespace.get(FunctionElement.MAIN_FUNCTION_NAME); | 770 libraryElement.exportNamespace.get(FunctionElement.MAIN_FUNCTION_NAME); |
772 if (entryPoint is FunctionElement) { | 771 if (entryPoint is FunctionElement) { |
773 libraryElement.entryPoint = entryPoint; | 772 libraryElement.entryPoint = entryPoint; |
774 } | 773 } |
775 // Create the synthetic element for `loadLibrary`. | 774 // Create the synthetic element for `loadLibrary`. |
776 libraryElement.createLoadLibraryFunction(summaryResynthesizer.typeProvider); | 775 libraryElement.createLoadLibraryFunction(summaryResynthesizer.typeProvider); |
777 // Done. | 776 // Done. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 // TODO(paulberry): make this work for generic methods. | 845 // TODO(paulberry): make this work for generic methods. |
847 return currentTypeParameters[ | 846 return currentTypeParameters[ |
848 currentTypeParameters.length - type.paramReference].type; | 847 currentTypeParameters.length - type.paramReference].type; |
849 } else { | 848 } else { |
850 // TODO(paulberry): handle references to things other than classes (note: | 849 // TODO(paulberry): handle references to things other than classes (note: |
851 // this should only occur in the case of erroneous code). | 850 // this should only occur in the case of erroneous code). |
852 // TODO(paulberry): test reference to something inside a part. | 851 // TODO(paulberry): test reference to something inside a part. |
853 // TODO(paulberry): test reference to something inside a part of the | 852 // TODO(paulberry): test reference to something inside a part of the |
854 // current lib. | 853 // current lib. |
855 UnlinkedReference reference = unlinkedUnit.references[type.reference]; | 854 UnlinkedReference reference = unlinkedUnit.references[type.reference]; |
856 PrelinkedReference referenceResolution = | 855 LinkedReference referenceResolution = |
857 prelinkedUnit.references[type.reference]; | 856 linkedUnit.references[type.reference]; |
858 ElementLocationImpl location; | 857 ElementLocationImpl location; |
859 if (referenceResolution.dependency != 0) { | 858 if (referenceResolution.dependency != 0) { |
860 location = getReferencedLocation( | 859 location = getReferencedLocation( |
861 prelinkedLibrary.dependencies[referenceResolution.dependency], | 860 linkedLibrary.dependencies[referenceResolution.dependency], |
862 referenceResolution.unit, | 861 referenceResolution.unit, |
863 reference.name); | 862 reference.name); |
864 } else if (referenceResolution.kind == | 863 } else if (referenceResolution.kind == ReferenceKind.unresolved) { |
865 PrelinkedReferenceKind.unresolved) { | |
866 return summaryResynthesizer.typeProvider.undefinedType; | 864 return summaryResynthesizer.typeProvider.undefinedType; |
867 } else if (reference.name.isEmpty) { | 865 } else if (reference.name.isEmpty) { |
868 return summaryResynthesizer.typeProvider.dynamicType; | 866 return summaryResynthesizer.typeProvider.dynamicType; |
869 } else { | 867 } else { |
870 String referencedLibraryUri = librarySource.uri.toString(); | 868 String referencedLibraryUri = librarySource.uri.toString(); |
871 String partUri; | 869 String partUri; |
872 if (referenceResolution.unit != 0) { | 870 if (referenceResolution.unit != 0) { |
873 String uri = unlinkedUnits[0].publicNamespace.parts[ | 871 String uri = unlinkedUnits[0].publicNamespace.parts[ |
874 referenceResolution.unit - 1]; | 872 referenceResolution.unit - 1]; |
875 Source partSource = | 873 Source partSource = |
(...skipping 10 matching lines...) Expand all Loading... |
886 typeArguments = <DartType>[]; | 884 typeArguments = <DartType>[]; |
887 for (int i = 0; i < referenceResolution.numTypeParameters; i++) { | 885 for (int i = 0; i < referenceResolution.numTypeParameters; i++) { |
888 if (i < type.typeArguments.length) { | 886 if (i < type.typeArguments.length) { |
889 typeArguments.add(buildType(type.typeArguments[i])); | 887 typeArguments.add(buildType(type.typeArguments[i])); |
890 } else { | 888 } else { |
891 typeArguments.add(summaryResynthesizer.typeProvider.dynamicType); | 889 typeArguments.add(summaryResynthesizer.typeProvider.dynamicType); |
892 } | 890 } |
893 } | 891 } |
894 } | 892 } |
895 switch (referenceResolution.kind) { | 893 switch (referenceResolution.kind) { |
896 case PrelinkedReferenceKind.classOrEnum: | 894 case ReferenceKind.classOrEnum: |
897 return new InterfaceTypeImpl.elementWithNameAndArgs( | 895 return new InterfaceTypeImpl.elementWithNameAndArgs( |
898 new ClassElementHandle(summaryResynthesizer, location), | 896 new ClassElementHandle(summaryResynthesizer, location), |
899 reference.name, | 897 reference.name, |
900 typeArguments); | 898 typeArguments); |
901 case PrelinkedReferenceKind.typedef: | 899 case ReferenceKind.typedef: |
902 return new FunctionTypeImpl.elementWithNameAndArgs( | 900 return new FunctionTypeImpl.elementWithNameAndArgs( |
903 new FunctionTypeAliasElementHandle( | 901 new FunctionTypeAliasElementHandle( |
904 summaryResynthesizer, location), | 902 summaryResynthesizer, location), |
905 reference.name, | 903 reference.name, |
906 typeArguments, | 904 typeArguments, |
907 typeArguments.isNotEmpty); | 905 typeArguments.isNotEmpty); |
908 default: | 906 default: |
909 // TODO(paulberry): figure out how to handle this case (which should | 907 // TODO(paulberry): figure out how to handle this case (which should |
910 // only occur in the event of erroneous code). | 908 // only occur in the event of erroneous code). |
911 throw new UnimplementedError(); | 909 throw new UnimplementedError(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 if (serializedTypeParameter.bound != null) { | 1003 if (serializedTypeParameter.bound != null) { |
1006 typeParameterElement.bound = buildType(serializedTypeParameter.bound); | 1004 typeParameterElement.bound = buildType(serializedTypeParameter.bound); |
1007 } | 1005 } |
1008 } | 1006 } |
1009 | 1007 |
1010 /** | 1008 /** |
1011 * Build an [ElementLocationImpl] for the entity in the given [unit] of the | 1009 * Build an [ElementLocationImpl] for the entity in the given [unit] of the |
1012 * given [dependency], having the given [name]. | 1010 * given [dependency], having the given [name]. |
1013 */ | 1011 */ |
1014 ElementLocationImpl getReferencedLocation( | 1012 ElementLocationImpl getReferencedLocation( |
1015 PrelinkedDependency dependency, int unit, String name) { | 1013 LinkedDependency dependency, int unit, String name) { |
1016 Source referencedLibrarySource = summaryResynthesizer.sourceFactory | 1014 Source referencedLibrarySource = summaryResynthesizer.sourceFactory |
1017 .resolveUri(librarySource, dependency.uri); | 1015 .resolveUri(librarySource, dependency.uri); |
1018 String referencedLibraryUri = referencedLibrarySource.uri.toString(); | 1016 String referencedLibraryUri = referencedLibrarySource.uri.toString(); |
1019 // TODO(paulberry): consider changing Location format so that this is | 1017 // TODO(paulberry): consider changing Location format so that this is |
1020 // not necessary (2nd string in location should just be the unit | 1018 // not necessary (2nd string in location should just be the unit |
1021 // number). | 1019 // number). |
1022 String partUri; | 1020 String partUri; |
1023 if (unit != 0) { | 1021 if (unit != 0) { |
1024 UnlinkedUnit referencedLibraryDefiningUnit = | 1022 UnlinkedUnit referencedLibraryDefiningUnit = |
1025 summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri); | 1023 summaryResynthesizer.getUnlinkedSummary(referencedLibraryUri); |
1026 String uri = | 1024 String uri = |
1027 referencedLibraryDefiningUnit.publicNamespace.parts[unit - 1]; | 1025 referencedLibraryDefiningUnit.publicNamespace.parts[unit - 1]; |
1028 Source partSource = summaryResynthesizer.sourceFactory | 1026 Source partSource = summaryResynthesizer.sourceFactory |
1029 .resolveUri(referencedLibrarySource, uri); | 1027 .resolveUri(referencedLibrarySource, uri); |
1030 partUri = partSource.uri.toString(); | 1028 partUri = partSource.uri.toString(); |
1031 } else { | 1029 } else { |
1032 partUri = referencedLibraryUri; | 1030 partUri = referencedLibraryUri; |
1033 } | 1031 } |
1034 return new ElementLocationImpl.con3( | 1032 return new ElementLocationImpl.con3( |
1035 <String>[referencedLibraryUri, partUri, name]); | 1033 <String>[referencedLibraryUri, partUri, name]); |
1036 } | 1034 } |
1037 | 1035 |
1038 /** | 1036 /** |
1039 * Populate a [CompilationUnitElement] by deserializing all the elements | 1037 * Populate a [CompilationUnitElement] by deserializing all the elements |
1040 * contained in it. | 1038 * contained in it. |
1041 */ | 1039 */ |
1042 void populateUnit(CompilationUnitElementImpl unit, int unitNum) { | 1040 void populateUnit(CompilationUnitElementImpl unit, int unitNum) { |
1043 prelinkedUnit = prelinkedLibrary.units[unitNum]; | 1041 linkedUnit = linkedLibrary.units[unitNum]; |
1044 unlinkedUnit = unlinkedUnits[unitNum]; | 1042 unlinkedUnit = unlinkedUnits[unitNum]; |
1045 unitHolder = new ElementHolder(); | 1043 unitHolder = new ElementHolder(); |
1046 unlinkedUnit.classes.forEach(buildClass); | 1044 unlinkedUnit.classes.forEach(buildClass); |
1047 unlinkedUnit.enums.forEach(buildEnum); | 1045 unlinkedUnit.enums.forEach(buildEnum); |
1048 unlinkedUnit.executables.forEach(buildExecutable); | 1046 unlinkedUnit.executables.forEach(buildExecutable); |
1049 unlinkedUnit.typedefs.forEach(buildTypedef); | 1047 unlinkedUnit.typedefs.forEach(buildTypedef); |
1050 unlinkedUnit.variables.forEach(buildVariable); | 1048 unlinkedUnit.variables.forEach(buildVariable); |
1051 String absoluteUri = unit.source.uri.toString(); | 1049 String absoluteUri = unit.source.uri.toString(); |
1052 unit.accessors = unitHolder.accessors; | 1050 unit.accessors = unitHolder.accessors; |
1053 unit.enums = unitHolder.enums; | 1051 unit.enums = unitHolder.enums; |
(...skipping 18 matching lines...) Expand all Loading... |
1072 elementMap[typeAlias.name] = typeAlias; | 1070 elementMap[typeAlias.name] = typeAlias; |
1073 } | 1071 } |
1074 for (FunctionElement function in unit.functions) { | 1072 for (FunctionElement function in unit.functions) { |
1075 elementMap[function.name] = function; | 1073 elementMap[function.name] = function; |
1076 } | 1074 } |
1077 for (PropertyAccessorElementImpl accessor in unit.accessors) { | 1075 for (PropertyAccessorElementImpl accessor in unit.accessors) { |
1078 elementMap[accessor.identifier] = accessor; | 1076 elementMap[accessor.identifier] = accessor; |
1079 } | 1077 } |
1080 resummarizedElements[absoluteUri] = elementMap; | 1078 resummarizedElements[absoluteUri] = elementMap; |
1081 unitHolder = null; | 1079 unitHolder = null; |
1082 prelinkedUnit = null; | 1080 linkedUnit = null; |
1083 unlinkedUnit = null; | 1081 unlinkedUnit = null; |
1084 } | 1082 } |
1085 } | 1083 } |
OLD | NEW |