public class ParseTreeTypeInference extends AbstractParseTreeVisitor
ASTPtRootNode
Yellow (neuendor) |
Green (neuendor) |
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, visitUnionConstructNode
protected Type _inferredChildType
protected ParserScope _scope
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 ParseTreeVisitor
visitArrayConstructNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitBitwiseNode(ASTPtBitwiseNode node) throws IllegalActionException
visitBitwiseNode
in interface ParseTreeVisitor
visitBitwiseNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) throws IllegalActionException
visitFunctionApplicationNode
in interface ParseTreeVisitor
visitFunctionApplicationNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitFunctionDefinitionNode(ASTPtFunctionDefinitionNode node) throws IllegalActionException
visitFunctionDefinitionNode
in interface ParseTreeVisitor
visitFunctionDefinitionNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitFunctionalIfNode(ASTPtFunctionalIfNode node) throws IllegalActionException
visitFunctionalIfNode
in interface ParseTreeVisitor
visitFunctionalIfNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitLeafNode(ASTPtLeafNode node) throws IllegalActionException
visitLeafNode
in interface ParseTreeVisitor
visitLeafNode
in class AbstractParseTreeVisitor
node
- 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 ParseTreeVisitor
visitLogicalNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitMatrixConstructNode(ASTPtMatrixConstructNode node) throws IllegalActionException
visitMatrixConstructNode
in interface ParseTreeVisitor
visitMatrixConstructNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitMethodCallNode(ASTPtMethodCallNode node) throws IllegalActionException
visitMethodCallNode
in interface ParseTreeVisitor
visitMethodCallNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitPowerNode(ASTPtPowerNode node) throws IllegalActionException
visitPowerNode
in interface ParseTreeVisitor
visitPowerNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitProductNode(ASTPtProductNode node) throws IllegalActionException
visitProductNode
in interface ParseTreeVisitor
visitProductNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitRecordConstructNode(ASTPtRecordConstructNode node) throws IllegalActionException
visitRecordConstructNode
in interface ParseTreeVisitor
visitRecordConstructNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException
visitRelationalNode
in interface ParseTreeVisitor
visitRelationalNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitShiftNode(ASTPtShiftNode node) throws IllegalActionException
visitShiftNode
in interface ParseTreeVisitor
visitShiftNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitSumNode(ASTPtSumNode node) throws IllegalActionException
visitSumNode
in interface ParseTreeVisitor
visitSumNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.public void visitUnaryNode(ASTPtUnaryNode node) throws IllegalActionException
visitUnaryNode
in interface ParseTreeVisitor
visitUnaryNode
in class AbstractParseTreeVisitor
node
- The specified node.IllegalActionException
- If an inference error occurs.protected void _assert(boolean flag, ASTPtRootNode node, java.lang.String message)
protected Type _getMethodReturnType(java.lang.Class<?> clazz, java.lang.String methodName, Type[] argTypes) throws IllegalActionException
IllegalActionException
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 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)