edu.mit.ai.psg.jevaES
Class EvalMethods

java.lang.Object
  |
  +--edu.mit.ai.psg.jevaES.EvalMethods

public class EvalMethods
extends Object

Centralized static methods for evaluating nodes while catching exceptions. Top level: evaluate(IExpressionNode) verifies type consistency before evaluating.

To evaluate subnodes, nodes call EvalMethods.eval(node, env) rather than calling the subnode eval method directly, so that when an error is thrown, this will wrap error in an EvaluatingError which identifies what node and env was being evaluated at the time. Similarly, nodes call EvalMethods.getType(IExpressionNode, IEnv) and EvalMethods.verifyTypes(IStatementNode, IEnv) rather than calling subnode methods directly so that when an error is thrown, this will wrap the error in a VerifyingError identifying node and env.

Evaluation may also throw other exceptions:

Author:
CarlManning, caroma@ai.mit.edu
Copyright (c) 1997, 1998, 1999 Massachusetts Institute of Technology
See Also:
VerifyingException, IllegalTypeException, IllegalNameException, IllegalConstructException, AbruptCompletionException, ThrowException, ReturnException, BreakException, ContinueException, VerifyingError, EvaluatingError

Field Summary
static IEnv defaultEnv
           
 
Constructor Summary
EvalMethods()
           
 
Method Summary
static Object eval(IExpressionNode node)
          return the value of previously verified expression in root env.
static Object eval(IExpressionNode enode, IEnv env)
          return the value of this previously verified expression in given env.
static IEnv eval(IStatementNode node)
          return IEnv, extended by previously verified statement.
static IEnv eval(IStatementNode snode, IEnv env)
          return env extended by this previously verified statement in given env.
static IStore evalToStore(IExpressionStoreNode node)
          return IStore for getting or setting the location denoted by this previously verified expression in root env.
static IStore evalToStore(IExpressionStoreNode esnode, IEnv env)
          return an IStore to get or set the location denoted by this previously verified expression in the given env.
static Object evaluate(IExpressionNode node)
          verify types then evaluate node with default env
static Object evaluate(IExpressionNode node, IEnv env)
          verify types then evaluate node with given env
static IEnv evaluate(IStatementNode node)
          verify types then evaluate node with default env
static IEnv evaluate(IStatementNode node, IEnv env)
          verify types then evaluate node with given env
static Class getType(IExpressionNode node)
          return the Class representing the Java type of this expression in default env, after type checking subexpressions.
static Class getType(IExpressionNode node, IEnv env)
          return Class representing Java type of this expression in given env after type checking subexpressions.
static boolean isConstant(IExpressionNode node)
          return true if this expression has constant value in root env.
static boolean isConstant(IExpressionNode node, IEnv env)
          return true if this expression has constant value in given env.
static IEnv verifyTypes(IStatementNode node)
           
static IEnv verifyTypes(IStatementNode node, IEnv env)
          return IEnv, extended by this statement if it is a local declaration but without evaluating initializers, after verifying types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultEnv

public static IEnv defaultEnv
Constructor Detail

EvalMethods

public EvalMethods()
Method Detail

evaluate

public static Object evaluate(IExpressionNode node)
                       throws VerifyingException,
                              ThrowException
verify types then evaluate node with default env
Returns:
value of expression evaluated in default env
Throws:
VerifyingException - if expression is illegal
ThrowException - if completes abruptly with an exception

evaluate

public static IEnv evaluate(IStatementNode node)
                     throws VerifyingException,
                            AbruptCompletionException
verify types then evaluate node with default env
Returns:
value of expression evaluated in default env
Throws:
VerifyingException - if statement is illegal
AbruptCompletionException - if completes abruptly

evaluate

public static Object evaluate(IExpressionNode node,
                              IEnv env)
                       throws VerifyingException,
                              ThrowException
verify types then evaluate node with given env
Returns:
value of expression evaluated in default env
Throws:
VerifyingException - if illegal expression
ThrowException - if completes abruptly with an exception

evaluate

public static IEnv evaluate(IStatementNode node,
                            IEnv env)
                     throws VerifyingException,
                            AbruptCompletionException
verify types then evaluate node with given env
Returns:
value of expression evaluated in default env
Throws:
VerifyingException - if illegal statement
AbruptCompletionException - if completes abruptly

getType

public static Class getType(IExpressionNode node)
                     throws VerifyingException
return the Class representing the Java type of this expression in default env, after type checking subexpressions.
Throws:
VerifyingException - if expression is illegal.

isConstant

public static boolean isConstant(IExpressionNode node)
                          throws VerifyingException
return true if this expression has constant value in root env.
Throws:
VerifyingException - if expression is illegal.

verifyTypes

public static IEnv verifyTypes(IStatementNode node)
                        throws VerifyingException
Returns:
IEnv, extended by this statement if it is a local declaration but without evaluating initializers, after verifying types.
Throws:
VerifyingException - if statement is illegal.

eval

public static Object eval(IExpressionNode node)
                   throws ThrowException
return the value of previously verified expression in root env.
Parameters:
previously - verified expression
Throws:
ThrowException - if completes abruptly with an exception

eval

public static IEnv eval(IStatementNode node)
                 throws AbruptCompletionException
return IEnv, extended by previously verified statement.
Parameters:
previously - verified statement
Throws:
AbruptCompletionException - if completes abruptly

evalToStore

public static IStore evalToStore(IExpressionStoreNode node)
                          throws ThrowException
return IStore for getting or setting the location denoted by this previously verified expression in root env.
Parameters:
previously - verified storable expression
Throws:
ThrowException - if completes abruptly with an exception .

getType

public static Class getType(IExpressionNode node,
                            IEnv env)
                     throws VerifyingException
return Class representing Java type of this expression in given env after type checking subexpressions.
Throws:
VerifyingException - if expression is illegal.

isConstant

public static boolean isConstant(IExpressionNode node,
                                 IEnv env)
                          throws VerifyingException
return true if this expression has constant value in given env.
Throws:
VerifyingException - if expression is illegal.

verifyTypes

public static IEnv verifyTypes(IStatementNode node,
                               IEnv env)
                        throws VerifyingException
return IEnv, extended by this statement if it is a local declaration but without evaluating initializers, after verifying types.
Throws:
VerifyingException - if statement is illegal.

eval

public static Object eval(IExpressionNode enode,
                          IEnv env)
                   throws ThrowException
return the value of this previously verified expression in given env.
Throws:
ThrowException - if completes abruptly with an exception

eval

public static IEnv eval(IStatementNode snode,
                        IEnv env)
                 throws AbruptCompletionException
return env extended by this previously verified statement in given env.
Throws:
AbruptCompletionException - if completes abruptly

evalToStore

public static IStore evalToStore(IExpressionStoreNode esnode,
                                 IEnv env)
                          throws ThrowException
return an IStore to get or set the location denoted by this previously verified expression in the given env.
Throws:
ThrowException - if completes abruptly with an exception

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-bugs@ai.mit.edu