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

Unified Diff: dart/frog/leg/elements/elements.dart

Issue 9663047: Repeated prefixes and parser fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased and status file Created 8 years, 9 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 | dart/frog/leg/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..4850bc075138726cbe2bab1ebd806ba234b72312 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
@@ -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,9 @@ 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();
- }
+ // Note: cachedNode.getBeginToken() will not be correct in all
+ // cases, for example, for function typed parameters.
+ Token position() => findMyName(variables.position());
}
// This element represents a list of variable or field declaration.
@@ -417,6 +414,21 @@ class AbstractFieldElement extends Element {
Node parseNode(DiagnosticListener listener) {
throw "internal error: AbstractFieldElement has no node";
}
+
+ position() {
+ // The getter and setter may be defined in two different
+ // compilation units. However, we know that one of them is
+ // non-null and defined in the same compilation unit as the
+ // abstract element.
+ //
+ // We need to make sure that the position returned is relative to
+ // the compilation unit of the abstract element.
+ if (getter !== null && getter.enclosingElement === enclosingElement) {
+ return getter.position();
+ } else {
+ return setter.position();
+ }
+ }
}
/** DEPRECATED. */
@@ -431,8 +443,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);
« no previous file with comments | « no previous file | dart/frog/leg/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698