Chromium Code Reviews| 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..b0c0a6a8d91d8b64888f0fcef86c80aa33bf82d4 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'; |
| @@ -773,64 +775,113 @@ class LibraryDependencyNode { |
| */ |
| Element addElementToExportScope(Compiler compiler, Element element, |
| 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 = element.name; |
| + exporters[element] = 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; |
| + |
| + Element computeExportedElement(Element newElement, |
| + Element existingElement) { |
| + if (existingElement != null && existingElement != newElement) { |
| + if (existingElement.isErroneous) { |
| + 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.
|
| + reportDuplicateExport(element, exports); |
| + reportDuplicateExportDecl(element, 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 (existingElement.library.isPlatformLibrary && |
| + !newElement.library.isPlatformLibrary) { |
| + // [existingElement] is implicitly hidden. |
| + return createWarnOnUseElement( |
| + MessageKind.HIDDEN_IMPLICIT_EXPORT, |
| + newElement, |
| + existingElement); |
| + } else if (!existingElement.library.isPlatformLibrary && |
| + element.library.isPlatformLibrary) { |
| + // [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(element, exports, reportError: false); |
| + reportDuplicateExportDecl(existingElement, existingExports); |
| + reportDuplicateExportDecl(element, exports); |
| + Element exportedElement = new ErroneousElementX( |
| + MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library); |
| + exporters[exportedElement] = existingExports; |
| + return exportedElement; |
| + } |
| + } |
| + } else { |
| + return element; |
| + } |
| + } |
| + |
| + Element existingElement = exportScope[name]; |
| + Element exportedElement = computeExportedElement(element, existingElement); |
|
karlklose
2014/09/15 09:34:31
Long line.
Johnni Winther
2014/09/16 11:03:31
Done.
|
| + exportScope[name] = exportedElement; |
| + return exportedElement; |
| + }); |
| } |
| /** |