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

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

Issue 10834243: Reduce usage of .enclosingElement to get enclosing class. (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 | « lib/compiler/implementation/dart_backend/backend.dart ('k') | lib/compiler/implementation/enqueue.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 1556604510ef10e1cbcc23df93d4c0ac91e69f10..58d44411abd83516d40d5f554f55dc2b1edeaf92 100644
--- a/lib/compiler/implementation/elements/elements.dart
+++ b/lib/compiler/implementation/elements/elements.dart
@@ -118,9 +118,15 @@ class Element implements Hashable {
}
bool isFunction() => kind === ElementKind.FUNCTION;
+ bool isConstructor() => isFactoryConstructor() || isGenerativeConstructor();
bool isClosure() => false;
- bool isMember() =>
- enclosingElement !== null && enclosingElement.kind === ElementKind.CLASS;
+ bool isMember() {
+ // Check that this element is defined in the scope of a Class.
+ Element enclosing = enclosingElement;
+ // TODO(lrn): Skip any synthetic elements inserted, e.g.,
Anders Johnsen 2012/08/09 08:08:37 Maybe just travel up the tree and see if you hit a
Lasse Reichstein Nielsen 2012/08/09 11:22:09 Alas no. That would make the parameter of a method
+ // a compilation unit override.
+ return enclosing !== null && enclosing.isClass();
+ }
bool isInstanceMember() => false;
bool isFactoryConstructor() => modifiers !== null && modifiers.isFactory();
bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR;
@@ -142,6 +148,7 @@ class Element implements Hashable {
bool isSetter() => kind === ElementKind.SETTER;
bool isAccessor() => isGetter() || isSetter();
bool isForeign() => kind === ElementKind.FOREIGN;
+ bool isLibrary() => kind === ElementKind.LIBRARY;
bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0;
@@ -193,7 +200,7 @@ class Element implements Hashable {
ClassElement getEnclosingClass() {
for (Element e = this; e !== null; e = e.enclosingElement) {
- if (e.kind === ElementKind.CLASS) return e;
+ if (e.isClass()) return e;
}
return null;
}
@@ -206,6 +213,7 @@ class Element implements Hashable {
}
Element getOutermostEnclosingMemberOrTopLevel() {
+ // TODO(lrn): Why is this called "Outermost"?
for (Element e = this; e !== null; e = e.enclosingElement) {
if (e.isMember() || e.isTopLevel()) {
return e;
« no previous file with comments | « lib/compiler/implementation/dart_backend/backend.dart ('k') | lib/compiler/implementation/enqueue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698