From b50c7e99603e9f85d82d700d62c16c4fcef88715 Mon Sep 17 00:00:00 2001 From: Geno <48206120+gabrielegenovese@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:57:56 +0200 Subject: Code generation (#20) Co-authored-by: geno Co-authored-by: Santo Cariotti --- src/ast/nodes/CompoundNode.java | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/ast/nodes/CompoundNode.java') diff --git a/src/ast/nodes/CompoundNode.java b/src/ast/nodes/CompoundNode.java index 2655f35..f0f63f2 100644 --- a/src/ast/nodes/CompoundNode.java +++ b/src/ast/nodes/CompoundNode.java @@ -23,23 +23,23 @@ public class CompoundNode implements Node { } @Override - public ArrayList checkSemantics(SymbolTable ST, int _nesting) { + public ArrayList checkSemantics(SymbolTable ST, int _nesting, FunctionType ft) { ArrayList errors = new ArrayList<>(); if (ifNode != null) { - errors.addAll(ifNode.checkSemantics(ST, _nesting)); + errors.addAll(ifNode.checkSemantics(ST, _nesting, ft)); } if (funcDef != null) { - errors.addAll(funcDef.checkSemantics(ST, _nesting)); + errors.addAll(funcDef.checkSemantics(ST, _nesting, ft)); } if (forStmt != null) { - errors.addAll(forStmt.checkSemantics(ST, _nesting)); + errors.addAll(forStmt.checkSemantics(ST, _nesting, ft)); } if (whileStmt != null) { - errors.addAll(whileStmt.checkSemantics(ST, _nesting)); + errors.addAll(whileStmt.checkSemantics(ST, _nesting, ft)); } return errors; @@ -50,10 +50,25 @@ public class CompoundNode implements Node { return new VoidType(); } - // TODO: add code generation for CompoundNode @Override public String codeGeneration() { - return ""; + if (ifNode != null) { + return ifNode.codeGeneration(); + } + + if (funcDef != null) { + return funcDef.codeGeneration(); + } + + if (forStmt != null) { + return forStmt.codeGeneration(); + } + + if (whileStmt != null) { + return whileStmt.codeGeneration(); + } + + return "Error: everything is null in Compound node\n"; } @Override -- cgit v1.2.3-71-g8e6c