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

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

Issue 10831154: Make field-get/set work without elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | lib/compiler/implementation/emitter.dart » ('j') | lib/compiler/implementation/emitter.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 a104749521a57a0089f9f97975d1dc8d53b23074..9fb6f4beeabbede6d3847d6afb705b601581f51a 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -872,11 +872,12 @@ class ClassElement extends ContainerElement {
}
Element lookupSuperMember(SourceString memberName) {
+ bool isPrivate = memberName.isPrivate();
for (ClassElement s = superclass; s != null; s = s.superclass) {
+ // Private members from a different library are not visible.
+ if (isPrivate && getLibrary() !== s.getLibrary()) continue;
Element e = s.lookupLocalMember(memberName);
if (e === null) continue;
- // Private members from a different library are not visible.
- if (memberName.isPrivate() && getLibrary() !== e.getLibrary()) continue;
// Static members are not inherited.
if (e.modifiers.isStatic()) continue;
return e;
@@ -895,6 +896,34 @@ class ClassElement extends ContainerElement {
return localMember === null ? lookupSuperMember(memberName) : localMember;
}
+ /**
+ * Returns true if the [fieldMember] is shadowed by another field. The given
+ * [fieldMember] must be a member of this class.
+ *
+ * This method also works if the [fieldMember] is private.
+ */
+ bool isShadowedByField(Element fieldMember) {
+ assert(fieldMember.isField());
+ // Note that we cannot use [lookupMember] or [lookupSuperMember] since it
+ // will not do the right thing for private elements.
+ ClassElement lookupClass = this;
+ LibraryElement memberLibrary = fieldMember.getLibrary();
+ if (fieldMember.name.isPrivate()) {
+ // We find a super class in the same library as the field. This way the
+ // lookupMember will work.
+ while (lookupClass.getLibrary() != memberLibrary) {
+ lookupClass = lookupClass.superclass;
+ }
+ }
+ SourceString fieldName = fieldMember.name;
+ while (true) {
+ Element foundMember = lookupClass.lookupMember(fieldName);
+ if (foundMember == fieldMember) return false;
+ if (foundMember.isField()) return true;
+ lookupClass = (foundMember.enclosingElement as ClassElement).superclass;
+ }
+ }
+
Element lookupConstructor(SourceString className,
[SourceString constructorName =
const SourceString(''),
« no previous file with comments | « no previous file | lib/compiler/implementation/emitter.dart » ('j') | lib/compiler/implementation/emitter.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698