/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.mcmaster.cas.matlab2smt;

/**
 *
 * @author matthew
 */
final class MatlabExpressionUnaryOperation implements MatlabExpression, MatlabExpressionWithSubExpression {

    MatlabExpressionUnaryOperation(MatlabUnaryOperation op, MatlabExpression rhs) {
        m_expr = rhs;
        m_op = op;
    }

    void setExpression(MatlabExpression expr) {
        m_expr = expr;
    }

    @Override
    public VariableType actualOutputTypeForRequestedOutput(VariableTypeMarker requestedType) {
        return m_expr.actualOutputTypeForRequestedOutput(requestedType);
    }

    @Override
    public String getCheckerOutput(CheckerGenerator generator, VariableType requestedType) {
        if (actualOutputTypeForRequestedOutput(requestedType) == null) {
            throw new IllegalArgumentException("Can generate output for requested type!");
        }

        String expression = m_expr.getCheckerOutput(generator, requestedType);

        return generator.GenerateUnaryOperation(m_op, expression, requestedType);
    }

    @Override
    public MatlabExpression getSubExpression() {
        return m_expr;
    }

    @Override
    public void setSubExpression(MatlabExpression subExpression) {
        m_expr = subExpression;
    }

    @Override
    public String toString() {
        return "( " + m_op + " " + m_expr + ")";
    }

    MatlabExpression m_expr;
    MatlabUnaryOperation m_op;
}
