KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > expr > ExitExp


1 // Copyright (c) 1999, 2006 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.expr;
5 import gnu.bytecode.*;
6 import gnu.mapping.*;
7
8 /**
9  * Expression to exit a lexically surrounding block.
10  * @author Per Bothner
11  */

12
13 public class ExitExp extends Expression
14 {
15   BlockExp block;
16   Expression result;
17
18   public ExitExp(Expression result, BlockExp block)
19   {
20     this.result = result;
21     this.block = block;
22   }
23
24   public ExitExp(BlockExp block)
25   {
26     this.result = QuoteExp.voidExp;
27     this.block = block;
28   }
29
30   protected boolean mustCompile () { return false; }
31
32   public void apply (CallContext ctx) throws Throwable JavaDoc
33   {
34     throw new BlockExitException(this, result.eval(ctx));
35   }
36
37   public void compile (Compilation comp, Target target)
38   {
39     CodeAttr code = comp.getCode();
40     Expression res = result == null ? QuoteExp.voidExp : result;
41     res.compileWithPosition(comp, block.subTarget);
42     code.doPendingFinalizers(block.oldTryState);
43     code.emitGoto(block.exitLabel);
44   }
45
46   protected Expression walk (ExpWalker walker)
47   {
48     return walker.walkExitExp(this);
49   }
50
51   protected void walkChildren (ExpWalker walker)
52   {
53     result = walker.walk(result);
54   }
55
56   public void print (OutPort out)
57   {
58     out.startLogicalBlock("(Exit", false, ")");
59     out.writeSpaceFill();
60     if (block == null || block.label == null)
61       out.print("<unknown>");
62     else
63       out.print(block.label.getName());
64     if (result != null)
65       {
66     out.writeSpaceLinear();
67     result.print(out);
68       }
69     out.endLogicalBlock(")");
70   }
71
72   public Type getType()
73   {
74     return Type.neverReturnsType;
75   }
76 }
77
Popular Tags