Compare commits
115 Commits
4d1950d0ba
...
LSP-Interf
Author | SHA1 | Date | |
---|---|---|---|
|
c9d38728af | ||
|
b7fad6e3c7 | ||
|
3cb9b74df1 | ||
|
effc31782f | ||
|
2a24eab9d3 | ||
|
b29eb71238 | ||
|
e9ce071e2b | ||
3567bae0d7 | |||
|
a314013f40 | ||
|
37c58be1f3 | ||
|
24920330c6 | ||
|
bc43ea749d | ||
9160c99cf2 | |||
c72a14cab3 | |||
10bb5d1d11 | |||
2842fc5069 | |||
5c5e0bd1e9 | |||
3d81318e01 | |||
53e2c20608 | |||
86e467fd82 | |||
25b14e9342 | |||
d0de0b31e4 | |||
dd180524b2 | |||
b3744bf5f7 | |||
fda16978c2 | |||
a485cd8fa6 | |||
f8c708f0f4 | |||
28d9946bbb | |||
7b4ca8f177 | |||
b879d7743d | |||
e26a43b400 | |||
5deed725ae | |||
8ae15f9d41 | |||
8c8e088612 | |||
2814c6538e | |||
dcbc29b49b | |||
05033bcb9d | |||
814f5dd5fa | |||
24ca985ccc | |||
d6ed0689bc | |||
d7676f36e3 | |||
|
c479b044b3 | ||
|
9046fb09e5 | ||
|
9e323759d6 | ||
558083166d | |||
|
aec2f9a399 | ||
|
31df7a65f0 | ||
|
185989ba62 | ||
|
0eb48ba425 | ||
ceee9a49c4 | |||
ee64218a5f | |||
c50f14a4a3 | |||
1f4250ff84 | |||
ae41c7f19d | |||
2416c80c20 | |||
4cc55c0059 | |||
9434facfa0 | |||
09a6b9a788 | |||
8b342c5604 | |||
cdb93b5155 | |||
b07e848fa2 | |||
313cd20f36 | |||
567fcc3b9a | |||
d9936e7197 | |||
8f194b3102 | |||
1391206dfe | |||
659bf6b500 | |||
|
42e31a3471 | ||
|
d3b3f92193 | ||
|
8208abcaea | ||
|
e4a3939ce9 | ||
|
d903ec0ebb | ||
|
61de81cf92 | ||
|
59888006e0 | ||
|
94034912b4 | ||
|
f303163118 | ||
|
7d99fba044 | ||
|
3740d34954 | ||
|
d8b861ea95 | ||
33ed22c06a | |||
70f7857661 | |||
|
cf45ea68bd | ||
|
be72e4d7fb | ||
45275b6888 | |||
2144dd9341 | |||
69c2bb3dc9 | |||
3a57d5e025 | |||
|
1e37538fde | ||
4cdd5d016c | |||
4318856fa8 | |||
1ace099d72 | |||
b76e1e46f0 | |||
09c483542d | |||
77411973be | |||
d0d9c46a67 | |||
|
24bf3d350f | ||
b9f9994de3 | |||
|
f0287c4611 | ||
|
edf609f916 | ||
|
14e2af7d2a | ||
|
158adf837a | ||
46b378e3a5 | |||
484a70c15c | |||
c461e89336 | |||
f846142ee1 | |||
443b8b0c09 | |||
ff715a22cf | |||
170955b333 | |||
88d81f4af7 | |||
bb11d24101 | |||
e2bf09548f | |||
|
c33e372446 | ||
|
7c546834c0 | ||
|
aa61f90fb1 | ||
|
b4da20e1d4 |
@@ -1,5 +1,8 @@
|
|||||||
name: Build and Test with Maven
|
name: Build and Test with Maven
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
branches-ignore:
|
||||||
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build-and-test-with-Maven:
|
Build-and-test-with-Maven:
|
||||||
@@ -15,11 +18,11 @@ jobs:
|
|||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '21'
|
java-version: '24'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
- name: Compile project
|
- name: Compile project
|
||||||
run: |
|
run: |
|
||||||
mvn compile
|
mvn compile
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
mvn test
|
mvn test
|
||||||
|
45
.gitea/workflows/sonarqube.yml
Normal file
45
.gitea/workflows/sonarqube.yml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
name: SonarQube Scan
|
||||||
|
jobs:
|
||||||
|
sonarqube:
|
||||||
|
name: SonarQube Trigger
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checking out
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
# Disabling shallow clone is recommended for improving relevancy of reporting
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install maven
|
||||||
|
run: |
|
||||||
|
apt update
|
||||||
|
apt install -y maven
|
||||||
|
- name: Install java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '24'
|
||||||
|
cache: 'maven'
|
||||||
|
- name: Compile project
|
||||||
|
run: |
|
||||||
|
mvn clean dependency:copy-dependencies verify
|
||||||
|
- name: SonarQube Scan
|
||||||
|
uses: SonarSource/sonarqube-scan-action@v5.3.0
|
||||||
|
env:
|
||||||
|
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
|
||||||
|
with:
|
||||||
|
args: >
|
||||||
|
-Dsonar.projectKey=Java-TX
|
||||||
|
-Dsonar.sources=src/main/java
|
||||||
|
-Dsonar.tests=src/test/java
|
||||||
|
-Dsonar.junit.reportPaths=target/test-reports
|
||||||
|
-Dsonar.java.binaries=target/classes
|
||||||
|
-Dsonar.java.libraries=target/dependency/*.jar
|
||||||
|
-Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
|
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
## Java-TX Compiler
|
||||||
|
|
||||||
|
[](https://gitea.hb.dhbw-stuttgart.de/sonarqube/dashboard?id=Java-TX)
|
||||||
|
[](https://gitea.hb.dhbw-stuttgart.de/sonarqube/dashboard?id=Java-TX)
|
||||||
|
[](https://gitea.hb.dhbw-stuttgart.de/sonarqube/dashboard?id=Java-TX)
|
||||||
|
|
||||||
|
Work in Progress Java-TX Compiler repository!
|
49
pom.xml
49
pom.xml
@@ -12,60 +12,79 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>4.13.2</version>
|
<version>5.13.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
|
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.antlr</groupId>
|
<groupId>org.antlr</groupId>
|
||||||
<artifactId>antlr4</artifactId>
|
<artifactId>antlr4</artifactId>
|
||||||
<version>4.11.1</version>
|
<version>4.13.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.16.1</version>
|
<version>2.19.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.classgraph</groupId>
|
<groupId>io.github.classgraph</groupId>
|
||||||
<artifactId>classgraph</artifactId>
|
<artifactId>classgraph</artifactId>
|
||||||
<version>4.8.172</version>
|
<version>4.8.180</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>33.2.0-jre</version>
|
<version>33.4.8-jre</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ow2.asm</groupId>
|
<groupId>org.ow2.asm</groupId>
|
||||||
<artifactId>asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
<version>9.5</version>
|
<version>9.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.jacoco</groupId>
|
||||||
|
<artifactId>jacoco-maven-plugin</artifactId>
|
||||||
|
<version>0.8.13</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare-agent</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>report</id>
|
||||||
|
<phase>prepare-package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>report</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.11.0</version>
|
<version>3.14.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<compilerArgs>--enable-preview</compilerArgs>
|
<compilerArgs>--enable-preview</compilerArgs>
|
||||||
<source>22</source>
|
<source>24</source>
|
||||||
<target>22</target>
|
<target>24</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.5.3</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
||||||
<reportsDirectory>${project.build.directory}/test-reports</reportsDirectory>
|
<reportsDirectory>${project.build.directory}/test-reports</reportsDirectory>
|
||||||
<argLine>--enable-preview</argLine>
|
<argLine>${argLine} --enable-preview</argLine>
|
||||||
<trimStackTrace>false</trimStackTrace>
|
<trimStackTrace>false</trimStackTrace>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/JavaTXCompilerTest.java</exclude>
|
<exclude>**/JavaTXCompilerTest.java</exclude>
|
||||||
@@ -77,7 +96,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.antlr</groupId>
|
<groupId>org.antlr</groupId>
|
||||||
<artifactId>antlr4-maven-plugin</artifactId>
|
<artifactId>antlr4-maven-plugin</artifactId>
|
||||||
<version>4.11.1</version>
|
<version>4.13.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>antlr</id>
|
<id>antlr</id>
|
||||||
@@ -90,7 +109,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.4.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
public class Box<A> {
|
public class Box {
|
||||||
|
|
||||||
A a;
|
a;
|
||||||
|
|
||||||
public Box() { }
|
public Box() { }
|
||||||
public Box(A a) {
|
public Box(a) {
|
||||||
//this.a = a;
|
//this.a = a;
|
||||||
}
|
}
|
||||||
|
set(x) {
|
||||||
|
a = x;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -6,7 +6,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class Bug325 {
|
public class Bug325 {
|
||||||
public main() {
|
public main() {
|
||||||
List<Integer> list = new ArrayList<>(List.of(1,2,3,4,5));
|
var list = new ArrayList<>(List.of(1,2,3,4,5));
|
||||||
var func = x -> x*2;
|
var func = x -> x*2;
|
||||||
return list.stream().map(func).toList();
|
return list.stream().map(func).toList();
|
||||||
}
|
}
|
||||||
|
22
resources/bytecode/javFiles/Bug363.jav
Normal file
22
resources/bytecode/javFiles/Bug363.jav
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
|
public class Bug363 {
|
||||||
|
uncurry (f){
|
||||||
|
return x -> f.apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
uncurry (f){
|
||||||
|
return (x, y) -> f.apply(x).apply(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
uncurry (f){
|
||||||
|
return (x, y, z) -> f.apply(x).apply(y).apply(z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public test(){
|
||||||
|
var f = x -> y -> z -> x + y + z;
|
||||||
|
var g = uncurry(f);
|
||||||
|
return g.apply("A", "B", "C"); // Outputs: 6
|
||||||
|
}
|
||||||
|
}
|
8
resources/bytecode/javFiles/Bug364.jav
Normal file
8
resources/bytecode/javFiles/Bug364.jav
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
public class Bug364{
|
||||||
|
public main(){
|
||||||
|
var f = x -> y -> z -> x + y + z;
|
||||||
|
return f.apply("A").apply("B").apply("C");
|
||||||
|
}
|
||||||
|
}
|
21
resources/bytecode/javFiles/Bug365.jav
Normal file
21
resources/bytecode/javFiles/Bug365.jav
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Object;
|
||||||
|
|
||||||
|
public class Bug365{
|
||||||
|
swap(f){
|
||||||
|
return x -> y -> f.apply(y).apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
swap(Fun1$$<String, Fun1$$<String, Fun1$$<String, Object>>> f){
|
||||||
|
return x -> y -> z -> f.apply(z).apply(y).apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ex1() {
|
||||||
|
var func = x -> y -> z -> x + y + z;
|
||||||
|
return func.apply("A").apply("B").apply("C");
|
||||||
|
}
|
||||||
|
public ex2() {
|
||||||
|
var func = x -> y -> z -> x + y + z;
|
||||||
|
return swap(func).apply("A").apply("B").apply("C");
|
||||||
|
}
|
||||||
|
}
|
12
resources/bytecode/javFiles/Bug366.jav
Normal file
12
resources/bytecode/javFiles/Bug366.jav
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class Bug366 {
|
||||||
|
public static lambda() {
|
||||||
|
return (a, b) -> a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static test() {
|
||||||
|
var l = lambda();
|
||||||
|
return l.apply(10, 20);
|
||||||
|
}
|
||||||
|
}
|
10
resources/bytecode/javFiles/Bug371.jav
Normal file
10
resources/bytecode/javFiles/Bug371.jav
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class Bug371 {
|
||||||
|
static m1(x, y) { return x || y; }
|
||||||
|
static m2(x, y) { return x && y; }
|
||||||
|
|
||||||
|
public static test() {
|
||||||
|
return m2(m1(true, false), true);
|
||||||
|
}
|
||||||
|
}
|
17
resources/bytecode/javFiles/Bug373.jav
Normal file
17
resources/bytecode/javFiles/Bug373.jav
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.Character;
|
||||||
|
|
||||||
|
public class Bug373 {
|
||||||
|
public static main() {
|
||||||
|
System.out.println(true);
|
||||||
|
System.out.println(false);
|
||||||
|
System.out.println(1);
|
||||||
|
System.out.println(1l);
|
||||||
|
System.out.println(1.0);
|
||||||
|
System.out.println(1.0f);
|
||||||
|
System.out.println('a');
|
||||||
|
}
|
||||||
|
}
|
@@ -1,16 +0,0 @@
|
|||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.lang.String;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
class BugXXX {
|
|
||||||
public main() {
|
|
||||||
List<Integer> i = new ArrayList<>(List.of(1,2,3,4,5,6,7,8,9,10));
|
|
||||||
Optional<Integer> tmp = i.stream().filter(x -> x == 5).map(x -> x*2).findFirst();
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
}
|
|
14
resources/bytecode/javFiles/Main.jav
Normal file
14
resources/bytecode/javFiles/Main.jav
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.lang.Iterable;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.util.List;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
class Main {
|
||||||
|
static main(args) {
|
||||||
|
for (var arg : args) {
|
||||||
|
System.out.println(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
resources/bytecode/javFiles/OverloadNestedPattern.jav
Normal file
20
resources/bytecode/javFiles/OverloadNestedPattern.jav
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
|
public record R(Object nested) {}
|
||||||
|
|
||||||
|
public class OverloadNestedPattern {
|
||||||
|
|
||||||
|
public Integer m(R(R(Integer a)), R(Integer b)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer m(R(R(Float a)), R(Float b)) {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer m(R(Integer a), R(Integer b)) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
@@ -5,13 +5,29 @@ import java.lang.Float;
|
|||||||
public record Point(Number x, Number y) {}
|
public record Point(Number x, Number y) {}
|
||||||
|
|
||||||
public class OverloadPattern {
|
public class OverloadPattern {
|
||||||
public m(Point(x, y), Point(z, a)) {
|
public Number m(Point(Integer x, Integer y), Point(Float a, Float b)) {
|
||||||
return x + y + z + a;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public m(Point(Float x, Float y)) {
|
public Number m(Point(Integer x, Integer y), Point(Integer a, Integer b)) {
|
||||||
return x * y;
|
return 2;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
public Number m(Point(Float x, Float y), Point(Integer a, Integer b)) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Number m(Point(Float x, Float y), Point(Float a, Float b)) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Number m(Point(Integer x, Integer y)) {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Number m(Point(Float x, Float y)) {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
public m(Integer x) {
|
public m(Integer x) {
|
||||||
return x;
|
return x;
|
||||||
|
@@ -1,14 +0,0 @@
|
|||||||
sealed interface List<T> permits LinkedElem, Elem {}
|
|
||||||
|
|
||||||
public record LinkedElem<T>(T a, List<T> l) implements List<T> {}
|
|
||||||
public record Elem<T>(T a) implements List<T> {}
|
|
||||||
|
|
||||||
public class PaternMatchingHaskellStyle {
|
|
||||||
public append(LinkedElem(a, Elem(e)), l2) {
|
|
||||||
return new LinkedElem<>(a, new LinkedElem<>(e, l2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public append(LinkedElem(a, r), l2) {
|
|
||||||
return new LinkedElem<>(a, append(r, l2));
|
|
||||||
}
|
|
||||||
}
|
|
21
resources/bytecode/javFiles/PatternMatchingHaskellStyle.jav
Normal file
21
resources/bytecode/javFiles/PatternMatchingHaskellStyle.jav
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
sealed interface List<T> permits LinkedElem, Elem {}
|
||||||
|
|
||||||
|
public record LinkedElem<T>(T a, List<T> l) implements List<T> {}
|
||||||
|
public record Elem<T>(T a) implements List<T> {}
|
||||||
|
|
||||||
|
public class PatternMatchingHaskellStyle {
|
||||||
|
|
||||||
|
public append(LinkedElem(a, b), list2) {
|
||||||
|
return handleAppend(a, b, list2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleAppend(a, Elem(e), list2) {
|
||||||
|
return new LinkedElem<>(a, new LinkedElem<>(e, list2));
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleAppend(a, LinkedElem(e,r), list2) {
|
||||||
|
return new LinkedElem<>(a, append(new LinkedElem(e, r), list2));
|
||||||
|
}
|
||||||
|
}
|
26
resources/bytecode/javFiles/PatternMatchingListAppend.jav
Normal file
26
resources/bytecode/javFiles/PatternMatchingListAppend.jav
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.Object;
|
||||||
|
|
||||||
|
sealed interface List<T> permits Cons, Empty {}
|
||||||
|
|
||||||
|
public record Cons<T>(T a, List<T> l) implements List<T> {}
|
||||||
|
public record Empty<T>() implements List<T> {}
|
||||||
|
|
||||||
|
public class PatternMatchingListAppend {
|
||||||
|
|
||||||
|
public append(Cons(a, b), list2) {
|
||||||
|
return new Cons<>(a, append(b, list2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public append(Empty(), list2) {
|
||||||
|
return list2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public append(a, list2) {
|
||||||
|
switch(a) {
|
||||||
|
case Cons(x, y) -> ...
|
||||||
|
case Empty() ->
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
14
resources/bytecode/javFiles/SwitchNestedValue.jav
Normal file
14
resources/bytecode/javFiles/SwitchNestedValue.jav
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public record R(Integer i) {}
|
||||||
|
|
||||||
|
public class SwitchNestedValue {
|
||||||
|
public main(r) {
|
||||||
|
return switch(r) {
|
||||||
|
case R(10) -> 1;
|
||||||
|
case R(20) -> 2;
|
||||||
|
case R(i) -> 3;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -2,24 +2,18 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Pattern;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
import de.dhbwstuttgart.target.generate.StatementToTargetExpression;
|
|
||||||
import de.dhbwstuttgart.target.tree.*;
|
import de.dhbwstuttgart.target.tree.*;
|
||||||
import de.dhbwstuttgart.target.tree.expression.*;
|
import de.dhbwstuttgart.target.tree.expression.*;
|
||||||
import de.dhbwstuttgart.target.tree.type.*;
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
import org.antlr.v4.codegen.Target;
|
|
||||||
import org.objectweb.asm.*;
|
import org.objectweb.asm.*;
|
||||||
|
|
||||||
import java.lang.invoke.*;
|
import java.lang.invoke.*;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
import static de.dhbwstuttgart.target.tree.expression.TargetBinaryOp.*;
|
import static de.dhbwstuttgart.target.tree.expression.TargetBinaryOp.*;
|
||||||
@@ -91,14 +85,16 @@ public class Codegen {
|
|||||||
int localCounter;
|
int localCounter;
|
||||||
MethodVisitor mv;
|
MethodVisitor mv;
|
||||||
TargetType returnType;
|
TargetType returnType;
|
||||||
|
boolean isStatic = false;
|
||||||
|
|
||||||
Stack<BreakEnv> breakStack = new Stack<>();
|
Stack<BreakEnv> breakStack = new Stack<>();
|
||||||
Stack<Integer> switchResultValue = new Stack<>();
|
Stack<Integer> switchResultValue = new Stack<>();
|
||||||
|
|
||||||
State(TargetType returnType, MethodVisitor mv, int localCounter) {
|
State(TargetType returnType, MethodVisitor mv, int localCounter, boolean isStatic) {
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.localCounter = localCounter;
|
this.localCounter = localCounter;
|
||||||
|
this.isStatic = isStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
void enterScope() {
|
void enterScope() {
|
||||||
@@ -109,6 +105,10 @@ public class Codegen {
|
|||||||
this.scope = this.scope.parent;
|
this.scope = this.scope.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalVar createVariable(TargetType type) {
|
||||||
|
return createVariable("__var" + this.localCounter, type);
|
||||||
|
}
|
||||||
|
|
||||||
LocalVar createVariable(String name, TargetType type) {
|
LocalVar createVariable(String name, TargetType type) {
|
||||||
var local = new LocalVar(localCounter, name, type);
|
var local = new LocalVar(localCounter, name, type);
|
||||||
scope.add(local);
|
scope.add(local);
|
||||||
@@ -232,9 +232,9 @@ public class Codegen {
|
|||||||
if (source.equals(dest))
|
if (source.equals(dest))
|
||||||
return;
|
return;
|
||||||
if (source.equals(TargetType.Long)) {
|
if (source.equals(TargetType.Long)) {
|
||||||
if (dest.equals(TargetType.Integer)) {
|
if (dest.equals(TargetType.Integer))
|
||||||
mv.visitInsn(L2I);
|
mv.visitInsn(L2I);
|
||||||
} else if (dest.equals(TargetType.Float))
|
else if (dest.equals(TargetType.Float))
|
||||||
mv.visitInsn(L2F);
|
mv.visitInsn(L2F);
|
||||||
else if (dest.equals(TargetType.Double))
|
else if (dest.equals(TargetType.Double))
|
||||||
mv.visitInsn(L2D);
|
mv.visitInsn(L2D);
|
||||||
@@ -277,6 +277,8 @@ public class Codegen {
|
|||||||
mv.visitInsn(I2F);
|
mv.visitInsn(I2F);
|
||||||
else if (dest.equals(TargetType.Double))
|
else if (dest.equals(TargetType.Double))
|
||||||
mv.visitInsn(I2D);
|
mv.visitInsn(I2D);
|
||||||
|
} else if (source.equals(TargetType.Boolean)) {
|
||||||
|
unboxPrimitive(state, dest);
|
||||||
} else if (isFunctionalInterface(source) && isFunctionalInterface(dest) &&
|
} else if (isFunctionalInterface(source) && isFunctionalInterface(dest) &&
|
||||||
!(source instanceof TargetFunNType && dest instanceof TargetFunNType)) {
|
!(source instanceof TargetFunNType && dest instanceof TargetFunNType)) {
|
||||||
boxFunctionalInterface(state, source, dest);
|
boxFunctionalInterface(state, source, dest);
|
||||||
@@ -760,6 +762,16 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static TargetType removeGenerics(TargetType param) {
|
||||||
|
return switch (param) {
|
||||||
|
case null -> null;
|
||||||
|
case TargetFunNType funNType -> new TargetFunNType(funNType.name(), funNType.funNParams(), List.of(), funNType.returnArguments());
|
||||||
|
case TargetRefType refType -> new TargetRefType(refType.name());
|
||||||
|
case TargetGenericType targetGenericType -> TargetType.Object;
|
||||||
|
default -> param;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void generateLambdaExpression(State state, TargetLambdaExpression lambda) {
|
private void generateLambdaExpression(State state, TargetLambdaExpression lambda) {
|
||||||
var mv = state.mv;
|
var mv = state.mv;
|
||||||
|
|
||||||
@@ -771,7 +783,8 @@ public class Codegen {
|
|||||||
|
|
||||||
var parameters = new ArrayList<>(lambda.captures());
|
var parameters = new ArrayList<>(lambda.captures());
|
||||||
parameters.addAll(signature.parameters());
|
parameters.addAll(signature.parameters());
|
||||||
var implSignature = new TargetMethod.Signature(Set.of(), parameters, lambda.signature().returnType());
|
parameters = parameters.stream().map(param -> param.withType(removeGenerics(param.pattern().type()))).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
var implSignature = new TargetMethod.Signature(Set.of(), parameters, removeGenerics(lambda.signature().returnType()));
|
||||||
|
|
||||||
TargetMethod impl;
|
TargetMethod impl;
|
||||||
if (lambdas.containsKey(lambda)) {
|
if (lambdas.containsKey(lambda)) {
|
||||||
@@ -779,21 +792,22 @@ public class Codegen {
|
|||||||
} else {
|
} else {
|
||||||
var name = "lambda$" + lambdaCounter++;
|
var name = "lambda$" + lambdaCounter++;
|
||||||
|
|
||||||
impl = new TargetMethod(0, name, lambda.block(), implSignature, null);
|
impl = new TargetMethod(state.isStatic ? ACC_STATIC : 0, name, lambda.block(), implSignature, null);
|
||||||
generateMethod(impl);
|
generateMethod(impl, state);
|
||||||
lambdas.put(lambda, 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 bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", mt.toMethodDescriptorString(), false);
|
||||||
var handle = new Handle(H_INVOKEVIRTUAL, clazz.getName(), impl.name(), implSignature.getDescriptor(), false);
|
var handle = new Handle(state.isStatic ? H_INVOKESTATIC : H_INVOKEVIRTUAL, clazz.getName(), impl.name(), implSignature.getDescriptor(), false);
|
||||||
|
|
||||||
var params = new ArrayList<TargetType>();
|
var params = new ArrayList<TargetType>();
|
||||||
params.add(new TargetRefType(clazz.qualifiedName().getClassName()));
|
if(!state.isStatic) params.add(new TargetRefType(clazz.qualifiedName().getClassName()));
|
||||||
params.addAll(lambda.captures().stream().map(mp -> mp.pattern().type()).toList());
|
params.addAll(lambda.captures().stream().map(mp -> mp.pattern().type()).toList());
|
||||||
|
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
if (!state.isStatic)
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
for (var index = 0; index < lambda.captures().size(); index++) {
|
for (var index = 0; index < lambda.captures().size(); index++) {
|
||||||
var capture = lambda.captures().get(index);
|
var capture = lambda.captures().get(index);
|
||||||
var pattern = (TargetTypePattern) capture.pattern();
|
var pattern = (TargetTypePattern) capture.pattern();
|
||||||
@@ -1309,16 +1323,17 @@ public class Codegen {
|
|||||||
var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, Object[].class);
|
var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, Object[].class);
|
||||||
var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/runtime/SwitchBootstraps", "typeSwitch", mt.toMethodDescriptorString(), false);
|
var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/runtime/SwitchBootstraps", "typeSwitch", mt.toMethodDescriptorString(), false);
|
||||||
|
|
||||||
var types = new ArrayList<Object>(aSwitch.cases().size());
|
var types = new ArrayList<>(aSwitch.cases().size());
|
||||||
for (var cse : aSwitch.cases()) for (var label : cse.labels()) {
|
for (var cse : aSwitch.cases()) for (var label : cse.labels()) {
|
||||||
if (label instanceof TargetTypePattern || label instanceof TargetComplexPattern)
|
if (label instanceof TargetTypePattern || label instanceof TargetComplexPattern) {
|
||||||
types.add(Type.getObjectType(label.type().getInternalName()));
|
if (label.type() instanceof TargetGenericType) types.add(Type.getType(Object.class));
|
||||||
else if (label instanceof TargetLiteral lit)
|
else types.add(Type.getObjectType(label.type().getInternalName()));
|
||||||
|
} else if (label instanceof TargetLiteral lit) {
|
||||||
types.add(lit.value());
|
types.add(lit.value());
|
||||||
else if (label instanceof TargetGuard guard)
|
} else if (label instanceof TargetGuard guard) {
|
||||||
types.add(Type.getObjectType(guard.inner().type().getInternalName()));
|
types.add(Type.getObjectType(guard.inner().type().getInternalName()));
|
||||||
// TODO Same here we need to evaluate constant;
|
// TODO Same here we need to evaluate constant;
|
||||||
else {
|
} else {
|
||||||
System.out.println(label);
|
System.out.println(label);
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
@@ -1393,8 +1408,10 @@ public class Codegen {
|
|||||||
|
|
||||||
state.breakStack.pop();
|
state.breakStack.pop();
|
||||||
if (aSwitch.isExpression()) {
|
if (aSwitch.isExpression()) {
|
||||||
mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
|
if (aSwitch.type() != null) {
|
||||||
unboxPrimitive(state, aSwitch.type());
|
mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
|
||||||
|
unboxPrimitive(state, aSwitch.type());
|
||||||
|
}
|
||||||
state.popSwitch();
|
state.popSwitch();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1431,7 +1448,24 @@ public class Codegen {
|
|||||||
state.mv.visitTypeInsn(CHECKCAST, pat.type().getInternalName());
|
state.mv.visitTypeInsn(CHECKCAST, pat.type().getInternalName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pat instanceof TargetTypePattern sp) {
|
if (pat instanceof TargetExpressionPattern ep) {
|
||||||
|
var cur = state.createVariable(pat.type());
|
||||||
|
state.mv.visitVarInsn(ASTORE, cur.index);
|
||||||
|
|
||||||
|
var expr = new Equal(pat.type(), new TargetLocalVar(cur.type, cur.name), ep.expression());
|
||||||
|
generate(state, expr);
|
||||||
|
|
||||||
|
var cont = new Label();
|
||||||
|
state.mv.visitJumpInsn(IFNE, cont);
|
||||||
|
for (var i = 0; i < depth - 1; i++) {
|
||||||
|
state.mv.visitInsn(POP);
|
||||||
|
}
|
||||||
|
|
||||||
|
state.mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
|
||||||
|
state.mv.visitLdcInsn(index + 1);
|
||||||
|
state.mv.visitJumpInsn(GOTO, start);
|
||||||
|
state.mv.visitLabel(cont);
|
||||||
|
} else if (pat instanceof TargetTypePattern sp) {
|
||||||
var local = state.createVariable(sp.name(), sp.type());
|
var local = state.createVariable(sp.name(), sp.type());
|
||||||
state.mv.visitVarInsn(ASTORE, local.index);
|
state.mv.visitVarInsn(ASTORE, local.index);
|
||||||
} else if (pat instanceof TargetComplexPattern cp) {
|
} else if (pat instanceof TargetComplexPattern cp) {
|
||||||
@@ -1446,10 +1480,27 @@ public class Codegen {
|
|||||||
// TODO Check if class is a Record
|
// TODO Check if class is a Record
|
||||||
|
|
||||||
for (var i = 0; i < cp.subPatterns().size(); i++) {
|
for (var i = 0; i < cp.subPatterns().size(); i++) {
|
||||||
state.mv.visitInsn(DUP);
|
|
||||||
|
|
||||||
var subPattern = cp.subPatterns().get(i);
|
var subPattern = cp.subPatterns().get(i);
|
||||||
|
|
||||||
|
state.mv.visitInsn(DUP);
|
||||||
extractField(state, cp.type(), i, clazz);
|
extractField(state, cp.type(), i, clazz);
|
||||||
|
|
||||||
|
if (subPattern.type() instanceof TargetRefType || subPattern.type() instanceof TargetExtendsWildcard) {
|
||||||
|
state.mv.visitInsn(DUP);
|
||||||
|
state.mv.visitTypeInsn(INSTANCEOF, subPattern.type().getInternalName());
|
||||||
|
|
||||||
|
var cont = new Label();
|
||||||
|
state.mv.visitJumpInsn(IFNE, cont);
|
||||||
|
for (var j = 0; j < depth + 1; j++) {
|
||||||
|
state.mv.visitInsn(POP);
|
||||||
|
}
|
||||||
|
|
||||||
|
state.mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
|
||||||
|
state.mv.visitLdcInsn(index + 1);
|
||||||
|
state.mv.visitJumpInsn(GOTO, start);
|
||||||
|
state.mv.visitLabel(cont);
|
||||||
|
}
|
||||||
|
|
||||||
bindPattern(state, subPattern.type(), subPattern, start, index, depth + 1);
|
bindPattern(state, subPattern.type(), subPattern, start, index, depth + 1);
|
||||||
}
|
}
|
||||||
state.mv.visitInsn(POP);
|
state.mv.visitInsn(POP);
|
||||||
@@ -1484,7 +1535,7 @@ public class Codegen {
|
|||||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
|
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|
||||||
var state = new State(null, mv, 0);
|
var state = new State(null, mv, 0, true);
|
||||||
generate(state, constructor.block());
|
generate(state, constructor.block());
|
||||||
|
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
@@ -1498,7 +1549,7 @@ public class Codegen {
|
|||||||
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature()));
|
||||||
|
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(null, mv, 1);
|
var state = new State(null, mv, 1, false);
|
||||||
for (var param : constructor.parameters()) {
|
for (var param : constructor.parameters()) {
|
||||||
var pattern = param.pattern();
|
var pattern = param.pattern();
|
||||||
if (pattern instanceof TargetTypePattern tp)
|
if (pattern instanceof TargetTypePattern tp)
|
||||||
@@ -1535,7 +1586,8 @@ public class Codegen {
|
|||||||
state.mv.visitInsn(DUP);
|
state.mv.visitInsn(DUP);
|
||||||
|
|
||||||
extractField(state, cp.type(), i, clazz);
|
extractField(state, cp.type(), i, clazz);
|
||||||
state.mv.visitTypeInsn(CHECKCAST, subPattern.type().getInternalName());
|
if (subPattern.type() instanceof TargetRefType)
|
||||||
|
state.mv.visitTypeInsn(CHECKCAST, subPattern.type().getInternalName());
|
||||||
offset = state.createVariable(subPattern.name(), subPattern.type()).index;
|
offset = state.createVariable(subPattern.name(), subPattern.type()).index;
|
||||||
state.mv.visitVarInsn(ASTORE, offset);
|
state.mv.visitVarInsn(ASTORE, offset);
|
||||||
if (subPattern instanceof TargetComplexPattern cp2) {
|
if (subPattern instanceof TargetComplexPattern cp2) {
|
||||||
@@ -1543,9 +1595,31 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateMethod(TargetMethod method) {
|
private void generateMethod(TargetMethod method) {
|
||||||
|
generateMethod(method, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateMainMethod() {
|
||||||
|
var mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitMethodInsn(INVOKESTATIC, "java/util/List", "of", "([Ljava/lang/Object;)Ljava/util/List;", true);
|
||||||
|
mv.visitMethodInsn(INVOKESTATIC, className, "main", "(Ljava/util/List;)V", false);
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(0, 0);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateMethod(TargetMethod method, State parent) {
|
||||||
var access = method.access();
|
var access = method.access();
|
||||||
|
|
||||||
|
var params = method.signature().parameters();
|
||||||
|
if (method.name().equals("main") && method.isStatic() && params.size() == 1 &&
|
||||||
|
params.getFirst().pattern().type().equals(new TargetRefType("java.util.List", List.of(new TargetRefType("java.lang.String"))))) {
|
||||||
|
|
||||||
|
generateMainMethod();
|
||||||
|
}
|
||||||
|
|
||||||
if (method.block() == null)
|
if (method.block() == null)
|
||||||
access |= ACC_ABSTRACT;
|
access |= ACC_ABSTRACT;
|
||||||
if (clazz instanceof TargetInterface)
|
if (clazz instanceof TargetInterface)
|
||||||
@@ -1559,7 +1633,10 @@ public class Codegen {
|
|||||||
|
|
||||||
if (method.block() != null) {
|
if (method.block() != null) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(method.signature().returnType(), mv, method.isStatic() ? 0 : 1);
|
var state = new State(method.signature().returnType(), mv, method.isStatic() ? 0 : 1, method.isStatic());
|
||||||
|
if (parent != null) {
|
||||||
|
state.scope.parent = parent.scope;
|
||||||
|
}
|
||||||
var offset = 1;
|
var offset = 1;
|
||||||
for (var param : method.signature().parameters()) {
|
for (var param : method.signature().parameters()) {
|
||||||
state.createVariable(param.pattern().name(), param.pattern().type());
|
state.createVariable(param.pattern().name(), param.pattern().type());
|
||||||
@@ -1569,6 +1646,8 @@ public class Codegen {
|
|||||||
bindLocalVariables(state, cp, offset);
|
bindLocalVariables(state, cp, offset);
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
//if (parent != null) System.out.println("parent: " + parent.scope.locals.keySet());
|
||||||
|
//System.out.println(state.scope.locals.keySet());
|
||||||
generate(state, method.block());
|
generate(state, method.block());
|
||||||
if (method.signature().returnType() == null)
|
if (method.signature().returnType() == null)
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
@@ -1675,7 +1754,7 @@ public class Codegen {
|
|||||||
|
|
||||||
// Generate wrapper method
|
// Generate wrapper method
|
||||||
var mv = cw2.visitMethod(ACC_PUBLIC, toMethod.name, toDescriptor, null, null);
|
var mv = cw2.visitMethod(ACC_PUBLIC, toMethod.name, toDescriptor, null, null);
|
||||||
var state = new State(null, mv, 0);
|
var state = new State(null, mv, 0, false);
|
||||||
|
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
mv.visitFieldInsn(GETFIELD, className, "wrapped", pair.from.toDescriptor());
|
mv.visitFieldInsn(GETFIELD, className, "wrapped", pair.from.toDescriptor());
|
||||||
@@ -1699,7 +1778,7 @@ public class Codegen {
|
|||||||
|
|
||||||
cw2.visitEnd();
|
cw2.visitEnd();
|
||||||
var bytes = cw2.toByteArray();
|
var bytes = cw2.toByteArray();
|
||||||
converter.auxiliaries.put(className, bytes);
|
compiler.auxiliaries.put(className, bytes);
|
||||||
|
|
||||||
// TODO These class loading shenanigans happen in a few places, the tests load the classes individually.
|
// TODO These class loading shenanigans happen in a few places, the tests load the classes individually.
|
||||||
// Instead we should just look at the folder.
|
// Instead we should just look at the folder.
|
||||||
@@ -1707,7 +1786,7 @@ public class Codegen {
|
|||||||
converter.classLoader.findClass(className);
|
converter.classLoader.findClass(className);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
try {
|
try {
|
||||||
converter.classLoader.loadClass(bytes);
|
converter.classLoader.loadClass(className, bytes);
|
||||||
} catch (LinkageError ignored) {}
|
} catch (LinkageError ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,10 @@ public class FunNGenerator {
|
|||||||
public final List<TargetType> inParams;
|
public final List<TargetType> inParams;
|
||||||
public final List<TargetType> realParams;
|
public final List<TargetType> realParams;
|
||||||
|
|
||||||
|
public GenericParameters(TargetFunNType funNType) {
|
||||||
|
this(funNType.funNParams(), funNType.returnArguments());
|
||||||
|
}
|
||||||
|
|
||||||
public GenericParameters(List<TargetType> params, int numReturns) {
|
public GenericParameters(List<TargetType> params, int numReturns) {
|
||||||
this.realParams = params;
|
this.realParams = params;
|
||||||
this.inParams = flattenTypeParams(params);
|
this.inParams = flattenTypeParams(params);
|
||||||
|
@@ -2,9 +2,11 @@
|
|||||||
package de.dhbwstuttgart.core;
|
package de.dhbwstuttgart.core;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Codegen;
|
import de.dhbwstuttgart.bytecode.Codegen;
|
||||||
|
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||||
@@ -73,6 +75,11 @@ public class JavaTXCompiler {
|
|||||||
public final List<File> classPath;
|
public final List<File> classPath;
|
||||||
private final File outputPath;
|
private final File outputPath;
|
||||||
|
|
||||||
|
public final Map<String, FunNGenerator.GenericParameters> usedFunN = new HashMap<>();
|
||||||
|
public final Set<Integer> usedFunNSuperTypes = new HashSet<>();
|
||||||
|
|
||||||
|
public Map<String, byte[]> auxiliaries = new HashMap<>();
|
||||||
|
|
||||||
public DirectoryClassLoader getClassLoader() {
|
public DirectoryClassLoader getClassLoader() {
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
@@ -393,7 +400,12 @@ public class JavaTXCompiler {
|
|||||||
logFile.write(ASTTypePrinter.print(sf));
|
logFile.write(ASTTypePrinter.print(sf));
|
||||||
System.out.println(ASTTypePrinter.print(sf));
|
System.out.println(ASTTypePrinter.print(sf));
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
List<UnifyPair> andConstraintsSorted = unifyCons.getUndConstraints().stream()
|
||||||
|
.sorted(Comparator.comparing(UnifyPair::getPairOp).thenComparing(UnifyPair::getLhsType, Comparator.comparing(UnifyType::getName)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
System.out.println(andConstraintsSorted);
|
||||||
|
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
@@ -416,7 +428,14 @@ public class JavaTXCompiler {
|
|||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
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("RESULT Final: " + li.getResults());
|
||||||
|
var finalResults = li.getResults().stream().sorted().toList();
|
||||||
|
int i = 0;
|
||||||
|
System.out.println("RESULT Final: ");
|
||||||
|
for (var result : finalResults){
|
||||||
|
System.out.println("Result: " + i++);
|
||||||
|
System.out.println(result.getSortedResults());
|
||||||
|
}
|
||||||
System.out.println("Constraints for Generated Generics: " + " ???");
|
System.out.println("Constraints for Generated Generics: " + " ???");
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
@@ -457,6 +476,85 @@ public class JavaTXCompiler {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TEMPORARY - Only for Language Server Usage
|
||||||
|
*/
|
||||||
|
public LanguageServerTransferObject getResultSetAndAbstractSyntax(File file) throws IOException, ClassNotFoundException {
|
||||||
|
var sf = sourceFiles.get(file);
|
||||||
|
if(sf == null){
|
||||||
|
sf = sourceFiles.values().stream().findFirst().get();
|
||||||
|
}
|
||||||
|
Set<ClassOrInterface> allClasses = new HashSet<>();
|
||||||
|
allClasses.addAll(getAvailableClasses(sf));
|
||||||
|
allClasses.addAll(sf.getClasses());
|
||||||
|
var newClasses = CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), file, this).stream().map(ASTFactory::createClass).collect(Collectors.toSet());
|
||||||
|
for (var clazz : newClasses) {
|
||||||
|
// Don't load classes that get recompiled
|
||||||
|
if (sf.getClasses().stream().anyMatch(nf -> nf.getClassName().equals(clazz.getClassName())))
|
||||||
|
continue;
|
||||||
|
if (allClasses.stream().noneMatch(old -> old.getClassName().equals(clazz.getClassName())))
|
||||||
|
allClasses.add(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
final ConstraintSet<Pair> cons = getConstraints(file);
|
||||||
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
|
try {
|
||||||
|
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||||
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses.stream().toList(), logFile, classLoader, this);
|
||||||
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
||||||
|
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
||||||
|
UnifyType lhs, rhs;
|
||||||
|
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;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
unifyCons = unifyCons.map(distributeInnerVars);
|
||||||
|
TypeUnify unify = new TypeUnify();
|
||||||
|
Set<PlaceholderType> varianceTPHold;
|
||||||
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
|
|
||||||
|
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints();
|
||||||
|
|
||||||
|
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);
|
||||||
|
generateBytecode(sf, li.getResults());
|
||||||
|
return new LanguageServerTransferObject(li.getResults(), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||||
|
}
|
||||||
|
/* UnifyResultModel End */
|
||||||
|
else {
|
||||||
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
||||||
|
results.addAll(result);
|
||||||
|
|
||||||
|
results = results.stream().map(x -> {
|
||||||
|
Optional<Set<UnifyPair>> 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));
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
}
|
||||||
|
generateBytecode(sf, results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()));
|
||||||
|
return new LanguageServerTransferObject(results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
@@ -631,12 +729,12 @@ public class JavaTXCompiler {
|
|||||||
var codegen = new Codegen(converter.convert(clazz), this, converter);
|
var codegen = new Codegen(converter.convert(clazz), this, converter);
|
||||||
var code = codegen.generate();
|
var code = codegen.generate();
|
||||||
generatedClasses.put(clazz.getClassName(), code);
|
generatedClasses.put(clazz.getClassName(), code);
|
||||||
converter.auxiliaries.forEach((name, source) -> {
|
|
||||||
generatedClasses.put(new JavaClassName(name), source);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
generatedGenerics.put(sf, converter.javaGenerics());
|
generatedGenerics.put(sf, converter.javaGenerics());
|
||||||
converter.generateFunNTypes();
|
converter.generateFunNTypes();
|
||||||
|
auxiliaries.forEach((name, source) -> {
|
||||||
|
generatedClasses.put(new JavaClassName(name), source);
|
||||||
|
});
|
||||||
return generatedClasses;
|
return generatedClasses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
package de.dhbwstuttgart.environment;
|
|
||||||
|
|
||||||
public class ByteArrayClassLoader extends ClassLoader implements IByteArrayClassLoader {
|
|
||||||
@Override
|
|
||||||
public Class _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError {
|
|
||||||
return defineClass(name, code, i, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
return super.findClass(name);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -30,7 +30,7 @@ public class CompilationEnvironment {
|
|||||||
public final PackageCrawler packageCrawler;
|
public final PackageCrawler packageCrawler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imitiert die Environment beim Aufruf des JavaCompilers auf einer Menge von java-Dateien Die Environment enth<EFBFBD>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
|
* @param sourceFiles die zu kompilierenden Dateien
|
||||||
*/
|
*/
|
||||||
|
@@ -6,18 +6,22 @@ import java.nio.file.Path;
|
|||||||
|
|
||||||
public interface IByteArrayClassLoader {
|
public interface IByteArrayClassLoader {
|
||||||
|
|
||||||
Class loadClass(String path) throws ClassNotFoundException;
|
Class<?> loadClass(String path) throws ClassNotFoundException;
|
||||||
|
|
||||||
default Class loadClass(byte[] code) {
|
default Class<?> loadClass(byte[] code) {
|
||||||
return this._defineClass(null, code, 0, code.length);
|
return this.loadClass(null, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
default Class loadClass(Path path) throws IOException {
|
default Class<?> loadClass(String name, byte[] code) {
|
||||||
|
return this._defineClass(name, code, 0, code.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Class<?> loadClass(Path path) throws IOException {
|
||||||
var code = Files.readAllBytes(path);
|
var code = Files.readAllBytes(path);
|
||||||
return this._defineClass(null, code, 0, code.length);
|
return this._defineClass(null, code, 0, code.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException;
|
public Class<?> findClass(String name) throws ClassNotFoundException;
|
||||||
|
|
||||||
Class _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError;
|
Class<?> _defineClass(String name, byte[] code, int i, int length) throws ClassFormatError;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,120 @@
|
|||||||
|
package de.dhbwstuttgart.languageServerInterface;
|
||||||
|
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.Codegen;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||||
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.target.tree.TargetStructure;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of an Interface for the Language-Server to get the Resultset and abstract Syntax.
|
||||||
|
*/
|
||||||
|
public class LanguageServerInterface {
|
||||||
|
|
||||||
|
|
||||||
|
public LanguageServerTransferObject getResultSetAndAbastractSyntax(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
|
NameGenerator.resetTo(resetNamesTo);
|
||||||
|
return getResultSetAndAbstractSyntax(path);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public SourceFile getAst(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||||
|
NameGenerator.resetTo(resetNamesTo);
|
||||||
|
return getAST(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the ResultSets, GenericResultSet and the AST
|
||||||
|
* You have to give the input as well as the path because of potential locks when the File is currently opened in an IDE.
|
||||||
|
* Example: file:///c:/test/main.jav -> file:///c:/test/out/main.class
|
||||||
|
*
|
||||||
|
* @param pathAsString the URI of the File. See Example.
|
||||||
|
* @throws IOException
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @throws URISyntaxException
|
||||||
|
*/
|
||||||
|
public LanguageServerTransferObject getResultSetAndAbstractSyntax(String pathAsString) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
|
||||||
|
var uri = new URI(pathAsString);
|
||||||
|
var path = Path.of(uri);
|
||||||
|
var file = path.toFile();
|
||||||
|
Files.createDirectories(path.getParent().resolve("out"));
|
||||||
|
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile());
|
||||||
|
|
||||||
|
var parsedSource = compiler.sourceFiles.get(file);
|
||||||
|
var tiResults = compiler.typeInference(file);
|
||||||
|
|
||||||
|
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(parsedSource, tiResults);
|
||||||
|
Files.createDirectories(path.getParent().resolve("out"));
|
||||||
|
compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
|
||||||
|
|
||||||
|
return new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the AST without calculating the result
|
||||||
|
* You have to give the input as well as the path because of potential locks when the File is currently opened in an IDE.
|
||||||
|
* Example: file:///c:/test/main.jav -> file:///c:/test/out/main.class
|
||||||
|
*
|
||||||
|
* @param path the URI of the File. See Example.
|
||||||
|
* @throws IOException
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @throws URISyntaxException
|
||||||
|
*/
|
||||||
|
public SourceFile getAST(String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||||
|
|
||||||
|
|
||||||
|
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||||
|
|
||||||
|
|
||||||
|
URI uri = new URI(path);
|
||||||
|
ArrayList<String> pathWithoutName = new ArrayList<>(List.of(uri.getPath().split("/")));
|
||||||
|
pathWithoutName.remove(List.of(uri.getPath().split("/")).size() - 1);
|
||||||
|
String stringPathWithoutName = "";
|
||||||
|
|
||||||
|
for (String i : pathWithoutName) {
|
||||||
|
stringPathWithoutName += "/" + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
FileUtils.cleanDirectory(new File(stringPathWithoutName + "/out"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
(new File(stringPathWithoutName + "/out")).mkdirs();
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
var test = getAST(uri.getPath().split("/")[uri.getPath().split("/").length - 1], new File(stringPathWithoutName).getPath());
|
||||||
|
System.setOut(System.out);
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SourceFile getAST(String filename, String filePath) throws IOException, ClassNotFoundException {
|
||||||
|
var file = Path.of(filePath, filename).toFile();
|
||||||
|
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()), Path.of(filePath + "/out").toFile());
|
||||||
|
return compiler.sourceFiles.get(file);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package de.dhbwstuttgart.languageServerInterface;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.model.CustomParserErrorHandler;
|
||||||
|
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Lexer;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java17ParserBaseListener;
|
||||||
|
import org.antlr.v4.runtime.CharStream;
|
||||||
|
import org.antlr.v4.runtime.CharStreams;
|
||||||
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ParserInterface {
|
||||||
|
|
||||||
|
public List<ParserError> getParseErrors(String input){
|
||||||
|
|
||||||
|
CustomParserErrorHandler errorListener = new CustomParserErrorHandler();
|
||||||
|
CharStream charStream = CharStreams.fromString(input);
|
||||||
|
|
||||||
|
Java17Lexer lexer = new Java17Lexer(charStream);
|
||||||
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
|
|
||||||
|
Java17Parser parser = new Java17Parser(tokens);
|
||||||
|
parser.removeErrorListeners();
|
||||||
|
parser.addErrorListener(errorListener);
|
||||||
|
|
||||||
|
|
||||||
|
ParseTree tree = parser.sourceFile();
|
||||||
|
ParseTreeWalker walker = new ParseTreeWalker();
|
||||||
|
Java17ParserBaseListener listener = new Java17ParserBaseListener();
|
||||||
|
walker.walk(listener, tree);
|
||||||
|
|
||||||
|
return errorListener.getErrorMessages();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,47 @@
|
|||||||
|
package de.dhbwstuttgart.languageServerInterface.model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.*;
|
||||||
|
import org.antlr.v4.runtime.atn.ATNConfigSet;
|
||||||
|
import org.antlr.v4.runtime.dfa.DFA;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.BitSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CustomParserErrorHandler implements ANTLRErrorListener {
|
||||||
|
private final List<ParserError> errorMessages = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
|
||||||
|
int endCharPosition = charPositionInLine;
|
||||||
|
if (offendingSymbol instanceof Token) {
|
||||||
|
Token offendingToken = (Token) offendingSymbol;
|
||||||
|
endCharPosition = charPositionInLine + offendingToken.getText().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
ParserError parserError = new ParserError(line, charPositionInLine, endCharPosition, msg);
|
||||||
|
errorMessages.add(parserError);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reportAmbiguity(Parser parser, DFA dfa, int i, int i1, boolean b, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reportAttemptingFullContext(Parser parser, DFA dfa, int i, int i1, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reportContextSensitivity(Parser parser, DFA dfa, int i, int i1, int i2, ATNConfigSet atnConfigSet) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ParserError> getErrorMessages() {
|
||||||
|
return errorMessages;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
package de.dhbwstuttgart.languageServerInterface.model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class LanguageServerTransferObject {
|
||||||
|
List<ResultSet> resultSets;
|
||||||
|
SourceFile Ast;
|
||||||
|
String printedAst;
|
||||||
|
Map<SourceFile, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
public LanguageServerTransferObject(List<ResultSet> resultSets, SourceFile Ast, String printedAst, Map<SourceFile, List<GenericsResult>> generatedGenerics) {
|
||||||
|
this.resultSets = resultSets;
|
||||||
|
this.Ast = Ast;
|
||||||
|
this.printedAst = printedAst;
|
||||||
|
this.generatedGenerics = generatedGenerics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ResultSet> getResultSets() {return resultSets;}
|
||||||
|
public SourceFile getAst() {return Ast;}
|
||||||
|
public String getPrintedAst() {return printedAst;}
|
||||||
|
public Map<SourceFile, List<GenericsResult>> getGeneratedGenerics() {return generatedGenerics;}
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
package de.dhbwstuttgart.languageServerInterface.model;
|
||||||
|
|
||||||
|
public class ParserError {
|
||||||
|
|
||||||
|
private int line;
|
||||||
|
private int charPositionInLine;
|
||||||
|
private int endCharPosition;
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
public ParserError(int line, int charPositionInLine, int endCharPosition, String msg) {
|
||||||
|
this.line = line;
|
||||||
|
this.charPositionInLine = charPositionInLine;
|
||||||
|
this. endCharPosition = endCharPosition;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndCharPosition() {
|
||||||
|
return endCharPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndCharPosition(int endCharPosition) {
|
||||||
|
this.endCharPosition = endCharPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharPositionInLine(int charPositionInLine) {
|
||||||
|
this.charPositionInLine = charPositionInLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLine(int line) {
|
||||||
|
this.line = line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCharPositionInLine() {
|
||||||
|
return charPositionInLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLine() {
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,20 @@
|
|||||||
|
package de.dhbwstuttgart.languageServerInterface.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.common.reflect.TypeResolver;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultEvent;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
||||||
|
|
||||||
|
public class ResultSetListener implements UnifyResultListener {
|
||||||
|
|
||||||
|
TypeResolver typeResolver;
|
||||||
|
|
||||||
|
public ResultSetListener(TypeResolver typeResolver){
|
||||||
|
this.typeResolver = typeResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNewTypeResultFound(UnifyResultEvent evt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -150,10 +150,10 @@ public class StatementGenerator {
|
|||||||
} else {
|
} else {
|
||||||
type = methodparameters?
|
type = methodparameters?
|
||||||
TypePlaceholder.fresh(fp.getStart(), 1, false)
|
TypePlaceholder.fresh(fp.getStart(), 1, false)
|
||||||
: TypePlaceholder.fresh(fp.getStart());
|
: TypePlaceholder.fresh(fp.getStart(), 1, false);
|
||||||
}
|
}
|
||||||
ret.add(new FormalParameter(paramName, type, fp.getStart()));
|
ret.add(new FormalParameter(paramName, type, fp.getStart()));
|
||||||
localVars.put(paramName, type);
|
localVars.put(paramName, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ParameterList(ret, ret.get(0).getOffset());
|
return new ParameterList(ret, ret.get(0).getOffset());
|
||||||
@@ -468,7 +468,7 @@ public class StatementGenerator {
|
|||||||
case RPatternContext rPattern:
|
case RPatternContext rPattern:
|
||||||
RecordPatternContext recordPattern = rPattern.recordPattern();
|
RecordPatternContext recordPattern = rPattern.recordPattern();
|
||||||
return convert(recordPattern);
|
return convert(recordPattern);
|
||||||
case Java17Parser.LPatternContext patternContext: return new LiteralPattern(TypePlaceholder.fresh(patternContext.start), patternContext.literal().get(0).getText(), patternContext.start);
|
case Java17Parser.LPatternContext patternContext: return new LiteralPattern(TypePlaceholder.fresh(patternContext.start), convert(patternContext.literal().get(0)), patternContext.start);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@@ -477,7 +477,8 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private RecordPattern convert(RecordPatternContext recordPatternCtx) {
|
private RecordPattern convert(RecordPatternContext recordPatternCtx) {
|
||||||
List<PatternContext> subPatternCtx = recordPatternCtx.recordStructurePattern().recordComponentPatternList().pattern();
|
var cpl = recordPatternCtx.recordStructurePattern().recordComponentPatternList();
|
||||||
|
List<PatternContext> subPatternCtx = cpl == null ? List.of() : cpl.pattern();
|
||||||
List<Pattern> subPattern = subPatternCtx.stream().map(this::convert).collect(Collectors.toList());
|
List<Pattern> subPattern = subPatternCtx.stream().map(this::convert).collect(Collectors.toList());
|
||||||
IdentifierContext identifierCtx = recordPatternCtx.identifier();
|
IdentifierContext identifierCtx = recordPatternCtx.identifier();
|
||||||
var text = (identifierCtx != null) ? identifierCtx.getText() : null;
|
var text = (identifierCtx != null) ? identifierCtx.getText() : null;
|
||||||
@@ -1064,7 +1065,7 @@ public class StatementGenerator {
|
|||||||
List<Pattern> parameterList = new ArrayList<>();
|
List<Pattern> parameterList = new ArrayList<>();
|
||||||
for (IdentifierContext identifier : lambdaParams.identifier()) {
|
for (IdentifierContext identifier : lambdaParams.identifier()) {
|
||||||
Token offset = identifier.getStart();
|
Token offset = identifier.getStart();
|
||||||
parameterList.add(new FormalParameter(identifier.getText(), TypePlaceholder.fresh(offset), offset));
|
parameterList.add(new FormalParameter(identifier.getText(), TypePlaceholder.fresh(offset, 1, false), offset));
|
||||||
}
|
}
|
||||||
params = new ParameterList(parameterList, lambdaParams.getStart());
|
params = new ParameterList(parameterList, lambdaParams.getStart());
|
||||||
} else if (lambdaParams.formalParameterList() != null) {
|
} else if (lambdaParams.formalParameterList() != null) {
|
||||||
@@ -1074,7 +1075,7 @@ public class StatementGenerator {
|
|||||||
List<Pattern> parameterList = new ArrayList<>();
|
List<Pattern> parameterList = new ArrayList<>();
|
||||||
for (LambdaLVTIParameterContext param : lambdaParams.lambdaLVTIList().lambdaLVTIParameter()) {
|
for (LambdaLVTIParameterContext param : lambdaParams.lambdaLVTIList().lambdaLVTIParameter()) {
|
||||||
Token offset = param.getStart();
|
Token offset = param.getStart();
|
||||||
parameterList.add(new FormalParameter(param.identifier().getText(), TypePlaceholder.fresh(offset), offset));
|
parameterList.add(new FormalParameter(param.identifier().getText(), TypePlaceholder.fresh(offset, 1, false), offset));
|
||||||
}
|
}
|
||||||
params = new ParameterList(parameterList, lambdaParams.getStart());
|
params = new ParameterList(parameterList, lambdaParams.getStart());
|
||||||
} else {
|
} else {
|
||||||
@@ -1098,9 +1099,9 @@ public class StatementGenerator {
|
|||||||
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
||||||
}
|
}
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
|
||||||
funNParams.add(TypePlaceholder.fresh(expression.getStart()));// ret-Type
|
funNParams.add(TypePlaceholder.fresh(expression.getStart(), -1, false));// ret-Type
|
||||||
params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen:
|
params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen:
|
||||||
funNParams.add(TypePlaceholder.fresh(expression.getStart())));
|
funNParams.add(TypePlaceholder.fresh(expression.getStart(), 1, false)));
|
||||||
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
|
||||||
// RefType lambdaType = new
|
// RefType lambdaType = new
|
||||||
// RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
// RefType(reg.getName("Fun"+params.getFormalparalist().size()),
|
||||||
|
@@ -41,7 +41,7 @@ public class JavaClassName {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt von einem Klassennamen nur den Namen der Klasse zur<EFBFBD>ck
|
* Gibt von einem Klassennamen nur den Namen der Klasse zurück
|
||||||
* Beispiel:
|
* Beispiel:
|
||||||
* java.lang.Object wird zu: Object
|
* java.lang.Object wird zu: Object
|
||||||
*/
|
*/
|
||||||
|
@@ -5,9 +5,9 @@ import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Speichert die Klassen f<EFBFBD>r einen bestimmten Projektscope
|
* Speichert die Klassen für einen bestimmten Projektscope
|
||||||
*/
|
*/
|
||||||
public class JavaClassRegistry {
|
public class JavaClassRegistry{
|
||||||
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
final Map<JavaClassName, Integer> existingClasses = new HashMap<>();
|
||||||
|
|
||||||
public JavaClassRegistry(Map<String, Integer> initialNames) {
|
public JavaClassRegistry(Map<String, Integer> initialNames) {
|
||||||
@@ -22,6 +22,10 @@ public class JavaClassRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<JavaClassName> getAllClassNames(){
|
||||||
|
return existingClasses.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
public void addName(String className, int numberOfGenerics) {
|
public void addName(String className, int numberOfGenerics) {
|
||||||
existingClasses.put(new JavaClassName(className), numberOfGenerics);
|
existingClasses.put(new JavaClassName(className), numberOfGenerics);
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,8 @@ public interface ASTVisitor extends StatementVisitor{
|
|||||||
|
|
||||||
void visit(FormalParameter formalParameter);
|
void visit(FormalParameter formalParameter);
|
||||||
|
|
||||||
|
void visit(LiteralPattern literalPattern);
|
||||||
|
|
||||||
void visit(GenericDeclarationList genericTypeVars);
|
void visit(GenericDeclarationList genericTypeVars);
|
||||||
|
|
||||||
void visit(Field field);
|
void visit(Field field);
|
||||||
|
@@ -37,6 +37,11 @@ public abstract class AbstractASTWalker implements ASTVisitor {
|
|||||||
formalParameter.getType().accept((ASTVisitor) this);
|
formalParameter.getType().accept((ASTVisitor) this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LiteralPattern literalPattern) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(GenericDeclarationList genericTypeVars) {
|
public void visit(GenericDeclarationList genericTypeVars) {
|
||||||
Iterator<GenericTypeVar> genericIterator = genericTypeVars.iterator();
|
Iterator<GenericTypeVar> genericIterator = genericTypeVars.iterator();
|
||||||
|
@@ -6,10 +6,12 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.target.tree.TargetGeneric;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||||
@@ -31,6 +33,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
private List<RefType> implementedInterfaces;
|
private List<RefType> implementedInterfaces;
|
||||||
private List<RefType> permittedSubtypes;
|
private List<RefType> permittedSubtypes;
|
||||||
private List<Constructor> constructors;
|
private List<Constructor> constructors;
|
||||||
|
private Set<GenericTypeVar> userDefinedGenerics;
|
||||||
|
|
||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, Optional<Constructor> fieldInitializations, Optional<Method> staticInitializer, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters, RefType superClass, Boolean isInterface, Boolean isFunctionalInterface, List<RefType> implementedInterfaces, List<RefType> permittedSubtypes, Token offset, String fileName) {
|
||||||
super(offset);
|
super(offset);
|
||||||
@@ -199,4 +202,22 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(name);
|
return Objects.hash(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<GenericTypeVar> getUserDefinedGenerics() {
|
||||||
|
if (this.userDefinedGenerics != null) return this.userDefinedGenerics;
|
||||||
|
|
||||||
|
var genericsIter = getGenerics().iterator();
|
||||||
|
if (genericsIter.hasNext()) {
|
||||||
|
// Add empty set of generics to cache so that it doesn't try to calculate it later
|
||||||
|
this.userDefinedGenerics = new HashSet<>();
|
||||||
|
while (genericsIter.hasNext()) {
|
||||||
|
var next = genericsIter.next();
|
||||||
|
userDefinedGenerics.add(next);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.userDefinedGenerics = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.userDefinedGenerics;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,15 +12,15 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
public class LiteralPattern extends FormalParameter
|
public class LiteralPattern extends FormalParameter
|
||||||
{
|
{
|
||||||
public final Object value;
|
public final Expression value;
|
||||||
public LiteralPattern(RefTypeOrTPHOrWildcardOrGeneric type, Object value, Token offset) {
|
public LiteralPattern(RefTypeOrTPHOrWildcardOrGeneric type, Expression value, Token offset) {
|
||||||
super((String) value, type, offset);
|
super(null, type, offset);
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public FormalParameter withType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
public FormalParameter withType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
return null;
|
return new LiteralPattern(type, value, getOffset());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void accept(ASTVisitor visitor) {
|
public void accept(ASTVisitor visitor) {
|
||||||
|
@@ -5,8 +5,10 @@ import java.util.*;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
//import sun.security.x509.X509CertInfo;
|
//import sun.security.x509.X509CertInfo;
|
||||||
|
|
||||||
public class SourceFile extends SyntaxTreeNode {
|
public class SourceFile extends SyntaxTreeNode {
|
||||||
@@ -18,6 +20,7 @@ public class SourceFile extends SyntaxTreeNode {
|
|||||||
private boolean isGenerated;
|
private boolean isGenerated;
|
||||||
|
|
||||||
public List<ClassOrInterface> availableClasses = new ArrayList<>();
|
public List<ClassOrInterface> availableClasses = new ArrayList<>();
|
||||||
|
public List<ASTToTargetAST.Generics> generics = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
||||||
@@ -40,6 +43,10 @@ public class SourceFile extends SyntaxTreeNode {
|
|||||||
this.imports = new HashSet<>(sf.imports);
|
this.imports = new HashSet<>(sf.imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addResultSet(ResultSet rs) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void setPackageName(String packageName) {
|
public void setPackageName(String packageName) {
|
||||||
this.pkgName = packageName;
|
this.pkgName = packageName;
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,6 @@ public class ASTFactory {
|
|||||||
private static final HashMap<java.lang.Class, ClassOrInterface> cache = new HashMap<>();
|
private static final HashMap<java.lang.Class, ClassOrInterface> cache = new HashMap<>();
|
||||||
|
|
||||||
public static ClassOrInterface createClass(java.lang.Class jreClass) {
|
public static ClassOrInterface createClass(java.lang.Class jreClass) {
|
||||||
System.out.println(jreClass);
|
|
||||||
if (cache.containsKey(jreClass))
|
if (cache.containsKey(jreClass))
|
||||||
return cache.get(jreClass);
|
return cache.get(jreClass);
|
||||||
|
|
||||||
@@ -174,12 +173,12 @@ public class ASTFactory {
|
|||||||
superClass = (RefType) createType(java.lang.Object.class);
|
superClass = (RefType) createType(java.lang.Object.class);
|
||||||
}
|
}
|
||||||
List<RefType> implementedInterfaces = new ArrayList<>();
|
List<RefType> implementedInterfaces = new ArrayList<>();
|
||||||
System.out.println(jreClass);
|
|
||||||
for (Type jreInterface : jreClass.getGenericInterfaces()) {
|
for (Type jreInterface : jreClass.getGenericInterfaces()) {
|
||||||
implementedInterfaces.add((RefType) createType(jreInterface));
|
implementedInterfaces.add((RefType) createType(jreInterface));
|
||||||
}
|
}
|
||||||
List<RefType> permittedSubtypes = new ArrayList<>();
|
List<RefType> permittedSubtypes = null;
|
||||||
if (jreClass.isSealed()) {
|
if (jreClass.isSealed()) {
|
||||||
|
permittedSubtypes = new ArrayList<>();
|
||||||
for (Class subclass : jreClass.getPermittedSubclasses()) {
|
for (Class subclass : jreClass.getPermittedSubclasses()) {
|
||||||
permittedSubtypes.add((RefType) createType(subclass));
|
permittedSubtypes.add((RefType) createType(subclass));
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,10 @@ public class NameGenerator {
|
|||||||
public static void reset() {
|
public static void reset() {
|
||||||
strNextName = "A";
|
strNextName = "A";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void resetTo(String name) {
|
||||||
|
strNextName = name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
||||||
|
@@ -57,6 +57,11 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
out.append(formalParameter.getName());
|
out.append(formalParameter.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LiteralPattern literalPattern) {
|
||||||
|
literalPattern.value.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(GenericDeclarationList genericTypeVars) {
|
public void visit(GenericDeclarationList genericTypeVars) {
|
||||||
Iterator<GenericTypeVar> genericIterator = genericTypeVars.iterator();
|
Iterator<GenericTypeVar> genericIterator = genericTypeVars.iterator();
|
||||||
@@ -508,12 +513,11 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
aRecordPattern.getType().accept(this);
|
aRecordPattern.getType().accept(this);
|
||||||
out.append("(");
|
out.append("(");
|
||||||
List<Pattern> subPatterns = aRecordPattern.getSubPattern();
|
List<Pattern> subPatterns = aRecordPattern.getSubPattern();
|
||||||
int i;
|
for (var i = 0; i < subPatterns.size(); i++) {
|
||||||
for (i = 0; i < subPatterns.size() - 1; i++) {
|
|
||||||
subPatterns.get(i).accept(this);
|
subPatterns.get(i).accept(this);
|
||||||
out.append(", ");
|
if (i < subPatterns.size() - 1)
|
||||||
|
out.append(", ");
|
||||||
}
|
}
|
||||||
subPatterns.get(i).accept(this);
|
|
||||||
String name;
|
String name;
|
||||||
if ((name = aRecordPattern.getName()) != null)
|
if ((name = aRecordPattern.getName()) != null)
|
||||||
out.append(name);
|
out.append(name);
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
package de.dhbwstuttgart.target.generate;
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.CodeGenException;
|
|
||||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
|
||||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||||
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
@@ -12,12 +12,13 @@ import de.dhbwstuttgart.syntaxtree.Record;
|
|||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator;
|
||||||
import de.dhbwstuttgart.target.tree.*;
|
import de.dhbwstuttgart.target.tree.*;
|
||||||
import de.dhbwstuttgart.target.tree.expression.*;
|
import de.dhbwstuttgart.target.tree.expression.*;
|
||||||
import de.dhbwstuttgart.target.tree.type.*;
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
import de.dhbwstuttgart.typeinference.result.*;
|
import de.dhbwstuttgart.typeinference.result.*;
|
||||||
|
|
||||||
import java.sql.Array;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -36,7 +37,6 @@ public class ASTToTargetAST {
|
|||||||
public Generics generics;
|
public Generics generics;
|
||||||
public List<Generics> currentMethodOverloads;
|
public List<Generics> currentMethodOverloads;
|
||||||
|
|
||||||
final Map<ClassOrInterface, Set<GenericTypeVar>> userDefinedGenerics = new HashMap<>();
|
|
||||||
final Map<Method, Set<SignaturePair>> tphsInMethods = new HashMap<>();
|
final Map<Method, Set<SignaturePair>> tphsInMethods = new HashMap<>();
|
||||||
private Method currentMethod;
|
private Method currentMethod;
|
||||||
|
|
||||||
@@ -61,17 +61,19 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public record Generics(JavaGenerics javaGenerics, TxGenerics txGenerics) {
|
public record Generics(JavaGenerics javaGenerics, TxGenerics txGenerics) {
|
||||||
|
public Generics(JavaTXCompiler compiler, ResultSet set) {
|
||||||
|
this(new JavaGenerics(compiler, set), new TxGenerics(compiler, set));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IByteArrayClassLoader classLoader;
|
public IByteArrayClassLoader classLoader;
|
||||||
protected SourceFile sourceFile;
|
protected SourceFile sourceFile;
|
||||||
|
|
||||||
public ASTToTargetAST(List<ResultSet> resultSets) {
|
public ASTToTargetAST(List<ResultSet> resultSets, IByteArrayClassLoader classLoader) {
|
||||||
this(null, resultSets);
|
this(null, resultSets, classLoader);
|
||||||
}
|
}
|
||||||
public ASTToTargetAST(JavaTXCompiler compiler, List<ResultSet> resultSets) {
|
public ASTToTargetAST(JavaTXCompiler compiler, List<ResultSet> resultSets, IByteArrayClassLoader classLoader) {
|
||||||
this(compiler, resultSets, null, new ByteArrayClassLoader());
|
this(compiler, resultSets, null, classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ASTToTargetAST(JavaTXCompiler compiler, List<ResultSet> resultSets, SourceFile sourceFile, IByteArrayClassLoader classLoader) {
|
public ASTToTargetAST(JavaTXCompiler compiler, List<ResultSet> resultSets, SourceFile sourceFile, IByteArrayClassLoader classLoader) {
|
||||||
@@ -81,9 +83,9 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
all = new ArrayList<>();
|
all = new ArrayList<>();
|
||||||
for (var set : resultSets) {
|
for (var set : resultSets) {
|
||||||
all.add(new Generics(new JavaGenerics(this, set), new TxGenerics(this, set)));
|
all.add(new Generics(compiler, set));
|
||||||
}
|
}
|
||||||
this.generics = all.get(0);
|
this.generics = all.getFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSignaturePair(TypePlaceholder signature, RefTypeOrTPHOrWildcardOrGeneric parameter) {
|
public void addSignaturePair(TypePlaceholder signature, RefTypeOrTPHOrWildcardOrGeneric parameter) {
|
||||||
@@ -93,9 +95,13 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList) {
|
Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList) {
|
||||||
|
return findMethod(owner, name, argumentList, this.generics.javaGenerics, this.compiler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<Method> findMethod(ClassOrInterface owner, String name, List<TargetType> argumentList, GenerateGenerics generics, JavaTXCompiler compiler) {
|
||||||
Optional<Method> method = Optional.empty();
|
Optional<Method> method = Optional.empty();
|
||||||
while (method.isEmpty()) {
|
while (method.isEmpty()) {
|
||||||
method = owner.getMethods().stream().filter(m -> m.name.equals(name) && parameterEquals(m.getParameterList(), argumentList)).findFirst();
|
method = owner.getMethods().stream().filter(m -> m.name.equals(name) && parameterEquals(m.getParameterList(), argumentList, generics)).findFirst();
|
||||||
if (owner.getClassName().toString().equals("java.lang.Object")) break;
|
if (owner.getClassName().toString().equals("java.lang.Object")) break;
|
||||||
owner = compiler.getClass(owner.getSuperClass().getName());
|
owner = compiler.getClass(owner.getSuperClass().getName());
|
||||||
}
|
}
|
||||||
@@ -103,16 +109,16 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Optional<Constructor> findConstructor(ClassOrInterface owner, List<TargetType> argumentList) {
|
Optional<Constructor> findConstructor(ClassOrInterface owner, List<TargetType> argumentList) {
|
||||||
return owner.getConstructors().stream().filter(c -> parameterEquals(c.getParameterList(), argumentList)).findFirst();
|
return owner.getConstructors().stream().filter(c -> parameterEquals(c.getParameterList(), argumentList, generics.javaGenerics)).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean parameterEquals(ParameterList parameterList, List<TargetType> arguments) {
|
static boolean parameterEquals(ParameterList parameterList, List<TargetType> arguments, GenerateGenerics generics) {
|
||||||
var pars = parameterList.getFormalparalist();
|
var pars = parameterList.getFormalparalist();
|
||||||
if (pars.size() != arguments.size())
|
if (pars.size() != arguments.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (var i = 0; i < pars.size(); i++) {
|
for (var i = 0; i < pars.size(); i++) {
|
||||||
var type1 = convert(pars.get(i).getType(), generics.javaGenerics);
|
var type1 = generics.getTargetType(pars.get(i).getType());
|
||||||
var type2 = arguments.get(i);
|
var type2 = arguments.get(i);
|
||||||
if (type1 instanceof TargetGenericType)
|
if (type1 instanceof TargetGenericType)
|
||||||
return true;
|
return true;
|
||||||
@@ -145,57 +151,219 @@ public class ASTToTargetAST {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<List<TargetMethod>> groupOverloads(ClassOrInterface input, List<Method> methods) {
|
// This finds a common sealed interface type to group together methods that use different records
|
||||||
var res = new ArrayList<List<TargetMethod>>();
|
private List<ClassOrInterface> commonSuperInterfaceTypes(TargetType a, TargetType b) {
|
||||||
for (var method : methods) {
|
if (a instanceof TargetGenericType && b instanceof TargetGenericType) return List.of(ASTFactory.createObjectClass());
|
||||||
// Convert all methods
|
if (a instanceof TargetRefType ta && b instanceof TargetGenericType)
|
||||||
var methodsWithTphs = convert(input, method);
|
return List.of(compiler.getClass(new JavaClassName(ta.name())));
|
||||||
// Then check for methods with the same signature
|
if (b instanceof TargetRefType tb && a instanceof TargetGenericType)
|
||||||
var mapOfSignatures = new HashMap<TargetMethod.Signature, List<MethodWithTphs>>();
|
return List.of(compiler.getClass(new JavaClassName(tb.name())));
|
||||||
for (var m : methodsWithTphs) {
|
|
||||||
var methodsWithSameSignature = mapOfSignatures.getOrDefault(m.method.signature(), new ArrayList<>());
|
|
||||||
methodsWithSameSignature.add(m);
|
|
||||||
mapOfSignatures.put(m.method.signature(), methodsWithSameSignature);
|
|
||||||
}
|
|
||||||
|
|
||||||
var resMethods = new HashSet<TargetMethod>();
|
if (a instanceof TargetRefType ta && b instanceof TargetRefType tb) {
|
||||||
for (var methodsWithSignature : mapOfSignatures.values()) {
|
var res = new HashSet<ClassOrInterface>();
|
||||||
outer: for (var m1 : methodsWithSignature) {
|
|
||||||
for (var m2 : methodsWithSignature) {
|
var cla = compiler.getClass(new JavaClassName(ta.name()));
|
||||||
for (var i = 0; i < m1.args.size(); i++) {
|
var clb = compiler.getClass(new JavaClassName(tb.name()));
|
||||||
var arg1 = m1.args.get(i);
|
|
||||||
var arg2 = m2.args.get(i);
|
if (cla.equals(clb)) return List.of(cla);
|
||||||
if (arg1.parameter.equals(arg2.parameter)) {
|
|
||||||
if (isSupertype(arg1.signature, arg2.signature) &&
|
while (!cla.equals(ASTFactory.createObjectClass())) {
|
||||||
!arg1.signature.equals(arg2.signature)) continue outer;
|
var clb2 = clb;
|
||||||
|
while (!clb2.equals(ASTFactory.createObjectClass())) {
|
||||||
|
for (var intfa : cla.getSuperInterfaces()) {
|
||||||
|
for (var intfb : clb.getSuperInterfaces()) {
|
||||||
|
if (intfa.equals(intfb)) {
|
||||||
|
var clintf = compiler.getClass(intfa.getName());
|
||||||
|
if (clintf.isSealed()) {
|
||||||
|
res.add(clintf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resMethods.add(m1.method);
|
clb2 = compiler.getClass(clb2.getSuperClass().getName());
|
||||||
|
}
|
||||||
|
cla = compiler.getClass(cla.getSuperClass().getName());
|
||||||
|
}
|
||||||
|
return res.stream().toList();
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO This is ugly and probably doesn't work right
|
||||||
|
private boolean patternStrictlyEquals(TargetComplexPattern a, TargetComplexPattern b) {
|
||||||
|
if (!a.name().equals(b.name())) return false;
|
||||||
|
if (a.subPatterns().size() != b.subPatterns().size()) return false;
|
||||||
|
for (var i = 0; i < a.subPatterns().size(); i++) {
|
||||||
|
var p1 = a.subPatterns().get(i);
|
||||||
|
var p2 = b.subPatterns().get(i);
|
||||||
|
if (p1 instanceof TargetComplexPattern pc1 && p2 instanceof TargetComplexPattern pc2 &&
|
||||||
|
patternStrictlyEquals(pc1, pc2)) return false;
|
||||||
|
if (p1 instanceof TargetTypePattern pt1 && p2 instanceof TargetTypePattern pt2) {
|
||||||
|
if (pt1.type() instanceof TargetGenericType && pt2.type() instanceof TargetGenericType) continue;
|
||||||
|
}
|
||||||
|
if (!p1.type().equals(p2.type()) && commonSuperInterfaceTypes(p1.type(), p2.type()).isEmpty()) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canCombine(TargetMethod m1, TargetMethod m2) {
|
||||||
|
if (!m1.name().equals(m2.name())) return false;
|
||||||
|
var s1 = m1.signature();
|
||||||
|
var s2 = m2.signature();
|
||||||
|
if (s1.parameters().size() != s2.parameters().size()) return false;
|
||||||
|
if (s1.parameters().isEmpty()) return false;
|
||||||
|
for (var i = 0; i < s1.parameters().size(); i++) {
|
||||||
|
var p1 = s1.parameters().get(i).pattern();
|
||||||
|
var p2 = s2.parameters().get(i).pattern();
|
||||||
|
if (p1.type() instanceof TargetGenericType || p2.type() instanceof TargetGenericType) continue;
|
||||||
|
if (p1 instanceof TargetComplexPattern pc1 && p2 instanceof TargetComplexPattern pc2 &&
|
||||||
|
patternStrictlyEquals(pc1, pc2)) return false;
|
||||||
|
if (!p1.equals(p2) && commonSuperInterfaceTypes(p1.type(), p2.type()).isEmpty()) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private record Combination(TargetMethod a, TargetMethod b) {
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof Combination(TargetMethod a1, TargetMethod b1))) return false;
|
||||||
|
return this.a.equals(a1) && this.b.equals(b1) ||
|
||||||
|
this.a.equals(b1) && this.b.equals(a1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(a) + Objects.hashCode(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<List<TargetMethod>> groupOverloads(ClassOrInterface input, List<Method> methods) {
|
||||||
|
var mapOfTargetMethods = new HashMap<Generics, TargetMethod[]>();
|
||||||
|
for (var generics : all) {
|
||||||
|
mapOfTargetMethods.put(generics, new TargetMethod[methods.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < methods.size(); i++) {
|
||||||
|
var method = methods.get(i);
|
||||||
|
// Convert all methods
|
||||||
|
var methodsWithTphs = convert(input, method);
|
||||||
|
for (var m : methodsWithTphs) {
|
||||||
|
var resultMethods = mapOfTargetMethods.get(m.generics);
|
||||||
|
resultMethods[i] = m.method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*System.out.println("============== INPUT ==============");
|
||||||
|
for (var m : mapOfTargetMethods.values()) {
|
||||||
|
for (var v : m) System.out.println(v.name() + " " + v.getSignature());
|
||||||
|
System.out.println();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
var allCombinations = new HashSet<Set<Combination>>();
|
||||||
|
// Combine methods based on their signature and position in the result set
|
||||||
|
for (var g1 : all) {
|
||||||
|
var resMeth1 = mapOfTargetMethods.get(g1);
|
||||||
|
for (var i = 0; i < methods.size(); i++) {
|
||||||
|
var m1 = resMeth1[i];
|
||||||
|
if (m1 == null) continue;
|
||||||
|
|
||||||
|
for (var g2 : all) {
|
||||||
|
if (g1 == g2) continue; // No need to combine the same method
|
||||||
|
var resMeth2 = mapOfTargetMethods.get(g2);
|
||||||
|
var m2 = resMeth2[i];
|
||||||
|
if (m2 == null) continue;
|
||||||
|
|
||||||
|
var combinations = new HashSet<Combination>();
|
||||||
|
|
||||||
|
if (canCombine(m1, m2)) {
|
||||||
|
//System.out.println(" Combining " + m1.getSignature() + " and " + m2.getSignature());
|
||||||
|
combinations.add(new Combination(m1, m2));
|
||||||
|
for (var j = 0; j < methods.size(); j++) {
|
||||||
|
if (j == i) continue;
|
||||||
|
var m3 = resMeth2[j];
|
||||||
|
if (m3 == null) continue;
|
||||||
|
var m4 = resMeth1[j];
|
||||||
|
if (m4 == null) continue;
|
||||||
|
combinations.add(new Combination(m4, m3));
|
||||||
|
//System.out.println("Also Combining " + m4.getSignature() + " and " + m3.getSignature());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//System.out.println(" Not Combining " + m1.getSignature() + " and " + m2.getSignature());
|
||||||
|
}
|
||||||
|
if (!combinations.isEmpty()) allCombinations.add(combinations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.add(resMethods.stream().toList());
|
|
||||||
}
|
}
|
||||||
return res;
|
|
||||||
|
if (allCombinations.isEmpty()) allCombinations.add(new HashSet<>());
|
||||||
|
|
||||||
|
// Combine back into output format
|
||||||
|
var r0 = new HashSet<Set<TargetMethod>>();
|
||||||
|
for (var combinations : allCombinations) {
|
||||||
|
var r1 = new HashSet<Set<TargetMethod>>();
|
||||||
|
// This is used to weed out duplicates
|
||||||
|
var uniqued = new HashSet<TargetMethod>();
|
||||||
|
// We go over all methods in the result
|
||||||
|
for (var g : all) for (var i = 0; i < methods.size(); i++) {
|
||||||
|
var r2 = new HashSet<TargetMethod>();
|
||||||
|
var m = mapOfTargetMethods.get(g)[i];
|
||||||
|
if (m == null) continue;
|
||||||
|
if (!uniqued.contains(m)) {
|
||||||
|
// Add the method to r2
|
||||||
|
r2.add(m);
|
||||||
|
uniqued.add(m);
|
||||||
|
} else continue;
|
||||||
|
// Find all combinations that contain the method and add them to the result
|
||||||
|
// if not filtered out by uniqued
|
||||||
|
for (var c : combinations) {
|
||||||
|
if (c.a.equals(m) || c.b.equals(m)) {
|
||||||
|
if (!uniqued.contains(c.a)) {
|
||||||
|
r2.add(c.a);
|
||||||
|
uniqued.add(c.a);
|
||||||
|
}
|
||||||
|
if (!uniqued.contains(c.b)) {
|
||||||
|
r2.add(c.b);
|
||||||
|
uniqued.add(c.b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r1.add(r2);
|
||||||
|
}
|
||||||
|
outer: for (var s1 : r1) {
|
||||||
|
for (var s2 : new HashSet<>(r0)) {
|
||||||
|
if (s2.containsAll(s1)) {
|
||||||
|
continue outer;
|
||||||
|
} else if (s1.containsAll(s2)) {
|
||||||
|
r0.remove(s2);
|
||||||
|
r0.add(s1);
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r0.add(s1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = r0.stream().map(l -> l.stream().toList()).toList();
|
||||||
|
|
||||||
|
System.out.println("============== OUTPUT ==============");
|
||||||
|
for (var l : result) {
|
||||||
|
for (var m : l) System.out.println(m.name() + " " + m.getSignature());
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TargetStructure convert(ClassOrInterface input) {
|
public TargetStructure convert(ClassOrInterface input) {
|
||||||
Set<TargetGeneric> javaGenerics = new HashSet<>();
|
Set<TargetGeneric> javaGenerics = new HashSet<>();
|
||||||
Set<TargetGeneric> txGenerics = new HashSet<>();
|
Set<TargetGeneric> txGenerics = new HashSet<>();
|
||||||
|
|
||||||
var genericsIter = input.getGenerics().iterator();
|
var userDefinedGenerics = input.getUserDefinedGenerics();
|
||||||
if (genericsIter.hasNext()) {
|
if (!userDefinedGenerics.isEmpty()) {
|
||||||
// Add empty set of generics to cache so that it doesn't try to calculate it later
|
// Add empty set of generics to cache so that it doesn't try to calculate it later
|
||||||
var userDefinedGenerics = new HashSet<GenericTypeVar>();
|
for (var generic : userDefinedGenerics) {
|
||||||
this.userDefinedGenerics.put(input, userDefinedGenerics);
|
// TODO Support multiple bouds
|
||||||
while (genericsIter.hasNext()) {
|
javaGenerics.add(new TargetGeneric(generic.getName(), convert(generic.getBounds().getFirst())));
|
||||||
var next = genericsIter.next();
|
|
||||||
userDefinedGenerics.add(next);
|
|
||||||
// TODO Support multiple bounds
|
|
||||||
javaGenerics.add(new TargetGeneric(next.getName(), convert(next.getBounds().get(0))));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.userDefinedGenerics.put(input, new HashSet<>());
|
|
||||||
// Generate generics only if there are no user defined ones
|
// Generate generics only if there are no user defined ones
|
||||||
javaGenerics = convert(generics.javaGenerics.generics(input), generics.javaGenerics);
|
javaGenerics = convert(generics.javaGenerics.generics(input), generics.javaGenerics);
|
||||||
txGenerics = convert(generics.txGenerics.generics(input), generics.txGenerics);
|
txGenerics = convert(generics.txGenerics.generics(input), generics.txGenerics);
|
||||||
@@ -209,7 +377,8 @@ public class ASTToTargetAST {
|
|||||||
var superInterfaces = input.getSuperInterfaces().stream().map(clazz -> convert(clazz, generics.javaGenerics)).toList();
|
var superInterfaces = input.getSuperInterfaces().stream().map(clazz -> convert(clazz, generics.javaGenerics)).toList();
|
||||||
var constructors = input.getConstructors().stream().map(constructor -> this.convert(input, constructor, finalFieldInitializer)).flatMap(List::stream).toList();
|
var constructors = input.getConstructors().stream().map(constructor -> this.convert(input, constructor, finalFieldInitializer)).flatMap(List::stream).toList();
|
||||||
var fields = input.getFieldDecl().stream().map(this::convert).toList();
|
var fields = input.getFieldDecl().stream().map(this::convert).toList();
|
||||||
var methods = groupOverloads(input, input.getMethods()).stream().map(m -> generatePatternOverloads(input, m)).flatMap(List::stream).toList();
|
var methods = groupOverloads(input, input.getMethods()).stream().map(m -> generatePatternOverloads(input, m)).flatMap(List::stream)
|
||||||
|
.collect(Collectors.toSet()).stream().toList(); // Unique generated methods
|
||||||
|
|
||||||
TargetMethod staticConstructor = null;
|
TargetMethod staticConstructor = null;
|
||||||
if (input.getStaticInitializer().isPresent())
|
if (input.getStaticInitializer().isPresent())
|
||||||
@@ -223,9 +392,14 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<MethodParameter> convert(ParameterList input, GenerateGenerics generics) {
|
public List<MethodParameter> convert(ParameterList input, GenerateGenerics generics) {
|
||||||
return input.getFormalparalist().stream().map(param ->
|
var res = new ArrayList<MethodParameter>();
|
||||||
new MethodParameter((TargetPattern) convert(param))
|
for (var i = 0; i < input.getFormalparalist().size(); i++) {
|
||||||
).toList();
|
var param = input.getFormalparalist().get(i);
|
||||||
|
var pattern = (TargetPattern) convert(param);
|
||||||
|
if (pattern instanceof TargetComplexPattern) pattern = pattern.withName("__var" + i);
|
||||||
|
res.add(new MethodParameter(pattern));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasGeneric(Set<TargetGeneric> generics, GenericRefType type) {
|
private boolean hasGeneric(Set<TargetGeneric> generics, GenericRefType type) {
|
||||||
@@ -251,7 +425,7 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<TargetConstructor> convert(ClassOrInterface currentClass, Constructor input, TargetBlock fieldInitializer) {
|
private List<TargetConstructor> convert(ClassOrInterface currentClass, Constructor input, TargetBlock fieldInitializer) {
|
||||||
generics = all.get(0);
|
generics = all.getFirst();
|
||||||
List<TargetConstructor> result = new ArrayList<>();
|
List<TargetConstructor> result = new ArrayList<>();
|
||||||
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
||||||
this.currentMethod = input;
|
this.currentMethod = input;
|
||||||
@@ -295,10 +469,78 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TargetExpression generatePatternOverloadsRec(int offset, TargetExpression switchExpr, List<TargetLocalVar> params, List<TargetPattern> patterns, List<TargetMethod> methods, TargetType classType) {
|
||||||
|
if (methods.isEmpty()) throw new DebugException("Couldn't find a candidate for switch overloading");
|
||||||
|
if (methods.size() == 1) {
|
||||||
|
var method = methods.getFirst();
|
||||||
|
var mParams = new ArrayList<TargetExpression>();
|
||||||
|
for (var i = 0; i < params.size(); i++) {
|
||||||
|
var tpe = method.signature().parameters().get(i).pattern().type();
|
||||||
|
mParams.add(new TargetLocalVar(tpe, params.get(i).name()));
|
||||||
|
}
|
||||||
|
TargetExpression caseBody = new TargetMethodCall(
|
||||||
|
method.signature().returnType(),
|
||||||
|
new TargetThis(classType),
|
||||||
|
mParams,
|
||||||
|
classType,
|
||||||
|
method.name(),
|
||||||
|
false, false, method.isPrivate()
|
||||||
|
);
|
||||||
|
if (method.signature().returnType() != null) {
|
||||||
|
caseBody = new TargetReturn(caseBody);
|
||||||
|
}
|
||||||
|
return caseBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cases = new ArrayList<TargetSwitch.Case>();
|
||||||
|
var usedPatterns = new HashSet<TargetPattern>();
|
||||||
|
|
||||||
|
for (var method : methods) {
|
||||||
|
var patternsRec = new ArrayList<>(patterns);
|
||||||
|
|
||||||
|
TargetExpression expr = null;
|
||||||
|
var i = 0;
|
||||||
|
for (var param : method.signature().parameters()) {
|
||||||
|
if (i == offset) {
|
||||||
|
patternsRec.add(param.pattern());
|
||||||
|
}
|
||||||
|
if (i > offset) {
|
||||||
|
// Find next pattern
|
||||||
|
expr = params.get(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastPattern = patternsRec.getLast();
|
||||||
|
if (usedPatterns.contains(lastPattern)) continue;
|
||||||
|
usedPatterns.add(lastPattern);
|
||||||
|
|
||||||
|
var candidates = methods.stream().filter(m -> {
|
||||||
|
var j = 0;
|
||||||
|
for (var param : m.signature().parameters()) {
|
||||||
|
if (j >= patternsRec.size()) return true;
|
||||||
|
if (!patternsRec.get(j).type().equals(param.pattern().type())) return false;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
var caseBody = generatePatternOverloadsRec(offset + 1, expr, params, patternsRec, candidates, classType);
|
||||||
|
var body = new TargetBlock(List.of(caseBody));
|
||||||
|
var case_ = new TargetSwitch.Case(List.of(lastPattern), body);
|
||||||
|
|
||||||
|
cases.add(case_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TargetSwitch(switchExpr, cases, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
private List<TargetMethod> generatePatternOverloads(ClassOrInterface clazz, List<TargetMethod> overloadedMethods) {
|
private List<TargetMethod> generatePatternOverloads(ClassOrInterface clazz, List<TargetMethod> overloadedMethods) {
|
||||||
if (overloadedMethods.size() <= 1) return overloadedMethods;
|
if (overloadedMethods.size() <= 1) return overloadedMethods;
|
||||||
// Check if we have a pattern as a parameter
|
// Check if we have a pattern as a parameter
|
||||||
var firstMethod = overloadedMethods.getFirst();
|
var firstMethod = overloadedMethods.getFirst();
|
||||||
|
var secondMethod = overloadedMethods.get(1);
|
||||||
if (firstMethod.signature().parameters().stream().noneMatch(mp -> mp.pattern() instanceof TargetComplexPattern)) return overloadedMethods;
|
if (firstMethod.signature().parameters().stream().noneMatch(mp -> mp.pattern() instanceof TargetComplexPattern)) return overloadedMethods;
|
||||||
// Rename existing methods
|
// Rename existing methods
|
||||||
|
|
||||||
@@ -308,8 +550,47 @@ public class ASTToTargetAST {
|
|||||||
res.add(new TargetMethod(method.access(), name, method.block(), method.signature(), method.txSignature()));
|
res.add(new TargetMethod(method.access(), name, method.block(), method.signature(), method.txSignature()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate dispatch method
|
var signatureParams = new ArrayList<MethodParameter>();
|
||||||
|
for (var i = 0; i < firstMethod.signature().parameters().size(); i++) {
|
||||||
|
var p1 = firstMethod.signature().parameters().get(i).pattern();
|
||||||
|
var t1 = p1.type();
|
||||||
|
var t2 = secondMethod.signature().parameters().get(i).pattern().type();
|
||||||
|
var commonSubTypes = new HashSet<>(commonSuperInterfaceTypes(t1, t2));
|
||||||
|
for (var m : overloadedMethods.subList(2, overloadedMethods.size())) {
|
||||||
|
var t3 = m.signature().parameters().get(i).pattern().type();
|
||||||
|
commonSubTypes.retainAll(commonSuperInterfaceTypes(t1, t3));
|
||||||
|
}
|
||||||
|
if (commonSubTypes.size() > 1) throw new DebugException("Invalid overload");
|
||||||
|
// TODO accept multiple types
|
||||||
|
var superType = ASTFactory.createObjectClass();
|
||||||
|
if (!commonSubTypes.isEmpty())
|
||||||
|
superType = commonSubTypes.iterator().next();
|
||||||
|
|
||||||
|
String name;
|
||||||
|
if (p1 instanceof TargetComplexPattern) name = "__var" + i;
|
||||||
|
else name = p1.name();
|
||||||
|
signatureParams.add(new MethodParameter(new TargetRefType(superType.getClassName().toString()), name));
|
||||||
|
}
|
||||||
|
|
||||||
|
var commonSubTypes = new HashSet<>(commonSuperInterfaceTypes(firstMethod.signature().returnType(), secondMethod.signature().returnType()));
|
||||||
|
for (var m : overloadedMethods.subList(2, overloadedMethods.size())) {
|
||||||
|
commonSubTypes.retainAll(commonSuperInterfaceTypes(firstMethod.signature().returnType(), m.signature().returnType()));
|
||||||
|
}
|
||||||
|
var returnType = commonSubTypes.isEmpty() ? TargetType.Object : new TargetRefType(commonSubTypes.iterator().next().getClassName().toString());
|
||||||
|
|
||||||
|
var parameters = signatureParams.stream().map( p -> new TargetLocalVar(p.pattern().type(), p.pattern().name())).toList();
|
||||||
|
//var patterns = List.of((TargetComplexPattern) firstMethod.signature().parameters().stream()
|
||||||
|
// .filter(p -> p.pattern() instanceof TargetComplexPattern).findFirst().orElseThrow().pattern());
|
||||||
|
|
||||||
|
// Generate dispatch method
|
||||||
|
var classType = new TargetRefType(clazz.getClassName().getClassName());
|
||||||
|
var stmt = generatePatternOverloadsRec(0, new TargetLocalVar(signatureParams.getFirst().pattern().type(), signatureParams.getFirst().pattern().name()), parameters, List.of(), res, classType);
|
||||||
|
var block = new TargetBlock(List.of(stmt));
|
||||||
|
|
||||||
|
var signature = new TargetMethod.Signature(Set.of(), signatureParams, returnType);
|
||||||
|
var bridgeMethod = new TargetMethod(firstMethod.access(), firstMethod.name(), block, signature, firstMethod.txSignature());
|
||||||
|
|
||||||
|
res.add(bridgeMethod);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +635,19 @@ public class ASTToTargetAST {
|
|||||||
}).findFirst();
|
}).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
record MethodWithTphs(TargetMethod method, List<SignaturePairTarget> args) {}
|
record MethodWithTphs(TargetMethod method, Generics generics, List<SignaturePairTarget> args) {
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof MethodWithTphs that)) return false;
|
||||||
|
return Objects.equals(method, that.method) && Objects.equals(args, that.args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(method, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
record Signature(TargetMethod.Signature java, TargetMethod.Signature tx, Generics generics) {}
|
record Signature(TargetMethod.Signature java, TargetMethod.Signature tx, Generics generics) {}
|
||||||
|
|
||||||
@@ -391,7 +684,6 @@ public class ASTToTargetAST {
|
|||||||
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), this.generics.txGenerics));
|
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), this.generics.txGenerics));
|
||||||
|
|
||||||
signatures.add(new Signature(javaSignature, txSignature, generics));
|
signatures.add(new Signature(javaSignature, txSignature, generics));
|
||||||
System.out.println(javaSignature);
|
|
||||||
var listOfGenerics = collectedGenerics.getOrDefault(javaSignature, new ArrayList<>());
|
var listOfGenerics = collectedGenerics.getOrDefault(javaSignature, new ArrayList<>());
|
||||||
listOfGenerics.add(generics);
|
listOfGenerics.add(generics);
|
||||||
collectedGenerics.put(javaSignature, listOfGenerics);
|
collectedGenerics.put(javaSignature, listOfGenerics);
|
||||||
@@ -404,7 +696,7 @@ public class ASTToTargetAST {
|
|||||||
var newMethod = new TargetMethod(method.modifier, method.name, convert(method.block), signature.java, signature.tx);
|
var newMethod = new TargetMethod(method.modifier, method.name, convert(method.block), signature.java, signature.tx);
|
||||||
var concreteParams = tphsInMethods.getOrDefault(method, new HashSet<>()).stream().map(sig -> new SignaturePairTarget(convert(sig.signature), convert(sig.parameter))).toList();
|
var concreteParams = tphsInMethods.getOrDefault(method, new HashSet<>()).stream().map(sig -> new SignaturePairTarget(convert(sig.signature), convert(sig.parameter))).toList();
|
||||||
|
|
||||||
result.add(new MethodWithTphs(newMethod, concreteParams));
|
result.add(new MethodWithTphs(newMethod, generics, concreteParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -414,7 +706,9 @@ public class ASTToTargetAST {
|
|||||||
var list = new ArrayList<MethodParameter>();
|
var list = new ArrayList<MethodParameter>();
|
||||||
for (var i = 0; i < paraList.getFormalparalist().size(); i++) {
|
for (var i = 0; i < paraList.getFormalparalist().size(); i++) {
|
||||||
var param = paraList.getParameterAt(i);
|
var param = paraList.getParameterAt(i);
|
||||||
list.add(new MethodParameter((TargetPattern) convert(param)).withType(convert(superList.getParameterAt(i).getType(), generics)));
|
var pattern = (TargetPattern) convert(param);
|
||||||
|
if (pattern instanceof TargetComplexPattern) pattern = pattern.withName("__var" + i);
|
||||||
|
list.add(new MethodParameter(pattern).withType(convert(superList.getParameterAt(i).getType(), generics)));
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -445,11 +739,6 @@ public class ASTToTargetAST {
|
|||||||
return new TargetField(input.modifier, convert(input.getType(), generics.javaGenerics), input.getName());
|
return new TargetField(input.modifier, convert(input.getType(), generics.javaGenerics), input.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<String, FunNGenerator.GenericParameters> usedFunN = new HashMap<>();
|
|
||||||
private final Set<Integer> usedFunNSuperTypes = new HashSet<>();
|
|
||||||
|
|
||||||
public Map<String, byte[]> auxiliaries = new HashMap<>();
|
|
||||||
|
|
||||||
public TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input) {
|
public TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input) {
|
||||||
return convert(input, generics.javaGenerics);
|
return convert(input, generics.javaGenerics);
|
||||||
}
|
}
|
||||||
@@ -482,7 +771,15 @@ public class ASTToTargetAST {
|
|||||||
return TargetFunNType.fromParams(params, filteredParams, gep.getReturnType() != null ? 1 : 0);
|
return TargetFunNType.fromParams(params, filteredParams, gep.getReturnType() != null ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FunNGenerator.GenericParameters convertToParameters(TargetFunNType input) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isSubtype(TargetType test, TargetType other) {
|
private boolean isSubtype(TargetType test, TargetType other) {
|
||||||
|
if (other.equals(TargetType.Object)) return true;
|
||||||
|
if (test instanceof TargetFunNType tfun && other instanceof TargetFunNType ofun)
|
||||||
|
return isSubtype(new FunNGenerator.GenericParameters(tfun), new FunNGenerator.GenericParameters(ofun));
|
||||||
|
|
||||||
var testClass = compiler.getClass(new JavaClassName(test.name()));
|
var testClass = compiler.getClass(new JavaClassName(test.name()));
|
||||||
var otherClass = compiler.getClass(new JavaClassName(other.name()));
|
var otherClass = compiler.getClass(new JavaClassName(other.name()));
|
||||||
if (testClass == null) return false;
|
if (testClass == null) return false;
|
||||||
@@ -510,28 +807,24 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateFunNTypes() {
|
public void generateFunNTypes() {
|
||||||
for (var entry : usedFunN.entrySet()) {
|
for (var entry : compiler.usedFunN.entrySet()) {
|
||||||
var gep = entry.getValue();
|
var gep = entry.getValue();
|
||||||
var superInterfaces = usedFunN.values().stream()
|
var superInterfaces = compiler.usedFunN.values().stream()
|
||||||
.filter(g -> !g.equals(gep))
|
.filter(g -> !g.equals(gep))
|
||||||
.filter(genericParameters -> isSubtype(gep, genericParameters))
|
.filter(genericParameters -> isSubtype(gep, genericParameters))
|
||||||
.map(FunNGenerator::getSpecializedClassName)
|
.map(FunNGenerator::getSpecializedClassName)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
var code = FunNGenerator.generateSpecializedBytecode(gep, superInterfaces);
|
var code = FunNGenerator.generateSpecializedBytecode(gep, superInterfaces);
|
||||||
|
compiler.auxiliaries.put(entry.getKey(), code);
|
||||||
try {
|
|
||||||
classLoader.findClass(entry.getKey());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
try {
|
|
||||||
classLoader.loadClass(code);
|
|
||||||
} catch (LinkageError ignored) {}
|
|
||||||
}
|
|
||||||
auxiliaries.put(entry.getKey(), code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, GenerateGenerics generics) {
|
public TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, GenerateGenerics generics) {
|
||||||
|
return convert(input, generics, compiler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, GenerateGenerics generics, JavaTXCompiler compiler) {
|
||||||
return input.acceptTV(new TypeVisitor<>() {
|
return input.acceptTV(new TypeVisitor<>() {
|
||||||
@Override
|
@Override
|
||||||
public TargetType visit(RefType refType) {
|
public TargetType visit(RefType refType) {
|
||||||
@@ -543,31 +836,31 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var params = refType.getParaList().stream().map(type -> {
|
var params = refType.getParaList().stream().map(type -> {
|
||||||
return convert(type, generics);
|
return convert(type, generics, compiler);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
if (name.matches("Fun\\d+\\$\\$")) { // TODO This seems like a bad idea
|
if (name.matches("Fun\\d+\\$\\$")) { // TODO This seems like a bad idea
|
||||||
var returnType = FunNGenerator.getReturnType(params);
|
var returnType = FunNGenerator.getReturnType(params);
|
||||||
var className = FunNGenerator.getSpecializedClassName(FunNGenerator.getArguments(params), returnType);
|
var className = FunNGenerator.getSpecializedClassName(FunNGenerator.getArguments(params), returnType);
|
||||||
if (!usedFunNSuperTypes.contains(params.size())) {
|
if (!compiler.usedFunNSuperTypes.contains(params.size())) {
|
||||||
usedFunNSuperTypes.add(params.size());
|
compiler.usedFunNSuperTypes.add(params.size());
|
||||||
var code = FunNGenerator.generateSuperBytecode(params.size() - 1, returnType != null ? 1 : 0);
|
var code = FunNGenerator.generateSuperBytecode(params.size() - 1, returnType != null ? 1 : 0);
|
||||||
var superClassName = FunNGenerator.getSuperClassName(params.size() - 1, returnType != null ? 1 : 0);
|
var superClassName = FunNGenerator.getSuperClassName(params.size() - 1, returnType != null ? 1 : 0);
|
||||||
try {
|
try {
|
||||||
classLoader.findClass(superClassName);
|
compiler.classLoader.findClass(superClassName);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
try {
|
try {
|
||||||
classLoader.loadClass(code);
|
compiler.classLoader.loadClass(superClassName, code);
|
||||||
} catch (LinkageError ignored) {}
|
} catch (LinkageError ignored) {}
|
||||||
}
|
}
|
||||||
auxiliaries.put(superClassName, code);
|
compiler.auxiliaries.put(superClassName, code);
|
||||||
}
|
}
|
||||||
FunNGenerator.GenericParameters gep = null;
|
FunNGenerator.GenericParameters gep = null;
|
||||||
if (!usedFunN.containsKey(className)) {
|
if (!compiler.usedFunN.containsKey(className)) {
|
||||||
gep = new FunNGenerator.GenericParameters(params, returnType != null ? 1 : 0);
|
gep = new FunNGenerator.GenericParameters(params, returnType != null ? 1 : 0);
|
||||||
usedFunN.put(className, gep);
|
compiler.usedFunN.put(className, gep);
|
||||||
} else {
|
} else {
|
||||||
gep = usedFunN.get(className);
|
gep = compiler.usedFunN.get(className);
|
||||||
}
|
}
|
||||||
return flattenFunNType(params, gep);
|
return flattenFunNType(params, gep);
|
||||||
}
|
}
|
||||||
@@ -576,7 +869,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TargetType visit(SuperWildcardType superWildcardType) {
|
public TargetType visit(SuperWildcardType superWildcardType) {
|
||||||
return new TargetSuperWildcard(convert(superWildcardType.getInnerType(), generics));
|
return new TargetSuperWildcard(convert(superWildcardType.getInnerType(), generics, compiler));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -586,7 +879,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TargetType visit(ExtendsWildcardType extendsWildcardType) {
|
public TargetType visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
return new TargetExtendsWildcard(convert(extendsWildcardType.getInnerType(), generics));
|
return new TargetExtendsWildcard(convert(extendsWildcardType.getInnerType(), generics, compiler));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,10 +1,9 @@
|
|||||||
package de.dhbwstuttgart.target.generate;
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
@@ -21,7 +20,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public abstract class GenerateGenerics {
|
public abstract class GenerateGenerics {
|
||||||
|
|
||||||
private final ASTToTargetAST astToTargetAST;
|
private final JavaTXCompiler compiler;
|
||||||
|
|
||||||
public class TPH {
|
public class TPH {
|
||||||
private final TypePlaceholder wrap;
|
private final TypePlaceholder wrap;
|
||||||
@@ -137,8 +136,8 @@ public abstract class GenerateGenerics {
|
|||||||
Map<TPH, RefTypeOrTPHOrWildcardOrGeneric> concreteTypes = new HashMap<>();
|
Map<TPH, RefTypeOrTPHOrWildcardOrGeneric> concreteTypes = new HashMap<>();
|
||||||
Map<TypePlaceholder, TypePlaceholder> equality = new HashMap<>();
|
Map<TypePlaceholder, TypePlaceholder> equality = new HashMap<>();
|
||||||
|
|
||||||
GenerateGenerics(ASTToTargetAST astToTargetAST, ResultSet constraints) {
|
GenerateGenerics(JavaTXCompiler compiler, ResultSet constraints) {
|
||||||
this.astToTargetAST = astToTargetAST;
|
this.compiler = compiler;
|
||||||
for (var constraint : constraints.results) {
|
for (var constraint : constraints.results) {
|
||||||
if (constraint instanceof PairTPHsmallerTPH p) {
|
if (constraint instanceof PairTPHsmallerTPH p) {
|
||||||
System.out.println(p.left + " " + p.left.getVariance());
|
System.out.println(p.left + " " + p.left.getVariance());
|
||||||
@@ -170,6 +169,25 @@ public abstract class GenerateGenerics {
|
|||||||
else if (to instanceof RefType t) concreteTypes.put(new TPH(from), t);
|
else if (to instanceof RefType t) concreteTypes.put(new TPH(from), t);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
Set<TPH> findTypeVariables(ParameterList params) {
|
||||||
|
var res = new HashSet<TPH>();
|
||||||
|
for (var param : params.getFormalparalist()) {
|
||||||
|
res.addAll(findTypeVariables(param));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<TPH> findTypeVariables(Pattern pattern) {
|
||||||
|
var res = new HashSet<TPH>();
|
||||||
|
if (pattern instanceof RecordPattern rp) {
|
||||||
|
for (var subPattern : rp.getSubPattern()) {
|
||||||
|
res.addAll(findTypeVariables(subPattern));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.addAll(findTypeVariables(pattern.getType()));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
Set<TPH> findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type) {
|
Set<TPH> findTypeVariables(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
var result = new HashSet<TPH>();
|
var result = new HashSet<TPH>();
|
||||||
if (type instanceof TypePlaceholder tph) {
|
if (type instanceof TypePlaceholder tph) {
|
||||||
@@ -265,7 +283,7 @@ public abstract class GenerateGenerics {
|
|||||||
Set<TPH> typeVariablesOfClass,
|
Set<TPH> typeVariablesOfClass,
|
||||||
Set<Pair> result
|
Set<Pair> result
|
||||||
) {
|
) {
|
||||||
var userDefinedGenericsOfClass = astToTargetAST.userDefinedGenerics.get(owner);
|
var userDefinedGenericsOfClass = owner.getUserDefinedGenerics();
|
||||||
|
|
||||||
// Type variables with bounds that are also type variables of the method
|
// Type variables with bounds that are also type variables of the method
|
||||||
for (var typeVariable : new HashSet<>(typeVariables)) {
|
for (var typeVariable : new HashSet<>(typeVariables)) {
|
||||||
@@ -313,7 +331,7 @@ public abstract class GenerateGenerics {
|
|||||||
|
|
||||||
if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver) {
|
if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver) {
|
||||||
if (expressionReceiver.expr instanceof This) {
|
if (expressionReceiver.expr instanceof This) {
|
||||||
var optMethod = astToTargetAST.findMethod(owner, methodCall.name, methodCall.signatureArguments().stream().map(astToTargetAST::convert).toList());
|
var optMethod = ASTToTargetAST.findMethod(owner, methodCall.name, methodCall.signatureArguments().stream().map(x -> getTargetType(x)).toList(), GenerateGenerics.this, compiler);
|
||||||
if (optMethod.isEmpty()) return;
|
if (optMethod.isEmpty()) return;
|
||||||
var method2 = optMethod.get();
|
var method2 = optMethod.get();
|
||||||
System.out.println("In: " + method.getName() + " Method: " + method2.getName());
|
System.out.println("In: " + method.getName() + " Method: " + method2.getName());
|
||||||
@@ -506,9 +524,7 @@ public abstract class GenerateGenerics {
|
|||||||
|
|
||||||
if (!(method instanceof Constructor))
|
if (!(method instanceof Constructor))
|
||||||
typeVariables.addAll(findTypeVariables(method.getReturnType()));
|
typeVariables.addAll(findTypeVariables(method.getReturnType()));
|
||||||
for (var arg : method.getParameterList().getFormalparalist()) {
|
typeVariables.addAll(findTypeVariables(method.getParameterList()));
|
||||||
typeVariables.addAll(findTypeVariables(arg.getType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (method.block != null)
|
if (method.block != null)
|
||||||
method.block.accept(new TracingStatementVisitor() {
|
method.block.accept(new TracingStatementVisitor() {
|
||||||
@@ -572,9 +588,7 @@ public abstract class GenerateGenerics {
|
|||||||
|
|
||||||
var usedTphs = new HashSet<TPH>();
|
var usedTphs = new HashSet<TPH>();
|
||||||
// For eliminating inner type variables we need to figure out which ones are actually used
|
// For eliminating inner type variables we need to figure out which ones are actually used
|
||||||
for (var param : method.getParameterList().getFormalparalist()) {
|
usedTphs.addAll(findTypeVariables(method.getParameterList()));
|
||||||
usedTphs.addAll(findTypeVariables(param.getType()));
|
|
||||||
}
|
|
||||||
usedTphs.addAll(findTypeVariables(method.getReturnType()));
|
usedTphs.addAll(findTypeVariables(method.getReturnType()));
|
||||||
referenced.addAll(usedTphs);
|
referenced.addAll(usedTphs);
|
||||||
referenced.addAll(typeVariablesOfClass);
|
referenced.addAll(typeVariablesOfClass);
|
||||||
@@ -672,11 +686,21 @@ public abstract class GenerateGenerics {
|
|||||||
if (p1 instanceof PairLT ptph && ptph.left.resolve().equals(ptph.right.resolve()))
|
if (p1 instanceof PairLT ptph && ptph.left.resolve().equals(ptph.right.resolve()))
|
||||||
result.remove(p1); // TODO This is a bit strange
|
result.remove(p1); // TODO This is a bit strange
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var tph : usedTphs) {
|
for (var tph : usedTphs) {
|
||||||
if (classGenerics == null || classGenerics.stream().noneMatch((pair) -> pair.left.equals(tph)))
|
if (classGenerics == null || classGenerics.stream().noneMatch((pair) -> pair.left.equals(tph)))
|
||||||
addToPairs(result, new PairEQ(tph, ASTToTargetAST.OBJECT));
|
addToPairs(result, new PairEQ(tph, ASTToTargetAST.OBJECT));
|
||||||
}
|
}
|
||||||
|
var all = new HashSet<>(result);
|
||||||
|
for (var p : all) {
|
||||||
|
if (p instanceof PairEQ peq && peq.right.equals(ASTToTargetAST.OBJECT)) {
|
||||||
|
for (var p2 : all) {
|
||||||
|
if (p2 instanceof PairLT && p2.left.equals(p.left)) {
|
||||||
|
result.remove(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ToAdd(TypePlaceholder left, TypePlaceholder right) {}
|
private record ToAdd(TypePlaceholder left, TypePlaceholder right) {}
|
||||||
@@ -983,8 +1007,8 @@ public abstract class GenerateGenerics {
|
|||||||
}
|
}
|
||||||
var type = concreteTypes.get(new TPH(tph));
|
var type = concreteTypes.get(new TPH(tph));
|
||||||
if (type == null) return new TargetGenericType(tph.getName());
|
if (type == null) return new TargetGenericType(tph.getName());
|
||||||
return astToTargetAST.convert(type, this);
|
return ASTToTargetAST.convert(type, this, compiler);
|
||||||
}
|
}
|
||||||
return astToTargetAST.convert(in, this);
|
return ASTToTargetAST.convert(in, this, compiler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -69,8 +69,4 @@ public class GenericsResult {
|
|||||||
return this.generics.getType(tph);
|
return this.generics.getType(tph);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TargetType resolveTarget(RefTypeOrTPHOrWildcardOrGeneric type) {
|
|
||||||
return this.generics.getTargetType(type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.target.generate;
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@@ -7,8 +8,8 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
final class JavaGenerics extends GenerateGenerics {
|
final class JavaGenerics extends GenerateGenerics {
|
||||||
JavaGenerics(ASTToTargetAST astToTargetAST, ResultSet constraints) {
|
JavaGenerics(JavaTXCompiler compiler, ResultSet constraints) {
|
||||||
super(astToTargetAST, constraints);
|
super(compiler, constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -14,6 +14,7 @@ import de.dhbwstuttgart.target.tree.expression.*;
|
|||||||
import de.dhbwstuttgart.target.tree.type.*;
|
import de.dhbwstuttgart.target.tree.type.*;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.sql.Array;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
@@ -32,54 +33,71 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class LambdaCaptureFinder extends TracingStatementVisitor {
|
||||||
|
|
||||||
|
// TODO The same mechanism is implemented in Codegen, maybe use it from there?
|
||||||
|
final Stack<Set<String>> localVariables = new Stack<>();
|
||||||
|
private final List<MethodParameter> parameters;
|
||||||
|
private final List<MethodParameter> captures;
|
||||||
|
|
||||||
|
LambdaCaptureFinder(List<MethodParameter> parameters, List<MethodParameter> captures) {
|
||||||
|
localVariables.push(new HashSet<>());
|
||||||
|
this.parameters = parameters;
|
||||||
|
this.captures = captures;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasLocalVar(String name) {
|
||||||
|
for (var localVariables : this.localVariables) {
|
||||||
|
if (localVariables.contains(name))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Block block) {
|
||||||
|
localVariables.push(new HashSet<>());
|
||||||
|
super.visit(block);
|
||||||
|
localVariables.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVar localVar) {
|
||||||
|
super.visit(localVar);
|
||||||
|
var capture = new MethodParameter(new TargetTypePattern(converter.convert(localVar.getType()), localVar.name));
|
||||||
|
if (!hasLocalVar(localVar.name) && !parameters.contains(capture) && !captures.contains(capture))
|
||||||
|
captures.add(capture);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LocalVarDecl varDecl) {
|
||||||
|
var localVariables = this.localVariables.peek();
|
||||||
|
localVariables.add(varDecl.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LambdaExpression lambda) {
|
||||||
|
var newCaptures = new ArrayList<MethodParameter>();
|
||||||
|
var captureFinder = new LambdaCaptureFinder(createParameters(lambda), newCaptures);
|
||||||
|
lambda.methodBody.accept(captureFinder);
|
||||||
|
newCaptures.removeAll(parameters);
|
||||||
|
captures.addAll(newCaptures);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MethodParameter> createParameters(LambdaExpression lambda) {
|
||||||
|
return StreamSupport.stream(lambda.params.spliterator(), false)
|
||||||
|
.map(p -> (FormalParameter) p)
|
||||||
|
.map(p -> new MethodParameter(new TargetTypePattern(converter.convert(p.getType()), p.getName())))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
var parameters = StreamSupport.stream(lambdaExpression.params.spliterator(), false)
|
var parameters = createParameters(lambdaExpression);
|
||||||
.map(p -> (FormalParameter) p)
|
|
||||||
.map(p -> new MethodParameter(new TargetTypePattern(converter.convert(p.getType()), p.getName())))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
List<MethodParameter> captures = new ArrayList<>();
|
List<MethodParameter> captures = new ArrayList<>();
|
||||||
lambdaExpression.methodBody.accept(new TracingStatementVisitor() {
|
var visitor = new LambdaCaptureFinder(parameters, captures);
|
||||||
// TODO The same mechanism is implemented in Codegen, maybe use it from there?
|
lambdaExpression.methodBody.accept(visitor);
|
||||||
final Stack<Set<String>> localVariables = new Stack<>();
|
|
||||||
{
|
|
||||||
localVariables.push(new HashSet<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasLocalVar(String name) {
|
|
||||||
for (var localVariables : this.localVariables) {
|
|
||||||
if (localVariables.contains(name))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(Block block) {
|
|
||||||
localVariables.push(new HashSet<>());
|
|
||||||
super.visit(block);
|
|
||||||
localVariables.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LocalVar localVar) {
|
|
||||||
super.visit(localVar);
|
|
||||||
var capture = new MethodParameter(new TargetTypePattern(converter.convert(localVar.getType()), localVar.name));
|
|
||||||
if (!hasLocalVar(localVar.name) && !parameters.contains(capture) && !captures.contains(capture))
|
|
||||||
captures.add(capture);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LocalVarDecl varDecl) {
|
|
||||||
var localVariables = this.localVariables.peek();
|
|
||||||
localVariables.add(varDecl.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(LambdaExpression lambda) {
|
|
||||||
} // Don't look at lambda expressions
|
|
||||||
});
|
|
||||||
|
|
||||||
TargetMethod.Signature signature = new TargetMethod.Signature(Set.of(), parameters, converter.convert(lambdaExpression.getReturnType()));;
|
TargetMethod.Signature signature = new TargetMethod.Signature(Set.of(), parameters, converter.convert(lambdaExpression.getReturnType()));;
|
||||||
var tpe = converter.convert(lambdaExpression.getType());
|
var tpe = converter.convert(lambdaExpression.getType());
|
||||||
@@ -120,7 +138,10 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(BoolExpression bool) {
|
public void visit(BoolExpression bool) {
|
||||||
System.out.println("BoolExpression");
|
result = switch(bool.operation) {
|
||||||
|
case OR -> new TargetBinaryOp.Or(converter.convert(bool.getType()), converter.convert(bool.lexpr), converter.convert(bool.rexpr));
|
||||||
|
case AND -> new TargetBinaryOp.And(converter.convert(bool.getType()), converter.convert(bool.lexpr), converter.convert(bool.rexpr));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -568,6 +589,11 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
result = new TargetTypePattern(converter.convert(aPattern.getType()), aPattern.getName());
|
result = new TargetTypePattern(converter.convert(aPattern.getType()), aPattern.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(LiteralPattern literalPattern) {
|
||||||
|
result = new TargetExpressionPattern(converter.convert(literalPattern.value));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ExpressionPattern aPattern) {
|
public void visit(ExpressionPattern aPattern) {
|
||||||
result = converter.convert(aPattern.getExpression());
|
result = converter.convert(aPattern.getExpression());
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.target.generate;
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@@ -7,8 +8,8 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
final class TxGenerics extends GenerateGenerics {
|
final class TxGenerics extends GenerateGenerics {
|
||||||
TxGenerics(ASTToTargetAST astToTargetAST, ResultSet constraints) {
|
TxGenerics(JavaTXCompiler compiler, ResultSet constraints) {
|
||||||
super(astToTargetAST, constraints);
|
super(compiler, constraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -11,4 +11,8 @@ public record MethodParameter(TargetPattern pattern) {
|
|||||||
public MethodParameter withType(TargetType type) {
|
public MethodParameter withType(TargetType type) {
|
||||||
return new MethodParameter(pattern.withType(type));
|
return new MethodParameter(pattern.withType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MethodParameter withName(String name) {
|
||||||
|
return new MethodParameter(pattern.withName(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -79,6 +79,10 @@ public record TargetMethod(int access, String name, TargetBlock block, Signature
|
|||||||
return (access & Opcodes.ACC_STATIC) != 0;
|
return (access & Opcodes.ACC_STATIC) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPrivate() {
|
||||||
|
return (access & Opcodes.ACC_PRIVATE) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof TargetMethod otherMethod)) return false;
|
if (!(other instanceof TargetMethod otherMethod)) return false;
|
||||||
|
@@ -9,4 +9,9 @@ public record TargetComplexPattern(TargetType type, String name, List<TargetPatt
|
|||||||
public TargetComplexPattern withType(TargetType type) {
|
public TargetComplexPattern withType(TargetType type) {
|
||||||
return new TargetComplexPattern(type, name, subPatterns);
|
return new TargetComplexPattern(type, name, subPatterns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetComplexPattern withName(String name) {
|
||||||
|
return new TargetComplexPattern(type, name, subPatterns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,20 @@
|
|||||||
|
package de.dhbwstuttgart.target.tree.expression;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
|
public record TargetExpressionPattern(TargetExpression expression) implements TargetPattern {
|
||||||
|
@Override
|
||||||
|
public TargetPattern withType(TargetType type) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetType type() {
|
||||||
|
return expression.type();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetPattern withName(String name) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@@ -12,4 +12,9 @@ public record TargetGuard(TargetPattern inner, TargetExpression expression) impl
|
|||||||
public TargetType type() {
|
public TargetType type() {
|
||||||
return inner.type();
|
return inner.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetGuard withName(String name) {
|
||||||
|
return new TargetGuard(inner.withName(name), expression);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ package de.dhbwstuttgart.target.tree.expression;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
public sealed interface TargetPattern extends TargetExpression permits TargetComplexPattern, TargetGuard, TargetTypePattern {
|
public sealed interface TargetPattern extends TargetExpression permits TargetComplexPattern, TargetExpressionPattern, TargetGuard, TargetTypePattern {
|
||||||
default String name() {
|
default String name() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -10,4 +10,6 @@ public sealed interface TargetPattern extends TargetExpression permits TargetCom
|
|||||||
TargetPattern withType(TargetType type);
|
TargetPattern withType(TargetType type);
|
||||||
|
|
||||||
TargetType type();
|
TargetType type();
|
||||||
|
|
||||||
|
TargetPattern withName(String name);
|
||||||
}
|
}
|
||||||
|
@@ -7,4 +7,9 @@ public record TargetTypePattern(TargetType type, String name) implements TargetP
|
|||||||
public TargetTypePattern withType(TargetType type) {
|
public TargetTypePattern withType(TargetType type) {
|
||||||
return new TargetTypePattern(type, name);
|
return new TargetTypePattern(type, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TargetTypePattern withName(String name) {
|
||||||
|
return new TargetTypePattern(type, name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class TypeInsertPlacer extends AbstractASTWalker{
|
public class TypeInsertPlacer extends AbstractASTWalker {
|
||||||
Set<TypeInsert> inserts = new HashSet<>();
|
Set<TypeInsert> inserts = new HashSet<>();
|
||||||
private ResultSet withResults;
|
private ResultSet withResults;
|
||||||
String pkgName;
|
String pkgName;
|
||||||
|
@@ -6,7 +6,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Constraint<A> extends HashSet<A> {
|
public class Constraint<A> extends HashSet<A> implements Comparable<Constraint<A>> {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
private Boolean isInherited = false;//wird beides nur für die Method-Constraints benoetigt
|
||||||
private Boolean isImplemented = false;
|
private Boolean isImplemented = false;
|
||||||
@@ -73,5 +73,9 @@ public class Constraint<A> extends HashSet<A> {
|
|||||||
public String toStringBase() {
|
public String toStringBase() {
|
||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Constraint<A> o) {
|
||||||
|
return this.toString().compareTo(o.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|||||||
/**
|
/**
|
||||||
* Paare, welche das Unifikationsergebnis darstellen
|
* Paare, welche das Unifikationsergebnis darstellen
|
||||||
*/
|
*/
|
||||||
public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B extends RefTypeOrTPHOrWildcardOrGeneric> {
|
public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric, B extends RefTypeOrTPHOrWildcardOrGeneric> implements Comparable<ResultPair<A,B>> {
|
||||||
private final A left;
|
private final A left;
|
||||||
private final B right;
|
private final B right;
|
||||||
|
|
||||||
@@ -58,5 +58,14 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ResultPair<A, B> o) {
|
||||||
|
if (o == null) {
|
||||||
|
return 1; // this is greater than null
|
||||||
|
}
|
||||||
|
|
||||||
|
return o.left.toString().compareTo(this.left.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package de.dhbwstuttgart.typeinference.result;
|
package de.dhbwstuttgart.typeinference.result;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
@@ -12,7 +14,7 @@ import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class ResultSet {
|
public class ResultSet implements Comparable<ResultSet>{
|
||||||
|
|
||||||
public final Set<ResultPair> results;
|
public final Set<ResultPair> results;
|
||||||
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
||||||
@@ -22,6 +24,10 @@ public class ResultSet {
|
|||||||
this.genIns = new HashSet<>();
|
this.genIns = new HashSet<>();
|
||||||
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ResultPair> getSortedResults() {
|
||||||
|
return results.stream().sorted().toList();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean contains(ResultPair toCheck) {
|
public boolean contains(ResultPair toCheck) {
|
||||||
return this.results.contains(toCheck);
|
return this.results.contains(toCheck);
|
||||||
@@ -63,6 +69,21 @@ public class ResultSet {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return results.hashCode();
|
return results.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(ResultSet o) {
|
||||||
|
List<ResultPair> thisSorted = this.getSortedResults();
|
||||||
|
List<ResultPair> otherSorted = o.getSortedResults();
|
||||||
|
int sizeCompare = Integer.compare(thisSorted.size(), otherSorted.size());
|
||||||
|
if (sizeCompare != 0) return sizeCompare;
|
||||||
|
|
||||||
|
for (int i = 0; i < thisSorted.size(); i++) {
|
||||||
|
int cmp = thisSorted.get(i).compareTo(otherSorted.get(i));
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Resolver implements ResultSetVisitor {
|
class Resolver implements ResultSetVisitor {
|
||||||
|
@@ -1,21 +1,27 @@
|
|||||||
package de.dhbwstuttgart.typeinference.typeAlgo;
|
package de.dhbwstuttgart.typeinference.typeAlgo;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.SourceLoc;
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||||
|
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.util.BiRelation;
|
import de.dhbwstuttgart.util.BiRelation;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class TYPE {
|
public class TYPE {
|
||||||
@@ -85,12 +91,25 @@ public class TYPE {
|
|||||||
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
|
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, m);
|
||||||
TYPEStmt methodScope = new TYPEStmt(blockInfo);
|
TYPEStmt methodScope = new TYPEStmt(blockInfo);
|
||||||
ConstraintSet constraintSet = new ConstraintSet();
|
ConstraintSet constraintSet = new ConstraintSet();
|
||||||
m.getParameterList().getFormalparalist().forEach(el -> {
|
|
||||||
if(el instanceof RecordPattern){
|
|
||||||
constraintSet.addAll(addRecursiveParameterConstraints((RecordPattern) el, blockInfo));
|
|
||||||
|
|
||||||
}
|
if (m.name.equals("main") && Modifier.isStatic(m.modifier) && m.getParameterList().getFormalparalist().size() == 1) {
|
||||||
});
|
// Add constraint for main method
|
||||||
|
var firstParam = m.getParameterList().getParameterAt(0);
|
||||||
|
|
||||||
|
constraintSet.addUndConstraint(new Pair(firstParam.getType(),
|
||||||
|
new RefType(new JavaClassName("java.util.List"),
|
||||||
|
List.of(new RefType(new JavaClassName("java.lang.String"), new NullToken())),
|
||||||
|
new NullToken()),
|
||||||
|
PairOperator.EQUALSDOT));
|
||||||
|
} else {
|
||||||
|
m.getParameterList().getFormalparalist().forEach(el -> {
|
||||||
|
if (el instanceof RecordPattern rp){
|
||||||
|
constraintSet.addAll(addRecursiveParameterConstraints(rp, blockInfo));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
m.block.accept(methodScope);
|
m.block.accept(methodScope);
|
||||||
constraintSet.addAll(methodScope.getConstraints());
|
constraintSet.addAll(methodScope.getConstraints());
|
||||||
return constraintSet;
|
return constraintSet;
|
||||||
@@ -100,25 +119,32 @@ public class TYPE {
|
|||||||
ConstraintSet constraintSet = new ConstraintSet();
|
ConstraintSet constraintSet = new ConstraintSet();
|
||||||
|
|
||||||
var subPatternList = recordPattern.getSubPattern();
|
var subPatternList = recordPattern.getSubPattern();
|
||||||
|
var resolver = new GenericsResolverSameName();
|
||||||
|
var refType = (RefType) recordPattern.getType();
|
||||||
|
|
||||||
|
var allClasses = blockInformation.getAvailableClasses();
|
||||||
|
var typename = refType.getName().getClassName();
|
||||||
|
|
||||||
|
ClassOrInterface allClass = allClasses.stream().filter(c -> c.getClassName().getClassName().equals(typename)).findFirst().orElseThrow();
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for(Pattern el : subPatternList){
|
for (Pattern el : subPatternList){
|
||||||
|
if (el instanceof RecordPattern){
|
||||||
if(el instanceof RecordPattern){
|
|
||||||
constraintSet.addAll(addRecursiveParameterConstraints((RecordPattern) el, blockInformation));
|
constraintSet.addAll(addRecursiveParameterConstraints((RecordPattern) el, blockInformation));
|
||||||
}else{
|
} else {
|
||||||
var allClasses = blockInformation.getAvailableClasses();
|
FormalParameter param = (FormalParameter) allClass.getConstructors().getFirst().getParameterList().getParameterAt(counter);
|
||||||
RefTypeOrTPHOrWildcardOrGeneric type;
|
FieldAssumption assumption = new FieldAssumption(param.getName(), allClass, param.getType(), blockInformation.getCurrentTypeScope());
|
||||||
|
|
||||||
for (ClassOrInterface allClass : allClasses) {
|
var fieldCons = new Pair(el.getType(), assumption.getType(resolver), PairOperator.SMALLERDOT);
|
||||||
var typename = recordPattern.getType().toString();
|
var recvCons = new Pair(refType, assumption.getReceiverType(resolver), PairOperator.EQUALSDOT);
|
||||||
var className = allClass.getClassName().getClassName();
|
constraintSet.addUndConstraint(fieldCons);
|
||||||
if(className.equals(typename)){
|
constraintSet.addUndConstraint(recvCons);
|
||||||
type = allClass.getConstructors().get(0).getParameterList().getParameterAt(counter).getType();
|
|
||||||
constraintSet.addUndConstraint(new Pair(el.getType(), type, PairOperator.SMALLERDOT, new SourceLoc(blockInformation.getCurrentClass().getFileName(), el.getOffset().getLine())));
|
for (var i = 0; i < refType.getParaList().size(); i++) {
|
||||||
}
|
constraintSet.addUndConstraint(new Pair(refType.getParaList().get(i),
|
||||||
|
((RefType)assumption.getReceiverType(resolver)).getParaList().get(i),
|
||||||
|
PairOperator.EQUALSDOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
TypePlaceholder tphRetType = TypePlaceholder.fresh(new NullToken());
|
TypePlaceholder tphRetType = TypePlaceholder.fresh(new NullToken(), -1, false);
|
||||||
List<RefTypeOrTPHOrWildcardOrGeneric> lambdaParams = lambdaExpression.params.getFormalparalist().stream().map((formalParameter -> formalParameter.getType())).collect(Collectors.toList());
|
List<RefTypeOrTPHOrWildcardOrGeneric> lambdaParams = lambdaExpression.params.getFormalparalist().stream().map((formalParameter -> formalParameter.getType())).collect(Collectors.toList());
|
||||||
lambdaParams.add(tphRetType);
|
lambdaParams.add(tphRetType);
|
||||||
// lambdaParams.add(0,tphRetType);
|
// lambdaParams.add(0,tphRetType);
|
||||||
@@ -635,6 +635,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
params.add(resolver.resolve(new GenericRefType(gtv.getName(), new NullToken())));
|
||||||
}
|
}
|
||||||
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
RefTypeOrTPHOrWildcardOrGeneric receiverType;
|
||||||
|
|
||||||
if (receiver instanceof FunNClass) {
|
if (receiver instanceof FunNClass) {
|
||||||
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString() + "$$"), params, new NullToken()); // new FunN(params);
|
receiverType = new RefType(new JavaClassName(receiver.getClassName().toString() + "$$"), params, new NullToken()); // new FunN(params);
|
||||||
} else {
|
} else {
|
||||||
@@ -841,7 +842,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
for (var child : switchStmt.getBlocks()) {
|
for (var child : switchStmt.getBlocks()) {
|
||||||
for (var label : child.getLabels()) {
|
for (var label : child.getLabels()) {
|
||||||
if (label.getPattern() == null) {
|
if (label.getPattern() == null) {
|
||||||
System.out.println("DefaultCase");
|
//System.out.println("DefaultCase");
|
||||||
} else {
|
} else {
|
||||||
constraintsSet.addUndConstraint(
|
constraintsSet.addUndConstraint(
|
||||||
new Pair(
|
new Pair(
|
||||||
@@ -910,10 +911,11 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
|
|
||||||
for (var subPattern : pattern.getSubPattern()) {
|
for (var subPattern : pattern.getSubPattern()) {
|
||||||
for (Constructor con : constructors) {
|
for (Constructor con : constructors) {
|
||||||
System.out.println("----------------------\n" + subPattern.getType() + " | " + con.getParameterList().getParameterAt(counter).getType() + "\n----------------------\n");
|
//System.out.println("----------------------\n" + subPattern.getType() + " | " + con.getParameterList().getParameterAt(counter).getType() + "\n----------------------\n");
|
||||||
constraintsSet.addUndConstraint(new Pair(subPattern.getType(), con.getParameterList().getParameterAt(counter).getType(), PairOperator.SMALLERDOT, loc(con.getParameterList().getParameterAt(counter).getOffset())));
|
constraintsSet.addUndConstraint(new Pair(subPattern.getType(), con.getParameterList().getParameterAt(counter).getType(), PairOperator.SMALLERDOT, loc(con.getParameterList().getParameterAt(counter).getOffset())));
|
||||||
}
|
}
|
||||||
if (subPattern instanceof RecordPattern) recursivelyAddRecordConstraints((RecordPattern) subPattern);
|
if (subPattern instanceof RecordPattern) recursivelyAddRecordConstraints((RecordPattern) subPattern);
|
||||||
|
else if (subPattern instanceof LiteralPattern lp) lp.value.accept(this);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ class Node<T> {
|
|||||||
addDescendant(descendant);
|
addDescendant(descendant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||||
*/
|
*/
|
||||||
@@ -73,7 +73,7 @@ class Node<T> {
|
|||||||
addPredecessor(predecessor);
|
addPredecessor(predecessor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The content of this node.
|
* The content of this node.
|
||||||
*/
|
*/
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static targetast.TestCodegen.generateClassFiles;
|
import static targetast.TestCodegen.generateClassFiles;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -9,13 +9,12 @@ import java.net.URL;
|
|||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
|
||||||
|
|
||||||
public class AllgemeinTest {
|
public class AllgemeinTest {
|
||||||
|
|
||||||
@@ -64,11 +63,11 @@ public class AllgemeinTest {
|
|||||||
//String className = "Cycle";
|
//String className = "Cycle";
|
||||||
//String className = "TripleTest";
|
//String className = "TripleTest";
|
||||||
//String className = "WildcardList";
|
//String className = "WildcardList";
|
||||||
//String className = "List";
|
String className = "List";
|
||||||
//String className = "Box";
|
//String className = "Box";
|
||||||
//String className = "GenBox";
|
//String className = "GenBox";
|
||||||
//String className = "InnerInf";
|
//String className = "InnerInf";
|
||||||
String className = "Foo";
|
//String className = "Foo";
|
||||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
||||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
@@ -6,12 +6,12 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class GenericsParserTest {
|
public class GenericsParserTest {
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,7 +24,7 @@ public class TestPackages {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("This doesn't work")
|
@Disabled("This doesn't work")
|
||||||
public void testPackagesCircular() throws Exception {
|
public void testPackagesCircular() throws Exception {
|
||||||
var cmp = new JavaTXCompiler(
|
var cmp = new JavaTXCompiler(
|
||||||
List.of(
|
List.of(
|
||||||
|
@@ -4,7 +4,7 @@ import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@@ -4,7 +4,7 @@ package astfactory;
|
|||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@@ -12,7 +12,8 @@ import java.lang.reflect.TypeVariable;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
|
||||||
public class ASTFactoryTest<A> extends HashMap<String, A>{
|
public class ASTFactoryTest<A> extends HashMap<String, A>{
|
||||||
@Test
|
@Test
|
||||||
|
@@ -3,7 +3,7 @@ package finiteClosure;
|
|||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.FCGenerator;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
5
src/test/java/languageServerInterfaceTest/test.jav
Normal file
5
src/test/java/languageServerInterfaceTest/test.jav
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
public class t{
|
||||||
|
public mofus(){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,9 +1,5 @@
|
|||||||
package syntaxtreegenerator;
|
package syntaxtreegenerator;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -12,21 +8,23 @@ import java.io.ObjectOutputStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit-Tests für den 'SyntaxTreeGenerator' aus dem Package 'parser' nach Vorbild der Klasse 'TestComplete' aus dem Test-Package 'targetast'
|
* Unit-Tests für den 'SyntaxTreeGenerator' aus dem Package 'parser' nach Vorbild der Klasse 'TestComplete' aus dem Test-Package 'targetast'
|
||||||
*/
|
*/
|
||||||
public class TestComplete {
|
public class TestComplete {
|
||||||
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
final String testFileDirectory = "resources/bytecode/javFiles/";
|
final String testFileDirectory = "resources/bytecode/javFiles/";
|
||||||
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
||||||
@@ -353,7 +351,7 @@ public class TestComplete {
|
|||||||
assertEquals("Comparing expected and resulting AST for mathStrucInteger.jav", expectedAST, resultingAST);
|
assertEquals("Comparing expected and resulting AST for mathStrucInteger.jav", expectedAST, resultingAST);
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
assertTrue("An error occured while generating the AST for mathStrucInteger.jav", exc instanceof NotImplementedException);
|
assertInstanceOf(NotImplementedException.class, exc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
package syntaxtreegenerator;
|
package syntaxtreegenerator;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
@@ -17,7 +17,7 @@ import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
|||||||
public class TestNewFeatures {
|
public class TestNewFeatures {
|
||||||
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
final String testFileDirectory = "resources/syntaxtreegenerator/javFiles/";
|
final String testFileDirectory = "resources/syntaxtreegenerator/javFiles/";
|
||||||
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
||||||
|
@@ -2,7 +2,6 @@ package targetast;
|
|||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
@@ -10,13 +9,13 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
import de.dhbwstuttgart.target.tree.TargetStructure;
|
import de.dhbwstuttgart.target.tree.TargetStructure;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class ASTToTypedTargetAST {
|
public class ASTToTypedTargetAST {
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ public class ASTToTypedTargetAST {
|
|||||||
public void emptyClass() {
|
public void emptyClass() {
|
||||||
ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), Optional.empty(), Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), new RefType(new JavaClassName("Object"), new NullToken()), false, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
|
ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), Optional.empty(), Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), new RefType(new JavaClassName("Object"), new NullToken()), false, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
|
||||||
ResultSet emptyResultSet = new ResultSet(new HashSet<>());
|
ResultSet emptyResultSet = new ResultSet(new HashSet<>());
|
||||||
TargetStructure emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass);
|
TargetStructure emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet), TestCodegen.createClassLoader()).convert(emptyClass);
|
||||||
assert emptyTargetClass.getName().equals("EmptyClass");
|
assert emptyTargetClass.getName().equals("EmptyClass");
|
||||||
assert emptyTargetClass.methods().size() == 0;
|
assert emptyTargetClass.methods().size() == 0;
|
||||||
assert emptyTargetClass.fields().size() == 0;
|
assert emptyTargetClass.fields().size() == 0;
|
||||||
@@ -32,13 +31,14 @@ public class ASTToTypedTargetAST {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void overloading() throws Exception {
|
public void overloading() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Overloading.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Overloading.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var classLoader = new ByteArrayClassLoader();
|
|
||||||
var overloading = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
var overloading = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
var overloading2 = TestCodegen.generateClass(converter.convert(classes.get(1)), classLoader);
|
var overloading2 = TestCodegen.generateClass(converter.convert(classes.get(1)), classLoader);
|
||||||
|
|
||||||
@@ -54,46 +54,54 @@ public class ASTToTypedTargetAST {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tphsAndGenerics() throws Exception {
|
public void tphsAndGenerics() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Tph2.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Tph2.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var tphAndGenerics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var tphAndGenerics = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cycles() throws Exception {
|
public void cycles() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var cycle = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var cycle = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void infimum() throws Exception {
|
public void infimum() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Infimum.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Infimum.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var infimum = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var infimum = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gen() throws Exception {
|
public void gen() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Gen.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Gen.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), TestCodegen.createClassLoader());
|
||||||
var m = generics.getDeclaredMethod("m", Vector.class);
|
var m = generics.getDeclaredMethod("m", Vector.class);
|
||||||
var mReturnType = m.getGenericReturnType();
|
var mReturnType = m.getGenericReturnType();
|
||||||
assertEquals(mReturnType, m.getParameters()[0].getParameterizedType());
|
assertEquals(mReturnType, m.getParameters()[0].getParameterizedType());
|
||||||
@@ -103,13 +111,15 @@ public class ASTToTypedTargetAST {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void definedGenerics() throws Exception {
|
public void definedGenerics() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
var B = generics.getTypeParameters()[0];
|
var B = generics.getTypeParameters()[0];
|
||||||
var mt1 = generics.getDeclaredMethod("mt1", Object.class);
|
var mt1 = generics.getDeclaredMethod("mt1", Object.class);
|
||||||
var constructor = generics.getDeclaredConstructor(Object.class);
|
var constructor = generics.getDeclaredConstructor(Object.class);
|
||||||
@@ -121,13 +131,15 @@ public class ASTToTypedTargetAST {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void definedGenerics2() throws Exception {
|
public void definedGenerics2() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics2.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics2.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics2 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics2 = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
assertEquals(generics2.getTypeParameters()[0].getBounds()[0], String.class);
|
assertEquals(generics2.getTypeParameters()[0].getBounds()[0], String.class);
|
||||||
var m = generics2.getDeclaredMethod("m1", Object.class);
|
var m = generics2.getDeclaredMethod("m1", Object.class);
|
||||||
assertEquals(m.getTypeParameters()[0].getBounds()[0], Integer.class);
|
assertEquals(m.getTypeParameters()[0].getBounds()[0], Integer.class);
|
||||||
@@ -135,26 +147,30 @@ public class ASTToTypedTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Not implemented")
|
@Disabled("Not implemented")
|
||||||
public void definedGenerics3() throws Exception {
|
public void definedGenerics3() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics3.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics3.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics3 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics3 = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void definedGenerics4() throws Exception {
|
public void definedGenerics4() throws Exception {
|
||||||
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics4.jav").toFile();
|
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics4.jav").toFile();
|
||||||
var compiler = new JavaTXCompiler(file);
|
var compiler = new JavaTXCompiler(file);
|
||||||
var resultSet = compiler.typeInference(file);
|
var resultSet = compiler.typeInference(file);
|
||||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
var converter = new ASTToTargetAST(compiler, resultSet, classLoader);
|
||||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||||
|
|
||||||
var generics4 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
var generics4 = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||||
|
|
||||||
// var instance = generics4.getDeclaredConstructor().newInstance();
|
// var instance = generics4.getDeclaredConstructor().newInstance();
|
||||||
// var method = generics4.getDeclaredMethod("m2", Object.class);
|
// var method = generics4.getDeclaredMethod("m2", Object.class);
|
||||||
|
@@ -1,22 +1,21 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class GreaterEqualTest {
|
public class GreaterEqualTest {
|
||||||
static Class<?> classToTest;
|
static Class<?> classToTest;
|
||||||
static Object instance;
|
static Object instance;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "GreaterEqual.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "GreaterEqual.jav");
|
||||||
classToTest = classFiles.get("GreaterEqual");
|
classToTest = classFiles.get("GreaterEqual");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,21 +1,20 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class GreaterThanTest {
|
public class GreaterThanTest {
|
||||||
static Class<?> classToTest;
|
static Class<?> classToTest;
|
||||||
static Object instance;
|
static Object instance;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "GreaterThan.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "GreaterThan.jav");
|
||||||
classToTest = classFiles.get("GreaterThan");
|
classToTest = classFiles.get("GreaterThan");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +1,20 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class InheritTest {
|
public class InheritTest {
|
||||||
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classLoader = new ByteArrayClassLoader();
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
|
|
||||||
var classes = TestCodegen.generateClassFiles(classLoader, "Inherit.jav");
|
var classes = TestCodegen.generateClassFiles(classLoader, "Inherit.jav");
|
||||||
classToTest = classes.get("Inherit");
|
classToTest = classes.get("Inherit");
|
||||||
@@ -35,72 +33,72 @@ public class InheritTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testmainAA() throws Exception {
|
public void testmainAA() throws Exception {
|
||||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
assertEquals("AA", m.invoke(instanceOfClassAA, 5));
|
||||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
assertEquals("AA", main.invoke(instanceOfClass, instanceOfClassAA, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainBB() throws Exception {
|
public void testmainBB() throws Exception {
|
||||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
assertEquals("AA", m.invoke(instanceOfClassBB, 5));
|
||||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB, 5), "AA");
|
assertEquals("AA", main.invoke(instanceOfClass, instanceOfClassBB, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainCC() throws Exception {
|
public void testmainCC() throws Exception {
|
||||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
assertEquals("CC", m.invoke(instanceOfClassCC, 5));
|
||||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC, 5), "CC");
|
assertEquals("CC", main.invoke(instanceOfClass, instanceOfClassCC, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainDD() throws Exception {
|
public void testmainDD() throws Exception {
|
||||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
assertEquals("CC", m.invoke(instanceOfClassDD, 5));
|
||||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD, 5), "CC");
|
assertEquals("CC", main.invoke(instanceOfClass, instanceOfClassDD, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainVectorAA() throws Exception {
|
public void testmainVectorAA() throws Exception {
|
||||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
assertEquals("AA", m.invoke(instanceOfClassAA, 5));
|
||||||
Vector v = new Vector<>();
|
Vector v = new Vector<>();
|
||||||
v.add(instanceOfClassAA);
|
v.add(instanceOfClassAA);
|
||||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
assertEquals("AA", main.invoke(instanceOfClass, v, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainVectorBB() throws Exception {
|
public void testmainVectorBB() throws Exception {
|
||||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
assertEquals("AA", m.invoke(instanceOfClassBB, 5));
|
||||||
Vector v = new Vector<>();
|
Vector v = new Vector<>();
|
||||||
v.add(instanceOfClassBB);
|
v.add(instanceOfClassBB);
|
||||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
assertEquals("AA", main.invoke(instanceOfClass, v, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainVectorCC() throws Exception {
|
public void testmainVectorCC() throws Exception {
|
||||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
assertEquals("CC", m.invoke(instanceOfClassCC, 5));
|
||||||
Vector v = new Vector<>();
|
Vector v = new Vector<>();
|
||||||
v.add(instanceOfClassCC);
|
v.add(instanceOfClassCC);
|
||||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
assertEquals("CC", main.invoke(instanceOfClass, v, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testmainVectorDD() throws Exception {
|
public void testmainVectorDD() throws Exception {
|
||||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||||
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
assertEquals("CC", m.invoke(instanceOfClassDD, 5));
|
||||||
Vector v = new Vector<>();
|
Vector v = new Vector<>();
|
||||||
v.add(instanceOfClassDD);
|
v.add(instanceOfClassDD);
|
||||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||||
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
assertEquals("CC", main.invoke(instanceOfClass, v, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,22 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@Ignore("FIXME")
|
@Disabled("FIXME")
|
||||||
public class InheritTest2 {
|
public class InheritTest2 {
|
||||||
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||||
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classLoader = new ByteArrayClassLoader();
|
var classLoader = TestCodegen.createClassLoader();
|
||||||
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit2.jav").get("Inherit2");
|
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit2.jav").get("Inherit2");
|
||||||
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
|
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
|
||||||
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
|
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
|
||||||
|
@@ -1,21 +1,20 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class LessEqualTest {
|
public class LessEqualTest {
|
||||||
static Class<?> classToTest;
|
static Class<?> classToTest;
|
||||||
static Object instance;
|
static Object instance;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "LessEqual.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "LessEqual.jav");
|
||||||
classToTest = classFiles.get("LessEqual");
|
classToTest = classFiles.get("LessEqual");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,21 +1,20 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class LessThanTest {
|
public class LessThanTest {
|
||||||
static Class<?> classToTest;
|
static Class<?> classToTest;
|
||||||
static Object instance;
|
static Object instance;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "LessThan.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "LessThan.jav");
|
||||||
classToTest = classFiles.get("LessThan");
|
classToTest = classFiles.get("LessThan");
|
||||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
public class OLTest {
|
public class OLTest {
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
@@ -14,9 +14,9 @@ public class OLTest {
|
|||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
private static Object instanceOfClass1;
|
private static Object instanceOfClass1;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "OL.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "OL.jav");
|
||||||
classToTest = classFiles.get("OL");
|
classToTest = classFiles.get("OL");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
classToTest1 = classFiles.get("OLMain");
|
classToTest1 = classFiles.get("OLMain");
|
||||||
|
@@ -1,20 +1,19 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class PostIncTest {
|
public class PostIncTest {
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "PostIncDec.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "PostIncDec.jav");
|
||||||
classToTest = classFiles.get("PostIncDec");
|
classToTest = classFiles.get("PostIncDec");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,19 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class PreIncTest {
|
public class PreIncTest {
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "PreInc.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "PreInc.jav");
|
||||||
classToTest = classFiles.get("PreInc");
|
classToTest = classFiles.get("PreInc");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,22 +1,21 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class PutTest {
|
public class PutTest {
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Put.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "Put.jav");
|
||||||
classToTest = classFiles.get("Put");
|
classToTest = classFiles.get("Put");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@ package targetast;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.bytecode.Codegen;
|
import de.dhbwstuttgart.bytecode.Codegen;
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||||
@@ -14,10 +14,10 @@ import de.dhbwstuttgart.target.tree.expression.*;
|
|||||||
import de.dhbwstuttgart.target.tree.type.TargetFunNType;
|
import de.dhbwstuttgart.target.tree.type.TargetFunNType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
@@ -37,6 +37,10 @@ public class TestCodegen {
|
|||||||
Files.write(outputPath.resolve(name + ".class"), code);
|
Files.write(outputPath.resolve(name + ".class"), code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IByteArrayClassLoader createClassLoader() {
|
||||||
|
return new DirectoryClassLoader(List.of(outputPath.toFile()), ClassLoader.getSystemClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
public static Path path = Path.of(System.getProperty("user.dir"), "resources/bytecode/javFiles/");
|
public static Path path = Path.of(System.getProperty("user.dir"), "resources/bytecode/javFiles/");
|
||||||
|
|
||||||
public static Map<String, ? extends Class<?>> generateClassFiles(IByteArrayClassLoader classLoader, String... files) throws IOException, ClassNotFoundException {
|
public static Map<String, ? extends Class<?>> generateClassFiles(IByteArrayClassLoader classLoader, String... files) throws IOException, ClassNotFoundException {
|
||||||
@@ -62,7 +66,7 @@ public class TestCodegen {
|
|||||||
|
|
||||||
converter.generateFunNTypes();
|
converter.generateFunNTypes();
|
||||||
|
|
||||||
for (var entry : converter.auxiliaries.entrySet()) {
|
for (var entry : compiler.auxiliaries.entrySet()) {
|
||||||
writeClassFile(entry.getKey(), entry.getValue());
|
writeClassFile(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +112,7 @@ public class TestCodegen {
|
|||||||
|
|
||||||
converter.generateFunNTypes();
|
converter.generateFunNTypes();
|
||||||
|
|
||||||
for (var entry : converter.auxiliaries.entrySet()) {
|
for (var entry : compiler.auxiliaries.entrySet()) {
|
||||||
writeClassFile(entry.getKey(), entry.getValue());
|
writeClassFile(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +123,7 @@ public class TestCodegen {
|
|||||||
public void testEmptyClass() throws Exception {
|
public void testEmptyClass() throws Exception {
|
||||||
var clazz = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Empty"));
|
var clazz = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Empty"));
|
||||||
clazz.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "main", List.of(), null, new TargetBlock(List.of()));
|
clazz.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "main", List.of(), null, new TargetBlock(List.of()));
|
||||||
generateClass(clazz, new ByteArrayClassLoader()).getDeclaredMethod("main").invoke(null);
|
generateClass(clazz, createClassLoader()).getDeclaredMethod("main").invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -132,7 +136,7 @@ public class TestCodegen {
|
|||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "mul", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Mul(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "mul", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Mul(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "rem", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Rem(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "rem", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Rem(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||||
|
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
assertEquals(clazz.getDeclaredMethod("add", Integer.class, Integer.class).invoke(null, 10, 10), 20);
|
assertEquals(clazz.getDeclaredMethod("add", Integer.class, Integer.class).invoke(null, 10, 10), 20);
|
||||||
assertEquals(clazz.getDeclaredMethod("sub", Integer.class, Integer.class).invoke(null, 20, 10), 10);
|
assertEquals(clazz.getDeclaredMethod("sub", Integer.class, Integer.class).invoke(null, 20, 10), 10);
|
||||||
assertEquals(clazz.getDeclaredMethod("div", Integer.class, Integer.class).invoke(null, 20, 10), 2);
|
assertEquals(clazz.getDeclaredMethod("div", Integer.class, Integer.class).invoke(null, 20, 10), 2);
|
||||||
@@ -148,7 +152,7 @@ public class TestCodegen {
|
|||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "neg", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Negate(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "neg", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Negate(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
||||||
|
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
assertEquals(clazz.getDeclaredMethod("not", Integer.class).invoke(null, 10), -11);
|
assertEquals(clazz.getDeclaredMethod("not", Integer.class).invoke(null, 10), -11);
|
||||||
assertEquals(clazz.getDeclaredMethod("neg", Integer.class).invoke(null, 10), -10);
|
assertEquals(clazz.getDeclaredMethod("neg", Integer.class).invoke(null, 10), -10);
|
||||||
assertEquals(clazz.getDeclaredMethod("add", Integer.class).invoke(null, 10), 10);
|
assertEquals(clazz.getDeclaredMethod("add", Integer.class).invoke(null, 10), 10);
|
||||||
@@ -162,7 +166,7 @@ public class TestCodegen {
|
|||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "and", List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(TargetType.Boolean, "b")), TargetType.Boolean, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.And(TargetType.Boolean, new TargetLocalVar(TargetType.Boolean, "a"), new TargetLocalVar(TargetType.Boolean, "b"))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "and", List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(TargetType.Boolean, "b")), TargetType.Boolean, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.And(TargetType.Boolean, new TargetLocalVar(TargetType.Boolean, "a"), new TargetLocalVar(TargetType.Boolean, "b"))))));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "or", List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(TargetType.Boolean, "b")), TargetType.Boolean, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Or(TargetType.Boolean, new TargetLocalVar(TargetType.Boolean, "a"), new TargetLocalVar(TargetType.Boolean, "b"))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "or", List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(TargetType.Boolean, "b")), TargetType.Boolean, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Or(TargetType.Boolean, new TargetLocalVar(TargetType.Boolean, "a"), new TargetLocalVar(TargetType.Boolean, "b"))))));
|
||||||
|
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
var and = clazz.getDeclaredMethod("and", Boolean.class, Boolean.class);
|
var and = clazz.getDeclaredMethod("and", Boolean.class, Boolean.class);
|
||||||
var or = clazz.getDeclaredMethod("or", Boolean.class, Boolean.class);
|
var or = clazz.getDeclaredMethod("or", Boolean.class, Boolean.class);
|
||||||
assertEquals(and.invoke(null, true, false), false);
|
assertEquals(and.invoke(null, true, false), false);
|
||||||
@@ -176,7 +180,7 @@ public class TestCodegen {
|
|||||||
public void testArithmeticConvert() throws Exception {
|
public void testArithmeticConvert() throws Exception {
|
||||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("ArithmeticConvert"));
|
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("ArithmeticConvert"));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(), TargetType.Long, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Add(TargetType.Long, new TargetLiteral.CharLiteral((char) 10), new TargetLiteral.LongLiteral((long) 20))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(), TargetType.Long, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Add(TargetType.Long, new TargetLiteral.CharLiteral((char) 10), new TargetLiteral.LongLiteral((long) 20))))));
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
assertEquals(clazz.getDeclaredMethod("add").invoke(null), (long) 30);
|
assertEquals(clazz.getDeclaredMethod("add").invoke(null), (long) 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +189,7 @@ public class TestCodegen {
|
|||||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("HelloWorld"));
|
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("HelloWorld"));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "helloWorld", List.of(), null, new TargetBlock(List.of(new TargetMethodCall(null, new TargetFieldVar(new TargetRefType("java.io.PrintStream"), new TargetRefType("java.lang.System"), true, new TargetClassName(new TargetRefType("java.lang.System")), "out"), List.of(new TargetLiteral.StringLiteral("Hello World!")), new TargetRefType("java.io.PrintStream"), "println", false, false, false))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "helloWorld", List.of(), null, new TargetBlock(List.of(new TargetMethodCall(null, new TargetFieldVar(new TargetRefType("java.io.PrintStream"), new TargetRefType("java.lang.System"), true, new TargetClassName(new TargetRefType("java.lang.System")), "out"), List.of(new TargetLiteral.StringLiteral("Hello World!")), new TargetRefType("java.io.PrintStream"), "println", false, false, false))));
|
||||||
|
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
clazz.getDeclaredMethod("helloWorld").invoke(null);
|
clazz.getDeclaredMethod("helloWorld").invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +197,7 @@ public class TestCodegen {
|
|||||||
public void testIfStatement() throws Exception {
|
public void testIfStatement() throws Exception {
|
||||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("IfStmt"));
|
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("IfStmt"));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "ifStmt", List.of(new MethodParameter(TargetType.Integer, "val")), TargetType.Integer, new TargetBlock(List.of(new TargetIf(new TargetBinaryOp.Equal(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "val"), new TargetLiteral.IntLiteral(10)), new TargetReturn(new TargetLiteral.IntLiteral(1)), new TargetIf(new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "val"), new TargetLiteral.IntLiteral(5)), new TargetReturn(new TargetLiteral.IntLiteral(2)), new TargetReturn(new TargetLiteral.IntLiteral(3)))))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "ifStmt", List.of(new MethodParameter(TargetType.Integer, "val")), TargetType.Integer, new TargetBlock(List.of(new TargetIf(new TargetBinaryOp.Equal(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "val"), new TargetLiteral.IntLiteral(10)), new TargetReturn(new TargetLiteral.IntLiteral(1)), new TargetIf(new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "val"), new TargetLiteral.IntLiteral(5)), new TargetReturn(new TargetLiteral.IntLiteral(2)), new TargetReturn(new TargetLiteral.IntLiteral(3)))))));
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
var ifStmt = clazz.getDeclaredMethod("ifStmt", Integer.class);
|
var ifStmt = clazz.getDeclaredMethod("ifStmt", Integer.class);
|
||||||
assertEquals(ifStmt.invoke(null, 10), 1);
|
assertEquals(ifStmt.invoke(null, 10), 1);
|
||||||
assertEquals(ifStmt.invoke(null, 3), 2);
|
assertEquals(ifStmt.invoke(null, 3), 2);
|
||||||
@@ -204,7 +208,7 @@ public class TestCodegen {
|
|||||||
public void testFor() throws Exception {
|
public void testFor() throws Exception {
|
||||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("For"));
|
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("For"));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "forLoop", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(TargetType.Integer, "sum", new TargetLiteral.IntLiteral(0)), new TargetFor(List.of(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0))), new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(1)))), new TargetBlock(List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "sum"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "sum"), new TargetLocalVar(TargetType.Integer, "i")))))), new TargetReturn(new TargetLocalVar(TargetType.Integer, "sum")))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "forLoop", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(TargetType.Integer, "sum", new TargetLiteral.IntLiteral(0)), new TargetFor(List.of(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0))), new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(1)))), new TargetBlock(List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "sum"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "sum"), new TargetLocalVar(TargetType.Integer, "i")))))), new TargetReturn(new TargetLocalVar(TargetType.Integer, "sum")))));
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
assertEquals(clazz.getDeclaredMethod("forLoop").invoke(null), 45);
|
assertEquals(clazz.getDeclaredMethod("forLoop").invoke(null), 45);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +216,7 @@ public class TestCodegen {
|
|||||||
public void testWhile() throws Exception {
|
public void testWhile() throws Exception {
|
||||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("While"));
|
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("While"));
|
||||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "whileLoop", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0)), new TargetWhile(new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), new TargetBlock(List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(1)))))), new TargetReturn(new TargetLocalVar(TargetType.Integer, "i")))));
|
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "whileLoop", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0)), new TargetWhile(new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), new TargetBlock(List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(1)))))), new TargetReturn(new TargetLocalVar(TargetType.Integer, "i")))));
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
assertEquals(clazz.getDeclaredMethod("whileLoop").invoke(null), 10);
|
assertEquals(clazz.getDeclaredMethod("whileLoop").invoke(null), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +239,7 @@ public class TestCodegen {
|
|||||||
new TargetReturn(new TargetLocalVar(TargetType.Integer, "res"))
|
new TargetReturn(new TargetLocalVar(TargetType.Integer, "res"))
|
||||||
)));
|
)));
|
||||||
|
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
var m = clazz.getDeclaredMethod("switchClassic", Integer.class);
|
var m = clazz.getDeclaredMethod("switchClassic", Integer.class);
|
||||||
assertEquals(m.invoke(null, 10), 0);
|
assertEquals(m.invoke(null, 10), 0);
|
||||||
assertEquals(m.invoke(null, 15), 1);
|
assertEquals(m.invoke(null, 15), 1);
|
||||||
@@ -264,7 +268,7 @@ public class TestCodegen {
|
|||||||
List.of(new TargetLiteral.IntLiteral(2))
|
List.of(new TargetLiteral.IntLiteral(2))
|
||||||
), true), TargetType.Integer)
|
), true), TargetType.Integer)
|
||||||
))));
|
))));
|
||||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
var clazz = generateClass(targetClass, createClassLoader());
|
||||||
var m = clazz.getDeclaredMethod("switchType", Object.class);
|
var m = clazz.getDeclaredMethod("switchType", Object.class);
|
||||||
assertEquals(m.invoke(null, "String"), 0);
|
assertEquals(m.invoke(null, "String"), 0);
|
||||||
assertEquals(m.invoke(null, 10), 1);
|
assertEquals(m.invoke(null, 10), 1);
|
||||||
@@ -273,9 +277,9 @@ public class TestCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("The lambda class is not generated because we don't call ASTToTargetAST")
|
@Disabled("The lambda class is not generated because we don't call ASTToTargetAST")
|
||||||
public void testLambda() throws Exception {
|
public void testLambda() throws Exception {
|
||||||
var classLoader = new ByteArrayClassLoader();
|
var classLoader = createClassLoader();
|
||||||
// var fun = classLoader.loadClass(Path.of(System.getProperty("user.dir"), "src/test/java/targetast/Fun1$$.class"));
|
// var fun = classLoader.loadClass(Path.of(System.getProperty("user.dir"), "src/test/java/targetast/Fun1$$.class"));
|
||||||
var interfaceType = TargetFunNType.fromParams(List.of(TargetType.Integer), 1);
|
var interfaceType = TargetFunNType.fromParams(List.of(TargetType.Integer), 1);
|
||||||
|
|
||||||
|
@@ -12,9 +12,9 @@ import de.dhbwstuttgart.target.generate.Bound;
|
|||||||
import static de.dhbwstuttgart.target.generate.Bound.*;
|
import static de.dhbwstuttgart.target.generate.Bound.*;
|
||||||
import de.dhbwstuttgart.target.generate.BoundsList;
|
import de.dhbwstuttgart.target.generate.BoundsList;
|
||||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -22,7 +22,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Ignore("TODO: Rewrite with the new algorithm")
|
@Disabled("TODO: Rewrite with the new algorithm")
|
||||||
public class TestGenerics {
|
public class TestGenerics {
|
||||||
private static final String rootDirectory = System.getProperty("user.dir") + "/resources/insertGenerics/javFiles/";
|
private static final String rootDirectory = System.getProperty("user.dir") + "/resources/insertGenerics/javFiles/";
|
||||||
private static final String bytecodeDirectory = System.getProperty("user.dir") + "targetTest";
|
private static final String bytecodeDirectory = System.getProperty("user.dir") + "targetTest";
|
||||||
|
@@ -1,21 +1,21 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
|
||||||
public class TphTest {
|
public class TphTest {
|
||||||
|
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Tph.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "Tph.jav");
|
||||||
classToTest = classFiles.get("Tph");
|
classToTest = classFiles.get("Tph");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +1,19 @@
|
|||||||
package targetast;
|
package targetast;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class WhileTest {
|
public class WhileTest {
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "While.jav");
|
var classFiles = TestCodegen.generateClassFiles(TestCodegen.createClassLoader(), "While.jav");
|
||||||
classToTest = classFiles.get("While");
|
classToTest = classFiles.get("While");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
}
|
}
|
||||||
|
@@ -8,8 +8,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsert;
|
|||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -22,7 +22,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Ignore("To be renewed")
|
@Disabled("To be renewed")
|
||||||
public class JavaTXCompilerTest {
|
public class JavaTXCompilerTest {
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
|
||||||
|
Reference in New Issue
Block a user