01: // Copyright (c) 1997 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.bytecode;
05:
06: import java.io.*;
07:
08: /** A CONSTANT_Long or CONSTANT_Double entry in the constant pool. */
09:
10: public class CpoolValue2 extends CpoolEntry {
11: int tag;
12: long value;
13:
14: CpoolValue2(int tag) {
15: this .tag = tag;
16: }
17:
18: CpoolValue2(ConstantPool cpool, int tag, int hash, long value) {
19: super (cpool, hash);
20: this .tag = tag;
21: this .value = value;
22: cpool.count++; /* Long and Double take an extra cpool slot. */
23: }
24:
25: public int getTag() {
26: return tag;
27: }
28:
29: public final long getValue() {
30: return value;
31: }
32:
33: static int hashCode(long val) {
34: return (int) val;
35: }
36:
37: public int hashCode() {
38: if (hash == 0)
39: hash = hashCode(value);
40: return hash;
41: }
42:
43: void write(DataOutputStream dstr) throws java.io.IOException {
44: dstr.writeByte(tag);
45: dstr.writeLong(value);
46: }
47:
48: public void print(ClassTypeWriter dst, int verbosity) {
49: if (tag == ConstantPool.LONG) {
50: if (verbosity > 0)
51: dst.print("Long ");
52: dst.print(value);
53: if (verbosity > 1 && value != 0) {
54: dst.print("=0x");
55: dst.print(Long.toHexString(value));
56: }
57: } else // tag == ConstantPool.DOUBLE
58: {
59: if (verbosity > 0)
60: dst.print("Double ");
61: dst.print(Double.longBitsToDouble(value));
62: if (verbosity > 1) {
63: dst.print("=0x");
64: dst.print(Long.toHexString(value));
65: }
66: }
67: }
68: }
|