| 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 bool wasDiagnosticEmitted = false; | 373 bool wasDiagnosticEmitted = false; |
| 372 compiler.withCurrentElement(library, () { | 374 compiler.withCurrentElement(library, () { |
| 373 wasDiagnosticEmitted = | 375 wasDiagnosticEmitted = |
| 374 compiler.onDeprecatedFeature(part, 'missing part-of tag'); | 376 compiler.onDeprecatedFeature(part, 'missing part-of tag'); |
| 375 }); | 377 }); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 388 * registering its dependency in [handler] for the computation of the import/ | 390 * registering its dependency in [handler] for the computation of the import/ |
| 389 * export scope. | 391 * export scope. |
| 390 */ | 392 */ |
| 391 void registerLibraryFromTag(LibraryDependencyHandler handler, | 393 void registerLibraryFromTag(LibraryDependencyHandler handler, |
| 392 LibraryElement library, | 394 LibraryElement library, |
| 393 LibraryDependency tag) { | 395 LibraryDependency tag) { |
| 394 Uri base = library.entryCompilationUnit.script.uri; | 396 Uri base = library.entryCompilationUnit.script.uri; |
| 395 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); | 397 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); |
| 396 LibraryElement loadedLibrary = | 398 LibraryElement loadedLibrary = |
| 397 createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri); | 399 createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri); |
| 400 if (loadedLibrary == null) return; |
| 398 handler.registerDependency(library, tag, loadedLibrary); | 401 handler.registerDependency(library, tag, loadedLibrary); |
| 399 | 402 |
| 400 if (!loadedLibrary.hasLibraryName()) { | 403 if (!loadedLibrary.hasLibraryName()) { |
| 401 compiler.withCurrentElement(library, () { | 404 compiler.withCurrentElement(library, () { |
| 402 compiler.reportFatalError( | 405 compiler.reportFatalError( |
| 403 tag == null ? null : tag.uri, | 406 tag == null ? null : tag.uri, |
| 404 MessageKind.GENERIC, | 407 MessageKind.GENERIC, |
| 405 {'text': | 408 {'text': |
| 406 'Error: No library name found in ${loadedLibrary.canonicalUri}.'}); | 409 'Error: No library name found in ${loadedLibrary.canonicalUri}.'}); |
| 407 }); | 410 }); |
| 408 } | 411 } |
| 409 } | 412 } |
| 410 | 413 |
| 411 /** | 414 /** |
| 412 * Create (or reuse) a library element for the library specified by the | 415 * Create (or reuse) a library element for the library specified by the |
| 413 * [resolvedUri]. | 416 * [resolvedUri]. |
| 414 * | 417 * |
| 415 * If a new library is created, the [handler] is notified. | 418 * If a new library is created, the [handler] is notified. |
| 416 */ | 419 */ |
| 417 // TODO(johnniwinther): Remove [canonicalUri] and make [resolvedUri] the | 420 // TODO(johnniwinther): Remove [canonicalUri] and make [resolvedUri] the |
| 418 // canonical uri when [Compiler.scanBuiltinLibrary] is removed. | 421 // canonical uri when [Compiler.scanBuiltinLibrary] is removed. |
| 419 LibraryElement createLibrary(LibraryDependencyHandler handler, | 422 LibraryElement createLibrary(LibraryDependencyHandler handler, |
| 420 LibraryElement importingLibrary, | 423 LibraryElement importingLibrary, |
| 421 Uri resolvedUri, Node node, Uri canonicalUri) { | 424 Uri resolvedUri, Node node, Uri canonicalUri) { |
| 422 bool newLibrary = false; | 425 // TODO(johnniwinther): Create erroneous library elements for missing |
| 426 // libraries. |
| 423 Uri readableUri = | 427 Uri readableUri = |
| 424 compiler.translateResolvedUri(importingLibrary, resolvedUri, node); | 428 compiler.translateResolvedUri(importingLibrary, resolvedUri, node); |
| 425 if (readableUri == null) return null; | 429 if (readableUri == null) return null; |
| 426 LibraryElement createLibrary() { | 430 LibraryElement library; |
| 427 newLibrary = true; | 431 if (canonicalUri != null) { |
| 432 library = compiler.libraries[canonicalUri.toString()]; |
| 433 } |
| 434 if (library == null) { |
| 428 Script script = compiler.readScript(readableUri, node); | 435 Script script = compiler.readScript(readableUri, node); |
| 429 LibraryElement element = new LibraryElementX(script, canonicalUri); | 436 if (script == null) return null; |
| 430 handler.registerNewLibrary(element); | 437 |
| 431 native.maybeEnableNative(compiler, element); | 438 library = new LibraryElementX(script, canonicalUri); |
| 432 return element; | 439 handler.registerNewLibrary(library); |
| 433 } | 440 native.maybeEnableNative(compiler, library); |
| 434 LibraryElement library; | 441 if (canonicalUri != null) { |
| 435 if (canonicalUri == null) { | 442 compiler.libraries[canonicalUri.toString()] = library; |
| 436 library = createLibrary(); | 443 } |
| 437 } else { | 444 |
| 438 library = compiler.libraries.putIfAbsent(canonicalUri.toString(), | |
| 439 createLibrary); | |
| 440 } | |
| 441 if (newLibrary) { | |
| 442 compiler.withCurrentElement(library, () { | 445 compiler.withCurrentElement(library, () { |
| 443 compiler.scanner.scanLibrary(library); | 446 compiler.scanner.scanLibrary(library); |
| 444 processLibraryTags(handler, library); | 447 processLibraryTags(handler, library); |
| 445 handler.registerLibraryExports(library); | 448 handler.registerLibraryExports(library); |
| 446 compiler.onLibraryScanned(library, resolvedUri); | 449 compiler.onLibraryScanned(library, resolvedUri); |
| 447 }); | 450 }); |
| 448 } | 451 } |
| 449 return library; | 452 return library; |
| 450 } | 453 } |
| 451 | 454 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 } | 842 } |
| 840 | 843 |
| 841 /** | 844 /** |
| 842 * Registers all top-level entities of [library] as starting point for the | 845 * Registers all top-level entities of [library] as starting point for the |
| 843 * fixed-point computation of the import/export scopes. | 846 * fixed-point computation of the import/export scopes. |
| 844 */ | 847 */ |
| 845 void registerLibraryExports(LibraryElement library) { | 848 void registerLibraryExports(LibraryElement library) { |
| 846 nodeMap[library].registerInitialExports(); | 849 nodeMap[library].registerInitialExports(); |
| 847 } | 850 } |
| 848 } | 851 } |
| OLD | NEW |