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(Object name, ClassType type) {
14: super ();
15: addDeclaration(name, type);
16: }
17:
18: /** "Convert" a <code>LambdaExp</code> to a <code>CatchClause</code>. */
19: public CatchClause(LambdaExp lexp) {
20: Declaration decl = lexp.firstDecl();
21: lexp.remove(null, decl);
22: add(decl);
23: body = lexp.body;
24: }
25:
26: public final CatchClause getNext() {
27: return next;
28: }
29:
30: public final void setNext(CatchClause next) {
31: this .next = next;
32: }
33:
34: public final Expression getBody() {
35: return body;
36: }
37:
38: public final void setBody(Expression body) {
39: this .body = body;
40: }
41:
42: protected boolean mustCompile() {
43: return true;
44: }
45:
46: public void compile(Compilation comp, Target target) {
47: gnu.bytecode.CodeAttr code = comp.getCode();
48: Declaration catchDecl = firstDecl();
49: Variable catchVar = catchDecl.allocateVariable(code);
50: code.enterScope(getVarScope());
51: code.emitCatchStart(catchVar);
52: body.compileWithPosition(comp, target);
53: code.emitCatchEnd();
54: code.popScope();
55: }
56:
57: protected void walkChildren(ExpWalker walker) {
58: body = walker.walk(body);
59: }
60:
61: public void print(OutPort out) {
62: out.writeSpaceLinear();
63: out.startLogicalBlock("(Catch", ")", 2);
64: out.writeSpaceFill();
65: decls.printInfo(out);
66: out.writeSpaceLinear();
67: body.print(out);
68: out.endLogicalBlock(")");
69: }
70: }
|