| 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 * The library loader uses four different kinds of URIs in different parts of | 10 * The library loader uses four different kinds of URIs in different parts of |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 /** | 358 /** |
| 359 * Handle a part tag in the scope of [library]. The [resolvedUri] given is | 359 * Handle a part tag in the scope of [library]. The [resolvedUri] given is |
| 360 * used as is, any URI resolution should be done beforehand. | 360 * used as is, any URI resolution should be done beforehand. |
| 361 */ | 361 */ |
| 362 void scanPart(Part part, Uri resolvedUri, LibraryElement library) { | 362 void scanPart(Part part, Uri resolvedUri, LibraryElement library) { |
| 363 if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri); | 363 if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri); |
| 364 Uri readableUri = compiler.translateResolvedUri(library, resolvedUri, part); | 364 Uri readableUri = compiler.translateResolvedUri(library, resolvedUri, part); |
| 365 if (readableUri == null) return; |
| 365 Script sourceScript = compiler.readScript(readableUri, part); | 366 Script sourceScript = compiler.readScript(readableUri, part); |
| 367 if (sourceScript == null) return; |
| 366 CompilationUnitElement unit = | 368 CompilationUnitElement unit = |
| 367 new CompilationUnitElementX(sourceScript, library); | 369 new CompilationUnitElementX(sourceScript, library); |
| 368 compiler.withCurrentElement(unit, () { | 370 compiler.withCurrentElement(unit, () { |
| 369 compiler.scanner.scan(unit); | 371 compiler.scanner.scan(unit); |
| 370 if (unit.partTag == null) { | 372 if (unit.partTag == null) { |
| 371 compiler.reportError(unit, MessageKind.MISSING_PART_OF_TAG); | 373 compiler.reportError(unit, MessageKind.MISSING_PART_OF_TAG); |
| 372 } | 374 } |
| 373 }); | 375 }); |
| 374 } | 376 } |
| 375 | 377 |
| 376 /** | 378 /** |
| 377 * Handle an import/export tag by loading the referenced library and | 379 * Handle an import/export tag by loading the referenced library and |
| 378 * registering its dependency in [handler] for the computation of the import/ | 380 * registering its dependency in [handler] for the computation of the import/ |
| 379 * export scope. | 381 * export scope. |
| 380 */ | 382 */ |
| 381 void registerLibraryFromTag(LibraryDependencyHandler handler, | 383 void registerLibraryFromTag(LibraryDependencyHandler handler, |
| 382 LibraryElement library, | 384 LibraryElement library, |
| 383 LibraryDependency tag) { | 385 LibraryDependency tag) { |
| 384 Uri base = library.entryCompilationUnit.script.uri; | 386 Uri base = library.entryCompilationUnit.script.uri; |
| 385 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); | 387 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); |
| 386 LibraryElement loadedLibrary = | 388 LibraryElement loadedLibrary = |
| 387 createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri); | 389 createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri); |
| 390 if (loadedLibrary == null) return; |
| 388 handler.registerDependency(library, tag, loadedLibrary); | 391 handler.registerDependency(library, tag, loadedLibrary); |
| 389 | 392 |
| 390 if (!loadedLibrary.hasLibraryName()) { | 393 if (!loadedLibrary.hasLibraryName()) { |
| 391 compiler.withCurrentElement(library, () { | 394 compiler.withCurrentElement(library, () { |
| 392 compiler.reportFatalError( | 395 compiler.reportFatalError( |
| 393 tag == null ? null : tag.uri, | 396 tag == null ? null : tag.uri, |
| 394 MessageKind.GENERIC, | 397 MessageKind.GENERIC, |
| 395 {'text': | 398 {'text': |
| 396 'Error: No library name found in ${loadedLibrary.canonicalUri}.'}); | 399 'Error: No library name found in ${loadedLibrary.canonicalUri}.'}); |
| 397 }); | 400 }); |
| 398 } | 401 } |
| 399 } | 402 } |
| 400 | 403 |
| 401 /** | 404 /** |
| 402 * Create (or reuse) a library element for the library specified by the | 405 * Create (or reuse) a library element for the library specified by the |
| 403 * [resolvedUri]. | 406 * [resolvedUri]. |
| 404 * | 407 * |
| 405 * If a new library is created, the [handler] is notified. | 408 * If a new library is created, the [handler] is notified. |
| 406 */ | 409 */ |
| 407 // TODO(johnniwinther): Remove [canonicalUri] and make [resolvedUri] the | 410 // TODO(johnniwinther): Remove [canonicalUri] and make [resolvedUri] the |
| 408 // canonical uri when [Compiler.scanBuiltinLibrary] is removed. | 411 // canonical uri when [Compiler.scanBuiltinLibrary] is removed. |
| 409 LibraryElement createLibrary(LibraryDependencyHandler handler, | 412 LibraryElement createLibrary(LibraryDependencyHandler handler, |
| 410 LibraryElement importingLibrary, | 413 LibraryElement importingLibrary, |
| 411 Uri resolvedUri, Node node, Uri canonicalUri) { | 414 Uri resolvedUri, Node node, Uri canonicalUri) { |
| 412 bool newLibrary = false; | 415 // TODO(johnniwinther): Create erroneous library elements for missing |
| 416 // libraries. |
| 413 Uri readableUri = | 417 Uri readableUri = |
| 414 compiler.translateResolvedUri(importingLibrary, resolvedUri, node); | 418 compiler.translateResolvedUri(importingLibrary, resolvedUri, node); |
| 415 if (readableUri == null) return null; | 419 if (readableUri == null) return null; |
| 416 LibraryElement createLibrary() { | 420 LibraryElement library; |
| 417 newLibrary = true; | 421 if (canonicalUri != null) { |
| 422 library = compiler.libraries[canonicalUri.toString()]; |
| 423 } |
| 424 if (library == null) { |
| 418 Script script = compiler.readScript(readableUri, node); | 425 Script script = compiler.readScript(readableUri, node); |
| 419 LibraryElement element = new LibraryElementX(script, canonicalUri); | 426 if (script == null) return null; |
| 420 handler.registerNewLibrary(element); | 427 |
| 421 native.maybeEnableNative(compiler, element); | 428 library = new LibraryElementX(script, canonicalUri); |
| 422 return element; | 429 handler.registerNewLibrary(library); |
| 423 } | 430 native.maybeEnableNative(compiler, library); |
| 424 LibraryElement library; | 431 if (canonicalUri != null) { |
| 425 if (canonicalUri == null) { | 432 compiler.libraries[canonicalUri.toString()] = library; |
| 426 library = createLibrary(); | 433 } |
| 427 } else { | 434 |
| 428 library = compiler.libraries.putIfAbsent(canonicalUri.toString(), | |
| 429 createLibrary); | |
| 430 } | |
| 431 if (newLibrary) { | |
| 432 compiler.withCurrentElement(library, () { | 435 compiler.withCurrentElement(library, () { |
| 433 compiler.scanner.scanLibrary(library); | 436 compiler.scanner.scanLibrary(library); |
| 434 processLibraryTags(handler, library); | 437 processLibraryTags(handler, library); |
| 435 handler.registerLibraryExports(library); | 438 handler.registerLibraryExports(library); |
| 436 compiler.onLibraryScanned(library, resolvedUri); | 439 compiler.onLibraryScanned(library, resolvedUri); |
| 437 }); | 440 }); |
| 438 } | 441 } |
| 439 return library; | 442 return library; |
| 440 } | 443 } |
| 441 | 444 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 } | 832 } |
| 830 | 833 |
| 831 /** | 834 /** |
| 832 * Registers all top-level entities of [library] as starting point for the | 835 * Registers all top-level entities of [library] as starting point for the |
| 833 * fixed-point computation of the import/export scopes. | 836 * fixed-point computation of the import/export scopes. |
| 834 */ | 837 */ |
| 835 void registerLibraryExports(LibraryElement library) { | 838 void registerLibraryExports(LibraryElement library) { |
| 836 nodeMap[library].registerInitialExports(); | 839 nodeMap[library].registerInitialExports(); |
| 837 } | 840 } |
| 838 } | 841 } |
| OLD | NEW |