diff options
Diffstat (limited to 'src/ast/nodes/FuncdefNode.java')
-rw-r--r-- | src/ast/nodes/FuncdefNode.java | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/ast/nodes/FuncdefNode.java b/src/ast/nodes/FuncdefNode.java index 67bc772..8985e08 100644 --- a/src/ast/nodes/FuncdefNode.java +++ b/src/ast/nodes/FuncdefNode.java @@ -1,7 +1,9 @@ package ast.nodes; import java.util.ArrayList; +import java.util.HashMap; +import semanticanalysis.STentry; import semanticanalysis.SemanticError; import semanticanalysis.SymbolTable; import ast.types.*; @@ -11,6 +13,7 @@ import org.antlr.v4.runtime.tree.TerminalNode; * Node for the `funcdef` statement of the grammar. */ public class FuncdefNode implements Node { + private TerminalNode name; private Node paramlist; private Node block; @@ -24,12 +27,29 @@ public class FuncdefNode implements Node { @Override public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { ArrayList<SemanticError> errors = new ArrayList<SemanticError>(); + int paramNumber = ((ParamlistNode) paramlist).getParamNumber(); + Type returnType = this.block.typeCheck(); + FunctionType ft = new FunctionType(paramNumber, returnType); + + ST.insert(this.name.toString(), ft, _nesting, ""); + + HashMap<String, STentry> HM = new HashMap<String, STentry>(); + + ST.add(HM); + + ST.insert(this.name.toString(), ft, _nesting + 1, ""); if (paramlist != null) { - errors.addAll(paramlist.checkSemantics(ST, _nesting)); + errors.addAll(paramlist.checkSemantics(ST, _nesting + 1)); } - errors.addAll(block.checkSemantics(ST, _nesting)); + // TODO: think to the fucking offset + // Offset is increased for the possible return value + ST.increaseoffset(); + + errors.addAll(block.checkSemantics(ST, _nesting + 1)); + + ST.remove(); return errors; } |