com.waveset.expression
Class ExNode

java.lang.Object
  extended bycom.waveset.expression.ExNode
All Implemented Interfaces:
com.sun.idm.debugger.common.Locatable
Direct Known Subclasses:
ExBlock, ExCall, ExDefun, ExDefvar, ExFunction.f_add, ExFunction.f_and, ExFunction.f_break, ExFunction.f_breakpoint, ExFunction.f_case, ExFunction.f_cmp, ExFunction.f_concat, ExFunction.f_cond, ExFunction.f_contains, ExFunction.f_containsAll, ExFunction.f_containsAny, ExFunction.f_div, ExFunction.f_dolist, ExFunction.f_eq, ExFunction.f_expand, ExFunction.f_getobj, ExFunction.f_gt, ExFunction.f_gte, ExFunction.f_index, ExFunction.f_indexOf, ExFunction.f_instanceof, ExFunction.f_isnull, ExFunction.f_isTrue, ExFunction.f_join, ExFunction.f_length, ExFunction.f_list, ExFunction.f_lt, ExFunction.f_lte, ExFunction.f_ltrim, ExFunction.f_map, ExFunction.f_match, ExFunction.f_member, ExFunction.f_message, ExFunction.f_mod, ExFunction.f_mult, ExFunction.f_neq, ExFunction.f_not, ExFunction.f_notnull, ExFunction.f_null, ExFunction.f_or, ExFunction.f_pad, ExFunction.f_rtrim, ExFunction.f_select, ExFunction.f_split, ExFunction.f_sub, ExFunction.f_substr, ExFunction.f_switch, ExFunction.f_trace, ExFunction.f_trim, ExFunction.f_upcase, ExFunction.f_while, ExFunction.f_ztrim, ExFunction.ListMutator, ExGet, ExInvoke, ExNew, ExPrint, ExReference, ExRule, ExRule.Argument, ExScript, ExSet, ExValueNode

public abstract class ExNode
extends java.lang.Object
implements com.sun.idm.debugger.common.Locatable

The basis for all nodes in a parsed expression tree.


Field Summary
protected  int _bindingCount
          Number of variable bindings found within this node.
protected  ExNode[] _children
          Our child nodes.
protected  ExDecoration _decoration
          An application attachment.
protected  ExNode _parent
          Our parent node in the tree.
static java.lang.String code_id
           
protected static Trace trace
           
 
Constructor Summary
protected ExNode()
          Make a new node.
 
Method Summary
 void addChild(ExNode node)
          Append one new node to the existing child list.
 void addChildren(ExNode[] nodes)
          Append a set of nodes to the existing child list.
protected  void addCommonAttributes(java.lang.StringBuffer b)
          Called by default by toXml.
 void beginTrace(java.lang.StringBuffer b)
          Called by ExState to format the start of a trace message for this node.
static void clearOwner(ExNode node)
           
 void endTrace(java.lang.StringBuffer b)
          Called by ExState to format the end of a trace message for this node.
 ExValue eval(ExState state)
          Default implementation of eval which takes care of tracing, breakpoints, and restoring the breakpoint stack upon exception.
 ExValue evalChild(ExState state, int childIndex)
          Evaluate one of our child nodes returning an ExValue.
 java.lang.Object evalChildToObject(ExState state, int childIndex)
          Evaluate one of our child nodes, returning an object.
 java.lang.String evalChildToString(ExState state, int childIndex)
          Evaluate one of our child nodes returning a string.
protected abstract  ExValue evalInternal(ExState state)
          Abstract evaluation method all nodes must have.
 boolean evalToBoolean(ExState state)
          Evaluate this node, and return a boolean.
 int evalToInt(ExState state)
          Evaluate this node, and return an int.
 java.lang.Object evalToObject(ExState state)
          Evaluate this node, and return an object value.
 java.lang.String evalToString(ExState state)
          Evaluate this node, and return an string.
 int getBindingCount()
          Get the number of variable bindings that appear within this node.
 ExNode getChild()
          Gets the first child node, a convenience method for places that expect only one node.
 ExNode[] getChildren()
          Get the child nodes.
 ExDecoration getDecoration()
          Get the node decoration.
abstract  java.lang.String getFunctionName()
          Nodes representing functions must have a name.
 ExDefvar getHiddenVariable()
          Get the optional hidden variable.
 com.sun.idm.debugger.common.Location getLocation()
           
 java.lang.Object getOwner()
           
 ExNode getParent()
          Get the parent node.
 boolean isLiteral()
          Called by ExState to determine if this node contains literal text, and therefore does not need a newline after the start tag.
protected  void parseCommonAttributes(org.w3c.dom.Element el)
          Called by default by parseXml.
 void parseXml(org.w3c.dom.Element el)
          Default XML parsing method.
 void postProcess()
          Traverses a node tree after initial parsing, resolving references to functions and variables, and performing any other optimizations that might be available.
 void removeChild(ExNode node)
          Remove a child node.
 ExDefun resolveFunction(java.lang.String name)
          Resolve a function reference.
 ExDefvar resolveVariable(java.lang.String name)
          Resolve a variable reference.
 void setBindingCount(int c)
          Set the number of variable bindings that appear within this node.
 void setChildren(ExNode[] nodes)
          Set the child list for this node.
 void setDecoration(ExDecoration d)
          Set the node decoration.
 void setEnvironment(ExEnvironment env)
          Set the node environment.
 void setLocation(com.sun.idm.debugger.common.Location l)
           
static void setOwner(ExNode node, java.lang.Object owner)
           
 void setOwner(java.lang.Object owner)
           
 void setParent(ExNode p)
          Set the parent node.
 java.lang.String toXml()
          Serialize a node to XML with header.
 void toXml(java.lang.StringBuffer b, int indent)
          Serialize the node back to XML.
 void toXml(java.lang.StringBuffer b, int indent, java.lang.String wrapper)
          Serialize expression XML with a wrapper.
 void toXmlAttributes(java.lang.StringBuffer b)
          Add attributes in the start tag of this node.
 void toXmlChildren(java.lang.StringBuffer b, int indent)
          Serialize children to an XML buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static final Trace trace

_parent

protected ExNode _parent
Our parent node in the tree.


_children

protected ExNode[] _children
Our child nodes.


_bindingCount

protected int _bindingCount
Number of variable bindings found within this node.


_decoration

protected ExDecoration _decoration
An application attachment.

Constructor Detail

ExNode

protected ExNode()
Make a new node.

Method Detail

evalInternal

protected abstract ExValue evalInternal(ExState state)
                                 throws WavesetException
Abstract evaluation method all nodes must have. Implementations of evalInternal need not (and should not) perform any tracing/breakpoints. This is all handled by the calling method eval.

Throws:
WavesetException

getFunctionName

public abstract java.lang.String getFunctionName()
Nodes representing functions must have a name. This name is used in the formatting of default trace messages and the default XML rendering. If a node doesn't have a name for some reason, or needs more control over the trace messges and XML, they must overload beginTrace, endTrace, and toXml below.


eval

public ExValue eval(ExState state)
             throws WavesetException
Default implementation of eval which takes care of tracing, breakpoints, and restoring the breakpoint stack upon exception. In general ExNodes should not override this, but there are a few special cases for nodes which must do their own trace setup or breakpoint handling.

Throws:
WavesetException

toXml

public void toXml(java.lang.StringBuffer b,
                  int indent)
Serialize the node back to XML.

This may be overloaded by subclasses if they have attributes or special formatting needs.


toXml

public void toXml(java.lang.StringBuffer b,
                  int indent,
                  java.lang.String wrapper)
Serialize expression XML with a wrapper.


toXmlAttributes

public void toXmlAttributes(java.lang.StringBuffer b)
Add attributes in the start tag of this node. Intended to be overloaded by subclasses.


addCommonAttributes

protected final void addCommonAttributes(java.lang.StringBuffer b)
Called by default by toXml. Should be called by any subclasses which override toXml


parseCommonAttributes

protected final void parseCommonAttributes(org.w3c.dom.Element el)
                                    throws WavesetException
Called by default by parseXml. Should be called by any subclasses which override parseXml and don't call super.parseXml

Throws:
WavesetException

toXmlChildren

public void toXmlChildren(java.lang.StringBuffer b,
                          int indent)
Serialize children to an XML buffer. Can be called by subclasses that want to overload the default toXml method.


toXml

public java.lang.String toXml()
Serialize a node to XML with header.


parseXml

public void parseXml(org.w3c.dom.Element el)
              throws WavesetException
Default XML parsing method. Parses the child elements into a list of child nodes.

Throws:
WavesetException

getParent

public ExNode getParent()
Get the parent node.


setParent

public void setParent(ExNode p)
Set the parent node.


getOwner

public java.lang.Object getOwner()

setOwner

public void setOwner(java.lang.Object owner)

getBindingCount

public int getBindingCount()
Get the number of variable bindings that appear within this node.


setBindingCount

public void setBindingCount(int c)
Set the number of variable bindings that appear within this node.


getChildren

public ExNode[] getChildren()
Get the child nodes.


getHiddenVariable

public ExDefvar getHiddenVariable()
Get the optional hidden variable. Ceratin nodes (dolist only) maintain an implicit variable which may be bound to a value but is not explicitly defined in the child list. Originally this was on the child list marked with a special flag, but this caused complications for the editor which wants to have complete control over the child list.


getChild

public ExNode getChild()
Gets the first child node, a convenience method for places that expect only one node.


setChildren

public void setChildren(ExNode[] nodes)
Set the child list for this node.


addChildren

public void addChildren(ExNode[] nodes)
Append a set of nodes to the existing child list.


addChild

public void addChild(ExNode node)
Append one new node to the existing child list.


removeChild

public void removeChild(ExNode node)
Remove a child node. Used occasionally during expression editing, or when expressions are being managed within a host application structure that is being edited. Don't check the node's parent just in case that got trashed, assume it may be on our list.


getDecoration

public ExDecoration getDecoration()
Get the node decoration.


setDecoration

public void setDecoration(ExDecoration d)
Set the node decoration.


setEnvironment

public void setEnvironment(ExEnvironment env)
Set the node environment. This can be used if we started playing with disassociated node trees, and want to root them within an environment in order to resolve references between trees.


setLocation

public void setLocation(com.sun.idm.debugger.common.Location l)
Specified by:
setLocation in interface com.sun.idm.debugger.common.Locatable

getLocation

public com.sun.idm.debugger.common.Location getLocation()
Specified by:
getLocation in interface com.sun.idm.debugger.common.Locatable

evalToString

public java.lang.String evalToString(ExState state)
                              throws WavesetException
Evaluate this node, and return an string.

Throws:
WavesetException

evalToBoolean

public boolean evalToBoolean(ExState state)
                      throws WavesetException
Evaluate this node, and return a boolean.

Throws:
WavesetException

evalToInt

public int evalToInt(ExState state)
              throws WavesetException
Evaluate this node, and return an int. If the result is null, or does not coerce, the returned value is zero.

Throws:
WavesetException

evalToObject

public java.lang.Object evalToObject(ExState state)
                              throws WavesetException
Evaluate this node, and return an object value.

Throws:
WavesetException

evalChild

public ExValue evalChild(ExState state,
                         int childIndex)
                  throws WavesetException
Evaluate one of our child nodes returning an ExValue.

A convenience method for a common operation.

Throws:
WavesetException

evalChildToString

public java.lang.String evalChildToString(ExState state,
                                          int childIndex)
                                   throws WavesetException
Evaluate one of our child nodes returning a string.

A convenience method for a common operation.

Throws:
WavesetException

evalChildToObject

public java.lang.Object evalChildToObject(ExState state,
                                          int childIndex)
                                   throws WavesetException
Evaluate one of our child nodes, returning an object.

A convenience method for a common operation.

Throws:
WavesetException

resolveFunction

public ExDefun resolveFunction(java.lang.String name)
Resolve a function reference.

We do this by searching backwards through the node tree looking for a node. This could be optimized by maintaining some kind of scope object, that we chain together, but since we try to resolve at "compile" time, speed isn't that important.


resolveVariable

public ExDefvar resolveVariable(java.lang.String name)
Resolve a variable reference.


postProcess

public void postProcess()
Traverses a node tree after initial parsing, resolving references to functions and variables, and performing any other optimizations that might be available.

This method can be overloaded in subclasses to do node specific post processing.


isLiteral

public boolean isLiteral()
Called by ExState to determine if this node contains literal text, and therefore does not need a newline after the start tag.


beginTrace

public void beginTrace(java.lang.StringBuffer b)
Called by ExState to format the start of a trace message for this node. By default, the begin trace mesage looks like an XML start tag, we use the value returned by the abstract getFunctionName method for the element name. Nodes can override this if they have more complicated trace information.


endTrace

public void endTrace(java.lang.StringBuffer b)
Called by ExState to format the end of a trace message for this node. By default, the begin trace mesage looks like an XML end tag, we use the value returned by the abstract getFunctionName method for the element name. Nodes can override this if they have more complicated trace information.


setOwner

public static void setOwner(ExNode node,
                            java.lang.Object owner)

clearOwner

public static void clearOwner(ExNode node)