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/names.dart' show Uris; | 9 import 'common/names.dart' show Uris; |
10 import 'common/tasks.dart' show CompilerTask, Measurer; | 10 import 'common/tasks.dart' show CompilerTask, Measurer; |
11 import 'common.dart'; | 11 import 'common.dart'; |
12 import 'elements/elements.dart' | 12 import 'elements/elements.dart' |
13 show | 13 show |
14 CompilationUnitElement, | 14 CompilationUnitElement, |
15 Element, | 15 Element, |
16 ImportElement, | 16 ImportElement, |
17 ExportElement, | 17 ExportElement, |
18 LibraryElement; | 18 LibraryElement; |
19 import 'elements/modelx.dart' | 19 import 'elements/modelx.dart' |
20 show | 20 show |
21 CompilationUnitElementX, | 21 CompilationUnitElementX, |
22 DeferredLoaderGetterElementX, | 22 DeferredLoaderGetterElementX, |
23 ErroneousElementX, | 23 ErroneousElementX, |
24 ExportElementX, | 24 ExportElementX, |
25 ImportElementX, | 25 ImportElementX, |
26 LibraryElementX, | 26 LibraryElementX, |
27 LibraryDependencyElementX, | 27 LibraryDependencyElementX, |
28 PrefixElementX, | 28 PrefixElementX, |
29 SyntheticImportElement; | 29 SyntheticImportElement; |
30 import 'enqueue.dart' show DeferredAction; | |
Siggi Cherem (dart-lang)
2017/03/14 05:27:55
consider moving Deferred action under util/deferre
Johnni Winther
2017/03/15 12:46:53
Will do in a later CL.
| |
30 import 'environment.dart'; | 31 import 'environment.dart'; |
31 import 'resolved_uri_translator.dart'; | 32 import 'resolved_uri_translator.dart'; |
32 import 'script.dart'; | 33 import 'script.dart'; |
33 import 'serialization/serialization.dart' show LibraryDeserializer; | 34 import 'serialization/serialization.dart' show LibraryDeserializer; |
34 import 'tree/tree.dart'; | 35 import 'tree/tree.dart'; |
35 import 'util/util.dart' show Link, LinkBuilder; | 36 import 'util/util.dart' show Link, LinkBuilder; |
36 | 37 |
37 typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( | 38 typedef Future<Iterable<LibraryElement>> ReuseLibrariesFunction( |
38 Iterable<LibraryElement> libraries); | 39 Iterable<LibraryElement> libraries); |
39 | 40 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 /// | 165 /// |
165 /// This method is used for incremental compilation. | 166 /// This method is used for incremental compilation. |
166 void reset({bool reuseLibrary(LibraryElement library)}); | 167 void reset({bool reuseLibrary(LibraryElement library)}); |
167 | 168 |
168 /// Asynchronous version of [reset]. | 169 /// Asynchronous version of [reset]. |
169 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); | 170 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); |
170 | 171 |
171 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list | 172 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list |
172 /// of libraries that can be reused. | 173 /// of libraries that can be reused. |
173 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries); | 174 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries); |
175 | |
176 /// Register a deferred action to be performed during resolution. | |
177 void registerDeferredAction(DeferredAction action); | |
178 | |
179 /// Returns the deferred actions registered since the last call to | |
180 /// [pullDeferredActions]. | |
181 Iterable<DeferredAction> pullDeferredActions(); | |
174 } | 182 } |
175 | 183 |
176 /// Interface for an entity that provide libraries. For instance from normal | 184 /// Interface for an entity that provide libraries. For instance from normal |
177 /// library loading or from deserialization. | 185 /// library loading or from deserialization. |
178 // TODO(johnniwinther): Use this to integrate deserialized libraries better. | 186 // TODO(johnniwinther): Use this to integrate deserialized libraries better. |
179 abstract class LibraryProvider { | 187 abstract class LibraryProvider { |
180 /// Looks up the library with the [canonicalUri]. | 188 /// Looks up the library with the [canonicalUri]. |
181 LibraryElement lookupLibrary(Uri canonicalUri); | 189 LibraryElement lookupLibrary(Uri canonicalUri); |
182 } | 190 } |
183 | 191 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 final LibraryDeserializer deserializer; | 303 final LibraryDeserializer deserializer; |
296 | 304 |
297 /// Hooks to inform others about progress done by this loader. | 305 /// Hooks to inform others about progress done by this loader. |
298 // TODO(sigmund): move away from this. | 306 // TODO(sigmund): move away from this. |
299 final LibraryLoaderListener listener; | 307 final LibraryLoaderListener listener; |
300 | 308 |
301 /// Definitions provided via the `-D` command line flags. Used to resolve | 309 /// Definitions provided via the `-D` command line flags. Used to resolve |
302 /// conditional imports. | 310 /// conditional imports. |
303 final Environment environment; | 311 final Environment environment; |
304 | 312 |
313 List<DeferredAction> _deferredActions = <DeferredAction>[]; | |
314 | |
305 final DiagnosticReporter reporter; | 315 final DiagnosticReporter reporter; |
306 | 316 |
307 _LibraryLoaderTask( | 317 _LibraryLoaderTask( |
308 this.uriTranslator, | 318 this.uriTranslator, |
309 this.scriptLoader, | 319 this.scriptLoader, |
310 this.scanner, | 320 this.scanner, |
311 this.deserializer, | 321 this.deserializer, |
312 this.listener, | 322 this.listener, |
313 this.environment, | 323 this.environment, |
314 this.reporter, | 324 this.reporter, |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 CompilationUnitElement createUnitSync(Script script, LibraryElement library) { | 763 CompilationUnitElement createUnitSync(Script script, LibraryElement library) { |
754 CompilationUnitElementX unit = new CompilationUnitElementX(script, library); | 764 CompilationUnitElementX unit = new CompilationUnitElementX(script, library); |
755 reporter.withCurrentElement(unit, () { | 765 reporter.withCurrentElement(unit, () { |
756 scanner.scanUnit(unit); | 766 scanner.scanUnit(unit); |
757 if (unit.partTag == null && !script.isSynthesized) { | 767 if (unit.partTag == null && !script.isSynthesized) { |
758 reporter.reportErrorMessage(unit, MessageKind.MISSING_PART_OF_TAG); | 768 reporter.reportErrorMessage(unit, MessageKind.MISSING_PART_OF_TAG); |
759 } | 769 } |
760 }); | 770 }); |
761 return unit; | 771 return unit; |
762 } | 772 } |
773 | |
774 void registerDeferredAction(DeferredAction action) { | |
775 _deferredActions.add(action); | |
776 } | |
777 | |
778 Iterable<DeferredAction> pullDeferredActions() { | |
779 Iterable<DeferredAction> actions = _deferredActions.toList(); | |
780 _deferredActions.clear(); | |
781 return actions; | |
782 } | |
763 } | 783 } |
764 | 784 |
765 /// A state machine for checking script tags come in the correct order. | 785 /// A state machine for checking script tags come in the correct order. |
766 class TagState { | 786 class TagState { |
767 /// Initial state. | 787 /// Initial state. |
768 static const int NO_TAG_SEEN = 0; | 788 static const int NO_TAG_SEEN = 0; |
769 | 789 |
770 /// Passed to [checkTag] when a library declaration (the syntax "library | 790 /// Passed to [checkTag] when a library declaration (the syntax "library |
771 /// name;") has been seen. Not an actual state. | 791 /// name;") has been seen. Not an actual state. |
772 static const int LIBRARY = 1; | 792 static const int LIBRARY = 1; |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1518 Future onLibrariesLoaded(LoadedLibraries results); | 1538 Future onLibrariesLoaded(LoadedLibraries results); |
1519 | 1539 |
1520 /// Called whenever a library element is created. | 1540 /// Called whenever a library element is created. |
1521 void onLibraryCreated(LibraryElement library); | 1541 void onLibraryCreated(LibraryElement library); |
1522 | 1542 |
1523 /// Called whenever a library is scanned from a script file. | 1543 /// Called whenever a library is scanned from a script file. |
1524 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); | 1544 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); |
1525 } | 1545 } |
1526 | 1546 |
1527 const _reuseLibrarySubtaskName = "Reuse library"; | 1547 const _reuseLibrarySubtaskName = "Reuse library"; |
OLD | NEW |