diff --git a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java index d528767..04c7525 100644 --- a/src/main/java/abstractSyntaxTree/Class/MethodDecl.java +++ b/src/main/java/abstractSyntaxTree/Class/MethodDecl.java @@ -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>> methodContext, HashMap> typeContext) throws Exception { diff --git a/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java b/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java index 93845ac..75c763a 100644 --- a/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java +++ b/src/main/java/abstractSyntaxTree/StatementExpression/MethodCallStatementExpression.java @@ -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); 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();