1 package polyglot.ext.jl.ast; 2 3 import polyglot.ast.*; 4 5 import polyglot.util.*; 6 import polyglot.types.*; 7 import polyglot.visit.*; 8 import java.util.*; 9 10 15 public class Throw_c extends Stmt_c implements Throw 16 { 17 protected Expr expr; 18 19 public Throw_c(Position pos, Expr expr) { 20 super(pos); 21 this.expr = expr; 22 } 23 24 25 public Expr expr() { 26 return this.expr; 27 } 28 29 30 public Throw expr(Expr expr) { 31 Throw_c n = (Throw_c) copy(); 32 n.expr = expr; 33 return n; 34 } 35 36 37 protected Throw_c reconstruct(Expr expr) { 38 if (expr != this.expr) { 39 Throw_c n = (Throw_c) copy(); 40 n.expr = expr; 41 return n; 42 } 43 44 return this; 45 } 46 47 48 public Node visitChildren(NodeVisitor v) { 49 Expr expr = (Expr) visitChild(this.expr, v); 50 return reconstruct(expr); 51 } 52 53 54 public Node typeCheck(TypeChecker tc) throws SemanticException { 55 if (! expr.type().isThrowable()) { 56 throw new SemanticException( 57 "Can only throw subclasses of \"" + 58 tc.typeSystem().Throwable() + "\".", expr.position()); 59 } 60 61 return this; 62 } 63 64 public Type childExpectedType(Expr child, AscriptionVisitor av) { 65 TypeSystem ts = av.typeSystem(); 66 67 if (child == expr) { 68 return ts.Throwable(); 69 } 70 71 return child.type(); 72 } 73 74 public String toString() { 75 return "throw " + expr + ";"; 76 } 77 78 79 public void prettyPrint(CodeWriter w, PrettyPrinter tr) { 80 w.write("throw "); 81 print(expr, w, tr); 82 w.write(";"); 83 } 84 85 public Term entry() { 86 return expr.entry(); 87 } 88 89 public List acceptCFG(CFGBuilder v, List succs) { 90 v.visitCFG(expr, this); 91 92 return Collections.EMPTY_LIST; 94 } 95 96 public List throwTypes(TypeSystem ts) { 97 return CollectionUtil.list(expr.type(), ts.NullPointerException()); 100 } 101 } 102 | Popular Tags |