From 41d76533c0743617174448564f1ad30d074e452d Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 11 Jan 2023 11:13:04 +0100 Subject: [PATCH 1/3] modified: src/test/java/targetast/TestCodegen.java modified: src/test/java/targetast/TestGenerics.java --- src/test/java/targetast/TestCodegen.java | 2 +- src/test/java/targetast/TestGenerics.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/targetast/TestCodegen.java b/src/test/java/targetast/TestCodegen.java index 8bc767b86..104ff7d07 100644 --- a/src/test/java/targetast/TestCodegen.java +++ b/src/test/java/targetast/TestCodegen.java @@ -42,7 +42,7 @@ public class TestCodegen { } public static Map> generateClassFiles(String filename, IByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException { - var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/", filename).toFile(); + var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/", filename).toFile(); var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile())); var resultSet = compiler.typeInference(); var sourceFile = compiler.sourceFiles.get(file); diff --git a/src/test/java/targetast/TestGenerics.java b/src/test/java/targetast/TestGenerics.java index 4e80d3f20..c782f5796 100644 --- a/src/test/java/targetast/TestGenerics.java +++ b/src/test/java/targetast/TestGenerics.java @@ -22,7 +22,7 @@ import java.util.List; public class TestGenerics { - private static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/insertGenericsJav/"; + private static final String rootDirectory = System.getProperty("user.dir") + "/resources/insertGenericsJav/"; private static final String bytecodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/"; private record Result(List genericsResults, ClassOrInterface clazz) { From b9c7b888c18f5bfabb8eedced7ab4cfdaa4a5e04 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 11 Jan 2023 11:14:49 +0100 Subject: [PATCH 2/3] Changes to be committed: deleted: src/test/java/targetast/Fun1$$.java --- src/test/java/targetast/Fun1$$.java | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/test/java/targetast/Fun1$$.java diff --git a/src/test/java/targetast/Fun1$$.java b/src/test/java/targetast/Fun1$$.java deleted file mode 100644 index 882112f24..000000000 --- a/src/test/java/targetast/Fun1$$.java +++ /dev/null @@ -1,3 +0,0 @@ -public interface Fun1$$ { - public R apply(T t); -} From f0f3a91e27c900c0bc70333badc567c59635064f Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 11 Jan 2023 18:51:55 +0100 Subject: [PATCH 3/3] Constraints fuer Generated Generics erzeugt und schreibt diese als Attribute methCallargTypesRetType in den Klassen TYPE, TypeStmt und JavaTXCompiler modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 9 ++++++++- .../typeinference/constraints/Constraint.java | 6 +----- .../typeinference/typeAlgo/TYPE.java | 9 +++++++++ .../typeinference/typeAlgo/TYPEStmt.java | 17 +++++++++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 5978aaf26..eeff2a45b 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -71,6 +71,9 @@ public class JavaTXCompiler { public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); private final DirectoryClassLoader classLoader; + private Map, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>(); + + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile), null); } @@ -127,7 +130,9 @@ public class JavaTXCompiler { allClasses.addAll(sf.getClasses()); } allClasses.addAll(importedClasses); - return new TYPE(sourceFiles.values(), allClasses).getConstraints(); + TYPE ty = new TYPE(sourceFiles.values(), allClasses); + methCallargTypesRetType = ty.getMethCallargTypesRetType(); + return ty.getConstraints(); } void addMethods(SourceFile sf, ClassOrInterface cl, List importedClasses, ClassOrInterface objectClass) { @@ -725,6 +730,7 @@ public class JavaTXCompiler { unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks); System.out.println("RESULT Final: " + li.getResults()); + System.out.println("Constraints for Generated Generics: " + methCallargTypesRetType); logFile.write("RES_FINAL: " + li.getResults().toString() + "\n"); logFile.flush(); return li.getResults(); @@ -753,6 +759,7 @@ public class JavaTXCompiler { return x; // wenn nichts veraendert wurde wird x zurueckgegeben }).collect(Collectors.toCollection(HashSet::new)); System.out.println("RESULT Final: " + results); + System.out.println("Constraints for Generated Generics: " + methCallargTypesRetType); logFile.write("RES_FINAL: " + results.toString() + "\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java index 6ebb9404b..a402ea53b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java @@ -10,10 +10,6 @@ public class Constraint extends HashSet { private static final long serialVersionUID = 1L; private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt - /* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt - * es Probleme beim Generated Generics - */ - public boolean isStatement = false; private Constraint extendConstraint = null; @@ -47,7 +43,7 @@ public class Constraint extends HashSet { } public String toString() { - return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement + return super.toString() + "\nisInherited = " + isInherited //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) + "\n" ; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 685ac9f62..05b0050a5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.statement.Statement; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; @@ -14,6 +15,8 @@ public class TYPE { private final Collection sfs; private final TypeInferenceInformation typeInferenceInformation; + + private Map, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>(); public TYPE(Collection sourceFiles, Collection allAvailableClasses){ sfs = sourceFiles; @@ -21,6 +24,10 @@ public class TYPE { } + public Map, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() { + return methCallargTypesRetType; + } + public ConstraintSet getConstraints() { ConstraintSet ret = new ConstraintSet(); for(SourceFile sf : sfs) @@ -72,6 +79,7 @@ public class TYPE { TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m); TYPEStmt methodScope = new TYPEStmt(blockInfo); m.block.accept(methodScope); + methCallargTypesRetType.putAll(methodScope.getMethCallargTypesRetType()); return methodScope.getConstraints(); } @@ -81,6 +89,7 @@ public class TYPE { //for(Statement stmt : m.fieldInitializations)stmt.accept(methodScope); ConstraintSet ret = this.getConstraintsMethod(m, info, currentClass); ret.addAll(methodScope.getConstraints()); + methCallargTypesRetType.putAll(methodScope.getMethCallargTypesRetType()); return ret; } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index ddc2dc923..eb6f5b755 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -30,6 +30,9 @@ public class TYPEStmt implements StatementVisitor{ private final TypeInferenceBlockInformation info; private final ConstraintSet constraintsSet = new ConstraintSet(); + + + Map, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>(); public TYPEStmt(TypeInferenceBlockInformation info){ this.info = info; @@ -38,6 +41,10 @@ public class TYPEStmt implements StatementVisitor{ public ConstraintSet getConstraints() { return constraintsSet; } + + public Map, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() { + return methCallargTypesRetType; + } /** * Erstellt einen neuen GenericResolver @@ -166,6 +173,14 @@ public class TYPEStmt implements StatementVisitor{ //Es wird in OderConstraints davon ausgegangen dass die Bedingungen für die Typen der Argumente links stehen //und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler) public void visit(MethodCall methodCall) { + Map, RefTypeOrTPHOrWildcardOrGeneric> argTypesRetType = new HashMap<>(); + argTypesRetType.put(methodCall.getArgumentList() + .getArguments() + .stream() + .map(x -> x.getType()) + .collect(Collectors.toCollection(HashSet::new)), + methodCall.getType()); + methCallargTypesRetType.put(methodCall.name, argTypesRetType); methodCall.receiver.accept(this); //Overloading: Set> methodConstraints = new HashSet<>(); @@ -181,7 +196,6 @@ public class TYPEStmt implements StatementVisitor{ ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) : x) .collect(Collectors.toCollection(() -> new Constraint(oneMethodConstraint.isInherited()))); - extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement; oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint); @@ -598,7 +612,6 @@ public class TYPEStmt implements StatementVisitor{ //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE - methodConstraint.isStatement = forMethod.getStatement(); methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));