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 1591483002: Prepare for chaining resynthesizers from AC to SDK AC. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fallback to the SDK. Created 4 years, 11 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/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 this.getPrelinkedSummary, 97 this.getPrelinkedSummary,
98 this.getUnlinkedSummary, 98 this.getUnlinkedSummary,
99 this.sourceFactory) 99 this.sourceFactory)
100 : super(context); 100 : super(context);
101 101
102 /** 102 /**
103 * Number of libraries that have been resynthesized so far. 103 * Number of libraries that have been resynthesized so far.
104 */ 104 */
105 int get resynthesisCount => _resynthesizedLibraries.length; 105 int get resynthesisCount => _resynthesizedLibraries.length;
106 106
107 /**
108 * Perform delayed finalization of the `dart:core` and `dart:async` libraries.
109 */
110 void finalizeCoreAsyncLibraries() {
111 (_resynthesizedLibraries['dart:core'] as LibraryElementImpl)
112 .createLoadLibraryFunction(typeProvider);
113 (_resynthesizedLibraries['dart:async'] as LibraryElementImpl)
114 .createLoadLibraryFunction(typeProvider);
115 }
116
107 @override 117 @override
108 Element getElement(ElementLocation location) { 118 Element getElement(ElementLocation location) {
109 List<String> components = location.components; 119 List<String> components = location.components;
110 String libraryUri = components[0]; 120 String libraryUri = components[0];
111 // Ask the parent resynthesizer. 121 // Ask the parent resynthesizer.
112 if (parent != null) { 122 if (parent != null) {
113 if (parent.hasLibrarySummary(libraryUri)) { 123 if (parent.hasLibrarySummary(libraryUri)) {
114 return parent.getElement(location); 124 return parent.getElement(location);
115 } 125 }
116 } 126 }
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 importElement.combinators = 745 importElement.combinators =
736 serializedImport.combinators.map(buildCombinator).toList(); 746 serializedImport.combinators.map(buildCombinator).toList();
737 return importElement; 747 return importElement;
738 } 748 }
739 749
740 /** 750 /**
741 * Main entry point. Resynthesize the [LibraryElement] and return it. 751 * Main entry point. Resynthesize the [LibraryElement] and return it.
742 */ 752 */
743 LibraryElement buildLibrary() { 753 LibraryElement buildLibrary() {
744 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty; 754 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty;
745 LibraryElementImpl libraryElement = new LibraryElementImpl( 755 LibraryElementImpl library = new LibraryElementImpl(
746 summaryResynthesizer.context, 756 summaryResynthesizer.context,
747 unlinkedUnits[0].libraryName, 757 unlinkedUnits[0].libraryName,
748 hasName ? unlinkedUnits[0].libraryNameOffset : -1, 758 hasName ? unlinkedUnits[0].libraryNameOffset : -1,
749 unlinkedUnits[0].libraryNameLength); 759 unlinkedUnits[0].libraryNameLength);
750 buildDocumentation( 760 buildDocumentation(library, unlinkedUnits[0].libraryDocumentationComment);
751 libraryElement, unlinkedUnits[0].libraryDocumentationComment);
752 CompilationUnitElementImpl definingCompilationUnit = 761 CompilationUnitElementImpl definingCompilationUnit =
753 new CompilationUnitElementImpl(librarySource.shortName); 762 new CompilationUnitElementImpl(librarySource.shortName);
754 libraryElement.definingCompilationUnit = definingCompilationUnit; 763 library.definingCompilationUnit = definingCompilationUnit;
755 definingCompilationUnit.source = librarySource; 764 definingCompilationUnit.source = librarySource;
756 definingCompilationUnit.librarySource = librarySource; 765 definingCompilationUnit.librarySource = librarySource;
757 List<CompilationUnitElement> parts = <CompilationUnitElement>[]; 766 List<CompilationUnitElement> parts = <CompilationUnitElement>[];
758 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; 767 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0];
759 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == 768 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 ==
760 prelinkedLibrary.units.length); 769 prelinkedLibrary.units.length);
761 for (int i = 1; i < prelinkedLibrary.units.length; i++) { 770 for (int i = 1; i < prelinkedLibrary.units.length; i++) {
762 CompilationUnitElementImpl part = buildPart( 771 CompilationUnitElementImpl part = buildPart(
763 unlinkedDefiningUnit.publicNamespace.parts[i - 1], 772 unlinkedDefiningUnit.publicNamespace.parts[i - 1],
764 unlinkedDefiningUnit.parts[i - 1], 773 unlinkedDefiningUnit.parts[i - 1],
765 unlinkedUnits[i]); 774 unlinkedUnits[i]);
766 parts.add(part); 775 parts.add(part);
767 } 776 }
768 libraryElement.parts = parts; 777 library.parts = parts;
769 List<ImportElement> imports = <ImportElement>[]; 778 List<ImportElement> imports = <ImportElement>[];
770 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) { 779 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) {
771 imports.add(buildImport(unlinkedDefiningUnit.imports[i], 780 imports.add(buildImport(unlinkedDefiningUnit.imports[i],
772 prelinkedLibrary.importDependencies[i])); 781 prelinkedLibrary.importDependencies[i]));
773 } 782 }
774 libraryElement.imports = imports; 783 library.imports = imports;
775 List<ExportElement> exports = <ExportElement>[]; 784 List<ExportElement> exports = <ExportElement>[];
776 assert(unlinkedDefiningUnit.exports.length == 785 assert(unlinkedDefiningUnit.exports.length ==
777 unlinkedDefiningUnit.publicNamespace.exports.length); 786 unlinkedDefiningUnit.publicNamespace.exports.length);
778 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) { 787 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) {
779 exports.add(buildExport(unlinkedDefiningUnit.publicNamespace.exports[i], 788 exports.add(buildExport(unlinkedDefiningUnit.publicNamespace.exports[i],
780 unlinkedDefiningUnit.exports[i])); 789 unlinkedDefiningUnit.exports[i]));
781 } 790 }
782 libraryElement.exports = exports; 791 library.exports = exports;
783 populateUnit(definingCompilationUnit, 0); 792 populateUnit(definingCompilationUnit, 0);
784 for (int i = 0; i < parts.length; i++) { 793 for (int i = 0; i < parts.length; i++) {
785 populateUnit(parts[i], i + 1); 794 populateUnit(parts[i], i + 1);
786 } 795 }
787 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement); 796 BuildLibraryElementUtils.patchTopLevelAccessors(library);
788 // Update delayed Object class references. 797 // Update delayed Object class references.
789 if (isCoreLibrary) { 798 if (isCoreLibrary) {
790 ClassElement objectElement = libraryElement.getType('Object'); 799 ClassElement objectElement = library.getType('Object');
791 assert(objectElement != null); 800 assert(objectElement != null);
792 for (ClassElementImpl classElement in delayedObjectSubclasses) { 801 for (ClassElementImpl classElement in delayedObjectSubclasses) {
793 classElement.supertype = objectElement.type; 802 classElement.supertype = objectElement.type;
794 } 803 }
795 } 804 }
796 // Compute namespaces. 805 // Compute namespaces.
797 libraryElement.publicNamespace = 806 library.publicNamespace =
798 new NamespaceBuilder().createPublicNamespaceForLibrary(libraryElement); 807 new NamespaceBuilder().createPublicNamespaceForLibrary(library);
799 libraryElement.exportNamespace = buildExportNamespace( 808 library.exportNamespace = buildExportNamespace(
800 libraryElement.publicNamespace, prelinkedLibrary.exportNames); 809 library.publicNamespace, prelinkedLibrary.exportNames);
801 // Find the entry point. Note: we can't use element.isEntryPoint because 810 // Find the entry point. Note: we can't use element.isEntryPoint because
802 // that will trigger resynthesis of exported libraries. 811 // that will trigger resynthesis of exported libraries.
803 Element entryPoint = 812 Element entryPoint =
804 libraryElement.exportNamespace.get(FunctionElement.MAIN_FUNCTION_NAME); 813 library.exportNamespace.get(FunctionElement.MAIN_FUNCTION_NAME);
805 if (entryPoint is FunctionElement) { 814 if (entryPoint is FunctionElement) {
806 libraryElement.entryPoint = entryPoint; 815 library.entryPoint = entryPoint;
807 } 816 }
808 // Create the synthetic element for `loadLibrary`. 817 // Create the synthetic element for `loadLibrary`.
809 libraryElement.createLoadLibraryFunction(summaryResynthesizer.typeProvider); 818 // Until the client received dart:core and dart:async, we cannot do this,
819 // because the TypeProvider is not fully initialized. So, it is up to the
820 // Dart SDK client to initialize TypeProvider and finish the dart:core and
821 // dart:async libraries creation.
822 if (library.name != 'dart.core' && library.name != 'dart.async') {
823 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider);
824 }
810 // Done. 825 // Done.
811 return libraryElement; 826 return library;
812 } 827 }
813 828
814 /** 829 /**
815 * Resynthesize a [ParameterElement]. 830 * Resynthesize a [ParameterElement].
816 */ 831 */
817 ParameterElement buildParameter(UnlinkedParam serializedParameter) { 832 ParameterElement buildParameter(UnlinkedParam serializedParameter) {
818 ParameterElementImpl parameterElement = new ParameterElementImpl( 833 ParameterElementImpl parameterElement = new ParameterElementImpl(
819 serializedParameter.name, serializedParameter.nameOffset); 834 serializedParameter.name, serializedParameter.nameOffset);
820 if (serializedParameter.isFunctionTyped) { 835 if (serializedParameter.isFunctionTyped) {
821 FunctionElementImpl parameterTypeElement = 836 FunctionElementImpl parameterTypeElement =
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 } 1125 }
1111 for (PropertyAccessorElementImpl accessor in unit.accessors) { 1126 for (PropertyAccessorElementImpl accessor in unit.accessors) {
1112 elementMap[accessor.identifier] = accessor; 1127 elementMap[accessor.identifier] = accessor;
1113 } 1128 }
1114 resummarizedElements[absoluteUri] = elementMap; 1129 resummarizedElements[absoluteUri] = elementMap;
1115 unitHolder = null; 1130 unitHolder = null;
1116 prelinkedUnit = null; 1131 prelinkedUnit = null;
1117 unlinkedUnit = null; 1132 unlinkedUnit = null;
1118 } 1133 }
1119 } 1134 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/sdk_io.dart ('k') | pkg/analyzer/lib/src/summary/summary_sdk.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698