Compare commits

..

8 Commits

Author SHA1 Message Date
dholle a1195b689d Fix test case
SonarQube Scan / SonarQube Trigger (push) Failing after 1m28s
2026-05-06 21:39:59 +02:00
pl@gohorb.ba-horb.de 3cd61778d6 Changes to be committed:
SonarQube Scan / SonarQube Trigger (push) Failing after 1m30s
new file:   Kombinatoren.jav
	new file:   Kombinatoren_Or.jav
	modified:   Kombinatoren_failure.jav
	modified:   ../../src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java
	modified:   ../../src/main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IRuleSet.java
	modified:   ../../src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
	modified:   ../../src/test/java/AllgemeinTest.java
	modified:   ../../src/test/java/TestComplete.java
2026-05-06 00:07:57 +02:00
pl@gohorb.ba-horb.de 021d3e1b27 modified: ../../src/test/java/AllgemeinTest.java
SonarQube Scan / SonarQube Trigger (push) Failing after 3m21s
2026-05-03 12:29:32 +02:00
pl@gohorb.ba-horb.de c90f01d5db Merge branch 'master' of https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore
SonarQube Scan / SonarQube Trigger (push) Failing after 1m30s
2026-05-03 12:24:37 +02:00
pl@gohorb.ba-horb.de 8b3b018ea9 modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java 2026-05-03 12:23:06 +02:00
pl@gohorb.ba-horb.de 210adaa493 new file: Kombinatoren_failure.jav
SonarQube Scan / SonarQube Trigger (push) Failing after 4m16s
modified:   ../../src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   ../../src/test/java/AllgemeinTest.java
2026-05-03 12:19:03 +02:00
dholle 2f7e4fc1e4 WIP
SonarQube Scan / SonarQube Trigger (push) Failing after 1m56s
2026-04-30 14:28:35 +02:00
dholle 433dcf83c2 Small bug fix
SonarQube Scan / SonarQube Trigger (push) Failing after 2m33s
2026-04-29 07:54:47 +02:00
26 changed files with 572 additions and 275 deletions
+70
View File
@@ -0,0 +1,70 @@
import java.util.stream.Stream;
//import java.util.List;
import java.util.ArrayList;
import java.io.PrintStream;
import java.lang.System;
//import java.lang.String;
import java.lang.Boolean;
import java.util.function.Function;
import Pair;
import Kombinatoren_failure;
public class Kombinatoren {
kb = new Kombinatoren_failure();
satisfy(cond) {
// return () -> Stream.of (newToks -> new Kombinatoren_failure().failure().apply().map(x -> x.apply(newToks)));
//}
return () -> Stream.of (toks -> {
if(toks.isEmpty()) {
return new ArrayList<>().stream();
}
else
{
var fst = toks.getFirst();
if (cond.apply(fst))
{
//var newToks = List.copyOf(toks.subList(1, toks.size()));
var newToks = new ArrayList<>(toks);
return newToks.removeFirst();
kb.getContent(
kb.succeed(fst).apply().map(x -> x.apply(newToks))
);
// ;
}
}
}
);
}
/* () -> Stream.of (toks -> {
//System.out.println(toks);
if(toks.isEmpty())
{
return new ArrayList<>().stream();
}
else {
var fst = toks.getFirst();
if (cond.apply(fst))
{
var newToks = List.copyOf(toks.subList(1, toks.size()));
//System.out.println("satisfy ok " + fst.toString());
//return get(succeed(fst).apply().map(x -> x.apply(newToks)));
}
else {
//System.out.println("satisfy failure " + fst.toString());
//return get(failure().apply()).apply(toks);
}
return new ArrayList<>().stream();
} } ) ;
}
*/
}
@@ -0,0 +1,30 @@
import java.util.stream.Stream;
import Pair;
import java.util.function.Function;
public class Kombinatoren_Or {
orP (p1, p2) {
return ()-> Stream.concat(p1.apply(), p2.apply());
}
/*
after (fst, snd) { //System.out.println("after2");
return () -> Stream.of(
toks -> {
return fst.apply().flatMap(x ->
x.apply(toks).flatMap(p1 ->
snd.apply().flatMap(y -> y.apply(p1.snd()).map(p2 ->
new Pair<>(new Pair<>(p1.fst(), p2.fst()), p2.snd()))))); } );
}
*/
trans (p, f) {
return () -> p.apply().map(x -> (toks -> x.apply(toks).map(pr -> new Pair<>(f.apply(pr.fst()), pr.snd() ) ) ) );
}
}
@@ -0,0 +1,59 @@
import java.util.stream.Stream;
import java.util.List;
import java.util.ArrayList;
import java.io.PrintStream;
import java.lang.System;
import java.lang.String;
import java.lang.Boolean;
import java.util.function.Function;
import Pair;
public class Kombinatoren_failure {
public getContent(s) {
return s.toList().getFirst();
}
public failure() {
return () -> Stream.of(
toks -> new ArrayList<>().stream());
}
public succeed( value) {
return () -> Stream.of(toks -> {
//System.out.println("succeed");
var al = new ArrayList<>();
al.add(new Pair<>(value, toks));
//al.forEach(x -> { System.out.println(x.toString());});
return al.stream();});
}
}
/*
satisfy(cond) {
return newToks -> failure().apply().map(x -> x.apply(newToks));
/*
return () -> Stream.of (toks -> {
if(toks.isEmpty()) {
return new ArrayList<>().stream();
}
else {
var fst = toks.getFirst();
if (cond.apply(fst)) {
var newToks = List.copyOf(toks.subList(1, toks.size()));
this.getContent(
succeed(fst)
.apply().map(x -> x.apply(newToks))
)
;
}
}
}
);
*/
}
}
*/
+10
View File
@@ -0,0 +1,10 @@
import java.lang.String;
public class Bug389 {
public swap(f) {
return x -> y -> f.apply(y).apply(x);
}
public swap(f) {
return x -> y -> z -> f.apply(z).apply(x).apply(y);
}
}
@@ -0,0 +1,12 @@
import Bug389;
import java.util.List;
import java.lang.String;
import java.lang.Integer;
public class Bug389Main {
public static main(args) {
var func = x -> y -> z -> x + y + z;
var swap = new Bug389();
swap.swap(func).apply(1).apply(2).apply(3);
}
}
@@ -1,14 +1,13 @@
sealed interface List<T> permits Cons, Empty {}
public record Cons<T>(T a, List<T> l) implements List<T> {}
public record Empty<T>() implements List<T> {}
public record Tuple<T1, T2>(T1 a, T2 b) {}
import Cons;
import Empty;
import List;
import Pair;
public class PatternMatching {
public zip(Cons(x, xs), Cons(y, ys)) {
return new Cons(new Tuple(x, y), zip(xs, ys));
return new Cons<>(new Pair<>(x, y), zip(xs, ys));
}
public zip(Empty x, Empty y) { return new Empty(); }
public zip(Empty x, Empty y) { return new Empty<>(); }
/*public zip(Empty x, Cons y) { return new Empty(); }
public zip(Cons x, Empty y) { return new Empty(); }
@@ -2,18 +2,24 @@ import java.lang.Object;
import List;
import Cons;
import Empty;
import Tuple;
import Pair;
public class PatternMatchingJava {
public zip(a, b) {
public <A, B> Cons<Pair<A, B>> zip(Cons<A> a, Cons<B> b) {
switch (a) {
case Cons(x, Cons xs) -> {
switch (b) {
case Cons(y, Cons ys) -> { return new Cons<>(new Tuple<>(x, y), zip(xs, ys)); }
case Cons(y, Empty()) -> { return new Empty<>(); }
case Cons(y, Cons ys) -> { return new Cons<>(new Pair<>(x, y), zip(xs, ys)); }
};
}
case Cons(x, Empty xs) -> {
switch (b) {
case Cons(y, Empty ys) -> { return new Cons<>(new Pair<>(x, y), zip(xs, ys)); }
};
}
case Cons(x, Empty()) -> { return new Empty<>(); }
};
}
public <A, B> Empty<Pair<A, B>> zip(Empty<A> a, Empty<B>) {
return new Empty<>();
}
}
@@ -1,5 +1,5 @@
sealed interface List<T> permits Cons, Empty {}
public sealed interface List<T> permits Cons, Empty {}
public record Cons<T>(T a, List<T> l) implements List<T> {}
public record Empty<T>() implements List<T> {}
public record Tuple<T1, T2>(T1 a, T2 b) {}
public record Pair<T1, T2>(T1 a, T2 b) {}
@@ -4,6 +4,7 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Pattern;
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
import de.dhbwstuttgart.target.tree.*;
import de.dhbwstuttgart.target.tree.expression.*;
@@ -422,43 +422,6 @@ public class JavaTXCompiler {
return typeInference(List.of(file));
}
public static String constraintSetToDot(ConstraintSet<Pair> c){
Iterator<String> colors = List.of(
"#FF0000", "#FF7F00", "#FFFF00", "#7FFF00", "#00FF00", "#00FF7F", "#00FFFF", "#007FFF",
"#0000FF", "#7F00FF", "#FF00FF", "#FF007F", "#BF0000", "#BF5F00", "#BFBF00", "#5FBF00",
"#00BF00", "#00BF5F", "#00BFBF", "#005FBF", "#0000BF", "#5F00BF", "#BF00BF", "#BF005F",
"#800000", "#804000", "#808000", "#408000", "#008000", "#008040", "#008080", "#004080",
"#000080", "#400080", "#800080", "#800040", "#FF4040", "#FF8040", "#FFFF40", "#80FF40",
"#40FF40", "#40FF80", "#40FFFF", "#4080FF", "#4040FF", "#8040FF", "#FF40FF", "#FF4080",
"#BF4040", "#BF8040", "#BFBF40", "#80BF40", "#40BF40", "#40BF80", "#40BFBF", "#4080BF",
"#4040BF", "#8040BF", "#BF40BF", "#BF4080", "#FF8080", "#FFBF80", "#FFFF80", "#BFFF80",
"#80FF80", "#80FFBF", "#80FFFF", "#80BFFF", "#8080FF", "#BF80FF", "#FF80FF", "#FF80BF").iterator();
StringBuilder sb = new StringBuilder();
sb.append("diagraph G{");
//and constraints to dot
sb.append(c.getUndConstraints().stream().map(Pair::toDot).collect(Collectors.joining("\n")));
//or constraints to dot
for (var orConstSet : c.getOderConstraints()){
for(var cons : orConstSet){
String color = colors.next();
sb.append(cons.stream().map(x -> x.toDot(color)).collect(Collectors.joining("\n")));
}
}
sb.append("}");
return sb.toString();
}
public static String q(String s) {
return "\"" + s.replace("\"", "\\\"") + "\"";
}
public List<ResultSet> typeInference(List<File> files) throws ClassNotFoundException, IOException {
Set<ClassOrInterface> allClasses = new HashSet<>();
@@ -475,36 +438,6 @@ public class JavaTXCompiler {
TYPE ty = new TYPE(definedClasses, allClasses);
var cons = ty.getConstraints();
var ANDconstraints = cons.getUndConstraints();
var ORConstraints = cons.getOderConstraints();
var orIterator = ORConstraints.iterator();
while(orIterator.hasNext()){
Set<Constraint<Pair>> y = orIterator.next();
if (y.isEmpty()) orIterator.remove();
else if (y.size() == 1){
ANDconstraints.addAll(y.iterator().next()); // add the OR constraint to the AND constraint since we only have one option
orIterator.remove();
}
}
String dot = constraintSetToDot(cons);
ANDconstraints.forEach(System.out::println);
for (var orc : ORConstraints){
System.out.println();
System.out.println("------");
System.out.println();
for(var hashs : orc){
System.out.print(hashs);
System.out.print("\n | \n");
}
}
Set<Set<UnifyPair>> results = new HashSet<>();
PlaceholderRegistry placeholderRegistry = new PlaceholderRegistry();
@@ -700,7 +700,7 @@ public class StatementGenerator {
case ConditionalassignexpressionContext condassign:
return convert(condassign);
default:
throw new NotImplementedException();
throw new NotImplementedException(expression.getClass().toString());
}
}
@@ -64,6 +64,8 @@ public class TypeGenerator {
switch (typeContext.primitiveType().getText()) {
case "boolean":
return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), typeContext.getStart());
case "char":
return new RefType(ASTFactory.createClass(Character.class).getClassName(), typeContext.getStart());
case "int":
return new RefType(ASTFactory.createClass(Integer.class).getClassName(), typeContext.getStart());
case "double":
@@ -71,7 +73,7 @@ public class TypeGenerator {
case "float":
return new RefType(ASTFactory.createClass(Float.class).getClassName(), typeContext.getStart());
default:
throw new NotImplementedException();
throw new NotImplementedException(typeContext.primitiveType().getText());
}
} else if (!typeContext.LBRACK().isEmpty()) { // ArrayType über eckige Klammer prüfen
// JavaTXParser.logger.info(unannTypeContext.getText());
@@ -229,9 +229,6 @@ public class ASTFactory {
public static Method createMethod(java.lang.reflect.Method jreMethod, String signature, java.lang.Class inClass, Boolean isInherited, Boolean isImplemented) {
String name = jreMethod.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType;
if (inClass.getName().equals("Swap")){
System.out.println();
}
Type jreRetType;
if (jreMethod.getGenericReturnType() != null) {
jreRetType = jreMethod.getGenericReturnType();
@@ -27,9 +27,10 @@ public class MethodCall extends Statement
public RefTypeOrTPHOrWildcardOrGeneric receiverType;
//sind Tphs, repraesentieren im Resultset die Signatur der aufgerufenen Methoden, letztes Element ist der Returntyp
public final ArrayList<TypePlaceholder> signature;
public final ArrayList<TypePlaceholder> signature;
public int modifiers;
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<TypePlaceholder> signature, Token offset){
super(retType,offset);
this.arglist = argumentList;
@@ -65,6 +65,10 @@ public class ASTToTargetAST {
public Generics(JavaTXCompiler compiler, ResultSet set) {
this(new JavaGenerics(compiler, set), new TxGenerics(compiler, set));
}
public static Generics nullGenerics() {
return new Generics(null, new ResultSet(Set.of()));
}
}
public IByteArrayClassLoader classLoader;
@@ -94,10 +98,15 @@ public class ASTToTargetAST {
tphsInMethods.put(currentMethod, set);
}
public static Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList, JavaTXCompiler compiler) {
return findMethod(owner, name, argumentList, Generics.nullGenerics().javaGenerics(), compiler);
}
public static Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList, IGenerics generics, JavaTXCompiler compiler) {
Optional<Method> method = Optional.empty();
while (method.isEmpty()) {
method = owner.getMethods().stream().filter(m -> m.name.equals(name) && parameterEquals(m.getParameterList(), argumentList, generics)).findFirst();
method = owner.getMethods().stream().filter(m -> m.name.equals(name) &&
parameterEquals(m.getParameterList().getFormalparalist().stream().map(p -> generics.getTargetType(p.getType())).toList(), argumentList)).findFirst();
if (owner.getClassName().toString().equals("java.lang.Object")) break;
owner = compiler.getClass(owner.getSuperClass().getName());
}
@@ -105,16 +114,16 @@ public class ASTToTargetAST {
}
Optional<Constructor> findConstructor(ClassOrInterface owner, List<TargetType> argumentList, IGenerics generics) {
return owner.getConstructors().stream().filter(c -> parameterEquals(c.getParameterList(), argumentList, generics)).findFirst();
return owner.getConstructors().stream().filter(c ->
parameterEquals(c.getParameterList().getFormalparalist().stream().map(p -> generics.getTargetType(p.getType())).toList(), argumentList)).findFirst();
}
static boolean parameterEquals(ParameterList parameterList, List<TargetType> arguments, IGenerics generics) {
var pars = parameterList.getFormalparalist();
static boolean parameterEquals(List<TargetType> pars, List<TargetType> arguments) {
if (pars.size() != arguments.size())
return false;
for (var i = 0; i < pars.size(); i++) {
var type1 = generics.getTargetType(pars.get(i).getType());
var type1 = pars.get(i);
var type2 = arguments.get(i);
if (type1 instanceof TargetGenericType)
return true;
@@ -380,9 +389,15 @@ public class ASTToTargetAST {
else return new TargetClass(input.getModifiers(), input.getClassName(), convert(input.getSuperClass(), generics.javaGenerics, compiler), javaGenerics, txGenerics, superInterfaces, constructors, staticConstructor, fields, methods);
}
@Deprecated
public List<MethodParameter> convert(ParameterList input) {
return convert(input, all.getFirst().javaGenerics);
var res = new ArrayList<MethodParameter>();
for (var i = 0; i < input.getFormalparalist().size(); i++) {
var param = input.getFormalparalist().get(i);
var pattern = (TargetPattern) convert(param, Generics.nullGenerics().javaGenerics);
if (pattern instanceof TargetComplexPattern) pattern = pattern.withName("__var" + i);
res.add(new MethodParameter(pattern));
}
return res;
}
public List<MethodParameter> convert(ParameterList input, IGenerics generics) {
@@ -701,6 +716,7 @@ public class ASTToTargetAST {
var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method);
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
System.out.println(javaSignature.getDescriptor());
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), generics.txGenerics, compiler));
signatures.add(new Signature(javaSignature, txSignature, generics));
@@ -754,7 +770,7 @@ public class ASTToTargetAST {
for (var i = 0; i < tspec.params().size(); i++) {
var param = tspec.params().get(i);
if (param instanceof TargetSpecializedType fn) {
collectArguments(tspec, newParams);
collectArguments(fn, newParams);
} else {
newParams.add(param);
}
@@ -216,6 +216,10 @@ public class StatementToTargetExpression implements ASTVisitor {
return ASTToTargetAST.findMethod(converter.compiler.getClass(className), name, args, generics, compiler);
}
Optional<Method> findMethod(JavaClassName className, String name, List<TargetType> args, JavaTXCompiler compiler) {
return ASTToTargetAST.findMethod(converter.compiler.getClass(className), name, args, compiler);
}
@Override
public void visit(MethodCall methodCall) {
var receiverType = converter.convert(methodCall.receiver.getType(), generics);
@@ -246,7 +250,7 @@ public class StatementToTargetExpression implements ASTVisitor {
} else if (!isFunNType) {
receiverClass = converter.compiler.getClass(receiverName);
if (receiverClass == null) throw new DebugException("Class " + receiverName + " does not exist!");
foundMethod = findMethod(receiverName, methodCall.name, signature, generics, converter.compiler).orElseThrow();
foundMethod = findMethod(receiverName, methodCall.name, signature, converter.compiler).orElseThrow();
}
if (!isFunNType) {
@@ -85,12 +85,11 @@ public class Constraint<A extends IConstraintElement> extends HashSet<A> impleme
}
public String toString() {
return super.toString();
// + "\nisInherited = " + isInherited
// + " isOveridden = " + isImplemented
// + " msc[" + methodSignatureConstraint.size() + "] = " + methodSignatureConstraint
// //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
// + "\n";
return super.toString() + "\nisInherited = " + isInherited
+ " isOveridden = " + isImplemented
+ " msc[" + methodSignatureConstraint.size() + "] = " + methodSignatureConstraint
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
+ "\n";
}
public String toStringBase() {
@@ -4,7 +4,6 @@ import de.dhbwstuttgart.server.packet.dataContainers.ISerializableData;
import de.dhbwstuttgart.server.packet.dataContainers.KeyStorage;
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialMap;
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
@@ -14,60 +13,58 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import static de.dhbwstuttgart.core.JavaTXCompiler.q;
public class Pair implements Serializable, IConstraintElement, ISerializableData {
public final RefTypeOrTPHOrWildcardOrGeneric TA1;
public final RefTypeOrTPHOrWildcardOrGeneric TA2;
public final RefTypeOrTPHOrWildcardOrGeneric TA1;
public final RefTypeOrTPHOrWildcardOrGeneric TA2;
private SourceLoc location;
private SourceLoc location;
private PairOperator eOperator = PairOperator.SMALLER;
private boolean noUnification = false;
private PairOperator eOperator = PairOperator.SMALLER;
private boolean noUnification = false;
private Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2) {
this.TA1 = TA1;
this.TA2 = TA2;
if (TA1 == null || TA2 == null)
throw new NullPointerException();
eOperator = PairOperator.SMALLER;
}
private Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2) {
this.TA1 = TA1;
this.TA2 = TA2;
if (TA1 == null || TA2 == null)
throw new NullPointerException();
eOperator = PairOperator.SMALLER;
}
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp) {
// Konstruktor
this(TA1, TA2);
this.eOperator = eOp;
}
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp) {
// Konstruktor
this(TA1, TA2);
this.eOperator = eOp;
}
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator e0p, SourceLoc location) {
this(TA1, TA2, e0p);
this.location = location;
}
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator e0p, SourceLoc location) {
this(TA1, TA2, e0p);
this.location = location;
}
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp, boolean noUnification) {
// Konstruktor
this(TA1, TA2);
this.eOperator = eOp;
this.noUnification = noUnification;
}
public Pair(RefTypeOrTPHOrWildcardOrGeneric TA1, RefTypeOrTPHOrWildcardOrGeneric TA2, PairOperator eOp, boolean noUnification) {
// Konstruktor
this(TA1, TA2);
this.eOperator = eOp;
this.noUnification = noUnification;
}
public SourceLoc getLocation() {
return this.location;
}
public SourceLoc getLocation() {
return this.location;
}
public String toString() {
// otth: Gibt ein Paar als String aus --> zum Debuggen und Vergleichen
String strElement1 = "NULL";
String strElement2 = "NULL";
String Operator = "<.";
public String toString() {
// otth: Gibt ein Paar als String aus --> zum Debuggen und Vergleichen
String strElement1 = "NULL";
String strElement2 = "NULL";
String Operator = "<.";
if (TA1 != null)
strElement1 = TA1.toString();
if (TA1 != null)
strElement1 = TA1.toString();
if (TA2 != null)
strElement2 = TA2.toString();
if (TA2 != null)
strElement2 = TA2.toString();
/* PL ausskommentiert 2018-05-24
if(OperatorEqual())
@@ -78,125 +75,103 @@ public class Pair implements Serializable, IConstraintElement, ISerializableData
Operator = "<?";
*/
return "\n(P: " + strElement1 + " " + eOperator.toString() + " " + strElement2 + ")";
return "\n(P: " + strElement1 + " " + eOperator.toString() + " " + strElement2 + ")";
/*- Equals: " + bEqual*/
}
/*- Equals: " + bEqual*/
}
/**
* <br/>Author: J�rg B�uerle
*
* @param obj
* @return
*/
public boolean equals(Object obj) {
return (
(obj instanceof Pair pairObj) &&
pairObj.TA1.equals(this.TA1) &&
pairObj.TA2.equals(this.TA2)
);
}
/**
* <br/>Author: J�rg B�uerle
*
* @param obj
* @return
*/
public boolean equals(Object obj) {
return (
(obj instanceof Pair pairObj) &&
pairObj.TA1.equals(this.TA1) &&
pairObj.TA2.equals(this.TA2)
);
}
/**
* Author: Arne Lüdtke<br/>
* Abfrage, ob Operator vom Typ Equal ist.
*/
public boolean OperatorEqual() {
return eOperator == PairOperator.EQUALSDOT;
}
/**
* Author: Arne Lüdtke<br/>
* Abfrage, ob Operator vom Typ Equal ist.
*/
public boolean OperatorEqual() {
return eOperator == PairOperator.EQUALSDOT;
}
/**
* Author: Arne Lüdtke<br/>
* Abfrage, ob Operator vom Typ Smaller ist.
*/
public boolean OperatorSmaller() {
return eOperator == PairOperator.SMALLER;
}
/**
* Author: Arne Lüdtke<br/>
* Abfrage, ob Operator vom Typ Smaller ist.
*/
public boolean OperatorSmaller() {
return eOperator == PairOperator.SMALLER;
}
/**
* Author: Arne Lüdtke<br/>
* Abfrage, ob Operator vom Typ SmallerExtends ist.
*/
public boolean OperatorSmallerExtends() {
return eOperator == PairOperator.SMALLERDOTWC;
}
/**
* Author: Arne Lüdtke<br/>
* Abfrage, ob Operator vom Typ SmallerExtends ist.
*/
public boolean OperatorSmallerExtends() {
return eOperator == PairOperator.SMALLERDOTWC;
}
/**
* Author: Arne Lüdtke<br/>
* Gibt den Operator zurück.
*/
public PairOperator GetOperator() {
return eOperator;
}
/**
* Author: Arne Lüdtke<br/>
* Gibt den Operator zurück.
*/
public PairOperator GetOperator() {
return eOperator;
}
public boolean OperatorSmallerDot() {
return eOperator == PairOperator.SMALLERDOT;
}
public boolean OperatorSmallerDot() {
return eOperator == PairOperator.SMALLERDOT;
}
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
constraints.map((Pair p) -> {
if (p.TA1 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
}
if (p.TA2 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
}
return null;
});
return ret;
}
static public Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>();
constraints.map((Pair p) -> {
if (p.TA1 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1);
}
if (p.TA2 instanceof TypePlaceholder) {
ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2);
}
return null;
});
return ret;
}
@Override
public SerialMap toSerial(KeyStorage keyStorage) {
// because toString() will output TA1 and TA2 recursively, we can ignore potential infinite recursion here too
SerialMap serialized = new SerialMap();
serialized.put("ta1", this.TA1.toSerial(keyStorage));
serialized.put("ta2", this.TA2.toSerial(keyStorage));
serialized.put("op", this.eOperator.toString());
serialized.put("noUnification", this.noUnification ? 1 : 0);
serialized.put("location", this.location == null ? null : this.location.toSerial(keyStorage));
return serialized;
}
@Override
public SerialMap toSerial(KeyStorage keyStorage) {
// because toString() will output TA1 and TA2 recursively, we can ignore potential infinite recursion here too
SerialMap serialized = new SerialMap();
serialized.put("ta1", this.TA1.toSerial(keyStorage));
serialized.put("ta2", this.TA2.toSerial(keyStorage));
serialized.put("op", this.eOperator.toString());
serialized.put("noUnification", this.noUnification ? 1 : 0);
serialized.put("location", this.location == null ? null : this.location.toSerial(keyStorage));
return serialized;
}
public static Pair fromSerial(SerialMap data, UnifyContext context) {
String op = data.getValue("op").getOf(String.class);
SerialMap ta1 = data.getMap("ta1");
SerialMap ta2 = data.getMap("ta2");
boolean noUnification = data.getValue("noUnification").getOf(Integer.class) == 1;
SerialMap location = data.getMapOrNull("location");
public static Pair fromSerial(SerialMap data, UnifyContext context) {
String op = data.getValue("op").getOf(String.class);
SerialMap ta1 = data.getMap("ta1");
SerialMap ta2 = data.getMap("ta2");
boolean noUnification = data.getValue("noUnification").getOf(Integer.class) == 1;
SerialMap location = data.getMapOrNull("location");
var pair = new Pair(
RefTypeOrTPHOrWildcardOrGeneric.fromSerial(ta1, context),
RefTypeOrTPHOrWildcardOrGeneric.fromSerial(ta2, context),
PairOperator.fromString(op),
noUnification
);
if (location != null) pair.location = SourceLoc.fromSerial(location);
return pair;
}
public String toDot(String color) {
return q(this.TA1.toString()) +
" -> " +
q(this.TA2.toString()) +
" [label=" +
q(this.GetOperator().toString()) +
",color=" + q(color) + "]" +
";\n";
}
public String toDot() {
return q(this.TA1.toString()) +
" -> " +
q(this.TA2.toString()) +
" [label=" +
q(this.GetOperator().toString()) +
"]" +
";\n";
}
var pair = new Pair(
RefTypeOrTPHOrWildcardOrGeneric.fromSerial(ta1, context),
RefTypeOrTPHOrWildcardOrGeneric.fromSerial(ta2, context),
PairOperator.fromString(op),
noUnification
);
if (location != null) pair.location = SourceLoc.fromSerial(location);
return pair;
}
}
// ino.end
@@ -35,8 +35,8 @@ public class TYPE {
this.definedClasses = definedClasses;
}
public ConstraintSet<Pair> getConstraints() {
ConstraintSet<Pair> ret = new ConstraintSet<>();
public ConstraintSet getConstraints() {
ConstraintSet ret = new ConstraintSet();
for (ClassOrInterface cl : definedClasses) {
Set<ClassOrInterface> allClasses = TypeUnifyTaskHelper.getPresizedHashSet(allAvailableClasses.size());
allClasses.addAll(allAvailableClasses);
@@ -45,9 +45,9 @@ public class TYPE {
return ret;
}
private ConstraintSet<Pair> getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
ConstraintSet<Pair> ret = new ConstraintSet<>();
ConstraintSet<Pair> methConstrains;
private ConstraintSet getConstraintsClass(ClassOrInterface cl, TypeInferenceInformation info) {
ConstraintSet ret = new ConstraintSet();
ConstraintSet methConstrains;
for(Method m : cl.getMethods()){
ret.addAll(methConstrains = getConstraintsMethod(m,info, cl));
m.constraints.addAll(methConstrains);
@@ -86,11 +86,11 @@ public class TYPE {
}
*/
private ConstraintSet<Pair> getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
if(m.block == null)return new ConstraintSet<Pair>(); //Abstrakte Methoden generieren keine Constraints
private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
TYPEStmt methodScope = new TYPEStmt(blockInfo);
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
ConstraintSet constraintSet = new ConstraintSet();
if (m.name.equals("main") && Modifier.isStatic(m.modifier) && m.getParameterList().getFormalparalist().size() == 1) {
// Add constraint for main method
@@ -736,12 +736,12 @@ public class TYPEStmt implements StatementVisitor {
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
// Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params)
ret.add(new Pair(foMethod.signature.get(i), assumption.getArgTypes().get(i), PairOperator.EQUALSDOT));
ret.add(new Pair(resolver.resolve(foMethod.signature.get(i)), resolver.resolve(assumption.getArgTypes().get(i)), PairOperator.EQUALSDOT));
}
// Zuordnung von MethodCall.signature(ReturnType) zu dem ReturnType der ausgewaehlten Methode (assumption.returnType)
ret.add(new Pair(foMethod.signature.getLast(), assumption.getReturnType(), PairOperator.EQUALSDOT));
ret.add(new Pair(resolver.resolve(foMethod.signature.getLast()), resolver.resolve(assumption.getReturnType()), PairOperator.EQUALSDOT));
return ret;
}
@@ -755,7 +755,7 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
if((!(lhsType instanceof ReferenceType) && !(lhsType instanceof FunNType)) || !(rhsType instanceof ExtendsType))
return Optional.empty();
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
@@ -781,7 +781,7 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
if((!(lhsType instanceof ReferenceType) && !(lhsType instanceof FunNType)) || !(rhsType instanceof SuperType))
return Optional.empty();
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
@@ -904,7 +904,7 @@ public class RuleSet implements IRuleSet{
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
var retType = fiArgs.getFirst();
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType); //FALSCHRUM????
var lhsRet = lhsArgs.getFirst();
Set<UnifyPair> result = new HashSet<>();
@@ -972,15 +972,65 @@ public class RuleSet implements IRuleSet{
}
@Override
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) {
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
if(!(rhsType instanceof FunNType))
return Optional.empty();
/* muss nach angepasst werden */
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
if (lhsType instanceof ReferenceType) {
UnifyType typeFI = pair.getLhsType();
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
if(!opt.isPresent())
return Optional.empty();
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
return Optional.empty();
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
var retType = fiArgs.getFirst();
var rhsArgs = intf.getFunctionalInterfaceTypeArguments(rhsType);
var rhsRet = rhsArgs.getFirst();
Set<UnifyPair> result = new HashSet<>();
//if (retType instanceof ExtendsType) {
result.add(new UnifyPair(retType, rhsRet, PairOperator.SMALLER));
//} else if (retType instanceof SuperType) {
// return Optional.empty();
//} else {
// result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
//}
for (var i = 1; i < fiArgs.size(); i++) {
var rh = rhsArgs.get(i);
var lh = fiArgs.get(i);
//if (rh instanceof SuperType) {
result.add(new UnifyPair(rh, lh, PairOperator.SMALLER));
//} else if (rh instanceof ExtendsType) {
// return Optional.empty();
//} else {
// result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
//}
}
return Optional.of(result);
}
else {
if(!(lhsType instanceof PlaceholderType))
return Optional.empty();
}
FunNType funNRhsType = (FunNType) rhsType;
@@ -1017,7 +1067,122 @@ public class RuleSet implements IRuleSet{
return Optional.of(result);
}
@Override
public Optional<Set<UnifyPair>> reduceFIFunN(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(rhsType instanceof FunNType))
return Optional.empty();
/* muss nach angepasst werden */
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
if (lhsType instanceof ReferenceType) {
UnifyType typeFI = pair.getLhsType();
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
if(!opt.isPresent())
return Optional.empty();
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
return Optional.empty();
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
var retType = fiArgs.getFirst();
var rhsArgs = intf.getFunctionalInterfaceTypeArguments(rhsType);
var rhsRet = rhsArgs.getFirst();
Set<UnifyPair> result = new HashSet<>();
//if (retType instanceof ExtendsType) {
result.add(new UnifyPair(retType, rhsRet, PairOperator.EQUALSDOT));
//} else if (retType instanceof SuperType) {
// return Optional.empty();
//} else {
// result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
//}
for (var i = 1; i < fiArgs.size(); i++) {
var rh = rhsArgs.get(i);
var lh = fiArgs.get(i);
//if (rh instanceof SuperType) {
result.add(new UnifyPair(rh, lh, PairOperator.EQUALSDOT));
//} else if (rh instanceof ExtendsType) {
// return Optional.empty();
//} else {
// result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
//}
}
return Optional.of(result);
}
else {
return Optional.empty();
}
}
@Override
public Optional<Set<UnifyPair>> reduceFunNFi(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.EQUALSDOT)
return Optional.empty();
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof FunNType))
return Optional.empty();
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
if (rhsType instanceof ReferenceType) {
UnifyType typeFI = pair.getRhsType();
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
if(!opt.isPresent())
return Optional.empty();
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
return Optional.empty();
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
var retType = fiArgs.getFirst();
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
var lhsRet = lhsArgs.getFirst();
Set<UnifyPair> result = new HashSet<>();
//if (retType instanceof ExtendsType) {
// result.add(new UnifyPair(lhsRet, retType, PairOperator.SMALLERDOTWC));
//} else if (retType instanceof SuperType) {
// return Optional.empty();
//} else {
result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
//}
for (var i = 1; i < fiArgs.size(); i++) {
var lh = lhsArgs.get(i);
var rh = fiArgs.get(i);
//if (rh instanceof SuperType) {
// result.add(new UnifyPair(lh, rh, PairOperator.SMALLERDOTWC));
//} else if (rh instanceof ExtendsType) {
// return Optional.empty();
//} else {
result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
//}
}
return Optional.of(result);
}
else {
return Optional.empty();
}
}
@Override
public Optional<UnifyPair> reduceTph(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
@@ -1025,7 +1190,7 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType))
if(!(lhsType instanceof PlaceholderType) || (!(rhsType instanceof ReferenceType) && !(rhsType instanceof FunNType)))
return Optional.empty();
return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
@@ -1239,7 +1239,7 @@ public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<Uni
// FunN Rules
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair, fc);
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair);
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair, fc);
// One of the rules has been applied
if (optSet.isPresent()) {
@@ -61,7 +61,9 @@ public interface IRuleSet {
*/
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair);
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair, IFiniteClosure fc);
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair);
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc);
public Optional<Set<UnifyPair>> reduceFIFunN(UnifyPair pair, IFiniteClosure fc);
public Optional<Set<UnifyPair>> reduceFunNFi(UnifyPair pair, IFiniteClosure fc);
/**
* Checks whether the erase1-Rule applies to the pair.
@@ -684,6 +684,7 @@ public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-1
return Optional.empty();
}
@Override
public Set<UnifyType> getAncestors(UnifyType t) {
+7 -2
View File
@@ -14,7 +14,9 @@ import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists;
import de.dhbwstuttgart.core.ConsoleInterface;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.util.Logger.LogLevel;
public class AllgemeinTest {
@@ -29,6 +31,7 @@ public class AllgemeinTest {
@Test
public void test() throws Exception {
ConsoleInterface.logLevel = LogLevel.DEBUG;
//String className = "GenTest";
//String className = "Overloading_Generics";
//String className = "Generics";
@@ -63,11 +66,13 @@ public class AllgemeinTest {
//String className = "Cycle";
//String className = "TripleTest";
//String className = "WildcardList";
String className = "List";
//String className = "List";
//String className = "Box";
//String className = "GenBox";
//String className = "InnerInf";
//String className = "Foo";
String className = "Kombinatoren_Or";
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
@@ -76,7 +81,7 @@ public class AllgemeinTest {
///*
compiler = new JavaTXCompiler(
Lists.newArrayList(new File(path)),
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/")),
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/AllgemeinTest/")),
new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/"), true);
//*/
compiler.generateBytecode();
+12 -2
View File
@@ -1,6 +1,8 @@
import de.dhbwstuttgart.core.ConsoleInterface;
import de.dhbwstuttgart.util.Logger;
import de.dhbwstuttgart.util.Logger.LogLevel;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -959,14 +961,14 @@ public class TestComplete {
@Test
public void testPatternMatchingZip() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "PatternMatching.jav");
ConsoleInterface.logLevel = LogLevel.DEBUG;
var classFiles = generateClassFiles(createClassLoader(), false,"PatternMatchingJava2.jav", "PatternMatching.jav");
var clazz = classFiles.get("PatternMatching");
var instance = clazz.getDeclaredConstructor().newInstance();
}
@Test
public void testPatternMatchingZipJava() throws Exception {
ConsoleInterface.logLevel = Logger.LogLevel.DEBUG;
var classFiles = generateClassFiles(createClassLoader(), false, "PatternMatchingJava.jav", "PatternMatchingJava2.jav");
var clazz = classFiles.get("PatternMatchingJava");
var instance = clazz.getDeclaredConstructor().newInstance();
@@ -1388,6 +1390,7 @@ public class TestComplete {
}
@Test
@Disabled("too slow")
public void testBug325() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Bug325.jav");
var clazz = classFiles.get("Bug325");
@@ -1536,6 +1539,13 @@ public class TestComplete {
// TODO This logs output that we should validate
}
@Test
public void testBug389() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), false, "Bug389.jav", "Bug389Main.jav");
var clazz = classFiles.get("Bug389Main");
clazz.getDeclaredMethod("main", List.class).invoke(null, List.of());
}
@Test
public void testBug390() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Bug390.jav");