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

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

Issue 10837140: Make addGetterOrSetter (now: defineAccessor) not add the abstract field as a member. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleaner validation of member accessors. Created 8 years, 4 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 | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »
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 2e5df0d36118a677c00062441ec2466bd71982b2..86569f03e3e82504ecabf6494bf89d35cca1da8a 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -370,7 +370,7 @@ class ScopeContainerElement extends ContainerElement {
void addToScope(Element element, DiagnosticListener listener) {
if (element.isAccessor()) {
- addGetterOrSetter(element, localScope[element.name], listener);
+ addAccessorToScope(element, localScope[element.name], listener);
} else {
Element existing = localScope.putIfAbsent(element.name, () => element);
if (existing !== element) {
@@ -385,13 +385,26 @@ class ScopeContainerElement extends ContainerElement {
return localScope[elementName];
}
- void addGetterOrSetter(FunctionElement element,
- Element existing,
- DiagnosticListener listener) {
+ /**
+ * Adds a definition for an [accessor] (getter or setter) to a container.
+ * The definition binds to an abstract field that can hold both a getter
+ * and a setter.
+ *
+ * The abstract field is added once, for the first getter or setter, and
+ * reused if the other one is also added.
+ * The abstract field should not be treated as a proper member of the
+ * container, it's simply a way to return two results for one lookup.
+ * That is, the getter or setter does not have the abstract field as enclosing
+ * element, they are enclosed by the class or compilation unit, as is the
+ * abstract field.
+ */
+ void addAccessorToScope(Element accessor,
+ Element existing,
+ DiagnosticListener listener) {
void reportError(Element other) {
// TODO(ahe): Do something similar to Resolver.reportErrorWithContext.
- listener.cancel('duplicate definition of ${element.name.slowToString()}',
- element: element);
+ listener.cancel('duplicate definition of ${accessor.name.slowToString()}',
+ element: accessor);
listener.cancel('existing definition', element: other);
}
@@ -400,28 +413,29 @@ class ScopeContainerElement extends ContainerElement {
reportError(existing);
} else {
AbstractFieldElement field = existing;
- if (element.kind == ElementKind.GETTER) {
- if (field.getter != null && field.getter != element) {
+ if (accessor.isGetter()) {
+ if (field.getter != null && field.getter != accessor) {
reportError(field.getter);
}
- field.getter = element;
+ field.getter = accessor;
} else {
- if (field.setter != null && field.setter != element) {
+ assert(accessor.isSetter());
+ if (field.setter != null && field.setter != accessor) {
reportError(field.setter);
}
- field.setter = element;
+ field.setter = accessor;
}
}
} else {
- Element container = element.getEnclosingClassOrCompilationUnit();
+ Element container = accessor.getEnclosingClassOrCompilationUnit();
AbstractFieldElement field =
- new AbstractFieldElement(element.name, container);
- if (element.kind == ElementKind.GETTER) {
- field.getter = element;
+ new AbstractFieldElement(accessor.name, container);
+ if (accessor.isGetter()) {
+ field.getter = accessor;
} else {
- field.setter = element;
+ field.setter = accessor;
}
- addMember(field, listener);
+ addToScope(field, listener);
}
}
}
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698