// Mike Maxim
// Environment class

package edu.cmu.cs.l3.semant;

import edu.cmu.cs.l3.symbol.*;

public class Environment {

    public static final int VALUE=0,TYPE=1,PROCEDURE=2,MAXTABLES=3;

    public Environment() {
	m_env = new SymbolTable[MAXTABLES];
	m_env[VALUE] = new SymbolTable();
	m_env[TYPE] = new SymbolTable();
	m_env[PROCEDURE] = new SymbolTable();
    }

    public void addEntry(Symbol name, Ty type, int env) throws SymbolTableException {
	m_env[env].put(name,type);
    }

    public Ty getEntry(Symbol name, int env) {
	return (Ty)m_env[env].get(name);
    }

    public void beginScope() {
        int i;
        for (i = 0; i < MAXTABLES; i++) {
            m_env[i].beginScope();
        }
    }

    public void endScope() {
        int i;
        for (i = 0; i < MAXTABLES; i++) {
            m_env[i].endScope();
        }
    }

    public void removeEntry(Symbol name, int env, boolean fromAll) {
	m_env[env].remove(name,fromAll);
    }

    public String toString() {
	String str="";
	int i;
	for (i = 0; i < MAXTABLES; i++) {
	    str += m_env[i].toString() + "\n";
	}
	return str;
    }

    private SymbolTable[] m_env;
}