From 318f6e1cc58d81a0e934e0a73eaa87f1b5147695 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Fri, 6 May 2016 16:59:59 +0200 Subject: [PATCH] code review todos erledigt --- .../typeinference/unify/TypeUnifyTask.java | 60 +++---------------- .../unify/model/FiniteClosure.java | 4 +- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 9cb2df6e..be67ea09 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -410,8 +410,11 @@ public class TypeUnifyTask extends RecursiveTask>> { // Case unknown: If a pair fits no other case, then the type unification has failed. // Through application of the rules, every pair should have one of the above forms. // Pairs that do not have one of the aboves form are contradictory. - else - undefined.add(pair); + else { + // If a pair is not defined, the unificiation will fail, so the loop can be stopped here. + undefined.add(pair); + break; + } } // Filter empty sets or sets that only contain an empty set. @@ -493,7 +496,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 2: (a <.? ? ext Theta') */ - protected Set> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) { + private Set> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, IFiniteClosure fc) { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); @@ -513,7 +516,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Cartesian Product Case 3: (a <.? ? sup Theta') */ - protected Set> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) { + private Set> unifyCase3(PlaceholderType a, SuperType subThetaPrime, IFiniteClosure fc) { Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); @@ -531,22 +534,10 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } - /** - * Cartesian Product Case 4: (a <.? Theta') - */ - protected Set> unifyCase4(PlaceholderType a, UnifyType thetaPrime, IFiniteClosure fc) { - Set> result = new HashSet<>(); - Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.EQUALSDOT)); - result.add(resultPrime); - - return result; - } - /** * Cartesian Product Case 5: (Theta <. a) */ - protected Set> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { + private Set> unifyCase5(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { Set> result = new HashSet<>(); boolean allGen = theta.getTypeParams().size() > 0; @@ -574,44 +565,11 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } - - /** - * Cartesian Product Case 6: (? ext Theta <.? a) - */ - protected Set> unifyCase6(ExtendsType extTheta, PlaceholderType a, IFiniteClosure fc) { - Set> result = new HashSet<>(); - UnifyType freshTph = PlaceholderType.freshPlaceholder(); - UnifyType extFreshTph = new ExtendsType(freshTph); - - Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, extFreshTph, PairOperator.EQUALSDOT)); - resultPrime.add(new UnifyPair(extTheta.getExtendedType(), freshTph, PairOperator.SMALLERDOT)); - result.add(resultPrime); - return result; - } - - /** - * Cartesian Product Case 7: (? sup Theta <.? a) - */ - protected Set> unifyCase7(SuperType supTheta, PlaceholderType a, IFiniteClosure fc) { - Set> result = new HashSet<>(); - - UnifyType aPrime = PlaceholderType.freshPlaceholder(); - UnifyType supAPrime = new SuperType(aPrime); - UnifyType theta = supTheta.getSuperedType(); - Set resultPrime = new HashSet<>(); - resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT)); - resultPrime.add(new UnifyPair(aPrime, theta, PairOperator.SMALLERDOT)); - result.add(resultPrime); - - return result; - } - /** * Cartesian Product Case 8: (Theta <.? a) */ - protected Set> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { + private Set> unifyCase8(UnifyType theta, PlaceholderType a, IFiniteClosure fc) { Set> result = new HashSet<>(); //for(UnifyType thetaS : fc.grArg(theta)) { Set resultPrime = new HashSet<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 2ea63a4a..9ace0e51 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -26,7 +26,7 @@ public class FiniteClosure implements IFiniteClosure { /** * A map that maps every typename to the nodes of the inheritance graph that contain a type with that name. */ - private HashMap>> strInheritanceGraph; + private HashMap>> strInheritanceGraph; /** * The initial pairs of that define the inheritance tree @@ -251,7 +251,6 @@ public class FiniteClosure implements IFiniteClosure { @Override public Set grArg(FunNType type) { - // TODO ist das richtig? Set result = new HashSet(); result.add(type); smaller(type).forEach(x -> result.add(new SuperType(x))); @@ -298,7 +297,6 @@ public class FiniteClosure implements IFiniteClosure { @Override public Set smArg(FunNType type) { - // TODO ist das richtig? Set result = new HashSet(); result.add(type); return result;