This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
commit ae5c94c832bcc2f481601e4bd1fc73652140b3e8 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Nov 27 15:08:03 2022 -0500 Unit tests and coverage for binary operations #174 --- src/changes/changes.xml | 1 + .../org/apache/bcel/generic/BinaryOpCreator.java | 816 +++++++++++---------- .../org/apache/bcel/util/BCELifierTestCase.java | 112 +-- 3 files changed, 469 insertions(+), 460 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c5e12995..aab0029b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -113,6 +113,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="markt" due-to="OSS-Fuzz">org.apache.bcel.classfile.StackMapType constructors now throw ClassFormatException on invalid input.</action> <action type="fix" dev="markt" due-to="OSS-Fuzz">When parsing class files, limit arrays to no more than 255 dimensions as per section 4.4.1 of the JVM specification.</action> <action type="fix" dev="ggregory" due-to="nbauma109">Tests and coverage for Utility class #175.</action> + <action type="fix" dev="ggregory" due-to="nbauma109">Unit tests and coverage for binary operations #174.</action> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Gary Gregory">Bump spotbugs-maven-plugin from 4.7.2.2 to 4.7.3.0 #167.</action> <action type="update" dev="ggregory" due-to="Dependabot">Bump jmh.version from 1.35 to 1.36 #170.</action> diff --git a/src/test/java/org/apache/bcel/generic/BinaryOpCreator.java b/src/test/java/org/apache/bcel/generic/BinaryOpCreator.java index cd654c90..3d372b8f 100644 --- a/src/test/java/org/apache/bcel/generic/BinaryOpCreator.java +++ b/src/test/java/org/apache/bcel/generic/BinaryOpCreator.java @@ -20,6 +20,7 @@ import org.apache.bcel.Const; import org.apache.bcel.classfile.StackMap; import org.apache.bcel.classfile.StackMapEntry; import org.apache.bcel.classfile.StackMapType; +import org.apache.commons.lang.ArrayUtils; import java.io.IOException; import java.io.OutputStream; @@ -31,12 +32,23 @@ public class BinaryOpCreator { private static final String ORG_APACHE_BCEL_GENERIC_BINARY_OP = "org.apache.bcel.generic.BinaryOp"; + public static void main(final String[] args) throws Exception { + final BinaryOpCreator creator = new BinaryOpCreator(); + final Path path = Paths.get("target/test-classes/org/apache/bcel/generic/BinaryOp.class"); + Files.deleteIfExists(path); + try (OutputStream out = Files.newOutputStream(path)) { + creator.create(out); + } + } + private final InstructionFactory factory; private final ConstantPoolGen cp; + private final ClassGen cg; public BinaryOpCreator() { - cg = new ClassGen(ORG_APACHE_BCEL_GENERIC_BINARY_OP, "java.lang.Object", "BinaryOp.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {}); + cg = new ClassGen(ORG_APACHE_BCEL_GENERIC_BINARY_OP, "java.lang.Object", "BinaryOp.java", Const.ACC_PUBLIC | Const.ACC_SUPER, + ArrayUtils.EMPTY_STRING_ARRAY); cg.setMajor(Const.MAJOR_1_8); cg.setMinor(Const.MINOR_1_8); @@ -85,7 +97,8 @@ public class BinaryOpCreator { private void createConstructor() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "<init>", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, ArrayUtils.EMPTY_STRING_ARRAY, "<init>", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); il.append(factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Const.INVOKESPECIAL)); @@ -96,676 +109,679 @@ public class BinaryOpCreator { il.dispose(); } - private void createMethodISUB() { + private void createMethodCalculate() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "isub", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.OBJECT, new Type[] { new ArrayType(Type.STRING, 1) }, new String[] { "args" }, + "calculate", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); + method.addException("java.lang.Exception"); + final StackMapType[] typesOfLocals = { new StackMapType((byte) 7, cp.addClass("java.lang.String"), cp.getConstantPool()) }; + final StackMapEntry[] table = { new StackMapEntry(252, 70, typesOfLocals, StackMapType.EMPTY_ARRAY, cp.getConstantPool()), + new StackMapEntry(251, 65, StackMapType.EMPTY_ARRAY, StackMapType.EMPTY_ARRAY, cp.getConstantPool()), + new StackMapEntry(251, 65, StackMapType.EMPTY_ARRAY, StackMapType.EMPTY_ARRAY, cp.getConstantPool()), + new StackMapEntry(251, 65, StackMapType.EMPTY_ARRAY, StackMapType.EMPTY_ARRAY, cp.getConstantPool()) }; + method.addCodeAttribute(new StackMap(cp.addUtf8("StackMapTable"), 17, table, cp.getConstantPool())); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("-", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 0)); + il.append(InstructionConst.AALOAD); + il.append(InstructionFactory.createStore(Type.OBJECT, 2)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, "i")); + il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); + final BranchInstruction ifeq1 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); + il.append(ifeq1); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(factory.createFieldAccess("java.lang.Integer", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(factory.createFieldAccess("java.lang.Integer", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), + new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(Type.OBJECT, (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 1)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Integer", "parseInt", Type.INT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 2)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Integer", "parseInt", Type.INT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, + Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + final InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, "l")); + il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); + final BranchInstruction ifeq2 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); + il.append(ifeq2); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(factory.createFieldAccess("java.lang.Long", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(factory.createFieldAccess("java.lang.Long", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), + new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(Type.OBJECT, (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 1)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Long", "parseLong", Type.LONG, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new Type[] { Type.LONG }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 2)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Long", "parseLong", Type.LONG, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new Type[] { Type.LONG }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, + Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + final InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, "f")); + il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); + final BranchInstruction ifeq3 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); + il.append(ifeq3); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(factory.createFieldAccess("java.lang.Float", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(factory.createFieldAccess("java.lang.Float", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), + new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(Type.OBJECT, (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 1)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Float", "parseFloat", Type.FLOAT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new Type[] { Type.FLOAT }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 2)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Float", "parseFloat", Type.FLOAT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new Type[] { Type.FLOAT }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, + Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + final InstructionHandle ih3 = il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, "d")); + il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); + final BranchInstruction ifeq4 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); + il.append(ifeq4); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(factory.createFieldAccess("java.lang.Double", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(factory.createFieldAccess("java.lang.Double", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), + new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); + il.append(new PUSH(cp, 2)); + il.append(factory.createNewArray(Type.OBJECT, (short) 1)); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 0)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 1)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Double", "parseDouble", Type.DOUBLE, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new Type[] { Type.DOUBLE }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(InstructionConst.DUP); + il.append(new PUSH(cp, 1)); + il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); + il.append(new PUSH(cp, 2)); + il.append(InstructionConst.AALOAD); + il.append(factory.createInvoke("java.lang.Double", "parseDouble", Type.DOUBLE, new Type[] { Type.STRING }, Const.INVOKESTATIC)); + il.append(factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new Type[] { Type.DOUBLE }, Const.INVOKESTATIC)); + il.append(InstructionConst.AASTORE); + il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, + Const.INVOKEVIRTUAL)); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + final InstructionHandle ih4 = il.append(InstructionConst.ACONST_NULL); + il.append(InstructionFactory.createReturn(Type.OBJECT)); + ifeq1.setTarget(ih1); + ifeq2.setTarget(ih2); + ifeq3.setTarget(ih3); + ifeq4.setTarget(ih4); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIADD() { + private void createMethodDADD() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "iadd", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "dadd", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("+", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); + il.append(InstructionFactory.createBinaryOperation("+", Type.DOUBLE)); + il.append(InstructionFactory.createReturn(Type.DOUBLE)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIREM() { + private void createMethodDDIV() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "irem", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "ddiv", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("%", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); + il.append(InstructionFactory.createBinaryOperation("/", Type.DOUBLE)); + il.append(InstructionFactory.createReturn(Type.DOUBLE)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIMUL() { + private void createMethodDMUL() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "imul", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "dmul", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("*", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); + il.append(InstructionFactory.createBinaryOperation("*", Type.DOUBLE)); + il.append(InstructionFactory.createReturn(Type.DOUBLE)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIDIV() { + private void createMethodDREM() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "idiv", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "drem", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("/", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); + il.append(InstructionFactory.createBinaryOperation("%", Type.DOUBLE)); + il.append(InstructionFactory.createReturn(Type.DOUBLE)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIAND() { + private void createMethodDSUB() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "iand", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "dsub", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("&", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); + il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); + il.append(InstructionFactory.createBinaryOperation("-", Type.DOUBLE)); + il.append(InstructionFactory.createReturn(Type.DOUBLE)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIOR() { + private void createMethodFADD() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ior", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fadd", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("|", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); + il.append(InstructionFactory.createBinaryOperation("+", Type.FLOAT)); + il.append(InstructionFactory.createReturn(Type.FLOAT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIXOR() { + private void createMethodFDIV() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ixor", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fdiv", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("^", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); + il.append(InstructionFactory.createBinaryOperation("/", Type.FLOAT)); + il.append(InstructionFactory.createReturn(Type.FLOAT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodISHL() { + private void createMethodFMUL() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ishl", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fmul", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation("<<", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); + il.append(InstructionFactory.createBinaryOperation("*", Type.FLOAT)); + il.append(InstructionFactory.createReturn(Type.FLOAT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodISHR() { + private void createMethodFREM() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ishr", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "frem", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation(">>", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); + il.append(InstructionFactory.createBinaryOperation("%", Type.FLOAT)); + il.append(InstructionFactory.createReturn(Type.FLOAT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodIUSHR() { + private void createMethodFSUB() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "iushr", ORG_APACHE_BCEL_GENERIC_BINARY_OP, - il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fsub", + ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.INT, 1)); - il.append(InstructionFactory.createLoad(Type.INT, 2)); - il.append(InstructionFactory.createBinaryOperation(">>>", Type.INT)); - il.append(InstructionFactory.createReturn(Type.INT)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); + il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); + il.append(InstructionFactory.createBinaryOperation("-", Type.FLOAT)); + il.append(InstructionFactory.createReturn(Type.FLOAT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLSUB() { + private void createMethodIADD() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lsub", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "iadd", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("-", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("+", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLADD() { + private void createMethodIAND() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "ladd", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "iand", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("+", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("&", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLREM() { + private void createMethodIDIV() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lrem", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "idiv", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("%", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("/", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLMUL() { + private void createMethodIMUL() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lmul", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "imul", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("*", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("*", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLDIV() { + private void createMethodIOR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "ldiv", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ior", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("/", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("|", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLAND() { + private void createMethodIREM() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "land", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "irem", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("&", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("%", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLOR() { + private void createMethodISHL() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lor", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ishl", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("|", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("<<", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLXOR() { + private void createMethodISHR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lxor", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ishr", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionFactory.createBinaryOperation("^", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation(">>", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLSHL() { + private void createMethodISUB() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lshl", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "isub", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionConst.L2I); - il.append(InstructionFactory.createBinaryOperation("<<", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("-", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLSHR() { + private void createMethodIUSHR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lshr", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "iushr", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionConst.L2I); - il.append(InstructionFactory.createBinaryOperation(">>", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation(">>>", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodLUSHR() { + private void createMethodIXOR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lushr", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.INT, new Type[] { Type.INT, Type.INT }, new String[] { "a", "b" }, "ixor", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.LONG, 1)); - il.append(InstructionFactory.createLoad(Type.LONG, 3)); - il.append(InstructionConst.L2I); - il.append(InstructionFactory.createBinaryOperation(">>>", Type.LONG)); - il.append(InstructionFactory.createReturn(Type.LONG)); + il.append(InstructionFactory.createLoad(Type.INT, 1)); + il.append(InstructionFactory.createLoad(Type.INT, 2)); + il.append(InstructionFactory.createBinaryOperation("^", Type.INT)); + il.append(InstructionFactory.createReturn(Type.INT)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodFSUB() { + private void createMethodLADD() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fsub", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "ladd", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); - il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); - il.append(InstructionFactory.createBinaryOperation("-", Type.FLOAT)); - il.append(InstructionFactory.createReturn(Type.FLOAT)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("+", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodFADD() { + private void createMethodLAND() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fadd", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "land", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); - il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); - il.append(InstructionFactory.createBinaryOperation("+", Type.FLOAT)); - il.append(InstructionFactory.createReturn(Type.FLOAT)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("&", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodFREM() { + private void createMethodLDIV() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "frem", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "ldiv", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); - il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); - il.append(InstructionFactory.createBinaryOperation("%", Type.FLOAT)); - il.append(InstructionFactory.createReturn(Type.FLOAT)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("/", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodFMUL() { + private void createMethodLMUL() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fmul", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lmul", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); - il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); - il.append(InstructionFactory.createBinaryOperation("*", Type.FLOAT)); - il.append(InstructionFactory.createReturn(Type.FLOAT)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("*", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodFDIV() { + private void createMethodLOR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.FLOAT, new Type[] { Type.FLOAT, Type.FLOAT }, new String[] { "a", "b" }, "fdiv", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lor", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.FLOAT, 1)); - il.append(InstructionFactory.createLoad(Type.FLOAT, 2)); - il.append(InstructionFactory.createBinaryOperation("/", Type.FLOAT)); - il.append(InstructionFactory.createReturn(Type.FLOAT)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("|", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodDSUB() { + private void createMethodLREM() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "dsub", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lrem", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); - il.append(InstructionFactory.createBinaryOperation("-", Type.DOUBLE)); - il.append(InstructionFactory.createReturn(Type.DOUBLE)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("%", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodDADD() { + private void createMethodLSHL() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "dadd", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lshl", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); - il.append(InstructionFactory.createBinaryOperation("+", Type.DOUBLE)); - il.append(InstructionFactory.createReturn(Type.DOUBLE)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionConst.L2I); + il.append(InstructionFactory.createBinaryOperation("<<", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodDREM() { + private void createMethodLSHR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "drem", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lshr", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); - il.append(InstructionFactory.createBinaryOperation("%", Type.DOUBLE)); - il.append(InstructionFactory.createReturn(Type.DOUBLE)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionConst.L2I); + il.append(InstructionFactory.createBinaryOperation(">>", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodDMUL() { + private void createMethodLSUB() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "dmul", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lsub", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); - il.append(InstructionFactory.createBinaryOperation("*", Type.DOUBLE)); - il.append(InstructionFactory.createReturn(Type.DOUBLE)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("-", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodDDIV() { + private void createMethodLUSHR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.DOUBLE, new Type[] { Type.DOUBLE, Type.DOUBLE }, new String[] { "a", "b" }, "ddiv", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lushr", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 1)); - il.append(InstructionFactory.createLoad(Type.DOUBLE, 3)); - il.append(InstructionFactory.createBinaryOperation("/", Type.DOUBLE)); - il.append(InstructionFactory.createReturn(Type.DOUBLE)); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionConst.L2I); + il.append(InstructionFactory.createBinaryOperation(">>>", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); il.dispose(); } - private void createMethodCalculate() { + private void createMethodLXOR() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.OBJECT, new Type[] { new ArrayType(Type.STRING, 1) }, new String[] { "args" }, "calculate", + final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.LONG, new Type[] { Type.LONG, Type.LONG }, new String[] { "a", "b" }, "lxor", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); - method.addException("java.lang.Exception"); - final StackMapType[] typesOfLocals = new StackMapType[] {new StackMapType((byte)7, cp.addClass("java.lang.String"), cp.getConstantPool()) }; - final StackMapEntry[] table = new StackMapEntry[] { - new StackMapEntry(252, 70, typesOfLocals, StackMapType.EMPTY_ARRAY, cp.getConstantPool()), - new StackMapEntry(251, 65, StackMapType.EMPTY_ARRAY, StackMapType.EMPTY_ARRAY, cp.getConstantPool()), - new StackMapEntry(251, 65, StackMapType.EMPTY_ARRAY, StackMapType.EMPTY_ARRAY, cp.getConstantPool()), - new StackMapEntry(251, 65, StackMapType.EMPTY_ARRAY, StackMapType.EMPTY_ARRAY, cp.getConstantPool())}; - method.addCodeAttribute(new StackMap(cp.addUtf8("StackMapTable"), 17, table, cp.getConstantPool())); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 0)); - il.append(InstructionConst.AALOAD); - il.append(InstructionFactory.createStore(Type.OBJECT, 2)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, "i")); - il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); - final BranchInstruction ifeq1 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); - il.append(ifeq1); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(factory.createFieldAccess("java.lang.Integer", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(factory.createFieldAccess("java.lang.Integer", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), - new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(Type.OBJECT, (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 1)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Integer", "parseInt", Type.INT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 2)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Integer", "parseInt", Type.INT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new Type[] { Type.INT }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createReturn(Type.OBJECT)); - final InstructionHandle ih1 = il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, "l")); - il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); - final BranchInstruction ifeq2 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); - il.append(ifeq2); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(factory.createFieldAccess("java.lang.Long", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(factory.createFieldAccess("java.lang.Long", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), - new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(Type.OBJECT, (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 1)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Long", "parseLong", Type.LONG, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new Type[] { Type.LONG }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 2)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Long", "parseLong", Type.LONG, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new Type[] { Type.LONG }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createReturn(Type.OBJECT)); - final InstructionHandle ih2 = il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, "f")); - il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); - final BranchInstruction ifeq3 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); - il.append(ifeq3); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(factory.createFieldAccess("java.lang.Float", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(factory.createFieldAccess("java.lang.Float", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), - new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(Type.OBJECT, (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 1)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Float", "parseFloat", Type.FLOAT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new Type[] { Type.FLOAT }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 2)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Float", "parseFloat", Type.FLOAT, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new Type[] { Type.FLOAT }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createReturn(Type.OBJECT)); - final InstructionHandle ih3 = il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, "d")); - il.append(factory.createInvoke("java.lang.String", "startsWith", Type.BOOLEAN, new Type[] { Type.STRING }, Const.INVOKEVIRTUAL)); - final BranchInstruction ifeq4 = InstructionFactory.createBranchInstruction(Const.IFEQ, null); - il.append(ifeq4); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(factory.createInvoke("java.lang.Object", "getClass", new ObjectType("java.lang.Class"), Type.NO_ARGS, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 2)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(new ObjectType("java.lang.Class"), (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(factory.createFieldAccess("java.lang.Double", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(factory.createFieldAccess("java.lang.Double", "TYPE", new ObjectType("java.lang.Class"), Const.GETSTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.Class", "getMethod", new ObjectType("java.lang.reflect.Method"), - new Type[] { Type.STRING, new ArrayType(new ObjectType("java.lang.Class"), 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(new PUSH(cp, 2)); - il.append(factory.createNewArray(Type.OBJECT, (short) 1)); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 0)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 1)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Double", "parseDouble", Type.DOUBLE, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new Type[] { Type.DOUBLE }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(InstructionConst.DUP); - il.append(new PUSH(cp, 1)); - il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); - il.append(new PUSH(cp, 2)); - il.append(InstructionConst.AALOAD); - il.append(factory.createInvoke("java.lang.Double", "parseDouble", Type.DOUBLE, new Type[] { Type.STRING }, Const.INVOKESTATIC)); - il.append(factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new Type[] { Type.DOUBLE }, Const.INVOKESTATIC)); - il.append(InstructionConst.AASTORE); - il.append(factory.createInvoke("java.lang.reflect.Method", "invoke", Type.OBJECT, new Type[] { Type.OBJECT, new ArrayType(Type.OBJECT, 1) }, Const.INVOKEVIRTUAL)); - il.append(InstructionFactory.createReturn(Type.OBJECT)); - final InstructionHandle ih4 = il.append(InstructionConst.ACONST_NULL); - il.append(InstructionFactory.createReturn(Type.OBJECT)); - ifeq1.setTarget(ih1); - ifeq2.setTarget(ih2); - ifeq3.setTarget(ih3); - ifeq4.setTarget(ih4); + il.append(InstructionFactory.createLoad(Type.LONG, 1)); + il.append(InstructionFactory.createLoad(Type.LONG, 3)); + il.append(InstructionFactory.createBinaryOperation("^", Type.LONG)); + il.append(InstructionFactory.createReturn(Type.LONG)); method.setMaxStack(); method.setMaxLocals(); cg.addMethod(method.getMethod()); @@ -774,8 +790,8 @@ public class BinaryOpCreator { private void createMethodMain() { final InstructionList il = new InstructionList(); - final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, new Type[] { new ArrayType(Type.STRING, 1) }, new String[] { "args" }, "main", - ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); + final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, new Type[] { new ArrayType(Type.STRING, 1) }, + new String[] { "args" }, "main", ORG_APACHE_BCEL_GENERIC_BINARY_OP, il, cp); method.addException("java.lang.Exception"); il.append(factory.createNew(ORG_APACHE_BCEL_GENERIC_BINARY_OP)); @@ -785,7 +801,8 @@ public class BinaryOpCreator { il.append(factory.createFieldAccess("java.lang.System", "out", new ObjectType("java.io.PrintStream"), Const.GETSTATIC)); il.append(InstructionFactory.createLoad(Type.OBJECT, 1)); il.append(InstructionFactory.createLoad(Type.OBJECT, 0)); - il.append(factory.createInvoke(ORG_APACHE_BCEL_GENERIC_BINARY_OP, "calculate", Type.OBJECT, new Type[] { new ArrayType(Type.STRING, 1) }, Const.INVOKEVIRTUAL)); + il.append(factory.createInvoke(ORG_APACHE_BCEL_GENERIC_BINARY_OP, "calculate", Type.OBJECT, new Type[] { new ArrayType(Type.STRING, 1) }, + Const.INVOKEVIRTUAL)); il.append(factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[] { Type.OBJECT }, Const.INVOKEVIRTUAL)); il.append(InstructionFactory.createReturn(Type.VOID)); method.setMaxStack(); @@ -793,13 +810,4 @@ public class BinaryOpCreator { cg.addMethod(method.getMethod()); il.dispose(); } - - public static void main(final String[] args) throws Exception { - final org.apache.bcel.generic.BinaryOpCreator creator = new org.apache.bcel.generic.BinaryOpCreator(); - final Path path = Paths.get("target/test-classes/org/apache/bcel/generic/BinaryOp.class"); - Files.deleteIfExists(path); - try (OutputStream out = Files.newOutputStream(path)) { - creator.create(out); - } - } } diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java index 5e5b15ff..24d2eb2e 100644 --- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java +++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java @@ -72,6 +72,62 @@ public class BCELifierTestCase extends AbstractTestCase { } } + @ParameterizedTest + @ValueSource(strings = { + // @formatter:off + "iadd 3 2 = 5", + "isub 3 2 = 1", + "imul 3 2 = 6", + "idiv 3 2 = 1", + "irem 3 2 = 1", + "iand 3 2 = 2", + "ior 3 2 = 3", + "ixor 3 2 = 1", + "ishl 4 1 = 8", + "ishr 4 1 = 2", + "iushr 4 1 = 2", + "ladd 3 2 = 5", + "lsub 3 2 = 1", + "lmul 3 2 = 6", + "ldiv 3 2 = 1", + "lrem 3 2 = 1", + "land 3 2 = 2", + "lor 3 2 = 3", + "lxor 3 2 = 1", + "lshl 4 1 = 8", + "lshr 4 1 = 2", + "lushr 4 1 = 2", + "fadd 3 2 = 5.0", + "fsub 3 2 = 1.0", + "fmul 3 2 = 6.0", + "fdiv 3 2 = 1.5", + "frem 3 2 = 1.0", + "dadd 3 2 = 5.0", + "dsub 3 2 = 1.0", + "dmul 3 2 = 6.0", + "ddiv 3 2 = 1.5", + "drem 3 2 = 1.0" + // @formatter:on + }) + public void testBinaryOp(final String exp) throws Exception { + BinaryOpCreator.main(new String[] {}); + final File workDir = new File("target"); + final Pattern pattern = Pattern.compile("([a-z]{3,5}) ([-+]?\\d*\\.?\\d+) ([-+]?\\d*\\.?\\d+) = ([-+]?\\d*\\.?\\d+)"); + final Matcher matcher = pattern.matcher(exp); + assertTrue(matcher.matches()); + final String op = matcher.group(1); + final String a = matcher.group(2); + final String b = matcher.group(3); + final String expected = matcher.group(4); + final String javaAgent = getJavaAgent(); + if (javaAgent == null) { + assertEquals(expected + EOL, exec(workDir, "java", "-cp", CLASSPATH, "org.apache.bcel.generic.BinaryOp", op, a, b)); + } else { + final String runtimeExecJavaAgent = javaAgent.replace("jacoco.exec", "jacoco_org.apache.bcel.generic.BinaryOp.exec"); + assertEquals(expected + EOL, exec(workDir, "java", runtimeExecJavaAgent, "-cp", CLASSPATH, "org.apache.bcel.generic.BinaryOp", op, a, b)); + } + } + private void testClassOnPath(final String javaClassFileName) throws Exception { final File workDir = new File("target"); final File infile = new File(javaClassFileName); @@ -160,60 +216,4 @@ public class BCELifierTestCase extends AbstractTestCase { final BCELifier bcelifier = new BCELifier(javaClass, os); bcelifier.start(); } - - @ParameterizedTest - @ValueSource(strings = { - // @formatter:off - "iadd 3 2 = 5", - "isub 3 2 = 1", - "imul 3 2 = 6", - "idiv 3 2 = 1", - "irem 3 2 = 1", - "iand 3 2 = 2", - "ior 3 2 = 3", - "ixor 3 2 = 1", - "ishl 4 1 = 8", - "ishr 4 1 = 2", - "iushr 4 1 = 2", - "ladd 3 2 = 5", - "lsub 3 2 = 1", - "lmul 3 2 = 6", - "ldiv 3 2 = 1", - "lrem 3 2 = 1", - "land 3 2 = 2", - "lor 3 2 = 3", - "lxor 3 2 = 1", - "lshl 4 1 = 8", - "lshr 4 1 = 2", - "lushr 4 1 = 2", - "fadd 3 2 = 5.0", - "fsub 3 2 = 1.0", - "fmul 3 2 = 6.0", - "fdiv 3 2 = 1.5", - "frem 3 2 = 1.0", - "dadd 3 2 = 5.0", - "dsub 3 2 = 1.0", - "dmul 3 2 = 6.0", - "ddiv 3 2 = 1.5", - "drem 3 2 = 1.0" - // @formatter:on - }) - public void testBinaryOp(final String exp) throws Exception { - BinaryOpCreator.main(new String[] {}); - final File workDir = new File("target"); - final Pattern pattern = Pattern.compile("([a-z]{3,5}) ([-+]?\\d*\\.?\\d+) ([-+]?\\d*\\.?\\d+) = ([-+]?\\d*\\.?\\d+)"); - final Matcher matcher = pattern.matcher(exp); - assertTrue(matcher.matches()); - final String op = matcher.group(1); - final String a = matcher.group(2); - final String b = matcher.group(3); - final String expected = matcher.group(4); - final String javaAgent = getJavaAgent(); - if (javaAgent == null) { - assertEquals(expected + EOL, exec(workDir, "java", "-cp", CLASSPATH, "org.apache.bcel.generic.BinaryOp", op, a, b)); - } else { - final String runtimeExecJavaAgent = javaAgent.replace("jacoco.exec", "jacoco_org.apache.bcel.generic.BinaryOp.exec"); - assertEquals(expected + EOL, exec(workDir, "java", runtimeExecJavaAgent, "-cp", CLASSPATH, "org.apache.bcel.generic.BinaryOp", op, a, b)); - } - } }