public class ParseTreeTypeInference extends AbstractParseTreeVisitor
ASTPtRootNode| Modifier and Type | Field and Description |
|---|---|
protected Type |
_inferredChildType |
protected ParserScope |
_scope |
| Constructor and Description |
|---|
ParseTreeTypeInference() |
| Modifier and Type | Method and 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 Type |
_getMethodReturnType(java.lang.Class<?> clazz,
java.lang.String methodName,
Type[] argTypes)
Get the return type of a method belonging to the specified class, or the
type of a field belonging to it.
|
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 Type |
_methodCall(java.lang.String methodName,
Type[] argTypes)
Infer the type of the specified method.
|
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.
|
_unsupportedVisitException, _visitAllChildren, _visitChild, visitAssignmentNode, visitUnionConstructNodeprotected Type _inferredChildType
protected ParserScope _scope
public ParseTreeTypeInference()
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)
flag - If false, then throw an InternalErrorExceptionnode - The nodemessage - The message included in the exceptionprotected Type _getMethodReturnType(java.lang.Class<?> clazz, java.lang.String methodName, Type[] argTypes) throws IllegalActionException
IllegalActionExceptionprotected Type _getTypeForName(java.lang.String name) throws IllegalActionException
IllegalActionException - If the identifier is undefined.protected Type[] _inferAllChildren(ASTPtRootNode node) throws IllegalActionException
IllegalActionExceptionprotected Type _inferChild(ASTPtRootNode node, int i) throws IllegalActionException
IllegalActionExceptionprotected boolean _isValidName(java.lang.String name) throws IllegalActionException
IllegalActionExceptionprotected Type _methodCall(java.lang.String methodName, Type[] argTypes) throws IllegalActionException
methodName - The method name.argTypes - An array of argument types.IllegalActionException - If an evaluation error occurs.ParseTreeEvaluator._methodCall(String, Type[], Object[])protected void _setType(ASTPtRootNode node, Type type)