Don't change the constraints anymore
This commit is contained in:
parent
5d5f3ee627
commit
45b80bb6c5
@ -39,55 +39,17 @@ public class ASTToTargetAST {
|
|||||||
Sigma(ResultSet constraints) {
|
Sigma(ResultSet constraints) {
|
||||||
ASTToTargetAST.this.sigma = this;
|
ASTToTargetAST.this.sigma = this;
|
||||||
|
|
||||||
Set<List<TypePlaceholder>> equalitySet = new HashSet<>();
|
|
||||||
Map<TypePlaceholder, List<TypePlaceholder>> unified = new HashMap<>();
|
|
||||||
|
|
||||||
for (var constraint : constraints.results) {
|
|
||||||
if (constraint instanceof PairTPHEqualTPH p) {
|
|
||||||
if (unified.containsKey(p.getLeft())) {
|
|
||||||
var equals = unified.get(p.getLeft());
|
|
||||||
equals.add(p.getRight());
|
|
||||||
unified.put(p.getLeft(), equals);
|
|
||||||
} else if (unified.containsKey(p.getRight())) {
|
|
||||||
var equals = unified.get(p.getRight());
|
|
||||||
equals.add(p.getLeft());
|
|
||||||
unified.put(p.getRight(), equals);
|
|
||||||
} else {
|
|
||||||
List<TypePlaceholder> equals = new ArrayList<>();
|
|
||||||
equals.add(p.getLeft());
|
|
||||||
equals.add(p.getRight());
|
|
||||||
unified.put(p.getLeft(), equals);
|
|
||||||
unified.put(p.getRight(), equals);
|
|
||||||
equalitySet.add(equals);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var constraint : constraints.results) {
|
for (var constraint : constraints.results) {
|
||||||
if (constraint instanceof PairTPHsmallerTPH p) {
|
if (constraint instanceof PairTPHsmallerTPH p) {
|
||||||
var left = p.left;
|
simplifiedConstraints.add(p);
|
||||||
var right = p.right;
|
} else if (constraint instanceof PairTPHEqualTPH p) {
|
||||||
if (unified.containsKey(left))
|
equality.put(p.getLeft(), p.getRight());
|
||||||
left = unified.get(left).get(0);
|
} else if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) {
|
||||||
if (unified.containsKey(right))
|
|
||||||
right = unified.get(right).get(0);
|
|
||||||
|
|
||||||
simplifiedConstraints.add(new PairTPHsmallerTPH(left, right));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("Simplified constraints: " + simplifiedConstraints);
|
|
||||||
|
|
||||||
for (var equality : equalitySet) {
|
|
||||||
var first = equality.get(0);
|
|
||||||
for (var i = 1; i < equality.size(); i++)
|
|
||||||
this.equality.put(equality.get(i), first);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var constraint : constraints.results) {
|
|
||||||
if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) {
|
|
||||||
concreteTypes.put(this.equality.getOrDefault(p.left, p.left), p.right);
|
concreteTypes.put(this.equality.getOrDefault(p.left, p.left), p.right);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("Simplified constraints: " + simplifiedConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type, Set<TypePlaceholder> typeVariables) {
|
void findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type, Set<TypePlaceholder> typeVariables) {
|
||||||
|
@ -231,7 +231,6 @@ public class TestComplete {
|
|||||||
assertEquals(result, instanceOfClass_m3);
|
assertEquals(result, instanceOfClass_m3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("Thread blocking for some reason")
|
|
||||||
@Test
|
@Test
|
||||||
public void matrixTest() throws Exception {
|
public void matrixTest() throws Exception {
|
||||||
var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader());
|
var classFiles = generateClassFiles("Matrix.jav", new ByteArrayClassLoader());
|
||||||
|
@ -24,67 +24,10 @@ public class TphTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test1() throws Exception {
|
public void test1() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
|
|
||||||
var classToTest = classFiles.get("Tph7");
|
|
||||||
var instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
|
|
||||||
//public <DZN, DZL, DZU extends DZN, DZM extends DZU> DZU m(DZL, DZM);
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
|
Object result = m.invoke(instanceOfClass, 1,2);
|
||||||
|
|
||||||
//System.out.println(m.toString());
|
assertEquals(1,result);
|
||||||
|
|
||||||
//Argumenttypes of the method m
|
|
||||||
var paraTypes = m.getGenericParameterTypes();
|
|
||||||
|
|
||||||
//Typeparameters of the method m
|
|
||||||
var typeParaTypes = m.getTypeParameters();
|
|
||||||
|
|
||||||
//Typeparameters are extracted from the argumenttypes
|
|
||||||
//Conditions for the extracted typeparameters are set
|
|
||||||
|
|
||||||
//paraTypes[0] = DLZ
|
|
||||||
var boundFstArg = Arrays.stream(typeParaTypes)
|
|
||||||
.filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds();
|
|
||||||
|
|
||||||
//Bound of DLZ has to be Object
|
|
||||||
assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get());
|
|
||||||
|
|
||||||
//paraTypes[0] = DZM
|
|
||||||
var boundSndArg = Arrays.stream(typeParaTypes)
|
|
||||||
.filter(x -> x.equals(paraTypes[1])).findFirst().get().getBounds();
|
|
||||||
|
|
||||||
//Bound of DZM has to be the return type of m
|
|
||||||
assertEquals(Arrays.stream(boundSndArg).findFirst().get(), m.getGenericReturnType());
|
|
||||||
|
|
||||||
//Bound of the bound of DZM
|
|
||||||
var boundBoundSndArg = Arrays.stream(typeParaTypes).filter(x -> x.equals(Arrays.stream(boundSndArg)
|
|
||||||
.findFirst().get())).findFirst().get().getBounds();
|
|
||||||
|
|
||||||
//boundBoundSndArg have to be a type variable (type of the local variable c)
|
|
||||||
assertEquals(true, Arrays.stream(boundBoundSndArg).findFirst().get() instanceof TypeVariable);
|
|
||||||
m.getGenericParameterTypes();
|
|
||||||
|
|
||||||
//public <DZU> DZU m2(DZU);
|
|
||||||
Method m2 = classToTest.getDeclaredMethod("m2", Object.class);
|
|
||||||
|
|
||||||
//Argumenttypes of the method m2
|
|
||||||
var paraTypesm2 = m2.getGenericParameterTypes();
|
|
||||||
|
|
||||||
//Typeparameters of the method m2
|
|
||||||
var typeParaTypesm2 = m2.getTypeParameters();
|
|
||||||
|
|
||||||
//Typeparameters are extracted from the argumenttypes
|
|
||||||
//Conditions for the extracted typeparameters are set
|
|
||||||
|
|
||||||
//paraTypes[0] = DZU
|
|
||||||
var fstArgm2 = Arrays.stream(typeParaTypesm2)
|
|
||||||
.filter(x -> x.equals(paraTypesm2[0])).findFirst().get();
|
|
||||||
|
|
||||||
//Bound of DZU has to be Object
|
|
||||||
assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get());
|
|
||||||
|
|
||||||
//DZU has to be the return type of m
|
|
||||||
assertEquals(fstArgm2, m2.getGenericReturnType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user