forked from JavaTX/JavaCompilerCore
WIP
This commit is contained in:
parent
25c0c9c101
commit
f8f76e9f7d
@ -1,12 +1,12 @@
|
||||
public class TestContraVariant {
|
||||
main(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
m(x) {
|
||||
var z = main(x);
|
||||
var y;
|
||||
x = y;
|
||||
return y;
|
||||
}
|
||||
|
||||
main(x) {
|
||||
return m(x);
|
||||
return new Pair(z, y);
|
||||
}
|
||||
}
|
@ -51,6 +51,7 @@ public class ASTFactory {
|
||||
var classReader = new ClassReader(bytes);
|
||||
var classVisitor = new ClassVisitor(Opcodes.ASM7) {
|
||||
String classSignature;
|
||||
|
||||
@Override
|
||||
public void visitAttribute(Attribute attribute) {
|
||||
if (attribute.type.equals("JavaTXSignature")) {
|
||||
@ -181,7 +182,7 @@ public class ASTFactory {
|
||||
}else{
|
||||
jreRetType = jreMethod.getReturnType();
|
||||
}
|
||||
returnType = createType(jreRetType);
|
||||
returnType = createType(jreRetType);
|
||||
Parameter[] jreParams = jreMethod.getParameters();
|
||||
Type[] jreGenericParams = jreMethod.getGenericParameterTypes();
|
||||
List<FormalParameter> params = new ArrayList<>();
|
||||
@ -284,7 +285,7 @@ public class ASTFactory {
|
||||
public SignatureVisitor visitTypeArgument(char wildcard) {
|
||||
this.wildcard = wildcard;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
boolean equals(RefTypeOrTPHOrWildcardOrGeneric a, RefTypeOrTPHOrWildcardOrGeneric b) {
|
||||
if (b instanceof SuperWildcardType wc)
|
||||
@ -395,11 +396,12 @@ public class ASTFactory {
|
||||
public static ClassOrInterface createObjectClass() {
|
||||
return createClass(Object.class);
|
||||
}
|
||||
|
||||
public static RefType createObjectType() {
|
||||
return new RefType(createClass(Object.class).getClassName(), new NullToken());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
public Constructor createEmptyConstructor(Class parent){
|
||||
Block block = new Block();
|
||||
block.setType(new de.dhbwstuttgart.syntaxtree.type.Void(block, 0));
|
||||
|
@ -145,7 +145,7 @@ public class ASTToTargetAST {
|
||||
return containsLeft && containsRight;
|
||||
}
|
||||
|
||||
static void addToPairs(Set<ResultPair<?, ?>> input, ResultPair<?, ?> pair) {
|
||||
void addToPairs(Set<ResultPair<?, ?>> input, ResultPair<?, ?> pair) {
|
||||
if (pair instanceof PairTPHsmallerTPH) {
|
||||
input.removeIf(pair2 -> {
|
||||
if (pair2 instanceof PairTPHequalRefTypeOrWildcardType) {
|
||||
@ -248,7 +248,8 @@ public class ASTToTargetAST {
|
||||
var optMethod = findMethod(owner, methodCall.name, methodCall.getArgumentList());
|
||||
if (optMethod.isEmpty()) return;
|
||||
var method = optMethod.get();
|
||||
var generics = family(owner, method);
|
||||
var generics = generics(owner, method);
|
||||
System.out.println("Generics: " + generics);
|
||||
|
||||
// transitive and
|
||||
var all = transitiveClosure(generics);
|
||||
@ -265,17 +266,21 @@ public class ASTToTargetAST {
|
||||
outer:
|
||||
for (var R1 : typeVariables) {
|
||||
if (typeVariablesOfClass.contains(R1)) continue;
|
||||
for (var generic : all) {
|
||||
if (!(generic.getRight() instanceof TypePlaceholder type))
|
||||
continue;
|
||||
for (var generic : all) if (generic instanceof PairTPHsmallerTPH ptph) {
|
||||
var l = equality.getOrDefault(ptph.left, ptph.left);
|
||||
var r = equality.getOrDefault(ptph.right, ptph.right);
|
||||
|
||||
for (var pair : simplifiedConstraints) {
|
||||
if (!(pair.left.equals(R1) && pair.right.equals(generic.getLeft())))
|
||||
var l2 = equality.getOrDefault(pair.left, pair.left);
|
||||
var r2 = equality.getOrDefault(pair.right, pair.right);
|
||||
if (!(l2.equals(R1) && r2.equals(l)))
|
||||
continue;
|
||||
|
||||
for (var R2 : typeVariables) {
|
||||
for (var pair2 : simplifiedConstraints) {
|
||||
if (!(pair2.right.equals(R2) && pair2.left.equals(type)))
|
||||
var l3 = equality.getOrDefault(pair2.left, pair2.left);
|
||||
var r3 = equality.getOrDefault(pair2.right, pair2.right);
|
||||
if (!(r3.equals(R2) && l3.equals(r)))
|
||||
continue;
|
||||
if (R1.equals(R2)) continue;
|
||||
if (!T1s.contains(R1) || !R2.equals(T2)) continue;
|
||||
@ -480,8 +485,8 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
Set<ResultPair<?, ?>> generics(ClassOrInterface owner, Method method) {
|
||||
if (computedGenericsOfMethods.containsKey(method))
|
||||
return computedGenericsOfMethods.get(method);
|
||||
//if (computedGenericsOfMethods.containsKey(method))
|
||||
// return computedGenericsOfMethods.get(method);
|
||||
|
||||
var classGenerics = generics(owner);
|
||||
|
||||
@ -597,7 +602,7 @@ public class ASTToTargetAST {
|
||||
continue outer;
|
||||
}
|
||||
if (classGenerics == null || classGenerics.stream().noneMatch((pair) -> pair.getLeft().equals(ptph.right)))
|
||||
result.add(new PairTPHequalRefTypeOrWildcardType(ptph.right, OBJECT));
|
||||
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(ptph.right, OBJECT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user