diff --git a/.gitignore b/.gitignore
index d3e21505..07778e4c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ bin
.DS_Store
.project
.settings/
+.vscode/
/target/
settings.json
diff --git a/pom.xml b/pom.xml
index ade9b85d..ee4bc93f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,13 +51,24 @@ http://maven.apache.org/maven-v4_0_0.xsd">
org.apache.maven.plugins
maven-compiler-plugin
- 3.8.0
+ 3.11.0
--enable-preview
20
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.1.0
+
+ --enable-preview
+
+ **/JavaTXCompilerTest.java
+
+
+
org.antlr
antlr4-maven-plugin
@@ -74,6 +85,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
org.apache.maven.plugins
maven-jar-plugin
+ 3.3.0
@@ -112,8 +124,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
- 20
- 20
de.dhbwstuttgart.core.ConsoleInterface
@@ -123,4 +133,4 @@ http://maven.apache.org/maven-v4_0_0.xsd">
file:///${project.basedir}/maven-repository/
-
+
\ No newline at end of file
diff --git a/resources/AllgemeinTest/Box.jav b/resources/AllgemeinTest/Box.jav
deleted file mode 100644
index 411f0551..00000000
--- a/resources/AllgemeinTest/Box.jav
+++ /dev/null
@@ -1,13 +0,0 @@
-class Box{
-void m(A a){}
-}
-
-class B { }
-
-class Box_Main extends B {
-
- m(b) {
- b.m(new Box_Main());
- b.m(new B());
- }
-}
diff --git a/resources/AllgemeinTest/Box_Main.jav b/resources/AllgemeinTest/Box_Main.jav
deleted file mode 100644
index 0ba86f19..00000000
--- a/resources/AllgemeinTest/Box_Main.jav
+++ /dev/null
@@ -1,13 +0,0 @@
-class Box{
- A f;
-}
-
-class B { }
-
-class Box_Main extends B {//Fehler Bugzilla Bug 230
-
- m(b) {
- b.f = new Box_Main();
- b.f = new B();
- }
-}
diff --git a/resources/AllgemeinTest/FCTest1.jav b/resources/AllgemeinTest/FCTest1.jav
deleted file mode 100644
index 98647278..00000000
--- a/resources/AllgemeinTest/FCTest1.jav
+++ /dev/null
@@ -1,12 +0,0 @@
-import java.util.Vector;
-import java.util.List;
-import java.lang.Integer;
-
-class FCTest1 extends Vector> {
- fc1() {
- var y;
- var z;
- y.add(z);
- return y;
- }
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/FCTest2.jav b/resources/AllgemeinTest/FCTest2.jav
deleted file mode 100644
index c3f892dd..00000000
--- a/resources/AllgemeinTest/FCTest2.jav
+++ /dev/null
@@ -1,11 +0,0 @@
-import java.util.Vector;
-import java.util.List;
-import java.lang.Integer;
-
-class FCTest2 extends Vector> {
- fc2(y) {
- var z;
- y.add(z);
- return y;
- }
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/FCTest3.jav b/resources/AllgemeinTest/FCTest3.jav
deleted file mode 100644
index e862c4b8..00000000
--- a/resources/AllgemeinTest/FCTest3.jav
+++ /dev/null
@@ -1,19 +0,0 @@
-import java.util.Vector;
-import java.lang.Integer;
-
-class FCTest3 extends Pair, Vector> {
-
-
- fc2(x) {
- x.snd().addElement(2);
- }
-
-
-
- fc2a() {
- var y;
- y.snd().addElement(2);
- return y;
- }
-
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/GenTest.jav b/resources/AllgemeinTest/GenTest.jav
deleted file mode 100644
index 409838ae..00000000
--- a/resources/AllgemeinTest/GenTest.jav
+++ /dev/null
@@ -1,10 +0,0 @@
-import java.lang.Integer;
-import java.util.Vector;
-
-public class GenTest {
-
- main(x) {
- var v = new Vector();
- return 1 + v.elementAt(0);
- }
-}
diff --git a/resources/AllgemeinTest/Generics.jav b/resources/AllgemeinTest/Generics.jav
deleted file mode 100644
index efed04f0..00000000
--- a/resources/AllgemeinTest/Generics.jav
+++ /dev/null
@@ -1,9 +0,0 @@
-class Generics {
- a;
- id(b) { return b; }
- setA(x) {
- a = x;
- return a;
- }
- m(x,y) { x = id(y); }
-}
diff --git a/resources/AllgemeinTest/Iteration.jav b/resources/AllgemeinTest/Iteration.jav
index c0b9dd65..2af750a4 100644
--- a/resources/AllgemeinTest/Iteration.jav
+++ b/resources/AllgemeinTest/Iteration.jav
@@ -1,4 +1,4 @@
-
+/*
class Pair {
T x;
U y;
@@ -17,7 +17,7 @@ class Pair {
return y;
}
}
-
+*/
public class Iteration {
id(x) {
diff --git a/resources/AllgemeinTest/M.jav b/resources/AllgemeinTest/M.jav
deleted file mode 100755
index 39e6d482..00000000
--- a/resources/AllgemeinTest/M.jav
+++ /dev/null
@@ -1,7 +0,0 @@
-import java.util.List;
-class M {
-void m(p, p2){
-
- new addList().addLists(p, p2);
-}
-}
diff --git a/resources/AllgemeinTest/OverloadingMain.jav b/resources/AllgemeinTest/OverloadingMain.jav
deleted file mode 100644
index 960f01db..00000000
--- a/resources/AllgemeinTest/OverloadingMain.jav
+++ /dev/null
@@ -1,9 +0,0 @@
-import java.util.Stack;
-import java.util.Vector;
-
-class OverloadingMain {
-
- mmMain(x) { var y; return new O1().mm(y); }
-
-}
-
diff --git a/resources/AllgemeinTest/Overloading_Generics.jav b/resources/AllgemeinTest/Overloading_Generics.jav
deleted file mode 100644
index d5691152..00000000
--- a/resources/AllgemeinTest/Overloading_Generics.jav
+++ /dev/null
@@ -1,20 +0,0 @@
-import java.lang.Integer;
-
-
-public class Overloading_Generics {
-
- id1 (x) { return x; }
-
- //Integer id (Integer x) { return x; }
-}
-
-
-class Overloading_Generics1 {
- main(x) {
- var olg = new Overloading_Generics();
- return olg.id1(1);
- }
-}
-
-
-
diff --git a/resources/AllgemeinTest/OverrideMain.jav b/resources/AllgemeinTest/OverrideMain.jav
deleted file mode 100644
index 0ede39ae..00000000
--- a/resources/AllgemeinTest/OverrideMain.jav
+++ /dev/null
@@ -1,25 +0,0 @@
-import java.util.Vector;
-import java.util.Stack;
-
-class OverrideMain {
- ovrMain(x) {
- var overide;
- overide.ovr(x);
- }
-}
-
-/*
- [
- [(TPH L = java.util.Stack), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH FTN, TPH FTM), (TPH K = void)],
-[(TPH FTO, TPH FTP), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Stack), (TPH K = void)],
-[(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH K = void), (TPH FTR, TPH FTQ), (TPH L = java.util.Vector)],
-[(TPH FTT, TPH FTS), (TPH M = ? extends Override2), (TPH L = java.util.Vector), (TPH K = void), (TPH N = java.lang.String)],
-[(TPH L = java.util.Vector), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH FTU, TPH FTV), (TPH K = void)],
-[(TPH FTX, TPH FTW), (TPH M = ? extends Override2), (TPH L = java.util.Vector), (TPH K = void), (TPH N = java.lang.String)],
-[(TPH M = ? extends Override2), (TPH L = java.util.Stack), (TPH K = void), (TPH FTY, TPH FTZ), (TPH N = java.lang.String)],
-[(TPH FUB, TPH FUA), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH L = java.util.Vector)],
-[(TPH N = java.lang.String), (TPH L = java.util.Vector), (TPH FUD, TPH FUC), (TPH M = ? extends Override2), (TPH K = void)],
-[(TPH N = java.lang.String), (TPH FUF, TPH FUE), (TPH M = ? extends Override2), (TPH K = void), (TPH L = java.util.Vector)]]
-
- [[(TPH M = ? extends Override2), (TPH MNX, TPH MNY), (TPH N = java.lang.String), (TPH K = void), (TPH L = java.util.Stack)], [(TPH L = java.util.Stack), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH K = void), (TPH MOB, TPH MOC)], [(TPH M = ? extends Override2), (TPH N = java.lang.String), (TPH MNZ, TPH MOA), (TPH L = java.util.Vector), (TPH K = void)], [(TPH L = java.util.Vector), (TPH K = void), (TPH M = ? extends Override2), (TPH MOD, TPH MOE), (TPH N = java.lang.String)], [(TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String), (TPH MOF, TPH MOG), (TPH L = java.util.Stack)], [(TPH L = java.util.Vector), (TPH K = void), (TPH MOH, TPH MOI), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH L = java.util.Vector), (TPH MOJ, TPH MOK), (TPH K = void), (TPH M = ? extends Override2), (TPH N = java.lang.String)], [(TPH MOL, TPH MOM), (TPH L = java.util.Stack), (TPH M = ? extends Override2), (TPH K = void), (TPH N = java.lang.String)], [(TPH L = java.util.Vector), (TPH MON, TPH MOO), (TPH N = java.lang.String), (TPH K = void), (TPH M = ? extends Override2)], [(TPH L = java.util.Stack), (TPH N = java.lang.String), (TPH M = ? extends Override2), (TPH MOQ, TPH MOP), (TPH K = void)]]
-*/
diff --git a/resources/AllgemeinTest/OverrideMainRet.jav b/resources/AllgemeinTest/OverrideMainRet.jav
deleted file mode 100644
index 44759c81..00000000
--- a/resources/AllgemeinTest/OverrideMainRet.jav
+++ /dev/null
@@ -1,11 +0,0 @@
-import java.util.Vector;
-import java.util.Stack;
-
-class OverrideMainRet {
- ovrMain() {
- var overide;
- var x;
- overide.ovr(x);
- return x;
- }
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/Pair.java b/resources/AllgemeinTest/Pair.java
deleted file mode 100644
index b47b1d84..00000000
--- a/resources/AllgemeinTest/Pair.java
+++ /dev/null
@@ -1,18 +0,0 @@
-class Pair {
- T x;
- U y;
-
- public Pair() { }
- public Pair(T x, U y) {
- this.x = x;
- this.y = y;
- }
-
- public T fst () {
- return x;
- }
-
- public U snd () {
- return y;
- }
-}
diff --git a/resources/AllgemeinTest/Put.jav b/resources/AllgemeinTest/Put.jav
deleted file mode 100644
index b22977c6..00000000
--- a/resources/AllgemeinTest/Put.jav
+++ /dev/null
@@ -1,19 +0,0 @@
-import java.util.Vector;
-import java.util.Stack;
-
-class Put {
-
- putElement(ele, v) {
- v.addElement(ele);
- }
-
- putElement(ele, s) {
- s.push(ele);
- }
-
-
- main(ele, x) {
- putElement(ele, x);
- }
-
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/Test.jav b/resources/AllgemeinTest/Test.jav
deleted file mode 100644
index 3d505a85..00000000
--- a/resources/AllgemeinTest/Test.jav
+++ /dev/null
@@ -1,4 +0,0 @@
-class Test {
- a;
- Test b;
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/TestSubTypless.jav b/resources/AllgemeinTest/TestSubTypless.jav
deleted file mode 100644
index 667fe6e7..00000000
--- a/resources/AllgemeinTest/TestSubTypless.jav
+++ /dev/null
@@ -1,12 +0,0 @@
-import java.util.ArrayList;
-
-class TestSubTypless {
- m(a){
- var l = new ArrayList<>();
- l.add(a);
- return m2(l).get(0);
- }
- m2(a){
- return m(a);
- }
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/TripleTest.jav b/resources/AllgemeinTest/TripleTest.jav
new file mode 100644
index 00000000..a0560b60
--- /dev/null
+++ b/resources/AllgemeinTest/TripleTest.jav
@@ -0,0 +1,19 @@
+class Triple {
+ U a;
+ T b;
+ S c;
+
+ Triple(U x, T y, S z) {
+ a = x; b = y; c = z;
+ }
+
+ U fst() { return a; }
+ T snd() { return b; }
+ S thrd() { return c; }
+}
+
+public class TripleTest {
+ m() {
+ return new Triple<>(m().thrd(), m().thrd(), m().thrd());
+ }
+}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/Twice.jav b/resources/AllgemeinTest/Twice.jav
deleted file mode 100644
index 396bc5e2..00000000
--- a/resources/AllgemeinTest/Twice.jav
+++ /dev/null
@@ -1,3 +0,0 @@
-class Twice {
- twice = f -> x -> f.apply(f.apply(x));
-}
diff --git a/resources/AllgemeinTest/Twice2.jav b/resources/AllgemeinTest/Twice2.jav
new file mode 100644
index 00000000..87a3f239
--- /dev/null
+++ b/resources/AllgemeinTest/Twice2.jav
@@ -0,0 +1,12 @@
+class Twice2 {
+ id1inst = new Id<>();
+ id1 = id1inst.id;
+ id2inst = new Id<>();
+ id2 = id2inst.id;
+ twice = id1.apply(id2);
+
+}
+
+class Id {
+ id = (T x) -> x;
+}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/Var.jav b/resources/AllgemeinTest/Var.jav
deleted file mode 100644
index b95b3667..00000000
--- a/resources/AllgemeinTest/Var.jav
+++ /dev/null
@@ -1,5 +0,0 @@
-class Var {
-
- var(x) { var y; }
-
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/VectorConstAdd.jav b/resources/AllgemeinTest/VectorConstAdd.jav
deleted file mode 100644
index b179bdcc..00000000
--- a/resources/AllgemeinTest/VectorConstAdd.jav
+++ /dev/null
@@ -1,15 +0,0 @@
-import java.util.Vector;
-import java.lang.Integer;
-
-
-public class VectorConstAdd {
- vectorAdd(v1) {
- var i = 0;
- var erg = new Vector<>();
- while (i < v1.size()) {
- erg.addElement(v1.elementAt(i) + 1);
- i++;
- }
- return erg;
- }
-}
diff --git a/resources/AllgemeinTest/VectorNotObject.jav b/resources/AllgemeinTest/VectorNotObject.jav
deleted file mode 100644
index d8ea900b..00000000
--- a/resources/AllgemeinTest/VectorNotObject.jav
+++ /dev/null
@@ -1,9 +0,0 @@
-import java.util.Vector;
-
-class VectorNotObject {
-
- vectorAddAll(v1, v2) {
- v1.addAll(v2);
- return v1;
- }
- }
diff --git a/resources/AllgemeinTest/WildcardCaptureConversionTest.jav b/resources/AllgemeinTest/WildcardCaptureConversionTest.jav
deleted file mode 100644
index 59016f7a..00000000
--- a/resources/AllgemeinTest/WildcardCaptureConversionTest.jav
+++ /dev/null
@@ -1,16 +0,0 @@
-import java.util.Vector;
-import java.lang.Integer;
-import java.lang.String;
-
-class WildcardCaptureConversionTest {
-
- m(x, y ,z) {
- x = new Vector();
- y = new Vector();
- x.add(1);
- y.add("2");
- //Integer i = x.elementAt(0);
- //String s = y.elementAt(0);
- return z.vectorAddAll(x, y);
- }
-}
\ No newline at end of file
diff --git a/resources/AllgemeinTest/Wildcard_Andi.jav b/resources/AllgemeinTest/Wildcard_Andi.jav
deleted file mode 100644
index e6160437..00000000
--- a/resources/AllgemeinTest/Wildcard_Andi.jav
+++ /dev/null
@@ -1,8 +0,0 @@
-class Wildcard_Andi {
-
- Test extends A> ex = new Test<>();
-
- Test super A> sup = new Test<>();
-}
-
-
diff --git a/resources/AllgemeinTest/addList.jav b/resources/AllgemeinTest/addList.jav
deleted file mode 100755
index a72023ea..00000000
--- a/resources/AllgemeinTest/addList.jav
+++ /dev/null
@@ -1,8 +0,0 @@
-import java.util.List;
-
-class addList {
- addLists(a, b){
-a.add(b.get(0));
-b.add(a.get(0));
-}
-}
diff --git a/resources/AllgemeinTest/wildcardPair.jav b/resources/AllgemeinTest/wildcardPair.jav
deleted file mode 100644
index 73f310f4..00000000
--- a/resources/AllgemeinTest/wildcardPair.jav
+++ /dev/null
@@ -1,22 +0,0 @@
-import java.util.List;
-import java.lang.Integer;
-import java.lang.Object;
-import java.lang.Boolean;
-
-class wildcardPair {
-
- make(l) {
- var p = new Pair(l.get(0), l.get(1));
- return p;
- }
- //Boolean compare(Pair x) { return true; }
- void m(l) {
- Object o = l.get(0);
-
- //Pair extends Object, ? extends Object> p;
- //List> b;
- //this.compare(p); //1, type incorrect
- make(l);
- //this.compare(this.make(b)); //2, OK
- }
-}
\ No newline at end of file
diff --git a/resources/javFiles/AddLong.jav b/resources/bytecode/javFiles/AddLong.jav
similarity index 100%
rename from resources/javFiles/AddLong.jav
rename to resources/bytecode/javFiles/AddLong.jav
diff --git a/resources/javFiles/EmptyClass.jav b/resources/bytecode/javFiles/EmptyClass.jav
similarity index 100%
rename from resources/javFiles/EmptyClass.jav
rename to resources/bytecode/javFiles/EmptyClass.jav
diff --git a/resources/javFiles/Expressions.jav b/resources/bytecode/javFiles/Expressions.jav
similarity index 100%
rename from resources/javFiles/Expressions.jav
rename to resources/bytecode/javFiles/Expressions.jav
diff --git a/resources/javFiles/FC_Matrix.jav b/resources/bytecode/javFiles/FC_Matrix.jav
similarity index 100%
rename from resources/javFiles/FC_Matrix.jav
rename to resources/bytecode/javFiles/FC_Matrix.jav
diff --git a/resources/javFiles/FacultyIf.jav b/resources/bytecode/javFiles/FacultyIf.jav
similarity index 100%
rename from resources/javFiles/FacultyIf.jav
rename to resources/bytecode/javFiles/FacultyIf.jav
diff --git a/resources/javFiles/FacultyTyped.jav b/resources/bytecode/javFiles/FacultyTyped.jav
similarity index 100%
rename from resources/javFiles/FacultyTyped.jav
rename to resources/bytecode/javFiles/FacultyTyped.jav
diff --git a/resources/javFiles/FieldAccess.jav b/resources/bytecode/javFiles/FieldAccess.jav
similarity index 100%
rename from resources/javFiles/FieldAccess.jav
rename to resources/bytecode/javFiles/FieldAccess.jav
diff --git a/resources/bytecode/javFiles/FieldTph2.jav b/resources/bytecode/javFiles/FieldTph2.jav
index 7d60b683..ed0d4521 100644
--- a/resources/bytecode/javFiles/FieldTph2.jav
+++ b/resources/bytecode/javFiles/FieldTph2.jav
@@ -1,3 +1,5 @@
+import java.lang.String;
+
public class FieldTph2 {
a;
diff --git a/resources/javFiles/Fields.jav b/resources/bytecode/javFiles/Fields.jav
similarity index 100%
rename from resources/javFiles/Fields.jav
rename to resources/bytecode/javFiles/Fields.jav
diff --git a/resources/bytecode/javFiles/InstanceOf.jav b/resources/bytecode/javFiles/InstanceOf.jav
new file mode 100644
index 00000000..4cee01f2
--- /dev/null
+++ b/resources/bytecode/javFiles/InstanceOf.jav
@@ -0,0 +1,18 @@
+import java.lang.Number;
+import java.lang.Integer;
+import java.lang.Double;
+import java.lang.String;
+
+public class InstanceOf {
+ main(n) {
+ if (n instanceof Integer i) {
+ takes(i);
+ return "Integer";
+ } else if (n instanceof Double d) {
+ takes(d);
+ return "Double";
+ }
+ }
+
+ takes(i) {} // Should be overloaded
+}
\ No newline at end of file
diff --git a/resources/javFiles/LambdaField.jav b/resources/bytecode/javFiles/LambdaField.jav
similarity index 100%
rename from resources/javFiles/LambdaField.jav
rename to resources/bytecode/javFiles/LambdaField.jav
diff --git a/resources/javFiles/LambdaRunnable.jav b/resources/bytecode/javFiles/LambdaRunnable.jav
similarity index 100%
rename from resources/javFiles/LambdaRunnable.jav
rename to resources/bytecode/javFiles/LambdaRunnable.jav
diff --git a/resources/javFiles/ListenerOverload.jav b/resources/bytecode/javFiles/ListenerOverload.jav
similarity index 100%
rename from resources/javFiles/ListenerOverload.jav
rename to resources/bytecode/javFiles/ListenerOverload.jav
diff --git a/resources/javFiles/Meth_Gen.jav b/resources/bytecode/javFiles/Meth_Gen.jav
similarity index 100%
rename from resources/javFiles/Meth_Gen.jav
rename to resources/bytecode/javFiles/Meth_Gen.jav
diff --git a/resources/javFiles/MethodCallGenerics.jav b/resources/bytecode/javFiles/MethodCallGenerics.jav
similarity index 100%
rename from resources/javFiles/MethodCallGenerics.jav
rename to resources/bytecode/javFiles/MethodCallGenerics.jav
diff --git a/resources/javFiles/MethodWildcardGen.jav b/resources/bytecode/javFiles/MethodWildcardGen.jav
similarity index 100%
rename from resources/javFiles/MethodWildcardGen.jav
rename to resources/bytecode/javFiles/MethodWildcardGen.jav
diff --git a/resources/javFiles/MethodsEasy.jav b/resources/bytecode/javFiles/MethodsEasy.jav
similarity index 100%
rename from resources/javFiles/MethodsEasy.jav
rename to resources/bytecode/javFiles/MethodsEasy.jav
diff --git a/resources/bytecode/javFiles/OL.jav b/resources/bytecode/javFiles/OL.jav
index 4eab848f..afeaa2f5 100644
--- a/resources/bytecode/javFiles/OL.jav
+++ b/resources/bytecode/javFiles/OL.jav
@@ -1,32 +1,15 @@
+import java.lang.Double;
import java.lang.String;
-import java.lang.Integer;
-import java.lang.Double;
-import java.lang.Boolean;
-//import java.util.Vector;
+import java.lang.Long;
-
-public class OL {
-
- java.lang.Double m(java.lang.Double x) { return x + x; }
- java.lang.Integer m(java.lang.Integer x) { return x + x; }
- java.lang.String m(java.lang.String x) { return x + x; }
- java.lang.Boolean m(Boolean x) { return x; }
-
-// if the class contains just this method, then correct BC will be generated.
-// But if another methods are contained then the generated BC is not correct
-// m(x) {
-// //x.add(1);
-// x.addAll(x);
-// return x;
-// }
-
+class OL {
+ m (x) { return x + x; }
}
-public class OLMain {
-
- main(x) {
+class OLMain {
+ main(x) {
var ol;
- ol = new OL();
- return ol.m(x);
- }
+ ol = new OL();
+ return ol.m(x);
+ }
}
diff --git a/resources/javFiles/Op1.jav b/resources/bytecode/javFiles/Op1.jav
similarity index 100%
rename from resources/javFiles/Op1.jav
rename to resources/bytecode/javFiles/Op1.jav
diff --git a/resources/bytecode/javFiles/OverloadPattern.jav b/resources/bytecode/javFiles/OverloadPattern.jav
new file mode 100644
index 00000000..f9bb0e55
--- /dev/null
+++ b/resources/bytecode/javFiles/OverloadPattern.jav
@@ -0,0 +1,50 @@
+import java.lang.Integer;
+import java.lang.Number;
+import java.lang.Float;
+
+record Point(Number x, Number y) {}
+
+public class OverloadPattern {
+ m(Point(Integer x, Integer y)) {
+ return x + y;
+ }
+
+ m(Point(Float x, Float y)) {
+ return x * y;
+ }
+
+ m(Integer x) {
+ return x;
+ }
+}
+
+/*
+public class OverloadPattern {
+ Integer m$Point$_$java$lang$Integer$_$java$lang$Integer$_$(Point point) {
+ var x = point.x();
+ var y = point.y();
+ return x + y;
+ }
+
+ Float m$Point$_$java$lang$Float$_$java$lang$Float$_$(Point point) {
+ var x = point.x();
+ var y = point.y();
+ return x * y;
+ }
+
+ Number m(Point point) {
+ switch(point) {
+ case Point(Integer x, Integer y) ->
+ m$Point$_$java$lang$Integer$_$java$lang$Integer$_$(point);
+ case Point(Float x, Float y) ->
+ m$Point$_$java$lang$Float$_$java$lang$Float$_$(point);
+ default -> throw new IllegalArgumentException();
+ }
+ }
+
+ Integer m(Integer x) {
+ return x;
+ }
+}
+
+*/
\ No newline at end of file
diff --git a/resources/javFiles/Package.jav b/resources/bytecode/javFiles/Package.jav
similarity index 100%
rename from resources/javFiles/Package.jav
rename to resources/bytecode/javFiles/Package.jav
diff --git a/resources/bytecode/javFiles/PairNoGenerics.jav b/resources/bytecode/javFiles/PairNoGenerics.jav
new file mode 100644
index 00000000..e69de29b
diff --git a/resources/bytecode/javFiles/RecordTest.jav b/resources/bytecode/javFiles/RecordTest.jav
new file mode 100644
index 00000000..c64c3d94
--- /dev/null
+++ b/resources/bytecode/javFiles/RecordTest.jav
@@ -0,0 +1,22 @@
+import java.lang.Integer;
+
+record Rec(Integer a, Integer b) {}
+
+/*public class Rec {
+ x; y;
+ Rec(Integer a, Integer b) {
+ x = a;
+ y = b;
+ }
+}*/
+
+public class RecordTest {
+ a = new Rec(10, 20);
+ b = new Rec(10, 20);
+ c = new Rec(20, 40);
+
+ doesEqual() { return a.equals(b); }
+ doesNotEqual() { return b.equals(c); }
+ hashCode() { return a.hashCode(); }
+ toString() { return a.toString(); }
+}
\ No newline at end of file
diff --git a/resources/javFiles/Subclass.jav b/resources/bytecode/javFiles/Subclass.jav
similarity index 100%
rename from resources/javFiles/Subclass.jav
rename to resources/bytecode/javFiles/Subclass.jav
diff --git a/resources/javFiles/Superclass.jav b/resources/bytecode/javFiles/Superclass.jav
similarity index 100%
rename from resources/javFiles/Superclass.jav
rename to resources/bytecode/javFiles/Superclass.jav
diff --git a/resources/bytecode/javFiles/Switch.jav b/resources/bytecode/javFiles/Switch.jav
new file mode 100644
index 00000000..9c0e741f
--- /dev/null
+++ b/resources/bytecode/javFiles/Switch.jav
@@ -0,0 +1,17 @@
+import java.lang.Integer;
+import java.lang.Object;
+import java.lang.Float;
+
+record Rec(Integer a, Object b) {}
+
+public class Switch {
+ main(o) {
+ return switch (o) {
+ case Rec(Integer a, Integer b) -> a + b;
+ case Rec(Integer a, Float b) -> a + 10;
+ case Rec(Integer a, Rec(Integer b, Integer c)) -> a + b + c;
+ case Integer i -> i;
+ default -> 0;
+ };
+ }
+}
\ No newline at end of file
diff --git a/resources/bytecode/javFiles/SwitchString.jav b/resources/bytecode/javFiles/SwitchString.jav
new file mode 100644
index 00000000..e8758c25
--- /dev/null
+++ b/resources/bytecode/javFiles/SwitchString.jav
@@ -0,0 +1,14 @@
+import java.lang.Integer;
+import java.lang.String;
+import java.lang.Object;
+
+public class SwitchString {
+ main(o) {
+ return switch (o) {
+ case "AaAaAa" -> 1; // These two have the same hash code!
+ case "AaAaBB" -> 2;
+ case "test", "TEST" -> 3;
+ default -> 4;
+ };
+ }
+}
\ No newline at end of file
diff --git a/resources/javFiles/Vector.jav b/resources/bytecode/javFiles/Vector.jav
similarity index 100%
rename from resources/javFiles/Vector.jav
rename to resources/bytecode/javFiles/Vector.jav
diff --git a/resources/javFiles/fc.jav b/resources/bytecode/javFiles/fc.jav
similarity index 100%
rename from resources/javFiles/fc.jav
rename to resources/bytecode/javFiles/fc.jav
diff --git a/resources/javFiles/test.jav b/resources/bytecode/javFiles/test.jav
similarity index 100%
rename from resources/javFiles/test.jav
rename to resources/bytecode/javFiles/test.jav
diff --git a/resources/javFiles/test1.jav b/resources/bytecode/javFiles/test1.jav
similarity index 100%
rename from resources/javFiles/test1.jav
rename to resources/bytecode/javFiles/test1.jav
diff --git a/resources/javFiles/EmptyMethod.jav b/resources/javFiles/EmptyMethod.jav
deleted file mode 100644
index dd28fc69..00000000
--- a/resources/javFiles/EmptyMethod.jav
+++ /dev/null
@@ -1,37 +0,0 @@
-public class EmptyMethod{
- static String s1 ="";
- String s2;
- public void m1(){
- //String s = "";
- System.out.println("test");
- //Integer ab = Math.abs(1);
- //Math.abs(1);
- //String lV = "local";
- //s1 = "1";
- //s1.concat("2");
- s2 = s1;
- //m2();
- Clazz i = new Clazz();
- Integer i = new Integer(1);
- }
-
- public void m2(){}
-}
-
-class Clazz{}
-/*
-public class EmptyMethod2{
- public static test = "5";
- public void m1(Integer i, String j, Boolean b){
- //String s = "";
- EmptyMethod em = new EmptyMethod();
- em.m1();
- em.s1 = "";
- //Integer ab = Math.abs(1);
- //Math.abs(1);
- //String lV = "local";
- //s1 = "1";
- //s1.concat("2");
- //s2 = s1;
- }
-}*/
\ No newline at end of file
diff --git a/resources/javFiles/Faculty.jav b/resources/javFiles/Faculty.jav
deleted file mode 100644
index ed201ff9..00000000
--- a/resources/javFiles/Faculty.jav
+++ /dev/null
@@ -1,16 +0,0 @@
-import java.lang.Integer;
-
-class Faculty {
- //fact;
-
- Integer mul(Integer x, Integer y) {
- return x;
- }
-
- m () {
- var fact = (Integer x) -> {
- return mul(x, fact.apply(x));
- };
- return fact;
- }
-}
\ No newline at end of file
diff --git a/resources/javFiles/Generics.jav b/resources/javFiles/Generics.jav
deleted file mode 100644
index dd7b4eba..00000000
--- a/resources/javFiles/Generics.jav
+++ /dev/null
@@ -1,22 +0,0 @@
-import java.lang.String;
-
-class Generics {
- // A mt1(A a, B b){
- B mt1(B a, B b){
- return mt1(a, a);
- }
-}
-
-class Test {
- methode(String s){
- return new Generics().mt1(s,s);
- }
-}
-
-/*
-Problem:
-auto test = new List();
-auto test2 = new List();
-... //code, welcher möglicherweise test und test2 vertauscht
-test.add("hallo");
-*/
\ No newline at end of file
diff --git a/resources/javFiles/IfTest.jav b/resources/javFiles/IfTest.jav
deleted file mode 100644
index 88885561..00000000
--- a/resources/javFiles/IfTest.jav
+++ /dev/null
@@ -1,14 +0,0 @@
-import java.lang.Integer;
-import java.lang.Boolean;
-import java.lang.Object;
-
-public class IfTest {
- Object m1(b) {
- Integer i;
- if(b) {
- return i;
- }else{
- return b;
- }
- }
-}
\ No newline at end of file
diff --git a/resources/javFiles/Import.jav b/resources/javFiles/Import.jav
deleted file mode 100644
index 2fc3a8b3..00000000
--- a/resources/javFiles/Import.jav
+++ /dev/null
@@ -1,8 +0,0 @@
-import java.util.Vector;
-
-class Import {
- void methode(){
- var v;
- v.add(v);
- }
-}
\ No newline at end of file
diff --git a/resources/javFiles/Lambda.jav b/resources/javFiles/Lambda.jav
deleted file mode 100644
index 296fd7ef..00000000
--- a/resources/javFiles/Lambda.jav
+++ /dev/null
@@ -1,12 +0,0 @@
-
-class Apply { }
-
-public class Lambda {
-
- m () {
- var lam1 = (x) -> {
- return x;
- };
- return lam1.apply(new Apply());
- }
-}
diff --git a/resources/javFiles/Lambda2.jav b/resources/javFiles/Lambda2.jav
deleted file mode 100644
index cf1e910b..00000000
--- a/resources/javFiles/Lambda2.jav
+++ /dev/null
@@ -1,33 +0,0 @@
-import java.lang.String;
-
-public class Lambda2
-{
- public static void main(List args){
- var listOfStrings = new List();
- var listOfObjects;
- listOfObjects = map(listOfStrings, (a) -> a);
-}
-
-public map(a , b){
- b.apply(a);
- return a;
-}
-
-/*
-public static List map(List input, Function func) {
- List output;
- output = new List();
- output.add(func.apply(input.get()));
- return output;
-}
-*/
-}
-
-class List{
- A get();
- void add(A);
-}
-
-class Function{
- B apply(A a);
-}
\ No newline at end of file
diff --git a/resources/javFiles/Lambda3.jav b/resources/javFiles/Lambda3.jav
deleted file mode 100644
index 9e22f302..00000000
--- a/resources/javFiles/Lambda3.jav
+++ /dev/null
@@ -1,24 +0,0 @@
-import java.lang.String;
-
-public class Lambda2
-{
- /*
- public static List map(List extends A> input,
- Function super A, ? extends A> func){
- input.add(func.apply(input.get()));
- }
- */
- public map(input,func){
- input.add(func.apply(input.get()));
- return map(new List(), func);
- }
-}
-
-class List{
- A get();
- void add(A);
-}
-
-class Function{
- B apply(A a);
-}
\ No newline at end of file
diff --git a/resources/javFiles/Matrix.jav b/resources/javFiles/Matrix.jav
deleted file mode 100644
index 5e1eac08..00000000
--- a/resources/javFiles/Matrix.jav
+++ /dev/null
@@ -1,28 +0,0 @@
-import java.util.Vector;
-import java.lang.Integer;
-
-class Matrix extends Vector> {
- Integer mul1(Integer x, Integer y) { return x;}
- Integer add1(Integer x, Integer y) { return x;}
- mul(m) {
- var ret = new Matrix();
- var i = 0;
- while(i < size()) {
- var v1 = this.elementAt(i);
- var v2 = new Vector();
- var j = 0;
- while(j < v1.size()) {
- var erg = 0;
- var k = 0;
- while(k < v1.size()) {
- erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
- //erg = add1(erg, mul1(v1.elementAt(k),
- // m.elementAt(k).elementAt(j)));
- k++; }
- v2.addElement(new Integer(erg));
- j++; }
- ret.addElement(v2);
- i++; }
- return ret;
- }
-}
diff --git a/resources/javFiles/Methods.jav b/resources/javFiles/Methods.jav
deleted file mode 100644
index e45d9830..00000000
--- a/resources/javFiles/Methods.jav
+++ /dev/null
@@ -1,17 +0,0 @@
-
-class Methods {
- mt4(a,b,c) { return a.add(b).sub(c) ; }
-
- mt1(a) {return a;}
-
- mt2(a) {return a.f; }
-
- mt3(a) {return a.add(); }
-}
-
-class Test {
- java.lang.Object f;
- add(){}
- add(b){return b;}
- sub(b){}
-}
\ No newline at end of file
diff --git a/resources/javFiles/OL.jav b/resources/javFiles/OL.jav
deleted file mode 100644
index 0a3f82ec..00000000
--- a/resources/javFiles/OL.jav
+++ /dev/null
@@ -1,15 +0,0 @@
-import java.lang.Double;
-import java.lang.String;
-import java.lang.Long;
-
-class OL {
- m (x) { return x + x; }
-}
-
-class OLMain {
- main(x) {
- var ol;
- ol = new OL();
- return ol.m(x);
- }
-}
\ No newline at end of file
diff --git a/resources/javFiles/Sorting.jav b/resources/javFiles/Sorting.jav
deleted file mode 100644
index e5897914..00000000
--- a/resources/javFiles/Sorting.jav
+++ /dev/null
@@ -1,15 +0,0 @@
-import java.util.List;
-import java.util.Collection;
-
-class Sorting{
- void merge(a, b){
- a.addAll(b);
- return a;
- }
-
- sort(in){
- var firstHalf = in;
- var secondHalf = in;
- return merge(sort(firstHalf), sort(secondHalf));
- }
-}
\ No newline at end of file
diff --git a/resources/javFiles/mathStruc.jav b/resources/javFiles/mathStruc.jav
deleted file mode 100644
index c8518e5d..00000000
--- a/resources/javFiles/mathStruc.jav
+++ /dev/null
@@ -1,8 +0,0 @@
-class MathStruc {
-
- A model;
-
- innerOp = o -> ms -> new MathStruc(o.apply(this.model, ms.model));
-
- MathStruc(A m) { model=m; }
- }
\ No newline at end of file
diff --git a/resources/javFiles/packageTest/Gen.jav b/resources/javFiles/packageTest/Gen.jav
deleted file mode 100644
index 3b58b188..00000000
--- a/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/resources/javFiles/packageTest/OLMain.jav b/resources/javFiles/packageTest/OLMain.jav
deleted file mode 100644
index 0cdb0b4f..00000000
--- a/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/resources/javFiles/packageTest/OLOneFile.jav b/resources/javFiles/packageTest/OLOneFile.jav
deleted file mode 100644
index eb865d61..00000000
--- a/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/resources/javFiles/packageTest/OLTest.txt b/resources/javFiles/packageTest/OLTest.txt
deleted file mode 100644
index d91b58d7..00000000
--- a/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/resources/javFiles/packageTest/OLextends.jav b/resources/javFiles/packageTest/OLextends.jav
deleted file mode 100644
index b3c055df..00000000
--- a/resources/javFiles/packageTest/OLextends.jav
+++ /dev/null
@@ -1,7 +0,0 @@
-import de.test.OL;
-
-
-public class OLextends extends OL {
-
-
-}
diff --git a/resources/javFiles/packageTest/Pair2.jav b/resources/javFiles/packageTest/Pair2.jav
deleted file mode 100644
index d62474ea..00000000
--- a/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/resources/javFiles/packageTest/Test.jav b/resources/javFiles/packageTest/Test.jav
deleted file mode 100644
index 2f6429a1..00000000
--- a/resources/javFiles/packageTest/Test.jav
+++ /dev/null
@@ -1,3 +0,0 @@
-
-public class Test{
-}
diff --git a/resources/javFiles/packageTest/UseOLMain.java b/resources/javFiles/packageTest/UseOLMain.java
deleted file mode 100644
index 2d7d6fd8..00000000
--- a/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/resources/javFiles/packageTest/de/test/ImportTest.jav b/resources/javFiles/packageTest/de/test/ImportTest.jav
deleted file mode 100644
index 58b6fc0b..00000000
--- a/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/resources/javFiles/packageTest/de/test/ImportTest2.jav b/resources/javFiles/packageTest/de/test/ImportTest2.jav
deleted file mode 100644
index 3526abc8..00000000
--- a/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/resources/javFiles/packageTest/de/test/ImportTestDefault.jav b/resources/javFiles/packageTest/de/test/ImportTestDefault.jav
deleted file mode 100644
index ecd8d7c5..00000000
--- a/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/resources/javFiles/packageTest/de/test/OL.jav b/resources/javFiles/packageTest/de/test/OL.jav
deleted file mode 100644
index 7f1ba512..00000000
--- a/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/resources/javFiles/packageTest/de/test/Pair.jav b/resources/javFiles/packageTest/de/test/Pair.jav
deleted file mode 100644
index dbde6636..00000000
--- a/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/resources/javFiles/packageTest/de/test/TestClass.jav b/resources/javFiles/packageTest/de/test/TestClass.jav
deleted file mode 100644
index 6681b36a..00000000
--- a/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/resources/javFiles/packageTest/de/test/ToImport.jav b/resources/javFiles/packageTest/de/test/ToImport.jav
deleted file mode 100644
index 3afdba54..00000000
--- a/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/resources/javFiles/packageTest/de/test/mathStruc.jav b/resources/javFiles/packageTest/de/test/mathStruc.jav
deleted file mode 100644
index 28db5db8..00000000
--- a/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/resources/javFiles/packageTest/de/test/mathStrucVector.jav b/resources/javFiles/packageTest/de/test/mathStrucVector.jav
deleted file mode 100644
index fe6d6055..00000000
--- a/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/resources/javFiles/packageTest/de/test/output/de/test/mathStrucVectoruse.java b/resources/javFiles/packageTest/de/test/output/de/test/mathStrucVectoruse.java
deleted file mode 100644
index 54b9e45b..00000000
--- a/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/resources/javFiles/packageTest/de/test/output/mathStrucVectoruse.java b/resources/javFiles/packageTest/de/test/output/mathStrucVectoruse.java
deleted file mode 100644
index 9a9b2e75..00000000
--- a/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/resources/javFiles/packageTest/de/test/packageNameTestWrongPackage.jav b/resources/javFiles/packageTest/de/test/packageNameTestWrongPackage.jav
deleted file mode 100644
index a86d22aa..00000000
--- a/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/resources/javFiles/packageTest/de/test/subpackage1/Test1.jav b/resources/javFiles/packageTest/de/test/subpackage1/Test1.jav
deleted file mode 100644
index a7011169..00000000
--- a/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/resources/javFiles/packageTest/de/test/subpackage1/ToImport2.jav b/resources/javFiles/packageTest/de/test/subpackage1/ToImport2.jav
deleted file mode 100644
index bcc67b95..00000000
--- a/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/resources/javFiles/packageTest/de/test/subpackage2/Test2.jav b/resources/javFiles/packageTest/de/test/subpackage2/Test2.jav
deleted file mode 100644
index 750f7612..00000000
--- a/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/resources/javFiles/packageTest/de/test/subpackage2/ToImport3.jav b/resources/javFiles/packageTest/de/test/subpackage2/ToImport3.jav
deleted file mode 100644
index 3efd8fff..00000000
--- a/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/resources/javFiles/packageTest/de/test/vectorAdd.jav b/resources/javFiles/packageTest/de/test/vectorAdd.jav
deleted file mode 100644
index 727a83a9..00000000
--- a/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/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/resources/syntaxtreegenerator/BinaryInMeth.ast b/resources/syntaxtreegenerator/BinaryInMeth.ast
new file mode 100644
index 00000000..5bb1379c
--- /dev/null
+++ b/resources/syntaxtreegenerator/BinaryInMeth.ast
@@ -0,0 +1,22 @@
+class BinaryInMeth {
+
+BinaryInMeth(){
+ super(());
+ }
+ TPH CMNB m(TPH CMNC a){
+ return ++a;
+ }
+
+ TPH CMNF m2(TPH CMNG a, TPH CMNH b){
+ return this.m Signature: [TPH CMNK, TPH CMNL](a op b);
+ }
+
+ TPH CMNP m3(TPH CMNQ a){
+ return this.m Signature: [TPH CMNT, TPH CMNU](++a);
+ }
+
+ BinaryInMeth(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Box.ast b/resources/syntaxtreegenerator/Box.ast
new file mode 100644
index 00000000..1bc437b3
--- /dev/null
+++ b/resources/syntaxtreegenerator/Box.ast
@@ -0,0 +1,25 @@
+class B {
+
+B(){
+ super(());
+ }
+ B(){
+ super(());
+ }
+
+}class Box_Main {
+
+Box_Main(){
+ super(());
+ }
+ TPH T m(TPH U b){
+ b.m Signature: [TPH W, TPH X](new Box_Main());
+ b.m Signature: [TPH AB, TPH AC](new B());
+ return;
+ }
+
+ Box_Main(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/ClassGenLam.ast b/resources/syntaxtreegenerator/ClassGenLam.ast
new file mode 100644
index 00000000..30b43454
--- /dev/null
+++ b/resources/syntaxtreegenerator/ClassGenLam.ast
@@ -0,0 +1,14 @@
+class ClassGenLam {
+
+ TPH HWDB lam;
+ClassGenLam(){
+ super(());
+ this.lam = (TPH HWDC x) -> {
+ return x;
+ };
+ }
+ ClassGenLam(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Cycle.ast b/resources/syntaxtreegenerator/Cycle.ast
new file mode 100644
index 00000000..18b435a8
--- /dev/null
+++ b/resources/syntaxtreegenerator/Cycle.ast
@@ -0,0 +1,16 @@
+class Cycle {
+
+Cycle(){
+ super(());
+ }
+ TPH GGXG m(TPH GGXH x, TPH GGXI y){
+ y = x;
+ x = y;
+ return;
+ }
+
+ Cycle(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Fac.ast b/resources/syntaxtreegenerator/Fac.ast
new file mode 100644
index 00000000..b15ecdd5
--- /dev/null
+++ b/resources/syntaxtreegenerator/Fac.ast
@@ -0,0 +1,22 @@
+class Fac {
+
+Fac(){
+ super(());
+ }
+ TPH BSTE getFac(TPH BSTF n){
+ TPH BSTG res;
+ res = 1;
+ TPH BSTI i;
+ i = 1;
+ while(i op n){
+ res = res op i;
+ i++;
+ };
+ return res;
+ }
+
+ Fac(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Faculty.ast b/resources/syntaxtreegenerator/Faculty.ast
new file mode 100644
index 00000000..66c777a8
--- /dev/null
+++ b/resources/syntaxtreegenerator/Faculty.ast
@@ -0,0 +1,25 @@
+class Faculty {
+
+ TPH DDAL fact;
+Faculty(){
+ super(());
+ }
+ TPH DDBK getFact(java.lang.Integer x){
+ return this.fact.apply Signature: [TPH DDBM, TPH DDBN](x);
+ }
+
+ Faculty(){
+ super(());
+ this.fact = (TPH DDAO x) -> {
+ if(x op 1)
+ {
+ return 1;
+ }
+ else
+ {
+ return x op this.fact.apply Signature: [TPH DDAW, TPH DDAX](x op 1);
+ };
+ };
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Field.ast b/resources/syntaxtreegenerator/Field.ast
new file mode 100644
index 00000000..43ffa1a6
--- /dev/null
+++ b/resources/syntaxtreegenerator/Field.ast
@@ -0,0 +1,16 @@
+class Field {
+
+ TPH JBCG x;
+Field(){
+ super(());
+ this.x = 5;
+ }
+ TPH JBCJ m(){
+ return this.x;
+ }
+
+ Field(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/FieldTph2.ast b/resources/syntaxtreegenerator/FieldTph2.ast
new file mode 100644
index 00000000..23c7c163
--- /dev/null
+++ b/resources/syntaxtreegenerator/FieldTph2.ast
@@ -0,0 +1,21 @@
+class FieldTph2 {
+
+ TPH DJBG a;
+FieldTph2(){
+ super(());
+ }
+ TPH DJBH m(TPH DJBI b){
+ b = this.a;
+ return b;
+ }
+
+ TPH DJBL m2(TPH DJBM c){
+ this.a = c;
+ return;
+ }
+
+ FieldTph2(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/FieldTphConsMeth.ast b/resources/syntaxtreegenerator/FieldTphConsMeth.ast
new file mode 100644
index 00000000..9ada6011
--- /dev/null
+++ b/resources/syntaxtreegenerator/FieldTphConsMeth.ast
@@ -0,0 +1,27 @@
+class FieldTphConsMeth {
+
+ TPH AINS a;
+FieldTphConsMeth(){
+ super(());
+ }
+ TPH AIOE id(TPH AIOF b){
+ return b;
+ }
+
+ TPH AIOH setA(TPH AIOI x){
+ this.a = x;
+ return this.a;
+ }
+
+ TPH AIOM m(TPH AION x, TPH AIOO y){
+ x = this.id Signature: [TPH AIOQ, TPH AIOR](y);
+ return;
+ }
+
+ FieldTphConsMeth(TPH AINU c){
+ super(());
+ this.a = this.id Signature: [TPH AINX, TPH AINY](c);
+ return;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/FieldTphMMeth.ast b/resources/syntaxtreegenerator/FieldTphMMeth.ast
new file mode 100644
index 00000000..3a0cacd1
--- /dev/null
+++ b/resources/syntaxtreegenerator/FieldTphMMeth.ast
@@ -0,0 +1,33 @@
+class FieldTphMMeth {
+
+ TPH HBWQ a;
+FieldTphMMeth(){
+ super(());
+ }
+ TPH HBXG m(TPH HBXH b, TPH HBXI d, TPH HBXJ e){
+ if(e)
+ {
+ return this.m3 Signature: [TPH HBXL, TPH HBXM](b);
+ }
+ else
+ {
+ return this.m3 Signature: [TPH HBXR, TPH HBXS](d);
+ };
+ }
+
+ TPH HBXY m2(TPH HBXZ b){
+ this.a = this.m3 Signature: [TPH HBYC, TPH HBYD](b);
+ return;
+ }
+
+ TPH HBYH m3(TPH HBYI b){
+ return b;
+ }
+
+ FieldTphMMeth(TPH HBWS c, TPH HBWT d, TPH HBWU e){
+ super(());
+ this.a = this.m Signature: [TPH HBWX, TPH HBWY, TPH HBWZ, TPH HBXA](c, d, e);
+ return;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Gen.ast b/resources/syntaxtreegenerator/Gen.ast
new file mode 100644
index 00000000..20f54843
--- /dev/null
+++ b/resources/syntaxtreegenerator/Gen.ast
@@ -0,0 +1,14 @@
+class Gen {
+
+Gen(){
+ super(());
+ }
+ java.util.Vector m(java.util.Vector v){
+ return v;
+ }
+
+ Gen(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Id.ast b/resources/syntaxtreegenerator/Id.ast
new file mode 100644
index 00000000..4b375d27
--- /dev/null
+++ b/resources/syntaxtreegenerator/Id.ast
@@ -0,0 +1,18 @@
+class Id {
+
+ TPH BDGF id2;
+Id(){
+ super(());
+ this.id2 = (TPH BDGG x) -> {
+ return x;
+ };
+ }
+ TPH BDGM id3(TPH BDGN x){
+ return this.id2.apply Signature: [TPH BDGP, TPH BDGQ](x);
+ }
+
+ Id(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Inf.ast b/resources/syntaxtreegenerator/Inf.ast
new file mode 100644
index 00000000..5425c25d
--- /dev/null
+++ b/resources/syntaxtreegenerator/Inf.ast
@@ -0,0 +1,28 @@
+class Inf {
+
+Inf(){
+ super(());
+ }
+ TPH KYAM m(TPH KYAN x, TPH KYAO y, TPH KYAP a){
+ TPH KYAQ z;
+ TPH KYAR v;
+ TPH KYAS w;
+ TPH KYAT b;
+ y = x;
+ z = x;
+ v = y;
+ w = y;
+ y = a;
+ b = a;
+ TPH KYAU c;
+ TPH KYAV d;
+ c = v;
+ d = v;
+ return;
+ }
+
+ Inf(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Instanceof.ast b/resources/syntaxtreegenerator/Instanceof.ast
new file mode 100644
index 00000000..29d07548
--- /dev/null
+++ b/resources/syntaxtreegenerator/Instanceof.ast
@@ -0,0 +1,44 @@
+class Instanceof {
+
+Instanceof(){
+ super(());
+ }
+ void checkInstanceof(){
+ TPH a;
+ a = 4;
+ return a instanceof java.lang.Integer;
+ }
+
+ void checkInstanceOfWithPattern(){
+ TPH b;
+ b = 4.0;
+ if(b instanceof d)
+ {
+ return d;
+ }
+ else
+ {
+ return Kein Double;
+ };
+ }
+
+ void checkInstanceOfWithGuardedPattern(){
+ TPH obj;
+ obj = test;
+ TPH flag;
+ if(obj instanceof s op s.length Signature: [TPH]() op 5)
+ {
+ flag = s.contains Signature: [TPH, TPH](jdk);
+ };
+ return;
+ }
+
+ java.lang.Boolean equals(java.lang.Object o){
+ return o instanceof other op x op other.x op y op other.y;
+ }
+
+ Instanceof(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/KompTph.ast b/resources/syntaxtreegenerator/KompTph.ast
new file mode 100644
index 00000000..0cde6326
--- /dev/null
+++ b/resources/syntaxtreegenerator/KompTph.ast
@@ -0,0 +1,26 @@
+class KompTph {
+
+KompTph(){
+ super(());
+ }
+ TPH EOGX m(TPH EOGY a, TPH EOGZ b, TPH EOHA c){
+ TPH EOHB d;
+ d = a;
+ TPH EOHC e;
+ e = a;
+ a = b;
+ c = b;
+ this.m2 Signature: [TPH EOHE, TPH EOHF, TPH EOHG](a, c);
+ return;
+ }
+
+ TPH EOHK m2(TPH EOHL a, TPH EOHM b){
+ this.m Signature: [TPH EOHO, TPH EOHP, TPH EOHQ, TPH EOHR](a, a, b);
+ return;
+ }
+
+ KompTph(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Lambda.ast b/resources/syntaxtreegenerator/Lambda.ast
new file mode 100644
index 00000000..1cdc8f14
--- /dev/null
+++ b/resources/syntaxtreegenerator/Lambda.ast
@@ -0,0 +1,18 @@
+class Lambda {
+
+Lambda(){
+ super(());
+ }
+ TPH KIZQ m(){
+ TPH KIZR lam1;
+ lam1 = (TPH KIZS x) -> {
+ return x;
+ };
+ return lam1;
+ }
+
+ Lambda(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/LambdaCapture.ast b/resources/syntaxtreegenerator/LambdaCapture.ast
new file mode 100644
index 00000000..de4944bf
--- /dev/null
+++ b/resources/syntaxtreegenerator/LambdaCapture.ast
@@ -0,0 +1,18 @@
+class LambdaCapture {
+
+ java.lang.Integer i;
+ TPH BIMD f;
+LambdaCapture(){
+ super(());
+ this.i = 8;
+ }
+ LambdaCapture(){
+ super(());
+ java.lang.Integer w;
+ w = 7;
+ this.f = (TPH BIMH j) -> {
+ return w op this.i;
+ };
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Matrix.ast b/resources/syntaxtreegenerator/Matrix.ast
new file mode 100644
index 00000000..f4779af2
--- /dev/null
+++ b/resources/syntaxtreegenerator/Matrix.ast
@@ -0,0 +1,52 @@
+class Matrix {
+
+Matrix(){
+ super(());
+ }
+ TPH SBB mul(TPH SBC m){
+ TPH SBD ret;
+ ret = new Matrix();
+ TPH SBF i;
+ i = 0;
+ while(i op this.size Signature: [TPH SBJ]()){
+ TPH SBM v1;
+ v1 = this.elementAt Signature: [TPH SBO, TPH SBP](i);
+ TPH SBS v2;
+ v2 = new java.util.Vector();
+ TPH SBU j;
+ j = 0;
+ while(j op v1.size Signature: [TPH SBX]()){
+ TPH SCA erg;
+ erg = 0;
+ TPH SCC k;
+ k = 0;
+ while(k op v1.size Signature: [TPH SCF]()){
+ erg = erg op v1.elementAt Signature: [TPH SCI, TPH SCJ](k) op m.elementAt Signature: [TPH SCM, TPH SCN](k).elementAt Signature: [TPH SCQ, TPH SCR](j);
+ k++;
+ };
+ v2.addElement Signature: [TPH SCZ, TPH SDA](erg);
+ j++;
+ };
+ ret.addElement Signature: [TPH SDG, TPH SDH](v2);
+ i++;
+ };
+ return ret;
+ }
+
+ Matrix(){
+ super(());
+ return;
+ }
+
+ Matrix(TPH SAF vv){
+ super(());
+ java.lang.Integer i;
+ i = 0;
+ while(i op vv.size Signature: [TPH SAI]()){
+ this.add Signature: [TPH SAQ, TPH SAR](vv.elementAt Signature: [TPH SAM, TPH SAN](i));
+ i = i op 1;
+ };
+ return;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/MatrixOP.ast b/resources/syntaxtreegenerator/MatrixOP.ast
new file mode 100644
index 00000000..4ea4d5e0
--- /dev/null
+++ b/resources/syntaxtreegenerator/MatrixOP.ast
@@ -0,0 +1,52 @@
+class MatrixOP {
+
+ TPH JGDT mul;
+MatrixOP(){
+ super(());
+ this.mul = (TPH JGDU m1, TPH JGDV m2) -> {
+ TPH JGDW ret;
+ ret = new MatrixOP();
+ TPH JGDY i;
+ i = 0;
+ while(i op m1.size Signature: [TPH JGEB]()){
+ TPH JGEE v1;
+ v1 = m1.elementAt Signature: [TPH JGEF, TPH JGEG](i);
+ TPH JGEJ v2;
+ v2 = new java.util.Vector();
+ TPH JGEL j;
+ j = 0;
+ while(j op v1.size Signature: [TPH JGEO]()){
+ TPH JGER erg;
+ erg = 0;
+ TPH JGET k;
+ k = 0;
+ while(k op v1.size Signature: [TPH JGEW]()){
+ erg = erg op v1.elementAt Signature: [TPH JGEZ, TPH JGFA](k) op m2.elementAt Signature: [TPH JGFD, TPH JGFE](k).elementAt Signature: [TPH JGFH, TPH JGFI](j);
+ k++;
+ };
+ v2.addElement Signature: [TPH JGFQ, TPH JGFR](erg);
+ j++;
+ };
+ ret.addElement Signature: [TPH JGFX, TPH JGFY](v2);
+ i++;
+ };
+ return ret;
+ };
+ }
+ MatrixOP(){
+ super(());
+ return;
+ }
+
+ MatrixOP(TPH JGGP vv){
+ super(());
+ java.lang.Integer i;
+ i = 0;
+ while(i op vv.size Signature: [TPH JGGS]()){
+ this.add Signature: [TPH JGHA, TPH JGHB](vv.elementAt Signature: [TPH JGGW, TPH JGGX](i));
+ i = i op 1;
+ };
+ return;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Merge.ast b/resources/syntaxtreegenerator/Merge.ast
new file mode 100644
index 00000000..c3632d11
--- /dev/null
+++ b/resources/syntaxtreegenerator/Merge.ast
@@ -0,0 +1,23 @@
+class Merge {
+
+Merge(){
+ super(());
+ }
+ TPH JQYM merge(TPH JQYN a, TPH JQYO b){
+ a.addAll Signature: [TPH JQYP, TPH JQYQ](b);
+ return a;
+ }
+
+ TPH JQYU sort(TPH JQYV in){
+ TPH JQYW firstHalf;
+ firstHalf = in.subList Signature: [TPH JQYZ, TPH JQZA, TPH JQZB](1, 2);
+ TPH JQZE secondHalf;
+ secondHalf = in.subList Signature: [TPH JQZH, TPH JQZI, TPH JQZJ](1, 2);
+ return this.merge Signature: [TPH JQZX, TPH JQZY, TPH JQZZ](this.sort Signature: [TPH JQZO, TPH JQZP](firstHalf), this.sort Signature: [TPH JQZT, TPH JQZU](secondHalf));
+ }
+
+ Merge(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/OL.ast b/resources/syntaxtreegenerator/OL.ast
new file mode 100644
index 00000000..96ea1505
--- /dev/null
+++ b/resources/syntaxtreegenerator/OL.ast
@@ -0,0 +1,41 @@
+class OL {
+
+OL(){
+ super(());
+ }
+ java.lang.Double m(java.lang.Double x){
+ return x op x;
+ }
+
+ java.lang.Integer m(java.lang.Integer x){
+ return x op x;
+ }
+
+ java.lang.String m(java.lang.String x){
+ return x op x;
+ }
+
+ java.lang.Boolean m(java.lang.Boolean x){
+ return x;
+ }
+
+ OL(){
+ super(());
+ }
+
+}class OLMain {
+
+OLMain(){
+ super(());
+ }
+ TPH BYOF main(TPH BYOG x){
+ TPH BYOH ol;
+ ol = new OL();
+ return ol.m Signature: [TPH BYOJ, TPH BYOK](x);
+ }
+
+ OLMain(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/OLFun.ast b/resources/syntaxtreegenerator/OLFun.ast
new file mode 100644
index 00000000..4f5e08f1
--- /dev/null
+++ b/resources/syntaxtreegenerator/OLFun.ast
@@ -0,0 +1,22 @@
+class OLFun {
+
+OLFun(){
+ super(());
+ }
+ TPH JXJR m(TPH JXJS f, TPH JXJT x){
+ x = f.apply Signature: [TPH JXJV, TPH JXJW](x op x);
+ return x;
+ }
+
+ TPH JXKA m2(TPH JXKB y){
+ this.m Signature: [TPH JXKK, TPH JXKL, TPH JXKM]((TPH JXKD x) -> {
+ return x op 2;
+ }, y);
+ return;
+ }
+
+ OLFun(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/OLFun2.ast b/resources/syntaxtreegenerator/OLFun2.ast
new file mode 100644
index 00000000..57415e3d
--- /dev/null
+++ b/resources/syntaxtreegenerator/OLFun2.ast
@@ -0,0 +1,16 @@
+class OLFun2 {
+
+ TPH CTXA x;
+OLFun2(){
+ super(());
+ }
+ TPH CTXB m(TPH CTXC f){
+ this.x = f.apply Signature: [TPH CTXH, TPH CTXI](this.x op this.x);
+ return;
+ }
+
+ OLFun2(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Overloading.ast b/resources/syntaxtreegenerator/Overloading.ast
new file mode 100644
index 00000000..29fd0bb1
--- /dev/null
+++ b/resources/syntaxtreegenerator/Overloading.ast
@@ -0,0 +1,31 @@
+class Overloading {
+
+Overloading(){
+ super(());
+ }
+ TPH N test(TPH O x){
+ return x.methode Signature: [TPH P]();
+ }
+
+ TPH T methode(){
+ return Overloading;
+ }
+
+ Overloading(){
+ super(());
+ }
+
+}class Overloading2 {
+
+Overloading2(){
+ super(());
+ }
+ TPH AO methode(){
+ return Overloading2;
+ }
+
+ Overloading2(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Pair.ast b/resources/syntaxtreegenerator/Pair.ast
new file mode 100644
index 00000000..67a01833
--- /dev/null
+++ b/resources/syntaxtreegenerator/Pair.ast
@@ -0,0 +1,20 @@
+class Pair {
+
+ U a;
+ T b;
+Pair(){
+ super(());
+ }
+ TPH IURS make(TPH IURT x){
+ TPH IURU ret;
+ ret = new Pair();
+ ret.a = x.elementAt Signature: [TPH IUSA, TPH IUSB](0);
+ ret.b = x.elementAt Signature: [TPH IUSG, TPH IUSH](1);
+ return ret;
+ }
+
+ Pair(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/PatternMatching.ast b/resources/syntaxtreegenerator/PatternMatching.ast
new file mode 100644
index 00000000..41a24534
--- /dev/null
+++ b/resources/syntaxtreegenerator/PatternMatching.ast
@@ -0,0 +1,120 @@
+class Point {
+
+ java.lang.Integer x;
+ java.lang.Integer y;
+Point(java.lang.Integer x, java.lang.Integer y){
+ super(());
+ this.x = x;
+ this.y = y;
+ }
+ java.lang.Integer x(){
+ return this.x;
+ }
+
+ java.lang.Integer y(){
+ return this.y;
+ }
+
+ Point(java.lang.Integer x, java.lang.Integer y){
+ super(());
+ this.x = x;
+ this.y = y;
+ }
+
+}class Shape {
+
+}class ColoredPoint {
+
+ Point pt;
+ java.lang.String color;
+ColoredPoint(Point pt, java.lang.String color){
+ super(());
+ this.pt = pt;
+ this.color = color;
+ }
+ Point pt(){
+ return this.pt;
+ }
+
+ java.lang.String color(){
+ return this.color;
+ }
+
+ ColoredPoint(Point pt, java.lang.String color){
+ super(());
+ this.pt = pt;
+ this.color = color;
+ }
+
+}class Rectangle {
+
+ ColoredPoint upperLeft;
+ ColoredPoint lowerRight;
+Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight){
+ super(());
+ this.upperLeft = upperLeft;
+ this.lowerRight = lowerRight;
+ }
+ ColoredPoint upperLeft(){
+ return this.upperLeft;
+ }
+
+ ColoredPoint lowerRight(){
+ return this.lowerRight;
+ }
+
+ Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight){
+ super(());
+ this.upperLeft = upperLeft;
+ this.lowerRight = lowerRight;
+ }
+
+}class Color {
+
+Color(){
+ super(());
+ }
+ Color(){
+ super(());
+ }
+
+}class Blue {
+
+Blue(){
+ super(());
+ }
+ Blue(){
+ super(());
+ }
+
+}class Red {
+
+Red(){
+ super(());
+ }
+ Red(){
+ super(());
+ }
+
+}class PatternMatching {
+
+PatternMatching(){
+ super(());
+ }
+ void printColorOfUpperLeftPoint(Shape shape){
+ switch(shape){
+ case Rectangle(ColoredPoint(Point pt, java.lang.String color), ColoredPoint lowerRight):
+ System.out.println Signature: [TPH, TPH](x: op pt.x Signature: [TPH]() op / color: op color op / lowerRight: op lowerRight);
+
+ default:
+ System.out.println Signature: [TPH, TPH](not a rectangle);
+
+ };
+ return;
+ }
+
+ PatternMatching(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Plus.ast b/resources/syntaxtreegenerator/Plus.ast
new file mode 100644
index 00000000..c395f007
--- /dev/null
+++ b/resources/syntaxtreegenerator/Plus.ast
@@ -0,0 +1,14 @@
+class Plus {
+
+Plus(){
+ super(());
+ }
+ TPH ACHZ m(TPH ACIA a, TPH ACIB b){
+ return a op b;
+ }
+
+ Plus(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Record.ast b/resources/syntaxtreegenerator/Record.ast
new file mode 100644
index 00000000..26d95878
--- /dev/null
+++ b/resources/syntaxtreegenerator/Record.ast
@@ -0,0 +1,47 @@
+class Point {
+
+ TPH x;
+ TPH y;
+Point(TPH x, TPH y){
+ super(());
+ this.x = x;
+ this.y = y;
+ }
+ TPH x(){
+ return this.x;
+ }
+
+ TPH y(){
+ return this.y;
+ }
+
+ Point(TPH x, TPH y){
+ super(());
+ this.x = x;
+ this.y = y;
+ }
+
+}class Line {
+
+ TPH pt1;
+ TPH pt2;
+Line(TPH pt1, TPH pt2){
+ super(());
+ this.pt1 = pt1;
+ this.pt2 = pt2;
+ }
+ TPH pt1(){
+ return this.pt1;
+ }
+
+ TPH pt2(){
+ return this.pt2;
+ }
+
+ Line(TPH pt1, TPH pt2){
+ super(());
+ this.pt1 = pt1;
+ this.pt2 = pt2;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/RelOps.ast b/resources/syntaxtreegenerator/RelOps.ast
new file mode 100644
index 00000000..4b8fa1dd
--- /dev/null
+++ b/resources/syntaxtreegenerator/RelOps.ast
@@ -0,0 +1,14 @@
+class RelOps {
+
+RelOps(){
+ super(());
+ }
+ TPH IPBY m(TPH IPBZ a, TPH IPCA b){
+ return a op b;
+ }
+
+ RelOps(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Scalar.ast b/resources/syntaxtreegenerator/Scalar.ast
new file mode 100644
index 00000000..fddde3ad
--- /dev/null
+++ b/resources/syntaxtreegenerator/Scalar.ast
@@ -0,0 +1,29 @@
+class Scalar {
+
+Scalar(){
+ super(());
+ }
+ TPH KOXT mul(TPH KOXU v){
+ TPH KOXV ret;
+ ret = 0;
+ TPH KOXX i;
+ i = 0;
+ while(i op this.size Signature: [TPH KOYB]()){
+ ret = ret op this.elementAt Signature: [TPH KOYF, TPH KOYG](i) op v.elementAt Signature: [TPH KOYJ, TPH KOYK](i);
+ i = i op 1;
+ };
+ return ret;
+ }
+
+ Scalar(TPH KOWX v){
+ super(());
+ java.lang.Integer i;
+ i = 0;
+ while(i op v.size Signature: [TPH KOXA]()){
+ this.add Signature: [TPH KOXI, TPH KOXJ](v.elementAt Signature: [TPH KOXE, TPH KOXF](i));
+ i = i op 1;
+ };
+ return;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Sealed.ast b/resources/syntaxtreegenerator/Sealed.ast
new file mode 100644
index 00000000..24423ca0
--- /dev/null
+++ b/resources/syntaxtreegenerator/Sealed.ast
@@ -0,0 +1,144 @@
+class Shape {
+
+Shape(){
+ super(());
+ }
+ Shape(){
+ super(());
+ }
+
+}class Circle {
+
+Circle(){
+ super(());
+ }
+ Circle(){
+ super(());
+ }
+
+}class Rectangle {
+
+Rectangle(){
+ super(());
+ }
+ Rectangle(){
+ super(());
+ }
+
+}class TransparentRectangle {
+
+TransparentRectangle(){
+ super(());
+ }
+ TransparentRectangle(){
+ super(());
+ }
+
+}class FilledRectangle {
+
+FilledRectangle(){
+ super(());
+ }
+ FilledRectangle(){
+ super(());
+ }
+
+}class Square {
+
+Square(){
+ super(());
+ }
+ Square(){
+ super(());
+ }
+
+}class WeirdShape {
+
+WeirdShape(){
+ super(());
+ }
+ WeirdShape(){
+ super(());
+ }
+
+}class Expr {
+
+}class ConstantExpr {
+
+ java.lang.Integer i;
+ConstantExpr(java.lang.Integer i){
+ super(());
+ this.i = i;
+ }
+ java.lang.Integer i(){
+ return this.i;
+ }
+
+ ConstantExpr(java.lang.Integer i){
+ super(());
+ this.i = i;
+ }
+
+}class PlusExpr {
+
+ Expr a;
+ Expr b;
+PlusExpr(Expr a, Expr b){
+ super(());
+ this.a = a;
+ this.b = b;
+ }
+ Expr a(){
+ return this.a;
+ }
+
+ Expr b(){
+ return this.b;
+ }
+
+ PlusExpr(Expr a, Expr b){
+ super(());
+ this.a = a;
+ this.b = b;
+ }
+
+}class TimesExpr {
+
+ Expr a;
+ Expr b;
+TimesExpr(Expr a, Expr b){
+ super(());
+ this.a = a;
+ this.b = b;
+ }
+ Expr a(){
+ return this.a;
+ }
+
+ Expr b(){
+ return this.b;
+ }
+
+ TimesExpr(Expr a, Expr b){
+ super(());
+ this.a = a;
+ this.b = b;
+ }
+
+}class NegExpr {
+
+ Expr e;
+NegExpr(Expr e){
+ super(());
+ this.e = e;
+ }
+ Expr e(){
+ return this.e;
+ }
+
+ NegExpr(Expr e){
+ super(());
+ this.e = e;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/SimpleCycle.ast b/resources/syntaxtreegenerator/SimpleCycle.ast
new file mode 100644
index 00000000..771757a9
--- /dev/null
+++ b/resources/syntaxtreegenerator/SimpleCycle.ast
@@ -0,0 +1,18 @@
+class SimpleCycle {
+
+SimpleCycle(){
+ super(());
+ }
+ TPH ETMJ m(){
+ TPH ETMK g;
+ TPH ETML h;
+ g = h;
+ h = g;
+ return;
+ }
+
+ SimpleCycle(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Sorting.ast b/resources/syntaxtreegenerator/Sorting.ast
new file mode 100644
index 00000000..979d2687
--- /dev/null
+++ b/resources/syntaxtreegenerator/Sorting.ast
@@ -0,0 +1,23 @@
+class Sorting {
+
+Sorting(){
+ super(());
+ }
+ TPH JNN merge(TPH JNO a, TPH JNP b){
+ a.addAll Signature: [TPH JNQ, TPH JNR](b);
+ return a;
+ }
+
+ TPH JNV sort(TPH JNW in){
+ TPH JNX firstHalf;
+ firstHalf = in;
+ TPH JNY secondHalf;
+ secondHalf = in;
+ return this.merge Signature: [TPH JOK, TPH JOL, TPH JOM](this.sort Signature: [TPH JOB, TPH JOC](firstHalf), this.sort Signature: [TPH JOG, TPH JOH](secondHalf));
+ }
+
+ Sorting(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/SubMatrix.ast b/resources/syntaxtreegenerator/SubMatrix.ast
new file mode 100644
index 00000000..61ab2f22
--- /dev/null
+++ b/resources/syntaxtreegenerator/SubMatrix.ast
@@ -0,0 +1,26 @@
+class Matrix2 {
+
+Matrix2(){
+ super(());
+ }
+ Matrix2(){
+ super(());
+ }
+
+}class SubMatrix {
+
+SubMatrix(){
+ super(());
+ }
+ TPH DOFK m(){
+ java.util.Vector v;
+ v = new java.util.Vector();
+ v.add Signature: [TPH DOFN, TPH DOFO](1);
+ return;
+ }
+
+ SubMatrix(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Switch.ast b/resources/syntaxtreegenerator/Switch.ast
new file mode 100644
index 00000000..f6dfd8fb
--- /dev/null
+++ b/resources/syntaxtreegenerator/Switch.ast
@@ -0,0 +1,96 @@
+class SwitchStatement {
+
+SwitchStatement(){
+ super(());
+ }
+ TPH switchStandard(){
+ str = SwitchMe;
+ switch(str){
+ case java.lang.String s:
+ return true;
+
+ default:
+ return false;
+
+ };
+ }
+
+ TPH switchInteger(){
+ i = 5;
+ switch(i){
+ case java.lang.Integer j:
+ case java.lang.String s:
+ i = 6;
+ break;
+
+ default:
+ i = 0;
+ break;
+
+ };
+ return i op 0;
+ }
+
+ TPH guardedPattern(){
+ TPH i;
+ i = 1;
+ switch(i){
+ case java.lang.Integer j:
+ return true;
+
+ default:
+ return false;
+
+ };
+ }
+
+ TPH recordPattern(java.lang.Object obj){
+ switch(obj){
+ case Coordinates(java.lang.Double lat, java.lang.Double lon):
+ return true;
+
+ default:
+ return false;
+
+ };
+ }
+
+ SwitchStatement(){
+ super(());
+ }
+
+}class SwitchExpression {
+
+ java.lang.Integer x;
+ java.lang.Integer y;
+SwitchExpression(java.lang.Integer x, java.lang.Integer y){
+ super(());
+ this.x = x;
+ this.y = y;
+ }
+ java.lang.Integer x(){
+ return this.x;
+ }
+
+ java.lang.Integer y(){
+ return this.y;
+ }
+
+ java.lang.Boolean switchStandard(TPH str){
+ return switch(str){
+ case java.lang.String s:
+ yield true;
+
+ default:
+ yield false;
+
+ };
+ }
+
+ SwitchExpression(java.lang.Integer x, java.lang.Integer y){
+ super(());
+ this.x = x;
+ this.y = y;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/TXGenerics.ast b/resources/syntaxtreegenerator/TXGenerics.ast
new file mode 100644
index 00000000..1c4a0eab
--- /dev/null
+++ b/resources/syntaxtreegenerator/TXGenerics.ast
@@ -0,0 +1,19 @@
+class TXGenerics {
+
+ TPH GLEG a;
+ TPH GLEH b;
+TXGenerics(){
+ super(());
+ }
+ TPH GLEI test(){
+ TPH GLEJ c;
+ c = new Cycle();
+ c.m Signature: [TPH GLEN, TPH GLEO, TPH GLEP](this.a, this.b);
+ return;
+ }
+
+ TXGenerics(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph.ast b/resources/syntaxtreegenerator/Tph.ast
new file mode 100644
index 00000000..939f9a57
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph.ast
@@ -0,0 +1,20 @@
+class Tph {
+
+Tph(){
+ super(());
+ }
+ TPH BNOP m(TPH BNOQ a, TPH BNOR b){
+ TPH BNOS c;
+ c = this.m2 Signature: [TPH BNOU, TPH BNOV](b);
+ return a;
+ }
+
+ TPH BNOZ m2(TPH BNPA b){
+ return b;
+ }
+
+ Tph(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph2.ast b/resources/syntaxtreegenerator/Tph2.ast
new file mode 100644
index 00000000..f138866a
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph2.ast
@@ -0,0 +1,18 @@
+class Tph2 {
+
+ TPH FGYW id;
+Tph2(){
+ super(());
+ this.id = (TPH FGYX x) -> {
+ return x;
+ };
+ }
+ TPH FGZD id3(TPH FGZE x){
+ return this.id.apply Signature: [TPH FGZG, TPH FGZH](x);
+ }
+
+ Tph2(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph3.ast b/resources/syntaxtreegenerator/Tph3.ast
new file mode 100644
index 00000000..cfbf0bc3
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph3.ast
@@ -0,0 +1,21 @@
+class Tph3 {
+
+Tph3(){
+ super(());
+ }
+ TPH FMEJ m1(TPH FMEK x, TPH FMEL y){
+ this.m2 Signature: [TPH FMEN, TPH FMEO](x);
+ x = y;
+ return;
+ }
+
+ TPH FMES m2(TPH FMET y){
+ this.m1 Signature: [TPH FMEV, TPH FMEW, TPH FMEX](y, y);
+ return;
+ }
+
+ Tph3(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph4.ast b/resources/syntaxtreegenerator/Tph4.ast
new file mode 100644
index 00000000..2ed453b8
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph4.ast
@@ -0,0 +1,22 @@
+class Tph4 {
+
+Tph4(){
+ super(());
+ }
+ TPH FRJD m(TPH FRJE a, TPH FRJF b){
+ TPH FRJG c;
+ c = this.m2 Signature: [TPH FRJI, TPH FRJJ](b);
+ TPH FRJM d;
+ d = this.m2 Signature: [TPH FRJO, TPH FRJP](c);
+ return d;
+ }
+
+ TPH FRJT m2(TPH FRJU b){
+ return b;
+ }
+
+ Tph4(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph5.ast b/resources/syntaxtreegenerator/Tph5.ast
new file mode 100644
index 00000000..dfdda9d1
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph5.ast
@@ -0,0 +1,19 @@
+class Tph5 {
+
+Tph5(){
+ super(());
+ }
+ TPH FWNY m(TPH FWNZ x, TPH FWOA y){
+ x = this.m2 Signature: [TPH FWOC, TPH FWOD](y);
+ return;
+ }
+
+ TPH FWOH m2(TPH FWOI y){
+ return y;
+ }
+
+ Tph5(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph6.ast b/resources/syntaxtreegenerator/Tph6.ast
new file mode 100644
index 00000000..eba65bc1
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph6.ast
@@ -0,0 +1,21 @@
+class Tph6 {
+
+Tph6(){
+ super(());
+ }
+ TPH GBSM m(TPH GBSN x, TPH GBSO y){
+ TPH GBSP c;
+ c = this.m2 Signature: [TPH GBSR, TPH GBSS](y);
+ c = this.m2 Signature: [TPH GBSW, TPH GBSX](x);
+ return;
+ }
+
+ TPH GBTB m2(TPH GBTC y){
+ return y;
+ }
+
+ Tph6(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Tph7.ast b/resources/syntaxtreegenerator/Tph7.ast
new file mode 100644
index 00000000..8d2ebe4b
--- /dev/null
+++ b/resources/syntaxtreegenerator/Tph7.ast
@@ -0,0 +1,20 @@
+class Tph7 {
+
+Tph7(){
+ super(());
+ }
+ TPH GQRI m(TPH GQRJ a, TPH GQRK b){
+ TPH GQRL c;
+ c = this.m2 Signature: [TPH GQRN, TPH GQRO](b);
+ return this.m2 Signature: [TPH GQRS, TPH GQRT](b);
+ }
+
+ TPH GQRX m2(TPH GQRY b){
+ return b;
+ }
+
+ Tph7(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/TypedID.ast b/resources/syntaxtreegenerator/TypedID.ast
new file mode 100644
index 00000000..0a56861d
--- /dev/null
+++ b/resources/syntaxtreegenerator/TypedID.ast
@@ -0,0 +1,22 @@
+class TypedID {
+
+ TPH GVWK lam;
+TypedID(){
+ super(());
+ this.lam = (TPH GVWL x) -> {
+ return x;
+ };
+ }
+ TPH GVWR id(TPH GVWS b){
+ return b;
+ }
+
+ TPH GVWU m(){
+ return this.lam;
+ }
+
+ TypedID(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/VectorAdd.ast b/resources/syntaxtreegenerator/VectorAdd.ast
new file mode 100644
index 00000000..992c9c1e
--- /dev/null
+++ b/resources/syntaxtreegenerator/VectorAdd.ast
@@ -0,0 +1,31 @@
+class VectorAdd {
+
+VectorAdd(){
+ super(());
+ }
+ TPH EXVJ vectorAdd(TPH EXVK v1, TPH EXVL v2){
+ TPH EXVM i;
+ i = 0;
+ v1 = new java.util.Vector();
+ TPH EXVP erg;
+ erg = new java.util.Vector();
+ while(i op v1.size Signature: [TPH EXVT]()){
+ erg.addElement Signature: [TPH EXWF, TPH EXWG](v1.elementAt Signature: [TPH EXVW, TPH EXVX](i) op v2.elementAt Signature: [TPH EXWA, TPH EXWB](i));
+ i++;
+ };
+ return erg;
+ }
+
+ TPH EXWN m(TPH EXWO x, TPH EXWP y, TPH EXWQ z){
+ x = new java.util.Vector();
+ y = new java.util.Vector();
+ x.add Signature: [TPH EXWU, TPH EXWV](1);
+ y.add Signature: [TPH EXWY, TPH EXWZ](2);
+ return z.addAll Signature: [TPH EXXC, TPH EXXD](x);
+ }
+
+ VectorAdd(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/VectorSuper.ast b/resources/syntaxtreegenerator/VectorSuper.ast
new file mode 100644
index 00000000..ec2faf35
--- /dev/null
+++ b/resources/syntaxtreegenerator/VectorSuper.ast
@@ -0,0 +1,17 @@
+class VectorSuper {
+
+VectorSuper(){
+ super(());
+ }
+ TPH HPGR m(TPH HPGS x){
+ java.lang.Integer y;
+ y = 1;
+ x.addElement Signature: [TPH HPGU, TPH HPGV](y);
+ return;
+ }
+
+ VectorSuper(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/Y.ast b/resources/syntaxtreegenerator/Y.ast
new file mode 100644
index 00000000..6a736191
--- /dev/null
+++ b/resources/syntaxtreegenerator/Y.ast
@@ -0,0 +1,16 @@
+class Y {
+
+ TPH IBFH y;
+Y(){
+ super(());
+ }
+ Y(){
+ super(());
+ this.y = (TPH IBFK f) -> {
+ return (TPH IBFL t) -> {
+ return f.apply Signature: [TPH IBFR, TPH IBFS](this.y.apply Signature: [TPH IBFN, TPH IBFO](f)).apply Signature: [TPH IBFV, TPH IBFW](t);
+ };
+ };
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/applyLambda.ast b/resources/syntaxtreegenerator/applyLambda.ast
new file mode 100644
index 00000000..504dddec
--- /dev/null
+++ b/resources/syntaxtreegenerator/applyLambda.ast
@@ -0,0 +1,27 @@
+class Apply {
+
+Apply(){
+ super(());
+ }
+ Apply(){
+ super(());
+ }
+
+}class applyLambda {
+
+applyLambda(){
+ super(());
+ }
+ TPH ASWH m(){
+ TPH ASWI lam1;
+ lam1 = (TPH ASWJ x) -> {
+ return x;
+ };
+ return lam1.apply Signature: [TPH ASWP, TPH ASWQ](new Apply());
+ }
+
+ applyLambda(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/javFiles/Instanceof.jav b/resources/syntaxtreegenerator/javFiles/Instanceof.jav
new file mode 100644
index 00000000..c9a2d0b3
--- /dev/null
+++ b/resources/syntaxtreegenerator/javFiles/Instanceof.jav
@@ -0,0 +1,36 @@
+import java.lang.Integer;
+import java.lang.Double;
+import java.lang.String;
+import java.lang.Object;
+
+public class Instanceof{
+ void checkInstanceof() {
+ var a = 4;
+ return (a instanceof java.lang.Integer);
+ }
+
+ void checkInstanceOfWithPattern(){
+ var b = 4.0;
+ if(b instanceof java.lang.Double d){
+ return d;
+ }else{
+ return "Kein Double";
+ }
+ }
+
+ void checkInstanceOfWithGuardedPattern(){
+ var obj = "test";
+ var flag;
+ if (obj instanceof String s && s.length() > 5) {
+ flag = s.contains("jdk");
+ }
+ }
+
+ record Point(int x, int y){ }
+
+ boolean equals(Object o) {
+ return (o instanceof Point other)
+ && x == other.x
+ && y == other.y;
+ }
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/javFiles/PatternMatching.jav b/resources/syntaxtreegenerator/javFiles/PatternMatching.jav
new file mode 100644
index 00000000..d256ac0a
--- /dev/null
+++ b/resources/syntaxtreegenerator/javFiles/PatternMatching.jav
@@ -0,0 +1,19 @@
+import java.lang.String;
+
+record Point(int x, int y) {}
+interface Shape {}
+record ColoredPoint(Point pt, String color) {}
+record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) implements Shape {}
+sealed class Color permits Blue, Red {}
+class Blue extends Color {}
+class Red extends Color {}
+
+class PatternMatching {
+void printColorOfUpperLeftPoint(Shape shape)
+{
+ switch (shape) {
+ case Rectangle(ColoredPoint(Point pt, String color), ColoredPoint lowerRight) -> System.out.println("x: " + pt.x() + " / color: " + color + " / lowerRight: " + lowerRight);
+ default -> System.out.println("not a rectangle");
+ };
+}
+}
diff --git a/resources/syntaxtreegenerator/javFiles/Record.jav b/resources/syntaxtreegenerator/javFiles/Record.jav
new file mode 100644
index 00000000..31edc83d
--- /dev/null
+++ b/resources/syntaxtreegenerator/javFiles/Record.jav
@@ -0,0 +1,5 @@
+// Simple records
+record Point(x, y){ }
+
+//Combination of records
+record Line(pt1, pt2){}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/javFiles/Sealed.jav b/resources/syntaxtreegenerator/javFiles/Sealed.jav
new file mode 100644
index 00000000..b7a68e5a
--- /dev/null
+++ b/resources/syntaxtreegenerator/javFiles/Sealed.jav
@@ -0,0 +1,21 @@
+public abstract sealed class Shape
+ permits Circle, Rectangle, Square, WeirdShape { }
+
+public final class Circle extends Shape { }
+
+public sealed class Rectangle extends Shape
+ permits TransparentRectangle, FilledRectangle { }
+public final class TransparentRectangle extends Rectangle { }
+public final class FilledRectangle extends Rectangle { }
+
+public final class Square extends Shape { }
+
+public non-sealed class WeirdShape extends Shape { }
+
+public sealed interface Expr
+ permits ConstantExpr, PlusExpr, TimesExpr, NegExpr { }
+
+public record ConstantExpr(int i) implements Expr { }
+public record PlusExpr(Expr a, Expr b) implements Expr { }
+public record TimesExpr(Expr a, Expr b) implements Expr { }
+public record NegExpr(Expr e) implements Expr { }
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/javFiles/Switch.jav b/resources/syntaxtreegenerator/javFiles/Switch.jav
new file mode 100644
index 00000000..6c0f68aa
--- /dev/null
+++ b/resources/syntaxtreegenerator/javFiles/Switch.jav
@@ -0,0 +1,52 @@
+import java.lang.Integer;
+import java.lang.Boolean;
+import java.lang.String;
+import java.lang.Object;
+
+class SwitchStatement {
+
+ switchStandard(){
+ str = "SwitchMe";
+ switch(str){
+ case String s: return true;
+ default: return false;
+ }
+ }
+
+ switchInteger(){
+ i = 5;
+ switch(i){
+ case Integer j:
+ case String s: i = 6; break;
+ default: i = 0; break;
+ }
+ return (i==0);
+ }
+
+ guardedPattern(){
+ var i = 1;
+ switch(i){
+ case Integer j && j == 1: return true;
+ default: return false;
+ }
+ }
+
+ record Coordinates(double x, double y) {}
+
+ recordPattern(Object obj){
+ switch(obj){
+ case Coordinates(double lat, double lon): return true;
+ default: return false;
+ }
+ }
+}
+
+record SwitchExpression(int x, int y){
+
+ boolean switchStandard(str){
+ return switch(str){
+ case String s -> yield true;
+ default -> yield false;
+ };
+ }
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/mathStruc.ast b/resources/syntaxtreegenerator/mathStruc.ast
new file mode 100644
index 00000000..85318505
--- /dev/null
+++ b/resources/syntaxtreegenerator/mathStruc.ast
@@ -0,0 +1,19 @@
+class mathStruc {
+
+ TPH IHHZ model;
+ TPH IHIA innerOp;
+mathStruc(){
+ super(());
+ this.innerOp = (TPH IHIB o) -> {
+ return (TPH IHIC ms) -> {
+ return new mathStruc(o.apply Signature: [TPH IHIF, TPH IHIG, TPH IHIH](this.model, ms.model));
+ };
+ };
+ }
+ mathStruc(TPH IHIW m){
+ super(());
+ this.model = m;
+ return;
+ }
+
+}
\ No newline at end of file
diff --git a/resources/syntaxtreegenerator/mathStrucInteger.ast b/resources/syntaxtreegenerator/mathStrucInteger.ast
new file mode 100644
index 00000000..c36d537a
--- /dev/null
+++ b/resources/syntaxtreegenerator/mathStrucInteger.ast
@@ -0,0 +1,38 @@
+class mathStrucInteger {
+
+ TPH EBJW model;
+ TPH EBJX innerOp;
+mathStrucInteger(){
+ super(());
+ this.innerOp = (TPH EBJY o) -> {
+ return (TPH EBJZ ms) -> {
+ return new mathStrucInteger(o.apply Signature: [TPH EBKC, TPH EBKD, TPH EBKE](this.model, ms.model));
+ };
+ };
+ }
+ mathStrucInteger(TPH EBKT m){
+ super(());
+ this.model = m;
+ return;
+ }
+
+}class mathStrucIntegerUse {
+
+mathStrucIntegerUse(){
+ super(());
+ }
+ TPH EBLO main(){
+ TPH EBLP ms;
+ ms = new mathStrucInteger(2);
+ TPH EBLT ms2;
+ ms2 = ms.innerOp.apply Signature: [TPH EBMD, TPH EBME]((TPH EBLV x, TPH EBLW y) -> {
+ return x op y;
+ }).apply Signature: [TPH EBMH, TPH EBMI](ms);
+ return ms2;
+ }
+
+ mathStrucIntegerUse(){
+ super(());
+ }
+
+}
\ No newline at end of file
diff --git a/resources/testBytecode/generatedBC/.gitignore b/resources/testBytecode/generatedBC/.gitignore
deleted file mode 100644
index 5e7d2734..00000000
--- a/resources/testBytecode/generatedBC/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-# Ignore everything in this directory
-*
-# Except this file
-!.gitignore
diff --git a/resources/testBytecode/public b/resources/testBytecode/public
deleted file mode 100644
index 8b137891..00000000
--- a/resources/testBytecode/public
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4 b/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4
new file mode 100644
index 00000000..7be32dad
--- /dev/null
+++ b/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Lexer.g4
@@ -0,0 +1,241 @@
+/*
+ [The "BSD licence"]
+ Copyright (c) 2013 Terence Parr, Sam Harwell
+ Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8)
+ Copyright (c) 2021 Michał Lorek (upgrade to Java 11)
+ Copyright (c) 2022 Michał Lorek (upgrade to Java 17)
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+lexer grammar Java17Lexer;
+
+// Keywords
+
+ABSTRACT: 'abstract';
+ASSERT: 'assert';
+BOOLEAN: 'boolean';
+BREAK: 'break';
+BYTE: 'byte';
+CASE: 'case';
+CATCH: 'catch';
+CHAR: 'char';
+CLASS: 'class';
+CONST: 'const';
+CONTINUE: 'continue';
+DEFAULT: 'default';
+DO: 'do';
+DOUBLE: 'double';
+ELSE: 'else';
+ENUM: 'enum';
+EXTENDS: 'extends';
+FINAL: 'final';
+FINALLY: 'finally';
+FLOAT: 'float';
+FOR: 'for';
+IF: 'if';
+GOTO: 'goto';
+IMPLEMENTS: 'implements';
+IMPORT: 'import';
+INSTANCEOF: 'instanceof';
+INT: 'int';
+INTERFACE: 'interface';
+LONG: 'long';
+NATIVE: 'native';
+NEW: 'new';
+PACKAGE: 'package';
+PRIVATE: 'private';
+PROTECTED: 'protected';
+PUBLIC: 'public';
+RETURN: 'return';
+SHORT: 'short';
+STATIC: 'static';
+STRICTFP: 'strictfp';
+SUPER: 'super';
+SWITCH: 'switch';
+SYNCHRONIZED: 'synchronized';
+THIS: 'this';
+THROW: 'throw';
+THROWS: 'throws';
+TRANSIENT: 'transient';
+TRY: 'try';
+VOID: 'void';
+VOLATILE: 'volatile';
+WHILE: 'while';
+
+// Module related keywords
+MODULE: 'module';
+OPEN: 'open';
+REQUIRES: 'requires';
+EXPORTS: 'exports';
+OPENS: 'opens';
+TO: 'to';
+USES: 'uses';
+PROVIDES: 'provides';
+WITH: 'with';
+TRANSITIVE: 'transitive';
+
+// Local Variable Type Inference
+VAR: 'var'; // reserved type name
+
+// Switch Expressions
+YIELD: 'yield'; // reserved type name from Java 14
+
+// Records
+RECORD: 'record';
+
+// Sealed Classes
+SEALED: 'sealed';
+PERMITS: 'permits';
+NON_SEALED: 'non-sealed';
+
+// Literals
+
+DECIMAL_LITERAL: ('0' | [1-9] (Digits? | '_'+ Digits)) [lL]?;
+HEX_LITERAL: '0' [xX] [0-9a-fA-F] ([0-9a-fA-F_]* [0-9a-fA-F])? [lL]?;
+OCT_LITERAL: '0' '_'* [0-7] ([0-7_]* [0-7])? [lL]?;
+BINARY_LITERAL: '0' [bB] [01] ([01_]* [01])? [lL]?;
+
+FLOAT_LITERAL: (Digits '.' Digits? | '.' Digits) ExponentPart? [fFdD]?
+ | Digits (ExponentPart [fFdD]? | [fFdD])
+ ;
+
+HEX_FLOAT_LITERAL: '0' [xX] (HexDigits '.'? | HexDigits? '.' HexDigits) [pP] [+-]? Digits [fFdD]?;
+
+BOOL_LITERAL: 'true'
+ | 'false'
+ ;
+
+CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\'';
+
+STRING_LITERAL: '"' (~["\\\r\n] | EscapeSequence)* '"';
+
+TEXT_BLOCK: '"""' [ \t]* [\r\n] (. | EscapeSequence)*? '"""';
+
+NULL_LITERAL: 'null';
+
+// Separators
+
+LPAREN: '(';
+RPAREN: ')';
+LBRACE: '{';
+RBRACE: '}';
+LBRACK: '[';
+RBRACK: ']';
+SEMI: ';';
+COMMA: ',';
+DOT: '.';
+
+// Operators
+
+ASSIGN: '=';
+GT: '>';
+LT: '<';
+BANG: '!';
+TILDE: '~';
+QUESTION: '?';
+COLON: ':';
+EQUAL: '==';
+LE: '<=';
+GE: '>=';
+NOTEQUAL: '!=';
+AND: '&&';
+OR: '||';
+INC: '++';
+DEC: '--';
+ADD: '+';
+SUB: '-';
+MUL: '*';
+DIV: '/';
+BITAND: '&';
+BITOR: '|';
+CARET: '^';
+MOD: '%';
+
+ADD_ASSIGN: '+=';
+SUB_ASSIGN: '-=';
+MUL_ASSIGN: '*=';
+DIV_ASSIGN: '/=';
+AND_ASSIGN: '&=';
+OR_ASSIGN: '|=';
+XOR_ASSIGN: '^=';
+MOD_ASSIGN: '%=';
+LSHIFT_ASSIGN: '<<=';
+RSHIFT_ASSIGN: '>>=';
+URSHIFT_ASSIGN: '>>>=';
+
+// Java 8 tokens
+
+ARROW: '->';
+COLONCOLON: '::';
+
+// Additional symbols not defined in the lexical specification
+
+AT: '@';
+ELLIPSIS: '...';
+
+// Whitespace and comments
+
+WS: [ \t\r\n\u000C]+ -> channel(HIDDEN);
+COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
+LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN);
+
+// Identifiers
+
+IDENTIFIER: Letter LetterOrDigit*;
+
+// Fragment rules
+
+fragment ExponentPart
+ : [eE] [+-]? Digits
+ ;
+
+fragment EscapeSequence
+ : '\\' [btnfr"'\\]
+ | '\\' ([0-3]? [0-7])? [0-7]
+ | '\\' 'u'+ HexDigit HexDigit HexDigit HexDigit
+ ;
+
+fragment HexDigits
+ : HexDigit ((HexDigit | '_')* HexDigit)?
+ ;
+
+fragment HexDigit
+ : [0-9a-fA-F]
+ ;
+
+fragment Digits
+ : [0-9] ([0-9_]* [0-9])?
+ ;
+
+fragment LetterOrDigit
+ : Letter
+ | [0-9]
+ ;
+
+fragment Letter
+ : [a-zA-Z$_] // these are the "java letters" below 0x7F
+ | ~[\u0000-\u007F\uD800-\uDBFF] // covers all characters above 0x7F which are not a surrogate
+ | [\uD800-\uDBFF] [\uDC00-\uDFFF] // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF
+ ;
\ No newline at end of file
diff --git a/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4 b/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4
new file mode 100644
index 00000000..ce974a10
--- /dev/null
+++ b/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4
@@ -0,0 +1,811 @@
+/*
+ [The "BSD licence"]
+ Copyright (c) 2013 Terence Parr, Sam Harwell
+ Copyright (c) 2017 Ivan Kochurkin (upgrade to Java 8)
+ Copyright (c) 2021 Michał Lorek (upgrade to Java 11)
+ Copyright (c) 2022 Michał Lorek (upgrade to Java 17)
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+parser grammar Java17Parser;
+
+options { tokenVocab=Java17Lexer; }
+
+sourceFile
+ : packageDeclaration? importDeclaration* classOrInterface* # srcfile
+ | moduleDeclaration EOF # moduledecl
+ ;
+
+packageDeclaration
+ : annotation* PACKAGE qualifiedName ';'
+ ;
+
+importDeclaration
+ : IMPORT STATIC? qualifiedName ('.' '*')? ';'
+ ;
+
+classOrInterface
+ : classOrInterfaceModifier*
+ (classDeclaration | enumDeclaration | interfaceDeclaration | annotationTypeDeclaration | recordDeclaration) # classorinterfacedecl
+ | ';' # noclassorinterface
+ ;
+
+modifier
+ : classOrInterfaceModifier
+ | NATIVE
+ | SYNCHRONIZED
+ | TRANSIENT
+ | VOLATILE
+ ;
+
+classOrInterfaceModifier
+ : annotation
+ | PUBLIC
+ | PROTECTED
+ | PRIVATE
+ | STATIC
+ | ABSTRACT
+ | FINAL // FINAL for class only -- does not apply to interfaces
+ | STRICTFP
+ | SEALED // Java17
+ | NON_SEALED // Java17
+ ;
+
+variableModifier
+ : FINAL # finalvarmod
+ | annotation # annotationvarmod
+ ;
+
+classDeclaration
+ : CLASS identifier genericDeclarationList?
+ (EXTENDS typeType)?
+ (IMPLEMENTS typeList)?
+ (PERMITS typeList)? // Java17
+ classBody
+ ;
+
+genericDeclarationList
+ : '<' genericTypeVar (',' genericTypeVar)* '>'
+ ;
+
+genericTypeVar
+ : annotation* identifier ((EXTENDS | IMPLEMENTS) annotation* typeBound)?
+ ;
+
+typeBound
+ : typeType ('&' typeType)*
+ ;
+
+enumDeclaration
+ : ENUM identifier (IMPLEMENTS typeList)? '{' enumConstants? ','? enumBodyDeclarations? '}'
+ ;
+
+enumConstants
+ : enumConstant (',' enumConstant)*
+ ;
+
+enumConstant
+ : annotation* identifier arguments? classBody?
+ ;
+
+enumBodyDeclarations
+ : ';' classBodyDeclaration*
+ ;
+
+interfaceDeclaration
+ : INTERFACE identifier genericDeclarationList? (EXTENDS typeList)? (PERMITS typeList)? interfaceBody
+ ;
+
+classBody
+ : '{' classBodyDeclaration* '}'
+ ;
+
+interfaceBody
+ : '{' interfaceBodyDeclaration* '}'
+ ;
+
+classBodyDeclaration
+ : ';' # emptyclassbody
+ | STATIC? block # classblock
+ | modifier* memberDeclaration # memberdecl
+ ;
+
+memberDeclaration
+ : classOrInterface # memberclassorinterface
+ | fieldDeclaration # memberfield
+ | method # membermethod
+ | constructor # memberconstructor
+ ;
+
+method
+ : methodDeclaration # methoddecl
+ | genericMethodDeclaration # genericmethod
+ ;
+
+/* We use rule this even for void methods which cannot have [] after parameters.
+ This simplifies grammar and we can consider void to be a type, which
+ renders the [] matching as a context-sensitive issue or a semantic check
+ for invalid return type after parsing.
+ */
+methodDeclaration
+ : methodHeader
+ (THROWS exceptionList)?
+ methodBody
+ ;
+
+methodHeader
+ : refType? identifier formalParameters ('[' ']')*
+ ;
+
+methodBody
+ : block # methodblock
+ | ';' # emptymethod
+ ;
+
+refType
+ : typeType # refType2
+ | VOID # refvoid
+ ;
+
+genericMethodDeclaration
+ : genericDeclarationList methodDeclaration
+ ;
+
+constructor
+ : genericConstructorDeclaration # genericconstructor
+ | constructorDeclaration # constructordecl
+ ;
+
+genericConstructorDeclaration
+ : genericDeclarationList constructorDeclaration
+ ;
+
+constructorDeclaration
+ : identifier formalParameters (THROWS exceptionList)? constructorBody=block
+ ;
+
+fieldDeclaration
+ : typeType? variableDeclarators ';'
+ ;
+
+interfaceBodyDeclaration
+ : modifier* interfaceMemberDeclaration # interfacemember
+ | ';' # emptyinterface
+ ;
+
+interfaceMemberDeclaration
+ : constDeclaration # interfaceconst
+ | interfaceMethodDeclaration # interfacemethod
+ | genericInterfaceMethodDeclaration # genericinterfacemethod
+ | classOrInterface # subclassorinterface
+ ;
+
+constDeclaration
+ : typeType? constantDeclarator (',' constantDeclarator)* ';'
+ ;
+
+constantDeclarator
+ : identifier ('[' ']')* '=' variableInitializer
+ ;
+
+// Early versions of Java allows brackets after the method name, eg.
+// public int[] return2DArray() [] { ... }
+// is the same as
+// public int[][] return2DArray() { ... }
+interfaceMethodDeclaration
+ : interfaceMethodModifier* interfaceCommonBodyDeclaration
+ ;
+
+// Java8
+interfaceMethodModifier
+ : annotation
+ | PUBLIC
+ | ABSTRACT
+ | DEFAULT
+ | STATIC
+ | STRICTFP
+ ;
+
+genericInterfaceMethodDeclaration
+ : interfaceMethodModifier* genericDeclarationList interfaceCommonBodyDeclaration
+ ;
+
+interfaceCommonBodyDeclaration
+ : annotation* refType? identifier formalParameters ('[' ']')* (THROWS exceptionList)? methodBody
+ ;
+
+variableDeclarators
+ : variableDeclarator (',' variableDeclarator)*
+ ;
+
+variableDeclarator
+ : variableDeclaratorId ('=' variableInitializer)?
+ ;
+
+variableDeclaratorId
+ : identifier ('[' ']')*
+ ;
+
+variableInitializer
+ : arrayInitializer
+ | expression
+ ;
+
+arrayInitializer
+ : '{' (variableInitializer (',' variableInitializer)* (',')? )? '}'
+ ;
+
+classOrInterfaceType
+ : (identifier typeArguments? '.')* typeIdentifier typeArguments?
+ ;
+
+typeArgument
+ : typeType
+ | wildcardType
+ ;
+
+wildcardType
+ : annotation* '?' (extendsWildcardType | superWildcardType)?
+ ;
+
+extendsWildcardType
+ : EXTENDS typeType
+ ;
+
+superWildcardType
+ : SUPER typeType
+ ;
+
+qualifiedNameList
+ : qualifiedName (',' qualifiedName)*
+ ;
+
+exceptionList
+ : qualifiedNameList
+ ;
+
+formalParameters
+ : '(' ( receiverParameter?
+ | receiverParameter (',' formalParameterList)?
+ | formalParameterList?
+ ) ')'
+ ;
+
+receiverParameter
+ : typeType? (identifier '.')* THIS
+ ;
+
+formalParameterList
+ : formalParameter (',' formalParameter)* (',' lastFormalParameter)?
+ | lastFormalParameter
+ ;
+
+formalParameter
+ : variableModifier* typeType? variableDeclaratorId
+ | pattern // Pattern matching for Methods
+ ;
+
+lastFormalParameter
+ : variableModifier* typeType? annotation* '...' variableDeclaratorId
+ ;
+
+// local variable type inference
+lambdaLVTIList
+ : lambdaLVTIParameter (',' lambdaLVTIParameter)*
+ ;
+
+lambdaLVTIParameter
+ : variableModifier* VAR identifier
+ ;
+
+qualifiedName
+ : identifier ('.' identifier)*
+ ;
+
+literal
+ : integerLiteral # intLiteral
+ | floatLiteral # fltLiteral
+ | CHAR_LITERAL # charLiteral
+ | STRING_LITERAL # stringLiteral
+ | BOOL_LITERAL # boolLiteral
+ | NULL_LITERAL # nullLiteral
+ | TEXT_BLOCK # textBlock // Java17
+ ;
+
+integerLiteral
+ : DECIMAL_LITERAL
+ | HEX_LITERAL
+ | OCT_LITERAL
+ | BINARY_LITERAL
+ ;
+
+floatLiteral
+ : FLOAT_LITERAL
+ | HEX_FLOAT_LITERAL
+ ;
+
+// ANNOTATIONS
+altAnnotationQualifiedName
+ : (identifier DOT)* '@' identifier
+ ;
+
+annotation
+ : ('@' qualifiedName | altAnnotationQualifiedName) ('(' ( elementValuePairs | elementValue )? ')')?
+ ;
+
+elementValuePairs
+ : elementValuePair (',' elementValuePair)*
+ ;
+
+elementValuePair
+ : identifier '=' elementValue
+ ;
+
+elementValue
+ : expression
+ | annotation
+ | elementValueArrayInitializer
+ ;
+
+elementValueArrayInitializer
+ : '{' (elementValue (',' elementValue)*)? (',')? '}'
+ ;
+
+annotationTypeDeclaration
+ : '@' INTERFACE identifier annotationTypeBody
+ ;
+
+annotationTypeBody
+ : '{' (annotationTypeElementDeclaration)* '}'
+ ;
+
+annotationTypeElementDeclaration
+ : modifier* annotationTypeElementRest
+ | ';' // this is not allowed by the grammar, but apparently allowed by the actual compiler
+ ;
+
+annotationTypeElementRest
+ : typeType annotationMethodOrConstantRest ';'
+ | classOrInterface ';'?
+ ;
+
+annotationMethodOrConstantRest
+ : annotationMethodRest
+ | annotationConstantRest
+ ;
+
+annotationMethodRest
+ : identifier '(' ')' defaultValue?
+ ;
+
+annotationConstantRest
+ : variableDeclarators
+ ;
+
+defaultValue
+ : DEFAULT elementValue
+ ;
+
+// MODULES - Java9
+
+moduleDeclaration
+ : OPEN? MODULE qualifiedName moduleBody
+ ;
+
+moduleBody
+ : '{' moduleDirective* '}'
+ ;
+
+moduleDirective
+ : REQUIRES requiresModifier* qualifiedName ';'
+ | EXPORTS qualifiedName (TO qualifiedName)? ';'
+ | OPENS qualifiedName (TO qualifiedName)? ';'
+ | USES qualifiedName ';'
+ | PROVIDES qualifiedName WITH qualifiedName ';'
+ ;
+
+requiresModifier
+ : TRANSITIVE
+ | STATIC
+ ;
+
+// RECORDS - Java 17
+
+recordDeclaration
+ : RECORD identifier genericDeclarationList? recordHeader
+ (IMPLEMENTS typeList)?
+ recordBody
+ ;
+
+recordHeader
+ : '(' recordComponentList? ')'
+ ;
+
+recordComponentList
+ : recordComponent (',' recordComponent)*
+ ;
+
+recordComponent
+ : typeType? identifier
+ ;
+
+recordBody
+ : '{' classBodyDeclaration* '}'
+ ;
+
+// STATEMENTS / BLOCKS
+
+block
+ : '{' blockStatement* '}'
+ ;
+
+blockStatement
+ : localVariableDeclaration ';'
+ | localTypeDeclaration
+ | statement
+ ;
+
+localVariableDeclaration
+ : variableModifier* (VAR | typeType) variableDeclarators
+ ;
+
+identifier
+ : IDENTIFIER
+ | MODULE
+ | OPEN
+ | REQUIRES
+ | EXPORTS
+ | OPENS
+ | TO
+ | USES
+ | PROVIDES
+ | WITH
+ | TRANSITIVE
+ | YIELD
+ | SEALED
+ | PERMITS
+ | RECORD
+ | VAR
+ ;
+
+typeIdentifier // Identifiers that are not restricted for type declarations
+ : IDENTIFIER
+ | MODULE
+ | OPEN
+ | REQUIRES
+ | EXPORTS
+ | OPENS
+ | TO
+ | USES
+ | PROVIDES
+ | WITH
+ | TRANSITIVE
+ | SEALED
+ | PERMITS
+ | RECORD
+ ;
+
+localTypeDeclaration
+ : classOrInterfaceModifier*
+ (classDeclaration | interfaceDeclaration | recordDeclaration)
+ | ';'
+ ;
+
+statement
+ : blockLabel=block #blockstmt
+ | ASSERT expression (':' expression)? ';' #assertstmt
+ | IF parExpression statement (ELSE statement)? #conditionalstmt
+ | FOR '(' forControl ')' statement #forloop
+ | WHILE parExpression statement #whileloop
+ | DO statement WHILE parExpression ';' #dowhileloop
+ | TRY block (catchClause+ finallyBlock? | finallyBlock) #trycatchblock
+ | TRY resourceSpecification block catchClause* finallyBlock? #trycatchresource
+ | SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' #switchstmt
+ | SYNCHRONIZED parExpression block #synchronizedstmt
+ | RETURN expression? ';' #returnstmt
+ | THROW expression ';' #throwstmt
+ | BREAK identifier? ';' #breakstmt
+ | CONTINUE identifier? ';' #continuestmt
+ | YIELD expression ';' #yieldstmt // Java17
+ | SEMI #semistmt
+ | statementExpression=expression ';' #stmtexpression
+ | identifierLabel=identifier ':' statement #labeledstmt
+ ;
+
+catchClause
+ : CATCH '(' variableModifier* catchType? identifier ')' block
+ ;
+
+catchType
+ : qualifiedName ('|' qualifiedName)*
+ ;
+
+finallyBlock
+ : FINALLY block
+ ;
+
+resourceSpecification
+ : '(' resources ';'? ')'
+ ;
+
+resources
+ : resource (';' resource)*
+ ;
+
+resource
+ : variableModifier* ( classOrInterfaceType? variableDeclaratorId | VAR identifier ) '=' expression
+ | identifier
+ ;
+
+/** Matches cases then statements, both of which are mandatory.
+ * To handle empty cases at the end, we add switchLabel* to statement.
+ */
+switchBlockStatementGroup
+ : switchLabel+ blockStatement+
+ ;
+
+switchLabel
+ : CASE constantExpression=expression ':' #switchLabelConst
+ | CASE enumConstantName=IDENTIFIER ':' #switchLabelEnum
+ | CASE pattern ':' #switchLabelPattern
+ | DEFAULT ':' #switchLabelDefault
+ ;
+
+forControl
+ : enhancedForControl
+ | forInit? ';' expression? ';' forUpdate=expressionList?
+ ;
+
+forInit
+ : localVariableDeclaration
+ | expressionList
+ ;
+
+enhancedForControl
+ : variableModifier* (typeType? | VAR) variableDeclaratorId ':' expression
+ ;
+
+// EXPRESSIONS
+
+parExpression
+ : '(' expression ')'
+ ;
+
+expressionList
+ : expression (',' expression)*
+ ;
+
+methodCall
+ : identifier '(' expressionList? ')'
+ | THIS '(' expressionList? ')'
+ | SUPER '(' expressionList? ')'
+ ;
+
+expression
+ : primary #primaryExpression2
+ | expression bop='.'
+ (
+ identifier
+ | methodCall
+ | THIS
+ | NEW nonWildcardTypeArguments? innerCreator
+ | SUPER superSuffix
+ | explicitGenericInvocation
+ ) # dottedexpression
+ | expression '[' expression ']' #arrayaccessexpression
+ | methodCall #methodcallexpression
+ | NEW creator #newinstanceexpression
+ | '(' annotation* typeType ('&' typeType)* ')' expression #castexpression
+ | expression postfix=('++' | '--') #postfixexpression
+ | prefix=('+'|'-'|'++'|'--'|'~'|'!') expression #prefixexpression
+ | expression bop=('*'|'/'|'%') expression #mathmuldivmodexpression
+ | expression bop=('+'|'-') expression #mathaddsubexpression
+ | expression ('<' '<' | '>' '>' '>' | '>' '>') expression #shiftexpression
+ | expression bop=('<=' | '>=' | '>' | '<') expression #relationalexpression
+ | expression bop=INSTANCEOF (typeType | pattern) #instanceofexpression
+ | expression bop=('==' | '!=') expression #equalityexpression
+ | expression bop='&' expression #bitwiseandexpression
+ | expression bop='^' expression #bitwisexorexpression
+ | expression bop='|' expression #bitwiseorexpression
+ | expression bop='&&' expression #andexpression
+ | expression bop='||' expression #orexpression
+ | expression bop='?' expression ':' expression #conditionalassignexpression
+ | expression
+ bop=('=' | '+=' | '-=' | '*=' | '/=' | '&=' | '|=' | '^=' | '>>=' | '>>>=' | '<<=' | '%=')
+ expression #assignexpression
+ | lambdaExpression #lambdaExpression2 // Java8
+ | switchExpression #switchExpression2 // Java17
+
+ // Java 8 methodReference
+ | expression '::' typeArguments? identifier #methodreferenceexpression
+ | typeType '::' (typeArguments? identifier | NEW) #methodorcreatorreferenceexpression
+ | classType '::' typeArguments? NEW #creatorreferenceexpression
+ ;
+
+// Java17
+pattern
+ : primaryPattern #pPattern
+ | guardedPattern #gPattern
+ ;
+
+primaryPattern
+ : typePattern #tPattern
+ | recordPattern #rPattern
+ | '(' pattern ')' #enclosedPattern
+ ;
+
+recordPattern
+ : typeType recordStructurePattern identifier?
+ ;
+
+typePattern
+ : variableModifier* typeType identifier
+ ;
+
+recordStructurePattern
+ : '(' recordComponentPatternList? ')'
+ ;
+
+recordComponentPatternList
+ : pattern (',' pattern)*
+ ;
+
+// Java8
+lambdaExpression
+ : lambdaParameters '->' lambdaBody
+ ;
+
+// Java8
+lambdaParameters
+ : identifier
+ | '(' formalParameterList? ')'
+ | '(' identifier (',' identifier)* ')'
+ | '(' lambdaLVTIList? ')'
+ ;
+
+// Java8
+lambdaBody
+ : expression
+ | block
+ ;
+
+primary
+ : '(' expression ')' # primaryExpression
+ | THIS # primaryThis
+ | SUPER # primarySuper
+ | literal # primaryLiteral
+ | identifier # primaryIdentifier
+ | refType '.' CLASS # primaryClassref
+ | nonWildcardTypeArguments (explicitGenericInvocationSuffix | THIS arguments) # primaryInvocation
+ ;
+
+// Java17
+switchExpression
+ : SWITCH parExpression '{' switchLabeledRule* '}'
+ ;
+
+// Java17
+switchLabeledRule
+ : switchLabelCase switchRuleOutcome
+ ;
+
+switchLabelCase
+ : CASE expressionList (ARROW | COLON) #labeledRuleExprList
+ | CASE NULL_LITERAL (ARROW | COLON) #labeledRuleNull
+ | CASE pattern (ARROW | COLON) #labeledRulePattern
+ | DEFAULT (ARROW | COLON) #labeledRuleDefault
+ ;
+
+// Java20
+guardedPattern
+ : primaryPattern WITH expression
+ ;
+
+// Java17
+switchRuleOutcome
+ : block
+ | expression ';'
+ ;
+
+classType
+ : (classOrInterfaceType '.')? annotation* identifier typeArguments?
+ ;
+
+creator
+ : nonWildcardTypeArguments createdName classCreatorRest
+ | createdName (arrayCreatorRest | classCreatorRest)
+ ;
+
+createdName
+ : identifier typeArgumentsOrDiamond?
+ | primitiveType
+ ;
+
+innerCreator
+ : identifier nonWildcardTypeArgumentsOrDiamond? classCreatorRest
+ ;
+
+arrayCreatorRest
+ : '[' (']' ('[' ']')* arrayInitializer | expression ']' ('[' expression ']')* ('[' ']')*)
+ ;
+
+classCreatorRest
+ : arguments classBody?
+ ;
+
+explicitGenericInvocation
+ : nonWildcardTypeArguments explicitGenericInvocationSuffix
+ ;
+
+typeArgumentsOrDiamond
+ : '<' '>'
+ | typeArguments
+ ;
+
+nonWildcardTypeArgumentsOrDiamond
+ : '<' '>'
+ | nonWildcardTypeArguments
+ ;
+
+nonWildcardTypeArguments
+ : '<' typeList '>'
+ ;
+
+typeList
+ : typeType (',' typeType)*
+ ;
+
+typeType
+ : annotation* (classOrInterfaceType | primitiveType) (annotation* '[' ']')*
+ ;
+
+primitiveType
+ : BOOLEAN
+ | CHAR
+ | BYTE
+ | SHORT
+ | INT
+ | LONG
+ | FLOAT
+ | DOUBLE
+ ;
+
+typeArguments
+ : '<' typeArgument (',' typeArgument)* '>'
+ ;
+
+superSuffix
+ : arguments
+ | '.' typeArguments? identifier arguments?
+ ;
+
+explicitGenericInvocationSuffix
+ : SUPER superSuffix
+ | identifier arguments
+ ;
+
+arguments
+ : '(' expressionList? ')'
+ ;
\ No newline at end of file
diff --git a/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java8.g4 b/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java8.g4
deleted file mode 100644
index 5188ddf6..00000000
--- a/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java8.g4
+++ /dev/null
@@ -1,1872 +0,0 @@
-/*
- * [The "BSD license"]
- * Copyright (c) 2014 Terence Parr
- * Copyright (c) 2014 Sam Harwell
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
- * A Java 8 grammar for ANTLR 4 derived from the Java Language Specification
- * chapter 19.
- *
- * NOTE: This grammar results in a generated parser that is much slower
- * than the Java 7 grammar in the grammars-v4/java directory. This
- * one is, however, extremely close to the spec.
- *
- * You can test with
- *
- * $ antlr4 Java8.g4
- * $ javac *.java
- * $ grun Java8 compilationUnit *.java
- *
- * Or,
-~/antlr/code/grammars-v4/java8 $ java Test .
-/Users/parrt/antlr/code/grammars-v4/java8/./Java8BaseListener.java
-/Users/parrt/antlr/code/grammars-v4/java8/./Java8Lexer.java
-/Users/parrt/antlr/code/grammars-v4/java8/./Java8Listener.java
-/Users/parrt/antlr/code/grammars-v4/java8/./Java8Parser.java
-/Users/parrt/antlr/code/grammars-v4/java8/./Test.java
-Total lexer+parser time 30844ms.
- */
-grammar Java8;
-
-/*
- * Productions from §3 (Lexical Structure)
- */
-
-literal
- : IntegerLiteral
- | FloatingPointLiteral
- | BooleanLiteral
- | CharacterLiteral
- | StringLiteral
- | NullLiteral
- ;
-
-/*
- * Productions from §4 (Types, Values, and Variables)
- */
-
-type
- : primitiveType
- | referenceType
- ;
-
-primitiveType
- : annotation* numericType
- | annotation* 'boolean'
- ;
-
-numericType
- : integralType
- | floatingPointType
- ;
-
-integralType
- : 'byte'
- | 'short'
- | 'int'
- | 'long'
- | 'char'
- ;
-
-floatingPointType
- : 'float'
- | 'double'
- ;
-
-referenceType
- : classOrInterfaceType
- | typeVariable
- | arrayType
- ;
-
-classOrInterfaceType
- : ( classType_lfno_classOrInterfaceType
- | interfaceType_lfno_classOrInterfaceType
- )
- ( classType_lf_classOrInterfaceType
- | interfaceType_lf_classOrInterfaceType
- )*
- ;
-
-classType
- : annotation* Identifier typeArguments?
- | classOrInterfaceType '.' annotation* Identifier typeArguments?
- ;
-
-classTypeList
- : classType (',' classType)*
- ;
-
-classType_lf_classOrInterfaceType
- : '.' annotation* Identifier typeArguments?
- ;
-
-classType_lfno_classOrInterfaceType
- : annotation* Identifier typeArguments?
- ;
-
-interfaceType
- : classType
- ;
-
-interfaceType_lf_classOrInterfaceType
- : classType_lf_classOrInterfaceType
- ;
-
-interfaceType_lfno_classOrInterfaceType
- : classType_lfno_classOrInterfaceType
- ;
-
-typeVariable
- : annotation* Identifier
- ;
-
-arrayType
- : primitiveType dims
- | classOrInterfaceType dims
- | typeVariable dims
- ;
-
-dims
- : annotation* '[' ']' (annotation* '[' ']')*
- ;
-
-typeParameter
- : typeParameterModifier* Identifier typeBound?
- ;
-
-typeParameterModifier
- : annotation
- ;
-
-typeBound
- : 'extends' typeVariable
- | 'extends' classOrInterfaceType additionalBound*
- ;
-
-additionalBound
- : '&' interfaceType
- ;
-
-typeArguments
- : '<' typeArgumentList '>'
- ;
-
-typeArgumentList
- : typeArgument (',' typeArgument)*
- ;
-
-typeArgument
- : referenceType
- | wildcard
- ;
-
-wildcard
- : annotation* '?' wildcardBounds?
- ;
-
-wildcardBounds
- : 'extends' referenceType
- | 'super' referenceType
- ;
-
-/*
- * Productions from §6 (Names)
- */
-
-packageName
- : Identifier
- | packageName '.' Identifier
- ;
-
-typeName
- : Identifier
- | packageOrTypeName '.' Identifier
- ;
-
-packageOrTypeName
- : Identifier
- | packageOrTypeName '.' Identifier
- ;
-
-expressionName
- : Identifier
- | ambiguousName '.' Identifier
- ;
-
-methodName
- : Identifier
- ;
-
-ambiguousName
- : Identifier
- | ambiguousName '.' Identifier
- ;
-
-/*
- * Productions from §7 (Packages)
- */
-
-compilationUnit
- : packageDeclaration? importDeclaration* typeDeclaration* EOF
- ;
-
-packageDeclaration
- : packageModifier* 'package' Identifier ('.' Identifier)* ';'
- ;
-
-packageModifier
- : annotation
- ;
-
-importDeclaration
- : singleTypeImportDeclaration
- | typeImportOnDemandDeclaration
- | singleStaticImportDeclaration
- | staticImportOnDemandDeclaration
- ;
-
-singleTypeImportDeclaration
- : 'import' typeName ';'
- ;
-
-typeImportOnDemandDeclaration
- : 'import' packageOrTypeName '.' '*' ';'
- ;
-
-singleStaticImportDeclaration
- : 'import' 'static' typeName '.' Identifier ';'
- ;
-
-staticImportOnDemandDeclaration
- : 'import' 'static' typeName '.' '*' ';'
- ;
-
-typeDeclaration
- : classDeclaration
- | interfaceDeclaration
- | ';'
- ;
-
-/*
- * Productions from §8 (Classes)
- */
-
-classDeclaration
- : normalClassDeclaration
- | enumDeclaration
- | recordDeclaration
- ;
-
-normalClassDeclaration
- : classModifier* 'class' Identifier typeParameters? superclass? superinterfaces? permittedsubclasses? classBody
- ;
-
-classModifier
- : annotation
- | 'public'
- | 'protected'
- | 'private'
- | 'abstract'
- | 'static'
- | 'sealed'
- | 'final'
- | 'non-sealed'
- | 'strictfp'
- ;
-
-typeParameters
- : '<' typeParameterList '>'
- ;
-
-typeParameterList
- : typeParameter (',' typeParameter)*
- ;
-
-superclass
- : 'extends' classType
- ;
-
-superinterfaces
- : 'implements' interfaceTypeList
- ;
-
-permittedsubclasses
- : 'permits' classTypeList
- ;
-
-interfaceTypeList
- : interfaceType (',' interfaceType)*
- ;
-
-classBody
- : '{' classBodyDeclaration* '}'
- ;
-
-classBodyDeclaration
- : classMemberDeclaration
- | instanceInitializer
- | staticInitializer
-// | constructorDeclaration
- ;
-
-classMemberDeclaration
- : fieldDeclaration
- | methodDeclaration
- | classDeclaration
- | interfaceDeclaration
- | ';'
- ;
-
-fieldDeclaration
- : fieldModifier* unannTypeOrAuto? variableDeclaratorList ';'
- ;
-
-fieldModifier
- : annotation
- | 'public'
- | 'protected'
- | 'private'
- | 'static'
- | 'final'
- | 'transient'
- | 'volatile'
- ;
-
-variableDeclaratorList
- : variableDeclarator (',' variableDeclarator)*
- ;
-
-variableDeclarator
- : variableDeclaratorId ('=' variableInitializer)? //auskommentiert, weil variablenDecklaration sonst nicht eindeutig
- ;
-
-variableDeclaratorId
- : Identifier dims?
- ;
-
-variableInitializer
- : expression
- | arrayInitializer
- ;
-
-unannType
- : unannPrimitiveType
- | unannReferenceType
- ;
-
-unannPrimitiveType
- : numericType
- | 'boolean'
- ;
-
-unannReferenceType
- : unannClassOrInterfaceType
- | unannTypeVariable
- | unannArrayType
- ;
-
-unannClassOrInterfaceType
- : ( unannClassType_lfno_unannClassOrInterfaceType
- | unannInterfaceType_lfno_unannClassOrInterfaceType
- )
- ( unannClassType_lf_unannClassOrInterfaceType
- | unannInterfaceType_lf_unannClassOrInterfaceType
- )*
- ;
-
-unannClassType
- : Identifier typeArguments?
- | unannClassOrInterfaceType '.' annotation* Identifier typeArguments?
- ;
-
-unannClassType_lf_unannClassOrInterfaceType
- : '.' annotation* Identifier typeArguments?
- ;
-
-unannClassType_lfno_unannClassOrInterfaceType
- : Identifier typeArguments?
- ;
-
-unannInterfaceType
- : unannClassType
- ;
-
-unannInterfaceType_lf_unannClassOrInterfaceType
- : unannClassType_lf_unannClassOrInterfaceType
- ;
-
-unannInterfaceType_lfno_unannClassOrInterfaceType
- : unannClassType_lfno_unannClassOrInterfaceType
- ;
-
-unannTypeVariable
- : Identifier
- ;
-
-unannArrayType
- : unannPrimitiveType dims
- | unannClassOrInterfaceType dims
- | unannTypeVariable dims
- ;
-
-methodDeclaration
- : methodModifier* methodHeader methodBody
- ;
-
-methodModifier
- : annotation
- | 'public'
- | 'protected'
- | 'private'
- | 'abstract'
- | 'static'
- | 'final'
- | 'synchronized'
- | 'native'
- | 'strictfp'
- ;
-
-methodHeader
- : result? methodDeclarator throws_?
- | typeParameters annotation* result? methodDeclarator throws_?
- ;
-
-result
- : unannType
- | 'void'
- ;
-
-methodDeclarator
- : Identifier '(' formalParameterList? ')' dims?
- ;
-
-formalParameterList
- : formalParameters ',' lastFormalParameter
- | lastFormalParameter
- ;
-
-formalParameters
- : formalParameter (',' formalParameter)*
- | receiverParameter (',' formalParameter)*
- ;
-
-formalParameter
- : variableModifier* unannType? variableDeclaratorId
- ;
-
-variableModifier
- : annotation
- | 'final'
- ;
-
-lastFormalParameter
- : variableModifier* unannType annotation* '...' variableDeclaratorId
- | formalParameter
- ;
-
-receiverParameter
- : annotation* unannType (Identifier '.')? 'this'
- ;
-
-throws_
- : 'throws' exceptionTypeList
- ;
-
-exceptionTypeList
- : exceptionType (',' exceptionType)*
- ;
-
-exceptionType
- : classType
- | typeVariable
- ;
-
-methodBody
- : block
- | ';'
- ;
-
-instanceInitializer
- : block
- ;
-
-staticInitializer
- : 'static' block
- ;
-
-constructorDeclaration
- : constructorModifier* constructorDeclarator throws_? constructorBody
- ;
-
-constructorModifier
- : annotation
- | 'public'
- | 'protected'
- | 'private'
- ;
-
-constructorDeclarator
- : typeParameters? simpleTypeName '(' formalParameterList? ')'
- ;
-
-simpleTypeName
- : Identifier
- ;
-
-constructorBody
- : '{' explicitConstructorInvocation? blockStatements? '}'
- ;
-
-explicitConstructorInvocation
- : typeArguments? 'this' '(' argumentList? ')' ';'
- | typeArguments? 'super' '(' argumentList? ')' ';'
- | expressionName '.' typeArguments? 'super' '(' argumentList? ')' ';'
- | primary '.' typeArguments? 'super' '(' argumentList? ')' ';'
- ;
-
-enumDeclaration
- : classModifier* 'enum' Identifier superinterfaces? enumBody
- ;
-
-enumBody
- : '{' enumConstantList? ','? enumBodyDeclarations? '}'
- ;
-
-enumConstantList
- : enumConstant (',' enumConstant)*
- ;
-
-enumConstant
- : enumConstantModifier* Identifier ('(' argumentList? ')')? classBody?
- ;
-
-enumConstantModifier
- : annotation
- ;
-
-enumBodyDeclarations
- : ';' classBodyDeclaration*
- ;
-
-recordDeclaration
- : classModifier* 'record' Identifier typeParameters? recordHeader superinterfaces? recordBody
- ;
-
-recordHeader
- : '(' recordComponentList? ')'
- ;
-
-recordComponentList
- : recordComponent (',' recordComponent)*
- ;
-
-recordComponent
- : annotation* unannType Identifier
- | variableArityRecordComponent
- ;
-
-variableArityRecordComponent
- : annotation* unannType annotation* '...' Identifier
- ;
-
-recordBody
- : '{' recordBodyDeclaration* '}'
- ;
-
-recordBodyDeclaration
- : classBodyDeclaration
- | compactConstructorDeclaration
- ;
-
-compactConstructorDeclaration
- : constructorModifier* simpleTypeName constructorBody
- ;
-
-/*
- * Productions from §9 (Interfaces)
- */
-
-interfaceDeclaration
- : normalInterfaceDeclaration
- | annotationTypeDeclaration
- ;
-
-normalInterfaceDeclaration
- : interfaceModifier* 'interface' Identifier typeParameters? extendsInterfaces? interfaceBody
- ;
-
-interfaceModifier
- : annotation
- | 'public'
- | 'protected'
- | 'private'
- | 'abstract'
- | 'static'
- | 'strictfp'
- ;
-
-extendsInterfaces
- : 'extends' interfaceTypeList
- ;
-
-interfaceBody
- : '{' interfaceMemberDeclaration* '}'
- ;
-
-interfaceMemberDeclaration
- : constantDeclaration
- | interfaceMethodDeclaration
- | classDeclaration
- | interfaceDeclaration
- | ';'
- ;
-
-constantDeclaration
- : constantModifier* unannType variableDeclaratorList ';'
- ;
-
-constantModifier
- : annotation
- | 'public'
- | 'static'
- | 'final'
- ;
-
-interfaceMethodDeclaration
- : interfaceMethodModifier* methodHeader methodBody
- ;
-
-interfaceMethodModifier
- : annotation
- | 'public'
- | 'abstract'
- | 'default'
- | 'static'
- | 'strictfp'
- ;
-
-annotationTypeDeclaration
- : interfaceModifier* '@' 'interface' Identifier annotationTypeBody
- ;
-
-annotationTypeBody
- : '{' annotationTypeMemberDeclaration* '}'
- ;
-
-annotationTypeMemberDeclaration
- : annotationTypeElementDeclaration
- | constantDeclaration
- | classDeclaration
- | interfaceDeclaration
- | ';'
- ;
-
-annotationTypeElementDeclaration
- : annotationTypeElementModifier* unannType Identifier '(' ')' dims? defaultValue? ';'
- ;
-
-annotationTypeElementModifier
- : annotation
- | 'public'
- | 'abstract'
- ;
-
-defaultValue
- : 'default' elementValue
- ;
-
-annotation
- : normalAnnotation
- | markerAnnotation
- | singleElementAnnotation
- ;
-
-normalAnnotation
- : '@' typeName '(' elementValuePairList? ')'
- ;
-
-elementValuePairList
- : elementValuePair (',' elementValuePair)*
- ;
-
-elementValuePair
- : Identifier '=' elementValue
- ;
-
-elementValue
- : conditionalExpression
- | elementValueArrayInitializer
- | annotation
- ;
-
-elementValueArrayInitializer
- : '{' elementValueList? ','? '}'
- ;
-
-elementValueList
- : elementValue (',' elementValue)*
- ;
-
-markerAnnotation
- : '@' typeName
- ;
-
-singleElementAnnotation
- : '@' typeName '(' elementValue ')'
- ;
-
-/*
- * Productions from §10 (Arrays)
- */
-
-arrayInitializer
- : '{' variableInitializerList? ','? '}'
- ;
-
-variableInitializerList
- : variableInitializer (',' variableInitializer)*
- ;
-
-/*
- * Productions from §14 (Blocks and Statements)
- */
-
-block
- : '{' blockStatements? '}'
- ;
-
-blockStatements
- : blockStatement blockStatement*
- ;
-
-blockStatement
- : localVariableDeclarationStatement
- | classDeclaration
- | statement
- ;
-
-localVariableDeclarationStatement
- : localVariableDeclaration ';'
- ;
-
-unannTypeOrAuto
- : unannType
- | 'var'
- ;
-
-localVariableDeclaration
- : variableModifier* unannTypeOrAuto variableDeclaratorList
- ;
-
-statement
- : statementWithoutTrailingSubstatement
- | labeledStatement
- | ifThenStatement
- | ifThenElseStatement
- | whileStatement
- | forStatement
- | switchExpression ';'?
- ;
-
-statementNoShortIf
- : statementWithoutTrailingSubstatement
- | labeledStatementNoShortIf
- | ifThenElseStatementNoShortIf
- | whileStatementNoShortIf
- | forStatementNoShortIf
- ;
-
-statementWithoutTrailingSubstatement
- : block
- | emptyStatement
- | expressionStatement
- | assertStatement
- | switchStatement
- | doStatement
- | breakStatement
- | yieldStatement
- | continueStatement
- | returnStatement
- | synchronizedStatement
- | throwStatement
- | tryStatement
- ;
-
-emptyStatement
- : ';'
- ;
-
-labeledStatement
- : Identifier ':' statement
- ;
-
-labeledStatementNoShortIf
- : Identifier ':' statementNoShortIf
- ;
-
-expressionStatement
- : statementExpression ';'
- ;
-
-statementExpression
- : assignment
- | preIncrementExpression
- | preDecrementExpression
- | postIncrementExpression
- | postDecrementExpression
- | methodInvocation
- | classInstanceCreationExpression
- ;
-
-ifThenStatement
- : 'if' '(' expression ')' statement
- ;
-
-ifThenElseStatement
- : 'if' parExpression statementNoShortIf 'else' statement
- ;
-
-ifThenElseStatementNoShortIf
- : 'if' parExpression statementNoShortIf 'else' statementNoShortIf
- ;
-
-assertStatement
- : 'assert' expression ';'
- | 'assert' expression ':' expression ';'
- ;
-
-switchStatement
- : 'switch' parExpression switchBlock
- ;
-
-switchBlock
- : '{' switchBlockStatementGroup* switchLabel* '}'
- ;
-
-switchBlockStatementGroup
- : switchLabels blockStatements
- ;
-
-switchLabels
- : switchLabel switchLabel*
- ;
-
-switchLabel
- : 'case' constantExpression ':'
- | 'case' enumConstantName ':'
- | 'default' ':'
- ;
-
-switchExpression
- : 'switch' parExpression '{' switchLabeledRule* '}'
- ;
-
-switchLabeledRule
- : CASE (expressionList | NullLiteral | guardedPattern) (ARROW|COLON) switchRuleOutcome
- | DEFAULT (ARROW|COLON) switchRuleOutcome
- ;
-
-guardedPattern
- : '(' guardedPattern ')'
- | variableModifier* annotation* Identifier ('&&' expression)*
- | guardedPattern '&&' expression
- ;
-
-switchRuleOutcome
- : block
- | blockStatement*
- ;
-
-enumConstantName
- : Identifier
- ;
-
-enumConstantNameList
- : enumConstantName (',' enumConstantName)*
- ;
-
-whileStatement
- : 'while' parExpression statement
- ;
-
-whileStatementNoShortIf
- : 'while' parExpression statementNoShortIf
- ;
-
-doStatement
- : 'do' statement 'while' parExpression ';'
- ;
-
-forStatement
- : basicForStatement
- | enhancedForStatement
- ;
-
-forStatementNoShortIf
- : basicForStatementNoShortIf
- | enhancedForStatementNoShortIf
- ;
-
-basicForStatement
- : 'for' '(' forInit? ';' expression? ';' forUpdate? ')' statement
- ;
-
-basicForStatementNoShortIf
- : 'for' '(' forInit? ';' expression? ';' forUpdate? ')' statementNoShortIf
- ;
-
-forInit
- : statementExpressionList
- | localVariableDeclaration
- ;
-
-forUpdate
- : statementExpressionList
- ;
-
-statementExpressionList
- : statementExpression (',' statementExpression)*
- ;
-
-enhancedForStatement
- : 'for' '(' variableModifier* unannType variableDeclaratorId ':' expression ')' statement
- ;
-
-enhancedForStatementNoShortIf
- : 'for' '(' variableModifier* unannType variableDeclaratorId ':' expression ')' statementNoShortIf
- ;
-
-breakStatement
- : 'break' Identifier? ';'
- ;
-
-yieldStatement
- : 'yield' Identifier? ';'
- ;
-
-continueStatement
- : 'continue' Identifier? ';'
- ;
-
-returnStatement
- : 'return' expression? ';'
- ;
-
-throwStatement
- : 'throw' expression ';'
- ;
-
-synchronizedStatement
- : 'synchronized' parExpression block
- ;
-
-tryStatement
- : 'try' block catches
- | 'try' block catches? finally_
- | tryWithResourcesStatement
- ;
-
-catches
- : catchClause catchClause*
- ;
-
-catchClause
- : 'catch' '(' catchFormalParameter ')' block
- ;
-
-catchFormalParameter
- : variableModifier* catchType variableDeclaratorId
- ;
-
-catchType
- : unannClassType ('|' classType)*
- ;
-
-finally_
- : 'finally' block
- ;
-
-tryWithResourcesStatement
- : 'try' resourceSpecification block catches? finally_?
- ;
-
-resourceSpecification
- : '(' resourceList ';'? ')'
- ;
-
-resourceList
- : resource (';' resource)*
- ;
-
-resource
- : variableModifier* unannType variableDeclaratorId '=' expression
- ;
-
-/*
- * Productions from §15 (Expressions)
- */
-
-primary
- : ( primaryNoNewArray_lfno_primary
- | arrayCreationExpression
- )
- ( primaryNoNewArray_lf_primary
- )*
- ;
-
-primaryNoNewArray
- : literal
- | typeName ('[' ']')* '.' 'class'
- | 'void' '.' 'class'
- | 'this'
- | typeName '.' 'this'
- | parExpression
- | classInstanceCreationExpression
- | fieldAccess
- | arrayAccess
- | methodInvocation
- | methodReference
- ;
-
-primaryNoNewArray_lf_arrayAccess
- :
- ;
-
-primaryNoNewArray_lfno_arrayAccess
- : literal
- | typeName ('[' ']')* '.' 'class'
- | 'void' '.' 'class'
- | 'this'
- | typeName '.' 'this'
- | parExpression
- | classInstanceCreationExpression
- | fieldAccess
- | methodInvocation
- | methodReference
- ;
-
-primaryNoNewArray_lf_primary
- : classInstanceCreationExpression_lf_primary
- | fieldAccess_lf_primary
- | arrayAccess_lf_primary
- | methodInvocation_lf_primary
- | methodReference_lf_primary
- ;
-
-primaryNoNewArray_lf_primary_lf_arrayAccess_lf_primary
- :
- ;
-
-primaryNoNewArray_lf_primary_lfno_arrayAccess_lf_primary
- : classInstanceCreationExpression_lf_primary
- | fieldAccess_lf_primary
- | methodInvocation_lf_primary
- | methodReference_lf_primary
- ;
-
-primaryNoNewArray_lfno_primary
- : literal //done
- | typeName ('[' ']')* '.' 'class'
- | unannPrimitiveType ('[' ']')* '.' 'class'
- | 'void' '.' 'class'
- | 'this'
- | typeName '.' 'this'
- | parExpression //done
- | classInstanceCreationExpression_lfno_primary //done
- | fieldAccess_lfno_primary
- | arrayAccess_lfno_primary
- | methodInvocation_lfno_primary //done
- | methodReference_lfno_primary
- ;
-
-primaryNoNewArray_lfno_primary_lf_arrayAccess_lfno_primary
- :
- ;
-
-primaryNoNewArray_lfno_primary_lfno_arrayAccess_lfno_primary
- : literal
- | typeName ('[' ']')* '.' 'class'
- | unannPrimitiveType ('[' ']')* '.' 'class'
- | 'void' '.' 'class'
- | 'this'
- | typeName '.' 'this'
- | parExpression
- | classInstanceCreationExpression_lfno_primary
- | fieldAccess_lfno_primary
- | methodInvocation_lfno_primary
- | methodReference_lfno_primary
- ;
-
-classInstanceCreationExpression
- : 'new' typeArguments? annotation* Identifier ('.' annotation* Identifier)* typeArgumentsOrDiamond? '(' argumentList? ')' classBody?
- | expressionName '.' 'new' typeArguments? annotation* Identifier typeArgumentsOrDiamond? '(' argumentList? ')' classBody?
- | primary '.' 'new' typeArguments? annotation* Identifier typeArgumentsOrDiamond? '(' argumentList? ')' classBody?
- ;
-
-classInstanceCreationExpression_lf_primary
- : '.' 'new' typeArguments? annotation* Identifier typeArgumentsOrDiamond? '(' argumentList? ')' classBody?
- ;
-
-classInstanceCreationExpression_lfno_primary
- : 'new' typeArguments? annotation* Identifier ('.' annotation* Identifier)* typeArgumentsOrDiamond? '(' argumentList? ')' classBody?
- | expressionName '.' 'new' typeArguments? annotation* Identifier typeArgumentsOrDiamond? '(' argumentList? ')' classBody?
- ;
-
-typeArgumentsOrDiamond
- : typeArguments
- | '<' '>'
- ;
-
-fieldAccess
- : primary '.' Identifier
- | 'super' '.' Identifier
- | typeName '.' 'super' '.' Identifier
- ;
-
-fieldAccess_lf_primary
- : '.' Identifier
- ;
-
-fieldAccess_lfno_primary
- : 'super' '.' Identifier
- | typeName '.' 'super' '.' Identifier
- ;
-
-arrayAccess
- : ( expressionName '[' expression ']'
- | primaryNoNewArray_lfno_arrayAccess '[' expression ']'
- )
- ( primaryNoNewArray_lf_arrayAccess '[' expression ']'
- )*
- ;
-
-arrayAccess_lf_primary
- : ( primaryNoNewArray_lf_primary_lfno_arrayAccess_lf_primary '[' expression ']'
- )
- ( primaryNoNewArray_lf_primary_lf_arrayAccess_lf_primary '[' expression ']'
- )*
- ;
-
-arrayAccess_lfno_primary
- : ( expressionName '[' expression ']'
- | primaryNoNewArray_lfno_primary_lfno_arrayAccess_lfno_primary '[' expression ']'
- )
- ( primaryNoNewArray_lfno_primary_lf_arrayAccess_lfno_primary '[' expression ']'
- )*
- ;
-
-methodInvocation
- : methodName '(' argumentList? ')'
- | typeName '.' typeArguments? Identifier '(' argumentList? ')'
- | expressionName '.' typeArguments? Identifier '(' argumentList? ')'
- | primary '.' typeArguments? Identifier '(' argumentList? ')'
- | 'super' '.' typeArguments? Identifier '(' argumentList? ')'
- | typeName '.' 'super' '.' typeArguments? Identifier '(' argumentList? ')'
- ;
-
-methodInvocation_lf_primary
- : '.' typeArguments? Identifier '(' argumentList? ')'
- ;
-
-methodInvocation_lfno_primary
- : methodName '(' argumentList? ')'
- | typeName '.' typeArguments? Identifier '(' argumentList? ')'
- | expressionName '.' typeArguments? Identifier '(' argumentList? ')'
- | 'super' '.' typeArguments? Identifier '(' argumentList? ')'
- | typeName '.' 'super' '.' typeArguments? Identifier '(' argumentList? ')'
- ;
-
-argumentList
- : expression (',' expression)*
- ;
-
-methodReference
- : expressionName '::' typeArguments? Identifier
- | referenceType '::' typeArguments? Identifier
- | primary '::' typeArguments? Identifier
- | 'super' '::' typeArguments? Identifier
- | typeName '.' 'super' '::' typeArguments? Identifier
- | classType '::' typeArguments? 'new'
- | arrayType '::' 'new'
- ;
-
-methodReference_lf_primary
- : '::' typeArguments? Identifier
- ;
-
-methodReference_lfno_primary
- : expressionName '::' typeArguments? Identifier
- | referenceType '::' typeArguments? Identifier
- | 'super' '::' typeArguments? Identifier
- | typeName '.' 'super' '::' typeArguments? Identifier
- | classType '::' typeArguments? 'new'
- | arrayType '::' 'new'
- ;
-
-arrayCreationExpression
- : 'new' primitiveType dimExprs dims?
- | 'new' classOrInterfaceType dimExprs dims?
- | 'new' primitiveType dims arrayInitializer
- | 'new' classOrInterfaceType dims arrayInitializer
- ;
-
-dimExprs
- : dimExpr dimExpr*
- ;
-
-dimExpr
- : annotation* '[' expression ']'
- ;
-
-constantExpression
- : expression
- ;
-
-constantExpressionList
- : constantExpression (',' constantExpression)*
- ;
-
-expression
- : lambdaExpression
- | assignmentExpression
- | switchExpression
- ;
-
-expressionList
- : expression (',' expression)*
- ;
-
-parExpression
- : '(' expression ')'
- ;
-
-lambdaExpression
- : lambdaParameters '->' lambdaBody
- ;
-
-lambdaParameters
- : Identifier
- | '(' formalParameterList? ')'
- //| '(' inferredFormalParameterList ')'
- ;
-
-inferredFormalParameterList
- : Identifier (',' Identifier)*
- ;
-
-lambdaBody
- : expression
- | block
- ;
-
-assignmentExpression
- : conditionalExpression
- | assignment
- ;
-
-assignment
- : leftHandSide assignmentOperator expression
- ;
-
-leftHandSide
- : expressionName
- | fieldAccess
- | arrayAccess
- ;
-
-assignmentOperator
- : '='
- | '*='
- | '/='
- | '%='
- | '+='
- | '-='
- | '<<='
- | '>>='
- | '>>>='
- | '&='
- | '^='
- | '|='
- ;
-
-conditionalExpression
- : conditionalOrExpression
- | conditionalOrExpression '?' expression ':' conditionalExpression
- ;
-
-conditionalOrExpression
- : conditionalAndExpression
- | conditionalOrExpression '||' conditionalAndExpression
- ;
-
-conditionalAndExpression
- : inclusiveOrExpression
- | conditionalAndExpression '&&' inclusiveOrExpression
- ;
-
-inclusiveOrExpression
- : exclusiveOrExpression
- | inclusiveOrExpression '|' exclusiveOrExpression
- ;
-
-exclusiveOrExpression
- : andExpression
- | exclusiveOrExpression '^' andExpression
- ;
-
-andExpression
- : equalityExpression
- | andExpression '&' equalityExpression
- ;
-
-equalityExpression
- : relationalExpression
- | equalityExpression '==' relationalExpression
- | equalityExpression '!=' relationalExpression
- ;
-
-relationalExpression
- : shiftExpression
- | relationalExpression '<' shiftExpression
- | relationalExpression '>' shiftExpression
- | relationalExpression '<=' shiftExpression
- | relationalExpression '>=' shiftExpression
- | relationalExpression 'instanceof' referenceType
- ;
-
-shiftExpression
- : additiveExpression
- | shiftExpression '<' '<' additiveExpression
- | shiftExpression '>' '>' additiveExpression
- | shiftExpression '>' '>' '>' additiveExpression
- ;
-
-additiveExpression
- : multiplicativeExpression
- | additiveExpression '+' multiplicativeExpression
- | additiveExpression '-' multiplicativeExpression
- ;
-
-multiplicativeExpression
- : unaryExpression
- | multiplicativeExpression '*' unaryExpression
- | multiplicativeExpression '/' unaryExpression
- | multiplicativeExpression '%' unaryExpression
- ;
-
-unaryExpression
- : preIncrementExpression
- | preDecrementExpression
- | '+' unaryExpression
- | '-' unaryExpression
- | unaryExpressionNotPlusMinus
- ;
-
-preIncrementExpression
- : '++' unaryExpression
- ;
-
-preDecrementExpression
- : '--' unaryExpression
- ;
-
-unaryExpressionNotPlusMinus
- : postfixExpression
- | '~' unaryExpression
- | '!' unaryExpression
- | castExpression
- ;
-
-postfixExpression
- : ( primary
- | expressionName
- )
- ( postIncrementExpression_lf_postfixExpression
- | postDecrementExpression_lf_postfixExpression
- )*
- ;
-
-postIncrementExpression
- : postfixExpression '++'
- ;
-
-postIncrementExpression_lf_postfixExpression
- : '++'
- ;
-
-postDecrementExpression
- : postfixExpression '--'
- ;
-
-postDecrementExpression_lf_postfixExpression
- : '--'
- ;
-
-castExpression
- : '(' primitiveType ')' unaryExpression
- | '(' referenceType additionalBound* ')' unaryExpressionNotPlusMinus
- | '(' referenceType additionalBound* ')' lambdaExpression
- ;
-
-// LEXER
-
-// §3.9 Keywords
-
-ABSTRACT : 'abstract';
-ASSERT : 'assert';
-BOOLEAN : 'boolean';
-BREAK : 'break';
-BYTE : 'byte';
-CASE : 'case';
-CATCH : 'catch';
-CHAR : 'char';
-CLASS : 'class';
-CONST : 'const';
-CONTINUE : 'continue';
-DEFAULT : 'default';
-DO : 'do';
-DOUBLE : 'double';
-ELSE : 'else';
-ENUM : 'enum';
-EXTENDS : 'extends';
-FINAL : 'final';
-FINALLY : 'finally';
-FLOAT : 'float';
-FOR : 'for';
-IF : 'if';
-GOTO : 'goto';
-IMPLEMENTS : 'implements';
-IMPORT : 'import';
-INSTANCEOF : 'instanceof';
-INT : 'int';
-INTERFACE : 'interface';
-LONG : 'long';
-NATIVE : 'native';
-NEW : 'new';
-PACKAGE : 'package';
-PRIVATE : 'private';
-PROTECTED : 'protected';
-PUBLIC : 'public';
-RETURN : 'return';
-SHORT : 'short';
-STATIC : 'static';
-STRICTFP : 'strictfp';
-SUPER : 'super';
-SWITCH : 'switch';
-SYNCHRONIZED : 'synchronized';
-THIS : 'this';
-THROW : 'throw';
-THROWS : 'throws';
-TRANSIENT : 'transient';
-TRY : 'try';
-VOID : 'void';
-VOLATILE : 'volatile';
-WHILE : 'while';
-
-// §3.10.1 Integer Literals
-
-IntegerLiteral
- : DecimalIntegerLiteral
- | HexIntegerLiteral
- | OctalIntegerLiteral
- | BinaryIntegerLiteral
- ;
-
-fragment
-DecimalIntegerLiteral
- : DecimalNumeral IntegerTypeSuffix?
- ;
-
-fragment
-HexIntegerLiteral
- : HexNumeral IntegerTypeSuffix?
- ;
-
-fragment
-OctalIntegerLiteral
- : OctalNumeral IntegerTypeSuffix?
- ;
-
-fragment
-BinaryIntegerLiteral
- : BinaryNumeral IntegerTypeSuffix?
- ;
-
-fragment
-IntegerTypeSuffix
- : [lL]
- ;
-
-fragment
-DecimalNumeral
- : '0'
- | NonZeroDigit (Digits? | Underscores Digits)
- ;
-
-fragment
-Digits
- : Digit (DigitsAndUnderscores? Digit)?
- ;
-
-fragment
-Digit
- : '0'
- | NonZeroDigit
- ;
-
-fragment
-NonZeroDigit
- : [1-9]
- ;
-
-fragment
-DigitsAndUnderscores
- : DigitOrUnderscore+
- ;
-
-fragment
-DigitOrUnderscore
- : Digit
- | '_'
- ;
-
-fragment
-Underscores
- : '_'+
- ;
-
-fragment
-HexNumeral
- : '0' [xX] HexDigits
- ;
-
-fragment
-HexDigits
- : HexDigit (HexDigitsAndUnderscores? HexDigit)?
- ;
-
-fragment
-HexDigit
- : [0-9a-fA-F]
- ;
-
-fragment
-HexDigitsAndUnderscores
- : HexDigitOrUnderscore+
- ;
-
-fragment
-HexDigitOrUnderscore
- : HexDigit
- | '_'
- ;
-
-fragment
-OctalNumeral
- : '0' Underscores? OctalDigits
- ;
-
-fragment
-OctalDigits
- : OctalDigit (OctalDigitsAndUnderscores? OctalDigit)?
- ;
-
-fragment
-OctalDigit
- : [0-7]
- ;
-
-fragment
-OctalDigitsAndUnderscores
- : OctalDigitOrUnderscore+
- ;
-
-fragment
-OctalDigitOrUnderscore
- : OctalDigit
- | '_'
- ;
-
-fragment
-BinaryNumeral
- : '0' [bB] BinaryDigits
- ;
-
-fragment
-BinaryDigits
- : BinaryDigit (BinaryDigitsAndUnderscores? BinaryDigit)?
- ;
-
-fragment
-BinaryDigit
- : [01]
- ;
-
-fragment
-BinaryDigitsAndUnderscores
- : BinaryDigitOrUnderscore+
- ;
-
-fragment
-BinaryDigitOrUnderscore
- : BinaryDigit
- | '_'
- ;
-
-// §3.10.2 Floating-Point Literals
-
-FloatingPointLiteral
- : DecimalFloatingPointLiteral
- | HexadecimalFloatingPointLiteral
- ;
-
-fragment
-DecimalFloatingPointLiteral
- : Digits '.' Digits? ExponentPart? FloatTypeSuffix?
- | '.' Digits ExponentPart? FloatTypeSuffix?
- | Digits ExponentPart FloatTypeSuffix?
- | Digits FloatTypeSuffix
- ;
-
-fragment
-ExponentPart
- : ExponentIndicator SignedInteger
- ;
-
-fragment
-ExponentIndicator
- : [eE]
- ;
-
-fragment
-SignedInteger
- : Sign? Digits
- ;
-
-fragment
-Sign
- : [+-]
- ;
-
-fragment
-FloatTypeSuffix
- : [fFdD]
- ;
-
-fragment
-HexadecimalFloatingPointLiteral
- : HexSignificand BinaryExponent FloatTypeSuffix?
- ;
-
-fragment
-HexSignificand
- : HexNumeral '.'?
- | '0' [xX] HexDigits? '.' HexDigits
- ;
-
-fragment
-BinaryExponent
- : BinaryExponentIndicator SignedInteger
- ;
-
-fragment
-BinaryExponentIndicator
- : [pP]
- ;
-
-// §3.10.3 Boolean Literals
-
-BooleanLiteral
- : 'true'
- | 'false'
- ;
-
-// §3.10.4 Character Literals
-
-CharacterLiteral
- : '\'' SingleCharacter '\''
- | '\'' EscapeSequence '\''
- ;
-
-fragment
-SingleCharacter
- : ~['\\]
- ;
-
-// §3.10.5 String Literals
-
-StringLiteral
- : '"' StringCharacters? '"'
- ;
-
-fragment
-StringCharacters
- : StringCharacter+
- ;
-
-fragment
-StringCharacter
- : ~["\\]
- | EscapeSequence
- ;
-
-// §3.10.6 Escape Sequences for Character and String Literals
-
-fragment
-EscapeSequence
- : '\\' [btnfr"'\\]
- | OctalEscape
- | UnicodeEscape // This is not in the spec but prevents having to preprocess the input
- ;
-
-fragment
-OctalEscape
- : '\\' OctalDigit
- | '\\' OctalDigit OctalDigit
- | '\\' ZeroToThree OctalDigit OctalDigit
- ;
-
-fragment
-ZeroToThree
- : [0-3]
- ;
-
-// This is not in the spec but prevents having to preprocess the input
-fragment
-UnicodeEscape
- : '\\' 'u' HexDigit HexDigit HexDigit HexDigit
- ;
-
-// §3.10.7 The Null Literal
-
-NullLiteral
- : 'null'
- ;
-
-// §3.11 Separators
-
-LPAREN : '(';
-RPAREN : ')';
-LBRACE : '{';
-RBRACE : '}';
-LBRACK : '[';
-RBRACK : ']';
-SEMI : ';';
-COMMA : ',';
-DOT : '.';
-
-// §3.12 Operators
-
-ASSIGN : '=';
-GT : '>';
-LT : '<';
-BANG : '!';
-TILDE : '~';
-QUESTION : '?';
-COLON : ':';
-EQUAL : '==';
-LE : '<=';
-GE : '>=';
-NOTEQUAL : '!=';
-AND : '&&';
-OR : '||';
-INC : '++';
-DEC : '--';
-ADD : '+';
-SUB : '-';
-MUL : '*';
-DIV : '/';
-BITAND : '&';
-BITOR : '|';
-CARET : '^';
-MOD : '%';
-ARROW : '->';
-COLONCOLON : '::';
-
-ADD_ASSIGN : '+=';
-SUB_ASSIGN : '-=';
-MUL_ASSIGN : '*=';
-DIV_ASSIGN : '/=';
-AND_ASSIGN : '&=';
-OR_ASSIGN : '|=';
-XOR_ASSIGN : '^=';
-MOD_ASSIGN : '%=';
-LSHIFT_ASSIGN : '<<=';
-RSHIFT_ASSIGN : '>>=';
-URSHIFT_ASSIGN : '>>>=';
-
-// §3.8 Identifiers (must appear after all keywords in the grammar)
-
-Identifier
- : JavaLetter JavaLetterOrDigit*
- ;
-
-fragment
-JavaLetter
- : [a-zA-Z$_] // these are the "java letters" below 0x7F
- | // covers all characters above 0x7F which are not a surrogate
- ~[\u0000-\u007F\uD800-\uDBFF]
- {Character.isJavaIdentifierStart(_input.LA(-1))}?
- | // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF
- [\uD800-\uDBFF] [\uDC00-\uDFFF]
- {Character.isJavaIdentifierStart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)))}?
- ;
-
-fragment
-JavaLetterOrDigit
- : [a-zA-Z0-9$_] // these are the "java letters or digits" below 0x7F
- | // covers all characters above 0x7F which are not a surrogate
- ~[\u0000-\u007F\uD800-\uDBFF]
- {Character.isJavaIdentifierPart(_input.LA(-1))}?
- | // covers UTF-16 surrogate pairs encodings for U+10000 to U+10FFFF
- [\uD800-\uDBFF] [\uDC00-\uDFFF]
- {Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)))}?
- ;
-
-//
-// Additional symbols not defined in the lexical specification
-//
-
-AT : '@';
-ELLIPSIS : '...';
-
-//
-// Whitespace and comments
-//
-
-WS : [ \t\r\n\u000C]+ -> skip
- ;
-
-COMMENT
- : '/*' .*? '*/' -> skip
- ;
-
-LINE_COMMENT
- : '//' ~[\r\n]* -> skip
- ;
diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
index 61b3a71e..0723aaef 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
@@ -1,14 +1,16 @@
package de.dhbwstuttgart.bytecode;
+import de.dhbwstuttgart.core.JavaTXCompiler;
+import de.dhbwstuttgart.exceptions.NotImplementedException;
+import de.dhbwstuttgart.parser.scope.JavaClassName;
+import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
+import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.target.tree.*;
import de.dhbwstuttgart.target.tree.expression.*;
import de.dhbwstuttgart.target.tree.type.*;
import org.objectweb.asm.*;
-import java.lang.invoke.CallSite;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
+import java.lang.invoke.*;
import java.util.*;
import static org.objectweb.asm.Opcodes.*;
@@ -16,19 +18,27 @@ import static de.dhbwstuttgart.target.tree.expression.TargetBinaryOp.*;
import static de.dhbwstuttgart.target.tree.expression.TargetLiteral.*;
public class Codegen {
- private final TargetClass clazz;
+ private final TargetStructure clazz;
private final ClassWriter cw;
public final String className;
private int lambdaCounter = 0;
private final HashMap lambdas = new HashMap<>();
+ private final JavaTXCompiler compiler;
- public Codegen(TargetClass clazz) {
+ public Codegen(TargetStructure clazz, JavaTXCompiler compiler) {
this.clazz = clazz;
this.className = clazz.qualifiedName();
- this.cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
+ this.cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS) {
+ @Override
+ protected ClassLoader getClassLoader() {
+ return compiler.getClassLoader();
+ }
+ };
+ this.compiler = compiler;
}
- private record LocalVar(int index, String name, TargetType type) {}
+ private record LocalVar(int index, String name, TargetType type) {
+ }
private static class Scope {
Scope parent;
@@ -54,12 +64,21 @@ public class Codegen {
}
}
+ private static class BreakEnv {
+ String labelName; // TODO This is for labeled statements (Not implemented)
+ Label startLabel;
+ Label endLabel;
+ }
+
private static class State {
Scope scope = new Scope(null);
int localCounter;
MethodVisitor mv;
TargetType returnType;
+ Stack breakStack = new Stack<>();
+ Stack switchResultValue = new Stack<>();
+
State(TargetType returnType, MethodVisitor mv, int localCounter) {
this.returnType = returnType;
this.mv = mv;
@@ -80,6 +99,13 @@ public class Codegen {
localCounter += 1;
return local;
}
+
+ void pushSwitch() {
+ switchResultValue.push(this.localCounter++);
+ }
+ void popSwitch() {
+ switchResultValue.pop();
+ }
}
private void popValue(State state, TargetType type) {
@@ -196,9 +222,7 @@ public class Codegen {
mv.visitInsn(L2F);
else if (dest.equals(TargetType.Double))
mv.visitInsn(L2D);
- else if (dest.equals(TargetType.Byte)
- || dest.equals(TargetType.Char)
- || dest.equals(TargetType.Short)) {
+ else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
mv.visitInsn(L2I);
convertTo(state, TargetType.Integer, dest);
}
@@ -209,9 +233,7 @@ public class Codegen {
mv.visitInsn(F2D);
else if (dest.equals(TargetType.Long))
mv.visitInsn(F2L);
- else if (dest.equals(TargetType.Byte)
- || dest.equals(TargetType.Char)
- || dest.equals(TargetType.Short)) {
+ else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
mv.visitInsn(F2I);
convertTo(state, TargetType.Integer, dest);
}
@@ -222,16 +244,11 @@ public class Codegen {
mv.visitInsn(D2F);
else if (dest.equals(TargetType.Long))
mv.visitInsn(D2L);
- else if (dest.equals(TargetType.Byte)
- || dest.equals(TargetType.Char)
- || dest.equals(TargetType.Short)) {
+ else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
mv.visitInsn(D2I);
convertTo(state, TargetType.Integer, dest);
}
- } else if (source.equals(TargetType.Byte)
- || source.equals(TargetType.Char)
- || source.equals(TargetType.Short)
- || source.equals(TargetType.Integer)) {
+ } else if (source.equals(TargetType.Byte) || source.equals(TargetType.Char) || source.equals(TargetType.Short) || source.equals(TargetType.Integer)) {
if (dest.equals(TargetType.Byte))
mv.visitInsn(I2B);
else if (dest.equals(TargetType.Char))
@@ -268,309 +285,300 @@ public class Codegen {
private void generateBinaryOp(State state, TargetBinaryOp op) {
var mv = state.mv;
switch (op) {
- case Add add: {
- if (add.type().equals(TargetType.String)) {
- mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
- mv.visitInsn(DUP);
- generate(state, add.left());
- convertToString(state, add.left().type());
- mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "", "(Ljava/lang/String;)V", false);
- } else {
- generate(state, add.left());
- convertTo(state, add.left().type(), add.type());
- generate(state, add.right());
- convertTo(state, add.right().type(), add.type());
- var type = add.type();
- if (type.equals(TargetType.Byte)
- || type.equals(TargetType.Char)
- || type.equals(TargetType.Integer)
- || type.equals(TargetType.Short)) {
- mv.visitInsn(IADD);
- } else if (type.equals(TargetType.Long)) {
- mv.visitInsn(LADD);
- } else if (type.equals(TargetType.Float)) {
- mv.visitInsn(FADD);
- } else if (type.equals(TargetType.Double)) {
- mv.visitInsn(DADD);
- } else {
- throw new CodeGenException("Invalid argument to Add expression");
- }
- }
- if (add.type().equals(TargetType.String)) {
- generate(state, add.right());
- convertToString(state, add.right().type());
- mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
- mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
- }
- break;
- }
- case Sub sub: {
- generate(state, sub.left());
- convertTo(state, sub.left().type(), op.type());
- generate(state, sub.right());
- convertTo(state, sub.right().type(), op.type());
- var type = sub.type();
- if (type.equals(TargetType.Byte)
- || type.equals(TargetType.Char)
- || type.equals(TargetType.Integer)
- || type.equals(TargetType.Short)) {
- mv.visitInsn(ISUB);
+ case Add add: {
+ if (add.type().equals(TargetType.String)) {
+ mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
+ mv.visitInsn(DUP);
+ generate(state, add.left());
+ convertToString(state, add.left().type());
+ mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "", "(Ljava/lang/String;)V", false);
+ } else {
+ generate(state, add.left());
+ convertTo(state, add.left().type(), add.type());
+ generate(state, add.right());
+ convertTo(state, add.right().type(), add.type());
+ var type = add.type();
+ if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
+ mv.visitInsn(IADD);
} else if (type.equals(TargetType.Long)) {
- mv.visitInsn(LSUB);
+ mv.visitInsn(LADD);
} else if (type.equals(TargetType.Float)) {
- mv.visitInsn(FSUB);
+ mv.visitInsn(FADD);
} else if (type.equals(TargetType.Double)) {
- mv.visitInsn(DSUB);
+ mv.visitInsn(DADD);
} else {
- throw new CodeGenException("Invalid argument to Sub expression");
+ throw new CodeGenException("Invalid argument to Add expression, type: " + add.type());
}
- break;
}
- case Div div: {
- generate(state, div.left());
- convertTo(state, div.left().type(), op.type());
- generate(state, div.right());
- convertTo(state, div.right().type(), op.type());
- var type = div.type();
- if (type.equals(TargetType.Byte)
- || type.equals(TargetType.Char)
- || type.equals(TargetType.Integer)
- || type.equals(TargetType.Short)) {
- mv.visitInsn(IDIV);
- } else if (type.equals(TargetType.Long)) {
- mv.visitInsn(LDIV);
- } else if (type.equals(TargetType.Float)) {
- mv.visitInsn(FDIV);
- } else if (type.equals(TargetType.Double)) {
- mv.visitInsn(DDIV);
- } else {
- throw new CodeGenException("Invalid argument to Div expression");
- }
- break;
+ if (add.type().equals(TargetType.String)) {
+ generate(state, add.right());
+ convertToString(state, add.right().type());
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
+ mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
}
- case Mul mul: {
- generate(state, mul.left());
- convertTo(state, mul.left().type(), op.type());
- generate(state, mul.right());
- convertTo(state, mul.right().type(), op.type());
- var type = mul.type();
- if (type.equals(TargetType.Byte)
- || type.equals(TargetType.Char)
- || type.equals(TargetType.Integer)
- || type.equals(TargetType.Short)) {
- mv.visitInsn(IMUL);
- } else if (type.equals(TargetType.Long)) {
- mv.visitInsn(LMUL);
- } else if (type.equals(TargetType.Float)) {
- mv.visitInsn(FMUL);
- } else if (type.equals(TargetType.Double)) {
- mv.visitInsn(DMUL);
- } else {
- throw new CodeGenException("Invalid argument to Mul expression");
- }
- break;
+ break;
+ }
+ case Sub sub: {
+ generate(state, sub.left());
+ convertTo(state, sub.left().type(), op.type());
+ generate(state, sub.right());
+ convertTo(state, sub.right().type(), op.type());
+ var type = sub.type();
+ if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
+ mv.visitInsn(ISUB);
+ } else if (type.equals(TargetType.Long)) {
+ mv.visitInsn(LSUB);
+ } else if (type.equals(TargetType.Float)) {
+ mv.visitInsn(FSUB);
+ } else if (type.equals(TargetType.Double)) {
+ mv.visitInsn(DSUB);
+ } else {
+ throw new CodeGenException("Invalid argument to Sub expression");
}
- case Rem rem: {
- generate(state, rem.left());
- convertTo(state, rem.left().type(), op.type());
- generate(state, rem.right());
- convertTo(state, rem.right().type(), op.type());
- var type = rem.type();
- if (type.equals(TargetType.Byte)
- || type.equals(TargetType.Char)
- || type.equals(TargetType.Integer)
- || type.equals(TargetType.Short)) {
- mv.visitInsn(IREM);
- } else if (type.equals(TargetType.Long)) {
- mv.visitInsn(LREM);
- } else if (type.equals(TargetType.Float)) {
- mv.visitInsn(FREM);
- } else if (type.equals(TargetType.Double)) {
- mv.visitInsn(DREM);
- } else {
- throw new CodeGenException("Invalid argument to Rem expression");
- }
- break;
+ break;
+ }
+ case Div div: {
+ generate(state, div.left());
+ convertTo(state, div.left().type(), op.type());
+ generate(state, div.right());
+ convertTo(state, div.right().type(), op.type());
+ var type = div.type();
+ if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
+ mv.visitInsn(IDIV);
+ } else if (type.equals(TargetType.Long)) {
+ mv.visitInsn(LDIV);
+ } else if (type.equals(TargetType.Float)) {
+ mv.visitInsn(FDIV);
+ } else if (type.equals(TargetType.Double)) {
+ mv.visitInsn(DDIV);
+ } else {
+ throw new CodeGenException("Invalid argument to Div expression");
}
- case Or or: {
- Label or_false = new Label();
- Label or_true = new Label();
- Label end = new Label();
- generate(state, or.left());
- mv.visitJumpInsn(IFNE, or_true);
- generate(state, or.right());
- mv.visitJumpInsn(IFEQ, or_false);
- mv.visitLabel(or_true);
- mv.visitInsn(ICONST_1);
- mv.visitJumpInsn(GOTO, end);
- mv.visitLabel(or_false);
- mv.visitInsn(ICONST_0);
- mv.visitLabel(end);
- break;
+ break;
+ }
+ case Mul mul: {
+ generate(state, mul.left());
+ convertTo(state, mul.left().type(), op.type());
+ generate(state, mul.right());
+ convertTo(state, mul.right().type(), op.type());
+ var type = mul.type();
+ if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
+ mv.visitInsn(IMUL);
+ } else if (type.equals(TargetType.Long)) {
+ mv.visitInsn(LMUL);
+ } else if (type.equals(TargetType.Float)) {
+ mv.visitInsn(FMUL);
+ } else if (type.equals(TargetType.Double)) {
+ mv.visitInsn(DMUL);
+ } else {
+ throw new CodeGenException("Invalid argument to Mul expression");
}
- case And and: {
- Label and_false = new Label();
- Label end = new Label();
- generate(state, and.left());
- mv.visitJumpInsn(IFEQ, and_false);
- generate(state, and.right());
- mv.visitJumpInsn(IFEQ, and_false);
- mv.visitInsn(ICONST_1);
- mv.visitJumpInsn(GOTO, end);
- mv.visitLabel(and_false);
- mv.visitInsn(ICONST_0);
- mv.visitLabel(end);
- break;
+ break;
+ }
+ case Rem rem: {
+ generate(state, rem.left());
+ convertTo(state, rem.left().type(), op.type());
+ generate(state, rem.right());
+ convertTo(state, rem.right().type(), op.type());
+ var type = rem.type();
+ if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
+ mv.visitInsn(IREM);
+ } else if (type.equals(TargetType.Long)) {
+ mv.visitInsn(LREM);
+ } else if (type.equals(TargetType.Float)) {
+ mv.visitInsn(FREM);
+ } else if (type.equals(TargetType.Double)) {
+ mv.visitInsn(DREM);
+ } else {
+ throw new CodeGenException("Invalid argument to Rem expression");
}
- case BAnd band: {
- generate(state, band.left());
- convertTo(state, band.left().type(), op.type());
- generate(state, band.right());
- convertTo(state, band.right().type(), op.type());
- if (band.type().equals(TargetType.Long))
- mv.visitInsn(LAND);
- else mv.visitInsn(IAND);
- break;
+ break;
+ }
+ case Or or: {
+ Label or_false = new Label();
+ Label or_true = new Label();
+ Label end = new Label();
+ generate(state, or.left());
+ mv.visitJumpInsn(IFNE, or_true);
+ generate(state, or.right());
+ mv.visitJumpInsn(IFEQ, or_false);
+ mv.visitLabel(or_true);
+ mv.visitInsn(ICONST_1);
+ mv.visitJumpInsn(GOTO, end);
+ mv.visitLabel(or_false);
+ mv.visitInsn(ICONST_0);
+ mv.visitLabel(end);
+ break;
+ }
+ case And and: {
+ Label and_false = new Label();
+ Label end = new Label();
+ generate(state, and.left());
+ mv.visitJumpInsn(IFEQ, and_false);
+ generate(state, and.right());
+ mv.visitJumpInsn(IFEQ, and_false);
+ mv.visitInsn(ICONST_1);
+ mv.visitJumpInsn(GOTO, end);
+ mv.visitLabel(and_false);
+ mv.visitInsn(ICONST_0);
+ mv.visitLabel(end);
+ break;
+ }
+ case BAnd band: {
+ generate(state, band.left());
+ convertTo(state, band.left().type(), op.type());
+ generate(state, band.right());
+ convertTo(state, band.right().type(), op.type());
+ if (band.type().equals(TargetType.Long))
+ mv.visitInsn(LAND);
+ else
+ mv.visitInsn(IAND);
+ break;
+ }
+ case BOr bor: {
+ generate(state, bor.left());
+ convertTo(state, bor.left().type(), op.type());
+ generate(state, bor.right());
+ convertTo(state, bor.right().type(), op.type());
+ if (bor.type().equals(TargetType.Long))
+ mv.visitInsn(LOR);
+ else
+ mv.visitInsn(IOR);
+ break;
+ }
+ case XOr xor: {
+ generate(state, xor.left());
+ convertTo(state, xor.left().type(), op.type());
+ generate(state, xor.right());
+ convertTo(state, xor.right().type(), op.type());
+ if (xor.type().equals(TargetType.Long))
+ mv.visitInsn(LXOR);
+ else
+ mv.visitInsn(IXOR);
+ break;
+ }
+ case Instof instof: {
+ // TODO
+ throw new NotImplementedException();
+ }
+ case Shl shl: {
+ generate(state, shl.left());
+ convertTo(state, shl.left().type(), op.type());
+ generate(state, shl.right());
+ convertTo(state, shl.right().type(), op.type());
+ if (shl.type().equals(TargetType.Long))
+ mv.visitInsn(LSHL);
+ else
+ mv.visitInsn(ISHL);
+ break;
+ }
+ case Shr shr: {
+ generate(state, shr.left());
+ convertTo(state, shr.left().type(), op.type());
+ generate(state, shr.right());
+ convertTo(state, shr.right().type(), op.type());
+ if (shr.type().equals(TargetType.Long))
+ mv.visitInsn(LSHR);
+ else
+ mv.visitInsn(ISHR);
+ break;
+ }
+ case UShr ushr: {
+ generate(state, ushr.left());
+ convertTo(state, ushr.left().type(), op.type());
+ generate(state, ushr.right());
+ convertTo(state, ushr.right().type(), op.type());
+ if (ushr.type().equals(TargetType.Long))
+ mv.visitInsn(LUSHR);
+ else
+ mv.visitInsn(IUSHR);
+ break;
+ }
+ case Greater greater: {
+ var type = largerType(greater.left().type(), greater.right().type());
+ if (type.equals(TargetType.Long)) {
+ generateRelationalOperator(state, greater, type, LCMP, IFGT);
+ } else if (type.equals(TargetType.Float)) {
+ generateRelationalOperator(state, greater, type, FCMPL, IFGT);
+ } else if (type.equals(TargetType.Double)) {
+ generateRelationalOperator(state, greater, type, DCMPL, IFGT);
+ } else {
+ generateRelationalOperator(state, greater, type, IF_ICMPGT);
}
- case BOr bor: {
- generate(state, bor.left());
- convertTo(state, bor.left().type(), op.type());
- generate(state, bor.right());
- convertTo(state, bor.right().type(), op.type());
- if (bor.type().equals(TargetType.Long))
- mv.visitInsn(LOR);
- else mv.visitInsn(IOR);
- break;
+ break;
+ }
+ case Less less: {
+ var type = largerType(less.left().type(), less.right().type());
+ if (type.equals(TargetType.Long)) {
+ generateRelationalOperator(state, less, type, LCMP, IFLT);
+ } else if (type.equals(TargetType.Float)) {
+ generateRelationalOperator(state, less, type, FCMPL, IFLT);
+ } else if (type.equals(TargetType.Double)) {
+ generateRelationalOperator(state, less, type, DCMPL, IFLT);
+ } else {
+ generateRelationalOperator(state, less, type, IF_ICMPLT);
}
- case XOr xor: {
- generate(state, xor.left());
- convertTo(state, xor.left().type(), op.type());
- generate(state, xor.right());
- convertTo(state, xor.right().type(), op.type());
- if (xor.type().equals(TargetType.Long))
- mv.visitInsn(LXOR);
- else mv.visitInsn(IXOR);
- break;
+ break;
+ }
+ case GreaterOrEqual greaterOrEqual: {
+ var type = largerType(greaterOrEqual.left().type(), greaterOrEqual.right().type());
+ if (type.equals(TargetType.Long)) {
+ generateRelationalOperator(state, greaterOrEqual, type, LCMP, IFGE);
+ } else if (type.equals(TargetType.Float)) {
+ generateRelationalOperator(state, greaterOrEqual, type, FCMPL, IFGE);
+ } else if (type.equals(TargetType.Double)) {
+ generateRelationalOperator(state, greaterOrEqual, type, DCMPL, IFGE);
+ } else {
+ generateRelationalOperator(state, greaterOrEqual, type, IF_ICMPGE);
}
- case Shl shl: {
- generate(state, shl.left());
- convertTo(state, shl.left().type(), op.type());
- generate(state, shl.right());
- convertTo(state, shl.right().type(), op.type());
- if (shl.type().equals(TargetType.Long))
- mv.visitInsn(LSHL);
- else mv.visitInsn(ISHL);
- break;
+ break;
+ }
+ case LessOrEqual lessOrEqual: {
+ var type = largerType(lessOrEqual.left().type(), lessOrEqual.right().type());
+ if (type.equals(TargetType.Long)) {
+ generateRelationalOperator(state, lessOrEqual, type, LCMP, IFLE);
+ } else if (type.equals(TargetType.Float)) {
+ generateRelationalOperator(state, lessOrEqual, type, FCMPL, IFLE);
+ } else if (type.equals(TargetType.Double)) {
+ generateRelationalOperator(state, lessOrEqual, type, DCMPL, IFLE);
+ } else {
+ generateRelationalOperator(state, lessOrEqual, type, IF_ICMPLE);
}
- case Shr shr: {
- generate(state, shr.left());
- convertTo(state, shr.left().type(), op.type());
- generate(state, shr.right());
- convertTo(state, shr.right().type(), op.type());
- if (shr.type().equals(TargetType.Long))
- mv.visitInsn(LSHR);
- else mv.visitInsn(ISHR);
- break;
+ break;
+ }
+ case Equal equal: {
+ var type = largerType(equal.left().type(), equal.right().type());
+ if (type.equals(TargetType.Long)) {
+ generateRelationalOperator(state, equal, type, LCMP, IFEQ);
+ } else if (type.equals(TargetType.Float)) {
+ generateRelationalOperator(state, equal, type, FCMPL, IFEQ);
+ } else if (type.equals(TargetType.Double)) {
+ generateRelationalOperator(state, equal, type, DCMPL, IFEQ);
+ } else if (type.equals(TargetType.Char) || type.equals(TargetType.Short) || type.equals(TargetType.Byte) || type.equals(TargetType.Integer) || type.equals(TargetType.Boolean)) {
+ generateRelationalOperator(state, equal, type, IF_ICMPEQ);
+ } else {
+ generateRelationalOperator(state, equal, type, IF_ACMPEQ);
}
- case UShr ushr: {
- generate(state, ushr.left());
- convertTo(state, ushr.left().type(), op.type());
- generate(state, ushr.right());
- convertTo(state, ushr.right().type(), op.type());
- if (ushr.type().equals(TargetType.Long))
- mv.visitInsn(LUSHR);
- else mv.visitInsn(IUSHR);
- break;
- }
- case Greater greater: {
- var type = largerType(greater.left().type(), greater.right().type());
- if (type.equals(TargetType.Long)) {
- generateRelationalOperator(state, greater, type, LCMP, IFGT);
- } else if (type.equals(TargetType.Float)) {
- generateRelationalOperator(state, greater, type, FCMPL, IFGT);
- } else if (type.equals(TargetType.Double)) {
- generateRelationalOperator(state, greater, type, DCMPL, IFGT);
- } else {
- generateRelationalOperator(state, greater, type, IF_ICMPGT);
- }
- break;
- }
- case Less less: {
- var type = largerType(less.left().type(), less.right().type());
- if (type.equals(TargetType.Long)) {
- generateRelationalOperator(state, less, type, LCMP, IFLT);
- } else if (type.equals(TargetType.Float)) {
- generateRelationalOperator(state, less, type, FCMPL, IFLT);
- } else if (type.equals(TargetType.Double)) {
- generateRelationalOperator(state, less, type, DCMPL, IFLT);
- } else {
- generateRelationalOperator(state, less, type, IF_ICMPLT);
- }
- break;
- }
- case GreaterOrEqual greaterOrEqual: {
- var type = largerType(greaterOrEqual.left().type(), greaterOrEqual.right().type());
- if (type.equals(TargetType.Long)) {
- generateRelationalOperator(state, greaterOrEqual, type, LCMP, IFGE);
- } else if (type.equals(TargetType.Float)) {
- generateRelationalOperator(state, greaterOrEqual, type, FCMPL, IFGE);
- } else if (type.equals(TargetType.Double)) {
- generateRelationalOperator(state, greaterOrEqual, type, DCMPL, IFGE);
- } else {
- generateRelationalOperator(state, greaterOrEqual, type, IF_ICMPGE);
- }
- break;
- }
- case LessOrEqual lessOrEqual: {
- var type = largerType(lessOrEqual.left().type(), lessOrEqual.right().type());
- if (type.equals(TargetType.Long)) {
- generateRelationalOperator(state, lessOrEqual, type, LCMP, IFLE);
- } else if (type.equals(TargetType.Float)) {
- generateRelationalOperator(state, lessOrEqual, type, FCMPL, IFLE);
- } else if (type.equals(TargetType.Double)) {
- generateRelationalOperator(state, lessOrEqual, type, DCMPL, IFLE);
- } else {
- generateRelationalOperator(state, lessOrEqual, type, IF_ICMPLE);
- }
- break;
- }
- case Equal equal: {
- var type = largerType(equal.left().type(), equal.right().type());
- if (type.equals(TargetType.Long)) {
- generateRelationalOperator(state, equal, type, LCMP, IFEQ);
- } else if (type.equals(TargetType.Float)) {
- generateRelationalOperator(state, equal, type, FCMPL, IFEQ);
- } else if (type.equals(TargetType.Double)) {
- generateRelationalOperator(state, equal, type, DCMPL, IFEQ);
- } else if (type.equals(TargetType.Char)
- || type.equals(TargetType.Short)
- || type.equals(TargetType.Byte)
- || type.equals(TargetType.Integer)
- || type.equals(TargetType.Boolean)) {
- generateRelationalOperator(state, equal, type, IF_ICMPEQ);
- } else {
- generateRelationalOperator(state, equal, type, IF_ACMPEQ);
- }
- break;
- }
- case NotEqual notEqual: {
- var type = largerType(notEqual.left().type(), notEqual.right().type());
- if (type.equals(TargetType.Long)) {
- generateRelationalOperator(state, notEqual, type, LCMP, IFNE);
- } else if (type.equals(TargetType.Float)) {
- generateRelationalOperator(state, notEqual, type, FCMPL, IFNE);
- } else if (type.equals(TargetType.Double)) {
- generateRelationalOperator(state, notEqual, type, DCMPL, IFNE);
- } else if (type.equals(TargetType.Char)
- || type.equals(TargetType.Short)
- || type.equals(TargetType.Byte)
- || type.equals(TargetType.Integer)) {
- generateRelationalOperator(state, notEqual, type, IF_ICMPNE);
- } else {
- generateRelationalOperator(state, notEqual, type, IF_ACMPNE);
- }
- break;
+ break;
+ }
+ case NotEqual notEqual: {
+ var type = largerType(notEqual.left().type(), notEqual.right().type());
+ if (type.equals(TargetType.Long)) {
+ generateRelationalOperator(state, notEqual, type, LCMP, IFNE);
+ } else if (type.equals(TargetType.Float)) {
+ generateRelationalOperator(state, notEqual, type, FCMPL, IFNE);
+ } else if (type.equals(TargetType.Double)) {
+ generateRelationalOperator(state, notEqual, type, DCMPL, IFNE);
+ } else if (type.equals(TargetType.Char) || type.equals(TargetType.Short) || type.equals(TargetType.Byte) || type.equals(TargetType.Integer)) {
+ generateRelationalOperator(state, notEqual, type, IF_ICMPNE);
+ } else {
+ generateRelationalOperator(state, notEqual, type, IF_ACMPNE);
}
+ break;
+ }
+ default: {
+ throw new NotImplementedException();
+ }
}
}
@@ -588,11 +596,10 @@ public class Codegen {
private void generateUnaryOp(State state, TargetUnaryOp op) {
var mv = state.mv;
switch (op) {
- case TargetUnaryOp.Add add:
+ case TargetUnaryOp.Add add ->
// This literally does nothing
- generate(state, add.expr());
- break;
- case TargetUnaryOp.Negate negate:
+ generate(state, add.expr());
+ case TargetUnaryOp.Negate negate -> {
generate(state, negate.expr());
if (negate.type().equals(TargetType.Double))
mv.visitInsn(DNEG);
@@ -600,9 +607,10 @@ public class Codegen {
mv.visitInsn(FNEG);
else if (negate.type().equals(TargetType.Long))
mv.visitInsn(LNEG);
- else mv.visitInsn(INEG);
- break;
- case TargetUnaryOp.Not not:
+ else
+ mv.visitInsn(INEG);
+ }
+ case TargetUnaryOp.Not not -> {
generate(state, not.expr());
if (not.type().equals(TargetType.Long)) {
mv.visitLdcInsn(-1L);
@@ -611,8 +619,8 @@ public class Codegen {
mv.visitInsn(ICONST_M1);
mv.visitInsn(IXOR);
}
- break;
- case TargetUnaryOp.PreIncrement preIncrement:
+ }
+ case TargetUnaryOp.PreIncrement preIncrement -> {
generate(state, preIncrement.expr());
if (preIncrement.type().equals(TargetType.Float)) {
mv.visitLdcInsn(1F);
@@ -633,8 +641,8 @@ public class Codegen {
}
boxPrimitive(state, preIncrement.type());
afterIncDec(state, preIncrement);
- break;
- case TargetUnaryOp.PreDecrement preDecrement:
+ }
+ case TargetUnaryOp.PreDecrement preDecrement -> {
generate(state, preDecrement.expr());
if (preDecrement.type().equals(TargetType.Float)) {
mv.visitLdcInsn(1F);
@@ -655,8 +663,8 @@ public class Codegen {
}
boxPrimitive(state, preDecrement.type());
afterIncDec(state, preDecrement);
- break;
- case TargetUnaryOp.PostIncrement postIncrement:
+ }
+ case TargetUnaryOp.PostIncrement postIncrement -> {
generate(state, postIncrement.expr());
if (postIncrement.type().equals(TargetType.Float)) {
mv.visitInsn(DUP);
@@ -677,8 +685,8 @@ public class Codegen {
}
boxPrimitive(state, postIncrement.type());
afterIncDec(state, postIncrement);
- break;
- case TargetUnaryOp.PostDecrement postDecrement:
+ }
+ case TargetUnaryOp.PostDecrement postDecrement -> {
generate(state, postDecrement.expr());
if (postDecrement.type().equals(TargetType.Float)) {
mv.visitInsn(DUP);
@@ -699,7 +707,7 @@ public class Codegen {
}
boxPrimitive(state, postDecrement.type());
afterIncDec(state, postDecrement);
- break;
+ }
}
}
@@ -712,33 +720,17 @@ public class Codegen {
} else {
var name = "lambda$" + lambdaCounter++;
var parameters = new ArrayList<>(lambda.captures());
- parameters.addAll(lambda.params().stream()
- .map(param -> param.type() instanceof TargetGenericType ? new MethodParameter(TargetType.Object, param.name()) : param)
- .toList());
+ parameters.addAll(lambda.params().stream().map(param -> param.pattern().type() instanceof TargetGenericType ? param.withType(TargetType.Object) : param).toList());
- impl = new TargetMethod(
- 0, name,
- lambda.block(),
- new TargetMethod.Signature(
- Set.of(),
- parameters,
- lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType()
- ),
- null
- );
+ impl = new TargetMethod(0, name, lambda.block(), new TargetMethod.Signature(Set.of(), parameters, lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType()), null);
generateMethod(impl);
lambdas.put(lambda, impl);
}
- var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
- MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
+ var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
- var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory",
- mt.toMethodDescriptorString(), false);
- var handle = new Handle(
- H_INVOKEVIRTUAL, clazz.getName(), impl.name(),
- impl.getDescriptor(), false
- );
+ var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", mt.toMethodDescriptorString(), false);
+ var handle = new Handle(H_INVOKEVIRTUAL, clazz.getName(), impl.name(), impl.getDescriptor(), false);
// TODO maybe make this a function?
var desugared = "(";
@@ -747,255 +739,551 @@ public class Codegen {
desugared += ")";
if (lambda.returnType() != null)
desugared += "Ljava/lang/Object;";
- else desugared += "V";
+ else
+ desugared += "V";
var params = new ArrayList();
params.add(new TargetRefType(clazz.qualifiedName()));
- params.addAll(lambda.captures().stream()
- .map(MethodParameter::type)
- .toList());
+ params.addAll(lambda.captures().stream().map(mp -> mp.pattern().type()).toList());
var descriptor = TargetMethod.getDescriptor(lambda.type(), params.toArray(TargetType[]::new));
mv.visitVarInsn(ALOAD, 0);
- for (var capture : lambda.captures())
- mv.visitVarInsn(ALOAD, state.scope.get(capture.name()).index);
+ for (var capture : lambda.captures()) {
+ var pattern = (TargetTypePattern) capture.pattern();
+ mv.visitVarInsn(ALOAD, state.scope.get(pattern.name()).index);
+ }
- mv.visitInvokeDynamicInsn("apply", descriptor,
- bootstrap, Type.getType(desugared), handle,
- Type.getType(TargetMethod.getDescriptor(impl.signature().returnType(), lambda.params().stream().map(MethodParameter::type).toArray(TargetType[]::new)))
- );
+ mv.visitInvokeDynamicInsn("apply", descriptor, bootstrap, Type.getType(desugared), handle, Type.getType(TargetMethod.getDescriptor(impl.signature().returnType(), lambda.params().stream().map(mp -> mp.pattern().type()).toArray(TargetType[]::new))));
}
private void generate(State state, TargetExpression expr) {
var mv = state.mv;
switch (expr) {
- case TargetClassName ignored:
- break; // NOP
- case TargetBlock block: {
- var localCounter = state.localCounter;
- state.enterScope();
- for (var e : block.statements()) {
- generate(state, e);
- if (e instanceof TargetMethodCall) {
- if (e.type() != null) popValue(state, e.type());
- } else if (e instanceof TargetAssign) {
- mv.visitInsn(POP); // TODO Nasty fix, we don't know if it is a primitive double or long
- } else if (e instanceof TargetStatementExpression se) {
- popValue(state, se.type());
+ case TargetClassName ignored:
+ break; // NOP
+ case TargetBlock block: {
+ var localCounter = state.localCounter;
+ state.enterScope();
+ for (var e : block.statements()) {
+ generate(state, e);
+ if (e instanceof TargetMethodCall) {
+ if (e.type() != null)
+ popValue(state, e.type());
+ } else if (e instanceof TargetAssign) {
+ mv.visitInsn(POP); // TODO Nasty fix, we don't know if it is a primitive double or long
+ } else if (e instanceof TargetStatementExpression se) {
+ popValue(state, se.type());
+ }
+ }
+ state.exitScope();
+ state.localCounter = localCounter;
+ break;
+ }
+ case TargetCast cast:
+ generate(state, cast.expr());
+ convertTo(state, cast.expr().type(), cast.type());
+ break;
+ case TargetInstanceOf instanceOf:
+ generateInstanceOf(state, instanceOf);
+ break;
+ case TargetLiteral literal:
+ switch (literal) {
+ case IntLiteral intLiteral -> mv.visitLdcInsn(intLiteral.value());
+ case FloatLiteral floatLiteral -> mv.visitLdcInsn(floatLiteral.value());
+ case LongLiteral longLiteral -> mv.visitLdcInsn(longLiteral.value());
+ case StringLiteral stringLiteral -> mv.visitLdcInsn(stringLiteral.value());
+ case CharLiteral charLiteral -> mv.visitIntInsn(BIPUSH, charLiteral.value());
+ case DoubleLiteral doubleLiteral -> mv.visitLdcInsn(doubleLiteral.value());
+ case BooleanLiteral booleanLiteral -> {
+ if (booleanLiteral.value()) {
+ mv.visitInsn(ICONST_1);
+ } else {
+ mv.visitInsn(ICONST_0);
}
}
- state.exitScope();
- state.localCounter = localCounter;
- break;
}
- case TargetCast cast:
- generate(state, cast.expr());
- convertTo(state, cast.expr().type(), cast.type());
- break;
- case TargetInstanceOf instanceOf:
- mv.visitTypeInsn(INSTANCEOF, instanceOf.right().getInternalName());
- break;
- case TargetLiteral literal:
- switch (literal) {
- case IntLiteral intLiteral:
- mv.visitLdcInsn(intLiteral.value());
- break;
- case FloatLiteral floatLiteral:
- mv.visitLdcInsn(floatLiteral.value());
- break;
- case LongLiteral longLiteral:
- mv.visitLdcInsn(longLiteral.value());
- break;
- case StringLiteral stringLiteral:
- mv.visitLdcInsn(stringLiteral.value());
- break;
- case CharLiteral charLiteral:
- mv.visitIntInsn(BIPUSH, charLiteral.value());
- break;
- case DoubleLiteral doubleLiteral:
- mv.visitLdcInsn(doubleLiteral.value());
- break;
- case BooleanLiteral booleanLiteral:
- if (booleanLiteral.value()) {
- mv.visitInsn(ICONST_1);
- } else {
- mv.visitInsn(ICONST_0);
- }
- 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);
+ 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;
+ case TargetUnaryOp op:
+ generateUnaryOp(state, op);
+ break;
+ case TargetAssign assign: {
+ switch (assign.left()) {
+ case TargetLocalVar localVar -> {
+ generate(state, assign.right());
+ convertTo(state, assign.right().type(), localVar.type());
+ boxPrimitive(state, localVar.type());
+ var local = state.scope.get(localVar.name());
+ mv.visitInsn(DUP);
mv.visitVarInsn(ASTORE, local.index());
}
- break;
- }
- case TargetBinaryOp op:
- generateBinaryOp(state, op);
- break;
- case TargetUnaryOp op:
- generateUnaryOp(state, op);
- break;
- case TargetAssign assign: {
- switch (assign.left()) {
- case TargetLocalVar localVar: {
- generate(state, assign.right());
- convertTo(state, assign.right().type(), localVar.type());
- boxPrimitive(state, localVar.type());
- var local = state.scope.get(localVar.name());
- mv.visitInsn(DUP);
- mv.visitVarInsn(ASTORE, local.index());
- break;
- }
- case TargetFieldVar dot: {
- var fieldType = dot.type();
- generate(state, dot.left());
- generate(state, assign.right());
- convertTo(state, assign.right().type(), fieldType);
- boxPrimitive(state, fieldType);
- if (dot.isStatic())
- mv.visitInsn(DUP);
- else mv.visitInsn(DUP_X1);
- mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toSignature());
- break;
- }
- default:
- throw new CodeGenException("Invalid assignment");
- }
- break;
- }
- case TargetLocalVar localVar: {
- LocalVar local = state.scope.get(localVar.name());
- mv.visitVarInsn(ALOAD, local.index());
- unboxPrimitive(state, local.type());
- break;
- }
- case TargetFieldVar dot: {
- if (!dot.isStatic())
+ case TargetFieldVar dot -> {
+ var fieldType = dot.type();
generate(state, dot.left());
- mv.visitFieldInsn(dot.isStatic() ? GETSTATIC : GETFIELD, dot.left().type().getInternalName(), dot.right(), dot.type().toSignature());
- unboxPrimitive(state, dot.type());
- break;
- }
- case TargetFor _for: {
- state.enterScope();
- var localCounter = state.localCounter;
- if (_for.init() != null)
- generate(state, _for.init());
- Label start = new Label();
- Label end = new Label();
- mv.visitLabel(start);
- if (_for.termination() != null)
- generate(state, _for.termination());
- else mv.visitInsn(ICONST_1);
- mv.visitJumpInsn(IFEQ, end);
- generate(state, _for.body());
- if (_for.increment() != null) {
- generate(state, _for.increment());
- if (_for.increment().type() != null) {
- popValue(state, _for.increment().type());
- }
+ generate(state, assign.right());
+ convertTo(state, assign.right().type(), fieldType);
+ boxPrimitive(state, fieldType);
+ if (dot.isStatic())
+ mv.visitInsn(DUP);
+ else
+ mv.visitInsn(DUP_X1);
+ mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toSignature());
}
- mv.visitJumpInsn(GOTO, start);
- mv.visitLabel(end);
- state.exitScope();
- state.localCounter = localCounter;
- break;
+ default -> throw new CodeGenException("Invalid assignment");
}
- case TargetWhile _while: {
- Label start = new Label();
- Label end = new Label();
- mv.visitLabel(start);
- generate(state, _while.cond());
- mv.visitJumpInsn(IFEQ, end);
- generate(state, _while.body());
- mv.visitJumpInsn(GOTO, start);
- mv.visitLabel(end);
- break;
- }
- case TargetIf _if: {
- generate(state, _if.cond());
- Label _else = new Label();
- Label end = new Label();
- mv.visitJumpInsn(IFEQ, _else);
- generate(state, _if.if_body());
- mv.visitJumpInsn(GOTO, end);
- mv.visitLabel(_else);
- if (_if.else_body() != null) {
- generate(state, _if.else_body());
- }
- mv.visitLabel(end);
- break;
- }
- case TargetReturn ret: {
- if (ret.expression() != null && state.returnType != null) {
- generate(state, ret.expression());
- convertTo(state, ret.expression().type(), state.returnType);
- boxPrimitive(state, state.returnType);
- mv.visitInsn(ARETURN);
- } else mv.visitInsn(RETURN);
- break;
- }
- case TargetThis _this: {
- mv.visitVarInsn(ALOAD, 0);
- break;
- }
- case TargetSuper _super: {
- mv.visitVarInsn(ALOAD, 0);
- break;
- }
- case TargetMethodCall call: {
- generate(state, call.expr());
- for (var i = 0; i < call.args().size(); i++) {
- var e = call.args().get(i);
- var arg = call.parameterTypes().get(i);
- generate(state, e);
- if (!(arg instanceof TargetPrimitiveType))
- boxPrimitive(state, e.type());
- }
- var descriptor = call.getDescriptor();
- if (call.owner() instanceof TargetFunNType) // Decay FunN
- descriptor = TargetMethod.getDescriptor(
- call.returnType() == null ? null : TargetType.Object,
- call.parameterTypes().stream().map(x -> TargetType.Object).toArray(TargetType[]::new)
- );
+ break;
+ }
+ case TargetLocalVar localVar: {
+ LocalVar local = state.scope.get(localVar.name());
+ mv.visitVarInsn(ALOAD, local.index());
+ unboxPrimitive(state, local.type());
+ break;
+ }
+ case TargetFieldVar dot: {
+ if (!dot.isStatic())
+ generate(state, dot.left());
+ mv.visitFieldInsn(dot.isStatic() ? GETSTATIC : GETFIELD, dot.left().type().getInternalName(), dot.right(), dot.type().toSignature());
+ unboxPrimitive(state, dot.type());
+ break;
+ }
+ case TargetFor _for: {
+ state.enterScope();
+ var localCounter = state.localCounter;
+ if (_for.init() != null)
+ generate(state, _for.init());
+ Label start = new Label();
+ Label end = new Label();
+ mv.visitLabel(start);
+ if (_for.termination() != null)
+ generate(state, _for.termination());
+ else
+ mv.visitInsn(ICONST_1);
+ mv.visitJumpInsn(IFEQ, end);
- mv.visitMethodInsn(call.isInterface() ? INVOKEINTERFACE : call.isStatic() ? INVOKESTATIC: call.name().equals("") ? INVOKESPECIAL : INVOKEVIRTUAL,
- call.owner().getInternalName(), call.name(), descriptor, call.isInterface());
+ var env = new BreakEnv();
+ env.startLabel = start;
+ env.endLabel = end;
- if (call.type() != null && call.returnType() != null && !(call.returnType() instanceof TargetPrimitiveType)) {
- if (!call.returnType().equals(call.type()) && !(call.type() instanceof TargetGenericType))
- mv.visitTypeInsn(CHECKCAST, call.type().getInternalName());
- unboxPrimitive(state, call.type());
+ state.breakStack.push(env);
+ generate(state, _for.body());
+ state.breakStack.pop();
+
+ if (_for.increment() != null) {
+ generate(state, _for.increment());
+ if (_for.increment().type() != null) {
+ popValue(state, _for.increment().type());
}
- break;
}
- case TargetLambdaExpression lambda:
- generateLambdaExpression(state, lambda);
- break;
- case TargetNew _new: {
- mv.visitTypeInsn(NEW, _new.type().getInternalName());
- mv.visitInsn(DUP);
- for (TargetExpression e : _new.params()) {
- generate(state, e);
+ mv.visitJumpInsn(GOTO, start);
+ mv.visitLabel(end);
+ state.exitScope();
+ state.localCounter = localCounter;
+ break;
+ }
+ case TargetWhile _while: {
+ Label start = new Label();
+ Label end = new Label();
+ mv.visitLabel(start);
+ generate(state, _while.cond());
+ mv.visitJumpInsn(IFEQ, end);
+
+ var env = new BreakEnv();
+ env.startLabel = start;
+ env.endLabel = end;
+
+ state.breakStack.push(env);
+ generate(state, _while.body());
+ state.breakStack.pop();
+
+ mv.visitJumpInsn(GOTO, start);
+ mv.visitLabel(end);
+ break;
+ }
+ case TargetIf _if: {
+ generate(state, _if.cond());
+ Label _else = new Label();
+ Label end = new Label();
+ mv.visitJumpInsn(IFEQ, _else);
+ generate(state, _if.if_body());
+ mv.visitJumpInsn(GOTO, end);
+ mv.visitLabel(_else);
+ if (_if.else_body() != null) {
+ generate(state, _if.else_body());
+ }
+ mv.visitLabel(end);
+ break;
+ }
+ case TargetReturn ret: {
+ if (ret.expression() != null && state.returnType != null) {
+ generate(state, ret.expression());
+ convertTo(state, ret.expression().type(), state.returnType);
+ boxPrimitive(state, state.returnType);
+ mv.visitInsn(ARETURN);
+ } else
+ mv.visitInsn(RETURN);
+ break;
+ }
+ case TargetYield yield: {
+ generate(state, yield.expression());
+ try {
+ yieldValue(state, yield.expression().type());
+ mv.visitJumpInsn(GOTO, state.breakStack.peek().endLabel);
+ } catch (EmptyStackException e) {
+ throw new CodeGenException("Yield outside of switch expression");
+ }
+ break;
+ }
+ case TargetSwitch _switch: {
+ generateSwitch(state, _switch);
+ break;
+ }
+ case TargetBreak brk: {
+ if (state.breakStack.isEmpty()) throw new CodeGenException("Break outside of switch or loop");
+ mv.visitJumpInsn(GOTO, state.breakStack.peek().endLabel);
+ break;
+ }
+ case TargetContinue cnt: {
+ if (state.breakStack.isEmpty()) throw new CodeGenException("Continue outside of loop");
+ var env = state.breakStack.peek();
+ if (env.startLabel == null) throw new CodeGenException("Continue outside of loop");
+ mv.visitJumpInsn(GOTO, env.startLabel);
+ break;
+ }
+ case TargetThis _this: {
+ mv.visitVarInsn(ALOAD, 0);
+ break;
+ }
+ case TargetSuper _super: {
+ mv.visitVarInsn(ALOAD, 0);
+ break;
+ }
+ case TargetMethodCall call: {
+ generate(state, call.expr());
+ for (var i = 0; i < call.args().size(); i++) {
+ var e = call.args().get(i);
+ var arg = call.parameterTypes().get(i);
+ generate(state, e);
+ if (!(arg instanceof TargetPrimitiveType))
boxPrimitive(state, e.type());
- }
- mv.visitMethodInsn(INVOKESPECIAL, _new.type().getInternalName(), "", _new.getDescriptor(), false);
- break;
}
- default:
- throw new CodeGenException("Unexpected value: " + expr);
+ var descriptor = call.getDescriptor();
+ if (call.owner() instanceof TargetFunNType) // Decay FunN
+ descriptor = TargetMethod.getDescriptor(call.returnType() == null ? null : TargetType.Object, call.parameterTypes().stream().map(x -> TargetType.Object).toArray(TargetType[]::new));
+
+ mv.visitMethodInsn(call.isInterface() ? INVOKEINTERFACE : call.isStatic() ? INVOKESTATIC : call.name().equals("") ? INVOKESPECIAL : INVOKEVIRTUAL, call.owner().getInternalName(), call.name(), descriptor, call.isInterface());
+
+ if (call.type() != null && call.returnType() != null && !(call.returnType() instanceof TargetPrimitiveType)) {
+ if (!call.returnType().equals(call.type()) && !(call.type() instanceof TargetGenericType))
+ mv.visitTypeInsn(CHECKCAST, call.type().getInternalName());
+ unboxPrimitive(state, call.type());
+ }
+ break;
+ }
+ case TargetLambdaExpression lambda:
+ generateLambdaExpression(state, lambda);
+ break;
+ case TargetNew _new: {
+ mv.visitTypeInsn(NEW, _new.type().getInternalName());
+ mv.visitInsn(DUP);
+ for (TargetExpression e : _new.params()) {
+ generate(state, e);
+ boxPrimitive(state, e.type());
+ }
+ mv.visitMethodInsn(INVOKESPECIAL, _new.type().getInternalName(), "", _new.getDescriptor(), false);
+ break;
+ }
+ default:
+ throw new CodeGenException("Unexpected value: " + expr);
}
}
+ private void generateInstanceOf(State state, TargetInstanceOf instanceOf) {
+ var mv = state.mv;
+
+ if (instanceOf.right() instanceof TargetTypePattern right && right.name() == null) {
+ mv.visitTypeInsn(INSTANCEOF, right.type().getInternalName());
+ return;
+ }
+
+ throw new NotImplementedException();
+ }
+
+ private void yieldValue(State state, TargetType type) {
+ boxPrimitive(state, type);
+ state.mv.visitVarInsn(ASTORE, state.switchResultValue.peek());
+ }
+
+ private void generateClassicSwitch(State state, TargetSwitch aSwitch) {
+ // TODO Constant expressions are allowed, we need to evaluate them somehow...
+ // For now we just assume we get literals...
+ // TODO This always uses a lookupswitch, a tableswitch may be faster in some cases but we can't generate that every time
+ // TODO We can't switch on Strings yet, the idea for this (like javac does it) would be to implement the hash code at compile time
+ // and switch based on that, adding an equals check for every case and going to yet another tableswitch which finally decides which branch to take
+ var mv = state.mv;
+ if (aSwitch.isExpression())
+ state.pushSwitch();
+
+ generate(state, aSwitch.expr());
+
+ state.enterScope();
+
+ var keys = new int[aSwitch.cases().stream().mapToInt(c -> c.labels().size()).sum()];
+ var labels = new Label[keys.length];
+ var bodyLabels = new Label[aSwitch.cases().size()];
+
+ var end = new Label();
+ var env = new BreakEnv();
+ env.endLabel = end;
+ state.breakStack.push(env);
+
+ var i = 0;
+ var j = 0;
+ for (var case_ : aSwitch.cases()) {
+ bodyLabels[j] = new Label();
+ for (var label : case_.labels()) {
+ if (!(label instanceof TargetLiteral literal))
+ throw new CodeGenException("Labels may only be constants for now");
+ keys[i] = (int) literal.value();
+ labels[i] = bodyLabels[j];
+ i += 1;
+ }
+ j += 1;
+ }
+
+ var defaultLabel = end;
+ if (aSwitch.default_() != null) {
+ defaultLabel = new Label();
+ }
+
+ mv.visitLookupSwitchInsn(defaultLabel, keys, labels);
+
+ for (var k = 0; k < aSwitch.cases().size(); k++) {
+ mv.visitLabel(bodyLabels[k]);
+ var cse = aSwitch.cases().get(k);
+ generate(state, cse.body());
+ if (cse.isSingleExpression() && aSwitch.isExpression())
+ yieldValue(state, cse.body().statements().get(0).type());
+ if (aSwitch.isExpression()) mv.visitJumpInsn(GOTO, end);
+ }
+
+ if (aSwitch.default_() != null) {
+ mv.visitLabel(defaultLabel);
+ generate(state, aSwitch.default_().body());
+ if (aSwitch.default_().isSingleExpression() && aSwitch.isExpression())
+ yieldValue(state, aSwitch.default_().body().statements().get(0).type());
+ }
+
+ mv.visitLabel(end);
+ state.breakStack.pop();
+
+ if (aSwitch.isExpression()) {
+ mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
+ unboxPrimitive(state, aSwitch.type());
+ state.popSwitch();
+ }
+
+ state.exitScope();
+ }
+
+ private void generateEnhancedSwitch(State state, TargetSwitch aSwitch) {
+ var mv = state.mv;
+ generate(state, aSwitch.expr());
+ var tmp = state.localCounter;
+ mv.visitInsn(DUP);
+ mv.visitVarInsn(ASTORE, tmp);
+
+ state.enterScope();
+ // This is the index to start the switch from
+ mv.visitInsn(ICONST_0);
+ if (aSwitch.isExpression())
+ state.pushSwitch();
+
+ // To be able to skip ahead to the next case
+ var start = new Label();
+ mv.visitLabel(start);
+
+ var end = new Label();
+ var env = new BreakEnv();
+ env.endLabel = end;
+ state.breakStack.push(env);
+
+ var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, Object[].class);
+ var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/runtime/SwitchBootstraps", "typeSwitch", mt.toMethodDescriptorString(), false);
+
+ var types = new ArrayList