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_Integer or CONSTANT_Float entry in the constant pool. */
09:
10: public class CpoolValue1 extends CpoolEntry {
11: int tag;
12: int value;
13:
14: CpoolValue1(int tag) {
15: this .tag = tag;
16: }
17:
18: CpoolValue1(ConstantPool cpool, int tag, int hash, int value) {
19: super (cpool, hash);
20: this .tag = tag;
21: this .value = value;
22: }
23:
24: public int getTag() {
25: return tag;
26: }
27:
28: public final int getValue() {
29: return value;
30: }
31:
32: static int hashCode(int val) {
33: return val;
34: }
35:
36: public int hashCode() {
37: if (hash == 0)
38: hash = value;
39: return hash;
40: }
41:
42: void write(DataOutputStream dstr) throws java.io.IOException {
43: dstr.writeByte(tag);
44: dstr.writeInt(value);
45: }
46:
47: public void print(ClassTypeWriter dst, int verbosity) {
48: if (tag == ConstantPool.INTEGER) {
49: if (verbosity > 0)
50: dst.print("Integer ");
51: dst.print(value);
52: if (verbosity > 1 && value != 0) {
53: dst.print("=0x");
54: dst.print(Integer.toHexString(value));
55: }
56: } else // tag == ConstantPool.FLOAT
57: {
58: if (verbosity > 0)
59: dst.print("Float ");
60: dst.print(Float.intBitsToFloat(value));
61: if (verbosity > 1) {
62: dst.print("=0x");
63: dst.print(Integer.toHexString(value));
64: }
65: }
66: }
67: }
|