LengthExpression.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.type.TypeIF.TypeKind;

/**
 * The expression is any expression of array type. For example if a is declared
 * int[2][3][4], then length(a)=2, length(a[1])=3, length(a[0][3])=4.
 * 
 * @author siegel
 * 
 */
public class LengthExpression extends UnaryExpression {

	public LengthExpression(ModelFactoryIF factory, Expression expression)
			throws SyntaxException {
		super(factory, ExpressionKind.LENGTH, expression);

		if (expression.type.kind() != TypeKind.ARRAY) {
			throw new SyntaxException(expression,
					"length requires array argument");
		}
		type = factory.integerType();
	}

	public String toString() {
		return "length(" + expression + ")";
	}

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