ContextoExecucaoImperativa2.java

Go to the documentation of this file.
00001 package plp.imperative2.memory;
00002 
00003 import java.util.HashMap;
00004 import java.util.Stack;
00005 
00006 import plp.expressions2.expression.Id;
00007 import plp.imperative1.memory.ContextoExecucaoImperativa;
00008 import plp.imperative1.memory.ListaValor;
00009 
00010 public class ContextoExecucaoImperativa2 extends ContextoExecucaoImperativa
00011                 implements AmbienteExecucaoImperativa2 {
00012 
00016         private Stack<HashMap<Id, Procedimento>> pilhaProcedimento;
00017 
00021         private ListaValor entrada;
00022 
00026         private ListaValor saida;
00027 
00031         public ContextoExecucaoImperativa2(ListaValor entrada) {
00032                 super(entrada);
00033                 pilhaProcedimento = new Stack<HashMap<Id, Procedimento>>();
00034         }
00035 
00036         public void incrementa() {
00037                 super.incrementa();
00038                 pilhaProcedimento.push(new HashMap<Id, Procedimento>());
00039         }
00040 
00041         public void restaura() {
00042                 super.restaura();
00043                 pilhaProcedimento.pop();
00044         }
00045 
00052         public void mapProcedimento(Id idArg, Procedimento procedimentoId)
00053                         throws ProcedimentoJaDeclaradoException {
00054 
00055                 HashMap<Id, Procedimento> aux = pilhaProcedimento.peek();
00056                 if (aux.put(idArg, procedimentoId) != null) {
00057                         throw new ProcedimentoJaDeclaradoException(idArg);
00058                 }
00059 
00060         }
00061 
00069         public Procedimento getProcedimento(Id idArg)
00070                         throws ProcedimentoNaoDeclaradoException {
00071                 Procedimento result = null;
00072                 Stack<HashMap<Id, Procedimento>> auxStack = new Stack<HashMap<Id, Procedimento>>();
00073                 while (result == null && !pilhaProcedimento.empty()) {
00074                         HashMap<Id, Procedimento> aux = pilhaProcedimento.pop();
00075                         auxStack.push(aux);
00076                         result = aux.get(idArg);
00077                 }
00078                 while (!auxStack.empty()) {
00079                         pilhaProcedimento.push(auxStack.pop());
00080                 }
00081                 if (result == null) {
00082                         throw new ProcedimentoNaoDeclaradoException(idArg);
00083                 }
00084 
00085                 return result;
00086         }
00087 }

Generated on Wed Jul 19 19:07:51 2006 for PLP by  doxygen 1.4.7