001: package net.sf.jdec.jvminstructions.commands;
002:
003: import net.sf.jdec.commonutil.Numbers;
004: import net.sf.jdec.constantpool.ClassDescription;
005: import net.sf.jdec.constantpool.FloatPrimitive;
006: import net.sf.jdec.constantpool.IntPrimitive;
007: import net.sf.jdec.constantpool.CPString;
008: import net.sf.jdec.core.Operand;
009: import net.sf.jdec.core.OperandStack;
010: import net.sf.jdec.reflection.Behaviour;
011: import net.sf.jdec.ui.util.UIUtil;
012: import net.sf.jdec.util.Constants;
013: import net.sf.jdec.util.Util;
014:
015: public class LdcCommand extends AbstractInstructionCommand {
016:
017: public LdcCommand(Behaviour context) {
018: super (context);
019:
020: }
021:
022: public int getSkipBytes() {
023: return 1;
024: }
025:
026: public void execute() {
027: int i = getCurrentInstPosInCode();
028: byte[] info = getCode();
029: int opValueI = info[++i];
030: // Important Fix
031: if (opValueI < 0)
032: opValueI += 256;
033:
034: int type = -1;
035: FloatPrimitive constFloat = null;
036: java.lang.String stringLiteral = "";
037: OperandStack opStack = getStack();
038: ClassDescription cd = getContext().getClassRef().getCd();
039: IntPrimitive constInt = cd
040: .getINTPrimitiveAtCPoolPosition(opValueI);
041: if (constInt == null) {
042: constFloat = cd.getFloatPrimitiveAtCPoolPosition(opValueI);
043: if (constFloat == null) {
044: CPString constString = cd
045: .getStringsAtCPoolPosition(opValueI);
046: stringLiteral = cd.getUTF8String(constString
047: .getUtf8pointer());
048: if (constString == null) {
049: // ERROR CONDITION
050: } else {
051: type = Constants.IS_OBJECT_REF;
052: }
053: } else {
054: type = Constants.IS_CONSTANT_FLOAT;
055: }
056: } else {
057: type = Constants.IS_CONSTANT_INT;
058: }
059: Operand op = new Operand();
060: op.setOperandType(type);
061: if (type == Constants.IS_CONSTANT_INT) {
062: op.setOperandValue(new Integer(constInt.getValue()));
063: op.setClassType("int");
064: }
065: if (type == Constants.IS_CONSTANT_FLOAT) {
066:
067: op.setOperandValue(constFloat.getValue() + "f ");
068: op.setClassType("float");
069: }
070: if (type == Constants.IS_OBJECT_REF) {
071:
072: java.lang.String nonascii = UIUtil.getUIUtil()
073: .getInterpretNonAscii();
074: if (nonascii.equals("true")) {
075: StringBuffer tp = new StringBuffer("");
076:
077: boolean sf = Numbers.shouldValueBeFormattedForNonAscii(
078: stringLiteral, "String", tp);
079: if (sf) {
080: stringLiteral = Util.formatForUTF(stringLiteral,
081: "String", tp);
082: }
083: } else {
084: stringLiteral = Util
085: .returnUnInterpretedNonAscii(stringLiteral);
086: }
087: op.setOperandValue("\"" + stringLiteral + "\"");
088: op.setClassType("java.lang.String");
089: }
090: boolean r = false;// checkIFLoadInstIsPartOFTernaryCond(currentForIndex);
091: if (r) {
092: if (opStack.size() > 0) {
093: java.lang.String str = opStack.getTopOfStack()
094: .getOperandValue();
095: str = str + op.getOperandValue();
096: op.setOperandValue(str);
097: }
098: }
099: opStack.push(op);
100: }
101:
102: }
|