diff options
Diffstat (limited to 'src/ast/nodes/ReturnStmtNode.java')
| -rw-r--r-- | src/ast/nodes/ReturnStmtNode.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/ast/nodes/ReturnStmtNode.java b/src/ast/nodes/ReturnStmtNode.java new file mode 100644 index 0000000..0cfd2b4 --- /dev/null +++ b/src/ast/nodes/ReturnStmtNode.java @@ -0,0 +1,57 @@ +package com.clp.project.ast.nodes; + +import java.util.ArrayList; + +import com.clp.project.semanticanalysis.SemanticError; +import com.clp.project.semanticanalysis.SymbolTable; +import com.clp.project.ast.types.*; + +/** + * Node for the `return_stmt` statement of the grammar. + */ +public class ReturnStmtNode implements Node { + private Node exprList; + + public ReturnStmtNode(Node exprList) { + this.exprList = exprList; + } + + @Override + public ArrayList<SemanticError> checkSemantics(SymbolTable ST, int _nesting) { + ArrayList<SemanticError> errors = new ArrayList<SemanticError>(); + + if (this.exprList != null) { + errors.addAll(this.exprList.checkSemantics(ST, _nesting)); + } + + return errors; + } + + @Override + public Type typeCheck() { + if (this.exprList != null) { + return this.exprList.typeCheck(); + } + + return new VoidType(); + } + + // TODO: add code generation for return stmt + @Override + public String codeGeneration() { + return ""; + } + + @Override + public String toPrint(String prefix) { + String str = prefix + "ReturnStmt\n"; + + prefix += " "; + if (this.exprList != null) { + str += this.exprList.toPrint(prefix); + } + + return str; + } + +} |
