Chromium Code Reviews| Index: lib/compiler/implementation/elements/elements.dart |
| diff --git a/lib/compiler/implementation/elements/elements.dart b/lib/compiler/implementation/elements/elements.dart |
| index 55ad5dd436df0d6b1c0695a72221d430c99cc7e1..18c83f4cc42860280b6a6ea24b51af89fab85794 100644 |
| --- a/lib/compiler/implementation/elements/elements.dart |
| +++ b/lib/compiler/implementation/elements/elements.dart |
| @@ -108,7 +108,6 @@ class Element implements Hashable { |
| final Element enclosingElement; |
| Link<Node> metadata = const EmptyLink<Node>(); |
| - |
| Element(this.name, this.kind, this.enclosingElement) { |
| assert(getLibrary() !== null); |
| } |
| @@ -137,8 +136,6 @@ class Element implements Hashable { |
| enclosing.kind === ElementKind.COMPILATION_UNIT_OVERRIDE) { |
| enclosing = enclosing.enclosingElement; |
| } |
| - // TODO(lrn): Skip any synthetic elements inserted, e.g., |
| - // a compilation unit override. |
| return enclosing !== null && enclosing.isClass(); |
| } |
| bool isInstanceMember() => false; |
| @@ -146,17 +143,7 @@ class Element implements Hashable { |
| bool isGenerativeConstructor() => kind === ElementKind.GENERATIVE_CONSTRUCTOR; |
| bool isGenerativeConstructorBody() => |
| kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY; |
| - bool isCompilationUnit() { |
| - return kind === ElementKind.COMPILATION_UNIT || |
| - kind === ElementKind.LIBRARY || |
| - kind === ElementKind.COMPILATION_UNIT_OVERRIDE; |
| - } |
| - /** |
| - * Provides the compilation unit corresponding to this element. |
| - * Returns non-null for elements where [isCompilationUnit] returns true, |
| - * but may not return the current [Element]. |
| - */ |
| - CompilationUnitElement asCompilationUnit() => null; |
| + bool isCompilationUnit() => kind === ElementKind.COMPILATION_UNIT; |
| bool isClass() => kind === ElementKind.CLASS; |
| bool isPrefix() => kind === ElementKind.PREFIX; |
| bool isVariable() => kind === ElementKind.VARIABLE; |
| @@ -177,7 +164,8 @@ class Element implements Hashable { |
| // elements are null) and is invalid for top level variable declarations for |
| // which the enclosing element is a VariableDeclarations and not a compilation |
| // unit. |
| - bool isTopLevel() => enclosingElement.isCompilationUnit(); |
| + bool isTopLevel() => |
| + enclosingElement !== null && enclosingElement.isCompilationUnit(); |
|
ahe
2012/08/15 10:00:19
I prefer to not use the short-hand function syntax
Lasse Reichstein Nielsen
2012/08/15 11:17:06
Done.
|
| bool isAssignable() { |
| if (modifiers != null && modifiers.isFinal()) return false; |
| @@ -199,13 +187,22 @@ class Element implements Hashable { |
| // the same hash code. Replace this with a simple id in the element? |
| int hashCode() => name === null ? 0 : name.hashCode(); |
| - Script getScript() { |
| - return getCompilationUnit().script; |
| - } |
| - |
| CompilationUnitElement getCompilationUnit() { |
| - if (isCompilationUnit()) return this; |
| - return enclosingElement.getCompilationUnit(); |
| + Element element = this; |
| + while (element !== null && !element.isCompilationUnit()) { |
| + if (element is CompilationUnitOverrideElement) { |
| + return (element as CompilationUnitOverrideElement).compilationUnit; |
|
ahe
2012/08/15 10:00:19
Please don't use the cast operator.
Lasse Reichstein Nielsen
2012/08/15 11:17:06
Done.
|
| + } |
| + if (element.isLibrary()) { |
| + return (element as LibraryElement).entryCompilationUnit; |
|
ahe
2012/08/15 10:00:19
Please don't use the cast operator.
Lasse Reichstein Nielsen
2012/08/15 11:17:06
Done.
|
| + } |
| + if (element is FunctionElement && |
| + (element as FunctionElement).isPatched) { |
|
ahe
2012/08/15 10:00:19
Please don't use cast operator.
Lasse Reichstein Nielsen
2012/08/15 11:17:06
Done.
|
| + element = (element as FunctionElement).patch; |
|
Lasse Reichstein Nielsen
2012/08/15 09:09:12
This is still not sufficient to handle all cases,
ahe
2012/08/15 10:00:19
Please don't use the cast operator.
Lasse Reichstein Nielsen
2012/08/15 11:17:06
Done.
|
| + } |
| + element = element.enclosingElement; |
| + } |
| + return element; |
| } |
| LibraryElement getLibrary() { |
| @@ -223,6 +220,13 @@ class Element implements Hashable { |
| return null; |
| } |
| + Element getEnclosingClassOrCompilationUnit() { |
| + for (Element e = this; e !== null; e = e.enclosingElement) { |
| + if (e.isClass() || e.isCompilationUnit()) return e; |
| + } |
| + return null; |
| + } |
| + |
| Element getEnclosingMember() { |
| for (Element e = this; e !== null; e = e.enclosingElement) { |
| if (e.isMember()) return e; |
| @@ -320,7 +324,7 @@ class ScopeContainerElement extends ContainerElement { |
| return localScope[elementName]; |
| } |
| - void addGetterOrSetter(Element element, |
| + void addGetterOrSetter(FunctionElement element, |
| Element existing, |
| DiagnosticListener listener) { |
| void reportError(Element other) { |
| @@ -348,7 +352,9 @@ class ScopeContainerElement extends ContainerElement { |
| } |
| } |
| } else { |
| - AbstractFieldElement field = new AbstractFieldElement(element.name, this); |
| + Element container = element.getEnclosingClassOrCompilationUnit(); |
| + AbstractFieldElement field = |
| + new AbstractFieldElement(element.name, container); |
| if (element.kind == ElementKind.GETTER) { |
| field.getter = element; |
| } else { |
| @@ -385,10 +391,6 @@ class CompilationUnitOverrideElement extends Element { |
| super(compilationUnit.name, |
| ElementKind.COMPILATION_UNIT_OVERRIDE, |
| enclosing); |
| - |
| - CompilationUnitElement asCompilationUnit() => compilationUnit; |
| - |
| - CompilationUnitElement getCompilationUnit() => compilationUnit; |
| } |
| class LibraryElement extends ScopeContainerElement { |
| @@ -461,8 +463,6 @@ class LibraryElement extends ScopeContainerElement { |
| } |
| } |
| - CompilationUnitElement getCompilationUnit() => entryCompilationUnit; |
| - |
| Scope buildEnclosingScope() => new TopScope(this); |
| } |
| @@ -699,10 +699,12 @@ class AbstractFieldElement extends Element { |
| // compilation units. However, we know that one of them is |
| // non-null and defined in the same compilation unit as the |
| // abstract element. |
| + // TODO(lrn): No we don't know that if the element from the same |
| + // compilation unit is patched. |
|
Lasse Reichstein Nielsen
2012/08/15 09:09:12
The current way to handle patched functions will c
ahe
2012/08/15 10:00:19
Is that coming?
Lasse Reichstein Nielsen
2012/08/15 11:17:06
It's being worked on as a separate change.
|
| // |
| // We need to make sure that the position returned is relative to |
| // the compilation unit of the abstract element. |
| - if (getter !== null |
| + if (getter !== null |
| && getter.getCompilationUnit() === getCompilationUnit()) { |
| return getter.position(); |
| } else { |
| @@ -811,11 +813,6 @@ class FunctionElement extends Element { |
| defaultImplementation = this; |
| } |
| - Script getScript() { |
| - if (patch !== null) return patch.getScript(); |
| - return super.getScript(); |
| - } |
| - |
| bool get isPatched() => patch !== null; |
| /** |