forked from JavaTX/JavaCompilerCore
Refactoring Backup. Not usable.
This commit is contained in:
parent
fc4d3abfe9
commit
c0c1cbd4b1
@ -46,9 +46,6 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -372,8 +369,6 @@ public class JavaTXCompiler {
|
|||||||
if (resultmodel) {
|
if (resultmodel) {
|
||||||
/* UnifyResultModel Anfang */
|
/* UnifyResultModel Anfang */
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
|
||||||
urm.addUnifyResultListener(li);
|
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, 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");
|
||||||
@ -537,6 +532,10 @@ public class JavaTXCompiler {
|
|||||||
/**
|
/**
|
||||||
* @param path - can be null, then class file output is in the same directory as the parsed source files
|
* @param path - can be null, then class file output is in the same directory as the parsed source files
|
||||||
*/
|
*/
|
||||||
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = getGeneratedGenericResultsForAllSourceFiles(
|
||||||
|
typeinferenceResult);
|
||||||
|
generateBytecode(path, typeinferenceResult, simplifyResultsForAllSourceFiles);
|
||||||
public void generateBytecode(File path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
public void generateBytecode(File path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
||||||
List<ResultSet> typeinferenceResult = this.typeInference();
|
List<ResultSet> typeinferenceResult = this.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = getGeneratedGenericResultsForAllSourceFiles(
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = getGeneratedGenericResultsForAllSourceFiles(
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class TypeUnify2Future {
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
|
public TypeUnify2Future(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
||||||
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
|
this.setToFlatten = setToFlatten;
|
||||||
|
this.nextSetElement = nextSetElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<UnifyPair> getNextSetElement() {
|
||||||
|
return nextSetElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -60,7 +60,33 @@ import com.google.common.collect.Ordering;
|
|||||||
* Implementation of the type unification algorithm
|
* Implementation of the type unification algorithm
|
||||||
* @author Florian Steurer
|
* @author Florian Steurer
|
||||||
*/
|
*/
|
||||||
public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
public class TypeUnifyTask {
|
||||||
|
|
||||||
|
public static Set<Set<UnifyPair>> typeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm){
|
||||||
|
Set<UnifyPair> neweq = new HashSet<>(eq);
|
||||||
|
/* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */
|
||||||
|
oderConstraints.stream()
|
||||||
|
.filter(x -> x.size()==1)
|
||||||
|
.map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x));
|
||||||
|
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraints.stream()
|
||||||
|
.filter(x -> x.size()>1)
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefe, true);
|
||||||
|
try {
|
||||||
|
logFile.close();
|
||||||
|
}
|
||||||
|
catch (IOException ioE) {
|
||||||
|
System.err.println("no log-File");
|
||||||
|
}
|
||||||
|
if (isUndefinedPairSetSet(res)) {
|
||||||
|
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static int i = 0;
|
private static int i = 0;
|
||||||
@ -71,7 +97,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde
|
* Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde
|
||||||
*/
|
*/
|
||||||
Set<UnifyPair> nextSetElement;
|
Set<UnifyPair> nextSetElement;
|
||||||
|
Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm
|
||||||
/**
|
/**
|
||||||
* Fuer die Threads
|
* Fuer die Threads
|
||||||
*/
|
*/
|
||||||
@ -210,12 +236,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @param fc The finite closure
|
* @param fc The finite closure
|
||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
protected static Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
|
|
||||||
rekTiefe++;
|
rekTiefe++;
|
||||||
nOfUnify++;
|
|
||||||
writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
|
||||||
writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString());
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variancen auf alle Gleichungen vererben
|
* Variancen auf alle Gleichungen vererben
|
||||||
@ -352,7 +375,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
//Aufruf von computeCartesianRecursive ANFANG
|
//Aufruf von computeCartesianRecursive ANFANG
|
||||||
//writeLog("topLevelSets: " + topLevelSets.toString());
|
//writeLog("topLevelSets: " + topLevelSets.toString());
|
||||||
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult);
|
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, rekTiefe, finalresult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,17 +383,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
//Aufruf von computeCartesianRecursive ENDE
|
//Aufruf von computeCartesianRecursive ENDE
|
||||||
|
|
||||||
//keine Ahnung woher das kommt
|
|
||||||
//Set<Set<UnifyPair>> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
|
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG
|
|
||||||
// Cartesian product over all (up to 10) top level sets
|
|
||||||
//Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
|
||||||
// .stream().map(x -> new HashSet<>(x))
|
|
||||||
// .collect(Collectors.toCollection(HashSet::new));
|
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
@ -393,47 +406,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> unifyres1 = null;
|
Set<Set<UnifyPair>> unifyres1 = null;
|
||||||
Set<Set<UnifyPair>> unifyres2 = null;
|
Set<Set<UnifyPair>> unifyres2 = null;
|
||||||
if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints);
|
if (!ocString.equals(newOderConstraints.toString())) writeLog("nach Subst: " + newOderConstraints);
|
||||||
//writeLog("nach Subst: " + eqPrimePrime);
|
|
||||||
/*
|
|
||||||
* Step 6 a) Restart (fork) for pairs where subst was applied
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
if(parallel) {
|
|
||||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()
|
|
||||||
&& oderConstraints.isEmpty()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
|
||||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
|
||||||
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
|
||||||
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
|
||||||
eqPrimePrimeSet.add(eqPrime);
|
|
||||||
else if(eqPrimePrime.isPresent()) {
|
|
||||||
//System.out.println("nextStep: " + eqPrimePrime.get());
|
|
||||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile, log);
|
|
||||||
forks.add(fork);
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//System.out.println("nextStep: " + eqPrime);
|
|
||||||
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile, log);
|
|
||||||
forks.add(fork);
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else */
|
|
||||||
{// sequentiell (Step 6b is included)
|
{// sequentiell (Step 6b is included)
|
||||||
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
|
||||||
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()
|
if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()
|
||||||
&& oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch
|
&& oderConstraints.isEmpty()) {
|
||||||
//PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent())
|
|
||||||
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
|
||||||
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
|
||||||
//try {
|
|
||||||
//if (isSolvedForm(eqPrime)) {
|
|
||||||
// writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
|
||||||
//}
|
|
||||||
//}
|
|
||||||
//catch (IOException e) {
|
|
||||||
// System.err.println("log-File nicht vorhanden");
|
|
||||||
//}
|
|
||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
if (finalresult && isSolvedForm(eqPrime)) {
|
if (finalresult && isSolvedForm(eqPrime)) {
|
||||||
writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
||||||
@ -452,23 +427,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG
|
|
||||||
//}
|
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Step 6 b) Build the union over everything.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* PL 2019-01-22: geloescht
|
|
||||||
|
|
||||||
if(parallel)
|
|
||||||
for(TypeUnifyTask fork : forks)
|
|
||||||
eqPrimePrimeSet.addAll(fork.join());
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Step 7: Filter empty sets;
|
|
||||||
*/
|
|
||||||
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new));
|
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());
|
writeLog("Result1 " + eqPrimePrimeSet.toString());
|
||||||
@ -478,9 +436,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, int rekTiefe, Boolean finalresult) {
|
||||||
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
|
||||||
|
|
||||||
fstElems.addAll(topLevelSets.stream()
|
fstElems.addAll(topLevelSets.stream()
|
||||||
.filter(x -> x.size()==1)
|
.filter(x -> x.size()==1)
|
||||||
.map(y -> y.stream().findFirst().get())
|
.map(y -> y.stream().findFirst().get())
|
||||||
@ -493,17 +449,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||||
//writeLog("nextSet: " + nextSet.toString());
|
|
||||||
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
List<Set<UnifyPair>> nextSetasList =new ArrayList<>(nextSet);
|
||||||
/*
|
|
||||||
try {
|
|
||||||
//List<Set<UnifyPair>>
|
|
||||||
//nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet);
|
|
||||||
}
|
|
||||||
catch (java.lang.IllegalArgumentException e) {
|
|
||||||
System.out.print("");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
int variance = 0;
|
int variance = 0;
|
||||||
|
|
||||||
@ -560,25 +507,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
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)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
//writeLog("nextSetasList: " + nextSetasList.toString());
|
|
||||||
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
||||||
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
|
||||||
|
|
||||||
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */
|
/* sameEqSet-Bestimmung: Wenn a = ty \in nextSet dann enthaelt sameEqSet alle Paare a < ty1 oder ty2 < a aus fstElems */
|
||||||
Set<UnifyPair> sameEqSet = new HashSet<>();
|
Set<UnifyPair> sameEqSet = new HashSet<>();
|
||||||
Optional<UnifyPair> optOrigPair = null;
|
Optional<UnifyPair> optOrigPair = null;
|
||||||
//if (variance != 2) {
|
//if (variance != 2) {
|
||||||
if (!oderConstraint) {
|
if (!oderConstraint) {
|
||||||
optOrigPair = nextSetElem.stream().filter(x -> (
|
optOrigPair = nextSetElem.stream().filter(x -> (
|
||||||
//x.getBasePair() != null && ist gegeben wenn variance != 2
|
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
||||||
//x.getBasePair().getPairOp().equals(PairOperator.SMALLERDOT) &&
|
|
||||||
(x.getPairOp().equals(PairOperator.EQUALSDOT)
|
|
||||||
/*
|
|
||||||
(x.getBasePair().getLhsType() instanceof PlaceholderType
|
|
||||||
&& x.getLhsType().equals(x.getBasePair().getLhsType()))
|
|
||||||
|| (x.getBasePair().getRhsType() instanceof PlaceholderType
|
|
||||||
&& x.getLhsType().equals(x.getBasePair().getRhsType())
|
|
||||||
*/
|
|
||||||
))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist
|
))).filter(x -> //Sicherstellen, dass bei a = ty a auch wirklich die gesuchte Typvariable ist
|
||||||
x.getLhsType().equals(x.getBasePair().getLhsType()) ||
|
x.getLhsType().equals(x.getBasePair().getLhsType()) ||
|
||||||
x.getLhsType().equals(x.getBasePair().getRhsType())
|
x.getLhsType().equals(x.getBasePair().getRhsType())
|
||||||
@ -735,7 +672,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, usedTasks);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
@ -785,41 +722,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<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, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
res = forkOrig.join();
|
||||||
synchronized (this) {
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
|
||||||
noOfThread--;
|
|
||||||
res = forkOrig.join();
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
forkOrig.writeLog("final Orig 1");
|
|
||||||
forkOrig.closeLogFile();
|
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
|
||||||
//add_res.add(fork_res);
|
|
||||||
};
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
|
||||||
for(TypeUnify2Task fork : forks) {
|
for(TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
noOfThread--;
|
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||||
synchronized (usedTasks) {
|
synchronized (usedTasks) {
|
||||||
if (this.myIsCancelled()) {
|
if (this.myIsCancelled()) {
|
||||||
@ -836,28 +746,18 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
aParDef.add(fork.getNextSetElement());
|
aParDef.add(fork.getNextSetElement());
|
||||||
}
|
}
|
||||||
fork.writeLog("final 1");
|
fork.writeLog("final 1");
|
||||||
fork.closeLogFile();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//noOfThread++;
|
//noOfThread++;
|
||||||
} else {
|
} else {
|
||||||
if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) {
|
if((variance == -1)) {
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
|
||||||
//forks.add(forkOrig);
|
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
writeLog("a in " + variance + " "+ a);
|
writeLog("a in " + variance + " "+ a);
|
||||||
@ -1512,7 +1412,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return true;}).reduce((xx, yy) -> xx || yy).get();
|
return true;}).reduce((xx, yy) -> xx || yy).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
|
protected static boolean isUndefinedPairSet(Set<UnifyPair> s) {
|
||||||
if (s.size() >= 1 ) {
|
if (s.size() >= 1 ) {
|
||||||
Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y));
|
Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y));
|
||||||
return ret;
|
return ret;
|
||||||
@ -1522,7 +1422,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isUndefinedPairSetSet(Set<Set<UnifyPair>> s) {
|
protected static boolean isUndefinedPairSetSet(Set<Set<UnifyPair>> s) {
|
||||||
if (s.size() >= 1) {
|
if (s.size() >= 1) {
|
||||||
Boolean ret = s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x,y)-> (x && y));
|
Boolean ret = s.stream(). map(x -> isUndefinedPairSet(x)).reduce(true, (x,y)-> (x && y));
|
||||||
return ret;
|
return ret;
|
||||||
@ -1581,7 +1481,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/*
|
/*
|
||||||
* Apply rules until the queue is empty
|
* Apply rules until the queue is empty
|
||||||
*/
|
*/
|
||||||
while(!eqQueue.isEmpty()) {
|
while(!eqQueue.isEmpty()) {
|
||||||
UnifyPair pair = eqQueue.pollFirst();
|
UnifyPair pair = eqQueue.pollFirst();
|
||||||
|
|
||||||
// ReduceUp, ReduceLow, ReduceUpLow
|
// ReduceUp, ReduceLow, ReduceUpLow
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
|
|
||||||
public class UnifyResultEvent {
|
|
||||||
|
|
||||||
private List<ResultSet> newTypeResult;
|
|
||||||
|
|
||||||
public UnifyResultEvent(List<ResultSet> newTypeResult) {
|
|
||||||
this.newTypeResult = newTypeResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ResultSet> getNewTypeResult() {
|
|
||||||
return newTypeResult;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
public interface UnifyResultListener {
|
|
||||||
|
|
||||||
void onNewTypeResultFound(UnifyResultEvent evt);
|
|
||||||
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
|
||||||
|
|
||||||
public class UnifyResultListenerImpl implements UnifyResultListener {
|
|
||||||
|
|
||||||
List<ResultSet> results = new ArrayList<>();
|
|
||||||
|
|
||||||
public synchronized void onNewTypeResultFound(UnifyResultEvent evt) {
|
|
||||||
results.addAll(evt.getNewTypeResult());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ResultSet> getResults() {
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
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.unify.interfaces.IFiniteClosure;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
|
||||||
|
|
||||||
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<>();
|
|
||||||
|
|
||||||
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
|
||||||
listeners.add(listenerToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
|
|
||||||
listeners.remove(listenerToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
for (UnifyResultListener listener : listeners) {
|
|
||||||
listener.onNewTypeResultFound(evt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -29,8 +29,6 @@ public class UnifyPair {
|
|||||||
*/
|
*/
|
||||||
private PairOperator pairOp;
|
private PairOperator pairOp;
|
||||||
|
|
||||||
private boolean undefinedPair = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unifier/substitute that generated this pair
|
* Unifier/substitute that generated this pair
|
||||||
* PL 2018-03-15
|
* PL 2018-03-15
|
||||||
@ -114,10 +112,7 @@ public class UnifyPair {
|
|||||||
public void addSubstitutions(Set<UnifyPair> sup) {
|
public void addSubstitutions(Set<UnifyPair> sup) {
|
||||||
substitution.addAll(sup);
|
substitution.addAll(sup);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUndefinedPair() {
|
|
||||||
undefinedPair = true;
|
|
||||||
}
|
|
||||||
public Set<UnifyPair> getSubstitution() {
|
public Set<UnifyPair> getSubstitution() {
|
||||||
return new HashSet<>(substitution);
|
return new HashSet<>(substitution);
|
||||||
}
|
}
|
||||||
@ -125,10 +120,6 @@ public class UnifyPair {
|
|||||||
public UnifyPair getBasePair() {
|
public UnifyPair getBasePair() {
|
||||||
return basePair;
|
return basePair;
|
||||||
}
|
}
|
||||||
public boolean isUndefinedPair() {
|
|
||||||
return undefinedPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<UnifyPair> getAllSubstitutions () {
|
public Set<UnifyPair> getAllSubstitutions () {
|
||||||
Set<UnifyPair> ret = new HashSet<>();
|
Set<UnifyPair> ret = new HashSet<>();
|
||||||
ret.addAll(new ArrayList<>(getSubstitution()));
|
ret.addAll(new ArrayList<>(getSubstitution()));
|
||||||
|
Loading…
Reference in New Issue
Block a user