diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 468f9647..0f1017ed 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -152,12 +152,12 @@ public class UnifyTypeFactory { } //NEVER USED - public static Constraint convert(Constraint constraint){ - Constraint unifyPairConstraint = constraint.stream() - .map(UnifyTypeFactory::convert) - .collect(Collectors.toCollection( () -> new Constraint (constraint.isInherited(), convert(constraint.getExtendConstraint())))); - return unifyPairConstraint; - } + //public static Constraint convert(Constraint constraint){ + // Constraint unifyPairConstraint = constraint.stream() + // .map(UnifyTypeFactory::convert) + // .collect(Collectors.toCollection( () -> new Constraint (constraint.isInherited(), convert(constraint.getExtendConstraint())))); + // return unifyPairConstraint; + //} public static UnifyPair convert(Pair p) { UnifyPair ret = null; diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index 9a3228fe..b25aa30b 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -271,6 +271,7 @@ public class OutputGenerator implements ASTVisitor{ public void visit(MethodCall methodCall) { methodCall.receiver.accept(this); out.append("."+methodCall.name); + out.append(" Signature: "+methodCall.signature); methodCall.getArgumentList().accept(this); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index a402ea53..ffac994b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -10,6 +10,11 @@ public class Constraint extends HashSet { private static final long serialVersionUID = 1L; private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt + /* + * wird verwendet um bei der Codegenerierung die richtige Methoden - Signatur + * auszuwaehlen + */ + /*private*/ Set methodSignatureConstraint = new HashSet<>(); private Constraint extendConstraint = null; @@ -21,9 +26,10 @@ public class Constraint extends HashSet { this.isInherited = isInherited; } - public Constraint(Boolean isInherited, Constraint extendConstraint) { + public Constraint(Boolean isInherited, Constraint extendConstraint, Set methodSignatureConstraint) { this.isInherited = isInherited; this.extendConstraint = extendConstraint; + this.methodSignatureConstraint = methodSignatureConstraint; } public void setIsInherited(Boolean isInherited) { @@ -41,6 +47,14 @@ public class Constraint extends HashSet { public void setExtendConstraint(Constraint c) { extendConstraint = c; } + + public Set getmethodSignatureConstraint() { + return methodSignatureConstraint; + } + + public void setmethodSignatureConstraint(Set c) { + methodSignatureConstraint = c; + } public String toString() { return super.toString() + "\nisInherited = " + isInherited diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 1c7b7439..cd3301c1 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -77,7 +77,8 @@ public class ConstraintSet { .map(o) .collect(Collectors.toCollection((as.getExtendConstraint() != null) ? () -> new Constraint (as.isInherited(), - as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new))) + as.getExtendConstraint().stream().map(o).collect(Collectors.toCollection(Constraint::new)), + as.getmethodSignatureConstraint().stream().map(o).collect(Collectors.toCollection(HashSet::new))) : () -> new Constraint (as.isInherited()) )); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java index 0c8ad7a5..78513531 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java @@ -14,6 +14,7 @@ public class Pair implements Serializable public final RefTypeOrTPHOrWildcardOrGeneric TA2; private PairOperator eOperator = PairOperator.SMALLER; + private Boolean noUnification = false; public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2 ) @@ -31,7 +32,16 @@ public class Pair implements Serializable this(TA1,TA2); this.eOperator = eOp; } - + + + public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp, Boolean noUnification) + { + // Konstruktor + this(TA1,TA2); + this.eOperator = eOp; + this.noUnification = noUnification; + } + public String toString() { // otth: Gibt ein Paar als String aus --> zum Debuggen und Vergleichen diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index ef84fad9..51d15bce 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -641,6 +641,10 @@ public class TYPEStmt implements StatementVisitor{ //PL 2023-01-24: dafuer ? extends receiverType noch ergaenzt extendsMethodConstraint.add(new Pair(forMethod.receiver.getType(), new ExtendsWildcardType(receiverType, receiverType.getOffset()), PairOperator.EQUALSDOT)); + //gegenseite Verschraenkung der beiden Mengen von Typannahmen + methodConstraint.setExtendConstraint(extendsMethodConstraint); + extendsMethodConstraint.setExtendConstraint(methodConstraint); + //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ANFANG //methodConstraint.add(new Pair(forMethod.receiverType, retType, // PairOperator.EQUALSDOT)); @@ -655,6 +659,13 @@ public class TYPEStmt implements StatementVisitor{ methodConstraint.addAll(parameterContraints); extendsMethodConstraint.addAll(parameterContraints); + Set methodSignatureConstraint = generatemethodSignatureConstraint(forMethod, assumption, info, resolver); + + System.out.println("methodSignatureConstraint; " + methodSignatureConstraint); + + methodConstraint.setmethodSignatureConstraint(methodSignatureConstraint); + extendsMethodConstraint.setmethodSignatureConstraint(methodSignatureConstraint); + Set> ret = new HashSet<>(); ret.add(methodConstraint); ret.add(extendsMethodConstraint); @@ -670,8 +681,7 @@ public class TYPEStmt implements StatementVisitor{ RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType(); RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i); - //Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params) - ret.add(new Pair(foMethod.signature.get(i), assumption.getArgTypes().get(i), PairOperator.EQUALSDOT)); + ret.add(new Pair(argType, assType, PairOperator.SMALLERDOT)); @@ -679,14 +689,26 @@ public class TYPEStmt implements StatementVisitor{ // ret.add(new Pair(foMethod.argTypes.get(i), assType, PairOperator.EQUALSDOT)); //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE } - - //Zuordnung von MethodCall.signature(ReturnType) zu dem ReturnType der ausgewaehlten Methode (assumption.returnType) - System.out.println(foMethod.name); - ret.add(new Pair(foMethod.signature.get(foMethod.signature.size()-1), assumption.getReturnType(), PairOperator.EQUALSDOT)); - return ret; } - + + + protected Set generatemethodSignatureConstraint(MethodCall foMethod, MethodAssumption assumption, + TypeInferenceBlockInformation info, GenericsResolver resolver) { + Set ret = new HashSet<>(); + + for(int i = 0; i getMethods(String name, int numArgs, TypeInferenceBlockInformation info) { List ret = new ArrayList<>(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 50ea9a2e..d120e483 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -683,7 +683,8 @@ public class RuleSet implements IRuleSet{ x -> uni.apply(pair,x)).collect(Collectors.toCollection((b.getExtendConstraint() != null) ? () -> new Constraint( b.isInherited(), - b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new))) + b.getExtendConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)), + b.getmethodSignatureConstraint().stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new))) : () -> new Constraint(b.isInherited()) )); oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 317f3660..a0515849 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -34,7 +34,7 @@ public class TypeUnify2Task extends TypeUnifyTask { System.out.println("two"); } one = true; - Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField); + Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, false); /*if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index cca673cd..3e8e9994 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -260,7 +260,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, false); noOfThread--; try { logFile.close(); @@ -305,7 +305,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, boolean sameEq) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); @@ -484,12 +484,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG //writeLog("topLevelSets: " + topLevelSets.toString()); - return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); + return computeCartesianRecursive(new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe, sameEq); } - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, boolean sameEq) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -578,12 +578,12 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), newOderConstraints, fc, parallel, rekTiefe, sameEq); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe); + Set> unifyres = unifyres2 = unify(eqPrime, newOderConstraints, fc, parallel, rekTiefe, sameEq); eqPrimePrimeSet.addAll(unifyres); @@ -625,7 +625,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param rekTiefe Deep of recursive calls * @return The set of all principal type unifiers */ - Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + Set> computeCartesianRecursive(ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, boolean sameEq) { //oneElems: Alle 1-elementigen Mengen, die nur ein Paar //a <. theta, theta <. a oder a =. theta enthalten @@ -639,7 +639,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Optional>> optNextSet = topLevelSets.stream().filter(x -> x.size()>1).findAny(); if (!optNextSet.isPresent()) {//Alle Elemente sind 1-elementig - Set> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe); + Set> result = unify2(oneElems, eq, oderConstraints, fc, parallel, rekTiefe, sameEq); return result; } @@ -705,7 +705,10 @@ public class TypeUnifyTask extends RecursiveTask>> { x.getPairOp() == PairOperator.EQUALSDOT) .map(x -> ((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance()) - .findAny(); + .reduce((n,m) -> { if ((n == 0) && (m==0)) return 0; + else if (n !=0) return n; //es muss mindestens eine Variance != 0 sein + else return m; + }); //Fuer Operatorenaufrufe wird variance auf 2 gesetzt. //da kein Receiver existiert also kein x.getGroundBasePair().getLhsType() instanceof PlaceholderType //Bei Varianz = 2 werden alle Elemente des Kartesischen Produkts abgearbeitet @@ -1150,10 +1153,17 @@ public class TypeUnifyTask extends RecursiveTask>> { //noOfThread++; } else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 - res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, sameEq); }}} //Ab hier alle parallele Berechnungen wieder zusammengeführt. + Set methodSignatureConstraint = + oderConstraint ? + ((Constraint)a).getmethodSignatureConstraint() + : new HashSet<>(); + if (oderConstraint) { + System.out.println("ERSTELLUNG: " +methodSignatureConstraint); + } if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -1482,6 +1492,17 @@ public class TypeUnifyTask extends RecursiveTask>> { //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); writeLog("res: " + res.toString()); + if (oderConstraint && !sameEq && !isUndefinedPairSetSet(result)) { + System.out.println("methodSignatureConstraint Return: " + methodSignatureConstraint); + result.forEach(x -> x.addAll(methodSignatureConstraint)); + /* + result = result.stream().map( + x -> { Optional> help = rules.subst(x); + return help.isPresent() ? + help.get(): + x; }).collect(Collectors.toSet()); + */ + } } //2020-02-02: if (variance ==2) Hier Aufruf von filterOverriding einfuegen writeLog("Return computeCR: " + result.toString()); @@ -1521,7 +1542,7 @@ public class TypeUnifyTask extends RecursiveTask>> { unitedSubst.addAll(sameEq.getAllBases()); localEq.add(new UnifyPair(aPair.getRhsType(), sameEq.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); finalresult = false; - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, true); finalresult = true; if (isUndefinedPairSetSet(localRes)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) { @@ -1539,7 +1560,7 @@ public class TypeUnifyTask extends RecursiveTask>> { unitedSubst.addAll(sameEq.getAllBases()); localEq.add(new UnifyPair(sameEq.getLhsType(), aPair.getRhsType(), sameEq.getPairOp(), unitedSubst, null)); finalresult = false; - Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0); + Set> localRes = unify(localEq, new ArrayList<>(), fc, false, 0, true); finalresult = true; if (isUndefinedPairSetSet(localRes)) { if (result.isEmpty() || isUndefinedPairSetSet(result)) {