ptolemy.copernicus.java
Class ParseTreeCodeGenerator

java.lang.Object
  extended by ptolemy.data.expr.AbstractParseTreeVisitor
      extended by ptolemy.copernicus.java.ParseTreeCodeGenerator
All Implemented Interfaces:
ParseTreeVisitor

public class ParseTreeCodeGenerator
extends AbstractParseTreeVisitor

This class visits parse trees and generates soot instructions that evaluate the parse tree.

Since:
Ptolemy II 2.1
Version:
$Id: ParseTreeCodeGenerator.java,v 1.71 2008/01/24 00:33:50 cxh Exp $
Author:
Steve Neuendorffer
See Also:
ASTPtRootNode
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (neuendor)

Field Summary
protected  soot.jimple.JimpleBody _body
          The code body under construction.
protected  soot.Unit _insertPoint
          The insertion point.
protected  java.util.HashMap _nodeToLocal
          A map from the node to the local variable.
protected  CodeGenerationScope _scope
          The scope of the parse tree.
protected  soot.util.Chain _units
          The units of the parse tree.
 
Constructor Summary
ParseTreeCodeGenerator()
           
 
Method Summary
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 _debug(ASTPtRootNode node)
          Print a debugging message.
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  soot.Local _getChildTokensLocal(int start, ASTPtRootNode node)
          Create a new local that references an array of tokens.
protected  soot.Local _getLocalForName(java.lang.String name)
           
protected  boolean _isValidName(java.lang.String name)
           
 soot.Local generateCode(ASTPtRootNode node, soot.jimple.JimpleBody body, CodeGenerationScope scope)
           
 soot.Local generateCode(ASTPtRootNode node, soot.jimple.JimpleBody body, soot.Unit insertPoint, CodeGenerationScope scope)
           
 void visitArrayConstructNode(ASTPtArrayConstructNode node)
           
 void visitBitwiseNode(ASTPtBitwiseNode node)
           
 void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
           
 void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
           
 void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
           
 void visitLeafNode(ASTPtLeafNode node)
           
 void visitLogicalNode(ASTPtLogicalNode node)
           
 void visitMatrixConstructNode(ASTPtMatrixConstructNode node)
           
 void visitMethodCallNode(ASTPtMethodCallNode node)
           
 void visitPowerNode(ASTPtPowerNode node)
           
 void visitProductNode(ASTPtProductNode node)
           
 void visitRecordConstructNode(ASTPtRecordConstructNode node)
           
 void visitRelationalNode(ASTPtRelationalNode node)
           
 void visitShiftNode(ASTPtShiftNode node)
           
 void visitSumNode(ASTPtSumNode node)
           
 void visitUnaryNode(ASTPtUnaryNode node)
           
 
Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode, visitUnionConstructNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_nodeToLocal

protected java.util.HashMap _nodeToLocal
A map from the node to the local variable.


_body

protected soot.jimple.JimpleBody _body
The code body under construction.


_units

protected soot.util.Chain _units
The units of the parse tree.


_scope

protected CodeGenerationScope _scope
The scope of the parse tree.


_insertPoint

protected soot.Unit _insertPoint
The insertion point.

Constructor Detail

ParseTreeCodeGenerator

public ParseTreeCodeGenerator()
Method Detail

generateCode

public soot.Local generateCode(ASTPtRootNode node,
                               soot.jimple.JimpleBody body,
                               CodeGenerationScope scope)
                        throws IllegalActionException
Throws:
IllegalActionException

generateCode

public soot.Local generateCode(ASTPtRootNode node,
                               soot.jimple.JimpleBody body,
                               soot.Unit insertPoint,
                               CodeGenerationScope scope)
                        throws IllegalActionException
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

visitFunctionalIfNode

public void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
                           throws IllegalActionException
Specified by:
visitFunctionalIfNode in interface ParseTreeVisitor
Overrides:
visitFunctionalIfNode 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

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

_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.


_debug

protected void _debug(ASTPtRootNode node)
Print a debugging message.


_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.

Throws:
IllegalActionException

_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.

Throws:
IllegalActionException

_getLocalForName

protected soot.Local _getLocalForName(java.lang.String name)
                               throws IllegalActionException
Throws:
IllegalActionException

_isValidName

protected boolean _isValidName(java.lang.String name)
                        throws IllegalActionException
Throws:
IllegalActionException

_getChildTokensLocal

protected soot.Local _getChildTokensLocal(int start,
                                          ASTPtRootNode node)
Create a new local that references an array of tokens. The array will have the size of the number of children of the given node, minus the given start position. Add code to the body to initialize and populate the array.