ptolemy.actor.gt
Class GTParameter.Evaluator

java.lang.Object
  extended by ptolemy.data.expr.AbstractParseTreeVisitor
      extended by ptolemy.data.expr.ParseTreeEvaluator
          extended by ptolemy.actor.gt.GTParameter.Evaluator
All Implemented Interfaces:
ParseTreeVisitor
Enclosing class:
GTParameter

public static class GTParameter.Evaluator
extends ParseTreeEvaluator

The evaluator used in a transformation rule. It differs from other evaluators in that it uses a pattern and a match result to resolve names in both the pattern and the host model that the pattern matches in the match result. If a name is found in the host model, its value in the host model is returned, regardless of whether the same name exists in the pattern or not (even if this evaluator is used to evaluate a parameter specified in the pattern).

Since:
Ptolemy II 7.1
Version:
$Id: GTParameter.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Huining Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Yellow (tfeng)

Field Summary
private  MatchResult _matchResult
          The match result.
private  Pattern _pattern
          The pattern.
 
Fields inherited from class ptolemy.data.expr.ParseTreeEvaluator
_evaluatedChildToken, _typeInference
 
Constructor Summary
GTParameter.Evaluator(Pattern pattern, MatchResult matchResult)
          Construct an evaluator.
 
Method Summary
protected  ParserScope _createScope(Pattern pattern, MatchResult matchResult, ParserScope superScope)
          Create the scope to be used for name resolution.
 Token evaluateParseTree(ASTPtRootNode node, ParserScope scope)
          Evaluate the parse tree with a scope that can resolve more names than the given scope.
 void visitMethodCallNode(ASTPtMethodCallNode node)
          Apply a method to the children of the specified node, where the first child is the object on which the method is defined and the rest of the children are arguments.
 
Methods inherited from class ptolemy.data.expr.ParseTreeEvaluator
_assert, _evaluateAllChildren, _evaluateArrayIndex, _evaluateChild, _evaluateMatrixIndex, _functionCall, _methodCall, _trace, _traceEnter, _traceLeave, evaluateParseTree, traceParseTreeEvaluation, visitArrayConstructNode, visitBitwiseNode, visitFunctionalIfNode, visitFunctionApplicationNode, visitFunctionDefinitionNode, visitLeafNode, visitLogicalNode, visitMatrixConstructNode, visitPowerNode, visitProductNode, visitRecordConstructNode, visitRelationalNode, visitShiftNode, visitSumNode, visitUnaryNode, visitUnionConstructNode
 
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_matchResult

private MatchResult _matchResult
The match result.


_pattern

private Pattern _pattern
The pattern.

Constructor Detail

GTParameter.Evaluator

public GTParameter.Evaluator(Pattern pattern,
                             MatchResult matchResult)
Construct an evaluator.

Parameters:
pattern - The pattern.
matchResult - The match result for the match between the pattern and a host model.
Method Detail

evaluateParseTree

public Token evaluateParseTree(ASTPtRootNode node,
                               ParserScope scope)
                        throws IllegalActionException
Evaluate the parse tree with a scope that can resolve more names than the given scope. The used scope first searches for names in the host model. If the attempt fails, it invokes the given scope to resolve the names.

Overrides:
evaluateParseTree in class ParseTreeEvaluator
Parameters:
node - The node to be evaluated.
scope - The scope to be used as a fallback.
Returns:
The result of evaluation.
Throws:
IllegalActionException - If an error occurs during evaluation.

visitMethodCallNode

public void visitMethodCallNode(ASTPtMethodCallNode node)
                         throws IllegalActionException
Apply a method to the children of the specified node, where the first child is the object on which the method is defined and the rest of the children are arguments. This also handles indexing into a record, which looks the same.

Specified by:
visitMethodCallNode in interface ParseTreeVisitor
Overrides:
visitMethodCallNode in class ParseTreeEvaluator
Parameters:
node - The specified node.
Throws:
IllegalActionException - If an evaluation error occurs.

_createScope

protected ParserScope _createScope(Pattern pattern,
                                   MatchResult matchResult,
                                   ParserScope superScope)
Create the scope to be used for name resolution.

Parameters:
pattern - The pattern.
matchResult - The match result.
superScope - The scope to fall back on if a name cannot be resolved.
Returns:
The scope.