1 package polyglot.ext.pao.visit; 2 3 import polyglot.ast.Expr; 4 import polyglot.ast.Node; 5 import polyglot.ast.NodeFactory; 6 import polyglot.ext.pao.extension.PaoExt; 7 import polyglot.ext.pao.types.PaoTypeSystem; 8 import polyglot.frontend.Job; 9 import polyglot.types.SemanticException; 10 import polyglot.types.Type; 11 import polyglot.types.TypeSystem; 12 import polyglot.util.Position; 13 import polyglot.visit.AscriptionVisitor; 14 import polyglot.visit.NodeVisitor; 15 16 24 public class PaoBoxer extends AscriptionVisitor 25 { 26 public PaoBoxer(Job job, TypeSystem ts, NodeFactory nf) { 27 super(job, ts, nf); 28 } 29 30 38 public Expr ascribe(Expr e, Type toType) { 39 Type fromType = e.type(); 40 41 if (toType == null) { 42 return e; 43 } 44 45 Position p = e.position(); 46 47 if (toType.isReference() && fromType.isPrimitive()) { 50 return nf.Cast(p, nf.CanonicalTypeNode(p, ts.Object()), e); 51 } 52 53 return e; 54 } 55 56 62 public Node leaveCall(Node old, Node n, NodeVisitor v) throws SemanticException { 63 n = super.leaveCall(old, n, v); 64 65 if (n.ext() instanceof PaoExt) { 66 return ((PaoExt) n.ext()).rewrite((PaoTypeSystem) typeSystem(), 67 nodeFactory()); 68 } 69 70 return n; 71 } 72 } 73 | Popular Tags |