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

package MONAViewer.monalanguage.node;

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

public final class ACallExp extends PExp
{
    private TName _name_;
    private final LinkedList _exp_ = new TypedLinkedList(new Exp_Cast());

    public ACallExp ()
    {
    }

    public ACallExp (
            TName _name_,
            List _exp_
    )
    {
        setName (_name_);
        this._exp_.clear();
        this._exp_.addAll(_exp_);
    }

    public Object clone()
    {
        return new ACallExp (
            (TName)cloneNode (_name_),
            cloneList (_exp_)
        );
    }

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

    public TName getName ()
    {
        return _name_;
    }

    public void setName (TName node)
    {
        if(_name_ != null)
        {
            _name_.parent(null);
        }

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

            node.parent(this);
        }

        _name_ = node;
    }
    public LinkedList getExp ()
    {
        return _exp_;
    }

    public void setExp (List list)
    {
        _exp_.clear();
        _exp_.addAll(list);
    }

    public String toString()
    {
        return ""
            + toString (_name_)
            + toString (_exp_)
        ;
    }

    void removeChild(Node child)
    {
        if ( _name_ == child )
        {
            _name_ = null;
            return;
        }
        if ( _exp_.remove(child))
        {
            return;
        }
    }

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

                i.remove();
                oldChild.parent(null);
                return;
            }
        }
    }

    private class Exp_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PExp node = (PExp) o;

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

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

            return node;
        }
    }
}
