Compare commits
5 Commits
31df7a65f0
...
issue363
| Author | SHA1 | Date | |
|---|---|---|---|
| d6ed0689bc | |||
| d7676f36e3 | |||
|
|
9e323759d6 | ||
| 558083166d | |||
|
|
aec2f9a399 |
@@ -1,12 +1,13 @@
|
|||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
|
import java.lang.Object;
|
||||||
|
|
||||||
public class Bug365{
|
public class Bug365{
|
||||||
swap(f){
|
swap(f){
|
||||||
return x -> y -> f.apply(y).apply(x);
|
return x -> y -> f.apply(y).apply(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
swap(f){
|
swap(Fun1$$<String, Fun1$$<String, Fun1$$<String, Object>>> f){
|
||||||
return x -> y -> z -> f.apply(z).apply(x).apply(y);
|
return x -> y -> z -> f.apply(z).apply(y).apply(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ex1() {
|
public ex1() {
|
||||||
|
|||||||
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> inParams;
|
||||||
public final List<TargetType> realParams;
|
public final List<TargetType> realParams;
|
||||||
|
|
||||||
|
public GenericParameters(TargetFunNType funNType) {
|
||||||
|
this(funNType.funNParams(), funNType.returnArguments());
|
||||||
|
}
|
||||||
|
|
||||||
public GenericParameters(List<TargetType> params, int numReturns) {
|
public GenericParameters(List<TargetType> params, int numReturns) {
|
||||||
this.realParams = params;
|
this.realParams = params;
|
||||||
this.inParams = flattenTypeParams(params);
|
this.inParams = flattenTypeParams(params);
|
||||||
|
|||||||
@@ -393,7 +393,12 @@ public class JavaTXCompiler {
|
|||||||
logFile.write(ASTTypePrinter.print(sf));
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
logFile.flush();
|
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> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
@@ -416,7 +421,14 @@ public class JavaTXCompiler {
|
|||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
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: " + " ???");
|
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();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import java.util.*;
|
|||||||
/**
|
/**
|
||||||
* Speichert die Klassen f<>r einen bestimmten Projektscope
|
* Speichert die Klassen f<>r einen bestimmten Projektscope
|
||||||
*/
|
*/
|
||||||
public class JavaClassRegistry {
|
public class JavaClassRegistry{
|
||||||
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
||||||
|
|
||||||
public JavaClassRegistry(Map<String, Integer> initialNames) {
|
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) {
|
public void addName(String className, int numberOfGenerics) {
|
||||||
existingClasses.put(new JavaClassName(className), 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.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
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.*;
|
||||||
import de.dhbwstuttgart.target.tree.expression.*;
|
import de.dhbwstuttgart.target.tree.expression.*;
|
||||||
import de.dhbwstuttgart.target.tree.type.*;
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
@@ -780,7 +782,15 @@ public class ASTToTargetAST {
|
|||||||
return TargetFunNType.fromParams(params, filteredParams, gep.getReturnType() != null ? 1 : 0);
|
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) {
|
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 testClass = compiler.getClass(new JavaClassName(test.name()));
|
||||||
var otherClass = compiler.getClass(new JavaClassName(other.name()));
|
var otherClass = compiler.getClass(new JavaClassName(other.name()));
|
||||||
if (testClass == null) return false;
|
if (testClass == null) return false;
|
||||||
|
|||||||
@@ -138,7 +138,10 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(BoolExpression bool) {
|
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
|
@Override
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
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 static final long serialVersionUID = 1L;
|
||||||
private Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
private Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
||||||
private Boolean isImplemented = false;
|
private Boolean isImplemented = false;
|
||||||
@@ -73,5 +73,9 @@ public class Constraint<A> extends HashSet<A> {
|
|||||||
public String toStringBase() {
|
public String toStringBase() {
|
||||||
return super.toString();
|
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
|
* 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 A left;
|
||||||
private final B right;
|
private final B right;
|
||||||
|
|
||||||
@@ -58,5 +58,14 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
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;
|
package de.dhbwstuttgart.typeinference.result;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
@@ -12,7 +14,7 @@ import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class ResultSet {
|
public class ResultSet implements Comparable<ResultSet>{
|
||||||
|
|
||||||
public final Set<ResultPair> results;
|
public final Set<ResultPair> results;
|
||||||
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
||||||
@@ -22,6 +24,10 @@ public class ResultSet {
|
|||||||
this.genIns = new HashSet<>();
|
this.genIns = new HashSet<>();
|
||||||
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
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) {
|
public boolean contains(ResultPair toCheck) {
|
||||||
return this.results.contains(toCheck);
|
return this.results.contains(toCheck);
|
||||||
@@ -63,6 +69,21 @@ public class ResultSet {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return results.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 {
|
class Resolver implements ResultSetVisitor {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ class Node<T> {
|
|||||||
addDescendant(descendant);
|
addDescendant(descendant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||||
*/
|
*/
|
||||||
@@ -73,7 +73,7 @@ class Node<T> {
|
|||||||
addPredecessor(predecessor);
|
addPredecessor(predecessor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content of this node.
|
* The content of this node.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1441,8 +1441,8 @@ public class TestComplete {
|
|||||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
var m = clazz.getDeclaredMethod("ex1");
|
var m = clazz.getDeclaredMethod("ex1");
|
||||||
assertEquals("ABC", m.invoke(instance));
|
assertEquals("ABC", m.invoke(instance));
|
||||||
//var ex2 = clazz.getDeclaredMethod("ex2");
|
var ex2 = clazz.getDeclaredMethod("ex2");
|
||||||
//assertEquals(0.0, ex2.invoke(instance));
|
assertEquals("BAC", ex2.invoke(instance));
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testBug366() throws Exception {
|
public void testBug366() throws Exception {
|
||||||
@@ -1451,4 +1451,12 @@ public class TestComplete {
|
|||||||
var m = clazz.getDeclaredMethod("test");
|
var m = clazz.getDeclaredMethod("test");
|
||||||
assertEquals(30, m.invoke(null));
|
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