polyglot.ext.pao.visit
Class PaoBoxer

java.lang.Object
  extended by polyglot.visit.NodeVisitor
      extended by polyglot.visit.HaltingVisitor
          extended by polyglot.visit.ErrorHandlingVisitor
              extended by polyglot.visit.ContextVisitor
                  extended by polyglot.visit.AscriptionVisitor
                      extended by 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.


Field Summary
 
Fields inherited from class polyglot.visit.ContextVisitor
context
 
Fields inherited from class polyglot.visit.ErrorHandlingVisitor
error, job, nf, ts
 
Constructor Summary
PaoBoxer(Job job, TypeSystem ts, NodeFactory nf)
           
 
Method Summary
 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.
 Node leaveCall(Node old, Node n, NodeVisitor v)
          Calls the PaoExt.rewrite(PaoTypeSystem, NodeFactory) method to rewrite the explicit casts inserted by the ascribe method into correct boxing and unboxing code.
 
Methods inherited from class polyglot.visit.AscriptionVisitor
enterCall, pop, toType
 
Methods inherited from class polyglot.visit.ContextVisitor
addDecls, begin, context, context, enter, enterScope, leave, superEnter
 
Methods inherited from class polyglot.visit.ErrorHandlingVisitor
catchErrors, enterCall, enterError, errorQueue, job, leaveCall, nodeFactory, typeSystem
 
Methods inherited from class polyglot.visit.HaltingVisitor
bypass, bypass, bypassChildren, copy, override, visitChildren
 
Methods inherited from class polyglot.visit.NodeVisitor
enter, finish, finish, leave, override, toString, visitEdge
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PaoBoxer

public PaoBoxer(Job job,
                TypeSystem ts,
                NodeFactory nf)
Method Detail

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 visited
toType - 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)