diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index f984d8c8..74bb67c6 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -103,7 +103,7 @@ public class JavaTXCompiler { return new ArrayList<>(allClasses); } - public List typeInference() throws ClassNotFoundException { + public List typeInferenceOld() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { @@ -215,8 +215,41 @@ public class JavaTXCompiler { 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 eq) { + Set usedTPH = new HashSet<>(); + Set phSet = eq.stream().map(x -> { + Set 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 phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0)); + while(!phSetVariance.isEmpty()) { + PlaceholderType a = phSetVariance.remove(0); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + Set 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 typeInferenceNew() throws ClassNotFoundException { + + public List typeInference() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { @@ -292,7 +325,7 @@ public class JavaTXCompiler { } } return y; } ); - varianceInheritanceConstrainSet(unifyCons); + varianceInheritanceConstraintSet(unifyCons); //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); //Set> result = unify.unify(xConsSet, finiteClosure); Set> 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()); } - /** - * 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 eq) { - Set usedTPH = new HashSet<>(); - Set phSet = eq.stream().map(x -> { - Set 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 phSetVariance = new ArrayList<>(phSet); - phSetVariance.removeIf(x -> (x.getVariance() == 0)); - while(!phSetVariance.isEmpty()) { - PlaceholderType a = phSetVariance.remove(0); - usedTPH.add(a); - //HashMap ht = new HashMap<>(); - //ht.put(a, a.getVariance()); - Set 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) * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ - private void varianceInheritanceConstrainSet(ConstraintSet cons) { + private void varianceInheritanceConstraintSet(ConstraintSet cons) { Set eq = cons.getAll(); Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 4ed9f8fb..24900e58 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -156,14 +156,15 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ - @Override - protected Set> compute() { + + protected Set> computeOld() { Set> res = unify(eq, fc, parallel); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } - protected Set> computeNew() { + @Override + protected Set> compute() { Set> fstElems = new HashSet<>(); fstElems.add(eq); Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); @@ -401,7 +402,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //else result.stream().filter(y -> !isUndefinedPairSet(y)); } // End of if (remainingSets.isEmpty()) 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; } // End of while (nextSetasList.size() > 0)