public class AscriptionVisitor extends ContextVisitor
ascribe()
method, which allows AST translations based on the expression
and also the type that is expected. For the base translation (standard
Java), the type of the expression and the type that is expected
are the same. Language extensions however may not have this property,
and can take advantage of the ascribe
method to transform
the AST into a different form that will pass Java type-checking.Modifier and Type | Field and Description |
---|---|
protected AscriptionVisitor |
outer |
protected Type |
type |
context, prune, rethrowMissingDependencies
error, job, nf, ts
bypass, bypassParent
Constructor and Description |
---|
AscriptionVisitor(Job job,
TypeSystem ts,
NodeFactory nf)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
Expr |
ascribe(Expr e,
Type toType)
The
ascribe() method is called for each expression
and is passed the type the expression is used at rather
than the type the type
checker assigns to it. |
NodeVisitor |
enterCall(Node parent,
Node n)
Sets up the expected type information for later calls to
ascribe() . |
JLang |
lang() |
Node |
leaveCall(Node old,
Node n,
NodeVisitor v)
Calls
ascribe() with the expected type and expression
as appropriate. |
AscriptionVisitor |
pop() |
Type |
toType()
Returns the type that is expected of the expression that is being
visited.
|
addDecls, addDecls, begin, context, context, enter, enter, enterScope, leave, rethrowMissingDependencies, superEnter
catchErrors, enterCall, enterError, errorQueue, hasErrors, job, leaveCall, leaveCall, nodeFactory, typeSystem
bypass, bypass, bypassChildren, override, visitChildren
copy, finish, finish, leave, override, toString, visitEdge, visitEdgeNoOverride
protected Type type
protected AscriptionVisitor outer
public AscriptionVisitor(Job job, TypeSystem ts, NodeFactory nf)
ErrorHandingVisitor
for more details.public JLang lang()
lang
in class NodeVisitor
public AscriptionVisitor pop()
public Type toType()
public NodeVisitor enterCall(Node parent, Node n) throws SemanticException
ascribe()
. Other than that, plays the same role
as the enterCall
method in
ErrorHandlingVisitor
.enterCall
in class ErrorHandlingVisitor
n
- The root of the subtree to be traversed.ErrorHandlingVisitor
which should be
used to visit the children of n
.SemanticException
NodeVisitor.enter(Node, Node)
public Expr ascribe(Expr e, Type toType) throws SemanticException
ascribe()
method is called for each expression
and is passed the type the expression is used at rather
than the type the type
checker assigns to it.
For instance, with the following code:
Object o = new Integer(3);
ascribe()
will be called with expression
new Integer(3)
and type Object
.e
- The expression that is being visitedtoType
- The type that the parent node is expecting.SemanticException
public Node leaveCall(Node old, Node n, NodeVisitor v) throws SemanticException
ascribe()
with the expected type and expression
as appropriate. Otherwise functionally the same as the
leaveCall
method in ErrorHandlingVisitor
.leaveCall
in class ErrorHandlingVisitor
SemanticException