/* SCCS - @(#)NewNode.java 1.2 - 02/28/99 - 12:39:18 */ /* * Copyright (c) 1997 USC Brain Project. email nsl@java.usc.edu. */ // // NewNode //////////////////////////////////////////////////////////// /** * NewNode - New expression node * new expressions, including the type and argument */ package npp.src.util; import pp.src.jbf.*; public class NewNode extends ExprNode{ private boolean nocode=false; public NewNode(NslCoupleNode node) { //super(node.tokentype, node.text, node.lineno, node.charno, node.charno0); super(node); nocode=true; } public NewNode(TypeNode ttype, ExprsNode tsize, ExprsNode targs) { super(ttype, ttype); lvalue = false; // System.out.println("NewNode: type: "+ttype.text+" code: "+ttype.type +" nsl="+ttype.nslNumeric+" numeric="+ttype.numeric); // super(YYtokentypes.nt_newExpression, ttype.text, ttype.lineno, ttype.charno, ttype.charno0); //System.out.println("ttype text:"+ttype.text); type = ttype; sizes = tsize; args = targs; instance_name = null; } /** * Code generation. * This code is especially for NslNumeric objects. There is no preprocessing on NslModule classes. * @param npp Nsl Preprocessor * @return error value */ public int genCode(NslPreProcessor npp) { java.util.Enumeration E; String str; if (nocode) return SUCCESS; code = "new "+type.text; if (sizes != null) { // array YYtoken t; E= sizes.list.elements(); while(E.hasMoreElements()) { if((t = ((YYtoken)E.nextElement()))!=null) { str = t.text; code += ("["+str+"]"); } } } else { // object //System.out.println("TYPE:"+ type.text); if (type.nslPort) { //System.out.println("YEP!!"); code += "(this,"; processed = true; // WARNING: needs further checking!! } else code += "("; /* optional statement that add default instance name */ if (instance_name != null) { code += ("\""+instance_name+"\""); processed = true; } if (args != null) { ExprNode e; E = args.list.elements(); if (instance_name == null && E.hasMoreElements()) { e = ((ExprNode)E.nextElement()); e.genCode(npp); if (e.processed) processed = true; str = e.code; code += str; } while(E.hasMoreElements()) { e = ((ExprNode)E.nextElement()); e.genCode(npp); if(e.processed) processed = true; str = e.code; code += (","+str); } } code += ")"; } //System.out.println("NewNode CodeGen: "+code); return SUCCESS; } /** set default instance name if it is not defined in teh new expression. * @param name name of the instantiated NslNumeric object */ void addInstanceName(String name) { boolean isstring; boolean isnull; ExprNode first=null; // for nsl nnumeric objects only //System.out.print(" // Addding instance name:"+name); /* type.nslNumeric guarantees that only Nslnumerics and NslPorts get their name declared automatically */ // System.err.println("---------> Trying ... "); if (args==null) isnull=true; else { first =(ExprNode)args.list.firstElement(); //if (first==null) isnull=true; else isnull = (first.type == null); } if (isnull) isstring=false; else isstring= (first.type.type== TypeNode.STRING); if (isstring) { if (first.text.equals("\"*\"")) {isstring=false; // System.err.println("---------> GOT *"); args.list.removeElement(first); } } //ERH: 11/20/97, true: need not to restrict to nslNumerics only if ((true || type.nslNumeric) && (args==null || isnull || !isstring )) { processed = true; instance_name = name; //System.err.println("---------> replaced "+ name); //#1 System.out.print(" DONE"); } //#1 else System.out.print(" NOT DONE"); //#1 System.out.println("."); } final public static int NO_OP = 0; final public static int SUCCESS = 1; // public TypeNode type; public ExprsNode sizes; public ExprsNode args; public String instance_name; }