modified: ../../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java

modified:   ../../../../main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java
toString veraendert
	modified:   ../../../../main/java/de/dhbwstuttgart/typeinference/unify/Match.java
	modified:   ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Fall A <. theta' veraendert.

	modified:   ../../bytecode/javFiles/MatrixOP.jav
This commit is contained in:
pl@gohorb.ba-horb.de 2020-03-09 14:06:41 +01:00
parent e913bfa768
commit b38340fc60
5 changed files with 36 additions and 12 deletions

View File

@ -480,15 +480,15 @@ public class JavaTXCompiler {
final ConstraintSet<Pair> cons = getConstraints();
Set<Set<UnifyPair>> results = new HashSet<>();
try {
Writer logFile = new OutputStreamWriter(new NullOutputStream());
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
// new FileWriter(new
// File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
//new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
// + sourceFiles.keySet().iterator().next().getName()));
new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_"
+ sourceFiles.keySet().iterator().next().getName()));
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
System.out.println(finiteClosure);
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
System.out.println("xxx1");
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
UnifyType lhs, rhs;
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
@ -500,6 +500,7 @@ public class JavaTXCompiler {
return x;
};
logFile.write("Unify:" + unifyCons.toString());
System.out.println("Unify:" + unifyCons.toString());
unifyCons = unifyCons.map(distributeInnerVars);

View File

@ -6,6 +6,7 @@ import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -29,7 +30,10 @@ public class ConstraintSet<A> {
@Override
public String toString(){
return cartesianProduct().toString();
BinaryOperator<String> b = (x,y) -> x+y;
return "\nUND:" + this.undConstraints.toString() + "\n" +
"ODER:" + this.oderConstraints.stream().reduce("", (x,y) -> x.toString()+ "\n" +y, b);
//cartesianProduct().toString();
}
public Set<List<Constraint<A>>> cartesianProduct(){

View File

@ -22,6 +22,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public class Match implements IMatch {
@Override
//vorne muss das Pattern stehen
//A<X> =. A<Integer> ==> True
//A<Integer> =. A<X> ==> False
public Optional<Unifier> match(ArrayList<UnifyPair> termsList) {

View File

@ -28,6 +28,7 @@ import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.IMatch;
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
@ -172,9 +173,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
thNo = totalnoOfThread;
writeLog("thNo2 " + thNo);
try {
this.logFile = new OutputStreamWriter(new NullOutputStream());
this.logFile = //new OutputStreamWriter(new NullOutputStream());
//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
//new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
logFile.write("");
}
catch (IOException e) {
@ -2033,6 +2034,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
PlaceholderType a = (PlaceholderType)pair.getLhsType();
UnifyType thetaPrime = pair.getRhsType();
if (thetaPrime instanceof ExtendsType) {
thetaPrime = ((ExtendsType)thetaPrime).getExtendedType();
}
if (thetaPrime instanceof SuperType) {
//HIER MUSS NOCH WAS UEBERLEGT WERDEN
}
Set<Set<UnifyPair>> result = new HashSet<>();
boolean allGen = thetaPrime.getTypeParams().size() > 0;
@ -2064,13 +2073,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
return x.accept(new freshPlaceholder(), hm);
}).collect(Collectors.toCollection(HashSet::new));
IMatch match = new Match();
for(UnifyType c : csPHRenamed) {
//PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt.
Set<UnifyType> thetaQs = new HashSet<>();
//TODO smaller wieder reinnehmen?
//thetaQs.add(c);//
thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new));
ArrayList<UnifyPair> ml = new ArrayList<>();
ml.add(new UnifyPair(c, thetaPrime, PairOperator.EQUALSDOT));
if (!(match.match(ml)).isPresent()) {
thetaQs.remove(c);
}
//Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
//thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht
//PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
@ -2078,7 +2092,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//PL 18-02-06: eingefuegt, thetaQs der Form V<V<...>> <. V'<V<...>> werden entfernt
//TODO PL 19-01-14 wieder reinnehmen kurzfristig auskommentiert
thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
//thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
//PL 18-02-06: eingefuegt
Set<UnifyType> thetaQPrimes = new HashSet<>();
@ -2095,7 +2109,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
thetaQPrimes.add(c.setTypeParams(tp));
}
for(UnifyType tqp : thetaQPrimes) {
for(UnifyType tqp : thetaQPrimes) {//PL 2020-03-08 umbauen in der Schleife wird nur unifizierbarer Typ gesucht break am Ende
Collection<PlaceholderType> tphs = tqp.getInvolvedPlaceholderTypes();
Optional<Unifier> opt = stdUnify.unify(tqp, thetaPrime);
if (!opt.isPresent()) {
@ -2114,7 +2128,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
//List<UnifyType> freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben
for (UnifyType tq : thetaQs) {
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq), new HashSet<>());
//geaendert PL 20-03-07
Set<UnifyType> smaller = new HashSet<>();
smaller.add(unifier.apply(tq));
//Set<UnifyType> smaller = fc.smaller(unifier.apply(tq), new HashSet<>());
//eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen
if (a.isWildcardable()) {
Set<UnifyType> smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
@ -2161,6 +2178,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//writeLog("MAX: " + oup.max(resultPrime.iterator()).toString());
}
}
break;//Wenn ein unifier gefunden ist reicht es aus PL 2020-03-07
}
}

View File

@ -1,6 +1,6 @@
import java.util.Vector;
import java.lang.Integer;
//import java.lang.Byte;
import java.lang.Byte;
import java.lang.Boolean;
public class MatrixOP extends Vector<Vector<Integer>> {