001: /*
002: * Astore_0Command.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/itor
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019: package net.sf.jdec.jvminstructions.commands;
020:
021: import net.sf.jdec.core.*;
022: import net.sf.jdec.main.ConsoleLauncher;
023: import net.sf.jdec.reflection.Behaviour;
024: import net.sf.jdec.util.Util;
025:
026: import java.util.ArrayList;
027: import java.util.Hashtable;
028:
029: public class Astore_3Command extends AbstractInstructionCommand {
030:
031: public Astore_3Command(Behaviour context) {
032: super (context);
033:
034: }
035:
036: public int getSkipBytes() {
037: return 0;
038: }
039:
040: public void execute() {
041:
042: int i = getCurrentInstPosInCode();
043: int currentForIndex = i;
044: int instructionPos = i;
045: Behaviour behaviour = getContext();
046: ArrayList methodTries = behaviour.getAllTriesForMethod();
047: byte[] info = behaviour.getCode();
048: boolean doNotPop = GlobalVariableStore.isDoNotPop();
049: OperandStack opStack = getContext().getOpStack();
050: boolean multinewfound = GlobalVariableStore.isMultinewfound();
051: Hashtable variableDimAss = GlobalVariableStore
052: .getVariableDimAss();
053: boolean dupnothandled = GlobalVariableStore.isDupnothandled();
054:
055: boolean add = DecompilerHelper.checkForStartOfCatch(
056: instructionPos, methodTries);
057: if (add == true && !doNotPop) {
058:
059: LocalVariable local = DecompilerHelper.getLocalVariable(3,
060: "store", "java.lang.Object", true, currentForIndex);
061: if (local != null) {
062:
063: boolean push = getGenericFinder().isPrevInstDup(
064: currentForIndex);
065: if (!push) {
066: Operand objref = (Operand) opStack.pop(); // Pop The
067: // Object Ref
068:
069: if (local.wasCreated()
070: && objref != null
071: && objref.getClassType().trim().length() > 0)
072: local.setDataType(objref.getClassType());
073: java.lang.String temp = (java.lang.String) objref
074: .getOperandValue(); // temp has new <Class
075: // Name>[<size>]
076: if (!local.isDeclarationGenerated()) {
077:
078: // temp=local.getDataType().replace('/','.')+"
079: // "+local.getVarName()+" ="+temp; // This shbud contain
080: // the actual Line in the method
081: boolean yes = true;
082: if (!multinewfound) {
083: StringBuffer m = new StringBuffer("");
084:
085: DecompilerHelper
086: .checkForImport(local.getDataType()
087: .replace('/', '.'), m);
088: if (local.getVarName().equals(temp) == true) {
089: yes = false;
090: }
091: Object vaf = DecompilerHelper
092: .newVariableAtFront(local
093: .getVarName(),
094: m.toString(), "null");
095: GlobalVariableStore.getVariablesatfront()
096: .add(vaf);
097: temp = local.getVarName() + "=" + temp;
098: } else {
099: multinewfound = false;
100: Integer n = (Integer) variableDimAss
101: .get(new Integer(0));
102: java.lang.String bracks = "";
103: if (n != null) {
104: for (int o = 0; o < n.intValue(); o++) {
105: bracks += "[]";
106: }
107: }
108: StringBuffer m = new StringBuffer("");
109: DecompilerHelper
110: .checkForImport(local.getDataType()
111: .replace('/', '.'), m);
112: Object vaf = DecompilerHelper
113: .newVariableAtFront(local
114: .getVarName(), m.toString()
115: + " " + bracks + " ",
116: "null");
117: GlobalVariableStore.getVariablesatfront()
118: .add(vaf);
119: temp = local.getVarName() + "=" + temp;
120:
121: }
122: if (yes) {
123: behaviour.appendToBuffer(Util
124: .formatDecompiledStatement(temp
125: + ";\n"));
126:
127: // behaviour.appendToBuffer( ";\n";
128: }
129: local.setDeclarationGenerated(true);
130: } else {
131: if (temp != null
132: && temp.trim().equalsIgnoreCase("this")) {
133: java.lang.String classname = ConsoleLauncher
134: .getClazzRef().getClassName();
135: temp = classname + " "
136: + local.getVarName() + " =" + temp;
137: behaviour.appendToBuffer(Util
138: .formatDecompiledStatement(temp
139: + ";\n"));
140: // behaviour.appendToBuffer( ";\n";
141: } else {
142: temp = " " + local.getVarName() + " ="
143: + temp;
144: behaviour.appendToBuffer(Util
145: .formatDecompiledStatement(temp
146: + ";\n"));
147: // behaviour.appendToBuffer( ";\n";
148: }
149: }
150: } else {
151: Operand top = opStack.getTopOfStack();
152: // boolean skipped=checkIFDUPWasSkipped(currentForIndex);
153: if (!dupnothandled)
154: opStack.getTopOfStack();
155: else
156: dupnothandled = false;
157:
158: java.lang.String temp = top.getOperandValue();
159: java.lang.String typedecl = "";
160: boolean yes = true;
161: boolean waslocaldecalred = true;
162: if (!local.isDeclarationGenerated()) {
163: waslocaldecalred = false;
164: if (!multinewfound) {
165: StringBuffer m = new StringBuffer("");
166: if (top.getClassType() != null) {
167: local.setDataType(top.getClassType());
168: }
169: DecompilerHelper
170: .checkForImport(local.getDataType()
171: .replace('/', '.'), m);
172: if (local.getVarName().equals(temp) == true) {
173: yes = false;
174: }
175: typedecl = m.toString() + " ";
176: } else {
177: multinewfound = false;
178: Integer n = (Integer) variableDimAss
179: .get(new Integer(0));
180: java.lang.String bracks = "";
181: if (n != null) {
182: for (int o = 0; o < n.intValue(); o++) {
183: bracks += "[]";
184: }
185: }
186: StringBuffer m = new StringBuffer("");
187: if (top.getClassType() != null) {
188: local.setDataType(top.getClassType());
189: }
190: DecompilerHelper
191: .checkForImport(local.getDataType()
192: .replace('/', '.'), m);
193: typedecl = m.toString() + bracks + " ";
194:
195: }
196: local.setDeclarationGenerated(true);
197: Object vaf = DecompilerHelper
198: .newVariableAtFront(local.getVarName(),
199: typedecl, "null");
200: GlobalVariableStore.getVariablesatfront().add(
201: vaf);
202: }
203: temp = local.getVarName() + " =" + temp + ";\n";
204: if (local.wasCreated() && top != null
205: && top.getClassType().trim().length() > 0)
206: local.setDataType(top.getClassType());
207: if (!DecompilerHelper.isTernaryCondition(
208: currentForIndex, info)) {
209: if (!newfound()) {
210: // TODO : This fix needs be tested....
211: if (waslocaldecalred == false && !yes) {
212:
213: } else
214: behaviour
215: .appendToBuffer(Util
216: .formatDecompiledStatement(temp));
217:
218: Operand op6 = createOperand(local
219: .getVarName());// "("+local.getVarName()+"=("+op.getOperandValue()+"))");
220: opStack.push(op6);
221: } else {
222: Operand op6 = createOperand(temp);
223: opStack.push(op6);
224: }
225: } else {
226: boolean ternEndfoundForParentIF = false;//isThisTernaryListEndForParentIF(currentForIndex);
227: boolean ternEndfound = false;//isThisTernaryListEnd(currentForIndex);
228:
229: boolean dupStoreForTerIf = false;//isThisDUPSTOREAtEndOFTernaryIF( currentForIndex, info, "store");
230: boolean n = DecompilerHelper
231: .anydupstoreinternarybesidesthis (
232: currentForIndex, info);
233: if (ternEndfound && n) {
234: opStack.push(top);
235: } else {
236: Operand p = opStack.getTopOfStack();
237: boolean end = false;//isTernaryEnd(currentForIndex);
238: if (dupStoreForTerIf) {
239: if (!end)
240: p.setOperandValue(p
241: .getOperandValue()
242: + "("
243: + local.getVarName()
244: + "="
245: + top.getOperandValue()
246: + ")");
247: else
248: p.setOperandValue(p
249: .getOperandValue()
250: + "("
251: + local.getVarName()
252: + "="
253: + top.getOperandValue()
254: + "))");
255: }
256: if (!dupStoreForTerIf) {
257: if (!end)
258: p.setOperandValue(p
259: .getOperandValue()
260: + "("
261: + top.getOperandValue()
262: + ")");
263: else
264: p.setOperandValue(p
265: .getOperandValue()
266: + top.getOperandValue()
267: + "))");
268: }
269: opStack.push(p);
270: }
271: if (ternEndfoundForParentIF)
272: GlobalVariableStore
273: .setTernList(new ArrayList());
274:
275: }
276: }
277:
278: }
279:
280: }
281: if (doNotPop == true)
282: doNotPop = false;
283: GlobalVariableStore.setDoNotPop(doNotPop);
284: GlobalVariableStore.setMultinewfound(multinewfound);
285: GlobalVariableStore.setVariableDimAss(variableDimAss);
286: GlobalVariableStore.setDupnothandled(dupnothandled);
287:
288: }
289:
290: }
|