forked from JavaTX/JavaCompilerCore
Merge branch 'targetBytecode' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into targetBytecode
This commit is contained in:
commit
6d12102fbf
@ -106,6 +106,25 @@ public class ASTToTargetAST {
|
|||||||
return generics.stream().anyMatch(generic -> generic.getLeft().equals(name));
|
return generics.stream().anyMatch(generic -> generic.getLeft().equals(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean containsRelation(Set<ResultPair<?, ?>> result, PairTPHsmallerTPH pair) {
|
||||||
|
// Check if both the right and the left are already part of a relation
|
||||||
|
var containsLeft = false;
|
||||||
|
for (var pair2 : result) {
|
||||||
|
if (pair2.getLeft().equals(pair.left)) {
|
||||||
|
containsLeft = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var containsRight = false;
|
||||||
|
for (var pair2 : result) {
|
||||||
|
if (pair2.getRight().equals(pair.right)) {
|
||||||
|
containsRight = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return containsLeft && containsRight;
|
||||||
|
}
|
||||||
|
|
||||||
// Family of generated Generics
|
// Family of generated Generics
|
||||||
Set<ResultPair<?, ?>> generics(ClassOrInterface owner, Method method) {
|
Set<ResultPair<?, ?>> generics(ClassOrInterface owner, Method method) {
|
||||||
if (computedGenericsOfMethods.containsKey(method))
|
if (computedGenericsOfMethods.containsKey(method))
|
||||||
@ -119,6 +138,7 @@ public class ASTToTargetAST {
|
|||||||
|
|
||||||
HashSet<TypePlaceholder> typeVariables = new HashSet<>();
|
HashSet<TypePlaceholder> typeVariables = new HashSet<>();
|
||||||
HashSet<TypePlaceholder> typeVariablesOfFields = new HashSet<>();
|
HashSet<TypePlaceholder> typeVariablesOfFields = new HashSet<>();
|
||||||
|
HashSet<TypePlaceholder> allTypeVariables = new HashSet<>();
|
||||||
|
|
||||||
for (var field : owner.getFieldDecl()) {
|
for (var field : owner.getFieldDecl()) {
|
||||||
findTypeVariables(field.getType(), typeVariablesOfFields);
|
findTypeVariables(field.getType(), typeVariablesOfFields);
|
||||||
@ -136,6 +156,17 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Type variables with bounds that are also type variables of the method
|
||||||
|
for (var typeVariable : new HashSet<>(typeVariables)) {
|
||||||
|
for (var pair : simplifiedConstraints) {
|
||||||
|
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
|
||||||
|
result.add(new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
||||||
|
typeVariables.add(pair.right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var visitedMethods = new HashSet<Method>();
|
||||||
method.block.accept(new TracingStatementVisitor() {
|
method.block.accept(new TracingStatementVisitor() {
|
||||||
@Override
|
@Override
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
@ -148,6 +179,9 @@ public class ASTToTargetAST {
|
|||||||
).findFirst();
|
).findFirst();
|
||||||
if (optMethod.isEmpty()) return;
|
if (optMethod.isEmpty()) return;
|
||||||
var method = optMethod.get();
|
var method = optMethod.get();
|
||||||
|
if (visitedMethods.contains(method)) return;
|
||||||
|
visitedMethods.add(method);
|
||||||
|
|
||||||
var generics = generics(owner, method);
|
var generics = generics(owner, method);
|
||||||
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
|
Set<ResultPair<?, ?>> all = new HashSet<>(generics);
|
||||||
|
|
||||||
@ -189,7 +223,11 @@ public class ASTToTargetAST {
|
|||||||
if (!(pair2.right.equals(tph2) && pair2.left.equals(type)))
|
if (!(pair2.right.equals(tph2) && pair2.left.equals(type)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
newPairs.add(new PairTPHsmallerTPH(tph, tph2));
|
var newPair = new PairTPHsmallerTPH(tph, tph2);
|
||||||
|
newPairs.add(newPair);
|
||||||
|
|
||||||
|
if (!containsRelation(result, newPair))
|
||||||
|
result.add(newPair);
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,10 +240,10 @@ public class ASTToTargetAST {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Type variables with bounds that are also type variables of the method or type variables of fields
|
// Type variables with bounds that are also type variables of fields
|
||||||
for (var typeVariable : new HashSet<>(typeVariables)) {
|
for (var typeVariable : new HashSet<>(typeVariables)) {
|
||||||
for (var pair : simplifiedConstraints) {
|
for (var pair : simplifiedConstraints) {
|
||||||
if (pair.left.equals(typeVariable) && (typeVariables.contains(pair.right) || typeVariablesOfFields.contains(pair.right))) {
|
if (pair.left.equals(typeVariable) && typeVariablesOfFields.contains(pair.right)) {
|
||||||
result.add(new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
result.add(new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
||||||
typeVariables.add(pair.right);
|
typeVariables.add(pair.right);
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import de.dhbwstuttgart.target.tree.MethodParameter;
|
|||||||
import de.dhbwstuttgart.target.tree.expression.*;
|
import de.dhbwstuttgart.target.tree.expression.*;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetFunNType;
|
import de.dhbwstuttgart.target.tree.type.TargetFunNType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||||
|
import de.dhbwstuttgart.target.tree.type.TargetSpecializedType;
|
||||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -135,12 +136,12 @@ public class StatementToTargetExpression implements StatementVisitor {
|
|||||||
var receiverType = converter.convert(methodCall.receiver.getType());
|
var receiverType = converter.convert(methodCall.receiver.getType());
|
||||||
var isFunNType = receiverType instanceof TargetFunNType;
|
var isFunNType = receiverType instanceof TargetFunNType;
|
||||||
var returnType = converter.convert(methodCall.getType());
|
var returnType = converter.convert(methodCall.getType());
|
||||||
var receiverName = new JavaClassName(((TargetRefType) converter.convert(methodCall.receiver.getType())).name());
|
var receiverName = new JavaClassName(((TargetSpecializedType) converter.convert(methodCall.receiver.getType())).name());
|
||||||
|
|
||||||
var argList = methodCall.arglist.getArguments().stream().map(expr -> converter.convert(expr.getType())).toList();
|
var argList = methodCall.arglist.getArguments().stream().map(expr -> converter.convert(expr.getType())).toList();
|
||||||
|
|
||||||
java.lang.reflect.Method foundMethod = null;
|
java.lang.reflect.Method foundMethod = null;
|
||||||
if (converter.sourceFile.imports.contains(receiverName)) {
|
if (converter.sourceFile != null && converter.sourceFile.imports.contains(receiverName)) {
|
||||||
try {
|
try {
|
||||||
var clazz = converter.classLoader.loadClass(receiverName.toString());
|
var clazz = converter.classLoader.loadClass(receiverName.toString());
|
||||||
|
|
||||||
|
@ -8,6 +8,11 @@ public record TargetFunNType(int N, List<TargetType> params) implements TargetSp
|
|||||||
return "Fun" + N + "$$";
|
return "Fun" + N + "$$";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toSignature() {
|
public String toSignature() {
|
||||||
return "L" + getName() + ";";
|
return "L" + getName() + ";";
|
||||||
|
@ -18,4 +18,6 @@ public sealed interface TargetSpecializedType extends TargetType permits TargetF
|
|||||||
ret += ";";
|
ret += ";";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String name();
|
||||||
}
|
}
|
||||||
|
@ -359,6 +359,13 @@ public class TestComplete {
|
|||||||
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
|
var m = tph5.getDeclaredMethod("m", Object.class, Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tph7Test() throws Exception {
|
||||||
|
var classFiles = generateClassFiles("Tph7.jav", new ByteArrayClassLoader());
|
||||||
|
var tph5 = classFiles.get("Tph7");
|
||||||
|
var instance = tph5.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
@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());
|
||||||
|
Loading…
Reference in New Issue
Block a user