| OLD | NEW |
| 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 'common.dart'; | 9 import 'common.dart'; |
| 10 import 'common/names.dart' show Uris; | 10 import 'common/names.dart' show Uris; |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 */ | 627 */ |
| 628 Future<LibraryElement> createLibrary(LibraryDependencyHandler handler, | 628 Future<LibraryElement> createLibrary(LibraryDependencyHandler handler, |
| 629 LibraryElement importingLibrary, Uri resolvedUri, | 629 LibraryElement importingLibrary, Uri resolvedUri, |
| 630 {Spannable node, bool skipFileWithPartOfTag: false}) { | 630 {Spannable node, bool skipFileWithPartOfTag: false}) { |
| 631 Uri readableUri = | 631 Uri readableUri = |
| 632 uriTranslator.translate(importingLibrary, resolvedUri, node); | 632 uriTranslator.translate(importingLibrary, resolvedUri, node); |
| 633 LibraryElement library = libraryCanonicalUriMap[resolvedUri]; | 633 LibraryElement library = libraryCanonicalUriMap[resolvedUri]; |
| 634 if (library != null) { | 634 if (library != null) { |
| 635 return new Future.value(library); | 635 return new Future.value(library); |
| 636 } | 636 } |
| 637 library = deserializer.readLibrary(resolvedUri); | 637 return deserializer.readLibrary(resolvedUri).then((LibraryElement library) { |
| 638 if (library != null) { | 638 if (library != null) { |
| 639 return loadDeserializedLibrary(handler, library); | 639 return loadDeserializedLibrary(handler, library); |
| 640 } | 640 } |
| 641 return reporter.withCurrentElement(importingLibrary, () { | 641 return reporter.withCurrentElement(importingLibrary, () { |
| 642 return _readScript(node, readableUri, resolvedUri).then((Script script) { | 642 return _readScript(node, readableUri, resolvedUri) |
| 643 if (script == null) return null; | 643 .then((Script script) { |
| 644 LibraryElement element = | 644 if (script == null) return null; |
| 645 createLibrarySync(handler, script, resolvedUri); | 645 LibraryElement element = |
| 646 CompilationUnitElementX compilationUnit = element.entryCompilationUnit; | 646 createLibrarySync(handler, script, resolvedUri); |
| 647 if (compilationUnit.partTag != null) { | 647 CompilationUnitElementX compilationUnit = |
| 648 if (skipFileWithPartOfTag) { | 648 element.entryCompilationUnit; |
| 649 // TODO(johnniwinther): Avoid calling [listener.onLibraryCreated] | 649 if (compilationUnit.partTag != null) { |
| 650 // for this library. | 650 if (skipFileWithPartOfTag) { |
| 651 libraryCanonicalUriMap.remove(resolvedUri); | 651 // TODO(johnniwinther): Avoid calling [listener.onLibraryCreated] |
| 652 return null; | 652 // for this library. |
| 653 libraryCanonicalUriMap.remove(resolvedUri); |
| 654 return null; |
| 655 } |
| 656 if (importingLibrary == null) { |
| 657 DiagnosticMessage error = reporter.withCurrentElement( |
| 658 compilationUnit, |
| 659 () => reporter.createMessage( |
| 660 compilationUnit.partTag, MessageKind.MAIN_HAS_PART_OF)); |
| 661 reporter.reportError(error); |
| 662 } else { |
| 663 DiagnosticMessage error = reporter.withCurrentElement( |
| 664 compilationUnit, |
| 665 () => reporter.createMessage( |
| 666 compilationUnit.partTag, MessageKind.IMPORT_PART_OF)); |
| 667 DiagnosticMessage info = reporter.withCurrentElement( |
| 668 importingLibrary, |
| 669 () => reporter.createMessage( |
| 670 node, MessageKind.IMPORT_PART_OF_HERE)); |
| 671 reporter.reportError(error, [info]); |
| 672 } |
| 653 } | 673 } |
| 654 if (importingLibrary == null) { | 674 return processLibraryTags(handler, element).then((_) { |
| 655 DiagnosticMessage error = reporter.withCurrentElement( | 675 reporter.withCurrentElement(element, () { |
| 656 compilationUnit, | 676 handler.registerLibraryExports(element); |
| 657 () => reporter.createMessage( | 677 }); |
| 658 compilationUnit.partTag, MessageKind.MAIN_HAS_PART_OF)); | 678 return element; |
| 659 reporter.reportError(error); | |
| 660 } else { | |
| 661 DiagnosticMessage error = reporter.withCurrentElement( | |
| 662 compilationUnit, | |
| 663 () => reporter.createMessage( | |
| 664 compilationUnit.partTag, MessageKind.IMPORT_PART_OF)); | |
| 665 DiagnosticMessage info = reporter.withCurrentElement( | |
| 666 importingLibrary, | |
| 667 () => reporter.createMessage( | |
| 668 node, MessageKind.IMPORT_PART_OF_HERE)); | |
| 669 reporter.reportError(error, [info]); | |
| 670 } | |
| 671 } | |
| 672 return processLibraryTags(handler, element).then((_) { | |
| 673 reporter.withCurrentElement(element, () { | |
| 674 handler.registerLibraryExports(element); | |
| 675 }); | 679 }); |
| 676 return element; | |
| 677 }); | 680 }); |
| 678 }); | 681 }); |
| 679 }); | 682 }); |
| 680 } | 683 } |
| 681 | 684 |
| 682 LibraryElement createLibrarySync( | 685 LibraryElement createLibrarySync( |
| 683 LibraryDependencyHandler handler, Script script, Uri resolvedUri) { | 686 LibraryDependencyHandler handler, Script script, Uri resolvedUri) { |
| 684 LibraryElement element = new LibraryElementX(script, resolvedUri); | 687 LibraryElement element = new LibraryElementX(script, resolvedUri); |
| 685 return reporter.withCurrentElement(element, () { | 688 return reporter.withCurrentElement(element, () { |
| 686 if (handler != null) { | 689 if (handler != null) { |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 /// Called after a request to load a library. The [results] will include all | 1475 /// Called after a request to load a library. The [results] will include all |
| 1473 /// transitive libraries loaded as a result of the initial request. | 1476 /// transitive libraries loaded as a result of the initial request. |
| 1474 Future onLibrariesLoaded(LoadedLibraries results); | 1477 Future onLibrariesLoaded(LoadedLibraries results); |
| 1475 | 1478 |
| 1476 /// Called whenever a library element is created. | 1479 /// Called whenever a library element is created. |
| 1477 void onLibraryCreated(LibraryElement library); | 1480 void onLibraryCreated(LibraryElement library); |
| 1478 | 1481 |
| 1479 /// Called whenever a library is scanned from a script file. | 1482 /// Called whenever a library is scanned from a script file. |
| 1480 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); | 1483 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); |
| 1481 } | 1484 } |
| OLD | NEW |