IntegerTypeNode.java

package edu.udel.cis.vsl.tass.ast.impl.type;

import java.io.PrintWriter;
import java.util.NoSuchElementException;

import edu.udel.cis.vsl.tass.ast.IF.ASTNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.type.IntegerTypeNodeIF;
import edu.udel.cis.vsl.tass.ast.impl.ASTNode;

public class IntegerTypeNode extends ASTNode implements IntegerTypeNodeIF {

	private boolean signed;
	private IntType intType;
	
	public IntegerTypeNode(long id) {
		super(id);
	}
	
	public IntegerTypeNode(long id, boolean signed, IntType intType) {
		super(id);
		this.signed = signed;
		this.intType = intType;
	}

	@Override
	public int numChildren() {
		return 0;
	}

	@Override
	public ASTNodeIF child(int index) throws NoSuchElementException{
		throw new NoSuchElementException("Node " + id()
				+ " does not have a child with index " + index + ".");
	}

	@Override
	public void setChild(int i, ASTNodeIF child) throws NoSuchElementException {
		throw new NoSuchElementException("Node " + id()
				+ " does not have a child with index " + i + ".");
	}

	@Override
	public String toString() {
		String result;
		if (signed)
			result = "Signed ";
		else
			result = "Unsigned ";
		result += intType.toString();
		return result;
	}
	
	@Override
	public void print(String prefix, PrintWriter out) {
		out.println(prefix + " AST Node " + id() + ", " + toString());
	}

	@Override
	public IntType intType() {
		return intType;
	}

	@Override
	public boolean isSigned() {
		return signed;
	}

	@Override
	public void setIntType(IntType type) {
		this.intType = type;
	}

	@Override
	public void setSigned(boolean signed) {
		this.signed = signed;
	}

}