01: package gnu.expr;
02:
03: import gnu.bytecode.*;
04: import gnu.mapping.OutPort;
05:
06: /** A "catch" clause of a "try-catch" form.
07: */
08:
09: public class CatchClause extends ScopeExp {
10: Expression body;
11: CatchClause next;
12:
13: public CatchClause(String name, ClassType type) {
14: super ();
15: addDeclaration(name, type);
16: }
17:
18: public final CatchClause getNext() {
19: return next;
20: }
21:
22: public final void setNext(CatchClause next) {
23: this .next = next;
24: }
25:
26: public final Expression getBody() {
27: return body;
28: }
29:
30: public final void setBody(Expression body) {
31: this .body = body;
32: }
33:
34: public final Declaration getDeclaration() {
35: return firstDecl();
36: }
37:
38: public void compile(Compilation comp, Target target) {
39: gnu.bytecode.CodeAttr code = comp.getCode();
40: Declaration catchDecl = firstDecl();
41: Variable catchVar = catchDecl.allocateVariable(code);
42: code.enterScope(scope);
43: code.emitCatchStart((ClassType) catchDecl.getType());
44: catchDecl.compileStore(comp);
45: body.compileWithPosition(comp, target);
46: code.emitCatchEnd();
47: code.popScope();
48: }
49:
50: protected void walkChildren(ExpWalker walker) {
51: body = body.walk(walker);
52: }
53:
54: public void print(OutPort ps) {
55: ps.print("(Catch ? ");
56: body.print(ps);
57: ps.print(")");
58: }
59: }
|