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

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

Issue 10968010: Import scope rules updated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | lib/compiler/implementation/resolver.dart » ('j') | lib/compiler/implementation/resolver.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/elements/elements.dart
diff --git a/lib/compiler/implementation/elements/elements.dart b/lib/compiler/implementation/elements/elements.dart
index 72e3a9abfe799df7f460665595cecc8af2774902..25e51919a4594ae7780dc517a53c31a1832622d5 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -316,10 +316,12 @@ class Element implements Hashable {
* [: element == null :].
*/
class ErroneousElement extends Element {
- final Message errorMessage;
+ final MessageKind messageKind;
+ final List messageArguments;
final SourceString targetName;
- ErroneousElement(this.errorMessage, this.targetName, Element enclosing)
+ ErroneousElement(this.messageKind, this.messageArguments,
+ this.targetName, Element enclosing)
: super(const SourceString('erroneous element'), null, enclosing);
isErroneous() => true;
@@ -337,9 +339,9 @@ class ErroneousElement extends Element {
class ErroneousFunctionElement extends ErroneousElement
implements FunctionElement {
- ErroneousFunctionElement(Message errorMessage, SourceString targetName,
- Element enclosing)
- : super(errorMessage, targetName, enclosing);
+ ErroneousFunctionElement(MessageKind messageKind, List messageArguments,
+ SourceString targetName, Element enclosing)
+ : super(messageKind, messageArguments, targetName, enclosing);
get type => unsupported();
get cachedNode => unsupported();
@@ -486,9 +488,11 @@ class LibraryElement extends ScopeContainerElement {
ScriptTag libraryTag;
bool canUseNative = false;
LibraryElement patch = null;
+ final Map<SourceString, Element> importScope;
Lasse Reichstein Nielsen 2012/09/20 12:21:08 Documentation. What is the meaning of this field?
Johnni Winther 2012/09/21 14:00:05 Comment added.
LibraryElement(Script script, [Uri uri])
: this.uri = ((uri === null) ? script.uri : uri),
+ importScope = new Map<SourceString, Element>(),
super(new SourceString(script.name), ElementKind.LIBRARY, null) {
entryCompilationUnit = new CompilationUnitElement(script, this);
}
@@ -504,11 +508,39 @@ class LibraryElement extends ScopeContainerElement {
tags = tags.prepend(tag);
}
- /** Look up a top-level element in this library. The element could
- * potentially have been imported from another library. Returns
- * null if no such element exist. */
+ /**
+ * Adds [element] to the imported scope of this library.
Lasse Reichstein Nielsen 2012/09/20 12:21:08 "imported scope" -> "import scope". You don't impo
Johnni Winther 2012/09/21 14:00:05 Done.
+ *
+ * If an element by the same name is already in the imported scope, an
+ * [ErroneousElement] will be put in the imported scope, allowing for the
+ * detection of ambiguous uses of imported names.
+ */
+ void addImport(Element element, DiagnosticListener listener) {
+ Element existing = importScope.putIfAbsent(element.name, () => element);
+ if (existing !== element && existing !== null) {
Lasse Reichstein Nielsen 2012/09/20 12:21:08 Adding the same element twice is an error (accordi
Lasse Reichstein Nielsen 2012/09/20 14:03:36 ... actual value, even.
Johnni Winther 2012/09/21 14:00:05 I don't understand. Did you mean '... is not an er
+ 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);
+ }
+ }
+ }
+
+
+ /**
+ * Look up a top-level element in this library. The element could
+ * potentially have been imported from another library. Returns
+ * null if no such element exist and an [ErroneousElement] if multiple
+ * elements have been imported.
+ */
Element find(SourceString elementName) {
- return localScope[elementName];
+ Element result = localScope[elementName];
+ if (result === null) {
+ result = importScope[elementName];
+ }
+ return result;
}
/** Look up a top-level element in this library, but only look for
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | lib/compiler/implementation/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698