Package ptolemy.data.expr
Class ParseTreeFreeVariableRenamer
- java.lang.Object
-
- ptolemy.data.expr.AbstractParseTreeVisitor
-
- ptolemy.data.expr.ParseTreeFreeVariableRenamer
-
- All Implemented Interfaces:
ParseTreeVisitor
public class ParseTreeFreeVariableRenamer extends AbstractParseTreeVisitor
This class visits parse trees and renames the free variables that match a specified variable. Use this class prior to changing the name of a variable to update references to the variable.- Since:
- Ptolemy II 5.2
- Version:
- $Id$
- Author:
- Edward A. Lee
- See Also:
ASTPtRootNode- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Yellow (eal)
-
-
Field Summary
Fields Modifier and Type Field Description protected Variable_dependentVariableThe variable to which the parse tree belongs.protected java.util.Set_formalParametersFormal parameters within a function definition.protected java.lang.String_nameThe new name.protected ParserScope_scopeThe scope.protected Variable_variableToRenameThe variable to be renamed.
-
Constructor Summary
Constructors Constructor Description ParseTreeFreeVariableRenamer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Collection_intersection(java.util.Collection collection1, java.util.Collection collection2)Return the intersection of two collections.protected void_visitAllChildren(ASTPtRootNode node)Loop through all of the children of this node, visiting each one of them, which will cause their token value to be determined.protected void_visitChild(ASTPtRootNode node, int i)Visit the child with the given index of the given node.voidrenameVariables(ASTPtRootNode node, Variable dependentVariable, Variable variableToRename, java.lang.String name)Rename the variables, if any, in the dependentVariable that refer to the specified variableToRename.voidvisitArrayConstructNode(ASTPtArrayConstructNode node)voidvisitBitwiseNode(ASTPtBitwiseNode node)voidvisitFunctionalIfNode(ASTPtFunctionalIfNode node)voidvisitFunctionApplicationNode(ASTPtFunctionApplicationNode node)voidvisitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)voidvisitLeafNode(ASTPtLeafNode node)voidvisitLogicalNode(ASTPtLogicalNode node)voidvisitMatrixConstructNode(ASTPtMatrixConstructNode node)voidvisitMethodCallNode(ASTPtMethodCallNode node)voidvisitPowerNode(ASTPtPowerNode node)voidvisitProductNode(ASTPtProductNode node)voidvisitRecordConstructNode(ASTPtRecordConstructNode node)voidvisitRelationalNode(ASTPtRelationalNode node)voidvisitShiftNode(ASTPtShiftNode node)voidvisitSumNode(ASTPtSumNode node)voidvisitUnaryNode(ASTPtUnaryNode node)-
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, visitAssignmentNode, visitUnionConstructNode
-
-
-
-
Field Detail
-
_dependentVariable
protected Variable _dependentVariable
The variable to which the parse tree belongs.
-
_formalParameters
protected java.util.Set _formalParameters
Formal parameters within a function definition.
-
_name
protected java.lang.String _name
The new name.
-
_scope
protected ParserScope _scope
The scope.
-
_variableToRename
protected Variable _variableToRename
The variable to be renamed.
-
-
Method Detail
-
renameVariables
public void renameVariables(ASTPtRootNode node, Variable dependentVariable, Variable variableToRename, java.lang.String name) throws IllegalActionException
Rename the variables, if any, in the dependentVariable that refer to the specified variableToRename.- Parameters:
node- The root node of the parse tree.dependentVariable- The dependent variable.variableToRename- The variable to rename.name- The new name.- Throws:
IllegalActionException- If thrown while visiting the node.
-
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
-
_intersection
protected java.util.Collection _intersection(java.util.Collection collection1, java.util.Collection collection2)Return the intersection of two collections.- Parameters:
collection1- The first collection.collection2- The second collection.- Returns:
- The intersection of two collections.
-
_visitAllChildren
protected void _visitAllChildren(ASTPtRootNode node) throws IllegalActionException
Loop through all of the children of this node, visiting each one of them, which will cause their token value to be determined.- Overrides:
_visitAllChildrenin classAbstractParseTreeVisitor- Parameters:
node- The node whose children are to be looped through.- Throws:
IllegalActionException- If thrown while visiting a child node.
-
_visitChild
protected void _visitChild(ASTPtRootNode node, int i) throws IllegalActionException
Visit the child with the given index of the given node. This is usually called while visiting the given node.- Overrides:
_visitChildin classAbstractParseTreeVisitor- Parameters:
node- The node.i- The index of the child to be visited.- Throws:
IllegalActionException- If thrown while visiting a child node.
-
-