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 14 public class Catch_c extends Stmt_c implements Catch 15 { 16 protected Formal formal; 17 protected Block body; 18 19 public Catch_c(Position pos, Formal formal, Block body) { 20 super(pos); 21 this.formal = formal; 22 this.body = body; 23 } 24 25 26 public Type catchType() { 27 return formal.declType(); 28 } 29 30 31 public Formal formal() { 32 return this.formal; 33 } 34 35 36 public Catch formal(Formal formal) { 37 Catch_c n = (Catch_c) copy(); 38 n.formal = formal; 39 return n; 40 } 41 42 43 public Block body() { 44 return this.body; 45 } 46 47 48 public Catch body(Block body) { 49 Catch_c n = (Catch_c) copy(); 50 n.body = body; 51 return n; 52 } 53 54 55 protected Catch_c reconstruct(Formal formal, Block body) { 56 if (formal != this.formal || body != this.body) { 57 Catch_c n = (Catch_c) copy(); 58 n.formal = formal; 59 n.body = body; 60 return n; 61 } 62 63 return this; 64 } 65 66 67 public Node visitChildren(NodeVisitor v) { 68 Formal formal = (Formal) visitChild(this.formal, v); 69 Block body = (Block) visitChild(this.body, v); 70 return reconstruct(formal, body); 71 } 72 73 public Context enterScope(Context c) { 74 return c.pushBlock(); 75 } 76 77 78 public Node typeCheck(TypeChecker tc) throws SemanticException { 79 TypeSystem ts = tc.typeSystem(); 80 81 if (! catchType().isThrowable()) { 82 throw new SemanticException( 83 "Can only throw subclasses of \"" + 84 ts.Throwable() + "\".", formal.position()); 85 86 } 87 88 return this; 89 } 90 91 public String toString() { 92 return "catch (" + formal + ") " + body; 93 } 94 95 96 public void prettyPrint(CodeWriter w, PrettyPrinter tr) { 97 w.write("catch ("); 98 printBlock(formal, w, tr); 99 w.write(")"); 100 printSubStmt(body, w, tr); 101 } 102 103 public Term entry() { 104 return formal.entry(); 105 } 106 107 public List acceptCFG(CFGBuilder v, List succs) { 108 v.visitCFG(formal, body.entry()); 109 v.visitCFG(body, this); 110 return succs; 111 } 112 } 113 | Popular Tags |