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

modified:   ../../src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
	modified:   ../../test/bytecode/javFiles/Matrix.jav
	modified:   ../../test/bytecode/javFiles/applyLambda.jav
? extends gen_nv =. ? super gen_nv sind in den RES
This commit is contained in:
Martin Plümicke 2018-08-05 15:05:17 +02:00
parent 883ab50f94
commit 3e4e66d60d
6 changed files with 85 additions and 24 deletions

View File

@ -24,6 +24,7 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
@ -38,7 +39,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public class JavaTXCompiler {
final boolean parallel = false;
final CompilationEnvironment environment;
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
@ -117,6 +118,7 @@ public class JavaTXCompiler {
logFile.write(ASTTypePrinter.print(sf));
}
logFile.flush();
Set<TypeUnifyTask> forks = new HashSet<>();
Set<List<Constraint<UnifyPair>>> cardProd = unifyCons.cartesianProduct();
for (List<Constraint<UnifyPair>> xCons : cardProd ){
Set<UnifyPair> xConsSet = new HashSet<>();
@ -175,15 +177,39 @@ public class JavaTXCompiler {
return y; } )
.collect(Collectors.toCollection(HashSet::new));
varianceInheritance(xConsSet);
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure, logFile, log);
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
}
catch (IOException e) { }
if (parallel) {
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
Set<UnifyPair> eq = new HashSet<>(xConsSet);
TypeUnifyTask fork = new TypeUnifyTask(eq, finiteClosure, true, logFile, log);
forks.add(fork);
fork.fork();
}
else {
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
}
for (TypeUnifyTask fork : forks) {
try {
Set<Set<UnifyPair>> result = fork.join();
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
catch (ConcurrentModificationException v) {
v.printStackTrace();
while (v.getCause() instanceof ConcurrentModificationException) {
v = (ConcurrentModificationException)v.getCause();
}
System.out.println(v);
}
}
}
catch (IOException e) { }
return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());

View File

@ -198,7 +198,9 @@ public class UnifyTypeFactory {
}else if(tr instanceof WildcardType){
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
}else throw new NotImplementedException();
}else throw new NotImplementedException();
}else {
throw new NotImplementedException();
}
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {

View File

@ -18,6 +18,10 @@ public class TypeUnify2Task extends TypeUnifyTask {
@Override
protected Set<Set<UnifyPair>> compute() {
if (one) {
System.out.println("two");
}
one = true;
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, fc, parallel);
/*if (isUndefinedPairSetSet(res)) {
return new HashSet<>(); }

View File

@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
import java.io.File;
@ -54,6 +55,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
FileWriter logFile;
protected boolean one = false;
/**
* The implementation of setOps that will be used during the unification
@ -139,6 +142,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/
@Override
protected Set<Set<UnifyPair>> compute() {
if (one) {
System.out.println("two");
}
one = true;
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
else return res;
@ -317,6 +324,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/
//System.out.println("vor Subst: " + eqPrime);
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
Set<Set<UnifyPair>> unifyres1 = null;
Set<Set<UnifyPair>> unifyres2 = null;
/*
* Step 6 a) Restart (fork) for pairs where subst was applied
@ -358,12 +367,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
eqPrimePrimeSet.add(eqPrime);
}
else if(eqPrimePrime.isPresent()) {
Set<Set<UnifyPair>> unifyres = unify(eqPrimePrime.get(), fc, parallel);
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), fc, parallel);
eqPrimePrimeSet.addAll(unifyres);
}
else {
Set<Set<UnifyPair>> unifyres = unify(eqPrime, fc, parallel);
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, fc, parallel);
eqPrimePrimeSet.addAll(unifyres);
@ -386,8 +395,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* Step 7: Filter empty sets;
*/
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet))
if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) {
writeLog("Result1 " + eqPrimePrimeSet.toString());
Iterator<UnifyPair> upit = eqPrimePrimeSet.iterator().next().iterator();
if (upit.next().getLhsType() instanceof WildcardType
|| upit.next().getLhsType() instanceof WildcardType) {
System.out.println("");
}
}
return eqPrimePrimeSet;
}
@ -523,16 +538,26 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<TypeUnifyTask> forks = new HashSet<>();
//TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log);
Set<UnifyPair> newEq = new HashSet<>(eq);
for(Set<UnifyPair> nSaL : nextSetasListRest) {
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
newElemsOrig.add(a);
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, fc, parallel, logFile, log);
forks.add(forkOrig);
forkOrig.fork();
while (!nextSetasListRest.isEmpty()) {
Set<UnifyPair> nSaL = nextSetasListRest.remove(0);
Set<UnifyPair> newEq = new HashSet<>(eq);
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
newElems.add(nSaL);
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, fc, parallel, logFile, log);
forks.add(fork);
fork.fork();
}
res = unify2(elems, eq, fc, parallel);
//res = fork1.join();
//res = unify2(elems, eq, fc, parallel);
res = forkOrig.join();
for(TypeUnifyTask fork : forks) {
Set<Set<UnifyPair>> fork_res = fork.join();
add_res.addAll(fork_res);
@ -546,12 +571,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
result = res;
if (res.iterator().next() instanceof WildcardType) {
System.out.println("");
}
}
else {
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|| result.isEmpty()) {
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
writeLog("RESADD:" + result.toString() + " " + res.toString());
result.addAll(res);
}
//else {
@ -1189,8 +1218,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
allGen = false;
break;
}
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded());
for(UnifyType thetaS : fc.greater(theta, fBounded/*pair.getfBounded()*/)) {
Set<UnifyPair> resultPrime = new HashSet<>();
Match match = new Match();
@ -1198,7 +1227,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
for(int i = 0; !allGen && i < freshTphs.length; i++) {
freshTphs[i] = PlaceholderType.freshPlaceholder();
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
Set<UnifyType> fBounded = pair.getfBounded();
//Set<UnifyType> fBounded = pair.getfBounded();
int i_ef = i;
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->

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 Matrix extends Vector<Vector<Integer>> {

View File

@ -8,8 +8,8 @@ public class applyLambda {
return x;
};
return lam1.apply(new Apply());
//return lam1;
//return lam1.apply(new Apply());
return lam1;
//return new Vector();
}
}