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

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

Issue 2002163002: Resynthesize exports lazily. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 */ 1089 */
1090 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { 1090 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) {
1091 if (serializedCombinator.shows.isNotEmpty) { 1091 if (serializedCombinator.shows.isNotEmpty) {
1092 return new ShowElementCombinatorImpl.forSerialized(serializedCombinator); 1092 return new ShowElementCombinatorImpl.forSerialized(serializedCombinator);
1093 } else { 1093 } else {
1094 return new HideElementCombinatorImpl.forSerialized(serializedCombinator); 1094 return new HideElementCombinatorImpl.forSerialized(serializedCombinator);
1095 } 1095 }
1096 } 1096 }
1097 1097
1098 /** 1098 /**
1099 * Resynthesize an [ExportElement],
1100 */
1101 ExportElement buildExport(
1102 _UnitResynthesizer definingUnitResynthesizer,
1103 UnlinkedExportPublic serializedExportPublic,
1104 UnlinkedExportNonPublic serializedExportNonPublic) {
1105 ExportElementImpl exportElement =
1106 new ExportElementImpl(serializedExportNonPublic.offset);
1107 String exportedLibraryUri = summaryResynthesizer.sourceFactory
1108 .resolveUri(librarySource, serializedExportPublic.uri)
1109 .uri
1110 .toString();
1111 exportElement.exportedLibrary = new LibraryElementHandle(
1112 summaryResynthesizer,
1113 new ElementLocationImpl.con3(<String>[exportedLibraryUri]));
1114 exportElement.uri = serializedExportPublic.uri;
1115 exportElement.combinators =
1116 serializedExportPublic.combinators.map(buildCombinator).toList();
1117 exportElement.uriOffset = serializedExportNonPublic.uriOffset;
1118 exportElement.uriEnd = serializedExportNonPublic.uriEnd;
1119 definingUnitResynthesizer.buildAnnotations(
1120 exportElement, serializedExportNonPublic.annotations);
1121 return exportElement;
1122 }
1123
1124 /**
1125 * Build an [ElementHandle] referring to the entity referred to by the given 1099 * Build an [ElementHandle] referring to the entity referred to by the given
1126 * [exportName]. 1100 * [exportName].
1127 */ 1101 */
1128 ElementHandle buildExportName(LinkedExportName exportName) { 1102 ElementHandle buildExportName(LinkedExportName exportName) {
1129 String name = exportName.name; 1103 String name = exportName.name;
1130 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor && 1104 if (exportName.kind == ReferenceKind.topLevelPropertyAccessor &&
1131 !name.endsWith('=')) { 1105 !name.endsWith('=')) {
1132 name += '?'; 1106 name += '?';
1133 } 1107 }
1134 ElementLocationImpl location = new ElementLocationImpl.con3( 1108 ElementLocationImpl location = new ElementLocationImpl.con3(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 linkedLibrary.units.length); 1178 linkedLibrary.units.length);
1205 for (int i = 1; i < linkedLibrary.units.length; i++) { 1179 for (int i = 1; i < linkedLibrary.units.length; i++) {
1206 _UnitResynthesizer partResynthesizer = buildPart( 1180 _UnitResynthesizer partResynthesizer = buildPart(
1207 definingUnitResynthesizer, 1181 definingUnitResynthesizer,
1208 unlinkedDefiningUnit.publicNamespace.parts[i - 1], 1182 unlinkedDefiningUnit.publicNamespace.parts[i - 1],
1209 unlinkedDefiningUnit.parts[i - 1], 1183 unlinkedDefiningUnit.parts[i - 1],
1210 i); 1184 i);
1211 partResynthesizers.add(partResynthesizer); 1185 partResynthesizers.add(partResynthesizer);
1212 } 1186 }
1213 library.parts = partResynthesizers.map((r) => r.unit).toList(); 1187 library.parts = partResynthesizers.map((r) => r.unit).toList();
1214 // Create exports.
1215 List<ExportElement> exports = <ExportElement>[];
1216 assert(unlinkedDefiningUnit.exports.length ==
1217 unlinkedDefiningUnit.publicNamespace.exports.length);
1218 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) {
1219 exports.add(buildExport(
1220 definingUnitResynthesizer,
1221 unlinkedDefiningUnit.publicNamespace.exports[i],
1222 unlinkedDefiningUnit.exports[i]));
1223 }
1224 library.exports = exports;
1225 // Populate units. 1188 // Populate units.
1226 populateUnit(definingUnitResynthesizer); 1189 populateUnit(definingUnitResynthesizer);
1227 for (_UnitResynthesizer partResynthesizer in partResynthesizers) { 1190 for (_UnitResynthesizer partResynthesizer in partResynthesizers) {
1228 populateUnit(partResynthesizer); 1191 populateUnit(partResynthesizer);
1229 } 1192 }
1230 // Update delayed Object class references. 1193 // Update delayed Object class references.
1231 if (isCoreLibrary) { 1194 if (isCoreLibrary) {
1232 ClassElement objectElement = library.getType('Object'); 1195 ClassElement objectElement = library.getType('Object');
1233 assert(objectElement != null); 1196 assert(objectElement != null);
1234 for (ClassElementImpl classElement in delayedObjectSubclasses) { 1197 for (ClassElementImpl classElement in delayedObjectSubclasses) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 */ 1292 */
1330 class _LibraryResynthesizerContext implements LibraryResynthesizerContext { 1293 class _LibraryResynthesizerContext implements LibraryResynthesizerContext {
1331 final _LibraryResynthesizer resynthesizer; 1294 final _LibraryResynthesizer resynthesizer;
1332 1295
1333 _LibraryResynthesizerContext(this.resynthesizer); 1296 _LibraryResynthesizerContext(this.resynthesizer);
1334 1297
1335 @override 1298 @override
1336 LinkedLibrary get linkedLibrary => resynthesizer.linkedLibrary; 1299 LinkedLibrary get linkedLibrary => resynthesizer.linkedLibrary;
1337 1300
1338 @override 1301 @override
1302 LibraryElement buildExportedLibrary(String relativeUri) {
1303 return _getLibraryByRelativeUri(relativeUri);
1304 }
1305
1306 @override
1339 Namespace buildExportNamespace() { 1307 Namespace buildExportNamespace() {
1340 LibraryElementImpl library = resynthesizer.library; 1308 LibraryElementImpl library = resynthesizer.library;
1341 return resynthesizer.buildExportNamespace( 1309 return resynthesizer.buildExportNamespace(
1342 library.publicNamespace, resynthesizer.linkedLibrary.exportNames); 1310 library.publicNamespace, resynthesizer.linkedLibrary.exportNames);
1343 } 1311 }
1344 1312
1345 @override 1313 @override
1346 LibraryElement buildImportedLibrary(int dependency) { 1314 LibraryElement buildImportedLibrary(int dependency) {
1347 String depUri = resynthesizer.linkedLibrary.dependencies[dependency].uri; 1315 String depUri = resynthesizer.linkedLibrary.dependencies[dependency].uri;
1348 String absoluteUri = resynthesizer.summaryResynthesizer.sourceFactory 1316 return _getLibraryByRelativeUri(depUri);
1349 .resolveUri(resynthesizer.librarySource, depUri)
1350 .uri
1351 .toString();
1352 return new LibraryElementHandle(resynthesizer.summaryResynthesizer,
1353 new ElementLocationImpl.con3(<String>[absoluteUri]));
1354 } 1317 }
1355 1318
1356 @override 1319 @override
1357 Namespace buildPublicNamespace() { 1320 Namespace buildPublicNamespace() {
1358 LibraryElementImpl library = resynthesizer.library; 1321 LibraryElementImpl library = resynthesizer.library;
1359 return new NamespaceBuilder().createPublicNamespaceForLibrary(library); 1322 return new NamespaceBuilder().createPublicNamespaceForLibrary(library);
1360 } 1323 }
1361 1324
1362 @override 1325 @override
1363 FunctionElement findEntryPoint() { 1326 FunctionElement findEntryPoint() {
1364 LibraryElementImpl library = resynthesizer.library; 1327 LibraryElementImpl library = resynthesizer.library;
1365 Element entryPoint = 1328 Element entryPoint =
1366 library.exportNamespace.get(FunctionElement.MAIN_FUNCTION_NAME); 1329 library.exportNamespace.get(FunctionElement.MAIN_FUNCTION_NAME);
1367 if (entryPoint is FunctionElement) { 1330 if (entryPoint is FunctionElement) {
1368 return entryPoint; 1331 return entryPoint;
1369 } 1332 }
1370 return null; 1333 return null;
1371 } 1334 }
1372 1335
1373 @override 1336 @override
1374 void patchTopLevelAccessors() { 1337 void patchTopLevelAccessors() {
1375 LibraryElementImpl library = resynthesizer.library; 1338 LibraryElementImpl library = resynthesizer.library;
1376 BuildLibraryElementUtils.patchTopLevelAccessors(library); 1339 BuildLibraryElementUtils.patchTopLevelAccessors(library);
1377 } 1340 }
1341
1342 LibraryElementHandle _getLibraryByRelativeUri(String depUri) {
1343 String absoluteUri = resynthesizer.summaryResynthesizer.sourceFactory
1344 .resolveUri(resynthesizer.librarySource, depUri)
1345 .uri
1346 .toString();
1347 return new LibraryElementHandle(resynthesizer.summaryResynthesizer,
1348 new ElementLocationImpl.con3(<String>[absoluteUri]));
1349 }
1378 } 1350 }
1379 1351
1380 /** 1352 /**
1381 * Data structure used during resynthesis to record all the information that is 1353 * Data structure used during resynthesis to record all the information that is
1382 * known about how to resynthesize a single entry in [LinkedUnit.references] 1354 * known about how to resynthesize a single entry in [LinkedUnit.references]
1383 * (and its associated entry in [UnlinkedUnit.references], if it exists). 1355 * (and its associated entry in [UnlinkedUnit.references], if it exists).
1384 */ 1356 */
1385 class _ReferenceInfo { 1357 class _ReferenceInfo {
1386 /** 1358 /**
1387 * The [_LibraryResynthesizer] which is being used to obtain summaries. 1359 * The [_LibraryResynthesizer] which is being used to obtain summaries.
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
3012 static String _getElementIdentifier(String name, ReferenceKind kind) { 2984 static String _getElementIdentifier(String name, ReferenceKind kind) {
3013 if (kind == ReferenceKind.topLevelPropertyAccessor || 2985 if (kind == ReferenceKind.topLevelPropertyAccessor ||
3014 kind == ReferenceKind.propertyAccessor) { 2986 kind == ReferenceKind.propertyAccessor) {
3015 if (!name.endsWith('=')) { 2987 if (!name.endsWith('=')) {
3016 return name + '?'; 2988 return name + '?';
3017 } 2989 }
3018 } 2990 }
3019 return name; 2991 return name;
3020 } 2992 }
3021 } 2993 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698