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