RealLiteralNode.java

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

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.AbstractSyntaxTreeIF;
import edu.udel.cis.vsl.tass.ast.IF.IdentifierNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.expression.RealLiteralNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.type.RealTypeNodeIF;
import edu.udel.cis.vsl.tass.ast.IF.type.TypeNodeIF;
import edu.udel.cis.vsl.tass.number.IF.RationalNumberIF;

public class RealLiteralNode extends LiteralNode implements RealLiteralNodeIF {

	private RealTypeNodeIF type;

	private RationalNumberIF realValue;

	public RealLiteralNode(long id) {
		super(id);
	}
	
	public RealLiteralNode(long id,
						   IdentifierNodeIF mIdentifier,
						   TypeNodeIF mType,
						   RationalNumberIF realValue) {
		super(id,mIdentifier,mType);
		this.realValue = realValue;
	}

	@Override
	public RationalNumberIF realValue() {
		return realValue;
	}
	
	@Override
	public void setRealValue(RationalNumberIF realValue) {
		this.realValue = realValue;
	}

	@Override
	public RealTypeNodeIF type() {
		return type;
	}

	@Override
	public void setType(RealTypeNodeIF type) {
		this.type = type;
	}

	@Override
	@SuppressWarnings("fallthrough")
	public ASTNodeIF child(int index) throws NoSuchElementException {
		switch (index) {
		case 0:
			//Fallthrough
		case 1:
			//Fallthrough
		case 2:
			return super.child(index);
		case 3:
			return type;
		default:
			throw new NoSuchElementException("Node " + id()
					+ " does not have a child with index " + index + ".");
		}
	}

	@Override
	@SuppressWarnings("fallthrough")
	public void setChild(int i, ASTNodeIF child) throws NoSuchElementException {
		switch (i) {
		case 0:
			//Fallthrough
		case 1:
			//Fallthrough
		case 2:
			super.setChild(i,child);
			break;
		case 3:
			type = (RealTypeNodeIF) child;
			break;
		default:
			throw new NoSuchElementException("Node " + id()
					+ " does not have a child with index " + i + ".");
		}
	}

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

	@Override
	protected String nodeType() {
		return "Real Literal Node";
	}

	@Override
	public String toString() {
		return super.toString() + " realValue: " + realValue;
	}

	@Override
	public void toXml(String prefix, PrintWriter out,AbstractSyntaxTreeIF ast) {
		//TODO: Implement
	}
}