KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > BreakBlock


1 /* BreakBlock Copyright (C) 1998-2002 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; see the file COPYING.LESSER. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: BreakBlock.java,v 3.7.4.1 2002/05/28 17:34:08 hoenicke Exp $
18  */

19
20 package jode.flow;
21 import jode.decompiler.TabbedPrintWriter;
22
23 /**
24  *
25  */

26 public class BreakBlock extends StructuredBlock {
27     StructuredBlock breaksBlock;
28     String JavaDoc label;
29
30     public BreakBlock(BreakableBlock breaksBlock, boolean needsLabel) {
31         this.breaksBlock = (StructuredBlock) breaksBlock;
32         breaksBlock.setBreaked();
33         if (needsLabel)
34             label = breaksBlock.getLabel();
35         else
36             label = null;
37     }
38
39     public void checkConsistent() {
40         super.checkConsistent();
41         StructuredBlock sb = outer;
42         while (sb != breaksBlock) {
43             if (sb == null)
44                 throw new RuntimeException JavaDoc("Inconsistency");
45             sb = sb.outer;
46         }
47     }
48
49     /**
50      * Tells if this block is empty and only changes control flow.
51      */

52     public boolean isEmpty() {
53         return true;
54     }
55
56     /**
57      * Returns the block where the control will normally flow to, when
58      * this block is finished.
59      */

60     public StructuredBlock getNextBlock() {
61         return breaksBlock.getNextBlock();
62     }
63
64     /**
65      * Returns the flow block where the control will normally flow to,
66      * when this block is finished (not ignoring the jump after this
67      * block).
68      * @return null, if the control flows into a non empty structured
69      * block or if this is the outermost block.
70      */

71     public FlowBlock getNextFlowBlock() {
72         return breaksBlock.getNextFlowBlock();
73     }
74
75     /**
76      * This is called after the analysis is completely done. It
77      * will remove all PUSH/stack_i expressions, (if the bytecode
78      * is correct).
79      * @param stack the stackmap at begin of the block
80      * @return null since the stack has no successor.
81      */

82     public VariableStack mapStackToLocal(VariableStack stack) {
83     ((BreakableBlock)breaksBlock).mergeBreakedStack(stack);
84     return null;
85     }
86
87     /**
88      * Tells if this block needs braces when used in a if or while block.
89      * @return true if this block should be sorrounded by braces.
90      */

91     public boolean needsBraces() {
92         return false;
93     }
94
95     public void dumpInstruction(TabbedPrintWriter writer)
96     throws java.io.IOException JavaDoc
97     {
98         writer.println("break"+(label == null ? "" : " "+label) + ";");
99     }
100
101     public boolean jumpMayBeChanged() {
102         return true;
103     }
104 }
105
Popular Tags