forked from i21017/JavaCompilerCore
Compare commits
30 Commits
feat/unify
...
feat/unify
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af15a1b90c | ||
| 814f5dd5fa | |||
| 24ca985ccc | |||
| d6ed0689bc | |||
| d7676f36e3 | |||
|
|
3d99f282f5 | ||
|
|
303c91dc87 | ||
|
|
9e323759d6 | ||
|
|
603a8b176a | ||
| 558083166d | |||
|
|
aec2f9a399 | ||
|
|
31df7a65f0 | ||
|
|
185989ba62 | ||
|
|
0eb48ba425 | ||
| ceee9a49c4 | |||
| ee64218a5f | |||
| c50f14a4a3 | |||
| 1f4250ff84 | |||
| ae41c7f19d | |||
| 2416c80c20 | |||
| 4cc55c0059 | |||
| 9434facfa0 | |||
| 09a6b9a788 | |||
| 8b342c5604 | |||
| cdb93b5155 | |||
| b07e848fa2 | |||
| 313cd20f36 | |||
| 567fcc3b9a | |||
| d9936e7197 | |||
| 8f194b3102 |
@@ -15,7 +15,7 @@ jobs:
|
|||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '23'
|
java-version: '24'
|
||||||
cache: 'maven'
|
cache: 'maven'
|
||||||
- name: Compile project
|
- name: Compile project
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
28
pom.xml
28
pom.xml
@@ -12,37 +12,37 @@ 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>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.java-websocket</groupId>
|
<groupId>org.java-websocket</groupId>
|
||||||
@@ -71,17 +71,17 @@ 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-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>23</source>
|
<source>24</source>
|
||||||
<target>23</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>
|
||||||
@@ -97,7 +97,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>
|
||||||
@@ -110,7 +110,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>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ 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.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.*;
|
||||||
@@ -87,14 +88,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() {
|
||||||
@@ -232,9 +235,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 +280,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 +765,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 +786,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,20 +795,21 @@ 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());
|
||||||
|
|
||||||
|
if (!state.isStatic)
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
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);
|
||||||
@@ -1521,7 +1538,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);
|
||||||
@@ -1535,7 +1552,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)
|
||||||
@@ -1581,9 +1598,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)
|
||||||
@@ -1597,7 +1636,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());
|
||||||
@@ -1607,6 +1649,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);
|
||||||
@@ -1713,7 +1757,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());
|
||||||
@@ -1745,7 +1789,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);
|
||||||
|
|||||||
@@ -401,10 +401,14 @@ public class JavaTXCompiler {
|
|||||||
logger.debug("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
logger.debug("\nUnify_distributeInnerVars: " + unifyCons.toString());
|
||||||
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
||||||
logger.debug("FC:\\" + finiteClosure.toString() + "\n");
|
logger.debug("FC:\\" + finiteClosure.toString() + "\n");
|
||||||
logger.debug(ASTTypePrinter.print(sf));
|
|
||||||
logger.info(ASTTypePrinter.print(sf));
|
logger.info(ASTTypePrinter.print(sf));
|
||||||
// logFile.flush();
|
// logFile.flush();
|
||||||
logger.info("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());
|
||||||
|
|
||||||
|
logger.info(andConstraintsSorted);
|
||||||
|
|
||||||
Set<PlaceholderType> varianceTPHold;
|
Set<PlaceholderType> varianceTPHold;
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||||
@@ -421,7 +425,6 @@ public class JavaTXCompiler {
|
|||||||
/*
|
/*
|
||||||
* Set<Set<UnifyPair>> ret = new HashSet<>(); for (Constraint<UnifyPair> y : x) { ret.add(new HashSet<>(y)); } return ret; }).collect(Collectors.toCollection(ArrayList::new))
|
* Set<Set<UnifyPair>> ret = new HashSet<>(); for (Constraint<UnifyPair> y : x) { ret.add(new HashSet<>(y)); } return ret; }).collect(Collectors.toCollection(ArrayList::new))
|
||||||
*/;
|
*/;
|
||||||
|
|
||||||
if (ConsoleInterface.unifyServerUrl.isPresent()) {
|
if (ConsoleInterface.unifyServerUrl.isPresent()) {
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyContext context = new UnifyContext(logger, true, urm, usedTasks, placeholderRegistry);
|
UnifyContext context = new UnifyContext(logger, true, urm, usedTasks, placeholderRegistry);
|
||||||
@@ -438,10 +441,14 @@ public class JavaTXCompiler {
|
|||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
UnifyContext context = new UnifyContext(logger, true, urm, usedTasks, placeholderRegistry);
|
UnifyContext context = new UnifyContext(logger, true, urm, usedTasks, placeholderRegistry);
|
||||||
TypeUnify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, context);
|
TypeUnify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, context);
|
||||||
logger.info("RESULT Final: " + li.getResults());
|
var finalResults = li.getResults().stream().sorted().toList();
|
||||||
logger.info("Constraints for Generated Generics: " + " ???");
|
int i = 0;
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
logger.info("RESULT Final: ");
|
||||||
// logFile.flush();
|
for (var result : finalResults){
|
||||||
|
logger.info("Result: " + i++);
|
||||||
|
logger.info(result.getSortedResults());
|
||||||
|
}
|
||||||
|
logger.info("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||||
return li.getResults();
|
return li.getResults();
|
||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
@@ -452,8 +459,6 @@ public class JavaTXCompiler {
|
|||||||
UnifyContext context = new UnifyContext(logger, false, new UnifyResultModel(cons, finiteClosure), usedTasks, placeholderRegistry);
|
UnifyContext context = new UnifyContext(logger, false, new UnifyResultModel(cons, finiteClosure), usedTasks, placeholderRegistry);
|
||||||
Set<Set<UnifyPair>> result = TypeUnify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, context);
|
Set<Set<UnifyPair>> result = TypeUnify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, context);
|
||||||
logger.info("RESULT: " + result);
|
logger.info("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString() + "\n");
|
|
||||||
// logFile.flush();
|
|
||||||
results.addAll(result);
|
results.addAll(result);
|
||||||
|
|
||||||
results = results.stream().map(x -> {
|
results = results.stream().map(x -> {
|
||||||
@@ -648,12 +653,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();
|
||||||
|
converter.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1100,9 +1100,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()),
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package de.dhbwstuttgart.server.packet.dataContainers.serialized;
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.annotation.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
public class SerialMap extends HashMap<String, ISerialNode> implements ISerialNode {
|
public class SerialMap extends HashMap<String, ISerialNode> implements ISerialNode {
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.dhbwstuttgart.target.generate;
|
|||||||
|
|
||||||
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.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@@ -12,6 +11,8 @@ 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.Target;
|
import de.dhbwstuttgart.target.Target;
|
||||||
import de.dhbwstuttgart.target.tree.*;
|
import de.dhbwstuttgart.target.tree.*;
|
||||||
import de.dhbwstuttgart.target.tree.expression.*;
|
import de.dhbwstuttgart.target.tree.expression.*;
|
||||||
@@ -67,11 +68,11 @@ public class ASTToTargetAST {
|
|||||||
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) {
|
||||||
@@ -782,7 +783,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;
|
||||||
@@ -819,14 +828,6 @@ public class ASTToTargetAST {
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
var code = FunNGenerator.generateSpecializedBytecode(gep, superInterfaces);
|
var code = FunNGenerator.generateSpecializedBytecode(gep, superInterfaces);
|
||||||
|
|
||||||
try {
|
|
||||||
classLoader.findClass(entry.getKey());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
try {
|
|
||||||
classLoader.loadClass(code);
|
|
||||||
} catch (LinkageError ignored) {}
|
|
||||||
}
|
|
||||||
auxiliaries.put(entry.getKey(), code);
|
auxiliaries.put(entry.getKey(), code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -857,7 +858,7 @@ public class ASTToTargetAST {
|
|||||||
classLoader.findClass(superClassName);
|
classLoader.findClass(superClassName);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
try {
|
try {
|
||||||
classLoader.loadClass(code);
|
classLoader.loadClass(superClassName, code);
|
||||||
} catch (LinkageError ignored) {}
|
} catch (LinkageError ignored) {}
|
||||||
}
|
}
|
||||||
auxiliaries.put(superClassName, code);
|
auxiliaries.put(superClassName, code);
|
||||||
|
|||||||
@@ -15,6 +15,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;
|
||||||
@@ -33,19 +34,17 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private class LambdaCaptureFinder extends TracingStatementVisitor {
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
|
||||||
var parameters = StreamSupport.stream(lambdaExpression.params.spliterator(), false)
|
|
||||||
.map(p -> (FormalParameter) p)
|
|
||||||
.map(p -> new MethodParameter(new TargetTypePattern(converter.convert(p.getType()), p.getName())))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
List<MethodParameter> captures = new ArrayList<>();
|
|
||||||
lambdaExpression.methodBody.accept(new TracingStatementVisitor() {
|
|
||||||
// TODO The same mechanism is implemented in Codegen, maybe use it from there?
|
// TODO The same mechanism is implemented in Codegen, maybe use it from there?
|
||||||
final Stack<Set<String>> localVariables = new Stack<>();
|
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<>());
|
localVariables.push(new HashSet<>());
|
||||||
|
this.parameters = parameters;
|
||||||
|
this.captures = captures;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasLocalVar(String name) {
|
boolean hasLocalVar(String name) {
|
||||||
@@ -79,8 +78,27 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LambdaExpression lambda) {
|
public void visit(LambdaExpression lambda) {
|
||||||
} // Don't look at lambda expressions
|
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
|
||||||
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
|
var parameters = createParameters(lambdaExpression);
|
||||||
|
List<MethodParameter> captures = new ArrayList<>();
|
||||||
|
var visitor = new LambdaCaptureFinder(parameters, captures);
|
||||||
|
lambdaExpression.methodBody.accept(visitor);
|
||||||
|
|
||||||
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());
|
||||||
@@ -121,7 +139,10 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(BoolExpression bool) {
|
public void visit(BoolExpression bool) {
|
||||||
Target.logger.info("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
|
||||||
|
|||||||
@@ -9,18 +9,13 @@ import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialUUID;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
public class Constraint<A extends IConstraintElement> extends HashSet<A> implements ISerializableData {
|
public class Constraint<A extends IConstraintElement> extends HashSet<A> implements Comparable<Constraint<A>>, ISerializableData {
|
||||||
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;
|
||||||
@@ -101,6 +96,12 @@ public class Constraint<A extends IConstraintElement> extends HashSet<A> impleme
|
|||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Constraint<A> o) {
|
||||||
|
return this.toString().compareTo(o.toString());
|
||||||
|
}
|
||||||
|
|
||||||
private String serialUUID = null;
|
private String serialUUID = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -167,5 +168,4 @@ public class Constraint<A extends IConstraintElement> extends HashSet<A> impleme
|
|||||||
|
|
||||||
return keyStorage.getUnserialized(uuid, Constraint.class);
|
return keyStorage.getUnserialized(uuid, Constraint.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
|||||||
* 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 ISerializableData {
|
implements Comparable<ResultPair<A,B>>, ISerializableData {
|
||||||
private final A left;
|
private final A left;
|
||||||
private final B right;
|
private final B right;
|
||||||
|
|
||||||
@@ -65,6 +65,16 @@ implements ISerializableData {
|
|||||||
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SerialMap toSerial(KeyStorage keyStorage) {
|
public SerialMap toSerial(KeyStorage keyStorage) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import de.dhbwstuttgart.util.Logger;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
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;
|
||||||
@@ -23,7 +24,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public class ResultSet implements ISerializableData {
|
public class ResultSet implements Comparable<ResultSet>, ISerializableData {
|
||||||
|
|
||||||
public final Set<ResultPair> results;
|
public final Set<ResultPair> results;
|
||||||
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
||||||
@@ -38,6 +39,10 @@ public class ResultSet implements ISerializableData {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
@@ -92,6 +97,21 @@ public class ResultSet implements ISerializableData {
|
|||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SerialMap toSerial(KeyStorage keyStorage) {
|
public SerialMap toSerial(KeyStorage keyStorage) {
|
||||||
SerialMap serialized = new SerialMap();;
|
SerialMap serialized = new SerialMap();;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
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;
|
||||||
@@ -9,9 +10,11 @@ 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.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.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.TypeUnifyTaskHelper;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTaskHelper;
|
||||||
@@ -19,6 +22,7 @@ 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 {
|
||||||
@@ -88,12 +92,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;
|
||||||
|
|||||||
@@ -75,7 +75,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);
|
||||||
@@ -643,6 +643,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 {
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.concurrent.RecursiveTask;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An intermediate class for the recursive steps of the TypeUnifyTask:
|
||||||
|
* This allows canceling parts of the recursion tree, instead of only the whole execution as before. But in
|
||||||
|
* order for that to work, all cancellable child tasks must be added when they are created
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
public abstract class CancellableTask<T> extends RecursiveTask<T> {
|
||||||
|
|
||||||
|
private final AtomicBoolean executionCancelled = new AtomicBoolean(false);
|
||||||
|
private final List<CancellableTask<?>> childTasks = new LinkedList<>();
|
||||||
|
private CancellableTask<?> parentTask = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the execution for this task and all its (recursive) children to be canceled
|
||||||
|
*/
|
||||||
|
protected void cancelExecution() {
|
||||||
|
// is this branch already canceled? Then do nothing
|
||||||
|
if (this.executionCancelled.getAndSet(true)) return;
|
||||||
|
this.cancelChildExecution();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelChildExecution() {
|
||||||
|
synchronized (this.childTasks) {
|
||||||
|
for (var childTask : childTasks) {
|
||||||
|
// no need to cancel a branch that is already finished
|
||||||
|
if (!childTask.isDone()) {
|
||||||
|
childTask.cancelExecution();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelChildExecutionAfter(CancellableTask<?> checkpointTask) {
|
||||||
|
boolean reachedCheckpoint = false;
|
||||||
|
int i = 0;
|
||||||
|
for (var childTask : childTasks) {
|
||||||
|
if (!reachedCheckpoint) {
|
||||||
|
reachedCheckpoint = childTask == checkpointTask;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// no need to cancel a branch that is already finished
|
||||||
|
if (!childTask.isDone()) {
|
||||||
|
childTask.cancelExecution();
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Skipped " + i + " younger siblings");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cancelSiblingTasks() {
|
||||||
|
if (this.parentTask != null) {
|
||||||
|
boolean thisWasCancelledBefore = this.executionCancelled.get();
|
||||||
|
this.parentTask.cancelChildExecution();
|
||||||
|
this.executionCancelled.set(thisWasCancelledBefore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelYoungerSiblingTasks() {
|
||||||
|
if (this.parentTask != null) {
|
||||||
|
this.parentTask.cancelChildExecutionAfter(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isExecutionCancelled() {
|
||||||
|
return executionCancelled.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChildTask(CancellableTask<?> childTask) {
|
||||||
|
this.childTasks.add(childTask);
|
||||||
|
childTask.setParentTask(this);
|
||||||
|
if (this.executionCancelled.get()) {
|
||||||
|
childTask.executionCancelled.set(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setParentTask(CancellableTask<?> parentTask) {
|
||||||
|
this.parentTask = parentTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -45,7 +45,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
*/
|
*/
|
||||||
//writeLog("xxx");
|
//writeLog("xxx");
|
||||||
//noOfThread--;
|
//noOfThread--;
|
||||||
if (this.myIsCancelled()) {
|
if (this.isExecutionCancelled()) {
|
||||||
return CompletableFuture.completedFuture(new HashSet<>());
|
return CompletableFuture.completedFuture(new HashSet<>());
|
||||||
} else {
|
} else {
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -27,11 +27,7 @@ import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
|
|||||||
import de.dhbwstuttgart.util.Logger;
|
import de.dhbwstuttgart.util.Logger;
|
||||||
import de.dhbwstuttgart.util.Pair;
|
import de.dhbwstuttgart.util.Pair;
|
||||||
import de.dhbwstuttgart.util.Tuple;
|
import de.dhbwstuttgart.util.Tuple;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -47,12 +43,9 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.RecursiveTask;
|
import java.util.concurrent.RecursiveTask;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +53,7 @@ import org.apache.commons.io.output.NullOutputStream;
|
|||||||
*
|
*
|
||||||
* @author Florian Steurer
|
* @author Florian Steurer
|
||||||
*/
|
*/
|
||||||
public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<UnifyPair>>>> {
|
public class TypeUnifyTask extends CancellableTask<CompletableFuture<Set<Set<UnifyPair>>>> {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -120,8 +113,6 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
public static int noShortendElements;
|
public static int noShortendElements;
|
||||||
public static int noou = 0;
|
public static int noou = 0;
|
||||||
|
|
||||||
boolean myIsCanceled = false;
|
|
||||||
|
|
||||||
public TypeUnifyTask(UnifyContext context) {
|
public TypeUnifyTask(UnifyContext context) {
|
||||||
this.context = context.newWithLogger(Logger.NULL_LOGGER);
|
this.context = context.newWithLogger(Logger.NULL_LOGGER);
|
||||||
rules = new RuleSet(context.placeholderRegistry());
|
rules = new RuleSet(context.placeholderRegistry());
|
||||||
@@ -216,13 +207,6 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
void myCancel(boolean b) {
|
|
||||||
myIsCanceled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean myIsCancelled() {
|
|
||||||
return myIsCanceled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<Set<Set<UnifyPair>>> compute() {
|
public CompletableFuture<Set<Set<UnifyPair>>> compute() {
|
||||||
if (one) {
|
if (one) {
|
||||||
@@ -252,7 +236,7 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
throw new TypeinferenceException("Unresolved constraints: " + res, new NullToken()); //return new HashSet<>();
|
throw new TypeinferenceException("Unresolved constraints: " + res, new NullToken()); //return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.myIsCancelled()) {
|
if (this.isExecutionCancelled()) {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +273,7 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
|
|
||||||
//.collect(Collectors.toCollection(HashSet::new)));
|
//.collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
|
||||||
if (this.myIsCancelled()) {
|
if (this.isExecutionCancelled()) {
|
||||||
return CompletableFuture.completedFuture(new HashSet<>());
|
return CompletableFuture.completedFuture(new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,7 +463,7 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
// .collect(Collectors.toCollection(HashSet::new));
|
// .collect(Collectors.toCollection(HashSet::new));
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
||||||
|
|
||||||
if (this.myIsCancelled()) {
|
if (this.isExecutionCancelled()) {
|
||||||
return CompletableFuture.completedFuture(new HashSet<>());
|
return CompletableFuture.completedFuture(new HashSet<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -756,7 +740,7 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
// Ergebnisvariable für die parallele Verabeitung: Tupel aus
|
// Ergebnisvariable für die parallele Verabeitung: Tupel aus
|
||||||
// - forkOrig result : currentThreadResult (frueher "res")
|
// - forkOrig result : currentThreadResult (frueher "res")
|
||||||
// - fork results : forkResults (frueher "add_res")
|
// - fork results : forkResults (frueher "add_res")
|
||||||
CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> parallelResultDataFuture;
|
CompletableFuture<VarianceCase.ComputationResults> parallelResultDataFuture;
|
||||||
|
|
||||||
|
|
||||||
if (parallel) {
|
if (parallel) {
|
||||||
@@ -768,13 +752,16 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
// same as variance = 0
|
// same as variance = 0
|
||||||
elems.add(varianceCase.a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
elems.add(varianceCase.a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
||||||
parallelResultDataFuture = this.unify2(elems, eq, oderConstraints, fc, false, rekTiefe, new HashSet<>(methodSignatureConstraint))
|
parallelResultDataFuture = this.unify2(elems, eq, oderConstraints, fc, false, rekTiefe, new HashSet<>(methodSignatureConstraint))
|
||||||
.thenApply(currentThreadResult -> new Tuple<>(currentThreadResult, new HashSet<>()));
|
.thenApply(VarianceCase.ComputationResults::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isExecutionCancelled()) {
|
||||||
|
return CompletableFuture.completedFuture(new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
return parallelResultDataFuture.thenCompose(parallelResultData -> {
|
return parallelResultDataFuture.thenCompose(parallelResultData -> {
|
||||||
Set<Set<UnifyPair>> currentThreadResult = parallelResultData.getFirst();
|
Set<Set<UnifyPair>> currentThreadResult = parallelResultData.mainResult;
|
||||||
Set<Set<Set<UnifyPair>>> forkResults = parallelResultData.getSecond();
|
Set<Set<Set<UnifyPair>>> forkResults = parallelResultData.forkResults;
|
||||||
|
|
||||||
Set<Set<UnifyPair>> result = prevResult;
|
Set<Set<UnifyPair>> result = prevResult;
|
||||||
List<Set<UnifyPair>> nextSetAsList = prevNextSetAsList;
|
List<Set<UnifyPair>> nextSetAsList = prevNextSetAsList;
|
||||||
@@ -871,6 +858,7 @@ public class TypeUnifyTask extends RecursiveTask<CompletableFuture<Set<Set<Unify
|
|||||||
// Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<>(nextSetAsList).iterator();
|
// Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<>(nextSetAsList).iterator();
|
||||||
boolean shouldBreak = varianceCase.eraseInvalidSets(rekTiefe, aParDef, nextSetAsList);
|
boolean shouldBreak = varianceCase.eraseInvalidSets(rekTiefe, aParDef, nextSetAsList);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
|
// this.cancelYoungerSiblingTasks();
|
||||||
return CompletableFuture.completedFuture(result);
|
return CompletableFuture.completedFuture(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class UnifyTaskModel {
|
|||||||
|
|
||||||
public synchronized void cancel() {
|
public synchronized void cancel() {
|
||||||
for(TypeUnifyTask t : usedTasks) {
|
for(TypeUnifyTask t : usedTasks) {
|
||||||
t.myCancel(true);
|
t.cancelExecution();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.UnifyCancelException;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
@@ -17,11 +16,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Variance1Case extends VarianceCase {
|
public class ContravarianceCase extends VarianceCase {
|
||||||
|
|
||||||
protected final int variance = 1;
|
protected final int variance = 1;
|
||||||
|
|
||||||
protected Variance1Case(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
protected ContravarianceCase(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
||||||
super(isOderConstraint, typeUnifyTask, context);
|
super(isOderConstraint, typeUnifyTask, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ public class Variance1Case extends VarianceCase {
|
|||||||
if (this.isOderConstraint) {
|
if (this.isOderConstraint) {
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>) a).getExtendConstraint());
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>) a).getExtendConstraint());
|
||||||
}
|
}
|
||||||
context.logger().debug("nextSetasListOderConstraints 1: " + nextSetasListOderConstraints);
|
context.logger().debug(() -> "nextSetasListOderConstraints 1: " + nextSetasListOderConstraints);
|
||||||
|
|
||||||
//Alle maximale Elemente in nextSetasListRest bestimmen
|
//Alle maximale Elemente in nextSetasListRest bestimmen
|
||||||
//nur für diese wird parallele Berechnung angestossen.
|
//nur für diese wird parallele Berechnung angestossen.
|
||||||
@@ -49,7 +48,7 @@ public class Variance1Case extends VarianceCase {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> computeParallel(
|
public CompletableFuture<ComputationResults> computeParallel(
|
||||||
Set<Set<UnifyPair>> elems,
|
Set<Set<UnifyPair>> elems,
|
||||||
Set<UnifyPair> eq,
|
Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
@@ -61,10 +60,6 @@ public class Variance1Case extends VarianceCase {
|
|||||||
Set<Set<UnifyPair>> result,
|
Set<Set<UnifyPair>> result,
|
||||||
Set<Set<UnifyPair>> aParDef
|
Set<Set<UnifyPair>> aParDef
|
||||||
) {
|
) {
|
||||||
CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> resultValues = CompletableFuture.completedFuture(new Tuple<>(
|
|
||||||
new HashSet<>(), new HashSet<>()
|
|
||||||
));
|
|
||||||
|
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
@@ -72,18 +67,19 @@ public class Variance1Case extends VarianceCase {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, methodSignatureConstraint);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, methodSignatureConstraint);
|
||||||
|
typeUnifyTask.addChildTask(forkOrig);
|
||||||
// schedule compute() on another thread
|
// schedule compute() on another thread
|
||||||
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
||||||
resultValues = resultValues.thenCombine(forkOrigFuture,
|
CompletableFuture<ComputationResults> resultValues = forkOrigFuture.thenApply(
|
||||||
(prevResults, currentThreadResult) -> {
|
(currentThreadResult) -> {
|
||||||
forkOrig.context.logger().debug("final Orig 1");
|
forkOrig.context.logger().debug("final Orig 1");
|
||||||
forkOrig.closeLogFile();
|
forkOrig.closeLogFile();
|
||||||
return new Tuple<>(currentThreadResult, prevResults.getSecond());
|
return new ComputationResults(currentThreadResult);
|
||||||
});
|
});
|
||||||
|
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return CompletableFuture.completedFuture(new ComputationResults());
|
||||||
}
|
}
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
@@ -108,16 +104,17 @@ public class Variance1Case extends VarianceCase {
|
|||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
||||||
|
typeUnifyTask.addChildTask(fork);
|
||||||
// schedule compute() on another thread
|
// schedule compute() on another thread
|
||||||
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
||||||
resultValues = resultValues.thenCombine(forkFuture,
|
resultValues = resultValues.thenCombine(forkFuture,
|
||||||
(prevResults, fork_res) -> {
|
(prevResults, fork_res) -> {
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return new ComputationResults();
|
||||||
}
|
}
|
||||||
context.logger().debug("fork_res: " + fork_res.toString());
|
context.logger().debug("fork_res: " + fork_res.toString());
|
||||||
context.logger().debug(Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
context.logger().debug(Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
||||||
prevResults.getSecond().add(fork_res);
|
prevResults.addForkResult(fork_res);
|
||||||
if (!typeUnifyTask.isUndefinedPairSetSet(fork_res)) {
|
if (!typeUnifyTask.isUndefinedPairSetSet(fork_res)) {
|
||||||
aParDef.add(fork.getNextSetElement());
|
aParDef.add(fork.getNextSetElement());
|
||||||
}
|
}
|
||||||
@@ -127,8 +124,8 @@ public class Variance1Case extends VarianceCase {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return CompletableFuture.completedFuture(new ComputationResults());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.UnifyCancelException;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
@@ -17,11 +16,11 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class VarianceM1Case extends VarianceCase {
|
public class CovarianceCase extends VarianceCase {
|
||||||
|
|
||||||
protected final int variance = -1;
|
protected final int variance = -1;
|
||||||
|
|
||||||
protected VarianceM1Case(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
protected CovarianceCase(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
||||||
super(isOderConstraint, typeUnifyTask, context);
|
super(isOderConstraint, typeUnifyTask, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +48,7 @@ public class VarianceM1Case extends VarianceCase {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> computeParallel(
|
public CompletableFuture<ComputationResults> computeParallel(
|
||||||
Set<Set<UnifyPair>> elems,
|
Set<Set<UnifyPair>> elems,
|
||||||
Set<UnifyPair> eq,
|
Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
@@ -61,10 +60,6 @@ public class VarianceM1Case extends VarianceCase {
|
|||||||
Set<Set<UnifyPair>> result,
|
Set<Set<UnifyPair>> result,
|
||||||
Set<Set<UnifyPair>> aParDef
|
Set<Set<UnifyPair>> aParDef
|
||||||
) {
|
) {
|
||||||
CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> resultValues = CompletableFuture.completedFuture(new Tuple<>(
|
|
||||||
new HashSet<>(), new HashSet<>()
|
|
||||||
));
|
|
||||||
|
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
@@ -72,18 +67,19 @@ public class VarianceM1Case extends VarianceCase {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, methodSignatureConstraint);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, methodSignatureConstraint);
|
||||||
|
typeUnifyTask.addChildTask(forkOrig);
|
||||||
// schedule compute() on another thread
|
// schedule compute() on another thread
|
||||||
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
||||||
resultValues = resultValues.thenCombine(forkOrigFuture,
|
CompletableFuture<ComputationResults> resultValues = forkOrigFuture.thenApply(
|
||||||
(prevResults, currentThreadResult) -> {
|
(currentThreadResult) -> {
|
||||||
forkOrig.context.logger().debug("final Orig -1");
|
forkOrig.context.logger().debug("final Orig -1");
|
||||||
forkOrig.closeLogFile();
|
forkOrig.closeLogFile();
|
||||||
return new Tuple<>(currentThreadResult, prevResults.getSecond());
|
return new ComputationResults(currentThreadResult);
|
||||||
});
|
});
|
||||||
|
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return resultValues;
|
||||||
}
|
}
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
@@ -109,16 +105,17 @@ public class VarianceM1Case extends VarianceCase {
|
|||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
||||||
|
typeUnifyTask.addChildTask(fork);
|
||||||
// schedule compute() on another thread
|
// schedule compute() on another thread
|
||||||
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
||||||
resultValues = resultValues.thenCombine(forkFuture,
|
resultValues = resultValues.thenCombine(forkFuture,
|
||||||
(prevResults, fork_res) -> {
|
(prevResults, fork_res) -> {
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return prevResults;
|
||||||
}
|
}
|
||||||
context.logger().debug(() -> "fork_res: " + fork_res.toString());
|
context.logger().debug(() -> "fork_res: " + fork_res.toString());
|
||||||
context.logger().debug(() -> Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
context.logger().debug(() -> Boolean.valueOf((typeUnifyTask.isUndefinedPairSetSet(fork_res))).toString());
|
||||||
prevResults.getSecond().add(fork_res);
|
prevResults.addForkResult(fork_res);
|
||||||
if (!typeUnifyTask.isUndefinedPairSetSet(fork_res)) {
|
if (!typeUnifyTask.isUndefinedPairSetSet(fork_res)) {
|
||||||
aParDef.add(fork.getNextSetElement());
|
aParDef.add(fork.getNextSetElement());
|
||||||
}
|
}
|
||||||
@@ -128,8 +125,8 @@ public class VarianceM1Case extends VarianceCase {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return resultValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
package de.dhbwstuttgart.typeinference.unify.cartesianproduct;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.UnifyCancelException;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnify2Task;
|
||||||
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
@@ -15,11 +14,12 @@ import java.util.Optional;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class Variance2Case extends VarianceCase {
|
public class InvarianceOrConstraintCase extends VarianceCase {
|
||||||
|
|
||||||
|
// either for invariance or for oderConstraints
|
||||||
protected final int variance = 2;
|
protected final int variance = 2;
|
||||||
|
|
||||||
protected Variance2Case(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
protected InvarianceOrConstraintCase(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
||||||
super(isOderConstraint, typeUnifyTask, context);
|
super(isOderConstraint, typeUnifyTask, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class Variance2Case extends VarianceCase {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> computeParallel(
|
public CompletableFuture<ComputationResults> computeParallel(
|
||||||
Set<Set<UnifyPair>> elems,
|
Set<Set<UnifyPair>> elems,
|
||||||
Set<UnifyPair> eq,
|
Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
@@ -49,8 +49,6 @@ public class Variance2Case extends VarianceCase {
|
|||||||
Set<Set<UnifyPair>> result,
|
Set<Set<UnifyPair>> result,
|
||||||
Set<Set<UnifyPair>> aParDef
|
Set<Set<UnifyPair>> aParDef
|
||||||
) {
|
) {
|
||||||
CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> resultValuesFuture;
|
|
||||||
|
|
||||||
context.logger().debug("var2einstieg");
|
context.logger().debug("var2einstieg");
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
@@ -60,14 +58,16 @@ public class Variance2Case extends VarianceCase {
|
|||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
||||||
|
typeUnifyTask.addChildTask(forkOrig);
|
||||||
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
CompletableFuture<Set<Set<UnifyPair>>> forkOrigFuture = CompletableFuture.supplyAsync(forkOrig::compute, context.executor()).thenCompose(f -> f);
|
||||||
resultValuesFuture = forkOrigFuture.thenApply((currentThreadResult) -> {
|
CompletableFuture<ComputationResults> resultValues = forkOrigFuture.thenApply((currentThreadResult) -> {
|
||||||
forkOrig.context.logger().debug("final Orig 2");
|
forkOrig.context.logger().debug("final Orig 2");
|
||||||
forkOrig.closeLogFile();
|
forkOrig.closeLogFile();
|
||||||
return new Tuple<>(currentThreadResult, new HashSet<>());
|
return new ComputationResults(currentThreadResult);
|
||||||
});
|
});
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
|
||||||
throw new UnifyCancelException();
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
|
return resultValues;
|
||||||
}
|
}
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
@@ -89,27 +89,24 @@ public class Variance2Case extends VarianceCase {
|
|||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraintForParallel));
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, context, rekTiefe, new HashSet<>(methodSignatureConstraintForParallel));
|
||||||
|
typeUnifyTask.addChildTask(fork);
|
||||||
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
CompletableFuture<Set<Set<UnifyPair>>> forkFuture = CompletableFuture.supplyAsync(fork::compute, context.executor()).thenCompose(f -> f);
|
||||||
resultValuesFuture = resultValuesFuture.thenCombine(forkFuture, (resultValues, fork_res) -> {
|
resultValues = resultValues.thenCombine(forkFuture, (prevResults, fork_res) -> {
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return prevResults;
|
||||||
}
|
}
|
||||||
resultValues.getSecond().add(fork_res);
|
prevResults.addForkResult(fork_res);
|
||||||
fork.context.logger().debug("final 2");
|
fork.context.logger().debug("final 2");
|
||||||
fork.closeLogFile();
|
fork.closeLogFile();
|
||||||
return resultValues;
|
return prevResults;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
if (typeUnifyTask.isExecutionCancelled()) {
|
||||||
throw new UnifyCancelException();
|
return resultValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeUnifyTask.myIsCancelled()) {
|
return resultValues;
|
||||||
throw new UnifyCancelException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultValuesFuture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -13,14 +13,13 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Variance0Case extends VarianceCase {
|
public class UnknownVarianceCase extends VarianceCase {
|
||||||
|
|
||||||
protected final int variance = 0;
|
protected final int variance = 0;
|
||||||
|
|
||||||
protected Variance0Case(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
protected UnknownVarianceCase(boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
||||||
super(isOderConstraint, typeUnifyTask, context);
|
super(isOderConstraint, typeUnifyTask, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ public class Variance0Case extends VarianceCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> computeParallel(
|
public CompletableFuture<ComputationResults> computeParallel(
|
||||||
Set<Set<UnifyPair>> elems,
|
Set<Set<UnifyPair>> elems,
|
||||||
Set<UnifyPair> eq,
|
Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
@@ -62,10 +61,9 @@ public class Variance0Case extends VarianceCase {
|
|||||||
Set<Set<UnifyPair>> result,
|
Set<Set<UnifyPair>> result,
|
||||||
Set<Set<UnifyPair>> aParDef
|
Set<Set<UnifyPair>> aParDef
|
||||||
) {
|
) {
|
||||||
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
elems.add(a);
|
||||||
return typeUnifyTask.unify2(elems, eq, oderConstraints, fc, context.parallel(), rekTiefe, new HashSet<>(methodSignatureConstraint)).thenApply(
|
return typeUnifyTask.unify2(elems, eq, oderConstraints, fc, context.parallel(), rekTiefe, new HashSet<>(methodSignatureConstraint))
|
||||||
unify2Result -> new Tuple<>(unify2Result, new HashSet<>())
|
.thenApply(ComputationResults::new);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,7 +73,7 @@ public class Variance0Case extends VarianceCase {
|
|||||||
Set<UnifyPair> compResult,
|
Set<UnifyPair> compResult,
|
||||||
Set<UnifyPair> compRes
|
Set<UnifyPair> compRes
|
||||||
) {
|
) {
|
||||||
context.logger().debug("RES var=1 ADD:" + result.toString() + " " + currentThreadResult.toString());
|
context.logger().debug("RES var=0 ADD:" + result.toString() + " " + currentThreadResult.toString());
|
||||||
result.addAll(currentThreadResult);
|
result.addAll(currentThreadResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5,9 +5,9 @@ import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.util.Logger;
|
|
||||||
import de.dhbwstuttgart.util.Tuple;
|
import de.dhbwstuttgart.util.Tuple;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -17,10 +17,10 @@ public abstract class VarianceCase {
|
|||||||
|
|
||||||
public static VarianceCase createFromVariance(int variance, boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
public static VarianceCase createFromVariance(int variance, boolean isOderConstraint, TypeUnifyTask typeUnifyTask, UnifyContext context) {
|
||||||
return switch (variance) {
|
return switch (variance) {
|
||||||
case 0 -> new Variance0Case(isOderConstraint, typeUnifyTask, context);
|
case 0 -> new UnknownVarianceCase(isOderConstraint, typeUnifyTask, context);
|
||||||
case 1 -> new Variance1Case(isOderConstraint, typeUnifyTask, context);
|
case 1 -> new ContravarianceCase(isOderConstraint, typeUnifyTask, context);
|
||||||
case -1 -> new VarianceM1Case(isOderConstraint, typeUnifyTask, context);
|
case -1 -> new CovarianceCase(isOderConstraint, typeUnifyTask, context);
|
||||||
case 2 -> new Variance2Case(isOderConstraint, typeUnifyTask, context);
|
case 2 -> new InvarianceOrConstraintCase(isOderConstraint, typeUnifyTask, context);
|
||||||
default -> throw new RuntimeException("Invalid variance: " + variance);
|
default -> throw new RuntimeException("Invalid variance: " + variance);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ public abstract class VarianceCase {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract CompletableFuture<Tuple<Set<Set<UnifyPair>>, Set<Set<Set<UnifyPair>>>>> computeParallel(
|
public abstract CompletableFuture<ComputationResults> computeParallel(
|
||||||
Set<Set<UnifyPair>> elems,
|
Set<Set<UnifyPair>> elems,
|
||||||
Set<UnifyPair> eq,
|
Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
@@ -104,4 +104,29 @@ public abstract class VarianceCase {
|
|||||||
Set<Set<UnifyPair>> aParDef,
|
Set<Set<UnifyPair>> aParDef,
|
||||||
List<Set<UnifyPair>> nextSetAsList
|
List<Set<UnifyPair>> nextSetAsList
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper class for the parallel computation results
|
||||||
|
*/
|
||||||
|
public static class ComputationResults {
|
||||||
|
public Set<Set<UnifyPair>> mainResult;
|
||||||
|
public Set<Set<Set<UnifyPair>>> forkResults;
|
||||||
|
|
||||||
|
public ComputationResults() {
|
||||||
|
this(new HashSet<>(), new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputationResults(Set<Set<UnifyPair>> mainResult) {
|
||||||
|
this(mainResult, new HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComputationResults(Set<Set<UnifyPair>> mainResult, Set<Set<Set<UnifyPair>>> forkResults) {
|
||||||
|
this.mainResult = mainResult;
|
||||||
|
this.forkResults = forkResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addForkResult(Set<Set<UnifyPair>> forkResult) {
|
||||||
|
forkResults.add(forkResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.model;
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.server.packet.dataContainers.ISerializableData;
|
import de.dhbwstuttgart.server.packet.dataContainers.ISerializableData;
|
||||||
import de.dhbwstuttgart.server.packet.dataContainers.KeyStorage;
|
import de.dhbwstuttgart.server.packet.dataContainers.KeyStorage;
|
||||||
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialList;
|
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialList;
|
||||||
@@ -10,6 +11,7 @@ import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
|||||||
import de.dhbwstuttgart.util.Logger;
|
import de.dhbwstuttgart.util.Logger;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -37,15 +39,16 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The finite closure for the type unification
|
* The finite closure for the type unification
|
||||||
|
*
|
||||||
* @author Florian Steurer
|
* @author Florian Steurer
|
||||||
*/
|
*/
|
||||||
public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||||
|
implements IFiniteClosure, ISerializableData {
|
||||||
|
|
||||||
final JavaTXCompiler compiler;
|
final JavaTXCompiler compiler;
|
||||||
final PlaceholderRegistry placeholderRegistry;
|
final PlaceholderRegistry placeholderRegistry;
|
||||||
|
|
||||||
Logger logger;
|
Logger logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map that maps every type to the node in the inheritance graph that contains that type.
|
* A map that maps every type to the node in the inheritance graph that contains that type.
|
||||||
*/
|
*/
|
||||||
@@ -122,8 +125,50 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
||||||
|
|
||||||
//PL eingefuegt 2020-05-07 File UnitTest InheritTest.java
|
//PL eingefuegt 2020-05-07 File UnitTest InheritTest.java
|
||||||
this.inheritanceGraph.forEach((x,y) -> { if (y.getDescendants().contains(parentNode)) { y.addDescendant(childNode); y.addAllDescendant(childNode.getDescendants());};
|
this.inheritanceGraph.forEach((x, y) -> {
|
||||||
if (y.getPredecessors().contains(childNode)) { y.addPredecessor(parentNode); y.addAllPredecessor(parentNode.getPredecessors());};} );
|
if (y.getDescendants().contains(parentNode)) {
|
||||||
|
y.addDescendant(childNode);
|
||||||
|
y.addAllDescendant(childNode.getDescendants());
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (y.getPredecessors().contains(childNode)) {
|
||||||
|
y.addPredecessor(parentNode);
|
||||||
|
y.addAllPredecessor(parentNode.getPredecessors());
|
||||||
|
}
|
||||||
|
;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> classesToKeep = (compiler == null) ? new ArrayList<>() :
|
||||||
|
new ArrayList<>(compiler.classRegistry.getAllClassNames().stream().map(JavaClassName::toString).toList());
|
||||||
|
|
||||||
|
classesToKeep.add("java.lang.Object");
|
||||||
|
classesToKeep.add("java.lang.Number");
|
||||||
|
classesToKeep.add("java.util.Collection");
|
||||||
|
classesToKeep.add("java.lang.Iterable");
|
||||||
|
|
||||||
|
//filter out all types not imported
|
||||||
|
Iterator<Map.Entry<UnifyType, Node<UnifyType>>> iterator = inheritanceGraph.entrySet().iterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Map.Entry<UnifyType, Node<UnifyType>> entry = iterator.next();
|
||||||
|
var name = entry.getKey().getName();
|
||||||
|
|
||||||
|
if (!classesToKeep.contains(name)) {
|
||||||
|
iterator.remove();
|
||||||
|
} else {
|
||||||
|
Node<UnifyType> node = entry.getValue();
|
||||||
|
|
||||||
|
// Remove unwanted predecessors
|
||||||
|
node.getPredecessors().removeIf(pred ->
|
||||||
|
!classesToKeep.contains(pred.getContent().getName())
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove unwanted descendants
|
||||||
|
node.getDescendants().removeIf(desc ->
|
||||||
|
!classesToKeep.contains(desc.getContent().getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the alternative representation with strings as keys
|
// Build the alternative representation with strings as keys
|
||||||
@@ -154,6 +199,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all types of the finite closure that are subtypes of the argument.
|
* Returns all types of the finite closure that are subtypes of the argument.
|
||||||
|
*
|
||||||
* @return The set of subtypes of the argument.
|
* @return The set of subtypes of the argument.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -200,9 +246,8 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
// if T = T' then T <* T'
|
// if T = T' then T <* T'
|
||||||
try {
|
try {
|
||||||
result.add(new Pair<>(t, fBounded));
|
result.add(new Pair<>(t, fBounded));
|
||||||
}
|
} catch (StackOverflowError e) {
|
||||||
catch (StackOverflowError e) {
|
//System.out.println("");
|
||||||
// context.logger().info("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if C<...> <* C<...> then ... (third case in definition of <*)
|
// if C<...> <* C<...> then ... (third case in definition of <*)
|
||||||
@@ -227,7 +272,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
termList.add(new UnifyPair(theta2, t, PairOperator.EQUALSDOT));
|
termList.add(new UnifyPair(theta2, t, PairOperator.EQUALSDOT));
|
||||||
Optional<Unifier> optSigma = match.match(termList);
|
Optional<Unifier> optSigma = match.match(termList);
|
||||||
//PL 18-02-05 Unifier durch Matcher ersetzt ENDE
|
//PL 18-02-05 Unifier durch Matcher ersetzt ENDE
|
||||||
if(!optSigma.isPresent())
|
if (optSigma.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Unifier sigma = optSigma.get();
|
Unifier sigma = optSigma.get();
|
||||||
@@ -240,8 +285,8 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<UnifyType> resut = result.stream().map(Pair::getKey).collect(Collectors.toCollection(HashSet::new));
|
HashSet<UnifyType> resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new));
|
||||||
if(resut.equals(types.stream().map(Pair::getKey).collect(Collectors.toCollection(HashSet::new))))
|
if (resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new))))
|
||||||
return resut;
|
return resut;
|
||||||
return computeSmaller(result);
|
return computeSmaller(result);
|
||||||
}
|
}
|
||||||
@@ -316,7 +361,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
termList.add(new UnifyPair(theta1, type, PairOperator.EQUALSDOT, location));
|
termList.add(new UnifyPair(theta1, type, PairOperator.EQUALSDOT, location));
|
||||||
Optional<Unifier> optSigma = match.match(termList);
|
Optional<Unifier> optSigma = match.match(termList);
|
||||||
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
|
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
|
||||||
if(!optSigma.isPresent()) {
|
if (optSigma.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Unifier sigma = optSigma.get();
|
Unifier sigma = optSigma.get();
|
||||||
@@ -366,8 +411,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
//F-Bounded Endlosrekursion
|
//F-Bounded Endlosrekursion
|
||||||
HashSet<UnifyType> res = new HashSet<UnifyType>();
|
HashSet<UnifyType> res = new HashSet<UnifyType>();
|
||||||
paramCandidates.add(res);
|
paramCandidates.add(res);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) ));
|
paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -516,8 +560,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
public Set<UnifyType> grArg(FunNType type, Set<UnifyType> fBounded) {
|
public Set<UnifyType> grArg(FunNType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> smaller = smaller(type, fBounded);
|
Set<UnifyType> smaller = smaller(type, fBounded);
|
||||||
Set<UnifyType> greater = greater(type, fBounded);
|
Set<UnifyType> greater = greater(type, fBounded);
|
||||||
|
Set<UnifyType> result = TypeUnifyTaskHelper.getPresizedHashSet(1 + smaller.size() + greater.size());
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>((int)((1 + smaller.size() + greater.size()) * 1.5));
|
|
||||||
result.add(type);
|
result.add(type);
|
||||||
smaller.forEach(x -> result.add(new SuperType(x)));
|
smaller.forEach(x -> result.add(new SuperType(x)));
|
||||||
greater.forEach(x -> result.add(new ExtendsType(x)));
|
greater.forEach(x -> result.add(new ExtendsType(x)));
|
||||||
@@ -529,7 +572,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
UnifyType t = type.getExtendedType();
|
UnifyType t = type.getExtendedType();
|
||||||
Set<UnifyType> greater = greater(t, fBounded);
|
Set<UnifyType> greater = greater(t, fBounded);
|
||||||
|
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>((int)((1 + greater.size()) * 1.5));
|
Set<UnifyType> result = TypeUnifyTaskHelper.getPresizedHashSet(1 + greater.size());
|
||||||
result.add(type);
|
result.add(type);
|
||||||
greater.forEach(x -> result.add(new ExtendsType(x)));
|
greater.forEach(x -> result.add(new ExtendsType(x)));
|
||||||
return result;
|
return result;
|
||||||
@@ -615,7 +658,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
public Set<UnifyType> getAllTypesByName(String typeName) {
|
public Set<UnifyType> getAllTypesByName(String typeName) {
|
||||||
if (!strInheritanceGraph.containsKey(typeName))
|
if (!strInheritanceGraph.containsKey(typeName))
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
return strInheritanceGraph.get(typeName).stream().map(Node::getContent).collect(Collectors.toCollection(HashSet::new));
|
return strInheritanceGraph.get(typeName).stream().map(x -> x.getContent()).collect(Collectors.toCollection(HashSet::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -662,6 +705,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a set of candidates for each position and computes all possible permutations.
|
* Takes a set of candidates for each position and computes all possible permutations.
|
||||||
|
*
|
||||||
* @param candidates The length of the list determines the number of type params. Each set
|
* @param candidates The length of the list determines the number of type params. Each set
|
||||||
* contains the candidates for the corresponding position.
|
* contains the candidates for the corresponding position.
|
||||||
*/
|
*/
|
||||||
@@ -673,6 +717,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a set of candidates for each position and computes all possible permutations.
|
* Takes a set of candidates for each position and computes all possible permutations.
|
||||||
|
*
|
||||||
* @param candidates The length of the list determines the number of type params. Each set
|
* @param candidates The length of the list determines the number of type params. Each set
|
||||||
* contains the candidates for the corresponding position.
|
* contains the candidates for the corresponding position.
|
||||||
* @param idx Idx for the current permutatiton.
|
* @param idx Idx for the current permutatiton.
|
||||||
@@ -708,6 +753,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
logger.debug(() -> "left: " + left + " right: " + right + " pairop: " + pairop +"\n");
|
logger.debug(() -> "left: " + left + " right: " + right + " pairop: " + pairop +"\n");
|
||||||
//if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
//if (left.getName().equals("Matrix") || right.getName().equals("Matrix"))
|
||||||
// context.logger().info("");
|
// context.logger().info("");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pairop = PairOperator.SMALLERDOTWC;
|
pairop = PairOperator.SMALLERDOTWC;
|
||||||
List<UnifyType> al = new ArrayList<>();
|
List<UnifyType> al = new ArrayList<>();
|
||||||
@@ -742,8 +788,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
&& ((ex = ((WildcardType) right).wildcardedType) instanceof PlaceholderType)
|
&& ((ex = ((WildcardType) right).wildcardedType) instanceof PlaceholderType)
|
||||||
&& ((PlaceholderType) left).getName().equals(((PlaceholderType) ex).getName())) {// a <.? ? extends a oder a <.? ? super a
|
&& ((PlaceholderType) left).getName().equals(((PlaceholderType) ex).getName())) {// a <.? ? extends a oder a <.? ? super a
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -752,8 +797,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
&& ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType)
|
&& ((ex = ((WildcardType)left).wildcardedType) instanceof PlaceholderType)
|
||||||
&& ((PlaceholderType)right).getName().equals(((PlaceholderType) ex).getName())) {// ? extends a <. a oder ? super a <. a
|
&& ((PlaceholderType)right).getName().equals(((PlaceholderType) ex).getName())) {// ? extends a <. a oder ? super a <. a
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -774,6 +818,7 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
);
|
);
|
||||||
long smallerLen = smallerRes.stream().filter(delFun).count();
|
long smallerLen = smallerRes.stream().filter(delFun).count();
|
||||||
logger.debug(() -> "\nsmallerLen: " + smallerLen + "\n");
|
logger.debug(() -> "\nsmallerLen: " + smallerLen + "\n");
|
||||||
|
|
||||||
if (smallerLen == 0) return -1;
|
if (smallerLen == 0) return -1;
|
||||||
else {
|
else {
|
||||||
up = new UnifyPair(right, left, pairop);
|
up = new UnifyPair(right, left, pairop);
|
||||||
@@ -807,5 +852,4 @@ public class FiniteClosure implements IFiniteClosure, ISerializableData {
|
|||||||
.map(pairData -> UnifyPair.fromSerial(pairData, context, keyStorage)).collect(Collectors.toSet());
|
.map(pairData -> UnifyPair.fromSerial(pairData, context, keyStorage)).collect(Collectors.toSet());
|
||||||
return new FiniteClosure(pairs, context.logger(), context.placeholderRegistry());
|
return new FiniteClosure(pairs, context.logger(), context.placeholderRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,11 +106,7 @@ public class UnifyPair implements IConstraintElement, ISerializableData {
|
|||||||
|
|
||||||
public SourceLoc getLocation() {
|
public SourceLoc getLocation() {
|
||||||
if (location != null) return location;
|
if (location != null) return location;
|
||||||
else if (basePair != null) {
|
else if (basePair != null) return basePair.getLocation();
|
||||||
SourceLoc baseLocation = basePair.getLocation();
|
|
||||||
location = baseLocation;
|
|
||||||
return baseLocation;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ import static com.diogonunes.jcolor.Ansi.colorize;
|
|||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
|
|
||||||
|
public static final Logger NULL_LOGGER = new NullLogger();
|
||||||
|
private static final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
protected final Writer writer;
|
protected final Writer writer;
|
||||||
protected final String prefix;
|
protected final String prefix;
|
||||||
|
|
||||||
public static Logger NULL_LOGGER = new NullLogger();
|
|
||||||
private static DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
public Logger() {
|
public Logger() {
|
||||||
this(null, "");
|
this(null, "");
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ public class Logger {
|
|||||||
/**
|
/**
|
||||||
* Create a new logger object that inherits the writer of the given logger object
|
* Create a new logger object that inherits the writer of the given logger object
|
||||||
*
|
*
|
||||||
* @param logger The old logger object, that will provide the writer
|
* @param logger The old logger object that will provide the writer
|
||||||
* @return The new prefix for the new logger object
|
* @return The new prefix for the new logger object
|
||||||
*/
|
*/
|
||||||
public static Logger inherit(Logger logger, String newPrefix) {
|
public static Logger inherit(Logger logger, String newPrefix) {
|
||||||
@@ -96,7 +96,7 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// output to the correct output-stream
|
// output to the correct output-stream
|
||||||
if (logLevel.isHigherOrEqualTo(LogLevel.ERROR)) {
|
if (logLevel.getValue() == LogLevel.ERROR.getValue()) {
|
||||||
System.out.println(coloredPrefix + s);
|
System.out.println(coloredPrefix + s);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -236,7 +236,7 @@ public class Logger {
|
|||||||
" | " + stackTraceElement.toString()
|
" | " + stackTraceElement.toString()
|
||||||
).collect(Collectors.joining("\n"));
|
).collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
// if there will be a cause printed afterward, announce it with the print of the exception
|
// if there is a cause printed afterward, announce it with the print of the exception
|
||||||
if (throwable.getCause() != null) {
|
if (throwable.getCause() != null) {
|
||||||
s += "\n\nCaused by: ";
|
s += "\n\nCaused by: ";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
|
|||||||
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 de.dhbwstuttgart.typeinference.unify.PlaceholderRegistry;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SuperInterfacesTest {
|
public class SuperInterfacesTest {
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package server;
|
package server;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.parser.SourceLoc;
|
import de.dhbwstuttgart.parser.SourceLoc;
|
||||||
import de.dhbwstuttgart.server.packet.DebugPacket;
|
import de.dhbwstuttgart.server.packet.DebugPacket;
|
||||||
import de.dhbwstuttgart.server.packet.IPacket;
|
import de.dhbwstuttgart.server.packet.IPacket;
|
||||||
@@ -16,18 +16,11 @@ import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialUUID;
|
|||||||
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialValue;
|
import de.dhbwstuttgart.server.packet.dataContainers.serialized.SerialValue;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.unify.PlaceholderRegistry;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
import de.dhbwstuttgart.typeinference.unify.UnifyContext;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.concurrent.ForkJoinPool;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class PacketTest {
|
public class PacketTest {
|
||||||
|
|
||||||
|
|||||||
@@ -35,24 +35,21 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import targetast.TestCodegen;
|
import targetast.TestCodegen;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@Ignore("Server tests create huge overhead, so they are ignored until required")
|
|
||||||
public class ServerTest {
|
public class ServerTest {
|
||||||
|
|
||||||
public ServerTest() {
|
public ServerTest() {
|
||||||
ConsoleInterface.unifyServerUrl = Optional.of("ws://localhost:5000");
|
ConsoleInterface.unifyServerUrl = Optional.of("ws://localhost:5000");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void checkServer_Scalar() throws IOException, ClassNotFoundException {
|
public void checkServer_Scalar() throws IOException, ClassNotFoundException {
|
||||||
compareLocalAndServerResult("Scalar.jav");
|
compareLocalAndServerResult("Scalar.jav");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
//@Test
|
||||||
public void checkServer_Matrix() throws IOException, ClassNotFoundException {
|
public void checkServer_Matrix() throws IOException, ClassNotFoundException {
|
||||||
compareLocalAndServerResult("Matrix.jav");
|
compareLocalAndServerResult("Matrix.jav");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -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