package pp.s1184725.boppi;

import pp.iloc.eval.Machine;

/**
 * The (->) type. Takes exactly two types as arguments.
 */
public class FunctionType implements Type {
	private Type argument, result;
	private int localDataSize;

	/**
	 * Creates a new function type from the given parameter and return types.
	 * 
	 * @param returnType
	 *            the result type when applying an argument to the function
	 * @param parameter
	 *            the input type for this function type
	 */
	public FunctionType(Type returnType, Type parameter) {
		result = returnType;
		argument = parameter;
	}

	@Override
	public int getSize() {
		return Machine.INT_SIZE;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof FunctionType))
			return false;

		FunctionType other = (FunctionType) obj;
		return result.equals(other.result) && argument.equals(other.argument);
	}

	@Override
	public String toString() {
		return argument.toString() + "->" + result.toString();
	}

	/**
	 * Sets the size (in bytes) of the local data segment for this function.
	 * 
	 * @param newSize
	 *            the size (in bytes) of the local data segment
	 */
	public void setLocalDataSize(int newSize) {
		localDataSize = newSize;
	}

	/**
	 * Returns the size (in bytes) of the local data segment for this function.
	 * 
	 * @return the size (in bytes) of the local data segment
	 */
	public int getLocalDataSize() {
		return localDataSize;
	}

	/**
	 * Returns the result type of this function.
	 * 
	 * @return the result type
	 */
	public Type getReturn() {
		return result;
	}

	/**
	 * Returns the parameter type of this function.
	 * 
	 * @return the parameter type
	 */
	public Type getParameter() {
		return argument;
	}
}
