2024-04-25 11:27:38 +00:00
|
|
|
package abstractSyntaxTree.Statement;
|
|
|
|
|
2024-05-02 11:12:39 +00:00
|
|
|
import TypeCheck.TypeCheckResult;
|
|
|
|
import TypeCheck.AbstractType;
|
2024-05-02 12:31:37 +00:00
|
|
|
import abstractSyntaxTree.Expression.IExpression;
|
2024-05-02 11:12:39 +00:00
|
|
|
|
|
|
|
public class ReturnStatement extends AbstractType implements IStatement{
|
2024-05-02 12:31:37 +00:00
|
|
|
IExpression expression;
|
|
|
|
|
|
|
|
public ReturnStatement(IExpression expression) {
|
|
|
|
this.expression = expression;
|
|
|
|
}
|
|
|
|
|
2024-05-02 11:12:39 +00:00
|
|
|
@Override
|
|
|
|
public TypeCheckResult typeCheck() throws Exception {
|
2024-05-02 12:31:37 +00:00
|
|
|
TypeCheckResult result = new TypeCheckResult();
|
|
|
|
|
|
|
|
if (expression == null) {
|
|
|
|
result.type = "void";
|
|
|
|
} else {
|
|
|
|
TypeCheckResult typedExpression = expression.typeCheck();
|
|
|
|
result.type = typedExpression.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2024-05-02 11:12:39 +00:00
|
|
|
}
|
2024-04-25 11:27:38 +00:00
|
|
|
}
|