01: package net.sf.jdec.jvminstructions.commands;
02:
03: import java.util.ArrayList;
04:
05: import net.sf.jdec.constantpool.ClassDescription;
06: import net.sf.jdec.constantpool.ClassInfo;
07: import net.sf.jdec.core.Operand;
08: import net.sf.jdec.core.OperandStack;
09: import net.sf.jdec.reflection.Behaviour;
10: import net.sf.jdec.util.Util;
11:
12: public class CheckcastCommand extends AbstractInstructionCommand {
13:
14: public CheckcastCommand(Behaviour context) {
15: super (context);
16:
17: }
18:
19: public int getSkipBytes() {
20: return 2;
21: }
22:
23: public void execute() {
24:
25: int i = getCurrentInstPosInCode();
26: byte[] info = getContext().getCode();
27: OperandStack stack = getContext().getOpStack();
28: Operand op = (Operand) stack.pop();
29: int classIndex = getGenericFinder().getOffset(i);
30: ClassDescription cd = getContext().getClassRef().getCd();
31: ClassInfo cinfo = cd.getClassInfoAtCPoolPosition(classIndex);
32: Object o = op.getOperandValue();
33: op = new Operand(); //
34: java.lang.String v = cd.getUTF8String(cinfo.getUtf8pointer())
35: .replace('/', '.');
36: if (v.startsWith("[")) {
37: Util.parseReturnType(v);
38: ArrayList list = Util.getreturnSignatureAsList();
39: if (list != null && list.size() > 0) {
40: v = (java.lang.String) list.get(0);
41: }
42: }
43: java.lang.String type = "";
44: java.lang.String castedRef = "";
45: int br = v.indexOf("[");
46: if (br != -1) {
47: type = v.substring(0, br).trim();
48: java.lang.String bracks = v.substring(br);
49: StringBuffer sb = new StringBuffer("");
50: Util.checkForImport(type, sb);
51: castedRef = "(" + sb.toString() + " " + bracks + ")"
52: + o.toString();
53: op.setClassType(type);
54: } else {
55: StringBuffer sb = new StringBuffer("");
56: Util.checkForImport(v, sb);
57: castedRef = "(" + sb.toString() + ")" + o.toString();
58: op.setClassType(v);
59: }
60:
61: op.setOperandValue(castedRef);
62: boolean r = false;// checkIFLoadInstIsPartOFTernaryCond(getCurrentInstPosInCode());
63: if (r) {
64: if (stack.size() > 0) {
65: java.lang.String str = stack.getTopOfStack()
66: .getOperandValue();
67: str = str + op.getOperandValue();
68: op.setOperandValue(str);
69: }
70: }
71: stack.push(op);
72: }
73:
74: }
|