From 87dede5d5f981c7c7d705555c8f1c5f1574160cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 24 May 2018 17:45:10 +0200 Subject: [PATCH] modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java F-Bounded Problematik durche neues greater ggf. geloest. Es werden Falle ausgeschlossen. Diese Faelle muessen noch ergaenzt werden. --- .../unify/model/FiniteClosure.java | 81 ++++++++++++++++++- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 4ab443e53..bc70e742c 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -187,13 +187,89 @@ public class FiniteClosure extends Ordering implements IFiniteClosure permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x))); return result; } - + /** * Returns all types of the finite closure that are supertypes of the argument. * @return The set of supertypes of the argument. */ @Override + //Eingefuegt PL 2018-05-24 F-Bounded Problematik public Set greater(UnifyType type, Set fBounded) { + Set result = new HashSet<>(); + Set>> PairResultFBounded = new HashSet<>(); + + Match match = new Match(); + + + // if T = T' then T <=* T' + result.add(type); + if(!strInheritanceGraph.containsKey(type.getName())) + return result; + + // if T <* T' then sigma(T) <* sigma(T') + Set> candidates = strInheritanceGraph.get(type.getName()); + for(Node candidate : candidates) { + UnifyType theta1 = candidate.getContent(); + + //PL 18-04-05 Unifier durch Matcher ersetzt ANFANG + ArrayList termList= new ArrayList(); + termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT)); + Optional optSigma = match.match(termList); + //PL 18-04-05 Unifier durch Matcher ersetzt ENDE + if(!optSigma.isPresent()) + continue; + + Unifier sigma = optSigma.get(); + sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); + + Set fBoundedNew = new HashSet<>(fBounded); + fBoundedNew.add(theta1); + Set theta2Set = candidate.getContentOfPredecessors(); + + for(UnifyType theta2 : theta2Set) { + result.add(theta2.apply(sigma)); + PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); + } + } + + for(Pair> pt : PairResultFBounded) { + UnifyType t = pt.getKey(); + Set lfBounded = pt.getValue().get(); + + // if C<...> <* C<...> then ... (third case in definition of <*) + //TypeParams typeparams = t.getTypeParams(); + if(t.getTypeParams().size() > 0) { + ArrayList> paramCandidates = new ArrayList<>(); + + for (int i = 0; i < t.getTypeParams().size(); i++) { + //UnifyType parai = t.getTypeParams().get(i); + int i_ef = i; + BiFunction f = (x,y) -> + { + ArrayList termList = new ArrayList(); + termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT)); + return ((match.match(termList).isPresent()) || x); + }; + //if (parai.getName().equals("java.lang.Integer")) { + // System.out.println(""); + //} + BinaryOperator bo = (a,b) -> (a || b); + if (lfBounded.stream().reduce(false,f,bo)) continue; //F-Bounded Endlosrekursion + paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) )); + } + permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x))); + } + } + return result; + } + + /* auskommentiert PL 2018-05-24 + /** + * Returns all types of the finite closure that are supertypes of the argument. + * @return The set of supertypes of the argument. + * + //@Override + public Set oldgreater(UnifyType type, Set fBounded) { if(type instanceof FunNType) return computeGreaterFunN((FunNType) type, fBounded); @@ -204,7 +280,7 @@ public class FiniteClosure extends Ordering implements IFiniteClosure /** * Computes the greater function for all types except function types. - */ + * protected Set computeGreater(Set>> types) { Set>> result = new HashSet<>(); @@ -275,6 +351,7 @@ public class FiniteClosure extends Ordering implements IFiniteClosure return resut; return computeGreater(result); } + */ /** * Computes the greater function for FunN-Types