author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Thu, 19 Mar 2015 17:27:21 +0000 | |
branch | cvs_MAIN_tracking |
changeset 3408 | 4f3cc813be4b |
parent 3324 | a58245c0e83a |
child 3360 | 1a8899091305 |
permissions | -rw-r--r-- |
454 | 1 |
" |
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2731
diff
changeset
|
2 |
COPYRIGHT (c) 1996-2015 by Claus Gittinger |
454 | 3 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
4 |
New code and modifications done at SWING Research Group [1]: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
5 |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2731
diff
changeset
|
6 |
COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
7 |
SWING Research Group, Czech Technical University in Prague |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
8 |
|
454 | 9 |
This software is furnished under a license and may be used |
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
15 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
16 |
[1] Code written at SWING Research Group contains a signature |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
17 |
of one of the above copright owners. For exact set of such code, |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
18 |
see the differences between this version and version stx:libjava |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
19 |
as of 1.9.2010 |
2151 | 20 |
" |
701 | 21 |
"{ Package: 'stx:libjava' }" |
22 |
||
6 | 23 |
Object subclass:#JavaDecompiler |
454 | 24 |
instanceVariableNames:'code pc javaMethod outStream classToCompileFor isStaticMethod |
25 |
lastConstIndex lastConstant accessedInstvars modifiedInstvars |
|
26 |
accessedStaticVars modifiedStaticVars sentMessages' |
|
6 | 27 |
classVariableNames:'DecoderTable' |
28 |
poolDictionaries:'' |
|
2108 | 29 |
category:'Languages-Java-Support-Decompiling' |
6 | 30 |
! |
31 |
||
454 | 32 |
!JavaDecompiler class methodsFor:'documentation'! |
33 |
||
34 |
copyright |
|
35 |
" |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2731
diff
changeset
|
36 |
COPYRIGHT (c) 1996-2015 by Claus Gittinger |
454 | 37 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
38 |
New code and modifications done at SWING Research Group [1]: |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
39 |
|
3324
a58245c0e83a
Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2731
diff
changeset
|
40 |
COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
41 |
SWING Research Group, Czech Technical University in Prague |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
42 |
|
454 | 43 |
This software is furnished under a license and may be used |
44 |
only in accordance with the terms of that license and with the |
|
45 |
inclusion of the above copyright notice. This software may not |
|
46 |
be provided or otherwise made available to, or used by, any |
|
47 |
other person. No title to or ownership of the software is |
|
48 |
hereby transferred. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
49 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
50 |
[1] Code written at SWING Research Group contains a signature |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
51 |
of one of the above copright owners. For exact set of such code, |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
52 |
see the differences between this version and version stx:libjava |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
53 |
as of 1.9.2010 |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
54 |
|
2095 | 55 |
" |
454 | 56 |
! |
57 |
||
58 |
examples |
|
59 |
" |
|
60 |
||
61 |
[exBegin] |
|
62 |
|m| |
|
63 |
||
64 |
m := JAVA::java::lang::Object compiledMethodAt:#'toString()Ljava/lang/String;'. |
|
65 |
JavaDecompiler decompile:m to:Transcript. |
|
66 |
[exEnd] |
|
67 |
||
68 |
||
69 |
||
70 |
[exBegin] |
|
71 |
|m| |
|
72 |
||
73 |
m := JAVA::java::lang::Object compiledMethodAt:#'toString()Ljava/lang/String;'. |
|
74 |
JavaDecompiler decompile:m to:nil. |
|
75 |
[exEnd] |
|
76 |
||
77 |
" |
|
78 |
||
79 |
! ! |
|
6 | 80 |
|
129 | 81 |
!JavaDecompiler class methodsFor:'initialization'! |
6 | 82 |
|
83 |
initialize |
|
84 |
DecoderTable := #( |
|
85 |
(nop) "/ 0 |
|
86 |
(aconst_null) "/ 1 |
|
87 |
(iconst_m1) "/ 2 |
|
88 |
(iconst_0) "/ 3 |
|
89 |
(iconst_1) "/ 4 |
|
90 |
(iconst_2) "/ 5 |
|
91 |
(iconst_3) "/ 6 |
|
92 |
(iconst_4) "/ 7 |
|
93 |
(iconst_5) "/ 8 |
|
94 |
(lconst_0) "/ 9 |
|
95 |
||
96 |
(lconst_1) "/ 10 |
|
97 |
(fconst_0) "/ 11 |
|
98 |
(fconst_1) "/ 12 |
|
99 |
(fconst_2) "/ 13 |
|
100 |
(dconst_0) "/ 14 |
|
101 |
(dconst_1) "/ 15 |
|
102 |
(bipush signedByte) "/ 16 |
|
103 |
(sipush signedShort) "/ 17 |
|
454 | 104 |
(ldc1 constIndexByte remember_ldc1) "/ 18 |
105 |
(ldc2 constIndexShort remember_ldc2) "/ 19 |
|
6 | 106 |
|
454 | 107 |
(ldc2w constIndexShort remember_ldc2w) "/ 20 |
6 | 108 |
(iload localIndexByte) "/ 21 |
109 |
(lload localIndexByte) "/ 22 |
|
110 |
(fload localIndexByte) "/ 23 |
|
111 |
(dload localIndexByte) "/ 24 |
|
112 |
(aload localIndexByte) "/ 25 |
|
24 | 113 |
(iload_0) "/ 26 |
6 | 114 |
(iload_1) "/ 27 |
115 |
(iload_2) "/ 28 |
|
116 |
(iload_3) "/ 29 |
|
117 |
||
118 |
(lload_0) "/ 30 |
|
119 |
(lload_1) "/ 31 |
|
120 |
(lload_2) "/ 32 |
|
121 |
(lload_3) "/ 33 |
|
122 |
(fload_0) "/ 34 |
|
123 |
(fload_1) "/ 35 |
|
124 |
(fload_2) "/ 36 |
|
125 |
(fload_3) "/ 37 |
|
126 |
(dload_0) "/ 38 |
|
127 |
(dload_1) "/ 39 |
|
128 |
||
129 |
(dload_2) "/ 40 |
|
130 |
(dload_3) "/ 41 |
|
131 |
(aload_0) "/ 42 |
|
132 |
(aload_1) "/ 43 |
|
133 |
(aload_2) "/ 44 |
|
134 |
(aload_3) "/ 45 |
|
135 |
(iaload) "/ 46 |
|
136 |
(laload) "/ 47 |
|
137 |
(faload) "/ 48 |
|
138 |
(daload) "/ 49 |
|
139 |
||
140 |
(aaload) "/ 50 |
|
141 |
(baload) "/ 51 |
|
142 |
(caload) "/ 52 |
|
143 |
(saload) "/ 53 |
|
144 |
(istore localIndexByte) "/ 54 |
|
145 |
(lstore localIndexByte) "/ 55 |
|
146 |
(fstore localIndexByte) "/ 56 |
|
147 |
(dstore localIndexByte) "/ 57 |
|
148 |
(astore localIndexByte) "/ 58 |
|
149 |
(istore_0) "/ 59 |
|
150 |
||
151 |
(istore_1) "/ 60 |
|
152 |
(istore_2) "/ 61 |
|
153 |
(istore_3) "/ 62 |
|
154 |
(lstore_0) "/ 63 |
|
155 |
(lstore_1) "/ 64 |
|
156 |
(lstore_2) "/ 65 |
|
157 |
(lstore_3) "/ 66 |
|
158 |
(fstore_0) "/ 67 |
|
159 |
(fstore_1) "/ 68 |
|
160 |
(fstore_2) "/ 69 |
|
161 |
||
162 |
(fstore_3) "/ 70 |
|
163 |
(dstore_0) "/ 71 |
|
164 |
(dstore_1) "/ 72 |
|
165 |
(dstore_2) "/ 73 |
|
166 |
(dstore_3) "/ 74 |
|
167 |
(astore_0) "/ 75 |
|
168 |
(astore_1) "/ 76 |
|
169 |
(astore_2) "/ 77 |
|
170 |
(astore_3) "/ 78 |
|
171 |
(iastore) "/ 79 |
|
172 |
||
173 |
(lastore) "/ 80 |
|
174 |
(fastore) "/ 81 |
|
175 |
(dastore) "/ 82 |
|
176 |
(aastore) "/ 83 |
|
177 |
(bastore) "/ 84 |
|
178 |
(castore) "/ 85 |
|
179 |
(sastore) "/ 86 |
|
180 |
(pop) "/ 87 |
|
181 |
(pop2) "/ 88 |
|
182 |
(dup) "/ 89 |
|
183 |
||
184 |
(dup_x1) "/ 90 |
|
185 |
(dup_x2) "/ 91 |
|
186 |
(dup2) "/ 92 |
|
187 |
(dup2_x1) "/ 93 |
|
188 |
(dup2_x2) "/ 94 |
|
189 |
(swap) "/ 95 |
|
190 |
(iadd) "/ 96 |
|
191 |
(ladd) "/ 97 |
|
192 |
(fadd) "/ 98 |
|
193 |
(dadd) "/ 99 |
|
194 |
||
195 |
(isub) "/ 100 |
|
196 |
(lsub) "/ 101 |
|
197 |
(fsub) "/ 102 |
|
198 |
(dsub) "/ 103 |
|
199 |
(imul) "/ 104 |
|
200 |
(lmul) "/ 105 |
|
201 |
(fmul) "/ 106 |
|
202 |
(dmul) "/ 107 |
|
203 |
(idiv) "/ 108 |
|
204 |
(ldiv) "/ 109 |
|
205 |
||
206 |
(fdiv) "/ 110 |
|
207 |
(ddiv) "/ 111 |
|
91 | 208 |
"/ (imod) "/ 112 "/ obsolete |
209 |
(irem) "/ 112 |
|
210 |
"/ (lmod) "/ 113 "/ obsolete |
|
211 |
(lrem) "/ 113 |
|
212 |
"/ (fmod) "/ 114 "/ obsolete |
|
213 |
(frem) "/ 114 |
|
214 |
"/ (dmod) "/ 115 "/ obsolete |
|
215 |
(drem) "/ 115 |
|
6 | 216 |
(ineg) "/ 116 |
217 |
(lneg) "/ 117 |
|
218 |
(fneg) "/ 118 |
|
219 |
(dneg) "/ 119 |
|
220 |
||
221 |
(ishl) "/ 120 |
|
222 |
(lshl) "/ 121 |
|
223 |
(ishr) "/ 122 |
|
224 |
(lshr) "/ 123 |
|
225 |
(iushr) "/ 124 |
|
226 |
(lushr) "/ 125 |
|
227 |
(iand) "/ 126 |
|
228 |
(land) "/ 127 |
|
229 |
(ior) "/ 128 |
|
230 |
(lor) "/ 129 |
|
231 |
||
232 |
(ixor) "/ 130 |
|
233 |
(lxor) "/ 131 |
|
39 | 234 |
(iinc localIndexByte signedByte) "/ 132 |
68 | 235 |
(i2l) "/ 133 |
44 | 236 |
(i2f) "/ 134 |
52 | 237 |
(i2d) "/ 135 |
44 | 238 |
(l2i) "/ 136 |
6 | 239 |
(l2f) "/ 137 |
240 |
(l2d) "/ 138 |
|
44 | 241 |
(f2i) "/ 139 |
6 | 242 |
|
243 |
(f2l) "/ 140 |
|
244 |
(f2d) "/ 141 |
|
245 |
(d2i) "/ 142 |
|
246 |
(d2l) "/ 143 |
|
247 |
(d2f) "/ 144 |
|
248 |
(int2byte) "/ 145 |
|
249 |
(int2char) "/ 146 |
|
250 |
(int2short) "/ 147 |
|
251 |
(lcmp) "/ 148 |
|
252 |
(fcmpl) "/ 149 |
|
253 |
||
254 |
(fcmpg) "/ 150 |
|
255 |
(dcmpl) "/ 151 |
|
256 |
(dcmpg) "/ 152 |
|
257 |
(ifeq signedBranchShort) "/ 153 |
|
258 |
(ifne signedBranchShort) "/ 154 |
|
259 |
(iflt signedBranchShort) "/ 155 |
|
260 |
(ifge signedBranchShort) "/ 156 |
|
261 |
(ifgt signedBranchShort) "/ 157 |
|
262 |
(ifle signedBranchShort) "/ 158 |
|
263 |
(if_icmpeq signedBranchShort) "/ 159 |
|
264 |
||
265 |
(if_icmpne signedBranchShort) "/ 160 |
|
266 |
(if_icmplt signedBranchShort) "/ 161 |
|
267 |
(if_icmpge signedBranchShort) "/ 162 |
|
268 |
(if_icmpgt signedBranchShort) "/ 163 |
|
269 |
(if_icmple signedBranchShort) "/ 164 |
|
270 |
(if_acmpeq signedBranchShort) "/ 165 |
|
271 |
(if_acmpne signedBranchShort) "/ 166 |
|
272 |
(goto signedBranchShort) "/ 167 |
|
273 |
(jsr signedBranchShort) "/ 168 |
|
274 |
(ret localIndexByte) "/ 169 |
|
275 |
||
276 |
(tableswitch tableSwitchBytes) "/ 170 |
|
277 |
(lookupswitch lookupSwitchBytes) "/ 171 |
|
278 |
(ireturn) "/ 172 |
|
279 |
(lreturn) "/ 173 |
|
280 |
(freturn) "/ 174 |
|
281 |
(dreturn) "/ 175 |
|
282 |
(areturn) "/ 176 |
|
283 |
(return) "/ 177 |
|
454 | 284 |
(getstatic constIndexShort remember_getstatic) "/ 178 |
285 |
(putstatic constIndexShort remember_putstatic) "/ 179 |
|
6 | 286 |
|
454 | 287 |
(getfield constIndexShort remember_getfield) "/ 180 |
288 |
(putfield constIndexShort remember_putfield) "/ 181 |
|
289 |
(invokevirtual constIndexShort remember_invokevirtual) "/ 182 |
|
290 |
(invokenonvirtual constIndexShort remember_invokenonvirtual) "/ 183 |
|
291 |
(invokestatic constIndexShort remember_invokestatic) "/ 184 |
|
292 |
(invokeinterface constIndexShort nargsByte reservedByte remember_invokeinterface) "/ 185 |
|
6 | 293 |
(newfromname) "/ 186 |
454 | 294 |
(new constIndexShort remember_new) "/ 187 |
6 | 295 |
(newarray arrayTypeByte) "/ 188 |
296 |
(anewarray constIndexShort) "/ 189 |
|
297 |
||
298 |
(arraylength) "/ 190 |
|
454 | 299 |
(athrow remember_athrow) "/ 191 |
27 | 300 |
(checkcast constIndexShort) "/ 192 |
6 | 301 |
(instanceof constIndexShort) "/ 193 |
302 |
(monitorenter) "/ 194 |
|
303 |
(monitorexit) "/ 195 |
|
68 | 304 |
"/ (verifystack) "/ 196 obsolete (Alpha release) |
198 | 305 |
(wide) "/ 196 |
68 | 306 |
(multianewarray constIndexShort dimensionsByte) "/ 197 |
41 | 307 |
|
68 | 308 |
(ifnull signedBranchShort) "/ 198 |
309 |
(ifnonnull signedBranchShort) "/ 199 |
|
6 | 310 |
|
68 | 311 |
(#'goto_w' signedBranchLong) "/ 200 |
312 |
(#'jsr_w' signedBranchShort) "/ 201 |
|
313 |
||
314 |
(breakpoint) "/ 202 |
|
315 |
||
6 | 316 |
nil "/ 203 |
317 |
nil "/ 204 |
|
318 |
nil "/ 205 |
|
68 | 319 |
nil "/ 206 |
6 | 320 |
nil "/ 207 |
321 |
nil "/ 208 |
|
68 | 322 |
(#'ret_w' signedBranchShort) "/ 209 |
6 | 323 |
|
324 |
nil "/ 210 |
|
325 |
nil "/ 211 |
|
326 |
nil "/ 212 |
|
327 |
nil "/ 213 |
|
328 |
nil "/ 214 |
|
329 |
nil "/ 215 |
|
330 |
nil "/ 216 |
|
331 |
nil "/ 217 |
|
332 |
nil "/ 218 |
|
333 |
nil "/ 219 |
|
334 |
||
335 |
nil "/ 220 |
|
336 |
nil "/ 221 |
|
337 |
nil "/ 222 |
|
338 |
nil "/ 223 |
|
339 |
nil "/ 224 |
|
340 |
nil "/ 225 |
|
341 |
nil "/ 226 |
|
342 |
nil "/ 227 |
|
343 |
nil "/ 228 |
|
344 |
nil "/ 229 |
|
345 |
||
346 |
nil "/ 230 |
|
347 |
nil "/ 231 |
|
348 |
nil "/ 232 |
|
349 |
nil "/ 233 |
|
350 |
nil "/ 234 |
|
351 |
nil "/ 235 |
|
352 |
nil "/ 236 |
|
353 |
nil "/ 237 |
|
354 |
nil "/ 238 |
|
355 |
nil "/ 239 |
|
356 |
||
357 |
nil "/ 240 |
|
358 |
nil "/ 241 |
|
359 |
nil "/ 242 |
|
360 |
nil "/ 243 |
|
361 |
nil "/ 244 |
|
362 |
nil "/ 245 |
|
363 |
nil "/ 246 |
|
364 |
nil "/ 247 |
|
365 |
nil "/ 248 |
|
366 |
nil "/ 249 |
|
367 |
||
368 |
nil "/ 250 |
|
369 |
nil "/ 251 |
|
370 |
nil "/ 252 |
|
371 |
nil "/ 253 |
|
372 |
nil "/ 254 |
|
124 | 373 |
(invokenonvirtual_d constIndexShort) "/ 255 special - dummy invokenonvirtual |
6 | 374 |
) |
375 |
||
376 |
" |
|
377 |
JavaDecompiler initialize |
|
378 |
" |
|
379 |
||
454 | 380 |
"Modified: / 16.11.1998 / 15:55:49 / cg" |
6 | 381 |
! ! |
382 |
||
129 | 383 |
!JavaDecompiler class methodsFor:'accessing'! |
27 | 384 |
|
385 |
instructionTable |
|
386 |
^ DecoderTable |
|
387 |
! ! |
|
388 |
||
161 | 389 |
!JavaDecompiler class methodsFor:'class definition generation'! |
390 |
||
391 |
definitionOf:aJavaClass on:s |
|
392 |
|pckgName needCR fields staticFields superClass |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
393 |
interfaces staticMethods nonStaticMethods |
187 | 394 |
accessAttributeStyle codeStyle classNameStyle methodNameStyle| |
395 |
||
396 |
accessAttributeStyle := Java prettyPrintStyle at:#accessAttribute. |
|
397 |
codeStyle := Java prettyPrintStyle at:#code. |
|
398 |
classNameStyle := Java prettyPrintStyle at:#className. |
|
399 |
methodNameStyle := Java prettyPrintStyle at:#className. |
|
161 | 400 |
|
401 |
pckgName := aJavaClass package. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
402 |
pckgName ~= 'java' ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
403 |
s nextPutAll:'package ' , ((pckgName copyFrom: 6) copyReplaceAll:$/ with:$.). |
175 | 404 |
s nextPutAll:';'; cr; cr. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
405 |
|
175 | 406 |
]. |
161 | 407 |
|
408 |
needCR := false. |
|
187 | 409 |
s emphasis:accessAttributeStyle. |
410 |
||
161 | 411 |
aJavaClass isPublic ifTrue:[ |
412 |
s nextPutAll:'public '. |
|
413 |
needCR := true. |
|
414 |
]. |
|
415 |
aJavaClass isAbstract ifTrue:[ |
|
416 |
s nextPutAll:'abstract '. |
|
417 |
needCR := true. |
|
418 |
]. |
|
419 |
aJavaClass isFinal ifTrue:[ |
|
420 |
s nextPutAll:'final '. |
|
421 |
needCR := true. |
|
422 |
]. |
|
187 | 423 |
s emphasis:codeStyle. |
161 | 424 |
|
425 |
needCR ifTrue:[ |
|
426 |
s cr |
|
427 |
]. |
|
428 |
aJavaClass isInterface ifTrue:[ |
|
429 |
s nextPutAll:'interface '. |
|
430 |
] ifFalse:[ |
|
431 |
s nextPutAll:'class '. |
|
432 |
]. |
|
187 | 433 |
s emphasis:classNameStyle; |
423 | 434 |
nextPutAll:aJavaClass lastName; |
187 | 435 |
emphasis:codeStyle; |
436 |
space. |
|
161 | 437 |
superClass := aJavaClass superclass. |
438 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
439 |
(superClass ~~ (JavaVM classNamed:'java/lang/Object') |
591 | 440 |
and:[superClass isJavaClass]) ifTrue:[ |
161 | 441 |
s nextPutAll:'extends '. |
187 | 442 |
s emphasis:classNameStyle. |
161 | 443 |
(superClass package ~= 'java/lang' |
444 |
and:[superClass package ~= pckgName]) ifTrue:[ |
|
187 | 445 |
s nextPutAll:(superClass displayString). |
161 | 446 |
] ifFalse:[ |
423 | 447 |
s nextPutAll:(superClass lastName). |
187 | 448 |
]. |
449 |
s emphasis:codeStyle. |
|
450 |
s space. |
|
161 | 451 |
]. |
452 |
||
453 |
(interfaces := aJavaClass interfaces) size > 0 ifTrue:[ |
|
165 | 454 |
(aJavaClass isInterface |
455 |
and:[interfaces size == 1]) ifTrue:[ |
|
456 |
s nextPutAll:'extends '. |
|
457 |
] ifFalse:[ |
|
458 |
s nextPutAll:'implements '. |
|
459 |
]. |
|
161 | 460 |
interfaces keysAndValuesDo:[:nr :if | |
443 | 461 |
|nameString| |
462 |
||
161 | 463 |
nr ~~ 1 ifTrue:[ |
464 |
s nextPutAll:', '. |
|
465 |
]. |
|
187 | 466 |
s emphasis:classNameStyle. |
161 | 467 |
(if package ~= 'java/lang' |
468 |
and:[if package ~= pckgName]) ifTrue:[ |
|
443 | 469 |
if isJavaClass ifFalse:[ |
470 |
"/ ought to be an unresolved class ... |
|
471 |
nameString := if fullName copyReplaceAll:$/ with:$. |
|
472 |
] ifTrue:[ |
|
473 |
nameString := if displayString |
|
474 |
]. |
|
161 | 475 |
] ifFalse:[ |
443 | 476 |
nameString := if lastName |
187 | 477 |
]. |
443 | 478 |
s nextPutAll:nameString. |
187 | 479 |
s emphasis:codeStyle. |
161 | 480 |
]. |
481 |
s space. |
|
482 |
]. |
|
483 |
||
484 |
s nextPutAll:'{'; cr. |
|
485 |
||
486 |
needCR := false. |
|
487 |
staticFields := aJavaClass staticFields. |
|
488 |
staticFields size > 0 ifTrue:[ |
|
489 |
needCR := true. |
|
490 |
||
491 |
staticFields do:[:aField | |
|
492 |
|type v| |
|
493 |
||
494 |
s nextPutAll:' '. |
|
187 | 495 |
s emphasis:accessAttributeStyle. |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
496 |
aField isSynthetic ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
497 |
s nextPutAll: '/*SYNTHETIC*/ '. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
498 |
]. |
161 | 499 |
aField isPublic ifTrue:[ |
500 |
s nextPutAll:'public '. |
|
501 |
] ifFalse:[ |
|
487 | 502 |
aField isPrivate ifTrue:[ |
503 |
s nextPutAll:'private '. |
|
504 |
] ifFalse:[ |
|
505 |
aField isProtected ifTrue:[ |
|
506 |
s nextPutAll:'protected '. |
|
507 |
] |
|
508 |
] |
|
161 | 509 |
]. |
510 |
s nextPutAll:'static '. |
|
511 |
aField isFinal ifTrue:[ |
|
512 |
s nextPutAll:'final '. |
|
513 |
]. |
|
488 | 514 |
aField isVolatile ifTrue:[ |
515 |
s nextPutAll:'volatile '. |
|
516 |
]. |
|
187 | 517 |
s emphasis:codeStyle. |
161 | 518 |
|
594 | 519 |
(((type := aField type) startsWith:pckgName) |
520 |
or:[type startsWith:(pckgName copyReplaceAll:$/ with:$.)]) ifTrue:[ |
|
161 | 521 |
type := type copyFrom:(pckgName size + 1 + 1). |
522 |
] ifFalse:[ |
|
523 |
(type startsWith:'java.lang.') ifTrue:[ |
|
524 |
type := type copyFrom:(11). |
|
525 |
] |
|
526 |
]. |
|
527 |
type := type copy replaceAll:$/ with:$.. |
|
528 |
s nextPutAll:type; space; |
|
529 |
nextPutAll:aField name. |
|
530 |
||
531 |
(v := aField constantValue) notNil ifTrue:[ |
|
532 |
s nextPutAll:' = '; nextPutAll:v displayString. |
|
533 |
]. |
|
534 |
||
535 |
s nextPutAll:';'; cr. |
|
536 |
needCR := true. |
|
537 |
]. |
|
538 |
]. |
|
539 |
||
540 |
||
541 |
fields := aJavaClass fields. |
|
542 |
fields size > 0 ifTrue:[ |
|
543 |
needCR ifTrue:[ |
|
544 |
s cr |
|
545 |
]. |
|
546 |
needCR := true. |
|
547 |
||
548 |
fields do:[:aField | |
|
593 | 549 |
|type v| |
161 | 550 |
|
551 |
s nextPutAll:' '. |
|
187 | 552 |
s emphasis:accessAttributeStyle. |
161 | 553 |
aField isPublic ifTrue:[ |
554 |
s nextPutAll:'public '. |
|
555 |
] ifFalse:[ |
|
487 | 556 |
aField isPrivate ifTrue:[ |
557 |
s nextPutAll:'private '. |
|
558 |
] ifFalse:[ |
|
559 |
aField isProtected ifTrue:[ |
|
560 |
s nextPutAll:'protected '. |
|
561 |
] |
|
562 |
] |
|
161 | 563 |
]. |
564 |
aField isFinal ifTrue:[ |
|
565 |
s nextPutAll:'final '. |
|
566 |
]. |
|
488 | 567 |
aField isTransient ifTrue:[ |
568 |
s nextPutAll:'transient '. |
|
569 |
]. |
|
570 |
aField isVolatile ifTrue:[ |
|
571 |
s nextPutAll:'volatile '. |
|
572 |
]. |
|
187 | 573 |
s emphasis:codeStyle. |
161 | 574 |
|
594 | 575 |
(((type := aField type) startsWith:pckgName) |
576 |
or:[type startsWith:(pckgName copyReplaceAll:$/ with:$.)]) ifTrue:[ |
|
161 | 577 |
type := type copyFrom:(pckgName size + 1 + 1). |
578 |
]. |
|
579 |
type := type copy replaceAll:$/ with:$.. |
|
580 |
s nextPutAll:type; space; |
|
593 | 581 |
nextPutAll:aField name. |
582 |
||
583 |
(v := aField constantValue) notNil ifTrue:[ |
|
584 |
s nextPutAll:' = '; nextPutAll:v displayString. |
|
585 |
]. |
|
586 |
s nextPutAll:';'; cr. |
|
161 | 587 |
]. |
588 |
]. |
|
589 |
||
590 |
aJavaClass methodDictionary size > 0 ifTrue:[ |
|
591 |
needCR ifTrue:[ |
|
190 | 592 |
s cr. |
593 |
needCR := false. |
|
161 | 594 |
]. |
595 |
||
450 | 596 |
staticMethods := OrderedCollection new. |
597 |
nonStaticMethods := OrderedCollection new. |
|
190 | 598 |
"/ |
599 |
"/ static methods first ... |
|
600 |
"/ |
|
601 |
aJavaClass methodDictionary do:[:aMethod | |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
602 |
aMethod isJavaMethod ifTrue:[ |
450 | 603 |
|m| |
604 |
||
605 |
m := aMethod. |
|
606 |
m isWrapped ifTrue:[ |
|
607 |
m := m originalMethod |
|
161 | 608 |
]. |
450 | 609 |
m isStatic ifTrue:[ |
610 |
staticMethods add:m. |
|
611 |
] ifFalse:[ |
|
612 |
nonStaticMethods add:m. |
|
613 |
] |
|
190 | 614 |
]. |
161 | 615 |
|
450 | 616 |
staticMethods notEmpty ifTrue:[ |
617 |
staticMethods sort:[:a :b | a name < b name]. |
|
618 |
staticMethods do:[:aMethod | |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
619 |
"JV@2011-12-14: method dictionary may contain non-Java methods |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
620 |
(proxies, for instance)" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
621 |
aMethod isJavaMethod ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
622 |
self methodDefinitionOf:aMethod inPackage:pckgName on:s. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
623 |
] |
161 | 624 |
]. |
190 | 625 |
s cr. |
626 |
]. |
|
161 | 627 |
|
190 | 628 |
"/ |
629 |
"/ instance methods ... |
|
630 |
"/ |
|
450 | 631 |
nonStaticMethods notEmpty ifTrue:[ |
632 |
nonStaticMethods sort:[:a :b | a name < b name]. |
|
633 |
nonStaticMethods do:[:aMethod | |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
634 |
"JV@2011-12-14: method dictionary may contain non-Java methods |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
635 |
(proxies, for instance)" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
636 |
aMethod isJavaMethod ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
637 |
self methodDefinitionOf:aMethod inPackage:pckgName on:s. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
638 |
] |
161 | 639 |
]. |
640 |
]. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
641 |
] |
161 | 642 |
]. |
643 |
||
644 |
s nextPutAll:'}'; cr. |
|
645 |
||
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
646 |
"Created: / 22-03-1997 / 14:29:37 / cg" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
647 |
"Modified: / 05-12-1998 / 15:58:37 / cg" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
648 |
"Modified: / 21-10-2011 / 13:40:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
649 |
"Modified: / 31-03-2012 / 00:36:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
190 | 650 |
! |
651 |
||
2151 | 652 |
methodDefinitionOf: m inPackage: pckgName on: s |
653 |
| aMethod nm specComponents accessAttributeStyle codeStyle methodNameStyle | |
|
450 | 654 |
|
655 |
aMethod := m. |
|
2151 | 656 |
m isWrapped ifTrue: [ |
450 | 657 |
aMethod := m originalMethod |
658 |
]. |
|
2151 | 659 |
accessAttributeStyle := Java prettyPrintStyle at: #accessAttribute. |
660 |
codeStyle := Java prettyPrintStyle at: #code. |
|
661 |
methodNameStyle := Java prettyPrintStyle at: #methodName. |
|
662 |
s nextPutAll: ' '. |
|
663 |
s emphasis: accessAttributeStyle. |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
664 |
aMethod isSynthetic ifTrue:[ |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
665 |
s nextPutAll: '/*SYNTHETIC*/ '. |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
666 |
]. |
2151 | 667 |
aMethod isPublic ifTrue: [ |
668 |
s nextPutAll: 'public '. |
|
669 |
] ifFalse: [ |
|
670 |
aMethod isProtected ifTrue: [ |
|
671 |
s nextPutAll: 'protected '. |
|
672 |
] ifFalse: [ s nextPutAll: 'private '. ] |
|
190 | 673 |
]. |
2151 | 674 |
aMethod isFinal ifTrue: [ |
675 |
s nextPutAll: 'final '. |
|
190 | 676 |
]. |
2151 | 677 |
aMethod isStatic ifTrue: [ |
678 |
s nextPutAll: 'static '. |
|
190 | 679 |
]. |
2151 | 680 |
aMethod isNative ifTrue: [ |
681 |
s nextPutAll: 'native '. |
|
190 | 682 |
]. |
2151 | 683 |
aMethod isSynchronized ifTrue: [ |
684 |
s nextPutAll: 'synchronized '. |
|
190 | 685 |
]. |
2151 | 686 |
s emphasis: codeStyle. |
687 |
(nm := aMethod name) = '<init>' ifTrue: [ |
|
423 | 688 |
nm := aMethod javaClass lastName. |
190 | 689 |
]. |
2151 | 690 |
specComponents := JavaMethod |
691 |
specComponentsWithArgsFromSignature: (aMethod instVarNamed:#descriptor) |
|
692 |
withName: nm |
|
693 |
in: (aMethod javaClass package). |
|
694 |
s nextPutAll: (specComponents at: 1). |
|
190 | 695 |
s space. |
2151 | 696 |
s emphasis: methodNameStyle. |
697 |
s nextPutAll: (specComponents at: 2). |
|
698 |
s emphasis: codeStyle. |
|
699 |
s nextPutAll: ' ('. |
|
700 |
s nextPutAll: (specComponents at: 3). |
|
701 |
s nextPutAll: ')'. |
|
702 |
aMethod exceptionTable size > 0 ifTrue: [ |
|
703 |
s nextPutAll: ' throws '. |
|
704 |
aMethod exceptionTable |
|
705 |
keysAndValuesDo: [ |
|
706 |
:index :aClassRef | |
|
707 |
| nm | |
|
190 | 708 |
|
2151 | 709 |
nm := aClassRef name. |
710 |
(nm startsWith: pckgName) ifTrue: [ |
|
711 |
nm := nm copyFrom: pckgName size + 2 |
|
712 |
] ifFalse: [ |
|
713 |
(nm startsWith: 'java/lang') ifTrue: [ |
|
714 |
nm := nm copyFrom: 'java/lang' size + 2. |
|
715 |
]. |
|
190 | 716 |
]. |
2151 | 717 |
index ~~ 1 ifTrue: [ s nextPutAll: ', ' ]. |
718 |
s nextPutAll: (nm copyReplaceAll: $/ with: $.) |
|
719 |
] |
|
190 | 720 |
]. |
2151 | 721 |
s |
722 |
nextPutAll: ';'; |
|
723 |
cr. |
|
190 | 724 |
|
2151 | 725 |
"Created: / 01-08-1997 / 12:24:11 / cg" |
726 |
"Modified: / 14-11-1998 / 00:03:09 / cg" |
|
727 |
"Modified: / 04-06-2011 / 17:18:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
728 |
"Modified (format): / 30-03-2012 / 19:52:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
161 | 729 |
! ! |
730 |
||
129 | 731 |
!JavaDecompiler class methodsFor:'decompiling'! |
6 | 732 |
|
733 |
decompile:aJavaMethod |
|
18 | 734 |
self decompile:aJavaMethod to:Transcript |
735 |
! |
|
736 |
||
737 |
decompile:aJavaMethod to:aStream |
|
738 |
self new decompile:aJavaMethod to:aStream |
|
6 | 739 |
! ! |
740 |
||
741 |
!JavaDecompiler methodsFor:'decompiling'! |
|
742 |
||
18 | 743 |
decompile:aJavaMethod to:aStream |
620 | 744 |
|who endPC| |
18 | 745 |
|
746 |
outStream := aStream. |
|
747 |
||
454 | 748 |
isStaticMethod := aJavaMethod isStatic. |
749 |
||
18 | 750 |
who := aJavaMethod who. |
751 |
who notNil ifTrue:[ |
|
129 | 752 |
classToCompileFor := who methodClass. |
454 | 753 |
outStream notNil ifTrue:[ |
754 |
outStream cr. |
|
755 |
"/ outStream showCR:'decompiling ' , classToCompileFor name , '>>' , (who methodSelector) , ':'. |
|
756 |
outStream showCR:'decompiling ' , aJavaMethod displayString , ':'. |
|
757 |
isStaticMethod ifTrue:[ |
|
758 |
outStream show:'static method'. |
|
759 |
]. |
|
760 |
outStream cr. |
|
761 |
outStream cr. |
|
762 |
] |
|
18 | 763 |
]. |
6 | 764 |
|
765 |
javaMethod := aJavaMethod. |
|
766 |
code := aJavaMethod javaByteCode. |
|
767 |
endPC := code size. |
|
18 | 768 |
endPC == 0 ifTrue:[ |
454 | 769 |
outStream notNil ifTrue:[ |
770 |
javaMethod isNative ifTrue:[ |
|
771 |
outStream nextPutAll:'// native method'; cr |
|
772 |
] ifFalse:[ |
|
773 |
outStream nextPutAll:'{} // no bytecode'; cr |
|
774 |
]. |
|
18 | 775 |
]. |
776 |
^ self |
|
777 |
]. |
|
778 |
||
620 | 779 |
self enumerateInstructions. |
780 |
||
781 |
"Modified: / 9.11.1999 / 15:33:20 / cg" |
|
782 |
! |
|
783 |
||
784 |
enumerateInstructions |
|
785 |
|who endPC insn spec op wide| |
|
786 |
||
198 | 787 |
wide := false. |
6 | 788 |
pc := 1. |
620 | 789 |
endPC := code size. |
6 | 790 |
[pc <= endPC] whileTrue:[ |
791 |
insn := code at:pc. |
|
792 |
pc := pc + 1. |
|
620 | 793 |
|
6 | 794 |
spec := DecoderTable at:(insn + 1). |
27 | 795 |
spec isNil ifTrue:[ |
620 | 796 |
op := '** invalid opcode: ', insn printString, ' **' |
27 | 797 |
] ifFalse:[ |
798 |
op := spec at:1 |
|
799 |
]. |
|
454 | 800 |
|
801 |
outStream notNil ifTrue:[ |
|
802 |
outStream |
|
803 |
show:((pc - 1 - 1) printStringPaddedTo:4); |
|
804 |
show:' '. |
|
805 |
outStream |
|
806 |
show:(wide ifTrue:[op , '(w)'] ifFalse:[op]). |
|
807 |
outStream |
|
808 |
show:' '. |
|
809 |
]. |
|
23 | 810 |
|
198 | 811 |
op == #wide ifTrue:[ |
812 |
wide := true. |
|
813 |
] ifFalse:[ |
|
620 | 814 |
self instructionHookPC:(pc-1) op:op spec:spec. |
815 |
||
198 | 816 |
spec notNil ifTrue:[ |
817 |
spec from:2 to:spec size do:[:what | |
|
818 |
wide ifTrue:[ |
|
819 |
self perform:(what , '_wide') asSymbol. |
|
820 |
] ifFalse:[ |
|
821 |
self perform:what |
|
822 |
] |
|
823 |
]. |
|
27 | 824 |
]. |
198 | 825 |
wide := false. |
6 | 826 |
]. |
620 | 827 |
|
454 | 828 |
outStream notNil ifTrue:[ |
829 |
outStream cr. |
|
830 |
] |
|
6 | 831 |
] |
832 |
||
620 | 833 |
"Created: / 9.11.1999 / 15:32:49 / cg" |
834 |
"Modified: / 9.11.1999 / 15:36:22 / cg" |
|
835 |
! |
|
836 |
||
837 |
instructionHookPC:pc op:op spec:spec |
|
838 |
||
839 |
"Created: / 9.11.1999 / 15:35:19 / cg" |
|
6 | 840 |
! ! |
841 |
||
842 |
!JavaDecompiler methodsFor:'operand decoding'! |
|
843 |
||
23 | 844 |
arrayTypeByte |
845 |
|hi low index type| |
|
846 |
||
847 |
index := code at:pc. |
|
848 |
pc := pc + 1. |
|
849 |
||
445 | 850 |
type := #('T_ARRAY' 'invalid2' 'invalid3' 'T_BOOLEAN' |
851 |
'T_CHAR' 'T_FLOAT' 'T_DOUBLE' 'T_BYTE' |
|
852 |
'T_SHORT' 'T_INT' 'T_LONG' ) at:index ifAbsent:['invalid' , index printString]. |
|
23 | 853 |
|
454 | 854 |
outStream notNil ifTrue:[ |
855 |
outStream |
|
856 |
show:index; |
|
857 |
show:' ['; |
|
858 |
show:type; |
|
859 |
show:']' |
|
860 |
] |
|
23 | 861 |
|
454 | 862 |
"Created: / 16.11.1998 / 15:41:47 / cg" |
863 |
"Modified: / 16.11.1998 / 15:43:27 / cg" |
|
23 | 864 |
! |
865 |
||
866 |
constIndexByte |
|
454 | 867 |
lastConstIndex := code at:pc. |
23 | 868 |
pc := pc + 1. |
869 |
||
454 | 870 |
lastConstant := javaMethod constantPool at:lastConstIndex ifAbsent:nil. |
23 | 871 |
|
454 | 872 |
outStream notNil ifTrue:[ |
873 |
outStream |
|
874 |
show:lastConstIndex; |
|
875 |
show:' ['; |
|
876 |
show:(lastConstant ? '??') displayString; |
|
877 |
show:'] ' |
|
878 |
] |
|
879 |
||
880 |
"Created: / 16.11.1998 / 15:42:56 / cg" |
|
881 |
"Modified: / 16.11.1998 / 15:58:52 / cg" |
|
23 | 882 |
! |
883 |
||
6 | 884 |
constIndexShort |
701 | 885 |
|s| |
886 |
||
454 | 887 |
lastConstIndex := code wordAt:pc MSB:true. |
24 | 888 |
pc := pc + 2. |
6 | 889 |
|
454 | 890 |
lastConstant := javaMethod constantPool at:lastConstIndex ifAbsent:nil. |
891 |
outStream notNil ifTrue:[ |
|
701 | 892 |
s := (lastConstant ? '??') displayString. |
893 |
s isString ifTrue:[ |
|
894 |
s bitsPerCharacter > 8 ifTrue:[ |
|
895 |
s := '...a 2-byte string...' |
|
896 |
] |
|
897 |
]. |
|
454 | 898 |
outStream |
899 |
show:lastConstIndex; |
|
900 |
show:' ['; |
|
701 | 901 |
show:s; |
454 | 902 |
show:'] ' |
903 |
] |
|
904 |
||
905 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
906 |
"Modified: / 16.11.1998 / 15:59:23 / cg" |
|
23 | 907 |
! |
908 |
||
27 | 909 |
dimensionsByte |
620 | 910 |
outStream notNil ifTrue:[ |
911 |
outStream show:' dims= '. |
|
912 |
]. |
|
27 | 913 |
self unsignedByte |
620 | 914 |
|
915 |
"Modified: / 9.11.1999 / 15:46:06 / cg" |
|
27 | 916 |
! |
917 |
||
23 | 918 |
localIndexByte |
198 | 919 |
|index| |
23 | 920 |
|
921 |
index := code at:pc. |
|
922 |
pc := pc + 1. |
|
923 |
||
454 | 924 |
outStream notNil ifTrue:[ |
925 |
outStream |
|
926 |
show:index; |
|
927 |
show:' ' |
|
928 |
] |
|
23 | 929 |
|
454 | 930 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
931 |
"Modified: / 16.11.1998 / 15:43:55 / cg" |
|
198 | 932 |
! |
933 |
||
934 |
localIndexByte_wide |
|
935 |
|index| |
|
936 |
||
937 |
index := code wordAt:pc MSB:true. |
|
938 |
pc := pc + 2. |
|
939 |
||
454 | 940 |
outStream notNil ifTrue:[ |
941 |
outStream |
|
942 |
show:index; |
|
943 |
show:' ' |
|
944 |
] |
|
198 | 945 |
|
454 | 946 |
"Created: / 4.8.1997 / 19:02:09 / cg" |
947 |
"Modified: / 16.11.1998 / 15:44:02 / cg" |
|
23 | 948 |
! |
949 |
||
27 | 950 |
lookupSwitchBytes |
951 |
|defaultOffset delta nPairs match pc0| |
|
952 |
||
953 |
pc0 := pc-1. "/ i.e. the pc of the tableSwitch op |
|
954 |
||
955 |
[(pc-1) \\ 4 ~~ 0] whileTrue:[ |
|
956 |
pc := pc + 1 |
|
957 |
]. |
|
958 |
||
959 |
defaultOffset := code signedDoubleWordAt:pc MSB:true. |
|
960 |
pc := pc + 4. |
|
961 |
nPairs := code signedDoubleWordAt:pc MSB:true. |
|
962 |
pc := pc + 4. |
|
963 |
||
620 | 964 |
outStream notNil ifTrue:[ |
965 |
outStream show:'n='; show:nPairs; cr. |
|
966 |
]. |
|
27 | 967 |
|
968 |
nPairs timesRepeat:[ |
|
969 |
match := code signedDoubleWordAt:pc MSB:true. |
|
970 |
pc := pc + 4. |
|
971 |
delta := code signedDoubleWordAt:pc MSB:true. |
|
972 |
pc := pc + 4. |
|
454 | 973 |
outStream notNil ifTrue:[ |
974 |
outStream show:' '; |
|
975 |
show:match; |
|
976 |
show:' -> '; |
|
977 |
show:delta; |
|
978 |
show:' ['; |
|
979 |
show:(pc0 - 1 + delta); |
|
980 |
show:']'; |
|
981 |
cr. |
|
982 |
] |
|
27 | 983 |
]. |
984 |
||
454 | 985 |
outStream notNil ifTrue:[ |
986 |
outStream show:' '; |
|
987 |
show:'default'; |
|
988 |
show:' -> '; |
|
989 |
show:defaultOffset; |
|
990 |
show:' ['; |
|
991 |
show:(pc0 - 1 + defaultOffset); |
|
992 |
show:']'. |
|
993 |
] |
|
252 | 994 |
|
620 | 995 |
"Modified: / 9.11.1999 / 15:45:50 / cg" |
27 | 996 |
! |
997 |
||
998 |
nargsByte |
|
999 |
|byte constants| |
|
1000 |
||
1001 |
byte := code byteAt:pc. |
|
1002 |
pc := pc + 1. |
|
1003 |
||
454 | 1004 |
outStream notNil ifTrue:[ |
1005 |
outStream |
|
1006 |
show:byte |
|
1007 |
] |
|
27 | 1008 |
|
454 | 1009 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
1010 |
"Modified: / 16.11.1998 / 15:44:34 / cg" |
|
27 | 1011 |
! |
1012 |
||
1013 |
reservedByte |
|
1014 |
|byte constants| |
|
1015 |
||
1016 |
byte := code byteAt:pc. |
|
1017 |
pc := pc + 1. |
|
1018 |
||
454 | 1019 |
outStream notNil ifTrue:[ |
1020 |
outStream |
|
1021 |
show:byte |
|
1022 |
] |
|
27 | 1023 |
|
454 | 1024 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
1025 |
"Modified: / 16.11.1998 / 15:44:42 / cg" |
|
27 | 1026 |
! |
1027 |
||
23 | 1028 |
signedBranchShort |
24 | 1029 |
|index constants| |
23 | 1030 |
|
24 | 1031 |
index := code signedWordAt:pc MSB:true. |
23 | 1032 |
|
454 | 1033 |
outStream notNil ifTrue:[ |
1034 |
outStream |
|
1035 |
show:index; |
|
1036 |
show:' ['; |
|
1037 |
show:(pc - 1 + index - 1); |
|
1038 |
show:']'. |
|
1039 |
]. |
|
25 | 1040 |
|
1041 |
pc := pc + 2. |
|
23 | 1042 |
|
252 | 1043 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
454 | 1044 |
"Modified: / 16.11.1998 / 15:44:51 / cg" |
24 | 1045 |
! |
1046 |
||
1047 |
signedByte |
|
1048 |
|byte constants| |
|
1049 |
||
1050 |
byte := code signedByteAt:pc. |
|
1051 |
pc := pc + 1. |
|
1052 |
||
454 | 1053 |
outStream notNil ifTrue:[ |
1054 |
outStream |
|
1055 |
show:byte |
|
1056 |
] |
|
24 | 1057 |
|
454 | 1058 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
1059 |
"Modified: / 16.11.1998 / 15:44:58 / cg" |
|
24 | 1060 |
! |
1061 |
||
261 | 1062 |
signedByte_wide |
1063 |
self signedShort |
|
1064 |
||
1065 |
"Created: / 13.1.1998 / 23:56:36 / cg" |
|
1066 |
! |
|
1067 |
||
24 | 1068 |
signedShort |
1069 |
|word constants| |
|
1070 |
||
1071 |
word := code signedWordAt:pc MSB:true. |
|
1072 |
pc := pc + 2. |
|
1073 |
||
454 | 1074 |
outStream notNil ifTrue:[ |
1075 |
outStream |
|
1076 |
show:word |
|
1077 |
] |
|
24 | 1078 |
|
454 | 1079 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
1080 |
"Modified: / 16.11.1998 / 15:45:06 / cg" |
|
24 | 1081 |
! |
1082 |
||
1083 |
tableSwitchBytes |
|
1084 |
|defaultOffset delta low high pc0| |
|
1085 |
||
1086 |
pc0 := pc-1. "/ i.e. the pc of the tableSwitch op |
|
1087 |
||
1088 |
[(pc-1) \\ 4 ~~ 0] whileTrue:[ |
|
1089 |
pc := pc + 1 |
|
1090 |
]. |
|
1091 |
||
1092 |
defaultOffset := code signedDoubleWordAt:pc MSB:true. |
|
1093 |
pc := pc + 4. |
|
1094 |
low := code signedDoubleWordAt:pc MSB:true. |
|
1095 |
pc := pc + 4. |
|
1096 |
high := code signedDoubleWordAt:pc MSB:true. |
|
1097 |
pc := pc + 4. |
|
1098 |
||
620 | 1099 |
outStream notNil ifTrue:[ |
1100 |
outStream cr. |
|
1101 |
]. |
|
24 | 1102 |
|
1103 |
low to:high do:[:switchValue | |
|
1104 |
delta := code signedDoubleWordAt:pc MSB:true. |
|
1105 |
pc := pc + 4. |
|
454 | 1106 |
outStream notNil ifTrue:[ |
1107 |
outStream show:' '; |
|
1108 |
show:switchValue; |
|
1109 |
show:' -> '; |
|
1110 |
show:delta; |
|
1111 |
show:' ['; |
|
1112 |
show:(pc0 - 1 + delta); |
|
1113 |
show:']'; |
|
1114 |
cr. |
|
1115 |
]. |
|
24 | 1116 |
]. |
1117 |
||
454 | 1118 |
outStream notNil ifTrue:[ |
1119 |
outStream show:' '; |
|
1120 |
show:'default'; |
|
1121 |
show:' -> '; |
|
1122 |
show:defaultOffset; |
|
1123 |
show:' ['; |
|
1124 |
show:(pc0 - 1 + defaultOffset); |
|
1125 |
show:']'. |
|
1126 |
] |
|
24 | 1127 |
|
620 | 1128 |
"Modified: / 9.11.1999 / 15:44:36 / cg" |
27 | 1129 |
! |
1130 |
||
1131 |
unsignedByte |
|
1132 |
|byte constants| |
|
1133 |
||
1134 |
byte := code byteAt:pc. |
|
1135 |
pc := pc + 1. |
|
1136 |
||
454 | 1137 |
outStream notNil ifTrue:[ |
1138 |
outStream |
|
1139 |
show:byte |
|
1140 |
] |
|
27 | 1141 |
|
454 | 1142 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
1143 |
"Modified: / 16.11.1998 / 15:45:33 / cg" |
|
6 | 1144 |
! ! |
1145 |
||
229 | 1146 |
!JavaDecompiler methodsFor:'private'! |
1147 |
||
1148 |
popType:type |
|
1149 |
(type == #long) ifTrue:[ |
|
1150 |
^ self popLong |
|
1151 |
]. |
|
1152 |
type == #double ifTrue:[ |
|
1153 |
^ self popDouble |
|
1154 |
]. |
|
1155 |
^ self popStack |
|
1156 |
||
1157 |
"Created: 16.8.1997 / 03:14:11 / cg" |
|
1158 |
! ! |
|
1159 |
||
454 | 1160 |
!JavaDecompiler methodsFor:'statistics'! |
1161 |
||
456 | 1162 |
remember_athrow |
1163 |
||
1164 |
"Created: / 16.11.1998 / 19:37:32 / cg" |
|
1165 |
! |
|
1166 |
||
454 | 1167 |
remember_getfield |
1168 |
|fieldRef| |
|
1169 |
||
1170 |
fieldRef := lastConstant. |
|
1171 |
"/ .... |
|
1172 |
||
1173 |
"Created: / 16.11.1998 / 16:07:58 / cg" |
|
1174 |
! |
|
1175 |
||
1176 |
remember_getstatic |
|
1177 |
|fieldRef| |
|
1178 |
||
1179 |
fieldRef := lastConstant. |
|
1180 |
"/ .... |
|
1181 |
||
1182 |
"Created: / 16.11.1998 / 16:08:06 / cg" |
|
1183 |
! |
|
1184 |
||
1185 |
remember_invokeinterface |
|
1186 |
|mthdRef| |
|
1187 |
||
1188 |
mthdRef := lastConstant. |
|
1189 |
"/ .... |
|
1190 |
||
1191 |
"Created: / 16.11.1998 / 16:07:29 / cg" |
|
1192 |
! |
|
1193 |
||
1194 |
remember_invokenonvirtual |
|
1195 |
|mthdRef| |
|
1196 |
||
1197 |
mthdRef := lastConstant. |
|
1198 |
"/ .... |
|
1199 |
||
1200 |
"Created: / 16.11.1998 / 16:06:49 / cg" |
|
1201 |
! |
|
1202 |
||
1203 |
remember_invokestatic |
|
1204 |
|mthdRef| |
|
1205 |
||
1206 |
mthdRef := lastConstant. |
|
1207 |
"/ .... |
|
1208 |
||
1209 |
"Created: / 16.11.1998 / 16:06:40 / cg" |
|
1210 |
! |
|
1211 |
||
1212 |
remember_invokevirtual |
|
1213 |
|mthdRef| |
|
1214 |
||
1215 |
mthdRef := lastConstant. |
|
1216 |
"/ .... |
|
1217 |
||
1218 |
"Created: / 16.11.1998 / 16:06:32 / cg" |
|
1219 |
! |
|
1220 |
||
1221 |
remember_ldc1 |
|
1222 |
|what| |
|
1223 |
||
1224 |
what := lastConstant. |
|
1225 |
"/ .... |
|
1226 |
||
1227 |
"Created: / 16.11.1998 / 16:07:12 / cg" |
|
1228 |
! |
|
1229 |
||
1230 |
remember_ldc2 |
|
1231 |
|what| |
|
1232 |
||
1233 |
what := lastConstant. |
|
1234 |
"/ .... |
|
1235 |
||
1236 |
"Created: / 16.11.1998 / 16:07:19 / cg" |
|
1237 |
! |
|
1238 |
||
1239 |
remember_ldc2w |
|
1240 |
|what| |
|
1241 |
||
1242 |
what := lastConstant. |
|
1243 |
"/ .... |
|
1244 |
||
1245 |
"Created: / 16.11.1998 / 16:07:20 / cg" |
|
1246 |
! |
|
1247 |
||
1248 |
remember_new |
|
1249 |
|class| |
|
1250 |
||
1251 |
class := lastConstant. |
|
1252 |
||
1253 |
"Created: / 16.11.1998 / 15:59:43 / cg" |
|
1254 |
"Modified: / 16.11.1998 / 16:12:27 / cg" |
|
1255 |
! |
|
1256 |
||
1257 |
remember_putfield |
|
1258 |
|fieldRef| |
|
1259 |
||
1260 |
fieldRef := lastConstant. |
|
1261 |
"/ .... |
|
1262 |
||
1263 |
"Created: / 16.11.1998 / 16:08:00 / cg" |
|
1264 |
! |
|
1265 |
||
1266 |
remember_putstatic |
|
1267 |
|fieldRef| |
|
1268 |
||
1269 |
fieldRef := lastConstant. |
|
1270 |
"/ .... |
|
1271 |
||
1272 |
"Created: / 16.11.1998 / 16:08:04 / cg" |
|
1273 |
! ! |
|
1274 |
||
129 | 1275 |
!JavaDecompiler class methodsFor:'documentation'! |
6 | 1276 |
|
1277 |
version |
|
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
1278 |
^ '$Header: /cvs/stx/stx/libjava/JavaDecompiler.st,v 1.56 2013-09-06 00:41:22 vrany Exp $' |
2256
ee48f7dd70a9
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2166
diff
changeset
|
1279 |
! |
ee48f7dd70a9
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2166
diff
changeset
|
1280 |
|
ee48f7dd70a9
fixed: #version_SVN ($ to §)
Claus Gittinger <cg@exept.de>
parents:
2166
diff
changeset
|
1281 |
version_CVS |
2678
c865275e48a7
Updated to match Mercurial revision a00302fe5083 with two tweaks:
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2396
diff
changeset
|
1282 |
^ '$Header: /cvs/stx/stx/libjava/JavaDecompiler.st,v 1.56 2013-09-06 00:41:22 vrany Exp $' |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1283 |
! |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1284 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1285 |
version_HG |
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1286 |
|
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1287 |
^ '$Changeset: <not expanded> $' |
2151 | 1288 |
! |
1289 |
||
1290 |
version_SVN |
|
2731
13f5be2bf83b
Merged d87e89dd5276 and fe83a843a7bf (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
1291 |
^ 'Id' |
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1292 |
|
6 | 1293 |
! ! |
2108 | 1294 |
|
2353
fa7400d022a0
Updated to https://swing.fit.cvut.cz/hg/stx.libjava/rev/31f8b995905e
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2256
diff
changeset
|
1295 |
|
2095 | 1296 |
JavaDecompiler initialize! |