forked from JavaTX/JavaCompilerCore
Compare commits
50
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26d951485b | ||
|
|
b5c5f1d979 | ||
|
|
4b25ada65a | ||
|
|
6f18180567 | ||
|
|
ed1be59546 | ||
|
|
42fabc115e | ||
|
|
cfc419b98e | ||
|
|
3b2df3c186 | ||
|
|
ed1feda8bf | ||
|
|
44d72a54e4 | ||
|
|
12f8dd162d | ||
|
|
6e37131fb2 | ||
|
|
eb09117a67 | ||
|
|
c7891b4965 | ||
|
|
f7891b1196 | ||
|
|
1e926e4996 | ||
|
|
acdaa1185b | ||
|
|
a20a45d7c3 | ||
|
|
a68035748c | ||
|
|
8c476b9e29 | ||
|
|
6bb462cd06 | ||
|
|
71555486b0 | ||
|
|
4048902442 | ||
|
|
4cfc070289 | ||
|
|
2920dfe68f | ||
|
|
c9d38728af | ||
|
|
b7fad6e3c7 | ||
|
|
3cb9b74df1 | ||
|
|
effc31782f | ||
|
|
2a24eab9d3 | ||
|
|
a314013f40 | ||
|
|
37c58be1f3 | ||
|
|
24920330c6 | ||
|
|
bc43ea749d | ||
|
|
c479b044b3 | ||
|
|
9046fb09e5 | ||
|
|
42e31a3471 | ||
|
|
d3b3f92193 | ||
|
|
8208abcaea | ||
|
|
e4a3939ce9 | ||
|
|
d903ec0ebb | ||
|
|
61de81cf92 | ||
|
|
59888006e0 | ||
|
|
94034912b4 | ||
|
|
f303163118 | ||
|
|
7d99fba044 | ||
|
|
3740d34954 | ||
|
|
d8b861ea95 | ||
|
|
cf45ea68bd | ||
|
|
be72e4d7fb |
No files matched your search
@@ -18,7 +18,7 @@ jobs:
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '24'
|
||||
java-version: '25'
|
||||
cache: 'maven'
|
||||
- name: Compile project
|
||||
run: |
|
||||
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '24'
|
||||
java-version: '25'
|
||||
cache: 'maven'
|
||||
- name: Compile project
|
||||
run: |
|
||||
|
||||
@@ -44,6 +44,11 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<artifactId>asm</artifactId>
|
||||
<version>9.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-util</artifactId>
|
||||
<version>9.8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -72,9 +77,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<configuration>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<source>24</source>
|
||||
<target>24</target>
|
||||
<source>25</source>
|
||||
<target>25</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class Bug378Id {
|
||||
id2 = x -> x;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import Bug378Id;
|
||||
import java.lang.Integer;
|
||||
|
||||
public class Bug378Main {
|
||||
public static main(args) {
|
||||
var hallo = (new Bug378Id<Integer>().id2).apply(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Double;
|
||||
import java.lang.System;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class Bug379 {
|
||||
public Fun1$$<Double, Double> fact = (x) -> {
|
||||
if (x == 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return x * (fact.apply(x-1));
|
||||
}
|
||||
};
|
||||
|
||||
public getFact(x) {
|
||||
return fact.apply(x);
|
||||
}
|
||||
|
||||
public static void main(x) {
|
||||
var f = new Bug379();
|
||||
var intRes = f.getFact(3);
|
||||
System.out.println(intRes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
sealed interface List<T> permits Cons, Empty {}
|
||||
record Cons<T>(T a , List<T> l ) implements List <T> {}
|
||||
record Empty<T>() implements List <T> {}
|
||||
|
||||
public class Bug380 {
|
||||
public <T> List<T> append(l1, List<T> l2) {
|
||||
return switch ( l1 ) {
|
||||
case Cons(e, rest) -> new Cons<>(e, append(rest, l2)); //::Typ TPH A
|
||||
case Empty() -> l2;//::TPH B
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.lang.Runnable;
|
||||
import java.lang.String;
|
||||
import java.lang.System;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.Thread;
|
||||
|
||||
public class Bug382 {
|
||||
public static main(a) {
|
||||
var f = () -> System.out.println("Hallo Welt!");
|
||||
new Thread(f).run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.lang.String;
|
||||
import java.lang.System;
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class Bug383 {
|
||||
public static main(a) {
|
||||
var f = () -> System.out.println("Hello from Thread!");
|
||||
f.apply();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Double;
|
||||
import java.lang.Number;
|
||||
import java.lang.String;
|
||||
|
||||
public record R(Number n) {}
|
||||
public record R(String n) {}
|
||||
|
||||
public class SwitchOverload {
|
||||
|
||||
public f(){}
|
||||
f() { return 10; }
|
||||
g() { return 20; }
|
||||
|
||||
public m(r) {
|
||||
return switch(r) {
|
||||
case R("test") -> f();
|
||||
case R("foo") -> g();
|
||||
case R r -> 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,7 @@ public class Codegen {
|
||||
}
|
||||
|
||||
private void popValue(State state, TargetType type) {
|
||||
if (type.equals(TargetType.Double) || type.equals(TargetType.Long))
|
||||
if (type.equals(TargetType.double_) || type.equals(TargetType.long_))
|
||||
state.mv.visitInsn(POP2);
|
||||
else
|
||||
state.mv.visitInsn(POP);
|
||||
@@ -134,21 +134,21 @@ public class Codegen {
|
||||
private void boxPrimitive(State state, TargetType type) {
|
||||
if (type instanceof TargetExtendsWildcard ew) type = ew.innerType();
|
||||
var mv = state.mv;
|
||||
if (type.equals(TargetType.Boolean) || type.equals(TargetType.boolean_)) {
|
||||
if (type.equals(TargetType.boolean_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
||||
} else if (type.equals(TargetType.Byte) || type.equals(TargetType.byte_)) {
|
||||
} else if (type.equals(TargetType.byte_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
|
||||
} else if (type.equals(TargetType.Double) || type.equals(TargetType.double_)) {
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
|
||||
} else if (type.equals(TargetType.Long) || type.equals(TargetType.long_)) {
|
||||
} else if (type.equals(TargetType.long_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
|
||||
} else if (type.equals(TargetType.Integer) || type.equals(TargetType.int_)) {
|
||||
} else if (type.equals(TargetType.int_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
|
||||
} else if (type.equals(TargetType.Float) || type.equals(TargetType.float_)) {
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
|
||||
} else if (type.equals(TargetType.Short) || type.equals(TargetType.short_)) {
|
||||
} else if (type.equals(TargetType.short_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
|
||||
} else if (type.equals(TargetType.Char) || type.equals(TargetType.char_)) {
|
||||
} else if (type.equals(TargetType.char_)) {
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false);
|
||||
}
|
||||
}
|
||||
@@ -185,9 +185,11 @@ public class Codegen {
|
||||
convertTo(state, op.right().type(), type);
|
||||
mv.visitJumpInsn(code, if_true);
|
||||
mv.visitInsn(ICONST_0);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(GOTO, end);
|
||||
mv.visitLabel(if_true);
|
||||
mv.visitInsn(ICONST_1);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitLabel(end);
|
||||
}
|
||||
|
||||
@@ -202,9 +204,11 @@ public class Codegen {
|
||||
mv.visitInsn(cmp);
|
||||
mv.visitJumpInsn(code, if_true);
|
||||
mv.visitInsn(ICONST_0);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(GOTO, end);
|
||||
mv.visitLabel(if_true);
|
||||
mv.visitInsn(ICONST_1);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitLabel(end);
|
||||
}
|
||||
|
||||
@@ -233,65 +237,85 @@ public class Codegen {
|
||||
if (source instanceof TargetExtendsWildcard ew) source = ew.innerType();
|
||||
if (dest instanceof TargetExtendsWildcard ew) dest = ew.innerType();
|
||||
|
||||
var mv = state.mv;
|
||||
if (source.equals(dest))
|
||||
return;
|
||||
if (source.equals(TargetType.Long)) {
|
||||
if (dest.equals(TargetType.Integer))
|
||||
mv.visitInsn(L2I);
|
||||
else if (dest.equals(TargetType.Float))
|
||||
mv.visitInsn(L2F);
|
||||
else if (dest.equals(TargetType.Double))
|
||||
mv.visitInsn(L2D);
|
||||
else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
|
||||
mv.visitInsn(L2I);
|
||||
convertTo(state, TargetType.Integer, dest);
|
||||
}
|
||||
} else if (source.equals(TargetType.Float)) {
|
||||
if (dest.equals(TargetType.Integer))
|
||||
mv.visitInsn(F2I);
|
||||
else if (dest.equals(TargetType.Double))
|
||||
mv.visitInsn(F2D);
|
||||
else if (dest.equals(TargetType.Long))
|
||||
mv.visitInsn(F2L);
|
||||
else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
|
||||
mv.visitInsn(F2I);
|
||||
convertTo(state, TargetType.Integer, dest);
|
||||
}
|
||||
} else if (source.equals(TargetType.Double)) {
|
||||
if (dest.equals(TargetType.Integer))
|
||||
mv.visitInsn(D2I);
|
||||
else if (dest.equals(TargetType.Float))
|
||||
mv.visitInsn(D2F);
|
||||
else if (dest.equals(TargetType.Long))
|
||||
mv.visitInsn(D2L);
|
||||
else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
|
||||
mv.visitInsn(D2I);
|
||||
convertTo(state, TargetType.Integer, dest);
|
||||
}
|
||||
} else if (source.equals(TargetType.Byte) || source.equals(TargetType.Char) || source.equals(TargetType.Short) || source.equals(TargetType.Integer)) {
|
||||
if (dest.equals(TargetType.Byte))
|
||||
mv.visitInsn(I2B);
|
||||
else if (dest.equals(TargetType.Char))
|
||||
mv.visitInsn(I2C);
|
||||
else if (dest.equals(TargetType.Short))
|
||||
mv.visitInsn(I2S);
|
||||
else if (dest.equals(TargetType.Long))
|
||||
mv.visitInsn(I2L);
|
||||
else if (dest.equals(TargetType.Float))
|
||||
mv.visitInsn(I2F);
|
||||
else if (dest.equals(TargetType.Double))
|
||||
mv.visitInsn(I2D);
|
||||
} else if (source.equals(TargetType.Boolean)) {
|
||||
unboxPrimitive(state, dest);
|
||||
} else if (isFunctionalInterface(source) && isFunctionalInterface(dest) &&
|
||||
|
||||
if (isFunctionalInterface(source) && isFunctionalInterface(dest) &&
|
||||
!(source instanceof TargetFunNType && dest instanceof TargetFunNType)) {
|
||||
boxFunctionalInterface(state, source, dest);
|
||||
} else if (!(dest instanceof TargetGenericType)) {
|
||||
//boxPrimitive(state, source);
|
||||
return;
|
||||
}
|
||||
|
||||
var mv = state.mv;
|
||||
if ((source instanceof TargetRefType || source instanceof TargetGenericType) &&
|
||||
(dest instanceof TargetRefType || dest instanceof TargetGenericType)) {
|
||||
if (dest instanceof TargetGenericType) return;
|
||||
mv.visitTypeInsn(CHECKCAST, dest.getInternalName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(source instanceof TargetPrimitiveType)) {
|
||||
unboxPrimitive(state, source);
|
||||
source = TargetType.toPrimitive(source);
|
||||
}
|
||||
|
||||
var origDest = dest;
|
||||
dest = TargetType.toPrimitive(dest);
|
||||
if (source.equals(TargetType.long_)) {
|
||||
if (dest.equals(TargetType.int_))
|
||||
mv.visitInsn(L2I);
|
||||
else if (dest.equals(TargetType.float_))
|
||||
mv.visitInsn(L2F);
|
||||
else if (dest.equals(TargetType.double_))
|
||||
mv.visitInsn(L2D);
|
||||
else if (dest.equals(TargetType.byte_) || dest.equals(TargetType.char_) || dest.equals(TargetType.short_)) {
|
||||
mv.visitInsn(L2I);
|
||||
convertTo(state, TargetType.int_, dest);
|
||||
}
|
||||
} else if (source.equals(TargetType.float_)) {
|
||||
if (dest.equals(TargetType.int_))
|
||||
mv.visitInsn(F2I);
|
||||
else if (dest.equals(TargetType.double_))
|
||||
mv.visitInsn(F2D);
|
||||
else if (dest.equals(TargetType.long_))
|
||||
mv.visitInsn(F2L);
|
||||
else if (dest.equals(TargetType.byte_) || dest.equals(TargetType.char_) || dest.equals(TargetType.short_)) {
|
||||
mv.visitInsn(F2I);
|
||||
convertTo(state, TargetType.int_, dest);
|
||||
}
|
||||
} else if (source.equals(TargetType.double_)) {
|
||||
if (dest.equals(TargetType.int_))
|
||||
mv.visitInsn(D2I);
|
||||
else if (dest.equals(TargetType.float_))
|
||||
mv.visitInsn(D2F);
|
||||
else if (dest.equals(TargetType.long_))
|
||||
mv.visitInsn(D2L);
|
||||
else if (dest.equals(TargetType.byte_) || dest.equals(TargetType.char_) || dest.equals(TargetType.short_)) {
|
||||
mv.visitInsn(D2I);
|
||||
convertTo(state, TargetType.int_, dest);
|
||||
}
|
||||
} else if (source.equals(TargetType.byte_) || source.equals(TargetType.char_) || source.equals(TargetType.short_) || source.equals(TargetType.int_)) {
|
||||
if (dest.equals(TargetType.byte_))
|
||||
mv.visitInsn(I2B);
|
||||
else if (dest.equals(TargetType.char_))
|
||||
mv.visitInsn(I2C);
|
||||
else if (dest.equals(TargetType.short_))
|
||||
mv.visitInsn(I2S);
|
||||
else if (dest.equals(TargetType.long_))
|
||||
mv.visitInsn(I2L);
|
||||
else if (dest.equals(TargetType.float_))
|
||||
mv.visitInsn(I2F);
|
||||
else if (dest.equals(TargetType.double_))
|
||||
mv.visitInsn(I2D);
|
||||
} else if (source.equals(TargetType.boolean_)) {
|
||||
unboxPrimitive(state, dest);
|
||||
}
|
||||
|
||||
if (!(origDest instanceof TargetPrimitiveType)) {
|
||||
if (dest instanceof TargetPrimitiveType)
|
||||
boxPrimitive(state, dest);
|
||||
else boxPrimitive(state, source);
|
||||
}
|
||||
}
|
||||
|
||||
record TypePair(TargetType from, TargetType to) {}
|
||||
@@ -350,9 +374,9 @@ public class Codegen {
|
||||
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
generate(state, add.left());
|
||||
convertTo(state, add.left().type(), add.type());
|
||||
convertTo(state, add.left().type(), TargetType.toPrimitive(add.type()));
|
||||
generate(state, add.right());
|
||||
convertTo(state, add.right().type(), add.type());
|
||||
convertTo(state, add.right().type(), TargetType.toPrimitive(add.type()));
|
||||
var type = add.type();
|
||||
if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|
||||
mv.visitInsn(IADD);
|
||||
@@ -365,6 +389,7 @@ public class Codegen {
|
||||
} else {
|
||||
throw new CodeGenException("Invalid argument to Add expression, type: " + add.type());
|
||||
}
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
}
|
||||
if (add.type().equals(TargetType.String)) {
|
||||
generate(state, add.right());
|
||||
@@ -376,9 +401,9 @@ public class Codegen {
|
||||
}
|
||||
case Sub sub: {
|
||||
generate(state, sub.left());
|
||||
convertTo(state, sub.left().type(), op.type());
|
||||
convertTo(state, sub.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, sub.right());
|
||||
convertTo(state, sub.right().type(), op.type());
|
||||
convertTo(state, sub.right().type(), TargetType.toPrimitive(op.type()));
|
||||
var type = sub.type();
|
||||
if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|
||||
mv.visitInsn(ISUB);
|
||||
@@ -391,13 +416,14 @@ public class Codegen {
|
||||
} else {
|
||||
throw new CodeGenException("Invalid argument to Sub expression");
|
||||
}
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Div div: {
|
||||
generate(state, div.left());
|
||||
convertTo(state, div.left().type(), op.type());
|
||||
convertTo(state, div.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, div.right());
|
||||
convertTo(state, div.right().type(), op.type());
|
||||
convertTo(state, div.right().type(), TargetType.toPrimitive(op.type()));
|
||||
var type = div.type();
|
||||
if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|
||||
mv.visitInsn(IDIV);
|
||||
@@ -410,13 +436,14 @@ public class Codegen {
|
||||
} else {
|
||||
throw new CodeGenException("Invalid argument to Div expression");
|
||||
}
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Mul mul: {
|
||||
generate(state, mul.left());
|
||||
convertTo(state, mul.left().type(), op.type());
|
||||
convertTo(state, mul.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, mul.right());
|
||||
convertTo(state, mul.right().type(), op.type());
|
||||
convertTo(state, mul.right().type(), TargetType.toPrimitive(op.type()));
|
||||
var type = mul.type();
|
||||
if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|
||||
mv.visitInsn(IMUL);
|
||||
@@ -429,13 +456,14 @@ public class Codegen {
|
||||
} else {
|
||||
throw new CodeGenException("Invalid argument to Mul expression");
|
||||
}
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Rem rem: {
|
||||
generate(state, rem.left());
|
||||
convertTo(state, rem.left().type(), op.type());
|
||||
convertTo(state, rem.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, rem.right());
|
||||
convertTo(state, rem.right().type(), op.type());
|
||||
convertTo(state, rem.right().type(), TargetType.toPrimitive(op.type()));
|
||||
var type = rem.type();
|
||||
if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|
||||
mv.visitInsn(IREM);
|
||||
@@ -448,6 +476,7 @@ public class Codegen {
|
||||
} else {
|
||||
throw new CodeGenException("Invalid argument to Rem expression");
|
||||
}
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Or or: {
|
||||
@@ -455,14 +484,18 @@ public class Codegen {
|
||||
Label or_true = new Label();
|
||||
Label end = new Label();
|
||||
generate(state, or.left());
|
||||
convertTo(state, or.left().type(), TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(IFNE, or_true);
|
||||
generate(state, or.right());
|
||||
convertTo(state, or.right().type(), TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(IFEQ, or_false);
|
||||
mv.visitLabel(or_true);
|
||||
mv.visitInsn(ICONST_1);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(GOTO, end);
|
||||
mv.visitLabel(or_false);
|
||||
mv.visitInsn(ICONST_0);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitLabel(end);
|
||||
break;
|
||||
}
|
||||
@@ -470,47 +503,54 @@ public class Codegen {
|
||||
Label and_false = new Label();
|
||||
Label end = new Label();
|
||||
generate(state, and.left());
|
||||
convertTo(state, and.left().type(), TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(IFEQ, and_false);
|
||||
generate(state, and.right());
|
||||
convertTo(state, and.right().type(), TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(IFEQ, and_false);
|
||||
mv.visitInsn(ICONST_1);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitJumpInsn(GOTO, end);
|
||||
mv.visitLabel(and_false);
|
||||
mv.visitInsn(ICONST_0);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitLabel(end);
|
||||
break;
|
||||
}
|
||||
case BAnd band: {
|
||||
generate(state, band.left());
|
||||
convertTo(state, band.left().type(), op.type());
|
||||
convertTo(state, band.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, band.right());
|
||||
convertTo(state, band.right().type(), op.type());
|
||||
convertTo(state, band.right().type(), TargetType.toPrimitive(op.type()));
|
||||
if (band.type().equals(TargetType.Long))
|
||||
mv.visitInsn(LAND);
|
||||
else
|
||||
mv.visitInsn(IAND);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case BOr bor: {
|
||||
generate(state, bor.left());
|
||||
convertTo(state, bor.left().type(), op.type());
|
||||
convertTo(state, bor.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, bor.right());
|
||||
convertTo(state, bor.right().type(), op.type());
|
||||
convertTo(state, bor.right().type(), TargetType.toPrimitive(op.type()));
|
||||
if (bor.type().equals(TargetType.Long))
|
||||
mv.visitInsn(LOR);
|
||||
else
|
||||
mv.visitInsn(IOR);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case XOr xor: {
|
||||
generate(state, xor.left());
|
||||
convertTo(state, xor.left().type(), op.type());
|
||||
convertTo(state, xor.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, xor.right());
|
||||
convertTo(state, xor.right().type(), op.type());
|
||||
convertTo(state, xor.right().type(), TargetType.toPrimitive(op.type()));
|
||||
if (xor.type().equals(TargetType.Long))
|
||||
mv.visitInsn(LXOR);
|
||||
else
|
||||
mv.visitInsn(IXOR);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Instof instof: {
|
||||
@@ -519,44 +559,47 @@ public class Codegen {
|
||||
}
|
||||
case Shl shl: {
|
||||
generate(state, shl.left());
|
||||
convertTo(state, shl.left().type(), op.type());
|
||||
convertTo(state, shl.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, shl.right());
|
||||
convertTo(state, shl.right().type(), op.type());
|
||||
convertTo(state, shl.right().type(), TargetType.toPrimitive(op.type()));
|
||||
if (shl.type().equals(TargetType.Long))
|
||||
mv.visitInsn(LSHL);
|
||||
else
|
||||
mv.visitInsn(ISHL);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Shr shr: {
|
||||
generate(state, shr.left());
|
||||
convertTo(state, shr.left().type(), op.type());
|
||||
convertTo(state, shr.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, shr.right());
|
||||
convertTo(state, shr.right().type(), op.type());
|
||||
convertTo(state, shr.right().type(), TargetType.toPrimitive(op.type()));
|
||||
if (shr.type().equals(TargetType.Long))
|
||||
mv.visitInsn(LSHR);
|
||||
else
|
||||
mv.visitInsn(ISHR);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case UShr ushr: {
|
||||
generate(state, ushr.left());
|
||||
convertTo(state, ushr.left().type(), op.type());
|
||||
convertTo(state, ushr.left().type(), TargetType.toPrimitive(op.type()));
|
||||
generate(state, ushr.right());
|
||||
convertTo(state, ushr.right().type(), op.type());
|
||||
convertTo(state, ushr.right().type(), TargetType.toPrimitive(op.type()));
|
||||
if (ushr.type().equals(TargetType.Long))
|
||||
mv.visitInsn(LUSHR);
|
||||
else
|
||||
mv.visitInsn(IUSHR);
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
break;
|
||||
}
|
||||
case Greater greater: {
|
||||
var type = largerType(greater.left().type(), greater.right().type());
|
||||
if (type.equals(TargetType.Long)) {
|
||||
var type = TargetType.toPrimitive(largerType(greater.left().type(), greater.right().type()));
|
||||
if (type.equals(TargetType.long_)) {
|
||||
generateRelationalOperator(state, greater, type, LCMP, IFGT);
|
||||
} else if (type.equals(TargetType.Float)) {
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
generateRelationalOperator(state, greater, type, FCMPL, IFGT);
|
||||
} else if (type.equals(TargetType.Double)) {
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
generateRelationalOperator(state, greater, type, DCMPL, IFGT);
|
||||
} else {
|
||||
generateRelationalOperator(state, greater, type, IF_ICMPGT);
|
||||
@@ -564,12 +607,12 @@ public class Codegen {
|
||||
break;
|
||||
}
|
||||
case Less less: {
|
||||
var type = largerType(less.left().type(), less.right().type());
|
||||
if (type.equals(TargetType.Long)) {
|
||||
var type = TargetType.toPrimitive(largerType(less.left().type(), less.right().type()));
|
||||
if (type.equals(TargetType.long_)) {
|
||||
generateRelationalOperator(state, less, type, LCMP, IFLT);
|
||||
} else if (type.equals(TargetType.Float)) {
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
generateRelationalOperator(state, less, type, FCMPL, IFLT);
|
||||
} else if (type.equals(TargetType.Double)) {
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
generateRelationalOperator(state, less, type, DCMPL, IFLT);
|
||||
} else {
|
||||
generateRelationalOperator(state, less, type, IF_ICMPLT);
|
||||
@@ -577,12 +620,12 @@ public class Codegen {
|
||||
break;
|
||||
}
|
||||
case GreaterOrEqual greaterOrEqual: {
|
||||
var type = largerType(greaterOrEqual.left().type(), greaterOrEqual.right().type());
|
||||
if (type.equals(TargetType.Long)) {
|
||||
var type = TargetType.toPrimitive(largerType(greaterOrEqual.left().type(), greaterOrEqual.right().type()));
|
||||
if (type.equals(TargetType.long_)) {
|
||||
generateRelationalOperator(state, greaterOrEqual, type, LCMP, IFGE);
|
||||
} else if (type.equals(TargetType.Float)) {
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
generateRelationalOperator(state, greaterOrEqual, type, FCMPL, IFGE);
|
||||
} else if (type.equals(TargetType.Double)) {
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
generateRelationalOperator(state, greaterOrEqual, type, DCMPL, IFGE);
|
||||
} else {
|
||||
generateRelationalOperator(state, greaterOrEqual, type, IF_ICMPGE);
|
||||
@@ -590,12 +633,12 @@ public class Codegen {
|
||||
break;
|
||||
}
|
||||
case LessOrEqual lessOrEqual: {
|
||||
var type = largerType(lessOrEqual.left().type(), lessOrEqual.right().type());
|
||||
if (type.equals(TargetType.Long)) {
|
||||
var type = TargetType.toPrimitive(largerType(lessOrEqual.left().type(), lessOrEqual.right().type()));
|
||||
if (type.equals(TargetType.long_)) {
|
||||
generateRelationalOperator(state, lessOrEqual, type, LCMP, IFLE);
|
||||
} else if (type.equals(TargetType.Float)) {
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
generateRelationalOperator(state, lessOrEqual, type, FCMPL, IFLE);
|
||||
} else if (type.equals(TargetType.Double)) {
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
generateRelationalOperator(state, lessOrEqual, type, DCMPL, IFLE);
|
||||
} else {
|
||||
generateRelationalOperator(state, lessOrEqual, type, IF_ICMPLE);
|
||||
@@ -603,30 +646,30 @@ public class Codegen {
|
||||
break;
|
||||
}
|
||||
case Equal equal: {
|
||||
var type = largerType(equal.left().type(), equal.right().type());
|
||||
if (type.equals(TargetType.Long)) {
|
||||
generateRelationalOperator(state, equal, type, LCMP, IFEQ);
|
||||
} else if (type.equals(TargetType.Float)) {
|
||||
generateRelationalOperator(state, equal, type, FCMPL, IFEQ);
|
||||
} else if (type.equals(TargetType.Double)) {
|
||||
generateRelationalOperator(state, equal, type, DCMPL, IFEQ);
|
||||
} else if (type.equals(TargetType.Char) || type.equals(TargetType.Short) || type.equals(TargetType.Byte) || type.equals(TargetType.Integer) || type.equals(TargetType.Boolean)) {
|
||||
generateRelationalOperator(state, equal, type, IF_ICMPEQ);
|
||||
var type = TargetType.toPrimitive(largerType(equal.left().type(), equal.right().type()));
|
||||
if (type.equals(TargetType.long_)) {
|
||||
generateRelationalOperator(state, equal, TargetType.long_, LCMP, IFEQ);
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
generateRelationalOperator(state, equal, TargetType.float_, FCMPL, IFEQ);
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
generateRelationalOperator(state, equal, TargetType.double_, DCMPL, IFEQ);
|
||||
} else if (type.equals(TargetType.char_) || type.equals(TargetType.short_) || type.equals(TargetType.byte_) || type.equals(TargetType.int_) || type.equals(TargetType.boolean_)) {
|
||||
generateRelationalOperator(state, equal, TargetType.int_, IF_ICMPEQ);
|
||||
} else {
|
||||
generateRelationalOperator(state, equal, type, IF_ACMPEQ);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NotEqual notEqual: {
|
||||
var type = largerType(notEqual.left().type(), notEqual.right().type());
|
||||
if (type.equals(TargetType.Long)) {
|
||||
generateRelationalOperator(state, notEqual, type, LCMP, IFNE);
|
||||
} else if (type.equals(TargetType.Float)) {
|
||||
generateRelationalOperator(state, notEqual, type, FCMPL, IFNE);
|
||||
} else if (type.equals(TargetType.Double)) {
|
||||
generateRelationalOperator(state, notEqual, type, DCMPL, IFNE);
|
||||
} else if (type.equals(TargetType.Char) || type.equals(TargetType.Short) || type.equals(TargetType.Byte) || type.equals(TargetType.Integer)) {
|
||||
generateRelationalOperator(state, notEqual, type, IF_ICMPNE);
|
||||
var type = TargetType.toPrimitive(largerType(notEqual.left().type(), notEqual.right().type()));
|
||||
if (type.equals(TargetType.long_)) {
|
||||
generateRelationalOperator(state, notEqual, TargetType.long_, LCMP, IFNE);
|
||||
} else if (type.equals(TargetType.float_)) {
|
||||
generateRelationalOperator(state, notEqual, TargetType.float_, FCMPL, IFNE);
|
||||
} else if (type.equals(TargetType.double_)) {
|
||||
generateRelationalOperator(state, notEqual, TargetType.double_, DCMPL, IFNE);
|
||||
} else if (type.equals(TargetType.char_) || type.equals(TargetType.short_) || type.equals(TargetType.byte_) || type.equals(TargetType.int_) || type.equals(TargetType.boolean_)) {
|
||||
generateRelationalOperator(state, notEqual, TargetType.int_, IF_ICMPNE);
|
||||
} else {
|
||||
generateRelationalOperator(state, notEqual, type, IF_ACMPNE);
|
||||
}
|
||||
@@ -657,6 +700,7 @@ public class Codegen {
|
||||
generate(state, add.expr());
|
||||
case TargetUnaryOp.Negate negate -> {
|
||||
generate(state, negate.expr());
|
||||
convertTo(state, negate.expr().type(), TargetType.boolean_);
|
||||
if (negate.type().equals(TargetType.Double))
|
||||
mv.visitInsn(DNEG);
|
||||
else if (negate.type().equals(TargetType.Float))
|
||||
@@ -665,9 +709,11 @@ public class Codegen {
|
||||
mv.visitInsn(LNEG);
|
||||
else
|
||||
mv.visitInsn(INEG);
|
||||
boxPrimitive(state, TargetType.toPrimitive(negate.expr().type()));
|
||||
}
|
||||
case TargetUnaryOp.Not not -> {
|
||||
generate(state, not.expr());
|
||||
convertTo(state, not.expr().type(), TargetType.boolean_);
|
||||
if (not.type().equals(TargetType.Long)) {
|
||||
mv.visitLdcInsn(-1L);
|
||||
mv.visitInsn(LXOR);
|
||||
@@ -675,93 +721,86 @@ public class Codegen {
|
||||
mv.visitInsn(ICONST_M1);
|
||||
mv.visitInsn(IXOR);
|
||||
}
|
||||
boxPrimitive(state, TargetType.toPrimitive(not.expr().type()));
|
||||
}
|
||||
case TargetUnaryOp.PreIncrement preIncrement -> {
|
||||
generate(state, preIncrement.expr());
|
||||
convertTo(state, preIncrement.expr().type(), TargetType.toPrimitive(op.type()));
|
||||
if (preIncrement.type().equals(TargetType.Float)) {
|
||||
mv.visitLdcInsn(1F);
|
||||
mv.visitInsn(FADD);
|
||||
mv.visitInsn(DUP);
|
||||
} else if (preIncrement.type().equals(TargetType.Double)) {
|
||||
mv.visitLdcInsn(1D);
|
||||
mv.visitInsn(DADD);
|
||||
mv.visitInsn(DUP2);
|
||||
} else if (preIncrement.type().equals(TargetType.Long)) {
|
||||
mv.visitLdcInsn(1L);
|
||||
mv.visitInsn(LADD);
|
||||
mv.visitInsn(DUP2);
|
||||
} else {
|
||||
mv.visitLdcInsn(1);
|
||||
mv.visitInsn(IADD);
|
||||
mv.visitInsn(DUP);
|
||||
}
|
||||
boxPrimitive(state, preIncrement.type());
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitInsn(DUP);
|
||||
afterIncDec(state, preIncrement);
|
||||
}
|
||||
case TargetUnaryOp.PreDecrement preDecrement -> {
|
||||
generate(state, preDecrement.expr());
|
||||
convertTo(state, preDecrement.expr().type(), TargetType.toPrimitive(op.type()));
|
||||
if (preDecrement.type().equals(TargetType.Float)) {
|
||||
mv.visitLdcInsn(1F);
|
||||
mv.visitInsn(FSUB);
|
||||
mv.visitInsn(DUP);
|
||||
} else if (preDecrement.type().equals(TargetType.Double)) {
|
||||
mv.visitLdcInsn(1D);
|
||||
mv.visitInsn(DSUB);
|
||||
mv.visitInsn(DUP2);
|
||||
} else if (preDecrement.type().equals(TargetType.Long)) {
|
||||
mv.visitLdcInsn(1L);
|
||||
mv.visitInsn(LSUB);
|
||||
mv.visitInsn(DUP2);
|
||||
} else {
|
||||
mv.visitLdcInsn(1);
|
||||
mv.visitInsn(ISUB);
|
||||
mv.visitInsn(DUP);
|
||||
}
|
||||
boxPrimitive(state, preDecrement.type());
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
mv.visitInsn(DUP);
|
||||
afterIncDec(state, preDecrement);
|
||||
}
|
||||
case TargetUnaryOp.PostIncrement postIncrement -> {
|
||||
generate(state, postIncrement.expr());
|
||||
mv.visitInsn(DUP);
|
||||
convertTo(state, postIncrement.expr().type(), TargetType.toPrimitive(op.type()));
|
||||
if (postIncrement.type().equals(TargetType.Float)) {
|
||||
mv.visitInsn(DUP);
|
||||
mv.visitLdcInsn(1F);
|
||||
mv.visitInsn(FADD);
|
||||
} else if (postIncrement.type().equals(TargetType.Double)) {
|
||||
mv.visitInsn(DUP2);
|
||||
mv.visitLdcInsn(1D);
|
||||
mv.visitInsn(DADD);
|
||||
} else if (postIncrement.type().equals(TargetType.Long)) {
|
||||
mv.visitInsn(DUP2);
|
||||
mv.visitLdcInsn(1L);
|
||||
mv.visitInsn(LADD);
|
||||
} else {
|
||||
mv.visitInsn(DUP);
|
||||
mv.visitLdcInsn(1);
|
||||
mv.visitInsn(IADD);
|
||||
}
|
||||
boxPrimitive(state, postIncrement.type());
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
afterIncDec(state, postIncrement);
|
||||
}
|
||||
case TargetUnaryOp.PostDecrement postDecrement -> {
|
||||
generate(state, postDecrement.expr());
|
||||
mv.visitInsn(DUP);
|
||||
convertTo(state, postDecrement.expr().type(), TargetType.toPrimitive(op.type()));
|
||||
if (postDecrement.type().equals(TargetType.Float)) {
|
||||
mv.visitInsn(DUP);
|
||||
mv.visitLdcInsn(1F);
|
||||
mv.visitInsn(FSUB);
|
||||
} else if (postDecrement.type().equals(TargetType.Double)) {
|
||||
mv.visitInsn(DUP2);
|
||||
mv.visitLdcInsn(1D);
|
||||
mv.visitInsn(DSUB);
|
||||
} else if (postDecrement.type().equals(TargetType.Long)) {
|
||||
mv.visitInsn(DUP2);
|
||||
mv.visitLdcInsn(1L);
|
||||
mv.visitInsn(LSUB);
|
||||
} else {
|
||||
mv.visitInsn(DUP);
|
||||
mv.visitLdcInsn(1);
|
||||
mv.visitInsn(ISUB);
|
||||
}
|
||||
boxPrimitive(state, postDecrement.type());
|
||||
boxPrimitive(state, TargetType.toPrimitive(op.type()));
|
||||
afterIncDec(state, postDecrement);
|
||||
}
|
||||
}
|
||||
@@ -909,7 +948,7 @@ public class Codegen {
|
||||
var local = state.createVariable(varDecl.name(), varDecl.varType());
|
||||
if (varDecl.value() != null) {
|
||||
generate(state, varDecl.value());
|
||||
boxPrimitive(state, varDecl.varType());
|
||||
boxPrimitive(state, varDecl.value().type());
|
||||
mv.visitVarInsn(ASTORE, local.index());
|
||||
} else {
|
||||
mv.visitInsn(ACONST_NULL);
|
||||
@@ -958,14 +997,14 @@ public class Codegen {
|
||||
mv.visitVarInsn(ALOAD, local.index());
|
||||
// This is a bit weird but sometimes the types don't match (see lambda expressions)
|
||||
convertTo(state, local.type(), localVar.type());
|
||||
unboxPrimitive(state, local.type());
|
||||
//unboxPrimitive(state, local.type());
|
||||
break;
|
||||
}
|
||||
case TargetFieldVar dot: {
|
||||
if (!dot.isStatic())
|
||||
generate(state, dot.left());
|
||||
mv.visitFieldInsn(dot.isStatic() ? GETSTATIC : GETFIELD, dot.left().type().getInternalName(), dot.right(), dot.type().toDescriptor());
|
||||
unboxPrimitive(state, dot.type());
|
||||
//unboxPrimitive(state, dot.type());
|
||||
break;
|
||||
}
|
||||
case TargetFor _for: {
|
||||
@@ -981,11 +1020,14 @@ public class Codegen {
|
||||
Label start = new Label();
|
||||
Label end = new Label();
|
||||
mv.visitLabel(start);
|
||||
if (_for.termination() != null)
|
||||
if (_for.termination() != null) {
|
||||
generate(state, _for.termination());
|
||||
else
|
||||
convertTo(state, _for.termination().type(), TargetType.boolean_);
|
||||
mv.visitJumpInsn(IFEQ, end);
|
||||
} else {
|
||||
mv.visitInsn(ICONST_1);
|
||||
mv.visitJumpInsn(IFEQ, end);
|
||||
mv.visitJumpInsn(IFEQ, end);
|
||||
}
|
||||
|
||||
var env = new BreakEnv();
|
||||
env.startLabel = start;
|
||||
@@ -1017,6 +1059,7 @@ public class Codegen {
|
||||
Label end = new Label();
|
||||
mv.visitLabel(start);
|
||||
generate(state, _while.cond());
|
||||
convertTo(state, _while.cond().type(), TargetType.boolean_);
|
||||
mv.visitJumpInsn(IFEQ, end);
|
||||
|
||||
var env = new BreakEnv();
|
||||
@@ -1047,6 +1090,7 @@ public class Codegen {
|
||||
|
||||
mv.visitLabel(check);
|
||||
generate(state, _do.cond());
|
||||
convertTo(state, _do.cond().type(), TargetType.boolean_);
|
||||
mv.visitJumpInsn(IFEQ, end);
|
||||
mv.visitJumpInsn(GOTO, start);
|
||||
mv.visitLabel(end);
|
||||
@@ -1054,6 +1098,7 @@ public class Codegen {
|
||||
}
|
||||
case TargetIf _if: {
|
||||
generate(state, _if.cond());
|
||||
convertTo(state, _if.cond().type(), TargetType.boolean_);
|
||||
Label _else = new Label();
|
||||
Label end = new Label();
|
||||
mv.visitJumpInsn(IFEQ, _else);
|
||||
@@ -1067,20 +1112,23 @@ public class Codegen {
|
||||
break;
|
||||
}
|
||||
case TargetReturn ret: {
|
||||
if (ret.expression() != null && state.returnType != null) {
|
||||
if (ret.expression() != null) {
|
||||
if (state.returnType instanceof TargetPrimitiveType) {
|
||||
generate(state, ret.expression());
|
||||
|
||||
unboxPrimitive(state, state.returnType);
|
||||
mv.visitInsn(findReturnCode(state.returnType));
|
||||
// Lambdas wrap the expression in a return if they are a single expression
|
||||
// It means we have to execute the code anyway but not return anything
|
||||
if (state.returnType != null) {
|
||||
convertTo(state, ret.expression().type(), state.returnType);
|
||||
mv.visitInsn(findReturnCode(state.returnType));
|
||||
}
|
||||
} else {
|
||||
generate(state, ret.expression());
|
||||
boxPrimitive(state, ret.expression().type());
|
||||
convertTo(state, ret.expression().type(), state.returnType);
|
||||
mv.visitInsn(ARETURN);
|
||||
if (state.returnType != null) {
|
||||
convertTo(state, ret.expression().type(), state.returnType);
|
||||
mv.visitInsn(ARETURN);
|
||||
}
|
||||
}
|
||||
} else
|
||||
mv.visitInsn(RETURN);
|
||||
} else mv.visitInsn(RETURN);
|
||||
break;
|
||||
}
|
||||
case TargetYield yield: {
|
||||
@@ -1127,12 +1175,14 @@ public class Codegen {
|
||||
var arg = call.parameterTypes().get(i);
|
||||
generate(state, e);
|
||||
convertTo(state, e.type(), arg);
|
||||
if (!(arg instanceof TargetPrimitiveType))
|
||||
boxPrimitive(state, e.type());
|
||||
}
|
||||
var descriptor = call.getDescriptor();
|
||||
if (call.owner() instanceof TargetFunNType) // Decay FunN
|
||||
descriptor = TargetMethod.getDescriptor(call.returnType() == null ? null : TargetType.Object, call.parameterTypes().stream().map(x -> TargetType.Object).toArray(TargetType[]::new));
|
||||
if (call.owner() instanceof TargetFunNType owner) {
|
||||
// Decay FunN
|
||||
descriptor = TargetMethod.getDescriptor(
|
||||
(owner.returnArguments() == 0 ? null : TargetType.Object),
|
||||
call.parameterTypes().stream().map(x -> TargetType.Object).toArray(TargetType[]::new));
|
||||
}
|
||||
|
||||
int insn = INVOKEVIRTUAL;
|
||||
if (call.isStatic()) insn = INVOKESTATIC;
|
||||
@@ -1141,11 +1191,13 @@ public class Codegen {
|
||||
|
||||
mv.visitMethodInsn(insn, call.owner().getInternalName(), call.name(), descriptor, call.isInterface());
|
||||
|
||||
if (call.type() != null && call.returnType() != null && !(call.returnType() instanceof TargetPrimitiveType)) {
|
||||
/*if (call.type() != null && call.returnType() != null && !(call.returnType() instanceof TargetPrimitiveType)) {
|
||||
if (!call.returnType().equals(call.type()) && !(call.type() instanceof TargetGenericType))
|
||||
mv.visitTypeInsn(CHECKCAST, call.type().getInternalName());
|
||||
unboxPrimitive(state, call.type());
|
||||
}
|
||||
}*/
|
||||
if (call.type() != null)
|
||||
convertTo(state, call.returnType(), call.type());
|
||||
break;
|
||||
}
|
||||
case TargetLambdaExpression lambda:
|
||||
@@ -1154,9 +1206,10 @@ public class Codegen {
|
||||
case TargetNew _new: {
|
||||
mv.visitTypeInsn(NEW, _new.type().getInternalName());
|
||||
mv.visitInsn(DUP);
|
||||
for (TargetExpression e : _new.params()) {
|
||||
for (var i = 0; i < _new.params().size(); i++) {
|
||||
var e = _new.params().get(i);
|
||||
generate(state, e);
|
||||
boxPrimitive(state, e.type());
|
||||
convertTo(state, e.type(), _new.signature().get(i));
|
||||
}
|
||||
mv.visitMethodInsn(INVOKESPECIAL, _new.type().getInternalName(), "<init>", _new.getDescriptor(), false);
|
||||
break;
|
||||
@@ -1168,6 +1221,7 @@ public class Codegen {
|
||||
}
|
||||
case TargetTernary ternary: {
|
||||
generate(state, ternary.cond());
|
||||
convertTo(state, ternary.cond().type(), TargetType.boolean_);
|
||||
var iffalse = new Label();
|
||||
var end = new Label();
|
||||
mv.visitJumpInsn(IFEQ, iffalse);
|
||||
@@ -1221,6 +1275,7 @@ public class Codegen {
|
||||
if (instanceOf.right() instanceof TargetTypePattern right && right.name() == null) {
|
||||
generate(state, instanceOf.left());
|
||||
mv.visitTypeInsn(INSTANCEOF, right.type().getInternalName());
|
||||
boxPrimitive(state, TargetType.boolean_);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1228,6 +1283,7 @@ public class Codegen {
|
||||
}
|
||||
|
||||
private void yieldValue(State state, TargetType type) {
|
||||
if (type == null) return;
|
||||
boxPrimitive(state, type);
|
||||
state.mv.visitVarInsn(ASTORE, state.switchResultValue.peek());
|
||||
}
|
||||
@@ -1243,6 +1299,7 @@ public class Codegen {
|
||||
state.pushSwitch();
|
||||
|
||||
generate(state, aSwitch.expr());
|
||||
unboxPrimitive(state, aSwitch.expr().type());
|
||||
|
||||
state.enterScope();
|
||||
|
||||
@@ -1378,6 +1435,7 @@ public class Codegen {
|
||||
|
||||
if (label instanceof TargetGuard gd) {
|
||||
generate(state, gd.expression());
|
||||
unboxPrimitive(state, TargetType.Boolean);
|
||||
var next = new Label();
|
||||
mv.visitJumpInsn(IFNE, next);
|
||||
mv.visitVarInsn(ALOAD, tmp);
|
||||
@@ -1415,7 +1473,7 @@ public class Codegen {
|
||||
if (aSwitch.isExpression()) {
|
||||
if (aSwitch.type() != null) {
|
||||
mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
|
||||
unboxPrimitive(state, aSwitch.type());
|
||||
//unboxPrimitive(state, aSwitch.type());
|
||||
}
|
||||
state.popSwitch();
|
||||
}
|
||||
@@ -1432,8 +1490,8 @@ public class Codegen {
|
||||
}
|
||||
|
||||
private void bindPattern(State state, TargetType type, TargetPattern pat, Label start, int index, int depth) {
|
||||
if (pat.type() instanceof TargetPrimitiveType)
|
||||
boxPrimitive(state, pat.type());
|
||||
//if (pat.type() instanceof TargetPrimitiveType)
|
||||
// boxPrimitive(state, pat.type());
|
||||
|
||||
if (pat.type() instanceof TargetRefType) {
|
||||
state.mv.visitInsn(DUP);
|
||||
@@ -1454,11 +1512,14 @@ public class Codegen {
|
||||
}
|
||||
|
||||
if (pat instanceof TargetExpressionPattern ep) {
|
||||
var cur = state.createVariable(pat.type());
|
||||
var cur = state.createVariable(TargetType.toWrapper(pat.type()));
|
||||
state.mv.visitVarInsn(ASTORE, cur.index);
|
||||
|
||||
var expr = new Equal(pat.type(), new TargetLocalVar(cur.type, cur.name), ep.expression());
|
||||
generate(state, expr);
|
||||
// For Strings we must use equals, and why not make it work for all types?
|
||||
generate(state, new TargetLocalVar(cur.type, cur.name));
|
||||
generate(state, ep.expression());
|
||||
boxPrimitive(state, ep.expression().type());
|
||||
state.mv.visitMethodInsn(INVOKESTATIC, "java/util/Objects", "equals", "(Ljava/lang/Object;Ljava/lang/Object;)Z", false);
|
||||
|
||||
var cont = new Label();
|
||||
state.mv.visitJumpInsn(IFNE, cont);
|
||||
@@ -1656,7 +1717,7 @@ public class Codegen {
|
||||
generate(state, method.block());
|
||||
if (method.signature().returnType() == null)
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
mv.visitMaxs(0, 0);
|
||||
}
|
||||
mv.visitEnd();
|
||||
}
|
||||
@@ -1672,6 +1733,8 @@ public class Codegen {
|
||||
}
|
||||
if (clazz.superType() != null)
|
||||
ret += clazz.superType().toSignature();
|
||||
else ret += "Ljava/lang/Object;";
|
||||
|
||||
for (var intf : clazz.implementingInterfaces()) {
|
||||
ret += intf.toSignature();
|
||||
}
|
||||
@@ -1774,8 +1837,12 @@ public class Codegen {
|
||||
} else convertTo(state, fromReturn, toReturn);
|
||||
}
|
||||
|
||||
if (toReturn != null)
|
||||
if (toReturn != null) {
|
||||
if ((fromReturn instanceof TargetRefType || fromReturn instanceof TargetGenericType)
|
||||
&& (toReturn instanceof TargetPrimitiveType))
|
||||
unboxPrimitive(state, TargetType.toWrapper(toReturn));
|
||||
mv.visitInsn(findReturnCode(toReturn));
|
||||
}
|
||||
|
||||
else mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(0, 0);
|
||||
@@ -1784,19 +1851,13 @@ public class Codegen {
|
||||
cw2.visitEnd();
|
||||
var bytes = cw2.toByteArray();
|
||||
compiler.auxiliaries.put(className, bytes);
|
||||
|
||||
// TODO These class loading shenanigans happen in a few places, the tests load the classes individually.
|
||||
// Instead we should just look at the folder.
|
||||
try {
|
||||
converter.classLoader.findClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
converter.classLoader.loadClass(className, bytes);
|
||||
} catch (LinkageError ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
cw.visitEnd();
|
||||
//ClassReader cr = new ClassReader(cw.toByteArray());
|
||||
//System.out.println("Checking class " + className);
|
||||
// TODO This fails for multi class projects because it tries to load the other classes
|
||||
//CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class FunNGenerator {
|
||||
if (type == null) return VOID;
|
||||
var res = "L" + type.getInternalName();
|
||||
if (type instanceof TargetSpecializedType a) {
|
||||
if (a.params().size() > 0) {
|
||||
if (!a.params().isEmpty() && !(a.params().size() == 1 && a.params().getFirst() == null)) {
|
||||
res += "<";
|
||||
for (var param : a.params()) {
|
||||
if (param instanceof TargetGenericType gp) {
|
||||
@@ -115,11 +115,12 @@ public class FunNGenerator {
|
||||
superFunNMethodSignature.append(String.format("T%s;", argumentGenericBase + currentParameter));
|
||||
superFunNMethodDescriptor.append(objectSignature);
|
||||
}
|
||||
superFunNClassSignature.append(String.format("%s:%s>%s", returnGeneric, objectSignature, objectSignature));
|
||||
if (numReturnTypes > 0) {
|
||||
superFunNClassSignature.append(String.format("%s:%s>%s", returnGeneric, objectSignature, objectSignature));
|
||||
superFunNMethodSignature.append(String.format(")T%s;", returnGeneric));
|
||||
superFunNMethodDescriptor.append(String.format(")%s", objectSignature));
|
||||
} else {
|
||||
superFunNClassSignature = new StringBuilder(objectSignature);
|
||||
superFunNMethodSignature.append(")V");
|
||||
superFunNMethodDescriptor.append(")V");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||
import de.dhbwstuttgart.exceptions.DebugException;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
@@ -67,7 +68,7 @@ public class JavaTXCompiler {
|
||||
Boolean resultmodel = true;
|
||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||
|
||||
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||
public final DirectoryClassLoader classLoader;
|
||||
|
||||
@@ -475,6 +476,85 @@ public class JavaTXCompiler {
|
||||
return results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* TEMPORARY - Only for Language Server Usage
|
||||
*/
|
||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(File file) throws IOException, ClassNotFoundException {
|
||||
var sf = sourceFiles.get(file);
|
||||
if(sf == null){
|
||||
sf = sourceFiles.values().stream().findFirst().get();
|
||||
}
|
||||
Set<ClassOrInterface> allClasses = new HashSet<>();
|
||||
allClasses.addAll(getAvailableClasses(sf));
|
||||
allClasses.addAll(sf.getClasses());
|
||||
var newClasses = CompilationEnvironment.loadDefaultPackageClasses(sf.getPkgName(), file, this).stream().map(ASTFactory::createClass).collect(Collectors.toSet());
|
||||
for (var clazz : newClasses) {
|
||||
// Don't load classes that get recompiled
|
||||
if (sf.getClasses().stream().anyMatch(nf -> nf.getClassName().equals(clazz.getClassName())))
|
||||
continue;
|
||||
if (allClasses.stream().noneMatch(old -> old.getClassName().equals(clazz.getClassName())))
|
||||
allClasses.add(clazz);
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints(file);
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
Writer logFile = new OutputStreamWriter(new NullOutputStream());
|
||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses.stream().toList(), logFile, classLoader, this);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(this, cons);
|
||||
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
||||
UnifyType lhs, rhs;
|
||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType) && ((rhs = x.getRhsType()) instanceof PlaceholderType) && (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
|
||||
((PlaceholderType) lhs).setInnerType(true);
|
||||
((PlaceholderType) rhs).setInnerType(true);
|
||||
}
|
||||
return x;
|
||||
|
||||
};
|
||||
|
||||
|
||||
unifyCons = unifyCons.map(distributeInnerVars);
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<PlaceholderType> varianceTPHold;
|
||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
||||
|
||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints();
|
||||
|
||||
if (resultmodel) {
|
||||
/* UnifyResultModel Anfang */
|
||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||
urm.addUnifyResultListener(li);
|
||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
||||
generateBytecode(sf, li.getResults());
|
||||
return new LanguageServerTransferObject(li.getResults(), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||
}
|
||||
/* UnifyResultModel End */
|
||||
else {
|
||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
||||
results.addAll(result);
|
||||
|
||||
results = results.stream().map(x -> {
|
||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC)
|
||||
y.setPairOp(PairOperator.EQUALSDOT);
|
||||
return y; // alle Paare a <.? b erden durch a =. b ersetzt
|
||||
}).collect(Collectors.toCollection(HashSet::new)));
|
||||
if (res.isPresent()) {// wenn subst ein Erg liefert wurde was veraendert
|
||||
return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure);
|
||||
} else
|
||||
return x; // wenn nichts veraendert wurde wird x zurueckgegeben
|
||||
}).collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
generateBytecode(sf, results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()));
|
||||
return new LanguageServerTransferObject(results.stream().map((unifyPairs -> new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()), sf, ASTTypePrinter.print(sf), generatedGenerics);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine Variance !=0 hat auf alle Typvariablen in Theta.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package de.dhbwstuttgart.languageServerInterface;
|
||||
|
||||
|
||||
import de.dhbwstuttgart.bytecode.Codegen;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.LanguageServerTransferObject;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
|
||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.target.tree.TargetStructure;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Implementation of an Interface for the Language-Server to get the Resultset and abstract Syntax.
|
||||
*/
|
||||
public class LanguageServerInterface {
|
||||
|
||||
|
||||
public LanguageServerTransferObject getResultSetAndAbastractSyntax(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
NameGenerator.resetTo(resetNamesTo);
|
||||
return getResultSetAndAbstractSyntax(path);
|
||||
|
||||
}
|
||||
|
||||
public SourceFile getAst(String path, String resetNamesTo) throws IOException, URISyntaxException, ClassNotFoundException {
|
||||
NameGenerator.resetTo(resetNamesTo);
|
||||
return getAST(path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the ResultSets, GenericResultSet and the AST
|
||||
* You have to give the input as well as the path because of potential locks when the File is currently opened in an IDE.
|
||||
* Example: file:///c:/test/main.jav -> file:///c:/test/out/main.class
|
||||
*
|
||||
* @param pathAsString the URI of the File. See Example.
|
||||
*/
|
||||
public LanguageServerTransferObject getResultSetAndAbstractSyntax(String pathAsString){
|
||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||
try {
|
||||
var uri = new URI(pathAsString);
|
||||
var path = Path.of(uri);
|
||||
var file = path.toFile();
|
||||
Files.createDirectories(path.getParent().resolve("out"));
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(path.getParent().toFile()), path.getParent().resolve("out").toFile());
|
||||
|
||||
var parsedSource = compiler.sourceFiles.get(file);
|
||||
var tiResults = compiler.typeInference(file);
|
||||
|
||||
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(parsedSource, tiResults);
|
||||
Files.createDirectories(path.getParent().resolve("out"));
|
||||
compiler.writeClassFile(bytecode, path.getParent().resolve("out").toFile(), false);
|
||||
|
||||
return new LanguageServerTransferObject(tiResults, parsedSource, "", compiler.getGeneratedGenerics());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the AST without calculating the result
|
||||
* You have to give the input as well as the path because of potential locks when the File is currently opened in an IDE.
|
||||
* Example: file:///c:/test/main.jav -> file:///c:/test/out/main.class
|
||||
*
|
||||
* @param path the URI of the File. See Example.
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
public SourceFile getAST(String path) throws IOException, ClassNotFoundException, URISyntaxException {
|
||||
|
||||
|
||||
System.setOut(new PrintStream(OutputStream.nullOutputStream()));
|
||||
|
||||
|
||||
URI uri = new URI(path);
|
||||
ArrayList<String> pathWithoutName = new ArrayList<>(List.of(uri.getPath().split("/")));
|
||||
pathWithoutName.remove(List.of(uri.getPath().split("/")).size() - 1);
|
||||
String stringPathWithoutName = "";
|
||||
|
||||
for (String i : pathWithoutName) {
|
||||
stringPathWithoutName += "/" + i;
|
||||
}
|
||||
|
||||
try {
|
||||
FileUtils.cleanDirectory(new File(stringPathWithoutName + "/out"));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
try {
|
||||
(new File(stringPathWithoutName + "/out")).mkdirs();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
var test = getAST(uri.getPath().split("/")[uri.getPath().split("/").length - 1], new File(stringPathWithoutName).getPath());
|
||||
System.setOut(System.out);
|
||||
return test;
|
||||
}
|
||||
|
||||
public static SourceFile getAST(String filename, String filePath) throws IOException, ClassNotFoundException {
|
||||
var file = Path.of(filePath, filename).toFile();
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()), Path.of(filePath + "/out").toFile());
|
||||
return compiler.sourceFiles.get(file);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.dhbwstuttgart.languageServerInterface;
|
||||
|
||||
|
||||
|
||||
import de.dhbwstuttgart.languageServerInterface.model.CustomParserErrorHandler;
|
||||
import de.dhbwstuttgart.languageServerInterface.model.ParserError;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Lexer;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17ParserBaseListener;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ParserInterface {
|
||||
|
||||
public List<ParserError> getParseErrors(String input){
|
||||
|
||||
CustomParserErrorHandler errorListener = new CustomParserErrorHandler();
|
||||
CharStream charStream = CharStreams.fromString(input);
|
||||
|
||||
Java17Lexer lexer = new Java17Lexer(charStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
Java17Parser parser = new Java17Parser(tokens);
|
||||
parser.removeErrorListeners();
|
||||
parser.addErrorListener(errorListener);
|
||||
|
||||
|
||||
ParseTree tree = parser.sourceFile();
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
Java17ParserBaseListener listener = new Java17ParserBaseListener();
|
||||
walker.walk(listener, tree);
|
||||
|
||||
return errorListener.getErrorMessages();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package de.dhbwstuttgart.languageServerInterface.model;
|
||||
|
||||
|
||||
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.atn.ATNConfigSet;
|
||||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomParserErrorHandler implements ANTLRErrorListener {
|
||||
private final List<ParserError> errorMessages = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
|
||||
int endCharPosition = charPositionInLine;
|
||||
if (offendingSymbol instanceof Token) {
|
||||
Token offendingToken = (Token) offendingSymbol;
|
||||
endCharPosition = charPositionInLine + offendingToken.getText().length();
|
||||
}
|
||||
|
||||
ParserError parserError = new ParserError(line, charPositionInLine, endCharPosition, msg);
|
||||
errorMessages.add(parserError);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportAmbiguity(Parser parser, DFA dfa, int i, int i1, boolean b, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportAttemptingFullContext(Parser parser, DFA dfa, int i, int i1, BitSet bitSet, ATNConfigSet atnConfigSet) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportContextSensitivity(Parser parser, DFA dfa, int i, int i1, int i2, ATNConfigSet atnConfigSet) {
|
||||
|
||||
}
|
||||
|
||||
public List<ParserError> getErrorMessages() {
|
||||
return errorMessages;
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package de.dhbwstuttgart.languageServerInterface.model;
|
||||
|
||||
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class LanguageServerTransferObject {
|
||||
List<ResultSet> resultSets;
|
||||
SourceFile Ast;
|
||||
String printedAst;
|
||||
Map<SourceFile, List<GenericsResult>> generatedGenerics = new HashMap<>();
|
||||
|
||||
|
||||
public LanguageServerTransferObject(List<ResultSet> resultSets, SourceFile Ast, String printedAst, Map<SourceFile, List<GenericsResult>> generatedGenerics) {
|
||||
this.resultSets = resultSets;
|
||||
this.Ast = Ast;
|
||||
this.printedAst = printedAst;
|
||||
this.generatedGenerics = generatedGenerics;
|
||||
}
|
||||
|
||||
public List<ResultSet> getResultSets() {return resultSets;}
|
||||
public SourceFile getAst() {return Ast;}
|
||||
public String getPrintedAst() {return printedAst;}
|
||||
public Map<SourceFile, List<GenericsResult>> getGeneratedGenerics() {return generatedGenerics;}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package de.dhbwstuttgart.languageServerInterface.model;
|
||||
|
||||
public class ParserError {
|
||||
|
||||
private int line;
|
||||
private int charPositionInLine;
|
||||
private int endCharPosition;
|
||||
String msg;
|
||||
|
||||
public ParserError(int line, int charPositionInLine, int endCharPosition, String msg) {
|
||||
this.line = line;
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
this. endCharPosition = endCharPosition;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getEndCharPosition() {
|
||||
return endCharPosition;
|
||||
}
|
||||
|
||||
public void setEndCharPosition(int endCharPosition) {
|
||||
this.endCharPosition = endCharPosition;
|
||||
}
|
||||
|
||||
public void setCharPositionInLine(int charPositionInLine) {
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
}
|
||||
|
||||
public void setLine(int line) {
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getCharPositionInLine() {
|
||||
return charPositionInLine;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package de.dhbwstuttgart.languageServerInterface.model;
|
||||
|
||||
|
||||
import com.google.common.reflect.TypeResolver;
|
||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultEvent;
|
||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
||||
|
||||
public class ResultSetListener implements UnifyResultListener {
|
||||
|
||||
TypeResolver typeResolver;
|
||||
|
||||
public ResultSetListener(TypeResolver typeResolver){
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewTypeResultFound(UnifyResultEvent evt) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class SyntaxTreeGenerator {
|
||||
this.allmodifiers.put(Modifier.toString(Modifier.INTERFACE), Modifier.INTERFACE);
|
||||
this.allmodifiers.put("sealed", 4096);
|
||||
this.allmodifiers.put("non-sealed", 8192);
|
||||
this.allmodifiers.put("default", 16384);
|
||||
this.allmodifiers.put("default", 0); // Doesn't exist
|
||||
this.allmodifiers.put("strictfp", 32768);
|
||||
|
||||
this.compiler = compiler;
|
||||
|
||||
@@ -168,7 +168,7 @@ public class TypeGenerator {
|
||||
if (generics.contains(name)) {
|
||||
return new GenericRefType(name, offset);
|
||||
} else {
|
||||
Pattern p = Pattern.compile("Fun(\\d+)[$][$]");
|
||||
Pattern p = Pattern.compile("Fun(Void|VoidImpl|Wrapper)?(\\d+)[$][$]"); // TODO Regex shenanigans
|
||||
Matcher m = p.matcher(name);
|
||||
if (m.matches()) {// es ist FunN$$-Type
|
||||
return new RefType(new JavaClassName(name), convert(typeArguments, reg, generics), offset);
|
||||
|
||||
@@ -13,6 +13,10 @@ public class NameGenerator {
|
||||
public static void reset() {
|
||||
strNextName = "A";
|
||||
}
|
||||
|
||||
public static void resetTo(String name) {
|
||||
strNextName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet einen neuen, eindeutigen Namen f�r eine neue
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
package de.dhbwstuttgart.target.generate;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||
@@ -845,13 +846,6 @@ public class ASTToTargetAST {
|
||||
compiler.usedFunNSuperTypes.add(params.size());
|
||||
var code = FunNGenerator.generateSuperBytecode(params.size() - 1, returnType != null ? 1 : 0);
|
||||
var superClassName = FunNGenerator.getSuperClassName(params.size() - 1, returnType != null ? 1 : 0);
|
||||
try {
|
||||
compiler.classLoader.findClass(superClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
compiler.classLoader.loadClass(superClassName, code);
|
||||
} catch (LinkageError ignored) {}
|
||||
}
|
||||
compiler.auxiliaries.put(superClassName, code);
|
||||
}
|
||||
FunNGenerator.GenericParameters gep = null;
|
||||
|
||||
@@ -161,7 +161,6 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
var isStatic = false;
|
||||
var type = converter.convert(fieldVar.receiver.getType());
|
||||
var clazz = converter.compiler.getClass(new JavaClassName(type.name()));
|
||||
var field = clazz.getField(fieldVar.fieldVarName).orElseThrow();
|
||||
|
||||
@@ -8,42 +8,42 @@ public sealed interface TargetLiteral extends TargetExpression {
|
||||
record BooleanLiteral(Boolean value) implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Boolean;
|
||||
return TargetType.boolean_;
|
||||
}
|
||||
}
|
||||
|
||||
record CharLiteral(Character value) implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Char;
|
||||
return TargetType.char_;
|
||||
}
|
||||
}
|
||||
|
||||
record IntLiteral(Integer value) implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Integer;
|
||||
return TargetType.int_;
|
||||
}
|
||||
}
|
||||
|
||||
record LongLiteral(Long value) implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Long;
|
||||
return TargetType.long_;
|
||||
}
|
||||
}
|
||||
|
||||
record FloatLiteral(Float value) implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Float;
|
||||
return TargetType.float_;
|
||||
}
|
||||
}
|
||||
|
||||
record DoubleLiteral(Double value) implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Double;
|
||||
return TargetType.double_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,4 +33,10 @@ public record TargetFunNType(String name, List<TargetType> funNParams, List<Targ
|
||||
public String getInternalName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSignature() {
|
||||
var args = FunNGenerator.getArguments(funNParams);
|
||||
return "LFun" + args.size() + "$$" + TargetSpecializedType.signatureParameters(funNParams) + ";";
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,20 @@ public sealed interface TargetSpecializedType extends TargetType permits TargetF
|
||||
@Override
|
||||
default String toSignature() {
|
||||
String ret = "L" + getInternalName();
|
||||
if (!params().isEmpty()) {
|
||||
ret += signatureParameters(params());
|
||||
ret += ";";
|
||||
return ret;
|
||||
}
|
||||
|
||||
static String signatureParameters(List<TargetType> params) {
|
||||
var ret = "";
|
||||
if (!params.isEmpty()) {
|
||||
ret += "<";
|
||||
for (var param : params()) {
|
||||
for (var param : params) {
|
||||
ret += param.toSignature();
|
||||
}
|
||||
ret += ">";
|
||||
}
|
||||
ret += ";";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
//PL 2018-12-19: Merge chekcen
|
||||
package de.dhbwstuttgart.typeinference.typeAlgo;
|
||||
|
||||
//import de.dhbwstuttgart.typeinference.unify.PlaceholderRegistry;
|
||||
//import de.dhbwstuttgart.typeinference.unify.TypeUnifyTaskHelper;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -116,17 +118,18 @@ public class TYPEStmt implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
fieldVar.receiver.accept(this);
|
||||
Set<Constraint> oderConstraints = new HashSet<>();
|
||||
List<FieldAssumption> fieldAssumptions = info.getFields(fieldVar.fieldVarName);
|
||||
Set<Constraint> oderConstraints = new HashSet<>();//TypeUnifyTaskHelper.getPresizedHashSet(fieldAssumptions.size());
|
||||
|
||||
|
||||
for (FieldAssumption fieldAssumption : info.getFields(fieldVar.fieldVarName)) {
|
||||
for (FieldAssumption fieldAssumption : fieldAssumptions) {
|
||||
Constraint constraint = new Constraint();
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
constraint.add(new Pair(fieldVar.receiver.getType(), fieldAssumption.getReceiverType(resolver), PairOperator.SMALLERDOT, loc(fieldVar.getOffset()))); // PL 2019-12-09: SMALLERDOT eingefuegt, EQUALSDOT entfernt, wenn ds Field privat ist muesste es EQUALSDOT lauten
|
||||
constraint.add(new Pair(fieldVar.getType(), fieldAssumption.getType(resolver), PairOperator.EQUALSDOT, loc(fieldVar.getOffset())));
|
||||
oderConstraints.add(constraint);
|
||||
}
|
||||
if (oderConstraints.size() == 0)
|
||||
if (oderConstraints.isEmpty())
|
||||
throw new TypeinferenceException("Kein Feld " + fieldVar.fieldVarName + " gefunden", fieldVar.getOffset());
|
||||
constraintsSet.addOderConstraint(oderConstraints);
|
||||
}
|
||||
@@ -141,7 +144,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(ForEachStmt forEachStmt) {
|
||||
var iterableType = new RefType(ASTFactory.createClass(java.lang.Iterable.class).getClassName(), Arrays.asList(new ExtendsWildcardType(forEachStmt.statement.getType(), new NullToken())), new NullToken());
|
||||
var iterableType = new RefType(ASTFactory.createClass(java.lang.Iterable.class).getClassName(), List.of(new ExtendsWildcardType(forEachStmt.statement.getType(), new NullToken())), new NullToken());
|
||||
constraintsSet.addUndConstraint(new Pair(forEachStmt.expression.getType(), iterableType, PairOperator.SMALLERDOT, loc(forEachStmt.getOffset())));
|
||||
forEachStmt.statement.accept(this);
|
||||
forEachStmt.expression.accept(this);
|
||||
@@ -189,7 +192,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
methodCall.receiver.accept(this);
|
||||
// Overloading:
|
||||
Set<Constraint<Pair>> methodConstraints = new HashSet<>();
|
||||
for (MethodAssumption m : this.getMethods(methodCall.name, methodCall.arglist, info)) {
|
||||
for (MethodAssumption m : TYPEStmt.getMethods(methodCall.name, methodCall.arglist, info)) {
|
||||
GenericsResolver resolver = getResolverInstance();
|
||||
Set<Constraint<Pair>> oneMethodConstraints = generateConstraint(methodCall, m, info, resolver);
|
||||
methodConstraints.addAll(oneMethodConstraints);
|
||||
@@ -199,7 +202,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
* oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint);
|
||||
*/
|
||||
}
|
||||
if (methodConstraints.size() < 1) {
|
||||
if (methodConstraints.isEmpty()) {
|
||||
throw new TypeinferenceException("Methode " + methodCall.name + " ist nicht vorhanden!", methodCall.getOffset());
|
||||
}
|
||||
constraintsSet.addOderConstraint(methodConstraints);
|
||||
@@ -212,7 +215,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
for (MethodAssumption m : this.getConstructors(info, (RefType) methodCall.getType(), methodCall.getArgumentList())) {
|
||||
methodConstraints.add(generateConstructorConstraint(methodCall, m, info, getResolverInstance()));
|
||||
}
|
||||
if (methodConstraints.size() < 1) {
|
||||
if (methodConstraints.isEmpty()) {
|
||||
throw new TypeinferenceException("Konstruktor in Klasse " + methodCall.getType().toString() + " ist nicht vorhanden!", methodCall.getOffset());
|
||||
}
|
||||
constraintsSet.addOderConstraint(methodConstraints);
|
||||
@@ -282,8 +285,13 @@ public class TYPEStmt implements StatementVisitor {
|
||||
// see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17
|
||||
// Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||
Constraint<Pair> numeric;
|
||||
HashSet<JavaClassName> classNames = new HashSet<>(); //TypeUnifyTaskHelper.getPresizedHashSet(info.getAvailableClasses().size());
|
||||
for (var classEl : info.getAvailableClasses()) {
|
||||
classNames.add(classEl.getClassName());
|
||||
}
|
||||
|
||||
// PL eingefuegt 2018-07-17
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(bytee.getName())) {
|
||||
if (classNames.contains(bytee.getName())) {
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), bytee, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), bytee, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
@@ -291,7 +299,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
// PL eingefuegt 2018-07-17
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(shortt.getName())) {
|
||||
if (classNames.contains(shortt.getName())) {
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), shortt, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), shortt, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
@@ -299,7 +307,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
// PL eingefuegt 2018-07-17
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(integer.getName())) {
|
||||
if (classNames.contains(integer.getName())) {
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
@@ -307,7 +315,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
// PL eingefuegt 2018-07-17
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(longg.getName())) {
|
||||
if (classNames.contains(longg.getName())) {
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
@@ -315,7 +323,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
// PL eingefuegt 2018-07-17
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(floatt.getName())) {
|
||||
if (classNames.contains(floatt.getName())) {
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
@@ -323,7 +331,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
numericAdditionOrStringConcatenation.add(numeric);
|
||||
}
|
||||
// PL eingefuegt 2018-07-17
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(doublee.getName())) {
|
||||
if (classNames.contains(doublee.getName())) {
|
||||
numeric = new Constraint<>();
|
||||
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT, loc(binary.getOffset())));
|
||||
@@ -338,7 +346,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
if (binary.operation.equals(BinaryExpr.Operator.ADD)) {
|
||||
// Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2)
|
||||
if (info.getAvailableClasses().stream().map(x -> x.getClassName()).collect(Collectors.toCollection(HashSet::new)).contains(string.getName())) {
|
||||
if (classNames.contains(string.getName())) {
|
||||
Constraint<Pair> stringConcat = new Constraint<>();
|
||||
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT, loc(binary.getOffset())));
|
||||
@@ -346,7 +354,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||
}
|
||||
}
|
||||
if (numericAdditionOrStringConcatenation.size() < 1) {
|
||||
if (numericAdditionOrStringConcatenation.isEmpty()) {
|
||||
throw new TypeinferenceException("Kein Typ für " + binary.operation.toString() + " vorhanden", binary.getOffset());
|
||||
}
|
||||
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
||||
@@ -694,8 +702,8 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
Set<Pair> methodSignatureConstraint = generatemethodSignatureConstraint(forMethod, assumption, info, resolver);
|
||||
|
||||
//System.out.println("methodSignatureConstraint: " + methodSignatureConstraint);
|
||||
//System.out.println("methodConstraint: " + methodConstraint);
|
||||
//context.logger().info("methodSignatureConstraint: " + methodSignatureConstraint);
|
||||
//context.logger().info("methodConstraint: " + methodConstraint);
|
||||
|
||||
methodConstraint.setmethodSignatureConstraint(methodSignatureConstraint);
|
||||
extendsMethodConstraint.setmethodSignatureConstraint(methodSignatureConstraint);
|
||||
@@ -728,12 +736,12 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
for (int i = 0; i < foMethod.arglist.getArguments().size(); i++) {
|
||||
// Zuordnung von MethoCall.signature (Argumenttypen) zu der Argumenttypen der ausgewaehlten Methode (assumption.params)
|
||||
ret.add(new Pair(foMethod.signature.get(i), assumption.getArgTypes().get(i), PairOperator.EQUALSDOT));
|
||||
ret.add(new Pair(resolver.resolve(foMethod.signature.get(i)), resolver.resolve(assumption.getArgTypes().get(i)), PairOperator.EQUALSDOT));
|
||||
|
||||
}
|
||||
|
||||
// Zuordnung von MethodCall.signature(ReturnType) zu dem ReturnType der ausgewaehlten Methode (assumption.returnType)
|
||||
ret.add(new Pair(foMethod.signature.get(foMethod.signature.size() - 1), assumption.getReturnType(), PairOperator.EQUALSDOT));
|
||||
ret.add(new Pair(resolver.resolve(foMethod.signature.getLast()), resolver.resolve(assumption.getReturnType()), PairOperator.EQUALSDOT));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -746,8 +754,8 @@ public class TYPEStmt implements StatementVisitor {
|
||||
// funNParams.add(TypePlaceholder.fresh(new NullToken()));
|
||||
funNParams.add(new GenericRefType(NameGenerator.makeNewName(), new NullToken()));
|
||||
}
|
||||
funNParams.get(funNParams.size() - 1);
|
||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.get(funNParams.size() - 1), funNParams.subList(0, funNParams.size() - 1), new TypeScope() {
|
||||
funNParams.getLast();
|
||||
ret.add(new MethodAssumption(new FunNClass(funNParams), funNParams.getLast(), funNParams.subList(0, funNParams.size() - 1), new TypeScope() {
|
||||
@Override
|
||||
public Iterable<? extends GenericTypeVar> getGenerics() {
|
||||
throw new NotImplementedException();
|
||||
@@ -842,7 +850,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
for (var child : switchStmt.getBlocks()) {
|
||||
for (var label : child.getLabels()) {
|
||||
if (label.getPattern() == null) {
|
||||
//System.out.println("DefaultCase");
|
||||
//context.logger().info("DefaultCase");
|
||||
} else {
|
||||
constraintsSet.addUndConstraint(
|
||||
new Pair(
|
||||
@@ -883,13 +891,9 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
child.getLabels().forEach(el -> {
|
||||
if (el.getType() instanceof RefType) {
|
||||
var recType = el;
|
||||
|
||||
if (el.getPattern() instanceof RecordPattern) {
|
||||
var pattern = (RecordPattern) recType.getPattern();
|
||||
recursivelyAddRecordConstraints(pattern);
|
||||
}
|
||||
|
||||
if (el.getPattern() instanceof RecordPattern pattern) {
|
||||
recursivelyAddRecordConstraints(pattern);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -905,13 +909,13 @@ public class TYPEStmt implements StatementVisitor {
|
||||
|
||||
var allClasses = info.getAvailableClasses();
|
||||
var interestingClasses = allClasses.stream().filter(as -> as.getClassName().equals(((RefType) pattern.getType()).getName())).toList();
|
||||
var constructors = interestingClasses.get(0).getConstructors();
|
||||
var constructors = interestingClasses.getFirst().getConstructors();
|
||||
|
||||
int counter = 0;
|
||||
|
||||
for (var subPattern : pattern.getSubPattern()) {
|
||||
for (Constructor con : constructors) {
|
||||
//System.out.println("----------------------\n" + subPattern.getType() + " | " + con.getParameterList().getParameterAt(counter).getType() + "\n----------------------\n");
|
||||
//context.logger().info("----------------------\n" + subPattern.getType() + " | " + con.getParameterList().getParameterAt(counter).getType() + "\n----------------------\n");
|
||||
constraintsSet.addUndConstraint(new Pair(subPattern.getType(), con.getParameterList().getParameterAt(counter).getType(), PairOperator.SMALLERDOT, loc(con.getParameterList().getParameterAt(counter).getOffset())));
|
||||
}
|
||||
if (subPattern instanceof RecordPattern) recursivelyAddRecordConstraints((RecordPattern) subPattern);
|
||||
@@ -935,7 +939,7 @@ public class TYPEStmt implements StatementVisitor {
|
||||
@Override
|
||||
public void visit(Yield aYield) {
|
||||
aYield.retexpr.accept(this);
|
||||
constraintsSet.addUndConstraint(new Pair(aYield.getType(), switchStack.peek().getType(), PairOperator.EQUALSDOT, loc(aYield.getOffset())));
|
||||
constraintsSet.addUndConstraint(new Pair(aYield.getType(), switchStack.peek().getType(), PairOperator.SMALLERDOT, loc(aYield.getOffset())));
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
}
|
||||
@@ -745,7 +745,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof ExtendsType))
|
||||
if((!(lhsType instanceof ReferenceType) && !(lhsType instanceof FunNType)) || !(rhsType instanceof ExtendsType))
|
||||
return Optional.empty();
|
||||
|
||||
return Optional.of(new UnifyPair(lhsType, ((ExtendsType) rhsType).getExtendedType(), PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
@@ -771,7 +771,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
if(!(lhsType instanceof ReferenceType) || !(rhsType instanceof SuperType))
|
||||
if((!(lhsType instanceof ReferenceType) && !(lhsType instanceof FunNType)) || !(rhsType instanceof SuperType))
|
||||
return Optional.empty();
|
||||
|
||||
return Optional.of(new UnifyPair(((SuperType) rhsType).getSuperedType(), lhsType, PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair.getBasePair()));
|
||||
@@ -861,16 +861,19 @@ public class RuleSet implements IRuleSet{
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNred: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNgreater: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("logFile-Error");
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@@ -897,7 +900,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||
var retType = fiArgs.getFirst();
|
||||
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
|
||||
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType); //FALSCHRUM????
|
||||
var lhsRet = lhsArgs.getFirst();
|
||||
|
||||
Set<UnifyPair> result = new HashSet<>();
|
||||
@@ -934,8 +937,8 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
||||
|
||||
Integer variance = ((PlaceholderType)rhsType).getVariance();
|
||||
Integer inversVariance = distributeVariance.inverseVariance(variance);
|
||||
int variance = ((PlaceholderType)rhsType).getVariance();
|
||||
int inversVariance = distributeVariance.inverseVariance(variance);
|
||||
|
||||
UnifyType[] freshPlaceholders = new UnifyType[funNLhsType.getTypeParams().size()];
|
||||
for(int i = 0; i < freshPlaceholders.length-1; i++) {
|
||||
@@ -943,6 +946,7 @@ public class RuleSet implements IRuleSet{
|
||||
((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
|
||||
}
|
||||
freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
|
||||
|
||||
((PlaceholderType)freshPlaceholders[freshPlaceholders.length-1]).setVariance(variance);
|
||||
result.add(new UnifyPair(funNLhsType.getTypeParams().get(funNLhsType.getTypeParams().size()-1), freshPlaceholders[funNLhsType.getTypeParams().size()-1], PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
|
||||
@@ -953,42 +957,94 @@ public class RuleSet implements IRuleSet{
|
||||
result.add(new UnifyPair(rhsType, funNLhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
|
||||
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNgreater: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNsmaller: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair) {
|
||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc) {
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOT)
|
||||
return Optional.empty();
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
||||
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof FunNType))
|
||||
if(!(rhsType instanceof FunNType))
|
||||
return Optional.empty();
|
||||
|
||||
/* muss nach angepasst werden */
|
||||
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
|
||||
if (lhsType instanceof ReferenceType) {
|
||||
UnifyType typeFI = pair.getLhsType();
|
||||
|
||||
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
|
||||
if(!opt.isPresent())
|
||||
return Optional.empty();
|
||||
|
||||
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
|
||||
return Optional.empty();
|
||||
|
||||
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||
var retType = fiArgs.getFirst();
|
||||
var rhsArgs = intf.getFunctionalInterfaceTypeArguments(rhsType);
|
||||
var rhsRet = rhsArgs.getFirst();
|
||||
|
||||
Set<UnifyPair> result = new HashSet<>();
|
||||
//if (retType instanceof ExtendsType) {
|
||||
result.add(new UnifyPair(retType, rhsRet, PairOperator.SMALLER));
|
||||
//} else if (retType instanceof SuperType) {
|
||||
// return Optional.empty();
|
||||
//} else {
|
||||
// result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
|
||||
for (var i = 1; i < fiArgs.size(); i++) {
|
||||
var rh = rhsArgs.get(i);
|
||||
var lh = fiArgs.get(i);
|
||||
|
||||
//if (rh instanceof SuperType) {
|
||||
result.add(new UnifyPair(rh, lh, PairOperator.SMALLER));
|
||||
//} else if (rh instanceof ExtendsType) {
|
||||
// return Optional.empty();
|
||||
//} else {
|
||||
// result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
else {
|
||||
if(!(lhsType instanceof PlaceholderType))
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FunNType funNRhsType = (FunNType) rhsType;
|
||||
|
||||
Set<UnifyPair> result = new HashSet<UnifyPair>();
|
||||
|
||||
Integer variance = ((PlaceholderType)lhsType).getVariance();
|
||||
Integer inversVariance = distributeVariance.inverseVariance(variance);
|
||||
int variance = ((PlaceholderType)lhsType).getVariance();
|
||||
int inversVariance = distributeVariance.inverseVariance(variance);
|
||||
|
||||
UnifyType[] freshPlaceholders = new UnifyType[funNRhsType.getTypeParams().size()];
|
||||
for(int i = 0; i < freshPlaceholders.length-1; i++) {
|
||||
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
|
||||
freshPlaceholders[i] = PlaceholderType.freshPlaceholder();
|
||||
((PlaceholderType)freshPlaceholders[i]).setVariance(inversVariance);
|
||||
}
|
||||
freshPlaceholders[freshPlaceholders.length-1] = PlaceholderType.freshPlaceholder();
|
||||
@@ -1003,21 +1059,139 @@ public class RuleSet implements IRuleSet{
|
||||
result.add(new UnifyPair(lhsType, funNRhsType.setTypeParams(new TypeParams(freshPlaceholders)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
|
||||
result.stream().forEach(x -> { UnifyType l = x.getLhsType();
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
if (l instanceof PlaceholderType) { ((PlaceholderType)l).disableWildcardtable(); }
|
||||
UnifyType r = x.getRhsType();
|
||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||
} );
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNsmaller: " + result + "\n");
|
||||
logFile.flush();
|
||||
|
||||
|
||||
try {
|
||||
logFile.write("FUNgreater: " + pair + "\n");
|
||||
logFile.write("FUNsmaller: " + result + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Set<UnifyPair>> reduceFIFunN(UnifyPair pair, IFiniteClosure fc) {
|
||||
if(pair.getPairOp() != PairOperator.EQUALSDOT)
|
||||
return Optional.empty();
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
||||
if(!(rhsType instanceof FunNType))
|
||||
return Optional.empty();
|
||||
|
||||
/* muss nach angepasst werden */
|
||||
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
|
||||
if (lhsType instanceof ReferenceType) {
|
||||
UnifyType typeFI = pair.getLhsType();
|
||||
|
||||
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
|
||||
if(!opt.isPresent())
|
||||
return Optional.empty();
|
||||
|
||||
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
|
||||
return Optional.empty();
|
||||
|
||||
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||
var retType = fiArgs.getFirst();
|
||||
var rhsArgs = intf.getFunctionalInterfaceTypeArguments(rhsType);
|
||||
var rhsRet = rhsArgs.getFirst();
|
||||
|
||||
Set<UnifyPair> result = new HashSet<>();
|
||||
//if (retType instanceof ExtendsType) {
|
||||
result.add(new UnifyPair(retType, rhsRet, PairOperator.EQUALSDOT));
|
||||
//} else if (retType instanceof SuperType) {
|
||||
// return Optional.empty();
|
||||
//} else {
|
||||
// result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
|
||||
for (var i = 1; i < fiArgs.size(); i++) {
|
||||
var rh = rhsArgs.get(i);
|
||||
var lh = fiArgs.get(i);
|
||||
|
||||
//if (rh instanceof SuperType) {
|
||||
result.add(new UnifyPair(rh, lh, PairOperator.EQUALSDOT));
|
||||
//} else if (rh instanceof ExtendsType) {
|
||||
// return Optional.empty();
|
||||
//} else {
|
||||
// result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("lofFile-Error");
|
||||
}
|
||||
return Optional.of(result);
|
||||
|
||||
@Override
|
||||
public Optional<Set<UnifyPair>> reduceFunNFi(UnifyPair pair, IFiniteClosure fc) {
|
||||
if(pair.getPairOp() != PairOperator.EQUALSDOT)
|
||||
return Optional.empty();
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
|
||||
if(!(lhsType instanceof FunNType))
|
||||
return Optional.empty();
|
||||
|
||||
//FunN$$<...> <. FunctinalInterface<...> wird umgewandelt in FunN$$<...> <. FunN$$<... args aus FuntionalInterface ...>
|
||||
if (rhsType instanceof ReferenceType) {
|
||||
UnifyType typeFI = pair.getRhsType();
|
||||
|
||||
Optional<UnifyType> opt = fc.getRightHandedFunctionalInterfaceType(typeFI.getName());
|
||||
if(!opt.isPresent())
|
||||
return Optional.empty();
|
||||
|
||||
if (!(typeFI instanceof ReferenceType refType) || !(refType instanceof FunInterfaceType intf))
|
||||
return Optional.empty();
|
||||
|
||||
var fiArgs = intf.getFunctionalInterfaceTypeArguments(refType);
|
||||
var retType = fiArgs.getFirst();
|
||||
var lhsArgs = intf.getFunctionalInterfaceTypeArguments(lhsType);
|
||||
var lhsRet = lhsArgs.getFirst();
|
||||
|
||||
Set<UnifyPair> result = new HashSet<>();
|
||||
//if (retType instanceof ExtendsType) {
|
||||
// result.add(new UnifyPair(lhsRet, retType, PairOperator.SMALLERDOTWC));
|
||||
//} else if (retType instanceof SuperType) {
|
||||
// return Optional.empty();
|
||||
//} else {
|
||||
result.add(new UnifyPair(lhsRet, retType, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
|
||||
for (var i = 1; i < fiArgs.size(); i++) {
|
||||
var lh = lhsArgs.get(i);
|
||||
var rh = fiArgs.get(i);
|
||||
|
||||
//if (rh instanceof SuperType) {
|
||||
// result.add(new UnifyPair(lh, rh, PairOperator.SMALLERDOTWC));
|
||||
//} else if (rh instanceof ExtendsType) {
|
||||
// return Optional.empty();
|
||||
//} else {
|
||||
result.add(new UnifyPair(lh, rh, PairOperator.EQUALSDOT));
|
||||
//}
|
||||
}
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Optional<UnifyPair> reduceTph(UnifyPair pair) {
|
||||
if(pair.getPairOp() != PairOperator.SMALLERDOTWC)
|
||||
@@ -1025,7 +1199,7 @@ public class RuleSet implements IRuleSet{
|
||||
|
||||
UnifyType lhsType = pair.getLhsType();
|
||||
UnifyType rhsType = pair.getRhsType();
|
||||
if(!(lhsType instanceof PlaceholderType) || !(rhsType instanceof ReferenceType))
|
||||
if(!(lhsType instanceof PlaceholderType) || (!(rhsType instanceof ReferenceType) && !(rhsType instanceof FunNType)))
|
||||
return Optional.empty();
|
||||
|
||||
return Optional.of(new UnifyPair(lhsType, rhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
@@ -1051,7 +1225,7 @@ public class RuleSet implements IRuleSet{
|
||||
if(isGen)
|
||||
result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
else {
|
||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||
result.add(new UnifyPair(rhsType, new ExtendsType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
result.add(new UnifyPair(extendedType, freshTph, PairOperator.SMALLERDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
}
|
||||
@@ -1079,7 +1253,7 @@ public class RuleSet implements IRuleSet{
|
||||
if(isGen)
|
||||
result.add(new UnifyPair(rhsType, lhsType, PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
else {
|
||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||
result.add(new UnifyPair(rhsType, new SuperType(freshTph), PairOperator.EQUALSDOT, pair.getSubstitution(), pair.getBasePair()));
|
||||
Set<UnifyType> fBounded = pair.getfBounded();
|
||||
fBounded.add(lhsType);
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -814,6 +815,21 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
writeLog("nextSet: " + nextSet.toString());
|
||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||
Function<Set<UnifyPair>, Set<UnifyPair>> setInnterType_false =
|
||||
a_elem -> a_elem.stream().map(up -> { UnifyType lhs = up.getLhsType();
|
||||
UnifyType rhs = up.getRhsType();
|
||||
if (lhs instanceof PlaceholderType) {
|
||||
PlaceholderType newLhs = new PlaceholderType((PlaceholderType)lhs);
|
||||
newLhs.setInnerType(false);
|
||||
lhs = newLhs;
|
||||
}
|
||||
if (rhs instanceof PlaceholderType) {
|
||||
PlaceholderType newRhs = new PlaceholderType((PlaceholderType)rhs);
|
||||
newRhs.setInnerType(false);
|
||||
rhs = newRhs;
|
||||
}
|
||||
UnifyPair up_new = new UnifyPair(up, lhs, rhs);
|
||||
return up_new;}).collect(Collectors.toCollection(HashSet::new));
|
||||
if (variance == 1) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
writeLog("Max: a in " + variance + " "+ a);
|
||||
@@ -826,8 +842,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
while (nextSetasListItRest.hasNext()) {
|
||||
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
||||
|
||||
if (//a.equals(a_next) ||
|
||||
(oup.compare(a, a_next) == 1)) {
|
||||
(oup.compare(setInnterType_false.apply(a), setInnterType_false.apply(a_next)) == 1)) {
|
||||
nextSetasListRest.remove(a_next);
|
||||
}
|
||||
}
|
||||
@@ -848,8 +865,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
while (nextSetasListItRest.hasNext()) {
|
||||
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
||||
if (new ArrayList<>((a_next)).getFirst().getLhsType().getName().equals("AES"))
|
||||
System.out.println();
|
||||
if (//a.equals(a_next) ||
|
||||
(oup.compare(a, a_next) == -1)) {
|
||||
(oup.compare(setInnterType_false.apply(a), setInnterType_false.apply(a_next)) == -1)) {
|
||||
nextSetasListRest.remove(a_next);
|
||||
}
|
||||
}
|
||||
@@ -1828,7 +1847,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// FunN Rules
|
||||
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
|
||||
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair, fc);
|
||||
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair);
|
||||
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair,fc);
|
||||
|
||||
// One of the rules has been applied
|
||||
if(optSet.isPresent()) {
|
||||
|
||||
@@ -40,6 +40,8 @@ public class UnifyResultModel {
|
||||
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
||||
Optional<Set<UnifyPair>> res = new RuleSet().subst(x.stream().map(y -> {
|
||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC)
|
||||
y.setPairOp(PairOperator.EQUALSDOT);
|
||||
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||
}).collect(Collectors.toCollection(HashSet::new)));
|
||||
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
||||
|
||||
@@ -61,7 +61,9 @@ public interface IRuleSet {
|
||||
*/
|
||||
public Optional<Set<UnifyPair>> reduceFunN(UnifyPair pair);
|
||||
public Optional<Set<UnifyPair>> greaterFunN(UnifyPair pair, IFiniteClosure fc);
|
||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair);
|
||||
public Optional<Set<UnifyPair>> smallerFunN(UnifyPair pair, IFiniteClosure fc);
|
||||
public Optional<Set<UnifyPair>> reduceFIFunN(UnifyPair pair, IFiniteClosure fc);
|
||||
public Optional<Set<UnifyPair>> reduceFunNFi(UnifyPair pair, IFiniteClosure fc);
|
||||
|
||||
/**
|
||||
* Checks whether the erase1-Rule applies to the pair.
|
||||
|
||||
@@ -35,7 +35,11 @@ public abstract class OrderingExtend<T> extends com.google.common.collect.Orderi
|
||||
|
||||
T min = min(iterable);
|
||||
ret.add(min);
|
||||
|
||||
if (min instanceof Set) {
|
||||
String x = ((UnifyPair)(new ArrayList<>((Set)min)).getFirst()).getLhsType().typeName;
|
||||
if (((UnifyPair)(new ArrayList((Set)min)).getFirst()).getLhsType().typeName.equals("AES"))
|
||||
System.out.println();
|
||||
}
|
||||
Iterator<T> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
T elem = it.next();
|
||||
|
||||
@@ -251,7 +251,7 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
.filter(x -> (x.getPairOp() == PairOperator.SMALLERDOT))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
/*
|
||||
///*
|
||||
synchronized(this) {
|
||||
try {
|
||||
((FiniteClosure)fc).logFile.write("leftBase: " + leftBase.toString() +"\n");
|
||||
@@ -269,7 +269,7 @@ public class OrderingUnifyPair extends OrderingExtend<Set<UnifyPair>> {
|
||||
catch (IOException ie) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
//*/
|
||||
|
||||
|
||||
Integer compareEq;
|
||||
|
||||
@@ -95,6 +95,15 @@ public final class PlaceholderType extends UnifyType{
|
||||
IsGenerated = isGenerated;
|
||||
}
|
||||
|
||||
public PlaceholderType(PlaceholderType ph) {
|
||||
super(ph);
|
||||
IsGenerated = ph.isGenerated();
|
||||
wildcardable = ph.isWildcardable();
|
||||
innerType = ph.isInnerType();
|
||||
variance = ph.getVariance();
|
||||
orCons = ph.getOrCons();
|
||||
}
|
||||
|
||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||
return visitor.visit(this, ht);
|
||||
}
|
||||
|
||||
@@ -101,6 +101,19 @@ public class UnifyPair {
|
||||
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
||||
}
|
||||
|
||||
public UnifyPair(UnifyPair up, UnifyType lhs, UnifyType rhs) {
|
||||
this.lhs = lhs;
|
||||
this.rhs = rhs;
|
||||
pairOp = up.pairOp;
|
||||
substitution = up.substitution;
|
||||
basePair = up.getBasePair();
|
||||
this.location = up.location;
|
||||
this.fBounded = up.fBounded;
|
||||
|
||||
// Caching hashcode
|
||||
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
||||
}
|
||||
|
||||
public SourceLoc getLocation() {
|
||||
if (location != null) return location;
|
||||
else if (basePair != null) return basePair.getLocation();
|
||||
|
||||
@@ -36,6 +36,10 @@ public abstract class UnifyType {
|
||||
typeParams = p;
|
||||
}
|
||||
|
||||
protected UnifyType(UnifyType ut) {
|
||||
typeName = ut.getName();
|
||||
typeParams = ut.typeParams;
|
||||
}
|
||||
|
||||
abstract public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht);
|
||||
|
||||
|
||||
@@ -63,11 +63,12 @@ public class AllgemeinTest {
|
||||
//String className = "Cycle";
|
||||
//String className = "TripleTest";
|
||||
//String className = "WildcardList";
|
||||
String className = "List";
|
||||
//String className = "List";
|
||||
//String className = "Box";
|
||||
//String className = "GenBox";
|
||||
//String className = "InnerInf";
|
||||
//String className = "Foo";
|
||||
String className = "Kombinatoren_After_Lazy2";
|
||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||
|
||||
@@ -735,8 +735,17 @@ public class TestComplete {
|
||||
public void testSwitchRecordLiteral() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "PatternMatchingLiteralStyle.jav");
|
||||
var clazz = classFiles.get("SwitchOverload");
|
||||
var record = classFiles.get("R");
|
||||
var rctor = record.getDeclaredConstructor(String.class);
|
||||
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var m = clazz.getDeclaredMethod("m", record);
|
||||
assertEquals(10, m.invoke(instance, rctor.newInstance("test")));
|
||||
assertEquals(20, m.invoke(instance, rctor.newInstance("foo")));
|
||||
assertEquals(0, m.invoke(instance, rctor.newInstance("???")));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwitchCaseHeritageDetection() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "SwitchCaseHeritageDetection.jav");
|
||||
@@ -1476,4 +1485,42 @@ public class TestComplete {
|
||||
var m = clazz.getDeclaredMethod("main");
|
||||
m.invoke(null);
|
||||
}
|
||||
|
||||
@Disabled("Doesn't work yet")
|
||||
@Test
|
||||
public void testBug378() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug378Main.jav");
|
||||
var clazz = classFiles.get("Bug378Main");
|
||||
var main = clazz.getDeclaredMethod("main", List.class);
|
||||
main.invoke(null, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug379() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug379.jav");
|
||||
var clazz = classFiles.get("Bug379");
|
||||
clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug380() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug380.jav");
|
||||
var clazz = classFiles.get("Bug380");
|
||||
clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug382() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug382.jav");
|
||||
var clazz = classFiles.get("Bug382");
|
||||
clazz.getDeclaredMethod("main", List.class).invoke(null, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug383() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug383.jav");
|
||||
var clazz = classFiles.get("Bug383");
|
||||
clazz.getDeclaredMethod("main", List.class).invoke(null, List.of());
|
||||
// TODO This logs output that we should validate
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class t{
|
||||
public mofus(){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user