/* This file was generated by SableCC (http://www.sablecc.org/). 
 * Then modified.
 */

package ast.node;

import ast.visitor.*;

@SuppressWarnings("nls")
public final class MeggySetPixel extends IStatement
{
    private IExp _x_exp_;
    private IExp _y_exp_;
    private IExp color;

    public MeggySetPixel(int _line_, int _pos_, 
            IExp _x_exp_, IExp _y_exp_, IExp color)
    {
        super(_line_, _pos_);
        
        setXExp(_x_exp_);
        setYExp(_y_exp_);
        setColor(color);
    }

    @Override
    public int getNumExpChildren() { return 3; }
    
    @Override
    public Object clone()
    {
        return new MeggySetPixel(
                this.getLine(),
                this.getPos(),
                this._x_exp_,this._y_exp_,this.color);
    }

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

    public IExp getXExp()
    {
        return this._x_exp_;
    }

    public IExp getYExp()
    {
        return this._y_exp_;
    }

    public IExp getColor()
    {
        return this.color;
    }

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

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

            node.parent(this);
        }

        this._x_exp_ = node;
    }

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

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

            node.parent(this);
        }

        this._y_exp_ = node;
    }

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

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

            node.parent(this);
        }

        this.color = node;
    }

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

        if(this._y_exp_ == child)
        {
            this._y_exp_ = null;
            return;
        }

        if(this.color == child)
        {
            this.color = null;
            return;
        }
        throw new RuntimeException("Not a child.");
    }

    @Override
    void replaceChild(Node oldChild, Node newChild)
    {
        // Replace child
        if(this._x_exp_ == oldChild)
        {
            setXExp((IExp) newChild);
            return;
        }

        if(this._y_exp_ == oldChild)
        {
            setYExp((IExp) newChild);
            return;
        }

        if(this.color == oldChild)
        {
            setColor((IExp) newChild);
            return;
        }

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