diff --git a/pom.xml b/pom.xml
index c03d39ab..f347874a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,7 +54,12 @@ http://maven.apache.org/maven-v4_0_0.xsd">
3.11.0
--enable-preview
+<<<<<<< HEAD
+
+ 20
+=======
20
+>>>>>>> patternMatching
@@ -122,6 +127,11 @@ http://maven.apache.org/maven-v4_0_0.xsd">
+<<<<<<< HEAD
+ 20
+ 20
+=======
+>>>>>>> patternMatching
de.dhbwstuttgart.core.ConsoleInterface
diff --git a/resources/AllgemeinTest/Iteration.jav b/resources/AllgemeinTest/Iteration.jav
index 29b201f5..c0b9dd65 100644
--- a/resources/AllgemeinTest/Iteration.jav
+++ b/resources/AllgemeinTest/Iteration.jav
@@ -20,18 +20,24 @@ class Pair {
public class Iteration {
+ id(x) {
+ return x;
+ }
+
m1(x, y) {
var help;
help = m2(x, y);
var y2 = help.snd();
- return new Pair<>(x,y2);
-
+ var x2 = id(x);
+ return new Pair<>(x2,y2);
+
}
m2(x,y) {
var help = m1(x, y);
var x2 = help.fst();
- return new Pair<>(x2, y);
+ var y2 = id(y);
+ return new Pair<>(x2, y2);
}
}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/AA.jav b/resources/bytecode/javFiles/AA.jav
similarity index 100%
rename from src/test/resources/javFiles/AA.jav
rename to resources/bytecode/javFiles/AA.jav
diff --git a/src/test/resources/javFiles/AddLong.jav b/resources/bytecode/javFiles/AddLong.jav
similarity index 100%
rename from src/test/resources/javFiles/AddLong.jav
rename to resources/bytecode/javFiles/AddLong.jav
diff --git a/src/test/resources/javFiles/AssignToLit.jav b/resources/bytecode/javFiles/AssignToLit.jav
similarity index 100%
rename from src/test/resources/javFiles/AssignToLit.jav
rename to resources/bytecode/javFiles/AssignToLit.jav
diff --git a/src/test/resources/javFiles/BB.jav b/resources/bytecode/javFiles/BB.jav
similarity index 100%
rename from src/test/resources/javFiles/BB.jav
rename to resources/bytecode/javFiles/BB.jav
diff --git a/src/test/resources/javFiles/BinaryInMeth.jav b/resources/bytecode/javFiles/BinaryInMeth.jav
similarity index 100%
rename from src/test/resources/javFiles/BinaryInMeth.jav
rename to resources/bytecode/javFiles/BinaryInMeth.jav
diff --git a/src/test/resources/javFiles/Box.jav b/resources/bytecode/javFiles/Box.jav
similarity index 100%
rename from src/test/resources/javFiles/Box.jav
rename to resources/bytecode/javFiles/Box.jav
diff --git a/src/test/resources/javFiles/Box.java b/resources/bytecode/javFiles/Box.java
similarity index 100%
rename from src/test/resources/javFiles/Box.java
rename to resources/bytecode/javFiles/Box.java
diff --git a/src/test/resources/javFiles/CC.jav b/resources/bytecode/javFiles/CC.jav
similarity index 100%
rename from src/test/resources/javFiles/CC.jav
rename to resources/bytecode/javFiles/CC.jav
diff --git a/src/test/resources/javFiles/ClassGenLam.jav b/resources/bytecode/javFiles/ClassGenLam.jav
similarity index 100%
rename from src/test/resources/javFiles/ClassGenLam.jav
rename to resources/bytecode/javFiles/ClassGenLam.jav
diff --git a/resources/bytecode/javFiles/Cycle.class b/resources/bytecode/javFiles/Cycle.class
new file mode 100644
index 00000000..a7650d8b
Binary files /dev/null and b/resources/bytecode/javFiles/Cycle.class differ
diff --git a/src/test/resources/javFiles/Cycle.jav b/resources/bytecode/javFiles/Cycle.jav
similarity index 100%
rename from src/test/resources/javFiles/Cycle.jav
rename to resources/bytecode/javFiles/Cycle.jav
diff --git a/src/test/resources/javFiles/DD.jav b/resources/bytecode/javFiles/DD.jav
similarity index 100%
rename from src/test/resources/javFiles/DD.jav
rename to resources/bytecode/javFiles/DD.jav
diff --git a/src/test/resources/javFiles/DuMethod.jav b/resources/bytecode/javFiles/DuMethod.jav
similarity index 100%
rename from src/test/resources/javFiles/DuMethod.jav
rename to resources/bytecode/javFiles/DuMethod.jav
diff --git a/src/test/resources/javFiles/EmptyClass.jav b/resources/bytecode/javFiles/EmptyClass.jav
similarity index 100%
rename from src/test/resources/javFiles/EmptyClass.jav
rename to resources/bytecode/javFiles/EmptyClass.jav
diff --git a/src/test/resources/javFiles/EmptyMethod.jav b/resources/bytecode/javFiles/EmptyMethod.jav
similarity index 100%
rename from src/test/resources/javFiles/EmptyMethod.jav
rename to resources/bytecode/javFiles/EmptyMethod.jav
diff --git a/src/test/resources/javFiles/Example.jav b/resources/bytecode/javFiles/Example.jav
similarity index 100%
rename from src/test/resources/javFiles/Example.jav
rename to resources/bytecode/javFiles/Example.jav
diff --git a/src/test/resources/javFiles/Exceptions.jav b/resources/bytecode/javFiles/Exceptions.jav
similarity index 100%
rename from src/test/resources/javFiles/Exceptions.jav
rename to resources/bytecode/javFiles/Exceptions.jav
diff --git a/src/test/resources/javFiles/Expressions.jav b/resources/bytecode/javFiles/Expressions.jav
similarity index 100%
rename from src/test/resources/javFiles/Expressions.jav
rename to resources/bytecode/javFiles/Expressions.jav
diff --git a/src/test/resources/javFiles/FC_Matrix.jav b/resources/bytecode/javFiles/FC_Matrix.jav
similarity index 100%
rename from src/test/resources/javFiles/FC_Matrix.jav
rename to resources/bytecode/javFiles/FC_Matrix.jav
diff --git a/src/test/resources/javFiles/Fac.jav b/resources/bytecode/javFiles/Fac.jav
similarity index 100%
rename from src/test/resources/javFiles/Fac.jav
rename to resources/bytecode/javFiles/Fac.jav
diff --git a/src/test/resources/javFiles/Faculty.jav b/resources/bytecode/javFiles/Faculty.jav
similarity index 100%
rename from src/test/resources/javFiles/Faculty.jav
rename to resources/bytecode/javFiles/Faculty.jav
diff --git a/src/test/resources/javFiles/Faculty2.jav b/resources/bytecode/javFiles/Faculty2.jav
similarity index 100%
rename from src/test/resources/javFiles/Faculty2.jav
rename to resources/bytecode/javFiles/Faculty2.jav
diff --git a/src/test/resources/javFiles/FacultyIf.jav b/resources/bytecode/javFiles/FacultyIf.jav
similarity index 100%
rename from src/test/resources/javFiles/FacultyIf.jav
rename to resources/bytecode/javFiles/FacultyIf.jav
diff --git a/src/test/resources/javFiles/FacultyTyped.jav b/resources/bytecode/javFiles/FacultyTyped.jav
similarity index 100%
rename from src/test/resources/javFiles/FacultyTyped.jav
rename to resources/bytecode/javFiles/FacultyTyped.jav
diff --git a/src/test/resources/javFiles/Field.jav b/resources/bytecode/javFiles/Field.jav
similarity index 100%
rename from src/test/resources/javFiles/Field.jav
rename to resources/bytecode/javFiles/Field.jav
diff --git a/src/test/resources/javFiles/FieldAccess.jav b/resources/bytecode/javFiles/FieldAccess.jav
similarity index 100%
rename from src/test/resources/javFiles/FieldAccess.jav
rename to resources/bytecode/javFiles/FieldAccess.jav
diff --git a/src/test/resources/javFiles/FieldTph.jav b/resources/bytecode/javFiles/FieldTph.jav
similarity index 100%
rename from src/test/resources/javFiles/FieldTph.jav
rename to resources/bytecode/javFiles/FieldTph.jav
diff --git a/src/test/resources/javFiles/FieldTph2.jav b/resources/bytecode/javFiles/FieldTph2.jav
similarity index 100%
rename from src/test/resources/javFiles/FieldTph2.jav
rename to resources/bytecode/javFiles/FieldTph2.jav
diff --git a/src/test/resources/javFiles/FieldTphConsMeth.jav b/resources/bytecode/javFiles/FieldTphConsMeth.jav
similarity index 100%
rename from src/test/resources/javFiles/FieldTphConsMeth.jav
rename to resources/bytecode/javFiles/FieldTphConsMeth.jav
diff --git a/src/test/resources/javFiles/FieldTphMMeth.jav b/resources/bytecode/javFiles/FieldTphMMeth.jav
similarity index 100%
rename from src/test/resources/javFiles/FieldTphMMeth.jav
rename to resources/bytecode/javFiles/FieldTphMMeth.jav
diff --git a/src/test/resources/javFiles/Fields.jav b/resources/bytecode/javFiles/Fields.jav
similarity index 100%
rename from src/test/resources/javFiles/Fields.jav
rename to resources/bytecode/javFiles/Fields.jav
diff --git a/src/test/resources/javFiles/For.jav b/resources/bytecode/javFiles/For.jav
similarity index 100%
rename from src/test/resources/javFiles/For.jav
rename to resources/bytecode/javFiles/For.jav
diff --git a/src/test/resources/javFiles/FunOL.jav b/resources/bytecode/javFiles/FunOL.jav
similarity index 100%
rename from src/test/resources/javFiles/FunOL.jav
rename to resources/bytecode/javFiles/FunOL.jav
diff --git a/src/test/resources/javFiles/Gen.jav b/resources/bytecode/javFiles/Gen.jav
similarity index 100%
rename from src/test/resources/javFiles/Gen.jav
rename to resources/bytecode/javFiles/Gen.jav
diff --git a/src/test/resources/javFiles/Generics.jav b/resources/bytecode/javFiles/Generics.jav
similarity index 100%
rename from src/test/resources/javFiles/Generics.jav
rename to resources/bytecode/javFiles/Generics.jav
diff --git a/src/test/resources/javFiles/Generics2.jav b/resources/bytecode/javFiles/Generics2.jav
similarity index 100%
rename from src/test/resources/javFiles/Generics2.jav
rename to resources/bytecode/javFiles/Generics2.jav
diff --git a/src/test/resources/javFiles/Generics3.jav b/resources/bytecode/javFiles/Generics3.jav
similarity index 100%
rename from src/test/resources/javFiles/Generics3.jav
rename to resources/bytecode/javFiles/Generics3.jav
diff --git a/src/test/resources/javFiles/Generics4.jav b/resources/bytecode/javFiles/Generics4.jav
similarity index 100%
rename from src/test/resources/javFiles/Generics4.jav
rename to resources/bytecode/javFiles/Generics4.jav
diff --git a/src/test/resources/javFiles/GreaterEqual.jav b/resources/bytecode/javFiles/GreaterEqual.jav
similarity index 100%
rename from src/test/resources/javFiles/GreaterEqual.jav
rename to resources/bytecode/javFiles/GreaterEqual.jav
diff --git a/src/test/resources/javFiles/GreaterThan.jav b/resources/bytecode/javFiles/GreaterThan.jav
similarity index 100%
rename from src/test/resources/javFiles/GreaterThan.jav
rename to resources/bytecode/javFiles/GreaterThan.jav
diff --git a/src/test/resources/javFiles/Id.jav b/resources/bytecode/javFiles/Id.jav
similarity index 100%
rename from src/test/resources/javFiles/Id.jav
rename to resources/bytecode/javFiles/Id.jav
diff --git a/src/test/resources/javFiles/IfTest.jav b/resources/bytecode/javFiles/IfTest.jav
similarity index 100%
rename from src/test/resources/javFiles/IfTest.jav
rename to resources/bytecode/javFiles/IfTest.jav
diff --git a/src/test/resources/javFiles/Import.jav b/resources/bytecode/javFiles/Import.jav
similarity index 100%
rename from src/test/resources/javFiles/Import.jav
rename to resources/bytecode/javFiles/Import.jav
diff --git a/src/test/resources/javFiles/Inf.jav b/resources/bytecode/javFiles/Inf.jav
similarity index 100%
rename from src/test/resources/javFiles/Inf.jav
rename to resources/bytecode/javFiles/Inf.jav
diff --git a/src/test/resources/javFiles/Infimum.jav b/resources/bytecode/javFiles/Infimum.jav
similarity index 100%
rename from src/test/resources/javFiles/Infimum.jav
rename to resources/bytecode/javFiles/Infimum.jav
diff --git a/src/test/resources/javFiles/Inherit.jav b/resources/bytecode/javFiles/Inherit.jav
similarity index 100%
rename from src/test/resources/javFiles/Inherit.jav
rename to resources/bytecode/javFiles/Inherit.jav
diff --git a/src/test/resources/javFiles/Inherit2.jav b/resources/bytecode/javFiles/Inherit2.jav
similarity index 100%
rename from src/test/resources/javFiles/Inherit2.jav
rename to resources/bytecode/javFiles/Inherit2.jav
diff --git a/src/test/resources/javFiles/Interface1.jav b/resources/bytecode/javFiles/Interface1.jav
similarity index 100%
rename from src/test/resources/javFiles/Interface1.jav
rename to resources/bytecode/javFiles/Interface1.jav
diff --git a/src/test/resources/javFiles/KompTph.jav b/resources/bytecode/javFiles/KompTph.jav
similarity index 100%
rename from src/test/resources/javFiles/KompTph.jav
rename to resources/bytecode/javFiles/KompTph.jav
diff --git a/src/test/resources/javFiles/LamRunnable.jav b/resources/bytecode/javFiles/LamRunnable.jav
similarity index 100%
rename from src/test/resources/javFiles/LamRunnable.jav
rename to resources/bytecode/javFiles/LamRunnable.jav
diff --git a/src/test/resources/javFiles/Lambda.jav b/resources/bytecode/javFiles/Lambda.jav
similarity index 100%
rename from src/test/resources/javFiles/Lambda.jav
rename to resources/bytecode/javFiles/Lambda.jav
diff --git a/src/test/resources/javFiles/Lambda2.jav b/resources/bytecode/javFiles/Lambda2.jav
similarity index 100%
rename from src/test/resources/javFiles/Lambda2.jav
rename to resources/bytecode/javFiles/Lambda2.jav
diff --git a/src/test/resources/javFiles/Lambda3.jav b/resources/bytecode/javFiles/Lambda3.jav
similarity index 100%
rename from src/test/resources/javFiles/Lambda3.jav
rename to resources/bytecode/javFiles/Lambda3.jav
diff --git a/src/test/resources/javFiles/Lambda4.jav b/resources/bytecode/javFiles/Lambda4.jav
similarity index 100%
rename from src/test/resources/javFiles/Lambda4.jav
rename to resources/bytecode/javFiles/Lambda4.jav
diff --git a/src/test/resources/javFiles/LambdaCapture.jav b/resources/bytecode/javFiles/LambdaCapture.jav
similarity index 100%
rename from src/test/resources/javFiles/LambdaCapture.jav
rename to resources/bytecode/javFiles/LambdaCapture.jav
diff --git a/src/test/resources/javFiles/LambdaField.jav b/resources/bytecode/javFiles/LambdaField.jav
similarity index 100%
rename from src/test/resources/javFiles/LambdaField.jav
rename to resources/bytecode/javFiles/LambdaField.jav
diff --git a/src/test/resources/javFiles/LambdaRunnable.jav b/resources/bytecode/javFiles/LambdaRunnable.jav
similarity index 100%
rename from src/test/resources/javFiles/LambdaRunnable.jav
rename to resources/bytecode/javFiles/LambdaRunnable.jav
diff --git a/src/test/resources/javFiles/LambdaVoid.jav b/resources/bytecode/javFiles/LambdaVoid.jav
similarity index 100%
rename from src/test/resources/javFiles/LambdaVoid.jav
rename to resources/bytecode/javFiles/LambdaVoid.jav
diff --git a/src/test/resources/javFiles/LessEqual.jav b/resources/bytecode/javFiles/LessEqual.jav
similarity index 100%
rename from src/test/resources/javFiles/LessEqual.jav
rename to resources/bytecode/javFiles/LessEqual.jav
diff --git a/src/test/resources/javFiles/LessThan.jav b/resources/bytecode/javFiles/LessThan.jav
similarity index 100%
rename from src/test/resources/javFiles/LessThan.jav
rename to resources/bytecode/javFiles/LessThan.jav
diff --git a/src/test/resources/javFiles/ListenerOverload.jav b/resources/bytecode/javFiles/ListenerOverload.jav
similarity index 100%
rename from src/test/resources/javFiles/ListenerOverload.jav
rename to resources/bytecode/javFiles/ListenerOverload.jav
diff --git a/src/test/resources/javFiles/Matrix.jav b/resources/bytecode/javFiles/Matrix.jav
similarity index 100%
rename from src/test/resources/javFiles/Matrix.jav
rename to resources/bytecode/javFiles/Matrix.jav
diff --git a/src/test/resources/javFiles/MatrixOP.jav b/resources/bytecode/javFiles/MatrixOP.jav
similarity index 100%
rename from src/test/resources/javFiles/MatrixOP.jav
rename to resources/bytecode/javFiles/MatrixOP.jav
diff --git a/src/test/resources/javFiles/Merge.jav b/resources/bytecode/javFiles/Merge.jav
similarity index 100%
rename from src/test/resources/javFiles/Merge.jav
rename to resources/bytecode/javFiles/Merge.jav
diff --git a/src/test/resources/javFiles/Meth_Gen.jav b/resources/bytecode/javFiles/Meth_Gen.jav
similarity index 100%
rename from src/test/resources/javFiles/Meth_Gen.jav
rename to resources/bytecode/javFiles/Meth_Gen.jav
diff --git a/src/test/resources/javFiles/MethodCallGenerics.jav b/resources/bytecode/javFiles/MethodCallGenerics.jav
similarity index 100%
rename from src/test/resources/javFiles/MethodCallGenerics.jav
rename to resources/bytecode/javFiles/MethodCallGenerics.jav
diff --git a/src/test/resources/javFiles/MethodWildcardGen.jav b/resources/bytecode/javFiles/MethodWildcardGen.jav
similarity index 100%
rename from src/test/resources/javFiles/MethodWildcardGen.jav
rename to resources/bytecode/javFiles/MethodWildcardGen.jav
diff --git a/src/test/resources/javFiles/Methods.jav b/resources/bytecode/javFiles/Methods.jav
similarity index 100%
rename from src/test/resources/javFiles/Methods.jav
rename to resources/bytecode/javFiles/Methods.jav
diff --git a/src/test/resources/javFiles/MethodsEasy.jav b/resources/bytecode/javFiles/MethodsEasy.jav
similarity index 100%
rename from src/test/resources/javFiles/MethodsEasy.jav
rename to resources/bytecode/javFiles/MethodsEasy.jav
diff --git a/src/test/resources/javFiles/OL.jav b/resources/bytecode/javFiles/OL.jav
similarity index 88%
rename from src/test/resources/javFiles/OL.jav
rename to resources/bytecode/javFiles/OL.jav
index 8f80e8cc..afeaa2f5 100644
--- a/src/test/resources/javFiles/OL.jav
+++ b/resources/bytecode/javFiles/OL.jav
@@ -1,4 +1,3 @@
-import java.lang.Integer;
import java.lang.Double;
import java.lang.String;
import java.lang.Long;
diff --git a/src/test/resources/javFiles/OLFun.jav b/resources/bytecode/javFiles/OLFun.jav
similarity index 100%
rename from src/test/resources/javFiles/OLFun.jav
rename to resources/bytecode/javFiles/OLFun.jav
diff --git a/src/test/resources/javFiles/OLFun2.jav b/resources/bytecode/javFiles/OLFun2.jav
similarity index 100%
rename from src/test/resources/javFiles/OLFun2.jav
rename to resources/bytecode/javFiles/OLFun2.jav
diff --git a/src/test/resources/javFiles/Op.jav b/resources/bytecode/javFiles/Op.jav
similarity index 100%
rename from src/test/resources/javFiles/Op.jav
rename to resources/bytecode/javFiles/Op.jav
diff --git a/src/test/resources/javFiles/Op1.jav b/resources/bytecode/javFiles/Op1.jav
similarity index 100%
rename from src/test/resources/javFiles/Op1.jav
rename to resources/bytecode/javFiles/Op1.jav
diff --git a/src/test/resources/javFiles/Op2.jav b/resources/bytecode/javFiles/Op2.jav
similarity index 100%
rename from src/test/resources/javFiles/Op2.jav
rename to resources/bytecode/javFiles/Op2.jav
diff --git a/src/test/resources/javFiles/OverlaodGen.jav b/resources/bytecode/javFiles/OverlaodGen.jav
similarity index 100%
rename from src/test/resources/javFiles/OverlaodGen.jav
rename to resources/bytecode/javFiles/OverlaodGen.jav
diff --git a/src/test/resources/javFiles/Overloading.jav b/resources/bytecode/javFiles/Overloading.jav
similarity index 100%
rename from src/test/resources/javFiles/Overloading.jav
rename to resources/bytecode/javFiles/Overloading.jav
diff --git a/src/test/resources/javFiles/Package.jav b/resources/bytecode/javFiles/Package.jav
similarity index 100%
rename from src/test/resources/javFiles/Package.jav
rename to resources/bytecode/javFiles/Package.jav
diff --git a/src/test/resources/javFiles/Pair.jav b/resources/bytecode/javFiles/Pair.jav
similarity index 100%
rename from src/test/resources/javFiles/Pair.jav
rename to resources/bytecode/javFiles/Pair.jav
diff --git a/src/test/resources/javFiles/Plus.jav b/resources/bytecode/javFiles/Plus.jav
similarity index 100%
rename from src/test/resources/javFiles/Plus.jav
rename to resources/bytecode/javFiles/Plus.jav
diff --git a/src/test/resources/javFiles/PostIncDec.jav b/resources/bytecode/javFiles/PostIncDec.jav
similarity index 100%
rename from src/test/resources/javFiles/PostIncDec.jav
rename to resources/bytecode/javFiles/PostIncDec.jav
diff --git a/src/test/resources/javFiles/PreInc.jav b/resources/bytecode/javFiles/PreInc.jav
similarity index 100%
rename from src/test/resources/javFiles/PreInc.jav
rename to resources/bytecode/javFiles/PreInc.jav
diff --git a/src/test/resources/javFiles/Put.jav b/resources/bytecode/javFiles/Put.jav
similarity index 100%
rename from src/test/resources/javFiles/Put.jav
rename to resources/bytecode/javFiles/Put.jav
diff --git a/src/test/resources/javFiles/RecursiveMeth.jav b/resources/bytecode/javFiles/RecursiveMeth.jav
similarity index 100%
rename from src/test/resources/javFiles/RecursiveMeth.jav
rename to resources/bytecode/javFiles/RecursiveMeth.jav
diff --git a/src/test/resources/javFiles/RelOps.jav b/resources/bytecode/javFiles/RelOps.jav
similarity index 100%
rename from src/test/resources/javFiles/RelOps.jav
rename to resources/bytecode/javFiles/RelOps.jav
diff --git a/src/test/resources/javFiles/ReturnMethod.jav b/resources/bytecode/javFiles/ReturnMethod.jav
similarity index 100%
rename from src/test/resources/javFiles/ReturnMethod.jav
rename to resources/bytecode/javFiles/ReturnMethod.jav
diff --git a/src/test/resources/javFiles/Scalar.jav b/resources/bytecode/javFiles/Scalar.jav
similarity index 100%
rename from src/test/resources/javFiles/Scalar.jav
rename to resources/bytecode/javFiles/Scalar.jav
diff --git a/src/test/resources/javFiles/SimpleCycle.jav b/resources/bytecode/javFiles/SimpleCycle.jav
similarity index 100%
rename from src/test/resources/javFiles/SimpleCycle.jav
rename to resources/bytecode/javFiles/SimpleCycle.jav
diff --git a/src/test/resources/javFiles/Sorting.jav b/resources/bytecode/javFiles/Sorting.jav
similarity index 100%
rename from src/test/resources/javFiles/Sorting.jav
rename to resources/bytecode/javFiles/Sorting.jav
diff --git a/src/test/resources/javFiles/StaticM.jav b/resources/bytecode/javFiles/StaticM.jav
similarity index 100%
rename from src/test/resources/javFiles/StaticM.jav
rename to resources/bytecode/javFiles/StaticM.jav
diff --git a/src/test/resources/javFiles/SubMatrix.jav b/resources/bytecode/javFiles/SubMatrix.jav
similarity index 100%
rename from src/test/resources/javFiles/SubMatrix.jav
rename to resources/bytecode/javFiles/SubMatrix.jav
diff --git a/src/test/resources/javFiles/Subclass.jav b/resources/bytecode/javFiles/Subclass.jav
similarity index 100%
rename from src/test/resources/javFiles/Subclass.jav
rename to resources/bytecode/javFiles/Subclass.jav
diff --git a/src/test/resources/javFiles/Superclass.jav b/resources/bytecode/javFiles/Superclass.jav
similarity index 100%
rename from src/test/resources/javFiles/Superclass.jav
rename to resources/bytecode/javFiles/Superclass.jav
diff --git a/src/test/resources/javFiles/TXGenerics.jav b/resources/bytecode/javFiles/TXGenerics.jav
similarity index 100%
rename from src/test/resources/javFiles/TXGenerics.jav
rename to resources/bytecode/javFiles/TXGenerics.jav
diff --git a/src/test/resources/javFiles/Tph.jav b/resources/bytecode/javFiles/Tph.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph.jav
rename to resources/bytecode/javFiles/Tph.jav
diff --git a/src/test/resources/javFiles/Tph2.jav b/resources/bytecode/javFiles/Tph2.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph2.jav
rename to resources/bytecode/javFiles/Tph2.jav
diff --git a/src/test/resources/javFiles/Tph3.jav b/resources/bytecode/javFiles/Tph3.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph3.jav
rename to resources/bytecode/javFiles/Tph3.jav
diff --git a/src/test/resources/javFiles/Tph4.jav b/resources/bytecode/javFiles/Tph4.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph4.jav
rename to resources/bytecode/javFiles/Tph4.jav
diff --git a/src/test/resources/javFiles/Tph5.jav b/resources/bytecode/javFiles/Tph5.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph5.jav
rename to resources/bytecode/javFiles/Tph5.jav
diff --git a/src/test/resources/javFiles/Tph6.jav b/resources/bytecode/javFiles/Tph6.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph6.jav
rename to resources/bytecode/javFiles/Tph6.jav
diff --git a/src/test/resources/javFiles/Tph7.jav b/resources/bytecode/javFiles/Tph7.jav
similarity index 100%
rename from src/test/resources/javFiles/Tph7.jav
rename to resources/bytecode/javFiles/Tph7.jav
diff --git a/src/test/resources/javFiles/TypedID.jav b/resources/bytecode/javFiles/TypedID.jav
similarity index 100%
rename from src/test/resources/javFiles/TypedID.jav
rename to resources/bytecode/javFiles/TypedID.jav
diff --git a/src/test/resources/javFiles/Vector.jav b/resources/bytecode/javFiles/Vector.jav
similarity index 100%
rename from src/test/resources/javFiles/Vector.jav
rename to resources/bytecode/javFiles/Vector.jav
diff --git a/src/test/resources/javFiles/VectorAdd.jav b/resources/bytecode/javFiles/VectorAdd.jav
similarity index 100%
rename from src/test/resources/javFiles/VectorAdd.jav
rename to resources/bytecode/javFiles/VectorAdd.jav
diff --git a/src/test/resources/javFiles/VectorSuper.jav b/resources/bytecode/javFiles/VectorSuper.jav
similarity index 100%
rename from src/test/resources/javFiles/VectorSuper.jav
rename to resources/bytecode/javFiles/VectorSuper.jav
diff --git a/src/test/resources/javFiles/VoidMeth.jav b/resources/bytecode/javFiles/VoidMeth.jav
similarity index 100%
rename from src/test/resources/javFiles/VoidMeth.jav
rename to resources/bytecode/javFiles/VoidMeth.jav
diff --git a/src/test/resources/javFiles/WC.jav b/resources/bytecode/javFiles/WC.jav
similarity index 100%
rename from src/test/resources/javFiles/WC.jav
rename to resources/bytecode/javFiles/WC.jav
diff --git a/src/test/resources/javFiles/While.jav b/resources/bytecode/javFiles/While.jav
similarity index 100%
rename from src/test/resources/javFiles/While.jav
rename to resources/bytecode/javFiles/While.jav
diff --git a/src/test/resources/javFiles/Y.jav b/resources/bytecode/javFiles/Y.jav
similarity index 100%
rename from src/test/resources/javFiles/Y.jav
rename to resources/bytecode/javFiles/Y.jav
diff --git a/src/test/resources/javFiles/applyLambda.jav b/resources/bytecode/javFiles/applyLambda.jav
similarity index 100%
rename from src/test/resources/javFiles/applyLambda.jav
rename to resources/bytecode/javFiles/applyLambda.jav
diff --git a/src/test/resources/javFiles/fc.jav b/resources/bytecode/javFiles/fc.jav
similarity index 100%
rename from src/test/resources/javFiles/fc.jav
rename to resources/bytecode/javFiles/fc.jav
diff --git a/src/test/resources/javFiles/mathStruc.jav b/resources/bytecode/javFiles/mathStruc.jav
similarity index 100%
rename from src/test/resources/javFiles/mathStruc.jav
rename to resources/bytecode/javFiles/mathStruc.jav
diff --git a/src/test/resources/javFiles/mathStrucInteger.jav b/resources/bytecode/javFiles/mathStrucInteger.jav
similarity index 100%
rename from src/test/resources/javFiles/mathStrucInteger.jav
rename to resources/bytecode/javFiles/mathStrucInteger.jav
diff --git a/src/test/resources/javFiles/mathStrucMatrixOP.jav b/resources/bytecode/javFiles/mathStrucMatrixOP.jav
similarity index 100%
rename from src/test/resources/javFiles/mathStrucMatrixOP.jav
rename to resources/bytecode/javFiles/mathStrucMatrixOP.jav
diff --git a/src/test/resources/javFiles/test.jav b/resources/bytecode/javFiles/test.jav
similarity index 100%
rename from src/test/resources/javFiles/test.jav
rename to resources/bytecode/javFiles/test.jav
diff --git a/src/test/resources/javFiles/test1.jav b/resources/bytecode/javFiles/test1.jav
similarity index 100%
rename from src/test/resources/javFiles/test1.jav
rename to resources/bytecode/javFiles/test1.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestAny.jav b/resources/insertGenerics/javFiles/TestAny.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestAny.jav
rename to resources/insertGenerics/javFiles/TestAny.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestAssign.jav b/resources/insertGenerics/javFiles/TestAssign.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestAssign.jav
rename to resources/insertGenerics/javFiles/TestAssign.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestClassField.jav b/resources/insertGenerics/javFiles/TestClassField.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestClassField.jav
rename to resources/insertGenerics/javFiles/TestClassField.jav
diff --git a/resources/insertGenerics/javFiles/TestContraVariant.jav b/resources/insertGenerics/javFiles/TestContraVariant.jav
new file mode 100644
index 00000000..9c060f0d
--- /dev/null
+++ b/resources/insertGenerics/javFiles/TestContraVariant.jav
@@ -0,0 +1,38 @@
+public class TestContraVariant {
+ main(x, y) {
+ var y2 = m(x, y);
+ var y3 = y2.snd();
+ var z;
+ y3 = z;
+ return new Pair<>(x, z);
+ }
+
+ m(x, y) {
+ var x2 = main(x, y);
+ var x3 = x2.fst();
+ var z;
+ x3 = z;
+ return new Pair<>(z, y);
+ }
+}
+
+class Pair {
+ public T x;
+ public U y;
+
+ public Pair() {
+ }
+
+ public Pair(T var1, U var2) {
+ x = var1;
+ y = var2;
+ }
+
+ public T fst() {
+ return x;
+ }
+
+ public U snd() {
+ return y;
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestGGFinder.jav b/resources/insertGenerics/javFiles/TestGGFinder.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestGGFinder.jav
rename to resources/insertGenerics/javFiles/TestGGFinder.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestLocalVarLambda.jav b/resources/insertGenerics/javFiles/TestLocalVarLambda.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestLocalVarLambda.jav
rename to resources/insertGenerics/javFiles/TestLocalVarLambda.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestMutualRecursion.jav b/resources/insertGenerics/javFiles/TestMutualRecursion.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestMutualRecursion.jav
rename to resources/insertGenerics/javFiles/TestMutualRecursion.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestMutualRecursionWithField.jav b/resources/insertGenerics/javFiles/TestMutualRecursionWithField.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestMutualRecursionWithField.jav
rename to resources/insertGenerics/javFiles/TestMutualRecursionWithField.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestMutualRecursionWithField2.jav b/resources/insertGenerics/javFiles/TestMutualRecursionWithField2.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestMutualRecursionWithField2.jav
rename to resources/insertGenerics/javFiles/TestMutualRecursionWithField2.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestMutualRecursionWithField3.jav b/resources/insertGenerics/javFiles/TestMutualRecursionWithField3.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestMutualRecursionWithField3.jav
rename to resources/insertGenerics/javFiles/TestMutualRecursionWithField3.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestReturnVar.jav b/resources/insertGenerics/javFiles/TestReturnVar.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestReturnVar.jav
rename to resources/insertGenerics/javFiles/TestReturnVar.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestSecondLineOfClassConstraints.jav b/resources/insertGenerics/javFiles/TestSecondLineOfClassConstraints.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestSecondLineOfClassConstraints.jav
rename to resources/insertGenerics/javFiles/TestSecondLineOfClassConstraints.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestTPHsAndGenerics.jav b/resources/insertGenerics/javFiles/TestTPHsAndGenerics.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestTPHsAndGenerics.jav
rename to resources/insertGenerics/javFiles/TestTPHsAndGenerics.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestTPHsAndGenerics2.jav b/resources/insertGenerics/javFiles/TestTPHsAndGenerics2.jav
similarity index 98%
rename from src/test/resources/javFiles/insertGenericsJav/TestTPHsAndGenerics2.jav
rename to resources/insertGenerics/javFiles/TestTPHsAndGenerics2.jav
index 9cdc21f7..2a75e829 100644
--- a/src/test/resources/javFiles/insertGenericsJav/TestTPHsAndGenerics2.jav
+++ b/resources/insertGenerics/javFiles/TestTPHsAndGenerics2.jav
@@ -10,4 +10,5 @@ class TPHsAndGenerics2 {
m2(a, b){
return b;
}
+
}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestThreeArgs.jav b/resources/insertGenerics/javFiles/TestThreeArgs.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestThreeArgs.jav
rename to resources/insertGenerics/javFiles/TestThreeArgs.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestTwoArgs.jav b/resources/insertGenerics/javFiles/TestTwoArgs.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestTwoArgs.jav
rename to resources/insertGenerics/javFiles/TestTwoArgs.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestTwoArgs2.jav b/resources/insertGenerics/javFiles/TestTwoArgs2.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestTwoArgs2.jav
rename to resources/insertGenerics/javFiles/TestTwoArgs2.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestTwoCalls.jav b/resources/insertGenerics/javFiles/TestTwoCalls.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestTwoCalls.jav
rename to resources/insertGenerics/javFiles/TestTwoCalls.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestVector.jav b/resources/insertGenerics/javFiles/TestVector.jav
similarity index 69%
rename from src/test/resources/javFiles/insertGenericsJav/TestVector.jav
rename to resources/insertGenerics/javFiles/TestVector.jav
index 1519afb7..76c06ff9 100644
--- a/src/test/resources/javFiles/insertGenericsJav/TestVector.jav
+++ b/resources/insertGenerics/javFiles/TestVector.jav
@@ -3,7 +3,7 @@ import java.util.Vector;
public class TestVector {
m(v, w) {
- w.addElement(id(v.elementAt(0)));
+ w.addElement(id(v.elementAt(0)));
}
id(x) {
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestVectorArg.jav b/resources/insertGenerics/javFiles/TestVectorArg.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestVectorArg.jav
rename to resources/insertGenerics/javFiles/TestVectorArg.jav
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestVoidMeth.jav b/resources/insertGenerics/javFiles/TestVoidMeth.jav
similarity index 100%
rename from src/test/resources/javFiles/insertGenericsJav/TestVoidMeth.jav
rename to resources/insertGenerics/javFiles/TestVoidMeth.jav
diff --git a/resources/packageTest/Gen.jav b/resources/packageTest/Gen.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/OLMain.jav b/resources/packageTest/OLMain.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/OLOneFile.jav b/resources/packageTest/OLOneFile.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/OLTest.txt b/resources/packageTest/OLTest.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/OLextends.jav b/resources/packageTest/OLextends.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/Pair2.jav b/resources/packageTest/Pair2.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/Test.jav b/resources/packageTest/Test.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/UseOLMain.java b/resources/packageTest/UseOLMain.java
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/ImportTest.jav b/resources/packageTest/de/test/ImportTest.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/ImportTest2.jav b/resources/packageTest/de/test/ImportTest2.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/ImportTestDefault.jav b/resources/packageTest/de/test/ImportTestDefault.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/OL.jav b/resources/packageTest/de/test/OL.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/Pair.jav b/resources/packageTest/de/test/Pair.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/TestClass.jav b/resources/packageTest/de/test/TestClass.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/ToImport.jav b/resources/packageTest/de/test/ToImport.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/mathStruc.jav b/resources/packageTest/de/test/mathStruc.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/mathStrucVector.jav b/resources/packageTest/de/test/mathStrucVector.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/output/de/test/mathStrucVectoruse.java b/resources/packageTest/de/test/output/de/test/mathStrucVectoruse.java
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/output/mathStrucVectoruse.java b/resources/packageTest/de/test/output/mathStrucVectoruse.java
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/packageNameTestWrongPackage.jav b/resources/packageTest/de/test/packageNameTestWrongPackage.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/subpackage1/Test1.jav b/resources/packageTest/de/test/subpackage1/Test1.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/subpackage1/ToImport2.jav b/resources/packageTest/de/test/subpackage1/ToImport2.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/subpackage2/Test2.jav b/resources/packageTest/de/test/subpackage2/Test2.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/subpackage2/ToImport3.jav b/resources/packageTest/de/test/subpackage2/ToImport3.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/packageTest/de/test/vectorAdd.jav b/resources/packageTest/de/test/vectorAdd.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/src/test/resources/syntaxtreegenerator/BinaryInMeth.ast b/resources/syntaxtreegenerator/BinaryInMeth.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/BinaryInMeth.ast
rename to resources/syntaxtreegenerator/BinaryInMeth.ast
diff --git a/src/test/resources/syntaxtreegenerator/Box.ast b/resources/syntaxtreegenerator/Box.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Box.ast
rename to resources/syntaxtreegenerator/Box.ast
diff --git a/src/test/resources/syntaxtreegenerator/ClassGenLam.ast b/resources/syntaxtreegenerator/ClassGenLam.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/ClassGenLam.ast
rename to resources/syntaxtreegenerator/ClassGenLam.ast
diff --git a/src/test/resources/syntaxtreegenerator/Cycle.ast b/resources/syntaxtreegenerator/Cycle.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Cycle.ast
rename to resources/syntaxtreegenerator/Cycle.ast
diff --git a/src/test/resources/syntaxtreegenerator/Fac.ast b/resources/syntaxtreegenerator/Fac.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Fac.ast
rename to resources/syntaxtreegenerator/Fac.ast
diff --git a/src/test/resources/syntaxtreegenerator/Faculty.ast b/resources/syntaxtreegenerator/Faculty.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Faculty.ast
rename to resources/syntaxtreegenerator/Faculty.ast
diff --git a/src/test/resources/syntaxtreegenerator/Field.ast b/resources/syntaxtreegenerator/Field.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Field.ast
rename to resources/syntaxtreegenerator/Field.ast
diff --git a/src/test/resources/syntaxtreegenerator/FieldTph2.ast b/resources/syntaxtreegenerator/FieldTph2.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/FieldTph2.ast
rename to resources/syntaxtreegenerator/FieldTph2.ast
diff --git a/src/test/resources/syntaxtreegenerator/FieldTphConsMeth.ast b/resources/syntaxtreegenerator/FieldTphConsMeth.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/FieldTphConsMeth.ast
rename to resources/syntaxtreegenerator/FieldTphConsMeth.ast
diff --git a/src/test/resources/syntaxtreegenerator/FieldTphMMeth.ast b/resources/syntaxtreegenerator/FieldTphMMeth.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/FieldTphMMeth.ast
rename to resources/syntaxtreegenerator/FieldTphMMeth.ast
diff --git a/src/test/resources/syntaxtreegenerator/Gen.ast b/resources/syntaxtreegenerator/Gen.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Gen.ast
rename to resources/syntaxtreegenerator/Gen.ast
diff --git a/src/test/resources/syntaxtreegenerator/Id.ast b/resources/syntaxtreegenerator/Id.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Id.ast
rename to resources/syntaxtreegenerator/Id.ast
diff --git a/src/test/resources/syntaxtreegenerator/Inf.ast b/resources/syntaxtreegenerator/Inf.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Inf.ast
rename to resources/syntaxtreegenerator/Inf.ast
diff --git a/src/test/resources/syntaxtreegenerator/KompTph.ast b/resources/syntaxtreegenerator/KompTph.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/KompTph.ast
rename to resources/syntaxtreegenerator/KompTph.ast
diff --git a/src/test/resources/syntaxtreegenerator/Lambda.ast b/resources/syntaxtreegenerator/Lambda.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Lambda.ast
rename to resources/syntaxtreegenerator/Lambda.ast
diff --git a/src/test/resources/syntaxtreegenerator/LambdaCapture.ast b/resources/syntaxtreegenerator/LambdaCapture.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/LambdaCapture.ast
rename to resources/syntaxtreegenerator/LambdaCapture.ast
diff --git a/src/test/resources/syntaxtreegenerator/Matrix.ast b/resources/syntaxtreegenerator/Matrix.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Matrix.ast
rename to resources/syntaxtreegenerator/Matrix.ast
diff --git a/src/test/resources/syntaxtreegenerator/MatrixOP.ast b/resources/syntaxtreegenerator/MatrixOP.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/MatrixOP.ast
rename to resources/syntaxtreegenerator/MatrixOP.ast
diff --git a/src/test/resources/syntaxtreegenerator/Merge.ast b/resources/syntaxtreegenerator/Merge.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Merge.ast
rename to resources/syntaxtreegenerator/Merge.ast
diff --git a/src/test/resources/syntaxtreegenerator/OL.ast b/resources/syntaxtreegenerator/OL.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/OL.ast
rename to resources/syntaxtreegenerator/OL.ast
diff --git a/src/test/resources/syntaxtreegenerator/OLFun.ast b/resources/syntaxtreegenerator/OLFun.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/OLFun.ast
rename to resources/syntaxtreegenerator/OLFun.ast
diff --git a/src/test/resources/syntaxtreegenerator/OLFun2.ast b/resources/syntaxtreegenerator/OLFun2.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/OLFun2.ast
rename to resources/syntaxtreegenerator/OLFun2.ast
diff --git a/src/test/resources/syntaxtreegenerator/Overloading.ast b/resources/syntaxtreegenerator/Overloading.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Overloading.ast
rename to resources/syntaxtreegenerator/Overloading.ast
diff --git a/src/test/resources/syntaxtreegenerator/Pair.ast b/resources/syntaxtreegenerator/Pair.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Pair.ast
rename to resources/syntaxtreegenerator/Pair.ast
diff --git a/src/test/resources/syntaxtreegenerator/Plus.ast b/resources/syntaxtreegenerator/Plus.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Plus.ast
rename to resources/syntaxtreegenerator/Plus.ast
diff --git a/src/test/resources/syntaxtreegenerator/RelOps.ast b/resources/syntaxtreegenerator/RelOps.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/RelOps.ast
rename to resources/syntaxtreegenerator/RelOps.ast
diff --git a/src/test/resources/syntaxtreegenerator/Scalar.ast b/resources/syntaxtreegenerator/Scalar.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Scalar.ast
rename to resources/syntaxtreegenerator/Scalar.ast
diff --git a/src/test/resources/syntaxtreegenerator/SimpleCycle.ast b/resources/syntaxtreegenerator/SimpleCycle.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/SimpleCycle.ast
rename to resources/syntaxtreegenerator/SimpleCycle.ast
diff --git a/src/test/resources/syntaxtreegenerator/Sorting.ast b/resources/syntaxtreegenerator/Sorting.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Sorting.ast
rename to resources/syntaxtreegenerator/Sorting.ast
diff --git a/src/test/resources/syntaxtreegenerator/SubMatrix.ast b/resources/syntaxtreegenerator/SubMatrix.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/SubMatrix.ast
rename to resources/syntaxtreegenerator/SubMatrix.ast
diff --git a/src/test/resources/syntaxtreegenerator/TXGenerics.ast b/resources/syntaxtreegenerator/TXGenerics.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/TXGenerics.ast
rename to resources/syntaxtreegenerator/TXGenerics.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph.ast b/resources/syntaxtreegenerator/Tph.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph.ast
rename to resources/syntaxtreegenerator/Tph.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph2.ast b/resources/syntaxtreegenerator/Tph2.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph2.ast
rename to resources/syntaxtreegenerator/Tph2.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph3.ast b/resources/syntaxtreegenerator/Tph3.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph3.ast
rename to resources/syntaxtreegenerator/Tph3.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph4.ast b/resources/syntaxtreegenerator/Tph4.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph4.ast
rename to resources/syntaxtreegenerator/Tph4.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph5.ast b/resources/syntaxtreegenerator/Tph5.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph5.ast
rename to resources/syntaxtreegenerator/Tph5.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph6.ast b/resources/syntaxtreegenerator/Tph6.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph6.ast
rename to resources/syntaxtreegenerator/Tph6.ast
diff --git a/src/test/resources/syntaxtreegenerator/Tph7.ast b/resources/syntaxtreegenerator/Tph7.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Tph7.ast
rename to resources/syntaxtreegenerator/Tph7.ast
diff --git a/src/test/resources/syntaxtreegenerator/TypedID.ast b/resources/syntaxtreegenerator/TypedID.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/TypedID.ast
rename to resources/syntaxtreegenerator/TypedID.ast
diff --git a/src/test/resources/syntaxtreegenerator/VectorAdd.ast b/resources/syntaxtreegenerator/VectorAdd.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/VectorAdd.ast
rename to resources/syntaxtreegenerator/VectorAdd.ast
diff --git a/src/test/resources/syntaxtreegenerator/VectorSuper.ast b/resources/syntaxtreegenerator/VectorSuper.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/VectorSuper.ast
rename to resources/syntaxtreegenerator/VectorSuper.ast
diff --git a/src/test/resources/syntaxtreegenerator/Y.ast b/resources/syntaxtreegenerator/Y.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/Y.ast
rename to resources/syntaxtreegenerator/Y.ast
diff --git a/src/test/resources/syntaxtreegenerator/applyLambda.ast b/resources/syntaxtreegenerator/applyLambda.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/applyLambda.ast
rename to resources/syntaxtreegenerator/applyLambda.ast
diff --git a/src/test/resources/syntaxtreegenerator/mathStruc.ast b/resources/syntaxtreegenerator/mathStruc.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/mathStruc.ast
rename to resources/syntaxtreegenerator/mathStruc.ast
diff --git a/src/test/resources/syntaxtreegenerator/mathStrucInteger.ast b/resources/syntaxtreegenerator/mathStrucInteger.ast
similarity index 100%
rename from src/test/resources/syntaxtreegenerator/mathStrucInteger.ast
rename to resources/syntaxtreegenerator/mathStrucInteger.ast
diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
index 29699d83..16837e50 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
@@ -782,6 +782,18 @@ public class Codegen {
break;
}
break;
+ case TargetVarDecl varDecl: {
+ var local = state.createVariable(varDecl.name(), varDecl.varType());
+ if (varDecl.value() != null) {
+ generate(state, varDecl.value());
+ boxPrimitive(state, varDecl.varType());
+ mv.visitVarInsn(ASTORE, local.index());
+ } else {
+ mv.visitInsn(ACONST_NULL);
+ mv.visitVarInsn(ASTORE, local.index());
+ }
+ break;
+ }
case TargetBinaryOp op:
generateBinaryOp(state, op);
break;
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java
index 00700542..36777e0f 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java
@@ -3,12 +3,10 @@ package de.dhbwstuttgart.target.generate;
import de.dhbwstuttgart.bytecode.FunNGenerator;
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
-import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.*;
-import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.target.tree.*;
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
import de.dhbwstuttgart.target.tree.expression.TargetExpression;
@@ -43,804 +41,6 @@ public class ASTToTargetAST {
record Generics(JavaGenerics javaGenerics, TxGenerics txGenerics) {
}
- final class TxGenerics extends GenerateGenerics {
- TxGenerics(ResultSet constraints) {
- super(constraints);
- }
-
- @Override
- void generics(ClassOrInterface owner, Method method, Set> result, HashSet referenced) {
- eliminateInfima(result, referenced);
- }
-
- @Override
- void generics(ClassOrInterface classOrInterface, Set> result, Set referenced) {
- eliminateInfima(result, referenced);
- eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced);
- }
- }
-
- final class JavaGenerics extends GenerateGenerics {
- JavaGenerics(ResultSet constraints) {
- super(constraints);
- }
-
- @Override
- void generics(ClassOrInterface owner, Method method, Set> result, HashSet referenced) {
- eliminateCycles(result, referenced);
- eliminateInfima(result, referenced);
- equalizeTypeVariables(result, referenced);
- }
-
- @Override
- void generics(ClassOrInterface classOrInterface, Set> result, Set referenced) {
- eliminateCycles(result, referenced);
- eliminateInfima(result, referenced);
- eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced);
- equalizeTypeVariables(result, referenced);
- }
- }
-
- abstract class GenerateGenerics {
- final Map>> computedGenericsOfMethods = new HashMap<>();
- final Map>> computedGenericsOfClasses = new HashMap<>();
-
- final Map> usedTPHsOfMethods = new HashMap<>();
- final Map>> familyOfMethods = new HashMap<>();
-
- final Set simplifiedConstraints = new HashSet<>();
- final Map concreteTypes = new HashMap<>();
- final Map equality = new HashMap<>();
-
- GenerateGenerics(ResultSet constraints) {
- for (var constraint : constraints.results) {
- if (constraint instanceof PairTPHsmallerTPH p) {
- simplifiedConstraints.add(p);
- } else if (constraint instanceof PairTPHEqualTPH p) {
- equality.put(p.getLeft(), p.getRight());
- } else if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) {
- concreteTypes.put(this.equality.getOrDefault(p.left, p.left), p.right);
- }
- }
-
- System.out.println("Simplified constraints: " + simplifiedConstraints);
- }
-
- Set findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type) {
- var result = new HashSet();
- if (type instanceof TypePlaceholder tph) {
- tph = equality.getOrDefault(tph, tph);
- if (concreteTypes.containsKey(tph)) {
- result.addAll(findTypeVariables(concreteTypes.get(tph)));
- return result;
- }
- result.add(tph);
- } else if (type instanceof RefType refType) {
- for (var t : refType.getParaList())
- result.addAll(findTypeVariables(t));
- } else if (type instanceof ExtendsWildcardType wildcardType) {
- result.addAll(findTypeVariables(wildcardType.getInnerType()));
- } else if (type instanceof SuperWildcardType wildcardType) {
- result.addAll(findTypeVariables(wildcardType.getInnerType()));
- }
- return result;
- }
-
- boolean containsRelation(Set> result, PairTPHsmallerTPH pair) {
- // Check if both the right and the left are already part of a relation
- var containsLeft = false;
- for (var pair2 : result) {
- if (pair2.getLeft().equals(pair.left)) {
- containsLeft = true;
- break;
- }
- }
- var containsRight = false;
- for (var pair2 : result) {
- if (pair2.getRight().equals(pair.right)) {
- containsRight = true;
- break;
- }
- }
- return containsLeft && containsRight;
- }
-
- void addToPairs(Set> input, ResultPair, ?> pair) {
- if (pair instanceof PairTPHsmallerTPH) {
- input.removeIf(pair2 -> {
- if (pair2 instanceof PairTPHequalRefTypeOrWildcardType) {
- return pair2.getLeft().equals(pair.getLeft()) && pair2.getRight().equals(OBJECT);
- }
- return false;
- });
- } else if (input.stream().anyMatch(p -> p.getLeft().equals(pair.getLeft()))) {
- return;
- }
-
- input.add(pair);
- }
-
- void addToEquality(TypePlaceholder from, TypePlaceholder to, Set referenced) {
- for (var entry : new HashSet<>(equality.entrySet())) {
- if (entry.getValue().equals(from)) {
- equality.remove(entry.getKey());
- equality.put(entry.getKey(), to);
- }
- }
- equality.put(from, to);
- referenced.remove(from);
- referenced.add(to);
- }
-
- static Set> transitiveClosure(Set> generics) {
- Set> all = new HashSet<>(generics);
- HashSet> toAdd = new HashSet<>();
- int sizeBefore;
- do {
- sizeBefore = all.size();
- toAdd.clear();
- for (var g1 : all) {
- for (var g2 : all) {
- if (g1 instanceof PairTPHsmallerTPH pair) {
- if (g2.getLeft().equals(pair.getRight()) && g2.getRight() instanceof TypePlaceholder right)
- toAdd.add(new PairTPHsmallerTPH(pair.left, right));
- }
- }
- }
- all.addAll(toAdd);
- } while (sizeBefore < all.size());
- return all;
- }
-
- private void methodFindConstraints(ClassOrInterface owner, Method method, Set typeVariables, Set typeVariablesOfClass, Set> result) {
- var userDefinedGenericsOfClass = userDefinedGenerics.get(owner);
-
- // Type variables with bounds that are also type variables of the method
- for (var typeVariable : new HashSet<>(typeVariables)) {
- typeVariable = equality.getOrDefault(typeVariable, typeVariable);
- if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
- continue;
- for (var pair : simplifiedConstraints) {
- var left = equality.getOrDefault(pair.left, pair.left);
- var right = equality.getOrDefault(pair.right, pair.right);
- if (left.equals(typeVariable) && typeVariables.contains(right)) {
- addToPairs(result, new PairTPHsmallerTPH(left, right));
- }
- }
- }
-
- method.block.accept(new TracingStatementVisitor() {
-
- private RefTypeOrTPHOrWildcardOrGeneric superType = new Void(new NullToken());
-
- @Override
- public void visit(MethodCall methodCall) {
- // Anfang es werden Paare von TPHs gespeichert, die bei den Generated Generics ueber die Methodengrenzen hinweg
- // betrachtet werden muessen
- // Definition 7.2 (Family of generated generics). T1 <. R1 <.^∗ R2 <. T2
- Set T1s = methodCall.getArgumentList().getArguments().stream().map(TypableStatement::getType).collect(Collectors.toCollection(HashSet::new)).stream().filter(x -> x instanceof TypePlaceholder).map(tph -> equality.getOrDefault(tph, (TypePlaceholder) tph)).collect(Collectors.toCollection(HashSet::new));
- RefTypeOrTPHOrWildcardOrGeneric T2 = superType;
- if (T2 instanceof TypePlaceholder tph)
- T2 = equality.getOrDefault(tph, tph);
-
- System.out.println("T1s: " + T1s + " T2: " + T2);
- // Ende
-
- superType = methodCall.receiverType;
- methodCall.receiver.accept(this);
- for (int i = 0; i < methodCall.arglist.getArguments().size(); i++) {
- superType = methodCall.signature.get(i);
- methodCall.arglist.getArguments().get(i).accept(this);
- }
-
- if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver) {
- if (expressionReceiver.expr instanceof This) {
- var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
- if (optMethod.isEmpty())
- return;
- var method = optMethod.get();
- var generics = generics(owner, method);
-
- // transitive and
- var all = transitiveClosure(generics);
- // reflexive
- var toAdd = new HashSet>();
- for (var generic : all) {
- toAdd.add(new PairTPHsmallerTPH((TypePlaceholder) generic.getLeft(), (TypePlaceholder) generic.getLeft()));
- }
- all.addAll(toAdd);
-
- HashSet newPairs = new HashSet<>();
-
- // Loop from hell
- outer: for (var R1 : typeVariables) {
- if (typeVariablesOfClass.contains(R1))
- continue;
- for (var generic : all)
- if (generic instanceof PairTPHsmallerTPH ptph) {
- var l = equality.getOrDefault(ptph.left, ptph.left);
- var r = equality.getOrDefault(ptph.right, ptph.right);
-
- for (var pair : simplifiedConstraints) {
- var l2 = equality.getOrDefault(pair.left, pair.left);
- var r2 = equality.getOrDefault(pair.right, pair.right);
- if (!(l2.equals(R1) && r2.equals(l)))
- continue;
-
- for (var R2 : typeVariables) {
- for (var pair2 : simplifiedConstraints) {
- var l3 = equality.getOrDefault(pair2.left, pair2.left);
- var r3 = equality.getOrDefault(pair2.right, pair2.right);
- if (!(r3.equals(R2) && l3.equals(r)))
- continue;
- if (R1.equals(R2))
- continue;
- if (!T1s.contains(R1) || !R2.equals(T2))
- continue;
-
- var newPair = new PairTPHsmallerTPH(R1, R2);
- newPairs.add(newPair);
-
- if (!containsRelation(result, newPair))
- addToPairs(result, newPair);
- continue outer;
- }
- }
- }
- }
- }
- simplifiedConstraints.addAll(newPairs);
- }
- }
- }
-
- @Override
- public void visit(LambdaExpression lambdaExpression) {
- superType = new Void(new NullToken());
- lambdaExpression.methodBody.accept(this);
- }
-
- @Override
- public void visit(Assign assign) {
- superType = assign.rightSide.getType();
- assign.rightSide.accept(this);
- }
-
- @Override
- public void visit(BinaryExpr binary) {
- superType = new Void(new NullToken());
- binary.lexpr.accept(this);
- superType = new Void(new NullToken());
- binary.rexpr.accept(this);
- }
-
- @Override
- public void visit(Block block) {
- for (var expr : block.statements) {
- superType = new Void(new NullToken());
- expr.accept(this);
- }
- }
-
- @Override
- public void visit(IfStmt ifStmt) {
- superType = new Void(new NullToken());
- ifStmt.expr.accept(this);
- superType = new Void(new NullToken());
- ifStmt.then_block.accept(this);
- superType = new Void(new NullToken());
- ifStmt.else_block.accept(this);
- }
-
- @Override
- public void visit(Return aReturn) {
- superType = aReturn.getType();
- aReturn.retexpr.accept(this);
- }
-
- @Override
- public void visit(WhileStmt whileStmt) {
- superType = new Void(new NullToken());
- whileStmt.expr.accept(this);
- superType = new Void(new NullToken());
- whileStmt.loopBlock.accept(this);
- }
-
- @Override
- public void visit(ArgumentList arglist) {
- for (int i = 0; i < arglist.getArguments().size(); i++) {
- superType = arglist.getArguments().get(i).getType();
- arglist.getArguments().get(i).accept(this);
- }
- }
- });
-
- var closure = transitiveClosure((Set) simplifiedConstraints);
- // Type variables with bounds that are also type variables of the class
- for (var typeVariable : new HashSet<>(typeVariables)) {
- typeVariable = equality.getOrDefault(typeVariable, typeVariable);
- if (typeVariablesOfClass.contains(typeVariable))
- continue;
-
- var pairs = new HashSet();
- for (var pair : closure) {
- if (!(pair instanceof PairTPHsmallerTPH ptph))
- continue;
- var left = equality.getOrDefault(ptph.left, ptph.left);
- var right = equality.getOrDefault(ptph.right, ptph.right);
- if (left.equals(typeVariable) && typeVariablesOfClass.contains(right)) {
- pairs.add(new PairTPHsmallerTPH(left, right));
- }
- }
-
- // Find the closest pair with the minimum amount of steps
- PairTPHsmallerTPH minimalPair = null;
- var minSteps = Integer.MAX_VALUE;
- for (var pair : pairs) {
- var left = pair.left;
- var visited = new HashSet();
- var steps = 0;
- while (!left.equals(pair.right)) {
- visited.add(left);
- var found = false;
- for (var pair2 : simplifiedConstraints) {
- if (left.equals(pair2.left) && !visited.contains(pair2.right)) {
- left = pair2.right;
- steps += 1;
- found = true;
- break;
- }
- }
- if (!found)
- break;
- }
- if (steps < minSteps) {
- minSteps = steps;
- minimalPair = pair;
- }
- }
-
- if (minimalPair != null)
- addToPairs(result, new PairTPHsmallerTPH(equality.getOrDefault(minimalPair.left, minimalPair.left), equality.getOrDefault(minimalPair.right, minimalPair.right)));
- }
-
- // All unbounded type variables (bounds not in method)
- outer: for (var typeVariable : typeVariables) {
- typeVariable = equality.getOrDefault(typeVariable, typeVariable);
- if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
- continue;
- for (var pair : result) {
- if (pair.getLeft().equals(typeVariable))
- continue outer;
- }
- addToPairs(result, new PairTPHequalRefTypeOrWildcardType(typeVariable, OBJECT));
- }
-
- // All unbounded bounds
- outer: for (var pair : simplifiedConstraints) {
- var r = equality.getOrDefault(pair.right, pair.right);
- for (var pair2 : simplifiedConstraints) {
- if (r.equals(equality.getOrDefault(pair2.left, pair2.left)))
- continue outer;
- }
- if (!classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, r) && typeVariables.contains(r)) {
- addToPairs(result, new PairTPHequalRefTypeOrWildcardType(r, OBJECT));
- }
- }
- }
-
- private boolean classHasGeneric(Set userDefinedGenericsOfClass, Set typeVariablesOfClass, TypePlaceholder typeVariable) {
- return typeVariablesOfClass.contains(typeVariable) || userDefinedGenericsOfClass.stream().anyMatch(g -> g.getName().equals(typeVariable.getName()));
- }
-
- private void methodFindTypeVariables(Method method, Set typeVariables) {
-
- if (!(method instanceof Constructor))
- typeVariables.addAll(findTypeVariables(method.getReturnType()));
- for (var arg : method.getParameterList().getFormalparalist()) {
- typeVariables.addAll(findTypeVariables(arg.getType()));
- }
-
- method.block.accept(new TracingStatementVisitor() {
- @Override
- public void visit(LocalVarDecl localVarDecl) {
- typeVariables.addAll(findTypeVariables(localVarDecl.getType()));
- }
-
- @Override
- public void visit(MethodCall methodCall) {
- super.visit(methodCall);
- typeVariables.addAll(findTypeVariables(methodCall.getType()));
- }
- });
- }
-
- abstract void generics(ClassOrInterface owner, Method method, Set> result, HashSet javaTypeVariablesOfClass);
-
- Set> family(ClassOrInterface owner, Method method) {
- if (familyOfMethods.containsKey(method))
- return familyOfMethods.get(method);
-
- var result = new HashSet>();
- familyOfMethods.put(method, result);
-
- var classGenerics = generics(owner);
- HashSet typeVariablesOfClass = new HashSet<>();
-
- for (var pair : classGenerics) {
- typeVariablesOfClass.add((TypePlaceholder) pair.getLeft());
- }
-
- HashSet javaTypeVariables = new HashSet<>();
-
- methodFindTypeVariables(method, javaTypeVariables);
- methodFindConstraints(owner, method, javaTypeVariables, typeVariablesOfClass, result);
- eliminateTransitives(result);
-
- return result;
- }
-
- Set> generics(ClassOrInterface owner, Method method) {
- // if (computedGenericsOfMethods.containsKey(method))
- // return computedGenericsOfMethods.get(method);
-
- var classGenerics = generics(owner);
-
- HashSet typeVariablesOfClass = new HashSet<>();
-
- for (var pair : classGenerics) {
- typeVariablesOfClass.add((TypePlaceholder) pair.getLeft());
- }
-
- var result = new HashSet<>(family(owner, method));
- computedGenericsOfMethods.put(method, result);
-
- var referenced = new HashSet();
-
- var usedTphs = new HashSet();
- // For eliminating inner type variables we need to figure out which ones are actually used
- for (var param : method.getParameterList().getFormalparalist()) {
- usedTphs.addAll(findTypeVariables(param.getType()));
- }
- usedTphs.addAll(findTypeVariables(method.getReturnType()));
- referenced.addAll(usedTphs);
- referenced.addAll(typeVariablesOfClass);
-
- generics(owner, method, result, referenced);
- usedTPHsOfMethods.put(method, usedTphs);
-
- eliminateInnerTypeVariables(referenced, result);
- addMissingObjectBounds(result, classGenerics, usedTphs);
-
- System.out.println(this.getClass().getSimpleName() + " " + method.name + ": " + result);
- return result;
- }
-
- private void eliminateChain(Set> result, List chain) {
- for (var pair : new HashSet<>(result)) {
- if (pair instanceof PairTPHsmallerTPH ptph && chain.get(chain.size() - 1).equals(ptph.left)) {
- if (chain.contains(ptph.right))
- return;
- var copy = new ArrayList<>(chain);
- copy.add(ptph.right);
- if (copy.size() > 2)
- result.remove(new PairTPHsmallerTPH(chain.get(0), ptph.right));
- eliminateChain(result, copy);
- }
- }
- }
-
- void eliminateTransitives(Set> result) {
- for (var pair : new HashSet<>(result))
- if (pair instanceof PairTPHsmallerTPH ptph) {
- var first = ptph.left;
- var chain = new ArrayList();
- chain.add(ptph.left);
- chain.add(ptph.right);
- eliminateChain(result, chain);
- }
- }
-
- void findAllBounds(RefTypeOrTPHOrWildcardOrGeneric type, Set> generics, Map equality) {
- if (type instanceof TypePlaceholder tph) {
- tph = equality.getOrDefault(tph, tph);
-
- var concreteType = concreteTypes.get(tph);
- if (concreteType != null) {
- findAllBounds(concreteType, generics, equality);
- return;
- }
-
- var found = false;
- for (var rsp : simplifiedConstraints) {
- var left = equality.getOrDefault(rsp.left, rsp.left);
- var right = equality.getOrDefault(rsp.right, rsp.right);
- if (left.equals(tph)) {
- var pair = new PairTPHsmallerTPH(tph, right);
- if (!generics.contains(pair)) {
- addToPairs(generics, pair);
- findAllBounds(right, generics, equality);
- found = true;
- }
- }
- }
- if (!found)
- addToPairs(generics, new PairTPHequalRefTypeOrWildcardType(tph, OBJECT));
- } else if (type instanceof RefType refType) {
- refType.getParaList().forEach(t -> findAllBounds(t, generics, equality));
- }
- }
-
- abstract void generics(ClassOrInterface classOrInterface, Set> result, Set referenced);
-
- Set> generics(ClassOrInterface classOrInterface) {
- if (computedGenericsOfClasses.containsKey(classOrInterface))
- return computedGenericsOfClasses.get(classOrInterface);
-
- Set> javaResult = new HashSet<>();
- computedGenericsOfClasses.put(classOrInterface, javaResult);
-
- for (var field : classOrInterface.getFieldDecl()) {
- findAllBounds(field.getType(), javaResult, equality);
- }
-
- var referenced = new HashSet();
- eliminateTransitives(javaResult);
- generics(classOrInterface, javaResult, referenced);
-
- var referencedByClass = new HashSet();
- for (var field : classOrInterface.getFieldDecl()) {
- findTphs(field.getType(), referencedByClass);
- }
-
- addMissingObjectBounds(javaResult, null, referencedByClass);
-
- System.out.println(this.getClass().getSimpleName() + " Class " + classOrInterface.getClassName().getClassName() + ": " + javaResult);
- return javaResult;
- }
-
- void addMissingObjectBounds(Set> result, Set> classGenerics, Set usedTphs) {
- outer: for (var tph : usedTphs) {
- tph = equality.getOrDefault(tph, tph);
- for (var p1 : new HashSet<>(result)) {
- if (p1.getLeft().equals(tph))
- continue outer;
- }
-
- TypePlaceholder finalTph = tph;
- if (classGenerics == null || classGenerics.stream().noneMatch((pair) -> pair.getLeft().equals(finalTph)))
- addToPairs(result, new PairTPHequalRefTypeOrWildcardType(tph, OBJECT));
- }
- }
-
- void equalizeTypeVariables(Set> input, Set referenced) {
- for (var pair : new HashSet<>(input)) {
- if (pair instanceof PairTPHsmallerTPH ptph && referenced.contains(ptph.left)) {
- var chain = new ArrayList();
- chain.add(ptph.left);
- chain.add(ptph.right);
-
- outer: while (true) {
- var added = false;
- for (var pair2 : input) {
- if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.left.equals(chain.get(chain.size() - 1))) {
- if (chain.contains(ptph2.right))
- break outer;
- chain.add(ptph2.right);
- added = true;
- }
- }
- if (!added)
- break;
- }
-
- var variance = chain.get(0).getVariance();
- if (variance != 1)
- continue;
- var index = 0;
- for (var tph : chain) {
- if (variance == 1 && tph.getVariance() == -1) {
- variance = -1;
- }
- if (variance == -1 && tph.getVariance() == 1 && referenced.contains(tph)) {
- break;
- }
- index++;
- }
- if (variance == 1)
- continue;
-
- var start = chain.get(0);
- var prev = start;
- for (var i = 1; i < index; i++) {
- var cur = chain.get(i);
- if (!referenced.contains(cur))
- continue;
- addToEquality(cur, start, referenced);
- input.remove(new PairTPHsmallerTPH(prev, cur));
- for (var pair2 : new HashSet<>(input)) {
- // TODO Maybe this would be unnecessary if we were to add the = constraints later on
- if (pair2 instanceof PairTPHequalRefTypeOrWildcardType && pair2.getLeft().equals(cur)) {
- input.remove(pair2);
- input.add(new PairTPHequalRefTypeOrWildcardType(start, pair2.getRight()));
- }
- }
- prev = chain.get(i);
- }
- }
- }
- }
-
- void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set tphs) {
- if (type instanceof RefType refType) {
- refType.getParaList().forEach(t -> findTphs(t, tphs));
- } else if (type instanceof TypePlaceholder tph) {
- tph = equality.getOrDefault(tph, tph);
- var concreteType = concreteTypes.get(tph);
- if (concreteType != null) {
- findTphs(concreteType, tphs);
- return;
- }
- tphs.add(tph);
- }
- }
-
- void eliminateInnerTypeVariablesOfClass(ClassOrInterface classOrInterface, Set> input, Set referenced) {
- for (var field : classOrInterface.getFieldDecl()) {
- findTphs(field.getType(), referenced);
- }
- for (var method : classOrInterface.getMethods()) {
- generics(classOrInterface, method);
- referenced.addAll(usedTPHsOfMethods.get(method));
- }
- eliminateInnerTypeVariables(referenced, input);
- }
-
- private void findChain(Set referenced, Set> input, Set> output, TypePlaceholder start, TypePlaceholder end, Set chain) {
- if (referenced.contains(end)) {
- var pair = new PairTPHsmallerTPH(start, end);
- output.add(pair);
- return;
- }
- var foundNext = false;
- for (var pair : input) {
- if (pair instanceof PairTPHsmallerTPH ptph && ptph.left.equals(end)) {
- if (chain.contains(ptph.right))
- return;
- chain = new HashSet<>(chain);
- chain.add(ptph.right);
- findChain(referenced, input, output, start, ptph.right, chain);
- foundNext = true;
- }
- }
- if (!foundNext) {
- output.add(new PairTPHequalRefTypeOrWildcardType(start, OBJECT));
- }
- }
-
- void eliminateInnerTypeVariables(Set referenced, Set> input) {
- var output = new HashSet>();
- for (var tph : referenced) {
- for (var pair : input) {
- if (pair instanceof PairTPHsmallerTPH pthp && pthp.left.equals(tph)) {
- var chain = new HashSet();
- chain.add(tph);
- findChain(referenced, input, output, tph, pthp.right, chain);
- }
- }
- }
- for (var pair : input) {
- if (pair instanceof PairTPHequalRefTypeOrWildcardType rtph) {
- if (referenced.contains(rtph.left))
- output.add(rtph);
- }
- }
-
- input.clear();
- input.addAll(output);
- }
-
- void eliminateCycles(Set> input, Set referenced) {
- var cycles = findCycles(input);
- for (var cycle : cycles) {
- var newTph = TypePlaceholder.fresh(new NullToken());
- var variance = cycle.get(0).getVariance();
- for (var tph : cycle) {
- if (tph.getVariance() != variance) {
- variance = 0;
- break;
- }
- }
- newTph.setVariance(variance);
-
- referenced.add(newTph);
- addToPairs(input, new PairTPHequalRefTypeOrWildcardType(newTph, OBJECT));
- cycle.add(cycle.get(0)); // Make it a complete cycle
- for (var i = 0; i < cycle.size() - 1; i++) {
- var left = cycle.get(i);
- var right = cycle.get(i + 1);
- var pair = new PairTPHsmallerTPH(left, right);
- input.remove(pair);
- addToEquality(left, newTph, referenced);
- }
- }
- }
-
- void eliminateInfima(Set> input, Set referenced) {
- var foundInfima = false;
- do {
- foundInfima = false;
- for (var constraint : new HashSet<>(input)) {
- var left = (TypePlaceholder) constraint.getLeft();
- Set infima = new HashSet<>();
- for (var pair : input) {
- if (pair instanceof PairTPHsmallerTPH stph)
- if (pair.getLeft().equals(constraint.getLeft()))
- infima.add(stph);
- }
- if (infima.size() > 1) {
- foundInfima = true;
- var newTph = TypePlaceholder.fresh(new NullToken());
- var variance = infima.stream().findFirst().get().right.getVariance();
- for (var pair : infima) {
- if (pair.right.getVariance() != variance) {
- variance = 0;
- break;
- }
- }
- newTph.setVariance(variance);
-
- // referenced.add(newTph);
- addToPairs(input, new PairTPHsmallerTPH(left, newTph));
- input.removeAll(infima);
- for (var infimum : infima) {
- addToEquality(infimum.right, newTph, referenced);
- new HashSet<>(input).forEach(pair -> {
- if (pair.getLeft().equals(infimum.right)) {
- input.remove(pair);
- if (pair instanceof PairTPHsmallerTPH stph) {
- if (!newTph.equals(stph.right))
- addToPairs(input, new PairTPHsmallerTPH(newTph, stph.right));
- } else if (pair instanceof PairTPHequalRefTypeOrWildcardType rtph) {
- addToPairs(input, new PairTPHequalRefTypeOrWildcardType(newTph, rtph.getRight()));
- }
- } else if (pair.getRight().equals(infimum.right)) {
- input.remove(pair);
- if (pair instanceof PairTPHsmallerTPH stph) {
- if (!newTph.equals(stph.left))
- addToPairs(input, new PairTPHsmallerTPH(stph.left, newTph));
- }
- }
- });
- }
- }
- }
- } while (foundInfima);
- }
-
- RefTypeOrTPHOrWildcardOrGeneric getType(RefTypeOrTPHOrWildcardOrGeneric type) {
- if (type instanceof TypePlaceholder tph) {
- if (equality.containsKey(tph)) {
- return getType(equality.get(tph));
- }
- return concreteTypes.getOrDefault(tph, tph);
- }
- return type;
- }
-
- TargetType getTargetType(RefTypeOrTPHOrWildcardOrGeneric in) {
- if (in instanceof TypePlaceholder tph) {
- if (equality.containsKey(tph)) {
- return getTargetType(equality.get(tph));
- }
- var type = concreteTypes.get(tph);
- if (type == null)
- return new TargetGenericType(tph.getName());
- return convert(type, this);
- }
- return convert(in, this);
- }
- }
protected IByteArrayClassLoader classLoader;
protected SourceFile sourceFile;
@@ -855,97 +55,11 @@ public class ASTToTargetAST {
all = new ArrayList<>();
for (var set : resultSets) {
- all.add(new Generics(new JavaGenerics(set), new TxGenerics(set)));
+ all.add(new Generics(new JavaGenerics(this, set), new TxGenerics(this, set)));
}
this.generics = all.get(0);
}
- static Set allNodes(Set> input) {
- return input.stream().filter(pair -> pair instanceof PairTPHsmallerTPH).flatMap(pair -> Stream.of((TypePlaceholder) pair.getLeft(), (TypePlaceholder) pair.getRight())).collect(Collectors.toSet());
- }
-
- static Set outgoingEdgesOf(TypePlaceholder tph, Set> input) {
- return input.stream().filter(pair -> pair instanceof PairTPHsmallerTPH && pair.getLeft().equals(tph)).map(pair -> (TypePlaceholder) pair.getRight()).collect(Collectors.toSet());
- }
-
- static boolean containsEdge(TypePlaceholder a, TypePlaceholder b, Set> input) {
- return input.stream().anyMatch(pair -> pair.getLeft().equals(a) && pair.getRight().equals(b));
- }
-
- // Tiernan simple cycles algorithm
- // Adapted from https://github.com/jgrapht/jgrapht/blob/master/jgrapht-core/src/main/java/org/jgrapht/alg/cycle/TiernanSimpleCycles.java
- static Set> findCycles(Set> input) {
- Map indices = new HashMap<>();
- List path = new ArrayList<>();
- Set pathSet = new HashSet<>();
- Map> blocked = new HashMap<>();
- Set> cycles = new HashSet<>();
-
- int index = 0;
- for (var tph : allNodes(input)) {
- blocked.put(tph, new HashSet<>());
- indices.put(tph, index++);
- }
-
- var vertexIterator = allNodes(input).iterator();
- if (!vertexIterator.hasNext())
- return cycles;
-
- TypePlaceholder startOfPath = null;
- TypePlaceholder endOfPath = vertexIterator.next();
- TypePlaceholder temp = null;
- int endIndex = 0;
- boolean extensionFound = false;
- path.add(endOfPath);
- pathSet.add(endOfPath);
-
- while (true) {
- do {
- extensionFound = false;
- for (TypePlaceholder n : outgoingEdgesOf(endOfPath, input)) {
- int cmp = indices.get(n).compareTo(indices.get(path.get(0)));
- if ((cmp > 0) && !pathSet.contains(n) && !blocked.get(endOfPath).contains(n)) {
- path.add(n);
- pathSet.add(n);
- endOfPath = n;
- extensionFound = true;
- break;
- }
- }
- } while (extensionFound);
-
- startOfPath = path.get(0);
- if (containsEdge(endOfPath, startOfPath, input)) {
- List cycle = new ArrayList<>(path);
- cycles.add(cycle);
- }
- if (path.size() > 1) {
- blocked.get(endOfPath).clear();
- endIndex = path.size() - 1;
- path.remove(endIndex);
- pathSet.remove(endOfPath);
- --endIndex;
- temp = endOfPath;
- endOfPath = path.get(endIndex);
- blocked.get(endOfPath).add(temp);
- continue;
- }
- if (vertexIterator.hasNext()) {
- path.clear();
- pathSet.clear();
- endOfPath = vertexIterator.next();
- path.add(endOfPath);
- pathSet.add(endOfPath);
- for (TypePlaceholder tph : blocked.keySet()) {
- blocked.get(tph).clear();
- }
- continue;
- }
- break;
- }
- return cycles;
- }
-
Optional findMethod(ClassOrInterface owner, String name, ArgumentList argumentList) {
return owner.getMethods().stream().filter(m -> m.name.equals(name) && parameterEquals(m.getParameterList(), argumentList)).findFirst();
}
@@ -968,12 +82,12 @@ public class ASTToTargetAST {
return true;
}
- Set convert(Set> result, GenerateGenerics generics) {
+ Set convert(Set result, GenerateGenerics generics) {
return result.stream().map(p -> {
- if (p instanceof PairTPHsmallerTPH pair) {
- return new TargetGeneric(pair.left.getName(), convert(pair.right, generics));
- } else if (p instanceof PairTPHequalRefTypeOrWildcardType pair) {
- return new TargetGeneric(pair.left.getName(), convert(pair.right, generics));
+ if (p instanceof GenerateGenerics.PairLT pair) {
+ return new TargetGeneric(pair.left.resolve().getName(), convert(pair.right.resolve(), generics));
+ } else if (p instanceof GenerateGenerics.PairEQ pair) {
+ return new TargetGeneric(pair.left.resolve().getName(), convert(pair.right, generics));
} else {
throw new IllegalArgumentException();
}
@@ -1001,6 +115,8 @@ public class ASTToTargetAST {
while (genericsIter.hasNext()) {
var next = genericsIter.next();
userDefinedGenerics.add(next);
+ // TODO Support multiple bounds
+ javaGenerics.add(new TargetGeneric(next.getName(), convert(next.getBounds().get(0))));
}
} else {
this.userDefinedGenerics.put(input, new HashSet<>());
@@ -1025,7 +141,7 @@ public class ASTToTargetAST {
return generics.stream().anyMatch(g -> g.name().equals(type.getParsedName()));
}
- private Set collectMethodGenerics(GenerateGenerics generateGenerics, Set> generics, Method input) {
+ private Set collectMethodGenerics(GenerateGenerics generateGenerics, Set generics, Method input) {
var convertedGenerics = new HashSet<>(convert(generics, generateGenerics));
outer: for (GenericTypeVar typeVar : input.getGenerics()) {
for (var classGeneric : currentClass.getGenerics()) {
@@ -1161,7 +277,7 @@ public class ASTToTargetAST {
} catch (ClassNotFoundException e) {
classLoader.loadClass(code);
}
- auxiliaries.put(className, code);
+ auxiliaries.put(superClassName, code);
}
FunNGenerator.GenericParameters gep = null;
if (!usedFunN.containsKey(className)) {
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/Bound.java b/src/main/java/de/dhbwstuttgart/target/generate/Bound.java
index 1b39df6c..3e749092 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/Bound.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/Bound.java
@@ -6,5 +6,19 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import java.util.List;
public record Bound(boolean isOnMethod, RefTypeOrTPHOrWildcardOrGeneric bound) {
+ public static Bound onMethod(String tph) {
+ return new Bound(true, TypePlaceholder.of(tph));
+ }
+ public static Bound onMethod(RefTypeOrTPHOrWildcardOrGeneric bound) {
+ return new Bound(true, bound);
+ }
+
+ public static Bound onClass(String tph) {
+ return new Bound(false, TypePlaceholder.of(tph));
+ }
+
+ public static Bound onClass(RefTypeOrTPHOrWildcardOrGeneric bound) {
+ return new Bound(false, bound);
+ }
}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/CycleFinder.java b/src/main/java/de/dhbwstuttgart/target/generate/CycleFinder.java
new file mode 100644
index 00000000..175b4221
--- /dev/null
+++ b/src/main/java/de/dhbwstuttgart/target/generate/CycleFinder.java
@@ -0,0 +1,104 @@
+package de.dhbwstuttgart.target.generate;
+
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class CycleFinder {
+ private CycleFinder() {}
+
+ static Set allNodes(Set extends GenerateGenerics.Pair> input) {
+ return input.stream()
+ .filter(GenerateGenerics.PairLT.class::isInstance)
+ .map(GenerateGenerics.PairLT.class::cast)
+ .flatMap(pair -> Stream.of(pair.left, pair.right)).collect(Collectors.toSet());
+ }
+
+ static Set outgoingEdgesOf(GenerateGenerics.TPH tph, Set extends GenerateGenerics.Pair> input) {
+ return input.stream()
+ .filter(GenerateGenerics.PairLT.class::isInstance)
+ .map(GenerateGenerics.PairLT.class::cast)
+ .filter(pair -> pair.left.equals(tph))
+ .map(pair -> pair.right).collect(Collectors.toSet());
+ }
+
+ static boolean containsEdge(GenerateGenerics.TPH a, GenerateGenerics.TPH b, Set extends GenerateGenerics.Pair> input) {
+ return input.stream()
+ .filter(GenerateGenerics.PairLT.class::isInstance)
+ .map(GenerateGenerics.PairLT.class::cast)
+ .anyMatch(pair -> pair.left.equals(a) && pair.right.equals(b));
+ }
+
+ // Tiernan simple cycles algorithm
+ // Adapted from https://github.com/jgrapht/jgrapht/blob/master/jgrapht-core/src/main/java/org/jgrapht/alg/cycle/TiernanSimpleCycles.java
+ static Set> findCycles(Set extends GenerateGenerics.Pair> input) {
+ Map indices = new HashMap<>();
+ List path = new ArrayList<>();
+ Set pathSet = new HashSet<>();
+ Map> blocked = new HashMap<>();
+ Set> cycles = new HashSet<>();
+
+ int index = 0;
+ for (var tph : allNodes(input)) {
+ blocked.put(tph, new HashSet<>());
+ indices.put(tph, index++);
+ }
+
+ var vertexIterator = allNodes(input).iterator();
+ if (!vertexIterator.hasNext()) return cycles;
+
+ GenerateGenerics.TPH startOfPath = null;
+ GenerateGenerics.TPH endOfPath = vertexIterator.next();
+ GenerateGenerics.TPH temp = null;
+ int endIndex = 0;
+ boolean extensionFound = false;
+ path.add(endOfPath);
+ pathSet.add(endOfPath);
+
+ while (true) {
+ do {
+ extensionFound = false;
+ for (GenerateGenerics.TPH n : outgoingEdgesOf(endOfPath, input)) {
+ int cmp = indices.get(n).compareTo(indices.get(path.get(0)));
+ if ((cmp > 0) && !pathSet.contains(n) && !blocked.get(endOfPath).contains(n)) {
+ path.add(n);
+ pathSet.add(n);
+ endOfPath = n;
+ extensionFound = true;
+ break;
+ }
+ }
+ } while (extensionFound);
+
+ startOfPath = path.get(0);
+ if (containsEdge(endOfPath, startOfPath, input)) {
+ List cycle = new ArrayList<>(path);
+ cycles.add(cycle);
+ }
+ if (path.size() > 1) {
+ blocked.get(endOfPath).clear();
+ endIndex = path.size() - 1;
+ path.remove(endIndex);
+ pathSet.remove(endOfPath);
+ --endIndex;
+ temp = endOfPath;
+ endOfPath = path.get(endIndex);
+ blocked.get(endOfPath).add(temp);
+ continue;
+ }
+ if (vertexIterator.hasNext()) {
+ path.clear();
+ pathSet.clear();
+ endOfPath = vertexIterator.next();
+ path.add(endOfPath);
+ pathSet.add(endOfPath);
+ for (GenerateGenerics.TPH tph : blocked.keySet()) {
+ blocked.get(tph).clear();
+ }
+ continue;
+ }
+ break;
+ }
+ return cycles;
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java b/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java
new file mode 100644
index 00000000..53143235
--- /dev/null
+++ b/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java
@@ -0,0 +1,901 @@
+package de.dhbwstuttgart.target.generate;
+
+import de.dhbwstuttgart.parser.NullToken;
+import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
+import de.dhbwstuttgart.syntaxtree.Constructor;
+import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
+import de.dhbwstuttgart.syntaxtree.Method;
+import de.dhbwstuttgart.syntaxtree.statement.*;
+import de.dhbwstuttgart.syntaxtree.type.*;
+import de.dhbwstuttgart.syntaxtree.type.Void;
+import de.dhbwstuttgart.target.tree.type.TargetGenericType;
+import de.dhbwstuttgart.target.tree.type.TargetType;
+import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
+import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
+import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
+import de.dhbwstuttgart.typeinference.result.ResultSet;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public abstract class GenerateGenerics {
+
+ private final ASTToTargetAST astToTargetAST;
+
+ public class TPH {
+ private final TypePlaceholder wrap;
+
+ TPH(TypePlaceholder wrap) {
+ this.wrap = wrap;
+ }
+
+ public TypePlaceholder resolve() {
+ return equality.getOrDefault(wrap, wrap);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ TPH tph = (TPH) o;
+ return Objects.equals(resolve(), tph.resolve());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(resolve());
+ }
+
+ @Override
+ public String toString() {
+ return resolve().getName();
+ }
+ }
+
+ public abstract class Pair {
+ public final TPH left;
+
+ Pair(TPH left) {
+ this.left = left;
+ }
+
+ public abstract RefTypeOrTPHOrWildcardOrGeneric resolveRight();
+ }
+
+ public class PairLT extends Pair {
+ public final TPH right;
+
+ PairLT(TPH left, TPH right) {
+ super(left);
+ this.right = right;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ PairLT pairLT = (PairLT) o;
+ return Objects.equals(right, pairLT.right) && Objects.equals(left, pairLT.left);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(right, left);
+ }
+
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric resolveRight() {
+ return right.resolve();
+ }
+
+ @Override
+ public String toString() {
+ return "(" + left + " < " + right + ")";
+ }
+ }
+
+ public class PairEQ extends Pair {
+ public final RefType right;
+
+ PairEQ(TPH left, RefType right) {
+ super(left);
+ this.right = right;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ PairEQ pairLT = (PairEQ) o;
+ return Objects.equals(right, pairLT.right) && Objects.equals(left, pairLT.left);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(right, left);
+ }
+
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric resolveRight() {
+ return right;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + left + " = " + right + ")";
+ }
+ }
+
+ final Map> computedGenericsOfMethods = new HashMap<>();
+ final Map> computedGenericsOfClasses = new HashMap<>();
+
+ final Map> usedTPHsOfMethods = new HashMap<>();
+ final Map> familyOfMethods = new HashMap<>();
+
+ final Set simplifiedConstraints = new HashSet<>();
+ final Map concreteTypes = new HashMap<>();
+ final Map equality = new HashMap<>();
+
+ GenerateGenerics(ASTToTargetAST astToTargetAST, ResultSet constraints) {
+ this.astToTargetAST = astToTargetAST;
+ for (var constraint : constraints.results) {
+ if (constraint instanceof PairTPHsmallerTPH p) {
+ simplifiedConstraints.add(new PairLT(new TPH(p.left), new TPH(p.right)));
+ } else if (constraint instanceof PairTPHEqualTPH p) {
+ equality.put(p.getLeft(), p.getRight());
+ } else if (constraint instanceof PairTPHequalRefTypeOrWildcardType p) {
+ concreteTypes.put(new TPH(p.left), p.right);
+ }
+ }
+
+ System.out.println("Simplified constraints: " + simplifiedConstraints);
+ }
+
+ Set findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type) {
+ var result = new HashSet();
+ if (type instanceof TypePlaceholder tph) {
+ var nTph = new TPH(tph);
+ if (concreteTypes.containsKey(nTph)) {
+ result.addAll(findTypeVariables(concreteTypes.get(nTph)));
+ return result;
+ }
+ result.add(nTph);
+ } else if (type instanceof RefType refType) {
+ for (var t : refType.getParaList())
+ result.addAll(findTypeVariables(t));
+ } else if (type instanceof ExtendsWildcardType wildcardType) {
+ result.addAll(findTypeVariables(wildcardType.getInnerType()));
+ } else if (type instanceof SuperWildcardType wildcardType) {
+ result.addAll(findTypeVariables(wildcardType.getInnerType()));
+ }
+ return result;
+ }
+
+ boolean containsRelation(Set result, PairLT pair) {
+ // Check if both the right and the left are already part of a relation
+ var containsLeft = false;
+ for (var pair2 : result) {
+ if (pair2.left.equals(pair.left)) {
+ containsLeft = true;
+ break;
+ }
+ }
+ var containsRight = false;
+ for (var pair2 : result)
+ if (pair2 instanceof PairLT plt) {
+ if (plt.right.equals(pair.right)) {
+ containsRight = true;
+ break;
+ }
+ }
+ return containsLeft && containsRight;
+ }
+
+ void addToPairs(Set input, Pair pair) {
+ if (pair instanceof PairLT plt) {
+ input.removeIf(pair2 -> {
+ if (pair2 instanceof PairEQ peq) {
+ return peq.left.equals(plt.left) && peq.right.equals(ASTToTargetAST.OBJECT);
+ }
+ return false;
+ });
+ } else if (input.stream().anyMatch(p -> p.left.equals(pair.left))) {
+ return;
+ }
+
+ input.add(pair);
+ }
+
+ void addToEquality(TypePlaceholder from, TypePlaceholder to, Set referenced) {
+ for (var entry : new HashSet<>(equality.entrySet())) {
+ if (entry.getValue().equals(from)) {
+ equality.remove(entry.getKey());
+ equality.put(entry.getKey(), to);
+ }
+ }
+ to.setVariance(from.getVariance());
+ equality.put(from, to);
+ referenced.remove(new TPH(from));
+ referenced.add(new TPH(to));
+ }
+
+ Set transitiveClosure(Set extends Pair> generics) {
+ Set all = new HashSet<>(generics);
+ Set toAdd = new HashSet<>();
+ int sizeBefore;
+ do {
+ sizeBefore = all.size();
+ toAdd.clear();
+ for (var g1 : all) {
+ for (var g2 : all) {
+ if (g1 instanceof PairLT pair && g2 instanceof PairLT pair2) {
+ if (pair2.left.equals(pair.right))
+ toAdd.add(new PairLT(pair.left, pair2.right));
+ }
+ }
+ }
+ all.addAll(toAdd);
+ } while (sizeBefore < all.size());
+ return all;
+ }
+
+ private void methodFindConstraints(
+ ClassOrInterface owner, Method method,
+ Set typeVariables,
+ Set typeVariablesOfClass,
+ Set result
+ ) {
+ var userDefinedGenericsOfClass = astToTargetAST.userDefinedGenerics.get(owner);
+
+ // Type variables with bounds that are also type variables of the method
+ for (var typeVariable : new HashSet<>(typeVariables)) {
+ if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
+ continue;
+ for (var pair : simplifiedConstraints) {
+ if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
+ addToPairs(result, new PairLT(pair.left, pair.right));
+ }
+ }
+ }
+
+ method.block.accept(new TracingStatementVisitor() {
+
+ private RefTypeOrTPHOrWildcardOrGeneric superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
+
+ @Override
+ public void visit(MethodCall methodCall) {
+ //Anfang es werden Paare von TPHs gespeichert, die bei den Generated Generics ueber die Methodengrenzen hinweg
+ //betrachtet werden muessen
+ //Definition 7.2 (Family of generated generics). T1 <. R1 <.^∗ R2 <. T2
+ Set T1s =
+ methodCall.getArgumentList()
+ .getArguments()
+ .stream()
+ .map(TypableStatement::getType)
+ .collect(Collectors.toCollection(HashSet::new))
+ .stream().filter(TypePlaceholder.class::isInstance)
+ .map(TypePlaceholder.class::cast)
+ .map(TPH::new)
+ .collect(Collectors.toCollection(HashSet::new));
+ Set T2s = new HashSet<>();
+ findTphs(superType, T2s);
+
+ System.out.println("T1s: " + T1s + " T2s: " + T2s);
+ //Ende
+
+ superType = methodCall.receiverType;
+ methodCall.receiver.accept(this);
+ for (int i = 0; i < methodCall.arglist.getArguments().size(); i++) {
+ superType = methodCall.arglist.getArguments().get(i).getType();
+ methodCall.arglist.getArguments().get(i).accept(this);
+ }
+
+ if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver) {
+ if (expressionReceiver.expr instanceof This) {
+ var optMethod = astToTargetAST.findMethod(owner, methodCall.name, methodCall.getArgumentList());
+ if (optMethod.isEmpty()) return;
+ var method2 = optMethod.get();
+ System.out.println("In: " + method.getName() + " Method: " + method2.getName());
+ var generics = family(owner, method2);
+
+ // transitive and
+ var all = transitiveClosure(generics);
+ // reflexive
+ var toAdd = new HashSet();
+ for (var generic : all) {
+ toAdd.add(new PairLT(generic.left, generic.left));
+ }
+ all.addAll(toAdd);
+
+ HashSet newPairs = new HashSet<>();
+
+ // Loop from hell
+ outer:
+ for (var R1 : typeVariables) {
+ if (typeVariablesOfClass.contains(R1)) continue;
+ for (var generic : all)
+ if (generic instanceof PairLT ptph) {
+ for (var pair : simplifiedConstraints) {
+ if (!(pair.left.equals(R1) && pair.right.equals(ptph.left)))
+ continue;
+
+ for (var R2 : typeVariables) {
+ for (var pair2 : simplifiedConstraints) {
+
+ if (!(pair2.right.equals(R2) && pair2.left.equals(ptph.right)))
+ continue;
+ if (R1.equals(R2)) continue;
+ if (!T1s.contains(R1) || !T2s.contains(R2)) continue;
+
+ var newPair = new PairLT(R1, R2);
+ System.out.println("New pair: " + newPair);
+ newPairs.add(newPair);
+
+ if (!containsRelation(result, newPair))
+ addToPairs(result, newPair);
+ continue outer;
+ }
+ }
+ }
+ }
+ }
+ simplifiedConstraints.addAll(newPairs);
+ }
+ }
+ }
+
+ @Override
+ public void visit(LambdaExpression lambdaExpression) {
+ superType = new Void(new NullToken());
+ lambdaExpression.methodBody.accept(this);
+ }
+
+ @Override
+ public void visit(Assign assign) {
+ superType = assign.rightSide.getType();
+ assign.rightSide.accept(this);
+ }
+
+ @Override
+ public void visit(BinaryExpr binary) {
+ superType = new Void(new NullToken());
+ binary.lexpr.accept(this);
+ superType = new Void(new NullToken());
+ binary.rexpr.accept(this);
+ }
+
+ @Override
+ public void visit(Block block) {
+ for (var expr : block.statements) {
+ superType = new de.dhbwstuttgart.syntaxtree.type.Void(new NullToken());
+ expr.accept(this);
+ }
+ }
+
+ @Override
+ public void visit(IfStmt ifStmt) {
+ superType = new Void(new NullToken());
+ ifStmt.expr.accept(this);
+ superType = new Void(new NullToken());
+ ifStmt.then_block.accept(this);
+ superType = new Void(new NullToken());
+ ifStmt.else_block.accept(this);
+ }
+
+ @Override
+ public void visit(Return aReturn) {
+ superType = aReturn.getType();
+ aReturn.retexpr.accept(this);
+ }
+
+ @Override
+ public void visit(WhileStmt whileStmt) {
+ superType = new Void(new NullToken());
+ whileStmt.expr.accept(this);
+ superType = new Void(new NullToken());
+ whileStmt.loopBlock.accept(this);
+ }
+
+ @Override
+ public void visit(ArgumentList arglist) {
+ for (int i = 0; i < arglist.getArguments().size(); i++) {
+ superType = arglist.getArguments().get(i).getType();
+ arglist.getArguments().get(i).accept(this);
+ }
+ }
+ });
+
+ var closure = transitiveClosure(simplifiedConstraints);
+ // Type variables with bounds that are also type variables of the class
+ for (var typeVariable : new HashSet<>(typeVariables)) {
+ if (typeVariablesOfClass.contains(typeVariable)) continue;
+
+ var pairs = new HashSet();
+ for (var pair : closure) {
+ if (!(pair instanceof PairLT ptph)) continue;
+ if (ptph.left.equals(typeVariable) && typeVariablesOfClass.contains(ptph.right)) {
+ pairs.add(new PairLT(ptph.left, ptph.right));
+ }
+ }
+
+ // Find the closest pair with the minimum amount of steps
+ PairLT minimalPair = null;
+ var minSteps = Integer.MAX_VALUE;
+ for (var pair : pairs) {
+ var left = pair.left;
+ var visited = new HashSet();
+ var steps = 0;
+ while (!left.equals(pair.right)) {
+ visited.add(left);
+ var found = false;
+ for (var pair2 : simplifiedConstraints) {
+ if (left.equals(pair2.left) && !visited.contains(pair2.right)) {
+ left = pair2.right;
+ steps += 1;
+ found = true;
+ break;
+ }
+ }
+ if (!found) break;
+ }
+ if (steps < minSteps) {
+ minSteps = steps;
+ minimalPair = pair;
+ }
+ }
+
+ if (minimalPair != null)
+ addToPairs(result, minimalPair);
+ }
+
+ // All unbounded type variables (bounds not in method)
+ outer:
+ for (var typeVariable : typeVariables) {
+ if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
+ continue;
+ for (var pair : result) {
+ if (pair.left.equals(typeVariable))
+ continue outer;
+ }
+ addToPairs(result, new PairEQ(typeVariable, ASTToTargetAST.OBJECT));
+ }
+
+ // All unbounded bounds
+ outer:
+ for (var pair : simplifiedConstraints) {
+ for (var pair2 : simplifiedConstraints) {
+ if (pair.right.equals(pair2.left))
+ continue outer;
+ }
+ if (!classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, pair.right) && typeVariables.contains(pair.right)) {
+ addToPairs(result, new PairEQ(pair.right, ASTToTargetAST.OBJECT));
+ }
+ }
+ }
+
+ private boolean classHasGeneric(Set userDefinedGenericsOfClass, Set typeVariablesOfClass, TPH typeVariable) {
+ return typeVariablesOfClass.contains(typeVariable) || userDefinedGenericsOfClass.stream().anyMatch(g -> g.getName().equals(typeVariable.resolve().getName()));
+ }
+
+ private void methodFindTypeVariables(
+ Method method,
+ Set typeVariables
+ ) {
+
+ if (!(method instanceof Constructor))
+ typeVariables.addAll(findTypeVariables(method.getReturnType()));
+ for (var arg : method.getParameterList().getFormalparalist()) {
+ typeVariables.addAll(findTypeVariables(arg.getType()));
+ }
+
+ method.block.accept(new TracingStatementVisitor() {
+ @Override
+ public void visit(LocalVarDecl localVarDecl) {
+ typeVariables.addAll(findTypeVariables(localVarDecl.getType()));
+ }
+
+ @Override
+ public void visit(MethodCall methodCall) {
+ super.visit(methodCall);
+ typeVariables.addAll(findTypeVariables(methodCall.getType()));
+ }
+ });
+ }
+
+ abstract void generics(ClassOrInterface owner, Method method, Set result, Set javaTypeVariablesOfClass);
+
+ Set family(ClassOrInterface owner, Method method) {
+ Set result = new HashSet<>();
+ if (familyOfMethods.containsKey(method))
+ return familyOfMethods.get(method);
+
+ familyOfMethods.put(method, result);
+
+ var classGenerics = generics(owner);
+ HashSet typeVariablesOfClass = new HashSet<>();
+
+ for (var pair : classGenerics) {
+ typeVariablesOfClass.add(pair.left);
+ }
+
+ HashSet javaTypeVariables = new HashSet<>();
+
+ methodFindTypeVariables(method, javaTypeVariables);
+ methodFindConstraints(owner, method, javaTypeVariables, typeVariablesOfClass, result);
+ eliminateTransitives(result);
+
+ return result;
+ }
+
+ Set generics(ClassOrInterface owner, Method method) {
+ if (computedGenericsOfMethods.containsKey(method)) {
+ var cached = computedGenericsOfMethods.get(method);
+ System.out.println("Cached " + method.getName() + ": " + cached);
+ return cached;
+ }
+
+ var result = new HashSet();
+ computedGenericsOfMethods.put(method, result);
+
+ var classGenerics = generics(owner);
+ HashSet typeVariablesOfClass = new HashSet<>();
+ for (var pair : classGenerics) {
+ typeVariablesOfClass.add(pair.left);
+ }
+
+ result.addAll(family(owner, method));
+
+ var referenced = new HashSet();
+
+ var usedTphs = new HashSet();
+ // For eliminating inner type variables we need to figure out which ones are actually used
+ for (var param : method.getParameterList().getFormalparalist()) {
+ usedTphs.addAll(findTypeVariables(param.getType()));
+ }
+ usedTphs.addAll(findTypeVariables(method.getReturnType()));
+ referenced.addAll(usedTphs);
+ referenced.addAll(typeVariablesOfClass);
+
+ generics(owner, method, result, referenced);
+ usedTPHsOfMethods.put(method, usedTphs);
+
+ normalize(result, classGenerics, usedTphs);
+
+ System.out.println(this.getClass().getSimpleName() + " " + method.name + ": " + result);
+ return result;
+ }
+
+ private void eliminateChain(Set result, List chain) {
+ for (var pair : new HashSet<>(result)) {
+ if (pair instanceof PairLT ptph && chain.get(chain.size() - 1).equals(ptph.left)) {
+ if (chain.contains(ptph.right)) return;
+ var copy = new ArrayList<>(chain);
+ copy.add(ptph.right);
+ if (copy.size() > 2)
+ result.remove(new PairLT(chain.get(0), ptph.right));
+ eliminateChain(result, copy);
+ }
+ }
+ }
+
+ void eliminateTransitives(Set result) {
+ for (var pair : new HashSet<>(result))
+ if (pair instanceof PairLT ptph) {
+ var first = ptph.left;
+ var chain = new ArrayList();
+ chain.add(ptph.left);
+ chain.add(ptph.right);
+ eliminateChain(result, chain);
+ }
+ }
+
+ void findAllBounds(RefTypeOrTPHOrWildcardOrGeneric type, Set generics) {
+ if (type instanceof TypePlaceholder tph) {
+ var nTph = new TPH(tph);
+ var concreteType = concreteTypes.get(nTph);
+ if (concreteType != null) {
+ findAllBounds(concreteType, generics);
+ return;
+ }
+
+ var found = false;
+ for (var rsp : simplifiedConstraints) {
+ if (rsp.left.equals(nTph)) {
+ var pair = new PairLT(new TPH(tph), rsp.right);
+ if (!generics.contains(pair)) {
+ addToPairs(generics, pair);
+ findAllBounds(rsp.right.resolve(), generics);
+ found = true;
+ }
+ }
+ }
+ if (!found)
+ addToPairs(generics, new PairEQ(nTph, ASTToTargetAST.OBJECT));
+ } else if (type instanceof RefType refType) {
+ refType.getParaList().forEach(t -> findAllBounds(t, generics));
+ }
+ }
+
+ abstract void generics(ClassOrInterface classOrInterface, Set result, Set referenced);
+
+ Set generics(ClassOrInterface classOrInterface) {
+ if (computedGenericsOfClasses.containsKey(classOrInterface))
+ return computedGenericsOfClasses.get(classOrInterface);
+
+ Set javaResult = new HashSet<>();
+ computedGenericsOfClasses.put(classOrInterface, javaResult);
+
+ for (var field : classOrInterface.getFieldDecl()) {
+ findAllBounds(field.getType(), javaResult);
+ }
+
+ var referenced = new HashSet();
+ eliminateTransitives(javaResult);
+ generics(classOrInterface, javaResult, referenced);
+
+ var referencedByClass = new HashSet();
+ for (var field : classOrInterface.getFieldDecl()) {
+ findTphs(field.getType(), referencedByClass);
+ }
+
+ normalize(javaResult, null, referencedByClass);
+
+ System.out.println(this.getClass().getSimpleName() + " Class " + classOrInterface.getClassName().getClassName() + ": " + javaResult);
+ return javaResult;
+ }
+
+ void normalize(Set result, Set classGenerics, Set usedTphs) {
+ outer:
+ for (var tph : usedTphs) {
+ for (var p1 : new HashSet<>(result)) {
+ if (p1 instanceof PairLT ptph && ptph.left.equals(ptph.right))
+ result.remove(p1); // TODO This is a bit strange
+ if (p1.left.equals(tph)) continue outer;
+ }
+
+ if (classGenerics == null || classGenerics.stream().noneMatch((pair) -> pair.left.equals(tph)))
+ addToPairs(result, new PairEQ(tph, ASTToTargetAST.OBJECT));
+ }
+ }
+
+ void equalizeTypeVariables(Set input, Set referenced) {
+ for (var pair : new HashSet<>(input)) {
+ if (pair instanceof PairLT ptph && referenced.contains(ptph.left)) {
+ var chain = new ArrayList();
+ chain.add(ptph.left);
+ chain.add(ptph.right);
+
+ outer:
+ while (true) {
+ var added = false;
+ for (var pair2 : input) {
+ if (pair2 instanceof PairLT ptph2 && ptph2.left.equals(chain.get(chain.size() - 1))) {
+ if (chain.contains(ptph2.right)) break outer;
+ chain.add(ptph2.right);
+ added = true;
+ }
+ }
+ if (!added) break;
+ }
+
+ System.out.println(chain + " " + chain.stream().map(e -> e.resolve().getVariance()).toList());
+ var variance = chain.get(0).resolve().getVariance();
+ if (variance != 1) continue;
+ var index = 0;
+ for (var tph : chain) {
+ if (variance == 1 && tph.resolve().getVariance() == -1) {
+ variance = -1;
+ }
+ if (variance == -1 && tph.resolve().getVariance() == 1 && referenced.contains(tph)) {
+ break;
+ }
+ index++;
+ }
+ if (variance == 1) continue;
+
+
+ var start = chain.get(0);
+ var prev = start;
+ for (var i = 1; i < index; i++) {
+ var cur = chain.get(i);
+ if (!referenced.contains(cur)) continue;
+ addToEquality(cur.resolve(), start.resolve(), referenced);
+ TPH finalPrev = prev;
+ input.removeIf(p -> p.equals(new PairLT(finalPrev, cur)));
+ for (var pair2 : new HashSet<>(input)) {
+ // TODO Maybe this would be unnecessary if we were to add the = constraints later on
+ if (pair2 instanceof PairEQ peq && pair.left.equals(cur)) {
+ input.remove(pair2);
+ input.add(new PairEQ(start, peq.right));
+ }
+ }
+ prev = chain.get(i);
+ }
+ }
+ }
+ }
+
+ void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set tphs) {
+ if (type instanceof RefType refType) {
+ refType.getParaList().forEach(t -> findTphs(t, tphs));
+ } else if (type instanceof TypePlaceholder tph) {
+ tph = equality.getOrDefault(tph, tph);
+ var concreteType = concreteTypes.get(new TPH(tph));
+ if (concreteType != null) {
+ findTphs(concreteType, tphs);
+ return;
+ }
+ tphs.add(new TPH(tph));
+ }
+ }
+
+ void eliminateInnerTypeVariablesOfClass(ClassOrInterface classOrInterface, Set input, Set referenced) {
+ for (var field : classOrInterface.getFieldDecl()) {
+ findTphs(field.getType(), referenced);
+ }
+ doIterationForMethods(classOrInterface);
+ for (var method : classOrInterface.getMethods()) {
+ referenced.addAll(usedTPHsOfMethods.get(method));
+ }
+ eliminateInnerTypeVariables(referenced, input);
+ }
+
+ void doIterationForMethods(ClassOrInterface classOrInterface) {
+ familyOfMethods.clear();
+
+ var oldFamily = new HashMap>();
+ do {
+ oldFamily.clear();
+ oldFamily.putAll(familyOfMethods);
+ familyOfMethods.clear();
+ for (var method : classOrInterface.getMethods()) {
+ family(classOrInterface, method);
+ }
+ } while(!oldFamily.equals(familyOfMethods));
+
+ for (var method : classOrInterface.getMethods()) {
+ generics(classOrInterface, method);
+ }
+ }
+
+ private void findChain(Set referenced, Set input, Set output, TPH start, TPH end, Set chain) {
+ if (referenced.contains(end)) {
+ var pair = new PairLT(start, end);
+ output.add(pair);
+ return;
+ }
+ var foundNext = false;
+ for (var pair : input) {
+ if (pair instanceof PairLT ptph && ptph.left.equals(end)) {
+ if (chain.contains(ptph.right)) return;
+ chain = new HashSet<>(chain);
+ chain.add(ptph.right);
+ findChain(referenced, input, output, start, ptph.right, chain);
+ foundNext = true;
+ }
+ }
+ if (!foundNext) {
+ output.add(new PairEQ(start, ASTToTargetAST.OBJECT));
+ }
+ }
+
+ void eliminateInnerTypeVariables(Set referenced, Set input) {
+ var output = new HashSet();
+ for (var tph : referenced) {
+ for (var pair : input) {
+ if (pair instanceof PairLT pthp && pthp.left.equals(tph)) {
+ var chain = new HashSet();
+ chain.add(tph);
+ findChain(referenced, input, output, tph, pthp.right, chain);
+ }
+ }
+ }
+ for (var pair : input) {
+ if (pair instanceof PairEQ rtph) {
+ if (referenced.contains(rtph.left))
+ output.add(rtph);
+ }
+ }
+
+ input.clear();
+ input.addAll(output);
+ }
+
+ void eliminateCycles(Set input, Set referenced) {
+ var cycles = CycleFinder.findCycles(input);
+ for (var cycle : cycles) {
+ var newTph = TypePlaceholder.fresh(new NullToken());
+ var variance = cycle.get(0).resolve().getVariance();
+ for (var tph : cycle) {
+ if (tph.resolve().getVariance() != variance) {
+ variance = 0;
+ break;
+ }
+ }
+ newTph.setVariance(variance);
+
+ referenced.add(new TPH(newTph));
+ addToPairs(input, new PairEQ(new TPH(newTph), ASTToTargetAST.OBJECT));
+ cycle.add(cycle.get(0)); // Make it a complete cycle
+ for (var i = 0; i < cycle.size() - 1; i++) {
+ var left = cycle.get(i);
+ var right = cycle.get(i + 1);
+ var pair = new PairLT(left, right);
+ input.remove(pair);
+ addToEquality(left.resolve(), newTph, referenced);
+ }
+ }
+ }
+
+ void eliminateInfima(Set input, Set referenced) {
+ var foundInfima = false;
+ do {
+ foundInfima = false;
+ for (var constraint : new HashSet<>(input)) {
+ var left = constraint.left;
+ Set infima = new HashSet<>();
+ for (var pair : input) {
+ if (pair instanceof PairLT stph) {
+ if (pair.left.equals(constraint.left))
+ infima.add(stph);
+ }
+ }
+ if (infima.size() > 1) {
+ foundInfima = true;
+ var newTph = TypePlaceholder.fresh(new NullToken());
+ var variance = infima.stream().findFirst().get().right.resolve().getVariance();
+ for (var pair : infima) {
+ if (pair.right.resolve().getVariance() != variance) {
+ variance = 0;
+ break;
+ }
+ }
+ newTph.setVariance(variance);
+
+ //referenced.add(newTph);
+ addToPairs(input, new PairLT(left, new TPH(newTph)));
+ input.removeAll(infima);
+ for (var infimum : infima) {
+ addToEquality(infimum.right.resolve(), newTph, referenced);
+ new HashSet<>(input).forEach(pair -> {
+ if (pair.left.equals(infimum.right)) {
+ input.remove(pair);
+ if (pair instanceof PairLT stph) {
+ if (!newTph.equals(stph.right.resolve()))
+ addToPairs(input, new PairLT(new TPH(newTph), stph.right));
+ } else if (pair instanceof PairEQ rtph) {
+ addToPairs(input, new PairEQ(new TPH(newTph), rtph.right));
+ }
+ } else if (pair instanceof PairLT stph && stph.right.equals(infimum.right)) {
+ input.remove(pair);
+ if (!newTph.equals(stph.left.resolve()))
+ addToPairs(input, new PairLT(stph.left, new TPH(newTph)));
+ }
+ });
+ }
+ }
+ }
+ } while (foundInfima);
+ }
+
+ RefTypeOrTPHOrWildcardOrGeneric getType(RefTypeOrTPHOrWildcardOrGeneric type) {
+ if (type instanceof TypePlaceholder tph) {
+ if (equality.containsKey(tph)) {
+ return getType(equality.get(tph));
+ }
+ return concreteTypes.getOrDefault(new TPH(tph), tph);
+ }
+ return type;
+ }
+
+ TargetType getTargetType(RefTypeOrTPHOrWildcardOrGeneric in) {
+ if (in instanceof TypePlaceholder tph) {
+ if (equality.containsKey(tph)) {
+ return getTargetType(equality.get(tph));
+ }
+ var type = concreteTypes.get(new TPH(tph));
+ if (type == null) return new TargetGenericType(tph.getName());
+ return astToTargetAST.convert(type, this);
+ }
+ return astToTargetAST.convert(in, this);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/GenericsResult.java b/src/main/java/de/dhbwstuttgart/target/generate/GenericsResult.java
index e06bca66..a30fdba9 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/GenericsResult.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/GenericsResult.java
@@ -5,14 +5,13 @@ import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.target.tree.type.TargetType;
-import de.dhbwstuttgart.typeinference.result.ResultPair;
import java.util.*;
public class GenericsResult {
- private final ASTToTargetAST.GenerateGenerics generics;
+ private final GenerateGenerics generics;
- GenericsResult(ASTToTargetAST.GenerateGenerics generics) {
+ GenericsResult(GenerateGenerics generics) {
this.generics = generics;
}
@@ -42,16 +41,16 @@ public class GenericsResult {
do {
bound = Optional.empty();
for (var pair : methodGenerics) {
- if (pair.getLeft().equals(type)) {
- type = resolve(pair.getRight());
+ if (pair.left.resolve().equals(type)) {
+ type = pair.resolveRight();
bound = Optional.of(new Bound(true, type));
break;
}
}
if (bound.isEmpty()) {
for (var pair : classGenerics) {
- if (pair.getLeft().equals(type)) {
- type = resolve(pair.getRight());
+ if (pair.left.resolve().equals(type)) {
+ type = pair.resolveRight();
bound = Optional.of(new Bound(false, type));
break;
}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/GenericsResultSet.java b/src/main/java/de/dhbwstuttgart/target/generate/GenericsResultSet.java
index 8092e44e..19ccaf31 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/GenericsResultSet.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/GenericsResultSet.java
@@ -1,23 +1,24 @@
package de.dhbwstuttgart.target.generate;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH;
+import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
+import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import java.util.*;
-public class GenericsResultSet extends AbstractSet> {
+public class GenericsResultSet extends AbstractSet {
- final Set> backing;
+ final Set backing;
final Map equality;
- public GenericsResultSet(Set> backing, Map equality) {
+ public GenericsResultSet(Set backing, Map equality) {
this.backing = backing == null ? new HashSet<>() : new HashSet<>(backing);
this.equality = equality;
}
@Override
- public Iterator> iterator() {
+ public Iterator iterator() {
return backing.iterator();
}
@@ -29,7 +30,14 @@ public class GenericsResultSet extends AbstractSet> {
public Optional> getResultPairFor(TypePlaceholder tph) {
var tph2 = equality.getOrDefault(tph, tph);
return this.stream().filter(pair -> {
- return pair.getLeft().equals(tph2);
- }).findFirst();
+ return pair.left.resolve().equals(tph2);
+ }).findFirst().map(pair -> {
+ ResultPair, ?> res = null;
+ if (pair instanceof GenerateGenerics.PairLT lt)
+ res = new PairTPHsmallerTPH(lt.left.resolve(), lt.right.resolve());
+ else if (pair instanceof GenerateGenerics.PairEQ eq)
+ res = new PairTPHequalRefTypeOrWildcardType(eq.left.resolve(), eq.right);
+ return res;
+ });
}
}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/JavaGenerics.java b/src/main/java/de/dhbwstuttgart/target/generate/JavaGenerics.java
new file mode 100644
index 00000000..16be617e
--- /dev/null
+++ b/src/main/java/de/dhbwstuttgart/target/generate/JavaGenerics.java
@@ -0,0 +1,29 @@
+package de.dhbwstuttgart.target.generate;
+
+import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
+import de.dhbwstuttgart.syntaxtree.Method;
+import de.dhbwstuttgart.typeinference.result.ResultSet;
+
+import java.util.Set;
+
+final class JavaGenerics extends GenerateGenerics {
+ JavaGenerics(ASTToTargetAST astToTargetAST, ResultSet constraints) {
+ super(astToTargetAST, constraints);
+ }
+
+ @Override
+ void generics(ClassOrInterface owner, Method method, Set result, Set referenced) {
+ eliminateCycles(result, referenced);
+ eliminateInfima(result, referenced);
+ equalizeTypeVariables(result, referenced);
+ eliminateInnerTypeVariables(referenced, result);
+ }
+
+ @Override
+ void generics(ClassOrInterface classOrInterface, Set result, Set referenced) {
+ eliminateCycles(result, referenced);
+ eliminateInfima(result, referenced);
+ eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced);
+ equalizeTypeVariables(result, referenced);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java
index 62e68843..a5c4d644 100644
--- a/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java
+++ b/src/main/java/de/dhbwstuttgart/target/generate/StatementToTargetExpression.java
@@ -206,7 +206,7 @@ public class StatementToTargetExpression implements StatementVisitor {
var returnType = isFunNType ? TargetType.Object : converter.convert(methodCall.signature.get(methodCall.signature.size() - 1));
var receiverName = new JavaClassName(converter.convert(methodCall.receiver.getType()).name());
var argList = methodCall.signature.stream().map(converter::convert).toList();
- // argList = argList.subList(0, argList.size() - 1);
+ argList = argList.subList(0, argList.size() - 1);
Method foundMethod = null;
if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver && expressionReceiver.expr instanceof This) {
diff --git a/src/main/java/de/dhbwstuttgart/target/generate/TxGenerics.java b/src/main/java/de/dhbwstuttgart/target/generate/TxGenerics.java
new file mode 100644
index 00000000..b64babb6
--- /dev/null
+++ b/src/main/java/de/dhbwstuttgart/target/generate/TxGenerics.java
@@ -0,0 +1,25 @@
+package de.dhbwstuttgart.target.generate;
+
+import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
+import de.dhbwstuttgart.syntaxtree.Method;
+import de.dhbwstuttgart.typeinference.result.ResultSet;
+
+import java.util.Set;
+
+final class TxGenerics extends GenerateGenerics {
+ TxGenerics(ASTToTargetAST astToTargetAST, ResultSet constraints) {
+ super(astToTargetAST, constraints);
+ }
+
+ @Override
+ void generics(ClassOrInterface owner, Method method, Set result, Set referenced) {
+ eliminateInfima(result, referenced);
+ eliminateInnerTypeVariables(referenced, result);
+ }
+
+ @Override
+ void generics(ClassOrInterface classOrInterface, Set result, Set referenced) {
+ eliminateInfima(result, referenced);
+ eliminateInnerTypeVariablesOfClass(classOrInterface, result, referenced);
+ }
+}
diff --git a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
index 660fc494..bfe4d566 100644
--- a/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
+++ b/src/main/java/de/dhbwstuttgart/typedeployment/TypeInsertFactory.java
@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
+import de.dhbwstuttgart.target.generate.GenerateGenerics;
import de.dhbwstuttgart.target.generate.GenericsResult;
import de.dhbwstuttgart.target.generate.GenericsResultSet;
import de.dhbwstuttgart.typeinference.result.*;
@@ -89,10 +90,10 @@ public class TypeInsertFactory {
String insert = " <";
for (var genericInsertConstraint : constraints) {
- if (genericInsertConstraint instanceof PairTPHequalRefTypeOrWildcardType peq) {
- insert += peq.left.getName();
- } else if (genericInsertConstraint instanceof PairTPHsmallerTPH psm) {
- insert += psm.left.getName() + " extends " + psm.right.getName();
+ if (genericInsertConstraint instanceof GenerateGenerics.PairEQ peq) {
+ insert += peq.left.resolve().getName();
+ } else if (genericInsertConstraint instanceof GenerateGenerics.PairLT psm) {
+ insert += psm.left.resolve().getName() + " extends " + psm.right.resolve().getName();
}
insert += ", ";
}
@@ -115,10 +116,10 @@ public class TypeInsertFactory {
String insert = " <";
for (var genericInsertConstraint : classConstraints) {
- if (genericInsertConstraint instanceof PairTPHequalRefTypeOrWildcardType peq) {
- insert += peq.left.getName();
- } else if (genericInsertConstraint instanceof PairTPHsmallerTPH psm) {
- insert += psm.left.getName() + " extends " + psm.right.getName();
+ if (genericInsertConstraint instanceof GenerateGenerics.PairEQ peq) {
+ insert += peq.left.resolve().getName();
+ } else if (genericInsertConstraint instanceof GenerateGenerics.PairLT psm) {
+ insert += psm.left.resolve().getName() + " extends " + psm.right.resolve().getName();
}
insert += ", ";
}
diff --git a/src/test/java/syntaxtreegenerator/TestComplete.java b/src/test/java/syntaxtreegenerator/TestComplete.java
index 5e6cf856..e60f01d8 100644
--- a/src/test/java/syntaxtreegenerator/TestComplete.java
+++ b/src/test/java/syntaxtreegenerator/TestComplete.java
@@ -24,8 +24,8 @@ public class TestComplete {
@BeforeClass
public static void setUp() {
- final String testFileDirectory = "src/test/resources/javFiles/";
- final String expectedASTDirectory = "src/test/resources/syntaxtreegenerator/";
+ final String testFileDirectory = "resources/bytecode/javFiles/";
+ final String expectedASTDirectory = "resources/syntaxtreegenerator/";
File dir = new File(testFileDirectory);
for (File f : dir.listFiles(new JavFilter())) {
String basefilename = f.getName().replace(".jav", "");
diff --git a/src/test/java/targetast/TestGenerics.java b/src/test/java/targetast/TestGenerics.java
index 1590378c..6d2ab724 100644
--- a/src/test/java/targetast/TestGenerics.java
+++ b/src/test/java/targetast/TestGenerics.java
@@ -7,10 +7,11 @@ import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
+import static de.dhbwstuttgart.target.generate.ASTToTargetAST.OBJECT;
import de.dhbwstuttgart.target.generate.Bound;
+import static de.dhbwstuttgart.target.generate.Bound.*;
import de.dhbwstuttgart.target.generate.BoundsList;
import de.dhbwstuttgart.target.generate.GenericsResult;
-import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -21,8 +22,7 @@ import java.util.ArrayList;
import java.util.List;
public class TestGenerics {
-
- private static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/insertGenericsJav/";
+ private static final String rootDirectory = System.getProperty("user.dir") + "/resources/insertGenerics/javFiles/";
private static final String bytecodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
private record Result(List genericsResults, ClassOrInterface clazz) {
@@ -59,12 +59,12 @@ public class TestGenerics {
var ECK1 = generics.getBounds(otherMethod.getParameterList().getParameterAt(0).getType(), result.clazz, anyMethod);
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
- var ECKChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
+ var ECKChain = new BoundsList(onClass(OBJECT));
assertEquals(ECK1, ECK2);
assertEquals(ECK2, generics.getBounds(b.getType(), result.clazz));
var M = generics.getBounds(a.getType(), result.clazz);
- var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("ECK")), new Bound(false, ASTToTargetAST.OBJECT));
+ var MChain = new BoundsList(onClass("ECK"), onClass(OBJECT));
assertEquals(M, MChain);
}
@@ -78,7 +78,7 @@ public class TestGenerics {
assertEquals(0, generics.get(fReturn).size());
var N = generics.getBounds(fReturn.getReturnType(), result.clazz);
- var NChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
+ var NChain = new BoundsList(onClass(OBJECT));
assertEquals(N, NChain);
}
@@ -96,7 +96,7 @@ public class TestGenerics {
var N = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
var N2 = generics.getBounds(m.getReturnType(), result.clazz, m);
- var NChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
+ var NChain = new BoundsList(onMethod(OBJECT));
assertEquals(N, N2);
assertEquals(N2, NChain);
@@ -122,13 +122,13 @@ public class TestGenerics {
assertEquals(2, generics.get(m).size());
var R = generics.getBounds(a.getType(), result.clazz);
- var RChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
+ var RChain = new BoundsList(onClass(OBJECT));
assertEquals(R, RChain);
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
assertEquals(O, AB);
- assertEquals(AB, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(AB, new BoundsList(onMethod(OBJECT)));
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
assertEquals(S, RChain);
@@ -136,7 +136,7 @@ public class TestGenerics {
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
- var XChain = new BoundsList(new Bound(true, ASTToTargetAST.OBJECT));
+ var XChain = new BoundsList(onMethod(OBJECT));
assertEquals(X, XChain);
assertEquals(Y, X);
}
@@ -162,25 +162,25 @@ public class TestGenerics {
assertEquals(3, generics.get(main).size());
var N = generics.getBounds(a.getType(), result.clazz);
- assertEquals(N, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
+ assertEquals(N, new BoundsList(onClass(OBJECT)));
var P = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
assertEquals(P, O);
- assertEquals(O, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(O, new BoundsList(onMethod(OBJECT)));
assertEquals(generics.resolve(m.getParameterList().getParameterAt(0).getType()), generics.resolve(m.getReturnType()));
var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
var AA = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
assertEquals(Y, AA);
- assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(AA, new BoundsList(onMethod(OBJECT)));
var AI = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
var AJ = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
var AH = generics.getBounds(m.getReturnType(), result.clazz, m);
assertEquals(AI, AJ);
assertEquals(AJ, AH);
- assertEquals(AH, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(AH, new BoundsList(onMethod(OBJECT)));
}
@Test
@@ -192,7 +192,7 @@ public class TestGenerics {
assertEquals(1, generics.get(anyMethod).size());
var M = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
- assertEquals(M, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(M, new BoundsList(onMethod(OBJECT)));
}
@Test
@@ -206,12 +206,12 @@ public class TestGenerics {
var generics = result.genericsResults.get(0);
var M = generics.getBounds(a.getType(), result.clazz);
var DYX = generics.getBounds(b.getType(), result.clazz);
- var MChain = new BoundsList(new Bound(false, TypePlaceholder.of("DYX")), new Bound(false, ASTToTargetAST.OBJECT));
- var DYXChain = new BoundsList(new Bound(false, ASTToTargetAST.OBJECT));
+ var MChain = new BoundsList(onClass("DYX"), onClass(OBJECT));
+ var DYXChain = new BoundsList(onClass(OBJECT));
assertEquals(M, MChain);
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
- assertEquals(Q, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(Q, new BoundsList(onMethod(OBJECT)));
System.out.println(otherMethod.getReturnType());
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
@@ -234,17 +234,17 @@ public class TestGenerics {
var generics = result.genericsResults.get(0);
var U = generics.getBounds(id2.getParameterList().getParameterAt(0).getType(), result.clazz, id2);
var FPT = generics.getBounds(id2.getReturnType(), result.clazz, id2);
- assertEquals(U, new BoundsList(new Bound(true, TypePlaceholder.of("FPT")), new Bound(false, ASTToTargetAST.OBJECT)));
- assertEquals(FPT, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
+ assertEquals(U, new BoundsList(onMethod("FPT"), onClass(OBJECT)));
+ assertEquals(FPT, new BoundsList(onClass(OBJECT)));
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
- assertEquals(AA, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
- assertEquals(AC, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(AA, new BoundsList(onMethod(OBJECT)));
+ assertEquals(AC, new BoundsList(onMethod(OBJECT)));
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
- assertEquals(AH, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(AH, new BoundsList(onMethod(OBJECT)));
assertEquals(AH, AL);
}
@@ -260,26 +260,34 @@ public class TestGenerics {
var generics = result.genericsResults.get(0);
var AO = generics.getBounds(a.getType(), result.clazz);
- var AOBound = new BoundsList(new Bound(false, TypePlaceholder.of("Y")), new Bound(false, TypePlaceholder.of("AK")), new Bound(false, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT));
+ var AOBound = new BoundsList(
+ onClass("Y"),
+ onClass("AK"),
+ onClass("AE"),
+ onClass(OBJECT)
+ );
assertEquals(AO, AOBound);
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
var c = new ArrayList();
- c.add(new Bound(true, TypePlaceholder.of("AO")));
+ c.add(onMethod("AO"));
c.addAll(AOBound);
var SChain = new BoundsList(c);
assertEquals(S, SChain);
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
- var YChain = new BoundsList(new Bound(true, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT));
+ var YChain = new BoundsList(onMethod("AE"), onClass(OBJECT));
var AE = generics.getBounds(m.getReturnType(), result.clazz, m);
assertEquals(Y, YChain);
- assertEquals(AE, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
+ assertEquals(AE, new BoundsList(onClass(OBJECT)));
// TODO main seems to change between runs
- /*
- * var AE2 = generics.getBounds(main.getReturnType(), result.clazz, main); var AF = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main); var AG = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main); assertEquals(AE, AE2)); assertEquals(AF, new BoundsList(new Bound(true, TypePlaceholder.of("AK")), new Bound(true, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT)))); assertEquals(AG, SChain));
- */
+ /*var AE2 = generics.getBounds(main.getReturnType(), result.clazz, main);
+ var AF = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
+ var AG = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
+ assertEquals(AE, AE2));
+ assertEquals(AF, new BoundsList(onMethod("AK"), onMethod("AE"), onClass(OBJECT))));
+ assertEquals(AG, SChain));*/
}
@Test
@@ -298,15 +306,15 @@ public class TestGenerics {
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
var O2 = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
assertEquals(O, O2);
- assertEquals(O2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(O2, new BoundsList(onMethod(OBJECT)));
// TODO Maybe test in other ways if the parameter generics equals the return generics
var S = generics.getBounds(main.getReturnType(), result.clazz, main);
var S2 = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
var T = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
assertEquals(S, S2);
- assertEquals(S2, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
- assertEquals(T, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(S2, new BoundsList(onMethod(OBJECT)));
+ assertEquals(T, new BoundsList(onMethod(OBJECT)));
}
@Test
@@ -321,11 +329,11 @@ public class TestGenerics {
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
- assertEquals(S, new BoundsList(new Bound(true, TypePlaceholder.of("V")), new Bound(true, ASTToTargetAST.OBJECT)));
- assertEquals(ACM, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(S, new BoundsList(onMethod("V"), onMethod(OBJECT)));
+ assertEquals(ACM, new BoundsList(onMethod(OBJECT)));
var Y = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
- assertEquals(Y, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(Y, new BoundsList(onMethod(OBJECT)));
assertEquals(Y, generics.getBounds(id.getReturnType(), result.clazz, id));
}
@@ -339,8 +347,8 @@ public class TestGenerics {
var par1 = generics.resolve(add.getParameterList().getParameterAt(0).getType());
var ACK = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, add);
var O = generics.getBounds(add.getParameterList().getParameterAt(1).getType(), result.clazz, add);
- assertEquals(ACK, new BoundsList(new Bound(true, ASTToTargetAST.OBJECT)));
- assertEquals(O, new BoundsList(new Bound(true, TypePlaceholder.of("ACK")), new Bound(true, ASTToTargetAST.OBJECT)));
+ assertEquals(ACK, new BoundsList(onMethod(OBJECT)));
+ assertEquals(O, new BoundsList(onMethod("ACK"), onMethod(OBJECT)));
var par2 = generics.resolve(main.getParameterList().getParameterAt(0).getType());
var ACK2 = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, add);
diff --git a/src/test/resources/javFiles/Cycle.class b/src/test/resources/javFiles/Cycle.class
deleted file mode 100644
index 6bac05ec..00000000
Binary files a/src/test/resources/javFiles/Cycle.class and /dev/null differ
diff --git a/src/test/resources/javFiles/insertGenericsJav/TestContraVariant.jav b/src/test/resources/javFiles/insertGenericsJav/TestContraVariant.jav
deleted file mode 100644
index 2b0e245f..00000000
--- a/src/test/resources/javFiles/insertGenericsJav/TestContraVariant.jav
+++ /dev/null
@@ -1,17 +0,0 @@
-public class TestContraVariant {
- main(x, y) {
- var y2 = m(x, y);
- var y3 = y2.snd();
- var z;
- y3 = z;
- return new Pair(x,z);
- }
-
- m(x, y) {
- var x2 = main(x, y);
- var x3 = x2.fst();
- var z;
- x3 = z;
- return new Pair(z, y);
- }
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/Gen.jav b/src/test/resources/javFiles/packageTest/Gen.jav
deleted file mode 100644
index 3b58b188..00000000
--- a/src/test/resources/javFiles/packageTest/Gen.jav
+++ /dev/null
@@ -1,8 +0,0 @@
-import java.lang.Integer;
-import java.util.Vector;
-
-public class Gen{
- Vector m(Vector v){
- return v;
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/OLMain.jav b/src/test/resources/javFiles/packageTest/OLMain.jav
deleted file mode 100644
index 0cdb0b4f..00000000
--- a/src/test/resources/javFiles/packageTest/OLMain.jav
+++ /dev/null
@@ -1,12 +0,0 @@
-import java.lang.String;
-import java.lang.Integer;
-import java.lang.Double;
-
-public class OLMain {
-
- main(x) {
- var ol;
- ol = new OLextends();
- return ol.m(x);
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/OLOneFile.jav b/src/test/resources/javFiles/packageTest/OLOneFile.jav
deleted file mode 100644
index eb865d61..00000000
--- a/src/test/resources/javFiles/packageTest/OLOneFile.jav
+++ /dev/null
@@ -1,22 +0,0 @@
-import java.lang.String;
-import java.lang.Integer;
-import java.lang.Double;
-import java.lang.Boolean;
-
-
-public class OLOneFile {
-
- m2(x) { return x + x; }
-
-}
-
-public class OLextendsOneFile extends OLOneFile { }
-
-public class OLMainOneFile {
-
- main(x) {
- var ol;
- ol = new OLextendsOneFile();
- return ol.m2(x);
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/OLTest.txt b/src/test/resources/javFiles/packageTest/OLTest.txt
deleted file mode 100644
index d91b58d7..00000000
--- a/src/test/resources/javFiles/packageTest/OLTest.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-java -jar ~/eclipse-workspace/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar de/test/OL.jav -d de/test/output
-java -jar ~/eclipse-workspace/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar OLextends.jav -cp de/test/output
-java -jar ~/eclipse-workspace/JavaCompilerCore/target/JavaTXcompiler-0.2-jar-with-dependencies.jar OLMain.jav -cp .:de/test/output
-javac UseOLMain.java
-java -cp .:de/test/output UseOLMain
-rm -f UseOLMain.class
diff --git a/src/test/resources/javFiles/packageTest/OLextends.jav b/src/test/resources/javFiles/packageTest/OLextends.jav
deleted file mode 100644
index b3c055df..00000000
--- a/src/test/resources/javFiles/packageTest/OLextends.jav
+++ /dev/null
@@ -1,7 +0,0 @@
-import de.test.OL;
-
-
-public class OLextends extends OL {
-
-
-}
diff --git a/src/test/resources/javFiles/packageTest/Pair2.jav b/src/test/resources/javFiles/packageTest/Pair2.jav
deleted file mode 100644
index d62474ea..00000000
--- a/src/test/resources/javFiles/packageTest/Pair2.jav
+++ /dev/null
@@ -1,14 +0,0 @@
-import de.test.Pair;
-
-class Pairs {
- setfst(fst) {
- return new Pair<>(snd, fst);
- }
-
- swap () {
- return new Pair<> (snd, fst); }
-
- polyrec(p) {
- return polyrec (p.swap());
- }
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/Test.jav b/src/test/resources/javFiles/packageTest/Test.jav
deleted file mode 100644
index 2f6429a1..00000000
--- a/src/test/resources/javFiles/packageTest/Test.jav
+++ /dev/null
@@ -1,3 +0,0 @@
-
-public class Test{
-}
diff --git a/src/test/resources/javFiles/packageTest/UseOLMain.java b/src/test/resources/javFiles/packageTest/UseOLMain.java
deleted file mode 100644
index 2d7d6fd8..00000000
--- a/src/test/resources/javFiles/packageTest/UseOLMain.java
+++ /dev/null
@@ -1,5 +0,0 @@
-class UseOLMain {
- public static void main(String[] arg) {
- System.out.println(new OLMain().main(1+1));
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/de/test/ImportTest.jav b/src/test/resources/javFiles/packageTest/de/test/ImportTest.jav
deleted file mode 100644
index 58b6fc0b..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/ImportTest.jav
+++ /dev/null
@@ -1,9 +0,0 @@
-package de.test;
-
-import de.test.ToImport;
-
-class ImportTest{
- void methode(){
- new ToImport();
- }
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/ImportTest2.jav b/src/test/resources/javFiles/packageTest/de/test/ImportTest2.jav
deleted file mode 100644
index 3526abc8..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/ImportTest2.jav
+++ /dev/null
@@ -1,11 +0,0 @@
-package de.test;
-
-import de.test.subpackage1.ToImport2;
-import de.test.subpackage2.ToImport3;
-
-class ImportTest2{
- void methode(){
- new ToImport2().m1();
- new ToImport3().m2();
- }
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/ImportTestDefault.jav b/src/test/resources/javFiles/packageTest/de/test/ImportTestDefault.jav
deleted file mode 100644
index ecd8d7c5..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/ImportTestDefault.jav
+++ /dev/null
@@ -1,7 +0,0 @@
-package de.test;
-
-class ImportTestDefault{
- void methode(){
- new ToImport();
- }
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/OL.jav b/src/test/resources/javFiles/packageTest/de/test/OL.jav
deleted file mode 100644
index 7f1ba512..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/OL.jav
+++ /dev/null
@@ -1,13 +0,0 @@
-package de.test;
-import java.lang.String;
-import java.lang.Integer;
-import java.lang.Double;
-import java.lang.Boolean;
-//import java.util.Vector;
-
-
-public class OL {
-
- public m(x) { return x + x; }
-
-}
diff --git a/src/test/resources/javFiles/packageTest/de/test/Pair.jav b/src/test/resources/javFiles/packageTest/de/test/Pair.jav
deleted file mode 100644
index dbde6636..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/Pair.jav
+++ /dev/null
@@ -1,12 +0,0 @@
-package de.test;
-
-class Pair {
- fst;
- snd;
-
- Pair(fst, snd) {
- this.fst = fst;
- this.snd = snd;
- }
-}
-
diff --git a/src/test/resources/javFiles/packageTest/de/test/TestClass.jav b/src/test/resources/javFiles/packageTest/de/test/TestClass.jav
deleted file mode 100644
index 6681b36a..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/TestClass.jav
+++ /dev/null
@@ -1,3 +0,0 @@
-package de.test;
-
-public class TestClass{}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/ToImport.jav b/src/test/resources/javFiles/packageTest/de/test/ToImport.jav
deleted file mode 100644
index 3afdba54..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/ToImport.jav
+++ /dev/null
@@ -1,4 +0,0 @@
-package de.test;
-
-class ToImport{
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/mathStruc.jav b/src/test/resources/javFiles/packageTest/de/test/mathStruc.jav
deleted file mode 100644
index 28db5db8..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/mathStruc.jav
+++ /dev/null
@@ -1,18 +0,0 @@
-package de.test;
-
-
-import java.util.Vector;
-import java.lang.Integer;
-
-public class mathStruc {
- model;
-
- //Fun1*, Fun1*,MathStruc >>
- innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(model,ms.model));
-
- public mathStruc(m) {
- model =m;
- //innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(this.model,ms.model));
- }
-}
-
diff --git a/src/test/resources/javFiles/packageTest/de/test/mathStrucVector.jav b/src/test/resources/javFiles/packageTest/de/test/mathStrucVector.jav
deleted file mode 100644
index fe6d6055..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/mathStrucVector.jav
+++ /dev/null
@@ -1,33 +0,0 @@
-package de.test;
-
-import java.util.Vector;
-import java.lang.Integer;
-import java.lang.Boolean;
-
-import de.test.mathStruc;
-import de.test.vectorAdd;
-
-
-public class mathStrucVector {
-
- public main() {
- Vector v1 = new Vector();
- v1.addElement(2);
- v1.addElement(2);
- Vector v2 = new Vector();
- v2.addElement(3);
- v2.addElement(3);
-
- vectorAdd va = new vectorAdd();
-
- var ms;
- ms = new mathStruc<>(v1);
- var ms2;
- ms2 = new mathStruc<>(v2);
- var ms3;
-
- ms3 = ms.innerOp.apply(va.add).apply(ms2);
- return ms3;
-
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/de/test/output/de/test/mathStrucVectoruse.java b/src/test/resources/javFiles/packageTest/de/test/output/de/test/mathStrucVectoruse.java
deleted file mode 100644
index 54b9e45b..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/output/de/test/mathStrucVectoruse.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package de.test;
-import de.test.mathStrucVector;
-
-
-class mathStrucVectorUse {
-
- public static void main(String[] args) {
- new mathStrucVector().main();
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/de/test/output/mathStrucVectoruse.java b/src/test/resources/javFiles/packageTest/de/test/output/mathStrucVectoruse.java
deleted file mode 100644
index 9a9b2e75..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/output/mathStrucVectoruse.java
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-class mathStrucVectorUse {
-
- public static void main(String[] args) {
- new mathStrucVector().main();
- }
-}
diff --git a/src/test/resources/javFiles/packageTest/de/test/packageNameTestWrongPackage.jav b/src/test/resources/javFiles/packageTest/de/test/packageNameTestWrongPackage.jav
deleted file mode 100644
index a86d22aa..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/packageNameTestWrongPackage.jav
+++ /dev/null
@@ -1,3 +0,0 @@
-package de.tesst;
-
-class TestClass{}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/subpackage1/Test1.jav b/src/test/resources/javFiles/packageTest/de/test/subpackage1/Test1.jav
deleted file mode 100644
index a7011169..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/subpackage1/Test1.jav
+++ /dev/null
@@ -1,4 +0,0 @@
-package de.test.subpackage1;
-
-class Test1{
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/subpackage1/ToImport2.jav b/src/test/resources/javFiles/packageTest/de/test/subpackage1/ToImport2.jav
deleted file mode 100644
index bcc67b95..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/subpackage1/ToImport2.jav
+++ /dev/null
@@ -1,5 +0,0 @@
-package de.test.subpackage1;
-
-class ToImport2{
-void m1(){}
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/subpackage2/Test2.jav b/src/test/resources/javFiles/packageTest/de/test/subpackage2/Test2.jav
deleted file mode 100644
index 750f7612..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/subpackage2/Test2.jav
+++ /dev/null
@@ -1,4 +0,0 @@
-package de.test.subpackage2;
-
-class Test2{
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/subpackage2/ToImport3.jav b/src/test/resources/javFiles/packageTest/de/test/subpackage2/ToImport3.jav
deleted file mode 100644
index 3efd8fff..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/subpackage2/ToImport3.jav
+++ /dev/null
@@ -1,5 +0,0 @@
-package de.test.subpackage2;
-
-class ToImport3{
-void m2(){}
-}
\ No newline at end of file
diff --git a/src/test/resources/javFiles/packageTest/de/test/vectorAdd.jav b/src/test/resources/javFiles/packageTest/de/test/vectorAdd.jav
deleted file mode 100644
index 727a83a9..00000000
--- a/src/test/resources/javFiles/packageTest/de/test/vectorAdd.jav
+++ /dev/null
@@ -1,20 +0,0 @@
-package de.test;
-
-import java.util.Vector;
-import java.lang.Integer;
-import java.lang.Boolean;
-
-
-public class vectorAdd {
-
- public add = (v1, v2) -> {
- var ret = new Vector();
- var i = 0;
- while(i < v1.size()) {
- //if (i < v2.size()) {
- ret.addElement(v1.elementAt(i) + v2.elementAt(i));
- //}
- }
- return ret;
- };
-}
diff --git a/src/test/resources/testBytecode/generatedBC/.gitignore b/src/test/resources/testBytecode/generatedBC/.gitignore
deleted file mode 100644
index 5e7d2734..00000000
--- a/src/test/resources/testBytecode/generatedBC/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-# Ignore everything in this directory
-*
-# Except this file
-!.gitignore