From b55d0779e98f9041ec368fb3fb4d3e2ef50372aa Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 22 Nov 2017 06:49:11 +0100 Subject: [PATCH] =?UTF-8?q?ResultPairs=20des=20Unify=20Algorithmus=20k?= =?UTF-8?q?=C3=B6nnnen=20nun=20auch=20Wildcard-Typen=20enthalten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/factory/UnifyTypeFactory.java | 23 ++++++++----------- .../typedeployment/TypeInsertFactory.java | 2 +- ...=> PairTPHequalRefTypeOrWildcardType.java} | 6 ++--- .../typeinference/result/ResultSet.java | 13 +++-------- .../result/ResultSetVisitor.java | 2 +- 5 files changed, 18 insertions(+), 28 deletions(-) rename src/de/dhbwstuttgart/typeinference/result/{PairTPHequalRefType.java => PairTPHequalRefTypeOrWildcardType.java} (68%) diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 7cd7ca9c..325e453f 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -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(); } diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java index b9eea3c6..290fd984 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java @@ -100,7 +100,7 @@ class TypeToInsertString implements ResultSetVisitor{ } @Override - public void visit(PairTPHequalRefType p) { + public void visit(PairTPHequalRefTypeOrWildcardType p) { } diff --git a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java similarity index 68% rename from src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java rename to src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java index bf29ce52..ef6dd00a 100644 --- a/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefType.java +++ b/src/de/dhbwstuttgart/typeinference/result/PairTPHequalRefTypeOrWildcardType.java @@ -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; diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java index f3c81b55..1d0bd32d 100644 --- a/src/de/dhbwstuttgart/typeinference/result/ResultSet.java +++ b/src/de/dhbwstuttgart/typeinference/result/ResultSet.java @@ -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); } diff --git a/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java b/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java index 3f21ae31..fbf241c1 100644 --- a/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java +++ b/src/de/dhbwstuttgart/typeinference/result/ResultSetVisitor.java @@ -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);