Recursively collect generics for FunN
This commit is contained in:
parent
9d9a1f6614
commit
66944cf3c1
@ -3,11 +3,13 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
import de.dhbwstuttgart.target.tree.TargetGeneric;
|
import de.dhbwstuttgart.target.tree.TargetGeneric;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetGenericType;
|
import de.dhbwstuttgart.target.tree.type.TargetGenericType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetSpecializedType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -71,14 +73,15 @@ public class FunNGenerator {
|
|||||||
boolean containsGeneric = false;
|
boolean containsGeneric = false;
|
||||||
|
|
||||||
String genericSignature = "<";
|
String genericSignature = "<";
|
||||||
|
var generics = new HashSet<TargetGenericType>();
|
||||||
for (TargetType typeArgument : parameters) {
|
for (TargetType typeArgument : parameters) {
|
||||||
//ToDo Etienne: Refactor
|
collectGenericTypeArguments(generics, typeArgument);
|
||||||
if (typeArgument instanceof TargetGenericType generic){
|
}
|
||||||
//if(genericSignature.contains(generic.name())) continue;
|
for (var generic : generics) {
|
||||||
genericSignature += String.format("%s:%s", generic.name(), objectSignature);
|
genericSignature += String.format("%s:%s", generic.name(), objectSignature);
|
||||||
containsGeneric = true;
|
containsGeneric = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
genericSignature += ">";
|
genericSignature += ">";
|
||||||
if (containsGeneric) funNClassSignature.insert(0, genericSignature);
|
if (containsGeneric) funNClassSignature.insert(0, genericSignature);
|
||||||
|
|
||||||
@ -88,6 +91,15 @@ public class FunNGenerator {
|
|||||||
return classWriter.toByteArray();
|
return classWriter.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void collectGenericTypeArguments(HashSet<TargetGenericType> generics, TargetType typeArgument) {
|
||||||
|
if (typeArgument instanceof TargetSpecializedType specializedType) {
|
||||||
|
for (var arg : specializedType.params())
|
||||||
|
collectGenericTypeArguments(generics, arg);
|
||||||
|
} else if (typeArgument instanceof TargetGenericType genericType) {
|
||||||
|
generics.add(genericType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String getSpecializedClassName(List<TargetType> argumentTypes, TargetType returnType) {
|
public static String getSpecializedClassName(List<TargetType> argumentTypes, TargetType returnType) {
|
||||||
return String.format("Fun%d$$%s%s",
|
return String.format("Fun%d$$%s%s",
|
||||||
argumentTypes.size(),
|
argumentTypes.size(),
|
||||||
|
Loading…
Reference in New Issue
Block a user