|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.electric.database.variable.VarContext
public class VarContext
VarContext represents a hierarchical path of NodeInsts. Its primary use is to determine the value of variables which contain Java code. In particular, the syntax @foo expands to P("foo") which looks for the variable called foo in the NodeInst of this VarContext.
A VarContext can also be used to recover the names of instances along a hierarchical path. LE.getdrive() is an example of a method that does this.
The VarContext object that represents the base top level is VarContext.globalContext. You can get a new VarContext with an extra NodeInst context attached by calling push(NodeInst) on the parent context. You can get a VarContext with the most recent NodeInst removed by calling pop(). Note that individual VarContexts are immutable: you get new ones by calling push and pop; push and pop do not edit their own VarContexts.
Retrieve a Variable by calling getVar(String name) on any ElectricObject.
If the one knows that the Variable contains an object that does not need to be evaluated, that object can be retrieved using Variable.getObject().
On the other hand, if the object may need to be evaluated because it is type Java, TCL, or Lisp, then such evaluation may be hierarchy dependent and one must call context.evalVar(variable).
Extra variables defined in the interpreter:
Extra functions defined in the interpreter:
P(name) -- get the value of variable name on the most recent NodeInst.
Defaults to Integer(0).
Methods PD(), PAR(), and PARD() are either gone or deprecated (RKao). Here
are what they used to do:
PD(name, default) -- get the value of variable name on the most recent
NodeInst. Defaults to default.
PAR(name) -- get the value of variable name on any NodeInst, starting
with the most recent. Defaults to Integer(0).
PARD(name, default) -- get the value of variable name on any NodeInst,
starting with the most recent. Defaults to default.
This class is thread-safe.
Nested Class Summary | |
---|---|
static class |
VarContext.EvalException
|
Field Summary | |
---|---|
static VarContext |
globalContext
The blank VarContext that is the parent of all VarContext chains. |
Method Summary | |
---|---|
void |
deleteVariableCache()
Get rid of the variable cache thereby release its storage |
boolean |
equals(java.lang.Object o)
Does deep comparison of two VarContexts. |
java.lang.Object |
evalSpice(Variable var,
boolean recurse)
Evaluate a spice variable |
java.lang.Object |
evalVar(Variable var)
Gets the value of Variable @param var. |
java.lang.Object |
evalVar(Variable var,
java.lang.Object info)
Same as evalVar, except an additional object 'info' is passed to the evaluator. |
java.lang.Object |
evalVarRecurse(Variable var,
java.lang.Object info)
This is the recursive version of evalVar that may throw an EvalException. |
java.lang.String |
getInstPath(java.lang.String sep)
Return the concatonation of all instances names left to right from the root to the leaf. |
Nodable |
getNodable()
Return the Node Instance that provides the context for the variable evaluation for this level. |
int |
getNumLevels()
Get the number of levels of context in this VarContext |
java.util.Iterator<Nodable> |
getPathIterator()
Get an iterator over the Nodables that describe this context. |
PortInst |
getPortInst()
Return the PortInst that resides on the NodeInst that provides the context. |
protected java.lang.Object |
lookupVarEval(java.lang.String name)
Lookup Variable one level up the hierarchy and evaluate. |
static double |
objectToDouble(java.lang.Object obj,
double def)
Helper method to convert an Object to a double, if possible. |
static float |
objectToFloat(java.lang.Object obj,
float def)
Helper method to convert an Object to a float, if possible. |
static int |
objectToInt(java.lang.Object obj,
int def)
Helper method to convert an Object to an integer, if possible. |
static short |
objectToShort(java.lang.Object obj,
short def)
Helper method to convert an Object to a short, if possible. |
VarContext |
pop()
get the VarContext that existed before you called push on it. |
static void |
printException(VarContext.EvalException e,
Variable var,
VarContext context,
java.lang.Object info)
|
VarContext |
push(Nodable ni)
get a new VarContext that consists of the current VarContext with the given NodeInst pushed onto the stack |
VarContext |
pushCaching(Nodable ni)
Push a new level onto the VarContext stack. |
VarContext |
removeParentContext(int levels)
Remove N levels of parent context from this VarContext. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final VarContext globalContext
Method Detail |
---|
public VarContext push(Nodable ni)
public VarContext pushCaching(Nodable ni)
Be warned that there is no mechanism to automatically flush the caches when the design is modified. The design MUST NOT change over the life time of this VarContext. If the design might change then you should use the non-caching VarContext.
public VarContext pop()
public Nodable getNodable()
public PortInst getPortInst()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the VarContext to compare against.
public java.util.Iterator<Nodable> getPathIterator()
public VarContext removeParentContext(int levels)
levels
- the number of levels of parent context to remove
public int getNumLevels()
public void deleteVariableCache()
public java.lang.Object evalVar(Variable var)
public java.lang.Object evalVar(Variable var, java.lang.Object info)
public static void printException(VarContext.EvalException e, Variable var, VarContext context, java.lang.Object info)
public java.lang.Object evalVarRecurse(Variable var, java.lang.Object info) throws VarContext.EvalException
var
- the variable to evaluateinfo
- an info object that may be needed by the evaluator
VarContext.EvalException
- an exception whose message contains the reason evaluation failedpublic java.lang.Object evalSpice(Variable var, boolean recurse)
var
- the variable to evaluaterecurse
- false to not recursively evaluate (only if param call is SPICE code).
protected java.lang.Object lookupVarEval(java.lang.String name) throws VarContext.EvalException
name
- the name of the variable
VarContext.EvalException
public java.lang.String getInstPath(java.lang.String sep)
sep
- the separator string.public static float objectToFloat(java.lang.Object obj, float def)
public static int objectToInt(java.lang.Object obj, int def)
public static short objectToShort(java.lang.Object obj, short def)
public static double objectToDouble(java.lang.Object obj, double def)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |