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

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

Issue 9243011: Implement named constructors and resolving of redirecting constructors and super-initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename field. Created 8 years, 11 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 | frog/leg/emitter.dart » ('j') | frog/leg/resolver.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/elements/elements.dart
diff --git a/frog/leg/elements/elements.dart b/frog/leg/elements/elements.dart
index 9f7f864f28ded716a3632b58bd3d364f8fd87a4d..92531a8c0ff638629d1746ea3e748eb3e34671da 100644
--- a/frog/leg/elements/elements.dart
+++ b/frog/leg/elements/elements.dart
@@ -214,11 +214,12 @@ class FunctionElement extends Element {
Modifiers this.modifiers,
Element enclosing)
: super(name, kind, enclosing);
- FunctionElement.node(FunctionExpression node,
+ FunctionElement.node(SourceString name,
+ FunctionExpression node,
ElementKind kind,
Modifiers this.modifiers,
Element enclosing)
- : super(node.name.asIdentifier().source, kind, enclosing),
+ : super(name, kind, enclosing),
this.node = node;
bool isInstanceMember() {
@@ -297,6 +298,8 @@ class ClassElement extends Element {
Type type;
Type supertype;
Link<Element> members = const EmptyLink<Element>();
+ Map<SourceString, Element> localMembers;
+ Map<SourceString, Element> constructors;
Link<Type> interfaces = const EmptyLink<Type>();
bool isResolved = false;
ClassNode node;
@@ -306,10 +309,18 @@ class ClassElement extends Element {
SynthesizedConstructorElement synthesizedConstructor;
ClassElement(SourceString name, CompilationUnitElement enclosing)
- : super(name, ElementKind.CLASS, enclosing);
+ : localMembers = new Map<SourceString, Element>(),
+ constructors = new Map<SourceString, Element>(),
+ super(name, ElementKind.CLASS, enclosing);
void addMember(Element element) {
members = members.prepend(element);
+ if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR ||
+ element.modifiers.isFactory()) {
+ constructors[element.name] = element;
+ } else {
+ localMembers[element.name] = element;
+ }
}
Type computeType(compiler) {
@@ -327,36 +338,20 @@ class ClassElement extends Element {
return this;
}
- Element lookupLocalElement(SourceString name, bool matches(Element)) {
- // TODO(karlklose): replace with more efficient solution.
- for (Link<Element> link = members;
- link !== null && !link.isEmpty();
- link = link.tail) {
- Element element = link.head;
- if (matches(element)) return element;
- }
- return null;
- }
-
Element lookupLocalMember(SourceString name) {
- bool matches(Element element) {
- return element.name == name
- && element.kind != ElementKind.GENERATIVE_CONSTRUCTOR;
- }
- return lookupLocalElement(name, matches);
+ return localMembers[name];
}
- Element lookupConstructor(SourceString name) {
- bool matches(Element element) {
- return element.name == name
- && (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR
- || element.modifiers.isFactory());
+ Element lookupConstructor(SourceString name, [Element noMatch(Element)]) {
+ Element result = constructors[name];
+ if (result === null && noMatch !== null) {
+ result = noMatch(lookupLocalMember(name));
}
- return lookupLocalElement(name, matches);
+ return result;
}
// TODO(ngeoffray): Implement these.
- bool canHaveDefaultConstructor() => true;
+ bool canHaveDefaultConstructor() => constructors.length == 0;
SynthesizedConstructorElement getSynthesizedConstructor() {
if (synthesizedConstructor === null && canHaveDefaultConstructor()) {
« no previous file with comments | « no previous file | frog/leg/emitter.dart » ('j') | frog/leg/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698