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

Unified 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: Updated cf. comments. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/library_loader.dart
diff --git a/sdk/lib/_internal/compiler/implementation/library_loader.dart b/sdk/lib/_internal/compiler/implementation/library_loader.dart
index be7978a95060d748e4fedfb0587f28a116dccf90..f2c876c55b5a3875214cb548feb54d06a4e4b91d 100644
--- a/sdk/lib/_internal/compiler/implementation/library_loader.dart
+++ b/sdk/lib/_internal/compiler/implementation/library_loader.dart
@@ -21,7 +21,9 @@ import 'elements/modelx.dart'
DeferredLoaderGetterElementX,
ErroneousElementX,
LibraryElementX,
- PrefixElementX;
+ PrefixElementX,
+ WarnOnUseElementX,
+ WrappedMessage;
import 'helpers/helpers.dart'; // Included for debug helpers.
import 'native_handler.dart' as native;
import 'tree/tree.dart';
@@ -768,69 +770,119 @@ class LibraryDependencyNode {
}
/**
- * Adds [element] to the export scope for this node. If the [element] name
- * is a duplicate, an error element is inserted into the export scope.
+ * Adds [newElement] to the export scope for this node. If the [newElement]
+ * name is a duplicate, an error element is inserted into the export scope.
*/
- Element addElementToExportScope(Compiler compiler, Element element,
+ Element addElementToExportScope(Compiler compiler, Element newElement,
Link<Export> exports) {
- String name = element.name;
-
- void reportDuplicateExport(Element duplicate,
- Link<Export> duplicateExports,
- {bool reportError: true}) {
- assert(invariant(library, !duplicateExports.isEmpty,
- message: "No export for $duplicate from ${duplicate.library} "
- "in $library."));
- compiler.withCurrentElement(library, () {
- for (Export export in duplicateExports) {
- if (reportError) {
- compiler.reportError(export,
- MessageKind.DUPLICATE_EXPORT, {'name': name});
- reportError = false;
- } else {
- compiler.reportInfo(export,
- MessageKind.DUPLICATE_EXPORT_CONT, {'name': name});
+ return compiler.withCurrentElement(library, () {
+ String name = newElement.name;
+ exporters[newElement] = exports;
+
+ void reportDuplicateExport(Element duplicate,
+ Link<Export> duplicateExports,
+ {bool reportError: true}) {
+ assert(invariant(library, !duplicateExports.isEmpty,
+ message: "No export for $duplicate from ${duplicate.library} "
+ "in $library."));
+ compiler.withCurrentElement(library, () {
+ for (Export export in duplicateExports) {
+ if (reportError) {
+ compiler.reportError(export,
+ MessageKind.DUPLICATE_EXPORT, {'name': name});
+ reportError = false;
+ } else {
+ compiler.reportInfo(export,
+ MessageKind.DUPLICATE_EXPORT_CONT, {'name': name});
+ }
}
- }
- });
- }
+ });
+ }
- void reportDuplicateExportDecl(Element duplicate,
- Link<Export> duplicateExports) {
- assert(invariant(library, !duplicateExports.isEmpty,
- message: "No export for $duplicate from ${duplicate.library} "
- "in $library."));
- compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL,
- {'name': name, 'uriString': duplicateExports.head.uri});
- }
+ void reportDuplicateExportDecl(Element duplicate,
+ Link<Export> duplicateExports) {
+ assert(invariant(library, !duplicateExports.isEmpty,
+ message: "No export for $duplicate from ${duplicate.library} "
+ "in $library."));
+ compiler.reportInfo(duplicate, MessageKind.DUPLICATE_EXPORT_DECL,
+ {'name': name, 'uriString': duplicateExports.head.uri});
+ }
- Element existingElement = exportScope[name];
- if (existingElement != null && existingElement != element) {
- if (existingElement.isErroneous) {
- reportDuplicateExport(element, exports);
- reportDuplicateExportDecl(element, exports);
- element = existingElement;
- } else if (existingElement.library == library) {
- // Do nothing. [existingElement] hides [element].
- } else if (element.library == library) {
- // [element] hides [existingElement].
- exportScope[name] = element;
- exporters[element] = exports;
- } else {
- // Declared elements hide exported elements.
- Link<Export> existingExports = exporters[existingElement];
- reportDuplicateExport(existingElement, existingExports);
- reportDuplicateExport(element, exports, reportError: false);
- reportDuplicateExportDecl(existingElement, existingExports);
- reportDuplicateExportDecl(element, exports);
- element = exportScope[name] = new ErroneousElementX(
- MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library);
+
+ Element createWarnOnUseElement(MessageKind messageKind,
+ Element hidingElement,
+ Element hiddenElement) {
+ Uri hiddenUri = hiddenElement.library.canonicalUri;
+ Uri hidingUri = hidingElement.library.canonicalUri;
+ Element exportedElement = new WarnOnUseElementX(
+ new WrappedMessage(
+ null, // Report on reference to [hidingElement].
+ messageKind,
+ {'name': name, 'hiddenUri': hiddenUri, 'hidingUri': hidingUri}),
+ new WrappedMessage(
+ compiler.spanFromSpannable(exporters[hiddenElement].head),
+ MessageKind.EXPORTED_HERE,
+ {'name': name,
+ 'uri': hiddenUri}),
+ hidingElement.enclosingElement, hidingElement);
+ exporters[exportedElement] = exports;
+ return exportedElement;
}
- } else {
- exportScope[name] = element;
- exporters[element] = exports;
- }
- return element;
+
+ bool fromPlatform(Element e) => e.library.isPlatformLibrary;
+
+ Element computeExportedElement(Element existingElement) {
+ if (existingElement != null && existingElement != newElement) {
+ if (existingElement.isErroneous) {
+ if (!fromPlatform(newElement)) {
+ reportDuplicateExport(newElement, exports);
+ reportDuplicateExportDecl(newElement, exports);
+ }
+ return existingElement;
+ } else if (existingElement.library == library) {
+ // Do nothing. [existingElement] hides [newElement].
+ return existingElement;
+ } else if (newElement.library == library) {
+ // [newElement] hides [existingElement].
+ return newElement;
+ } else {
+ if (fromPlatform(existingElement) &&
+ !fromPlatform(newElement)) {
+ // [existingElement] is implicitly hidden.
+ return createWarnOnUseElement(
+ MessageKind.HIDDEN_IMPLICIT_EXPORT,
+ newElement,
+ existingElement);
+ } else if (!fromPlatform(existingElement) &&
+ fromPlatform(newElement)) {
+ // [element] is implicitly hidden.
+ return createWarnOnUseElement(
+ MessageKind.HIDDEN_IMPLICIT_EXPORT,
+ existingElement,
+ newElement);
+ } else {
+ // Declared elements hide exported elements.
+ Link<Export> existingExports = exporters[existingElement];
+ reportDuplicateExport(existingElement, existingExports);
+ reportDuplicateExport(newElement, exports, reportError: false);
+ reportDuplicateExportDecl(existingElement, existingExports);
+ reportDuplicateExportDecl(newElement, exports);
+ Element exportedElement = new ErroneousElementX(
+ MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library);
+ exporters[exportedElement] = existingExports;
+ return exportedElement;
+ }
+ }
+ } else {
+ return newElement;
+ }
+ }
+
+ Element existingElement = exportScope[name];
+ Element exportedElement = computeExportedElement(existingElement);
+ exportScope[name] = exportedElement;
+ return exportedElement;
+ });
}
/**
« 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