public PGValue visit(NodeListOptional n, Node argu) { ParamList_pg pl = new ParamList_pg(); if (n.present()) { PGValue _ret = null; int _count = 0; for (Enumeration<Node> e = n.elements(); e.hasMoreElements(); ) { PGValue p = (PGValue) e.nextElement().accept(this, argu); if (p != null) pl.Insert(p); _count++; } return pl; } else return null; }
/** f0 -> "MAIN" f1 -> StmtList() f2 -> "END" f3 -> ( Procedure() )* f4 -> <EOF> */ public PGValue visit(Goal n, Node argu) { PGValue _ret = null; ParamList_pg pl; n.f0.accept(this, argu); if (met_name.equals("MAIN")) { // System.out.println("MAIN"); n.f1.accept(this, n.f1); return null; } n.f2.accept(this, argu); pl = (ParamList_pg) n.f3.accept(this, argu); n.f4.accept(this, argu); return pl.GetFirst(); }
/** f0 -> "CALL" f1 -> Exp() f2 -> "(" f3 -> ( Exp() )* f4 -> ")" */ public PGValue visit(Call n, Node argu) { // NOTE: bug fix by jurgens@cs 10/30/07, kgo@cs 11/14/07 // // details: local_arg_size was previously initialized to 20. // This resulted in TEMP values being overwritten by the caller. // For recursive calls, the overwritten values were bugs if any // thing stored in an overwritten temp was used after the // recursive call. For this reason, we now make a copy of the // entire temp space before each call. n.f0.accept(this, argu); PGValue function_addr = n.f1.accept(this, argu); if (!(function_addr instanceof Label_pg)) { System.err.println("error in CALL"); System.exit(0); return null; // Will never actually be reached. } String m_name = function_addr.GetLabel(); n.f2.accept(this, argu); // Caller saves all local variables. PGValue[] saved_locals = new PGValue[TPV.length]; System.arraycopy(TPV, 0, saved_locals, 0, TPV.length); // Copy call args into first N temps. ParamList_pg pl = (ParamList_pg) n.f3.accept(this, argu); // NOTE: we save and return the TEMPs for the caller, so we are // free to update the TPV array at this point. kgo@cs fixed a // bug where this statement caused the callee to have TPV // side-effects for the caller. // NOTE: that if the method had no parameters, pl will be null. // This bug was discovered by Prof. Todd Millstein todd@cs. // check to see if the callee has any arguments and if so, pass // them into the TPV temp array using the caller's parameters if (pl != null) { int num_params = pl.GetVal(); PGValue[] param_list = pl.GetList(); for (int i = 0; i < num_params; i++) { TPV[i] = param_list[i]; } } n.f4.accept(this, argu); met_name = m_name; boolean old_start = start; boolean old_stop = stop; start = true; stop = false; // System.out.println("No NO NO 222" + met_name); PGValue _ret = pg_root.accept(this, pg_root); // System.out.println("No NO NO"); start = old_start; stop = old_stop; // Restore saved local variables. TPV = saved_locals; return _ret; }