ContextoCompilacaoImperativa2.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.ContextoCompilacaoImperativa;
00008 import plp.imperative1.memory.ListaValor;
00009 import plp.imperative2.declaration.ListaDeclaracaoParametro;
00010 
00011 public class ContextoCompilacaoImperativa2 extends ContextoCompilacaoImperativa
00012                 implements AmbienteCompilacaoImperativa2 {
00013 
00017         private Stack<HashMap<Id, ListaDeclaracaoParametro>> pilhaParametrosProcedimento;
00018 
00022         public ContextoCompilacaoImperativa2(ListaValor entrada) {
00023                 super(entrada);
00024                 pilhaParametrosProcedimento = new Stack<HashMap<Id, ListaDeclaracaoParametro>>();
00025         }
00026 
00027         public void incrementa() {
00028                 super.incrementa();
00029                 pilhaParametrosProcedimento
00030                                 .push(new HashMap<Id, ListaDeclaracaoParametro>());
00031         }
00032 
00033         public void restaura() {
00034                 super.restaura();
00035                 pilhaParametrosProcedimento.pop();
00036         }
00037 
00038         public void mapParametrosProcedimento(Id idArg,
00039                         ListaDeclaracaoParametro parametrosId)
00040                         throws ProcedimentoJaDeclaradoException {
00041                 HashMap<Id, ListaDeclaracaoParametro> aux = pilhaParametrosProcedimento
00042                                 .peek();
00043                 if (aux.put(idArg, parametrosId) != null) {
00044                         throw new ProcedimentoJaDeclaradoException(idArg);
00045                 }
00046         }
00047 
00048         public ListaDeclaracaoParametro getParametrosProcedimento(Id idArg)
00049                         throws ProcedimentoNaoDeclaradoException {
00050                 ListaDeclaracaoParametro result = null;
00051                 Stack<HashMap<Id, ListaDeclaracaoParametro>> auxStack = new Stack<HashMap<Id, ListaDeclaracaoParametro>>();
00052                 while (result == null && !pilhaParametrosProcedimento.empty()) {
00053                         HashMap<Id, ListaDeclaracaoParametro> aux = pilhaParametrosProcedimento
00054                                         .pop();
00055                         auxStack.push(aux);
00056                         result = aux.get(idArg);
00057                 }
00058                 while (!auxStack.empty()) {
00059                         pilhaParametrosProcedimento.push(auxStack.pop());
00060                 }
00061                 if (result == null) {
00062                         throw new ProcedimentoNaoDeclaradoException(idArg);
00063                 }
00064 
00065                 return result;
00066 
00067         }
00068 
00069 }

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