From 1e968111278c66d214c4298473e5ee62dad8e9b8 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Tue, 12 Apr 2016 10:54:17 +0200 Subject: [PATCH 1/5] refactoring and commenting --- .../unify/MartelliMontanariUnify.java | 6 +- .../typeinference/unify/RuleSet.java | 8 +-- .../typeinference/unify/Unify.java | 2 +- .../unify/model/FiniteClosure.java | 15 ----- .../typeinference/unify/model/Unifier.java | 63 +++++++++++++++---- 5 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java b/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java index ae017235..45e52133 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/MartelliMontanariUnify.java @@ -25,7 +25,7 @@ public class MartelliMontanariUnify implements IUnify { public Optional unify(Set terms) { // Sets with less than 2 terms are trivially unified if(terms.size() < 2) - return Optional.of(Unifier.Identity()); + return Optional.of(Unifier.identity()); // For the the set of terms {t1,...,tn}, // build a list of equations {(t1 = t2), (t2 = t3), (t3 = t4), ....} @@ -39,7 +39,7 @@ public class MartelliMontanariUnify implements IUnify { } // Start with the identity unifier. Substitutions will be added later. - Unifier mgu = Unifier.Identity(); + Unifier mgu = Unifier.identity(); // Apply rules while possible int idx = 0; @@ -91,7 +91,7 @@ public class MartelliMontanariUnify implements IUnify { // SUBST - Rule if(lhsType instanceof PlaceholderType) { - mgu.Add((PlaceholderType) lhsType, rhsType); + mgu.add((PlaceholderType) lhsType, rhsType); termsList = termsList.stream().map(mgu::apply).collect(Collectors.toCollection(ArrayList::new)); idx = idx+1 == termsList.size() ? 0 : idx+1; continue; diff --git a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 82ee9683..8fb5ddf2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -417,9 +417,9 @@ public class RuleSet implements IRuleSet{ TypeParams typeDParams = typeD.getTypeParams(); TypeParams typeDgenParams = typeDgen.getTypeParams(); - Unifier unif = Unifier.Identity(); + Unifier unif = Unifier.identity(); for(int i = 0; i < typeDParams.size(); i++) - unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); + unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); return Optional.of(new UnifyPair(unif.apply(newLhs), typeDs, PairOperator.SMALLERDOT)); } @@ -465,7 +465,7 @@ public class RuleSet implements IRuleSet{ Unifier unif = new Unifier((PlaceholderType) typeDgenParams.get(0), typeDParams.get(0)); for(int i = 1; i < typeDParams.size(); i++) - unif.Add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); + unif.add((PlaceholderType) typeDgenParams.get(i), typeDParams.get(i)); return Optional.of(new UnifyPair(unif.apply(newLhs), typeExtDs, PairOperator.SMALLERDOTWC)); } @@ -517,7 +517,7 @@ public class RuleSet implements IRuleSet{ Unifier unif = new Unifier((PlaceholderType) typeSupDsgenParams.get(0), typeDParams.get(0)); for(int i = 1; i < typeDParams.size(); i++) - unif.Add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i)); + unif.add((PlaceholderType) typeSupDsgenParams.get(i), typeDParams.get(i)); return Optional.of(new UnifyPair(unif.apply(newLhs), newRhs, PairOperator.SMALLERDOTWC)); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 0d2014b9..0bb0723f 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -377,7 +377,7 @@ public class Unify { Unifier unifier = opt.get(); unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams().toArray()); Set substitutionSet = new HashSet<>(); - for (Entry sigma : unifier.getSubstitutions()) + for (Entry sigma : unifier) substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT)); List freshTphs = new ArrayList<>(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index f06fead7..fd946eb0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -372,21 +372,6 @@ public class FiniteClosure implements IFiniteClosure { return result; } - - public boolean isGenericType(UnifyType t) { - if(t.getTypeParams().size() == 0) - return true; - - if(!strInheritanceGraph.containsKey(t.getName())) - return false; - - for(UnifyPair pair : pairs) - if(pair.getLhsType().equals(t)) - return true; - - return false; - } - @Override public Set getAllTypesByName(String typeName) { if(!strInheritanceGraph.containsKey(typeName)) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index f5af52d0..61302430 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -1,15 +1,26 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.util.HashMap; +import java.util.Iterator; import java.util.Map.Entry; -import java.util.Set; import java.util.function.Function; - -public class Unifier implements Function /*, Set*/ { // TODO set implementieren +/** + * A set of substitutions (s -> t) that is an applicable function to types and pairs. + * @author Florian Steurer + */ +public class Unifier implements Function, Iterable> { + + /** + * The set of substitutions that unify a type-term + */ private HashMap substitutions = new HashMap<>(); - + /** + * Creates a new instance with a single substitution (source -> target). + * @param The type that is replaced + * @param The type that replaces + */ public Unifier(PlaceholderType source, UnifyType target) { substitutions.put(source, target); } @@ -20,13 +31,23 @@ public class Unifier implements Function /*, Set*/ protected Unifier() { } - - public static Unifier Identity() { + + /** + * Creates an unifier that is the identity function (thus has no substitutions). + */ + public static Unifier identity() { return new Unifier(); } - public void Add(PlaceholderType source, UnifyType target) { + /** + * Adds a substitution to the unifier from (source -> target) + * @param The type that is replaced + * @param The type that replaces + */ + public void add(PlaceholderType source, UnifyType target) { Unifier tempU = new Unifier(source, target); + // Every new substitution must be applied to previously added substitutions + // otherwise the unifier needs to be applied multiple times to unify two terms for(PlaceholderType pt : substitutions.keySet()) substitutions.put(pt, substitutions.get(pt).apply(tempU)); substitutions.put(source, target); @@ -37,26 +58,39 @@ public class Unifier implements Function /*, Set*/ return t.apply(this); } + /** + * Applies the unifier to the two terms of the pair. + * @return A new pair where the left and right-hand side are applied + */ public UnifyPair apply(UnifyPair p) { return new UnifyPair(this.apply(p.getLhsType()), this.apply(p.getRhsType()), p.getPairOp()); } + /** + * True if the typevariable t will be substituted if the unifier is applied. + * false otherwise. + */ public boolean hasSubstitute(PlaceholderType t) { return substitutions.containsKey(t); } + /** + * Returns the type that will replace the typevariable t if the unifier is applied. + */ public UnifyType getSubstitute(PlaceholderType t) { return substitutions.get(t); } - - public Set> getSubstitutions() { - return substitutions.entrySet(); - } - + + /** + * Garantuees that if there is a substitutions (a -> b) in this unifier, + * a is not an element of the targetParams. Substitutions that do not + * satisfy this condition, are swapped. + */ public void swapPlaceholderSubstitutions(UnifyType... targetParams) { for(UnifyType tph : targetParams) { if(!(tph instanceof PlaceholderType)) continue; + // Swap a substitutions (a -> b) if a is an element of the target params. if(substitutions.containsKey(tph) && substitutions.get(tph) instanceof PlaceholderType) { PlaceholderType newLhs = (PlaceholderType) substitutions.get(tph); substitutions.remove(tph); @@ -75,5 +109,10 @@ public class Unifier implements Function /*, Set*/ result += " }"; return result; } + + @Override + public Iterator> iterator() { + return substitutions.entrySet().iterator(); + } } From ea32cd5680c10c0f91a5d96ddcbf755a37c5f3c0 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Tue, 12 Apr 2016 11:12:57 +0200 Subject: [PATCH 2/5] commenting and refactoring --- .../typeinference/unify/Unify.java | 2 +- .../unify/model/FiniteClosure.java | 4 +- .../unify/model/PlaceholderType.java | 1 - .../typeinference/unify/model/TypeParams.java | 78 +++++++++++++------ .../typeinference/unify/model/Unifier.java | 2 +- 5 files changed, 57 insertions(+), 30 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unify.java b/src/de/dhbwstuttgart/typeinference/unify/Unify.java index 0bb0723f..4d727591 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unify.java @@ -375,7 +375,7 @@ public class Unify { continue; Unifier unifier = opt.get(); - unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams().toArray()); + unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index fd946eb0..c4d1658b 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -105,7 +105,7 @@ public class FiniteClosure implements IFiniteClosure { if (!sigma2Opt.isPresent()) continue; Unifier sigma2 = sigma2Opt.get(); - sigma2.swapPlaceholderSubstitutions(typePrime.getTypeParams().toArray()); + sigma2.swapPlaceholderSubstitutions(typePrime.getTypeParams()); if(type.equals(theta2)) continue; Set theta1s = smaller(theta2); @@ -205,7 +205,7 @@ public class FiniteClosure implements IFiniteClosure { continue; Unifier sigma2 = sigma2Opt.get(); - sigma2.swapPlaceholderSubstitutions(typePrime.getTypeParams().toArray()); + sigma2.swapPlaceholderSubstitutions(typePrime.getTypeParams()); Set theta1s = greater(theta2); for (UnifyType theta1 : theta1s) { // Because only the most general type is calculated, sigma1 = sigma2 diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index ddb7d273..9b032b4a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -1,6 +1,5 @@ package de.dhbwstuttgart.typeinference.unify.model; -import java.util.ArrayList; import java.util.HashSet; import java.util.Random; import java.util.Set; diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java index f5b7686b..aa534b60 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java @@ -5,43 +5,61 @@ import java.util.Iterator; import de.dhbwstuttgart.typeinference.Menge; +/** + * The generic or non-generic parameters of a type e.g. for List + * @author Florian Steurer + */ public final class TypeParams implements Iterable{ + /** + * The array which backs the type parameters. + */ private final UnifyType[] typeParams; + /** + * Creates a new set of type parameters. + * @param types The type parameters. + */ public TypeParams(Menge types){ typeParams = new UnifyType[types.size()]; - for(int i=0;i"; + return Arrays.stream(typeParams).allMatch(x -> x instanceof PlaceholderType); } + /** + * Returns the number of the type parameters in this object. + * @return number of type parameters, always positive (including 0). + */ public int size() { return typeParams.length; } + /** + * Returns true if this object has size() of zero, false otherwise. + */ public boolean empty() { return typeParams.length == 0; } + /** + * Applies a unifier to every parameter in this object. + * @param unif The applied unifier. + * @return A new type parameter object, where the unifier was applied to every parameter. + */ public TypeParams apply(Unifier unif) { UnifyType[] newParams = new UnifyType[typeParams.length]; for(int i = 0; i < typeParams.length; i++) @@ -49,6 +67,10 @@ public final class TypeParams implements Iterable{ return new TypeParams(newParams); } + /** + * True if the PlaceholderType t is a parameter of this object, or if any parameter + * contains t (arbitrary depth of recursion), false otherwise. + */ public boolean occurs(PlaceholderType t) { for(UnifyType p : typeParams) if(p instanceof PlaceholderType) @@ -60,26 +82,24 @@ public final class TypeParams implements Iterable{ return false; } - public boolean contains(UnifyType t) { - for(UnifyType t1 : typeParams) - if(t1.equals(t1)) - return true; - return false; - } - + /** + * Returns the i-th parameter of this object. + * @throws ArrayOutOfBoundsException if i > this.size()-1. + */ public UnifyType get(int i) { return typeParams[i]; } + /** + * Sets the the type t as the i-th parameter and returns a new object + * that equals this object, except for the i-th type. + * @throws ArrayOutOfBoundsException if i > this.size()-1. + */ public TypeParams set(UnifyType t, int idx) { UnifyType[] newparams = Arrays.copyOf(typeParams, typeParams.length); newparams[idx] = t; return new TypeParams(newparams); } - - public UnifyType[] toArray() { - return Arrays.copyOf(typeParams, typeParams.length); - } @Override public Iterator iterator() { @@ -107,5 +127,13 @@ public final class TypeParams implements Iterable{ return true; } + + @Override + public String toString() { + String res = ""; + for(UnifyType t : typeParams) + res += t + ","; + return "<" + res.substring(0, res.length()-1) + ">"; + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 61302430..1a3988db 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -86,7 +86,7 @@ public class Unifier implements Function, Iterable targetParams) { for(UnifyType tph : targetParams) { if(!(tph instanceof PlaceholderType)) continue; From a16e62f4bd47da379c2aec5af33b28074c178d73 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Tue, 12 Apr 2016 11:18:55 +0200 Subject: [PATCH 3/5] refactoring and commenting --- .../unify/model/ExtendsType.java | 11 +++++----- .../typeinference/unify/model/SuperType.java | 20 ++++++++++++++----- .../unify/model/WildcardType.java | 8 ++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java index 9416d786..d5490e96 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java @@ -17,15 +17,16 @@ public final class ExtendsType extends WildcardType { super("? extends " + extendedType.getName(), extendedType); } + /** + * The extended type e.g. Integer in "? extends Integer" + */ public UnifyType getExtendedType() { return wildcardedType; } - @Override - public TypeParams getTypeParams() { - return wildcardedType.getTypeParams(); - } - + /** + * Sets the type parameters of the wildcarded type and returns a new extendstype that extends that type. + */ @Override public UnifyType setTypeParams(TypeParams newTp) { return new ExtendsType(wildcardedType.setTypeParams(newTp)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java index 7c557ade..8a828156 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java @@ -4,11 +4,23 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +/** + * A super wildcard type e.g. ? super Integer. + * @author Florian Steurer + */ public final class SuperType extends WildcardType { + + /** + * Creates a new instance "? extends superedType" + * @param superedType The type that is supered e.g. Integer in "? super Integer" + */ public SuperType(UnifyType superedType) { super("? super " + superedType.getName(), superedType); } + /** + * The type that is supered e.g. Integer in "? super Integer" + */ public UnifyType getSuperedType() { return wildcardedType; } @@ -18,11 +30,9 @@ public final class SuperType extends WildcardType { return "? super " + wildcardedType; } - @Override - public TypeParams getTypeParams() { - return wildcardedType.getTypeParams(); - } - + /** + * Sets the type parameters of the wildcarded type and returns a new supertype that supers that type. + */ @Override public UnifyType setTypeParams(TypeParams newTp) { return new SuperType(wildcardedType.setTypeParams(newTp)); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index 9db59498..19efd88a 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -29,6 +29,14 @@ public abstract class WildcardType extends UnifyType { return wildcardedType; } + /** + * Returns the type parameters of the WILDCARDED TYPE. + */ + @Override + public TypeParams getTypeParams() { + return wildcardedType.getTypeParams(); + } + @Override public int hashCode() { return wildcardedType.hashCode() + getName().hashCode() + 17; From 8b6a4d174621bce3b68b8cff60be414daaaf891e Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Tue, 12 Apr 2016 11:28:07 +0200 Subject: [PATCH 4/5] refactoring and commenting --- .../unify/model/PlaceholderType.java | 52 ++++++++++++++----- .../unify/model/ReferenceType.java | 6 +++ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 9b032b4a..01102fca 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -6,42 +6,68 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +/** + * An unbounded placeholder type. + * @author Florian Steurer + */ public final class PlaceholderType extends UnifyType{ + /** + * Static list containing the names of all existing placeholders. + * Used for generating fresh placeholders. + */ protected static final HashSet EXISTING_PLACEHOLDERS = new HashSet(); + + /** + * Prefix of auto-generated placeholder names. + */ protected static String nextName = "gen_"; + + /** + * Random number generator used to generate fresh placeholder name. + */ protected static Random rnd = new Random(43558747548978L); + /** + * True if this object was auto-generated, false if this object was user-generated. + */ private final boolean IsGenerated; + /** + * Creates a new placeholder type with the specified name. + */ public PlaceholderType(String name) { super(name, new TypeParams()); - EXISTING_PLACEHOLDERS.add(name); - IsGenerated = false; + EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names + IsGenerated = false; // This type is user generated } + /** + * Creates a new placeholdertype + * @param isGenerated true if this placeholder is auto-generated, false if it is user-generated. + */ protected PlaceholderType(String name, boolean isGenerated) { super(name, new TypeParams()); - EXISTING_PLACEHOLDERS.add(name); + EXISTING_PLACEHOLDERS.add(name); // Add to list of existing placeholder names IsGenerated = isGenerated; } + /** + * Creates a fresh placeholder type with a name that does so far not exist. + * A user could later instantiate a type using the same name that is equivalent to this type. + * @return A fresh placeholder type. + */ public static PlaceholderType freshPlaceholder() { - String name = nextName + randomChar(); - + String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' + // Add random chars while the name is in use. while(EXISTING_PLACEHOLDERS.contains(name)); - name += randomChar(); - + name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z' return new PlaceholderType(name, true); } /** - * Returns random char between 'a' and 'z' + * True if this placeholder is auto-generated, false if it is user-generated. */ - private static char randomChar() { - return (char) (rnd.nextInt(22) + 97); - } - public boolean isGenerated() { return IsGenerated; } @@ -58,7 +84,7 @@ public final class PlaceholderType extends UnifyType{ @Override public UnifyType setTypeParams(TypeParams newTp) { - return this; + return this; // Placeholders never have params. } @Override diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java index 4f557b53..ad02c9ab 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java @@ -4,7 +4,13 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +/** + * A reference type e.q. Integer or List. + * @author Florian Steurer + * + */ public final class ReferenceType extends UnifyType { + public ReferenceType(String name, UnifyType... typeParams) { super(name, new TypeParams(typeParams)); } From f8d7a95731cd64b632ccadf7896c51f4e2459516 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Tue, 12 Apr 2016 11:36:43 +0200 Subject: [PATCH 5/5] commenting --- .../unify/model/PairOperator.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java b/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java index 7b8258bd..fd18f6c0 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PairOperator.java @@ -1,22 +1,42 @@ package de.dhbwstuttgart.typeinference.unify.model; +/** + * Operators of pairs of the unification. + * @author Florian Steurer + */ public enum PairOperator { + /** + * The smaller operator (T < P) is used to express a subtyping relation between + * T and P for example in the finite closure. It is necessarily true. + */ SMALLER, + + /** + * The smallerdot operator (T <. P) is used to express a subtyping relation between + * of T and P in a CONSTRAINT during the unification. It is not necessarily true. + */ SMALLERDOT, + + /** + * The smallerdot operator for arguments (T <.? P) is used to express that + * T is an element of smArg(P) (or P is an element of grArg(T)) in a CONSTRAINT + * during the unification. It is not necessarily true. + */ SMALLERDOTWC, + + /** + * The equalsdot operator (T =. P) is used to express that two types during the unification + * should be equal. It is not necessarily true. + */ EQUALSDOT; @Override public String toString() { switch (this) { - case SMALLER: - return "<"; - case SMALLERDOT: - return "<."; - case SMALLERDOTWC: - return "<.?"; - default: - return "=."; + case SMALLER: return "<"; + case SMALLERDOT: return "<."; + case SMALLERDOTWC: return "<.?"; + default: return "=."; // EQUALSDOT } - }; + } } \ No newline at end of file