Chromium Code Reviews| 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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 pendingExportMap.clear(); | 707 pendingExportMap.clear(); |
| 708 return pendingExports; | 708 return pendingExports; |
| 709 } | 709 } |
| 710 | 710 |
| 711 /** | 711 /** |
| 712 * Adds [element] to the export scope for this node. If the [element] name | 712 * Adds [element] to the export scope for this node. If the [element] name |
| 713 * is a duplicate, an error element is inserted into the export scope. | 713 * is a duplicate, an error element is inserted into the export scope. |
| 714 */ | 714 */ |
| 715 Element addElementToExportScope(Compiler compiler, Element element, | 715 Element addElementToExportScope(Compiler compiler, Element element, |
| 716 Link<Export> exports) { | 716 Link<Export> exports) { |
| 717 | |
| 718 SourceString name = element.name; | 717 SourceString name = element.name; |
| 719 | 718 |
| 720 void reportDuplicateExport(Element duplicate, | 719 void reportDuplicateExport(Element duplicate, |
| 721 Link<Export> duplicateExports, | 720 Link<Export> duplicateExports, |
| 722 {bool reportError: true}) { | 721 {bool reportError: true}) { |
| 722 assert(invariant(library, !duplicateExports.isEmpty, | |
| 723 message: "No export for $duplicate from ${duplicate.getLibrary()} " | |
| 724 "in $library.")); | |
| 723 compiler.withCurrentElement(library, () { | 725 compiler.withCurrentElement(library, () { |
| 724 for (Export export in duplicateExports) { | 726 for (Export export in duplicateExports) { |
| 725 if (reportError) { | 727 if (reportError) { |
| 726 compiler.reportError(export, | 728 compiler.reportError(export, |
| 727 MessageKind.DUPLICATE_EXPORT, {'name': name}); | 729 MessageKind.DUPLICATE_EXPORT, {'name': name}); |
| 728 reportError = false; | 730 reportError = false; |
| 729 } else { | 731 } else { |
| 730 compiler.reportInfo(export, | 732 compiler.reportInfo(export, |
| 731 MessageKind.DUPLICATE_EXPORT_CONT, {'name': name}); | 733 MessageKind.DUPLICATE_EXPORT_CONT, {'name': name}); |
| 732 } | 734 } |
| 733 } | 735 } |
| 734 }); | 736 }); |
| 735 } | 737 } |
| 736 | 738 |
| 737 void reportDuplicateExportDecl(Element duplicate, | 739 void reportDuplicateExportDecl(Element duplicate, |
| 738 Link<Export> duplicateExports) { | 740 Link<Export> duplicateExports) { |
| 741 assert(invariant(library, !duplicateExports.isEmpty, | |
| 742 message: "No export for $duplicate from ${duplicate.getLibrary()} " | |
| 743 "in $library.")); | |
| 739 compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL, | 744 compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL, |
| 740 {'name': name, 'uriString': duplicateExports.head.uri}); | 745 {'name': name, 'uriString': duplicateExports.head.uri}); |
| 741 } | 746 } |
| 742 | 747 |
| 743 Element existingElement = exportScope[name]; | 748 Element existingElement = exportScope[name]; |
| 744 if (existingElement != null && existingElement != element) { | 749 if (existingElement != null && existingElement != element) { |
| 745 if (existingElement.isErroneous()) { | 750 if (existingElement.isErroneous()) { |
| 746 reportDuplicateExport(element, exports); | 751 reportDuplicateExport(element, exports); |
| 747 reportDuplicateExportDecl(element, exports); | 752 reportDuplicateExportDecl(element, exports); |
| 748 element = existingElement; | 753 element = existingElement; |
| 749 } else if (existingElement.getLibrary() != library) { | 754 } else if (existingElement.getLibrary() == library) { |
| 755 // Do nothing. [existingElement] hides [element]. | |
| 756 } else if (element.getLibrary() == library) { | |
| 757 // Do nothing. [element] hides [existingElement]. | |
|
karlklose
2013/10/03 13:35:19
Remove "Do nothing."
Johnni Winther
2013/10/03 13:38:51
Done.
| |
| 758 exportScope[name] = element; | |
| 759 exporters[element] = exports; | |
| 760 } else { | |
| 750 // Declared elements hide exported elements. | 761 // Declared elements hide exported elements. |
| 751 Link<Export> existingExports = exporters[existingElement]; | 762 Link<Export> existingExports = exporters[existingElement]; |
| 752 reportDuplicateExport(existingElement, existingExports); | 763 reportDuplicateExport(existingElement, existingExports); |
| 753 reportDuplicateExport(element, exports, reportError: false); | 764 reportDuplicateExport(element, exports, reportError: false); |
| 754 reportDuplicateExportDecl(existingElement, existingExports); | 765 reportDuplicateExportDecl(existingElement, existingExports); |
| 755 reportDuplicateExportDecl(element, exports); | 766 reportDuplicateExportDecl(element, exports); |
| 756 element = exportScope[name] = new ErroneousElementX( | 767 element = exportScope[name] = new ErroneousElementX( |
| 757 MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library); | 768 MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library); |
| 758 } | 769 } |
| 759 } else { | 770 } else { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 905 } | 916 } |
| 906 | 917 |
| 907 /** | 918 /** |
| 908 * Registers all top-level entities of [library] as starting point for the | 919 * Registers all top-level entities of [library] as starting point for the |
| 909 * fixed-point computation of the import/export scopes. | 920 * fixed-point computation of the import/export scopes. |
| 910 */ | 921 */ |
| 911 void registerLibraryExports(LibraryElement library) { | 922 void registerLibraryExports(LibraryElement library) { |
| 912 nodeMap[library].registerInitialExports(); | 923 nodeMap[library].registerInitialExports(); |
| 913 } | 924 } |
| 914 } | 925 } |
| OLD | NEW |