Compare commits

...

9 Commits

Author SHA1 Message Date
pl@gohorb.ba-horb.de 76f2048797 new file: resources/AllgemeinTest/Kombinatoren_After.jav
SonarQube Scan / SonarQube Trigger (push) Failing after 1m28s
new file:   resources/AllgemeinTest/Kombinatoren_After_Lazy.jav
	modified:   resources/AllgemeinTest/Kombinatoren_Or.jav
	renamed:    resources/AllgemeinTest/Kombinatoren.jav -> resources/AllgemeinTest/Kombinatoren_Satisfy.jav
	new file:   resources/AllgemeinTest/Kombinatoren_Trans.jav
	modified:   resources/AllgemeinTest/Kombinatoren_failure.jav
	new file:   resources/AllgemeinTest/Pair.java
	new file:   resources/AllgemeinTest/Parser.jav
	modified:   src/test/java/AllgemeinTest.java
2026-05-18 18:50:40 +02:00
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 1m51s
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
27 changed files with 607 additions and 44 deletions
@@ -0,0 +1,19 @@
import java.util.stream.Stream;
import Pair;
import java.util.function.Function;
public class Kombinatoren_After {
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()))))); } );
}
}
@@ -0,0 +1,17 @@
import java.util.stream.Stream;
import Pair;
import java.util.function.Function;
public class Kombinatoren_After_Lazy {
afterP (fst, snd) {
return toks -> {
return fst.apply(toks).flatMap(p1 ->
snd.apply(p1.snd()).map(p2 ->
new Pair<>(new Pair<>(p1.fst(), p2.fst()), p2.snd())));
};
}
}
@@ -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,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_Satisfy {
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,13 @@
import java.util.stream.Stream;
import Pair;
//import java.util.function.Function;
public class Kombinatoren_Trans {
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,73 @@
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.util.List;
import java.util.ArrayList;
import java.io.PrintStream;
import java.lang.System;
import java.util.Optional;
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();});
}
parser(p, inp) {
return p.map(y -> y.apply(
inp.chars().mapToObj(c -> (char) c)
.collect(Collectors.toList())))
.flatMap(x -> x)
.filter(x -> x.snd().isEmpty())
.findFirst()
.get()
.fst();
}
}
/*
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))
)
;
}
}
}
);
*/
}
}
*/
+27
View File
@@ -0,0 +1,27 @@
import java.util.*;
public class Pair<T, U> {
T a;
U b;
public Pair() { }
public Pair(T a, U b) {
System.out.println("Pair a; " + a + " b: " + b);
this.a = a;
this.b = b;
}
public T fst () {
return a;
}
public U snd () {
System.out.println("snd b: " + b);
return b;
}
public String toString() {
return "Pair<"+a.toString()+","+b.toString()+">";
}
}
+82
View File
@@ -0,0 +1,82 @@
import java.util.stream.Stream;
//import java.util.stream.IntStream;
//import java.util.List;
import java.util.ArrayList;
import java.io.PrintStream;
import java.lang.System;
import java.util.Optional;
import java.lang.Character;
import java.lang.String;
import java.lang.Boolean;
import java.lang.Integer;
import java.util.function.Function;
import java.util.function.Predicate;
//import java.util.function.IntFunction;
import Pair;
public class Parser {
strToList(s) {
var al;
al = new ArrayList<>();
var i = 0;
while (i < s.length()) {
al.add(s.charAt(i));
i=i+1;
}
return al;
}
/*
parser(p, inp) {
return p.map(y -> y.apply(
strToList(inp)//chars().mapToObj(c -> (Character) c)
//.toList()
))
//.flatMap(x -> x)
//.filter(x -> x.snd().isEmpty())
;
/*
.findFirst()
.get()
.fst()
;
}
*/
}
/*
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 {} import Cons;
import Empty;
public record Cons<T>(T a, List<T> l) implements List<T> {} import List;
public record Empty<T>() implements List<T> {} import Pair;
public record Tuple<T1, T2>(T1 a, T2 b) {}
public class PatternMatching { public class PatternMatching {
public zip(Cons(x, xs), Cons(y, ys)) { 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(Empty x, Cons y) { return new Empty(); }
public zip(Cons x, Empty y) { return new Empty(); } public zip(Cons x, Empty y) { return new Empty(); }
@@ -2,18 +2,24 @@ import java.lang.Object;
import List; import List;
import Cons; import Cons;
import Empty; import Empty;
import Tuple; import Pair;
public class PatternMatchingJava { public class PatternMatchingJava {
public zip(a, b) { public <A, B> Cons<Pair<A, B>> zip(Cons<A> a, Cons<B> b) {
switch (a) { switch (a) {
case Cons(x, Cons xs) -> { case Cons(x, Cons xs) -> {
switch (b) { switch (b) {
case Cons(y, Cons ys) -> { return new Cons<>(new Tuple<>(x, y), zip(xs, ys)); } case Cons(y, Cons ys) -> { return new Cons<>(new Pair<>(x, y), zip(xs, ys)); }
case Cons(y, Empty()) -> { return new Empty<>(); } };
}
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 Cons<T>(T a, List<T> l) implements List<T> {}
public record Empty<T>() 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.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface; import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Pattern;
import de.dhbwstuttgart.target.generate.ASTToTargetAST; import de.dhbwstuttgart.target.generate.ASTToTargetAST;
import de.dhbwstuttgart.target.tree.*; import de.dhbwstuttgart.target.tree.*;
import de.dhbwstuttgart.target.tree.expression.*; import de.dhbwstuttgart.target.tree.expression.*;
@@ -700,7 +700,7 @@ public class StatementGenerator {
case ConditionalassignexpressionContext condassign: case ConditionalassignexpressionContext condassign:
return convert(condassign); return convert(condassign);
default: default:
throw new NotImplementedException(); throw new NotImplementedException(expression.getClass().toString());
} }
} }
@@ -64,6 +64,8 @@ public class TypeGenerator {
switch (typeContext.primitiveType().getText()) { switch (typeContext.primitiveType().getText()) {
case "boolean": case "boolean":
return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), typeContext.getStart()); return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), typeContext.getStart());
case "char":
return new RefType(ASTFactory.createClass(Character.class).getClassName(), typeContext.getStart());
case "int": case "int":
return new RefType(ASTFactory.createClass(Integer.class).getClassName(), typeContext.getStart()); return new RefType(ASTFactory.createClass(Integer.class).getClassName(), typeContext.getStart());
case "double": case "double":
@@ -71,7 +73,7 @@ public class TypeGenerator {
case "float": case "float":
return new RefType(ASTFactory.createClass(Float.class).getClassName(), typeContext.getStart()); return new RefType(ASTFactory.createClass(Float.class).getClassName(), typeContext.getStart());
default: default:
throw new NotImplementedException(); throw new NotImplementedException(typeContext.primitiveType().getText());
} }
} else if (!typeContext.LBRACK().isEmpty()) { // ArrayType über eckige Klammer prüfen } else if (!typeContext.LBRACK().isEmpty()) { // ArrayType über eckige Klammer prüfen
// JavaTXParser.logger.info(unannTypeContext.getText()); // 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) { public static Method createMethod(java.lang.reflect.Method jreMethod, String signature, java.lang.Class inClass, Boolean isInherited, Boolean isImplemented) {
String name = jreMethod.getName(); String name = jreMethod.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType; RefTypeOrTPHOrWildcardOrGeneric returnType;
if (inClass.getName().equals("Swap")){
System.out.println();
}
Type jreRetType; Type jreRetType;
if (jreMethod.getGenericReturnType() != null) { if (jreMethod.getGenericReturnType() != null) {
jreRetType = jreMethod.getGenericReturnType(); jreRetType = jreMethod.getGenericReturnType();
@@ -28,6 +28,7 @@ public class MethodCall extends Statement
//sind Tphs, repraesentieren im Resultset die Signatur der aufgerufenen Methoden, letztes Element ist der Returntyp //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){ RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<TypePlaceholder> signature, Token offset){
@@ -65,6 +65,10 @@ public class ASTToTargetAST {
public Generics(JavaTXCompiler compiler, ResultSet set) { public Generics(JavaTXCompiler compiler, ResultSet set) {
this(new JavaGenerics(compiler, set), new TxGenerics(compiler, 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; public IByteArrayClassLoader classLoader;
@@ -94,10 +98,15 @@ public class ASTToTargetAST {
tphsInMethods.put(currentMethod, set); 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) { public static Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList, IGenerics generics, JavaTXCompiler compiler) {
Optional<Method> method = Optional.empty(); Optional<Method> method = Optional.empty();
while (method.isEmpty()) { 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; if (owner.getClassName().toString().equals("java.lang.Object")) break;
owner = compiler.getClass(owner.getSuperClass().getName()); owner = compiler.getClass(owner.getSuperClass().getName());
} }
@@ -105,16 +114,16 @@ public class ASTToTargetAST {
} }
Optional<Constructor> findConstructor(ClassOrInterface owner, List<TargetType> argumentList, IGenerics generics) { 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) { static boolean parameterEquals(List<TargetType> pars, List<TargetType> arguments) {
var pars = parameterList.getFormalparalist();
if (pars.size() != arguments.size()) if (pars.size() != arguments.size())
return false; return false;
for (var i = 0; i < pars.size(); i++) { 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); var type2 = arguments.get(i);
if (type1 instanceof TargetGenericType) if (type1 instanceof TargetGenericType)
return true; 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); 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) { 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) { public List<MethodParameter> convert(ParameterList input, IGenerics generics) {
@@ -701,6 +716,7 @@ public class ASTToTargetAST {
var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method); var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method);
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType); 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)); var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), generics.txGenerics, compiler));
signatures.add(new Signature(javaSignature, txSignature, generics)); signatures.add(new Signature(javaSignature, txSignature, generics));
@@ -754,7 +770,7 @@ public class ASTToTargetAST {
for (var i = 0; i < tspec.params().size(); i++) { for (var i = 0; i < tspec.params().size(); i++) {
var param = tspec.params().get(i); var param = tspec.params().get(i);
if (param instanceof TargetSpecializedType fn) { if (param instanceof TargetSpecializedType fn) {
collectArguments(tspec, newParams); collectArguments(fn, newParams);
} else { } else {
newParams.add(param); newParams.add(param);
} }
@@ -216,6 +216,10 @@ public class StatementToTargetExpression implements ASTVisitor {
return ASTToTargetAST.findMethod(converter.compiler.getClass(className), name, args, generics, compiler); 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 @Override
public void visit(MethodCall methodCall) { public void visit(MethodCall methodCall) {
var receiverType = converter.convert(methodCall.receiver.getType(), generics); var receiverType = converter.convert(methodCall.receiver.getType(), generics);
@@ -246,7 +250,7 @@ public class StatementToTargetExpression implements ASTVisitor {
} else if (!isFunNType) { } else if (!isFunNType) {
receiverClass = converter.compiler.getClass(receiverName); receiverClass = converter.compiler.getClass(receiverName);
if (receiverClass == null) throw new DebugException("Class " + receiverName + " does not exist!"); 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) { if (!isFunNType) {
@@ -736,12 +736,12 @@ public class TYPEStmt implements StatementVisitor {
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) { for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
// Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params) // 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) // 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; return ret;
} }
@@ -755,7 +755,7 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType(); UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType(); 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.empty();
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair())); 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 lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType(); 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.empty();
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair())); 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 fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
var retType = fiArgs.getFirst(); var retType = fiArgs.getFirst();
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType); var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType); //FALSCHRUM????
var lhsRet = lhsArgs.getFirst(); var lhsRet = lhsArgs.getFirst();
Set<UnifyPair> result = new HashSet<>(); Set<UnifyPair> result = new HashSet<>();
@@ -972,16 +972,66 @@ public class RuleSet implements IRuleSet{
} }
@Override @Override
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) { public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc) {
if(pair.getPairOp() != PairOperator.SMALLERDOT) if(pair.getPairOp() != PairOperator.SMALLERDOT)
return Optional.empty(); return Optional.empty();
UnifyType lhsType = pair.getLhsType(); UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType(); UnifyType rhsType = pair.getRhsType();
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType)) if(!(rhsType instanceof FunNType))
return Optional.empty(); 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; FunNType funNRhsType = (FunNType) rhsType;
Set<UnifyPair> result = new HashSet<UnifyPair>(); Set<UnifyPair> result = new HashSet<UnifyPair>();
@@ -1018,6 +1068,121 @@ public class RuleSet implements IRuleSet{
return Optional.of(result); 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 @Override
public Optional<UnifyPair> reduceTph(UnifyPair pair) { public Optional<UnifyPair> reduceTph(UnifyPair pair) {
if(pair.getPairOp() != PairOperator.SMALLERDOTWC) if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
@@ -1025,7 +1190,7 @@ public class RuleSet implements IRuleSet{
UnifyType lhsType = pair.getLhsType(); UnifyType lhsType = pair.getLhsType();
UnifyType rhsType = pair.getRhsType(); 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.empty();
return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair())); 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 // FunN Rules
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair); optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair, fc); 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 // One of the rules has been applied
if (optSet.isPresent()) { if (optSet.isPresent()) {
@@ -61,7 +61,9 @@ public interface IRuleSet {
*/ */
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair); public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair);
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair, IFiniteClosure fc); 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. * Checks whether the erase1-Rule applies to the pair.
@@ -685,6 +685,7 @@ public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-1
return Optional.empty(); return Optional.empty();
} }
@Override @Override
public Set<UnifyType> getAncestors(UnifyType t) { public Set<UnifyType> getAncestors(UnifyType t) {
if (!inheritanceGraph.containsKey(t)) if (!inheritanceGraph.containsKey(t))
+8 -2
View File
@@ -14,7 +14,9 @@ import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import de.dhbwstuttgart.core.ConsoleInterface;
import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.util.Logger.LogLevel;
public class AllgemeinTest { public class AllgemeinTest {
@@ -29,6 +31,7 @@ public class AllgemeinTest {
@Test @Test
public void test() throws Exception { public void test() throws Exception {
ConsoleInterface.logLevel = LogLevel.DEBUG;
//String className = "GenTest"; //String className = "GenTest";
//String className = "Overloading_Generics"; //String className = "Overloading_Generics";
//String className = "Generics"; //String className = "Generics";
@@ -63,11 +66,14 @@ public class AllgemeinTest {
//String className = "Cycle"; //String className = "Cycle";
//String className = "TripleTest"; //String className = "TripleTest";
//String className = "WildcardList"; //String className = "WildcardList";
String className = "List"; //String className = "List";
//String className = "Box"; //String className = "Box";
//String className = "GenBox"; //String className = "GenBox";
//String className = "InnerInf"; //String className = "InnerInf";
//String className = "Foo"; //String className = "Foo";
String className = "Kombinatoren_failure";
//String className = "Parser";
//PL 2019-10-24: genutzt fuer unterschiedliche Tests //PL 2019-10-24: genutzt fuer unterschiedliche Tests
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav"; path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav"; //path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
@@ -76,7 +82,7 @@ public class AllgemeinTest {
///* ///*
compiler = new JavaTXCompiler( compiler = new JavaTXCompiler(
Lists.newArrayList(new File(path)), 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); new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/"), true);
//*/ //*/
compiler.generateBytecode(); compiler.generateBytecode();
+12 -2
View File
@@ -1,6 +1,8 @@
import de.dhbwstuttgart.core.ConsoleInterface; import de.dhbwstuttgart.core.ConsoleInterface;
import de.dhbwstuttgart.util.Logger; import de.dhbwstuttgart.util.Logger;
import de.dhbwstuttgart.util.Logger.LogLevel;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -959,14 +961,14 @@ public class TestComplete {
@Test @Test
public void testPatternMatchingZip() throws Exception { 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 clazz = classFiles.get("PatternMatching");
var instance = clazz.getDeclaredConstructor().newInstance(); var instance = clazz.getDeclaredConstructor().newInstance();
} }
@Test @Test
public void testPatternMatchingZipJava() throws Exception { public void testPatternMatchingZipJava() throws Exception {
ConsoleInterface.logLevel = Logger.LogLevel.DEBUG;
var classFiles = generateClassFiles(createClassLoader(), false, "PatternMatchingJava.jav", "PatternMatchingJava2.jav"); var classFiles = generateClassFiles(createClassLoader(), false, "PatternMatchingJava.jav", "PatternMatchingJava2.jav");
var clazz = classFiles.get("PatternMatchingJava"); var clazz = classFiles.get("PatternMatchingJava");
var instance = clazz.getDeclaredConstructor().newInstance(); var instance = clazz.getDeclaredConstructor().newInstance();
@@ -1388,6 +1390,7 @@ public class TestComplete {
} }
@Test @Test
@Disabled("too slow")
public void testBug325() throws Exception { public void testBug325() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Bug325.jav"); var classFiles = generateClassFiles(createClassLoader(), "Bug325.jav");
var clazz = classFiles.get("Bug325"); var clazz = classFiles.get("Bug325");
@@ -1536,6 +1539,13 @@ public class TestComplete {
// TODO This logs output that we should validate // 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 @Test
public void testBug390() throws Exception { public void testBug390() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Bug390.jav"); var classFiles = generateClassFiles(createClassLoader(), "Bug390.jav");