Compare commits
7 Commits
a0367d5464
...
669c778af8
Author | SHA1 | Date | |
---|---|---|---|
|
669c778af8 | ||
|
5071406b3f | ||
|
9d2d076215 | ||
|
6262c9434c | ||
|
59c5e48201 | ||
|
1cf1c99e72 | ||
|
5c60918c47 |
@ -592,7 +592,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
this.lamCounter++;
|
||||
|
||||
String typeErasure = createDescriptorWithTypeErasure(lambdaExpression);
|
||||
//ToDo Etienne: Double Check
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(lambdaExpression.getReturnType());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes = lambdaExpression
|
||||
.params
|
||||
@ -828,7 +827,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
||||
} else if(!helper.isInCurrPkg(clazz)){
|
||||
if(clazz.contains(CONSTANTS.$$)) {
|
||||
mDesc = helper.getDescriptorOfApplyMethod(methCallType);
|
||||
//ToDo Etienne: Double Check
|
||||
RefTypeOrTPHOrWildcardOrGeneric returnType = resolver.resolve(methodCall.getType());
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes = methodCall
|
||||
.arglist
|
||||
|
@ -153,7 +153,6 @@ public class DescriptorToString implements DescriptorVisitor, CONSTANTS {
|
||||
return desc;
|
||||
}
|
||||
|
||||
//ToDo Etienne: ändern
|
||||
@Override
|
||||
public String visit(Lambda lambdaExpression) {
|
||||
String desc = "(";
|
||||
|
@ -113,7 +113,7 @@ public final class FunNGenerator implements FunNUtilities{
|
||||
public String getSpecializedClassName(List<RefTypeOrTPHOrWildcardOrGeneric> argumentTypes, RefTypeOrTPHOrWildcardOrGeneric returnType) {
|
||||
Objects.requireNonNull(argumentTypes);
|
||||
Objects.requireNonNull(returnType);
|
||||
return String.format("Fun%d$$%s%s",
|
||||
return String.format("Fun%d$$$_$%s%s",
|
||||
argumentTypes.size(),
|
||||
argumentTypes
|
||||
.stream()
|
||||
|
@ -20,7 +20,8 @@ public class ASTToTargetAST {
|
||||
public TargetClass convert(ClassOrInterface input, Map<TypePlaceholder, TargetType> sigma){
|
||||
List<TargetConstructor> targetConstructors = new ArrayList<>();
|
||||
//TODO constructor conversion -> also reduce syntactic sugar
|
||||
return new TargetClass(input.getModifiers(),input.getClassName().toString(), sigma.get(input.getSuperClass()),
|
||||
return new TargetClass(input.getModifiers(),input.getClassName().toString(), null,
|
||||
sigma.get(input.getSuperClass()),
|
||||
input.getSuperInterfaces().stream().map(it -> sigma.get(it)).collect(Collectors.toList()),
|
||||
targetConstructors,
|
||||
input.getFieldDecl().stream().map(it -> convert(it, sigma)).collect(Collectors.toList()),
|
||||
@ -42,7 +43,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
private TargetField convert(Field input, Map<TypePlaceholder, TargetType> sigma) {
|
||||
return null;
|
||||
return new TargetField(convert(input.getType(), sigma), input.getName());
|
||||
}
|
||||
|
||||
private TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map<TypePlaceholder, TargetType> sigma) {
|
||||
|
@ -0,0 +1,7 @@
|
||||
package de.dhbwstuttgart.target.tree;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
|
||||
public record GenericDeclaration(GenericRefType generic, TargetType bound) {
|
||||
}
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record TargetClass(int modifiers, String qualifiedName, TargetType superType, List<TargetType> implementingInterfaces,
|
||||
public record TargetClass(int modifiers, String qualifiedName, List<GenericDeclaration> generics, TargetType superType,
|
||||
List<TargetType> implementingInterfaces,
|
||||
List<TargetConstructor> constructors, List<TargetField> fields, List<TargetMethod> methods) {}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package de.dhbwstuttgart.target.tree;
|
||||
|
||||
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record TargetConstructor(List<MethodParameter> parameterTypes) {
|
||||
public record TargetConstructor(List<MethodParameter> parameterTypes, TargetBlock block) {
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package de.dhbwstuttgart.target.tree.type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record TargetExtendsWildcard(TargetType innerType) implements TargetType{
|
||||
}
|
||||
|
||||
|
@ -38,34 +38,38 @@ public class OLFun2Test {
|
||||
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||
classToTest = loader.loadClass("OLFun2");
|
||||
classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||
classFun1IntDouble = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleInt = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
|
||||
classFun1IntInt = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||
classFun1IntDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleInt = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithIntegerInteger() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1IntInt);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.class, m.getReturnType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithIntegerDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1IntDouble);
|
||||
assertNotNull(m);
|
||||
assertEquals(Double.class, m.getReturnType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithDoubleInteger() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleInt);
|
||||
assertNotNull(m);
|
||||
assertEquals(Integer.class, m.getReturnType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mExistsWithDoubleDouble() throws Exception{
|
||||
Method m = classToTest.getDeclaredMethod("m", classFun1DoubleDouble);
|
||||
assertNotNull(m);
|
||||
assertEquals(Double.class, m.getReturnType());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -40,12 +40,12 @@ public class OLFunTest {
|
||||
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||
classToTest = loader.loadClass("OLFun");
|
||||
classFun1IntInt = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||
classFun1IntDouble = loader.loadClass("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleDouble = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleInt = loader.loadClass("Fun1$$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
|
||||
classFun1StringInt = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$Integer$_$");
|
||||
classFun1StringDouble = loader.loadClass("Fun1$$Ljava$lang$String$_$Ljava$lang$Double$_$");
|
||||
classFun1IntInt = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$");
|
||||
classFun1IntDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleDouble = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Double$_$");
|
||||
classFun1DoubleInt = loader.loadClass("Fun1$$$_$Ljava$lang$Double$_$Ljava$lang$Integer$_$");
|
||||
classFun1StringInt = loader.loadClass("Fun1$$$_$Ljava$lang$String$_$Ljava$lang$Integer$_$");
|
||||
classFun1StringDouble = loader.loadClass("Fun1$$$_$Ljava$lang$String$_$Ljava$lang$Double$_$");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -49,70 +49,70 @@ public class FunNGeneratorTest {
|
||||
@Test
|
||||
public void specializedClassName_VoidVoid(){
|
||||
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(), voidType);
|
||||
assertEquals("Fun0$$Ljava$lang$Void$_$", specializedClassName);
|
||||
assertEquals("Fun0$$$_$Ljava$lang$Void$_$", specializedClassName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specializedClassName_VoidInt(){
|
||||
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(), integerType);
|
||||
assertEquals("Fun0$$Ljava$lang$Integer$_$", specializedClassName);
|
||||
assertEquals("Fun0$$$_$Ljava$lang$Integer$_$", specializedClassName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specializedClassName_IntInt(){
|
||||
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(integerType), integerType);
|
||||
assertEquals("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", specializedClassName);
|
||||
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", specializedClassName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specializedClassName_IntT(){
|
||||
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(integerType), genericT);
|
||||
assertEquals("Fun1$$Ljava$lang$Integer$_$LT$_$", specializedClassName);
|
||||
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$LT$_$", specializedClassName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void specializedClassName_IntTPH(){
|
||||
var specializedClassName = funNGenerator.getSpecializedClassName(Arrays.asList(integerType), TypePlaceholder.fresh(null));
|
||||
assertEquals("Fun1$$Ljava$lang$Integer$_$LTPH$_$", specializedClassName);
|
||||
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$LTPH$_$", specializedClassName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signature_IntInt(){
|
||||
var classSignature = funNGenerator.getSpecializedSignature(Arrays.asList(integerType), integerType);
|
||||
assertEquals("LFun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$;", classSignature);
|
||||
assertEquals("LFun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$;", classSignature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signature_IntT(){
|
||||
var classSignature = funNGenerator.getSpecializedSignature(Arrays.asList(integerType), genericT);
|
||||
assertEquals("LFun1$$Ljava$lang$Integer$_$LT$_$<TT;>;", classSignature);
|
||||
assertEquals("LFun1$$$_$Ljava$lang$Integer$_$LT$_$<TT;>;", classSignature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signature_TPHTPH(){
|
||||
var classSignature = funNGenerator.getSpecializedSignature(Arrays.asList(tph), tph);
|
||||
assertEquals(String.format("LFun1$$LTPH$_$LTPH$_$<T%s$;T%s$;>;",tph.getName(), tph.getName()), classSignature);
|
||||
assertEquals(String.format("LFun1$$$_$LTPH$_$LTPH$_$<T%s$;T%s$;>;",tph.getName(), tph.getName()), classSignature);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptor_IntInt(){
|
||||
var classDescriptor = funNGenerator.getSpecializedDescriptor(Arrays.asList(integerType), integerType);
|
||||
//does not have to contain L and ; because TypeToDescriptor returns the descriptor without these characters as well
|
||||
assertEquals("Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", classDescriptor);
|
||||
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", classDescriptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptor_IntT(){
|
||||
var classDescriptor = funNGenerator.getSpecializedDescriptor(Arrays.asList(integerType), genericT);
|
||||
//does not have to contain L and ; because TypeToDescriptor returns the descriptor without these characters as well
|
||||
assertEquals("Fun1$$Ljava$lang$Integer$_$LT$_$", classDescriptor);
|
||||
assertEquals("Fun1$$$_$Ljava$lang$Integer$_$LT$_$", classDescriptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptor_TPHTPH(){
|
||||
var classDescriptor = funNGenerator.getSpecializedDescriptor(Arrays.asList(tph), tph);
|
||||
//does not have to contain L and ; because TypeToDescriptor returns the descriptor without these characters as well
|
||||
assertEquals("Fun1$$LTPH$_$LTPH$_$", classDescriptor);
|
||||
assertEquals("Fun1$$$_$LTPH$_$LTPH$_$", classDescriptor);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -227,21 +227,21 @@ public class FunNGeneratorTest {
|
||||
//specialized bytecode reference methods
|
||||
private static byte[] specializedBytecodeReference_VoidInt() {
|
||||
ClassWriter classWriter = new ClassWriter(0);
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun0$$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun0$$<Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun0$$"});
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun0$$$_$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun0$$<Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun0$$"});
|
||||
classWriter.visitEnd();
|
||||
return classWriter.toByteArray();
|
||||
}
|
||||
|
||||
private static byte[] specializedBytecodeReference_IntInt() {
|
||||
ClassWriter classWriter = new ClassWriter(0);
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun1$$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun1$$<Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun1$$"});
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun1$$$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "Ljava/lang/Object;LFun1$$<Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun1$$"});
|
||||
classWriter.visitEnd();
|
||||
return classWriter.toByteArray();
|
||||
}
|
||||
|
||||
private static byte[] specializedBytecodeReference_TIntInt() {
|
||||
ClassWriter classWriter = new ClassWriter(0);
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun2$$LT$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "<T:Ljava/lang/Object;>Ljava/lang/Object;LFun2$$<TT;Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun2$$"});
|
||||
classWriter.visit(V1_8, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, "Fun2$$$_$LT$_$Ljava$lang$Integer$_$Ljava$lang$Integer$_$", "<T:Ljava/lang/Object;>Ljava/lang/Object;LFun2$$<TT;Ljava/lang/Integer;Ljava/lang/Integer;>;", "java/lang/Object", new String[]{"Fun2$$"});
|
||||
classWriter.visitEnd();
|
||||
return classWriter.toByteArray();
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ public class OLFun2 {
|
||||
m(f){
|
||||
var x = 1;
|
||||
var y = f.apply(x + x) + 1;
|
||||
return y;
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
public class OLFunTest{
|
||||
public static void main(String[] args){
|
||||
var olFun2 = new OLFun2();
|
||||
olFun2.m((Integer x) -> x);
|
||||
olFun2.m((Integer x) -> (Double) Double.valueOf(x));
|
||||
olFun2.m((Double x) -> x);
|
||||
olFun2.m((Double x) -> x.intValue());
|
||||
Integer i = olFun2.m((Integer x) -> x);
|
||||
i = olFun2.m((Double x) -> x.intValue());
|
||||
|
||||
Double d = olFun2.m((Integer x) -> Double.valueOf(x));
|
||||
d = olFun2.m((Double x) -> x);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user