package pp.s1184725.boppi;

/**
 * This class tracks a variable's properties. It is agnostic of the type system
 * used. The type reference and offset are immutable.
 *
 * @param <T>
 *            the typing class
 */
public class Variable<T> {
	private final T type;
	private final int depth;
	private final int offset;

	/**
	 * Creates a variable with the given type instance and memory offset.
	 * 
	 * @param type
	 *            the type of the variable
	 * @param depth
	 *            the lexical depth of this variable
	 * @param offset
	 *            the memory offset for this variable
	 */
	public Variable(T type, int depth, int offset) {
		this.type = type;
		this.depth = depth;
		this.offset = offset;
	}

	/**
	 * Gets the type of this variable instance.
	 * 
	 * @return the type
	 */
	public T getType() {
		return type;
	}

	/**
	 * Gets the local data offset of this variable instance.
	 * 
	 * @return the offset
	 */
	public int getOffset() {
		return offset;
	}

	/**
	 * Gets the lexical depth of this variable instance.
	 * 
	 * @return the depth
	 */
	public int getDepth() {
		return depth;
	}

	@Override
	public String toString() {
		return String.format("%s:%X@%d", type.toString(), hashCode(), offset);
	}
}
