From 38e5046902a49e059bd6f914b6aa5c9278a3bcf9 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 9 Apr 1999 08:01:02 +0000 Subject: [PATCH] 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 --- jode/jode/bytecode/GrowableConstantPool.java | 55 ++++++++++++++++---- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/jode/jode/bytecode/GrowableConstantPool.java b/jode/jode/bytecode/GrowableConstantPool.java index 074be50..b5f594a 100644 --- a/jode/jode/bytecode/GrowableConstantPool.java +++ b/jode/jode/bytecode/GrowableConstantPool.java @@ -62,13 +62,26 @@ public class GrowableConstantPool extends ConstantPool { if (index != null) return index.intValue(); int newIndex = count; - grow(count+(tag == DOUBLE || tag == LONG ? 2 : 1)); + grow(count + 1); tags[newIndex] = tag; constants[newIndex] = constant; entryToIndex.put(key, new Integer(newIndex)); count++; - if (tag == DOUBLE || tag == LONG) - count++; + return newIndex; + } + + 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; } @@ -129,17 +142,31 @@ public class GrowableConstantPool extends ConstantPool { tag = INTEGER; else if (c instanceof Float) tag = FLOAT; - else if (c instanceof Long) - tag = LONG; - else if (c instanceof Double) - tag = DOUBLE; else - throw new IllegalArgumentException("illegal constant "+c - +" of type: "+ c.getClass()); + 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; + 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). * @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) throws ClassFormatException { return putConstant(cp.getConstant(index));