Merge remote-tracking branch 'origin/master'

This commit is contained in:
Krauß, Josefine 2024-06-20 11:03:41 +02:00
commit 5a66ce97ca
3 changed files with 14 additions and 4 deletions

View File

@ -49,6 +49,9 @@ public class MethodDecl implements Node {
return result;
}
//TODO: Es wird kein Bytecode für Standardkonstruktoren für die Klassen generiert
//TODO: Stack computing schlägt fehl --> Reihenfolge aufruf? --> Sobald if-else / if / while drin sind? --> vllt auch schon bei MethodenDecl
//Need to get the returnType of the method if it is an object
// methodContext (class, (returnType, (identifier, parameter)))
public void codeGen(ClassWriter cw, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext) throws Exception {

View File

@ -57,6 +57,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
//Generate Bytecode for the receiver
if (classThatHasTheMethodIfNotThis != null) {
//TODO: classThatHasTheMethodIfNotThis must be an object --> instance of the class not the class itself
// This is not finished
// Need to call codeGen so it pushes the instance onto the stack, which will be popped of
//classThatHasTheMethodIfNotThis.codeGen();
@ -84,7 +85,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
for (MethodDecl methodDecl : methodDecls) {
if (methodDecl.name.equals(methodName)) {
//Get the method descriptor
// descriptor = methodDecl.getMethodDescriptor(methodContext);
//descriptor = methodDecl.getMethodDescriptor(methodContext);
}
}
// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, thisClass.name, methodName, descriptor, false);

View File

@ -66,7 +66,10 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
@Override
public Node visitConstuctorDecl(DecafParser.ConstuctorDeclContext ctx) {
String name = ctx.Identifier().getText();
ParameterList parameterList = (ParameterList) visit(ctx.parameterList());
ParameterList parameterList = new ParameterList(new ArrayList<>());
if (ctx.parameterList() != null) {
parameterList = (ParameterList) visit(ctx.parameterList());
}
BlockStatement block = (BlockStatement) visitBlock(ctx.block());
return new MethodDecl("", null, name, parameterList, block);
}
@ -76,8 +79,11 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
String type;
String name = ctx.Identifier().getText();
BlockStatement block = (BlockStatement) visitBlock(ctx.block());
ParameterList parameterList = (ParameterList) visit(ctx.parameterList());
if (ctx.Void() != null) {
ParameterList parameterList = new ParameterList(new ArrayList<>());
if (ctx.parameterList() != null) {
parameterList = (ParameterList) visit(ctx.parameterList());
}
if (ctx.Void() != null) {
type = "void";
} else {
type = ctx.type().getText();