From ed671aeb97892be88648368b5fe4938842528cf4 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 5 Apr 2023 17:48:15 +0200 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java modified: src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java <. weider eingefuegt bei Return typen von Methodcalls und Return-Statements Vergleich dementsprechend angepasst. --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 2 +- .../syntaxtree/factory/UnifyTypeFactory.java | 1 + .../syntaxtree/type/TypePlaceholder.java | 16 ++++++++++++++++ .../typeinference/typeAlgo/TYPEStmt.java | 5 +++++ .../unify/model/OrderingUnifyPair.java | 14 +++++++++++--- .../unify/model/PlaceholderType.java | 16 ++++++++++++++++ 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index fc1b0000..c582fa96 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -69,7 +69,7 @@ public class JavaTXCompiler { //public static JavaTXCompiler INSTANCE; final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll? public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 0f1017ed..92b72ec4 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -121,6 +121,7 @@ public class UnifyTypeFactory { } PlaceholderType ntph = new PlaceholderType(tph.getName()); ntph.setVariance(tph.getVariance()); + ntph.setOrCons(tph.getOrCons()); int in = PLACEHOLDERS.indexOf(ntph); if (in == -1) { PLACEHOLDERS.add(ntph); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 2aaa8068..8452b2c8 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -24,6 +24,14 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric * wird im Generate Generics Teil nach der Rueckumwandlung nach dem Unify genutzt */ private int variance = 0; + + /* + * Fuer Oder-Constraints: + * orCons = 1: Receiver + * orCons = 0: Argument oder kein Oder-Constraint + * orCons = -1: RetType + */ + private byte orCons = 0; /** @@ -104,4 +112,12 @@ public class TypePlaceholder extends RefTypeOrTPHOrWildcardOrGeneric public void accept(ResultSetVisitor visitor) { visitor.visit(this); } + + public void setOrCons(byte i) { + orCons = i; + } + + public byte getOrCons() { + return orCons; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index ecd7600f..acdce189 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -613,6 +613,11 @@ public class TYPEStmt implements StatementVisitor{ methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT)); extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.SMALLERDOT)); + //methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); + //extendsMethodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); + + ((TypePlaceholder)forMethod.getType()).setOrCons((byte)-1);//fuer Maximums-Bestimmung + Set parameterContraints = generateParameterConstraints(forMethod, assumption, info, resolver); methodConstraint.addAll(parameterContraints); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 35eee0eb..7e319a42 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -131,7 +131,11 @@ public class OrderingUnifyPair extends OrderingExtend> { * fuehrt zu Fehlern bei Arrays.sort (contract nicht erfuellt) * @see com.google.common.collect.Ordering#compare(java.lang.Object, java.lang.Object) */ - public int compare (Set left, Set right) { + public int compare (Set leftpara, Set rightpara) { + + Set left = new HashSet<>(leftpara); + Set right = new HashSet<>(rightpara); + /* //pairop = PairOperator.SMALLERDOTWC; List al = new ArrayList<>(); @@ -220,22 +224,26 @@ public class OrderingUnifyPair extends OrderingExtend> { !(y.getRhsType() instanceof PlaceholderType) && x.getPairOp() == PairOperator.EQUALSDOT);}) .collect(Collectors.toCollection(HashSet::new)); + left.removeAll(lefteqOder); Set righteqOder = right.stream() .filter(x -> { UnifyPair y = x.getGroundBasePair(); return (y.getLhsType() instanceof PlaceholderType && !(y.getRhsType() instanceof PlaceholderType) && x.getPairOp() == PairOperator.EQUALSDOT);}) .collect(Collectors.toCollection(HashSet::new)); + right.removeAll(righteqOder); Set lefteqRet = left.stream() .filter(x -> { UnifyPair y = x.getGroundBasePair(); return (y.getRhsType() instanceof PlaceholderType && - x.getPairOp() == PairOperator.EQUALSDOT);}) + ((PlaceholderType)y.getRhsType()).getOrCons() == (byte)-1);}) .collect(Collectors.toCollection(HashSet::new)); + left.removeAll(lefteqRet); Set righteqRet = right.stream() .filter(x -> { UnifyPair y = x.getGroundBasePair(); return (y.getRhsType() instanceof PlaceholderType && - x.getPairOp() == PairOperator.EQUALSDOT);}) + ((PlaceholderType)y.getRhsType()).getOrCons() == (byte)-1);}) .collect(Collectors.toCollection(HashSet::new)); + right.removeAll(righteqRet); Set leftleOder = left.stream() .filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT)) .collect(Collectors.toCollection(HashSet::new)); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java index 63f3d448..07d85727 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -59,6 +59,14 @@ public final class PlaceholderType extends UnifyType{ * PL 2018-03-21 */ private int variance = 0; + + /* + * Fuer Oder-Constraints: + * orCons = 1: Receiver + * orCons = 0: Argument oder kein Oder-Constraint + * orCons = -1: RetType + */ + private byte orCons = 0; /** * Creates a new placeholder type with the specified name. @@ -122,6 +130,14 @@ public final class PlaceholderType extends UnifyType{ }} } + public void setOrCons(byte i) { + orCons = i; + } + + public byte getOrCons() { + return orCons; + } + public Boolean isWildcardable() { return wildcardable; }