Package com.singularsys.jeptests.system
Class StackCheckingFastEvaluator
java.lang.Object
com.singularsys.jeptests.system.StackCheckingFastEvaluator
- All Implemented Interfaces:
Evaluator,GenericVisitor<Object,,Void, EvaluationException> JepComponent,Serializable
public class StackCheckingFastEvaluator
extends Object
implements Evaluator, GenericVisitor<Object,Void,EvaluationException>
An Evaluator which checks the stack size after every function call.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanprotected booleanWhether null values for variables are trapped -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvaluates a sub expression.Main entry point, evaluates a node and returns and object with the value of the node.Gets a light-weight instance suitable for using in multiple threads.voidInitialize the component.booleanbooleanbooleanWhether null values for variables are trapped.booleanWhether variables with unset values are trapped.makeException(String message) Create an Exception of the correct type.protected ObjectnodeAccept(Node node) voidsetTrapInfinity(boolean trapInfinity) voidsetTrapNaN(boolean trapNaN) voidsetTrapNullValues(boolean trapNullValues) Sets whether null values for variables are trapped.voidsetTrapUnsetValues(boolean trapUnsetValues) Sets whether unset variable values are trapped.visit(ASTConstant node, Void data) Visit a constant nodevisit(ASTFunNode node, Void data) Visit a function nodeVisit an operator nodevisit(ASTVarNode node, Void data) Visit a variable nodevisitConstant(Node node) protected ObjectVisits a function/operator node.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.jep.GenericVisitor
makeException, visit, visitChildren
-
Field Details
-
trapUnsetValues
protected boolean trapUnsetValuesWhether null values for variables are trapped -
trapNullValues
protected boolean trapNullValues -
trapNaN
protected boolean trapNaN -
trapInfinity
protected boolean trapInfinity
-
-
Constructor Details
-
StackCheckingFastEvaluator
public StackCheckingFastEvaluator()
-
-
Method Details
-
init
Description copied from interface:JepComponentInitialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
eval
Description copied from interface:EvaluatorEvaluates a sub expression. This method can be called by PostfixMathCommands which implementCallbackEvaluationI- Specified by:
evalin interfaceEvaluator- Parameters:
node- node to evaluate- Returns:
- The value after evaluating the sub expression.
- Throws:
EvaluationException- if errors occur during evaluation;
-
evaluate
Description copied from interface:EvaluatorMain entry point, evaluates a node and returns and object with the value of the node.- Specified by:
evaluatein interfaceEvaluator- Parameters:
node- node to evaluate- Returns:
- value after evaluation
- Throws:
EvaluationException- if errors occur during evaluation;
-
nodeAccept
- Throws:
EvaluationException
-
visit
Description copied from interface:GenericVisitorVisit a constant node- Specified by:
visitin interfaceGenericVisitor<Object,Void, EvaluationException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
EvaluationException
-
visitConstant
- Throws:
EvaluationException
-
visit
Description copied from interface:GenericVisitorVisit a variable node- Specified by:
visitin interfaceGenericVisitor<Object,Void, EvaluationException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
EvaluationException
-
visitVar
- Throws:
EvaluationException
-
visit
Description copied from interface:GenericVisitorVisit a function node- Specified by:
visitin interfaceGenericVisitor<Object,Void, EvaluationException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
EvaluationException
-
visit
Description copied from interface:GenericVisitorVisit an operator node- Specified by:
visitin interfaceGenericVisitor<Object,Void, EvaluationException> - Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
EvaluationException
-
visitFun
Visits a function/operator node. This is the most visited method for most expression evaluations. Keeping it fast is important.- Parameters:
node-- Throws:
EvaluationException
-
isTrapUnsetValues
public boolean isTrapUnsetValues()Whether variables with unset values are trapped.- Returns:
- Since:
- 3.5
-
setTrapUnsetValues
public void setTrapUnsetValues(boolean trapUnsetValues) Sets whether unset variable values are trapped. This flag is set by when theVariable.setValidValue(boolean)or cleared usingVariableTable.clearValues().- Parameters:
trapUnsetValues- true to trap unset values, false to ignore them- Since:
- 3.5
-
isTrapNullValues
public boolean isTrapNullValues()Whether null values for variables are trapped.- Returns:
- the status if the trap null values flag.
-
setTrapNullValues
public void setTrapNullValues(boolean trapNullValues) Sets whether null values for variables are trapped. If set (the default) then an EvaluationException is thrown for null values of variables. If not set then null values are passed to PostfixMathCommands who will need to test for null values.- Parameters:
trapNullValues-
-
isTrapNaN
public boolean isTrapNaN() -
setTrapNaN
public void setTrapNaN(boolean trapNaN) -
isTrapInfinity
public boolean isTrapInfinity() -
setTrapInfinity
public void setTrapInfinity(boolean trapInfinity) -
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- a new FastEvaluator
-
makeException
Description copied from interface:GenericVisitorCreate an Exception of the correct type. A typical implementation is@Override public JepException makeException(String message) { return new JepException(message); }- Specified by:
makeExceptionin interfaceGenericVisitor<Object,Void, EvaluationException> - Parameters:
message- error message- Returns:
- an Exception
-