1 package gnu.expr; 2 import gnu.bytecode.*; 3 import gnu.mapping.OutPort; 4 5 7 8 public class CatchClause extends ScopeExp 9 { 10 Expression body; 11 CatchClause next; 12 13 public CatchClause (Object name, ClassType type) 14 { 15 super (); 16 addDeclaration (name, type); 17 } 18 19 20 public CatchClause (LambdaExp lexp) 21 { 22 Declaration decl = lexp.firstDecl(); 23 lexp.remove(null, decl); 24 add(decl); 25 body = lexp.body; 26 } 27 28 public final CatchClause getNext() { return next; } 29 public final void setNext (CatchClause next) { this.next = next; } 30 31 public final Expression getBody() { return body; } 32 public final void setBody(Expression body) { this.body = body; } 33 34 protected boolean mustCompile () { return true; } 35 36 public void compile (Compilation comp, Target target) 37 { 38 gnu.bytecode.CodeAttr code = comp.getCode(); 39 Declaration catchDecl = firstDecl(); 40 Variable catchVar = catchDecl.allocateVariable(code); 41 code.enterScope(getVarScope()); 42 code.emitCatchStart(catchVar); 43 body.compileWithPosition(comp, target); 44 code.emitCatchEnd(); 45 code.popScope (); 46 } 47 48 protected void walkChildren(ExpWalker walker) 49 { 50 body = walker.walk(body); 51 } 52 53 public void print (OutPort out) 54 { 55 out.writeSpaceLinear(); 56 out.startLogicalBlock("(Catch", ")", 2); 57 out.writeSpaceFill(); 58 decls.printInfo(out); 59 out.writeSpaceLinear(); 60 body.print(out); 61 out.endLogicalBlock(")"); 62 } 63 } 64 | Popular Tags |