From 6dce7058a00dde7125213a5e0bbb16fe5acbb8c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= <pl@macmini_pl.verw.ba-horb.de>
Date: Fri, 19 Oct 2018 16:24:00 +0200
Subject: [PATCH] 	modified:  
 src/de/dhbwstuttgart/core/JavaTXCompiler.java typeInference <->
 typeInferenceOld 	modified:  
 src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java compute <->
 computeOld

---
 src/de/dhbwstuttgart/core/JavaTXCompiler.java | 74 ++++++++++---------
 .../typeinference/unify/TypeUnifyTask.java    |  9 ++-
 2 files changed, 43 insertions(+), 40 deletions(-)

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<ResultSet> typeInference() throws ClassNotFoundException {
+    public List<ResultSet> typeInferenceOld() throws ClassNotFoundException {
         List<ClassOrInterface> 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<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();
         //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<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
 			//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
 			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());
         }
 
-    /**
-	 * 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)
 	 * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. 
 	 * @param eq The set of constraints
 	 */
-	private void varianceInheritanceConstrainSet(ConstraintSet<UnifyPair> cons) {
+	private void varianceInheritanceConstraintSet(ConstraintSet<UnifyPair> cons) {
 		Set<UnifyPair> eq = cons.getAll();
 		Set<PlaceholderType> usedTPH = new HashSet<>();
 		Set<PlaceholderType> 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<Set<Set<UnifyPair>>>  {
 		}		
 }
 */
-	@Override
-	protected Set<Set<UnifyPair>> compute() {
+	
+	protected Set<Set<UnifyPair>> computeOld() {
 		Set<Set<UnifyPair>> res = unify(eq, fc, parallel);
 		if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
 		else return res;
 	}
 	
-	protected Set<Set<UnifyPair>> computeNew() {
+	@Override
+	protected Set<Set<UnifyPair>> compute() {
 		Set<Set<UnifyPair>> fstElems = new HashSet<>();
 		fstElems.add(eq);
 		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));
 			} // 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)