Remove inner type variables
This commit is contained in:
parent
ef06a8de38
commit
de417d3ee6
@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.result.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ASTToTargetAST {
|
public class ASTToTargetAST {
|
||||||
|
|
||||||
@ -268,10 +269,45 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
computedGenericsOfClasses.put(classOrInterface, result);
|
computedGenericsOfClasses.put(classOrInterface, result);
|
||||||
eliminateCyclesAndInfima(result);
|
eliminateCyclesAndInfima(result);
|
||||||
|
eliminateInnerTypeVariables(classOrInterface, result);
|
||||||
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + result);
|
System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set<TypePlaceholder> tphs) {
|
||||||
|
if (type instanceof RefType refType) {
|
||||||
|
refType.getParaList().forEach(t -> findTphs(t, tphs));
|
||||||
|
} else if (type instanceof TypePlaceholder tph) {
|
||||||
|
tph = equality.getOrDefault(tph, tph);
|
||||||
|
var concreteType = concreteTypes.get(tph);
|
||||||
|
if (concreteType != null) {
|
||||||
|
findTphs(concreteType, tphs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tphs.add(tph);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void eliminateInnerTypeVariables(ClassOrInterface classOrInterface, Set<ResultPair<?, ?>> input) {
|
||||||
|
Set<TypePlaceholder> referenced = new HashSet<>();
|
||||||
|
for (var field : classOrInterface.getFieldDecl()) {
|
||||||
|
findTphs(field.getType(), referenced);
|
||||||
|
}
|
||||||
|
|
||||||
|
var oldInput = new HashSet<>(input);
|
||||||
|
for (var pair : oldInput) {
|
||||||
|
if (!referenced.contains(pair.getLeft())) {
|
||||||
|
input.remove(pair);
|
||||||
|
for (var pair2 : oldInput) {
|
||||||
|
if (pair2.getRight().equals(pair.getLeft())) {
|
||||||
|
input.remove(pair2);
|
||||||
|
input.add(new PairTPHsmallerTPH((TypePlaceholder) pair2.getLeft(), (TypePlaceholder) pair.getRight()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void eliminateCyclesAndInfima(Set<ResultPair<?, ?>> input) {
|
void eliminateCyclesAndInfima(Set<ResultPair<?, ?>> input) {
|
||||||
// Eliminate cycles
|
// Eliminate cycles
|
||||||
var cycles = findCycles(input);
|
var cycles = findCycles(input);
|
||||||
@ -346,7 +382,9 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Set<TypePlaceholder> allNodes(Set<ResultPair<?, ?>> input) {
|
static Set<TypePlaceholder> allNodes(Set<ResultPair<?, ?>> input) {
|
||||||
return input.stream().map(pair -> (TypePlaceholder) pair.getLeft()).collect(Collectors.toSet());
|
return input.stream()
|
||||||
|
.filter(pair -> pair instanceof PairTPHsmallerTPH)
|
||||||
|
.flatMap(pair -> Stream.of((TypePlaceholder) pair.getLeft(), (TypePlaceholder) pair.getRight())).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Set<TypePlaceholder> outgoingEdgesOf(TypePlaceholder tph, Set<ResultPair<?, ?>> input) {
|
static Set<TypePlaceholder> outgoingEdgesOf(TypePlaceholder tph, Set<ResultPair<?, ?>> input) {
|
||||||
|
Loading…
Reference in New Issue
Block a user