📄 variable.java
字号:
LibId[] libIds = (LibId[])value; for (int i = 0; i < libIds.length; i++) { if (libIds[i] == null) continue; LibId libId = idMapper.get(libIds[i]); if (libId != libIds[i]) { libIds[i] = libId; newValue = libIds; } } break; case CELL|ARRAY: CellId[] cellIds = (CellId[])value; for (int i = 0; i < cellIds.length; i++) { if (cellIds[i] == null) continue; CellId cellId = idMapper.get(cellIds[i]); if (cellId != cellIds[i]) { cellIds[i] = cellId; newValue = cellIds; } } break; case EXPORT|ARRAY: ExportId[] exportIds = (ExportId[])value; for (int i = 0; i < exportIds.length; i++) { if (exportIds[i] == null) continue; ExportId exportId = idMapper.get(exportIds[i]); if (exportId != exportIds[i]) { exportIds[i] = exportId; newValue = exportIds; } } break; } return newValue; } /** * Returns thread-independent element of array value of this Variable. * @param index index of array * @return element of array value. * @throws ArrayIndexOutOfBoundsException if index is scalar of value is out of bounds. */ public Object getObject(int index) { if ((type & ARRAY) == 0) throw new ArrayIndexOutOfBoundsException(index); return ((Object[])value)[index]; } /** * Method to return the Variable Key associated with this Variable. * @return the Variable Key associated with this variable. */ public Key getKey() { return key; } /** * Returns true if variable is linked to a linked owner, false otherwise. * @param owner owner of this variable. * @return true if variable is linked to a linked owner, false otherwise. */ public boolean isLinked(ElectricObject owner) { return owner.isLinked() && owner.getParameterOrVariable(getKey()) == this; } /** * Method to return a more readable name for this Variable. * The method adds "Parameter" or "Attribute" as appropriate * and uses sensible names such as "Diode Size" instead of "SCHEM_diode". * @return a more readable name for this Variable. */ public String getReadableName(ElectricObject owner) { String trueName = ""; String name = getKey().getName(); if (isAttribute()) { if (owner.isParam(getKey())) trueName += "Parameter '" + name.substring(5) + "'"; else trueName += "Attribute '" + name.substring(5) + "'"; } else { String betterName = betterVariableName(name); if (betterName != null) trueName += betterName; else trueName += "Variable '" + name + "'"; }// unitname = us_variableunits(var);// if (unitname != 0) formatinfstr(infstr, x_(" (%s)"), unitname); return trueName; } /** * Method to return a full description of this Variable. * The description includes the object on which this Variable resides. * @return a full description of this Variable. */ public String getFullDescription(ElectricObject eobj) { String trueName = getReadableName(eobj); String description = null; if (eobj instanceof Export) { description = trueName + " on " + eobj; } else if (eobj instanceof PortInst) { PortInst pi = (PortInst)eobj; description = trueName + " on " + pi.getPortProto() + " of " + pi.getNodeInst().describe(true); } else if (eobj instanceof ArcInst) { description = trueName + " on " + eobj; } else if (eobj instanceof NodeInst) { NodeInst ni = (NodeInst)eobj; description = trueName + " on " + ni; if (ni.getProto() == Generic.tech().invisiblePinNode) { String varName = getKey().getName(); String betterName = betterVariableName(varName); if (betterName != null) description = betterName; } } else if (eobj instanceof Cell) { description = trueName + " of " + eobj; } return description; } /** * Method to convert the standard Variable names to more readable strings. * @param name the actual Variable name. * @return a better name for it (returns the same name if no better one exists). */ public static String betterVariableName(String name) { // handle standard variable names if (name.equals("ARC_name")) return "Arc Name"; if (name.equals("ARC_radius")) return "Arc Radius"; if (name.equals("ART_color")) return "Color"; if (name.equals("ART_degrees")) return "Number of Degrees"; if (name.equals("ART_message")) return "Annotation text"; if (name.equals("NET_ncc_match")) return "NCC equivalence"; if (name.equals("NET_ncc_forcedassociation")) return "NCC association"; if (name.equals("NODE_name")) return "Node Name"; if (name.equals("SCHEM_capacitance")) return "Capacitance"; if (name.equals("SCHEM_diode")) return "Diode Size"; if (name.equals("SCHEM_global_name")) return "Global Signal Name"; if (name.equals("SCHEM_inductance")) return "Inductance"; if (name.equals("SCHEM_resistance")) return "Resistance"; if (name.equals("SIM_fall_delay")) return "Fall Delay"; if (name.equals("SIM_fasthenry_group_name")) return "FastHenry Group"; if (name.equals("SIM_rise_delay")) return "Rise Delay"; if (name.equals("SIM_spice_card")) return "SPICE code"; if (name.equals("SIM_spice_declaration")) return "SPICE declaration"; if (name.equals("SIM_spice_model")) return "SPICE model"; if (name.equals("SIM_verilog_wire_type")) return "Verilog Wire type"; if (name.equals("SIM_weak_node")) return "Transistor Strength"; if (name.equals("transistor_width")) return "Transistor Width"; if (name.equals("VERILOG_code")) return "Verilog code"; if (name.equals("VERILOG_declaration")) return "Verilog declaration"; if (name.equals("VERILOG_parameter")) return "Verilog parameter"; if (name.equals("VERILOG_external_code")) return "Verilog external code"; return null; } /** * Method to return the "true" name for this Variable. * The method removes the "ATTR_" and "ATTRP_" prefixes. * @return the "true" name for this Variable. */ public String getTrueName() { String name = getKey().getName(); if (name.startsWith("ATTR_")) return name.substring(5); if (name.startsWith("ATTRP_")) { int i = name.lastIndexOf('_'); return name.substring(i); } return name; } /** * Method to return a description of this Variable. * @return a description of this Variable. */ public String describe(VarContext context, Object eobj) { return describe(-1, context, eobj); } /** * Return a description of this Variable without any context * or helper object info */ public String describe(int aindex) { return describe(aindex, VarContext.globalContext, null); } /** * Method to return a String describing this Variable. * @param aindex if negative, print the entire array. * @param context the VarContext for this Variable. * @param eobj the Object on which this Variable resides. * @return a String desribing this Variable. */ public String describe(int aindex, VarContext context, Object eobj) { TextDescriptor.Unit units = getUnit(); StringBuffer returnVal = new StringBuffer(); TextDescriptor.DispPos dispPos = getDispPart(); if (isCode()) { // special case for code: it is a string, the type applies to the result if (context == null) context = VarContext.globalContext; Object val = null; try { val = context.evalVarRecurse(this, eobj); } catch (VarContext.EvalException e) { VarContext.printException(e, this, context, eobj); val = e.getMessage(); } if (val == null) val = "?"; returnVal.append(makeStringVar(val, units)); } else { returnVal.append(getPureValue(aindex)); } if (dispPos == TextDescriptor.DispPos.NAMEVALUE && (aindex < 0 || getLength() == 1)) { return this.getTrueName() + "=" + returnVal; } return returnVal.toString(); } /** * Method to convert this Variable to a String without any evaluation of code. * @param aindex if negative, print the entire array. * @return a String desribing this Variable. */ public String getPureValue(int aindex) { TextDescriptor.Unit units = getUnit(); StringBuffer returnVal = new StringBuffer(); Object thisAddr = getObject(); if (thisAddr instanceof Object[]) { // compute the array length Object [] addrArray = (Object [])thisAddr; int len = addrArray.length; // if asking for a single entry, get it if (aindex >= 0) { // normal array indexing if (aindex < len) returnVal.append(makeStringVar(addrArray[aindex], units)); } else { // in an array, quote strings if (len > 1) returnVal.append("["); for(int i=0; i<len; i++) { if (i != 0) returnVal.append(","); returnVal.append(makeStringVar(addrArray[i], units)); } if (len > 1) returnVal.append("]"); } } else { returnVal.append(makeStringVar(thisAddr, units)); } return returnVal.toString(); } /** * Method to convert object "addr" to a string, given a set of units. * For completion of the method, the units should be treated as in "makeStringVar()". */ private String makeStringVar(Object addr, TextDescriptor.Unit units) {// if (addr instanceof Integer)// {// return ((Integer)addr).toString();// } if (addr instanceof Float) { return TextUtils.makeUnits(((Float)addr).floatValue(), units); } if (addr instanceof Double) { return TextUtils.makeUnits(((Double)addr).doubleValue(), units); }// if (addr instanceof Short)// return ((Short)addr).toString();// if (addr instanceof Byte)// return ((Byte)addr).toString();// if (addr instanceof String)// return (String)addr; if (addr instanceof Object[]) { StringBuffer buf = new StringBuffer(); buf.append("["); Object [] objects = (Object[])addr; for (int i=0; i<objects.length; i++) { if (objects[i] != null) buf.append(makeStringVar(objects[i], units)); buf.append(", "); } buf.replace(buf.length()-2, buf.length(), "]"); return buf.toString(); } return addr.toString(); } /** * This function is to compare Variable elements. Initiative CrossLibCopy * @param obj Object to compare to * @param buffer To store comparison messages in case of failure * @return True if objects represent same PortInst */ public boolean compare(Object obj, StringBuffer buffer) { if (this == obj) return (true); // Better if compare classes? but it will crash with obj=null if (obj == null || getClass() != obj.getClass()) return (false); Variable var = (Variable)obj; boolean check = var.getTextDescriptor().equals(getTextDescriptor()); if (!check && buffer != null) buffer.append("No same variables detected in " + var + " and " + this + "\n"); return (check); } @Override public int hashCode() { return key.hashCode(); } @Override
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -