diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a8c0675dd..bd35376d3 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -4,10 +4,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Optional; import java.util.Queue; import java.util.Set; import java.util.Stack; +import java.util.function.Function; import java.util.stream.Collectors; import de.dhbwstuttgart.exceptions.DebugException; @@ -619,8 +621,12 @@ public class RuleSet implements IRuleSet{ return succ ? permutation : new int[0]; } - @Override public Optional> subst(Set pairs) { + return subst(pairs, new ArrayList<>()); + } + + @Override + public Optional> subst(Set pairs, List>> oderConstraints) { HashMap typeMap = new HashMap<>(); Stack occuringTypes = new Stack<>(); @@ -664,9 +670,29 @@ public class RuleSet implements IRuleSet{ Unifier uni = new Unifier(lhsType, rhsType); result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); + + Function,? extends HashSet> applyUni = b -> b.stream().map( + x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)); + List>> oderConstraintsRet = new ArrayList<>(); + for(Set> oc : oderConstraints) { + //Set> ocRet = new HashSet<>(); + //for(Set cs : oc) { + Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)); + oderConstraintsRet.add(csRet); + //} + } + oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); + /* + oderConstraints = oderConstraints.stream().map( + a -> a.stream().map(applyUni + //b -> b.stream().map( + // x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new) ) + ).collect(Collectors.toCollection(HashSet::new)) + ).collect(Collectors.toList(ArrayList::new)); + } + */ applied = true; } - result.add(pair); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 5a3d48627..59dd208a7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -656,9 +656,12 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 5: Substitution */ //writeLog("vor Subst: " + eqPrime); - Optional> eqPrimePrime = rules.subst(eqPrime); + writeLog("vor Subst: " + oderConstraints); + String ocString = oderConstraints.toString(); + Optional> eqPrimePrime = rules.subst(eqPrime, oderConstraints); Set> unifyres1 = null; Set> unifyres2 = null; + if (!ocString.equals(oderConstraints.toString())) writeLog("nach Subst: " + oderConstraints); //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index a2b647c60..1ed46cb01 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.typeinference.unify.interfaces; +import java.util.List; import java.util.Optional; import java.util.Set; @@ -85,6 +86,13 @@ public interface IRuleSet { public Optional adaptExt(UnifyPair pair, IFiniteClosure fc); public Optional adaptSup(UnifyPair pair, IFiniteClosure fc); + /** + * Applies the subst-Rule to a set of pairs (usually Eq'). + * @param pairs The set of pairs where the subst rule should apply. + * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. + */ + public Optional> subst(Set pairs, List>> oderConstraints); + /** * Applies the subst-Rule to a set of pairs (usually Eq'). * @param pairs The set of pairs where the subst rule should apply. diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 9e87c1e6a..295051617 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean;