Compare commits

...

5 Commits

Author SHA1 Message Date
Bruder John
4d5c0017b4 Merge branch 'main' into johns-branch
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-01 08:32:44 +02:00
3e901ea254 Merge pull request 'NewParser' (#15) from NewParser into main
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Reviewed-on: #15
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-06-27 16:56:32 +00:00
85ae06048c Add Return if Returntype is Void
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 18:55:28 +02:00
cd845cd91c Fixed Merge Conflicts
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-06-27 18:45:14 +02:00
78d5528733 Merge pull request 'More Tests, Structure, etc. Huge Changes' (#14) from Tests into main
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Reviewed-on: #14
Reviewed-by: Johannes Ehlert <i22005@hb.dhbw-stuttgart.de>
2024-06-27 10:49:35 +00:00

View File

@ -60,13 +60,16 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
constructorNode.addParameter((ParameterNode) visit(parameter)); constructorNode.addParameter((ParameterNode) visit(parameter));
} }
} }
constructorNode.block.addStatement(new ReturnNode(null));
return constructorNode; return constructorNode;
} }
@Override @Override
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) { public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
if(ctx.MainMethodDeclaration() != null) { if(ctx.MainMethodDeclaration() != null) {
return new MainMethodNode((BlockNode) visit(ctx.blockStatement())); MainMethodNode mainMethod = new MainMethodNode((BlockNode) visit(ctx.blockStatement()));
mainMethod.block.addStatement(new ReturnNode(null));
return mainMethod;
} else { } else {
if(ctx.type() != null) { if(ctx.type() != null) {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement())); MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
@ -83,6 +86,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
methodNode.addParameter((ParameterNode) visit(parameter)); methodNode.addParameter((ParameterNode) visit(parameter));
} }
} }
methodNode.block.addStatement(new ReturnNode(null));
return methodNode; return methodNode;
} }
} }
@ -133,16 +137,8 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override @Override
public ASTNode visitBlockStatement(SimpleJavaParser.BlockStatementContext ctx) { public ASTNode visitBlockStatement(SimpleJavaParser.BlockStatementContext ctx) {
BlockNode blockNode = new BlockNode(); BlockNode blockNode = new BlockNode();
boolean hasReturnStatement = false;
for(SimpleJavaParser.StatementContext statement : ctx.statement()) { for(SimpleJavaParser.StatementContext statement : ctx.statement()) {
IStatementNode statementNode = (IStatementNode) visit(statement); blockNode.addStatement((IStatementNode) visit(statement));
if(statementNode instanceof ReturnNode) {
hasReturnStatement = true;
}
blockNode.addStatement(statementNode);
}
if(!hasReturnStatement) {
blockNode.addStatement(new ReturnNode(null));
} }
return blockNode; return blockNode;
} }