package code.term;

import code.instr.Instruction;
import code.symbols.ConstructorSymbol;
import code.symbols.DataSymbol;
import code.term.visitor.ToStringTermVisitor;

/**
 * Term representation for built in terms (eg ints, chars, ect).
 *
 * @author Sergio Antoy
 * @since June 17, 2003
 */
public abstract class TermImplBuiltin implements TermImpl {

    /*
     * Exceptions thrown by the TermImplBuiltin
     */
    private final static IllegalStateException argException
            = new IllegalStateException("No argument of builtin type");


    /**
     * Creates a new TepmImplBuiltin.
     */
    protected TermImplBuiltin() {
    }

    /**
     * Returns the root symbol of this term.
     *
     * @return The rootSymbol value
     */
    public String getRootSymbol() {
        return (String) accept(ToStringTermVisitor.singleton, null);
    }

    /**
     * Returns the root id of this term.
     *
     * @return The root value
     */
    public int getRoot() {
        return DataSymbol.Constructor;
    }


    /**
     * Gets the argument attribute of the TermImplBuiltin object
     *
     * @return The argument value
     */
    public Term[] getArgument() {
        return new Term[0];
    }


    /**
     * Throws the argument exception since
     * built ins do not have arguments
     *
     * @param number Description of the Parameter
     * @return The argument value
     */
    public Term getArgument(byte number) {
        throw argException;
    }


    /**
     * Returns the kind of this term.
     *
     * @return The kind value
     */
    public byte getKind() {
        return DataSymbol.Constructor;
    }


    /**
     * Returns true since all builtins are in
     * head normal form.
     *
     * @return The hNF value
     */
    public boolean isHNF() {
        return true;
    }


    /**
     * Returns true since all builtins are in
     * normal form.
     *
     * @return The nF value
     */
    public boolean isNF() {
        return true;
    }


    /**
     * This is no code for rewritting builtins
     * so this returns an empty list.
     *
     * @return The code value
     */
    public Instruction[] getCode() {
        return ConstructorSymbol.noCode;
    }
    
}

