|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectptolemy.data.expr.AbstractParseTreeVisitor
ptolemy.data.expr.ParseTreeTypeInference
This class visits parse trees and infers a type for each node in the parse tree. This type is stored in the parse tree.
ASTPtRootNode
| Yellow (neuendor) |
| Green (neuendor) |
| Field Summary | |
protected Type |
_inferredChildType
|
protected ParserScope |
_scope
|
| Constructor Summary | |
ParseTreeTypeInference()
|
|
| 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 Type |
_getTypeForName(java.lang.String name)
Return the type of the identifier with the given name. |
protected Type[] |
_inferAllChildren(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 Type |
_inferChild(ASTPtRootNode node,
int i)
Visit the child with the given index of the given node. |
protected boolean |
_isValidName(java.lang.String name)
Test if the given identifier is valid. |
protected void |
_setType(ASTPtRootNode node,
Type type)
|
Type |
inferTypes(ASTPtRootNode node)
Infer the type of the parse tree with the specified root node. |
Type |
inferTypes(ASTPtRootNode node,
ParserScope scope)
Infer the type of the parse tree with the specified root node using the specified scope to resolve the values of variables. |
void |
visitArrayConstructNode(ASTPtArrayConstructNode node)
Set the type of the given node to be an ArrayType that is the least upper bound of the types of the node's children. |
void |
visitBitwiseNode(ASTPtBitwiseNode node)
Set the type of the given node to be the type that is the least upper bound of the types of the node's children. |
void |
visitFunctionalIfNode(ASTPtFunctionalIfNode node)
Set the type of the given node to be the least upper bound of the types of the two branches of the if. |
void |
visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
Set the type of the given node to be the return type of the function determined for the given node. |
void |
visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
Set the type of the given node to be a function type whose argument types are determined by the children of the node. |
void |
visitLeafNode(ASTPtLeafNode node)
Set the type of the given node to be the type of constant the variable refers to, if the node represents a constant, or the type of the identifier the node refers to in the current scope. |
void |
visitLogicalNode(ASTPtLogicalNode node)
Set the type of the given node to be boolean. |
void |
visitMatrixConstructNode(ASTPtMatrixConstructNode node)
Set the type of the given node to be an MatrixType based on the least upper bound of the types of the node's children. |
void |
visitMethodCallNode(ASTPtMethodCallNode node)
Set the type of the given node to be the return type of the method determined for the given node. |
void |
visitPowerNode(ASTPtPowerNode node)
Set the type of the given node to be the type of the first child of the given node. |
void |
visitProductNode(ASTPtProductNode node)
Set the type of the given node to be the least upper bound type of the types of the node's children. |
void |
visitRecordConstructNode(ASTPtRecordConstructNode node)
Set the type of the given node to be a record token that contains fields for each name in the record construction, where the type of each field in the record is determined by the corresponding type of the child nodes. |
void |
visitRelationalNode(ASTPtRelationalNode node)
Set the type of the given node to be boolean. |
void |
visitShiftNode(ASTPtShiftNode node)
Set the type of the given node to be the type of the first child of the given node. |
void |
visitSumNode(ASTPtSumNode node)
Set the type of the given node to be the least upper bound type of the types of the node's children. |
void |
visitUnaryNode(ASTPtUnaryNode node)
Set the type of the given node to be the type of the child of the given node. |
| Methods inherited from class ptolemy.data.expr.AbstractParseTreeVisitor |
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected ParserScope _scope
protected Type _inferredChildType
| Constructor Detail |
public ParseTreeTypeInference()
| Method Detail |
public Type inferTypes(ASTPtRootNode node)
throws IllegalActionException
node - The root of the parse tree.
IllegalActionException - If an evaluation error occurs.
public Type inferTypes(ASTPtRootNode node,
ParserScope scope)
throws IllegalActionException
node - The root of the parse tree.scope - The scope for evaluation.
IllegalActionException - If an error occurs during
evaluation.
public void visitArrayConstructNode(ASTPtArrayConstructNode node)
throws IllegalActionException
visitArrayConstructNode in interface ParseTreeVisitorvisitArrayConstructNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitBitwiseNode(ASTPtBitwiseNode node)
throws IllegalActionException
visitBitwiseNode in interface ParseTreeVisitorvisitBitwiseNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node)
throws IllegalActionException
visitFunctionApplicationNode in interface ParseTreeVisitorvisitFunctionApplicationNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node)
throws IllegalActionException
visitFunctionDefinitionNode in interface ParseTreeVisitorvisitFunctionDefinitionNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitFunctionalIfNode(ASTPtFunctionalIfNode node)
throws IllegalActionException
visitFunctionalIfNode in interface ParseTreeVisitorvisitFunctionalIfNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitLeafNode(ASTPtLeafNode node)
throws IllegalActionException
visitLeafNode in interface ParseTreeVisitorvisitLeafNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error
occurs, or an identifier is not bound in the current scope.
public void visitLogicalNode(ASTPtLogicalNode node)
throws IllegalActionException
visitLogicalNode in interface ParseTreeVisitorvisitLogicalNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitMatrixConstructNode(ASTPtMatrixConstructNode node)
throws IllegalActionException
visitMatrixConstructNode in interface ParseTreeVisitorvisitMatrixConstructNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitMethodCallNode(ASTPtMethodCallNode node)
throws IllegalActionException
visitMethodCallNode in interface ParseTreeVisitorvisitMethodCallNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitPowerNode(ASTPtPowerNode node)
throws IllegalActionException
visitPowerNode in interface ParseTreeVisitorvisitPowerNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitProductNode(ASTPtProductNode node)
throws IllegalActionException
visitProductNode in interface ParseTreeVisitorvisitProductNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitRecordConstructNode(ASTPtRecordConstructNode node)
throws IllegalActionException
visitRecordConstructNode in interface ParseTreeVisitorvisitRecordConstructNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitRelationalNode(ASTPtRelationalNode node)
throws IllegalActionException
visitRelationalNode in interface ParseTreeVisitorvisitRelationalNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitShiftNode(ASTPtShiftNode node)
throws IllegalActionException
visitShiftNode in interface ParseTreeVisitorvisitShiftNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitSumNode(ASTPtSumNode node)
throws IllegalActionException
visitSumNode in interface ParseTreeVisitorvisitSumNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
public void visitUnaryNode(ASTPtUnaryNode node)
throws IllegalActionException
visitUnaryNode in interface ParseTreeVisitorvisitUnaryNode in class AbstractParseTreeVisitornode - The specified node.
IllegalActionException - If an inference error occurs.
protected void _assert(boolean flag,
ASTPtRootNode node,
java.lang.String message)
protected Type _getTypeForName(java.lang.String name)
throws IllegalActionException
IllegalActionException - If the identifier is undefined.
protected Type[] _inferAllChildren(ASTPtRootNode node)
throws IllegalActionException
IllegalActionException
protected Type _inferChild(ASTPtRootNode node,
int i)
throws IllegalActionException
IllegalActionException
protected boolean _isValidName(java.lang.String name)
throws IllegalActionException
IllegalActionException
protected void _setType(ASTPtRootNode node,
Type type)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||