001: package net.sf.jdec.jvminstructions.commands;
002:
003: import java.util.Hashtable;
004:
005: import net.sf.jdec.constantpool.ClassDescription;
006: import net.sf.jdec.constantpool.ClassInfo;
007: import net.sf.jdec.core.DecompilerHelper;
008: import net.sf.jdec.core.GlobalVariableStore;
009: import net.sf.jdec.core.JvmOpCodes;
010: import net.sf.jdec.core.LocalVariable;
011: import net.sf.jdec.core.LocalVariableStructure;
012: import net.sf.jdec.core.Operand;
013: import net.sf.jdec.core.OperandStack;
014: import net.sf.jdec.reflection.Behaviour;
015: import net.sf.jdec.util.Constants;
016:
017: public class MultiAnewArrayCommand extends AbstractInstructionCommand {
018:
019: public MultiAnewArrayCommand(Behaviour context) {
020: super (context);
021:
022: }
023:
024: public int getSkipBytes() {
025: return 3;
026: }
027:
028: public void execute() {
029: GlobalVariableStore.setMultinewfound(true);
030: int i = getCurrentInstPosInCode();
031: int classIndex = getGenericFinder().getOffset(i);//(info[++i] << 8) | info[++i]);
032: i += 2;
033: ClassDescription cd = getContext().getClassRef().getCd();
034: ClassInfo cinfo = cd.getClassInfoAtCPoolPosition(classIndex);
035: java.lang.String temp = cd
036: .getUTF8String(cinfo.getUtf8pointer());
037: ;
038: LocalVariableStructure structure = getContext()
039: .getLocalVariables();
040: int lastBracket = temp.lastIndexOf("[");
041: temp = temp.substring(lastBracket + 1);
042: temp = DecompilerHelper.getArrayType(temp);
043: Hashtable variableDimAss = GlobalVariableStore
044: .getVariableDimAss();
045: byte[] info = getCode();
046: int dimensions = info[++i];
047: OperandStack opStack = getStack();
048: int Temp = i + 1;
049: int nextindex = -1;
050: boolean ty = false;
051: if (info[Temp] == JvmOpCodes.ASTORE) {
052: nextindex = info[(Temp + 1)];
053: ty = true;
054: }
055: if (info[Temp] == JvmOpCodes.ASTORE_0) {
056:
057: nextindex = 0;
058: }
059: if (info[Temp] == JvmOpCodes.ASTORE_1) {
060:
061: nextindex = 1;
062: }
063: if (info[Temp] == JvmOpCodes.ASTORE_2) {
064:
065: nextindex = 2;
066: }
067: if (info[Temp] == JvmOpCodes.ASTORE_3) {
068:
069: nextindex = 3;
070: }
071: int d = -1;
072: int cnt = -1;
073: if (variableDimAss != null) {
074: Integer n = (Integer) variableDimAss.get(new Integer(
075: nextindex));
076: d = -1;
077:
078: if (n != null) {
079: d = n.intValue();
080: }
081: } else {
082: if (cd.isClassCompiledWithMinusG()) {
083: LocalVariable lv;
084: java.lang.String tpe = null;
085:
086: if (ty) {
087: lv = structure.getVariabelAtIndex(nextindex,
088: Temp + 2);
089: if (lv != null)
090: tpe = lv.getDataType();
091:
092: } else {
093: lv = structure.getVariabelAtIndex(nextindex,
094: Temp + 1);
095: if (lv != null)
096: tpe = lv.getDataType();
097: }
098: if (tpe != null) {
099: int openb = tpe.indexOf("[");
100:
101: if (openb != -1) {
102: cnt = 1;
103:
104: while ((openb + 1) < tpe.length()) {
105:
106: char ch = tpe.charAt((openb + 1));
107: if (ch == '[') {
108: cnt++;
109:
110: }
111: openb++;
112: }
113:
114: }
115: }
116: }
117:
118: }
119:
120: Operand ops[] = new Operand[dimensions];
121: java.lang.String dimenPart = "[";
122: for (int indx = 0; indx < dimensions; indx++) {
123: ops[indx] = opStack.getTopOfStack();
124:
125: }
126:
127: // Reverse Array
128: Operand opsTemp[] = new Operand[dimensions];
129: int lastPos = dimensions - 1;
130: for (int indx = 0; indx < dimensions; indx++) {
131: opsTemp[indx] = ops[lastPos];
132: lastPos--;
133:
134: }
135: for (int indx = 0; indx < dimensions; indx++) {
136: dimenPart += opsTemp[indx].getOperandValue() + "]";
137: if (indx != dimensions - 1)
138: dimenPart += "[";
139: }
140: if (d > dimensions) {
141: int rem = d - dimensions;
142: for (int zz = 0; zz < rem; zz++) {
143: dimenPart += "[]";
144: }
145: }
146:
147: if (cnt > dimensions && d == -1) {
148: int rem = cnt - dimensions;
149: for (int zz = 0; zz < rem; zz++) {
150: dimenPart += "[]";
151: }
152: }
153: if (cd.isClassCompiledWithMinusG() == false) {
154: variableDimAss.put(new Integer(nextindex), new Integer(
155: dimensions));
156: }
157:
158: Operand op2 = new Operand();
159: op2.setClassType(temp);
160: temp = "new " + temp + dimenPart;
161:
162: op2.setCategory(Constants.CATEGORY1);
163: op2.setOperandType(Constants.IS_ARRAY_REF);
164: op2.setOperandValue(temp);
165: op2.setMultiDimension(true);
166: boolean r = false;//checkIFLoadInstIsPartOFTernaryCond(currentForIndex);
167: if (r) {
168: if (opStack.size() > 0) {
169: java.lang.String str = opStack.getTopOfStack()
170: .getOperandValue();
171: str = str + op2.getOperandValue();
172: op2.setOperandValue(str);
173: }
174: }
175: opStack.push(op2);
176: }
177:
178: }
|