forked from JavaTX/JavaCompilerCore
modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
typeInference <-> typeInferenceOld modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java compute <-> computeOld
This commit is contained in:
parent
225f380735
commit
6dce7058a0
@ -103,7 +103,7 @@ public class JavaTXCompiler {
|
|||||||
return new ArrayList<>(allClasses);
|
return new ArrayList<>(allClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
public List<ResultSet> typeInferenceOld() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for(SourceFile sf : this.sourceFiles.values()) {
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
@ -215,8 +215,41 @@ public class JavaTXCompiler {
|
|||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
||||||
|
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
|
* @param eq The set of constraints
|
||||||
|
*/
|
||||||
|
private void varianceInheritance(Set<UnifyPair> eq) {
|
||||||
|
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||||
|
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||||
|
Set<PlaceholderType> pair = new HashSet<>();
|
||||||
|
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
||||||
|
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
||||||
|
return pair;
|
||||||
|
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
||||||
|
|
||||||
|
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
||||||
|
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
||||||
|
while(!phSetVariance.isEmpty()) {
|
||||||
|
PlaceholderType a = phSetVariance.remove(0);
|
||||||
|
usedTPH.add(a);
|
||||||
|
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
||||||
|
//ht.put(a, a.getVariance());
|
||||||
|
Set<UnifyPair> eq1 = new HashSet<>(eq);
|
||||||
|
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
||||||
|
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
|
||||||
|
eq1 = new HashSet<>(eq);
|
||||||
|
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
||||||
|
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
|
||||||
|
phSetVariance = new ArrayList<>(phSet);
|
||||||
|
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<ResultSet> typeInferenceNew() throws ClassNotFoundException {
|
|
||||||
|
public List<ResultSet> typeInference() throws ClassNotFoundException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
|
||||||
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
//Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
||||||
for(SourceFile sf : this.sourceFiles.values()) {
|
for(SourceFile sf : this.sourceFiles.values()) {
|
||||||
@ -292,7 +325,7 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return y; } );
|
return y; } );
|
||||||
varianceInheritanceConstrainSet(unifyCons);
|
varianceInheritanceConstraintSet(unifyCons);
|
||||||
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
//Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log);
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log);
|
||||||
@ -321,44 +354,13 @@ public class JavaTXCompiler {
|
|||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
|
||||||
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
|
||||||
* @param eq The set of constraints
|
|
||||||
*/
|
|
||||||
private void varianceInheritance(Set<UnifyPair> eq) {
|
|
||||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
|
||||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
|
||||||
Set<PlaceholderType> pair = new HashSet<>();
|
|
||||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
|
||||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
|
||||||
return pair;
|
|
||||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
|
||||||
|
|
||||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
|
||||||
while(!phSetVariance.isEmpty()) {
|
|
||||||
PlaceholderType a = phSetVariance.remove(0);
|
|
||||||
usedTPH.add(a);
|
|
||||||
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
|
||||||
//ht.put(a, a.getVariance());
|
|
||||||
Set<UnifyPair> eq1 = new HashSet<>(eq);
|
|
||||||
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
|
||||||
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
|
|
||||||
eq1 = new HashSet<>(eq);
|
|
||||||
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
|
||||||
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
|
|
||||||
phSetVariance = new ArrayList<>(phSet);
|
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a)
|
||||||
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
* wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
||||||
* @param eq The set of constraints
|
* @param eq The set of constraints
|
||||||
*/
|
*/
|
||||||
private void varianceInheritanceConstrainSet(ConstraintSet<UnifyPair> cons) {
|
private void varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
|
||||||
Set<UnifyPair> eq = cons.getAll();
|
Set<UnifyPair> eq = cons.getAll();
|
||||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
Set<PlaceholderType> usedTPH = new HashSet<>();
|
||||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
||||||
|
@ -156,14 +156,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> computeOld() {
|
||||||
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
|
||||||
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||||
else return res;
|
else return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Set<Set<UnifyPair>> computeNew() {
|
@Override
|
||||||
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
Set<Set<UnifyPair>> fstElems = new HashSet<>();
|
Set<Set<UnifyPair>> fstElems = new HashSet<>();
|
||||||
fstElems.add(eq);
|
fstElems.add(eq);
|
||||||
Set<Set<UnifyPair>> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel);
|
Set<Set<UnifyPair>> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel);
|
||||||
@ -401,7 +402,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
//else result.stream().filter(y -> !isUndefinedPairSet(y));
|
||||||
} // End of if (remainingSets.isEmpty())
|
} // End of if (remainingSets.isEmpty())
|
||||||
else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
|
else {//duerfte gar nicht mehr vorkommen PL 2018-04-03
|
||||||
result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
result.addAll(computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} // End of while (nextSetasList.size() > 0)
|
} // End of while (nextSetasList.size() > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user