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
This commit is contained in:
pl@gohorb.ba-horb.de 2023-01-11 18:51:55 +01:00
parent b9c7b888c1
commit f0f3a91e27
4 changed files with 33 additions and 8 deletions

View File

@ -71,6 +71,9 @@ public class JavaTXCompiler {
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
private final DirectoryClassLoader classLoader;
private Map<String, Map<Set<RefTypeOrTPHOrWildcardOrGeneric>, 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<ClassOrInterface> 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);

View File

@ -10,10 +10,6 @@ public class Constraint<A> extends HashSet<A> {
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<A> extendConstraint = null;
@ -47,7 +43,7 @@ public class Constraint<A> extends HashSet<A> {
}
public String toString() {
return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement
return super.toString() + "\nisInherited = " + isInherited
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
+ "\n" ;
}

View File

@ -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<SourceFile> sfs;
private final TypeInferenceInformation typeInferenceInformation;
private Map<String, Map<Set<RefTypeOrTPHOrWildcardOrGeneric>, RefTypeOrTPHOrWildcardOrGeneric>> methCallargTypesRetType = new HashMap<>();
public TYPE(Collection<SourceFile> sourceFiles, Collection<ClassOrInterface> allAvailableClasses){
sfs = sourceFiles;
@ -21,6 +24,10 @@ public class TYPE {
}
public Map<String, Map<Set<RefTypeOrTPHOrWildcardOrGeneric>, 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;
}
}

View File

@ -30,6 +30,9 @@ public class TYPEStmt implements StatementVisitor{
private final TypeInferenceBlockInformation info;
private final ConstraintSet constraintsSet = new ConstraintSet();
Map<String, Map<Set<RefTypeOrTPHOrWildcardOrGeneric>, 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<String, Map<Set<RefTypeOrTPHOrWildcardOrGeneric>, 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<Set<RefTypeOrTPHOrWildcardOrGeneric>, 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<Constraint<Pair>> 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<Pair>(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));