/* SCCS - @(#)ExprNode.java 1.2 - 02/28/99 - 12:39:10 */ /* * Copyright (c) 1997 USC Brain Project. email nsl@java.usc.edu. */ // // ExprNode //////////////////////////////////////////////////////////// /** * ExprNode - General expression statement */ package npp.src.util; import java.lang.String; import java.util.Vector; import pp.src.jbf.*; public class ExprNode extends YYtoken{ static final boolean Use_Nsl_As_Temp_Variable = false; public ExprNode(NslCoupleNode node) { super(node.tokentype, node.text, node.lineno, node.charno, node.charno0); nslSymbol=false; } public ExprNode(YYtoken ctype, YYtoken sym) { // well, it is kind of convenience to reuse something in YYtokentypes. super(ctype.tokentype, sym.text, ctype.lineno, ctype.charno-ctype.text.length()+1, ctype.charno0); lvalue = true; processed = false; type = (TypeNode) ctype; code = sym.text; tmp_number = 0; nslSymbol=false; } public ExprNode(ExprNode node) { super(YYtokentypes.nt_expression, node.text, node.lineno, node.charno, node.charno0); lvalue = node.isLvalue(); processed = node.isProcessed(); type =node.type; code = node.text; tmp_number = 0; nslSymbol=false; } public ExprNode(FormalNode node) { super(YYtokentypes.nt_expression, node.text, node.lineno, node.charno, node.charno0); lvalue = node.isLvalue(); processed = false; type = node.type; code = node.text; tmp_number = 0; nslSymbol=false; } /** a token with unknown type */ public ExprNode(YYtoken node) { super(node.tokentype, node.text, node.lineno, node.charno-node.text.length()+1, node.charno0); lvalue = true; processed = false; type = null; // unknown type code = node.text; tmp_number = 0; nslSymbol=false; } /** * Code generation. [default] * @param npp Nsl Preprocessor * @return error value */ public int genCode(NslPreProcessor npp) { if(type==null) { npp.resolveVar(this); } return NO_OP; } /** * Code generation. [LHS default] * @param npp Nsl Preprocessor * @return error value */ public int genCode(NslPreProcessor npp, boolean left_value) { //default method return genCode(npp); } public int getDim() { if (type==null) { return 0; } else { return type.getDim(); } } public void addDim(int i) { type.addDim(i); } public void addDim(YYtoken t) { type.addDim(t); } public void subDim(int i) { type.subDim(i); } public void subDim(YYtoken t) { type.subDim(t); } public void setLvalue(boolean b) { lvalue = b;} public boolean isLvalue() { return lvalue; } public void setProcessed(boolean b) { processed = b;} public boolean isProcessed() { return processed; } /** Generate strings that define the variable size in the first dimension * @param n expression that determine the size * @param npp NslPreProcessor * @return generated string */ String getTempSize1(ExprNode n, NslPreProcessor npp) { if( Use_Nsl_As_Temp_Variable) { if (n.tmp_number>0) { // return npp.TEMP_NUMBER_PREFIX+n.tmp_number+".length"; return npp.TEMP_NUMBER_PREFIX+n.tmp_number+".getSize1()"; } if (n.type.nslNumeric) { return n.code+".getSize1()"; } else if(n.type.numeric) { return n.code+".length"; } else { /* type incompatible error !!!! */ } } else { // not Use_Nsl_As_Temp_Variable if (n.tmp_number>0) { // return npp.TEMP_NUMBER_PREFIX+n.tmp_number+".length"; return npp.TEMP_NUMBER_PREFIX+n.tmp_number+".length"; } if (n.type.nslNumeric) { return n.code+".getSize1()"; } else if(n.type.numeric) { return n.code+".length"; } else { /* type incompatible error !!!! */ } } return null; } /** Generate strings that define the variable size in the second dimension * @param n expression that determine the size * @param npp NslPreProcessor * @return generated string */ String getTempSize2(ExprNode n, NslPreProcessor npp) { if( Use_Nsl_As_Temp_Variable) { if (n.tmp_number>0) { // return npp.TEMP_NUMBER_PREFIX+n.tmp_number+"[0].length"; return npp.TEMP_NUMBER_PREFIX+n.tmp_number+".getSize2()"; } if (n.type.nslNumeric) { return n.code+".getSize2()"; } else if(n.type.numeric) { return n.code+"[0].length"; } else { /* type incompatible error !!!! */ } } else { // not Use_Nsl_As_Temp_Variable if (n.tmp_number>0) { return npp.TEMP_NUMBER_PREFIX+n.tmp_number+"[0].length"; } if (n.type.nslNumeric) { return n.code+".getSize2()"; } else if(n.type.numeric) { return n.code+"[0].length"; } else { /* type incompatible error !!!! */ } } return null; } public final static int NO_OP = 0; public final static int SUCCESS =1; public final static int NOT_LEFT_VALUE_ASSIGNMENT_ERROR = 10; public TypeNode type; public String code; public boolean lvalue; public boolean processed; public int tmp_number; public boolean nslSymbol; }