diff --git a/src/main/java/de/maishai/BlockGenerator.java b/src/main/java/de/maishai/BlockGenerator.java index 6b762cc..075c1cf 100644 --- a/src/main/java/de/maishai/BlockGenerator.java +++ b/src/main/java/de/maishai/BlockGenerator.java @@ -14,7 +14,10 @@ public class BlockGenerator extends DecafBaseVisitor { public Block visitBlock(DecafParser.BlockContext ctx) { List statements = new ArrayList<>(ctx.stmt().size()); for (DecafParser.StmtContext stmtContext : ctx.stmt()) { - statements.addAll(new StatementGenerator().visit(stmtContext)); + List statementList = new StatementGenerator().visit(stmtContext); + if (statementList != null){ + statements.addAll(statementList); + } } if (ctx.return_() != null){ statements.add(ctx.return_().isEmpty() ? new Return(null) : new Return(new ExpressionGenerator().visit(ctx.return_()))); diff --git a/src/main/java/de/maishai/StatementGenerator.java b/src/main/java/de/maishai/StatementGenerator.java index f3bf0de..f01cf0d 100644 --- a/src/main/java/de/maishai/StatementGenerator.java +++ b/src/main/java/de/maishai/StatementGenerator.java @@ -110,9 +110,11 @@ public class StatementGenerator extends DecafBaseVisitor> { recursiveOwnerChain = ExpressionGenerator.generateRecursiveOwnerChain(recipientList, null); } List args = new ArrayList<>(); - for (var expr : ctx.methCall().methName().args().expr()) { - Expression astExpr = expr.accept(new ExpressionGenerator()); - args.add(astExpr); + if (ctx.methCall().methName().args() != null) { + for (var expr : ctx.methCall().methName().args().expr()) { + Expression astExpr = expr.accept(new ExpressionGenerator()); + args.add(astExpr); + } } return List.of(new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().IDENTIFIER().getText()), args)); }