You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/08/09 08:05:39 UTC
[1/2] groovy git commit: GROOVY-7542: CompileStatic class generation
bug "register with message: rightShiftUnsigned and arguments X" (testcase
plus rightShift/leftShift - closes #85)
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_4_X a671fafe1 -> 052fee66d
GROOVY-7542: CompileStatic class generation bug "register with message: rightShiftUnsigned and arguments X" (testcase plus rightShift/leftShift - closes #85)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/052fee66
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/052fee66
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/052fee66
Branch: refs/heads/GROOVY_2_4_X
Commit: 052fee66d2b2e21d6b74dcedee82d55274b11398
Parents: 760b0c1
Author: paulk <pa...@asert.com.au>
Authored: Tue Aug 9 17:54:41 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Tue Aug 9 18:05:25 2016 +1000
----------------------------------------------------------------------
.../asm/sc/StaticTypesCallSiteWriter.java | 25 ++++-------------
.../groovy/transform/stc/Groovy7542Bug.groovy | 28 ++++++++++++++++++++
2 files changed, 33 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/052fee66/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 8e38681..334fbc8 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -646,13 +646,8 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
} else if ("power".equals(message)) {
writePowerCall(receiver, arguments, rType, aType);
return true;
- } else if ("mod".equals(message)) {
- writeModCall(receiver, arguments, rType, aType);
- return true;
- }
- else if("rightShiftUnsigned".equals(message))
- {
- writeShiftOperatorCall(receiver, arguments, rType, aType);
+ } else if ("mod".equals(message) || "leftShift".equals(message) || "rightShift".equals(message) || "rightShiftUnsigned".equals(message)) {
+ writeOperatorCall(receiver, arguments, message);
return true;
}
} else if (STRING_TYPE.equals(rType) && "plus".equals(message)) {
@@ -745,23 +740,13 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
operandStack.replace(rType.getComponentType(), m2-m1);
}
- private void writeModCall(Expression receiver, Expression arguments, ClassNode rType, ClassNode aType) {
- prepareSiteAndReceiver(receiver, "mod", false, controller.getCompileStack().isLHS());
- controller.getOperandStack().doGroovyCast(Number_TYPE);
- visitBoxedArgument(arguments);
- controller.getOperandStack().doGroovyCast(Number_TYPE);
- MethodVisitor mv = controller.getMethodVisitor();
- mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", "mod", "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
- controller.getOperandStack().replace(Number_TYPE, 2);
- }
-
- private void writeShiftOperatorCall(Expression receiver, Expression arguments, ClassNode rType, ClassNode aType) {
- prepareSiteAndReceiver(receiver, "rightShiftUnsigned", false, controller.getCompileStack().isLHS());
+ private void writeOperatorCall(Expression receiver, Expression arguments, String operator) {
+ prepareSiteAndReceiver(receiver, operator, false, controller.getCompileStack().isLHS());
controller.getOperandStack().doGroovyCast(Number_TYPE);
visitBoxedArgument(arguments);
controller.getOperandStack().doGroovyCast(Number_TYPE);
MethodVisitor mv = controller.getMethodVisitor();
- mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", "rightShiftUnsigned", "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
+ mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", operator, "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
controller.getOperandStack().replace(Number_TYPE, 2);
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/052fee66/src/test/groovy/transform/stc/Groovy7542Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/Groovy7542Bug.groovy b/src/test/groovy/transform/stc/Groovy7542Bug.groovy
new file mode 100644
index 0000000..18a5740
--- /dev/null
+++ b/src/test/groovy/transform/stc/Groovy7542Bug.groovy
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package groovy.transform.stc
+
+class Groovy7542Bug extends StaticTypeCheckingTestCase {
+ void testShiftOperators() {
+ assert [20].collect { it >> 2 } == [5]
+ assert [20].collect { it >>> 2 } == [5]
+ assert [20].collect { it << 2 } == [80]
+ }
+}
[2/2] groovy git commit: GROOVY-7542: CompileStatic class generation
bug 'register with message: rightShiftUnsigned and arguments X'
Posted by pa...@apache.org.
GROOVY-7542: CompileStatic class generation bug 'register with message: rightShiftUnsigned and arguments X'
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/760b0c1f
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/760b0c1f
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/760b0c1f
Branch: refs/heads/GROOVY_2_4_X
Commit: 760b0c1f8d7f9573a84e1abed5db8dfa7dd88523
Parents: a671faf
Author: antoaravinth <an...@gmail.com>
Authored: Sun Aug 16 18:24:47 2015 +0530
Committer: paulk <pa...@asert.com.au>
Committed: Tue Aug 9 18:05:25 2016 +1000
----------------------------------------------------------------------
.../classgen/asm/sc/StaticTypesCallSiteWriter.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/760b0c1f/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 8cb9595..8e38681 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -650,6 +650,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
writeModCall(receiver, arguments, rType, aType);
return true;
}
+ else if("rightShiftUnsigned".equals(message))
+ {
+ writeShiftOperatorCall(receiver, arguments, rType, aType);
+ return true;
+ }
} else if (STRING_TYPE.equals(rType) && "plus".equals(message)) {
writeStringPlusCall(receiver, message, arguments);
return true;
@@ -749,7 +754,17 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", "mod", "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
controller.getOperandStack().replace(Number_TYPE, 2);
}
-
+
+ private void writeShiftOperatorCall(Expression receiver, Expression arguments, ClassNode rType, ClassNode aType) {
+ prepareSiteAndReceiver(receiver, "rightShiftUnsigned", false, controller.getCompileStack().isLHS());
+ controller.getOperandStack().doGroovyCast(Number_TYPE);
+ visitBoxedArgument(arguments);
+ controller.getOperandStack().doGroovyCast(Number_TYPE);
+ MethodVisitor mv = controller.getMethodVisitor();
+ mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/typehandling/NumberMath", "rightShiftUnsigned", "(Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;", false);
+ controller.getOperandStack().replace(Number_TYPE, 2);
+ }
+
private void writePowerCall(Expression receiver, Expression arguments, final ClassNode rType, ClassNode aType) {
OperandStack operandStack = controller.getOperandStack();
int m1 = operandStack.getStackLength();