1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jdo.impl.enhancer.classfile;
20
21 /***
22 * Environment for decoding byte codes into instructions
23 */
24 class InsnReadEnv {
25
26
27 private CodeEnv codeEnv;
28
29
30 private byte[] byteCodes;
31
32
33 private int currPc;
34
35 /***
36 * Constructor
37 */
38 InsnReadEnv(byte[] bytes, CodeEnv codeEnv) {
39 this.byteCodes = bytes;
40 this.currPc = 0;
41 this.codeEnv = codeEnv;
42 }
43
44 /***
45 * Return the index of the next instruction to decode
46 */
47 int currentPC() {
48 return currPc;
49 }
50
51 /***
52 * Are there more byte codes to decode?
53 */
54 boolean more() {
55 return currPc < byteCodes.length;
56 }
57
58 /***
59 * Get a single byte from the byte code stream
60 */
61 byte getByte() {
62 if (!more())
63 throw new InsnError("out of byte codes");
64
65 return byteCodes[currPc++];
66 }
67
68 /***
69 * Get a single unsigned byte from the byte code stream
70 */
71 int getUByte() {
72 return getByte() & 0xff;
73 }
74
75 /***
76 * Get a short from the byte code stream
77 */
78 int getShort() {
79 byte byte1 = byteCodes[currPc++];
80 byte byte2 = byteCodes[currPc++];
81 return (byte1 << 8) | (byte2 & 0xff);
82 }
83
84 /***
85 * Get an unsigned short from the byte code stream
86 */
87 int getUShort() {
88 return getShort() & 0xffff;
89 }
90
91 /***
92 * Get an int from the byte code stream
93 */
94 int getInt() {
95 byte byte1 = byteCodes[currPc++];
96 byte byte2 = byteCodes[currPc++];
97 byte byte3 = byteCodes[currPc++];
98 byte byte4 = byteCodes[currPc++];
99 return (byte1 << 24) | ((byte2 & 0xff) << 16) |
100 ((byte3 & 0xff) << 8) | (byte4 & 0xff);
101 }
102
103 /***
104 * Get the constant pool which applies to the method being decoded
105 */
106 ConstantPool pool() {
107 return codeEnv.pool();
108 }
109
110 /***
111 * Get the canonical InsnTarget instance for the specified
112 * pc within the method.
113 */
114 InsnTarget getTarget(int targ) {
115 return codeEnv.getTarget(targ);
116 }
117 }