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