diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index ab589e8d..e264f0f4 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -534,13 +534,13 @@ public class JavaTXCompiler { // Set> result = unify.unifySequential(xConsSet, finiteClosure, // logFile, log); // Set> result = unify.unify(xConsSet, finiteClosure); - List>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> { + List>> oderConstraints = unifyCons.getOderConstraints()/*.stream().map(x -> { Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); } return ret; - }).collect(Collectors.toCollection(ArrayList::new)); + }).collect(Collectors.toCollection(ArrayList::new))*/; unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks); } catch (IOException e) { @@ -722,13 +722,13 @@ public class JavaTXCompiler { // Set> result = unify.unifySequential(xConsSet, finiteClosure, // logFile, log); // Set> result = unify.unify(xConsSet, finiteClosure); - List>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> { - Set> ret = new HashSet<>(); + List>> oderConstraints = unifyCons.getOderConstraints()//.stream().map(x -> { + /*Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); } return ret; - }).collect(Collectors.toCollection(ArrayList::new)); + }).collect(Collectors.toCollection(ArrayList::new))*/; if (resultmodel) { /* UnifyResultModel Anfang */ UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java index d75602d6..c99caa53 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/ClassOrInterface.java @@ -74,7 +74,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{ return methodAdded; } - //Sets taht it is added + //Sets that it is added public void setMethodsAdded() { methodAdded = true; } diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java index 99cd3f91..ec13878e 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/Method.java @@ -31,6 +31,7 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope private ExceptionList exceptionlist; private GenericDeclarationList generics; private final RefTypeOrTPHOrWildcardOrGeneric returnType; + public final Boolean isInherited; public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) { @@ -41,6 +42,19 @@ public class Method extends SyntaxTreeNode implements IItemWithOffset, TypeScope this.parameterlist = parameterList; this.block = block; this.generics = gtvDeclarations; + this.isInherited = false; + } + + public Method(int modifier, String name, RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList parameterList, Block block, + GenericDeclarationList gtvDeclarations, Token offset, Boolean isInherited) { + super(offset); + this.name = name; + this.modifier = modifier; + this.returnType = returnType; + this.parameterlist = parameterList; + this.block = block; + this.generics = gtvDeclarations; + this.isInherited = isInherited; } public ParameterList getParameterList() { diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index a682717c..fc704572 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -3,8 +3,11 @@ package de.dhbwstuttgart.syntaxtree.factory; import java.lang.reflect.*; import java.lang.reflect.Constructor; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; @@ -35,8 +38,15 @@ public class ASTFactory { for(java.lang.reflect.Constructor constructor : jreClass.getConstructors()){ konstruktoren.add(createConstructor(constructor, jreClass)); } - for(java.lang.reflect.Method method : jreClass.getMethods()){ - methoden.add(createMethod(method, jreClass)); + Set allMethods = new HashSet<>(Arrays.asList(jreClass.getMethods())); + Set allDeclaredMethods = new HashSet<>(Arrays.asList(jreClass.getDeclaredMethods())); + Set allInheritedMethods = new HashSet<>(allMethods); + allInheritedMethods.removeAll(allDeclaredMethods); + for(java.lang.reflect.Method method : allDeclaredMethods){ + methoden.add(createMethod(method, jreClass, false)); + } + for(java.lang.reflect.Method method : allInheritedMethods){ + methoden.add(createMethod(method, jreClass, true)); } List felder = new ArrayList<>(); for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){ @@ -102,7 +112,7 @@ public class ASTFactory { return new de.dhbwstuttgart.syntaxtree.Constructor(modifier, name,returnType, parameterList, block, gtvDeclarations, offset /*, new ArrayList<>() geloescht PL 2018-11-24 */); } - public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass){ + public static Method createMethod(java.lang.reflect.Method jreMethod, java.lang.Class inClass, Boolean isInherited){ String name = jreMethod.getName(); RefTypeOrTPHOrWildcardOrGeneric returnType; Type jreRetType; @@ -126,7 +136,7 @@ public class ASTFactory { GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName()); Token offset = new NullToken(); - return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset); + return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited); } public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName){ diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 84d0f1e5..addcc61e 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -153,8 +153,12 @@ public class UnifyTypeFactory { return constraints.map(UnifyTypeFactory::convert); } + //never used public static Constraint convert(Constraint constraint){ - return constraint.stream().map(UnifyTypeFactory::convert).collect(Collectors.toCollection(Constraint::new)); + Boolean isInherited = constraint.isInherited(); + Constraint unifyPairConstraint = constraint.stream().map(UnifyTypeFactory::convert).collect(Collectors.toCollection(Constraint::new)); + unifyPairConstraint.setIsInherited(isInherited); + return unifyPairConstraint; } public static UnifyPair convert(Pair p) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java index c1a6d449..6e6c5c5a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/assumptions/MethodAssumption.java @@ -17,13 +17,15 @@ public class MethodAssumption extends Assumption{ private ClassOrInterface receiver; private RefTypeOrTPHOrWildcardOrGeneric retType; List params; + private final Boolean isInherited; public MethodAssumption(ClassOrInterface receiver, RefTypeOrTPHOrWildcardOrGeneric retType, - List params, TypeScope scope){ + List params, TypeScope scope, Boolean isInherited){ super(scope); this.receiver = receiver; this.retType = retType; this.params = params; + this.isInherited = isInherited; } /* @@ -70,4 +72,8 @@ public class MethodAssumption extends Assumption{ return receiverType; } + + public Boolean isInherited() { + return isInherited; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index 476f18dd..fbccd8b8 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -7,4 +7,25 @@ import java.util.HashSet; import java.util.Set; public class Constraint extends HashSet { + private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt + + public Constraint() { + super(); + } + + public Constraint(Boolean isInherited) { + this.isInherited = isInherited; + } + + public void setIsInherited(Boolean isInherited) { + this.isInherited = isInherited; + } + + public Boolean isInherited() { + return isInherited; + } + + public String toString() { + return super.toString() + " isInherited = " + isInherited; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index bc0ad928..d8190e7d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -51,8 +51,12 @@ public class ConstraintSet { List>> newOder = new ArrayList<>(); for(Set> oderConstraint : oderConstraints){ newOder.add( - oderConstraint.parallelStream().map((Constraint as) -> - as.stream().map(o).collect(Collectors.toCollection(Constraint::new))).collect(Collectors.toSet()) + oderConstraint.parallelStream().map((Constraint as) -> { + Boolean isInherited = as.isInherited(); + Constraint newConst = as.stream().map(o).collect(Collectors.toCollection(Constraint::new)); + newConst.setIsInherited(isInherited); + return newConst; + }).collect(Collectors.toSet()) ); } ret.oderConstraints = newOder; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index cf67b857..364077f2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -175,6 +175,7 @@ public class TYPEStmt implements StatementVisitor{ !(x.TA2 instanceof TypePlaceholder)) ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : x).collect(Collectors.toCollection(Constraint::new)); + oneMethodConstraint.setIsInherited(m.isInherited()); methodConstraints.add(oneMethodConstraint); } if(methodConstraints.size()<1){ @@ -567,7 +568,7 @@ public class TYPEStmt implements StatementVisitor{ protected Constraint generateConstraint(MethodCall forMethod, MethodAssumption assumption, TypeInferenceBlockInformation info, GenericsResolver resolver){ - Constraint methodConstraint = new Constraint<>(); + Constraint methodConstraint = new Constraint<>(assumption.isInherited()); ClassOrInterface receiverCl = assumption.getReceiver(); /* List params = new ArrayList<>(); @@ -633,7 +634,7 @@ public class TYPEStmt implements StatementVisitor{ public RefTypeOrTPHOrWildcardOrGeneric getReturnType() { throw new NotImplementedException(); } - })); + }, false)); } for(ClassOrInterface cl : info.getAvailableClasses()){ for(Method m : cl.getMethods()){ @@ -642,7 +643,7 @@ public class TYPEStmt implements StatementVisitor{ RefTypeOrTPHOrWildcardOrGeneric retType = m.getReturnType();//info.checkGTV(m.getReturnType()); ret.add(new MethodAssumption(cl, retType, convertParams(m.getParameterList(),info), - createTypeScope(cl, m))); + createTypeScope(cl, m), m.isInherited)); } } } @@ -677,7 +678,7 @@ public class TYPEStmt implements StatementVisitor{ for(Method m : cl.getConstructors()){ if(m.getParameterList().getFormalparalist().size() == argList.getArguments().size()){ ret.add(new MethodAssumption(cl, ofType, convertParams(m.getParameterList(), - info), createTypeScope(cl, m))); + info), createTypeScope(cl, m), m.isInherited)); } } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index 755cbf0a..e52b3cd0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.WildcardType; +import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.distributeVariance; import java.io.FileWriter; @@ -631,7 +632,7 @@ public class RuleSet implements IRuleSet{ } @Override - public Optional> subst(Set pairs, List>> oderConstraints) { + public Optional> subst(Set pairs, List>> oderConstraints) { HashMap typeMap = new HashMap<>(); Stack occuringTypes = new Stack<>(); @@ -678,17 +679,17 @@ public class RuleSet implements IRuleSet{ result = result.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(ArrayList::new)); result1 = result1.stream().map(x -> uni.apply(pair,x)).collect(Collectors.toCollection(LinkedList::new)); - Function,? extends HashSet> applyUni = b -> b.stream().map( - x -> uni.apply(pair,x)).collect(Collectors.toCollection(HashSet::new)); + Function,? extends Constraint> applyUni = b -> b.stream().map( + x -> uni.apply(pair,x)).collect(Collectors.toCollection(Constraint::new)); List>> oderConstraintsRet = new ArrayList<>(); - for(Set> oc : oderConstraints) { + for(Set> oc : oderConstraints) { //Set> ocRet = new HashSet<>(); //for(Set cs : oc) { Set> csRet = oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new)); oderConstraintsRet.add(csRet); //} } - oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(HashSet::new))); + oderConstraints.replaceAll(oc -> oc.stream().map(applyUni).collect(Collectors.toCollection(Constraint::new))); /* oderConstraints = oderConstraints.stream().map( a -> a.stream().map(applyUni diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 6b045547..d78d8c8d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -28,7 +28,7 @@ public class TypeUnify { * @param cons * @return */ - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); @@ -54,7 +54,7 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); @@ -72,7 +72,7 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); @@ -105,7 +105,7 @@ public class TypeUnify { * @param cons * @return */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks); Set> res = unifyTask.compute(); try { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 54c3fb99..798c6f05 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -18,7 +18,7 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 127b0fb4..8ebce509 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -101,7 +101,7 @@ public class TypeUnifyTask extends RecursiveTask>> { protected Set eq; //und-constraints - protected List>> oderConstraintsField; + protected List>> oderConstraintsField; protected IFiniteClosure fc; @@ -146,7 +146,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); @@ -247,7 +247,7 @@ public class TypeUnifyTask extends RecursiveTask>> { oderConstraintsField.stream() .filter(x -> x.size()==1) .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); - ArrayList>> remainingOderconstraints = oderConstraintsField.stream() + ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true); @@ -292,7 +292,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, Boolean finalresult) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //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()); @@ -357,7 +357,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // There are up to 10 toplevel set. 8 of 10 are the result of the // cartesian product of the sets created by pattern matching. - List>> topLevelSets = new ArrayList<>(); + List>> topLevelSets = new ArrayList<>(); //System.out.println(eq2s); @@ -385,8 +385,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); - Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); + List>> oderConstraintsOutput = new ArrayList<>();//new ArrayList<>(oderConstraints); + Set>>> secondLevelSets = calculatePairSets(eq2s, oderConstraints, fc, undefinedPairs, oderConstraintsOutput); //PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer //nicht ausgewertet Faculty Beispiel im 1. Schritt //PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren @@ -434,8 +434,8 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden - for(Set>> secondLevelSet : secondLevelSets) { - for (Set> secondlevelelem : secondLevelSet) { + for(Set>> secondLevelSet : secondLevelSets) { + for (Set> secondlevelelem : secondLevelSet) { topLevelSets.add(secondlevelelem); } } @@ -450,7 +450,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } - Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -482,7 +482,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("vor Subst: " + eqPrime); writeLog("vor Subst: " + oderConstraints); String ocString = oderConstraints.toString(); - List>> newOderConstraints = new ArrayList<>(oderConstraints); + List>> newOderConstraints = new ArrayList<>(oderConstraints); Optional> eqPrimePrime = rules.subst(eqPrime, newOderConstraints); Set> unifyres1 = null; Set> unifyres2 = null; @@ -572,21 +572,21 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) .map(y -> y.stream().findFirst().get()) .collect(Collectors.toCollection(HashSet::new))); - ArrayList>> remainingSets = topLevelSets.stream() + ArrayList>> remainingSets = topLevelSets.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe, finalresult); return result; } - Set> nextSet = remainingSets.remove(0); + Set> nextSet = remainingSets.remove(0); writeLog("nextSet: " + nextSet.toString()); List> nextSetasList =new ArrayList<>(nextSet); try { @@ -835,7 +835,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); - List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ @@ -891,7 +891,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); - List>> newOderConstraints = new ArrayList<>(oderConstraints); + List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); forks.add(fork); @@ -943,7 +943,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); - List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ @@ -999,7 +999,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); - List>> newOderConstraints = new ArrayList<>(oderConstraints); + List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); forks.add(fork); @@ -1052,7 +1052,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); - List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ @@ -1075,7 +1075,7 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03 Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); - List>> newOderConstraints = new ArrayList<>(oderConstraints); + List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); forks.add(fork); @@ -1288,7 +1288,8 @@ public class TypeUnifyTask extends RecursiveTask>> { while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a_new.equals(a_next) || - (oup.compare(a_new, a_next) == 1)) { + ((oup.compare(a_new, a_next) == 1) && + (!oderConstraint || ((Constraint)a_next).isInherited()))) { writeLog("Removed: " + a_next.toString()); nextSetasList.remove(a_next); } @@ -1336,7 +1337,8 @@ public class TypeUnifyTask extends RecursiveTask>> { while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a_new.equals(a_next) || - (oup.compare(a_new, a_next) == -1)) { + ((oup.compare(a_new, a_next) == -1) && + (!oderConstraint || ((Constraint)a_new).isInherited()))) { writeLog("Removed: " + a_next.toString()); nextSetasList.remove(a_next); //PL geaendert 2019-01-09 } @@ -1813,10 +1815,10 @@ public class TypeUnifyTask extends RecursiveTask>> { * from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements * (as in case 1 where sigma is added to the innermost set). */ - protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { writeLog("eq2s: " + eq2s.toString()); oderConstraintsOutput.addAll(oderConstraintsInput); - List>>> result = new ArrayList<>(9); + List>>> result = new ArrayList<>(9); // Init all 8 cases + 9. Case: oderConstraints for(int i = 0; i < 9; i++) @@ -1869,8 +1871,9 @@ public class TypeUnifyTask extends RecursiveTask>> { eq2s.remove(up); } } - if (eq2sAsListFst.isEmpty()) { - List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind + //if (eq2sAsListFst.isEmpty()) + { + List>> oderConstraintsVariance = oderConstraintsOutput.stream() //Alle Elemente rauswerfen, die Variance 0 haben oder keine TPH in LHS oder RHS sind .filter(x -> x.stream() .filter(y -> y.stream().filter(z -> ((z.getLhsType() instanceof PlaceholderType) @@ -1880,7 +1883,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ).findFirst().isPresent() ).findFirst().isPresent()).collect(Collectors.toList()); if (!oderConstraintsVariance.isEmpty()) { - Set> ret = oderConstraintsVariance.get(0); + Set> ret = oderConstraintsVariance.get(0); oderConstraintsOutput.remove(ret); //Set retFlat = new HashSet<>(); //ret.stream().forEach(x -> retFlat.addAll(x)); @@ -1915,7 +1918,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet if (!oderConstraintsOutput.isEmpty()) { - Set> ret = oderConstraintsOutput.remove(0); + Set> ret = oderConstraintsOutput.remove(0); //if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M")) // System.out.println("M"); //Set retFlat = new HashSet<>(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java index 752ff8b2..bac6bcb0 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; import java.util.Set; +import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; /** @@ -91,7 +92,7 @@ public interface IRuleSet { * @param pairs The set of pairs where the subst rule should apply. * @return An optional of the modified set, if there were any substitutions. An empty optional if there were no substitutions. */ - public Optional> subst(Set pairs, List>> oderConstraints); + public Optional> subst(Set pairs, List>> oderConstraints); /** * Applies the subst-Rule to a set of pairs (usually Eq'). diff --git a/src/test/java/AllgemeinTest.java b/src/test/java/AllgemeinTest.java index 9905f315..73f29ea9 100644 --- a/src/test/java/AllgemeinTest.java +++ b/src/test/java/AllgemeinTest.java @@ -38,7 +38,8 @@ public class AllgemeinTest { //String className = "FCTest2"; //String className = "Pair"; //String className = "FCTest3"; - String className = "Var"; + //String className = "Var"; + String className = "Put"; //PL 2019-10-24: genutzt fuer unterschiedliche Tests path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/" + className + ".jav"; //path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";