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