First step to fixing methodCall

This commit is contained in:
Jochen Seyfried 2024-07-01 23:35:24 +02:00
parent cabbbdcaf3
commit 38aeaa657d
2 changed files with 17 additions and 15 deletions

View File

@ -37,6 +37,8 @@ public class InstVarExpression extends AbstractType implements IExpression{
}
TypeCheckResult result = new TypeCheckResult();
result.type = varType;
//TODO: Needed for methodCall codeGen
setTypeCheckResult(result);
return result;
}

View File

@ -119,30 +119,30 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
} else {
throw new ExecutionControl.NotImplementedException("Receiver is null.");
}
/*
else {
String type = localVars.get(receiver.identifier);
if (type == null) {
type = typeContext.get(thisClass).get(receiver.identifier);
}
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, receiver.identifier, "L" + type + ";");
}
*/
// Generate the code for each argument expression
for (IExpression argument : arguments) {
argument.codeGen(mv, localVars, typeContext, methodContext);
}
// Invoke the method
String descriptor = getMethodDescriptor(localVars, methodContext);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, methodName, descriptor, false);
// Invoke the method for each receiving method in the chain
for (ReceivingMethod receivingMethod : receivingMethods) {
// Get the owner class for the current method in the chain
owner = receivingMethod.thisClass;
// Generate the code for each argument expression for the current method
for (IExpression argument : receivingMethod.arguments) {
argument.codeGen(mv, localVars, typeContext, methodContext);
}
// Invoke the current method
String descriptor = getMethodDescriptor(receivingMethod.methodName, localVars, methodContext, receivingMethod.arguments);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, receivingMethod.methodName, descriptor, false);
}
}
// ()I
private String getMethodDescriptor(LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) {
private String getMethodDescriptor(String methodName, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, List<IExpression> arguments) {
StringBuilder descriptor = new StringBuilder("(");
for (IExpression argument : arguments) {