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