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 java.util.ArrayList;
022: import java.util.Hashtable;
023:
024: import net.sf.jdec.core.DecompilerHelper;
025: import net.sf.jdec.core.GlobalVariableStore;
026: import net.sf.jdec.core.LocalVariable;
027: import net.sf.jdec.core.Operand;
028: import net.sf.jdec.core.OperandStack;
029: import net.sf.jdec.main.ConsoleLauncher;
030: import net.sf.jdec.reflection.Behaviour;
031: import net.sf.jdec.util.Util;
032:
033: public class Astore_1Command extends AbstractInstructionCommand {
034:
035: public Astore_1Command(Behaviour context) {
036: super (context);
037:
038: }
039:
040: public int getSkipBytes() {
041: return 0;
042: }
043:
044: public void execute() {
045:
046: int i = getCurrentInstPosInCode();
047: int currentForIndex = i;
048: int instructionPos = i;
049: Behaviour behaviour = getContext();
050: ArrayList methodTries = behaviour.getAllTriesForMethod();
051: byte[] info = behaviour.getCode();
052: boolean doNotPop = GlobalVariableStore.isDoNotPop();
053: OperandStack opStack = getContext().getOpStack();
054: boolean multinewfound = GlobalVariableStore.isMultinewfound();
055: Hashtable variableDimAss = GlobalVariableStore
056: .getVariableDimAss();
057:
058: boolean dupnothandled = GlobalVariableStore.isDupnothandled();
059:
060: boolean add = DecompilerHelper.checkForStartOfCatch(
061: instructionPos, methodTries);
062: if (add == true && !doNotPop) {
063:
064: LocalVariable local = DecompilerHelper.getLocalVariable(1,
065: "store", "java.lang.Object", true, currentForIndex);
066: if (local != null) {
067:
068: boolean push = getGenericFinder().isPrevInstDup(
069: currentForIndex);
070: if (!push) {
071: Operand objref = (Operand) opStack.pop(); // Pop The
072: // Object Ref
073:
074: if (local.wasCreated()
075: && objref != null
076: && objref.getClassType().trim().length() > 0)
077: local.setDataType(objref.getClassType());
078: java.lang.String temp = (java.lang.String) objref
079: .getOperandValue(); // temp has new <Class
080: // Name>[<size>]
081: if (!local.isDeclarationGenerated()) {
082:
083: // temp=local.getDataType().replace('/','.')+"
084: // "+local.getVarName()+" ="+temp; // This shbud contain
085: // the actual Line in the method
086: boolean yes = true;
087: if (!multinewfound) {
088: StringBuffer m = new StringBuffer("");
089:
090: DecompilerHelper
091: .checkForImport(local.getDataType()
092: .replace('/', '.'), m);
093: if (local.getVarName().equals(temp) == true) {
094: yes = false;
095: }
096: Object vaf = DecompilerHelper
097: .newVariableAtFront(local
098: .getVarName(),
099: m.toString(), "null");
100: GlobalVariableStore.getVariablesatfront()
101: .add(vaf);
102: temp = local.getVarName() + "=" + temp;
103: } else {
104: multinewfound = false;
105: Integer n = (Integer) variableDimAss
106: .get(new Integer(0));
107: java.lang.String bracks = "";
108: if (n != null) {
109: for (int o = 0; o < n.intValue(); o++) {
110: bracks += "[]";
111: }
112: }
113: StringBuffer m = new StringBuffer("");
114: DecompilerHelper
115: .checkForImport(local.getDataType()
116: .replace('/', '.'), m);
117: Object vaf = DecompilerHelper
118: .newVariableAtFront(local
119: .getVarName(), m.toString()
120: + " " + bracks + " ",
121: "null");
122: GlobalVariableStore.getVariablesatfront()
123: .add(vaf);
124: temp = local.getVarName() + "=" + temp;
125:
126: }
127: if (yes) {
128: behaviour.appendToBuffer(Util
129: .formatDecompiledStatement(temp
130: + ";\n"));
131:
132: // behaviour.appendToBuffer( ";\n";
133: }
134: local.setDeclarationGenerated(true);
135: } else {
136: if (temp != null
137: && temp.trim().equalsIgnoreCase("this")) {
138: java.lang.String classname = ConsoleLauncher
139: .getClazzRef().getClassName();
140: temp = classname + " "
141: + local.getVarName() + " =" + temp;
142: behaviour.appendToBuffer(Util
143: .formatDecompiledStatement(temp
144: + ";\n"));
145: // behaviour.appendToBuffer( ";\n";
146: } else {
147: temp = " " + local.getVarName() + " ="
148: + temp;
149: behaviour.appendToBuffer(Util
150: .formatDecompiledStatement(temp
151: + ";\n"));
152: // behaviour.appendToBuffer( ";\n";
153: }
154: }
155: } else {
156: Operand top = opStack.getTopOfStack();
157: // boolean skipped=checkIFDUPWasSkipped(currentForIndex);
158: if (!dupnothandled)
159: opStack.getTopOfStack();
160: else
161: dupnothandled = false;
162:
163: java.lang.String temp = top.getOperandValue();
164: java.lang.String typedecl = "";
165: boolean yes = true;
166: boolean waslocaldecalred = true;
167: if (!local.isDeclarationGenerated()) {
168: waslocaldecalred = false;
169: if (!multinewfound) {
170: StringBuffer m = new StringBuffer("");
171: if (top.getClassType() != null) {
172: local.setDataType(top.getClassType());
173: }
174: DecompilerHelper
175: .checkForImport(local.getDataType()
176: .replace('/', '.'), m);
177: if (local.getVarName().equals(temp) == true) {
178: yes = false;
179: }
180: typedecl = m.toString() + " ";
181: } else {
182: multinewfound = false;
183: Integer n = (Integer) variableDimAss
184: .get(new Integer(0));
185: java.lang.String bracks = "";
186: if (n != null) {
187: for (int o = 0; o < n.intValue(); o++) {
188: bracks += "[]";
189: }
190: }
191: StringBuffer m = new StringBuffer("");
192: if (top.getClassType() != null) {
193: local.setDataType(top.getClassType());
194: }
195: DecompilerHelper
196: .checkForImport(local.getDataType()
197: .replace('/', '.'), m);
198: typedecl = m.toString() + bracks + " ";
199:
200: }
201: local.setDeclarationGenerated(true);
202: Object vaf = DecompilerHelper
203: .newVariableAtFront(local.getVarName(),
204: typedecl, "null");
205: GlobalVariableStore.getVariablesatfront().add(
206: vaf);
207: }
208: temp = local.getVarName() + " =" + temp + ";\n";
209: if (local.wasCreated() && top != null
210: && top.getClassType().trim().length() > 0)
211: local.setDataType(top.getClassType());
212: if (!DecompilerHelper.isTernaryCondition(
213: currentForIndex, info)) {
214: if (!newfound()) {
215: // TODO : This fix needs be tested....
216: if (waslocaldecalred == false && !yes) {
217:
218: } else
219: behaviour
220: .appendToBuffer(Util
221: .formatDecompiledStatement(temp));
222:
223: Operand op6 = createOperand(local
224: .getVarName());// "("+local.getVarName()+"=("+op.getOperandValue()+"))");
225: opStack.push(op6);
226: } else {
227: Operand op6 = createOperand(temp);
228: opStack.push(op6);
229: }
230: } else {
231: boolean ternEndfoundForParentIF = false;//isThisTernaryListEndForParentIF(currentForIndex);
232: boolean ternEndfound = false;//isThisTernaryListEnd(currentForIndex);
233:
234: boolean dupStoreForTerIf = false;//isThisDUPSTOREAtEndOFTernaryIF( currentForIndex, info, "store");
235: boolean n = DecompilerHelper
236: .anydupstoreinternarybesidesthis (
237: currentForIndex, info);
238: if (ternEndfound && n) {
239: opStack.push(top);
240: } else {
241: Operand p = opStack.getTopOfStack();
242: boolean end = false;//isTernaryEnd(currentForIndex);
243: if (dupStoreForTerIf) {
244: if (!end)
245: p.setOperandValue(p
246: .getOperandValue()
247: + "("
248: + local.getVarName()
249: + "="
250: + top.getOperandValue()
251: + ")");
252: else
253: p.setOperandValue(p
254: .getOperandValue()
255: + "("
256: + local.getVarName()
257: + "="
258: + top.getOperandValue()
259: + "))");
260: }
261: if (!dupStoreForTerIf) {
262: if (!end)
263: p.setOperandValue(p
264: .getOperandValue()
265: + "("
266: + top.getOperandValue()
267: + ")");
268: else
269: p.setOperandValue(p
270: .getOperandValue()
271: + top.getOperandValue()
272: + "))");
273: }
274: opStack.push(p);
275: }
276: if (ternEndfoundForParentIF)
277: GlobalVariableStore
278: .setTernList(new ArrayList());
279:
280: }
281: }
282:
283: }
284:
285: }
286: if (doNotPop == true)
287: doNotPop = false;
288: GlobalVariableStore.setDoNotPop(doNotPop);
289: GlobalVariableStore.setMultinewfound(multinewfound);
290: GlobalVariableStore.setVariableDimAss(variableDimAss);
291: GlobalVariableStore.setDupnothandled(dupnothandled);
292:
293: }
294:
295: }
|