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