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

new file:   src/de/dhbwstuttgart/typeinference/unify/freshPlaceholder.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/UnifyType.java
freshtypevraiable Vistor soweit fertig noch nicht getestet
This commit is contained in:
Martin Plümicke 2018-03-18 15:11:45 +01:00
parent 103c7e4b14
commit b0b1426e20
8 changed files with 66 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -11,6 +12,7 @@ import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.RecursiveTask; import java.util.concurrent.RecursiveTask;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -749,7 +751,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//System.out.println(i); //System.out.println(i);
//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); BinaryOperator<HashMap<PlaceholderType,PlaceholderType>> combiner = (x,y) -> { x.putAll(y); return x;};
HashMap<PlaceholderType,PlaceholderType> hm = tqp.getInvolvedPlaceholderTypes().stream()
.reduce(new HashMap<PlaceholderType,PlaceholderType>(),
(x, y)-> { x.put(y,PlaceholderType.freshPlaceholder()); return x; }, combiner);
Optional<Unifier> opt = stdUnify.unify(tqp.accept(new freshPlaceholder(), hm), 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;
} }

View File

@ -0,0 +1,47 @@
package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.HashMap;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
public class freshPlaceholder implements UnifyTypeVisitor {
public ReferenceType visit(ReferenceType refty, HashMap<PlaceholderType,PlaceholderType> ht) {
return new ReferenceType(refty.getName(),
new TypeParams(
Arrays.stream(refty.getTypeParams().get())
.map(x -> x.accept(this, ht))
.collect(Collectors.toCollection(ArrayList::new))));
}
public PlaceholderType visit(PlaceholderType phty, HashMap<PlaceholderType,PlaceholderType> ht) {
return ht.get(phty);
}
public FunNType visit(FunNType funnty, HashMap<PlaceholderType,PlaceholderType> ht) {
return FunNType.getFunNType(
new TypeParams(
Arrays.stream(funnty.getTypeParams().get())
.map(x -> x.accept(this, ht))
.collect(Collectors.toCollection(ArrayList::new)))
);
}
public SuperType visit(SuperType suty, HashMap<PlaceholderType,PlaceholderType> ht) {
return new SuperType(suty.getWildcardedType().accept(this, ht));
}
public ExtendsType visit(ExtendsType extty, HashMap<PlaceholderType,PlaceholderType> ht) {
return new ExtendsType(extty.getWildcardedType().accept(this, ht));
}
}

View File

@ -2,7 +2,7 @@ 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.HashMap;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
@ -13,7 +13,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
*/ */
public final class ExtendsType extends WildcardType { public final class ExtendsType extends WildcardType {
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) { public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht); return visitor.visit(this, ht);
} }

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference.unify.model; package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Hashtable; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
*/ */
public class FunNType extends UnifyType { public class FunNType extends UnifyType {
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) { public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht); return visitor.visit(this, ht);
} }

View File

@ -2,8 +2,8 @@ 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.HashMap;
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;
@ -56,7 +56,7 @@ public final class PlaceholderType extends UnifyType{
IsGenerated = isGenerated; IsGenerated = isGenerated;
} }
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) { public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht); return visitor.visit(this, ht);
} }

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference.unify.model; package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Hashtable; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
@ -19,7 +19,7 @@ public final class ReferenceType extends UnifyType {
private final int hashCode; private final int hashCode;
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) { public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht); return visitor.visit(this, ht);
} }

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference.unify.model; package de.dhbwstuttgart.typeinference.unify.model;
import java.util.Hashtable; import java.util.HashMap;
import java.util.Set; import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
@ -12,7 +12,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
*/ */
public final class SuperType extends WildcardType { public final class SuperType extends WildcardType {
public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht) { public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht) {
return visitor.visit(this, ht); return visitor.visit(this, ht);
} }

View File

@ -2,7 +2,7 @@ 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.HashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -37,7 +37,7 @@ public abstract class UnifyType {
} }
abstract public UnifyType accept(UnifyTypeVisitor visitor, Hashtable<PlaceholderType,PlaceholderType> ht); abstract public UnifyType accept(UnifyTypeVisitor visitor, HashMap<PlaceholderType,PlaceholderType> ht);
/** /**
* Returns the name of the type. * Returns the name of the type.