author | Marcel Hlopko <marcel.hlopko@fit.cvut.cz> |
Tue, 18 Dec 2012 19:02:51 +0100 | |
branch | development |
changeset 1910 | 278ceba64f94 |
parent 1864 | 60a8dc26c8c6 |
child 2069 | 75d40b7b986f |
permissions | -rw-r--r-- |
752 | 1 |
" |
877 | 2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
877 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
752 | 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 |
|
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
752 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#JavaDecompiler |
|
24 |
instanceVariableNames:'code pc javaMethod outStream classToCompileFor isStaticMethod |
|
25 |
lastConstIndex lastConstant accessedInstvars modifiedInstvars |
|
26 |
accessedStaticVars modifiedStaticVars sentMessages' |
|
27 |
classVariableNames:'DecoderTable' |
|
28 |
poolDictionaries:'' |
|
29 |
category:'Languages-Java-Support-Decompiling' |
|
30 |
! |
|
31 |
||
32 |
!JavaDecompiler class methodsFor:'documentation'! |
|
33 |
||
34 |
copyright |
|
35 |
" |
|
877 | 36 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
1152 | 37 |
|
1155 | 38 |
New code and modifications done at SWING Research Group [1]: |
1152 | 39 |
|
877 | 40 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
41 |
SWING Research Group, Czech Technical University in Prague |
|
42 |
||
752 | 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. |
|
877 | 49 |
|
1155 | 50 |
[1] Code written at SWING Research Group contains a signature |
51 |
of one of the above copright owners. For exact set of such code, |
|
52 |
see the differences between this version and version stx:libjava |
|
1152 | 53 |
as of 1.9.2010 |
877 | 54 |
|
752 | 55 |
" |
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 |
! ! |
|
80 |
||
81 |
!JavaDecompiler class methodsFor:'initialization'! |
|
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 |
|
104 |
(ldc1 constIndexByte remember_ldc1) "/ 18 |
|
105 |
(ldc2 constIndexShort remember_ldc2) "/ 19 |
|
106 |
||
107 |
(ldc2w constIndexShort remember_ldc2w) "/ 20 |
|
108 |
(iload localIndexByte) "/ 21 |
|
109 |
(lload localIndexByte) "/ 22 |
|
110 |
(fload localIndexByte) "/ 23 |
|
111 |
(dload localIndexByte) "/ 24 |
|
112 |
(aload localIndexByte) "/ 25 |
|
113 |
(iload_0) "/ 26 |
|
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 |
|
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 |
|
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 |
|
234 |
(iinc localIndexByte signedByte) "/ 132 |
|
235 |
(i2l) "/ 133 |
|
236 |
(i2f) "/ 134 |
|
237 |
(i2d) "/ 135 |
|
238 |
(l2i) "/ 136 |
|
239 |
(l2f) "/ 137 |
|
240 |
(l2d) "/ 138 |
|
241 |
(f2i) "/ 139 |
|
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 |
|
284 |
(getstatic constIndexShort remember_getstatic) "/ 178 |
|
285 |
(putstatic constIndexShort remember_putstatic) "/ 179 |
|
286 |
||
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 |
|
293 |
(newfromname) "/ 186 |
|
294 |
(new constIndexShort remember_new) "/ 187 |
|
295 |
(newarray arrayTypeByte) "/ 188 |
|
296 |
(anewarray constIndexShort) "/ 189 |
|
297 |
||
298 |
(arraylength) "/ 190 |
|
299 |
(athrow remember_athrow) "/ 191 |
|
300 |
(checkcast constIndexShort) "/ 192 |
|
301 |
(instanceof constIndexShort) "/ 193 |
|
302 |
(monitorenter) "/ 194 |
|
303 |
(monitorexit) "/ 195 |
|
304 |
"/ (verifystack) "/ 196 obsolete (Alpha release) |
|
305 |
(wide) "/ 196 |
|
306 |
(multianewarray constIndexShort dimensionsByte) "/ 197 |
|
307 |
||
308 |
(ifnull signedBranchShort) "/ 198 |
|
309 |
(ifnonnull signedBranchShort) "/ 199 |
|
310 |
||
311 |
(#'goto_w' signedBranchLong) "/ 200 |
|
312 |
(#'jsr_w' signedBranchShort) "/ 201 |
|
313 |
||
314 |
(breakpoint) "/ 202 |
|
315 |
||
316 |
nil "/ 203 |
|
317 |
nil "/ 204 |
|
318 |
nil "/ 205 |
|
319 |
nil "/ 206 |
|
320 |
nil "/ 207 |
|
321 |
nil "/ 208 |
|
322 |
(#'ret_w' signedBranchShort) "/ 209 |
|
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 |
|
373 |
(invokenonvirtual_d constIndexShort) "/ 255 special - dummy invokenonvirtual |
|
374 |
) |
|
375 |
||
376 |
" |
|
377 |
JavaDecompiler initialize |
|
378 |
" |
|
379 |
||
380 |
"Modified: / 16.11.1998 / 15:55:49 / cg" |
|
381 |
! ! |
|
382 |
||
383 |
!JavaDecompiler class methodsFor:'accessing'! |
|
384 |
||
385 |
instructionTable |
|
386 |
^ DecoderTable |
|
387 |
! ! |
|
388 |
||
389 |
!JavaDecompiler class methodsFor:'class definition generation'! |
|
390 |
||
391 |
definitionOf:aJavaClass on:s |
|
392 |
|pckgName needCR fields staticFields superClass |
|
1281 | 393 |
interfaces staticMethods nonStaticMethods |
752 | 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. |
|
400 |
||
401 |
pckgName := aJavaClass package. |
|
1441 | 402 |
pckgName ~= 'java' ifTrue:[ |
403 |
s nextPutAll:'package ' , ((pckgName copyFrom: 6) copyReplaceAll:$/ with:$.). |
|
752 | 404 |
s nextPutAll:';'; cr; cr. |
1441 | 405 |
|
752 | 406 |
]. |
407 |
||
408 |
needCR := false. |
|
409 |
s emphasis:accessAttributeStyle. |
|
410 |
||
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 |
]. |
|
423 |
s emphasis:codeStyle. |
|
424 |
||
425 |
needCR ifTrue:[ |
|
426 |
s cr |
|
427 |
]. |
|
428 |
aJavaClass isInterface ifTrue:[ |
|
429 |
s nextPutAll:'interface '. |
|
430 |
] ifFalse:[ |
|
431 |
s nextPutAll:'class '. |
|
432 |
]. |
|
433 |
s emphasis:classNameStyle; |
|
434 |
nextPutAll:aJavaClass lastName; |
|
435 |
emphasis:codeStyle; |
|
436 |
space. |
|
437 |
superClass := aJavaClass superclass. |
|
438 |
||
1036 | 439 |
(superClass ~~ (JavaVM classNamed:'java/lang/Object') |
752 | 440 |
and:[superClass isJavaClass]) ifTrue:[ |
441 |
s nextPutAll:'extends '. |
|
442 |
s emphasis:classNameStyle. |
|
443 |
(superClass package ~= 'java/lang' |
|
444 |
and:[superClass package ~= pckgName]) ifTrue:[ |
|
445 |
s nextPutAll:(superClass displayString). |
|
446 |
] ifFalse:[ |
|
447 |
s nextPutAll:(superClass lastName). |
|
448 |
]. |
|
449 |
s emphasis:codeStyle. |
|
450 |
s space. |
|
451 |
]. |
|
452 |
||
453 |
(interfaces := aJavaClass interfaces) size > 0 ifTrue:[ |
|
454 |
(aJavaClass isInterface |
|
455 |
and:[interfaces size == 1]) ifTrue:[ |
|
456 |
s nextPutAll:'extends '. |
|
457 |
] ifFalse:[ |
|
458 |
s nextPutAll:'implements '. |
|
459 |
]. |
|
460 |
interfaces keysAndValuesDo:[:nr :if | |
|
461 |
|nameString| |
|
462 |
||
463 |
nr ~~ 1 ifTrue:[ |
|
464 |
s nextPutAll:', '. |
|
465 |
]. |
|
466 |
s emphasis:classNameStyle. |
|
467 |
(if package ~= 'java/lang' |
|
468 |
and:[if package ~= pckgName]) ifTrue:[ |
|
469 |
if isJavaClass ifFalse:[ |
|
470 |
"/ ought to be an unresolved class ... |
|
471 |
nameString := if fullName copyReplaceAll:$/ with:$. |
|
472 |
] ifTrue:[ |
|
473 |
nameString := if displayString |
|
474 |
]. |
|
475 |
] ifFalse:[ |
|
476 |
nameString := if lastName |
|
477 |
]. |
|
478 |
s nextPutAll:nameString. |
|
479 |
s emphasis:codeStyle. |
|
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:' '. |
|
495 |
s emphasis:accessAttributeStyle. |
|
1441 | 496 |
aField isSynthetic ifTrue:[ |
497 |
s nextPutAll: '/*SYNTHETIC*/ '. |
|
498 |
]. |
|
752 | 499 |
aField isPublic ifTrue:[ |
500 |
s nextPutAll:'public '. |
|
501 |
] ifFalse:[ |
|
502 |
aField isPrivate ifTrue:[ |
|
503 |
s nextPutAll:'private '. |
|
504 |
] ifFalse:[ |
|
505 |
aField isProtected ifTrue:[ |
|
506 |
s nextPutAll:'protected '. |
|
507 |
] |
|
508 |
] |
|
509 |
]. |
|
510 |
s nextPutAll:'static '. |
|
511 |
aField isFinal ifTrue:[ |
|
512 |
s nextPutAll:'final '. |
|
513 |
]. |
|
514 |
aField isVolatile ifTrue:[ |
|
515 |
s nextPutAll:'volatile '. |
|
516 |
]. |
|
517 |
s emphasis:codeStyle. |
|
518 |
||
519 |
(((type := aField type) startsWith:pckgName) |
|
520 |
or:[type startsWith:(pckgName copyReplaceAll:$/ with:$.)]) ifTrue:[ |
|
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 | |
|
549 |
|type v| |
|
550 |
||
551 |
s nextPutAll:' '. |
|
552 |
s emphasis:accessAttributeStyle. |
|
553 |
aField isPublic ifTrue:[ |
|
554 |
s nextPutAll:'public '. |
|
555 |
] ifFalse:[ |
|
556 |
aField isPrivate ifTrue:[ |
|
557 |
s nextPutAll:'private '. |
|
558 |
] ifFalse:[ |
|
559 |
aField isProtected ifTrue:[ |
|
560 |
s nextPutAll:'protected '. |
|
561 |
] |
|
562 |
] |
|
563 |
]. |
|
564 |
aField isFinal ifTrue:[ |
|
565 |
s nextPutAll:'final '. |
|
566 |
]. |
|
567 |
aField isTransient ifTrue:[ |
|
568 |
s nextPutAll:'transient '. |
|
569 |
]. |
|
570 |
aField isVolatile ifTrue:[ |
|
571 |
s nextPutAll:'volatile '. |
|
572 |
]. |
|
573 |
s emphasis:codeStyle. |
|
574 |
||
575 |
(((type := aField type) startsWith:pckgName) |
|
576 |
or:[type startsWith:(pckgName copyReplaceAll:$/ with:$.)]) ifTrue:[ |
|
577 |
type := type copyFrom:(pckgName size + 1 + 1). |
|
578 |
]. |
|
579 |
type := type copy replaceAll:$/ with:$.. |
|
580 |
s nextPutAll:type; space; |
|
581 |
nextPutAll:aField name. |
|
582 |
||
583 |
(v := aField constantValue) notNil ifTrue:[ |
|
584 |
s nextPutAll:' = '; nextPutAll:v displayString. |
|
585 |
]. |
|
586 |
s nextPutAll:';'; cr. |
|
587 |
]. |
|
588 |
]. |
|
589 |
||
590 |
aJavaClass methodDictionary size > 0 ifTrue:[ |
|
591 |
needCR ifTrue:[ |
|
592 |
s cr. |
|
593 |
needCR := false. |
|
594 |
]. |
|
595 |
||
596 |
staticMethods := OrderedCollection new. |
|
597 |
nonStaticMethods := OrderedCollection new. |
|
598 |
"/ |
|
599 |
"/ static methods first ... |
|
600 |
"/ |
|
601 |
aJavaClass methodDictionary do:[:aMethod | |
|
1281 | 602 |
aMethod isJavaMethod ifTrue:[ |
752 | 603 |
|m| |
604 |
||
605 |
m := aMethod. |
|
606 |
m isWrapped ifTrue:[ |
|
607 |
m := m originalMethod |
|
608 |
]. |
|
609 |
m isStatic ifTrue:[ |
|
610 |
staticMethods add:m. |
|
611 |
] ifFalse:[ |
|
612 |
nonStaticMethods add:m. |
|
613 |
] |
|
614 |
]. |
|
615 |
||
616 |
staticMethods notEmpty ifTrue:[ |
|
617 |
staticMethods sort:[:a :b | a name < b name]. |
|
618 |
staticMethods do:[:aMethod | |
|
1281 | 619 |
"JV@2011-12-14: method dictionary may contain non-Java methods |
620 |
(proxies, for instance)" |
|
621 |
aMethod isJavaMethod ifTrue:[ |
|
622 |
self methodDefinitionOf:aMethod inPackage:pckgName on:s. |
|
623 |
] |
|
752 | 624 |
]. |
625 |
s cr. |
|
626 |
]. |
|
627 |
||
628 |
"/ |
|
629 |
"/ instance methods ... |
|
630 |
"/ |
|
631 |
nonStaticMethods notEmpty ifTrue:[ |
|
632 |
nonStaticMethods sort:[:a :b | a name < b name]. |
|
633 |
nonStaticMethods do:[:aMethod | |
|
1281 | 634 |
"JV@2011-12-14: method dictionary may contain non-Java methods |
635 |
(proxies, for instance)" |
|
636 |
aMethod isJavaMethod ifTrue:[ |
|
637 |
self methodDefinitionOf:aMethod inPackage:pckgName on:s. |
|
638 |
] |
|
752 | 639 |
]. |
640 |
]. |
|
1281 | 641 |
] |
752 | 642 |
]. |
643 |
||
644 |
s nextPutAll:'}'; cr. |
|
645 |
||
1036 | 646 |
"Created: / 22-03-1997 / 14:29:37 / cg" |
647 |
"Modified: / 05-12-1998 / 15:58:37 / cg" |
|
648 |
"Modified: / 21-10-2011 / 13:40:44 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1441 | 649 |
"Modified: / 31-03-2012 / 00:36:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 650 |
! |
651 |
||
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
652 |
methodDefinitionOf: m inPackage: pckgName on: s |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
653 |
| aMethod nm specComponents accessAttributeStyle codeStyle methodNameStyle | |
752 | 654 |
|
655 |
aMethod := m. |
|
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
656 |
m isWrapped ifTrue: [ |
752 | 657 |
aMethod := m originalMethod |
658 |
]. |
|
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
659 |
accessAttributeStyle := Java prettyPrintStyle at: #accessAttribute. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
660 |
codeStyle := Java prettyPrintStyle at: #code. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
661 |
methodNameStyle := Java prettyPrintStyle at: #methodName. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
662 |
s nextPutAll: ' '. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
663 |
s emphasis: accessAttributeStyle. |
1441 | 664 |
aMethod isSynthetic ifTrue:[ |
665 |
s nextPutAll: '/*SYNTHETIC*/ '. |
|
666 |
]. |
|
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
667 |
aMethod isPublic ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
668 |
s nextPutAll: 'public '. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
669 |
] ifFalse: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
670 |
aMethod isProtected ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
671 |
s nextPutAll: 'protected '. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
672 |
] ifFalse: [ s nextPutAll: 'private '. ] |
752 | 673 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
674 |
aMethod isFinal ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
675 |
s nextPutAll: 'final '. |
752 | 676 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
677 |
aMethod isStatic ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
678 |
s nextPutAll: 'static '. |
752 | 679 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
680 |
aMethod isNative ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
681 |
s nextPutAll: 'native '. |
752 | 682 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
683 |
aMethod isSynchronized ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
684 |
s nextPutAll: 'synchronized '. |
752 | 685 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
686 |
s emphasis: codeStyle. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
687 |
(nm := aMethod name) = '<init>' ifTrue: [ |
752 | 688 |
nm := aMethod javaClass lastName. |
689 |
]. |
|
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
690 |
specComponents := JavaMethod |
915 | 691 |
specComponentsWithArgsFromSignature: (aMethod instVarNamed:#descriptor) |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
692 |
withName: nm |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
693 |
in: (aMethod javaClass package). |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
694 |
s nextPutAll: (specComponents at: 1). |
752 | 695 |
s space. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
696 |
s emphasis: methodNameStyle. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
697 |
s nextPutAll: (specComponents at: 2). |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
698 |
s emphasis: codeStyle. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
699 |
s nextPutAll: ' ('. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
700 |
s nextPutAll: (specComponents at: 3). |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
701 |
s nextPutAll: ')'. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
702 |
aMethod exceptionTable size > 0 ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
703 |
s nextPutAll: ' throws '. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
704 |
aMethod exceptionTable |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
705 |
keysAndValuesDo: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
706 |
:index :aClassRef | |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
707 |
| nm | |
752 | 708 |
|
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
709 |
nm := aClassRef name. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
710 |
(nm startsWith: pckgName) ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
711 |
nm := nm copyFrom: pckgName size + 2 |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
712 |
] ifFalse: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
713 |
(nm startsWith: 'java/lang') ifTrue: [ |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
714 |
nm := nm copyFrom: 'java/lang' size + 2. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
715 |
]. |
752 | 716 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
717 |
index ~~ 1 ifTrue: [ s nextPutAll: ', ' ]. |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
718 |
s nextPutAll: (nm copyReplaceAll: $/ with: $.) |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
719 |
] |
752 | 720 |
]. |
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
721 |
s |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
722 |
nextPutAll: ';'; |
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
723 |
cr. |
752 | 724 |
|
837
8f42226d82c0
slightly refactored exceptionTable methods and their callers.. no typechanging side effects
hlopkmar
parents:
752
diff
changeset
|
725 |
"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
|
726 |
"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
|
727 |
"Modified: / 04-06-2011 / 17:18:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
1441 | 728 |
"Modified (format): / 30-03-2012 / 19:52:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
752 | 729 |
! ! |
730 |
||
731 |
!JavaDecompiler class methodsFor:'decompiling'! |
|
732 |
||
733 |
decompile:aJavaMethod |
|
734 |
self decompile:aJavaMethod to:Transcript |
|
735 |
! |
|
736 |
||
737 |
decompile:aJavaMethod to:aStream |
|
738 |
self new decompile:aJavaMethod to:aStream |
|
739 |
! ! |
|
740 |
||
741 |
!JavaDecompiler methodsFor:'decompiling'! |
|
742 |
||
743 |
decompile:aJavaMethod to:aStream |
|
744 |
|who endPC| |
|
745 |
||
746 |
outStream := aStream. |
|
747 |
||
748 |
isStaticMethod := aJavaMethod isStatic. |
|
749 |
||
750 |
who := aJavaMethod who. |
|
751 |
who notNil ifTrue:[ |
|
752 |
classToCompileFor := who methodClass. |
|
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 |
] |
|
763 |
]. |
|
764 |
||
765 |
javaMethod := aJavaMethod. |
|
766 |
code := aJavaMethod javaByteCode. |
|
767 |
endPC := code size. |
|
768 |
endPC == 0 ifTrue:[ |
|
769 |
outStream notNil ifTrue:[ |
|
770 |
javaMethod isNative ifTrue:[ |
|
771 |
outStream nextPutAll:'// native method'; cr |
|
772 |
] ifFalse:[ |
|
773 |
outStream nextPutAll:'{} // no bytecode'; cr |
|
774 |
]. |
|
775 |
]. |
|
776 |
^ self |
|
777 |
]. |
|
778 |
||
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 |
||
787 |
wide := false. |
|
788 |
pc := 1. |
|
789 |
endPC := code size. |
|
790 |
[pc <= endPC] whileTrue:[ |
|
791 |
insn := code at:pc. |
|
792 |
pc := pc + 1. |
|
793 |
||
794 |
spec := DecoderTable at:(insn + 1). |
|
795 |
spec isNil ifTrue:[ |
|
796 |
op := '** invalid opcode: ', insn printString, ' **' |
|
797 |
] ifFalse:[ |
|
798 |
op := spec at:1 |
|
799 |
]. |
|
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 |
]. |
|
810 |
||
811 |
op == #wide ifTrue:[ |
|
812 |
wide := true. |
|
813 |
] ifFalse:[ |
|
814 |
self instructionHookPC:(pc-1) op:op spec:spec. |
|
815 |
||
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 |
]. |
|
824 |
]. |
|
825 |
wide := false. |
|
826 |
]. |
|
827 |
||
828 |
outStream notNil ifTrue:[ |
|
829 |
outStream cr. |
|
830 |
] |
|
831 |
] |
|
832 |
||
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" |
|
840 |
! ! |
|
841 |
||
842 |
!JavaDecompiler methodsFor:'operand decoding'! |
|
843 |
||
844 |
arrayTypeByte |
|
845 |
|hi low index type| |
|
846 |
||
847 |
index := code at:pc. |
|
848 |
pc := pc + 1. |
|
849 |
||
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]. |
|
853 |
||
854 |
outStream notNil ifTrue:[ |
|
855 |
outStream |
|
856 |
show:index; |
|
857 |
show:' ['; |
|
858 |
show:type; |
|
859 |
show:']' |
|
860 |
] |
|
861 |
||
862 |
"Created: / 16.11.1998 / 15:41:47 / cg" |
|
863 |
"Modified: / 16.11.1998 / 15:43:27 / cg" |
|
864 |
! |
|
865 |
||
866 |
constIndexByte |
|
867 |
lastConstIndex := code at:pc. |
|
868 |
pc := pc + 1. |
|
869 |
||
870 |
lastConstant := javaMethod constantPool at:lastConstIndex ifAbsent:nil. |
|
871 |
||
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" |
|
882 |
! |
|
883 |
||
884 |
constIndexShort |
|
885 |
|s| |
|
886 |
||
887 |
lastConstIndex := code wordAt:pc MSB:true. |
|
888 |
pc := pc + 2. |
|
889 |
||
890 |
lastConstant := javaMethod constantPool at:lastConstIndex ifAbsent:nil. |
|
891 |
outStream notNil ifTrue:[ |
|
892 |
s := (lastConstant ? '??') displayString. |
|
893 |
s isString ifTrue:[ |
|
894 |
s bitsPerCharacter > 8 ifTrue:[ |
|
895 |
s := '...a 2-byte string...' |
|
896 |
] |
|
897 |
]. |
|
898 |
outStream |
|
899 |
show:lastConstIndex; |
|
900 |
show:' ['; |
|
901 |
show:s; |
|
902 |
show:'] ' |
|
903 |
] |
|
904 |
||
905 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
906 |
"Modified: / 16.11.1998 / 15:59:23 / cg" |
|
907 |
! |
|
908 |
||
909 |
dimensionsByte |
|
910 |
outStream notNil ifTrue:[ |
|
911 |
outStream show:' dims= '. |
|
912 |
]. |
|
913 |
self unsignedByte |
|
914 |
||
915 |
"Modified: / 9.11.1999 / 15:46:06 / cg" |
|
916 |
! |
|
917 |
||
918 |
localIndexByte |
|
919 |
|index| |
|
920 |
||
921 |
index := code at:pc. |
|
922 |
pc := pc + 1. |
|
923 |
||
924 |
outStream notNil ifTrue:[ |
|
925 |
outStream |
|
926 |
show:index; |
|
927 |
show:' ' |
|
928 |
] |
|
929 |
||
930 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
931 |
"Modified: / 16.11.1998 / 15:43:55 / cg" |
|
932 |
! |
|
933 |
||
934 |
localIndexByte_wide |
|
935 |
|index| |
|
936 |
||
937 |
index := code wordAt:pc MSB:true. |
|
938 |
pc := pc + 2. |
|
939 |
||
940 |
outStream notNil ifTrue:[ |
|
941 |
outStream |
|
942 |
show:index; |
|
943 |
show:' ' |
|
944 |
] |
|
945 |
||
946 |
"Created: / 4.8.1997 / 19:02:09 / cg" |
|
947 |
"Modified: / 16.11.1998 / 15:44:02 / cg" |
|
948 |
! |
|
949 |
||
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 |
||
964 |
outStream notNil ifTrue:[ |
|
965 |
outStream show:'n='; show:nPairs; cr. |
|
966 |
]. |
|
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. |
|
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 |
] |
|
983 |
]. |
|
984 |
||
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 |
] |
|
994 |
||
995 |
"Modified: / 9.11.1999 / 15:45:50 / cg" |
|
996 |
! |
|
997 |
||
998 |
nargsByte |
|
999 |
|byte constants| |
|
1000 |
||
1001 |
byte := code byteAt:pc. |
|
1002 |
pc := pc + 1. |
|
1003 |
||
1004 |
outStream notNil ifTrue:[ |
|
1005 |
outStream |
|
1006 |
show:byte |
|
1007 |
] |
|
1008 |
||
1009 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
1010 |
"Modified: / 16.11.1998 / 15:44:34 / cg" |
|
1011 |
! |
|
1012 |
||
1013 |
reservedByte |
|
1014 |
|byte constants| |
|
1015 |
||
1016 |
byte := code byteAt:pc. |
|
1017 |
pc := pc + 1. |
|
1018 |
||
1019 |
outStream notNil ifTrue:[ |
|
1020 |
outStream |
|
1021 |
show:byte |
|
1022 |
] |
|
1023 |
||
1024 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
1025 |
"Modified: / 16.11.1998 / 15:44:42 / cg" |
|
1026 |
! |
|
1027 |
||
1028 |
signedBranchShort |
|
1029 |
|index constants| |
|
1030 |
||
1031 |
index := code signedWordAt:pc MSB:true. |
|
1032 |
||
1033 |
outStream notNil ifTrue:[ |
|
1034 |
outStream |
|
1035 |
show:index; |
|
1036 |
show:' ['; |
|
1037 |
show:(pc - 1 + index - 1); |
|
1038 |
show:']'. |
|
1039 |
]. |
|
1040 |
||
1041 |
pc := pc + 2. |
|
1042 |
||
1043 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
1044 |
"Modified: / 16.11.1998 / 15:44:51 / cg" |
|
1045 |
! |
|
1046 |
||
1047 |
signedByte |
|
1048 |
|byte constants| |
|
1049 |
||
1050 |
byte := code signedByteAt:pc. |
|
1051 |
pc := pc + 1. |
|
1052 |
||
1053 |
outStream notNil ifTrue:[ |
|
1054 |
outStream |
|
1055 |
show:byte |
|
1056 |
] |
|
1057 |
||
1058 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
1059 |
"Modified: / 16.11.1998 / 15:44:58 / cg" |
|
1060 |
! |
|
1061 |
||
1062 |
signedByte_wide |
|
1063 |
self signedShort |
|
1064 |
||
1065 |
"Created: / 13.1.1998 / 23:56:36 / cg" |
|
1066 |
! |
|
1067 |
||
1068 |
signedShort |
|
1069 |
|word constants| |
|
1070 |
||
1071 |
word := code signedWordAt:pc MSB:true. |
|
1072 |
pc := pc + 2. |
|
1073 |
||
1074 |
outStream notNil ifTrue:[ |
|
1075 |
outStream |
|
1076 |
show:word |
|
1077 |
] |
|
1078 |
||
1079 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
1080 |
"Modified: / 16.11.1998 / 15:45:06 / cg" |
|
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 |
||
1099 |
outStream notNil ifTrue:[ |
|
1100 |
outStream cr. |
|
1101 |
]. |
|
1102 |
||
1103 |
low to:high do:[:switchValue | |
|
1104 |
delta := code signedDoubleWordAt:pc MSB:true. |
|
1105 |
pc := pc + 4. |
|
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 |
]. |
|
1116 |
]. |
|
1117 |
||
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 |
] |
|
1127 |
||
1128 |
"Modified: / 9.11.1999 / 15:44:36 / cg" |
|
1129 |
! |
|
1130 |
||
1131 |
unsignedByte |
|
1132 |
|byte constants| |
|
1133 |
||
1134 |
byte := code byteAt:pc. |
|
1135 |
pc := pc + 1. |
|
1136 |
||
1137 |
outStream notNil ifTrue:[ |
|
1138 |
outStream |
|
1139 |
show:byte |
|
1140 |
] |
|
1141 |
||
1142 |
"Created: / 16.4.1996 / 15:00:04 / cg" |
|
1143 |
"Modified: / 16.11.1998 / 15:45:33 / cg" |
|
1144 |
! ! |
|
1145 |
||
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 |
||
1160 |
!JavaDecompiler methodsFor:'statistics'! |
|
1161 |
||
1162 |
remember_athrow |
|
1163 |
||
1164 |
"Created: / 16.11.1998 / 19:37:32 / cg" |
|
1165 |
! |
|
1166 |
||
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 |
||
1275 |
!JavaDecompiler class methodsFor:'documentation'! |
|
1276 |
||
1277 |
version |
|
1864 | 1278 |
^ '$Header$' |
1279 |
! |
|
1280 |
||
1281 |
version_HG |
|
1282 |
||
1283 |
^ '$Changeset: <not expanded> $' |
|
752 | 1284 |
! |
1285 |
||
1286 |
version_SVN |
|
1864 | 1287 |
^ '§Id§' |
923 | 1288 |
|
752 | 1289 |
! ! |
1290 |
||
1291 |
JavaDecompiler initialize! |