polyglot.ext.pao.visit
Class PaoBoxer
java.lang.Object
polyglot.visit.NodeVisitor
polyglot.visit.HaltingVisitor
polyglot.visit.ErrorHandlingVisitor
polyglot.visit.ContextVisitor
polyglot.visit.AscriptionVisitor
polyglot.ext.pao.visit.PaoBoxer
- All Implemented Interfaces:
- java.lang.Cloneable, Copy
public class PaoBoxer
- extends AscriptionVisitor
Visitor that inserts boxing and unboxing code into the AST.
PaoBoxer
accomplishes this task by first inserting explicit
casts into the AST, where primitive values need to be treated as objects,
and then uses the PaoExt.rewrite(PaoTypeSystem, NodeFactory)
method to rewrite these explicit casts into appropriate boxing and
unboxing code.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
PaoBoxer
public PaoBoxer(Job job,
TypeSystem ts,
NodeFactory nf)
ascribe
public Expr ascribe(Expr e,
Type toType)
- Inserts an explicit cast if the type of expressions
e
is
a primitive type, and the type toType
is a reference type.
For example, Integer i = 42
will be modified to
Integer i = (Object)42
. The leaveCall
method
will ensure that these explicit casts are rewritten to the correct
boxing and unboxing code.
- Overrides:
ascribe
in class AscriptionVisitor
- Parameters:
e
- The expression that is being visitedtoType
- The type that the parent node is expecting.
- Returns:
- The new translated Expr node, or if nothing has changed, just
e.
leaveCall
public Node leaveCall(Node old,
Node n,
NodeVisitor v)
throws SemanticException
- Calls the
PaoExt.rewrite(PaoTypeSystem, NodeFactory)
method to rewrite the explicit casts inserted by the
ascribe
method into correct boxing and unboxing code.
- Overrides:
leaveCall
in class AscriptionVisitor
- Parameters:
old
- The original state of root of the current subtree.n
- The current state of the root of the current subtree.v
- The NodeVisitor
object used to visit the children.
- Returns:
- The final result of the traversal of the tree rooted at
n
.
- Throws:
SemanticException
- See Also:
NodeVisitor.leave(Node, Node, NodeVisitor)