From: adam Date: Fri, 3 Jun 2005 06:15:01 +0000 (+0000) Subject: LongEnt split into DoubleEnt and LongEnt X-Git-Url: http://git.megacz.com/?p=org.ibex.classgen.git;a=commitdiff_plain;h=0e74145dcd9c0aa01c5403d9d9bc9cb496776ba8 LongEnt split into DoubleEnt and LongEnt darcs-hash:20050603061501-5007d-b5fdc7152fd89895beb22e4411cb2f825af16606.gz --- diff --git a/src/org/ibex/classgen/ConstantPool.java b/src/org/ibex/classgen/ConstantPool.java index 70ea083..74a6c30 100644 --- a/src/org/ibex/classgen/ConstantPool.java +++ b/src/org/ibex/classgen/ConstantPool.java @@ -20,9 +20,7 @@ class ConstantPool { public abstract class Ent { int n; // this is the refcount if state == OPEN, index if >= STABLE int tag; - Ent(int tag) { this.tag = tag; } - void dump(DataOutput o) throws IOException { o.writeByte(tag); } String debugToString() { return toString(); } // so we can remove this method when not debugging abstract Object key() throws ClassFile.ClassReadExn; // be careful using this, it drags in a bunch of code @@ -41,19 +39,17 @@ class ConstantPool { void dump(DataOutput o) throws IOException { super.dump(o); o.writeFloat(f); } Object key() { return new Float(f); } } - - // INVARIANTS: tag == 5 || tag == 6 class LongEnt extends Ent { - long l; - LongEnt(int tag) { super(tag); } + final long l; + LongEnt(long l) { super(5); this.l = l; } void dump(DataOutput o) throws IOException { super.dump(o); o.writeLong(l); } - Object key() { - switch(tag) { - case 5: return new Long(l); - case 6: return new Double(Double.longBitsToDouble(l)); - default: throw new Error("should never happen"); - } - } + Object key() { return new Long(l); } + } + class DoubleEnt extends Ent { + final double d; + DoubleEnt(double d) { super(6); this.d = d; } + void dump(DataOutput o) throws IOException { super.dump(o); o.writeDouble(d); } + Object key() { return new Double(d); } } /* INVARIANTS: @@ -197,14 +193,8 @@ class ConstantPool { ent = ce; } else if(o instanceof Integer) { ent = new IntEnt(((Integer)o).intValue()); } else if(o instanceof Float) { ent = new FloatEnt(((Float)o).floatValue()); - } else if(o instanceof Long) { - LongEnt le = new LongEnt(5); - le.l = ((Long)o).longValue(); - ent = le; - } else if(o instanceof Double) { - LongEnt le = new LongEnt(6); - le.l = Double.doubleToLongBits(((Double)o).doubleValue()); - ent = le; + } else if(o instanceof Long) { ent = new LongEnt(((Long)o).longValue()); + } else if(o instanceof Double) { ent = new DoubleEnt(((Double)o).doubleValue()); } else if(o instanceof Utf8Key) { Utf8Ent ue = new Utf8Ent(); ue.s = ((Utf8Key)o).s;