KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jode > flow > InstructionContainer


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

19
20 package jode.flow;
21 import jode.decompiler.LocalInfo;
22 import jode.expr.Expression;
23 import jode.expr.InvokeOperator;
24 import jode.expr.LocalVarOperator;
25 import jode.util.SimpleSet;
26
27 import java.util.Set JavaDoc;
28
29 /**
30  * This is a method for block containing a single instruction.
31  */

32 public abstract class InstructionContainer extends StructuredBlock {
33     /**
34      * The instruction.
35      */

36     Expression instr;
37
38     public InstructionContainer(Expression instr) {
39         this.instr = instr;
40     }
41
42     public InstructionContainer(Expression instr, Jump jump) {
43     this(instr);
44         setJump(jump);
45     }
46
47     /**
48      * Make the declarations, i.e. initialize the declare variable
49      * to correct values. This will declare every variable that
50      * is marked as used, but not done.<br>
51      *
52      * This will now also combine locals, that use the same slot, have
53      * compatible types and are declared in the same block. <br>
54      *
55      * @param done The set of the already declare variables.
56      */

57     public void makeDeclaration(Set done) {
58     if (instr != null)
59         instr.makeDeclaration(done);
60     super.makeDeclaration(done);
61     }
62
63     /**
64      * This method should remove local variables that are only written
65      * and read one time directly after another. <br>
66      *
67      * This is especially important for stack locals, that are created
68      * when there are unusual swap or dup instructions, but also makes
69      * inlined functions more pretty (but not that close to the
70      * bytecode).
71      */

72     public void removeOnetimeLocals() {
73     if (instr != null)
74         instr = instr.removeOnetimeLocals();
75     super.removeOnetimeLocals();
76     }
77
78     /**
79      * Fill all in variables into the given VariableSet.
80      * @param in The VariableSet, the in variables should be stored to.
81      */

82     public void fillInGenSet(Set in, Set gen) {
83     if (instr != null)
84         instr.fillInGenSet(in, gen);
85     }
86
87     public Set getDeclarables() {
88     Set used = new SimpleSet();
89     if (instr != null)
90         instr.fillDeclarables(used);
91     return used;
92     }
93
94     public boolean doTransformations() {
95     if (instr == null)
96         return false;
97     /* Do on the fly access$ transformation, since some further
98      * operations need this.
99      */

100     if (instr instanceof InvokeOperator) {
101         Expression expr = ((InvokeOperator)instr).simplifyAccess();
102         if (expr != null)
103         instr = expr;
104     }
105         StructuredBlock last = flowBlock.lastModified;
106         return CreateNewConstructor.transform(this, last)
107             || CreateAssignExpression.transform(this, last)
108             || CreateExpression.transform(this, last)
109             || CreatePrePostIncExpression.transform(this, last)
110             || CreateIfThenElseOperator.create(this, last)
111             || CreateConstantArray.transform(this, last)
112         || CreateCheckNull.transformJavac(this, last);
113     }
114
115     /**
116      * Get the contained instruction.
117      * @return the contained instruction.
118      */

119     public final Expression getInstruction() {
120         return instr;
121     }
122
123     public void simplify() {
124     if (instr != null)
125         instr = instr.simplify();
126     super.simplify();
127     }
128
129     /**
130      * Set the contained instruction.
131      * @param instr the new instruction.
132      */

133     public final void setInstruction(Expression instr) {
134         this.instr = instr;
135     }
136 }
137
Popular Tags