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; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 * The distinction between readable URI and resource URI is necessary to ensure | 124 * The distinction between readable URI and resource URI is necessary to ensure |
125 * that these imports | 125 * that these imports |
126 * | 126 * |
127 * import 'package:foo.dart' as a; | 127 * import 'package:foo.dart' as a; |
128 * import 'packages/foo.dart' as b; | 128 * import 'packages/foo.dart' as b; |
129 * | 129 * |
130 * do _not_ resolve to the same library when the package root URI happens to | 130 * do _not_ resolve to the same library when the package root URI happens to |
131 * point to the 'packages' folder. | 131 * point to the 'packages' folder. |
132 * | 132 * |
133 */ | 133 */ |
134 abstract class LibraryLoaderTask implements CompilerTask { | 134 abstract class LibraryLoaderTask implements LibraryProvider, CompilerTask { |
135 factory LibraryLoaderTask( | 135 factory LibraryLoaderTask( |
136 ResolvedUriTranslator uriTranslator, | 136 ResolvedUriTranslator uriTranslator, |
137 ScriptLoader scriptLoader, | 137 ScriptLoader scriptLoader, |
138 ElementScanner scriptScanner, | 138 ElementScanner scriptScanner, |
139 LibraryDeserializer deserializer, | 139 LibraryDeserializer deserializer, |
140 LibraryLoaderListener listener, | 140 LibraryLoaderListener listener, |
141 Environment environment, | 141 Environment environment, |
142 DiagnosticReporter reporter, | 142 DiagnosticReporter reporter, |
143 Measurer measurer) = _LibraryLoaderTask; | 143 Measurer measurer) = _LibraryLoaderTask; |
144 | 144 |
145 /// Returns all libraries that have been loaded. | 145 /// Returns all libraries that have been loaded. |
146 Iterable<LibraryElement> get libraries; | 146 Iterable<LibraryElement> get libraries; |
147 | 147 |
148 /// Looks up the library with the [canonicalUri]. | |
149 LibraryElement lookupLibrary(Uri canonicalUri); | |
150 | |
151 /// Loads the library specified by the [resolvedUri] and returns its | 148 /// Loads the library specified by the [resolvedUri] and returns its |
152 /// [LibraryElement]. | 149 /// [LibraryElement]. |
153 /// | 150 /// |
154 /// If the library is not already loaded, the method creates the | 151 /// If the library is not already loaded, the method creates the |
155 /// [LibraryElement] for the library and computes the import/export scope, | 152 /// [LibraryElement] for the library and computes the import/export scope, |
156 /// loading and computing the import/export scopes of all required libraries | 153 /// loading and computing the import/export scopes of all required libraries |
157 /// in the process. The method handles cyclic dependency between libraries. | 154 /// in the process. The method handles cyclic dependency between libraries. |
158 /// | 155 /// |
159 /// If [skipFileWithPartOfTag] is `true`, `null` is returned if the | 156 /// If [skipFileWithPartOfTag] is `true`, `null` is returned if the |
160 /// compilation unit for [resolvedUri] contains a `part of` tag. This is only | 157 /// compilation unit for [resolvedUri] contains a `part of` tag. This is only |
161 /// used for analysis through [Compiler.analyzeUri]. | 158 /// used for analysis through [Compiler.analyzeUri]. |
162 Future<LibraryElement> loadLibrary(Uri resolvedUri, | 159 Future<LibraryElement> loadLibrary(Uri resolvedUri, |
163 {bool skipFileWithPartOfTag: false}); | 160 {bool skipFileWithPartOfTag: false}); |
164 | 161 |
165 /// Reset the library loader task to prepare for compilation. If provided, | 162 /// Reset the library loader task to prepare for compilation. If provided, |
166 /// libraries matching [reuseLibrary] are reused. | 163 /// libraries matching [reuseLibrary] are reused. |
167 /// | 164 /// |
168 /// This method is used for incremental compilation. | 165 /// This method is used for incremental compilation. |
169 void reset({bool reuseLibrary(LibraryElement library)}); | 166 void reset({bool reuseLibrary(LibraryElement library)}); |
170 | 167 |
171 /// Asynchronous version of [reset]. | 168 /// Asynchronous version of [reset]. |
172 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); | 169 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); |
173 | 170 |
174 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list | 171 /// Similar to [resetAsync] but [reuseLibrary] maps all libraries to a list |
175 /// of libraries that can be reused. | 172 /// of libraries that can be reused. |
176 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries); | 173 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries); |
177 } | 174 } |
178 | 175 |
| 176 /// Interface for an entity that provide libraries. For instance from normal |
| 177 /// library loading or from deserialization. |
| 178 // TODO(johnniwinther): Use this to integrate deserialized libraries better. |
| 179 abstract class LibraryProvider { |
| 180 /// Looks up the library with the [canonicalUri]. |
| 181 LibraryElement lookupLibrary(Uri canonicalUri); |
| 182 } |
| 183 |
179 /// Handle for creating synthesized/patch libraries during library loading. | 184 /// Handle for creating synthesized/patch libraries during library loading. |
180 abstract class LibraryLoader { | 185 abstract class LibraryLoader { |
181 /// This method must be called when a new synthesized/patch library has been | 186 /// This method must be called when a new synthesized/patch library has been |
182 /// created to ensure that [library] will part of library dependency graph | 187 /// created to ensure that [library] will part of library dependency graph |
183 /// used for computing import/export scopes. | 188 /// used for computing import/export scopes. |
184 void registerNewLibrary(LibraryElement library); | 189 void registerNewLibrary(LibraryElement library); |
185 | 190 |
186 /// This method must be called when a new synthesized/patch library has been | 191 /// This method must be called when a new synthesized/patch library has been |
187 /// scanned in order to process the library tags in [library] and thus handle | 192 /// scanned in order to process the library tags in [library] and thus handle |
188 /// imports/exports/parts in the synthesized/patch library. | 193 /// imports/exports/parts in the synthesized/patch library. |
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 Future onLibrariesLoaded(LoadedLibraries results); | 1512 Future onLibrariesLoaded(LoadedLibraries results); |
1508 | 1513 |
1509 /// Called whenever a library element is created. | 1514 /// Called whenever a library element is created. |
1510 void onLibraryCreated(LibraryElement library); | 1515 void onLibraryCreated(LibraryElement library); |
1511 | 1516 |
1512 /// Called whenever a library is scanned from a script file. | 1517 /// Called whenever a library is scanned from a script file. |
1513 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); | 1518 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); |
1514 } | 1519 } |
1515 | 1520 |
1516 const _reuseLibrarySubtaskName = "Reuse library"; | 1521 const _reuseLibrarySubtaskName = "Reuse library"; |
OLD | NEW |