ResultPairs des Unify Algorithmus könnnen nun auch Wildcard-Typen enthalten

This commit is contained in:
JanUlrich 2017-11-22 06:49:11 +01:00
parent 928396927e
commit b55d0779e9
5 changed files with 18 additions and 28 deletions

View File

@ -11,21 +11,13 @@ import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefType;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
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;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.*;
public class UnifyTypeFactory {
@ -205,10 +197,15 @@ public class UnifyTypeFactory {
if(tr instanceof TypePlaceholder) {
if(mp.getPairOp().equals(PairOperator.EQUALSDOT))
throw new DebugException("TPH =. TPH ist ein ungültiges Ergebnis");
//Einfach ignorieren TODO: Das hier muss ausgebessert werden:
//return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, ASTFactory.createObjectType());
else
return new PairTPHsmallerTPH((TypePlaceholder)tl, (TypePlaceholder)tr);
}
return new PairTPHequalRefType((TypePlaceholder)tl, (RefType) tr);
}else if(tr instanceof RefType){
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
}else if(tr instanceof WildcardType){
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
}else throw new NotImplementedException();
}else throw new NotImplementedException();
}

View File

@ -100,7 +100,7 @@ class TypeToInsertString implements ResultSetVisitor{
}
@Override
public void visit(PairTPHequalRefType p) {
public void visit(PairTPHequalRefTypeOrWildcardType p) {
}

View File

@ -7,11 +7,11 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* Steht für A =. RefType
*/
public class PairTPHequalRefType extends ResultPair{
public class PairTPHequalRefTypeOrWildcardType extends ResultPair{
public final TypePlaceholder left;
public final RefType right;
public final RefTypeOrTPHOrWildcardOrGeneric right;
public PairTPHequalRefType(TypePlaceholder left, RefType right){
public PairTPHequalRefTypeOrWildcardType(TypePlaceholder left, RefTypeOrTPHOrWildcardOrGeneric right){
super(left, right);
this.left = left;
this.right = right;

View File

@ -1,16 +1,9 @@
package de.dhbwstuttgart.typeinference.result;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import javax.xml.transform.Result;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ResultSet {
@ -70,7 +63,7 @@ class Resolver implements ResultSetVisitor {
}
@Override
public void visit(PairTPHequalRefType p) {
public void visit(PairTPHequalRefTypeOrWildcardType p) {
if(p.left.equals(toResolve)){
resolved = p.right;
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
@ -134,7 +127,7 @@ class TPHResolver implements ResultSetVisitor {
}
@Override
public void visit(PairTPHequalRefType p) {
public void visit(PairTPHequalRefTypeOrWildcardType p) {
TypePlaceholder otherSide = null;
if(p.right.equals(tph)){
otherSide = p.left;
@ -209,7 +202,7 @@ class RelatedTypeWalker implements ResultSetVisitor {
}
@Override
public void visit(PairTPHequalRefType p) {
public void visit(PairTPHequalRefTypeOrWildcardType p) {
if(p.getLeft().equals(toResolve)){
p.getRight().accept(this);
}

View File

@ -4,7 +4,7 @@ import de.dhbwstuttgart.syntaxtree.type.*;
public interface ResultSetVisitor {
void visit(PairTPHsmallerTPH p);
void visit(PairTPHequalRefType p);
void visit(PairTPHequalRefTypeOrWildcardType p);
void visit(RefType refType);