Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/library_loader.dart

Issue 564403002: Handle implicitly hidden exports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library dart2js.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart2jslib.dart' 8 import 'dart2jslib.dart'
9 show Compiler, 9 show Compiler,
10 CompilerTask, 10 CompilerTask,
11 MessageKind, 11 MessageKind,
12 Script, 12 Script,
13 invariant; 13 invariant;
14 import 'elements/elements.dart' 14 import 'elements/elements.dart'
15 show CompilationUnitElement, 15 show CompilationUnitElement,
16 Element, 16 Element,
17 LibraryElement, 17 LibraryElement,
18 PrefixElement; 18 PrefixElement;
19 import 'elements/modelx.dart' 19 import 'elements/modelx.dart'
20 show CompilationUnitElementX, 20 show CompilationUnitElementX,
21 DeferredLoaderGetterElementX, 21 DeferredLoaderGetterElementX,
22 ErroneousElementX, 22 ErroneousElementX,
23 LibraryElementX, 23 LibraryElementX,
24 PrefixElementX; 24 PrefixElementX,
25 WarnOnUseElementX,
26 WrappedMessage;
25 import 'helpers/helpers.dart'; // Included for debug helpers. 27 import 'helpers/helpers.dart'; // Included for debug helpers.
26 import 'native_handler.dart' as native; 28 import 'native_handler.dart' as native;
27 import 'tree/tree.dart'; 29 import 'tree/tree.dart';
28 import 'util/util.dart' show Link, LinkBuilder; 30 import 'util/util.dart' show Link, LinkBuilder;
29 31
30 /** 32 /**
31 * [CompilerTask] for loading libraries and setting up the import/export scopes. 33 * [CompilerTask] for loading libraries and setting up the import/export scopes.
32 * 34 *
33 * The library loader uses four different kinds of URIs in different parts of 35 * The library loader uses four different kinds of URIs in different parts of
34 * the loading process. 36 * the loading process.
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 pendingExportMap.clear(); 768 pendingExportMap.clear();
767 return pendingExports; 769 return pendingExports;
768 } 770 }
769 771
770 /** 772 /**
771 * Adds [element] to the export scope for this node. If the [element] name 773 * Adds [element] to the export scope for this node. If the [element] name
772 * is a duplicate, an error element is inserted into the export scope. 774 * is a duplicate, an error element is inserted into the export scope.
773 */ 775 */
774 Element addElementToExportScope(Compiler compiler, Element element, 776 Element addElementToExportScope(Compiler compiler, Element element,
775 Link<Export> exports) { 777 Link<Export> exports) {
776 String name = element.name; 778 return compiler.withCurrentElement(library, () {
779 String name = element.name;
780 exporters[element] = exports;
777 781
778 void reportDuplicateExport(Element duplicate, 782 void reportDuplicateExport(Element duplicate,
779 Link<Export> duplicateExports, 783 Link<Export> duplicateExports,
780 {bool reportError: true}) { 784 {bool reportError: true}) {
781 assert(invariant(library, !duplicateExports.isEmpty, 785 assert(invariant(library, !duplicateExports.isEmpty,
782 message: "No export for $duplicate from ${duplicate.library} " 786 message: "No export for $duplicate from ${duplicate.library} "
783 "in $library.")); 787 "in $library."));
784 compiler.withCurrentElement(library, () { 788 compiler.withCurrentElement(library, () {
785 for (Export export in duplicateExports) { 789 for (Export export in duplicateExports) {
786 if (reportError) { 790 if (reportError) {
787 compiler.reportError(export, 791 compiler.reportError(export,
788 MessageKind.DUPLICATE_EXPORT, {'name': name}); 792 MessageKind.DUPLICATE_EXPORT, {'name': name});
789 reportError = false; 793 reportError = false;
794 } else {
795 compiler.reportInfo(export,
796 MessageKind.DUPLICATE_EXPORT_CONT, {'name': name});
797 }
798 }
799 });
800 }
801
802 void reportDuplicateExportDecl(Element duplicate,
803 Link<Export> duplicateExports) {
804 assert(invariant(library, !duplicateExports.isEmpty,
805 message: "No export for $duplicate from ${duplicate.library} "
806 "in $library."));
807 compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL,
808 {'name': name, 'uriString': duplicateExports.head.uri});
809 }
810
811
812 Element createWarnOnUseElement(MessageKind messageKind,
813 Element hidingElement,
814 Element hiddenElement) {
815 Uri hiddenUri = hiddenElement.library.canonicalUri;
816 Uri hidingUri = hidingElement.library.canonicalUri;
817 Element exportedElement = new WarnOnUseElementX(
818 new WrappedMessage(
819 null, // Report on reference to [hidingElement].
820 messageKind,
821 {'name': name, 'hiddenUri': hiddenUri, 'hidingUri': hidingUri}),
822 new WrappedMessage(
823 compiler.spanFromSpannable(exporters[hiddenElement].head),
824 MessageKind.EXPORTED_HERE,
825 {'name': name,
826 'uri': hiddenUri}),
827 hidingElement.enclosingElement, hidingElement);
828 exporters[exportedElement] = exports;
829 return exportedElement;
830 }
831
832 Element computeExportedElement(Element newElement,
833 Element existingElement) {
834 if (existingElement != null && existingElement != newElement) {
835 if (existingElement.isErroneous) {
836 if (!element.library.isPlatformLibrary) {
karlklose 2014/09/15 09:34:31 Consider to extract boolean variables for these. O
Johnni Winther 2014/09/16 11:03:32 Done.
837 reportDuplicateExport(element, exports);
838 reportDuplicateExportDecl(element, exports);
839 }
840 return existingElement;
841 } else if (existingElement.library == library) {
842 // Do nothing. [existingElement] hides [newElement].
843 return existingElement;
844 } else if (newElement.library == library) {
845 // [newElement] hides [existingElement].
846 return newElement;
790 } else { 847 } else {
791 compiler.reportInfo(export, 848 if (existingElement.library.isPlatformLibrary &&
792 MessageKind.DUPLICATE_EXPORT_CONT, {'name': name}); 849 !newElement.library.isPlatformLibrary) {
850 // [existingElement] is implicitly hidden.
851 return createWarnOnUseElement(
852 MessageKind.HIDDEN_IMPLICIT_EXPORT,
853 newElement,
854 existingElement);
855 } else if (!existingElement.library.isPlatformLibrary &&
856 element.library.isPlatformLibrary) {
857 // [element] is implicitly hidden.
858 return createWarnOnUseElement(
859 MessageKind.HIDDEN_IMPLICIT_EXPORT,
860 existingElement,
861 newElement);
862 } else {
863 // Declared elements hide exported elements.
864 Link<Export> existingExports = exporters[existingElement];
865 reportDuplicateExport(existingElement, existingExports);
866 reportDuplicateExport(element, exports, reportError: false);
867 reportDuplicateExportDecl(existingElement, existingExports);
868 reportDuplicateExportDecl(element, exports);
869 Element exportedElement = new ErroneousElementX(
870 MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library);
871 exporters[exportedElement] = existingExports;
872 return exportedElement;
873 }
793 } 874 }
875 } else {
876 return element;
794 } 877 }
795 }); 878 }
796 }
797 879
798 void reportDuplicateExportDecl(Element duplicate, 880 Element existingElement = exportScope[name];
799 Link<Export> duplicateExports) { 881 Element exportedElement = computeExportedElement(element, existingElement) ;
karlklose 2014/09/15 09:34:31 Long line.
Johnni Winther 2014/09/16 11:03:31 Done.
800 assert(invariant(library, !duplicateExports.isEmpty, 882 exportScope[name] = exportedElement;
801 message: "No export for $duplicate from ${duplicate.library} " 883 return exportedElement;
802 "in $library.")); 884 });
803 compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL,
804 {'name': name, 'uriString': duplicateExports.head.uri});
805 }
806
807 Element existingElement = exportScope[name];
808 if (existingElement != null && existingElement != element) {
809 if (existingElement.isErroneous) {
810 reportDuplicateExport(element, exports);
811 reportDuplicateExportDecl(element, exports);
812 element = existingElement;
813 } else if (existingElement.library == library) {
814 // Do nothing. [existingElement] hides [element].
815 } else if (element.library == library) {
816 // [element] hides [existingElement].
817 exportScope[name] = element;
818 exporters[element] = exports;
819 } else {
820 // Declared elements hide exported elements.
821 Link<Export> existingExports = exporters[existingElement];
822 reportDuplicateExport(existingElement, existingExports);
823 reportDuplicateExport(element, exports, reportError: false);
824 reportDuplicateExportDecl(existingElement, existingExports);
825 reportDuplicateExportDecl(element, exports);
826 element = exportScope[name] = new ErroneousElementX(
827 MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library);
828 }
829 } else {
830 exportScope[name] = element;
831 exporters[element] = exports;
832 }
833 return element;
834 } 885 }
835 886
836 /** 887 /**
837 * Propagates the exported [element] to all library nodes that depend upon 888 * Propagates the exported [element] to all library nodes that depend upon
838 * this node. If the propagation updated any pending exports, [:true:] is 889 * this node. If the propagation updated any pending exports, [:true:] is
839 * returned. 890 * returned.
840 */ 891 */
841 bool propagateElement(Element element) { 892 bool propagateElement(Element element) {
842 bool change = false; 893 bool change = false;
843 for (ExportLink link in dependencies) { 894 for (ExportLink link in dependencies) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 * fixed-point computation of the import/export scopes. 1036 * fixed-point computation of the import/export scopes.
986 */ 1037 */
987 void registerLibraryExports(LibraryElement library) { 1038 void registerLibraryExports(LibraryElement library) {
988 nodeMap[library].registerInitialExports(); 1039 nodeMap[library].registerInitialExports();
989 } 1040 }
990 1041
991 Future processLibraryTags(LibraryElement library) { 1042 Future processLibraryTags(LibraryElement library) {
992 return task.processLibraryTags(this, library); 1043 return task.processLibraryTags(this, library);
993 } 1044 }
994 } 1045 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698