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

Unified Diff: frog/leg/ssa/builder.dart

Issue 9378040: Allow self-referencing closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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
« no previous file with comments | « frog/leg/elements/elements.dart ('k') | frog/leg/ssa/closure.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/ssa/builder.dart
diff --git a/frog/leg/ssa/builder.dart b/frog/leg/ssa/builder.dart
index 640a3a344552fce60d753f058f68ace6e37fdd61..936ba72524a5f426e04cd4793217e035eb54762a 100644
--- a/frog/leg/ssa/builder.dart
+++ b/frog/leg/ssa/builder.dart
@@ -216,13 +216,6 @@ class LocalsHandler {
new ClosureTranslator(builder.compiler, builder.elements);
closureData = translator.translate(node);
- if (closureData.thisElement !== null &&
- isAccessedDirectly(closureData.thisElement)) {
- HInstruction thisInstruction = new HThis();
- updateLocal(closureData.thisElement, thisInstruction);
- builder.add(thisInstruction);
- }
-
FunctionParameters params = function.computeParameters(builder.compiler);
params.forEachParameter((Element element) {
HParameterValue parameter = new HParameterValue(element);
@@ -240,6 +233,17 @@ class LocalsHandler {
closureData.freeVariableMapping.forEach((Element from, Element to) {
redirectElement(from, to);
});
+ if (closureData.isClosure()) {
+ // Inside closure redirect references to itself to [:this:].
+ HInstruction thisInstruction = new HThis();
+ builder.add(thisInstruction);
+ updateLocal(closureData.closureElement, thisInstruction);
+ } else if (function.isInstanceMember() ||
+ function.isGenerativeConstructor()) {
+ HInstruction thisInstruction = new HThis();
+ builder.add(thisInstruction);
+ updateLocal(closureData.thisElement, thisInstruction);
+ }
}
/**
@@ -888,16 +892,16 @@ class SsaBuilder implements Visitor {
visitFunctionExpression(FunctionExpression node) {
ClosureData nestedClosureData = closureDataCache[node];
assert(nestedClosureData !== null);
- assert(nestedClosureData.globalizedClosureElement !== null);
- ClassElement globalizedClosureElement =
- nestedClosureData.globalizedClosureElement;
+ assert(nestedClosureData.closureClassElement !== null);
+ ClassElement closureClassElement =
+ nestedClosureData.closureClassElement;
FunctionElement callElement = nestedClosureData.callElement;
compiler.enqueue(new WorkItem.toCodegen(callElement, elements));
- compiler.registerInstantiatedClass(globalizedClosureElement);
- assert(globalizedClosureElement.members.isEmpty());
+ compiler.registerInstantiatedClass(closureClassElement);
+ assert(closureClassElement.members.isEmpty());
List<HInstruction> capturedVariables = <HInstruction>[];
- for (Element member in globalizedClosureElement.backendMembers) {
+ for (Element member in closureClassElement.backendMembers) {
// The backendMembers also contains the call method(s). We are only
// interested in the fields.
if (member.kind == ElementKind.FIELD) {
@@ -907,7 +911,7 @@ class SsaBuilder implements Visitor {
}
}
- push(new HForeignNew(globalizedClosureElement, capturedVariables));
+ push(new HForeignNew(closureClassElement, capturedVariables));
}
visitIdentifier(Identifier node) {
@@ -1403,8 +1407,7 @@ class SsaBuilder implements Visitor {
visit(node.selector);
closureTarget = pop();
} else {
- assert(element.kind === ElementKind.VARIABLE ||
- element.kind === ElementKind.PARAMETER);
+ assert(Elements.isLocal(element));
closureTarget = localsHandler.readLocal(element);
}
var inputs = <HInstruction>[];
« no previous file with comments | « frog/leg/elements/elements.dart ('k') | frog/leg/ssa/closure.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698