Chromium Code Reviews| Index: lib/compiler/implementation/ssa/builder.dart |
| diff --git a/lib/compiler/implementation/ssa/builder.dart b/lib/compiler/implementation/ssa/builder.dart |
| index 0f48c2db6630722f804d14577f59830eeb5c0b69..fe3a9f81a485a6b3b3a7e2072cf4577eafe4545a 100644 |
| --- a/lib/compiler/implementation/ssa/builder.dart |
| +++ b/lib/compiler/implementation/ssa/builder.dart |
| @@ -1605,34 +1605,44 @@ class SsaBuilder implements Visitor { |
| } |
| } |
| - void generateGetter(Send send, Element element) { |
| + HInstruction generateInstanceSendReceiver(Send send) { |
| + assert(Elements.isInstanceSend(send, elements)); |
| + if (send.receiver == null) { |
| + return localsHandler.readThis(); |
| + } |
| + visit(send.receiver); |
| + return pop(); |
| + } |
| + |
| + void generateInstanceGetterWithCompiledReceiver(Send send, |
| + HInstruction receiver) { |
| + assert(Elements.isInstanceSend(send, elements)); |
| + SourceString getterName = send.selector.asIdentifier().source; |
| Selector selector = elements.getSelector(send); |
| + Element staticInterceptor = null; |
| + if (methodInterceptionEnabled) { |
| + staticInterceptor = interceptors.getStaticGetInterceptor(getterName); |
|
Lasse Reichstein Nielsen
2012/04/10 12:31:13
This pattern seems more complicated than necessary
floitsch
2012/04/10 15:51:00
This is a copy/paste from below. I will change it
|
| + } |
| + if (staticInterceptor != null) { |
| + HStatic target = new HStatic(staticInterceptor); |
| + add(target); |
| + List<HInstruction> inputs = <HInstruction>[target, receiver]; |
| + push(new HInvokeInterceptor(selector, getterName, true, inputs)); |
| + } else { |
| + push(new HInvokeDynamicGetter(selector, null, getterName, receiver)); |
| + } |
| + } |
| + |
| + void generateGetter(Send send, Element element) { |
| if (Elements.isStaticOrTopLevelField(element)) { |
| + Selector selector = elements.getSelector(send); |
| push(new HStatic(element)); |
| if (element.kind == ElementKind.GETTER) { |
| push(new HInvokeStatic(selector, <HInstruction>[pop()])); |
| } |
| } else if (Elements.isInstanceSend(send, elements)) { |
| - HInstruction receiver; |
| - if (send.receiver == null) { |
| - receiver = localsHandler.readThis(); |
| - } else { |
| - visit(send.receiver); |
| - receiver = pop(); |
| - } |
| - SourceString getterName = send.selector.asIdentifier().source; |
| - Element staticInterceptor = null; |
| - if (methodInterceptionEnabled) { |
| - staticInterceptor = interceptors.getStaticGetInterceptor(getterName); |
| - } |
| - if (staticInterceptor != null) { |
| - HStatic target = new HStatic(staticInterceptor); |
| - add(target); |
| - List<HInstruction> inputs = <HInstruction>[target, receiver]; |
| - push(new HInvokeInterceptor(selector, getterName, true, inputs)); |
| - } else { |
| - push(new HInvokeDynamicGetter(selector, null, getterName, receiver)); |
| - } |
| + HInstruction receiver = generateInstanceSendReceiver(send); |
| + generateInstanceGetterWithCompiledReceiver(send, receiver); |
| } else if (Elements.isStaticOrTopLevelFunction(element)) { |
| push(new HStatic(element)); |
| compiler.registerGetOfStaticFunction(element); |
| @@ -1641,9 +1651,32 @@ class SsaBuilder implements Visitor { |
| } |
| } |
| - void generateSetter(SendSet send, Element element, HInstruction value) { |
| + void generateInstanceSetterWithCompiledReceiver(Send send, |
| + HInstruction receiver, |
| + HInstruction value) { |
| + assert(Elements.isInstanceSend(send, elements)); |
| + SourceString dartSetterName = send.selector.asIdentifier().source; |
| Selector selector = elements.getSelector(send); |
| + Element staticInterceptor = null; |
| + if (methodInterceptionEnabled) { |
| + staticInterceptor = |
| + interceptors.getStaticSetInterceptor(dartSetterName); |
|
Lasse Reichstein Nielsen
2012/04/10 12:31:13
Check if this fits on one line. If not, perhaps ch
floitsch
2012/04/10 15:51:00
Done.
|
| + } |
| + if (staticInterceptor != null) { |
| + HStatic target = new HStatic(staticInterceptor); |
| + add(target); |
| + List<HInstruction> inputs = <HInstruction>[target, receiver, value]; |
| + add(new HInvokeInterceptor(selector, dartSetterName, false, inputs)); |
| + } else { |
| + add(new HInvokeDynamicSetter(selector, null, dartSetterName, |
| + receiver, value)); |
| + } |
| + stack.add(value); |
| + } |
| + |
| + void generateSetter(SendSet send, Element element, HInstruction value) { |
| if (Elements.isStaticOrTopLevelField(element)) { |
| + Selector selector = elements.getSelector(send); |
| if (element.kind == ElementKind.SETTER) { |
| HStatic target = new HStatic(element); |
| add(target); |
| @@ -1653,29 +1686,8 @@ class SsaBuilder implements Visitor { |
| } |
| stack.add(value); |
| } else if (element === null || Elements.isInstanceField(element)) { |
| - SourceString dartSetterName = send.selector.asIdentifier().source; |
| - HInstruction receiver; |
| - if (send.receiver == null) { |
| - receiver = localsHandler.readThis(); |
| - } else { |
| - visit(send.receiver); |
| - receiver = pop(); |
| - } |
| - Element staticInterceptor = null; |
| - if (methodInterceptionEnabled) { |
| - staticInterceptor = |
| - interceptors.getStaticSetInterceptor(dartSetterName); |
| - } |
| - if (staticInterceptor != null) { |
| - HStatic target = new HStatic(staticInterceptor); |
| - add(target); |
| - List<HInstruction> inputs = <HInstruction>[target, receiver, value]; |
| - add(new HInvokeInterceptor(selector, dartSetterName, false, inputs)); |
| - } else { |
| - add(new HInvokeDynamicSetter(selector, null, dartSetterName, |
| - receiver, value)); |
| - } |
| - stack.add(value); |
| + HInstruction receiver = generateInstanceSendReceiver(send); |
| + generateInstanceSetterWithCompiledReceiver(send, receiver, value); |
| } else { |
| localsHandler.updateLocal(element, value); |
| stack.add(value); |
| @@ -2199,7 +2211,14 @@ class SsaBuilder implements Visitor { |
| Element element = elements[node]; |
| bool isCompoundAssignment = !node.arguments.isEmpty(); |
| bool isPrefix = !node.isPostfix; // Compound assignments are prefix. |
| - generateGetter(node, elements[node.selector]); |
| + |
| + HInstruction receiver; // Only used if the node is an instance send. |
|
Lasse Reichstein Nielsen
2012/04/10 12:31:13
Please initialize to null explicitly.
floitsch
2012/04/10 15:51:00
Done.
|
| + if (Elements.isInstanceSend(node, elements)) { |
| + receiver = generateInstanceSendReceiver(node); |
| + generateInstanceGetterWithCompiledReceiver(node, receiver); |
| + } else { |
| + generateGetter(node, elements[node.selector]); |
| + } |
| HInstruction left = pop(); |
| HInstruction right; |
| if (isCompoundAssignment) { |
| @@ -2211,7 +2230,11 @@ class SsaBuilder implements Visitor { |
| visitBinary(left, op, right); |
| HInstruction operation = pop(); |
| assert(operation !== null); |
| - generateSetter(node, element, operation); |
| + if (Elements.isInstanceSend(node, elements)) { |
| + generateInstanceSetterWithCompiledReceiver(node, receiver, operation); |
|
Lasse Reichstein Nielsen
2012/04/10 12:31:13
Assert that receiver isn't null here.
floitsch
2012/04/10 15:51:00
Done.
|
| + } else { |
| + generateSetter(node, element, operation); |
| + } |
| if (!isPrefix) { |
| pop(); |
| stack.add(left); |