ASTTypeCast.java

package edu.udel.cis.vsl.tass.front.minimp.ast.expression;

import edu.udel.cis.vsl.tass.front.minimp.ast.type.ASTTypeIF;
import edu.udel.cis.vsl.tass.util.Source;
/**
 * Represents a typecast expression.
 * @author Ben Perry
 */
public class ASTTypeCast implements ASTExpressionIF{
	/** Source location */
	private Source source;
	
	/** Source text at the location */
	private String text;

	/** Underlying expression being typecasted. */
	private ASTExpressionIF expression;

	/** The type being cast to. */
	private ASTTypeIF type;
	
	/** Empty constructor */
	public ASTTypeCast(){}
	
	/**
	 * Creates the typecast using the given expression and new type.
	 * @param anExpression - the expression to type-cast.
	 * @param aNewType - the new type of the expression.
	 */
	public ASTTypeCast(ASTExpressionIF anExpression, ASTTypeIF aNewType){
		expression = anExpression;
		type = aNewType;
	}

	@Override
	public ASTTypeIF getType() {
		return type;
	}

	@Override
	public void setSource(Source source) {
		this.source = source;
	}

	@Override
	public void setText(String text) {
		this.text= text;
	}

	@Override
	public Source getSource() {
		return this.source;
	}
	
	public String toString(){return text;}
	
	/**
	 * Sets the type that this cast will be cast to.
	 * @param type - the new type.
	 */
	public void setType(ASTTypeIF type){
		this.type = type;
	}
	
	/**
	 * Gets the underlying expression being typecasted.
	 * @return ExpressionIF - the expression
	 */
	public ASTExpressionIF getExpression(){return this.expression;}
	
	/**
	 * Sets the underlying expression being typecasted.
	 * @param anExpression - the expression being typecasted.
	 */
	public void setExpression(ASTExpressionIF anExpression){
		expression = anExpression;
	}

}