Parser Bugfix

This commit is contained in:
laurenz 2024-05-18 17:19:31 +02:00
parent 4d0f124057
commit 35d7733c62
2 changed files with 9 additions and 4 deletions

View File

@ -14,7 +14,10 @@ public class BlockGenerator extends DecafBaseVisitor<Block> {
public Block visitBlock(DecafParser.BlockContext ctx) { public Block visitBlock(DecafParser.BlockContext ctx) {
List<Statement> statements = new ArrayList<>(ctx.stmt().size()); List<Statement> statements = new ArrayList<>(ctx.stmt().size());
for (DecafParser.StmtContext stmtContext : ctx.stmt()) { for (DecafParser.StmtContext stmtContext : ctx.stmt()) {
statements.addAll(new StatementGenerator().visit(stmtContext)); List<Statement> statementList = new StatementGenerator().visit(stmtContext);
if (statementList != null){
statements.addAll(statementList);
}
} }
if (ctx.return_() != null){ if (ctx.return_() != null){
statements.add(ctx.return_().isEmpty() ? new Return(null) : new Return(new ExpressionGenerator().visit(ctx.return_()))); statements.add(ctx.return_().isEmpty() ? new Return(null) : new Return(new ExpressionGenerator().visit(ctx.return_())));

View File

@ -110,9 +110,11 @@ public class StatementGenerator extends DecafBaseVisitor<List<Statement>> {
recursiveOwnerChain = ExpressionGenerator.generateRecursiveOwnerChain(recipientList, null); recursiveOwnerChain = ExpressionGenerator.generateRecursiveOwnerChain(recipientList, null);
} }
List<Expression> args = new ArrayList<>(); List<Expression> args = new ArrayList<>();
for (var expr : ctx.methCall().methName().args().expr()) { if (ctx.methCall().methName().args() != null) {
Expression astExpr = expr.accept(new ExpressionGenerator()); for (var expr : ctx.methCall().methName().args().expr()) {
args.add(astExpr); 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)); return List.of(new MethodCall(new FieldVarAccess(isField, recursiveOwnerChain, ctx.methCall().methName().id().IDENTIFIER().getText()), args));
} }