001: package net.sf.jdec.jvminstructions.commands;
002:
003: import net.sf.jdec.reflection.Behaviour;
004: import net.sf.jdec.util.Constants;
005: import net.sf.jdec.util.ExecutionState;
006: import net.sf.jdec.core.*;
007: import net.sf.jdec.lookup.IFinder;
008:
009: import java.util.ArrayList;
010:
011: /*
012: * AALoadCommand.java Copyright (c) 2006,07 Swaroop Belur
013: *
014: * This program is free software; you can redistribute it and/or
015: * modify it under the terms of the GNU General Public License
016: * as published by the Free Software Foundation; either version 2
017: * of the License, or (at your option) any later version.
018:
019: * This program is distributed in the hope that it will be useful,
020: * but WITHOUT ANY WARRANTY; without even the implied warranty of
021: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
022: * GNU General Public License for more details.
023:
024: * You should have received a copy of the GNU General Public License
025: * along with this program; if not, write to the Free Software
026: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
027: *
028: */
029: public class AALoadCommand extends AbstractInstructionCommand {
030:
031: private IFinder genericFinder = getGenericFinder();
032:
033: public AALoadCommand(Behaviour context) {
034: super (context);
035: }
036:
037: public int getSkipBytes() {
038: return 0;
039: }
040:
041: public void execute() {
042: OperandStack stack = getContext().getOpStack();
043: Operand sourcePos = (Operand) stack.pop();
044: Operand srcarrayRef = (Operand) stack.pop(); //
045: Operand op = createOperand(srcarrayRef.getOperandValue() + "["
046: + sourcePos.getOperandValue() + "]",
047: Constants.IS_OBJECT_REF, Constants.CATEGORY1);
048: boolean r = false;//checkIFLoadInstIsPartOFTernaryCond(currentForIndex);
049: /* if(r){
050: if(opStack.size() > 0){
051: java.lang.String str=opStack.getTopOfStack().getOperandValue();
052: str=str+op.getOperandValue();
053: op.setOperandValue(str);
054: }
055: }*/
056: stack.push(op);
057:
058: // check to adjust local variable type
059: int cur = ExecutionState.getCurrentInstructionPosition();
060: byte info[] = getContext().getCode();
061:
062: int prev = genericFinder.getPrevStartOfInst(cur);
063: prev = genericFinder.getPrevStartOfInst(prev);
064: StringBuffer index = new StringBuffer("");
065: if (getLoadFinder().isInstAload(prev, index) != -1) {
066: int varIndex = Integer.parseInt(index.toString());
067: ArrayList variables = getContext().getLocalVariables()
068: .getMethodLocalVaribales();
069: boolean flag = false;
070: boolean complex = false;
071: int astoreIndex = -1;
072: if (genericFinder.isThisInstrStart(cur + 1)) {
073: switch (info[cur + 1]) {
074: case JvmOpCodes.ASTORE:
075: flag = true;
076: complex = true;
077: astoreIndex = info[(cur + 2)];
078: break;
079:
080: case JvmOpCodes.ASTORE_0:
081: flag = true;
082: astoreIndex = 0;
083: break;
084: case JvmOpCodes.ASTORE_1:
085: flag = true;
086: astoreIndex = 1;
087: break;
088: case JvmOpCodes.ASTORE_2:
089: flag = true;
090: astoreIndex = 2;
091: break;
092: case JvmOpCodes.ASTORE_3:
093: flag = true;
094: astoreIndex = 3;
095: break;
096:
097: }
098: }
099: if (flag) {
100: for (int z = 0; z < variables.size(); z++) {
101: LocalVariable lv = (LocalVariable) variables.get(z);
102: if (lv.getIndexPos() == varIndex) {
103: java.lang.String type = lv.getDataType();
104: java.lang.String typeCopy = type;
105: if (type != null && type.trim().length() > 0) {
106: type = type.replaceAll("\\[", "");
107: type = type.replaceAll("\\]", "");
108: type = type.trim();
109: LocalVariable local = null;
110: if (complex) {
111: local = DecompilerHelper
112: .getLocalVariable(
113: astoreIndex,
114: "store",
115: "java.lang.Object",
116: false,
117: ExecutionState
118: .getCurrentInstructionPosition());
119: } else {
120: local = DecompilerHelper
121: .getLocalVariable(
122: astoreIndex,
123: "store",
124: "java.lang.Object",
125: true,
126: ExecutionState
127: .getCurrentInstructionPosition());
128: }
129: if (local != null) {
130: int bracket = typeCopy.indexOf("[");
131: int bracketCount = 0;
132: while (bracket != -1) {
133: bracketCount++;
134: bracket = typeCopy.indexOf("[",
135: bracket + 1);
136: }
137: java.lang.String bracketStr = "";
138: for (int x = 0; x < bracketCount - 1; x++) {
139: bracketStr += "[]";
140: }
141: local.setDataType(type + " "
142: + bracketStr);
143: break;
144: }
145: }
146: }
147: }
148: }
149: }
150: }
151: }
|