Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e24bbd552 | ||
|
|
50f2572644 | ||
|
|
e1518c8b37 | ||
|
|
f7a85db191 | ||
|
|
41d5f661e1 | ||
|
|
b7f46c428f |
@@ -5,6 +5,8 @@ import java.lang.Object;
|
|||||||
|
|
||||||
public class HelloWorld {
|
public class HelloWorld {
|
||||||
public static hello() {
|
public static hello() {
|
||||||
System.out.println((Object)"Hello World!");
|
System.out.println("Hello World!");
|
||||||
|
System.out.println("Bye World!");
|
||||||
|
System.out.println("The end!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,8 +381,21 @@ public class ASTToTargetAST {
|
|||||||
TargetBlock finalFieldInitializer = fieldInitializer;
|
TargetBlock finalFieldInitializer = fieldInitializer;
|
||||||
|
|
||||||
var superInterfaces = input.getSuperInterfaces().stream().map(clazz -> convert(clazz, generics.javaGenerics, compiler)).toList();
|
var superInterfaces = input.getSuperInterfaces().stream().map(clazz -> convert(clazz, generics.javaGenerics, compiler)).toList();
|
||||||
var constructors = input.getConstructors().stream().map(constructor -> this.convert(input, constructor, finalFieldInitializer, generics)).flatMap(List::stream).toList();
|
var constructors = input.getConstructors().stream().map(constructor -> {
|
||||||
var fields = input.getFieldDecl().stream().map(f -> convert(f, generics.javaGenerics)).toList();
|
try {
|
||||||
|
return this.convert(input, constructor, finalFieldInitializer, generics);
|
||||||
|
} catch (DiscardResultSet discard) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).filter(Objects::nonNull).flatMap(List::stream).toList();
|
||||||
|
var fields = input.getFieldDecl().stream().map(f -> {
|
||||||
|
var possibleTypes = new HashSet<TargetType>();
|
||||||
|
for (var g : all) possibleTypes.add(convert(f.getType(), g.javaGenerics(), compiler));
|
||||||
|
if (possibleTypes.size() > 1)
|
||||||
|
compiler.warn(new CompilerWarning(f.getOffset(), "Multiple possible types for field " + f.getName() + ": " + possibleTypes + " please select one"));
|
||||||
|
return convert(f, generics.javaGenerics);
|
||||||
|
}).toList();
|
||||||
var m0 = groupMethods(input, input.getMethods());
|
var m0 = groupMethods(input, input.getMethods());
|
||||||
|
|
||||||
var m1 = new ArrayList<TargetMethod>();
|
var m1 = new ArrayList<TargetMethod>();
|
||||||
@@ -889,10 +902,13 @@ public class ASTToTargetAST {
|
|||||||
signatures.add(new Signature(javaSignature, txSignature, generics));
|
signatures.add(new Signature(javaSignature, txSignature, generics));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!signatures.isEmpty()) {
|
for (var signature : new ArrayList<>(signatures)) {
|
||||||
var signature = signatures.getFirst();
|
try {
|
||||||
// We need to convert once to find out what TPHs are existing in the given method
|
convert(new MethodWithTphs(method, signature.generics, signature));
|
||||||
convert(new MethodWithTphs(method, signature.generics, signature));
|
} catch (DiscardResultSet discard) {
|
||||||
|
// If a result set is discarded we skip it from now on
|
||||||
|
signatures.removeIf(s -> s == signature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var signature : signatures) {
|
for (var signature : signatures) {
|
||||||
@@ -980,7 +996,7 @@ public class ASTToTargetAST {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSubtype(TargetType test, TargetType other) {
|
public boolean isSubtype(TargetType test, TargetType other) {
|
||||||
if (other.equals(TargetType.Object)) return true;
|
if (other.equals(TargetType.Object)) return true;
|
||||||
if (test instanceof TargetFunNType tfun && other instanceof TargetFunNType ofun)
|
if (test instanceof TargetFunNType tfun && other instanceof TargetFunNType ofun)
|
||||||
return isSubtype(new FunNGenerator.GenericParameters(tfun), new FunNGenerator.GenericParameters(ofun));
|
return isSubtype(new FunNGenerator.GenericParameters(tfun), new FunNGenerator.GenericParameters(ofun));
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DiscardResultSet extends RuntimeException {
|
||||||
|
public DiscardResultSet() {}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.target.generate;
|
package de.dhbwstuttgart.target.generate;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
@@ -222,6 +223,19 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MethodCall methodCall) {
|
public void visit(MethodCall methodCall) {
|
||||||
|
|
||||||
|
// Look at the signature in all result sets and check if a more specific insertion exists.
|
||||||
|
// If so, discard this result set by throwing an exception
|
||||||
|
for (var tph : Iterables.concat(List.of(methodCall.receiver.getType()), methodCall.signatureArguments())) {
|
||||||
|
var currentType = converter.convert(tph, generics);
|
||||||
|
for (var g2 : converter.all) if (g2.javaGenerics() != generics) {
|
||||||
|
var type = g2.javaGenerics().getTargetType(tph);
|
||||||
|
if (!Objects.equals(type, currentType) && converter.isSubtype(type, currentType)) {
|
||||||
|
throw new DiscardResultSet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var receiverType = converter.convert(methodCall.receiver.getType(), generics);
|
var receiverType = converter.convert(methodCall.receiver.getType(), generics);
|
||||||
var isFunNType = receiverType instanceof TargetFunNType;
|
var isFunNType = receiverType instanceof TargetFunNType;
|
||||||
|
|
||||||
@@ -261,7 +275,6 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
isInterface = receiverClass.isInterface();
|
isInterface = receiverClass.isInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
//System.out.println(argList);
|
|
||||||
result = new TargetMethodCall(
|
result = new TargetMethodCall(
|
||||||
converter.convert(methodCall.getType(), generics), returnType, argList,
|
converter.convert(methodCall.getType(), generics), returnType, argList,
|
||||||
converter.convert(methodCall.receiver, generics),
|
converter.convert(methodCall.receiver, generics),
|
||||||
|
|||||||
@@ -392,6 +392,8 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(BoolExpression expr) {
|
public void visit(BoolExpression expr) {
|
||||||
|
expr.lexpr.accept(this);
|
||||||
|
expr.rexpr.accept(this);
|
||||||
|
|
||||||
constraintsSet.addUndConstraint(new Pair(bool, expr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset())));
|
constraintsSet.addUndConstraint(new Pair(bool, expr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset())));
|
||||||
constraintsSet.addUndConstraint(new Pair(bool, expr.lexpr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset())));
|
constraintsSet.addUndConstraint(new Pair(bool, expr.lexpr.getType(), PairOperator.EQUALSDOT, loc(expr.getOffset())));
|
||||||
|
|||||||
Reference in New Issue
Block a user