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

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

Issue 2001903002: Make imports resynthesizing completely lazy. (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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 this.unlinkedUnits, this.librarySource) { 1082 this.unlinkedUnits, this.librarySource) {
1083 libraryUri = librarySource.uri.toString(); 1083 libraryUri = librarySource.uri.toString();
1084 isCoreLibrary = libraryUri == 'dart:core'; 1084 isCoreLibrary = libraryUri == 'dart:core';
1085 } 1085 }
1086 1086
1087 /** 1087 /**
1088 * Resynthesize a [NamespaceCombinator]. 1088 * Resynthesize a [NamespaceCombinator].
1089 */ 1089 */
1090 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { 1090 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) {
1091 if (serializedCombinator.shows.isNotEmpty) { 1091 if (serializedCombinator.shows.isNotEmpty) {
1092 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); 1092 return new ShowElementCombinatorImpl.forSerialized(serializedCombinator);
1093 // Note: we call toList() so that we don't retain a reference to the
1094 // deserialized data structure.
1095 combinator.shownNames = serializedCombinator.shows.toList();
1096 combinator.offset = serializedCombinator.offset;
1097 combinator.end = serializedCombinator.end;
1098 return combinator;
1099 } else { 1093 } else {
1100 HideElementCombinatorImpl combinator = new HideElementCombinatorImpl(); 1094 return new HideElementCombinatorImpl.forSerialized(serializedCombinator);
1101 // Note: we call toList() so that we don't retain a reference to the
1102 // deserialized data structure.
1103 combinator.hiddenNames = serializedCombinator.hides.toList();
1104 return combinator;
1105 } 1095 }
1106 } 1096 }
1107 1097
1108 /** 1098 /**
1109 * Resynthesize an [ExportElement], 1099 * Resynthesize an [ExportElement],
1110 */ 1100 */
1111 ExportElement buildExport( 1101 ExportElement buildExport(
1112 _UnitResynthesizer definingUnitResynthesizer, 1102 _UnitResynthesizer definingUnitResynthesizer,
1113 UnlinkedExportPublic serializedExportPublic, 1103 UnlinkedExportPublic serializedExportPublic,
1114 UnlinkedExportNonPublic serializedExportNonPublic) { 1104 UnlinkedExportNonPublic serializedExportNonPublic) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 }); 1171 });
1182 // Add all the names from [exportNames]. 1172 // Add all the names from [exportNames].
1183 for (LinkedExportName exportName in exportNames) { 1173 for (LinkedExportName exportName in exportNames) {
1184 definedNames.putIfAbsent( 1174 definedNames.putIfAbsent(
1185 exportName.name, () => buildExportName(exportName)); 1175 exportName.name, () => buildExportName(exportName));
1186 } 1176 }
1187 return new Namespace(definedNames); 1177 return new Namespace(definedNames);
1188 } 1178 }
1189 1179
1190 /** 1180 /**
1191 * Resynthesize an [ImportElement].
1192 */
1193 ImportElement buildImport(
1194 _UnitResynthesizer definingUnitResynthesizer,
1195 UnlinkedImport serializedImport,
1196 int dependency,
1197 LibraryElement libraryBeingResynthesized) {
1198 ImportElementImpl importElement = new ImportElementImpl.forSerialized(
1199 serializedImport, dependency, library);
1200 importElement.combinators =
1201 serializedImport.combinators.map(buildCombinator).toList();
1202 return importElement;
1203 }
1204
1205 /**
1206 * Main entry point. Resynthesize the [LibraryElement] and return it. 1181 * Main entry point. Resynthesize the [LibraryElement] and return it.
1207 */ 1182 */
1208 LibraryElement buildLibrary() { 1183 LibraryElement buildLibrary() {
1209 // Create LibraryElementImpl. 1184 // Create LibraryElementImpl.
1210 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty; 1185 bool hasName = unlinkedUnits[0].libraryName.isNotEmpty;
1211 library = new LibraryElementImpl.forSerialized( 1186 library = new LibraryElementImpl.forSerialized(
1212 summaryResynthesizer.context, 1187 summaryResynthesizer.context,
1213 unlinkedUnits[0].libraryName, 1188 unlinkedUnits[0].libraryName,
1214 hasName ? unlinkedUnits[0].libraryNameOffset : -1, 1189 hasName ? unlinkedUnits[0].libraryNameOffset : -1,
1215 unlinkedUnits[0].libraryNameLength, 1190 unlinkedUnits[0].libraryNameLength,
(...skipping 13 matching lines...) Expand all
1229 linkedLibrary.units.length); 1204 linkedLibrary.units.length);
1230 for (int i = 1; i < linkedLibrary.units.length; i++) { 1205 for (int i = 1; i < linkedLibrary.units.length; i++) {
1231 _UnitResynthesizer partResynthesizer = buildPart( 1206 _UnitResynthesizer partResynthesizer = buildPart(
1232 definingUnitResynthesizer, 1207 definingUnitResynthesizer,
1233 unlinkedDefiningUnit.publicNamespace.parts[i - 1], 1208 unlinkedDefiningUnit.publicNamespace.parts[i - 1],
1234 unlinkedDefiningUnit.parts[i - 1], 1209 unlinkedDefiningUnit.parts[i - 1],
1235 i); 1210 i);
1236 partResynthesizers.add(partResynthesizer); 1211 partResynthesizers.add(partResynthesizer);
1237 } 1212 }
1238 library.parts = partResynthesizers.map((r) => r.unit).toList(); 1213 library.parts = partResynthesizers.map((r) => r.unit).toList();
1239 // Create imports.
1240 List<ImportElement> imports = <ImportElement>[];
1241 for (int i = 0; i < unlinkedDefiningUnit.imports.length; i++) {
1242 imports.add(buildImport(
1243 definingUnitResynthesizer,
1244 unlinkedDefiningUnit.imports[i],
1245 linkedLibrary.importDependencies[i],
1246 library));
1247 }
1248 library.imports = imports;
1249 // Create exports. 1214 // Create exports.
1250 List<ExportElement> exports = <ExportElement>[]; 1215 List<ExportElement> exports = <ExportElement>[];
1251 assert(unlinkedDefiningUnit.exports.length == 1216 assert(unlinkedDefiningUnit.exports.length ==
1252 unlinkedDefiningUnit.publicNamespace.exports.length); 1217 unlinkedDefiningUnit.publicNamespace.exports.length);
1253 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) { 1218 for (int i = 0; i < unlinkedDefiningUnit.exports.length; i++) {
1254 exports.add(buildExport( 1219 exports.add(buildExport(
1255 definingUnitResynthesizer, 1220 definingUnitResynthesizer,
1256 unlinkedDefiningUnit.publicNamespace.exports[i], 1221 unlinkedDefiningUnit.publicNamespace.exports[i],
1257 unlinkedDefiningUnit.exports[i])); 1222 unlinkedDefiningUnit.exports[i]));
1258 } 1223 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 1326
1362 /** 1327 /**
1363 * Implementation of [LibraryResynthesizerContext] for [_LibraryResynthesizer]. 1328 * Implementation of [LibraryResynthesizerContext] for [_LibraryResynthesizer].
1364 */ 1329 */
1365 class _LibraryResynthesizerContext implements LibraryResynthesizerContext { 1330 class _LibraryResynthesizerContext implements LibraryResynthesizerContext {
1366 final _LibraryResynthesizer resynthesizer; 1331 final _LibraryResynthesizer resynthesizer;
1367 1332
1368 _LibraryResynthesizerContext(this.resynthesizer); 1333 _LibraryResynthesizerContext(this.resynthesizer);
1369 1334
1370 @override 1335 @override
1336 LinkedLibrary get linkedLibrary => resynthesizer.linkedLibrary;
1337
1338 @override
1371 Namespace buildExportNamespace() { 1339 Namespace buildExportNamespace() {
1372 LibraryElementImpl library = resynthesizer.library; 1340 LibraryElementImpl library = resynthesizer.library;
1373 return resynthesizer.buildExportNamespace( 1341 return resynthesizer.buildExportNamespace(
1374 library.publicNamespace, resynthesizer.linkedLibrary.exportNames); 1342 library.publicNamespace, resynthesizer.linkedLibrary.exportNames);
1375 } 1343 }
1376 1344
1377 @override 1345 @override
1378 LibraryElement buildImportedLibrary(int dependency) { 1346 LibraryElement buildImportedLibrary(int dependency) {
1379 String depUri = resynthesizer.linkedLibrary.dependencies[dependency].uri; 1347 String depUri = resynthesizer.linkedLibrary.dependencies[dependency].uri;
1380 String absoluteUri = resynthesizer.summaryResynthesizer.sourceFactory 1348 String absoluteUri = resynthesizer.summaryResynthesizer.sourceFactory
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after
3044 static String _getElementIdentifier(String name, ReferenceKind kind) { 3012 static String _getElementIdentifier(String name, ReferenceKind kind) {
3045 if (kind == ReferenceKind.topLevelPropertyAccessor || 3013 if (kind == ReferenceKind.topLevelPropertyAccessor ||
3046 kind == ReferenceKind.propertyAccessor) { 3014 kind == ReferenceKind.propertyAccessor) {
3047 if (!name.endsWith('=')) { 3015 if (!name.endsWith('=')) {
3048 return name + '?'; 3016 return name + '?';
3049 } 3017 }
3050 } 3018 }
3051 return name; 3019 return name;
3052 } 3020 }
3053 } 3021 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698