package pp.s1184725.boppi.symboltable;

import pp.s1184725.boppi.exception.*;
import pp.s1184725.boppi.type.*;

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

	@Override
	public FunctionScope<T> closeFunctionScope() throws NoProgramException {
		System.out.println(this.getClass().getName() + ": leaving scope depth " + functionScope.size());
		return super.closeFunctionScope();
	}

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

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

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

}
