bug fix VectorNotObject test

This commit is contained in:
luca9913 2023-06-01 20:59:16 +02:00
parent 52b7040337
commit 30a62a6621
5 changed files with 647 additions and 699 deletions

View File

@ -51,11 +51,10 @@ http://maven.apache.org/maven-v4_0_0.xsd">
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.11.0</version>
<configuration> <configuration>
<compilerArgs>--enable-preview</compilerArgs> <compilerArgs>--enable-preview</compilerArgs>
<source>19</source> <release>20</release>
<target>19</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@ -112,8 +111,6 @@ http://maven.apache.org/maven-v4_0_0.xsd">
</repository> </repository>
</repositories> </repositories>
<properties> <properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass> <mainClass>de.dhbwstuttgart.core.ConsoleInterface</mainClass>
</properties> </properties>
<distributionManagement> <distributionManagement>

View File

@ -28,7 +28,8 @@ public class Codegen {
this.cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); this.cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
} }
private record LocalVar(int index, String name, TargetType type) {} private record LocalVar(int index, String name, TargetType type) {
}
private static class Scope { private static class Scope {
Scope parent; Scope parent;
@ -196,9 +197,7 @@ public class Codegen {
mv.visitInsn(L2F); mv.visitInsn(L2F);
else if (dest.equals(TargetType.Double)) else if (dest.equals(TargetType.Double))
mv.visitInsn(L2D); mv.visitInsn(L2D);
else if (dest.equals(TargetType.Byte) else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
|| dest.equals(TargetType.Char)
|| dest.equals(TargetType.Short)) {
mv.visitInsn(L2I); mv.visitInsn(L2I);
convertTo(state, TargetType.Integer, dest); convertTo(state, TargetType.Integer, dest);
} }
@ -209,9 +208,7 @@ public class Codegen {
mv.visitInsn(F2D); mv.visitInsn(F2D);
else if (dest.equals(TargetType.Long)) else if (dest.equals(TargetType.Long))
mv.visitInsn(F2L); mv.visitInsn(F2L);
else if (dest.equals(TargetType.Byte) else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
|| dest.equals(TargetType.Char)
|| dest.equals(TargetType.Short)) {
mv.visitInsn(F2I); mv.visitInsn(F2I);
convertTo(state, TargetType.Integer, dest); convertTo(state, TargetType.Integer, dest);
} }
@ -222,16 +219,11 @@ public class Codegen {
mv.visitInsn(D2F); mv.visitInsn(D2F);
else if (dest.equals(TargetType.Long)) else if (dest.equals(TargetType.Long))
mv.visitInsn(D2L); mv.visitInsn(D2L);
else if (dest.equals(TargetType.Byte) else if (dest.equals(TargetType.Byte) || dest.equals(TargetType.Char) || dest.equals(TargetType.Short)) {
|| dest.equals(TargetType.Char)
|| dest.equals(TargetType.Short)) {
mv.visitInsn(D2I); mv.visitInsn(D2I);
convertTo(state, TargetType.Integer, dest); convertTo(state, TargetType.Integer, dest);
} }
} else if (source.equals(TargetType.Byte) } else if (source.equals(TargetType.Byte) || source.equals(TargetType.Char) || source.equals(TargetType.Short) || source.equals(TargetType.Integer)) {
|| source.equals(TargetType.Char)
|| source.equals(TargetType.Short)
|| source.equals(TargetType.Integer)) {
if (dest.equals(TargetType.Byte)) if (dest.equals(TargetType.Byte))
mv.visitInsn(I2B); mv.visitInsn(I2B);
else if (dest.equals(TargetType.Char)) else if (dest.equals(TargetType.Char))
@ -281,10 +273,7 @@ public class Codegen {
generate(state, add.right()); generate(state, add.right());
convertTo(state, add.right().type(), add.type()); convertTo(state, add.right().type(), add.type());
var type = add.type(); var type = add.type();
if (type.equals(TargetType.Byte) if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|| type.equals(TargetType.Char)
|| type.equals(TargetType.Integer)
|| type.equals(TargetType.Short)) {
mv.visitInsn(IADD); mv.visitInsn(IADD);
} else if (type.equals(TargetType.Long)) { } else if (type.equals(TargetType.Long)) {
mv.visitInsn(LADD); mv.visitInsn(LADD);
@ -310,10 +299,7 @@ public class Codegen {
generate(state, sub.right()); generate(state, sub.right());
convertTo(state, sub.right().type(), op.type()); convertTo(state, sub.right().type(), op.type());
var type = sub.type(); var type = sub.type();
if (type.equals(TargetType.Byte) if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|| type.equals(TargetType.Char)
|| type.equals(TargetType.Integer)
|| type.equals(TargetType.Short)) {
mv.visitInsn(ISUB); mv.visitInsn(ISUB);
} else if (type.equals(TargetType.Long)) { } else if (type.equals(TargetType.Long)) {
mv.visitInsn(LSUB); mv.visitInsn(LSUB);
@ -332,10 +318,7 @@ public class Codegen {
generate(state, div.right()); generate(state, div.right());
convertTo(state, div.right().type(), op.type()); convertTo(state, div.right().type(), op.type());
var type = div.type(); var type = div.type();
if (type.equals(TargetType.Byte) if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|| type.equals(TargetType.Char)
|| type.equals(TargetType.Integer)
|| type.equals(TargetType.Short)) {
mv.visitInsn(IDIV); mv.visitInsn(IDIV);
} else if (type.equals(TargetType.Long)) { } else if (type.equals(TargetType.Long)) {
mv.visitInsn(LDIV); mv.visitInsn(LDIV);
@ -354,10 +337,7 @@ public class Codegen {
generate(state, mul.right()); generate(state, mul.right());
convertTo(state, mul.right().type(), op.type()); convertTo(state, mul.right().type(), op.type());
var type = mul.type(); var type = mul.type();
if (type.equals(TargetType.Byte) if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|| type.equals(TargetType.Char)
|| type.equals(TargetType.Integer)
|| type.equals(TargetType.Short)) {
mv.visitInsn(IMUL); mv.visitInsn(IMUL);
} else if (type.equals(TargetType.Long)) { } else if (type.equals(TargetType.Long)) {
mv.visitInsn(LMUL); mv.visitInsn(LMUL);
@ -376,10 +356,7 @@ public class Codegen {
generate(state, rem.right()); generate(state, rem.right());
convertTo(state, rem.right().type(), op.type()); convertTo(state, rem.right().type(), op.type());
var type = rem.type(); var type = rem.type();
if (type.equals(TargetType.Byte) if (type.equals(TargetType.Byte) || type.equals(TargetType.Char) || type.equals(TargetType.Integer) || type.equals(TargetType.Short)) {
|| type.equals(TargetType.Char)
|| type.equals(TargetType.Integer)
|| type.equals(TargetType.Short)) {
mv.visitInsn(IREM); mv.visitInsn(IREM);
} else if (type.equals(TargetType.Long)) { } else if (type.equals(TargetType.Long)) {
mv.visitInsn(LREM); mv.visitInsn(LREM);
@ -429,7 +406,8 @@ public class Codegen {
convertTo(state, band.right().type(), op.type()); convertTo(state, band.right().type(), op.type());
if (band.type().equals(TargetType.Long)) if (band.type().equals(TargetType.Long))
mv.visitInsn(LAND); mv.visitInsn(LAND);
else mv.visitInsn(IAND); else
mv.visitInsn(IAND);
break; break;
} }
case BOr bor: { case BOr bor: {
@ -439,7 +417,8 @@ public class Codegen {
convertTo(state, bor.right().type(), op.type()); convertTo(state, bor.right().type(), op.type());
if (bor.type().equals(TargetType.Long)) if (bor.type().equals(TargetType.Long))
mv.visitInsn(LOR); mv.visitInsn(LOR);
else mv.visitInsn(IOR); else
mv.visitInsn(IOR);
break; break;
} }
case XOr xor: { case XOr xor: {
@ -449,7 +428,8 @@ public class Codegen {
convertTo(state, xor.right().type(), op.type()); convertTo(state, xor.right().type(), op.type());
if (xor.type().equals(TargetType.Long)) if (xor.type().equals(TargetType.Long))
mv.visitInsn(LXOR); mv.visitInsn(LXOR);
else mv.visitInsn(IXOR); else
mv.visitInsn(IXOR);
break; break;
} }
case Shl shl: { case Shl shl: {
@ -459,7 +439,8 @@ public class Codegen {
convertTo(state, shl.right().type(), op.type()); convertTo(state, shl.right().type(), op.type());
if (shl.type().equals(TargetType.Long)) if (shl.type().equals(TargetType.Long))
mv.visitInsn(LSHL); mv.visitInsn(LSHL);
else mv.visitInsn(ISHL); else
mv.visitInsn(ISHL);
break; break;
} }
case Shr shr: { case Shr shr: {
@ -469,7 +450,8 @@ public class Codegen {
convertTo(state, shr.right().type(), op.type()); convertTo(state, shr.right().type(), op.type());
if (shr.type().equals(TargetType.Long)) if (shr.type().equals(TargetType.Long))
mv.visitInsn(LSHR); mv.visitInsn(LSHR);
else mv.visitInsn(ISHR); else
mv.visitInsn(ISHR);
break; break;
} }
case UShr ushr: { case UShr ushr: {
@ -479,7 +461,8 @@ public class Codegen {
convertTo(state, ushr.right().type(), op.type()); convertTo(state, ushr.right().type(), op.type());
if (ushr.type().equals(TargetType.Long)) if (ushr.type().equals(TargetType.Long))
mv.visitInsn(LUSHR); mv.visitInsn(LUSHR);
else mv.visitInsn(IUSHR); else
mv.visitInsn(IUSHR);
break; break;
} }
case Greater greater: { case Greater greater: {
@ -542,11 +525,7 @@ public class Codegen {
generateRelationalOperator(state, equal, type, FCMPL, IFEQ); generateRelationalOperator(state, equal, type, FCMPL, IFEQ);
} else if (type.equals(TargetType.Double)) { } else if (type.equals(TargetType.Double)) {
generateRelationalOperator(state, equal, type, DCMPL, IFEQ); generateRelationalOperator(state, equal, type, DCMPL, IFEQ);
} else if (type.equals(TargetType.Char) } else if (type.equals(TargetType.Char) || type.equals(TargetType.Short) || type.equals(TargetType.Byte) || type.equals(TargetType.Integer) || type.equals(TargetType.Boolean)) {
|| type.equals(TargetType.Short)
|| type.equals(TargetType.Byte)
|| type.equals(TargetType.Integer)
|| type.equals(TargetType.Boolean)) {
generateRelationalOperator(state, equal, type, IF_ICMPEQ); generateRelationalOperator(state, equal, type, IF_ICMPEQ);
} else { } else {
generateRelationalOperator(state, equal, type, IF_ACMPEQ); generateRelationalOperator(state, equal, type, IF_ACMPEQ);
@ -561,10 +540,7 @@ public class Codegen {
generateRelationalOperator(state, notEqual, type, FCMPL, IFNE); generateRelationalOperator(state, notEqual, type, FCMPL, IFNE);
} else if (type.equals(TargetType.Double)) { } else if (type.equals(TargetType.Double)) {
generateRelationalOperator(state, notEqual, type, DCMPL, IFNE); generateRelationalOperator(state, notEqual, type, DCMPL, IFNE);
} else if (type.equals(TargetType.Char) } else if (type.equals(TargetType.Char) || type.equals(TargetType.Short) || type.equals(TargetType.Byte) || type.equals(TargetType.Integer)) {
|| type.equals(TargetType.Short)
|| type.equals(TargetType.Byte)
|| type.equals(TargetType.Integer)) {
generateRelationalOperator(state, notEqual, type, IF_ICMPNE); generateRelationalOperator(state, notEqual, type, IF_ICMPNE);
} else { } else {
generateRelationalOperator(state, notEqual, type, IF_ACMPNE); generateRelationalOperator(state, notEqual, type, IF_ACMPNE);
@ -600,7 +576,8 @@ public class Codegen {
mv.visitInsn(FNEG); mv.visitInsn(FNEG);
else if (negate.type().equals(TargetType.Long)) else if (negate.type().equals(TargetType.Long))
mv.visitInsn(LNEG); mv.visitInsn(LNEG);
else mv.visitInsn(INEG); else
mv.visitInsn(INEG);
break; break;
case TargetUnaryOp.Not not: case TargetUnaryOp.Not not:
generate(state, not.expr()); generate(state, not.expr());
@ -712,29 +689,17 @@ public class Codegen {
} else { } else {
var name = "lambda$" + lambdaCounter++; var name = "lambda$" + lambdaCounter++;
var parameters = new ArrayList<>(lambda.captures()); var parameters = new ArrayList<>(lambda.captures());
parameters.addAll(lambda.params().stream() parameters.addAll(lambda.params().stream().map(param -> param.type() instanceof TargetGenericType ? new MethodParameter(TargetType.Object, param.name()) : param).toList());
.map(param -> param.type() instanceof TargetGenericType ? new MethodParameter(TargetType.Object, param.name()) : param)
.toList());
impl = new TargetMethod( impl = new TargetMethod(0, name, Set.of(), Set.of(), parameters, lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType(), lambda.block());
0, name, Set.of(), Set.of(),
parameters,
lambda.returnType() instanceof TargetGenericType ? TargetType.Object : lambda.returnType(),
lambda.block()
);
generateMethod(impl); generateMethod(impl);
lambdas.put(lambda, impl); lambdas.put(lambda, impl);
} }
var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, var mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
MethodType.class, MethodType.class, MethodHandle.class, MethodType.class);
var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", var bootstrap = new Handle(H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", mt.toMethodDescriptorString(), false);
mt.toMethodDescriptorString(), false); var handle = new Handle(H_INVOKEVIRTUAL, clazz.getName(), impl.name(), impl.getDescriptor(), false);
var handle = new Handle(
H_INVOKEVIRTUAL, clazz.getName(), impl.name(),
impl.getDescriptor(), false
);
// TODO maybe make this a function? // TODO maybe make this a function?
var desugared = "("; var desugared = "(";
@ -743,23 +708,19 @@ public class Codegen {
desugared += ")"; desugared += ")";
if (lambda.returnType() != null) if (lambda.returnType() != null)
desugared += "Ljava/lang/Object;"; desugared += "Ljava/lang/Object;";
else desugared += "V"; else
desugared += "V";
var params = new ArrayList<TargetType>(); var params = new ArrayList<TargetType>();
params.add(new TargetRefType(clazz.qualifiedName())); params.add(new TargetRefType(clazz.qualifiedName()));
params.addAll(lambda.captures().stream() params.addAll(lambda.captures().stream().map(MethodParameter::type).toList());
.map(MethodParameter::type)
.toList());
var descriptor = TargetMethod.getDescriptor(lambda.type(), params.toArray(TargetType[]::new)); var descriptor = TargetMethod.getDescriptor(lambda.type(), params.toArray(TargetType[]::new));
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);
for (var capture : lambda.captures()) for (var capture : lambda.captures())
mv.visitVarInsn(ALOAD, state.scope.get(capture.name()).index); mv.visitVarInsn(ALOAD, state.scope.get(capture.name()).index);
mv.visitInvokeDynamicInsn("apply", descriptor, mv.visitInvokeDynamicInsn("apply", descriptor, bootstrap, Type.getType(desugared), handle, Type.getType(TargetMethod.getDescriptor(impl.returnType(), lambda.params().stream().map(MethodParameter::type).toArray(TargetType[]::new))));
bootstrap, Type.getType(desugared), handle,
Type.getType(TargetMethod.getDescriptor(impl.returnType(), lambda.params().stream().map(MethodParameter::type).toArray(TargetType[]::new)))
);
} }
private void generate(State state, TargetExpression expr) { private void generate(State state, TargetExpression expr) {
@ -773,7 +734,8 @@ public class Codegen {
for (var e : block.statements()) { for (var e : block.statements()) {
generate(state, e); generate(state, e);
if (e instanceof TargetMethodCall) { if (e instanceof TargetMethodCall) {
if (e.type() != null) popValue(state, e.type()); if (e.type() != null)
popValue(state, e.type());
} else if (e instanceof TargetAssign) { } else if (e instanceof TargetAssign) {
mv.visitInsn(POP); // TODO Nasty fix, we don't know if it is a primitive double or long mv.visitInsn(POP); // TODO Nasty fix, we don't know if it is a primitive double or long
} else if (e instanceof TargetStatementExpression se) { } else if (e instanceof TargetStatementExpression se) {
@ -856,7 +818,8 @@ public class Codegen {
boxPrimitive(state, fieldType); boxPrimitive(state, fieldType);
if (dot.isStatic()) if (dot.isStatic())
mv.visitInsn(DUP); mv.visitInsn(DUP);
else mv.visitInsn(DUP_X1); else
mv.visitInsn(DUP_X1);
mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toSignature()); mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toSignature());
break; break;
} }
@ -888,7 +851,8 @@ public class Codegen {
mv.visitLabel(start); mv.visitLabel(start);
if (_for.termination() != null) if (_for.termination() != null)
generate(state, _for.termination()); generate(state, _for.termination());
else mv.visitInsn(ICONST_1); else
mv.visitInsn(ICONST_1);
mv.visitJumpInsn(IFEQ, end); mv.visitJumpInsn(IFEQ, end);
generate(state, _for.body()); generate(state, _for.body());
if (_for.increment() != null) { if (_for.increment() != null) {
@ -934,7 +898,8 @@ public class Codegen {
convertTo(state, ret.expression().type(), state.returnType); convertTo(state, ret.expression().type(), state.returnType);
boxPrimitive(state, state.returnType); boxPrimitive(state, state.returnType);
mv.visitInsn(ARETURN); mv.visitInsn(ARETURN);
} else mv.visitInsn(RETURN); } else
mv.visitInsn(RETURN);
break; break;
} }
case TargetThis _this: { case TargetThis _this: {
@ -956,13 +921,9 @@ public class Codegen {
} }
var descriptor = call.getDescriptor(); var descriptor = call.getDescriptor();
if (call.owner() instanceof TargetFunNType) // Decay FunN if (call.owner() instanceof TargetFunNType) // Decay FunN
descriptor = TargetMethod.getDescriptor( descriptor = TargetMethod.getDescriptor(call.returnType() == null ? null : TargetType.Object, call.parameterTypes().stream().map(x -> TargetType.Object).toArray(TargetType[]::new));
call.returnType() == null ? null : TargetType.Object,
call.parameterTypes().stream().map(x -> TargetType.Object).toArray(TargetType[]::new)
);
mv.visitMethodInsn(call.isInterface() ? INVOKEINTERFACE : call.isStatic() ? INVOKESTATIC: call.name().equals("<init>") ? INVOKESPECIAL : INVOKEVIRTUAL, mv.visitMethodInsn(call.isInterface() ? INVOKEINTERFACE : call.isStatic() ? INVOKESTATIC : call.name().equals("<init>") ? INVOKESPECIAL : INVOKEVIRTUAL, call.owner().getInternalName(), call.name(), descriptor, call.isInterface());
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)) if (!call.returnType().equals(call.type()) && !(call.type() instanceof TargetGenericType))
@ -1000,7 +961,7 @@ public class Codegen {
mv.visitCode(); mv.visitCode();
var state = new State(null, mv, 1); var state = new State(null, mv, 1);
for (var param: constructor.parameters()) for (var param : constructor.parameters())
state.createVariable(param.name(), param.type()); state.createVariable(param.name(), param.type());
var stmts = constructor.block().statements(); var stmts = constructor.block().statements();
@ -1027,7 +988,7 @@ public class Codegen {
mv.visitCode(); mv.visitCode();
var state = new State(method.returnType(), mv, method.isStatic() ? 0 : 1); var state = new State(method.returnType(), mv, method.isStatic() ? 0 : 1);
for (var param: method.parameters()) for (var param : method.parameters())
state.createVariable(param.name(), param.type()); state.createVariable(param.name(), param.type());
generate(state, method.block()); generate(state, method.block());
if (method.returnType() == null) if (method.returnType() == null)
@ -1048,10 +1009,7 @@ public class Codegen {
} }
public byte[] generate() { public byte[] generate() {
cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC | ACC_SUPER, clazz.qualifiedName(), cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC | ACC_SUPER, clazz.qualifiedName(), generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName() : "java/lang/Object", clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new));
generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
);
if (!clazz.txGenerics().isEmpty()) if (!clazz.txGenerics().isEmpty())
cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics()))); cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics())));

View File

@ -122,17 +122,15 @@ public class StatementGenerator {
public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) { public ParameterList convert(Java17Parser.FormalParameterListContext formalParameterListContext) {
List<FormalParameter> ret = new ArrayList<>(); List<FormalParameter> ret = new ArrayList<>();
List<Java17Parser.FormalParameterContext> fps = new ArrayList<>(); List<Java17Parser.FormalParameterContext> fps = new ArrayList<>();
if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null) if (!Objects.isNull(formalParameterListContext.lastFormalParameter())) {
return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer
/* /*
* Restrukturierung Java17-Grammatik Zeile wird nicht mehr benötigt, da Regel für Parameter-Liste nicht mehr rekursiv ist. "lastFormalParameter" hat kein Kind "formalParameter" mehr. * Der '...' Operator wird noch nicht unterstützt, da dafür benötigte Typen (List oder Array) nicht vom Typinferenzalgo. verarbeitet werden können
*
* if(formalParameterListContext.lastFormalParameter().formalParameter() == null) throw new NotImplementedException();
*/ */
throw new NotImplementedException("Formale Parameter variabler Länge nicht unterstützt.");
}
if (formalParameterListContext.children.size() == 0)
return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer
fps = formalParameterListContext.formalParameter(); fps = formalParameterListContext.formalParameter();
for (Java17Parser.FormalParameterContext fp : fps) { for (Java17Parser.FormalParameterContext fp : fps) {
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId()); String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
RefTypeOrTPHOrWildcardOrGeneric type; RefTypeOrTPHOrWildcardOrGeneric type;

View File

@ -206,7 +206,7 @@ public class StatementToTargetExpression implements StatementVisitor {
var returnType = isFunNType ? TargetType.Object : converter.convert(methodCall.signature.get(methodCall.signature.size() - 1)); var returnType = isFunNType ? TargetType.Object : converter.convert(methodCall.signature.get(methodCall.signature.size() - 1));
var receiverName = new JavaClassName(converter.convert(methodCall.receiver.getType()).name()); var receiverName = new JavaClassName(converter.convert(methodCall.receiver.getType()).name());
var argList = methodCall.signature.stream().map(converter::convert).toList(); var argList = methodCall.signature.stream().map(converter::convert).toList();
argList = argList.subList(0, argList.size() - 1); // argList = argList.subList(0, argList.size() - 1);
Method foundMethod = null; Method foundMethod = null;
if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver && expressionReceiver.expr instanceof This) { if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver && expressionReceiver.expr instanceof This) {

View File

@ -206,7 +206,7 @@ public class TestComplete {
vv1.addElement(v3); vv1.addElement(v3);
vv1.addElement(v4); vv1.addElement(v4);
var instanceOfClass_m2 = matrixOP.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1); var instanceOfClass_m2 = matrixOP.getDeclaredConstructor(Vector.class).newInstance(vv1);// Matrix m2 = new Matrix(vv1);
var mul = matrixOP.getField("mul"); var mul = matrixOP.getField("mul");
mul.setAccessible(true); mul.setAccessible(true);
@ -238,10 +238,10 @@ public class TestComplete {
var matrix = classFiles.get("Matrix"); var matrix = classFiles.get("Matrix");
Vector<Vector<Integer>> vv = new Vector<>(); Vector<Vector<Integer>> vv = new Vector<>();
Vector<Integer> v1 = new Vector<> (); Vector<Integer> v1 = new Vector<>();
v1.addElement(2); v1.addElement(2);
v1.addElement(2); v1.addElement(2);
Vector<Integer> v2 = new Vector<> (); Vector<Integer> v2 = new Vector<>();
v2.addElement(3); v2.addElement(3);
v2.addElement(3); v2.addElement(3);
vv.addElement(v1); vv.addElement(v1);
@ -250,10 +250,10 @@ public class TestComplete {
var instanceOfClass_m1 = matrix.getDeclaredConstructor(Vector.class).newInstance(vv); var instanceOfClass_m1 = matrix.getDeclaredConstructor(Vector.class).newInstance(vv);
Vector<Vector<Integer>> vv1 = new Vector<>(); Vector<Vector<Integer>> vv1 = new Vector<>();
Vector<Integer> v3 = new Vector<> (); Vector<Integer> v3 = new Vector<>();
v3.addElement(2); v3.addElement(2);
v3.addElement(2); v3.addElement(2);
Vector<Integer> v4 = new Vector<> (); Vector<Integer> v4 = new Vector<>();
v4.addElement(3); v4.addElement(3);
v4.addElement(3); v4.addElement(3);
vv1.addElement(v3); vv1.addElement(v3);
@ -266,10 +266,10 @@ public class TestComplete {
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString()); System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m2.toString() + " = " + result.toString());
Vector<Vector<Integer>> res = new Vector<>(); Vector<Vector<Integer>> res = new Vector<>();
Vector<Integer> v5 = new Vector<> (); Vector<Integer> v5 = new Vector<>();
v5.addElement(10); v5.addElement(10);
v5.addElement(10); v5.addElement(10);
Vector<Integer> v6 = new Vector<> (); Vector<Integer> v6 = new Vector<>();
v6.addElement(15); v6.addElement(15);
v6.addElement(15); v6.addElement(15);
res.addElement(v5); res.addElement(v5);
@ -324,7 +324,7 @@ public class TestComplete {
var relOps = classFiles.get("RelOps"); var relOps = classFiles.get("RelOps");
var instance = relOps.getDeclaredConstructor().newInstance(); var instance = relOps.getDeclaredConstructor().newInstance();
var m = relOps.getDeclaredMethod("m", Integer.class,Integer.class); var m = relOps.getDeclaredMethod("m", Integer.class, Integer.class);
assertFalse((Boolean) m.invoke(instance, 7, 3)); assertFalse((Boolean) m.invoke(instance, 7, 3));
} }
@ -487,7 +487,6 @@ public class TestComplete {
assertEquals(W, m2.getGenericReturnType()); assertEquals(W, m2.getGenericReturnType());
} }
@Test @Test
public void Tph7Test() throws Exception { public void Tph7Test() throws Exception {
var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader()); var classFiles = TestCodegen.generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
@ -497,59 +496,55 @@ public class TestComplete {
// public <N, O> N m(O var1, N var2) // public <N, O> N m(O var1, N var2)
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class); Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
//System.out.println(m.toString()); // System.out.println(m.toString());
//Argumenttypes of the method m // Argumenttypes of the method m
var paraTypes = m.getGenericParameterTypes(); var paraTypes = m.getGenericParameterTypes();
//Typeparameters of the method m // Typeparameters of the method m
var typeParaTypes = m.getTypeParameters(); var typeParaTypes = m.getTypeParameters();
//Typeparameters are extracted from the argumenttypes // Typeparameters are extracted from the argumenttypes
//Conditions for the extracted typeparameters are set // Conditions for the extracted typeparameters are set
//paraTypes[0] = O // paraTypes[0] = O
var boundFstArg = Arrays.stream(typeParaTypes) var boundFstArg = Arrays.stream(typeParaTypes).filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds();
.filter(x -> x.equals(paraTypes[0])).findFirst().get().getBounds();
//Bound of O has to be Object // Bound of O has to be Object
assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get()); assertEquals(Object.class, Arrays.stream(boundFstArg).findFirst().get());
//paraTypes[1] = N // paraTypes[1] = N
var N = Arrays.stream(typeParaTypes) var N = Arrays.stream(typeParaTypes).filter(x -> x.equals(paraTypes[1])).findFirst().get();
.filter(x -> x.equals(paraTypes[1])).findFirst().get();
var boundSndArg = N.getBounds(); var boundSndArg = N.getBounds();
//Bound of H has to be Object // Bound of H has to be Object
assertEquals(Object.class, Arrays.stream(boundSndArg).findFirst().get()); assertEquals(Object.class, Arrays.stream(boundSndArg).findFirst().get());
//N has to be the return type of m // N has to be the return type of m
assertEquals(N, m.getGenericReturnType()); assertEquals(N, m.getGenericReturnType());
//public <DZU> DZU m2(DZU); // public <DZU> DZU m2(DZU);
Method m2 = classToTest.getDeclaredMethod("m2", Object.class); Method m2 = classToTest.getDeclaredMethod("m2", Object.class);
//Argumenttypes of the method m2 // Argumenttypes of the method m2
var paraTypesm2 = m2.getGenericParameterTypes(); var paraTypesm2 = m2.getGenericParameterTypes();
//Typeparameters of the method m2 // Typeparameters of the method m2
var typeParaTypesm2 = m2.getTypeParameters(); var typeParaTypesm2 = m2.getTypeParameters();
//Typeparameters are extracted from the argumenttypes // Typeparameters are extracted from the argumenttypes
//Conditions for the extracted typeparameters are set // Conditions for the extracted typeparameters are set
//paraTypes[0] = DZU // paraTypes[0] = DZU
var fstArgm2 = Arrays.stream(typeParaTypesm2) var fstArgm2 = Arrays.stream(typeParaTypesm2).filter(x -> x.equals(paraTypesm2[0])).findFirst().get();
.filter(x -> x.equals(paraTypesm2[0])).findFirst().get();
//Bound of DZU has to be Object // Bound of DZU has to be Object
assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get()); assertEquals(Object.class, Arrays.stream(fstArgm2.getBounds()).findFirst().get());
//DZU has to be the return type of m // DZU has to be the return type of m
assertEquals(fstArgm2, m2.getGenericReturnType()); assertEquals(fstArgm2, m2.getGenericReturnType());
} }
@Test @Test
public void typedIdTest() throws Exception { public void typedIdTest() throws Exception {
var classFiles = generateClassFiles("TypedID.jav", new ByteArrayClassLoader()); var classFiles = generateClassFiles("TypedID.jav", new ByteArrayClassLoader());