/* SCCS - @(#)MethodNode.java 1.6 - 08/31/99 - 19:30:59 */ /* * Copyright (c) 1997 USC Brain Project. email nsl@java.usc.edu. */ package npp.src.util; import java.util.Enumeration; import pp.src.jbf.*; public class MethodNode extends YYtoken{ private static boolean use_parameter_passing = true; //98/7/30 aa: took out lower case calls : makeconn //98/7/30 aa: changed CallFromConstructor to callFromConstructor //98/7/30 aa: Added allFromConstructorBottom //98/7/30 aa: Added callFromConstructorTop //98/7/30 aa: change CALLFROMCONST to CALLFROMCONSTR //98/7/30 aa: add CALLFROMCONSTRBOTTOM //98/7/30 aa: add CALLFROMCONSTRTOP public MethodNode(FormalNode node) { super(node.tokentype, node.text, node.lineno, node.charno, node.charno0); signature = node; if (signature.text.equals("makeInst")) method_type = MAKEINST; else if (signature.text.equals("makeConn")) method_type = MAKECONN; else if (signature.text.equals("initSys")) method_type = INITSYS; else if (signature.text.equals("simRun")) method_type = SIMRUN; else if (signature.text.equals("initRun")) method_type = INITRUN; else if (signature.text.equals("initModule")) method_type = INITMODULE; else if (signature.text.equals("initTrain")) method_type = INITTRAIN; else if (signature.text.equals("endRun") ) method_type = ENDRUN; else if (signature.text.equals("endSys")) method_type = ENDSYS; else if (signature.text.equals("create")) // should not happen method_type = CREATE; else if (signature.text.equals("callFromConstructor")) method_type = CALLFROMCONSTR; else if (signature.text.equals("callFromConstructorBottom")) method_type = CALLFROMCONSTRBOTTOM; else if (signature.text.equals("callFromConstructorTop")) method_type = CALLFROMCONSTRTOP; else if (signature.text.equals("simTrain")) method_type = SIMTRAIN; else if (signature.text.equals("endTrain")) method_type = ENDTRAIN; else if (signature.text.equals("endModule")) method_type = ENDMODULE; else if (signature.text.equals("initTrainEpoch")) method_type = INITTRAINEPOCH; else if (signature.text.equals("initRunEpoch")) method_type = INITRUNEPOCH; else method_type = UNKNOWN; } public void makeInstSpecialProcess(npp.src.util.NslPreProcessor npp) { if (method_type == MAKEINST && params!= null) { plist = new StringBuffer(1024); ptype = new StringBuffer(1024); pinit = new StringBuffer(2048); Enumeration E = params.list.elements(); FormalNode fn; while(E.hasMoreElements()) { fn = (FormalNode)E.nextElement(); plist.append(", "+fn.text); ptype.append(", "+fn.type.text+" "+fn.text); pinit.append("\tthis."+fn.text+" = "+fn.text+";\n"); npp.addMakeInstDeclStmt("\t"+fn.type.text+" "+fn.text+" ;"+"/* for makeinst() args */ ", fn); } } } String genConstructor(String module_name) { if(method_type != MAKEINST) return ""; StringBuffer strbuf = new StringBuffer(4096); /* StringBuffer plist = new StringBuffer(1024); StringBuffer ptype = new StringBuffer(1024); StringBuffer pinit = new StringBuffer(2048); */ // Enumeration E; strbuf.append("\t/* constructor and related methods */\n"); // default constructor method strbuf.append("\tpublic "+module_name+"() {\n"); strbuf.append("\t\tsuper();\n"); strbuf.append("\t\tif (NslMain.TopLoaded) { System.err.println(\n"); strbuf.append("\t\t \"ERROR: construction without (name,parent)\");\n"); strbuf.append("\t\t System.exit(1);} \n"); strbuf.append("\t\t NslMain.TopLoaded=true; \n"); strbuf.append("\t\tsetParams(\""+module_name+"\",null);\n"); strbuf.append("\t\tmakeInst();\n\t"); strbuf.append("\t/* this constructor must be called ONLY by Top level*/\n\t}\n"); // constructor with parameter input // default parameter actions strbuf.append("\t"+ module_name+ "(String childinstname, NslModule parentinst"); if (params!= null) { Enumeration E = params.list.elements(); /* FormalNode fn; while(E.hasMoreElements()) { fn = (FormalNode)E.nextElement(); plist.append(", "+fn.text); ptype.append(", "+fn.type.text+" "+fn.text); pinit.append("\tthis."+fn.text+" = "+fn.text+";\n"); npp.addMakeInstDeclStmt(fn.type.text+" "+fn.text, fn); } */ strbuf.append(ptype); } strbuf.append(") {\n"); strbuf.append("\t\tsuper();\n"); strbuf.append("\t\tsetParams(childinstname, parentinst"); if(params!= null) { strbuf.append(plist); } strbuf.append(");\n"); if(use_parameter_passing) { // new! for local makeinst calling, instead from // parent constructor strbuf.append("\t\tmakeInst("); if(params!=null) { strbuf.append(plist.toString().substring(1)); } strbuf.append(");\n"); //ERH: commented out // strbuf.append("\tif (parentinst != null)\n\t\tparentinst.addModule((NslModule)this);\n"); } strbuf.append("\t}\n"); /* strbuf.append("\tprivate "+module_name+ " setParams(String instancename, NslModule parent"); */ strbuf.append("\tpublic void setParams(String instancename, NslModule parentinst"); if(params != null) { strbuf.append(ptype); } strbuf.append(")\n\t{\n"); strbuf.append("\tsuper.setParams(instancename, parentinst);\n\t"); if(params != null) { strbuf.append(pinit); } strbuf.append("\t}\n\n"); return strbuf.toString(); } /* boolean isMakeInst() { return signature.text.equals("makeinst") || signature.text.equals("makeInst"); } boolean isMakeConn() { return signature.text.equals("makeconn") || signature.text.equals("makeConn"); } boolean isInit() { return signature.text.equals("initRun"); } boolean isExecute() { return signature.text.equals("simRun") ; } boolean isFinalPrint() { return signature.text.equals("finalprint"); } */ void setParams(ParamsNode pn) { // check name uniqueness!!! params = pn; } void setEndToken(YYtoken end_token) { this.end_token = end_token; } public static int NONE = 0; public static int CONSTRUCTOR = 1; public static int MAKEINST = 2; public static int MAKECONN = 3; public static int INITSYS = 4; public static int RUNSIM = 5; public static int ENDSYS = 6; public static int CREATE = 7; public static int INITRUN = 8; public static int ENDRUN = 9; public static int CALLFROMCONSTR = 10; public static int CALLFROMCONSTRBOTTOM = 11; public static int CALLFROMCONSTRTOP = 12; public static int INITMODULE = 13; public static int INITTRAIN = 14; public static int ENDMODULE = 15; public static int SIMTRAIN = 16; public static int ENDTRAIN = 17; public static int SIMRUN = 18; public static int INITRUNEPOCH = 19; public static int INITTRAINEPOCH = 20; public static int UNKNOWN = 100; public static int MIN_METHOD_TYPE = 1; public static int MAX_METHOD_TYPE = 18; StringBuffer plist; StringBuffer ptype; StringBuffer pinit; public FormalNode signature; public int method_type; public ParamsNode params; YYtoken end_token; }