1
3 package jminusminus;
4
5 import java.io.DataOutputStream;
6 import java.io.IOException;
7
8 import static jminusminus.CLConstants.*;
9
10
13 abstract class CLCPInfo {
14
17 public int cpIndex;
18
19
22 public short tag;
23
24
30 public void write(CLOutputStream out) throws IOException {
31 out.writeByte(tag);
32 }
33
34
40 public boolean equals(Object other) {
41 return false;
42 }
43 }
44
45
48 class CLConstantClassInfo extends CLCPInfo {
49
52 public int nameIndex;
53
54
59 public CLConstantClassInfo(int nameIndex) {
60 super.tag = CONSTANT_Class;
61 this.nameIndex = nameIndex;
62 }
63
64
67 public void write(CLOutputStream out) throws IOException {
68 super.write(out);
69 out.writeShort(nameIndex);
70 }
71
72
75 public boolean equals(Object other) {
76 if (other instanceof CLConstantClassInfo) {
77 CLConstantClassInfo c = (CLConstantClassInfo) other;
78 if (c.nameIndex == nameIndex) {
79 return true;
80 }
81 }
82 return false;
83 }
84 }
85
86
90 abstract class CLConstantMemberRefInfo extends CLCPInfo {
91
94 public int classIndex;
95
96
99 public int nameAndTypeIndex;
100
101
108 protected CLConstantMemberRefInfo(int classIndex, int nameAndTypeIndex, short tag) {
109 super.tag = tag;
110 this.classIndex = classIndex;
111 this.nameAndTypeIndex = nameAndTypeIndex;
112 }
113
114
117 public void write(CLOutputStream out) throws IOException {
118 super.write(out);
119 out.writeShort(classIndex);
120 out.writeShort(nameAndTypeIndex);
121 }
122
123
126 public boolean equals(Object other) {
127 if (other instanceof CLConstantMemberRefInfo) {
128 CLConstantMemberRefInfo c = (CLConstantMemberRefInfo) other;
129 if ((c.tag == tag) && (c.classIndex == classIndex)
130 && (c.nameAndTypeIndex == nameAndTypeIndex)) {
131 return true;
132 }
133 }
134 return false;
135 }
136 }
137
138
141 class CLConstantFieldRefInfo extends CLConstantMemberRefInfo {
142
148
149 public CLConstantFieldRefInfo(int classIndex, int nameAndTypeIndex) {
150 super(classIndex, nameAndTypeIndex, CONSTANT_Fieldref);
151 }
152 }
153
154
157 class CLConstantMethodRefInfo extends CLConstantMemberRefInfo {
158
164 public CLConstantMethodRefInfo(int classIndex, int nameAndTypeIndex) {
165 super(classIndex, nameAndTypeIndex, CONSTANT_Methodref);
166 }
167 }
168
169
172 class CLConstantInterfaceMethodRefInfo extends CLConstantMemberRefInfo {
173
179 public CLConstantInterfaceMethodRefInfo(int classIndex, int nameAndTypeIndex) {
180 super(classIndex, nameAndTypeIndex, CONSTANT_InterfaceMethodref);
181 }
182 }
183
184
187 class CLConstantStringInfo extends CLCPInfo {
188
191 public int stringIndex;
192
193
198 public CLConstantStringInfo(int stringIndex) {
199 super.tag = CONSTANT_String;
200 this.stringIndex = stringIndex;
201 }
202
203
206 public void write(CLOutputStream out) throws IOException {
207 super.write(out);
208 out.writeShort(stringIndex);
209 }
210
211
214 public boolean equals(Object other) {
215 if (other instanceof CLConstantStringInfo) {
216 CLConstantStringInfo c = (CLConstantStringInfo) other;
217 if (c.stringIndex == stringIndex) {
218 return true;
219 }
220 }
221 return false;
222 }
223 }
224
225
228 class CLConstantIntegerInfo extends CLCPInfo {
229
232 public int i;
233
234
239 public CLConstantIntegerInfo(int i) {
240 super.tag = CONSTANT_Integer;
241 this.i = i;
242 }
243
244
249 public short[] bytes() {
250 short[] s = new short[4];
251 short mask = 0xFF;
252 int k = i;
253 for (int j = 0; j < 4; j++) {
254 s[3 - j] = (short) (k & mask);
255 k >>>= 8;
256 }
257 return s;
258 }
259
260
263 public void write(CLOutputStream out) throws IOException {
264 super.write(out);
265
266 ((DataOutputStream) out).writeInt(i);
268 }
269
270
273 public boolean equals(Object other) {
274 if (other instanceof CLConstantIntegerInfo) {
275 CLConstantIntegerInfo c = (CLConstantIntegerInfo) other;
276 if (c.i == i) {
277 return true;
278 }
279 }
280 return false;
281 }
282 }
283
284
287 class CLConstantFloatInfo extends CLCPInfo {
288
291 public float f;
292
293
298 public CLConstantFloatInfo(float f) {
299 super.tag = CONSTANT_Float;
300 this.f = f;
301 }
302
303
308 public short[] bytes() {
309 short[] s = new short[4];
310 short mask = 0xFF;
311 int i = Float.floatToIntBits(f);
312 for (int j = 0; j < 4; j++) {
313 s[3 - j] = (short) (i & mask);
314 i >>>= 8;
315 }
316 return s;
317 }
318
319
322 public void write(CLOutputStream out) throws IOException {
323 super.write(out);
324 out.writeFloat(f);
325 }
326
327
330 public boolean equals(Object other) {
331 if (other instanceof CLConstantFloatInfo) {
332 CLConstantFloatInfo c = (CLConstantFloatInfo) other;
333 if (c.f == f) {
334 return true;
335 }
336 }
337 return false;
338 }
339 }
340
341
344 class CLConstantLongInfo extends CLCPInfo {
345
348 public long l;
349
350
355 private short[] bytes() {
356 short[] s = new short[8];
357 short mask = 0xFF;
358 long k = l;
359 for (int j = 0; j < 8; j++) {
360 s[7 - j] = (short) (k & mask);
361 k >>>= 8;
362 }
363 return s;
364 }
365
366
371 public CLConstantLongInfo(long l) {
372 super.tag = CONSTANT_Long;
373 this.l = l;
374 }
375
376
381 public short[] lowBytes() {
382 short[] s = bytes();
383 short[] l = new short[4];
384 l[0] = s[4];
385 l[1] = s[5];
386 l[2] = s[6];
387 l[3] = s[7];
388 return l;
389 }
390
391
396 public short[] highBytes() {
397 short[] s = bytes();
398 short[] h = new short[4];
399 h[0] = s[0];
400 h[1] = s[1];
401 h[2] = s[2];
402 h[3] = s[3];
403 return h;
404 }
405
406
409 public void write(CLOutputStream out) throws IOException {
410 super.write(out);
411 out.writeLong(l);
412 }
413
414
417 public boolean equals(Object other) {
418 if (other instanceof CLConstantLongInfo) {
419 CLConstantLongInfo c = (CLConstantLongInfo) other;
420 if (c.l == l) {
421 return true;
422 }
423 }
424 return false;
425 }
426 }
427
428
431 class CLConstantDoubleInfo extends CLCPInfo {
432
435 public double d;
436
437
442 private short[] bytes() {
443 short[] s = new short[8];
444 short mask = 0xFF;
445 long l = Double.doubleToLongBits(d);
446 for (int j = 0; j < 8; j++) {
447 s[7 - j] = (short) (l & mask);
448 l >>>= 8;
449 }
450 return s;
451 }
452
453
458 public CLConstantDoubleInfo(double d) {
459 super.tag = CONSTANT_Double;
460 this.d = d;
461 }
462
463
468 public short[] lowBytes() {
469 short[] s = bytes();
470 short[] l = new short[4];
471 l[0] = s[4];
472 l[1] = s[5];
473 l[2] = s[6];
474 l[3] = s[7];
475 return l;
476 }
477
478
483 public short[] highBytes() {
484 short[] s = bytes();
485 short[] h = new short[4];
486 h[0] = s[0];
487 h[1] = s[1];
488 h[2] = s[2];
489 h[3] = s[3];
490 return h;
491 }
492
493
496 public void write(CLOutputStream out) throws IOException {
497 super.write(out);
498 out.writeDouble(d);
499 }
500
501
504 public boolean equals(Object other) {
505 if (other instanceof CLConstantDoubleInfo) {
506 CLConstantDoubleInfo c = (CLConstantDoubleInfo) other;
507 if (c.d == d) {
508 return true;
509 }
510 }
511 return false;
512 }
513 }
514
515
518 class CLConstantNameAndTypeInfo extends CLCPInfo {
519
522 public int nameIndex;
523
524
527 public int descriptorIndex;
528
529
535 public CLConstantNameAndTypeInfo(int nameIndex, int descriptorIndex) {
536 super.tag = CONSTANT_NameAndType;
537 this.nameIndex = nameIndex;
538 this.descriptorIndex = descriptorIndex;
539 }
540
541
544 public void write(CLOutputStream out) throws IOException {
545 super.write(out);
546 out.writeShort(nameIndex);
547 out.writeShort(descriptorIndex);
548 }
549
550
553
554 public boolean equals(Object other) {
555 if (other instanceof CLConstantNameAndTypeInfo) {
556 CLConstantNameAndTypeInfo c = (CLConstantNameAndTypeInfo) other;
557 if ((c.nameIndex == nameIndex) && (c.descriptorIndex == descriptorIndex)) {
558 return true;
559 }
560 }
561 return false;
562 }
563 }
564
565
568 class CLConstantUtf8Info extends CLCPInfo {
569
572 public byte[] b;
573
574
579 public CLConstantUtf8Info(byte[] b) {
580 super.tag = CONSTANT_Utf8;
581 this.b = b;
582 }
583
584
589 public int length() {
590 return b.length;
591 }
592
593
596 public void write(CLOutputStream out) throws IOException {
597 super.write(out);
598 out.writeUTF(new String(b));
599 }
600
601
604 public boolean equals(Object other) {
605 if (other instanceof CLConstantUtf8Info) {
606 CLConstantUtf8Info c = (CLConstantUtf8Info) other;
607 if ((new String(b)).equals(new String(c.b))) {
608 return true;
609 }
610 }
611 return false;
612 }
613 }
614