001: /* InstructionContainer Copyright (C) 1998-2002 Jochen Hoenicke.
002: *
003: * This program is free software; you can redistribute it and/or modify
004: * it under the terms of the GNU Lesser General Public License as published by
005: * the Free Software Foundation; either version 2, or (at your option)
006: * any later version.
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program; see the file COPYING.LESSER. If not, write to
015: * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
016: *
017: * $Id: InstructionContainer.java.in,v 4.2.2.1 2002/05/28 17:34:09 hoenicke Exp $
018: */
019:
020: package jode.flow;
021:
022: import jode.decompiler.LocalInfo;
023: import jode.expr.Expression;
024: import jode.expr.InvokeOperator;
025: import jode.expr.LocalVarOperator;
026: import jode.util.SimpleSet;
027:
028: import java.util.Set;
029:
030: /**
031: * This is a method for block containing a single instruction.
032: */
033: public abstract class InstructionContainer extends StructuredBlock {
034: /**
035: * The instruction.
036: */
037: Expression instr;
038:
039: public InstructionContainer(Expression instr) {
040: this .instr = instr;
041: }
042:
043: public InstructionContainer(Expression instr, Jump jump) {
044: this (instr);
045: setJump(jump);
046: }
047:
048: /**
049: * Make the declarations, i.e. initialize the declare variable
050: * to correct values. This will declare every variable that
051: * is marked as used, but not done.<br>
052: *
053: * This will now also combine locals, that use the same slot, have
054: * compatible types and are declared in the same block. <br>
055: *
056: * @param done The set of the already declare variables.
057: */
058: public void makeDeclaration(Set done) {
059: if (instr != null)
060: instr.makeDeclaration(done);
061: super .makeDeclaration(done);
062: }
063:
064: /**
065: * This method should remove local variables that are only written
066: * and read one time directly after another. <br>
067: *
068: * This is especially important for stack locals, that are created
069: * when there are unusual swap or dup instructions, but also makes
070: * inlined functions more pretty (but not that close to the
071: * bytecode).
072: */
073: public void removeOnetimeLocals() {
074: if (instr != null)
075: instr = instr.removeOnetimeLocals();
076: super .removeOnetimeLocals();
077: }
078:
079: /**
080: * Fill all in variables into the given VariableSet.
081: * @param in The VariableSet, the in variables should be stored to.
082: */
083: public void fillInGenSet(Set in, Set gen) {
084: if (instr != null)
085: instr.fillInGenSet(in, gen);
086: }
087:
088: public Set getDeclarables() {
089: Set used = new SimpleSet();
090: if (instr != null)
091: instr.fillDeclarables(used);
092: return used;
093: }
094:
095: public boolean doTransformations() {
096: if (instr == null)
097: return false;
098: /* Do on the fly access$ transformation, since some further
099: * operations need this.
100: */
101: if (instr instanceof InvokeOperator) {
102: Expression expr = ((InvokeOperator) instr).simplifyAccess();
103: if (expr != null)
104: instr = expr;
105: }
106: StructuredBlock last = flowBlock.lastModified;
107: return CreateNewConstructor.transform(this , last)
108: || CreateAssignExpression.transform(this , last)
109: || CreateExpression.transform(this , last)
110: || CreatePrePostIncExpression.transform(this , last)
111: || CreateIfThenElseOperator.create(this , last)
112: || CreateConstantArray.transform(this , last)
113: || CreateCheckNull.transformJavac(this , last);
114: }
115:
116: /**
117: * Get the contained instruction.
118: * @return the contained instruction.
119: */
120: public final Expression getInstruction() {
121: return instr;
122: }
123:
124: public void simplify() {
125: if (instr != null)
126: instr = instr.simplify();
127: super .simplify();
128: }
129:
130: /**
131: * Set the contained instruction.
132: * @param instr the new instruction.
133: */
134: public final void setInstruction(Expression instr) {
135: this.instr = instr;
136: }
137: }
|