From b5af3a42a8c7d16e78c2fadddc2690a095dc9ad3 Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Tue, 21 Mar 2023 10:34:34 +0100 Subject: [PATCH 1/2] Fix wrong generic parameter on FunN3336 base class --- src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java b/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java index 49c9b736..ad032c02 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java @@ -39,12 +39,12 @@ public class FunNGenerator { StringBuilder superFunNMethodDescriptor = new StringBuilder("("); for (int currentParameter = 1; currentParameter <= numberArguments; currentParameter++){ - superFunNClassSignature.append(String.format("%s%d:%s",argumentGenericBase, currentParameter, objectSignature)); - superFunNMethodSignature.append(String.format("%s", applySignature(new TargetRefType(argumentGenericBase + currentParameter)))); + superFunNClassSignature.append(String.format("%s%d:%s", argumentGenericBase, currentParameter, objectSignature)); + superFunNMethodSignature.append(String.format("T%s;", argumentGenericBase + currentParameter)); superFunNMethodDescriptor.append(objectSignature); } superFunNClassSignature.append(String.format("%s:%s>%s", returnGeneric, objectSignature, objectSignature)); - superFunNMethodSignature.append(String.format(")%s", applySignature(new TargetRefType(returnGeneric)))); + superFunNMethodSignature.append(String.format(")T%s;", returnGeneric)); superFunNMethodDescriptor.append(String.format(")%s", objectSignature)); System.out.println(superFunNMethodSignature); From d93836d1105faedf7549c99cfc16e2c4b56f2e2f Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Tue, 21 Mar 2023 12:12:42 +0100 Subject: [PATCH 2/2] Fix incorrect generics for derived FunN --- Test.java | 7 +++++++ src/main/java/de/dhbwstuttgart/bytecode/Codegen.java | 2 ++ src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java | 6 +++--- src/test/java/targetast/TestComplete.java | 1 - 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 Test.java diff --git a/Test.java b/Test.java new file mode 100644 index 00000000..b0e1ed48 --- /dev/null +++ b/Test.java @@ -0,0 +1,7 @@ +public interface Test extends Base { + +} + +interface Base { + +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index df56b333..efa8def2 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -1025,6 +1025,8 @@ public class Codegen { if (!method.txGenerics().isEmpty()) mv.visitAttribute(new JavaTXSignatureAttribute(method.getTXSignature())); + System.out.println(method.getDescriptor()); + System.out.println(method.getSignature()); mv.visitCode(); var state = new State(method.returnType(), mv, method.isStatic() ? 0 : 1); for (var param: method.parameters()) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java b/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java index ad032c02..270a0bb5 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/FunNGenerator.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.bytecode; +import de.dhbwstuttgart.target.tree.TargetGeneric; import de.dhbwstuttgart.target.tree.type.TargetGenericType; import de.dhbwstuttgart.target.tree.type.TargetRefType; import de.dhbwstuttgart.target.tree.type.TargetType; @@ -66,7 +67,7 @@ public class FunNGenerator { List parameters = Stream .concat(argumentTypes.stream(), Stream.of(returnType)) .collect(Collectors.toList()); - StringBuilder funNClassSignature = new StringBuilder(objectSignature + applySignature(new TargetRefType(getSuperClassName(argumentTypes.size()), parameters))); + StringBuilder funNClassSignature = new StringBuilder(objectSignature + applyDescriptor(new TargetRefType(getSuperClassName(argumentTypes.size()), parameters))); boolean containsGeneric = false; String genericSignature = "<"; @@ -74,13 +75,12 @@ public class FunNGenerator { //ToDo Etienne: Refactor if (typeArgument instanceof TargetGenericType generic){ //if(genericSignature.contains(generic.name())) continue; - genericSignature += String.format("%s:%s", generic.name(), applyDescriptor(generic)); + genericSignature += String.format("%s:%s", generic.name(), objectSignature); containsGeneric = true; } } genericSignature += ">"; if (containsGeneric) funNClassSignature.insert(0, genericSignature); - System.out.println(funNClassSignature.toString()); ClassWriter classWriter = new ClassWriter(0); classWriter.visit(bytecodeVersion, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, getSpecializedClassName(argumentTypes, returnType), funNClassSignature.toString(), objectSuperType, new String[]{getSuperClassName(argumentTypes.size())}); diff --git a/src/test/java/targetast/TestComplete.java b/src/test/java/targetast/TestComplete.java index 5333944e..b1773e15 100644 --- a/src/test/java/targetast/TestComplete.java +++ b/src/test/java/targetast/TestComplete.java @@ -233,7 +233,6 @@ public class TestComplete { } @Test - @Ignore public void matrixTest() throws Exception { var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader()); var matrix = classFiles.get("Matrix");