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.type.TargetGenericType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetSpecializedType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@ -71,14 +73,15 @@ public class FunNGenerator {
|
||||
boolean containsGeneric = false;
|
||||
|
||||
String genericSignature = "<";
|
||||
var generics = new HashSet<TargetGenericType>();
|
||||
for (TargetType typeArgument : parameters) {
|
||||
//ToDo Etienne: Refactor
|
||||
if (typeArgument instanceof TargetGenericType generic){
|
||||
//if(genericSignature.contains(generic.name())) continue;
|
||||
collectGenericTypeArguments(generics, typeArgument);
|
||||
}
|
||||
for (var generic : generics) {
|
||||
genericSignature += String.format("%s:%s", generic.name(), objectSignature);
|
||||
containsGeneric = true;
|
||||
}
|
||||
}
|
||||
|
||||
genericSignature += ">";
|
||||
if (containsGeneric) funNClassSignature.insert(0, genericSignature);
|
||||
|
||||
@ -88,6 +91,15 @@ public class FunNGenerator {
|
||||
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) {
|
||||
return String.format("Fun%d$$%s%s",
|
||||
argumentTypes.size(),
|
||||
|
Loading…
Reference in New Issue
Block a user