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