/* SCCS - @(#)Patch.java 1.1 - 06/05/00 - 14:15:08 */ /* * Copyright (c) 1997 USC Brain Project. email nsl@java.usc.edu. */ package patch.src.util; import java.io.*; import java.util.*; import patch.src.*; import pp.src.jbf.*; public class Patch { public Patch () { // class_var_scope = cur_var_scope = new Vector(); cur_var_scope = new Vector(); var_scope = new Stack(); // wholebuffer = null; } /** Declare new class of the current file */ public void startClass(YYtoken curC, YYtoken bClass) throws FileNotFoundException { // Parse the base Class first and push the var in higher scope String curClass = cur_class = curC.text; FileInputStream fin = new FileInputStream(bClass.text+".tmp"); yybl = new YYlex(fin); yybp = new YYparse(yybl); try { yybl.init(this); yybp.init(this); yybp.yyparse(); } catch (Exception e) { System.err.println("!!! exception detected:" + e.getMessage()); e.printStackTrace(); System.err.println(cur_class); System.err.println("*** CAN NOT PARSE TMP FILE ! *** \n"); System.exit(0); } cur_class = curClass; pushScope(); } public void endClass() { // Just prints out the variables in scope Stack tmp_stack; Vector scope; Enumeration E = cur_var_scope.elements(); FormalNode ttmp; // scan the current scope while (E.hasMoreElements()) { ttmp = (FormalNode)E.nextElement(); System.err.println(ttmp.code0); // System.err.println(ttmp.type.text); } // scan outer scope tmp_stack = new Stack(); while (!var_scope.empty()) { E = ((Vector)var_scope.peek()).elements(); while (E.hasMoreElements()) { ttmp = (FormalNode)E.nextElement(); System.err.println(ttmp.code0); // System.err.println(ttmp.type.text); } // not found in this scope tmp_stack.push(var_scope.pop()); } // not found any scope restoreScope(tmp_stack); } public void addLocalVar(FormalNode n) { //System.out.println("Add variable "+n.text); cur_var_scope.addElement(n); } private void restoreScope(Stack tmp) { try { while(!tmp.empty()) { var_scope.push(tmp.pop()); } } catch (EmptyStackException e) { System.err.println("System internal error: Patch"); throw e; } } public void pushScope() { if(cur_var_scope!=null) var_scope.push(cur_var_scope); cur_var_scope = new Vector(10,10); //System.out.println("Push ........................................"); } public void popScope() { try { cur_var_scope.removeAllElements(); cur_var_scope = (Vector) var_scope.pop(); //System.out.println("Pull ........................................"); } catch(EmptyStackException e) { System.err.println("Patch.java: pop empty scope at popScope()"); throw e; } } Vector cur_var_scope; Stack var_scope; public String cur_class; YYlex yybl; YYparse yybp; public void genCode() { // printout the var stack } }