Chromium Code Reviews| Index: dart/frog/leg/elements/elements.dart |
| diff --git a/dart/frog/leg/elements/elements.dart b/dart/frog/leg/elements/elements.dart |
| index 2a2312e9caf25df8c6cf6814257b9cf5aeba313a..12197ece4f7043990f419f11fd710b947b774767 100644 |
| --- a/dart/frog/leg/elements/elements.dart |
| +++ b/dart/frog/leg/elements/elements.dart |
| @@ -92,11 +92,11 @@ class Element implements Hashable { |
| Modifiers get modifiers() => null; |
| Node parseNode(DiagnosticListener listener) { |
| - listener.cancel("Internal Error: Element.parseNode"); |
| + listener.cancel("Internal Error: $this.parseNode", token: position()); |
| } |
| Type computeType(Compiler compiler) { |
| - compiler.internalError("Element.computeType."); |
| + compiler.internalError("$this.computeType.", token: position()); |
| } |
| bool isFunction() => kind === ElementKind.FUNCTION; |
| @@ -125,6 +125,13 @@ class Element implements Hashable { |
| Token position() => null; |
| + Token findMyName(Token token) { |
| + for (Token t = token; t !== EOF_TOKEN; t = t.next) { |
| + if (t.value == name) return t; |
| + } |
| + return token; |
| + } |
| + |
| const Element(this.name, this.kind, this.enclosingElement); |
| // TODO(kasperl): This is a very bad hash code for the element and |
| @@ -260,7 +267,7 @@ class LibraryElement extends CompilationUnitElement { |
| } else { |
| Element existing = elements.putIfAbsent(element.name, () => element); |
| if (existing !== element) { |
| - listener.cancel('duplicate definition', token: element.position()); |
| + listener.cancel('duplicate definition $element', token: element.position()); |
|
ngeoffray
2012/03/10 22:36:51
line too long
ngeoffray
2012/03/10 22:36:51
definition 'of' ?
ahe
2012/03/11 13:01:50
Done.
ahe
2012/03/11 13:01:50
Debug code.
|
| listener.cancel('existing definition', token: existing.position()); |
| } |
| } |
| @@ -270,12 +277,6 @@ class LibraryElement extends CompilationUnitElement { |
| return elements[name]; |
| } |
| - Element lookupLocalMember(SourceString name) { |
| - Element element = find(name); |
| - if (element === null) return null; |
| - return (this === element.getLibrary()) ? element : null; |
| - } |
| - |
| void forEachExport(f(Element element)) { |
| elements.forEach((SourceString _, Element e) { |
| if (this === e.getLibrary() |
| @@ -288,16 +289,15 @@ class LibraryElement extends CompilationUnitElement { |
| } |
| class PrefixElement extends Element { |
| - final LiteralString prefix; |
| - final LibraryElement library; |
| + Map<SourceString, Element> imported; |
| + |
| + PrefixElement(SourceString prefix, Element enclosing) |
| + : imported = new Map<SourceString, Element>(), |
| + super(prefix, ElementKind.PREFIX, enclosing); |
| - PrefixElement(LiteralString prefix, |
| - LibraryElement this.library, |
| - Element enclosing) |
| - : this.prefix = prefix, |
| - super(prefix.dartString.source, ElementKind.PREFIX, enclosing); |
| + lookupLocalMember(SourceString name) => imported[name]; |
| - lookupLocalMember(SourceString name) => library.lookupLocalMember(name); |
| + Type computeType(Compiler compiler) => compiler.types.dynamicType; |
| } |
| class TypedefElement extends Element { |
| @@ -346,12 +346,7 @@ class VariableElement extends Element { |
| return isMember() && !modifiers.isStatic(); |
| } |
| - Token position() { |
| - // TODO(ahe): Record the token corresponding to name instead of |
| - // returning different values at different points in time. |
| - return (cachedNode !== null) |
| - ? cachedNode.getBeginToken() : variables.position(); |
| - } |
| + Token position() => findMyName(variables.position()); |
|
ngeoffray
2012/03/10 22:36:51
Why don't you check cachedNode first before going
ahe
2012/03/10 23:07:18
Wouldn't be correct for function typed parameters.
ngeoffray
2012/03/10 23:11:27
Could you please add that as a comment?
ahe
2012/03/11 13:01:50
Done.
|
| } |
| // This element represents a list of variable or field declaration. |
| @@ -417,6 +412,14 @@ class AbstractFieldElement extends Element { |
| Node parseNode(DiagnosticListener listener) { |
| throw "internal error: AbstractFieldElement has no node"; |
| } |
| + |
| + position() { |
| + if (getter !== null && getter.enclosingElement === enclosingElement) { |
|
ngeoffray
2012/03/10 22:36:51
I don't understand the second check.
ahe
2012/03/10 23:07:18
I'll add a comment explaining this.
The getter an
ngeoffray
2012/03/10 23:11:27
I see, thanks for the comment!
|
| + return getter.position(); |
| + } else { |
| + return setter.position(); |
|
ngeoffray
2012/03/10 22:36:51
setter could be null
ahe
2012/03/10 23:07:18
No. See my comment above.
|
| + } |
| + } |
| } |
| /** DEPRECATED. */ |
| @@ -431,8 +434,9 @@ Type getType(TypeAnnotation typeAnnotation, |
| } |
| Identifier identifier = typeAnnotation.typeName.asIdentifier(); |
| if (identifier === null) { |
| - compiler.cancel('library prefixes not handled', |
| - node: typeAnnotation.typeName); |
| + compiler.reportWarning(typeAnnotation.typeName, |
| + 'library prefixes not handled'); |
| + return compiler.types.dynamicType; |
| } |
| SourceString name = identifier.source; |
| Element element = library.find(name); |