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..f347874a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,13 +51,28 @@ http://maven.apache.org/maven-v4_0_0.xsd">
org.apache.maven.plugins
maven-compiler-plugin
- 3.8.0
+ 3.11.0
--enable-preview
+<<<<<<< HEAD
20
+=======
+ 20
+>>>>>>> patternMatching
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.1.0
+
+ --enable-preview
+
+ **/JavaTXCompilerTest.java
+
+
+
org.antlr
antlr4-maven-plugin
@@ -112,8 +127,11 @@ http://maven.apache.org/maven-v4_0_0.xsd">
+<<<<<<< HEAD
20
20
+=======
+>>>>>>> patternMatching
de.dhbwstuttgart.core.ConsoleInterface
@@ -123,4 +141,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/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/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/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/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/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/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/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/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/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/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/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/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/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/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..966b4458
--- /dev/null
+++ b/src/main/antlr4/de/dhbwstuttgart/parser/antlr/Java17Parser.g4
@@ -0,0 +1,812 @@
+/*
+ [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 # reftype
+ | 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
+ | interfaceDeclaration # subinterface
+ | annotationTypeDeclaration # interfaceannotationtype
+ | classDeclaration # interfaceclass
+ | enumDeclaration # interfaceenum
+ | recordDeclaration # interfacerecord // Java17
+ ;
+
+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
+ ;
+
+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 ';'
+ | classDeclaration ';'?
+ | interfaceDeclaration ';'?
+ | enumDeclaration ';'?
+ | annotationTypeDeclaration ';'?
+ | recordDeclaration ';'? // Java17
+ ;
+
+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
+ | switchExpression ';'? #switchexpressionstmt // Java17
+ | 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 | enumConstantName=IDENTIFIER | pattern) ':'
+ | DEFAULT ':'
+ ;
+
+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 #primaryexpression
+ | 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 #lambdaexpression // Java8
+ | switchExpression #switchexpression // Java17
+
+ // Java 8 methodReference
+ | expression '::' typeArguments? identifier #methodreferenceexpression
+ | typeType '::' (typeArguments? identifier | NEW) #methodorcreatorreferenceexpression
+ | classType '::' typeArguments? NEW #creatorreferenceexpression
+ ;
+
+// Java17
+pattern
+ : primaryPattern
+ | guardedPattern
+ ;
+
+primaryPattern
+ : typePattern
+ | recordPattern
+ | '(' pattern ')'
+ ;
+
+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
+ : CASE (expressionList | NULL_LITERAL | pattern) (ARROW | COLON) switchRuleOutcome
+ | DEFAULT (ARROW | COLON) switchRuleOutcome
+ ;
+
+// Java17
+guardedPattern
+ : variableModifier* typeType? annotation* identifier ('&&' expression)*
+ | guardedPattern '&&' expression
+ ;
+
+// Java17
+switchRuleOutcome
+ : block
+ | blockStatement*
+ ;
+
+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..29699d83 100644
--- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
+++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java
@@ -28,7 +28,8 @@ public class Codegen {
this.cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
}
- private record LocalVar(int index, String name, TargetType type) {}
+ private record LocalVar(int index, String name, TargetType type) {
+ }
private static class Scope {
Scope parent;
@@ -196,9 +197,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 +208,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 +219,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 +260,293 @@ 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");
}
- 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 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;
+ }
}
}
@@ -588,118 +564,119 @@ public class Codegen {
private void generateUnaryOp(State state, TargetUnaryOp op) {
var mv = state.mv;
switch (op) {
- case TargetUnaryOp.Add add:
- // This literally does nothing
- generate(state, add.expr());
- break;
- case TargetUnaryOp.Negate negate:
- generate(state, negate.expr());
- if (negate.type().equals(TargetType.Double))
- mv.visitInsn(DNEG);
- else if (negate.type().equals(TargetType.Float))
- mv.visitInsn(FNEG);
- else if (negate.type().equals(TargetType.Long))
- mv.visitInsn(LNEG);
- else mv.visitInsn(INEG);
- break;
- case TargetUnaryOp.Not not:
- generate(state, not.expr());
- if (not.type().equals(TargetType.Long)) {
- mv.visitLdcInsn(-1L);
- mv.visitInsn(LXOR);
- } else {
- mv.visitInsn(ICONST_M1);
- mv.visitInsn(IXOR);
- }
- break;
- case TargetUnaryOp.PreIncrement preIncrement:
- generate(state, preIncrement.expr());
- if (preIncrement.type().equals(TargetType.Float)) {
- mv.visitLdcInsn(1F);
- mv.visitInsn(FADD);
- mv.visitInsn(DUP);
- } else if (preIncrement.type().equals(TargetType.Double)) {
- mv.visitLdcInsn(1D);
- mv.visitInsn(DADD);
- mv.visitInsn(DUP2);
- } else if (preIncrement.type().equals(TargetType.Long)) {
- mv.visitLdcInsn(1L);
- mv.visitInsn(LADD);
- mv.visitInsn(DUP2);
- } else {
- mv.visitLdcInsn(1);
- mv.visitInsn(IADD);
- mv.visitInsn(DUP);
- }
- boxPrimitive(state, preIncrement.type());
- afterIncDec(state, preIncrement);
- break;
- case TargetUnaryOp.PreDecrement preDecrement:
- generate(state, preDecrement.expr());
- if (preDecrement.type().equals(TargetType.Float)) {
- mv.visitLdcInsn(1F);
- mv.visitInsn(FSUB);
- mv.visitInsn(DUP);
- } else if (preDecrement.type().equals(TargetType.Double)) {
- mv.visitLdcInsn(1D);
- mv.visitInsn(DSUB);
- mv.visitInsn(DUP2);
- } else if (preDecrement.type().equals(TargetType.Long)) {
- mv.visitLdcInsn(1L);
- mv.visitInsn(LSUB);
- mv.visitInsn(DUP2);
- } else {
- mv.visitLdcInsn(1);
- mv.visitInsn(ISUB);
- mv.visitInsn(DUP);
- }
- boxPrimitive(state, preDecrement.type());
- afterIncDec(state, preDecrement);
- break;
- case TargetUnaryOp.PostIncrement postIncrement:
- generate(state, postIncrement.expr());
- if (postIncrement.type().equals(TargetType.Float)) {
- mv.visitInsn(DUP);
- mv.visitLdcInsn(1F);
- mv.visitInsn(FADD);
- } else if (postIncrement.type().equals(TargetType.Double)) {
- mv.visitInsn(DUP2);
- mv.visitLdcInsn(1D);
- mv.visitInsn(DADD);
- } else if (postIncrement.type().equals(TargetType.Long)) {
- mv.visitInsn(DUP2);
- mv.visitLdcInsn(1L);
- mv.visitInsn(LADD);
- } else {
- mv.visitInsn(DUP);
- mv.visitLdcInsn(1);
- mv.visitInsn(IADD);
- }
- boxPrimitive(state, postIncrement.type());
- afterIncDec(state, postIncrement);
- break;
- case TargetUnaryOp.PostDecrement postDecrement:
- generate(state, postDecrement.expr());
- if (postDecrement.type().equals(TargetType.Float)) {
- mv.visitInsn(DUP);
- mv.visitLdcInsn(1F);
- mv.visitInsn(FSUB);
- } else if (postDecrement.type().equals(TargetType.Double)) {
- mv.visitInsn(DUP2);
- mv.visitLdcInsn(1D);
- mv.visitInsn(DSUB);
- } else if (postDecrement.type().equals(TargetType.Long)) {
- mv.visitInsn(DUP2);
- mv.visitLdcInsn(1L);
- mv.visitInsn(LSUB);
- } else {
- mv.visitInsn(DUP);
- mv.visitLdcInsn(1);
- mv.visitInsn(ISUB);
- }
- boxPrimitive(state, postDecrement.type());
- afterIncDec(state, postDecrement);
- break;
+ case TargetUnaryOp.Add add:
+ // This literally does nothing
+ generate(state, add.expr());
+ break;
+ case TargetUnaryOp.Negate negate:
+ generate(state, negate.expr());
+ if (negate.type().equals(TargetType.Double))
+ mv.visitInsn(DNEG);
+ else if (negate.type().equals(TargetType.Float))
+ mv.visitInsn(FNEG);
+ else if (negate.type().equals(TargetType.Long))
+ mv.visitInsn(LNEG);
+ else
+ mv.visitInsn(INEG);
+ break;
+ case TargetUnaryOp.Not not:
+ generate(state, not.expr());
+ if (not.type().equals(TargetType.Long)) {
+ mv.visitLdcInsn(-1L);
+ mv.visitInsn(LXOR);
+ } else {
+ mv.visitInsn(ICONST_M1);
+ mv.visitInsn(IXOR);
+ }
+ break;
+ case TargetUnaryOp.PreIncrement preIncrement:
+ generate(state, preIncrement.expr());
+ if (preIncrement.type().equals(TargetType.Float)) {
+ mv.visitLdcInsn(1F);
+ mv.visitInsn(FADD);
+ mv.visitInsn(DUP);
+ } else if (preIncrement.type().equals(TargetType.Double)) {
+ mv.visitLdcInsn(1D);
+ mv.visitInsn(DADD);
+ mv.visitInsn(DUP2);
+ } else if (preIncrement.type().equals(TargetType.Long)) {
+ mv.visitLdcInsn(1L);
+ mv.visitInsn(LADD);
+ mv.visitInsn(DUP2);
+ } else {
+ mv.visitLdcInsn(1);
+ mv.visitInsn(IADD);
+ mv.visitInsn(DUP);
+ }
+ boxPrimitive(state, preIncrement.type());
+ afterIncDec(state, preIncrement);
+ break;
+ case TargetUnaryOp.PreDecrement preDecrement:
+ generate(state, preDecrement.expr());
+ if (preDecrement.type().equals(TargetType.Float)) {
+ mv.visitLdcInsn(1F);
+ mv.visitInsn(FSUB);
+ mv.visitInsn(DUP);
+ } else if (preDecrement.type().equals(TargetType.Double)) {
+ mv.visitLdcInsn(1D);
+ mv.visitInsn(DSUB);
+ mv.visitInsn(DUP2);
+ } else if (preDecrement.type().equals(TargetType.Long)) {
+ mv.visitLdcInsn(1L);
+ mv.visitInsn(LSUB);
+ mv.visitInsn(DUP2);
+ } else {
+ mv.visitLdcInsn(1);
+ mv.visitInsn(ISUB);
+ mv.visitInsn(DUP);
+ }
+ boxPrimitive(state, preDecrement.type());
+ afterIncDec(state, preDecrement);
+ break;
+ case TargetUnaryOp.PostIncrement postIncrement:
+ generate(state, postIncrement.expr());
+ if (postIncrement.type().equals(TargetType.Float)) {
+ mv.visitInsn(DUP);
+ mv.visitLdcInsn(1F);
+ mv.visitInsn(FADD);
+ } else if (postIncrement.type().equals(TargetType.Double)) {
+ mv.visitInsn(DUP2);
+ mv.visitLdcInsn(1D);
+ mv.visitInsn(DADD);
+ } else if (postIncrement.type().equals(TargetType.Long)) {
+ mv.visitInsn(DUP2);
+ mv.visitLdcInsn(1L);
+ mv.visitInsn(LADD);
+ } else {
+ mv.visitInsn(DUP);
+ mv.visitLdcInsn(1);
+ mv.visitInsn(IADD);
+ }
+ boxPrimitive(state, postIncrement.type());
+ afterIncDec(state, postIncrement);
+ break;
+ case TargetUnaryOp.PostDecrement postDecrement:
+ generate(state, postDecrement.expr());
+ if (postDecrement.type().equals(TargetType.Float)) {
+ mv.visitInsn(DUP);
+ mv.visitLdcInsn(1F);
+ mv.visitInsn(FSUB);
+ } else if (postDecrement.type().equals(TargetType.Double)) {
+ mv.visitInsn(DUP2);
+ mv.visitLdcInsn(1D);
+ mv.visitInsn(DSUB);
+ } else if (postDecrement.type().equals(TargetType.Long)) {
+ mv.visitInsn(DUP2);
+ mv.visitLdcInsn(1L);
+ mv.visitInsn(LSUB);
+ } else {
+ mv.visitInsn(DUP);
+ mv.visitLdcInsn(1);
+ mv.visitInsn(ISUB);
+ }
+ boxPrimitive(state, postDecrement.type());
+ afterIncDec(state, postDecrement);
+ break;
}
}
@@ -712,33 +689,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.type() instanceof TargetGenericType ? new MethodParameter(TargetType.Object, param.name()) : 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,250 +708,234 @@ 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(MethodParameter::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);
- 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(MethodParameter::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());
+ 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 TargetInstanceOf instanceOf:
- mv.visitTypeInsn(INSTANCEOF, instanceOf.right().getInternalName());
+ case FloatLiteral floatLiteral:
+ mv.visitLdcInsn(floatLiteral.value());
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;
- }
+ case LongLiteral longLiteral:
+ mv.visitLdcInsn(longLiteral.value());
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());
+ 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(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 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");
+ mv.visitInsn(ICONST_0);
}
break;
}
+ break;
+ case TargetBinaryOp op:
+ generateBinaryOp(state, op);
+ break;
+ case TargetUnaryOp op:
+ generateUnaryOp(state, op);
+ break;
+ case TargetAssign assign: {
+ switch (assign.left()) {
case TargetLocalVar localVar: {
- LocalVar local = state.scope.get(localVar.name());
- mv.visitVarInsn(ALOAD, local.index());
- unboxPrimitive(state, local.type());
+ 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: {
- 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);
- generate(state, _for.body());
- if (_for.increment() != null) {
- generate(state, _for.increment());
- if (_for.increment().type() != null) {
- popValue(state, _for.increment().type());
- }
- }
- 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);
- 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)
- );
-
- 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);
+ 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("Unexpected value: " + expr);
+ 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())
+ 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());
+ }
+ }
+ 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);
+ 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));
+
+ 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);
}
}
@@ -1005,7 +950,7 @@ public class Codegen {
mv.visitCode();
var state = new State(null, mv, 1);
- for (var param: constructor.parameters())
+ for (var param : constructor.parameters())
state.createVariable(param.name(), param.type());
var stmts = constructor.block().statements();
@@ -1033,7 +978,7 @@ public class Codegen {
mv.visitCode();
var state = new State(method.signature().returnType(), mv, method.isStatic() ? 0 : 1);
- for (var param: method.signature().parameters())
+ for (var param : method.signature().parameters())
state.createVariable(param.name(), param.type());
generate(state, method.block());
if (method.signature().returnType() == null)
@@ -1057,10 +1002,7 @@ public class Codegen {
}
public byte[] generate() {
- cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC | ACC_SUPER, clazz.qualifiedName(),
- generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
- clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
- );
+ cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC | ACC_SUPER, clazz.qualifiedName(), generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName() : "java/lang/Object", clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new));
if (clazz.txGenerics() != null)
cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics())));
diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
index 04537c2c..f2353709 100644
--- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
+++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
@@ -10,7 +10,7 @@ import de.dhbwstuttgart.parser.JavaTXParser;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
-import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SourceFileContext;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
@@ -58,148 +58,121 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.*;
+import java.util.Map.Entry;
import java.util.function.Function;
import java.util.stream.Collectors;
+import org.antlr.v4.runtime.Token;
import org.apache.commons.io.output.NullOutputStream;
-
public class JavaTXCompiler {
- //public static JavaTXCompiler INSTANCE;
- final CompilationEnvironment environment;
+ // public static JavaTXCompiler INSTANCE;
+ final CompilationEnvironment environment;
Boolean resultmodel = false;
- public final Map sourceFiles = new HashMap<>();
- Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
- public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
- private final DirectoryClassLoader classLoader;
-
+ public final Map sourceFiles = new HashMap<>();
+ Boolean log = false; // gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
+ public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
+ private final DirectoryClassLoader classLoader;
+
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
this(Arrays.asList(sourceFile), null);
}
- public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
- this(sourceFile);
- this.log = log;
- }
+
+ public JavaTXCompiler(File sourceFile, Boolean log) throws IOException, ClassNotFoundException {
+ this(sourceFile);
+ this.log = log;
+ }
+
public JavaTXCompiler(List sourceFiles) throws IOException, ClassNotFoundException {
this(sourceFiles, null);
}
- public JavaTXCompiler(List sources, List contextPath) throws IOException, ClassNotFoundException {
- if(contextPath == null || contextPath.isEmpty()){
- //When no contextPaths are given, the working directory is the sources root
+
+ public JavaTXCompiler(List sources, List contextPath) throws IOException, ClassNotFoundException {
+ if (contextPath == null || contextPath.isEmpty()) {
+ // When no contextPaths are given, the working directory is the sources root
contextPath = Lists.newArrayList(new File(System.getProperty("user.dir")));
}
- classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader());
+ classLoader = new DirectoryClassLoader(contextPath, ClassLoader.getSystemClassLoader());
environment = new CompilationEnvironment(sources);
- for (File s : sources) {
- sourceFiles.put(s, parse(s));
- }
- //INSTANCE = this;
- }
+ for (File s : sources) {
+ sourceFiles.put(s, parse(s));
+ }
+ // INSTANCE = this;
+ }
- public ConstraintSet getConstraints() throws ClassNotFoundException, IOException {
- List allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
- List importedClasses = new ArrayList<>();
- ClassOrInterface objectClass = ASTFactory.createClass(
- classLoader.loadClass(new JavaClassName("java.lang.Object").toString()));
- //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
- for (File forSourceFile : sourceFiles.keySet()){
- for (JavaClassName name : sourceFiles.get(forSourceFile).getImports()) {
- //TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
- ClassOrInterface importedClass = ASTFactory.createClass(
- classLoader.loadClass(name.toString()));
- importedClasses.add(importedClass);
- }
- for(Class c : CompilationEnvironment.loadDefaultPackageClasses(forSourceFile, classLoader)){
+ public ConstraintSet getConstraints() throws ClassNotFoundException, IOException {
+ List allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
+ List importedClasses = new ArrayList<>();
+ ClassOrInterface objectClass = ASTFactory.createClass(classLoader.loadClass(new JavaClassName("java.lang.Object").toString()));
+ // Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
+ for (Entry source : sourceFiles.entrySet()) {
+ for (JavaClassName name : source.getValue().getImports()) {
+ // TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
+ ClassOrInterface importedClass = ASTFactory.createClass(classLoader.loadClass(name.toString()));
+ importedClasses.add(importedClass);
+ }
+ for (Class c : CompilationEnvironment.loadDefaultPackageClasses(source.getValue().getPkgName(), source.getKey(), classLoader)) {
ClassOrInterface importedClass = ASTFactory.createClass(c);
importedClasses.add(importedClass);
}
- }
- for (File f : this.sourceFiles.keySet()) {
+ }
+ for (File f : this.sourceFiles.keySet()) {
SourceFile sf = sourceFiles.get(f);
- sf = new SourceFile(sf.getPkgName(),
- sf.KlassenVektor.stream()
- .map(cl -> new ClassOrInterface(cl))
- .collect(Collectors.toCollection(ArrayList::new)),
- sf.imports);
- //sf enthaelt neues Source-File, neue Klassen-Objekte und neue
- //ArrayListen-Objekte fuer Fields, Construktoren und Methoden
- //Alle anderen Objekte werden nur kopiert.
+ sf = new SourceFile(sf.getPkgName(), sf.KlassenVektor.stream().map(cl -> new ClassOrInterface(cl)).collect(Collectors.toCollection(ArrayList::new)), sf.imports);
+ // sf enthaelt neues Source-File, neue Klassen-Objekte und neue
+ // ArrayListen-Objekte fuer Fields, Construktoren und Methoden
+ // Alle anderen Objekte werden nur kopiert.
SourceFile sf_new = sf;
sf.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, importedClasses, objectClass));
allClasses.addAll(sf.getClasses());
}
- allClasses.addAll(importedClasses);
- TYPE ty = new TYPE(sourceFiles.values(), allClasses);
- return ty.getConstraints();
- }
-
- void addMethods(SourceFile sf, ClassOrInterface cl, List importedClasses, ClassOrInterface objectClass) {
+ allClasses.addAll(importedClasses);
+ TYPE ty = new TYPE(sourceFiles.values(), allClasses);
+ return ty.getConstraints();
+ }
+
+ void addMethods(SourceFile sf, ClassOrInterface cl, List importedClasses, ClassOrInterface objectClass) {
if (!cl.areMethodsAdded()) {
ClassOrInterface superclass = null;
if (cl.getSuperClass().getName().equals(new JavaClassName("java.lang.Object"))) {
superclass = objectClass;
- }
- else {
- Optional optSuperclass =
- importedClasses.stream().filter(x -> x.getClassName().equals(
- cl.getSuperClass().getName())).findFirst();
+ } else {
+ Optional optSuperclass = importedClasses.stream().filter(x -> x.getClassName().equals(cl.getSuperClass().getName())).findFirst();
if (optSuperclass.isPresent()) {
superclass = optSuperclass.get();
- }
- else {
- optSuperclass =
- sf.KlassenVektor.stream().filter(x -> x.getClassName().equals(
- cl.getSuperClass().getName())).findFirst();
+ } else {
+ optSuperclass = sf.KlassenVektor.stream().filter(x -> x.getClassName().equals(cl.getSuperClass().getName())).findFirst();
if (optSuperclass.isPresent()) {
superclass = optSuperclass.get();
- addMethods(sf, superclass, importedClasses, objectClass);
- }
- else {
- //throw new ClassNotFoundException("");
+ addMethods(sf, superclass, importedClasses, objectClass);
+ } else {
+ // throw new ClassNotFoundException("");
}
}
}
- Iterator paraIt= cl.getSuperClass().getParaList().iterator();
+ Iterator paraIt = cl.getSuperClass().getParaList().iterator();
Iterator tvarVarIt = superclass.getGenerics().iterator();
-
+
HashMap gtvs = new HashMap<>();
- while (paraIt.hasNext()) {
+ while (paraIt.hasNext()) {
gtvs.put(tvarVarIt.next().getName(), paraIt.next());
}
Iterator methodIt = superclass.getMethods().iterator();
- //TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert werden
- while(methodIt.hasNext()) {
+ // TODO: PL 2020-05-06: Hier müssen ueberschriebene Methoden noch rausgefiltert
+ // werden
+ while (methodIt.hasNext()) {
Method m = methodIt.next();
- ParameterList newParaList = new ParameterList(
- m.getParameterList()
- .getFormalparalist()
- .stream()
- .map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset()))
- .collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
+ ParameterList newParaList = new ParameterList(m.getParameterList().getFormalparalist().stream().map(fp -> new FormalParameter(fp.getName(), fp.getType().acceptTV(new TypeExchanger(gtvs)), fp.getOffset())).collect(Collectors.toCollection(ArrayList::new)), m.getParameterList().getOffset());
cl.getMethods().add(new Method(m.modifier, m.name, m.getReturnType().acceptTV(new TypeExchanger(gtvs)), newParaList, m.block,
- //new GenericDeclarationList(newGenericsList, ((GenericDeclarationList)m.getGenerics()).getOffset()),
- (GenericDeclarationList)m.getGenerics(),
- m.getOffset(), true));
+ // new GenericDeclarationList(newGenericsList,
+ // ((GenericDeclarationList)m.getGenerics()).getOffset()),
+ (GenericDeclarationList) m.getGenerics(), m.getOffset(), true));
}
-
+
}
cl.setMethodsAdded();
}
-
-
-
- public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
- //PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal hinzugefuegt werden
- //List allClasses = new ArrayList<>();//environment.getAllAvailableClasses();
- Set allClasses = new HashSet<>();
-
- /* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt
- }
- allClasses.addAll(importedClasses);
-
- return new TYPE(sourceFiles.values(), allClasses).getConstraints();
- }
public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException {
// PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal
@@ -209,16 +182,19 @@ public class JavaTXCompiler {
Set allClasses = new HashSet<>();
/*
- * PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt for
- * (SourceFile sf : sourceFiles.values()) { allClasses.addAll(sf.getClasses());
- * }
+ * PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt } allClasses.addAll(importedClasses);
+ *
+ * return new TYPE(sourceFiles.values(), allClasses).getConstraints(); }
+ *
+ * public List getAvailableClasses(SourceFile forSourceFile) throws ClassNotFoundException { // PL 2018-09-18: List durch Set ersetzt, damit die Klassen nur einmal // hinzugefuegt werden // List allClasses = new // ArrayList<>();//environment.getAllAvailableClasses(); Set allClasses = new HashSet<>();
+ *
+ * /* PL 2018-09-19 geloescht werden bereits in typeInference hinzugefuegt for (SourceFile sf : sourceFiles.values()) { allClasses.addAll(sf.getClasses()); }
*/
List importedClasses = new ArrayList<>();
for (JavaClassName name : forSourceFile.getImports()) {
// TODO: Hier werden imports von eigenen (.jav) Klassen nicht beachtet
- ClassOrInterface importedClass = ASTFactory
- .createClass(classLoader.loadClass(name.toString()));
+ ClassOrInterface importedClass = ASTFactory.createClass(classLoader.loadClass(name.toString()));
importedClasses.add(importedClass);
allClasses.addAll(importedClasses);
}
@@ -226,159 +202,56 @@ public class JavaTXCompiler {
}
/*
- * public List typeInferenceOld() throws ClassNotFoundException {
- * List allClasses = new
- * ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten
- * Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf :
- * this.sourceFiles.values()) { allClasses.addAll(getAvailableClasses(sf));
- * allClasses.addAll(sf.getClasses()); }
+ * public List typeInferenceOld() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf : this.sourceFiles.values()) { allClasses.addAll(getAvailableClasses(sf)); allClasses.addAll(sf.getClasses()); }
*
* final ConstraintSet cons = getConstraints();
*
- * FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
- * System.out.println(finiteClosure); ConstraintSet unifyCons =
- * UnifyTypeFactory.convert(cons);
+ * FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons);
*
- * TypeUnify unify = new TypeUnify(); Set> results = new
- * HashSet<>(); try { File logPath = new
- * File(System.getProperty("user.dir")+"/target/logFiles/"); logPath.mkdirs();
- * FileWriter logFile = new FileWriter(new File(logPath, "log"));
- * logFile.write("FC:\\" + finiteClosure.toString()+"\n"); for(SourceFile sf :
- * this.sourceFiles.values()) { logFile.write(ASTTypePrinter.print(sf)); }
- * logFile.flush(); Set>> cardProd =
- * unifyCons.cartesianProduct(); for (List> xCons :
- * cardProd ){ Set xConsSet = new HashSet<>(); for
- * (Constraint constraint : xCons) { xConsSet.addAll(constraint); }
- * //.collect(Collectors.toCollection(ArrayList::new))))
- * System.out.println(xConsSet); Set methodParaTypeVarNames =
- * allClasses.stream().map(x -> x.getMethods().stream().map(y ->
- * y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType()
- * instanceof TypePlaceholder) .map(z ->
- * ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(
- * HashSet::new))) .reduce(new HashSet(), (a,b) -> { a.addAll(b); return
- * a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet(),
- * (a,b) -> { a.addAll(b); return a;} );
+ * TypeUnify unify = new TypeUnify(); Set> results = new HashSet<>(); try { File logPath = new File(System.getProperty("user.dir")+"/target/logFiles/"); logPath.mkdirs(); FileWriter logFile = new FileWriter(new File(logPath, "log")); logFile.write("FC:\\" + finiteClosure.toString()+"\n"); for(SourceFile sf : this.sourceFiles.values()) { logFile.write(ASTTypePrinter.print(sf)); } logFile.flush(); Set>> cardProd = unifyCons.cartesianProduct(); for
+ * (List> xCons : cardProd ){ Set xConsSet = new HashSet<>(); for (Constraint constraint : xCons) { xConsSet.addAll(constraint); } //.collect(Collectors.toCollection(ArrayList::new)))) System.out.println(xConsSet); Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType() instanceof TypePlaceholder) .map(z ->
+ * ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection( HashSet::new))) .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} );
*
- * Set constructorParaTypeVarNames = allClasses.stream().map(x ->
- * x.getConstructors().stream().map(y ->
- * y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType()
- * instanceof TypePlaceholder) .map(z ->
- * ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(
- * HashSet::new))) .reduce(new HashSet(), (a,b) -> { a.addAll(b); return
- * a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet(),
- * (a,b) -> { a.addAll(b); return a;} );
+ * Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType() instanceof TypePlaceholder) .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection( HashSet::new))) .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} );
*
- * Set paraTypeVarNames = methodParaTypeVarNames;
- * paraTypeVarNames.addAll(constructorParaTypeVarNames);
+ * Set paraTypeVarNames = methodParaTypeVarNames; paraTypeVarNames.addAll(constructorParaTypeVarNames);
*
- * Set returnTypeVarNames = allClasses.stream().map(x ->
- * x.getMethods().stream().filter(y -> y.getReturnType() instanceof
- * TypePlaceholder) .map(z ->
- * ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.
- * toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}
- * ).get();
+ * Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors. toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
*
- * Set fieldTypeVarNames = allClasses.stream().map(x ->
- * x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof
- * TypePlaceholder) .map(z ->
- * ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.
- * toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}
- * ).get();
+ * Set fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors. toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get();
*
* returnTypeVarNames.addAll(fieldTypeVarNames);
*
- * xConsSet = xConsSet.stream().map(x -> { //Hier muss ueberlegt werden, ob //1.
- * alle Argument- und Retuntyp-Variablen in allen UnifyPairs // mit
- * disableWildcardtable() werden. //2. alle Typvariablen mit Argument- oder
- * Retuntyp-Variablen //in Beziehung auch auf disableWildcardtable() gesetzt
- * werden muessen //PL 2018-04-23 if ((x.getLhsType() instanceof
- * PlaceholderType)) { if (paraTypeVarNames.contains(x.getLhsType().getName()))
- * { ((PlaceholderType)x.getLhsType()).setVariance((byte)1);
- * ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } if
- * (returnTypeVarNames.contains(x.getLhsType().getName())) {
- * ((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
- * ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } } if
- * ((x.getRhsType() instanceof PlaceholderType)) { if
- * (paraTypeVarNames.contains(x.getRhsType().getName())) {
- * ((PlaceholderType)x.getRhsType()).setVariance((byte)1);
- * ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } if
- * (returnTypeVarNames.contains(x.getRhsType().getName())) {
- * ((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
- * ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } return x;//HIER
- * DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS
- * ANDERE SEITE }).map( y -> { if ((y.getLhsType() instanceof PlaceholderType)
- * && (y.getRhsType() instanceof PlaceholderType)) { if
- * (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
- * ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
- * ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
- * )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
- * && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
- * ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
- * )).getVariance()); } } return y; } )
- * .collect(Collectors.toCollection(HashSet::new));
- * varianceInheritance(xConsSet); Set> result =
- * unify.unifySequential(xConsSet, finiteClosure, logFile, log);
- * //Set> result = unify.unify(xConsSet, finiteClosure);
- * System.out.println("RESULT: " + result); logFile.write("RES: " +
- * result.toString()+"\n"); logFile.flush(); results.addAll(result); }
+ * xConsSet = xConsSet.stream().map(x -> { //Hier muss ueberlegt werden, ob //1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs // mit disableWildcardtable() werden. //2. alle Typvariablen mit Argument- oder Retuntyp-Variablen //in Beziehung auch auf disableWildcardtable() gesetzt werden muessen //PL 2018-04-23 if ((x.getLhsType() instanceof PlaceholderType)) { if (paraTypeVarNames.contains(x.getLhsType().getName())) { ((PlaceholderType)x.getLhsType()).setVariance((byte)1);
+ * ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } if (returnTypeVarNames.contains(x.getLhsType().getName())) { ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } } if ((x.getRhsType() instanceof PlaceholderType)) { if (paraTypeVarNames.contains(x.getRhsType().getName())) { ((PlaceholderType)x.getRhsType()).setVariance((byte)1); ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } if
+ * (returnTypeVarNames.contains(x.getRhsType().getName())) { ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE }).map( y -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { if (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
+ * ((PlaceholderType)y.getRhsType()).getVariance() == 0) { ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType( )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType( )).getVariance()); } } return y; } ) .collect(Collectors.toCollection(HashSet::new)); varianceInheritance(xConsSet); Set> result =
+ * unify.unifySequential(xConsSet, finiteClosure, logFile, log); //Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); results.addAll(result); }
*
- * results = results.stream().map(x -> { Optional> res = new
- * RuleSet().subst(x.stream().map(y -> { if (y.getPairOp() ==
- * PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); return y;
- * //alle Paare a <.? b erden durch a =. b ersetzt
- * }).collect(Collectors.toCollection(HashSet::new))); if (res.isPresent())
- * {//wenn subst ein Erg liefert wurde was veraendert return new
- * TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); } else
- * return x; //wenn nichts veraendert wurde wird x zurueckgegeben
- * }).collect(Collectors.toCollection(HashSet::new));
- * System.out.println("RESULT Final: " + results); logFile.write("RES_FINAL: " +
- * results.toString()+"\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " +
- * PlaceholderType.EXISTING_PLACEHOLDERS); logFile.flush(); } catch (IOException
- * e) { e.printStackTrace(); } return results.stream().map((unifyPairs -> new
- * ResultSet(UnifyTypeFactory.convert(unifyPairs,
+ * results = results.stream().map(x -> { Optional> res = new RuleSet().subst(x.stream().map(y -> { if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); return y; //alle Paare a <.? b erden durch a =. b ersetzt }).collect(Collectors.toCollection(HashSet::new))); if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); } else return x; //wenn nichts
+ * veraendert wurde wird x zurueckgegeben }).collect(Collectors.toCollection(HashSet::new)); System.out.println("RESULT Final: " + results); logFile.write("RES_FINAL: " + results.toString()+"\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); logFile.flush(); } catch (IOException e) { e.printStackTrace(); } return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs,
* generateTPHMap(cons))))).collect(Collectors.toList()); }
*/
/**
- * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine
- * Variance !=0 hat auf alle Typvariablen in Theta.
+ * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
*
*
*/
/*
- * private void varianceInheritance(Set eq) { Set
- * usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x ->
- * { Set pair = new HashSet<>(); if (x.getLhsType() instanceof
- * PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); if
- * (x.getRhsType() instanceof PlaceholderType)
- * pair.add((PlaceholderType)x.getRhsType()); return pair; }).reduce(new
- * HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d);
- * return c;});
+ * private void varianceInheritance(Set eq) { Set usedTPH = new HashSet<>(); Set phSet = eq.stream().map(x -> { Set pair = new HashSet<>(); if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType()); return pair; }).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
*
- * ArrayList phSetVariance = new ArrayList<>(phSet);
- * phSetVariance.removeIf(x -> (x.getVariance() == 0));
- * while(!phSetVariance.isEmpty()) { PlaceholderType a =
- * phSetVariance.remove(0); usedTPH.add(a); //HashMap
- * ht = new HashMap<>(); //ht.put(a, a.getVariance()); Set eq1 = new
- * HashSet<>(eq); eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType
- * && ((PlaceholderType)x.getLhsType()).equals(a))); eq1.stream().forEach(x -> {
- * x.getRhsType().accept(new distributeVariance(), a.getVariance());}); eq1 =
- * new HashSet<>(eq); eq1.removeIf(x -> !(x.getRhsType() instanceof
- * PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
- * eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(),
- * a.getVariance());}); phSetVariance = new ArrayList<>(phSet);
- * phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); }
- * }
+ * ArrayList phSetVariance = new ArrayList<>(phSet); phSetVariance.removeIf(x -> (x.getVariance() == 0)); while(!phSetVariance.isEmpty()) { PlaceholderType a = phSetVariance.remove(0); usedTPH.add(a); //HashMap ht = new HashMap<>(); //ht.put(a, a.getVariance()); Set eq1 = new HashSet<>(eq); eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a))); eq1.stream().forEach(x -> {
+ * x.getRhsType().accept(new distributeVariance(), a.getVariance());}); eq1 = new HashSet<>(eq); eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a))); eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());}); phSetVariance = new ArrayList<>(phSet); phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); } }
*/
- public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
- throws ClassNotFoundException, IOException {
+ public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile) throws ClassNotFoundException, IOException {
List allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
- for (File f : this.sourceFiles.keySet()) {
- SourceFile sf = sourceFiles.get(f);
+ for (Entry source : this.sourceFiles.entrySet()) {
+ SourceFile sf = source.getValue();
allClasses.addAll(getAvailableClasses(sf));
allClasses.addAll(sf.getClasses());
- allClasses.addAll(CompilationEnvironment.loadDefaultPackageClasses(f,classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList()));
+ allClasses.addAll(CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), source.getKey(), classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList()));
}
final ConstraintSet cons = getConstraints();
@@ -386,9 +259,7 @@ public class JavaTXCompiler {
UnifyResultModel urm = null;
// urm.addUnifyResultListener(resultListener);
try {
- logFile = logFile == null
- ? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName()))
- : logFile;
+ logFile = logFile == null ? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName())) : logFile;
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
System.out.println(finiteClosure);
urm = new UnifyResultModel(cons, finiteClosure);
@@ -397,9 +268,7 @@ public class JavaTXCompiler {
Function distributeInnerVars = x -> {
UnifyType lhs, rhs;
- if (((lhs = x.getLhsType()) instanceof PlaceholderType)
- && ((rhs = x.getRhsType()) instanceof PlaceholderType)
- && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
+ if (((lhs = x.getLhsType()) instanceof PlaceholderType) && ((rhs = x.getRhsType()) instanceof PlaceholderType) && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
((PlaceholderType) lhs).setInnerType(true);
((PlaceholderType) rhs).setInnerType(true);
}
@@ -417,58 +286,40 @@ public class JavaTXCompiler {
}
logFile.flush();
- Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream()
- .map(y -> y.getParameterList().getFormalparalist().stream()
- .filter(z -> z.getType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- }, (a, b) -> {
- a.addAll(b);
- return a;
- })).reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- });
+ Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ }, (a, b) -> {
+ a.addAll(b);
+ return a;
+ })).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ });
- Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream()
- .map(y -> y.getParameterList().getFormalparalist().stream()
- .filter(z -> z.getType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- }, (a, b) -> {
- a.addAll(b);
- return a;
- })).reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- });
+ Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ }, (a, b) -> {
+ a.addAll(b);
+ return a;
+ })).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ });
Set paraTypeVarNames = methodParaTypeVarNames;
paraTypeVarNames.addAll(constructorParaTypeVarNames);
- Set returnTypeVarNames = allClasses.stream()
- .map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getReturnType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce((a, b) -> {
- a.addAll(b);
- return a;
- }).get();
+ Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
+ a.addAll(b);
+ return a;
+ }).get();
- Set fieldTypeVarNames = allClasses.stream()
- .map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getReturnType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce((a, b) -> {
- a.addAll(b);
- return a;
- }).get();
+ Set fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
+ a.addAll(b);
+ return a;
+ }).get();
returnTypeVarNames.addAll(fieldTypeVarNames);
@@ -500,41 +351,24 @@ public class JavaTXCompiler {
}
}
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
- // JEWEILS ANDERE SEITE
+ // JEWEILS ANDERE SEITE
});
Set varianceTPHold;
Set varianceTPH = new HashSet<>();
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
/*
- * PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL
- * 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
- * //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH);
- * varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y
- * -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType()
- * instanceof PlaceholderType)) { if
- * (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
- * ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
- * ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
- * )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
- * && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
- * ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
- * )).getVariance()); } } return y; } ); } while
- * (!varianceTPHold.equals(varianceTPH));
+ * PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH); varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { if (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
+ * ((PlaceholderType)y.getRhsType()).getVariance() == 0) { ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType( )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType( )).getVariance()); } } return y; } ); } while (!varianceTPHold.equals(varianceTPH));
*/
// Set> result = unify.unifySequential(xConsSet, finiteClosure,
// logFile, log);
// Set> result = unify.unify(xConsSet, finiteClosure);
- List>> oderConstraints = unifyCons.getOderConstraints()/*.stream().map(x -> {
- Set> ret = new HashSet<>();
- for (Constraint y : x) {
- ret.add(new HashSet<>(y));
- }
- return ret;
- }).collect(Collectors.toCollection(ArrayList::new))*/;
- unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
- usedTasks);
+ List>> oderConstraints = unifyCons.getOderConstraints()/*
+ * .stream().map(x -> { Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); } return ret; }).collect(Collectors. toCollection(ArrayList::new))
+ */;
+ unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
} catch (IOException e) {
System.err.println("kein LogFile");
}
@@ -544,11 +378,11 @@ public class JavaTXCompiler {
public List typeInference() throws ClassNotFoundException, IOException {
List allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
- for (File f : this.sourceFiles.keySet()) {
- SourceFile sf = sourceFiles.get(f);
+ for (Entry source : this.sourceFiles.entrySet()) {
+ SourceFile sf = source.getValue();
allClasses.addAll(getAvailableClasses(sf));
allClasses.addAll(sf.getClasses());
- var newClasses = CompilationEnvironment.loadDefaultPackageClasses(f,classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList());
+ var newClasses = CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), source.getKey(), classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList());
for (var clazz : newClasses) {
var found = false;
for (var old : allClasses) {
@@ -557,31 +391,29 @@ public class JavaTXCompiler {
break;
}
}
- if (!found) allClasses.add(clazz);
+ if (!found)
+ allClasses.add(clazz);
}
}
final ConstraintSet cons = getConstraints();
Set> results = new HashSet<>();
try {
- Writer logFile = log ? new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" + sourceFiles.keySet().iterator().next().getName()))
- : new OutputStreamWriter(new NullOutputStream());
+ Writer logFile = log ? new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "log_" + sourceFiles.keySet().iterator().next().getName())) : new OutputStreamWriter(new NullOutputStream());
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
System.out.println(finiteClosure);
ConstraintSet unifyCons = UnifyTypeFactory.convert(cons);
System.out.println("xxx1");
Function distributeInnerVars = x -> {
UnifyType lhs, rhs;
- if (((lhs = x.getLhsType()) instanceof PlaceholderType)
- && ((rhs = x.getRhsType()) instanceof PlaceholderType)
- && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
+ if (((lhs = x.getLhsType()) instanceof PlaceholderType) && ((rhs = x.getRhsType()) instanceof PlaceholderType) && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
((PlaceholderType) lhs).setInnerType(true);
((PlaceholderType) rhs).setInnerType(true);
}
return x;
};
-
+
logFile.write("Unify:" + unifyCons.toString());
System.out.println("Unify:" + unifyCons.toString());
unifyCons = unifyCons.map(distributeInnerVars);
@@ -595,58 +427,40 @@ public class JavaTXCompiler {
}
logFile.flush();
- Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream()
- .map(y -> y.getParameterList().getFormalparalist().stream()
- .filter(z -> z.getType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- }, (a, b) -> {
- a.addAll(b);
- return a;
- })).reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- });
+ Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ }, (a, b) -> {
+ a.addAll(b);
+ return a;
+ })).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ });
- Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream()
- .map(y -> y.getParameterList().getFormalparalist().stream()
- .filter(z -> z.getType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- }, (a, b) -> {
- a.addAll(b);
- return a;
- })).reduce(new HashSet(), (a, b) -> {
- a.addAll(b);
- return a;
- });
+ Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist().stream().filter(z -> z.getType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ }, (a, b) -> {
+ a.addAll(b);
+ return a;
+ })).reduce(new HashSet(), (a, b) -> {
+ a.addAll(b);
+ return a;
+ });
Set paraTypeVarNames = methodParaTypeVarNames;
paraTypeVarNames.addAll(constructorParaTypeVarNames);
- Set returnTypeVarNames = allClasses.stream()
- .map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getReturnType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce((a, b) -> {
- a.addAll(b);
- return a;
- }).get();
+ Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
+ a.addAll(b);
+ return a;
+ }).get();
- Set fieldTypeVarNames = allClasses.stream()
- .map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
- .map(z -> ((TypePlaceholder) z.getReturnType()).getName())
- .collect(Collectors.toCollection(HashSet::new)))
- .reduce((a, b) -> {
- a.addAll(b);
- return a;
- }).get();
+ Set fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder).map(z -> ((TypePlaceholder) z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a, b) -> {
+ a.addAll(b);
+ return a;
+ }).get();
returnTypeVarNames.addAll(fieldTypeVarNames);
@@ -678,63 +492,42 @@ public class JavaTXCompiler {
}
}
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
- // JEWEILS ANDERE SEITE
+ // JEWEILS ANDERE SEITE
});
-
- //PL 2020-02-05 alle Oder-Constraints Receiver und Parameter werden auf variance 1 gesetzt
- //Es wird davon ausgegangen, dass in OderConstraints in Bedingungen für Parameter die Typen der Argumente links stehen
- //und die Typen der Rückgabewerte immer rechts stehen
-
+
+ // PL 2020-02-05 alle Oder-Constraints Receiver und Parameter werden auf
+ // variance 1 gesetzt
+ // Es wird davon ausgegangen, dass in OderConstraints in Bedingungen für
+ // Parameter die Typen der Argumente links stehen
+ // und die Typen der Rückgabewerte immer rechts stehen
+
/*
- unifyCons.getOderConstraints().forEach(z -> z.forEach(y -> y.forEach(x -> {
- if ((x.getLhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.SMALLERDOT) == 0) {
- ((PlaceholderType) x.getLhsType()).setVariance((byte)1);
- }
- else if ((x.getRhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.EQUALSDOT) == 0) {
- ((PlaceholderType) x.getRhsType()).setVariance((byte)-1);
- }
- })));
- */
-
+ * unifyCons.getOderConstraints().forEach(z -> z.forEach(y -> y.forEach(x -> { if ((x.getLhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.SMALLERDOT) == 0) { ((PlaceholderType) x.getLhsType()).setVariance((byte)1); } else if ((x.getRhsType() instanceof PlaceholderType) && x.getPairOp().compareTo(PairOperator.EQUALSDOT) == 0) { ((PlaceholderType) x.getRhsType()).setVariance((byte)-1); } })));
+ */
+
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
Set varianceTPHold;
Set varianceTPH = new HashSet<>();
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
/*
- * PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL
- * 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
- * //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH);
- * varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y
- * -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType()
- * instanceof PlaceholderType)) { if
- * (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
- * ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
- * ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
- * )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
- * && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
- * ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
- * )).getVariance()); } } return y; } ); } while
- * (!varianceTPHold.equals(varianceTPH));
+ * PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH); varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { if (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
+ * ((PlaceholderType)y.getRhsType()).getVariance() == 0) { ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType( )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType( )).getVariance()); } } return y; } ); } while (!varianceTPHold.equals(varianceTPH));
*/
// Set> result = unify.unifySequential(xConsSet, finiteClosure,
// logFile, log);
// Set> result = unify.unify(xConsSet, finiteClosure);
- List>> oderConstraints = unifyCons.getOderConstraints()//.stream().map(x -> {
- /*Set> ret = new HashSet<>();
- for (Constraint y : x) {
- ret.add(new HashSet<>(y));
- }
- return ret;
- }).collect(Collectors.toCollection(ArrayList::new))*/;
+ List>> oderConstraints = unifyCons.getOderConstraints()// .stream().map(x -> {
+ /*
+ * Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); } return ret; }).collect(Collectors.toCollection(ArrayList::new))
+ */;
if (resultmodel) {
/* UnifyResultModel Anfang */
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
urm.addUnifyResultListener(li);
- unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
- usedTasks);
+ unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
System.out.println("RESULT Final: " + li.getResults());
System.out.println("Constraints for Generated Generics: " + " ???");
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
@@ -746,8 +539,7 @@ public class JavaTXCompiler {
// Set> result = unify.unify(unifyCons.getUndConstraints(),
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
// finiteClosure));
- Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints,
- finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
+ Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
System.out.println("RESULT: " + result);
logFile.write("RES: " + result.toString() + "\n");
logFile.flush();
@@ -774,14 +566,11 @@ public class JavaTXCompiler {
} catch (IOException e) {
System.err.println("kein LogFile");
}
- return results.stream()
- .map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons)))))
- .collect(Collectors.toList());
+ return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList());
}
/**
- * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine
- * Variance !=0 hat auf alle Typvariablen in Theta.
+ * Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
*
*
*/
@@ -829,21 +618,19 @@ public class JavaTXCompiler {
}
});
phSetVariance = new ArrayList<>(phSet); // macht vermutlich keinen Sinn PL 2018-10-18, doch, es koennen neue
- // TPHs mit Variancen dazugekommen sein PL 2018-11-07
+ // TPHs mit Variancen dazugekommen sein PL 2018-11-07
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
}
return usedTPH;
}
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
- CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
- SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile, classLoader),
- new GenericsRegistry(null));
+ SourceFileContext tree = JavaTXParser.parse(sourceFile);
+ SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(tree, sourceFile, classLoader), new GenericsRegistry(null));
SourceFile ret = generator.convert(tree, environment.packageCrawler, classLoader);
return ret;
}
-
public void generateBytecode() throws ClassNotFoundException, IOException {
generateBytecode((File) null);
}
@@ -852,7 +639,7 @@ public class JavaTXCompiler {
* @param path - can be null, then class file output is in the same directory as the parsed source files
*/
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
- if(path != null)
+ if (path != null)
generateBytecode(new File(path));
else
generateBytecode();
@@ -873,7 +660,7 @@ public class JavaTXCompiler {
}
/**
- * @param outputPath - can be null, then class file output is in the same directory as the parsed source files
+ * @param outputPath - can be null, then class file output is in the same directory as the parsed source files
* @param typeinferenceResult
* @throws IOException
*/
@@ -882,10 +669,10 @@ public class JavaTXCompiler {
HashMap classFiles = new HashMap<>();
SourceFile sf = sourceFiles.get(f);
File path;
- if(outputPath == null){
- path = f.getParentFile(); //Set path to path of the parsed .jav file
- }else{
- path = new File(outputPath ,sf.getPkgName().replace(".","/")); //add package path to root path
+ if (outputPath == null) {
+ path = f.getParentFile(); // Set path to path of the parsed .jav file
+ } else {
+ path = new File(outputPath, sf.getPkgName().replace(".", "/")); // add package path to root path
}
var generatedClasses = generateBytecode(sf, typeinferenceResult);
@@ -924,52 +711,53 @@ public class JavaTXCompiler {
}
}
- /* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */
+ /* PL 2020-03-17 mit TypeExchanger in FCGenerator.java zusammenfuehren */
/**
- * Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
- */
- private static class TypeExchanger implements TypeVisitor{
+ * Tauscht die GTVs in einem Typ gegen die entsprechenden Typen in der übergebenen Map aus.
+ */
+ private static class TypeExchanger implements TypeVisitor {
- private final HashMap gtvs;
+ private final HashMap gtvs;
- TypeExchanger(HashMap gtvs){
- this.gtvs = gtvs;
- }
+ TypeExchanger(HashMap gtvs) {
+ this.gtvs = gtvs;
+ }
- @Override
- public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
- List params = new ArrayList<>();
- for(RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()){
- params.add(param.acceptTV(this));
- }
- RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
- return ret;
- }
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric visit(RefType refType) {
+ List params = new ArrayList<>();
+ for (RefTypeOrTPHOrWildcardOrGeneric param : refType.getParaList()) {
+ params.add(param.acceptTV(this));
+ }
+ RefTypeOrTPHOrWildcardOrGeneric ret = new RefType(refType.getName(), params, new NullToken());
+ return ret;
+ }
- @Override
- public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
- SuperWildcardType ret = new SuperWildcardType(superWildcardType.getInnerType().acceptTV(this), superWildcardType.getOffset());
- return ret;
- }
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric visit(SuperWildcardType superWildcardType) {
+ SuperWildcardType ret = new SuperWildcardType(superWildcardType.getInnerType().acceptTV(this), superWildcardType.getOffset());
+ return ret;
+ }
- @Override
- public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
- return typePlaceholder; //TypePlaceholder der vererbert wird kann bei der Vererbung nicht instanziert werden.
- }
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric visit(TypePlaceholder typePlaceholder) {
+ return typePlaceholder; // TypePlaceholder der vererbert wird kann bei der Vererbung nicht instanziert
+ // werden.
+ }
- @Override
- public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
- ExtendsWildcardType ret = new ExtendsWildcardType(extendsWildcardType.getInnerType().acceptTV(this), extendsWildcardType.getOffset());
- return ret;
- }
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric visit(ExtendsWildcardType extendsWildcardType) {
+ ExtendsWildcardType ret = new ExtendsWildcardType(extendsWildcardType.getInnerType().acceptTV(this), extendsWildcardType.getOffset());
+ return ret;
+ }
- @Override
- public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
- if(! gtvs.containsKey(genericRefType.getParsedName()))
- throw new DebugException("Dieser Fall darf nicht auftreten");
- return gtvs.get(genericRefType.getParsedName());
- }
+ @Override
+ public RefTypeOrTPHOrWildcardOrGeneric visit(GenericRefType genericRefType) {
+ if (!gtvs.containsKey(genericRefType.getParsedName()))
+ throw new DebugException("Dieser Fall darf nicht auftreten");
+ return gtvs.get(genericRefType.getParsedName());
+ }
- }
+ }
}
diff --git a/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java b/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java
index 9ca471cb..79c89760 100644
--- a/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java
+++ b/src/main/java/de/dhbwstuttgart/environment/CompilationEnvironment.java
@@ -9,17 +9,17 @@ import java.util.*;
import com.google.common.collect.Lists;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
-import org.antlr.v4.runtime.tree.TerminalNode;
import de.dhbwstuttgart.exceptions.DebugException;
+import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.JavaTXParser;
-import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SourceFileContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SrcfileContext;
import de.dhbwstuttgart.parser.scope.GatherNames;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
/**
- * Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt
- * Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
+ * Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
*
* TODO: Zur Initialisierung der CompilationEnvironment sollten alle SourceFiles mit ANTLR geparst werden und alle Klassen Generics und Typen herausgefunden werden
*/
@@ -29,79 +29,79 @@ public class CompilationEnvironment {
public final PackageCrawler packageCrawler;
/**
- * Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien
- * Die Environment enth�lt automatisch die Java Standard Library
+ * Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien Die Environment enth�lt automatisch die Java Standard Library
+ *
* @param sourceFiles die zu kompilierenden Dateien
*/
public CompilationEnvironment(List sourceFiles) {
/**
- * Java 9 bringt einige Änderungen am Classloader
- * So funktioniert der BootClassLoader nicht mehr.
- * hier gibts ein paar Quellen zum nachlesen:
- * http://java9.wtf/class-loading/
- * https://stackoverflow.com/questions/46494112/classloaders-hierarchy-in-java-9
+ * Java 9 bringt einige Änderungen am Classloader So funktioniert der BootClassLoader nicht mehr. hier gibts ein paar Quellen zum nachlesen: http://java9.wtf/class-loading/ https://stackoverflow.com/questions/46494112/classloaders-hierarchy-in-java-9
*
*/
- //String bootClassPath = System.getProperty("sun.boot.class.path");
- // DirectoryClassLoader cl = DirectoryClassLoader.getPlatformClassLoader();
- String bootClassPath = System.getProperty("java.class.path");
+ // String bootClassPath = System.getProperty("sun.boot.class.path");
+ // DirectoryClassLoader cl = DirectoryClassLoader.getPlatformClassLoader();
+ String bootClassPath = System.getProperty("java.class.path");
librarys = new ArrayList<>();
- for(String path : bootClassPath.split(File.pathSeparator)) {
- try {
- librarys.add(new URL("file:"+path));
- } catch (MalformedURLException e) {
- new DebugException("Fehler im Classpath auf diesem System");
- }
+ for (String path : bootClassPath.split(File.pathSeparator)) {
+ try {
+ librarys.add(new URL("file:" + path));
+ } catch (MalformedURLException e) {
+ new DebugException("Fehler im Classpath auf diesem System");
}
- //URLClassLoader loader = new URLClassLoader(new URL[0], cl);
- //librarys = Arrays.asList(loader.getURLs());
+ }
+ // URLClassLoader loader = new URLClassLoader(new URL[0], cl);
+ // librarys = Arrays.asList(loader.getURLs());
this.sourceFiles = sourceFiles;
- this.packageCrawler = new PackageCrawler(librarys);
+ this.packageCrawler = new PackageCrawler(librarys);
}
- public JavaClassRegistry getRegistry(File forSourceFile, ClassLoader classLoader) throws ClassNotFoundException, IOException {
+ public JavaClassRegistry getRegistry(SourceFileContext tree, File sourceFile, ClassLoader classLoader) throws ClassNotFoundException, IOException {
Map allNames;
- CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
- allNames = GatherNames.getNames(tree, packageCrawler, classLoader);
- for(Class c : loadDefaultPackageClasses(forSourceFile, classLoader)){
- allNames.put(c.getName(), c.getTypeParameters().length);
+ if (tree instanceof SrcfileContext srcfile) {
+ allNames = GatherNames.getNames((SrcfileContext) tree, packageCrawler, classLoader);
+ for (Class c : loadDefaultPackageClasses(getPackageName(srcfile), sourceFile, classLoader)) {
+ allNames.put(c.getName(), c.getTypeParameters().length);
+ }
+ return new JavaClassRegistry(allNames);
+ } else {
+ throw new NotImplementedException();
}
- return new JavaClassRegistry(allNames);
+
}
- public static List loadDefaultPackageClasses(File forSourceFile, ClassLoader classLoader) throws IOException, ClassNotFoundException {
+ public static List loadDefaultPackageClasses(String packageName, File sourceFile, ClassLoader classLoader) throws IOException, ClassNotFoundException {
List ret = new ArrayList<>();
- String packageName = getPackageName(JavaTXParser.parse(forSourceFile));
- //Set classLoader to include default package for this specific source file
- File dir = new File(forSourceFile.getAbsoluteFile().getParent());
+ // Set classLoader to include default package for this specific source file
+ File dir = sourceFile.getParentFile();
String dirPath = dir.toString() + "/";
- if(packageName.length()>0)dirPath = dirPath.substring(0,dirPath.length() - packageName.length());
+ if (packageName.length() > 0)
+ dirPath = dirPath.substring(0, dirPath.length() - packageName.length() - 1);
String path = dirPath;
ArrayList defaultPath = Lists.newArrayList(new File(path));
classLoader = new DirectoryClassLoader(defaultPath, classLoader);
- //Gather all names in the default package for this source file (classes that are imported by default)
- File [] files = dir.listFiles((dir1, name) -> name.endsWith(".class"));
- if(files != null)for (File classFile : files) {
- String className = classFile.getName().substring(0,classFile.getName().length()-6);
- if (className.matches("Fun\\d+\\$\\$.*")) continue;
- ret.add(classLoader.loadClass(packageName + className));
- }
+ // Gather all names in the default package for this source file (classes that are imported by default)
+ File[] files = dir.listFiles((dir1, name) -> name.endsWith(".class"));
+ if (files != null)
+ for (File classFile : files) {
+ String className = classFile.getName().substring(0, classFile.getName().length() - 6);
+ if (className.matches("Fun\\d+\\$\\$.*"))
+ continue;
+ ret.add(classLoader.loadClass(packageName + className));
+ }
return ret;
}
- private static String getPackageName(CompilationUnitContext forTree){
+ private static String getPackageName(SrcfileContext forTree) {
String packageName = "";
- if(forTree.packageDeclaration() != null && forTree.packageDeclaration().Identifier() != null)
- for(TerminalNode subPackage : forTree.packageDeclaration().Identifier()){
- packageName += subPackage.toString() + ".";
- }
+ if (forTree.packageDeclaration() != null && !forTree.packageDeclaration().qualifiedName().identifier().isEmpty())
+ packageName = forTree.packageDeclaration().qualifiedName().getText();
return packageName;
}
public List getAllAvailableClasses() {
List ret = new ArrayList<>();
- for(Class c : new PackageCrawler(librarys).getAllAvailableClasses()){
+ for (Class c : new PackageCrawler(librarys).getAllAvailableClasses()) {
ret.add(ASTFactory.createClass(c));
}
return ret;
diff --git a/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java b/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java
index aad0a575..eb5db14e 100644
--- a/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java
+++ b/src/main/java/de/dhbwstuttgart/parser/JavaTXParser.java
@@ -2,12 +2,13 @@ package de.dhbwstuttgart.parser;
import de.dhbwstuttgart.environment.CompilationEnvironment;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
-import de.dhbwstuttgart.parser.antlr.Java8Lexer;
-import de.dhbwstuttgart.parser.antlr.Java8Parser;
+import de.dhbwstuttgart.parser.antlr.Java17Lexer;
+import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.syntaxtree.SourceFile;
-import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import java.io.*;
@@ -15,23 +16,21 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-public class JavaTXParser {
- public static Java8Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
+public class JavaTXParser {
+ public static Java17Parser.SourceFileContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
InputStream stream = new FileInputStream(source);
- ANTLRInputStream input = new ANTLRInputStream(stream);
- Java8Lexer lexer = new Java8Lexer(input);
+ // DEPRECATED: ANTLRInputStream input = new ANTLRInputStream(stream);
+ CharStream input = CharStreams.fromStream(stream);
+ Java17Lexer lexer = new Java17Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
- Java8Parser parser = new Java8Parser(tokens);
- return parser.compilationUnit();
+ Java17Parser parser = new Java17Parser(tokens);
+ return parser.sourceFile();
/*
- SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source));
- return generator.convert(tree);
- */
+ * SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source)); return generator.convert(tree);
+ */
}
-
- /* Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet:
- public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException {
- return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
- }
- */
+
+ /*
+ * Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet: public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException { return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))); }
+ */
}
diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
index f156114b..b22ef7b2 100644
--- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
+++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
@@ -1,28 +1,114 @@
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import org.antlr.v4.runtime.Token;
+
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
-import de.dhbwstuttgart.parser.antlr.Java8Parser;
+import de.dhbwstuttgart.parser.antlr.Java17Parser;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.AndexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ArrayaccessexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.AssertstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.AssignexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwiseandexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwiseorexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.BitwisexorexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.BlockstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.BoolLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.BreakstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.CastexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.CharLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ConditionalassignexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ConditionalstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ContinuestmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.DottedexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.DowhileloopContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.EqualityexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ExpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.FltLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ForloopContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.IdentifierContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.IntLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.LabeledstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.LambdaLVTIParameterContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.LambdaexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.MathaddsubexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.MathmuldivmodexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodCallContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.MethodcallexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.NewinstanceexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.NullLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.OrexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PostfixexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrefixexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryClassrefContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryExpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryIdentifierContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimarySuperContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryThisContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.PrimaryexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.RelationalexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ReturnstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SemistmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ShiftexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.StmtexpressionContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.StringLiteralContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchexpressionstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SwitchstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.SynchronizedstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.ThrowstmtContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchblockContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.TrycatchresourceContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.WhileloopContext;
+import de.dhbwstuttgart.parser.antlr.Java17Parser.YieldstmtContext;
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
-import de.dhbwstuttgart.syntaxtree.*;
-import de.dhbwstuttgart.syntaxtree.statement.*;
-import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr.Operation;
+import de.dhbwstuttgart.syntaxtree.FormalParameter;
+import de.dhbwstuttgart.syntaxtree.ParameterList;
+import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
+import de.dhbwstuttgart.syntaxtree.statement.Assign;
+import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
+import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
+import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
+import de.dhbwstuttgart.syntaxtree.statement.Block;
+import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
+import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
+import de.dhbwstuttgart.syntaxtree.statement.Expression;
+import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
+import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
+import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
+import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
+import de.dhbwstuttgart.syntaxtree.statement.Literal;
+import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
+import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
+import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
+import de.dhbwstuttgart.syntaxtree.statement.NewClass;
+import de.dhbwstuttgart.syntaxtree.statement.Receiver;
+import de.dhbwstuttgart.syntaxtree.statement.Return;
+import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
+import de.dhbwstuttgart.syntaxtree.statement.Statement;
+import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
+import de.dhbwstuttgart.syntaxtree.statement.Super;
+import de.dhbwstuttgart.syntaxtree.statement.This;
+import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
+import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
-import de.dhbwstuttgart.syntaxtree.type.Void;
-
-import org.antlr.v4.runtime.Token;
-import org.antlr.v4.runtime.tree.TerminalNode;
-
-import java.util.*;
-import java.util.stream.Collectors;
public class StatementGenerator {
private JavaClassRegistry reg;
- private Map fields; // PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen
+ private Map fields; // PL 2018-11-01 fields eingefuegt, damit die fields
+ // immer die gleiche TPH bekommen
private Map localVars;
private GenericsRegistry generics;
@@ -33,25 +119,24 @@ public class StatementGenerator {
this.localVars = localVars;
}
- public ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
+ public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) {
List ret = new ArrayList<>();
- List fps = new ArrayList<>();
- if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
+ List fps = new ArrayList<>();
+ if (Objects.isNull(formalParameterListContext))
return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer
-
- if (formalParameterListContext.lastFormalParameter().formalParameter() == null)
- throw new NotImplementedException();
-
- if (formalParameterListContext != null && formalParameterListContext.formalParameters() != null && formalParameterListContext.formalParameters().formalParameter() != null) {
- fps = new ArrayList<>(formalParameterListContext.formalParameters().formalParameter());
+ if (!Objects.isNull(formalParameterListContext.lastFormalParameter())) {
+ /*
+ * Der '...' Operator wird noch nicht unterstützt, da dafür benötigte Typen (List oder Array) nicht vom Typinferenzalgo. verarbeitet werden können
+ */
+ throw new NotImplementedException("Formale Parameter variabler Länge nicht unterstützt.");
}
- fps.add(formalParameterListContext.lastFormalParameter().formalParameter());
- for (Java8Parser.FormalParameterContext fp : fps) {
+ fps = formalParameterListContext.formalParameter();
+ for (Java17Parser.FormalParameterContext fp : fps) {
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
RefTypeOrTPHOrWildcardOrGeneric type;
- if (fp.unannType() != null) {
- type = TypeGenerator.convert(fp.unannType(), reg, generics);
+ if (fp.typeType() != null) {
+ type = TypeGenerator.convert(fp.typeType(), reg, generics);
} else {
type = TypePlaceholder.fresh(fp.getStart());
}
@@ -65,125 +150,421 @@ public class StatementGenerator {
* StatementGeneration:
*/
- private Statement convert(Java8Parser.StatementContext stmt) {
- if (stmt.statementWithoutTrailingSubstatement() != null) {
- return convert(stmt.statementWithoutTrailingSubstatement());
- } else if (stmt.whileStatement() != null) {
- return convert(stmt.whileStatement());
- } else if (stmt.forStatement() != null) {
- return convert(stmt.forStatement());
- } else if (stmt.ifThenElseStatement() != null) {
- return convert(stmt.ifThenElseStatement());
- } else if (stmt.ifThenStatement() != null) {
- return convert(stmt.ifThenStatement());
- } else if (stmt.labeledStatement() != null) {
- return convert(stmt.labeledStatement());
- } else
+ private Statement convert(Java17Parser.StatementContext stmt) {
+ switch (stmt) {
+ case BlockstmtContext blockstmt:
+ return convert(blockstmt.block(), false);
+ case ConditionalstmtContext condition:
+ return convert(condition);
+ case WhileloopContext whileloop:
+ return convert(whileloop);
+ case DowhileloopContext dowhileloop:
+ return convert(dowhileloop);
+ case SwitchstmtContext switchstmt:
+ return convert(switchstmt);
+ case SwitchexpressionstmtContext switchexpression:
+ return convert(switchexpression);
+ case ReturnstmtContext returnstmt:
+ return convert(returnstmt);
+ case YieldstmtContext yieldstmt:
+ return convert(yieldstmt);
+ case StmtexpressionContext stmtexpression:
+ return convert(stmtexpression);
+ case AssertstmtContext assertstmt:
+ return convert(assertstmt);
+ case ForloopContext forloop:
+ return convert(forloop);
+ case TrycatchblockContext trycatchblock:
+ return convert(trycatchblock);
+ case TrycatchresourceContext trycatchresource:
+ return convert(trycatchresource);
+ case SynchronizedstmtContext synchronizedstmt:
+ return convert(synchronizedstmt);
+ case ThrowstmtContext throwstmt:
+ return convert(throwstmt);
+ case BreakstmtContext breakstmt:
+ return convert(breakstmt);
+ case ContinuestmtContext continuestmt:
+ return convert(continuestmt);
+ case SemistmtContext semistmt:
+ return convert(semistmt);
+ case LabeledstmtContext labeledstmt:
+ return convert(labeledstmt);
+ default:
throw new NotImplementedException();
+ }
}
- private Statement convert(Java8Parser.StatementNoShortIfContext stmt) {
- if (stmt.statementWithoutTrailingSubstatement() != null) {
- return convert(stmt.statementWithoutTrailingSubstatement());
- } else if (stmt.labeledStatementNoShortIf() != null) {
- return convert(stmt.labeledStatementNoShortIf());
- } else if (stmt.ifThenElseStatementNoShortIf() != null) {
- return convert(stmt.ifThenElseStatementNoShortIf());
- } else if (stmt.whileStatementNoShortIf() != null) {
- return convert(stmt.whileStatementNoShortIf());
- } else if (stmt.forStatementNoShortIf() != null) {
- return convert(stmt.forStatementNoShortIf());
- } else
- throw new NotImplementedException();
- }
-
- private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) {
- if (stmt.block() != null) {
- return convert(stmt.block(), false);
- } else if (stmt.emptyStatement() != null) {
- return new EmptyStmt(stmt.getStart());
- } else if (stmt.expressionStatement() != null) {
- return convert(stmt.expressionStatement());
- } else if (stmt.assertStatement() != null) {
- return convert(stmt.assertStatement());
- } else if (stmt.switchStatement() != null) {
- return convert(stmt.switchStatement());
- } else if (stmt.doStatement() != null) {
- return convert(stmt.doStatement());
- } else if (stmt.breakStatement() != null) {
- return convert(stmt.breakStatement());
- } else if (stmt.continueStatement() != null) {
- return convert(stmt.continueStatement());
- } else if (stmt.returnStatement() != null) {
- return convert(stmt.returnStatement());
- } else if (stmt.synchronizedStatement() != null) {
- return convert(stmt.synchronizedStatement());
- } else if (stmt.throwStatement() != null) {
- return convert(stmt.throwStatement());
- } else if (stmt.tryStatement() != null) {
- return convert(stmt.tryStatement());
- } else
- throw new NotImplementedException();
- }
-
- public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) {
+ public Block convert(Java17Parser.BlockContext block, boolean addTrailingReturn) {
List statements = new ArrayList<>();
- if (block.blockStatements() != null)
- for (Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()) {
- List stmt = convert(statementContext);
- statements.addAll(stmt);
+ if (block.blockStatement().size() > 0)
+ for (Java17Parser.BlockStatementContext statementContext : block.blockStatement()) {
+ statements.addAll(convert(statementContext));
}
if (addTrailingReturn)
statements = SyntacticSugar.addTrailingReturn(statements);
return new Block(statements, block.getStart());
}
- private List