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. 55
      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,17 +142,31 @@ 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)
tag = LONG;
else if (c instanceof Double)
tag = DOUBLE;
else else
throw new IllegalArgumentException("illegal constant "+c throw new IllegalArgumentException
+" of type: "+ c.getClass()); ("illegal constant " + c + " of type: " + c.getClass());
return putConstant(tag, c); 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;
else if (c instanceof Double)
tag = DOUBLE;
else
throw new IllegalArgumentException
("illegal long constant " + c + " of type: " + c.getClass());
return putLongConstant(tag, c);
}
/** /**
* Reserve an entry in this constant pool for a constant (for ldc). * Reserve an entry in this constant pool for a constant (for ldc).
* @param c the constant, must be of type * @param c the constant, must be of type
@ -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