From 719e19e7f884509f9752ce834c33cd1f4cd90222 Mon Sep 17 00:00:00 2001 From: Jochen Seyfried Date: Thu, 20 Jun 2024 09:07:29 +0200 Subject: [PATCH 1/2] Added TODOs --- src/main/java/abstractSyntaxTree/Class/MethodDecl.java | 3 +++ .../StatementExpression/MethodCallStatementExpression.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java index 384d8a1..7235f31 100644 --- a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java +++ b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java @@ -48,6 +48,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>> methodContext, HashMap> typeContext) throws Exception { diff --git a/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java b/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java index 4fa060c..19b31c7 100644 --- a/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java +++ b/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java @@ -60,6 +60,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(); @@ -87,7 +88,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); From ebd4f7ca4e874883c419892ce1cdef88d9e0ca0f Mon Sep 17 00:00:00 2001 From: StefanZ3 Date: Thu, 20 Jun 2024 09:35:43 +0200 Subject: [PATCH 2/2] fix parameterList in ast --- src/main/java/astGenerator/ASTGenerator.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/astGenerator/ASTGenerator.java b/src/main/java/astGenerator/ASTGenerator.java index ab192db..b079acd 100644 --- a/src/main/java/astGenerator/ASTGenerator.java +++ b/src/main/java/astGenerator/ASTGenerator.java @@ -66,7 +66,10 @@ public class ASTGenerator extends DecafBaseVisitor { @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 { 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();