public class ParseTreeEvaluatorForGuardExpression extends ParseTreeEvaluator
This visitor has two modes of operation: construction mode and update mode. During the construction mode, this visitor constructs a relation list where each element of the list corresponds to a relation of the guard expression. The order of the elements is fixed and it is the same as the order that the relations appear in the guard expression. If the guard expression changes, the relation list will be reconstructed. During the update mode, the relation list gets updated only. The order of the elements get updated is the same order the relations of the guard expression get evaluated.
When this visitor evaluates the parse tree, if the visiting node is a leaf node and the evaluated token is a boolean token, or the visiting node is a relational node, the visiting node is treated as a relation. The visitor evaluates the 'difference' and 'relationType' of this relation, and stores the evaluation results into the corresponding element in the relation list.
The 'difference' of a relation is calculated in the following way.
For a leaf node evaluated as a boolean token, the difference is
0. This situation corresponds to the "true", or "false", or "x_isPresent"
elements in a guard expression. For a relational node with the format
(scalarLeft relationOperator scalarRight), the difference is the absolute
double value of (scalarLeft - scalarRight). For details of relation type,
see RelationType
.
If the evaluator is in the construction mode, the relation information is added into the relation list, if it is in the update mode, the corresponding element of the relation List gets updated.
Note, this evaluator does not use short-circuit evaluation on logical nodes, meaning all nodes will be evaluated.
RelationList
,
ParseTreeEvaluator
_evaluatedChildToken, _typeInference
Constructor and Description |
---|
ParseTreeEvaluatorForGuardExpression(RelationList relationList,
double errorTolerance)
Construct a parse tree evaluator for a guard expression of the
given relation list and the error tolerance for evaluation the relations.
|
Modifier and Type | Method and Description |
---|---|
Token |
evaluateParseTree(ASTPtRootNode node,
ParserScope scope)
Evaluate the parse tree with the specified root node using
the specified scope to resolve the values of variables.
|
RelationList |
getRelationList()
Return the list of relations (boolean-valued expressions that do not
contain a logical operator, such as comparison expressions) in the
guard expression of this transition.
|
void |
setConstructionMode()
Set parse tree evaluator to be in construction mode.
|
void |
visitLeafNode(ASTPtLeafNode node)
Visit the leaf node.
|
void |
visitLogicalNode(ASTPtLogicalNode node)
Visit the logical node.
|
void |
visitRelationalNode(ASTPtRelationalNode node)
Visit the relation node.
|
_assert, _evaluateAllChildren, _evaluateArrayIndex, _evaluateChild, _evaluateMatrixIndex, _functionCall, _methodCall, _trace, _traceEnter, _traceLeave, evaluateParseTree, traceParseTreeEvaluation, visitArrayConstructNode, visitBitwiseNode, visitFunctionalIfNode, visitFunctionApplicationNode, visitFunctionDefinitionNode, visitMatrixConstructNode, visitMethodCallNode, visitPowerNode, visitProductNode, visitRecordConstructNode, visitShiftNode, visitSumNode, visitUnaryNode, visitUnionConstructNode
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode
public ParseTreeEvaluatorForGuardExpression(RelationList relationList, double errorTolerance)
relationList
- The relation list.errorTolerance
- The errorTolerance.public Token evaluateParseTree(ASTPtRootNode node, ParserScope scope) throws IllegalActionException
evaluateParseTree
in class ParseTreeEvaluator
node
- The root of the parse tree.scope
- The scope for evaluation.IllegalActionException
- If an error occurs during
evaluation.public RelationList getRelationList()
public void setConstructionMode()
public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException
visitLeafNode
in interface ParseTreeVisitor
visitLeafNode
in class ParseTreeEvaluator
node
- The leaf node to be evaluated.IllegalActionException
- If the super class method
visitLeafNode throws the IllegalActionException.public void visitLogicalNode(ASTPtLogicalNode node) throws IllegalActionException
visitLogicalNode
in interface ParseTreeVisitor
visitLogicalNode
in class ParseTreeEvaluator
node
- The logical node to be evaluated.IllegalActionException
- If the super class method
visitLogicalNode throws the IllegalActionException.public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException
visitRelationalNode
in interface ParseTreeVisitor
visitRelationalNode
in class ParseTreeEvaluator
node
- The relation node to be evaluated.IllegalActionException
- If the super class method
visitRelationNode throws the IllegalActionException.