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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 /** | 514 /** |
515 * Imports the library into the [importingLibrary]. | 515 * Imports the library into the [importingLibrary]. |
516 */ | 516 */ |
517 void importLibrary(Compiler compiler, LibraryElement importingLibrary) { | 517 void importLibrary(Compiler compiler, LibraryElement importingLibrary) { |
518 assert(invariant(importingLibrary, | 518 assert(invariant(importingLibrary, |
519 importedLibrary.exportsHandled, | 519 importedLibrary.exportsHandled, |
520 message: 'Exports not handled on $importedLibrary')); | 520 message: 'Exports not handled on $importedLibrary')); |
521 var combinatorFilter = new CombinatorFilter.fromTag(import); | 521 var combinatorFilter = new CombinatorFilter.fromTag(import); |
522 if (import != null && import.prefix != null) { | 522 if (import != null && import.prefix != null) { |
523 SourceString prefix = import.prefix.source; | 523 SourceString prefix = import.prefix.source; |
524 Element e = importingLibrary.find(prefix); | 524 Element existingElement = importingLibrary.find(prefix); |
525 if (e == null) { | 525 PrefixElement prefixElement; |
526 e = new PrefixElementX(prefix, importingLibrary.entryCompilationUnit, | 526 if (existingElement == null || !existingElement.isPrefix()) { |
527 import.getBeginToken()); | 527 prefixElement = new PrefixElementX(prefix, |
528 importingLibrary.addToScope(e, compiler); | 528 importingLibrary.entryCompilationUnit, import.getBeginToken()); |
| 529 } else { |
| 530 prefixElement = existingElement; |
529 } | 531 } |
530 if (!identical(e.kind, ElementKind.PREFIX)) { | 532 importingLibrary.addToScope(prefixElement, compiler); |
531 compiler.withCurrentElement(e, () { | |
532 compiler.reportWarning(e, 'duplicated definition'); | |
533 }); | |
534 compiler.reportFatalError( | |
535 import.prefix, | |
536 MessageKind.GENERIC, {'text': 'Error: Duplicate definition.'}); | |
537 } | |
538 PrefixElement prefixElement = e; | |
539 importedLibrary.forEachExport((Element element) { | 533 importedLibrary.forEachExport((Element element) { |
540 if (combinatorFilter.exclude(element)) return; | 534 if (combinatorFilter.exclude(element)) return; |
541 // TODO(johnniwinther): Clean-up like [checkDuplicateLibraryName]. | 535 prefixElement.addImport(element, import, compiler); |
542 Element existing = | |
543 prefixElement.imported.putIfAbsent(element.name, () => element); | |
544 if (!identical(existing, element)) { | |
545 compiler.withCurrentElement(existing, () { | |
546 compiler.reportWarning(existing, 'duplicated import'); | |
547 }); | |
548 compiler.withCurrentElement(element, () { | |
549 compiler.reportFatalError( | |
550 element, | |
551 MessageKind.GENERIC, {'text': 'Error: Duplicated import.'}); | |
552 }); | |
553 } | |
554 }); | 536 }); |
555 } else { | 537 } else { |
556 importedLibrary.forEachExport((Element element) { | 538 importedLibrary.forEachExport((Element element) { |
557 compiler.withCurrentElement(importingLibrary, () { | 539 compiler.withCurrentElement(importingLibrary, () { |
558 if (combinatorFilter.exclude(element)) return; | 540 if (combinatorFilter.exclude(element)) return; |
559 importingLibrary.addImport(element, import, compiler); | 541 importingLibrary.addImport(element, import, compiler); |
560 }); | 542 }); |
561 }); | 543 }); |
562 } | 544 } |
563 } | 545 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 } | 898 } |
917 | 899 |
918 /** | 900 /** |
919 * Registers all top-level entities of [library] as starting point for the | 901 * Registers all top-level entities of [library] as starting point for the |
920 * fixed-point computation of the import/export scopes. | 902 * fixed-point computation of the import/export scopes. |
921 */ | 903 */ |
922 void registerLibraryExports(LibraryElement library) { | 904 void registerLibraryExports(LibraryElement library) { |
923 nodeMap[library].registerInitialExports(); | 905 nodeMap[library].registerInitialExports(); |
924 } | 906 } |
925 } | 907 } |
OLD | NEW |