01: // Copyright (c) 1999 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.expr;
05:
06: import gnu.bytecode.*;
07: import gnu.mapping.OutPort;
08:
09: /**
10: * Expression to exit a lexically surrounding block.
11: * @author Per Bothner
12: */
13:
14: public class ExitExp extends Expression {
15: BlockExp block;
16: Expression result;
17:
18: public ExitExp(Expression result, BlockExp block) {
19: this .result = result;
20: this .block = block;
21: }
22:
23: public ExitExp(BlockExp block) {
24: this .result = QuoteExp.voidExp;
25: this .block = block;
26: }
27:
28: public void compile(Compilation comp, Target target) {
29: CodeAttr code = comp.getCode();
30: Expression res = result == null ? QuoteExp.voidExp : result;
31: res.compileWithPosition(comp, block.subTarget);
32: block.exit(code);
33: }
34:
35: protected Expression walk(ExpWalker walker) {
36: return walker.walkExitExp(this );
37: }
38:
39: protected void walkChildren(ExpWalker walker) {
40: result = result.walk(walker);
41: }
42:
43: public void print(OutPort out) {
44: out.startLogicalBlock("(Exit", false, ")");
45: if (block == null || block.label == null)
46: out.print("<unknown>");
47: else
48: out.print(block.label.getName());
49: if (result != null) {
50: out.writeSpaceLinear();
51: result.print(out);
52: }
53: out.endLogicalBlock(")");
54: }
55:
56: public Type getType() {
57: return Type.neverReturnsType;
58: }
59: }
|