| 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 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 */ | 544 */ |
| 545 void importLibrary(Compiler compiler, LibraryElement importingLibrary) { | 545 void importLibrary(Compiler compiler, LibraryElement importingLibrary) { |
| 546 assert(invariant(importingLibrary, | 546 assert(invariant(importingLibrary, |
| 547 importedLibrary.exportsHandled, | 547 importedLibrary.exportsHandled, |
| 548 message: 'Exports not handled on $importedLibrary')); | 548 message: 'Exports not handled on $importedLibrary')); |
| 549 var combinatorFilter = new CombinatorFilter.fromTag(import); | 549 var combinatorFilter = new CombinatorFilter.fromTag(import); |
| 550 if (import != null && import.prefix != null) { | 550 if (import != null && import.prefix != null) { |
| 551 String prefix = import.prefix.source; | 551 String prefix = import.prefix.source; |
| 552 Element existingElement = importingLibrary.find(prefix); | 552 Element existingElement = importingLibrary.find(prefix); |
| 553 PrefixElement prefixElement; | 553 PrefixElement prefixElement; |
| 554 if (existingElement == null || !existingElement.isPrefix()) { | 554 if (existingElement == null || !existingElement.isPrefix) { |
| 555 prefixElement = new PrefixElementX(prefix, | 555 prefixElement = new PrefixElementX(prefix, |
| 556 importingLibrary.entryCompilationUnit, import.getBeginToken()); | 556 importingLibrary.entryCompilationUnit, import.getBeginToken()); |
| 557 } else { | 557 } else { |
| 558 prefixElement = existingElement; | 558 prefixElement = existingElement; |
| 559 } | 559 } |
| 560 importingLibrary.addToScope(prefixElement, compiler); | 560 importingLibrary.addToScope(prefixElement, compiler); |
| 561 importedLibrary.forEachExport((Element element) { | 561 importedLibrary.forEachExport((Element element) { |
| 562 if (combinatorFilter.exclude(element)) return; | 562 if (combinatorFilter.exclude(element)) return; |
| 563 prefixElement.addImport(element, import, compiler); | 563 prefixElement.addImport(element, import, compiler); |
| 564 }); | 564 }); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 * is a duplicate, an error element is inserted into the export scope. | 732 * is a duplicate, an error element is inserted into the export scope. |
| 733 */ | 733 */ |
| 734 Element addElementToExportScope(Compiler compiler, Element element, | 734 Element addElementToExportScope(Compiler compiler, Element element, |
| 735 Link<Export> exports) { | 735 Link<Export> exports) { |
| 736 String name = element.name; | 736 String name = element.name; |
| 737 | 737 |
| 738 void reportDuplicateExport(Element duplicate, | 738 void reportDuplicateExport(Element duplicate, |
| 739 Link<Export> duplicateExports, | 739 Link<Export> duplicateExports, |
| 740 {bool reportError: true}) { | 740 {bool reportError: true}) { |
| 741 assert(invariant(library, !duplicateExports.isEmpty, | 741 assert(invariant(library, !duplicateExports.isEmpty, |
| 742 message: "No export for $duplicate from ${duplicate.getLibrary()} " | 742 message: "No export for $duplicate from ${duplicate.library} " |
| 743 "in $library.")); | 743 "in $library.")); |
| 744 compiler.withCurrentElement(library, () { | 744 compiler.withCurrentElement(library, () { |
| 745 for (Export export in duplicateExports) { | 745 for (Export export in duplicateExports) { |
| 746 if (reportError) { | 746 if (reportError) { |
| 747 compiler.reportError(export, | 747 compiler.reportError(export, |
| 748 MessageKind.DUPLICATE_EXPORT, {'name': name}); | 748 MessageKind.DUPLICATE_EXPORT, {'name': name}); |
| 749 reportError = false; | 749 reportError = false; |
| 750 } else { | 750 } else { |
| 751 compiler.reportInfo(export, | 751 compiler.reportInfo(export, |
| 752 MessageKind.DUPLICATE_EXPORT_CONT, {'name': name}); | 752 MessageKind.DUPLICATE_EXPORT_CONT, {'name': name}); |
| 753 } | 753 } |
| 754 } | 754 } |
| 755 }); | 755 }); |
| 756 } | 756 } |
| 757 | 757 |
| 758 void reportDuplicateExportDecl(Element duplicate, | 758 void reportDuplicateExportDecl(Element duplicate, |
| 759 Link<Export> duplicateExports) { | 759 Link<Export> duplicateExports) { |
| 760 assert(invariant(library, !duplicateExports.isEmpty, | 760 assert(invariant(library, !duplicateExports.isEmpty, |
| 761 message: "No export for $duplicate from ${duplicate.getLibrary()} " | 761 message: "No export for $duplicate from ${duplicate.library} " |
| 762 "in $library.")); | 762 "in $library.")); |
| 763 compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL, | 763 compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL, |
| 764 {'name': name, 'uriString': duplicateExports.head.uri}); | 764 {'name': name, 'uriString': duplicateExports.head.uri}); |
| 765 } | 765 } |
| 766 | 766 |
| 767 Element existingElement = exportScope[name]; | 767 Element existingElement = exportScope[name]; |
| 768 if (existingElement != null && existingElement != element) { | 768 if (existingElement != null && existingElement != element) { |
| 769 if (existingElement.isErroneous()) { | 769 if (existingElement.isErroneous) { |
| 770 reportDuplicateExport(element, exports); | 770 reportDuplicateExport(element, exports); |
| 771 reportDuplicateExportDecl(element, exports); | 771 reportDuplicateExportDecl(element, exports); |
| 772 element = existingElement; | 772 element = existingElement; |
| 773 } else if (existingElement.getLibrary() == library) { | 773 } else if (existingElement.library == library) { |
| 774 // Do nothing. [existingElement] hides [element]. | 774 // Do nothing. [existingElement] hides [element]. |
| 775 } else if (element.getLibrary() == library) { | 775 } else if (element.library == library) { |
| 776 // [element] hides [existingElement]. | 776 // [element] hides [existingElement]. |
| 777 exportScope[name] = element; | 777 exportScope[name] = element; |
| 778 exporters[element] = exports; | 778 exporters[element] = exports; |
| 779 } else { | 779 } else { |
| 780 // Declared elements hide exported elements. | 780 // Declared elements hide exported elements. |
| 781 Link<Export> existingExports = exporters[existingElement]; | 781 Link<Export> existingExports = exporters[existingElement]; |
| 782 reportDuplicateExport(existingElement, existingExports); | 782 reportDuplicateExport(existingElement, existingExports); |
| 783 reportDuplicateExport(element, exports, reportError: false); | 783 reportDuplicateExport(element, exports, reportError: false); |
| 784 reportDuplicateExportDecl(existingElement, existingExports); | 784 reportDuplicateExportDecl(existingElement, existingExports); |
| 785 reportDuplicateExportDecl(element, exports); | 785 reportDuplicateExportDecl(element, exports); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 } | 935 } |
| 936 | 936 |
| 937 /** | 937 /** |
| 938 * Registers all top-level entities of [library] as starting point for the | 938 * Registers all top-level entities of [library] as starting point for the |
| 939 * fixed-point computation of the import/export scopes. | 939 * fixed-point computation of the import/export scopes. |
| 940 */ | 940 */ |
| 941 void registerLibraryExports(LibraryElement library) { | 941 void registerLibraryExports(LibraryElement library) { |
| 942 nodeMap[library].registerInitialExports(); | 942 nodeMap[library].registerInitialExports(); |
| 943 } | 943 } |
| 944 } | 944 } |
| OLD | NEW |