28 lines
729 B
Java
28 lines
729 B
Java
package abstractSyntaxTree.Statement;
|
|
|
|
import TypeCheck.TypeCheckResult;
|
|
import TypeCheck.AbstractType;
|
|
import abstractSyntaxTree.Expression.IExpression;
|
|
|
|
public class ReturnStatement extends AbstractType implements IStatement{
|
|
IExpression expression;
|
|
|
|
public ReturnStatement(IExpression expression) {
|
|
this.expression = expression;
|
|
}
|
|
|
|
@Override
|
|
public TypeCheckResult typeCheck() throws Exception {
|
|
TypeCheckResult result = new TypeCheckResult();
|
|
|
|
if (expression == null) {
|
|
result.type = "void";
|
|
} else {
|
|
TypeCheckResult typedExpression = expression.typeCheck();
|
|
result.type = typedExpression.type;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|