modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
Nachtraegliches Einfuegen von Variance in OderConstraints auskommentiert. modified: src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java Variance im konvertieren eingefuegt modified: src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java Variace eingefuegt modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java In OderConstraints Variance bei der Erstellung eingefuegt
This commit is contained in:
parent
28400c8bde
commit
a5662cdd9a
@ -603,6 +603,7 @@ public class JavaTXCompiler {
|
||||
//Es wird davon ausgegangen, dass in OderConstraints in Bedingungen für Parameter die Typen der Argumente links stehen
|
||||
//und die Typen der Rückgabewerte immer rechts stehen
|
||||
|
||||
/*
|
||||
unifyCons.getOderConstraints().forEach(z -> z.forEach(y -> y.forEach(x -> {
|
||||
if ((x.getLhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.SMALLERDOT) == 0) {
|
||||
((PlaceholderType) x.getLhsType()).setVariance((byte)1);
|
||||
@ -611,6 +612,7 @@ public class JavaTXCompiler {
|
||||
((PlaceholderType) x.getRhsType()).setVariance((byte)-1);
|
||||
}
|
||||
})));
|
||||
*/
|
||||
|
||||
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
||||
Set<PlaceholderType> varianceTPHold;
|
||||
|
@ -122,6 +122,7 @@ public class UnifyTypeFactory {
|
||||
System.out.println("XXX"+innerType);
|
||||
}
|
||||
PlaceholderType ntph = new PlaceholderType(tph.getName());
|
||||
ntph.setVariance(tph.getVariance());
|
||||
int in = PLACEHOLDERS.indexOf(ntph);
|
||||
if (in == -1) {
|
||||
PLACEHOLDERS.add(ntph);
|
||||
|
@ -18,7 +18,8 @@ import org.antlr.v4.runtime.Token;
|
||||
public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
{
|
||||
private final String name;
|
||||
|
||||
|
||||
int variance = 0;
|
||||
|
||||
|
||||
/**
|
||||
@ -69,6 +70,14 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setVariance(int variance) {
|
||||
this.variance= variance;
|
||||
}
|
||||
|
||||
public int getVariance() {
|
||||
return this.variance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.*;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -164,7 +165,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
public void visit(MethodCall methodCall) {
|
||||
methodCall.receiver.accept(this);
|
||||
//Overloading:
|
||||
Set<Constraint> methodConstraints = new HashSet<>();
|
||||
Set<Constraint<Pair>> methodConstraints = new HashSet<>();
|
||||
for(MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)){
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
methodConstraints.add(generateConstraint(methodCall, m, info, resolver));
|
||||
@ -559,7 +560,7 @@ public class TYPEStmt implements StatementVisitor{
|
||||
|
||||
protected Constraint<Pair> generateConstraint(MethodCall forMethod, MethodAssumption assumption,
|
||||
TypeInferenceBlockInformation info, GenericsResolver resolver){
|
||||
Constraint methodConstraint = new Constraint();
|
||||
Constraint<Pair> methodConstraint = new Constraint<>();
|
||||
ClassOrInterface receiverCl = assumption.getReceiver();
|
||||
/*
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
||||
@ -572,10 +573,17 @@ public class TYPEStmt implements StatementVisitor{
|
||||
*/
|
||||
|
||||
RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver);
|
||||
methodConstraint.add(new Pair(forMethod.receiver.getType(), retType,
|
||||
RefTypeOrTPHOrWildcardOrGeneric zwSp;
|
||||
methodConstraint.add(new Pair(zwSp = forMethod.receiver.getType(), retType,
|
||||
PairOperator.SMALLERDOT));
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||
if (zwSp instanceof TypePlaceholder) {
|
||||
((TypePlaceholder) zwSp).setVariance(1);
|
||||
}
|
||||
methodConstraint.add(new Pair(assumption.getReturnType(resolver), zwSp = forMethod.getType(),
|
||||
PairOperator.EQUALSDOT));
|
||||
if (zwSp instanceof TypePlaceholder) {
|
||||
((TypePlaceholder) zwSp).setVariance(-1);
|
||||
}
|
||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||
return methodConstraint;
|
||||
}
|
||||
@ -588,6 +596,9 @@ public class TYPEStmt implements StatementVisitor{
|
||||
RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType();
|
||||
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);
|
||||
ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT));
|
||||
if (argType instanceof TypePlaceholder) {
|
||||
((TypePlaceholder) argType).setVariance(1);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user