Compare commits
7 Commits
0eb48ba425
...
issue363
| Author | SHA1 | Date | |
|---|---|---|---|
| d6ed0689bc | |||
| d7676f36e3 | |||
|
|
9e323759d6 | ||
| 558083166d | |||
|
|
aec2f9a399 | ||
|
|
31df7a65f0 | ||
|
|
185989ba62 |
@@ -1,12 +1,13 @@
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
|
||||
public class Bug365{
|
||||
swap(f){
|
||||
return x -> y -> f.apply(y).apply(x);
|
||||
}
|
||||
|
||||
swap(f){
|
||||
return x -> y -> z -> f.apply(z).apply(x).apply(y);
|
||||
swap(Fun1$$<String, Fun1$$<String, Fun1$$<String, Object>>> f){
|
||||
return x -> y -> z -> f.apply(z).apply(y).apply(x);
|
||||
}
|
||||
|
||||
public ex1() {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import java.lang.String;
|
||||
|
||||
public class Bug365a{
|
||||
swap(f){
|
||||
return x -> y -> f.apply(y).apply(x);
|
||||
}
|
||||
|
||||
|
||||
public ex2() {
|
||||
var func = x -> y -> x + y;
|
||||
return swap(func).apply("A").apply("B");
|
||||
}
|
||||
}
|
||||
10
resources/bytecode/javFiles/Bug371.jav
Normal file
10
resources/bytecode/javFiles/Bug371.jav
Normal file
@@ -0,0 +1,10 @@
|
||||
import java.lang.Boolean;
|
||||
|
||||
public class Bug371 {
|
||||
static m1(x, y) { return x || y; }
|
||||
static m2(x, y) { return x && y; }
|
||||
|
||||
public static test() {
|
||||
return m2(m1(true, false), true);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.lang.String;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.lang.Integer;
|
||||
|
||||
class BugXXX {
|
||||
public main() {
|
||||
List<Integer> i = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10));
|
||||
Optional<Integer> tmp = i.stream().filter(x -> x == 5).map(x -> x*2).findFirst();
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@ public class FunNGenerator {
|
||||
public final List<TargetType> inParams;
|
||||
public final List<TargetType> realParams;
|
||||
|
||||
public GenericParameters(TargetFunNType funNType) {
|
||||
this(funNType.funNParams(), funNType.returnArguments());
|
||||
}
|
||||
|
||||
public GenericParameters(List<TargetType> params, int numReturns) {
|
||||
this.realParams = params;
|
||||
this.inParams = flattenTypeParams(params);
|
||||
|
||||
@@ -393,7 +393,12 @@ public class JavaTXCompiler {
|
||||
logFile.write(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
logFile.flush();
|
||||
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
||||
List<UnifyPair> andConstraintsSorted = unifyCons.getUndConstraints().stream()
|
||||
.sorted(Comparator.comparing(UnifyPair::getPairOp).thenComparing(UnifyPair::getLhsType, Comparator.comparing(UnifyType::getName)))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
System.out.println(andConstraintsSorted);
|
||||
|
||||
Set<PlaceholderType> varianceTPHold;
|
||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||
@@ -416,7 +421,14 @@ public class JavaTXCompiler {
|
||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||
urm.addUnifyResultListener(li);
|
||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
||||
System.out.println("RESULT Final: " + li.getResults());
|
||||
//System.out.println("RESULT Final: " + li.getResults());
|
||||
var finalResults = li.getResults().stream().sorted().toList();
|
||||
int i = 0;
|
||||
System.out.println("RESULT Final: ");
|
||||
for (var result : finalResults){
|
||||
System.out.println("Result: " + i++);
|
||||
System.out.println(result.getSortedResults());
|
||||
}
|
||||
System.out.println("Constraints for Generated Generics: " + " ???");
|
||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||
logFile.flush();
|
||||
|
||||
@@ -1099,9 +1099,9 @@ public class StatementGenerator {
|
||||
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
||||
}
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart()));// ret-Type
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart(), -1, false));// ret-Type
|
||||
params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen:
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
|
||||
funNParams.add(TypePlaceholder.fresh(expression.getStart(), 1, false)));
|
||||
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
||||
// RefType lambdaType = new
|
||||
// RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.*;
|
||||
/**
|
||||
* Speichert die Klassen f<>r einen bestimmten Projektscope
|
||||
*/
|
||||
public class JavaClassRegistry {
|
||||
public class JavaClassRegistry{
|
||||
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
||||
|
||||
public JavaClassRegistry(Map<String, Integer> initialNames) {
|
||||
@@ -22,6 +22,10 @@ public class JavaClassRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public Set<JavaClassName> getAllClassNames(){
|
||||
return existingClasses.keySet();
|
||||
}
|
||||
|
||||
public void addName(String className, int numberOfGenerics) {
|
||||
existingClasses.put(new JavaClassName(className), numberOfGenerics);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import de.dhbwstuttgart.syntaxtree.Record;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator;
|
||||
import de.dhbwstuttgart.target.tree.*;
|
||||
import de.dhbwstuttgart.target.tree.expression.*;
|
||||
import de.dhbwstuttgart.target.tree.type.*;
|
||||
@@ -780,7 +782,15 @@ public class ASTToTargetAST {
|
||||
return TargetFunNType.fromParams(params, filteredParams, gep.getReturnType() != null ? 1 : 0);
|
||||
}
|
||||
|
||||
private FunNGenerator.GenericParameters convertToParameters(TargetFunNType input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isSubtype(TargetType test, TargetType other) {
|
||||
if (other.equals(TargetType.Object)) return true;
|
||||
if (test instanceof TargetFunNType tfun && other instanceof TargetFunNType ofun)
|
||||
return isSubtype(new FunNGenerator.GenericParameters(tfun), new FunNGenerator.GenericParameters(ofun));
|
||||
|
||||
var testClass = compiler.getClass(new JavaClassName(test.name()));
|
||||
var otherClass = compiler.getClass(new JavaClassName(other.name()));
|
||||
if (testClass == null) return false;
|
||||
|
||||
@@ -138,7 +138,10 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(BoolExpression bool) {
|
||||
System.out.println("BoolExpression");
|
||||
result = switch(bool.operation) {
|
||||
case OR -> new TargetBinaryOp.Or(converter.convert(bool.getType()), converter.convert(bool.lexpr), converter.convert(bool.rexpr));
|
||||
case AND -> new TargetBinaryOp.And(converter.convert(bool.getType()), converter.convert(bool.lexpr), converter.convert(bool.rexpr));
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Constraint<A> extends HashSet<A> {
|
||||
public class Constraint<A> extends HashSet<A> implements Comparable<Constraint<A>> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
||||
private Boolean isImplemented = false;
|
||||
@@ -73,5 +73,9 @@ public class Constraint<A> extends HashSet<A> {
|
||||
public String toStringBase() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(Constraint<A> o) {
|
||||
return this.toString().compareTo(o.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
/**
|
||||
* Paare, welche das Unifikationsergebnis darstellen
|
||||
*/
|
||||
public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B extends RefTypeOrTPHOrWildcardOrGeneric> {
|
||||
public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric, B extends RefTypeOrTPHOrWildcardOrGeneric> implements Comparable<ResultPair<A,B>> {
|
||||
private final A left;
|
||||
private final B right;
|
||||
|
||||
@@ -58,5 +58,14 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ResultPair<A, B> o) {
|
||||
if (o == null) {
|
||||
return 1; // this is greater than null
|
||||
}
|
||||
|
||||
return o.left.toString().compareTo(this.left.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.dhbwstuttgart.typeinference.result;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
@@ -12,7 +14,7 @@ import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ResultSet {
|
||||
public class ResultSet implements Comparable<ResultSet>{
|
||||
|
||||
public final Set<ResultPair> results;
|
||||
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
||||
@@ -22,6 +24,10 @@ public class ResultSet {
|
||||
this.genIns = new HashSet<>();
|
||||
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
||||
}
|
||||
|
||||
public List<ResultPair> getSortedResults() {
|
||||
return results.stream().sorted().toList();
|
||||
}
|
||||
|
||||
public boolean contains(ResultPair toCheck) {
|
||||
return this.results.contains(toCheck);
|
||||
@@ -63,6 +69,21 @@ public class ResultSet {
|
||||
public int hashCode() {
|
||||
return results.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ResultSet o) {
|
||||
List<ResultPair> thisSorted = this.getSortedResults();
|
||||
List<ResultPair> otherSorted = o.getSortedResults();
|
||||
int sizeCompare = Integer.compare(thisSorted.size(), otherSorted.size());
|
||||
if (sizeCompare != 0) return sizeCompare;
|
||||
|
||||
for (int i = 0; i < thisSorted.size(); i++) {
|
||||
int cmp = thisSorted.get(i).compareTo(otherSorted.get(i));
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Resolver implements ResultSetVisitor {
|
||||
|
||||
@@ -73,7 +73,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpression lambdaExpression) {
|
||||
TypePlaceholder tphRetType = TypePlaceholder.fresh(new NullToken());
|
||||
TypePlaceholder tphRetType = TypePlaceholder.fresh(new NullToken(), -1, false);
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> lambdaParams = lambdaExpression.params.getFormalparalist().stream().map((formalParameter -> formalParameter.getType())).collect(Collectors.toList());
|
||||
lambdaParams.add(tphRetType);
|
||||
// lambdaParams.add(0,tphRetType);
|
||||
@@ -635,18 +635,8 @@ public class TYPEStmt implements StatementVisitor {
|
||||
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
||||
}
|
||||
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||
//alle Variance auf COntravariant setzen
|
||||
|
||||
if (receiver instanceof FunNClass) {
|
||||
params.forEach(x -> {
|
||||
if (x instanceof TypePlaceholder) {
|
||||
((TypePlaceholder) x).setVariance(1);
|
||||
}}
|
||||
);
|
||||
//Returntyp auf Contravariance setzen.
|
||||
RefTypeOrTPHOrWildcardOrGeneric para;
|
||||
if ((para= params.getLast()) instanceof TypePlaceholder) {
|
||||
((TypePlaceholder) para).setVariance(-1);
|
||||
}
|
||||
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString() + "$$"), params, new NullToken()); // new FunN(params);
|
||||
} else {
|
||||
receiverType = new RefType(receiver.getClassName(), params, new NullToken());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ class Node<T> {
|
||||
addDescendant(descendant);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ class Node<T> {
|
||||
addPredecessor(predecessor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The content of this node.
|
||||
*/
|
||||
|
||||
@@ -1441,18 +1441,8 @@ public class TestComplete {
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var m = clazz.getDeclaredMethod("ex1");
|
||||
assertEquals("ABC", m.invoke(instance));
|
||||
//var ex2 = clazz.getDeclaredMethod("ex2");
|
||||
//assertEquals(0.0, ex2.invoke(instance));
|
||||
}
|
||||
@Test
|
||||
public void testBug365a() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug365a.jav");
|
||||
var clazz = classFiles.get("Bug365");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var m = clazz.getDeclaredMethod("ex1");
|
||||
assertEquals("ABC", m.invoke(instance));
|
||||
//var ex2 = clazz.getDeclaredMethod("ex2");
|
||||
//assertEquals(0.0, ex2.invoke(instance));
|
||||
var ex2 = clazz.getDeclaredMethod("ex2");
|
||||
assertEquals("BAC", ex2.invoke(instance));
|
||||
}
|
||||
@Test
|
||||
public void testBug366() throws Exception {
|
||||
@@ -1461,4 +1451,12 @@ public class TestComplete {
|
||||
var m = clazz.getDeclaredMethod("test");
|
||||
assertEquals(30, m.invoke(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug371() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug371.jav");
|
||||
var clazz = classFiles.get("Bug371");
|
||||
var m = clazz.getDeclaredMethod("test");
|
||||
assertEquals(true, m.invoke(null));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user