handle Short/Long constants in different methods

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@526 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 9d0cf969b0
commit 38e5046902
  1. 53
      jode/jode/bytecode/GrowableConstantPool.java

@ -62,13 +62,26 @@ public class GrowableConstantPool extends ConstantPool {
if (index != null) if (index != null)
return index.intValue(); return index.intValue();
int newIndex = count; int newIndex = count;
grow(count+(tag == DOUBLE || tag == LONG ? 2 : 1)); grow(count + 1);
tags[newIndex] = tag; tags[newIndex] = tag;
constants[newIndex] = constant; constants[newIndex] = constant;
entryToIndex.put(key, new Integer(newIndex)); entryToIndex.put(key, new Integer(newIndex));
count++; count++;
if (tag == DOUBLE || tag == LONG) return newIndex;
count++; }
int putLongConstant(int tag, Object constant) {
String key = "" + (char)tag + constant;
Integer index = (Integer) entryToIndex.get(key);
if (index != null)
return index.intValue();
int newIndex = count;
grow(count + 2);
tags[newIndex] = tag;
tags[newIndex+1] = -tag;
constants[newIndex] = constant;
entryToIndex.put(key, new Integer(newIndex));
count += 2;
return newIndex; return newIndex;
} }
@ -129,15 +142,29 @@ public class GrowableConstantPool extends ConstantPool {
tag = INTEGER; tag = INTEGER;
else if (c instanceof Float) else if (c instanceof Float)
tag = FLOAT; tag = FLOAT;
else if (c instanceof Long) else
throw new IllegalArgumentException
("illegal constant " + c + " of type: " + c.getClass());
return putConstant(tag, c);
}
}
/**
* Puts a constant into this constant pool
* @param c the constant, must be of type
* Integer, Long, Float, Double or String
* @return the index into the pool of this constant.
*/
public int putLongConstant(Object c) {
int tag;
if (c instanceof Long)
tag = LONG; tag = LONG;
else if (c instanceof Double) else if (c instanceof Double)
tag = DOUBLE; tag = DOUBLE;
else else
throw new IllegalArgumentException("illegal constant "+c throw new IllegalArgumentException
+" of type: "+ c.getClass()); ("illegal long constant " + c + " of type: " + c.getClass());
return putConstant(tag, c); return putLongConstant(tag, c);
}
} }
/** /**
@ -155,6 +182,16 @@ public class GrowableConstantPool extends ConstantPool {
} }
} }
/**
* Reserve an entry in this constant pool for a constant (for ldc).
* @param c the constant, must be of type
* Integer, Long, Float, Double or String
* @return the reserved index into the pool of this constant.
*/
public int reserveLongConstant(Object c) {
return putLongConstant(c);
}
public int copyConstant(ConstantPool cp, int index) public int copyConstant(ConstantPool cp, int index)
throws ClassFormatException { throws ClassFormatException {
return putConstant(cp.getConstant(index)); return putConstant(cp.getConstant(index));

Loading…
Cancel
Save