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
This commit is contained in:
pl@gohorb.ba-horb.de 2023-02-08 17:39:45 +01:00
parent 4074273ecb
commit 239698c8d6
4 changed files with 10 additions and 68 deletions

View File

@ -72,10 +72,6 @@ public class JavaTXCompiler {
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
private final DirectoryClassLoader classLoader; private final DirectoryClassLoader classLoader;
//zum Loeschen Anfang obsolet PL 2023-01-18
private BiRelation<String, BiRelation<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new BiRelation<>();
//zum Loeschen Ende obsolet PL 2023-01-18
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile), null); this(Arrays.asList(sourceFile), null);
} }
@ -133,7 +129,6 @@ public class JavaTXCompiler {
} }
allClasses.addAll(importedClasses); allClasses.addAll(importedClasses);
TYPE ty = new TYPE(sourceFiles.values(), allClasses); TYPE ty = new TYPE(sourceFiles.values(), allClasses);
methCallargTypesRetType = ty.getMethCallargTypesRetType();
return ty.getConstraints(); return ty.getConstraints();
} }
@ -732,7 +727,7 @@ public class JavaTXCompiler {
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
usedTasks); usedTasks);
System.out.println("RESULT Final: " + li.getResults()); 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.write("RES_FINAL: " + li.getResults().toString() + "\n");
logFile.flush(); logFile.flush();
return li.getResults(); return li.getResults();
@ -761,7 +756,7 @@ public class JavaTXCompiler {
return x; // wenn nichts veraendert wurde wird x zurueckgegeben return x; // wenn nichts veraendert wurde wird x zurueckgegeben
}).collect(Collectors.toCollection(HashSet::new)); }).collect(Collectors.toCollection(HashSet::new));
System.out.println("RESULT Final: " + results); 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.write("RES_FINAL: " + results.toString() + "\n");
logFile.flush(); logFile.flush();
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);

View File

@ -18,20 +18,11 @@ public class TYPE {
private final Collection<SourceFile> sfs; private final Collection<SourceFile> sfs;
private final TypeInferenceInformation typeInferenceInformation; private final TypeInferenceInformation typeInferenceInformation;
//zum Loeschen Anfang obsolet PL 2023-01-18
private BiRelation<String, BiRelation<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new BiRelation<>();
//zum Loeschen Ende obsolet PL 2023-01-18
public TYPE(Collection<SourceFile> sourceFiles, Collection<ClassOrInterface> allAvailableClasses){ public TYPE(Collection<SourceFile> sourceFiles, Collection<ClassOrInterface> allAvailableClasses){
sfs = sourceFiles; sfs = sourceFiles;
this.typeInferenceInformation = new TypeInferenceInformation(allAvailableClasses); this.typeInferenceInformation = new TypeInferenceInformation(allAvailableClasses);
} }
public BiRelation<String, BiRelation<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() {
return methCallargTypesRetType;
}
public ConstraintSet getConstraints() { public ConstraintSet getConstraints() {
ConstraintSet ret = new ConstraintSet(); ConstraintSet ret = new ConstraintSet();
for(SourceFile sf : sfs) for(SourceFile sf : sfs)
@ -83,7 +74,6 @@ public class TYPE {
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m); TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
TYPEStmt methodScope = new TYPEStmt(blockInfo); TYPEStmt methodScope = new TYPEStmt(blockInfo);
m.block.accept(methodScope); m.block.accept(methodScope);
methCallargTypesRetType.putAll(methodScope.getMethCallargTypesRetType());
return methodScope.getConstraints(); return methodScope.getConstraints();
} }
@ -93,7 +83,6 @@ public class TYPE {
//for(Statement stmt : m.fieldInitializations)stmt.accept(methodScope); //for(Statement stmt : m.fieldInitializations)stmt.accept(methodScope);
ConstraintSet ret = this.getConstraintsMethod(m, info, currentClass); ConstraintSet ret = this.getConstraintsMethod(m, info, currentClass);
ret.addAll(methodScope.getConstraints()); ret.addAll(methodScope.getConstraints());
methCallargTypesRetType.putAll(methodScope.getMethCallargTypesRetType());
return ret; return ret;
} }
} }

View File

@ -32,11 +32,6 @@ public class TYPEStmt implements StatementVisitor{
private final TypeInferenceBlockInformation info; private final TypeInferenceBlockInformation info;
private final ConstraintSet constraintsSet = new ConstraintSet(); private final ConstraintSet constraintsSet = new ConstraintSet();
//zum Loeschen Anfang obsolet PL 2023-01-18
private RefTypeOrTPHOrWildcardOrGeneric superType = new Void(new NullToken());
private BiRelation<String, BiRelation<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new BiRelation<>();
//zum Loeschen Ende obsolet PL 2023-01-18
public TYPEStmt(TypeInferenceBlockInformation info){ public TYPEStmt(TypeInferenceBlockInformation info){
this.info = info; this.info = info;
} }
@ -45,10 +40,6 @@ public class TYPEStmt implements StatementVisitor{
return constraintsSet; return constraintsSet;
} }
public BiRelation<String, BiRelation<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric>> getMethCallargTypesRetType() {
return methCallargTypesRetType;
}
/** /**
* Erstellt einen neuen GenericResolver * Erstellt einen neuen GenericResolver
* Die Idee dieser Datenstruktur ist es, GTVs einen eindeutigen TPH zuzuweisen. * Die Idee dieser Datenstruktur ist es, GTVs einen eindeutigen TPH zuzuweisen.
@ -67,7 +58,6 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(ArgumentList arglist) { public void visit(ArgumentList arglist) {
for(int i = 0;i<arglist.getArguments().size();i++){ for(int i = 0;i<arglist.getArguments().size();i++){
superType = arglist.getArguments().get(i).getType();
arglist.getArguments().get(i).accept(this); arglist.getArguments().get(i).accept(this);
} }
} }
@ -89,7 +79,6 @@ public class TYPEStmt implements StatementVisitor{
//Constraints des Bodys generieren: //Constraints des Bodys generieren:
TYPEStmt lambdaScope = new TYPEStmt(new TypeInferenceBlockInformation(info, lambdaExpression)); TYPEStmt lambdaScope = new TYPEStmt(new TypeInferenceBlockInformation(info, lambdaExpression));
superType = new Void(new NullToken());
lambdaExpression.methodBody.accept(lambdaScope); lambdaExpression.methodBody.accept(lambdaScope);
constraintsSet.addAll(lambdaScope.getConstraints()); constraintsSet.addAll(lambdaScope.getConstraints());
} }
@ -97,7 +86,6 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(Assign assign) { public void visit(Assign assign) {
assign.lefSide.accept(this); assign.lefSide.accept(this);
superType = assign.lefSide.getType();
assign.rightSide.accept(this); assign.rightSide.accept(this);
constraintsSet.addUndConstraint(new Pair( constraintsSet.addUndConstraint(new Pair(
assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT)); assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT));
@ -106,7 +94,6 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(Block block) { public void visit(Block block) {
for(Statement stmt : block.getStatements()){ for(Statement stmt : block.getStatements()){
superType = new Void(new NullToken());
stmt.accept(this); stmt.accept(this);
} }
} }
@ -123,7 +110,6 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(FieldVar fieldVar) { public void visit(FieldVar fieldVar) {
superType = new Void(new NullToken());
fieldVar.receiver.accept(this); fieldVar.receiver.accept(this);
Set<Constraint> oderConstraints = new HashSet<>(); Set<Constraint> oderConstraints = new HashSet<>();
for(FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)){ for(FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)){
@ -148,17 +134,14 @@ public class TYPEStmt implements StatementVisitor{
public void visit(IfStmt ifStmt) { public void visit(IfStmt ifStmt) {
RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()); RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken());
//Expression inferieren: //Expression inferieren:
superType = new Void(new NullToken());
ifStmt.expr.accept(this); ifStmt.expr.accept(this);
//Expression muss boolean sein: //Expression muss boolean sein:
constraintsSet.addUndConstraint(new Pair(ifStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT)); constraintsSet.addUndConstraint(new Pair(ifStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT));
//Blöcke inferieren: //Blöcke inferieren:
superType = new Void(new NullToken());
ifStmt.then_block.accept(this); ifStmt.then_block.accept(this);
//Beide Blöcke müssen den gleichen Supertyp haben, welcher den Rückgabetyp des If-Stmts darstellt //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)); constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT));
if(ifStmt.else_block != null){ if(ifStmt.else_block != null){
superType = new Void(new NullToken());
ifStmt.else_block.accept(this); ifStmt.else_block.accept(this);
constraintsSet.addUndConstraint(new Pair(ifStmt.else_block.getType(), ifStmt.getType(), PairOperator.SMALLERDOT)); 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) //und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler)
public void visit(MethodCall methodCall) { 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<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric> argTypesRetType = new BiRelation<>();
Set<RefTypeOrTPHOrWildcardOrGeneric> 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); methodCall.receiver.accept(this);
//Overloading: //Overloading:
Set<Constraint<Pair>> methodConstraints = new HashSet<>(); Set<Constraint<Pair>> methodConstraints = new HashSet<>();
@ -249,7 +215,6 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(ExpressionReceiver receiver) { public void visit(ExpressionReceiver receiver) {
superType = new Void(new NullToken());
receiver.expr.accept(this); 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 //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) //und die Typen der Rückgabewerte immer rechts stehen (vgl. JavaTXCompiler)
public void visit(BinaryExpr binary) { public void visit(BinaryExpr binary) {
superType = new Void(new NullToken()); binary.lexpr.accept(this);
binary.lexpr.accept(this); binary.rexpr.accept(this);
superType = new Void(new NullToken());
binary.rexpr.accept(this);
if(binary.operation.equals(BinaryExpr.Operator.DIV) || if(binary.operation.equals(BinaryExpr.Operator.DIV) ||
binary.operation.equals(BinaryExpr.Operator.MUL)|| binary.operation.equals(BinaryExpr.Operator.MUL)||
binary.operation.equals(BinaryExpr.Operator.MOD)|| binary.operation.equals(BinaryExpr.Operator.MOD)||
@ -531,7 +494,6 @@ public class TYPEStmt implements StatementVisitor{
@Override @Override
public void visit(Return returnExpr) { public void visit(Return returnExpr) {
superType = returnExpr.getType();
returnExpr.retexpr.accept(this); returnExpr.retexpr.accept(this);
constraintsSet.addUndConstraint(new Pair(returnExpr.getType(),info.getCurrentTypeScope().getReturnType(), PairOperator.EQUALSDOT)); 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) { public void visit(WhileStmt whileStmt) {
RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()); RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken());
//Expression inferieren: //Expression inferieren:
superType = new Void(new NullToken());
whileStmt.expr.accept(this); whileStmt.expr.accept(this);
//Expression muss boolean sein: //Expression muss boolean sein:
constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT)); constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT));
//LoopBlock inferieren: //LoopBlock inferieren:
superType = new Void(new NullToken());
whileStmt.loopBlock.accept(this); whileStmt.loopBlock.accept(this);
} }
@ -600,7 +560,6 @@ public class TYPEStmt implements StatementVisitor{
public void visit(AssignToField assignLeftSide) { public void visit(AssignToField assignLeftSide) {
//Hier ist kein Code nötig. Es werden keine extra Constraints generiert //Hier ist kein Code nötig. Es werden keine extra Constraints generiert
//HIER muss Code rein PL 2018-10-24 //HIER muss Code rein PL 2018-10-24
superType = new Void(new NullToken());
assignLeftSide.field.accept(this); assignLeftSide.field.accept(this);
} }
@ -676,7 +635,6 @@ public class TYPEStmt implements StatementVisitor{
TypeInferenceBlockInformation info, GenericsResolver resolver) { TypeInferenceBlockInformation info, GenericsResolver resolver) {
Set<Pair> ret = new HashSet<>(); Set<Pair> ret = new HashSet<>();
for(int i = 0;i<foMethod.arglist.getArguments().size();i++){ for(int i = 0;i<foMethod.arglist.getArguments().size();i++){
superType = assumption.getArgTypes(resolver).get(i);
foMethod.arglist.getArguments().get(i).accept(this); foMethod.arglist.getArguments().get(i).accept(this);
RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType(); RefTypeOrTPHOrWildcardOrGeneric argType = foMethod.arglist.getArguments().get(i).getType();
RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i); RefTypeOrTPHOrWildcardOrGeneric assType = assumption.getArgTypes(resolver).get(i);

View File

@ -867,9 +867,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
if (oderConstraint) { if (oderConstraint) {//Methodconstraints werden abgespeichert für die Bytecodegenerierung von Methodenaufrufen
methodSignatureConstraint.addAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint()); methodSignatureConstraint.addAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint());
System.out.println("ERSTELLUNG: " +methodSignatureConstraint); //System.out.println("ERSTELLUNG: " +methodSignatureConstraint);
} }
i++; i++;
@ -1180,9 +1180,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}}} }}}
//Ab hier alle parallele Berechnungen wieder zusammengeführt. //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<UnifyPair>)a).getmethodSignatureConstraint()); methodSignatureConstraint.removeAll(((Constraint<UnifyPair>)a).getmethodSignatureConstraint());
System.out.println("REMOVE: " +methodSignatureConstraint); //System.out.println("REMOVE: " +methodSignatureConstraint);
} }
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
@ -1476,7 +1476,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
System.out.println(); System.out.println();
} }
writeLog("nextSetasList vor filter-Aufruf: " + nextSetasList); 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 -> { nextSetasList = nextSetasList.stream().filter(x -> {
//Boolean ret = false; //Boolean ret = false;
//for (PlaceholderType var : vars) { //for (PlaceholderType var : vars) {