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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * [CompilerTask] for loading libraries and setting up the import/export scopes. | 8 * [CompilerTask] for loading libraries and setting up the import/export scopes. |
9 */ | 9 */ |
10 abstract class LibraryLoader extends CompilerTask { | 10 abstract class LibraryLoader extends CompilerTask { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 final Map<String, LibraryElement> libraryNames = | 131 final Map<String, LibraryElement> libraryNames = |
132 new LinkedHashMap<String, LibraryElement>(); | 132 new LinkedHashMap<String, LibraryElement>(); |
133 | 133 |
134 LibraryDependencyHandler currentHandler; | 134 LibraryDependencyHandler currentHandler; |
135 | 135 |
136 LibraryElement loadLibrary(Uri uri, Node node, Uri canonicalUri) { | 136 LibraryElement loadLibrary(Uri uri, Node node, Uri canonicalUri) { |
137 return measure(() { | 137 return measure(() { |
138 assert(currentHandler == null); | 138 assert(currentHandler == null); |
139 currentHandler = new LibraryDependencyHandler(compiler); | 139 currentHandler = new LibraryDependencyHandler(compiler); |
140 LibraryElement library = | 140 LibraryElement library = |
141 createLibrary(currentHandler, uri, node, canonicalUri); | 141 createLibrary(currentHandler, null, uri, node, canonicalUri); |
ngeoffray
2013/01/16 15:40:57
Why is that null here?
Johnni Winther
2013/01/21 09:27:54
The importing uri. Since this is a load from the o
| |
142 currentHandler.computeExports(); | 142 currentHandler.computeExports(); |
143 currentHandler = null; | 143 currentHandler = null; |
144 return library; | 144 return library; |
145 }); | 145 }); |
146 } | 146 } |
147 | 147 |
148 /** | 148 /** |
149 * Processes the library tags in [library]. | 149 * Processes the library tags in [library]. |
150 * | 150 * |
151 * The imported/exported libraries are loaded and processed recursively but | 151 * The imported/exported libraries are loaded and processed recursively but |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 } | 238 } |
239 | 239 |
240 bool isDartCore(Uri uri) => uri.scheme == "dart" && uri.path == "core"; | 240 bool isDartCore(Uri uri) => uri.scheme == "dart" && uri.path == "core"; |
241 | 241 |
242 /** | 242 /** |
243 * Lazily loads and returns the [LibraryElement] for the dart:core library. | 243 * Lazily loads and returns the [LibraryElement] for the dart:core library. |
244 */ | 244 */ |
245 LibraryElement loadCoreLibrary(LibraryDependencyHandler handler) { | 245 LibraryElement loadCoreLibrary(LibraryDependencyHandler handler) { |
246 if (compiler.coreLibrary == null) { | 246 if (compiler.coreLibrary == null) { |
247 Uri coreUri = new Uri.fromComponents(scheme: 'dart', path: 'core'); | 247 Uri coreUri = new Uri.fromComponents(scheme: 'dart', path: 'core'); |
248 compiler.coreLibrary = createLibrary(handler, coreUri, null, coreUri); | 248 compiler.coreLibrary |
249 = createLibrary(handler, null, coreUri, null, coreUri); | |
ngeoffray
2013/01/16 15:40:57
ditto
Johnni Winther
2013/01/21 09:27:54
The import is synthetic and we need no special acc
| |
249 } | 250 } |
250 return compiler.coreLibrary; | 251 return compiler.coreLibrary; |
251 } | 252 } |
252 | 253 |
253 void patchDartLibrary(LibraryDependencyHandler handler, | 254 void patchDartLibrary(LibraryDependencyHandler handler, |
254 LibraryElement library, String dartLibraryPath) { | 255 LibraryElement library, String dartLibraryPath) { |
255 if (library.isPatched) return; | 256 if (library.isPatched) return; |
256 Uri patchUri = compiler.resolvePatchUri(dartLibraryPath); | 257 Uri patchUri = compiler.resolvePatchUri(dartLibraryPath); |
257 if (patchUri != null) { | 258 if (patchUri != null) { |
258 compiler.patchParser.patchLibrary(handler, patchUri, library); | 259 compiler.patchParser.patchLibrary(handler, patchUri, library); |
(...skipping 28 matching lines...) Expand all Loading... | |
287 } | 288 } |
288 | 289 |
289 /** | 290 /** |
290 * Handle an import/export tag by loading the referenced library and | 291 * Handle an import/export tag by loading the referenced library and |
291 * registering its dependency in [handler] for the computation of the import/ | 292 * registering its dependency in [handler] for the computation of the import/ |
292 * export scope. | 293 * export scope. |
293 */ | 294 */ |
294 void registerLibraryFromTag(LibraryDependencyHandler handler, | 295 void registerLibraryFromTag(LibraryDependencyHandler handler, |
295 LibraryElement library, | 296 LibraryElement library, |
296 LibraryDependency tag) { | 297 LibraryDependency tag) { |
298 Uri importingUri = library.uri; | |
297 Uri base = library.entryCompilationUnit.script.uri; | 299 Uri base = library.entryCompilationUnit.script.uri; |
298 Uri resolved = base.resolve(tag.uri.dartString.slowToString()); | 300 Uri resolved = base.resolve(tag.uri.dartString.slowToString()); |
299 LibraryElement loadedLibrary = | 301 LibraryElement loadedLibrary = |
300 createLibrary(handler, resolved, tag.uri, resolved); | 302 createLibrary(handler, importingUri, resolved, tag.uri, resolved); |
301 handler.registerDependency(library, tag, loadedLibrary); | 303 handler.registerDependency(library, tag, loadedLibrary); |
302 | 304 |
303 if (!loadedLibrary.hasLibraryName()) { | 305 if (!loadedLibrary.hasLibraryName()) { |
304 compiler.withCurrentElement(library, () { | 306 compiler.withCurrentElement(library, () { |
305 compiler.reportError(tag == null ? null : tag.uri, | 307 compiler.reportError(tag == null ? null : tag.uri, |
306 'no library name found in ${loadedLibrary.uri}'); | 308 'no library name found in ${loadedLibrary.uri}'); |
307 }); | 309 }); |
308 } | 310 } |
309 } | 311 } |
310 | 312 |
311 /** | 313 /** |
312 * Create (or reuse) a library element for the library located at [uri]. | 314 * Create (or reuse) a library element for the library located at [scriptUri]. |
313 * If a new library is created, the [handler] is notified. | 315 * If a new library is created, the [handler] is notified. |
314 */ | 316 */ |
315 LibraryElement createLibrary(LibraryDependencyHandler handler, | 317 LibraryElement createLibrary(LibraryDependencyHandler handler, |
316 Uri uri, Node node, Uri canonicalUri) { | 318 Uri importingUri, |
319 Uri scriptUri, Node node, Uri canonicalUri) { | |
317 bool newLibrary = false; | 320 bool newLibrary = false; |
321 Uri uri = compiler.resolveScriptUri(importingUri, scriptUri, node); | |
322 if (uri == null) return null; | |
318 LibraryElement createLibrary() { | 323 LibraryElement createLibrary() { |
319 newLibrary = true; | 324 newLibrary = true; |
320 Script script = compiler.readScript(uri, node); | 325 Script script = compiler.readScript(uri, node); |
321 LibraryElement element = new LibraryElementX(script, canonicalUri); | 326 LibraryElement element = new LibraryElementX(script, canonicalUri); |
322 handler.registerNewLibrary(element); | 327 handler.registerNewLibrary(element); |
323 native.maybeEnableNative(compiler, element, uri); | 328 native.maybeEnableNative(compiler, element); |
324 return element; | 329 return element; |
325 } | 330 } |
326 LibraryElement library; | 331 LibraryElement library; |
327 if (canonicalUri == null) { | 332 if (canonicalUri == null) { |
328 library = createLibrary(); | 333 library = createLibrary(); |
329 } else { | 334 } else { |
330 library = compiler.libraries.putIfAbsent(canonicalUri.toString(), | 335 library = compiler.libraries.putIfAbsent(canonicalUri.toString(), |
331 createLibrary); | 336 createLibrary); |
332 } | 337 } |
333 if (newLibrary) { | 338 if (newLibrary) { |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 } | 718 } |
714 | 719 |
715 /** | 720 /** |
716 * Registers all top-level entities of [library] as starting point for the | 721 * Registers all top-level entities of [library] as starting point for the |
717 * fixed-point computation of the import/export scopes. | 722 * fixed-point computation of the import/export scopes. |
718 */ | 723 */ |
719 void registerLibraryExports(LibraryElement library) { | 724 void registerLibraryExports(LibraryElement library) { |
720 nodeMap[library].registerInitialExports(); | 725 nodeMap[library].registerInitialExports(); |
721 } | 726 } |
722 } | 727 } |
OLD | NEW |