/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of SableCC.                             *
 * See the file "LICENSE" for copyright information and the  *
 * terms and conditions for copying, distribution and        *
 * modification of SableCC.                                  *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

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

package $0$node;

import $0$analysis.Analysis;

public final class Start extends Node
{
    private $1$ _$2$_;
    private EOF _eof_;

    public Start()
    {}

    public Start(
        $1$ _$2$_,
        EOF _eof_)
    {
        set$1$(_$2$_);
        setEOF(_eof_);
    }

    @Override
    public Start clone()
    {
        Start cloned = new Start();
        cloned.set$1$(cloneNode(this._$2$_));
        cloned.setEOF(cloneNode(this._eof_));
        cloned.initSourcePositionsFrom(this);
        return cloned;
    }

    @Override
    public void apply(Switch sw)
    {
        ((Analysis) sw).caseStart(this);
    }

    public $1$ get$1$()
    {
        return this._$2$_;
    }

    public void set$1$($1$ node)
    {
        if(this._$2$_ != null)
        {
            this._$2$_.parent(null);
        }

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

            node.parent(this);
        }

        this._$2$_ = node;
    }

    public EOF getEOF()
    {
        return this._eof_;
    }

    public void setEOF(EOF node)
    {
        if(this._eof_ != null)
        {
            this._eof_.parent(null);
        }

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

            node.parent(this);
        }

        this._eof_ = node;
    }

    @Override
    void removeChild(Node child)
    {
        if(this._$2$_ == child)
        {
            this._$2$_ = null;
            return;
        }

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

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

    @Override
    void replaceChild(Node oldChild, Node newChild)
    {
        if(this._$2$_ == oldChild)
        {
            set$1$(($1$) newChild);
            return;
        }

        if(this._eof_ == oldChild)
        {
            setEOF((EOF) newChild);
            return;
        }

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

    @Override
    public String toString()
    {
        return "" +
            toString(this._$2$_) +
            toString(this._eof_);
    }
}

$

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

package $0$node;

import $0$analysis.Analysis;

public final class EOF extends Token
{
    public EOF()
    {
        super("");
    }

    public EOF(int line, int pos)
    {
        super("", line, pos);
    }

    @Override
    public EOF clone()
    {
        EOF cloned = new EOF(this.getLine(), this.getPos());
        cloned.initSourcePositionsFrom(this);
        return cloned;
    }

    @Override
    public void apply(Switch sw)
    {
        ((Analysis) sw).caseEOF(this);
    }
}

$

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

package $0$node;

import de.hhu.stups.sablecc.patch.IToken;
import de.hhu.stups.sablecc.patch.SourcePosition;

public abstract class Token extends Node implements IToken
{
    private String text;
    private int line;
    private int pos;

    protected Token(String text, int line, int pos)
    {
        this.text = text;
        this.line = line;
        this.pos = pos;
    }

    protected Token(String text)
    {
        this(text, 0, 0);
    }

    @Override
    public abstract Token clone();

    @Override
    public String getText()
    {
        return this.text;
    }

    @Override
    public void setText(String text)
    {
        this.text = text;
        // Invalidate any already calculated SourcePositions
        setStartPos(null);
        setEndPos(null);
    }

    @Override
    public int getLine()
    {
        return this.line;
    }

    @Override
    public void setLine(int line)
    {
        this.line = line;
        // Invalidate any already calculated SourcePositions
        setStartPos(null);
        setEndPos(null);
    }

    @Override
    public int getPos()
    {
        return this.pos;
    }

    @Override
    public void setPos(int pos)
    {
        this.pos = pos;
        // Invalidate any already calculated SourcePositions
        setStartPos(null);
        setEndPos(null);
    }

    // startPos and endPos are calculated lazily to avoid creating two SourcePosition objects for every token.

    @Override
    public SourcePosition getStartPos()
    {
        SourcePosition startPos = super.getStartPos();
        if(startPos == null)
        {
            startPos = new SourcePosition(this.line, this.pos);
            setStartPos(startPos);
        }
        return startPos;
    }

    @Override
    public SourcePosition getEndPos()
    {
        SourcePosition endPos = super.getEndPos();
        if(endPos == null)
        {
            endPos = new SourcePosition(this.line, this.pos + (this.text == null ? 0 : this.text.length()));
            setEndPos(endPos);
        }
        return endPos;
    }

    @Override
    public String toString()
    {
        return this.text + " ";
    }

    @Override
    void removeChild(Node child)
    {
        throw new RuntimeException("Not a child.");
    }

    @Override
    void replaceChild(Node oldChild, Node newChild)
    {
        throw new RuntimeException("Not a child.");
    }
}

$

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

package $0$node;

import java.util.LinkedList;
import java.util.List;

import de.hhu.stups.sablecc.patch.PositionedNode;

public abstract class Node extends PositionedNode implements Switchable, Cloneable
{
    private Node parent;

    protected Node()
    {}

    // clone intentionally does not keep parent!
    // The new copied node is not a child of the original parent anymore.
    @Override
    public abstract Node clone();

    public Node parent()
    {
        return this.parent;
    }

    void parent(Node parent)
    {
        this.parent = parent;
    }

    abstract void removeChild(Node child);
    abstract void replaceChild(Node oldChild, Node newChild);

    public void replaceBy(Node node)
    {
        this.parent.replaceChild(this, node);
    }

    protected static String toString(Node node)
    {
        if(node != null)
        {
            return node.toString();
        }

        return "";
    }

    protected static String toString(List<?> list)
    {
        StringBuilder s = new StringBuilder();

        for(Object o : list)
        {
            s.append(o);
        }

        return s.toString();
    }

    @SuppressWarnings("unchecked")
    protected static <T extends Node> T cloneNode(T node)
    {
        if(node != null)
        {
            return (T) node.clone();
        }

        return null;
    }

    @SuppressWarnings("unchecked")
    protected static <T extends Node> List<T> cloneList(List<T> list)
    {
        List<T> clone = new LinkedList<T>();

        for(T n : list)
        {
            clone.add((T) n.clone());
        }

        return clone;
    }
}

$

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

package $0$node;

public interface Switch
{}

$

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

package $0$node;

public interface Switchable
{
    void apply(Switch sw);
}

$
