forked from JavaTX/JavaCompilerCore
modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java zurueckumwandlung von den Unifytypen in UnifyResultModel verlegt.
This commit is contained in:
parent
396efb52de
commit
08d69ce6e3
@ -284,12 +284,13 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
final ConstraintSet<Pair> cons = getConstraints();
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
UnifyResultModel urm = new UnifyResultModel();
|
UnifyResultModel urm = null;
|
||||||
try {
|
try {
|
||||||
FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
|
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
|
urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
|
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars =
|
Function<UnifyPair, UnifyPair> distributeInnerVars =
|
||||||
@ -401,7 +402,7 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm);
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
@ -538,10 +539,10 @@ public class JavaTXCompiler {
|
|||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
if (resultmodel) {
|
if (resultmodel) {
|
||||||
/* UnifyResultModel Anfang */
|
/* UnifyResultModel Anfang */
|
||||||
UnifyResultModel urm = new UnifyResultModel();
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm);
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
||||||
System.out.println("RESULT Final: " + li.getResults());
|
System.out.println("RESULT Final: " + li.getResults());
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString()+"\n");
|
logFile.write("RES_FINAL: " + li.getResults().toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
@ -549,8 +550,8 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons);
|
Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
||||||
//Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons);
|
//Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
@ -13,23 +13,56 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
public class TypeUnify {
|
public class TypeUnify {
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet<Pair> cons) {
|
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons);
|
/**
|
||||||
|
* unify parallel ohne result modell
|
||||||
|
* @param undConstrains
|
||||||
|
* @param oderConstraints
|
||||||
|
* @param fc
|
||||||
|
* @param logFile
|
||||||
|
* @param log
|
||||||
|
* @param cons
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet<Pair> cons, UnifyResultModel ret) {
|
/**
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons);
|
* unify asynchron mit Rückgabe UnifyResultModel ohne dass alle results gesammelt sind
|
||||||
|
* @param undConstrains
|
||||||
|
* @param oderConstraints
|
||||||
|
* @param fc
|
||||||
|
* @param logFile
|
||||||
|
* @param log
|
||||||
|
* @param cons
|
||||||
|
* @param ret
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet<Pair> cons, UnifyResultModel ret) {
|
/**
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons);
|
* unify parallel mit Rückgabe UnifyResultModel nachdem alle results gesammelt sind
|
||||||
|
* @param undConstrains
|
||||||
|
* @param oderConstraints
|
||||||
|
* @param fc
|
||||||
|
* @param logFile
|
||||||
|
* @param log
|
||||||
|
* @param cons
|
||||||
|
* @param ret
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
@ -44,8 +77,18 @@ public class TypeUnify {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet<Pair> cons) {
|
/**
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, new UnifyResultModel(), cons);
|
* unify sequentiell mit oderconstraints
|
||||||
|
* @param undConstrains
|
||||||
|
* @param oderConstraints
|
||||||
|
* @param fc
|
||||||
|
* @param logFile
|
||||||
|
* @param log
|
||||||
|
* @param cons
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, UnifyResultModel ret) {
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> setToFlatten;
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet<Pair> cons) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* Fuer die Threads
|
* Fuer die Threads
|
||||||
*/
|
*/
|
||||||
UnifyResultModel urm;
|
UnifyResultModel urm;
|
||||||
ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons;
|
//ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons;
|
||||||
protected static int noOfThread = 0;
|
protected static int noOfThread = 0;
|
||||||
private static int totalnoOfThread = 0;
|
private static int totalnoOfThread = 0;
|
||||||
int thNo;
|
int thNo;
|
||||||
@ -133,7 +133,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons2) {
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||||
@ -153,16 +153,21 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.parallel = parallel;
|
this.parallel = parallel;
|
||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
|
||||||
|
noOfThread++;
|
||||||
|
totalnoOfThread++;
|
||||||
|
//writeLog("thNo1 " + thNo);
|
||||||
|
thNo = totalnoOfThread;
|
||||||
|
writeLog("thNo2 " + thNo);
|
||||||
|
try {
|
||||||
|
this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
System.err.println("log-File nicht vorhanden");
|
||||||
|
}
|
||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
this.rekTiefeField = rekTiefe;
|
this.rekTiefeField = rekTiefe;
|
||||||
this.urm = urm;
|
this.urm = urm;
|
||||||
this.cons = cons2;
|
|
||||||
|
|
||||||
noOfThread++;
|
|
||||||
totalnoOfThread++;
|
|
||||||
writeLog("thNo1 " + thNo);
|
|
||||||
thNo = totalnoOfThread;
|
|
||||||
writeLog("thNo2 " + thNo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,10 +663,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//writeLog("vor Subst: " + eqPrime);
|
//writeLog("vor Subst: " + eqPrime);
|
||||||
writeLog("vor Subst: " + oderConstraints);
|
writeLog("vor Subst: " + oderConstraints);
|
||||||
String ocString = oderConstraints.toString();
|
String ocString = oderConstraints.toString();
|
||||||
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime, oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime, newOderConstraints);
|
||||||
Set<Set<UnifyPair>> unifyres1 = null;
|
Set<Set<UnifyPair>> unifyres1 = null;
|
||||||
Set<Set<UnifyPair>> unifyres2 = null;
|
Set<Set<UnifyPair>> unifyres2 = null;
|
||||||
if (!ocString.equals(oderConstraints.toString())) writeLog("nach Subst: " + oderConstraints);
|
if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints);
|
||||||
//writeLog("nach Subst: " + eqPrimePrime);
|
//writeLog("nach Subst: " + eqPrimePrime);
|
||||||
/*
|
/*
|
||||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||||
@ -714,16 +720,17 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs ->
|
urm.notify(eqPrimePrimeSetRet);
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList()));
|
//urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs ->
|
||||||
|
// new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), oderConstraints, fc, parallel, rekTiefe);
|
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, oderConstraints, fc, parallel, rekTiefe);
|
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
@ -935,7 +942,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
@ -953,7 +960,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
@ -961,6 +968,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
noOfThread--;
|
||||||
|
writeLog("wait "+ forkOrig.thNo);
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
||||||
@ -969,6 +978,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
};
|
};
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnify2Task fork : forks) {
|
for(TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
@ -981,7 +991,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
aParDef.add(fork.getNextSetElement());
|
aParDef.add(fork.getNextSetElement());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
noOfThread++;
|
||||||
} else {
|
} else {
|
||||||
if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) {
|
if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) {
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
@ -991,7 +1002,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
@ -1009,7 +1020,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
@ -1017,6 +1028,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
noOfThread--;
|
||||||
|
writeLog("wait "+ forkOrig.thNo);
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
||||||
@ -1025,6 +1038,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
};
|
};
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnify2Task fork : forks) {
|
for(TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
@ -1038,6 +1052,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
noOfThread++;
|
||||||
} else {
|
} else {
|
||||||
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
|
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
|
||||||
writeLog("var2einstieg");
|
writeLog("var2einstieg");
|
||||||
@ -1048,7 +1063,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
@ -1064,7 +1079,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
@ -1072,6 +1087,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
noOfThread--;
|
||||||
|
writeLog("wait "+ forkOrig.thNo);
|
||||||
res = forkOrig.join();
|
res = forkOrig.join();
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
||||||
@ -1079,7 +1096,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//add_res.add(fork_res); //vermutlich falsch
|
//add_res.add(fork_res); //vermutlich falsch
|
||||||
};
|
};
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnifyTask fork : forks) {
|
for(TypeUnifyTask fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
@ -1087,8 +1104,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//noOfThread--; an das Ende von compute verschoben
|
//noOfThread--; an das Ende von compute verschoben
|
||||||
add_res.add(fork_res);
|
add_res.add(fork_res);
|
||||||
};
|
};
|
||||||
}}
|
}
|
||||||
else {
|
noOfThread++;
|
||||||
|
} else {
|
||||||
//parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten
|
//parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten
|
||||||
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
||||||
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe);
|
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe);
|
||||||
|
@ -1,13 +1,31 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
public class UnifyResultModel {
|
public class UnifyResultModel {
|
||||||
|
|
||||||
|
ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons;
|
||||||
|
|
||||||
|
IFiniteClosure fc;
|
||||||
|
|
||||||
|
public UnifyResultModel(ConstraintSet<de.dhbwstuttgart.typeinference.constraints.Pair> cons,
|
||||||
|
IFiniteClosure fc) {
|
||||||
|
this.cons = cons;
|
||||||
|
this.fc = fc;
|
||||||
|
}
|
||||||
|
|
||||||
private List<UnifyResultListener> listeners = new ArrayList<>();
|
private List<UnifyResultListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
||||||
@ -18,7 +36,20 @@ public class UnifyResultModel {
|
|||||||
listeners.remove(listenerToRemove);
|
listeners.remove(listenerToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notify(List<ResultSet> newResult) {
|
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet) {
|
||||||
|
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
||||||
|
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||||
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
|
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
||||||
|
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc);
|
||||||
|
}
|
||||||
|
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
List<ResultSet> newResult = eqPrimePrimeSetRet.stream().map(unifyPairs ->
|
||||||
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))
|
||||||
|
.collect(Collectors.toList());
|
||||||
UnifyResultEvent evt = new UnifyResultEvent(newResult);
|
UnifyResultEvent evt = new UnifyResultEvent(newResult);
|
||||||
|
|
||||||
for (UnifyResultListener listener : listeners) {
|
for (UnifyResultListener listener : listeners) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Byte;
|
//import java.lang.Byte;
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class MatrixOP extends Vector<Vector<Integer>> {
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user