X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Futils%2FCodeBuilderUtils.java;h=81f7b117a82f61f7ade860cd1362d5b4a85559e3;hb=6c0602e24f372963350b594fed9c7828a5540641;hp=cc8f3e0c5ab5a7f5dfefb8cf43b77b28b76c756e;hpb=593a8f75d9dbc363234002dc500c346afbeba040;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java index cc8f3e0c5..81f7b117a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/CodeBuilderUtils.java @@ -93,72 +93,75 @@ public class CodeBuilderUtils { tsmb.finish(); } - if(generateEqualsAndHashCode) { - // Create equals - { - TypeDesc CLASS = TypeDesc.forClass(Class.class); + if(generateEqualsAndHashCode) + implementHashCodeAndEquals(classBuilder, recordName, fieldNamePrefix, types); + } - MethodBuilderBase tsmb = classBuilder.addMethodBase(Opcodes.ACC_PUBLIC, "equals", TypeDesc.BOOLEAN, Constants.OBJECTS[1]); - LocalVariable parameter = tsmb.getParameter(0); - Label success = tsmb.createLabel(); - Label failure = tsmb.createLabel(); + public static void implementHashCodeAndEquals(ClassBuilder classBuilder, String recordName, String fieldNamePrefix, TypeDesc[] types) { + // Create equals + { + TypeDesc CLASS = TypeDesc.forClass(Class.class); - // Check type - tsmb.loadThis(); - tsmb.loadLocal(parameter); - tsmb.ifComparisonBranch(success, "==", TypeDesc.OBJECT); - tsmb.loadLocal(parameter); - tsmb.ifNullBranch(failure, true); - tsmb.loadLocal(parameter); - tsmb.invokeVirtual("java/lang/Object", "getClass", CLASS, Constants.EMPTY_TYPEDESC_ARRAY); - tsmb.loadThis(); - tsmb.invokeVirtual("java/lang/Object", "getClass", CLASS, Constants.EMPTY_TYPEDESC_ARRAY); - tsmb.ifComparisonBranch(failure, "!=", CLASS); - tsmb.loadLocal(parameter); - tsmb.checkCast(classBuilder.getType()); - LocalVariable other = tsmb.createLocalVariable("other", classBuilder.getType()); - tsmb.storeLocal(other); + MethodBuilderBase tsmb = classBuilder.addMethodBase(Opcodes.ACC_PUBLIC, "equals", TypeDesc.BOOLEAN, Constants.OBJECTS[1]); + LocalVariable parameter = tsmb.getParameter(0); + Label success = tsmb.createLabel(); + Label failure = tsmb.createLabel(); - // Compare fields - for(int i=0;i