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

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

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error 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..684ba90b8647ead4c308bca9d4fde54070c6bbda 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.
*
@@ -374,15 +379,13 @@ class Element implements Spannable {
* to check for unresolvable elements instead of
* [: element == null :].
*/
-class ErroneousElement extends Element {
+class ErroneousElement extends Element implements FunctionElement {
final MessageKind messageKind;
final List messageArguments;
- final SourceString targetName;
ErroneousElement(this.messageKind, this.messageArguments,
- this.targetName, Element enclosing)
- : super(const SourceString('erroneous element'),
- ElementKind.ERROR, enclosing);
+ SourceString name, Element enclosing)
+ : super(name, ElementKind.ERROR, enclosing);
isErroneous() => true;
@@ -390,23 +393,7 @@ class ErroneousElement extends Element {
throw 'unsupported operation on erroneous element';
}
- SourceString get name => unsupported();
Link<MetadataAnnotation> get metadata => unsupported();
-
- getLibrary() => enclosingElement.getLibrary();
-
- String toString() {
- String n = targetName.slowToString();
- return '<$n: ${messageKind.message(messageArguments)}>';
- }
-}
-
-class ErroneousFunctionElement extends ErroneousElement
- implements FunctionElement {
- ErroneousFunctionElement(MessageKind messageKind, List messageArguments,
- SourceString targetName, Element enclosing)
- : super(messageKind, messageArguments, targetName, enclosing);
-
get type => unsupported();
get cachedNode => unsupported();
get functionSignature => unsupported();
@@ -420,6 +407,52 @@ class ErroneousFunctionElement extends ErroneousElement
requiredParameterCount(compiler) => unsupported();
optionalParameterCount(compiler) => unsupported();
parameterCount(copmiler) => unsupported();
+
+ get redirectionTarget => this;
+
+ getLibrary() => enclosingElement.getLibrary();
+
+ String toString() {
+ String n = name.slowToString();
+ return '<$n: ${messageKind.message(messageArguments)}>';
+ }
+}
+
+/**
+ * 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 first element that this ambiguous element might refer to.
+ */
+ final Element existingElement;
+
+ /**
+ * The second element that this ambiguous element might refer to.
+ */
+ final Element newElement;
+
+ AmbiguousElement(this.messageKind, this.messageArguments,
+ Element enclosingElement, Element existingElement, Element newElement)
+ : this.existingElement = existingElement,
+ this.newElement = newElement,
+ super(existingElement.name, ElementKind.AMBIGUOUS, enclosingElement);
+
+ bool isAmbiguous() => true;
}
class ContainerElement extends Element {
@@ -660,13 +693,11 @@ 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);
- }
+ // 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);
} else {
importScope[element.name] = element;
}
@@ -1101,10 +1132,14 @@ class FunctionElement extends Element {
FunctionElement origin = null;
/**
- * If this is an interface constructor, [defaultImplementation] will
- * changed by the resolver to point to the default
- * implementation. Otherwise, [:defaultImplementation === this:].
+ * If this is a redirecting factory, [defaultImplementation] will be
+ * changed by the resolver to point to the redirection target. If
+ * this is an interface constructor, [defaultImplementation] will be
+ * changed by the resolver to point to the default implementation.
+ * Otherwise, [:defaultImplementation === this:].
*/
+ // TODO(ahe): Rename this field to redirectionTarget and remove
+ // mention of interface constructors above.
FunctionElement defaultImplementation;
FunctionElement(SourceString name,
@@ -1141,6 +1176,24 @@ class FunctionElement extends Element {
bool get isPatched => patch != null;
bool get isPatch => origin != null;
+ FunctionElement get redirectionTarget {
+ if (this == defaultImplementation) return this;
+ Element target = defaultImplementation;
+ Set<Element> seen = new Set<Element>();
+ seen.add(target);
+ while (!target.isErroneous() && target != target.defaultImplementation) {
+ target = target.defaultImplementation;
+ if (seen.contains(target)) {
+ // TODO(ahe): This is expedient for now, but it should be
+ // checked by the resolver. Keeping http://dartbug.com/3970
+ // open to track this.
+ throw new SpannableAssertionFailure(
+ target, 'redirecting factory leads to cycle');
+ }
+ }
+ return target;
+ }
+
/**
* Applies a patch function to this function. The patch function's body
* is used as replacement when parsing this function's body.
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart2js.dart ('k') | sdk/lib/_internal/compiler/implementation/filenames.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698