1 package polyglot.visit; 2 3 import polyglot.ast.*; 4 import polyglot.types.*; 5 import polyglot.util.*; 6 import polyglot.frontend.Job; 7 import java.util.*; 8 9 22 public class AscriptionVisitor extends ContextVisitor 23 { 24 Type type; 25 AscriptionVisitor outer; 26 27 33 public AscriptionVisitor(Job job, TypeSystem ts, NodeFactory nf) { 34 super(job, ts, nf); 35 type = null; 36 outer = null; 37 } 38 39 42 public AscriptionVisitor pop() { 43 return outer; 44 } 45 46 49 public Type toType() { 50 return type; 51 } 52 53 59 public NodeVisitor enterCall(Node parent, Node n) throws SemanticException { 60 Type t = null; 61 62 if (parent != null && n instanceof Expr) { 63 t = parent.childExpectedType((Expr) n, this); 64 } 65 66 AscriptionVisitor v = (AscriptionVisitor) copy(); 67 v.outer = this; 68 v.type = t; 69 70 return v; 71 } 72 73 90 public Expr ascribe(Expr e, Type toType) throws SemanticException { 91 return e; 92 } 93 94 99 public Node leaveCall(Node old, Node n, NodeVisitor v) 100 throws SemanticException { 101 102 if (n instanceof Expr) { 103 Expr e = (Expr) n; 104 Type type = ((AscriptionVisitor) v).type; 105 return ascribe(e, type); 106 } 107 108 return n; 109 } 110 } 111 | Popular Tags |