Revert "Get rid of mutable state, hopefully fix #307"
This reverts commit bc61fc2e1d
.
This commit is contained in:
parent
8fdfbf875b
commit
3b14cd609f
@ -37,6 +37,8 @@ public class ASTToTargetAST {
|
||||
|
||||
public final JavaTXCompiler compiler;
|
||||
|
||||
protected ClassOrInterface currentClass; // TODO This is only needed because of SuperCall, maybe there's
|
||||
|
||||
public List<GenericsResult> txGenerics() {
|
||||
return all.stream().map(generics -> new GenericsResult(generics.txGenerics)).toList();
|
||||
}
|
||||
@ -45,8 +47,8 @@ public class ASTToTargetAST {
|
||||
return all.stream().map(generics -> new GenericsResult(generics.javaGenerics)).toList();
|
||||
}
|
||||
|
||||
public TargetExpression convert(ClassOrInterface clazz, Pattern pattern) {
|
||||
var converter = new StatementToTargetExpression(this, clazz);
|
||||
public TargetExpression convert(Pattern pattern) {
|
||||
var converter = new StatementToTargetExpression(this);
|
||||
pattern.accept(converter);
|
||||
return converter.result;
|
||||
}
|
||||
@ -130,6 +132,7 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
public TargetStructure convert(ClassOrInterface input) {
|
||||
currentClass = input;
|
||||
Set<TargetGeneric> javaGenerics = new HashSet<>();
|
||||
Set<TargetGeneric> txGenerics = new HashSet<>();
|
||||
|
||||
@ -153,17 +156,17 @@ public class ASTToTargetAST {
|
||||
|
||||
TargetBlock fieldInitializer = null;
|
||||
if (input.getfieldInitializations().isPresent())
|
||||
fieldInitializer = convert(input, input.getfieldInitializations().get().block);
|
||||
fieldInitializer = convert(input.getfieldInitializations().get().block);
|
||||
TargetBlock finalFieldInitializer = fieldInitializer;
|
||||
|
||||
var superInterfaces = input.getSuperInterfaces().stream().map(clazz -> convert(clazz, generics.javaGenerics)).toList();
|
||||
var constructors = input.getConstructors().stream().map(constructor -> this.convert(input, constructor, finalFieldInitializer)).flatMap(List::stream).toList();
|
||||
var constructors = input.getConstructors().stream().map(constructor -> this.convert(constructor, finalFieldInitializer)).flatMap(List::stream).toList();
|
||||
var fields = input.getFieldDecl().stream().map(this::convert).toList();
|
||||
var methods = groupOverloads(input.getMethods()).stream().map(m -> convert(input, m)).flatMap(List::stream).toList();
|
||||
var methods = groupOverloads(input.getMethods()).stream().map(this::convert).flatMap(List::stream).toList();
|
||||
|
||||
TargetMethod staticConstructor = null;
|
||||
if (input.getStaticInitializer().isPresent())
|
||||
staticConstructor = this.convert(input, input.getStaticInitializer().get()).get(0);
|
||||
staticConstructor = this.convert(input.getStaticInitializer().get()).get(0);
|
||||
|
||||
if (input instanceof Record)
|
||||
return new TargetRecord(input.getModifiers(), input.getClassName(), javaGenerics, txGenerics, superInterfaces, constructors, staticConstructor, fields, methods);
|
||||
@ -172,9 +175,9 @@ public class ASTToTargetAST {
|
||||
else return new TargetClass(input.getModifiers(), input.getClassName(), convert(input.getSuperClass(), generics.javaGenerics), javaGenerics, txGenerics, superInterfaces, constructors, staticConstructor, fields, methods);
|
||||
}
|
||||
|
||||
private List<MethodParameter> convert(ClassOrInterface clazz, ParameterList input, GenerateGenerics generics) {
|
||||
private List<MethodParameter> convert(ParameterList input, GenerateGenerics generics) {
|
||||
return input.getFormalparalist().stream().map(param ->
|
||||
new MethodParameter((TargetPattern) convert(clazz, param))
|
||||
new MethodParameter((TargetPattern) convert(param))
|
||||
).toList();
|
||||
}
|
||||
|
||||
@ -182,7 +185,7 @@ public class ASTToTargetAST {
|
||||
return generics.stream().anyMatch(g -> g.name().equals(type.getParsedName()));
|
||||
}
|
||||
|
||||
private Set<TargetGeneric> collectMethodGenerics(ClassOrInterface currentClass, GenerateGenerics generateGenerics, Set<GenerateGenerics.Pair> generics, Method input) {
|
||||
private Set<TargetGeneric> collectMethodGenerics(GenerateGenerics generateGenerics, Set<GenerateGenerics.Pair> generics, Method input) {
|
||||
var convertedGenerics = new HashSet<>(convert(generics, generateGenerics));
|
||||
outer: for (GenericTypeVar typeVar : input.getGenerics()) {
|
||||
for (var classGeneric : currentClass.getGenerics()) {
|
||||
@ -200,22 +203,22 @@ public class ASTToTargetAST {
|
||||
return convertedGenerics;
|
||||
}
|
||||
|
||||
private List<TargetConstructor> convert(ClassOrInterface clazz, Constructor input, TargetBlock fieldInitializer) {
|
||||
private List<TargetConstructor> convert(Constructor input, TargetBlock fieldInitializer) {
|
||||
generics = all.get(0);
|
||||
List<TargetConstructor> result = new ArrayList<>();
|
||||
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
||||
|
||||
for (var s : all) {
|
||||
generics = s;
|
||||
var javaGenerics = this.generics.javaGenerics.generics(clazz, input);
|
||||
var txGenerics = this.generics.txGenerics.generics(clazz, input);
|
||||
List<MethodParameter> params = convert(clazz, input.getParameterList(), this.generics.javaGenerics);
|
||||
var javaGenerics = this.generics.javaGenerics.generics(currentClass, input);
|
||||
var txGenerics = this.generics.txGenerics.generics(currentClass, input);
|
||||
List<MethodParameter> params = convert(input.getParameterList(), this.generics.javaGenerics);
|
||||
if (parameterSet.stream().noneMatch(p -> p.equals(params))) {
|
||||
List<MethodParameter> txParams = convert(clazz, input.getParameterList(), this.generics.txGenerics);
|
||||
var javaMethodGenerics = collectMethodGenerics(clazz, generics.javaGenerics(), javaGenerics, input);
|
||||
var txMethodGenerics = collectMethodGenerics(clazz, generics.txGenerics(), txGenerics, input);
|
||||
List<MethodParameter> txParams = convert(input.getParameterList(), this.generics.txGenerics);
|
||||
var javaMethodGenerics = collectMethodGenerics(generics.javaGenerics(), javaGenerics, input);
|
||||
var txMethodGenerics = collectMethodGenerics(generics.txGenerics(), txGenerics, input);
|
||||
|
||||
result.add(new TargetConstructor(input.modifier, javaMethodGenerics, txMethodGenerics, params, txParams, convert(clazz, input.block), fieldInitializer));
|
||||
result.add(new TargetConstructor(input.modifier, javaMethodGenerics, txMethodGenerics, params, txParams, convert(input.block), fieldInitializer));
|
||||
parameterSet.add(params);
|
||||
}
|
||||
}
|
||||
@ -288,9 +291,9 @@ public class ASTToTargetAST {
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
private List<TargetMethod> convert(ClassOrInterface currentClass, List<Method> overloadedMethods) {
|
||||
private List<TargetMethod> convert(List<Method> overloadedMethods) {
|
||||
if (overloadedMethods.size() == 1) {
|
||||
return convert(currentClass, overloadedMethods.get(0));
|
||||
return convert(overloadedMethods.get(0));
|
||||
}
|
||||
var res = new ArrayList<Method>();
|
||||
for (var method : overloadedMethods) {
|
||||
@ -327,7 +330,7 @@ public class ASTToTargetAST {
|
||||
var entryPoint = new Method(template.modifier, template.name, template.getReturnType(), params, block, template.getGenerics(), new NullToken());
|
||||
|
||||
res.add(entryPoint); // TODO*/
|
||||
return res.stream().map(m -> this.convert(currentClass, m)).flatMap(List::stream).toList();
|
||||
return res.stream().map(this::convert).flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
private Expression makeRecordSwitch(RefTypeOrTPHOrWildcardOrGeneric returnType, ParameterList params, List<Method> overloadedMethods) {
|
||||
@ -351,7 +354,7 @@ public class ASTToTargetAST {
|
||||
return swtch;
|
||||
}
|
||||
|
||||
private Optional<Method> findSuperMethodToOverride(ClassOrInterface currentClass, String name, List<MethodParameter> params) {
|
||||
private Optional<Method> findSuperMethodToOverride(String name, List<MethodParameter> params) {
|
||||
var superClass = compiler.getClass(currentClass.getSuperClass().getName());
|
||||
var methodStream = superClass.getMethods().stream();
|
||||
for (var superInterface : currentClass.getSuperInterfaces()) {
|
||||
@ -372,7 +375,7 @@ public class ASTToTargetAST {
|
||||
}).findFirst();
|
||||
}
|
||||
|
||||
private List<TargetMethod> convert(ClassOrInterface currentClass, Method method) {
|
||||
private List<TargetMethod> convert(Method method) {
|
||||
generics = all.get(0);
|
||||
List<TargetMethod> result = new ArrayList<>();
|
||||
Set<List<MethodParameter>> parameterSet = new HashSet<>();
|
||||
@ -381,58 +384,58 @@ public class ASTToTargetAST {
|
||||
generics = s;
|
||||
var javaGenerics = this.generics.javaGenerics.generics(currentClass, method);
|
||||
var txGenerics = this.generics.txGenerics.generics(currentClass, method);
|
||||
List<MethodParameter> params = convert(currentClass, method.getParameterList(), this.generics.javaGenerics);
|
||||
List<MethodParameter> params = convert(method.getParameterList(), this.generics.javaGenerics);
|
||||
var returnType = convert(method.getReturnType(), this.generics.javaGenerics);
|
||||
var superMethod = findSuperMethodToOverride(currentClass, method.getName(), params);
|
||||
var superMethod = findSuperMethodToOverride(method.getName(), params);
|
||||
if (superMethod.isPresent()) {
|
||||
// If we find a super method to override, use its parameters and return types
|
||||
returnType = convert(superMethod.get().getReturnType(), this.generics.javaGenerics);
|
||||
params = convert(currentClass, superMethod.get().getParameterList(), method.getParameterList(), this.generics.javaGenerics);
|
||||
params = convert(superMethod.get().getParameterList(), method.getParameterList(), this.generics.javaGenerics);
|
||||
}
|
||||
|
||||
List<MethodParameter> finalParams = params;
|
||||
if (parameterSet.stream().noneMatch(p -> p.equals(finalParams))) {
|
||||
List<MethodParameter> txParams = convert(currentClass, method.getParameterList(), this.generics.txGenerics);
|
||||
List<MethodParameter> txParams = convert(method.getParameterList(), this.generics.txGenerics);
|
||||
|
||||
var javaMethodGenerics = collectMethodGenerics(currentClass, generics.javaGenerics(), javaGenerics, method);
|
||||
var txMethodGenerics = collectMethodGenerics(currentClass, generics.txGenerics(), txGenerics, method);
|
||||
var javaMethodGenerics = collectMethodGenerics(generics.javaGenerics(), javaGenerics, method);
|
||||
var txMethodGenerics = collectMethodGenerics(generics.txGenerics(), txGenerics, method);
|
||||
|
||||
var javaSignature = new TargetMethod.Signature(javaMethodGenerics, params, returnType);
|
||||
var txSignature = new TargetMethod.Signature(txMethodGenerics, txParams, convert(method.getReturnType(), this.generics.txGenerics));
|
||||
result.add(new TargetMethod(method.modifier, method.name, convert(currentClass, method.block), javaSignature, txSignature));
|
||||
result.add(new TargetMethod(method.modifier, method.name, convert(method.block), javaSignature, txSignature));
|
||||
parameterSet.add(params);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<MethodParameter> convert(ClassOrInterface currentClass, ParameterList superList, ParameterList paraList, JavaGenerics generics) {
|
||||
private List<MethodParameter> convert(ParameterList superList, ParameterList paraList, JavaGenerics generics) {
|
||||
var list = new ArrayList<MethodParameter>();
|
||||
for (var i = 0; i < paraList.getFormalparalist().size(); i++) {
|
||||
var param = paraList.getParameterAt(i);
|
||||
list.add(new MethodParameter((TargetPattern) convert(currentClass, param)).withType(convert(superList.getParameterAt(i).getType(), generics)));
|
||||
list.add(new MethodParameter((TargetPattern) convert(param)).withType(convert(superList.getParameterAt(i).getType(), generics)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
protected TargetSwitch.Case convert(ClassOrInterface clazz, SwitchBlock block) {
|
||||
return new TargetSwitch.Case(block.getLabels().stream().map(x -> convert(clazz, x)).toList(), convert(clazz, (Block) block), block.isExpression);
|
||||
protected TargetSwitch.Case convert(SwitchBlock block) {
|
||||
return new TargetSwitch.Case(block.getLabels().stream().map(this::convert).toList(), convert((Block) block), block.isExpression);
|
||||
}
|
||||
|
||||
protected TargetBlock convert(ClassOrInterface clazz, Block block) {
|
||||
protected TargetBlock convert(Block block) {
|
||||
if (block == null) return null;
|
||||
return new TargetBlock(block.statements.stream().map(x -> convert(clazz, x)).toList());
|
||||
return new TargetBlock(block.statements.stream().map(this::convert).toList());
|
||||
}
|
||||
|
||||
protected TargetBlock convertWrapInBlock(ClassOrInterface clazz, Expression expression) {
|
||||
var res = convert(clazz, expression);
|
||||
protected TargetBlock convertWrapInBlock(Expression expression) {
|
||||
var res = convert(expression);
|
||||
if (!(res instanceof TargetBlock))
|
||||
return new TargetBlock(List.of(res));
|
||||
return (TargetBlock) res;
|
||||
}
|
||||
|
||||
protected TargetExpression convert(ClassOrInterface currentClass, Expression expr) {
|
||||
var converter = new StatementToTargetExpression(this, currentClass);
|
||||
protected TargetExpression convert(Expression expr) {
|
||||
var converter = new StatementToTargetExpression(this);
|
||||
expr.accept(converter);
|
||||
return converter.result;
|
||||
}
|
||||
|
@ -20,11 +20,8 @@ import java.util.stream.StreamSupport;
|
||||
|
||||
public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
private final ClassOrInterface currentClass;
|
||||
|
||||
public StatementToTargetExpression(ASTToTargetAST converter, ClassOrInterface currentClass) {
|
||||
public StatementToTargetExpression(ASTToTargetAST converter) {
|
||||
this.converter = converter;
|
||||
this.currentClass = currentClass;
|
||||
}
|
||||
|
||||
public TargetExpression result;
|
||||
@ -84,38 +81,38 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
} // Don't look at lambda expressions
|
||||
});
|
||||
|
||||
result = new TargetLambdaExpression(converter.convert(lambdaExpression.getType()), captures, parameters, converter.convert(lambdaExpression.getReturnType()), converter.convert(currentClass, lambdaExpression.methodBody));
|
||||
result = new TargetLambdaExpression(converter.convert(lambdaExpression.getType()), captures, parameters, converter.convert(lambdaExpression.getReturnType()), converter.convert(lambdaExpression.methodBody));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Assign assign) {
|
||||
TargetExpression left;
|
||||
if (assign.lefSide instanceof AssignToLocal) {
|
||||
left = converter.convert(currentClass, ((AssignToLocal) assign.lefSide).localVar);
|
||||
left = converter.convert(((AssignToLocal) assign.lefSide).localVar);
|
||||
} else {
|
||||
left = converter.convert(currentClass, ((AssignToField) assign.lefSide).field);
|
||||
left = converter.convert(((AssignToField) assign.lefSide).field);
|
||||
}
|
||||
|
||||
result = new TargetAssign(converter.convert(assign.getType()), left, converter.convert(currentClass, assign.rightSide));
|
||||
result = new TargetAssign(converter.convert(assign.getType()), left, converter.convert(assign.rightSide));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr binary) {
|
||||
result = switch (binary.operation) {
|
||||
case ADD -> new TargetBinaryOp.Add(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case SUB -> new TargetBinaryOp.Sub(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case MUL -> new TargetBinaryOp.Mul(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case MOD -> new TargetBinaryOp.Rem(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case AND -> new TargetBinaryOp.BAnd(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case OR -> new TargetBinaryOp.BOr(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case XOR -> new TargetBinaryOp.XOr(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case DIV -> new TargetBinaryOp.Div(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case LESSTHAN -> new TargetBinaryOp.Less(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case BIGGERTHAN -> new TargetBinaryOp.Greater(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case LESSEQUAL -> new TargetBinaryOp.LessOrEqual(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case BIGGEREQUAL -> new TargetBinaryOp.GreaterOrEqual(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case EQUAL -> new TargetBinaryOp.Equal(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case NOTEQUAL -> new TargetBinaryOp.NotEqual(converter.convert(binary.getType()), converter.convert(currentClass, binary.lexpr), converter.convert(currentClass, binary.rexpr));
|
||||
case ADD -> new TargetBinaryOp.Add(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case SUB -> new TargetBinaryOp.Sub(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case MUL -> new TargetBinaryOp.Mul(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case MOD -> new TargetBinaryOp.Rem(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case AND -> new TargetBinaryOp.BAnd(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case OR -> new TargetBinaryOp.BOr(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case XOR -> new TargetBinaryOp.XOr(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case DIV -> new TargetBinaryOp.Div(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case LESSTHAN -> new TargetBinaryOp.Less(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case BIGGERTHAN -> new TargetBinaryOp.Greater(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case LESSEQUAL -> new TargetBinaryOp.LessOrEqual(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case BIGGEREQUAL -> new TargetBinaryOp.GreaterOrEqual(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case EQUAL -> new TargetBinaryOp.Equal(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
case NOTEQUAL -> new TargetBinaryOp.NotEqual(converter.convert(binary.getType()), converter.convert(binary.lexpr), converter.convert(binary.rexpr));
|
||||
};
|
||||
}
|
||||
|
||||
@ -126,12 +123,12 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(Block block) {
|
||||
result = converter.convert(currentClass, block);
|
||||
result = converter.convert(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr castExpr) {
|
||||
result = new TargetCast(converter.convert(castExpr.getType()), converter.convert(currentClass, castExpr.expr));
|
||||
result = new TargetCast(converter.convert(castExpr.getType()), converter.convert(castExpr.expr));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,32 +138,32 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(FieldVar fieldVar) {
|
||||
result = new TargetFieldVar(converter.convert(fieldVar.getType()), converter.convert(fieldVar.receiver.getType()), fieldVar.isStatic, converter.convert(currentClass, fieldVar.receiver), fieldVar.fieldVarName);
|
||||
result = new TargetFieldVar(converter.convert(fieldVar.getType()), converter.convert(fieldVar.receiver.getType()), fieldVar.isStatic, converter.convert(fieldVar.receiver), fieldVar.fieldVarName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt forStmt) {
|
||||
result = new TargetFor(
|
||||
forStmt.initializer.stream().map(c -> converter.convert(currentClass, c)).toList(),
|
||||
forStmt.condition != null ? converter.convert(currentClass, forStmt.condition) : null,
|
||||
forStmt.loopExpr.stream().map(c -> converter.convert(currentClass, c)).toList(),
|
||||
converter.convertWrapInBlock(currentClass, forStmt.block)
|
||||
forStmt.initializer.stream().map(converter::convert).toList(),
|
||||
forStmt.condition != null ? converter.convert(forStmt.condition) : null,
|
||||
forStmt.loopExpr.stream().map(converter::convert).toList(),
|
||||
converter.convertWrapInBlock(forStmt.block)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForEachStmt forEachStmt) {
|
||||
result = new TargetForEach(converter.convert(currentClass, forEachStmt.statement), converter.convert(currentClass, forEachStmt.expression), converter.convertWrapInBlock(currentClass, forEachStmt.block));
|
||||
result = new TargetForEach(converter.convert(forEachStmt.statement), converter.convert(forEachStmt.expression), converter.convertWrapInBlock(forEachStmt.block));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
result = new TargetIf(converter.convert(currentClass, ifStmt.expr), converter.convertWrapInBlock(currentClass, ifStmt.then_block), ifStmt.else_block != null ? converter.convertWrapInBlock(currentClass, ifStmt.else_block) : null);
|
||||
result = new TargetIf(converter.convert(ifStmt.expr), converter.convertWrapInBlock(ifStmt.then_block), ifStmt.else_block != null ? converter.convertWrapInBlock(ifStmt.else_block) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOf instanceOf) {
|
||||
result = new TargetInstanceOf(converter.convert(currentClass, instanceOf.getExpression()), converter.convert(currentClass, instanceOf.getPattern()));
|
||||
result = new TargetInstanceOf(converter.convert(instanceOf.getExpression()), converter.convert(instanceOf.getPattern()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -206,10 +203,10 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
var isPrivate = false;
|
||||
var signature = methodCall.signatureArguments().stream().map(converter::convert).toList();
|
||||
|
||||
var receiverClass = currentClass;
|
||||
var receiverClass = converter.currentClass;
|
||||
if (methodCall.receiver instanceof ExpressionReceiver expressionReceiver && expressionReceiver.expr instanceof This) {
|
||||
var thisMethod = converter.findMethod(currentClass, methodCall.name, signature);
|
||||
foundMethod = thisMethod.orElseGet(() -> findMethod(currentClass.getSuperClass().getName(), methodCall.name, signature).orElseThrow());
|
||||
var thisMethod = converter.findMethod(converter.currentClass, methodCall.name, signature);
|
||||
foundMethod = thisMethod.orElseGet(() -> findMethod(converter.currentClass.getSuperClass().getName(), methodCall.name, signature).orElseThrow());
|
||||
} else if (!isFunNType) {
|
||||
receiverClass = converter.compiler.getClass(receiverName);
|
||||
foundMethod = findMethod(receiverName, methodCall.name, signature).orElseThrow();
|
||||
@ -223,7 +220,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
isInterface = receiverClass.isInterface();
|
||||
}
|
||||
|
||||
result = new TargetMethodCall(converter.convert(methodCall.getType()), returnType, argList, converter.convert(currentClass, methodCall.receiver), methodCall.getArgumentList().getArguments().stream().map(c -> converter.convert(currentClass, c)).toList(), receiverType, methodCall.name, isStatic, isInterface, isPrivate);
|
||||
result = new TargetMethodCall(converter.convert(methodCall.getType()), returnType, argList, converter.convert(methodCall.receiver), methodCall.getArgumentList().getArguments().stream().map(converter::convert).toList(), receiverType, methodCall.name, isStatic, isInterface, isPrivate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -231,7 +228,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
var receiverName = new JavaClassName(newClass.name);
|
||||
var ctor = converter.findConstructor(converter.compiler.getClass(receiverName), newClass.signatureArguments().stream().map(converter::convert).toList());
|
||||
var signature = ctor.orElseThrow().getParameterList().getFormalparalist().stream().map(e -> converter.convert(e.getType())).toList();
|
||||
result = new TargetNew(new TargetRefType(newClass.name), signature, newClass.getArgumentList().getArguments().stream().map(c -> converter.convert(currentClass, c)).toList());
|
||||
result = new TargetNew(new TargetRefType(newClass.name), signature, newClass.getArgumentList().getArguments().stream().map(converter::convert).toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -242,7 +239,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(Return aReturn) {
|
||||
result = new TargetReturn(converter.convert(currentClass, aReturn.retexpr));
|
||||
result = new TargetReturn(converter.convert(aReturn.retexpr));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -272,7 +269,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt whileStmt) {
|
||||
result = new TargetWhile(converter.convert(currentClass, whileStmt.expr), converter.convert(currentClass, whileStmt.loopBlock));
|
||||
result = new TargetWhile(converter.convert(whileStmt.expr), converter.convert(whileStmt.loopBlock));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -283,47 +280,47 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
// TODO These two might not be necessary
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
result = converter.convert(currentClass, assignLeftSide.field);
|
||||
result = converter.convert(assignLeftSide.field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
result = converter.convert(currentClass, assignLeftSide.localVar);
|
||||
result = converter.convert(assignLeftSide.localVar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperCall superCall) {
|
||||
var aSuper = converter.convert(currentClass.getSuperClass());
|
||||
var aSuper = converter.convert(converter.currentClass.getSuperClass());
|
||||
var type = converter.convert(superCall.getType());
|
||||
var parameters = superCall.arglist.getArguments().stream().map(par -> converter.convert(par.getType())).toList();
|
||||
|
||||
result = new TargetMethodCall(type, type, parameters, new TargetSuper(aSuper), superCall.getArgumentList().getArguments().stream().map(c -> converter.convert(currentClass, c)).toList(), aSuper, superCall.name, false, false, false);
|
||||
result = new TargetMethodCall(type, type, parameters, new TargetSuper(aSuper), superCall.getArgumentList().getArguments().stream().map(converter::convert).toList(), aSuper, superCall.name, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ThisCall thisCall) {
|
||||
var aThis = converter.convert(new RefType(currentClass.getClassName(), new NullToken()));
|
||||
var aThis = converter.convert(new RefType(converter.currentClass.getClassName(), new NullToken()));
|
||||
var type = converter.convert(thisCall.getType());
|
||||
var parameters = thisCall.arglist.getArguments().stream().map(par -> converter.convert(par.getType())).toList();
|
||||
|
||||
result = new TargetMethodCall(type, type, parameters, new TargetThis(aThis), thisCall.getArgumentList().getArguments().stream().map(c -> converter.convert(currentClass, c)).toList(), aThis, thisCall.name, false, false, false);
|
||||
result = new TargetMethodCall(type, type, parameters, new TargetThis(aThis), thisCall.getArgumentList().getArguments().stream().map(converter::convert).toList(), aThis, thisCall.name, false, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionReceiver expressionReceiver) {
|
||||
result = converter.convert(currentClass, expressionReceiver.expr);
|
||||
result = converter.convert(expressionReceiver.expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr unaryExpr) {
|
||||
result = switch (unaryExpr.operation) {
|
||||
case NOT -> new TargetUnaryOp.Not(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case MINUS -> new TargetUnaryOp.Negate(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case PREINCREMENT -> new TargetUnaryOp.PreIncrement(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case PREDECREMENT -> new TargetUnaryOp.PreDecrement(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case POSTINCREMENT -> new TargetUnaryOp.PostIncrement(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case PLUS -> new TargetUnaryOp.Add(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case POSTDECREMENT -> new TargetUnaryOp.PostDecrement(converter.convert(unaryExpr.getType()), converter.convert(currentClass, unaryExpr.expr));
|
||||
case NOT -> new TargetUnaryOp.Not(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
case MINUS -> new TargetUnaryOp.Negate(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
case PREINCREMENT -> new TargetUnaryOp.PreIncrement(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
case PREDECREMENT -> new TargetUnaryOp.PreDecrement(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
case POSTINCREMENT -> new TargetUnaryOp.PostIncrement(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
case PLUS -> new TargetUnaryOp.Add(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
case POSTDECREMENT -> new TargetUnaryOp.PostDecrement(converter.convert(unaryExpr.getType()), converter.convert(unaryExpr.expr));
|
||||
};
|
||||
}
|
||||
|
||||
@ -351,20 +348,20 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(Throw aThrow) {
|
||||
result = new TargetThrow(converter.convert(currentClass, aThrow.expr));
|
||||
result = new TargetThrow(converter.convert(aThrow.expr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Switch switchStmt) {
|
||||
var cases = switchStmt.getBlocks().stream().filter(s -> !s.isDefault()).map(c -> converter.convert(currentClass, c)).toList();
|
||||
var cases = switchStmt.getBlocks().stream().filter(s -> !s.isDefault()).map(converter::convert).toList();
|
||||
|
||||
TargetSwitch.Case default_ = null;
|
||||
for (var block : switchStmt.getBlocks()) {
|
||||
if (block.isDefault()) {
|
||||
default_ = new TargetSwitch.Case(converter.convert(currentClass, (Block) block), block.isExpression);
|
||||
default_ = new TargetSwitch.Case(converter.convert((Block) block), block.isExpression);
|
||||
}
|
||||
}
|
||||
result = new TargetSwitch(converter.convert(currentClass, switchStmt.getSwitch()), cases, default_ , converter.convert(switchStmt.getType()), !switchStmt.getStatement());
|
||||
result = new TargetSwitch(converter.convert(switchStmt.getSwitch()), cases, default_ , converter.convert(switchStmt.getType()), !switchStmt.getStatement());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -372,12 +369,12 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(SwitchLabel switchLabel) {
|
||||
result = converter.convert(currentClass, switchLabel.getPattern());
|
||||
result = converter.convert(switchLabel.getPattern());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Yield aYield) {
|
||||
result = new TargetYield(converter.convert(currentClass, aYield.retexpr));
|
||||
result = new TargetYield(converter.convert(aYield.retexpr));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -452,7 +449,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionPattern aPattern) {
|
||||
result = converter.convert(currentClass, aPattern.getExpression());
|
||||
result = converter.convert(aPattern.getExpression());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -460,12 +457,12 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
result = new TargetComplexPattern(
|
||||
converter.convert(aRecordPattern.getType()),
|
||||
aRecordPattern.getName(),
|
||||
aRecordPattern.getSubPattern().stream().map(x -> (TargetPattern) converter.convert(currentClass, x)).toList()
|
||||
aRecordPattern.getSubPattern().stream().map(x -> (TargetPattern) converter.convert(x)).toList()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(GuardedPattern aGuardedPattern) {
|
||||
result = new TargetGuard((TargetPattern) converter.convert(currentClass, aGuardedPattern.getNestedPattern()), converter.convert(currentClass, aGuardedPattern.getCondition()));
|
||||
result = new TargetGuard((TargetPattern) converter.convert(aGuardedPattern.getNestedPattern()), converter.convert(aGuardedPattern.getCondition()));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user