package pp.s1184725.boppi;

import java.util.EmptyStackException;

/**
 * Same functionality as {@link CachingSymbolTable} except actions on the table
 * are logged to the console.
 *
 * @param <T>
 *            the typing class
 */
public class DebugCachingSymbolTable<T extends Type> extends CachingSymbolTable<T> {

	@Override
	public void openFunctionScope() {
		super.openFunctionScope();
		System.out.println(this.getClass().getName() + ": entering scope depth " + functionDepth);
	}

	@Override
	public void closeFunctionScope() throws EmptyStackException {
		System.out.println(this.getClass().getName() + ": leaving scope depth " + functionDepth);
		super.closeFunctionScope();
	}

	@Override
	public Variable<T> put(String id, T type) throws Exception, EmptyStackException {
		System.out.println(this.getClass().getName() + ": declaring '" + id + "' (" + type.toString() + ") at scope "
				+ functionDepth);
		return super.put(id, type);
	}

	@Override
	public Variable<T> get(String id) throws Exception, EmptyStackException {
		System.out.println(this.getClass().getName() + ": retrieving '" + id + "' (depth "
				+ symbolCache.get(id).getDepth() + ") at scope " + functionDepth);
		return super.get(id);
	}

}
