ptolemy.data.expr
Class ParseTreeSpecializer
java.lang.Object
extended byptolemy.data.expr.AbstractParseTreeVisitor
extended byptolemy.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: ParseTreeSpecializer.java,v 1.29 2005年07月08日 19:57:32 cxh Exp $
- Author:
- Steve Neuendorffer
- See Also:
ASTPtRootNode
- Accepted Rating:
Red (cxh)
- Proposed Rating:
Red (neuendor)
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_excludedNames
protected java.util.List _excludedNames
_result
protected ASTPtRootNode _result
_scope
protected ParserScope _scope
_evaluator
protected ParseTreeEvaluator _evaluator
ParseTreeSpecializer
public ParseTreeSpecializer()
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.
- Throws:
IllegalActionException
visitArrayConstructNode
public void visitArrayConstructNode(ASTPtArrayConstructNode node)
throws IllegalActionException
- Specified by:
visitArrayConstructNode in interface ParseTreeVisitor- Overrides:
visitArrayConstructNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitBitwiseNode
public void visitBitwiseNode(ASTPtBitwiseNode node)
throws IllegalActionException
- Specified by:
visitBitwiseNode in interface ParseTreeVisitor- Overrides:
visitBitwiseNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitFunctionApplicationNode
public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
throws IllegalActionException
- Specified by:
visitFunctionApplicationNode in interface ParseTreeVisitor- Overrides:
visitFunctionApplicationNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitFunctionDefinitionNode
public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
throws IllegalActionException
- Specified by:
visitFunctionDefinitionNode in interface ParseTreeVisitor- Overrides:
visitFunctionDefinitionNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitFunctionalIfNode
public void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
throws IllegalActionException
- Specified by:
visitFunctionalIfNode in interface ParseTreeVisitor- Overrides:
visitFunctionalIfNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitLeafNode
public void visitLeafNode(ASTPtLeafNode node)
throws IllegalActionException
- Specified by:
visitLeafNode in interface ParseTreeVisitor- Overrides:
visitLeafNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitLogicalNode
public void visitLogicalNode(ASTPtLogicalNode node)
throws IllegalActionException
- Specified by:
visitLogicalNode in interface ParseTreeVisitor- Overrides:
visitLogicalNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitMatrixConstructNode
public void visitMatrixConstructNode(ASTPtMatrixConstructNode node)
throws IllegalActionException
- Specified by:
visitMatrixConstructNode in interface ParseTreeVisitor- Overrides:
visitMatrixConstructNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitMethodCallNode
public void visitMethodCallNode(ASTPtMethodCallNode node)
throws IllegalActionException
- Specified by:
visitMethodCallNode in interface ParseTreeVisitor- Overrides:
visitMethodCallNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitPowerNode
public void visitPowerNode(ASTPtPowerNode node)
throws IllegalActionException
- Specified by:
visitPowerNode in interface ParseTreeVisitor- Overrides:
visitPowerNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitProductNode
public void visitProductNode(ASTPtProductNode node)
throws IllegalActionException
- Specified by:
visitProductNode in interface ParseTreeVisitor- Overrides:
visitProductNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitRecordConstructNode
public void visitRecordConstructNode(ASTPtRecordConstructNode node)
throws IllegalActionException
- Specified by:
visitRecordConstructNode in interface ParseTreeVisitor- Overrides:
visitRecordConstructNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitRelationalNode
public void visitRelationalNode(ASTPtRelationalNode node)
throws IllegalActionException
- Specified by:
visitRelationalNode in interface ParseTreeVisitor- Overrides:
visitRelationalNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitShiftNode
public void visitShiftNode(ASTPtShiftNode node)
throws IllegalActionException
- Specified by:
visitShiftNode in interface ParseTreeVisitor- Overrides:
visitShiftNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitSumNode
public void visitSumNode(ASTPtSumNode node)
throws IllegalActionException
- Specified by:
visitSumNode in interface ParseTreeVisitor- Overrides:
visitSumNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
visitUnaryNode
public void visitUnaryNode(ASTPtUnaryNode node)
throws IllegalActionException
- Specified by:
visitUnaryNode in interface ParseTreeVisitor- Overrides:
visitUnaryNode in class AbstractParseTreeVisitor
- Throws:
IllegalActionException
_childrenAreConstant
protected boolean _childrenAreConstant(ASTPtRootNode node)
- Return 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