DereferenceExpression.java

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

import edu.udel.cis.vsl.tass.model.IF.ModelFactoryIF;
import edu.udel.cis.vsl.tass.model.IF.SyntaxException;
import edu.udel.cis.vsl.tass.model.IF.expression.DereferenceExpressionIF;
import edu.udel.cis.vsl.tass.model.IF.type.PointerTypeIF;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF;
import edu.udel.cis.vsl.tass.model.IF.type.TypeIF.TypeKind;

public class DereferenceExpression extends UnaryExpression implements
		DereferenceExpressionIF {

	public DereferenceExpression(ModelFactoryIF factory, Expression argument)
			throws SyntaxException {
		super(factory, ExpressionKind.DEREFERENCE, (Expression) argument);
		TypeIF argumentType = argument.type();

		if (argumentType.kind() != TypeKind.POINTER)
			throw new SyntaxException(argument,
					"Argument to dereference operator does not have pointer type: "
							+ argumentType);
		type = ((PointerTypeIF) argumentType).baseType();
	}

	public String atomString() {
		return toString();
	}

	public String toString() {
		return "*" + expression.atomString();
	}

}