forked from JavaTX/JavaCompilerCore
Occurs-Check mit Abbruch eingebaut
finalResult zum Attribut der Klasse gemacht
This commit is contained in:
parent
fec83c3a62
commit
e00d76ce3b
@ -655,7 +655,6 @@ public class RuleSet implements IRuleSet{
|
|||||||
else
|
else
|
||||||
t1.getTypeParams().forEach(x -> occuringTypes.push(x));
|
t1.getTypeParams().forEach(x -> occuringTypes.push(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
|
Queue<UnifyPair> result1 = new LinkedList<UnifyPair>(pairs);
|
||||||
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
|
ArrayList<UnifyPair> result = new ArrayList<UnifyPair>();
|
||||||
boolean applied = false;
|
boolean applied = false;
|
||||||
@ -669,6 +668,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
&& pair.getLhsType() instanceof PlaceholderType)
|
&& pair.getLhsType() instanceof PlaceholderType)
|
||||||
lhsType = (PlaceholderType) pair.getLhsType();
|
lhsType = (PlaceholderType) pair.getLhsType();
|
||||||
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
rhsType = pair.getRhsType(); //PL eingefuegt 2017-09-29 statt !((rhsType = pair.getRhsType()) instanceof PlaceholderType)
|
||||||
|
|
||||||
if(lhsType != null
|
if(lhsType != null
|
||||||
//&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
|
//&& !((rhsType = pair.getRhsType()) instanceof PlaceholderType) //PL geloescht am 2017-09-29 Begründung: auch Typvariablen muessen ersetzt werden.
|
||||||
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
|
&& typeMap.get(lhsType) > 1 // The type occurs in more pairs in the set than just the recent pair.
|
||||||
|
@ -34,7 +34,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
System.out.println("two");
|
System.out.println("two");
|
||||||
}
|
}
|
||||||
one = true;
|
one = true;
|
||||||
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true);
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField);
|
||||||
/*if (isUndefinedPairSetSet(res)) {
|
/*if (isUndefinedPairSetSet(res)) {
|
||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
|
@ -110,6 +110,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
protected boolean parallel;
|
protected boolean parallel;
|
||||||
|
|
||||||
|
//Gives if unify is not called from checkA
|
||||||
|
private boolean finalresult = true;
|
||||||
|
|
||||||
int rekTiefeField;
|
int rekTiefeField;
|
||||||
|
|
||||||
Integer nOfUnify = 0;
|
Integer nOfUnify = 0;
|
||||||
@ -257,7 +260,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
|
ArrayList<Set<Constraint<UnifyPair>>> remainingOderconstraints = oderConstraintsField.stream()
|
||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true);
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField);
|
||||||
noOfThread--;
|
noOfThread--;
|
||||||
try {
|
try {
|
||||||
logFile.close();
|
logFile.close();
|
||||||
@ -299,7 +302,7 @@ 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 Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
|
||||||
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
||||||
// ).collect(Collectors.toCollection(HashSet::new));
|
// ).collect(Collectors.toCollection(HashSet::new));
|
||||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
||||||
@ -308,9 +311,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
//.collect(Collectors.toCollection(HashSet::new)));
|
//.collect(Collectors.toCollection(HashSet::new)));
|
||||||
/*
|
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
|
||||||
*/
|
|
||||||
synchronized (usedTasks) {
|
synchronized (usedTasks) {
|
||||||
if (this.myIsCancelled()) {
|
if (this.myIsCancelled()) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
@ -339,6 +340,29 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Occurs-Check durchfuehren
|
||||||
|
*/
|
||||||
|
|
||||||
|
Set<UnifyPair> ocurrPairs = eq.stream().filter(x -> {
|
||||||
|
UnifyType lhs, rhs;
|
||||||
|
return (lhs = x.getLhsType()) instanceof PlaceholderType
|
||||||
|
&& !((rhs = x.getRhsType()) instanceof PlaceholderType)
|
||||||
|
&& rhs.getTypeParams().occurs((PlaceholderType)lhs);})
|
||||||
|
.map(x -> { x.setUndefinedPair(); return x;})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
writeLog("ocurrPairs: " + ocurrPairs);
|
||||||
|
if (ocurrPairs.size() > 0) {
|
||||||
|
Set<Set<UnifyPair>> ret = new HashSet<>();
|
||||||
|
ret.add(ocurrPairs);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
|
*/
|
||||||
Set<UnifyPair> eq0;
|
Set<UnifyPair> eq0;
|
||||||
Set<UnifyPair> eq0Prime;
|
Set<UnifyPair> eq0Prime;
|
||||||
Optional<Set<UnifyPair>> eqSubst = Optional.of(eq);
|
Optional<Set<UnifyPair>> eqSubst = Optional.of(eq);
|
||||||
@ -457,12 +481,12 @@ 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 ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, finalresult);
|
return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
//Aufruf von computeCartesianRecursive ENDE
|
//Aufruf von computeCartesianRecursive ENDE
|
||||||
|
|
||||||
//keine Ahnung woher das kommt
|
//keine Ahnung woher das kommt
|
||||||
@ -551,12 +575,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(eqPrimePrime.isPresent()) {
|
else if(eqPrimePrime.isPresent()) {
|
||||||
Set<Set<UnifyPair>> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, finalresult);
|
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, newOderConstraints, fc, parallel, rekTiefe, finalresult);
|
Set<Set<UnifyPair>> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
|
|
||||||
eqPrimePrimeSet.addAll(unifyres);
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
@ -596,10 +620,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @param fc The finite closure
|
* @param fc The finite closure
|
||||||
* @param parallel If the algorithm should be parallelized run
|
* @param parallel If the algorithm should be parallelized run
|
||||||
* @param rekTiefe Deep of recursive calls
|
* @param rekTiefe Deep of recursive calls
|
||||||
* @param finalresult Gives if unify is not called from checkA
|
|
||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
Set<Set<UnifyPair>> computeCartesianRecursive(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(ArrayList<Set<? extends Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) {
|
||||||
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||||
Set<Set<UnifyPair>> fstElems = new HashSet<>();
|
Set<Set<UnifyPair>> fstElems = new HashSet<>();
|
||||||
fstElems.addAll(topLevelSets.stream()
|
fstElems.addAll(topLevelSets.stream()
|
||||||
@ -610,7 +633,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
|
if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig
|
||||||
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult);
|
Set<Set<UnifyPair>> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
Set<? extends Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||||
@ -1173,7 +1196,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
} else {
|
} 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, finalresult);
|
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe);
|
||||||
}}}
|
}}}
|
||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
@ -1523,7 +1546,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
||||||
unitedSubst.addAll(sameEq.getAllBases());
|
unitedSubst.addAll(sameEq.getAllBases());
|
||||||
localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
||||||
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false);
|
finalresult = false;
|
||||||
|
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0);
|
||||||
|
finalresult = true;
|
||||||
if (isUndefinedPairSetSet(localRes)) {
|
if (isUndefinedPairSetSet(localRes)) {
|
||||||
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
||||||
result.addAll(localRes);
|
result.addAll(localRes);
|
||||||
@ -1539,7 +1564,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
unitedSubst.addAll(sameEq.getAllSubstitutions());
|
||||||
unitedSubst.addAll(sameEq.getAllBases());
|
unitedSubst.addAll(sameEq.getAllBases());
|
||||||
localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null));
|
||||||
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, false);
|
finalresult = false;
|
||||||
|
Set<Set<UnifyPair>> localRes = unify(localEq, new ArrayList<>(), fc, false, 0);
|
||||||
|
finalresult = true;
|
||||||
if (isUndefinedPairSetSet(localRes)) {
|
if (isUndefinedPairSetSet(localRes)) {
|
||||||
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
if (result.isEmpty() || isUndefinedPairSetSet(result)) {
|
||||||
result.addAll(localRes);
|
result.addAll(localRes);
|
||||||
@ -2519,7 +2546,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
synchronized ( this ) {
|
synchronized ( this ) {
|
||||||
if (log) {
|
if (log && finalresult) {
|
||||||
try {
|
try {
|
||||||
logFile.write("Thread no.:" + thNo + "\n");
|
logFile.write("Thread no.:" + thNo + "\n");
|
||||||
logFile.write("noOfThread:" + noOfThread + "\n");
|
logFile.write("noOfThread:" + noOfThread + "\n");
|
||||||
|
@ -40,7 +40,8 @@ public class AllgemeinTest {
|
|||||||
//String className = "FCTest3";
|
//String className = "FCTest3";
|
||||||
//String className = "Var";
|
//String className = "Var";
|
||||||
//String className = "Put";
|
//String className = "Put";
|
||||||
String className = "Twice";
|
//String className = "Twice";
|
||||||
|
String className = "TestSubTypless";
|
||||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav";
|
||||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
Loading…
Reference in New Issue
Block a user