edu.mit.ai.psg.jevaES
Class ExpressionNode

java.lang.Object
  |
  +--edu.mit.ai.psg.jevaES.SimpleNode
        |
        +--edu.mit.ai.psg.jevaES.JevaNode
              |
              +--edu.mit.ai.psg.jevaES.ExpressionNode
Direct Known Subclasses:
JNEArrayAccessExpression, JNEArrayCreationExpression, JNEAssignmentExpression, JNECastExpression, JNEConditionalAndExpression, JNEConditionalExpression, JNEConditionalOrExpression, JNEInstanceCreationExpression, JNEInstanceOfExpression, JNELiteralExpression, JNEMethodInvocationExpression, JNEParenthesizedExpression, JNEPostfixExpression, JNEPreDecrementExpression, JNEPreIncrementExpression, JNEUnaryExpression, JNName, LeftAssociativeOperatorExpression

public abstract class ExpressionNode
extends JevaNode
implements IExpressionNode

A base class for Expressions which caches its type (and value if constant). Don't call its methods directly, but instead use EvalMethods which capture errors into an EvaluatingError.

Author:
CarlManning, caroma@ai.mit.edu
Copyright (c) 1997, 1998 Massachusetts Institute of Technology
See Also:
EvalMethods

Fields inherited from class edu.mit.ai.psg.jevaES.SimpleNode
children, id, parent
 
Constructor Summary
ExpressionNode(int id)
          Creates an ExpressionNode with the given JevaParseTreeConstants ID
 
Method Summary
abstract  boolean computeIsConstant(IEnv env)
          Compute whether this expression is a constant (nodes should not call this method directly).
abstract  Class computeType(IEnv env)
          Compute the static type of the expression (nodes should not call this method directly).
abstract  Object eval(IEnv env)
          Evaluate this expression (nodes should not call this method directly).
 Class getType(IEnv env)
          Return the static type of the expression (nodes should not call this method directly).
 Object getValue(IEnv env)
          Get the value of this node (nodes should not call this method directly).
 boolean isConstant(IEnv env)
          Test whether this is a compile-time constant expression (nodes should not call this method directly).
 
Methods inherited from class edu.mit.ai.psg.jevaES.JevaNode
getBeginToken, getEndToken, print, print, printToken, printToString, printToString, setBeginToken, setEndToken
 
Methods inherited from class edu.mit.ai.psg.jevaES.SimpleNode
dump, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExpressionNode

public ExpressionNode(int id)
Creates an ExpressionNode with the given JevaParseTreeConstants ID
Method Detail

getType

public final Class getType(IEnv env)
                    throws VerifyingException
Return the static type of the expression (nodes should not call this method directly). Computed once, then cached. Expressions don't override this directly, they override computeType instead.
Specified by:
getType in interface IExpressionNode
Parameters:
env - environment of name bindings, etc.
Throws:
VerifyingException - if expression is illegal
See Also:
computeType(edu.mit.ai.psg.jevaES.IEnv), EvalMethods.getType(IExpressionNode, IEnv)

computeType

public abstract Class computeType(IEnv env)
                           throws VerifyingException
Compute the static type of the expression (nodes should not call this method directly). Called by getType.
Parameters:
env - environment of name bindings, etc.
Throws:
VerifyingException - if expression is illegal
See Also:
EvalMethods.getType(IExpressionNode, IEnv)

isConstant

public final boolean isConstant(IEnv env)
                         throws VerifyingException
Test whether this is a compile-time constant expression (nodes should not call this method directly). Computed only once by calling the computeIsConstant method, then value is cached. This predicate is sometimes required for determining type (see [JavaLangSpec sec 15.27, 5.2, 15.24, 14.9]), so neither it nor computeIsConstant can call getType on this node. Expressions don't override this directly, they override computeIsConstant instead.
Specified by:
isConstant in interface IExpressionNode
Parameters:
env - environment of name bindings, etc.
Throws:
VerifyingException - if expression is illegal
See Also:
computeIsConstant(edu.mit.ai.psg.jevaES.IEnv), EvalMethods.isConstant(IExpressionNode, IEnv)

computeIsConstant

public abstract boolean computeIsConstant(IEnv env)
                                   throws VerifyingException
Compute whether this expression is a constant (nodes should not call this method directly). Called by the isConstant method.
Parameters:
env - environment of name bindings, etc.
Throws:
VerifyingException - if expression is illegal.
See Also:
isConstant(edu.mit.ai.psg.jevaES.IEnv), EvalMethods.isConstant(IExpressionNode, IEnv)

getValue

public final Object getValue(IEnv env)
                      throws ThrowException
Get the value of this node (nodes should not call this method directly). Computes value by calling the eval method; value is cached if it is constant. Specific expression nodes don't override this method directly, they override the eval method instead.
Specified by:
getValue in interface IExpressionNode
Parameters:
env - environment of name bindings, etc.
Throws:
ThrowException - if abruptly completed with an exception
See Also:
eval(edu.mit.ai.psg.jevaES.IEnv), isConstant(edu.mit.ai.psg.jevaES.IEnv), EvalMethods.eval(IExpressionNode, IEnv)

eval

public abstract Object eval(IEnv env)
                     throws ThrowException
Evaluate this expression (nodes should not call this method directly). Called by the getValue method.
Parameters:
env - environment of name bindings, etc.
Throws:
ThrowException - if abruptly completed with an exception
See Also:
getValue(edu.mit.ai.psg.jevaES.IEnv), EvalMethods.eval(IExpressionNode, IEnv)

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-bugs@ai.mit.edu