From 239698c8d6f356e01b552957289d3cfcd04391da Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 8 Feb 2023 17:39:45 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java modified: src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java etwas aufgeraeumt --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 11 ++--- .../typeinference/typeAlgo/TYPE.java | 11 ----- .../typeinference/typeAlgo/TYPEStmt.java | 46 +------------------ .../typeinference/unify/TypeUnifyTask.java | 10 ++-- 4 files changed, 10 insertions(+), 68 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 67e553e65..89b4d4827 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -71,11 +71,7 @@ public class JavaTXCompiler { Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); private final DirectoryClassLoader classLoader; - - //zum Loeschen Anfang obsolet PL 2023-01-18 - private BiRelation, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new BiRelation<>(); - //zum Loeschen Ende obsolet PL 2023-01-18 - + public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile), null); } @@ -133,7 +129,6 @@ public class JavaTXCompiler { } allClasses.addAll(importedClasses); TYPE ty = new TYPE(sourceFiles.values(), allClasses); - methCallargTypesRetType = ty.getMethCallargTypesRetType(); return ty.getConstraints(); } @@ -732,7 +727,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); + System.out.println("Constraints for Generated Generics: " + " ???"); logFile.write("RES_FINAL: " + li.getResults().toString() + "\n"); logFile.flush(); return li.getResults(); @@ -761,7 +756,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); + System.out.println("Constraints for Generated Generics: " + " ???"); logFile.write("RES_FINAL: " + results.toString() + "\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java index 148fce2f1..dba8f6c09 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPE.java @@ -18,20 +18,11 @@ public class TYPE { private final Collection sfs; private final TypeInferenceInformation typeInferenceInformation; - //zum Loeschen Anfang obsolet PL 2023-01-18 - private BiRelation, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new BiRelation<>(); - //zum Loeschen Ende obsolet PL 2023-01-18 - public TYPE(Collection sourceFiles, Collection allAvailableClasses){ sfs = sourceFiles; this.typeInferenceInformation = new TypeInferenceInformation(allAvailableClasses); } - - public BiRelation, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() { - return methCallargTypesRetType; - } - public ConstraintSet getConstraints() { ConstraintSet ret = new ConstraintSet(); for(SourceFile sf : sfs) @@ -83,7 +74,6 @@ 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(); } @@ -93,7 +83,6 @@ 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 51d15bce3..198b0f4ce 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -31,11 +31,6 @@ public class TYPEStmt implements StatementVisitor{ private final TypeInferenceBlockInformation info; private final ConstraintSet constraintsSet = new ConstraintSet(); - - //zum Loeschen Anfang obsolet PL 2023-01-18 - private RefTypeOrTPHOrWildcardOrGeneric superType = new Void(new NullToken()); - private BiRelation, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new BiRelation<>(); - //zum Loeschen Ende obsolet PL 2023-01-18 public TYPEStmt(TypeInferenceBlockInformation info){ this.info = info; @@ -44,10 +39,6 @@ public class TYPEStmt implements StatementVisitor{ public ConstraintSet getConstraints() { return constraintsSet; } - - public BiRelation, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() { - return methCallargTypesRetType; - } /** * Erstellt einen neuen GenericResolver @@ -67,7 +58,6 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(ArgumentList arglist) { for(int i = 0;i oderConstraints = new HashSet<>(); for(FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)){ @@ -148,17 +134,14 @@ public class TYPEStmt implements StatementVisitor{ public void visit(IfStmt ifStmt) { RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()); //Expression inferieren: - superType = new Void(new NullToken()); ifStmt.expr.accept(this); //Expression muss boolean sein: constraintsSet.addUndConstraint(new Pair(ifStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT)); //Blöcke inferieren: - superType = new Void(new NullToken()); ifStmt.then_block.accept(this); //Beide Blöcke müssen den gleichen Supertyp haben, welcher den Rückgabetyp des If-Stmts darstellt constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT)); if(ifStmt.else_block != null){ - superType = new Void(new NullToken()); ifStmt.else_block.accept(this); constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT)); } @@ -185,23 +168,6 @@ public class TYPEStmt implements StatementVisitor{ //und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler) public void visit(MethodCall methodCall) { - //Anfang es werden Paare von TPHs gespeichert, die bei den Generated Generics ueber die Methodengrenzen hinweg - //betrachtet werden muessen - BiRelation, RefTypeOrTPHOrWildcardOrGeneric> argTypesRetType = new BiRelation<>(); - Set argTphSet = methodCall.getArgumentList() - .getArguments() - .stream() - .map(x -> x.getType()) - .collect(Collectors.toCollection(HashSet::new)) - .stream().filter(x -> x instanceof TypePlaceholder) - .collect(Collectors.toCollection(HashSet::new)); - if (superType instanceof TypePlaceholder) { - argTypesRetType.put(argTphSet, superType); - methCallargTypesRetType.put(methodCall.name, argTypesRetType); - } - //Ende - - superType = methodCall.receiver.getType(); methodCall.receiver.accept(this); //Overloading: Set> methodConstraints = new HashSet<>(); @@ -249,7 +215,6 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(ExpressionReceiver receiver) { - superType = new Void(new NullToken()); receiver.expr.accept(this); } @@ -282,10 +247,8 @@ 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(BinaryExpr binary) { - superType = new Void(new NullToken()); - binary.lexpr.accept(this); - superType = new Void(new NullToken()); - binary.rexpr.accept(this); + binary.lexpr.accept(this); + binary.rexpr.accept(this); if(binary.operation.equals(BinaryExpr.Operator.DIV) || binary.operation.equals(BinaryExpr.Operator.MUL)|| binary.operation.equals(BinaryExpr.Operator.MOD)|| @@ -531,7 +494,6 @@ public class TYPEStmt implements StatementVisitor{ @Override public void visit(Return returnExpr) { - superType = returnExpr.getType(); returnExpr.retexpr.accept(this); constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT)); } @@ -582,12 +544,10 @@ public class TYPEStmt implements StatementVisitor{ public void visit(WhileStmt whileStmt) { RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()); //Expression inferieren: - superType = new Void(new NullToken()); whileStmt.expr.accept(this); //Expression muss boolean sein: constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT)); //LoopBlock inferieren: - superType = new Void(new NullToken()); whileStmt.loopBlock.accept(this); } @@ -600,7 +560,6 @@ public class TYPEStmt implements StatementVisitor{ public void visit(AssignToField assignLeftSide) { //Hier ist kein Code nötig. Es werden keine extra Constraints generiert //HIER muss Code rein PL 2018-10-24 - superType = new Void(new NullToken()); assignLeftSide.field.accept(this); } @@ -676,7 +635,6 @@ public class TYPEStmt implements StatementVisitor{ TypeInferenceBlockInformation info, GenericsResolver resolver) { Set ret = new HashSet<>(); for(int i = 0;i>> { } } - if (oderConstraint) { + if (oderConstraint) {//Methodconstraints werden abgespeichert für die Bytecodegenerierung von Methodenaufrufen methodSignatureConstraint.addAll(((Constraint)a).getmethodSignatureConstraint()); - System.out.println("ERSTELLUNG: " +methodSignatureConstraint); + //System.out.println("ERSTELLUNG: " +methodSignatureConstraint); } i++; @@ -1180,9 +1180,9 @@ public class TypeUnifyTask extends RecursiveTask>> { }}} //Ab hier alle parallele Berechnungen wieder zusammengeführt. - if (oderConstraint) { + if (oderConstraint) {//Wenn weiteres Element nextSetasList genommen wird, muss die vorherige methodsignatur geloescht werden methodSignatureConstraint.removeAll(((Constraint)a).getmethodSignatureConstraint()); - System.out.println("REMOVE: " +methodSignatureConstraint); + //System.out.println("REMOVE: " +methodSignatureConstraint); } if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen @@ -1476,7 +1476,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(); } writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList); - if (!oderConstraint) { + if (!oderConstraint) {//PL 2023-02-08 eingefuegt: Bei oderconstraints sind Subststitutionen nicht als Substitutionen in idesem Sinne zu sehen nextSetasList = nextSetasList.stream().filter(x -> { //Boolean ret = false; //for (PlaceholderType var : vars) {