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

Unified Diff: frog/leg/resolver.dart

Issue 9327001: Implement super initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase and update test expectations. Created 8 years, 10 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
Index: frog/leg/resolver.dart
diff --git a/frog/leg/resolver.dart b/frog/leg/resolver.dart
index 6b18f5b04864e327a94a451018f9f2809e84bc6d..4e98612c7f7244e34bf8a0ae33252e4ebd493ded 100644
--- a/frog/leg/resolver.dart
+++ b/frog/leg/resolver.dart
@@ -27,8 +27,13 @@ class TreeElementMapping implements TreeElements {
class ResolverTask extends CompilerTask {
Queue<ClassElement> toResolve;
+ // Caches the elements of analyzed constructors to make them available
+ // for inlining in later tasks.
+ Map<FunctionElement, TreeElements> constructorElements;
+
ResolverTask(Compiler compiler)
- : super(compiler), toResolve = new Queue<ClassElement>();
+ : super(compiler), toResolve = new Queue<ClassElement>(),
+ constructorElements = new Map<FunctionElement, TreeElements>();
String get name() => 'Resolver';
@@ -36,6 +41,7 @@ class ResolverTask extends CompilerTask {
return measure(() {
switch (element.kind) {
case ElementKind.GENERATIVE_CONSTRUCTOR:
+ case ElementKind.GENERATIVE_CONSTRUCTOR_BODY:
ngeoffray 2012/02/07 14:25:59 Why are you adding this one? The generative constr
case ElementKind.FUNCTION:
case ElementKind.GETTER:
case ElementKind.SETTER:
@@ -53,6 +59,10 @@ class ResolverTask extends CompilerTask {
}
TreeElements resolveMethodElement(FunctionElement element) {
+ if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR &&
+ constructorElements[element] !== null) {
+ return constructorElements[element];
+ }
FunctionExpression tree = element.parseNode(compiler);
ResolverVisitor visitor = new ResolverVisitor(compiler, element);
visitor.useElement(tree, element);
@@ -73,6 +83,9 @@ class ResolverTask extends CompilerTask {
newResolvedClasses = newResolvedClasses.prepend(classElement);
}
checkClassHierarchy(newResolvedClasses);
+ if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR) {
+ constructorElements[element] = visitor.mapping;
+ }
return visitor.mapping;
}
@@ -161,26 +174,6 @@ class InitializerResolver {
Link<Node> initializers;
bool hasSuper;
- bool isSuperConstructorCall(Send node) {
- return (node.receiver === null &&
- node.selector.asIdentifier() !== null &&
- node.selector.asIdentifier().isSuper()) ||
- (node.receiver !== null &&
- node.receiver.asIdentifier() !== null &&
- node.receiver.asIdentifier().isSuper() &&
- node.selector.asIdentifier() !== null);
- }
-
- bool isConstructorRedirect(Send node) {
- return (node.receiver === null &&
- node.selector.asIdentifier() !== null &&
- node.selector.asIdentifier().isThis()) ||
- (node.receiver !== null &&
- node.receiver.asIdentifier() !== null &&
- node.receiver.asIdentifier().isThis() &&
- node.selector.asIdentifier() !== null);
- }
-
InitializerResolver(this.visitor, this.constructor)
: initialized = new Map<SourceString, Node>(), hasSuper = false;
@@ -244,7 +237,7 @@ class InitializerResolver {
ClassElement lookupTarget = constructor.enclosingElement;
bool validTarget = true;
- if (isSuperConstructorCall(call)) {
+ if (Initializers.isSuperConstructorCall(call)) {
// Check for invalid initializers.
if (hasSuper) {
error(call, MessageKind.DUPLICATE_SUPER_INITIALIZER);
@@ -256,7 +249,7 @@ class InitializerResolver {
} else {
lookupTarget = lookupTarget.supertype.element;
}
- } else if (isConstructorRedirect(call)) {
+ } else if (Initializers.isConstructorRedirect(call)) {
// Check that there are no other initializers.
if (!initializers.tail.isEmpty()) {
error(call, MessageKind.REDIRECTING_CTOR_HAS_INITIALIZER);

Powered by Google App Engine
This is Rietveld 408576698