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

package MONAViewer.monalanguage.node;

import java.util.*;
import MONAViewer.monalanguage.analysis.*;

public final class ALet0Exp extends PExp
{
    private final LinkedList _def_ = new TypedLinkedList(new Def_Cast());
    private PExp _in_;

    public ALet0Exp ()
    {
    }

    public ALet0Exp (
            List _def_,
            PExp _in_
    )
    {
        this._def_.clear();
        this._def_.addAll(_def_);
        setIn (_in_);
    }

    public Object clone()
    {
        return new ALet0Exp (
            cloneList (_def_),
            (PExp)cloneNode (_in_)
        );
    }

    public void apply(Switch sw)
    {
        ((Analysis) sw).caseALet0Exp(this);
    }

    public LinkedList getDef ()
    {
        return _def_;
    }

    public void setDef (List list)
    {
        _def_.clear();
        _def_.addAll(list);
    }
    public PExp getIn ()
    {
        return _in_;
    }

    public void setIn (PExp node)
    {
        if(_in_ != null)
        {
            _in_.parent(null);
        }

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

            node.parent(this);
        }

        _in_ = node;
    }

    public String toString()
    {
        return ""
            + toString (_def_)
            + toString (_in_)
        ;
    }

    void removeChild(Node child)
    {
        if ( _def_.remove(child))
        {
            return;
        }
        if ( _in_ == child )
        {
            _in_ = null;
            return;
        }
    }

    void replaceChild(Node oldChild, Node newChild)
    {
        for(ListIterator i = _def_.listIterator(); i.hasNext();)
        {
            if(i.next() == oldChild)
            {
                if(newChild != null)
                {
                    i.set(newChild);
                    oldChild.parent(null);
                    return;
                }

                i.remove();
                oldChild.parent(null);
                return;
            }
        }
        if ( _in_ == oldChild )
        {
            setIn ((PExp) newChild);
            return;
        }
    }

    private class Def_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PDef node = (PDef) o;

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

            if((node.parent() == null) ||
                (node.parent() != ALet0Exp.this))
            {
                node.parent(ALet0Exp.this);
            }

            return node;
        }
    }
}
