package ast.node;

import ast.visitor.Visitor;

@SuppressWarnings("nls")
public final class PrintStatement extends IStatement
{
    private IExp _exp_;

    public PrintStatement()
    {
        // Constructor
    }

    public PrintStatement(IExp _exp_)
    {
        // Constructor
        setExp(_exp_);
    }

    @Override
    public Object clone()
    {
        return new PrintStatement(cloneNode(this._exp_));
    }

    public void accept(Visitor v)
    {
        v.visitPrintStatement(this);
    }

    public IExp getExp()
    {
        return this._exp_;
    }

    public void setExp(IExp node)
    {
        if(this._exp_ != null)
        {
            this._exp_.parent(null);
        }

        if(node != null)
        {
            if(node.parent() != null)
            {
                node.parent().removeChild(node);
            }

            node.parent(this);
        }

        this._exp_ = node;
    }

    @Override
    void removeChild(Node child)
    {
        // Remove child
        if(this._exp_ == child)
        {
            this._exp_ = null;
            return;
        }

        throw new RuntimeException("Not a child.");
    }

    @Override
    void replaceChild(Node oldChild, Node newChild)
    {
        // Replace child
        if(this._exp_ == oldChild)
        {
            setExp((IExp) newChild);
            return;
        }
        throw new RuntimeException("Not a child.");
    }
}
