Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode
This commit is contained in:
commit
d39fd64f0f
@ -1027,7 +1027,7 @@ public class Codegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public byte[] generate() {
|
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",
|
generateSignature(clazz), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object",
|
||||||
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new)
|
||||||
);
|
);
|
||||||
|
@ -135,7 +135,7 @@ public class ASTToTargetAST {
|
|||||||
typeVariablesOfFields.addAll(findTypeVariables(field.getType()));
|
typeVariablesOfFields.addAll(findTypeVariables(field.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//findTypeVariables(method.getReturnType(), typeVariables);
|
typeVariables.addAll(findTypeVariables(method.getReturnType()));
|
||||||
for (var arg : method.getParameterList().getFormalparalist()) {
|
for (var arg : method.getParameterList().getFormalparalist()) {
|
||||||
typeVariables.addAll(findTypeVariables(arg.getType()));
|
typeVariables.addAll(findTypeVariables(arg.getType()));
|
||||||
}
|
}
|
||||||
@ -459,7 +459,6 @@ public class ASTToTargetAST {
|
|||||||
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(pair.right, OBJECT));
|
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(pair.right, OBJECT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
eliminateCyclesAndInfima(result);
|
eliminateCyclesAndInfima(result);
|
||||||
usedTPHsOfMethods.put(method, typeVariables);
|
usedTPHsOfMethods.put(method, typeVariables);
|
||||||
|
|
||||||
@ -569,6 +568,8 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void eliminateInnerTypeVariables(Set<TypePlaceholder> referenced, Set<ResultPair<?, ?>> input) {
|
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);
|
var oldInput = new HashSet<>(input);
|
||||||
for (var pair : oldInput) {
|
for (var pair : oldInput) {
|
||||||
if (pair instanceof PairTPHsmallerTPH ptph && !referenced.contains(ptph.left)) {
|
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) {
|
void eliminateCycles(Set<ResultPair<?, ?>> input) {
|
||||||
|
@ -31,7 +31,7 @@ public class TestCodegen {
|
|||||||
private static void writeClassFile(String name, byte[] code) throws IOException {
|
private static void writeClassFile(String name, byte[] code) throws IOException {
|
||||||
var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
|
var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
|
||||||
Files.createDirectories(path);
|
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 {
|
public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException {
|
||||||
|
@ -226,7 +226,6 @@ public class TestGenerics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore("This doesn't work properly")
|
|
||||||
public void testThreeArgs() throws Exception {
|
public void testThreeArgs() throws Exception {
|
||||||
var result = computeGenerics("TestThreeArgs.jav");
|
var result = computeGenerics("TestThreeArgs.jav");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user