From a97548c3ee21fb55ba3861d740ca2b74be11802f Mon Sep 17 00:00:00 2001 From: StefanZ3 Date: Fri, 31 May 2024 12:11:43 +0200 Subject: [PATCH] fix localvardecl --- src/main/java/astGenerator/ASTGenerator.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/astGenerator/ASTGenerator.java b/src/main/java/astGenerator/ASTGenerator.java index 8ae4d20..2d8a6d0 100644 --- a/src/main/java/astGenerator/ASTGenerator.java +++ b/src/main/java/astGenerator/ASTGenerator.java @@ -39,7 +39,7 @@ public class ASTGenerator extends DecafBaseVisitor { hasMain = false; } for (DecafParser.LocalVarDeclContext fieldDecl: ctx.localVarDecl()) { - fieldDecls.add((FieldDecl) visit(fieldDecl)); + fieldDecls.add((FieldDecl) generateFieldDecl(fieldDecl)); } for (DecafParser.ConstuctorDeclContext constDecl: ctx.constuctorDecl()) { MethodDecl constructor = ((MethodDecl) visit(constDecl)); @@ -54,9 +54,13 @@ public class ASTGenerator extends DecafBaseVisitor { return new RefType(name,fieldDecls, methodDecls, hasMain); } + public Node generateFieldDecl(DecafParser.LocalVarDeclContext ctx) { + return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText()); + } + @Override public Node visitLocalVarDecl(DecafParser.LocalVarDeclContext ctx) { - return new FieldDecl(ctx.type().getText(), ctx.Identifier().getText()); + return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText()); } @Override @@ -108,6 +112,8 @@ public class ASTGenerator extends DecafBaseVisitor { return visitStmtExpr(ctx.stmtExpr()); } else if (ctx.emptyStatement() != null) { return visitEmptyStatement(ctx.emptyStatement()); + } else if (ctx.localVarDecl() != null) { + return visitLocalVarDecl(ctx.localVarDecl()); } return null; }