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

Unified Diff: lib/compiler/implementation/ssa/builder.dart

Issue 9979021: Fix instance compound assignment. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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: 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);
« no previous file with comments | « no previous file | tests/language/language-leg.status » ('j') | tests/language/src/InstanceCompoundAssignmentOperatorTest.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698