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); |