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

Unified Diff: pkg/compiler/lib/src/deferred_load.dart

Issue 785303003: Add option for outputting a deferred loading mapping. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Whitespace Created 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/deferred_load.dart
diff --git a/pkg/compiler/lib/src/deferred_load.dart b/pkg/compiler/lib/src/deferred_load.dart
index f11b6545e07036c08ab9558dca600908930a6545..2b0ab4d236b111b289753f172816dabc20c23abf 100644
--- a/pkg/compiler/lib/src/deferred_load.dart
+++ b/pkg/compiler/lib/src/deferred_load.dart
@@ -40,6 +40,7 @@ import 'elements/elements.dart' show
import 'util/util.dart' show
Link, makeUnique;
+import 'util/uri_extras.dart' as uri_extras;
import 'util/setlet.dart' show
Setlet;
@@ -146,6 +147,10 @@ class DeferredLoadTask extends CompilerTask {
final Map<Import, LibraryElement> _allDeferredImports =
new Map<Import, LibraryElement>();
+ /// Because the token-stream is forgotten later in the program, we cache a
+ /// description of each deferred import.
+ final _deferredImportDescriptions = new Map<Import, ImportDescription>();
+
// For each deferred import we want to know exactly what elements have to
// be loaded.
Map<Import, Set<Element>> _importedDeferredBy = null;
@@ -617,7 +622,7 @@ class DeferredLoadTask extends CompilerTask {
});
}
- void ensureMetadataResolved(Compiler compiler) {
+ void beforeResolution(Compiler compiler) {
if (compiler.mainApp == null) return;
_allDeferredImports[_fakeMainImport] = compiler.mainApp;
var lastDeferred;
@@ -671,7 +676,10 @@ class DeferredLoadTask extends CompilerTask {
// The last import we saw with the same prefix.
Import previousDeferredImport = prefixDeferredImport[prefix];
if (import.isDeferred) {
- _allDeferredImports[import] = library.getLibraryFromTag(import);
+ LibraryElement importedLibrary = library.getLibraryFromTag(import);
+ _allDeferredImports[import] = importedLibrary;
+ _deferredImportDescriptions[import] =
+ new ImportDescription(import, library, compiler);
if (prefix == null) {
compiler.reportError(import,
@@ -764,4 +772,37 @@ class DeferredLoadTask extends CompilerTask {
}
return null;
}
+
+ /// Returns a json-style map for describing what files that are loaded by a
+ /// given deferred import.
+ Map deferredMap() {
floitsch 2015/01/05 14:10:38 has a getter name. Either make it a getter, or cha
sigurdm 2015/01/05 15:23:08 Done.
+ JavaScriptBackend backend = compiler.backend;
+ Map mapping = {};
+ _deferredImportDescriptions.keys.forEach((ast.Import import) {
+ List<OutputUnit> outputUnits = hunksToLoad[importDeferName[import]];
+ ImportDescription description = _deferredImportDescriptions[import];
+ Map a = mapping.putIfAbsent(description.importingUri, () => {});
floitsch 2015/01/05 14:10:38 what's "a" ? Type the map (both static and dynamic
sigurdm 2015/01/05 15:23:08 Fixed the name.
+
+ a[description.prefix] = outputUnits.map(
+ (OutputUnit outputUnit) {
+ return backend.emitter.oldEmitter.deferredPartFileName(outputUnit);
floitsch 2015/01/05 14:10:38 Don't go through "oldEmitter". The best is probabl
sigurdm 2015/01/05 15:23:08 Moved it to backend.
+ }).toList();
+ });
+ return mapping;
+ }
}
+
+class ImportDescription {
+ /// Relative uri to the importing library.
+ final String importingUri;
+ /// The prefix this import is imported as.
+ final String prefix;
+
+ ImportDescription(Import import,
+ LibraryElement importingLibrary,
+ Compiler compiler)
+ : importingUri = uri_extras.relativize(
+ compiler.mainApp.canonicalUri,
+ importingLibrary.canonicalUri, false),
+ prefix = import.prefix.source;
+}

Powered by Google App Engine
This is Rietveld 408576698