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

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

Issue 9359011: Capture this. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments and fixed bug. 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/ssa/builder.dart
diff --git a/frog/leg/ssa/builder.dart b/frog/leg/ssa/builder.dart
index 354c55fd0718c6242b7711f1f79d72d667f0b6e1..e4456cf7f4a54f13a6358fb2305b182279351200 100644
--- a/frog/leg/ssa/builder.dart
+++ b/frog/leg/ssa/builder.dart
@@ -166,7 +166,6 @@ class LocalsHandler {
// The values of locals that can be directly accessed (without redirections
// to boxes or closure-fields).
Map<Element, HInstruction> directLocals;
- HInstruction thisDefinition;
Map<Element, Element> redirectionMapping;
SsaBuilder builder;
ClosureData closureData;
@@ -184,7 +183,6 @@ class LocalsHandler {
: directLocals = new Map<Element, HInstruction>.from(other.directLocals),
redirectionMapping = other.redirectionMapping,
builder = other.builder,
- thisDefinition = other.thisDefinition,
closureData = other.closureData;
void startFunction(FunctionElement function,
@@ -195,8 +193,9 @@ class LocalsHandler {
closureData = translator.translate(node);
if (function.isInstanceMember()) {
- thisDefinition = new HThis();
- builder.add(thisDefinition);
+ HInstruction thisInstruction = new HThis();
+ updateLocal(closureData.thisElement, thisInstruction);
+ builder.add(thisInstruction);
}
FunctionParameters params = function.computeParameters(builder.compiler);
@@ -306,7 +305,7 @@ class LocalsHandler {
return directLocals[element];
} else if (isStoredInClosureField(element)) {
Element redirect = redirectionMapping[element];
- // We must not use the [LocalsHandler.thisDefinition] since that could
+ // We must not use the [LocalsHandler.readThis()] since that could
// point to a captured this which would be stored in a closure-field
// itself.
HInstruction receiver = new HThis();
@@ -334,22 +333,20 @@ class LocalsHandler {
}
}
+ HInstruction readThis() {
+ return readLocal(closureData.thisElement);
+ }
+
/**
* Sets the [element] to [value]. If the element is boxed or stored in a
* closure then the method generates code to set the value.
*/
void updateLocal(Element element, HInstruction value) {
- // TODO(floitsch): replace the following if with an assert.
- if (element is !VariableElement) {
- builder.compiler.internalError("expected a variable",
- node: element.parseNode(builder.compiler));
- }
-
if (isAccessedDirectly(element)) {
directLocals[element] = value;
} else if (isStoredInClosureField(element)) {
Element redirect = redirectionMapping[element];
- // We must not use the [LocalsHandler.thisDefinition] since that could
+ // We must not use the [LocalsHandler.readThis()] since that could
// point to a captured this which would be stored in a closure-field
// itself.
HInstruction receiver = new HThis();
@@ -771,10 +768,7 @@ class SsaBuilder implements Visitor {
visitIdentifier(Identifier node) {
if (node.isThis()) {
- if (localsHandler.thisDefinition === null) {
- compiler.unimplemented("Ssa.visitIdentifier.", node: node);
- }
- stack.add(localsHandler.thisDefinition);
+ stack.add(localsHandler.readThis());
} else {
compiler.internalError("SsaBuilder.visitIdentifier on non-this",
node: node);
@@ -998,10 +992,7 @@ class SsaBuilder implements Visitor {
} else if (element === null || Elements.isInstanceField(element)) {
HInstruction receiver;
if (send.receiver == null) {
- receiver = localsHandler.thisDefinition;
- if (receiver === null) {
- compiler.unimplemented("SsaBuilder.generateGetter.", node: send);
- }
+ receiver = localsHandler.readThis();
} else {
visit(send.receiver);
receiver = pop();
@@ -1041,10 +1032,7 @@ class SsaBuilder implements Visitor {
SourceString dartSetterName = send.selector.asIdentifier().source;
HInstruction receiver;
if (send.receiver == null) {
- receiver = localsHandler.thisDefinition;
- if (receiver === null) {
- compiler.unimplemented("Ssa.generateSetter.", node: send);
- }
+ receiver = localsHandler.readThis();
} else {
visit(send.receiver);
receiver = pop();
@@ -1236,10 +1224,7 @@ class SsaBuilder implements Visitor {
}
if (node.receiver === null) {
- HThis receiver = localsHandler.thisDefinition;
- if (receiver === null) {
- compiler.unimplemented("Ssa.visitDynamicSend.", node: node);
- }
+ HThis receiver = localsHandler.readThis();
inputs.add(receiver);
} else {
visit(node.receiver);
@@ -1324,11 +1309,7 @@ class SsaBuilder implements Visitor {
Selector selector = elements.getSelector(node);
Element element = elements[node];
HStatic target = new HStatic(element);
- HThis context = localsHandler.thisDefinition;
- if (context === null) {
- compiler.unimplemented("Ssa.visitSuperSend without thisDefinition.",
- node: node);
- }
+ HThis context = localsHandler.readThis();
add(target);
var inputs = <HInstruction>[target, context];
addStaticSendArgumentsToList(node, element, inputs);

Powered by Google App Engine
This is Rietveld 408576698