modified: src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java

modified:   src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
This commit is contained in:
pl@gohorb.ba-horb.de 2020-03-26 12:44:56 +01:00
parent 850af6a6ae
commit eca187da79
5 changed files with 108 additions and 18 deletions

View File

@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.type.*;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.Iterator; import java.util.Iterator;
import java.util.Optional;
public class OutputGenerator implements ASTVisitor{ public class OutputGenerator implements ASTVisitor{
private static final String TAB = " "; private static final String TAB = " ";
@ -123,6 +124,11 @@ public class OutputGenerator implements ASTVisitor{
f.accept(this); f.accept(this);
out.append("\n"); out.append("\n");
} }
Optional<Constructor> fI;
if ((fI = classOrInterface.getfieldInitializations()).isPresent()) {
out.append("Initializations:");
fI.get().accept(this);
}
for(Method m : classOrInterface.getMethods()){ for(Method m : classOrInterface.getMethods()){
out.append(tabs); out.append(tabs);
m.accept(this); m.accept(this);

View File

@ -169,6 +169,13 @@ public class TYPEStmt implements StatementVisitor{
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));
resolver = getResolverInstance();
Constraint<Pair> oneMethodConstraint = generateConstraint(methodCall, m, info, resolver);
oneMethodConstraint = oneMethodConstraint.stream().map(x -> (x.TA1 instanceof TypePlaceholder && x.GetOperator() == PairOperator.EQUALSDOT &&
!(x.TA2 instanceof TypePlaceholder)) ?
new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) :
x).collect(Collectors.toCollection(Constraint::new));
methodConstraints.add(oneMethodConstraint);
} }
if(methodConstraints.size()<1){ if(methodConstraints.size()<1){
throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset()); throw new TypeinferenceException("Methode "+methodCall.name+" ist nicht vorhanden!",methodCall.getOffset());

View File

@ -639,7 +639,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
.filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType && .filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType &&
x.getRhsType() instanceof ReferenceType && x.getRhsType() instanceof ReferenceType &&
x.getPairOp() == PairOperator.EQUALSDOT) x.getPairOp() == PairOperator.EQUALSDOT)
.map(x -> ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance()) .map(x ->
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
.findAny(); .findAny();
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt //Fuer Operatorenaufrufe wird variance auf 2 gesetzt
//Es werden alle Elemente des Kartesischen Produkts abgearbeitet //Es werden alle Elemente des Kartesischen Produkts abgearbeitet
@ -671,6 +672,27 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
a_next = nextSetasList.iterator().next(); a_next = nextSetasList.iterator().next();
} }
*/ */
if (variance == 2) {
writeLog("VARIANCE2 " + nextSetasList.toString());
Set<UnifyPair> XX = nextSetasList.iterator()
.next()
.stream()
.filter(x ->
x.getGroundBasePair().getLhsType() instanceof PlaceholderType &&
! (x.getRhsType() instanceof PlaceholderType) &&
x.getPairOp() == PairOperator.EQUALSDOT)
.collect(Collectors.toCollection(HashSet::new));
Set<Integer> sI = XX.stream()
.map(x ->
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
.collect(Collectors.toCollection(HashSet::new));;
Optional<Integer> oI = sI.stream()
.findAny();
variance = oI.isPresent() ? oI.get() : 2;
System.out.println("");
}
if (!nextSetasList.iterator().hasNext()) if (!nextSetasList.iterator().hasNext())
System.out.print(""); System.out.print("");
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.BinaryOperator; import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -44,7 +45,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
}} }}
catch (ClassCastException e) { catch (ClassCastException e) {
try { try {
((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() +"\n\n"); ((FiniteClosure)fc).logFile.write("ClassCastException: " + left.toString() + " " + left.getGroundBasePair() + "\n\n");
((FiniteClosure)fc).logFile.flush(); ((FiniteClosure)fc).logFile.flush();
} }
catch (IOException ie) { catch (IOException ie) {
@ -197,17 +198,42 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
//} //}
//ODER-CONSTRAINT //ODER-CONSTRAINT
Set<UnifyPair> lefteqOder = lefteq.stream() Set<UnifyPair> leftBase = left.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof ReferenceType)) Set<UnifyPair> rightBase = right.stream().map(x -> x.getGroundBasePair()).collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> lefteqOder = left.stream()
.filter(x -> { UnifyPair y = x.getGroundBasePair();
try {
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
((FiniteClosure)fc).logFile.write("y: " + y.toString() +"\n");
((FiniteClosure)fc).logFile.write("y.getLhsType() : " + y.getLhsType() .toString() +"\n\n");
((FiniteClosure)fc).logFile.write("y.getRhsType(): " + y.getRhsType().toString() +"\n");
((FiniteClosure)fc).logFile.write("x.getPairOp(): " + x.getPairOp().toString() +"\n\n");
}
catch (IOException ie) {
}
return (y.getLhsType() instanceof PlaceholderType &&
y.getRhsType() instanceof ReferenceType &&
x.getPairOp() == PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> righteqOder = righteq.stream() Set<UnifyPair> righteqOder = right.stream()
.filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getRhsType() instanceof ReferenceType)) .filter(x -> { UnifyPair y = x.getGroundBasePair();
return (y.getLhsType() instanceof PlaceholderType &&
y.getRhsType() instanceof ReferenceType &&
x.getPairOp() == PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> lefteqRet = left.stream() Set<UnifyPair> lefteqRet = left.stream()
.filter(x -> (x.getRhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) .filter(x -> { UnifyPair y = x.getGroundBasePair();
return (y.getRhsType() instanceof PlaceholderType &&
x.getPairOp() == PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> righteqRet = right.stream() Set<UnifyPair> righteqRet = right.stream()
.filter(x -> (x.getRhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) .filter(x -> { UnifyPair y = x.getGroundBasePair();
return (y.getRhsType() instanceof PlaceholderType &&
x.getPairOp() == PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> leftleOder = left.stream() Set<UnifyPair> leftleOder = left.stream()
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT)) .filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
@ -215,12 +241,36 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
Set<UnifyPair> rightleOder = right.stream() Set<UnifyPair> rightleOder = right.stream()
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT)) .filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
synchronized(this) {
try {
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
((FiniteClosure)fc).logFile.write("rightBase: " + rightBase.toString() +"\n\n");
((FiniteClosure)fc).logFile.write("left: " + left.toString() +"\n");
((FiniteClosure)fc).logFile.write("right: " + right.toString() +"\n\n");
((FiniteClosure)fc).logFile.write("lefteqOder: " + lefteqOder.toString() +"\n");
((FiniteClosure)fc).logFile.write("righteqOder: " + righteqOder.toString() +"\n\n");
((FiniteClosure)fc).logFile.write("lefteqRet: " + lefteqRet.toString() +"\n");
((FiniteClosure)fc).logFile.write("righteqRet: " + righteqRet.toString() +"\n\n");
((FiniteClosure)fc).logFile.write("leftleOder: " + leftleOder.toString() +"\n");
((FiniteClosure)fc).logFile.write("rightleOder: " + rightleOder.toString() +"\n\n");
((FiniteClosure)fc).logFile.flush();
}
catch (IOException ie) {
}
}
if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) { if (lefteqOder.size() == 1 && righteqOder.size() == 1 && lefteqRet.size() == 1 && righteqRet.size() == 1) {
Match m = new Match(); Match m = new Match();
if (compareEq(lefteqOder.iterator().next(), righteqOder.iterator().next()) == -1) { if (compareEq(lefteqOder.iterator().next().getGroundBasePair(), righteqOder.iterator().next().getGroundBasePair()) == -1) {
ArrayList<UnifyPair> matchList = ArrayList<UnifyPair> matchList =
leftleOder.stream().map(x -> { Iterator<UnifyPair> rightleOderIt = rightleOder.iterator(); leftleOder.stream().map(x -> {
return new UnifyPair(x.getRhsType(), rightleOderIt.next().getRhsType(), PairOperator.EQUALSDOT);}) UnifyPair rightElem = rightleOder.stream()
.filter(y -> y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
.findAny().get();
return new UnifyPair(x.getRhsType(), rightElem.getRhsType(), PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
if (m.match(matchList).isPresent()) { if (m.match(matchList).isPresent()) {
return -1; return -1;
@ -228,10 +278,13 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
else { else {
return 0; return 0;
} }
} else if (compareEq(lefteqOder.iterator().next(), righteqOder.iterator().next()) == 1) { } else if (compareEq(lefteqOder.iterator().next().getGroundBasePair(), righteqOder.iterator().next().getGroundBasePair()) == 1) {
ArrayList<UnifyPair> matchList = ArrayList<UnifyPair> matchList =
rightleOder.stream().map(x -> { Iterator<UnifyPair> leftOderIt = leftleOder.iterator(); rightleOder.stream().map(x -> {
return new UnifyPair(x.getRhsType(), leftOderIt.next().getRhsType(), PairOperator.EQUALSDOT);}) UnifyPair leftElem = leftleOder.stream()
.filter(y -> y.getGroundBasePair().getLhsType().equals(x.getGroundBasePair().getLhsType()))
.findAny().get();
return new UnifyPair(x.getRhsType(), leftElem.getRhsType(), PairOperator.EQUALSDOT);})
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
if (m.match(matchList).isPresent()) { if (m.match(matchList).isPresent()) {
return 1; return 1;

View File

@ -217,12 +217,14 @@ public class UnifyPair {
public String toString() { public String toString() {
String ret = ""; String ret = "";
if (lhs instanceof PlaceholderType) { if (lhs instanceof PlaceholderType) {
ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType() ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " "
+ " " + ((PlaceholderType)lhs).isWildcardable(); + "WC: " + ((PlaceholderType)lhs).isWildcardable()
+ ", IT: " + ((PlaceholderType)lhs).isInnerType();
} }
if (rhs instanceof PlaceholderType) { if (rhs instanceof PlaceholderType) {
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType() ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " "
+ " " + ((PlaceholderType)rhs).isWildcardable(); + "WC: " + ((PlaceholderType)rhs).isWildcardable()
+ ", IT: " + ((PlaceholderType)rhs).isInnerType();
} }
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])";
} }