Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode

This commit is contained in:
pl@gohorb.ba-horb.de 2023-02-02 14:50:18 +01:00
commit d39fd64f0f
4 changed files with 20 additions and 5 deletions

View File

@ -1027,7 +1027,7 @@ public class Codegen {
}
public byte[] generate() {
cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC, clazz.qualifiedName(),
cw.visit(V1_8, clazz.modifiers() | ACC_PUBLIC | ACC_SUPER, clazz.qualifiedName(),
generateSignature(clazz), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
);

View File

@ -135,7 +135,7 @@ public class ASTToTargetAST {
typeVariablesOfFields.addAll(findTypeVariables(field.getType()));
}
//findTypeVariables(method.getReturnType(), typeVariables);
typeVariables.addAll(findTypeVariables(method.getReturnType()));
for (var arg : method.getParameterList().getFormalparalist()) {
typeVariables.addAll(findTypeVariables(arg.getType()));
}
@ -459,7 +459,6 @@ public class ASTToTargetAST {
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(pair.right, OBJECT));
}
}
eliminateCyclesAndInfima(result);
usedTPHsOfMethods.put(method, typeVariables);
@ -569,6 +568,8 @@ public class ASTToTargetAST {
}
void eliminateInnerTypeVariables(Set<TypePlaceholder> referenced, Set<ResultPair<?, ?>> input) {
// Remove type variables that are part of a relation A < B < C where B is not in referenced
// Add new pair A < C
var oldInput = new HashSet<>(input);
for (var pair : oldInput) {
if (pair instanceof PairTPHsmallerTPH ptph && !referenced.contains(ptph.left)) {
@ -582,6 +583,21 @@ public class ASTToTargetAST {
}
}
}
// Remove lone type variables, A = RefType where A is in no relation X < A or A < X and A is not in referenced
oldInput = new HashSet<>(input);
outer:
for (var pair : oldInput) {
if (pair instanceof PairTPHequalRefTypeOrWildcardType ptph) {
if (!referenced.contains(ptph.left)) {
for (var pair2 : oldInput) {
if (pair != pair2 && (pair2.getLeft().equals(ptph.left) || pair2.getRight().equals(ptph.left)))
continue outer;
}
input.remove(pair);
}
}
}
}
void eliminateCycles(Set<ResultPair<?, ?>> input) {

View File

@ -31,7 +31,7 @@ public class TestCodegen {
private static void writeClassFile(String name, byte[] code) throws IOException {
var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
Files.createDirectories(path);
Files.write(path.resolve(name + ".class"), code, StandardOpenOption.CREATE);
Files.write(path.resolve(name + ".class"), code);
}
public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException {

View File

@ -226,7 +226,6 @@ public class TestGenerics {
}
@Test
@Ignore("This doesn't work properly")
public void testThreeArgs() throws Exception {
var result = computeGenerics("TestThreeArgs.jav");
}