|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
//PL 2018-12-19: Merge chekcen
|
|
|
|
|
package de.dhbwstuttgart.typeinference.typeAlgo;
|
|
|
|
|
|
|
|
|
|
import java.lang.Record;
|
|
|
|
|
import java.sql.Ref;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
|
|
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
|
|
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
|
|
|
|
import de.dhbwstuttgart.parser.NullToken;
|
|
|
|
@ -48,11 +50,13 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
|
|
|
|
|
private SourceLoc loc(Token token) {
|
|
|
|
|
return new SourceLoc(info.getCurrentClass().getFileName(), token.getLine());
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Erstellt einen neuen GenericResolver Die Idee dieser Datenstruktur ist es, GTVs einen eindeutigen TPH zuzuweisen. Bei Methodenaufrufen oder anderen Zugriffen, bei denen alle benutzten GTVs jeweils einen einheitlichen TPH bekommen müssen kann diese Klasse eingesetzt werden. Wichtig ist, dass hierfür jeweils eine frische Instanz benutzt wird.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static GenericsResolver getResolverInstance() {
|
|
|
|
@ -235,7 +239,7 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
private final RefType doublee = new RefType(ASTFactory.createClass(Double.class).getClassName(), new NullToken());
|
|
|
|
|
private final RefType string = new RefType(ASTFactory.createClass(String.class).getClassName(), new NullToken());
|
|
|
|
|
private final RefType bool = new RefType(ASTFactory.createClass(Boolean.class).getClassName(), new NullToken());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final RefType charr = new RefType(ASTFactory.createClass(Character.class).getClassName(), new NullToken());
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -261,13 +265,13 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
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)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.ADD)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.SUB)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.OR)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.AND)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.XOR)) {
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.MUL)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.MOD)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.ADD)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.SUB)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.OR)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.AND)
|
|
|
|
|
|| binary.operation.equals(BinaryExpr.Operator.XOR)) {
|
|
|
|
|
|
|
|
|
|
Set<Constraint<Pair>> numericAdditionOrStringConcatenation = new HashSet<>();
|
|
|
|
|
|
|
|
|
@ -330,7 +334,7 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* PL auskommentiert Anfang 2018-07-17 /* In Java passiert bei den binären Operatoren eine sogenannte Type Promotion: https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2 Das bedeutet, dass Java die Typen je nach belieben castet, so lange sie nur von Number erben
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* numeric = new Constraint<>(); numeric.add(new Pair(binary.getType(), number, PairOperator.SMALLERDOT)); numericAdditionOrStringConcatenation.add(numeric); PL auskommentiert Ende 2018-07-17
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
@ -354,7 +358,7 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
* shortt, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); numericRelationConcatenation.add(numeric); numeric = new Constraint<>(); numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT));
|
|
|
|
|
* numericRelationConcatenation.add(numeric); numeric = new Constraint<>(); numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); numericRelationConcatenation.add(numeric); numeric = new Constraint<>(); numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT)); numeric.add(new
|
|
|
|
|
* Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); numericRelationConcatenation.add(numeric); numeric = new Constraint<>(); numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT)); numeric.add(new Pair(binary.getType(), bool, PairOperator.SMALLERDOT)); numericRelationConcatenation.add(numeric);
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* //***ACHTUNG: Moeglicherweise oder und und-Contraint falsch constraintsSet.addOderConstraint(numericRelationConcatenation); //***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
|
|
|
|
*/
|
|
|
|
|
// Testeise eingefuegt PL 2018-05-24
|
|
|
|
@ -628,14 +632,14 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
public static RefTypeOrTPHOrWildcardOrGeneric getReceiverType(ClassOrInterface receiver, GenericsResolver resolver) {
|
|
|
|
|
if (receiver == null) return null;
|
|
|
|
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
|
|
|
|
for(GenericTypeVar gtv : receiver.getGenerics()){
|
|
|
|
|
for (GenericTypeVar gtv : receiver.getGenerics()) {
|
|
|
|
|
//Die Generics werden alle zu TPHs umgewandelt.
|
|
|
|
|
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
|
|
|
|
}
|
|
|
|
|
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
|
|
|
|
if(receiver instanceof FunNClass){
|
|
|
|
|
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString()+"$$"), params, new NullToken()); // new FunN(params);
|
|
|
|
|
}else{
|
|
|
|
|
if (receiver instanceof FunNClass) {
|
|
|
|
|
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString() + "$$"), params, new NullToken()); // new FunN(params);
|
|
|
|
|
} else {
|
|
|
|
|
receiverType = new RefType(receiver.getClassName(), params, new NullToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -654,7 +658,7 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
ClassOrInterface receiverCl = assumption.getReceiver();
|
|
|
|
|
/*
|
|
|
|
|
* List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>(); for(GenericTypeVar gtv : receiverCl.getGenerics()){ //Die Generics werden alle zu TPHs umgewandelt. params.add(resolver.resolve(gtv.getName())); }
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* RefTypeOrTPHOrWildcardOrGeneric receiverType = new RefType(assumption.getReceiver().getClassName(), params, forMethod.getOffset());
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
@ -776,7 +780,7 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
// TODO: Hier müssen die Parameter mit den TPHs in den GEnerics des Receivers verknüpft werden
|
|
|
|
|
/*
|
|
|
|
|
* BEispiel: auto test = new List<String>(); test.add("hallo");
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Hier kriegt der Receiver ja den COnstraint TPH REceiver <. List<TPH A> Dann mus bei dem Parameter der COnstraint entstehen: TPH A <. String
|
|
|
|
|
*/
|
|
|
|
|
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
|
|
|
|
@ -834,7 +838,15 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
if (caseExpressionType == null) {
|
|
|
|
|
for (var child : switchStmt.getBlocks()) {
|
|
|
|
|
for (var label : child.getLabels()) {
|
|
|
|
|
if (label.getPattern() instanceof FormalParameter) {
|
|
|
|
|
if (label.getPattern() == null) {
|
|
|
|
|
System.out.println("DefaultCase");
|
|
|
|
|
}
|
|
|
|
|
if (label.getPattern() instanceof RecordPattern) {
|
|
|
|
|
RecordPattern recordPattern = (RecordPattern) label.getPattern();
|
|
|
|
|
System.out.println("HALFTAN DER WEI?E ICH CHECK ECHT GART NCIHTS MEHR");
|
|
|
|
|
System.out.println(recordPattern.getName());
|
|
|
|
|
//constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT, loc(label.getOffset())));
|
|
|
|
|
} else if (label.getPattern() instanceof FormalParameter) {
|
|
|
|
|
constraintsSet.addUndConstraint(new Pair(label.getPattern().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT, loc(label.getOffset())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -844,6 +856,33 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var child : switchStmt.getBlocks()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
child.getLabels().forEach(el -> {
|
|
|
|
|
if (el.getType() instanceof RefType) {
|
|
|
|
|
var recType = el;
|
|
|
|
|
|
|
|
|
|
if(el.getPattern() instanceof RecordPattern){
|
|
|
|
|
var pattern = (RecordPattern) recType.getPattern();
|
|
|
|
|
|
|
|
|
|
var allClasses = info.getAvailableClasses();
|
|
|
|
|
var interestingClasses = allClasses.stream().filter(as -> as.getClassName().equals(((RefType) el.getType()).getName())).toList();
|
|
|
|
|
|
|
|
|
|
var test = "";
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < pattern.getSubPattern().size(); i++){
|
|
|
|
|
var supPattern = pattern.getSubPattern().get(i);
|
|
|
|
|
for(int j = 0; j < interestingClasses.size(); j++){
|
|
|
|
|
constraintsSet.addUndConstraint(new Pair(supPattern.getType(), interestingClasses.get(j).getFieldDecl().get(i).getType(), PairOperator.SMALLERDOT, loc(switchStmt.getOffset())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
child.accept(this);
|
|
|
|
|
constraintsSet.addUndConstraint(new Pair(child.getType(), switchStmt.getType(), PairOperator.SMALLERDOT, loc(switchStmt.getOffset())));
|
|
|
|
|
}
|
|
|
|
@ -860,7 +899,7 @@ public class TYPEStmt implements StatementVisitor {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void visit(SwitchLabel switchLabel) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
System.out.println("I MOCH WAS");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|