From bc2cab8c959a258ed74dfddc80f9522e38626502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 17 May 2018 18:07:21 +0200 Subject: [PATCH] modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java modified: src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: test/javFiles/Lambda.jav modified: test/javFiles/Lambda3.jav --- src/de/dhbwstuttgart/core/JavaTXCompiler.java | 33 +++++-------------- .../syntaxtree/factory/UnifyTypeFactory.java | 12 ++++++- .../unify/model/PlaceholderType.java | 1 + test/javFiles/Lambda.jav | 10 +++--- test/javFiles/Lambda3.jav | 1 + 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index 1fdf6e860..1790a1955 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -155,31 +155,16 @@ public class JavaTXCompiler { } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - })//.map( y -> { - if ((y.getLhsType() instanceof PlaceholderType) && (x.getRhsType() instanceof PlaceholderType)) { - - if (paraTypeVarNames.contains(x.getLhsType().getName())) { - ((PlaceholderType)x.getLhsType()).setVariance((byte)1); - ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + }).map( y -> { + if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { + if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) { + ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance()); + } + if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { + ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance()); + } } - if (returnTypeVarNames.contains(x.getLhsType().getName())) { - ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); - ((PlaceholderType)x.getLhsType()).disableWildcardtable(); - } - } - if ((x.getRhsType() instanceof PlaceholderType)) { - if (paraTypeVarNames.contains(x.getRhsType().getName())) { - ((PlaceholderType)x.getRhsType()).setVariance((byte)1); - ((PlaceholderType)x.getRhsType()).disableWildcardtable(); - } - if (returnTypeVarNames.contains(x.getRhsType().getName())) { - ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); - ((PlaceholderType)x.getRhsType()).disableWildcardtable(); - } - } - return x; - - if (y.getLhsType().getVariance() != 0) { y.getRhsType().setVariance(y.getLhsType().getVariance()); } }) + return y; } ) .collect(Collectors.toCollection(HashSet::new)); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile); //Set> result = unify.unify(xConsSet, finiteClosure); diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index e58ce50f6..e3f4de884 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -26,6 +26,8 @@ import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.unify.model.*; public class UnifyTypeFactory { + + private static ArrayList PLACEHOLDERS = new ArrayList<>(); public static FiniteClosure generateFC(List fromClasses) throws ClassNotFoundException { /* @@ -113,7 +115,15 @@ public class UnifyTypeFactory { } public static UnifyType convert(TypePlaceholder tph){ - return new PlaceholderType(tph.getName()); + PlaceholderType ntph = new PlaceholderType(tph.getName()); + int in = PLACEHOLDERS.indexOf(ntph); + if (in == -1) { + PLACEHOLDERS.add(ntph); + return ntph; + } + else { + return PLACEHOLDERS.get(in); + } } public static UnifyType convert(GenericRefType t){ diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index fe7758bea..efd83b5d2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -89,6 +89,7 @@ public final class PlaceholderType extends UnifyType{ return new PlaceholderType(name, true); } + /** * True if this placeholder is auto-generated, false if it is user-generated. */ diff --git a/test/javFiles/Lambda.jav b/test/javFiles/Lambda.jav index 378eb4d3e..2a2d57150 100644 --- a/test/javFiles/Lambda.jav +++ b/test/javFiles/Lambda.jav @@ -1,8 +1,8 @@ -class Lambda{ +class Lambda { -methode(){ + method(){ return ((f) -> f); -} + } } /* interface Fun0{ @@ -12,7 +12,7 @@ interface Fun0{ interface Fun1{ A apply(B b); } -*/ interface Fun2{ A apply(B b, C c); -} \ No newline at end of file +} +*/ diff --git a/test/javFiles/Lambda3.jav b/test/javFiles/Lambda3.jav index 9c4e960cd..9e22f3027 100644 --- a/test/javFiles/Lambda3.jav +++ b/test/javFiles/Lambda3.jav @@ -1,3 +1,4 @@ +import java.lang.String; public class Lambda2 {