Compare commits

...

2 Commits

Author SHA1 Message Date
77bf6cff62 Merge remote-tracking branch 'origin/master' 2024-05-31 12:12:18 +02:00
a97548c3ee fix localvardecl 2024-05-31 12:11:43 +02:00

View File

@ -39,7 +39,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
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<Node> {
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<Node> {
return visitStmtExpr(ctx.stmtExpr());
} else if (ctx.emptyStatement() != null) {
return visitEmptyStatement(ctx.emptyStatement());
} else if (ctx.localVarDecl() != null) {
return visitLocalVarDecl(ctx.localVarDecl());
}
return null;
}