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

Unified Diff: sdk/lib/_internal/compiler/implementation/elements/elements.dart

Issue 11361124: Introduce AmbiguousElement (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 8 years, 1 month 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
Index: sdk/lib/_internal/compiler/implementation/elements/elements.dart
diff --git a/sdk/lib/_internal/compiler/implementation/elements/elements.dart b/sdk/lib/_internal/compiler/implementation/elements/elements.dart
index f03c982a2b942bf88a16a1ad6900ca66275194d7..4d8e4a2430bb789679c8fdb13f0b57e95d798f1a 100644
--- a/sdk/lib/_internal/compiler/implementation/elements/elements.dart
+++ b/sdk/lib/_internal/compiler/implementation/elements/elements.dart
@@ -116,6 +116,8 @@ class ElementKind {
static const ElementKind VOID =
const ElementKind('void', ElementCategory.NONE);
+ static const ElementKind AMBIGUOUS =
+ const ElementKind('ambiguous', ElementCategory.NONE);
static const ElementKind ERROR =
const ElementKind('error', ElementCategory.NONE);
@@ -195,6 +197,9 @@ class Element implements Spannable {
/** See [ErroneousElement] for documentation. */
bool isErroneous() => false;
+ /** See [AmbiguousElement] for documentation. */
+ bool isAmbiguous() => false;
+
/**
* Is [:true:] if this element has a corresponding patch.
*
@@ -422,6 +427,47 @@ class ErroneousFunctionElement extends ErroneousElement
parameterCount(copmiler) => unsupported();
}
+/**
+ * An ambiguous element represent multiple elements accessible by the same name.
+ *
+ * Ambiguous elements are created during handling of import/export scopes. If an
+ * ambiguous element is encountered during resolution a warning/error should be
+ * reported.
+ */
+class AmbiguousElement extends Element {
+ /**
+ * The message to report on resolving this element.
+ */
+ final MessageKind messageKind;
+
+ /**
+ * The message arguments to report on resolving this element.
+ */
+ final List messageArguments;
+
+ /**
+ * The elements that this ambiguous element might refer to.
+ */
+ Link<Element> elements = const Link<Element>();
+
+ AmbiguousElement(MessageKind this.messageKind, List this.messageArguments,
karlklose 2012/11/07 11:41:24 Initializing formals get the type from the field,
Johnni Winther 2012/11/07 13:02:01 Done.
+ Element enclosingElement, Element existingElement, Element newElement)
+ : super(existingElement.name, ElementKind.AMBIGUOUS, enclosingElement) {
+ addAmbiguousElement(existingElement);
+ addAmbiguousElement(newElement);
+ }
+
+ bool isAmbiguous() => true;
+
+ /**
+ * Adds an element as one of the elements that this ambiguous element might
+ * refer to.
+ */
+ void addAmbiguousElement(Element element) {
+ elements = elements.prepend(element);
+ }
+}
+
class ContainerElement extends Element {
Link<Element> localMembers = const Link<Element>();
@@ -660,12 +706,15 @@ class LibraryElement extends ScopeContainerElement {
void addImport(Element element, DiagnosticListener listener) {
Element existing = importScope[element.name];
if (existing != null) {
- if (!existing.isErroneous()) {
- // TODO(johnniwinther): Provide access to both the new and existing
- // elements.
- importScope[element.name] = new ErroneousElement(
- MessageKind.DUPLICATE_IMPORT,
- [element.name], element.name, this);
+ if (!existing.isAmbiguous()) {
+ // TODO(johnniwinther): Provide access to the import tags from which
+ // the elements came.
+ importScope[element.name] = new AmbiguousElement(
+ MessageKind.DUPLICATE_IMPORT, [element.name],
+ this, existing, element);
karlklose 2012/11/07 11:41:24 Try fitting this and existing on the previous line
Johnni Winther 2012/11/07 13:02:01 Done.
+ } else {
+ AmbiguousElement ambiguous = existing;
+ ambiguous.addAmbiguousElement(element);
}
} else {
importScope[element.name] = element;

Powered by Google App Engine
This is Rietveld 408576698