// Mike Maxim
// Absyn for dec lists

package edu.cmu.cs.l3.absyn;

import java.util.*;

public class ASDeclarationList extends ASDeclaration {

    public ASDeclarationList(int p) {
	super(p);
	m_classname = "ASDeclarationList";
    }
    public ASDeclarationList(int p, ASDeclaration d) {
	super(p);
	m_decs.addElement(d);

	m_classname = "ASDeclarationList";
    }

    public ASDeclaration getDeclaration(int index) {
	return (ASDeclaration)m_decs.elementAt(index);
    }

    public int getSize() {
	return m_decs.size();
    }

    public void setType(ASType type) {
	int i;
	for (i = 0; i < m_decs.size(); i++) {
	    ((ASDeclaration)m_decs.get(i)).getTypeInfo().setASType(type);
	}
    }

    public ASDeclarationList prepend(ASDeclaration d) {

	int i;
	ASDeclarationList dl = new ASDeclarationList(d.getPosition());

	dl.m_decs.addElement(d);
	for (i = 0; i < m_decs.size(); i++)
	    dl.m_decs.addElement(m_decs.elementAt(i));

	return dl;
    }

    public ASDeclarationList join(ASDeclarationList d) {

	int i;
	ASDeclarationList dl = new ASDeclarationList(m_pos);

	for (i = 0; i < m_decs.size(); i++)
	    dl.m_decs.addElement(m_decs.elementAt(i));

	for (i = 0; i < d.m_decs.size(); i++)
	    dl.m_decs.addElement(d.m_decs.elementAt(i));

	return dl;
    }

    public ASDeclarationList removeFront() {

	int i;
	ASDeclarationList dl = new ASDeclarationList(m_pos);

	for (i = 1; i < m_decs.size(); i++)
	    dl.m_decs.addElement(m_decs.elementAt(i));

	return dl;
    }

    public String toString() {

	int i;
	String composite="";

	for (i = 0; i < m_decs.size(); i++)
	    composite += m_decs.elementAt(i).toString() + " ";

	return composite;
    }

    private Vector m_decs = new Vector();
}
