diff --git a/pom.xml b/pom.xml index 8ae93bf58..3c31a7e8e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,8 +1,7 @@ - +http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 de.dhbwstuttgart JavaTXcompiler @@ -68,7 +67,7 @@ src/main/antlr4/java8 - ${project.basedir}/target/generated-sources/de/dhbwstuttgart/parser/antlr + ${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/parser/antlr -package de.dhbwstuttgart.parser.antlr @@ -82,7 +81,7 @@ src/main/antlr4/sat - ${project.basedir}/target/generated-sources/de/dhbwstuttgart/sat/asp/parser/antlr + ${project.basedir}/target/generated-sources/antlr4/de/dhbwstuttgart/sat/asp/parser/antlr -package de.dhbwstuttgart.sat.asp.parser.antlr @@ -139,19 +138,10 @@ - - org.eclipse.tycho - tycho-p2-repository-plugin - ${tycho.version} - - - package - - archive-repository - - - - + @@ -179,3 +169,5 @@ + + diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index d46702891..ff2c49a30 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -832,7 +832,9 @@ public class BytecodeGenMethod implements StatementVisitor { System.out.println(methods[i]); } methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods); - }catch (Exception e2) { + } + catch (Exception e2) { + System.out.println(""); //do nothing } } diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index a860adf98..f8d4a363b 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -1,3 +1,4 @@ +//PL 2018-12-19: typeInferenceOld nach typeInference uebertragen package de.dhbwstuttgart.core; @@ -15,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter; import de.dhbwstuttgart.typeinference.constraints.Constraint; @@ -29,6 +31,7 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; import java.io.File; @@ -44,7 +47,7 @@ public class JavaTXCompiler { final CompilationEnvironment environment; public final Map sourceFiles = new HashMap<>(); - Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile)); @@ -103,7 +106,8 @@ public class JavaTXCompiler { return new ArrayList<>(allClasses); } - public List typeInference() throws ClassNotFoundException { +/* + public List typeInferenceOld() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { @@ -187,10 +191,7 @@ public class JavaTXCompiler { } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE - }) - /* PL 2018-11-07 wird in varianceInheritance erledigt - .map( y -> { - + }).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()); @@ -200,20 +201,16 @@ public class JavaTXCompiler { } } return y; } ) - */ .collect(Collectors.toCollection(HashSet::new)); - varianceInheritance(xConsSet); - - - - Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); - //Set> result = unify.unify(xConsSet, finiteClosure); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); + varianceInheritance(xConsSet); + Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); } - + results = results.stream().map(x -> { Optional> res = new RuleSet().subst(x.stream().map(y -> { if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); @@ -236,12 +233,14 @@ public class JavaTXCompiler { return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); } - + */ /** - * Vererbt alle Variancen + * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) + * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. * @param eq The set of constraints */ - private void varianceInheritance(Set eq) { + /* + private void varianceInheritance(Set eq) { Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { Set pair = new HashSet<>(); @@ -267,6 +266,203 @@ public class JavaTXCompiler { phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } } + */ + + + public List typeInference() throws ClassNotFoundException { + List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC + for(SourceFile sf : this.sourceFiles.values()) { + allClasses.addAll(getAvailableClasses(sf)); + allClasses.addAll(sf.getClasses()); + } + + final ConstraintSet cons = getConstraints(); + Set> results = new HashSet<>(); + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + + FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); + System.out.println(finiteClosure); + ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); + + Function distributeInnerVars = + x -> { + UnifyType lhs, rhs; + if (((lhs = x.getLhsType()) instanceof PlaceholderType) + && ((rhs = x.getRhsType()) instanceof PlaceholderType) + && (((PlaceholderType)lhs).isInnerType() + || ((PlaceholderType)rhs).isInnerType())) + { + ((PlaceholderType)lhs).setInnerType(true); + ((PlaceholderType)rhs).setInnerType(true); + } + return x; + + }; + logFile.write(unifyCons.toString()); + unifyCons = unifyCons.map(distributeInnerVars); + logFile.write(unifyCons.toString()); + TypeUnify unify = new TypeUnify(); + //Set> results = new HashSet<>(); Nach vorne gezogen + logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + for(SourceFile sf : this.sourceFiles.values()) { + logFile.write(ASTTypePrinter.print(sf)); + } + logFile.flush(); + + Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); + + Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); + + Set paraTypeVarNames = methodParaTypeVarNames; + paraTypeVarNames.addAll(constructorParaTypeVarNames); + + + Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + Set fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + returnTypeVarNames.addAll(fieldTypeVarNames); + + unifyCons = unifyCons.map(x -> { + //Hier muss ueberlegt werden, ob + //1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs + // mit disableWildcardtable() werden. + //2. alle Typvariablen mit Argument- oder Retuntyp-Variablen + //in Beziehung auch auf disableWildcardtable() gesetzt werden muessen + //PL 2018-04-23 + if ((x.getLhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + 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;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE + }); + Set varianceTPHold; + Set varianceTPH = new HashSet<>(); + varianceTPH = varianceInheritanceConstraintSet(unifyCons); + + /* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt + do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen + //anderen Seite übertragen + varianceTPHold = new HashSet<>(varianceTPH); + varianceTPH = varianceInheritanceConstraintSet(unifyCons); + unifyCons.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()); + } + } + return y; } ); } + while (!varianceTPHold.equals(varianceTPH)); + */ + + //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); + + + results = results.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + System.out.println("RESULT Final: " + results); + logFile.write("RES_FINAL: " + results.toString()+"\n"); + logFile.flush(); + logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); + logFile.flush(); + } + catch (IOException e) { + System.err.println("kein LogFile"); + } + return results.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); + } + + + /** + * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) + * wenn a eine Variance !=0 hat auf alle Typvariablen in Theta. + * @param eq The set of constraints + */ + private Set varianceInheritanceConstraintSet(ConstraintSet cons) { + Set eq = cons.getAll(); + Set usedTPH = new HashSet<>(); + Set phSet = eq.stream().map(x -> { + Set pair = new HashSet<>(); + if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); + if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); + return pair; + }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;}); + + ArrayList phSetVariance = new ArrayList<>(phSet); + phSetVariance.removeIf(x -> (x.getVariance() == 0)); + while(!phSetVariance.isEmpty()) { + PlaceholderType a = phSetVariance.remove(0); + usedTPH.add(a); + //HashMap ht = new HashMap<>(); + //ht.put(a, a.getVariance()); + //ConstraintSet eq1 = cons; + //eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); + //durch if-Abfrage im foreach geloest + cons.forEach(x -> { + if (x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)) { + x.getRhsType().accept(new distributeVariance(), a.getVariance()); + } + }); + //` eq1 = new HashSet<>(eq); + //eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); + //durch if-Abfrage im foreach geloest + cons.forEach(x -> { + if (x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)) { + x.getLhsType().accept(new distributeVariance(), a.getVariance()); + } + }); + phSetVariance = new ArrayList<>(phSet); //macht vermutlich keinen Sinn PL 2018-10-18, doch, es koennen neue TPHs mit Variancen dazugekommen sein PL 2018-11-07 + phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); + } + return usedTPH; + } + private Map generateTPHMap(ConstraintSet constraints) { HashMap ret = new HashMap<>(); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 71985334e..f3fbdd636 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.syntaxtree.factory; +import java.io.FileWriter; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -29,7 +30,7 @@ public class UnifyTypeFactory { private static ArrayList PLACEHOLDERS = new ArrayList<>(); - public static FiniteClosure generateFC(List fromClasses) throws ClassNotFoundException { + public static FiniteClosure generateFC(List fromClasses, FileWriter logFile) throws ClassNotFoundException { /* Die transitive Hülle muss funktionieren. Man darf schreiben List extends AL @@ -40,7 +41,7 @@ public class UnifyTypeFactory { Generell dürfen sie immer die gleichen Namen haben. TODO: die transitive Hülle bilden */ - return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses)); + return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses), logFile); } public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){ @@ -63,26 +64,26 @@ public class UnifyTypeFactory { * Convert from * ASTType -> UnifyType */ - public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t){ + public static UnifyType convert(RefTypeOrTPHOrWildcardOrGeneric t, Boolean innerType){ if(t instanceof GenericRefType){ - return UnifyTypeFactory.convert((GenericRefType)t); + return UnifyTypeFactory.convert((GenericRefType)t, innerType); }else if(t instanceof FunN){ - return UnifyTypeFactory.convert((FunN)t); + return UnifyTypeFactory.convert((FunN)t, innerType); }else if(t instanceof TypePlaceholder){ - return UnifyTypeFactory.convert((TypePlaceholder)t); + return UnifyTypeFactory.convert((TypePlaceholder)t, innerType); }else if(t instanceof ExtendsWildcardType){ - return UnifyTypeFactory.convert((ExtendsWildcardType)t); + return UnifyTypeFactory.convert((ExtendsWildcardType)t, innerType); }else if(t instanceof SuperWildcardType){ - return UnifyTypeFactory.convert((SuperWildcardType)t); + return UnifyTypeFactory.convert((SuperWildcardType)t, innerType); }else if(t instanceof RefType){ - return UnifyTypeFactory.convert((RefType)t); + return UnifyTypeFactory.convert((RefType)t, innerType); } //Es wurde versucht ein Typ umzuwandeln, welcher noch nicht von der Factory abgedeckt ist throw new NotImplementedException("Der Typ "+t+" kann nicht umgewandelt werden"); } - public static UnifyType convert(RefType t){ + public static UnifyType convert(RefType t, Boolean innerType){ //Check if it is a FunN Type: Pattern p = Pattern.compile("Fun(\\d+)"); Matcher m = p.matcher(t.getName().toString()); @@ -90,14 +91,14 @@ public class UnifyTypeFactory { if(b){ Integer N = Integer.valueOf(m.group(1)); if((N + 1) == t.getParaList().size()){ - return convert(new FunN(t.getParaList())); + return convert(new FunN(t.getParaList()), false); } } UnifyType ret; if(t.getParaList() != null && t.getParaList().size() > 0){ List params = new ArrayList<>(); for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ - params.add(UnifyTypeFactory.convert(pT)); + params.add(UnifyTypeFactory.convert(pT, true)); } ret = new ReferenceType(t.getName().toString(),new TypeParams(params)); }else{ @@ -106,39 +107,45 @@ public class UnifyTypeFactory { return ret; } - public static UnifyType convert(FunN t){ + public static UnifyType convert(FunN t, Boolean innerType){ UnifyType ret; List params = new ArrayList<>(); if(t.getParaList() != null && t.getParaList().size() > 0){ for(RefTypeOrTPHOrWildcardOrGeneric pT : t.getParaList()){ - params.add(UnifyTypeFactory.convert(pT)); + params.add(UnifyTypeFactory.convert(pT, false)); } } ret = FunNType.getFunNType(new TypeParams(params)); return ret; } - public static UnifyType convert(TypePlaceholder tph){ + public static UnifyType convert(TypePlaceholder tph, Boolean innerType){ + if (tph.getName().equals("AFR")) { + System.out.println("XXX"+innerType); + } PlaceholderType ntph = new PlaceholderType(tph.getName()); int in = PLACEHOLDERS.indexOf(ntph); if (in == -1) { PLACEHOLDERS.add(ntph); + ntph.setInnerType(innerType); return ntph; } else { - return PLACEHOLDERS.get(in); + PlaceholderType oldpht = PLACEHOLDERS.get(in); + oldpht.setInnerType(oldpht.isInnerType() || innerType); + return oldpht; } } - public static UnifyType convert(GenericRefType t){ + public static UnifyType convert(GenericRefType t, Boolean innerType){ return new ReferenceType(t.getParsedName()); } - public static UnifyType convert(WildcardType t){ + public static UnifyType convert(WildcardType t, Boolean innerType){ if(t.isExtends()) - return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType())); + return new ExtendsType(UnifyTypeFactory.convert(t.getInnerType(), false)); else if(t.isSuper()) - return new SuperType(UnifyTypeFactory.convert(t.getInnerType())); + return new SuperType(UnifyTypeFactory.convert(t.getInnerType(), false)); else throw new NotImplementedException(); } @@ -152,22 +159,42 @@ public class UnifyTypeFactory { } public static UnifyPair convert(Pair p) { + UnifyPair ret = null; if(p.GetOperator().equals(PairOperator.SMALLERDOT)) { - UnifyPair ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1) - , UnifyTypeFactory.convert(p.TA2)); - return ret; + ret = generateSmallerDotPair(UnifyTypeFactory.convert(p.TA1, false) + , UnifyTypeFactory.convert(p.TA2, false)); + //return ret; }else if(p.GetOperator().equals(PairOperator.SMALLERNEQDOT)) { - UnifyPair ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1) - , UnifyTypeFactory.convert(p.TA2)); - return ret; + ret = generateSmallNotEqualDotPair(UnifyTypeFactory.convert(p.TA1, false) + , UnifyTypeFactory.convert(p.TA2, false)); + //return ret; }else if(p.GetOperator().equals(PairOperator.EQUALSDOT)) { - UnifyPair ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1) - , UnifyTypeFactory.convert(p.TA2)); - return ret; + ret = generateEqualDotPair(UnifyTypeFactory.convert(p.TA1, false) + , UnifyTypeFactory.convert(p.TA2, false)); + //return ret; }else if(p.GetOperator().equals(PairOperator.SMALLER)){ - return generateSmallerPair(UnifyTypeFactory.convert(p.TA1), - UnifyTypeFactory.convert(p.TA2)); + ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1, false), + UnifyTypeFactory.convert(p.TA2, false)); }else throw new NotImplementedException(); + UnifyType lhs, rhs; + if (((lhs = ret.getLhsType()) instanceof PlaceholderType) + && ((PlaceholderType)lhs).isWildcardable() + && (rhs = ret.getLhsType()) instanceof PlaceholderType) { + if (lhs.getName().equals("AQ")) { + System.out.println(""); + } + ((PlaceholderType)rhs).enableWildcardtable(); + } + + if (((rhs = ret.getLhsType()) instanceof PlaceholderType) + && ((PlaceholderType)rhs).isWildcardable() + && (lhs = ret.getLhsType()) instanceof PlaceholderType) { + if (rhs.getName().equals("AQ")) { + System.out.println(""); + } + ((PlaceholderType)lhs).enableWildcardtable(); + } + return ret; } /** diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 01356fe9a..4d1f076f3 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import java.util.*; +import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -52,4 +53,29 @@ public class ConstraintSet { ret.oderConstraints = newOder; return ret; } + + public void forEach (Consumer c) { + undConstraints.stream().forEach(c); + for(Set> oderConstraint : oderConstraints){ + oderConstraint.parallelStream().forEach((Constraint as) -> + as.stream().forEach(c)); + } + } + + public Set getAll () { + Set ret = new HashSet<>(); + ret.addAll(undConstraints); + for(Set> oderConstraint : oderConstraints){ + oderConstraint.parallelStream().forEach((Constraint as) -> ret.addAll(as)); + } + return ret; + } + + public List>> getOderConstraints() { + return oderConstraints; + } + + public Set getUndConstraints() { + return undConstraints; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 2f705c67d..4fd14fbc8 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -1,3 +1,4 @@ +//PL 2018-12-19: Merge chekcen package de.dhbwstuttgart.typeinference.typeAlgo; import de.dhbwstuttgart.exceptions.NotImplementedException; @@ -228,6 +229,13 @@ public class TYPEStmt implements StatementVisitor{ binary.operation.equals(BinaryExpr.Operator.ADD)|| binary.operation.equals(BinaryExpr.Operator.SUB)){ Set> numericAdditionOrStringConcatenation = new HashSet<>(); + +// TODO PL 2018-11-06 + + // Auf importierte Typen einschraenken + // pruefen, ob Typen richtig bestimmt werden. + + //Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer: //see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17 diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java index 78f7360f2..3e9956075 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/Match.java @@ -22,6 +22,8 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; public class Match implements IMatch { @Override + //A =. A ==> True + //A =. A ==> False public Optional match(ArrayList termsList) { // Start with the identity unifier. Substitutions will be added later. diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index fa190cb7f..d2428defc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,9 +1,11 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.util.List; import java.util.Set; import java.util.concurrent.ForkJoinPool; +import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; @@ -21,5 +23,11 @@ public class TypeUnify { Set> res = unifyTask.compute(); return res; } + + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log); + Set> res = unifyTask.compute(); + return res; + } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 801cae504..a149be4cc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1,3 +1,4 @@ +//PL 2018-12-19: Merge checken package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; @@ -18,6 +19,7 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; +import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; @@ -71,7 +73,9 @@ public class TypeUnifyTask extends RecursiveTask>> { */ protected IRuleSet rules; - protected Set eq; + protected Set eq; //und-constraints + + protected List>> oderConstraintsField; protected IFiniteClosure fc; @@ -85,6 +89,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Integer noAllErasedElements = 0; + static Integer noou = 0; + static int noBacktracking; public TypeUnifyTask() { @@ -101,6 +107,25 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(logFile); } + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { + 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)); + this.oderConstraintsField = oderConstraints.stream().map(x -> { + Set> ret = new HashSet<>(); + for (Constraint y : x) { + ret.add(new HashSet<>(y)); + } + return ret; + }).collect(Collectors.toCollection(ArrayList::new)); + + //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.fc = fc; + this.oup = new OrderingUnifyPair(fc); + this.parallel = parallel; + this.logFile = logFile; + this.log = log; + rules = new RuleSet(logFile); + } /** * Vererbt alle Variancen @@ -134,12 +159,279 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ - @Override + protected Set> compute() { - Set> res = unify(eq, fc, parallel); + Set neweq = new HashSet<>(eq); + /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ + oderConstraintsField.stream() + .filter(x -> x.size()==1) + .map(y -> y.stream().findFirst().get()).forEach(x -> neweq.addAll(x)); + ArrayList>> remainingOderconstraints = oderConstraintsField.stream() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, 0); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } +/* + @Override + protected Set> compute() { + Set> fstElems = new HashSet<>(); + fstElems.add(eq); + Set> res = computeCartesianRecursiveOderConstraints(fstElems, oderConstraints, fc, parallel); + if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } + else return res; + } +*/ + + + public Set> computeCartesianRecursiveOderConstraints(Set> fstElems, List>> topLevelSets, IFiniteClosure fc, boolean parallel, int rekTiefe) { + //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() + .filter(x -> x.size()>1) + .collect(Collectors.toCollection(ArrayList::new)); + if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig + Set eq = new HashSet<>(); + fstElems.stream().forEach(x -> eq.addAll(x)); + Set> result = unify(eq, new ArrayList<>(), fc, parallel, rekTiefe); + return result; + } + Set> nextSet = remainingSets.remove(0); + writeLog("nextSet: " + nextSet.toString()); + List> nextSetasList =new ArrayList<>(nextSet); + try { + //List> + //nextSetasList = oup.sortedCopy(nextSet);//new ArrayList<>(nextSet); + } + catch (java.lang.IllegalArgumentException e) { + System.out.print(""); + } + Set> result = new HashSet<>(); + int variance = 0; + Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) + .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) + .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) + .reduce((a,b)-> {if (a==b) return a; else return 0; })) + .filter(d -> d.isPresent()) + .map(e -> e.get()) + .findAny(); + if (xi.isPresent()) { + variance = xi.get(); + } + //if (variance == 1 && nextSetasList.size() > 1) { + // List> al = new ArrayList<>(nextSetasList.size()); + // for (int ii = 0; ii < nextSetasList.size();ii++) { + // al.add(0,nextSetasList.get(ii)); + // } + // nextSetasList = al; + //} + //Set a = nextSetasListIt.next(); + /*if (nextSetasList.size()>1) {zu loeschen + if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D")) + System.out.print(""); + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else if (variance == 0) { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + */ + if (!nextSetasList.iterator().hasNext()) + System.out.print(""); + if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); + writeLog("nextSetasList: " + nextSetasList.toString()); + while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { + Set a = null; + if (variance == 1) { + a = oup.max(nextSetasList.iterator()); + nextSetasList.remove(a); + } + else if (variance == -1) { + a = oup.min(nextSetasList.iterator()); + nextSetasList.remove(a); + } + else if (variance == 0) { + a = nextSetasList.remove(0); + } + //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); + //nextSetasList.remove(a); + /* zu loeschen + if (nextSetasList.size() > 0) { + if (nextSetasList.size()>1) { + if (variance == 1) { + a_next = oup.max(nextSetasList.iterator()); + } + else if (variance == -1) { + a_next = oup.min(nextSetasList.iterator()); + } + else { + a_next = nextSetasList.iterator().next(); + } + } + else { + a_next = nextSetasList.iterator().next(); + } + } + */ + //PL 2018-03-01 + //TODO: 1. Maximum und Minimum unterscheiden + //TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern + //for(Set a : newSet) { + i++; + Set> elems = new HashSet>(fstElems); + elems.add(a); + Set> res = new HashSet<>(); + if (remainingSets.isEmpty()) { + noou++; + writeLog("Vor unify Aufruf: " + eq.toString()); + writeLog("No of Unify " + noou); + System.out.println(noou); + Set eq = new HashSet<>(); + elems.stream().forEach(x -> eq.addAll(x)); + res = unify(eq, new ArrayList<>(), fc, parallel, rekTiefe); + } + else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 + res = computeCartesianRecursiveOderConstraints(elems, remainingSets, fc, parallel, rekTiefe); + + } + if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = res; + } + else { + if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + result.addAll(res); + } + //else { + //wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren + // if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { + // result = result; + // } + //} + } + + + + + /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ + if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { + if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) + System.out.print(""); + Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); + if (variance == 1) { + System.out.println(""); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a.equals(a_next) || + (oup.compare(a, a_next) == 1)) { + nextSetasList.remove(a_next); + } + else { + System.out.println(""); + } + } + } + else { if (variance == -1) { + System.out.println(""); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a.equals(a_next) || + (oup.compare(a, a_next) == -1)) { + nextSetasList.remove(0); + } + else { + System.out.println(""); + } + } + } + else if (variance == 0) { + //break; + }} + } + /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ + + /* PL 2018-11-05 wird falsch weil es auf der obersten Ebene ist. + if (isUndefinedPairSetSet(res)) { + int nofstred= 0; + Set abhSubst = res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllSubstitutions()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) + .reduce((y,z) -> { y.addAll(z); return y;}).get(); + Set b = a;//effective final a + Set durchschnitt = abhSubst.stream() + .filter(x -> b.contains(x)) + //.filter(y -> abhSubst.contains(y)) + .collect(Collectors.toCollection(HashSet::new)); + //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); + int len = nextSetasList.size(); + Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results + Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() + .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen + su.add(x.getGroundBasePair()); // urspruengliches Paar + su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen + return new Pair<>(su, x.getGroundBasePair());}) + .collect(Collectors.toCollection(HashSet::new)); + if (res.size() > 1) { + System.out.println(); + } + nextSetasList = nextSetasList.stream().filter(x -> { + //Boolean ret = false; + //for (PlaceholderType var : vars) { + // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); + //} + return (!x.containsAll(durchschnitt));//Was passiert wenn durchschnitt leer ist?? + })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10 + .collect(Collectors.toCollection(ArrayList::new)); + nofstred = nextSetasList.size(); + //NOCH NICHT korrekt PL 2018-10-12 + //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) + // .collect(Collectors.toCollection(ArrayList::new)); + writeLog("res (undef): " + res.toString()); + writeLog("abhSubst: " + abhSubst.toString()); + writeLog("a: " + a.toString()); + writeLog("Durchschnitt: " + durchschnitt.toString()); + writeLog("nextSet: " + nextSet.toString()); + writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number first erased Elements (undef): " + (len - nofstred)); + writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size())); + writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); + noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); + writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); + noBacktracking++; + writeLog("Number of Backtracking: " + noBacktracking); + System.out.println(""); + } + */ + //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { + // return result; + //} + //else { + // result.removeIf(y -> isUndefinedPairSet(y)); + //} + //else result.stream().filter(y -> !isUndefinedPairSet(y)); + + + } // End of while (nextSetasList.size() > 0) + return result; + } + /** * Computes all principal type unifiers for a set of constraints. @@ -147,18 +439,22 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(Set eq, IFiniteClosure fc, boolean parallel) { + protected Set> unify(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //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()); //if (aas.isEmpty()) { // System.out.println(""); //} + + //.collect(Collectors.toCollection(HashSet::new))); /* * Step 1: Repeated application of reduce, adapt, erase, swap */ + rekTiefe++; nOfUnify++; writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); + writeLog(nOfUnify.toString() + " Oderconstraints: " + oderConstraints.toString()); //eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new)); /* @@ -224,11 +520,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set undefinedPairs = new HashSet<>(); if (printtag) System.out.println("eq2s " + eq2s); //writeLog("BufferSet: " + bufferSet.toString()+"\n"); - Set>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs); + 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 //Typen getestet werden. + writeLog(nOfUnify.toString() + " Oderconstraints2: " + oderConstraintsOutput.toString()); if (printtag) System.out.println("secondLevelSets:" +secondLevelSets); // If pairs occured that did not match one of the cartesian product cases, // those pairs are contradictory and the unification is impossible. @@ -280,12 +578,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //Aufruf von computeCartesianRecursive ANFANG - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); + //writeLog("topLevelSets: " + topLevelSets.toString()); + return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, oderConstraintsOutput, fc, parallel, rekTiefe); } - Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + Set> unify2(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Aufruf von computeCartesianRecursive ENDE //keine Ahnung woher das kommt @@ -312,14 +611,15 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 5: Substitution */ - //System.out.println("vor Subst: " + eqPrime); + //writeLog("vor Subst: " + eqPrime); Optional> eqPrimePrime = rules.subst(eqPrime); - + //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied */ if(parallel) { - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + && oderConstraints.isEmpty()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. @@ -339,26 +639,29 @@ public class TypeUnifyTask extends RecursiveTask>> { } else { // sequentiell (Step 6b is included) if (printtag) System.out.println("nextStep: " + eqPrimePrime); - if (eqPrime.equals(eq) && !eqPrimePrime.isPresent()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch + if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() + && oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. try { if (isSolvedForm(eqPrime)) { - logFile.write(eqPrime.toString()+"\n"); + logFile.write("eqPrime:" + eqPrime.toString()+"\n"); logFile.flush(); } } - catch (IOException e) { } + catch (IOException e) { + System.err.println("log-File nicht vorhanden"); + } eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unify(eqPrimePrime.get(), fc, false); + Set> unifyres = unify(eqPrimePrime.get(), oderConstraints, fc, false, rekTiefe); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unify(eqPrime, fc, false); + Set> unifyres = unify(eqPrime, oderConstraints, fc, false, rekTiefe); eqPrimePrimeSet.addAll(unifyres); @@ -387,7 +690,7 @@ public class TypeUnifyTask extends RecursiveTask>> { - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //ArrayList>> remainingSets = new ArrayList<>(topLevelSets); fstElems.addAll(topLevelSets.stream() .filter(x -> x.size()==1) @@ -397,7 +700,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); if (remainingSets.isEmpty()) {//Alle Elemente sind 1-elementig - Set> result = unify2(fstElems, eq, fc, parallel); + Set> result = unify2(fstElems, eq, oderConstraints, fc, parallel, rekTiefe); return result; } Set> nextSet = remainingSets.remove(0); @@ -415,7 +718,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Optional xi = nextSetasList.stream().map(x -> x.stream().filter(y -> y.getLhsType() instanceof PlaceholderType) .filter(z -> ((PlaceholderType)z.getLhsType()).getVariance() != 0) .map(c -> ((PlaceholderType)c.getLhsType()).getVariance()) - .reduce((a,b)-> {if (a==b) return a; else return 0; })) + .reduce((a,b)-> {if (a==b) return a; else return 2; })) //2 kommt insbesondere bei Oder-Constraints vor .filter(d -> d.isPresent()) .map(e -> e.get()) .findAny(); @@ -463,7 +766,7 @@ public class TypeUnifyTask extends RecursiveTask>> { a = oup.min(nextSetasList.iterator()); nextSetasList.remove(a); } - else if (variance == 0) { + else if (variance == 0 || variance == 2) { a = nextSetasList.remove(0); } //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); @@ -492,10 +795,11 @@ public class TypeUnifyTask extends RecursiveTask>> { //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); + writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n"); elems.add(a); //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt - //writeLog("Vor unify2 Aufruf: " + eq.toString()); - Set> res = unify2(elems, eq, fc, parallel); + //writeLog("Vor unify2 Aufruf: " + elems.toString()); + Set> res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -505,22 +809,42 @@ public class TypeUnifyTask extends RecursiveTask>> { || (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) || result.isEmpty()) { - if (!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) { + if ((!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) //korrekte Loesungen aus und-constraints + && (a.stream().map(x-> (x.getBasePair() != null)).reduce(true, (x, y) -> (x && y)))) //bei oder-Constraints nicht ausfuehren + { + //TODO: PL 2019-01-15: Bug 129: Im Moment wird nur das Maximum und das Minimum des aktuellen Elements betrachtet. + //Die zu vereinigenden Mengen können mehrere Elemente enthalten. Das ist bisher nicht berücksichtigt //Alle Variablen bestimmen die nicht hinzugefügt wurden in a - List vars_a = a.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) - ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar + System.out.println(""); + List vars_a = + a.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) + || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) + ) + .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); Set fstElemRes = res.iterator().next(); Set compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new)); //Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last - List varsLast_a = a_last.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) - ||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //System.out.println(a_last); + a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());}); + List varsLast_a = + a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName()) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType)) + || ((x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))) + && (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getRhsType() instanceof PlaceholderType))) + .map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new)); + //[(java.util.Vector <. gen_aq, , 1), (CEK =. ? extends gen_aq, 1)] KANN VORKOMMEN //erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen Set fstElemResult = result.iterator().next(); Set compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));; - if (variance == 1) { + writeLog("a_last:" + a_last + " a: " + a); + writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); + writeLog("compResult:" + compResult + " compRes: " + compRes); int resOfCompare = oup.compare(compResult, compRes); if (resOfCompare == -1) { writeLog("Geloescht result: " + result); @@ -534,6 +858,9 @@ public class TypeUnifyTask extends RecursiveTask>> { //result = result; }}} else { if (variance == -1) { + writeLog("a_last:" + a_last + " a: " + a); + writeLog("varsLast_a:" + varsLast_a + " vars_a: " + vars_a); + writeLog("compResult:" + compResult + " compRes: " + compRes); int resOfCompare = oup.compare(compResult, compRes); if (resOfCompare == 1) { writeLog("Geloescht result: " + result); @@ -575,33 +902,41 @@ public class TypeUnifyTask extends RecursiveTask>> { Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { System.out.println(""); + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a.equals(a_next) || (oup.compare(a, a_next) == 1)) { + writeLog("Removed: " + a_next.toString()); nextSetasList.remove(a_next); } else { + writeLog("Not Removed: " + a_next.toString()); System.out.println(""); } } } else { if (variance == -1) { System.out.println(""); + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) { - nextSetasList.remove(0); + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); //PL geaendert 2019-01-09 } else { System.out.println(""); + writeLog("Not Removed: " + a_next.toString()); } } } else if (variance == 0) { + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } + writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); } } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ @@ -614,6 +949,14 @@ public class TypeUnifyTask extends RecursiveTask>> { .map(x -> x.getAllSubstitutions()) .reduce((y,z) -> { y.addAll(z); return y;}).get()) .reduce((y,z) -> { y.addAll(z); return y;}).get(); + abhSubst.addAll( + res.stream() + .map(b -> + b.stream() + .map(x -> x.getAllBases()) + .reduce((y,z) -> { y.addAll(z); return y;}).get()) + .reduce((y,z) -> { y.addAll(z); return y;}).get() + ); Set b = a;//effective final a Set durchschnitt = abhSubst.stream() .filter(x -> b.contains(x)) @@ -645,7 +988,7 @@ public class TypeUnifyTask extends RecursiveTask>> { // .collect(Collectors.toCollection(ArrayList::new)); writeLog("res (undef): " + res.toString()); writeLog("abhSubst: " + abhSubst.toString()); - writeLog("a: " + a.toString()); + writeLog("a2: " + rekTiefe + " " + a.toString()); writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); @@ -665,7 +1008,10 @@ public class TypeUnifyTask extends RecursiveTask>> { // result.removeIf(y -> isUndefinedPairSet(y)); //} //else result.stream().filter(y -> !isUndefinedPairSet(y)); + writeLog("res: " + res.toString()); } + + writeLog("Return computeCR: " + result.toString()); return result; } @@ -942,15 +1288,18 @@ 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, IFiniteClosure fc, Set undefined) { - List>>> result = new ArrayList<>(8); + protected Set>>> calculatePairSets(Set eq2s, List>> oderConstraintsInput, IFiniteClosure fc, Set undefined, List>> oderConstraintsOutput) { + oderConstraintsOutput.addAll(oderConstraintsInput); + List>>> result = new ArrayList<>(9); - // Init all 8 cases - for(int i = 0; i < 8; i++) + // Init all 8 cases + 9. Case: oderConstraints + for(int i = 0; i < 9; i++) result.add(new HashSet<>()); + ArrayList eq2sprime = new ArrayList<>(eq2s); Iterator eq2sprimeit = eq2sprime.iterator(); ArrayList eq2sAsList = new ArrayList<>(); + Boolean first = true; while(eq2sprimeit.hasNext()) {// alle mit Variance != 0 nach vorne schieben UnifyPair up = eq2sprimeit.next(); if ((up.getLhsType() instanceof PlaceholderType && ((PlaceholderType)up.getLhsType()).getVariance() != 0) @@ -959,8 +1308,45 @@ public class TypeUnifyTask extends RecursiveTask>> { eq2s.remove(up); } } + if (eq2sAsList.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) + && (((PlaceholderType)(z.getLhsType())).getVariance() != 0)) + || ((z.getRhsType() instanceof PlaceholderType) + && (((PlaceholderType)(z.getRhsType())).getVariance() != 0)) + ).findFirst().isPresent() + ).findFirst().isPresent()).collect(Collectors.toList()); + if (!oderConstraintsVariance.isEmpty()) { + Set> ret = oderConstraintsVariance.get(0); + oderConstraintsOutput.remove(ret); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); + first = false; + } + } + eq2sAsList.addAll(eq2s); - Boolean first = true; + + if (eq2sAsList.isEmpty() && first) {//Alle eq2s sind empty und alle oderConstraints mit Variance != 0 sind bearbeitet + if (!oderConstraintsOutput.isEmpty()) { + Set> ret = oderConstraintsOutput.remove(0); + //if (ret.iterator().next().iterator().next().getLhsType().getName().equals("M")) + // System.out.println("M"); + //Set retFlat = new HashSet<>(); + //ret.stream().forEach(x -> retFlat.addAll(x)); + ret.stream().forEach(x -> x.stream().forEach(y -> y.addSubstitutions(x))); + result.get(8).add(ret); + first = false; + } + } + /* + Bei allen die Abhaengigkeit der Elemente aus eq2sAsList als evtl. als Substitution + hinzufuegen + */ for(UnifyPair pair : eq2sAsList) { PairOperator pairOp = pair.getPairOp(); UnifyType lhsType = pair.getLhsType(); @@ -970,6 +1356,9 @@ public class TypeUnifyTask extends RecursiveTask>> { if (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType) { //System.out.println(pair); if (first) { //writeLog(pair.toString()+"\n"); + if (((PlaceholderType)(pair.getLhsType())).getName().equals("AR")) { + System.out.println("AR"); + } Set> x1 = unifyCase1(pair, fc); if (pairOp == PairOperator.SMALLERNEQDOT) { Set remElem = new HashSet<>(); @@ -1112,11 +1501,15 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } - + //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 + // && thetaPrime instanceof ReferenceType + // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector") + // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { + // System.out.println(""); + //} Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] - //PL 18-02-06 entfernt, kommt durch unify wieder rein //cs.add(thetaPrime); //PL 18-02-06 entfernt @@ -1158,19 +1551,21 @@ public class TypeUnifyTask extends RecursiveTask>> { } for(UnifyType tqp : thetaQPrimes) { + Collection tphs = tqp.getInvolvedPlaceholderTypes(); Optional opt = stdUnify.unify(tqp, thetaPrime); if (!opt.isPresent()) { continue; } - Unifier unifier = opt.get(); unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams()); Set substitutionSet = new HashSet<>(); for (Entry sigma : unifier) { - substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, + if (!tphs.contains(sigma.getKey())) {//eingefuegt PL 2019-02-02 Bug 127 + substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT, //TODO: nochmals ueberlegen ob hier pair.getSubstitution() korrekt ist, oder ob leere Menge hin müsste //alle folgenden New UnifyPair ebenfalls ueberpruefen PL 2018-04-19 pair.getSubstitution(), pair)); + } } //List freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben for (UnifyType tq : thetaQs) { @@ -1195,6 +1590,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) { if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12 freshTphs.add(PlaceholderType.freshPlaceholder()); + freshTphs.forEach(x -> ((PlaceholderType)x).setInnerType(true)); resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair)); } @@ -1236,6 +1632,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType aPrime = PlaceholderType.freshPlaceholder(); ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)aPrime).disableWildcardtable(); UnifyType extAPrime = new ExtendsType(aPrime); UnifyType thetaPrime = extThetaPrime.getExtendedType(); Set resultPrime = new HashSet<>(); @@ -1256,12 +1653,14 @@ public class TypeUnifyTask extends RecursiveTask>> { */ private Set> unifyCase3(UnifyPair pair, IFiniteClosure fc) { PlaceholderType a = (PlaceholderType) pair.getLhsType(); + a.reversVariance(); SuperType subThetaPrime = (SuperType) pair.getRhsType(); byte variance = pair.getVariance(); Set> result = new HashSet<>(); UnifyType aPrime = PlaceholderType.freshPlaceholder(); ((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance()); + ((PlaceholderType)aPrime).disableWildcardtable(); UnifyType supAPrime = new SuperType(aPrime); UnifyType thetaPrime = subThetaPrime.getSuperedType(); Set resultPrime = new HashSet<>(); @@ -1295,7 +1694,27 @@ public class TypeUnifyTask extends RecursiveTask>> { break; } - for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { + //eingefuegt PL 2019-01-03 ANFANG + //fc.setLogTrue(); + //writeLog("FBOUNDED: " + pair.getfBounded()); + //writeLog("Pair: " + pair); + Set greater = fc.greater(theta, pair.getfBounded()); + //writeLog("GREATER: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " "); + if (a.isWildcardable()) { + Set greater_ext = greater.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType)) + .map(x -> { + //BinaryOperator> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen + //HashMap hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben + // .reduce(new HashMap(), + // (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner); + return new SuperType (x);})//.accept(new freshPlaceholder(), hm));} + .collect(Collectors.toCollection(HashSet::new)); + greater.addAll(greater_ext); + } + //eingefuegt PL 2019-01-03 ENDE + + //for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) { + for(UnifyType thetaS : greater) { Set resultPrime = new HashSet<>(); Match match = new Match(); @@ -1303,7 +1722,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(int i = 0; !allGen && i < freshTphs.length; i++) { freshTphs[i] = PlaceholderType.freshPlaceholder(); ((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance()); - Set fBounded = pair.getfBounded(); + Set fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt int i_ef = i; BiFunction f = (x,y) -> @@ -1317,7 +1736,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //} BinaryOperator bo = (x,y) -> (x || y); if (fBounded.stream().reduce(false,f,bo)) { - resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); + resultPrime.add(new UnifyPair(freshTphs[i], thetaS.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); } else { fBounded.add(thetaS.getTypeParams().get(i)); @@ -1331,7 +1750,8 @@ public class TypeUnifyTask extends RecursiveTask>> { resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new)); result.add(resultPrime); - //writeLog(resultPrime.toString()); + //writeLog("FBOUNDED2: " + pair.getfBounded()); + //writeLog("resultPrime Theta < a: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " " + resultPrime.toString()); } return result; @@ -1354,6 +1774,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyType freshTph = PlaceholderType.freshPlaceholder(); ((PlaceholderType)freshTph).setVariance(a.getVariance()); + ((PlaceholderType)freshTph).disableWildcardtable(); resultPrime = new HashSet<>(); resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair)); resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair, pair.getfBounded())); @@ -1407,11 +1828,13 @@ public class TypeUnifyTask extends RecursiveTask>> { void writeLog(String str) { if (log) { try { - logFile.write(str+"\n"); + logFile.write(str+"\n\n"); logFile.flush(); } - catch (IOException e) { } + catch (IOException e) { + System.err.println("kein LogFile"); + } } } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java index 3e20f4332..37d70d550 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java @@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; */ public interface IFiniteClosure { + public void setLogTrue(); /** * Returns all types of the finite closure that are subtypes of the argument. * @return The set of subtypes of the argument. diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 4aa769e55..07c864570 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -1,5 +1,7 @@ package de.dhbwstuttgart.typeinference.unify.model; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -30,6 +32,11 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; public class FiniteClosure //extends Ordering //entfernt PL 2018-12-11 implements IFiniteClosure { + FileWriter logFile; + static Boolean log = false; + public void setLogTrue() { + log = true; + } /** * A map that maps every type to the node in the inheritance graph that contains that type. */ @@ -46,10 +53,21 @@ implements IFiniteClosure { */ private Set pairs; + /** + * Hastable fuer die greater-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> greaterHash = new Hashtable<>(); + + /** + * Hastable fuer die smaller-Werte, damit sie nicht doppelt berechnet werden muessen + */ + Hashtable> smallerHash = new Hashtable<>(); + /** * Creates a new instance using the inheritance tree defined in the pairs. */ - public FiniteClosure(Set pairs) { + public FiniteClosure(Set pairs, FileWriter logFile) { + this.logFile = logFile; this.pairs = new HashSet<>(pairs); inheritanceGraph = new HashMap>(); @@ -98,12 +116,29 @@ implements IFiniteClosure { */ @Override public Set smaller(UnifyType type, Set fBounded) { + + Set ret; + if ((ret = smallerHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + if(type instanceof FunNType) return computeSmallerFunN((FunNType) type, fBounded); Set>> ts = new HashSet<>(); ts.add(new Pair<>(type, fBounded)); - return computeSmaller(ts); + Set result = computeSmaller(ts); + smallerHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ + return result; } /** @@ -197,6 +232,13 @@ implements IFiniteClosure { //Eingefuegt PL 2018-05-24 F-Bounded Problematik public Set greater(UnifyType type, Set fBounded) { + Set ret; + if ((ret = greaterHash.get(new hashKeyType(type))) != null) { + //System.out.println(greaterHash); + return new HashSet<>(ret); + } + + if(type instanceof FunNType) { return computeGreaterFunN((FunNType) type, fBounded); } @@ -214,6 +256,17 @@ implements IFiniteClosure { // if T <* T' then sigma(T) <* sigma(T') Set> candidates = strInheritanceGraph.get(type.getName()); + + /* + try { + if (log) logFile.write(candidates.toString()); + //log = false; + } + catch (IOException e) { + System.err.println("no LogFile"); + } + */ + for(Node candidate : candidates) { UnifyType theta1 = candidate.getContent(); @@ -222,9 +275,9 @@ implements IFiniteClosure { termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT)); Optional optSigma = match.match(termList); //PL 18-04-05 Unifier durch Matcher ersetzt ENDE - if(!optSigma.isPresent()) + if(!optSigma.isPresent()) { continue; - + } Unifier sigma = optSigma.get(); sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams()); @@ -237,7 +290,15 @@ implements IFiniteClosure { PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew)); } } - + /* + try { + if (log) logFile.write(PairResultFBounded.toString()); + log = false; + } + catch (IOException e) { + System.err.println("no LogFile"); + } + */ for(Pair> pt : PairResultFBounded) { UnifyType t = pt.getKey(); Set lfBounded = pt.getValue().get(); @@ -273,6 +334,16 @@ implements IFiniteClosure { //System.out.println(""); } } + + greaterHash.put(new hashKeyType(type), result); + /* + try { + logFile.write("\ntype: " + type + "\nret: " + ret + "\nresult: " + result);//"greaterHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile"); + }*/ return result; } @@ -487,7 +558,7 @@ implements IFiniteClosure { result.add(type); return result; } - + @Override public Set getAllTypesByName(String typeName) { if(!strInheritanceGraph.containsKey(typeName)) @@ -607,8 +678,15 @@ implements IFiniteClosure { return 0; } } - if ((right instanceof PlaceholderType) && (left instanceof WildcardType)) { - return 0; + if (right instanceof PlaceholderType) {//&& (left instanceof WildcardType)) {PL geloescht 2019-01-15 analog zu oben + if ((left instanceof WildcardType) //PL eingefuegt 2019-01-15 analog zu oben + && ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType) + && ((PlaceholderType)right).getName().equals(((PlaceholderType)ex).getName())) {// ? extends a <. a oder ? super a <. a + return 1; + } + else { + return 0; + } } UnifyPair up = new UnifyPair(left, right, pairop); TypeUnifyTask unifyTask = new TypeUnifyTask(); 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 c655e6fd2..73d735785 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -30,7 +30,8 @@ public class OrderingUnifyPair extends Ordering> { * in dem compare(Theta, Theta') aufgerufen wird. */ public int compareEq (UnifyPair left, UnifyPair right) { - if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) { + //if (left.getRhsType() instanceof WildcardType || right.getRhsType() instanceof WildcardType) {//PL 2019-01-12 ausgetauscht + if (((PlaceholderType)left.getLhsType()).isInnerType() && ((PlaceholderType)right.getLhsType()).isInnerType()) { return fc.compare(left.getRhsType(), right.getRhsType(), PairOperator.SMALLERDOTWC); } else { @@ -54,6 +55,20 @@ public class OrderingUnifyPair extends Ordering> { UnifyPair up; if (left instanceof WildcardType || right instanceof WildcardType) { up = new UnifyPair(left, right, PairOperator.SMALLERDOTWC); + if (((left instanceof ExtendsType) + && (((ExtendsType)left).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)left).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType)) || + ((right instanceof ExtendsType) + && (((ExtendsType)right).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)right).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType))) + { + System.out.println(""); + } + if (((right instanceof SuperType) && (((SuperType)right).getSuperedType().getName().equals("java.lang.Object"))) + ||((left instanceof SuperType) && (((SuperType)left).getSuperedType().getName().equals("java.lang.Object")))) +{ + System.out.println(""); + } } else { up = new UnifyPair(left, right, PairOperator.SMALLERDOT); @@ -67,6 +82,19 @@ public class OrderingUnifyPair extends Ordering> { else { if (left instanceof WildcardType || right instanceof WildcardType) { up = new UnifyPair(right, left, PairOperator.SMALLERDOTWC); + if (((left instanceof ExtendsType) + && (((ExtendsType)left).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)left).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType)) || + ((right instanceof ExtendsType) + && (((ExtendsType)right).getExtendedType().getName().equals("java.util.Vector")) + && (((ReferenceType)((ExtendsType)right).getExtendedType()).getTypeParams().iterator().next() instanceof ExtendsType))) + { + System.out.println(""); + } + if (right instanceof SuperType) + { + System.out.println(""); + } } else { up = new UnifyPair(right, left, PairOperator.SMALLERDOT); @@ -87,6 +115,16 @@ public class OrderingUnifyPair extends Ordering> { * @see com.google.common.collect.Ordering#compare(java.lang.Object, java.lang.Object) */ public int compare (Set left, Set right) { + if ((left.size() == 1) && right.size() == 1) { + if (left.iterator().next().getLhsType().getName().equals("AFS")) { + System.out.println(""); + } + if (((right.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)right.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object"))) + ||((left.iterator().next().getRhsType() instanceof SuperType) && (((SuperType)left.iterator().next().getRhsType()).getSuperedType().getName().equals("java.lang.Object")))) + { + System.out.println(""); + } + } Set lefteq = left.stream() .filter(x -> (x.getLhsType() instanceof PlaceholderType && x.getPairOp() == PairOperator.EQUALSDOT)) .collect(Collectors.toCollection(HashSet::new)); @@ -110,17 +148,25 @@ public class OrderingUnifyPair extends Ordering> { && x.getPairOp() == PairOperator.SMALLERDOTWC)) .collect(Collectors.toCollection(HashSet::new)); //System.out.println(left.toString()); - //Fall 2 und 3 + //Fall 2 //if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) { // System.out.print(""); //} - if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { + if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { return 1; } - //Fall 2 und 3 - if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) { + //Fall 2 + if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof ExtendsType && rightle.size() == 1) { return -1; } + //Fall 3 + if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof SuperType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) { + return -1; + } + //Fall 3 + if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof SuperType && rightle.size() == 1) { + return 1; + } //Fall 5 if (lefteq.size() == 1 && leftle.size() == 0 && righteq.size() == 1 && rightle.size() == 1) { return -1; 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 012099987..60cf342f2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java @@ -46,6 +46,11 @@ public final class PlaceholderType extends UnifyType{ */ private boolean wildcardable = true; + /** + * is innerType gibt an, ob der Type des PlaceholderType innerhalb eines Typkonstruktorsverwendet wird + */ + private boolean innerType = false; + /** * variance shows the variance of the pair * -1: contravariant @@ -108,6 +113,15 @@ public final class PlaceholderType extends UnifyType{ return variance; } + public void reversVariance() { + if (variance == 1) { + setVariance(-1); + } else { + if (variance == -1) { + setVariance(1); + }} + } + public Boolean isWildcardable() { return wildcardable; } @@ -115,6 +129,22 @@ public final class PlaceholderType extends UnifyType{ wildcardable = false; } + public void enableWildcardtable() { + wildcardable = true; + } + + public void setWildcardtable(Boolean wildcardable) { + this.wildcardable = wildcardable; + } + + public Boolean isInnerType() { + return innerType; + } + + public void setInnerType(Boolean innerType) { + this.innerType = innerType; + } + @Override Set smArg(IFiniteClosure fc, Set fBounded) { return fc.smArg(this, fBounded); @@ -157,7 +187,7 @@ public final class PlaceholderType extends UnifyType{ @Override - public Collection getInvolvedPlaceholderTypes() { + public Collection getInvolvedPlaceholderTypes() { ArrayList ret = new ArrayList<>(); ret.add(this); return ret; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index d69138a72..19f6010f7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -121,6 +121,10 @@ public class UnifyPair { pairOp = po; } + public void addSubstitutions(Set sup) { + substitution.addAll(sup); + } + public byte getVariance() { return variance; } @@ -152,6 +156,15 @@ public class UnifyPair { return ret; } + public Set getAllBases () { + Set ret = new HashSet<>(); + if (basePair != null) { + ret.add(getBasePair()); + ret.addAll(basePair.getAllBases()); + } + return ret; + } + public UnifyPair getGroundBasePair () { if (basePair == null) { return this; @@ -206,12 +219,12 @@ public class UnifyPair { public String toString() { String ret = ""; if (lhs instanceof PlaceholderType) { - ret = new Integer(((PlaceholderType)lhs).getVariance()).toString(); + ret = new Integer(((PlaceholderType)lhs).getVariance()).toString() + " " + ((PlaceholderType)lhs).isInnerType(); } if (rhs instanceof PlaceholderType) { - ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString(); + ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString() + " " + ((PlaceholderType)rhs).isInnerType(); } - return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])"; + return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ")"; //+ ", [" + getfBounded().toString()+ "])"; } /* diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java index bb7bc1c6c..298f87e7d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java @@ -97,7 +97,7 @@ public abstract class UnifyType { return typeName + params; } - public Collection getInvolvedPlaceholderTypes() { + public Collection getInvolvedPlaceholderTypes() { ArrayList ret = new ArrayList<>(); ret.addAll(typeParams.getInvolvedPlaceholderTypes()); return ret; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java index 81999492b..ea70139ff 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/WildcardType.java @@ -64,7 +64,7 @@ public abstract class WildcardType extends UnifyType { @Override - public Collection getInvolvedPlaceholderTypes() { + public Collection getInvolvedPlaceholderTypes() { ArrayList ret = new ArrayList<>(); ret.addAll(wildcardedType.getInvolvedPlaceholderTypes()); return ret; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java new file mode 100644 index 000000000..dedfcd86d --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/hashKeyType.java @@ -0,0 +1,25 @@ +package de.dhbwstuttgart.typeinference.unify.model; + +public class hashKeyType { + UnifyType realType; + + hashKeyType(UnifyType realType) { + this.realType= realType; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof hashKeyType) { + return realType.equals(((hashKeyType)obj).realType); + } + else + { + return false; + } + } + + @Override + public int hashCode() { + return realType.hashCode(); + } +} diff --git a/src/test/java/bytecode/VectorSuperTest.java b/src/test/java/bytecode/VectorSuperTest.java new file mode 100644 index 000000000..7699b684a --- /dev/null +++ b/src/test/java/bytecode/VectorSuperTest.java @@ -0,0 +1,45 @@ +package bytecode; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.BeforeClass; +import org.junit.Test; + +import de.dhbwstuttgart.core.JavaTXCompiler; + +public class VectorSuperTest { + + private static String path; + private static File fileToTest; + private static JavaTXCompiler compiler; + private static ClassLoader loader; + private static Class classToTest; + private static String pathToClassFile; + private static Object instanceOfClass; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/VectorSuper.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler(fileToTest); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; + compiler.generateBytecode(pathToClassFile); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("VectorSuper"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + } + + @Test + public void test1() throws Exception { + Method m = classToTest.getDeclaredMethod("m", Vector.class); + //Object result = m.invoke(instanceOfClass, 1); + + //assertEquals(1,result); + } +} diff --git a/src/test/java/bytecode/YTest.java b/src/test/java/bytecode/YTest.java index 2a63a3ed5..524170ebe 100644 --- a/src/test/java/bytecode/YTest.java +++ b/src/test/java/bytecode/YTest.java @@ -26,8 +26,8 @@ public class YTest { path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Y.jav"; fileToTest = new File(path); // compiler = new JavaTXCompiler(fileToTest); -// compiler.generateBytecode(System.getProperty("user.dir")+"/testBytecode/generatedBC/"); -// pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/"; +// compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"); +// pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/"; // loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); // classToTest = loader.loadClass("Y"); /* diff --git a/src/test/java/javFiles/AddLong.jav b/src/test/java/javFiles/AddLong.jav deleted file mode 100644 index d6d47e9fd..000000000 --- a/src/test/java/javFiles/AddLong.jav +++ /dev/null @@ -1,9 +0,0 @@ -import java.lang.Integer; -import java.lang.Long; - -public class AddLong{ - Long add(Integer a, Long b) { - Long c = a+b; - return c; - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/EmptyClass.jav b/src/test/java/javFiles/EmptyClass.jav deleted file mode 100644 index 8160d7dae..000000000 --- a/src/test/java/javFiles/EmptyClass.jav +++ /dev/null @@ -1,3 +0,0 @@ -public class EmptyClass{ - -} \ No newline at end of file diff --git a/src/test/java/javFiles/EmptyMethod.jav b/src/test/java/javFiles/EmptyMethod.jav deleted file mode 100644 index dd28fc696..000000000 --- a/src/test/java/javFiles/EmptyMethod.jav +++ /dev/null @@ -1,37 +0,0 @@ -public class EmptyMethod{ - static String s1 =""; - String s2; - public void m1(){ - //String s = ""; - System.out.println("test"); - //Integer ab = Math.abs(1); - //Math.abs(1); - //String lV = "local"; - //s1 = "1"; - //s1.concat("2"); - s2 = s1; - //m2(); - Clazz i = new Clazz(); - Integer i = new Integer(1); - } - - public void m2(){} -} - -class Clazz{} -/* -public class EmptyMethod2{ - public static test = "5"; - public void m1(Integer i, String j, Boolean b){ - //String s = ""; - EmptyMethod em = new EmptyMethod(); - em.m1(); - em.s1 = ""; - //Integer ab = Math.abs(1); - //Math.abs(1); - //String lV = "local"; - //s1 = "1"; - //s1.concat("2"); - //s2 = s1; - } -}*/ \ No newline at end of file diff --git a/src/test/java/javFiles/Expressions.jav b/src/test/java/javFiles/Expressions.jav deleted file mode 100644 index e2e992a12..000000000 --- a/src/test/java/javFiles/Expressions.jav +++ /dev/null @@ -1,8 +0,0 @@ -class Expressions{ - -void test(){ - var x = 2; - x = x + 2; -} - -} \ No newline at end of file diff --git a/src/test/java/javFiles/FC_Matrix.jav b/src/test/java/javFiles/FC_Matrix.jav deleted file mode 100644 index 75ead472c..000000000 --- a/src/test/java/javFiles/FC_Matrix.jav +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.Vector; - -class Matrix extends Vector> { - - methode(m) { - m.add(1); - Matrix i; - methode(i); - } - } diff --git a/src/test/java/javFiles/Faculty.jav b/src/test/java/javFiles/Faculty.jav deleted file mode 100644 index ca539adda..000000000 --- a/src/test/java/javFiles/Faculty.jav +++ /dev/null @@ -1,15 +0,0 @@ -import java.lang.Integer; - -class Faculty { - - Integer mul(Integer x, Integer y) { - return x; - } - - m () { - var fact = (Integer x) -> { - return mul(x, fact.apply(x)); - }; - return fact; - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/FacultyIf.jav b/src/test/java/javFiles/FacultyIf.jav deleted file mode 100644 index 3c3689232..000000000 --- a/src/test/java/javFiles/FacultyIf.jav +++ /dev/null @@ -1,17 +0,0 @@ -import java.lang.Integer; - -class Faculty { - - m () { - - var fact = (Integer x) -> { - if (x == 1) { - return x; - } - else { - return x * (fact.apply(x-1)); - } - }; - return fact; - } -} diff --git a/src/test/java/javFiles/FacultyTyped.jav b/src/test/java/javFiles/FacultyTyped.jav deleted file mode 100644 index 089d2f334..000000000 --- a/src/test/java/javFiles/FacultyTyped.jav +++ /dev/null @@ -1,19 +0,0 @@ -import java.lang.Integer; - -class Faculty { - - Integer mul(Integer x, Integer y) { - return x; - } - - Fun1 m () { - var fact = (Integer x) -> { - return mul(x, fact.apply(x)); - }; - return fact; - } -} - -interface Fun1{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/java/javFiles/Fields.jav b/src/test/java/javFiles/Fields.jav deleted file mode 100644 index cd2add71c..000000000 --- a/src/test/java/javFiles/Fields.jav +++ /dev/null @@ -1,11 +0,0 @@ -import java.lang.String; - -class Fields{ -test2 = "test"; -test; -m(){ - var test3; - return test; -} - -} \ No newline at end of file diff --git a/src/test/java/javFiles/Generics.jav b/src/test/java/javFiles/Generics.jav deleted file mode 100644 index dd7b4eba5..000000000 --- a/src/test/java/javFiles/Generics.jav +++ /dev/null @@ -1,22 +0,0 @@ -import java.lang.String; - -class Generics { - // A mt1(A a, B b){ - B mt1(B a, B b){ - return mt1(a, a); - } -} - -class Test { - methode(String s){ - return new Generics().mt1(s,s); - } -} - -/* -Problem: -auto test = new List(); -auto test2 = new List(); -... //code, welcher möglicherweise test und test2 vertauscht -test.add("hallo"); -*/ \ No newline at end of file diff --git a/src/test/java/javFiles/IfTest.jav b/src/test/java/javFiles/IfTest.jav deleted file mode 100644 index 1e1141df2..000000000 --- a/src/test/java/javFiles/IfTest.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.Integer; -import java.lang.Boolean; -import java.lang.Object; - -public class IfTest{ - Object m1(b) { - Integer i; - if(b) { - return i; - }else{ - return b; - } - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Import.jav b/src/test/java/javFiles/Import.jav deleted file mode 100644 index c48082baa..000000000 --- a/src/test/java/javFiles/Import.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v; - v.add(v); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Lambda.jav b/src/test/java/javFiles/Lambda.jav deleted file mode 100644 index 5bd67a0b7..000000000 --- a/src/test/java/javFiles/Lambda.jav +++ /dev/null @@ -1,13 +0,0 @@ - -class Apply { } - -public class Lambda { - - m () { - var lam1 = (x) -> { - return x; - }; - return lam1.apply(new Apply()); - } -} - diff --git a/src/test/java/javFiles/Lambda2.jav b/src/test/java/javFiles/Lambda2.jav deleted file mode 100644 index cf1e910b8..000000000 --- a/src/test/java/javFiles/Lambda2.jav +++ /dev/null @@ -1,33 +0,0 @@ -import java.lang.String; - -public class Lambda2 -{ - public static void main(List args){ - var listOfStrings = new List(); - var listOfObjects; - listOfObjects = map(listOfStrings, (a) -> a); -} - -public map(a , b){ - b.apply(a); - return a; -} - -/* -public static List map(List input, Function func) { - List output; - output = new List(); - output.add(func.apply(input.get())); - return output; -} -*/ -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/java/javFiles/Lambda3.jav b/src/test/java/javFiles/Lambda3.jav deleted file mode 100644 index 9e22f3027..000000000 --- a/src/test/java/javFiles/Lambda3.jav +++ /dev/null @@ -1,24 +0,0 @@ -import java.lang.String; - -public class Lambda2 -{ - /* - public static List map(List input, - Function func){ - input.add(func.apply(input.get())); - } - */ - public map(input,func){ - input.add(func.apply(input.get())); - return map(new List(), func); - } -} - -class List{ - A get(); - void add(A); -} - -class Function{ - B apply(A a); -} \ No newline at end of file diff --git a/src/test/java/javFiles/LambdaField.jav b/src/test/java/javFiles/LambdaField.jav deleted file mode 100644 index 4eb537380..000000000 --- a/src/test/java/javFiles/LambdaField.jav +++ /dev/null @@ -1,6 +0,0 @@ -public class LambdaField { - - f = x -> x; - -} - diff --git a/src/test/java/javFiles/LambdaRunnable.jav b/src/test/java/javFiles/LambdaRunnable.jav deleted file mode 100644 index 37924ea2b..000000000 --- a/src/test/java/javFiles/LambdaRunnable.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.Runnable; -import java.lang.String; -import java.lang.System; - -public class LamRunnable{ - - public LamRunnable(){ - - - Runnable lam = () -> {System.out.println("lambda");}; - lam.run(); - } -} - diff --git a/src/test/java/javFiles/ListenerOverload.jav b/src/test/java/javFiles/ListenerOverload.jav deleted file mode 100644 index e1a8d65d8..000000000 --- a/src/test/java/javFiles/ListenerOverload.jav +++ /dev/null @@ -1,20 +0,0 @@ -import java.lang.Integer; -import java.lang.String; - -class ListenerOverload{ - -call(p){ - call(p.left); - call(p.right); -} - -call(Integer i){} - -call(String s){} - -} - -class Pair{ - A left; - B right; -} \ No newline at end of file diff --git a/src/test/java/javFiles/Matrix.jav b/src/test/java/javFiles/Matrix.jav deleted file mode 100644 index 5e1eac086..000000000 --- a/src/test/java/javFiles/Matrix.jav +++ /dev/null @@ -1,28 +0,0 @@ -import java.util.Vector; -import java.lang.Integer; - -class Matrix extends Vector> { - Integer mul1(Integer x, Integer y) { return x;} - Integer add1(Integer x, Integer y) { return x;} - mul(m) { - var ret = new Matrix(); - var i = 0; - while(i < size()) { - var v1 = this.elementAt(i); - var v2 = new Vector(); - var j = 0; - while(j < v1.size()) { - var erg = 0; - var k = 0; - while(k < v1.size()) { - erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j); - //erg = add1(erg, mul1(v1.elementAt(k), - // m.elementAt(k).elementAt(j))); - k++; } - v2.addElement(new Integer(erg)); - j++; } - ret.addElement(v2); - i++; } - return ret; - } -} diff --git a/src/test/java/javFiles/Meth_Gen.jav b/src/test/java/javFiles/Meth_Gen.jav deleted file mode 100644 index 056dd82f8..000000000 --- a/src/test/java/javFiles/Meth_Gen.jav +++ /dev/null @@ -1,11 +0,0 @@ -class Meth_Gen { - - m1(x, y) { - m2(x); - x = y; - } - - m2(y) { - m1(y, y); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/MethodCallGenerics.jav b/src/test/java/javFiles/MethodCallGenerics.jav deleted file mode 100644 index 0d02509bc..000000000 --- a/src/test/java/javFiles/MethodCallGenerics.jav +++ /dev/null @@ -1,14 +0,0 @@ -import java.lang.String; - -class Generics { - // A mt1(A a, B b){ - B mt1(B a, B b){ - return mt1(a, a); - } -} - -class Test { - methode(String s){ - return new Generics().mt1(s,s); - } -} diff --git a/src/test/java/javFiles/Methods.jav b/src/test/java/javFiles/Methods.jav deleted file mode 100644 index e45d98306..000000000 --- a/src/test/java/javFiles/Methods.jav +++ /dev/null @@ -1,17 +0,0 @@ - -class Methods { - mt4(a,b,c) { return a.add(b).sub(c) ; } - - mt1(a) {return a;} - - mt2(a) {return a.f; } - - mt3(a) {return a.add(); } -} - -class Test { - java.lang.Object f; - add(){} - add(b){return b;} - sub(b){} -} \ No newline at end of file diff --git a/src/test/java/javFiles/MethodsEasy.jav b/src/test/java/javFiles/MethodsEasy.jav deleted file mode 100644 index ee6f9dafc..000000000 --- a/src/test/java/javFiles/MethodsEasy.jav +++ /dev/null @@ -1,7 +0,0 @@ - -class Methods { - mt4(a,b,c) { return a.mt3(b).mt3(c) ; } - - mt3(a) {return a.mt3(a); } -} - diff --git a/src/test/java/javFiles/Op1.jav b/src/test/java/javFiles/Op1.jav deleted file mode 100644 index 800f58b86..000000000 --- a/src/test/java/javFiles/Op1.jav +++ /dev/null @@ -1,11 +0,0 @@ -public class Op1{ - public Op1() { - - Runnable lam = () -> { - String test = ""; - String b = "b"; - test = b; - System.out.println(test);}; - //lam.run(); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Package.jav b/src/test/java/javFiles/Package.jav deleted file mode 100644 index bbc1e51da..000000000 --- a/src/test/java/javFiles/Package.jav +++ /dev/null @@ -1,5 +0,0 @@ -package strucType.input; - -class Neu -{ -} \ No newline at end of file diff --git a/src/test/java/javFiles/Sorting.jav b/src/test/java/javFiles/Sorting.jav deleted file mode 100644 index 04ef23e51..000000000 --- a/src/test/java/javFiles/Sorting.jav +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.List; -import java.util.Collection; - -class Sorting{ - void merge(a, b){ - a.addAll(b); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Subclass.jav b/src/test/java/javFiles/Subclass.jav deleted file mode 100644 index fe6e92088..000000000 --- a/src/test/java/javFiles/Subclass.jav +++ /dev/null @@ -1,6 +0,0 @@ -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/Superclass.jav b/src/test/java/javFiles/Superclass.jav deleted file mode 100644 index d58089de6..000000000 --- a/src/test/java/javFiles/Superclass.jav +++ /dev/null @@ -1,6 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} diff --git a/src/test/java/javFiles/Vector.jav b/src/test/java/javFiles/Vector.jav deleted file mode 100644 index 5c21cfffa..000000000 --- a/src/test/java/javFiles/Vector.jav +++ /dev/null @@ -1,23 +0,0 @@ -import java.util.ArrayList; -import java.util.Vector; -import java.lang.Object; - -class MyVector{ - -id(x){ - Object i; - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - x.add(i); - return x; -} -} \ No newline at end of file diff --git a/src/test/java/javFiles/fc.jav b/src/test/java/javFiles/fc.jav deleted file mode 100644 index a3278cbcc..000000000 --- a/src/test/java/javFiles/fc.jav +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.List; - -class Test{ - methode(param1, param2, param3) { - param2.add(param3); - return param1.meth(param2); - } -} - -interface Klasse1{ - Klasse1 meth(List p); - Klasse1 meth(Klasse2 p); -} - -interface Klasse2{ - Klasse1 meth(Klasse1 p); - Klasse2 meth(Klasse2 p); -} \ No newline at end of file diff --git a/src/test/java/javFiles/mathStruc.jav b/src/test/java/javFiles/mathStruc.jav deleted file mode 100644 index 93f901ce5..000000000 --- a/src/test/java/javFiles/mathStruc.jav +++ /dev/null @@ -1,13 +0,0 @@ - -class mathStruc { - -mathStruc(A a) { } - -A model(){ A a; return a; } - -methode(){ -var innerOp = o -> ms -> - new mathStruc(o.apply(this.model(),ms.model())); - return innerOp; - } -} \ No newline at end of file diff --git a/src/test/java/javFiles/test.jav b/src/test/java/javFiles/test.jav deleted file mode 100644 index 303d167ac..000000000 --- a/src/test/java/javFiles/test.jav +++ /dev/null @@ -1,15 +0,0 @@ -class Test{ - methode(param1, param2, param3) { - return param1.meth(param2.meth(param3)); - } -} - -interface Klasse1{ - Klasse1 meth(Klasse1 p); - Klasse1 meth(Klasse2 p); -} - -interface Klasse2{ - Klasse1 meth(Klasse1 p); - Klasse2 meth(Klasse2 p); -} \ No newline at end of file diff --git a/src/test/java/javFiles/test1.jav b/src/test/java/javFiles/test1.jav deleted file mode 100644 index 4b34948e9..000000000 --- a/src/test/java/javFiles/test1.jav +++ /dev/null @@ -1,7 +0,0 @@ -class Faculty { - - int a; - m (int x) { - return a+x; - } -} diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 48f6eda29..9e87c1e6a 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -2,7 +2,7 @@ import java.util.Vector; import java.lang.Integer; //import java.lang.Float; //import java.lang.Byte; -import java.lang.Boolean; +//import java.lang.Boolean; public class Matrix extends Vector> { @@ -19,7 +19,7 @@ public class Matrix extends Vector> { } } - mul(m) { + mul(m) { var ret = new Matrix(); var i = 0; while(i < size()) { diff --git a/src/test/resources/bytecode/javFiles/Merge.jav b/src/test/resources/bytecode/javFiles/Merge.jav index 9240146e0..ad5e103e0 100644 --- a/src/test/resources/bytecode/javFiles/Merge.jav +++ b/src/test/resources/bytecode/javFiles/Merge.jav @@ -1,8 +1,8 @@ import java.util.List; import java.lang.Integer; -import java.util.Collection; +//import java.util.Collection; -class Merge { +class Merge { merge(a, b) { a.addAll(b); diff --git a/src/test/resources/bytecode/javFiles/VectorSuper.jav b/src/test/resources/bytecode/javFiles/VectorSuper.jav new file mode 100644 index 000000000..fbadafb2e --- /dev/null +++ b/src/test/resources/bytecode/javFiles/VectorSuper.jav @@ -0,0 +1,11 @@ +import java.util.Vector; +import java.lang.Integer; + +public class VectorSuper { + + m(x){ + Integer y = 1; + x.addElement(y); + //return x; + } +} \ No newline at end of file diff --git a/src/test/resources/javFiles/Faculty.jav b/src/test/resources/javFiles/Faculty.jav index ca539adda..71f405154 100644 --- a/src/test/resources/javFiles/Faculty.jav +++ b/src/test/resources/javFiles/Faculty.jav @@ -5,7 +5,7 @@ class Faculty { Integer mul(Integer x, Integer y) { return x; } - + m () { var fact = (Integer x) -> { return mul(x, fact.apply(x)); diff --git a/src/test/resources/log4jTesting.xml b/src/test/resources/log4jTesting.xml new file mode 100755 index 000000000..dc30c2453 --- /dev/null +++ b/src/test/resources/log4jTesting.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/testBytecode/Field.java b/src/test/resources/testBytecode/Field.java deleted file mode 100644 index 50002082b..000000000 --- a/src/test/resources/testBytecode/Field.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Field{ - public void m(){ - MethFieldVar mF = new MethFieldVar(); - mF.s1 = "Field S1"; - } -} diff --git a/src/test/resources/testBytecode/Import.java b/src/test/resources/testBytecode/Import.java deleted file mode 100644 index f3519acb2..000000000 --- a/src/test/resources/testBytecode/Import.java +++ /dev/null @@ -1,8 +0,0 @@ -import java.util.Vector; - -class Import { - void methode(){ - Vector v = new Vector(); - v.add(v); - } -} diff --git a/src/test/resources/testBytecode/Lam1.java b/src/test/resources/testBytecode/Lam1.java deleted file mode 100644 index 142feed2e..000000000 --- a/src/test/resources/testBytecode/Lam1.java +++ /dev/null @@ -1,10 +0,0 @@ -import java.util.function.Function; -public class Lam1{ - public Lam1() { - Function fun = (x) -> x+"1"; - fun.apply("2"); - - Runnable lam = () -> System.out.println("lambda"); - lam.run(); - } -} diff --git a/src/test/resources/testBytecode/LamRun.java b/src/test/resources/testBytecode/LamRun.java deleted file mode 100644 index fdaf0852e..000000000 --- a/src/test/resources/testBytecode/LamRun.java +++ /dev/null @@ -1,8 +0,0 @@ -public class LamRun{ - - public void mRun(){ - - Runnable lam = () -> System.out.println("lambda"); - lam.run(); - } -} diff --git a/src/test/resources/testBytecode/MethFieldVar.java b/src/test/resources/testBytecode/MethFieldVar.java deleted file mode 100644 index 74086a016..000000000 --- a/src/test/resources/testBytecode/MethFieldVar.java +++ /dev/null @@ -1,38 +0,0 @@ -public class MethFieldVar{ - String s1;// = ""; - String s2; - -/* public void meth(Integer i, String j, Boolean b){ - //String local = "a"; - //int localL = local.length(); - //int l = s.length(); - String s = null; - //s = ""; - //return s.length();//l+localL; - } -*/ - public void mm(){ -// return "mm"; - } - public void m2(){ - System.out.println(""); - // Math.abs(1); - // String lV = "local"; - // s1 = "1"; - // s1.concat("2"); - s2 = s1; - - mm(); - - Clazz i = new Clazz(); - - Runnable lam = ()->{ - String test = ""; - String b = "b"; - test = b; - System.out.println(test); - }; - } -} - -class Clazz{} diff --git a/src/test/resources/testBytecode/Subclass.java b/src/test/resources/testBytecode/Subclass.java deleted file mode 100644 index 3e8b58538..000000000 --- a/src/test/resources/testBytecode/Subclass.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - } -} diff --git a/src/test/resources/testBytecode/SuperTest.java b/src/test/resources/testBytecode/SuperTest.java deleted file mode 100644 index 1b6ac2680..000000000 --- a/src/test/resources/testBytecode/SuperTest.java +++ /dev/null @@ -1,14 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} - -public class Subclass extends Superclass { - - public void printMethod() { - super.printMethod(); - - } -} diff --git a/src/test/resources/testBytecode/Superclass.java b/src/test/resources/testBytecode/Superclass.java deleted file mode 100644 index d58089de6..000000000 --- a/src/test/resources/testBytecode/Superclass.java +++ /dev/null @@ -1,6 +0,0 @@ -public class Superclass { - - public void printMethod() { - System.out.println("Printed in Superclass."); - } -} diff --git a/src/test/resources/testBytecode/TestMyTest.java b/src/test/resources/testBytecode/TestMyTest.java deleted file mode 100644 index e1305f761..000000000 --- a/src/test/resources/testBytecode/TestMyTest.java +++ /dev/null @@ -1,11 +0,0 @@ -class TestMyTest{ -public static void main(String[] a){ - //test1 - //new TestClass(); - //test if statement - //new TestIf(new Boolean(true)); - // test lambda - //new TestClass(); - new LamRun(); -} -} diff --git a/src/test/resources/testBytecode/manually/Fac1.java b/src/test/resources/testBytecode/manually/Fac1.java new file mode 100644 index 000000000..e36ad3aed --- /dev/null +++ b/src/test/resources/testBytecode/manually/Fac1.java @@ -0,0 +1,6 @@ +class Fuc1{ + + Integer mul(Integer x, Integer y) { + return x; + } +} diff --git a/src/test/resources/testBytecode/manually/Fac2.java b/src/test/resources/testBytecode/manually/Fac2.java new file mode 100644 index 000000000..dbf307b83 --- /dev/null +++ b/src/test/resources/testBytecode/manually/Fac2.java @@ -0,0 +1,14 @@ +import java.util.function.Function; +class Fac2 { + + Integer mul(Integer x, Integer y) { + return x; + } + + Function m () { + Function fact = (Integer x) -> { + return mul(x, x); + }; + return fact; + } +} diff --git a/src/test/resources/testBytecode/manually/LamAssign.java b/src/test/resources/testBytecode/manually/LamAssign.java new file mode 100644 index 000000000..8d45a6415 --- /dev/null +++ b/src/test/resources/testBytecode/manually/LamAssign.java @@ -0,0 +1,10 @@ +import java.util.function.Function; +class LamAssign { + + Function m () { + Function lam1 = (Integer x) -> { + return x; + }; + return lam1; + } +} diff --git a/src/test/resources/testBytecode/manually/LamAssignWithM.java b/src/test/resources/testBytecode/manually/LamAssignWithM.java new file mode 100644 index 000000000..61077d275 --- /dev/null +++ b/src/test/resources/testBytecode/manually/LamAssignWithM.java @@ -0,0 +1,12 @@ +import java.util.function.Function; +class LamAssignWithM { + Integer mul(Integer x, Integer y) { + return x; + } + Function m () { + Function lam1 = (Integer x) -> { + return mul(x,x); + }; + return lam1; + } +} diff --git a/src/test/resources/testBytecode/manually/LamWithAnField.java b/src/test/resources/testBytecode/manually/LamWithAnField.java new file mode 100644 index 000000000..ae6da4fc1 --- /dev/null +++ b/src/test/resources/testBytecode/manually/LamWithAnField.java @@ -0,0 +1,14 @@ +import java.util.function.Function; +class LamWithAnField { + Integer mul(Integer x, Integer y) { + return x; + } + LamWithField temp= new LamWithField(); + Function m () { + Function lam1 = (Integer x) -> { + return temp.res*x; + }; + return lam1; + } +} + diff --git a/src/test/resources/testBytecode/manually/LamWithField.java b/src/test/resources/testBytecode/manually/LamWithField.java new file mode 100644 index 000000000..dacdca8bf --- /dev/null +++ b/src/test/resources/testBytecode/manually/LamWithField.java @@ -0,0 +1,14 @@ +import java.util.function.Function; +class LamWithField { + Integer mul(Integer x, Integer y) { + return x; + } + Integer res = new Integer(5); + Function m () { + Function lam1 = (Integer x) -> { + return res*x; + }; + return lam1; + } +} + diff --git a/src/test/resources/testBytecode/manually/ReturnM1.java b/src/test/resources/testBytecode/manually/ReturnM1.java new file mode 100644 index 000000000..3f89147dd --- /dev/null +++ b/src/test/resources/testBytecode/manually/ReturnM1.java @@ -0,0 +1,6 @@ +class ReturnM1{ + Integer r; + Integer mul(Integer x, Integer y) { + return r; + } +} diff --git a/src/test/resources/testBytecode/testF.java b/src/test/resources/testBytecode/testF.java deleted file mode 100644 index fa4a50b7f..000000000 --- a/src/test/resources/testBytecode/testF.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets(){ - public static void main(String[] args){ - new tetsF(); - } -} diff --git a/src/test/resources/testBytecode/testTets.java b/src/test/resources/testBytecode/testTets.java deleted file mode 100644 index 4f95cbc00..000000000 --- a/src/test/resources/testBytecode/testTets.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets{ - public static void main(String[] args){ - new TetsF(); - } -} diff --git a/src/test/resources/testBytecode/testTetsF.java b/src/test/resources/testBytecode/testTetsF.java deleted file mode 100644 index fa4a50b7f..000000000 --- a/src/test/resources/testBytecode/testTetsF.java +++ /dev/null @@ -1,5 +0,0 @@ -public class testTets(){ - public static void main(String[] args){ - new tetsF(); - } -}