Package ptolemy.data.expr
Class CParseTreeCodeGenerator
- java.lang.Object
-
- ptolemy.data.expr.AbstractParseTreeVisitor
-
- ptolemy.data.expr.CParseTreeCodeGenerator
-
- All Implemented Interfaces:
ParseTreeVisitor
public class CParseTreeCodeGenerator extends AbstractParseTreeVisitor
This class visits parse trees and generates soot instructions that evaluate the parse tree.- Since:
- Ptolemy II 4.0
- 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 int_nodeNumberThe node number, used to create unique node names.protected java.util.HashMap_nodeToLocalNameA map from node to local node name.
-
Constructor Summary
Constructors Constructor Description CParseTreeCodeGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_assert(boolean flag, ASTPtRootNode node, java.lang.String message)Assert that the given boolean value, which describes the given parse tree node is true.protected void_generateAllChildren(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_generateChild(ASTPtRootNode node, int i)Visit the child with the given index of the given node.protected java.lang.String_getLocalNameForName(java.lang.String name)Get the local name for this this name.protected boolean_isValidName(java.lang.String name)Return true if the name is a valid name.voidgenerateCode(ASTPtRootNode node)Generate code for a node.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, _visitAllChildren, _visitChild, visitAssignmentNode, visitUnionConstructNode
-
-
-
-
Method Detail
-
generateCode
public void generateCode(ASTPtRootNode node) throws IllegalActionException
Generate code for a node.- Parameters:
node- The node for which code is generated.- Throws:
IllegalActionException- If type inference fails.
-
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
-
visitFunctionalIfNode
public void visitFunctionalIfNode(ASTPtFunctionalIfNode node) throws IllegalActionException
- Specified by:
visitFunctionalIfNodein interfaceParseTreeVisitor- Overrides:
visitFunctionalIfNodein classAbstractParseTreeVisitor- Throws:
IllegalActionException
-
visitFunctionDefinitionNode
public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node) throws IllegalActionException
- Specified by:
visitFunctionDefinitionNodein interfaceParseTreeVisitor- Overrides:
visitFunctionDefinitionNodein 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
-
_assert
protected void _assert(boolean flag, ASTPtRootNode node, java.lang.String message)Assert that the given boolean value, which describes the given parse tree node is true. If it is false, then throw a new InternalErrorException that describes the node that includes the given message.- Parameters:
flag- The value to be checked. If false, then an InternalErrorException is thrown.node- The node.message- The error message to be included in the exception if the flag parameter is false.
-
_generateAllChildren
protected void _generateAllChildren(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.- Parameters:
node- The node.- Throws:
IllegalActionException- If thrown while generating a child.
-
_generateChild
protected void _generateChild(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.- Parameters:
node- The node.i- The index of the child to be visited.- Throws:
IllegalActionException- If thrown while visiting a child node.
-
_getLocalNameForName
protected java.lang.String _getLocalNameForName(java.lang.String name) throws IllegalActionExceptionGet the local name for this this name.- Parameters:
name- The name to be looked up.- Returns:
- The local name.
- Throws:
IllegalActionException- Always thrown in this base class.
-
_isValidName
protected boolean _isValidName(java.lang.String name) throws IllegalActionExceptionReturn true if the name is a valid name. This base class always returns false.- Parameters:
name- The name to be looked up.- Returns:
- True if the name is valid. This base class always returns false.
- Throws:
IllegalActionException- Not thrown in this base class.
-
-