KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > JsrBlock


1 /* JsrBlock 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: JsrBlock.java,v 4.7.4.2 2002/05/28 17:34:09 hoenicke Exp $
18  */

19
20 package jode.flow;
21 import jode.decompiler.LocalInfo;
22 import jode.type.Type;
23
24 /**
25  * This block represents a jsr instruction. A jsr instruction is
26  * used to call the finally block, or to call the monitorexit block in
27  * a synchronized block.
28  *
29  * @author Jochen Hoenicke
30  */

31 public class JsrBlock extends StructuredBlock {
32     /**
33      * The inner block that jumps to the subroutine.
34      */

35     StructuredBlock innerBlock;
36     boolean good = false;
37
38     public JsrBlock(Jump subroutine, Jump next) {
39     innerBlock = new EmptyBlock(subroutine);
40     innerBlock.outer = this;
41     setJump(next);
42     }
43     
44     public void setGood(boolean g) {
45     good = g;
46     }
47
48     public boolean isGood() {
49     return good;
50     }
51
52     /* The implementation of getNext[Flow]Block is the standard
53      * implementation */

54
55     /**
56      * Replaces the given sub block with a new block.
57      * @param oldBlock the old sub block.
58      * @param newBlock the new sub block.
59      * @return false, if oldBlock wasn't a direct sub block.
60      */

61     public boolean replaceSubBlock(StructuredBlock oldBlock,
62                    StructuredBlock newBlock) {
63         if (innerBlock == oldBlock)
64             innerBlock = newBlock;
65         else
66             return false;
67         return true;
68     }
69
70     /**
71      * This is called after the analysis is completely done. It
72      * will remove all PUSH/stack_i expressions, (if the bytecode
73      * is correct). <p>
74      * The default implementation merges the stack after each sub block.
75      * This may not be, what you want. <p>
76      *
77      * @param initialStack the stackmap at begin of the block
78      * @return the stack after the block has executed.
79      * @throw RuntimeException if something did get wrong.
80      */

81     public VariableStack mapStackToLocal(VariableStack stack) {
82     /* There shouldn't be any JSR blocks remaining, but who knows.
83      */

84     /* The innerBlock is startet with a new stack entry (return address)
85      * It should GOTO immediately and never complete.
86      */

87     LocalInfo retAddr = new LocalInfo();
88     retAddr.setType(Type.tUObject);
89     innerBlock.mapStackToLocal(stack.push(retAddr));
90     if (jump != null) {
91         jump.stackMap = stack;
92         return null;
93     }
94     return stack;
95     }
96
97     /**
98      * Returns all sub block of this structured block.
99      */

100     public StructuredBlock[] getSubBlocks() {
101     return new StructuredBlock[] { innerBlock };
102     }
103
104     public void dumpInstruction(jode.decompiler.TabbedPrintWriter writer)
105         throws java.io.IOException JavaDoc
106     {
107     writer.println("JSR");
108     writer.tab();
109     innerBlock.dumpSource(writer);
110     writer.untab();
111     }
112 }
113
Popular Tags