CpoolValue2.java 1.4 KB

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