modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java

modified:   src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/TypeParams.java
	modified:   src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java
visitor freshPlaceholder implements UnifyTypeVisitor
This commit is contained in:
Martin Plümicke 2018-03-17 15:01:03 +01:00
parent 3638edfa73
commit 103c7e4b14
8 changed files with 48 additions and 2 deletions

View File

@ -750,9 +750,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//if (i == 62) //if (i == 62)
// System.out.println(tqp.toString()); // System.out.println(tqp.toString());
Optional<Unifier> opt = stdUnify.unify(tqp.setTypeParams(newTp), thetaPrime); Optional<Unifier> opt = stdUnify.unify(tqp.setTypeParams(newTp), thetaPrime);
if (!opt.isPresent()) tpq muesse freshtv gesetzt werden PL 2018-03-16 if (!opt.isPresent()) { //tpq muesse freshtv gesetzt werden PL 2018-03-16
continue; continue;
}
Unifier unifier = opt.get(); Unifier unifier = opt.get();
unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams());
Set<UnifyPair> substitutionSet = new HashSet<>(); Set<UnifyPair> substitutionSet = new HashSet<>();

View File

@ -2,15 +2,21 @@ package de.dhbwstuttgart.typeinference.unify.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Hashtable;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
/** /**
* An extends wildcard type "? extends T". * An extends wildcard type "? extends T".
*/ */
public final class ExtendsType extends WildcardType { public final class ExtendsType extends WildcardType {
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht);
}
/** /**
* Creates a new extends wildcard type. * Creates a new extends wildcard type.
* @param extendedType The extended type e.g. Integer in "? extends Integer" * @param extendedType The extended type e.g. Integer in "? extends Integer"

View File

@ -1,8 +1,10 @@
package de.dhbwstuttgart.typeinference.unify.model; package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Hashtable;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
/** /**
* A real function type in java. * A real function type in java.
@ -10,6 +12,10 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
*/ */
public class FunNType extends UnifyType { public class FunNType extends UnifyType {
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht);
}
/** /**
* Creates a FunN-Type with the specified TypeParameters. * Creates a FunN-Type with the specified TypeParameters.
*/ */

View File

@ -3,10 +3,12 @@ package de.dhbwstuttgart.typeinference.unify.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Hashtable;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
/** /**
* An unbounded placeholder type. * An unbounded placeholder type.
@ -54,6 +56,10 @@ public final class PlaceholderType extends UnifyType{
IsGenerated = isGenerated; IsGenerated = isGenerated;
} }
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht);
}
/** /**
* Creates a fresh placeholder type with a name that does so far not exist. * 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. * A user could later instantiate a type using the same name that is equivalent to this type.

View File

@ -1,8 +1,10 @@
package de.dhbwstuttgart.typeinference.unify.model; package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Hashtable;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
/** /**
* A reference type e.q. Integer or List<T>. * A reference type e.q. Integer or List<T>.
@ -16,6 +18,11 @@ public final class ReferenceType extends UnifyType {
*/ */
private final int hashCode; private final int hashCode;
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht);
}
public ReferenceType(String name, UnifyType... params) { public ReferenceType(String name, UnifyType... params) {
super(name, new TypeParams(params)); super(name, new TypeParams(params));
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode(); hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();

View File

@ -1,8 +1,10 @@
package de.dhbwstuttgart.typeinference.unify.model; package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Hashtable;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
/** /**
* A super wildcard type e.g. ? super Integer. * A super wildcard type e.g. ? super Integer.
@ -10,6 +12,10 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
*/ */
public final class SuperType extends WildcardType { public final class SuperType extends WildcardType {
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht);
}
/** /**
* Creates a new instance "? extends superedType" * Creates a new instance "? extends superedType"
* @param superedType The type that is supered e.g. Integer in "? super Integer" * @param superedType The type that is supered e.g. Integer in "? super Integer"

View File

@ -115,6 +115,14 @@ public final class TypeParams implements Iterable<UnifyType>{
return typeParams[i]; return typeParams[i];
} }
/**
* Returns the parameters of this object.
* PL 2018-03-17
*/
public UnifyType[] get() {
return typeParams;
}
/** /**
* Sets the the type t as the i-th parameter and returns a new object * 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. * that equals this object, except for the i-th type.

View File

@ -2,10 +2,13 @@ package de.dhbwstuttgart.typeinference.unify.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
/** /**
* Represents a java type. * Represents a java type.
@ -33,6 +36,9 @@ public abstract class UnifyType {
typeParams = p; typeParams = p;
} }
abstract public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht);
/** /**
* Returns the name of the type. * Returns the name of the type.
* @return The name e.q. List for List<T>, Integer or ? extends Integer * @return The name e.q. List for List<T>, Integer or ? extends Integer