Package ptolemy.data.expr
Class ParseTreeSpecializer
- java.lang.Object
-
- ptolemy.data.expr.AbstractParseTreeVisitor
-
- ptolemy.data.expr.ParseTreeSpecializer
-
- All Implemented Interfaces:
ParseTreeVisitor
public class ParseTreeSpecializer extends AbstractParseTreeVisitor
This class reduces a parse tree, given a scope of bound variables. If an identifier is not found in the given scope, then the identifier is bound to any constants registered with the expression parser. If any subtrees of the parse tree become constant, they are evaluated and replaced with leaf nodes containing the evaluated result.- Since:
- Ptolemy II 2.1
- Version:
- $Id$
- Author:
- Steve Neuendorffer
- See Also:
ASTPtRootNode- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (neuendor)
-
-
Field Summary
Fields Modifier and Type Field Description protected ParseTreeEvaluator_evaluatorprotected java.util.List_excludedNamesprotected ASTPtRootNode_resultprotected ParserScope_scope
-
Constructor Summary
Constructors Constructor Description ParseTreeSpecializer()
-
Method Summary
-
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode, visitUnionConstructNode
-
-
-
-
Field Detail
-
_excludedNames
protected java.util.List _excludedNames
-
_result
protected ASTPtRootNode _result
-
_scope
protected ParserScope _scope
-
_evaluator
protected ParseTreeEvaluator _evaluator
-
-
Method Detail
-
specialize
public ASTPtRootNode specialize(ASTPtRootNode node, java.util.List excludedNames, ParserScope scope) throws IllegalActionException
Return a new parse tree resulting from the specialization of the given parse tree. Every identifier reference is replaced by constants according to the given scope. Constant subtrees are replaced with constant leaf nodes. Exclude the given set of names from being replaced. The given parse tree is not destroyed in the process.- Parameters:
node- The nodeexcludedNames- the names to be excludedscope- The scope- Returns:
- The new parse tree
- Throws:
IllegalActionException- If the node can't be cloned or if thrown while visiting.
-
visitArrayConstructNode
public void visitArrayConstructNode(ASTPtArrayConstructNode node) throws IllegalActionException
- Specified by:
visitArrayConstructNodein interfaceParseTreeVisitor- Overrides:
visitArrayConstructNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitBitwiseNode
public void visitBitwiseNode(ASTPtBitwiseNode node) throws IllegalActionException
- Specified by:
visitBitwiseNodein interfaceParseTreeVisitor- Overrides:
visitBitwiseNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitFunctionApplicationNode
public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) throws IllegalActionException
- Specified by:
visitFunctionApplicationNodein interfaceParseTreeVisitor- Overrides:
visitFunctionApplicationNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitFunctionDefinitionNode
public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node) throws IllegalActionException
- Specified by:
visitFunctionDefinitionNodein interfaceParseTreeVisitor- Overrides:
visitFunctionDefinitionNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitFunctionalIfNode
public void visitFunctionalIfNode(ASTPtFunctionalIfNode node) throws IllegalActionException
- Specified by:
visitFunctionalIfNodein interfaceParseTreeVisitor- Overrides:
visitFunctionalIfNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitLeafNode
public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException
- Specified by:
visitLeafNodein interfaceParseTreeVisitor- Overrides:
visitLeafNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitLogicalNode
public void visitLogicalNode(ASTPtLogicalNode node) throws IllegalActionException
- Specified by:
visitLogicalNodein interfaceParseTreeVisitor- Overrides:
visitLogicalNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitMatrixConstructNode
public void visitMatrixConstructNode(ASTPtMatrixConstructNode node) throws IllegalActionException
- Specified by:
visitMatrixConstructNodein interfaceParseTreeVisitor- Overrides:
visitMatrixConstructNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitMethodCallNode
public void visitMethodCallNode(ASTPtMethodCallNode node) throws IllegalActionException
- Specified by:
visitMethodCallNodein interfaceParseTreeVisitor- Overrides:
visitMethodCallNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitPowerNode
public void visitPowerNode(ASTPtPowerNode node) throws IllegalActionException
- Specified by:
visitPowerNodein interfaceParseTreeVisitor- Overrides:
visitPowerNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitProductNode
public void visitProductNode(ASTPtProductNode node) throws IllegalActionException
- Specified by:
visitProductNodein interfaceParseTreeVisitor- Overrides:
visitProductNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitRecordConstructNode
public void visitRecordConstructNode(ASTPtRecordConstructNode node) throws IllegalActionException
- Specified by:
visitRecordConstructNodein interfaceParseTreeVisitor- Overrides:
visitRecordConstructNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitRelationalNode
public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException
- Specified by:
visitRelationalNodein interfaceParseTreeVisitor- Overrides:
visitRelationalNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitShiftNode
public void visitShiftNode(ASTPtShiftNode node) throws IllegalActionException
- Specified by:
visitShiftNodein interfaceParseTreeVisitor- Overrides:
visitShiftNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitSumNode
public void visitSumNode(ASTPtSumNode node) throws IllegalActionException
- Specified by:
visitSumNodein interfaceParseTreeVisitor- Overrides:
visitSumNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitUnaryNode
public void visitUnaryNode(ASTPtUnaryNode node) throws IllegalActionException
- Specified by:
visitUnaryNodein interfaceParseTreeVisitor- Overrides:
visitUnaryNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
_childrenAreConstant
protected boolean _childrenAreConstant(ASTPtRootNode node)
Return true if all of the children of this node are constant.- Parameters:
node- the node- Returns:
- True if all of the children of this node are constant.
-
_defaultVisit
protected void _defaultVisit(ASTPtRootNode node) throws IllegalActionException
- Throws:
IllegalActionException
-
_replaceConstantNode
protected void _replaceConstantNode(ASTPtRootNode node) throws IllegalActionException
- Throws:
IllegalActionException
-
-