KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > ReturnBlock


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

19
20 package jode.flow;
21 import jode.decompiler.TabbedPrintWriter;
22 import jode.expr.Expression;
23
24 /**
25  * This is the structured block for a Return block.
26  */

27 public class ReturnBlock extends InstructionContainer {
28     /**
29      * The loads that are on the stack before instr is executed.
30      */

31     VariableStack stack;
32
33     public ReturnBlock() {
34     super(null);
35     }
36
37     public ReturnBlock(Expression instr) {
38         super(instr, new Jump(FlowBlock.END_OF_METHOD));
39     }
40
41     /**
42      * This does take the instr into account and modifies stack
43      * accordingly. It then calls super.mapStackToLocal.
44      * @param stack the stack before the instruction is called
45      * @return stack the stack afterwards.
46      */

47     public VariableStack mapStackToLocal(VariableStack stack) {
48     VariableStack newStack = stack;
49     if (instr != null) {
50         int params = instr.getFreeOperandCount();
51         if (params > 0) {
52         this.stack = stack.peek(params);
53         newStack = stack.pop(params);
54         }
55     }
56     if (jump != null)
57         jump.stackMap = newStack;
58     return null;
59     }
60
61     public void removePush() {
62     if (stack != null)
63         instr = stack.mergeIntoExpression(instr);
64     }
65
66     /**
67      * Tells if this block needs braces when used in a if or while block.
68      * @return true if this block should be sorrounded by braces.
69      */

70     public boolean needsBraces() {
71         return declare != null && !declare.isEmpty();
72     }
73
74     public void dumpInstruction(TabbedPrintWriter writer)
75     throws java.io.IOException JavaDoc
76     {
77         writer.print("return");
78     if (instr != null) {
79         writer.print(" ");
80         instr.dumpExpression(writer.IMPL_PAREN, writer);
81     }
82     writer.println(";");
83     }
84 }
85
Popular Tags