feat: working with Integer-Values but not Strings.
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Has been cancelled
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Has been cancelled
This commit is contained in:
parent
0d572ed9b6
commit
5f944e441c
@ -2,14 +2,12 @@ import java.lang.Integer;
|
||||
import java.lang.Object;
|
||||
import java.lang.Float;
|
||||
|
||||
public record Rec(Integer a, Object b) {}
|
||||
public record Rec(Object a, Object b) {}
|
||||
|
||||
public class SwitchInfered {
|
||||
public main(o) {
|
||||
return switch (o) {
|
||||
case Rec(a, b) -> a + b;
|
||||
case Rec(Integer a, Float b) -> a + 10;
|
||||
case Rec(Integer a, Rec(Integer b, Integer c)) -> a + b + c;
|
||||
case Integer i -> i;
|
||||
default -> 0;
|
||||
};
|
||||
|
@ -1404,6 +1404,9 @@ public class Codegen {
|
||||
for (var i = 0; i < depth; i++) {
|
||||
state.mv.visitInsn(POP);
|
||||
}
|
||||
|
||||
|
||||
|
||||
state.mv.visitVarInsn(ALOAD, state.switchResultValue.peek());
|
||||
state.mv.visitLdcInsn(index + 1);
|
||||
state.mv.visitJumpInsn(GOTO, start);
|
||||
|
@ -474,7 +474,8 @@ public class StatementGenerator {
|
||||
List<Pattern> subPattern = subPatternCtx.stream().map(this::convert).collect(Collectors.toList());
|
||||
IdentifierContext identifierCtx = recordPatternCtx.identifier();
|
||||
var text = (identifierCtx != null) ? identifierCtx.getText() : null;
|
||||
var type = TypeGenerator.convert(recordPatternCtx.typeType(), reg, generics);
|
||||
//Hier evtl. Typ anpassen -> wenn kein Typ bekannt ist push neuen Typ auf Hashtable
|
||||
var type = recordPatternCtx.typeType() == null ? TypePlaceholder.fresh(recordPatternCtx.getStart()) : TypeGenerator.convert(recordPatternCtx.typeType(), reg, generics);
|
||||
if (text != null) localVars.put(text, type);
|
||||
return new RecordPattern(subPattern, text, type, recordPatternCtx.getStart());
|
||||
}
|
||||
|
@ -3,12 +3,15 @@ import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import targetast.TestCodegen;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@ -678,8 +681,16 @@ public class TestComplete {
|
||||
public void testSwitchInfered() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "SwitchInfered.jav");
|
||||
var clazz = classFiles.get("SwitchInfered");
|
||||
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var swtch = clazz.getDeclaredMethod("main", Object.class);
|
||||
|
||||
var record = classFiles.get("Rec");
|
||||
var ctor = record.getDeclaredConstructor(Object.class, Object.class);
|
||||
var r1 = ctor.newInstance(1, 2);
|
||||
|
||||
|
||||
assertEquals(swtch.invoke(instance, r1), 3);
|
||||
}
|
||||
|
||||
@Ignore("Not implemented")
|
||||
@ -733,6 +744,7 @@ public class TestComplete {
|
||||
var clazz = classFiles.get("Interfaces");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStatic() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Static.jav");
|
||||
|
@ -22,6 +22,7 @@ import static org.junit.Assert.*;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -83,6 +84,9 @@ public class TestCodegen {
|
||||
public static Class<?> generateClass(TargetStructure clazz, IByteArrayClassLoader classLoader, ASTToTargetAST converter) throws IOException {
|
||||
Codegen codegen = new Codegen(clazz, converter.compiler, converter);
|
||||
var code = codegen.generate();
|
||||
try (FileOutputStream fos = new FileOutputStream("C:\\Users\\ruben\\Desktop\\asd\\test.class")) {
|
||||
fos.write(code);
|
||||
}
|
||||
writeClassFile(clazz.qualifiedName().getClassName(), code);
|
||||
return classLoader.loadClass(code);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user