application of unifiers

This commit is contained in:
Florian Steurer 2015-11-13 23:17:14 +01:00
parent fd5902f6dd
commit 8a40acb73e
6 changed files with 35 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.typinference.unify.model;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
public final class ExtendsType extends Type {
private Type extendedType;
@ -49,4 +50,9 @@ public final class ExtendsType extends Type {
ExtendsType other = (ExtendsType) obj;
return other.getExtendedType().equals(extendedType);
}
@Override
public Type applyToTypeParams(Unifier unif) {
return new ExtendsType(extendedType.applyToTypeParams(unif));
}
}

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.typinference.unify.model;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
public final class PlaceholderType extends Type{
@ -32,4 +33,9 @@ public final class PlaceholderType extends Type{
return ((PlaceholderType) obj).getName().equals(typeName);
}
@Override
public Type applyToTypeParams(Unifier unif) {
return this;
}
}

View File

@ -3,11 +3,16 @@ package de.dhbwstuttgart.typinference.unify.model;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
public final class SimpleType extends Type {
public SimpleType(String name, Type... typeParams) {
super(name, new TypeParams(typeParams));
}
private SimpleType(String name, TypeParams params) {
super(name, params);
}
@Override
public Set<Type> smArg(IFiniteClosure fc) {
@ -36,4 +41,9 @@ public final class SimpleType extends Type {
return other.getTypeParams().equals(typeParams);
}
@Override
public Type applyToTypeParams(Unifier unif) {
return new SimpleType(typeName, typeParams.apply(unif));
}
}

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.typinference.unify.model;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
public final class SuperType extends Type {
@ -50,4 +51,9 @@ public final class SuperType extends Type {
SuperType other = (SuperType) obj;
return other.getSuperedType().equals(superedType);
}
@Override
public Type applyToTypeParams(Unifier unif) {
return new SuperType(superedType.applyToTypeParams(unif));
}
}

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.typinference.unify.model;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unifynew.Unifier;
public abstract class Type {
@ -31,6 +32,8 @@ public abstract class Type {
public abstract Set<Type> grArg(IFiniteClosure fc);
public abstract Type applyToTypeParams(Unifier unif);
@Override
public String toString() {
String params = "";

View File

@ -28,9 +28,11 @@ public final class TypeParams implements Iterable<Type>{
return typeParams.length == 0;
}
public void apply(Unifier u) {
public TypeParams apply(Unifier unif) {
Type[] newParams = new Type[typeParams.length];
for(int i = 0; i < typeParams.length; i++)
typeParams[i] = u.apply(typeParams[i]);
newParams[i] = typeParams[i].applyToTypeParams(unif);
return new TypeParams(newParams);
}
public boolean contains(Type t) {