NichtHaskell/Source/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java
Jochen Seyfried 2527d15467 Added Bytecodegeneration to the missing classes
Also included some TODOs in areas where parameters and some connections are missing
2024-05-07 13:50:51 +02:00

63 lines
1.9 KiB
Java

package abstractSyntaxTree.StatementExpression;
import TypeCheck.AbstractType;
import TypeCheck.TypeCheckResult;
import abstractSyntaxTree.Class.MethodDecl;
import abstractSyntaxTree.Datatype.RefType;
import abstractSyntaxTree.Expression.IExpression;
import abstractSyntaxTree.Statement.IStatement;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import java.util.List;
public class MethodCallStatementExpression extends AbstractType implements IExpression, IStatement {
String methodName;
List<IExpression> arguments;
RefType classThatHasTheMethodIfNotThis;
RefType thisClass;
public MethodCallStatementExpression(String methodName, List<IExpression> arguments) {
this.methodName = methodName;
this.arguments = arguments;
}
@Override
public TypeCheckResult typeCheck() throws Exception {
TypeCheckResult result = new TypeCheckResult();
RefType searchMethodHere;
if(classThatHasTheMethodIfNotThis == null){
searchMethodHere = thisClass;
} else {
searchMethodHere = classThatHasTheMethodIfNotThis;
}
List<MethodDecl> methods = searchMethodHere.methodDecls;
if(!methods.contains(methodName)){
throw new Exception("method not found");
}
return result;
}
@Override
public void CodeGen(MethodVisitor mv) throws Exception {
//Generate Bytecode for the receiver
if(classThatHasTheMethodIfNotThis != null){
classThatHasTheMethodIfNotThis.CodeGen(mv);
} else {
mv.visitVarInsn(Opcodes.ALOAD, 0);
}
for (IExpression argument : arguments) {
argument.CodeGen(mv);
}
//We need the class reference and the return type of the method
//mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, thisClass.name, methodName, return type);
}
}