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

Side by Side Diff: pkg/compiler/lib/src/library_loader.dart

Issue 1192103002: Support serialization of the compiler backbone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments Created 5 years, 5 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'dart2jslib.dart' show 9 import 'dart2jslib.dart' show
10 Compiler, 10 Compiler,
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 */ 475 */
476 Future scanPart(Part part, Uri resolvedUri, LibraryElement library) { 476 Future scanPart(Part part, Uri resolvedUri, LibraryElement library) {
477 if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri); 477 if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri);
478 Uri readableUri = compiler.translateResolvedUri(library, resolvedUri, part); 478 Uri readableUri = compiler.translateResolvedUri(library, resolvedUri, part);
479 if (readableUri == null) return new Future.value(); 479 if (readableUri == null) return new Future.value();
480 return compiler.withCurrentElement(library, () { 480 return compiler.withCurrentElement(library, () {
481 return compiler.readScript(part, readableUri). 481 return compiler.readScript(part, readableUri).
482 then((Script sourceScript) { 482 then((Script sourceScript) {
483 if (sourceScript == null) return; 483 if (sourceScript == null) return;
484 484
485 CompilationUnitElement unit = 485 CompilationUnitElementX unit =
486 new CompilationUnitElementX(sourceScript, library); 486 new CompilationUnitElementX(sourceScript, library);
487 compiler.withCurrentElement(unit, () { 487 compiler.withCurrentElement(unit, () {
488 compiler.scanner.scan(unit); 488 compiler.scanner.scan(unit);
489 if (unit.partTag == null && !sourceScript.isSynthesized) { 489 if (unit.partTag == null && !sourceScript.isSynthesized) {
490 compiler.reportError(unit, MessageKind.MISSING_PART_OF_TAG); 490 compiler.reportError(unit, MessageKind.MISSING_PART_OF_TAG);
491 } 491 }
492 }); 492 });
493 }); 493 });
494 }); 494 });
495 } 495 }
(...skipping 20 matching lines...) Expand all
516 } 516 }
517 return createLibrary(handler, library, resolvedUri, tag.uri) 517 return createLibrary(handler, library, resolvedUri, tag.uri)
518 .then((LibraryElement loadedLibrary) { 518 .then((LibraryElement loadedLibrary) {
519 if (loadedLibrary == null) return; 519 if (loadedLibrary == null) return;
520 compiler.withCurrentElement(library, () { 520 compiler.withCurrentElement(library, () {
521 handler.registerDependency(library, tag, loadedLibrary); 521 handler.registerDependency(library, tag, loadedLibrary);
522 }); 522 });
523 }); 523 });
524 } 524 }
525 525
526 /// Loads the deserialized [library] with the [handler].
527 ///
528 /// All libraries imported or exported transitively from [library] will be
529 /// loaded as well.
530 Future<LibraryElement> loadDeserializedLibrary(
531 LibraryDependencyHandler handler,
532 LibraryElement library) async {
533 compiler.onLibraryCreated(library);
534 libraryCanonicalUriMap[library.canonicalUri] = library;
535 await compiler.onLibraryScanned(library, handler);
536 for (LibraryTag tag in library.tags) {
537 LibraryElement dependency = library.getLibraryFromTag(tag);
538 await createLibrary(handler, library, dependency.canonicalUri);
539 }
540 return library;
541 }
542
526 /** 543 /**
527 * Create (or reuse) a library element for the library specified by the 544 * Create (or reuse) a library element for the library specified by the
528 * [resolvedUri]. 545 * [resolvedUri].
529 * 546 *
530 * If a new library is created, the [handler] is notified. 547 * If a new library is created, the [handler] is notified.
531 */ 548 */
532 Future<LibraryElement> createLibrary(LibraryDependencyHandler handler, 549 Future<LibraryElement> createLibrary(LibraryDependencyHandler handler,
533 LibraryElement importingLibrary, 550 LibraryElement importingLibrary,
534 Uri resolvedUri, 551 Uri resolvedUri,
535 [Node node]) { 552 [Node node]) {
536 Uri readableUri = 553 Uri readableUri =
537 compiler.translateResolvedUri(importingLibrary, resolvedUri, node); 554 compiler.translateResolvedUri(importingLibrary, resolvedUri, node);
538 LibraryElement library = libraryCanonicalUriMap[resolvedUri]; 555 LibraryElement library = libraryCanonicalUriMap[resolvedUri];
539 if (library != null) { 556 if (library != null) {
540 return new Future.value(library); 557 return new Future.value(library);
541 } 558 }
559 library = compiler.serialization.readLibrary(resolvedUri);
560 if (library != null) {
561 return loadDeserializedLibrary(handler, library);
562 }
542 var readScript = compiler.readScript; 563 var readScript = compiler.readScript;
543 if (readableUri == null) { 564 if (readableUri == null) {
544 readableUri = resolvedUri; 565 readableUri = resolvedUri;
545 readScript = compiler.synthesizeScript; 566 readScript = compiler.synthesizeScript;
546 } 567 }
547 return compiler.withCurrentElement(importingLibrary, () { 568 return compiler.withCurrentElement(importingLibrary, () {
548 return readScript(node, readableUri).then((Script script) { 569 return readScript(node, readableUri).then((Script script) {
549 if (script == null) return null; 570 if (script == null) return null;
550 LibraryElement element = 571 LibraryElement element =
551 createLibrarySync(handler, script, resolvedUri); 572 createLibrarySync(handler, script, resolvedUri);
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 } 1215 }
1195 suffixes.add(const Link<Uri>().prepend(canonicalUri)); 1216 suffixes.add(const Link<Uri>().prepend(canonicalUri));
1196 } 1217 }
1197 suffixChainMap[library] = suffixes; 1218 suffixChainMap[library] = suffixes;
1198 return; 1219 return;
1199 } 1220 }
1200 1221
1201 computeSuffixes(rootLibrary, const Link<Uri>()); 1222 computeSuffixes(rootLibrary, const Link<Uri>());
1202 } 1223 }
1203 } 1224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698