2
|
1 |
CompiledCode subclass:#JavaMethod
|
72
|
2 |
instanceVariableNames:'javaByteCode numArgs numLocals returnType accessFlags name
|
83
|
3 |
signature exceptionHandlerTable exceptionTable lineNumberTable
|
148
|
4 |
localVariableTable javaClass numStack isNOOPMethod'
|
8
|
5 |
classVariableNames:'SignatureTypeCodes'
|
2
|
6 |
poolDictionaries:''
|
|
7 |
category:'Java-Classes'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
129
|
11 |
!JavaMethod class methodsFor:'initialization'!
|
8
|
12 |
|
|
13 |
initialize
|
|
14 |
SignatureTypeCodes := IdentityDictionary new.
|
|
15 |
SignatureTypeCodes at:$B put:#byte.
|
|
16 |
SignatureTypeCodes at:$C put:#char.
|
|
17 |
SignatureTypeCodes at:$D put:#double.
|
|
18 |
SignatureTypeCodes at:$F put:#float.
|
|
19 |
SignatureTypeCodes at:$I put:#int.
|
|
20 |
SignatureTypeCodes at:$J put:#long.
|
|
21 |
SignatureTypeCodes at:$S put:#'unsigned short'.
|
|
22 |
SignatureTypeCodes at:$Z put:#boolean.
|
|
23 |
SignatureTypeCodes at:$L put:#object.
|
|
24 |
SignatureTypeCodes at:$[ put:#array.
|
|
25 |
|
|
26 |
"
|
|
27 |
JavaMethod initialize
|
|
28 |
"
|
|
29 |
! !
|
|
30 |
|
129
|
31 |
!JavaMethod class methodsFor:'signature parsing'!
|
5
|
32 |
|
29
|
33 |
argSigArrayFromSignature:aSignature
|
|
34 |
"given a signature, return a specArray for the arguments"
|
|
35 |
|
|
36 |
|s argSpec retvalSpec|
|
|
37 |
|
|
38 |
s := aSignature readStream.
|
|
39 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
40 |
|
|
41 |
^ self argSigArrayFromStream:s.
|
|
42 |
|
|
43 |
"
|
|
44 |
JavaMethod argSigArrayFromSignature:'(LObject;)V'
|
|
45 |
JavaMethod argSigArrayFromSignature:'(BB)S'
|
|
46 |
JavaMethod argSigArrayFromSignature:'(LObject;LObject;II)V'
|
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
argSigArrayFromStream:s
|
|
51 |
"parse an argSpec, return an array of specs - see java doc"
|
|
52 |
|
|
53 |
|argSpec spec|
|
|
54 |
|
|
55 |
spec := #().
|
|
56 |
[s atEnd or:[s peek == $)]] whileFalse:[
|
|
57 |
"/ s peek == Character space ifTrue:[
|
|
58 |
"/ s next
|
|
59 |
"/ ] ifFalse:[
|
|
60 |
argSpec := self fieldTypeFromStream:s.
|
|
61 |
spec := spec copyWith:argSpec.
|
|
62 |
"/ ]
|
|
63 |
].
|
|
64 |
^ spec
|
|
65 |
|
|
66 |
|
|
67 |
!
|
|
68 |
|
113
|
69 |
argSpecFromSignature:aSignature withName:name
|
|
70 |
"given a signature, return a spec"
|
|
71 |
|
|
72 |
|s argSpec retvalSpec|
|
|
73 |
|
|
74 |
s := aSignature readStream.
|
|
75 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
76 |
|
|
77 |
argSpec := self argSpecFromStream:s.
|
|
78 |
|
|
79 |
s next ~~ $) ifTrue:[self halt. ^ name].
|
|
80 |
|
|
81 |
^ name , ' (' , argSpec , ')'
|
|
82 |
|
|
83 |
"
|
|
84 |
JavaMethod argSpecFromSignature:'(LObject;)V' withName:'foo'
|
|
85 |
JavaMethod argSpecFromSignature:'(BB)S' withName:'foo'
|
|
86 |
"
|
|
87 |
!
|
|
88 |
|
8
|
89 |
argSpecFromStream:s
|
|
90 |
"parse an argSpec - see java doc"
|
|
91 |
|
|
92 |
|argSpec spec|
|
|
93 |
|
|
94 |
spec := ''.
|
|
95 |
[s atEnd or:[s peek == $)]] whileFalse:[
|
27
|
96 |
"/ s peek == Character space ifTrue:[
|
|
97 |
"/ s next
|
|
98 |
"/ ] ifFalse:[
|
|
99 |
argSpec := self fieldTypeFromStream:s.
|
|
100 |
spec size ~~ 0 ifTrue:[
|
|
101 |
spec := spec , ' '
|
|
102 |
].
|
|
103 |
spec := spec , argSpec.
|
|
104 |
"/ ]
|
8
|
105 |
].
|
|
106 |
^ spec
|
|
107 |
|
5
|
108 |
|
|
109 |
!
|
|
110 |
|
142
|
111 |
argSpecFromStream:s in:aPackage
|
|
112 |
"parse an argSpec - see java doc"
|
|
113 |
|
|
114 |
|argSpec spec|
|
|
115 |
|
|
116 |
spec := ''.
|
|
117 |
[s atEnd or:[s peek == $)]] whileFalse:[
|
|
118 |
"/ s peek == Character space ifTrue:[
|
|
119 |
"/ s next
|
|
120 |
"/ ] ifFalse:[
|
|
121 |
argSpec := self fieldTypeFromStream:s in:aPackage.
|
|
122 |
spec size ~~ 0 ifTrue:[
|
|
123 |
spec := spec , ' '
|
|
124 |
].
|
|
125 |
spec := spec , argSpec.
|
|
126 |
"/ ]
|
|
127 |
].
|
|
128 |
^ spec
|
|
129 |
|
|
130 |
"Created: 18.3.1997 / 11:06:44 / cg"
|
|
131 |
!
|
|
132 |
|
8
|
133 |
fieldTypeFromStream:s
|
|
134 |
"parse a fieldTypeSpec - see java doc"
|
|
135 |
|
10
|
136 |
|typeChar typeSym spec elType size className|
|
8
|
137 |
|
|
138 |
typeChar := s next.
|
|
139 |
|
|
140 |
typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown.
|
|
141 |
|
|
142 |
typeSym == #unknown ifTrue:[
|
|
143 |
^ typeSym
|
|
144 |
].
|
|
145 |
typeSym == #object ifTrue:[
|
10
|
146 |
className := s upTo:$;.
|
|
147 |
"/ strip off default
|
113
|
148 |
"/ (className startsWith:'java/lang/') ifTrue:[
|
|
149 |
"/ ^ className copyFrom:11
|
|
150 |
"/ ].
|
|
151 |
^ className copy replaceAll:$/ by:$.
|
8
|
152 |
].
|
|
153 |
typeSym == #array ifTrue:[
|
|
154 |
s peek isDigit ifTrue:[
|
|
155 |
size := Integer readFrom:s.
|
|
156 |
elType := self fieldTypeFromStream:s.
|
|
157 |
^ elType , '[' , size printString , ']'
|
|
158 |
].
|
|
159 |
elType := self fieldTypeFromStream:s.
|
|
160 |
^ elType , '[]'
|
|
161 |
].
|
|
162 |
^ typeSym
|
|
163 |
!
|
|
164 |
|
142
|
165 |
fieldTypeFromStream:s in:aPackage
|
|
166 |
"parse a fieldTypeSpec - see java doc"
|
|
167 |
|
|
168 |
|typeChar typeSym spec elType size className nm|
|
|
169 |
|
|
170 |
typeChar := s next.
|
|
171 |
|
|
172 |
typeSym := SignatureTypeCodes at:typeChar ifAbsent:#unknown.
|
|
173 |
|
|
174 |
typeSym == #unknown ifTrue:[
|
|
175 |
^ typeSym
|
|
176 |
].
|
|
177 |
typeSym == #object ifTrue:[
|
|
178 |
className := s upTo:$;.
|
|
179 |
"/ strip off default
|
|
180 |
|
|
181 |
"/ (className startsWith:'java/lang/') ifTrue:[
|
|
182 |
"/ ^ className copyFrom:11
|
|
183 |
"/ ].
|
|
184 |
|
|
185 |
nm := className.
|
|
186 |
aPackage notNil ifTrue:[
|
|
187 |
(nm startsWith:aPackage) ifTrue:[
|
|
188 |
nm := nm copyFrom:(aPackage size + 2).
|
|
189 |
].
|
|
190 |
].
|
|
191 |
|
|
192 |
nm := nm copy replaceAll:$/ by:$..
|
|
193 |
^ nm
|
|
194 |
].
|
|
195 |
typeSym == #array ifTrue:[
|
|
196 |
s peek isDigit ifTrue:[
|
|
197 |
size := Integer readFrom:s.
|
|
198 |
elType := self fieldTypeFromStream:s.
|
|
199 |
^ elType , '[' , size printString , ']'
|
|
200 |
].
|
|
201 |
elType := self fieldTypeFromStream:s.
|
|
202 |
^ elType , '[]'
|
|
203 |
].
|
|
204 |
^ typeSym
|
|
205 |
|
|
206 |
"Created: 18.3.1997 / 11:07:56 / cg"
|
|
207 |
"Modified: 18.3.1997 / 11:18:09 / cg"
|
|
208 |
!
|
|
209 |
|
27
|
210 |
numArgsFromSignature:aSignature
|
|
211 |
"given a signature, return the number of args"
|
|
212 |
|
|
213 |
|s argSpec|
|
|
214 |
|
|
215 |
s := aSignature readStream.
|
|
216 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
217 |
|
|
218 |
^ self numArgsFromStream:s.
|
|
219 |
|
|
220 |
"
|
|
221 |
JavaMethod numArgsFromSignature:'(LObject;)V'
|
|
222 |
JavaMethod numArgsFromSignature:'(BB)S'
|
|
223 |
JavaMethod numArgsFromSignature:'()V'
|
|
224 |
"
|
|
225 |
!
|
|
226 |
|
|
227 |
numArgsFromStream:s
|
|
228 |
"parse an argSpec - see java doc"
|
|
229 |
|
55
|
230 |
|argSpec n t|
|
27
|
231 |
|
|
232 |
n := 0.
|
|
233 |
[s atEnd or:[s peek == $)]] whileFalse:[
|
55
|
234 |
t := self fieldTypeFromStream:s.
|
|
235 |
"/
|
|
236 |
"/ some args count as 2
|
|
237 |
"/
|
|
238 |
t == #long ifTrue:[
|
|
239 |
n := n + 2.
|
|
240 |
] ifFalse:[
|
|
241 |
t == #double ifTrue:[
|
|
242 |
n := n + 2
|
|
243 |
] ifFalse:[
|
|
244 |
n := n + 1.
|
|
245 |
]
|
|
246 |
]
|
27
|
247 |
].
|
|
248 |
^ n
|
|
249 |
!
|
|
250 |
|
29
|
251 |
retValSpecFromSignature:aSignature
|
|
252 |
"given a signature, return a spec"
|
|
253 |
|
|
254 |
|s argSpec retvalSpec|
|
|
255 |
|
|
256 |
s := aSignature readStream.
|
|
257 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
258 |
|
|
259 |
argSpec := self argSpecFromStream:s.
|
|
260 |
|
|
261 |
s next ~~ $) ifTrue:[self halt. ^ name].
|
|
262 |
|
|
263 |
retvalSpec := self retvalSpecFromStream:s.
|
|
264 |
|
|
265 |
^ retvalSpec
|
|
266 |
|
|
267 |
"
|
|
268 |
JavaMethod retValSpecFromSignature:'(LObject;)V'
|
|
269 |
JavaMethod retValSpecFromSignature:'(BB)S'
|
|
270 |
"
|
|
271 |
!
|
|
272 |
|
142
|
273 |
retValSpecFromSignature:aSignature in:aPackage
|
|
274 |
"given a signature, return a spec"
|
|
275 |
|
|
276 |
|s argSpec retvalSpec|
|
|
277 |
|
|
278 |
s := aSignature readStream.
|
|
279 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
280 |
|
|
281 |
argSpec := self argSpecFromStream:s in:aPackage.
|
|
282 |
|
|
283 |
s next ~~ $) ifTrue:[self halt. ^ name].
|
|
284 |
|
|
285 |
retvalSpec := self retvalSpecFromStream:s in:aPackage.
|
|
286 |
|
|
287 |
^ retvalSpec
|
|
288 |
|
|
289 |
"
|
|
290 |
JavaMethod retValSpecFromSignature:'(LObject;)V'
|
|
291 |
JavaMethod retValSpecFromSignature:'(BB)S'
|
|
292 |
"
|
|
293 |
|
|
294 |
"Created: 18.3.1997 / 11:11:50 / cg"
|
|
295 |
!
|
|
296 |
|
72
|
297 |
returnTypeFromSignature:aSignature
|
|
298 |
"given a signature, return its type as a string"
|
27
|
299 |
|
80
|
300 |
|s c argSpec retvalSpec|
|
27
|
301 |
|
|
302 |
s := aSignature readStream.
|
80
|
303 |
(c := s peek) ~~ $( ifTrue:[
|
|
304 |
c == $' ifTrue:[
|
|
305 |
[s peek ~= $'] whileTrue:[s next].
|
|
306 |
s next.
|
|
307 |
^ (self retvalSpecFromStream:s)
|
|
308 |
].
|
|
309 |
^ (self retvalSpecFromStream:s)
|
|
310 |
].
|
27
|
311 |
|
80
|
312 |
s next.
|
27
|
313 |
self argSpecFromStream:s.
|
80
|
314 |
s next ~~ $) ifTrue:[self halt. ^ nil].
|
27
|
315 |
|
72
|
316 |
^ (self retvalSpecFromStream:s)
|
|
317 |
|
|
318 |
"
|
|
319 |
JavaMethod returnTypeFromSignature:'(LObject;)V'
|
|
320 |
JavaMethod returnTypeFromSignature:'(BB)S'
|
|
321 |
JavaMethod returnTypeFromSignature:'()J'
|
80
|
322 |
JavaMethod returnTypeFromSignature:'''first''J'
|
72
|
323 |
"
|
|
324 |
!
|
|
325 |
|
|
326 |
returnsVoidFromSignature:aSignature
|
|
327 |
"given a signature, return true if it returns void, false if not"
|
|
328 |
|
83
|
329 |
^ (self typeFromSignature:aSignature) = 'void'
|
27
|
330 |
|
|
331 |
"
|
|
332 |
JavaMethod returnsVoidFromSignature:'(LObject;)V'
|
|
333 |
JavaMethod returnsVoidFromSignature:'(BB)S'
|
|
334 |
"
|
|
335 |
!
|
|
336 |
|
8
|
337 |
retvalSpecFromStream:s
|
|
338 |
"parse a retvalSpec - see java doc"
|
|
339 |
|
|
340 |
|argSpec spec|
|
|
341 |
|
72
|
342 |
s atEnd ifTrue:[self halt. ^ #void].
|
|
343 |
s peek == $V ifTrue:[^ #void].
|
8
|
344 |
^ self fieldTypeFromStream:s
|
10
|
345 |
|
|
346 |
!
|
|
347 |
|
142
|
348 |
retvalSpecFromStream:s in:aPackage
|
|
349 |
"parse a retvalSpec - see java doc"
|
|
350 |
|
|
351 |
|argSpec spec|
|
|
352 |
|
|
353 |
s atEnd ifTrue:[self halt. ^ #void].
|
|
354 |
s peek == $V ifTrue:[^ #void].
|
|
355 |
^ self fieldTypeFromStream:s in:aPackage
|
|
356 |
|
|
357 |
"Created: 18.3.1997 / 11:12:19 / cg"
|
|
358 |
!
|
|
359 |
|
10
|
360 |
specFromSignature:aSignature withName:name
|
|
361 |
"given a signature, return a spec"
|
|
362 |
|
|
363 |
|s argSpec retvalSpec|
|
|
364 |
|
|
365 |
s := aSignature readStream.
|
|
366 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
367 |
|
|
368 |
argSpec := self argSpecFromStream:s.
|
|
369 |
|
|
370 |
s next ~~ $) ifTrue:[self halt. ^ name].
|
|
371 |
|
|
372 |
retvalSpec := self retvalSpecFromStream:s.
|
|
373 |
|
|
374 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')'
|
|
375 |
|
|
376 |
"
|
|
377 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo'
|
27
|
378 |
JavaMethod specFromSignature:'(BB)S' withName:'foo'
|
10
|
379 |
"
|
83
|
380 |
!
|
|
381 |
|
142
|
382 |
specFromSignature:aSignature withName:name in:aPackage
|
|
383 |
"given a signature, return a spec"
|
|
384 |
|
|
385 |
|s argSpec retvalSpec|
|
|
386 |
|
|
387 |
s := aSignature readStream.
|
|
388 |
s next ~~ $( ifTrue:[self halt. ^ name].
|
|
389 |
|
|
390 |
argSpec := self argSpecFromStream:s in:aPackage.
|
|
391 |
|
|
392 |
s next ~~ $) ifTrue:[self halt. ^ name].
|
|
393 |
|
|
394 |
retvalSpec := self retvalSpecFromStream:s in:aPackage.
|
|
395 |
|
|
396 |
^ retvalSpec , ' ' , name , ' (' , argSpec , ')'
|
|
397 |
|
|
398 |
"
|
|
399 |
JavaMethod specFromSignature:'(LObject;)V' withName:'foo'
|
|
400 |
JavaMethod specFromSignature:'(BB)S' withName:'foo'
|
|
401 |
"
|
|
402 |
|
|
403 |
"Created: 18.3.1997 / 11:06:22 / cg"
|
|
404 |
!
|
|
405 |
|
83
|
406 |
typeFromSignature:aSignature
|
|
407 |
"given a signature, return its type as a string"
|
|
408 |
|
|
409 |
|s c argSpec retvalSpec|
|
|
410 |
|
|
411 |
s := aSignature readStream.
|
|
412 |
(c := s peek) ~~ $( ifTrue:[
|
|
413 |
c == $' ifTrue:[
|
|
414 |
s next.
|
|
415 |
[s peek ~= $'] whileTrue:[s next].
|
|
416 |
s next.
|
|
417 |
^ (self retvalSpecFromStream:s)
|
|
418 |
].
|
|
419 |
^ (self retvalSpecFromStream:s)
|
|
420 |
].
|
|
421 |
|
|
422 |
s next.
|
|
423 |
self argSpecFromStream:s.
|
|
424 |
s next ~~ $) ifTrue:[self halt. ^ nil].
|
|
425 |
|
|
426 |
^ (self retvalSpecFromStream:s)
|
|
427 |
|
|
428 |
"
|
|
429 |
JavaMethod typeFromSignature:'(LObject;)V'
|
|
430 |
JavaMethod typeFromSignature:'(BB)S'
|
|
431 |
JavaMethod typeFromSignature:'()J'
|
|
432 |
JavaMethod typeFromSignature:'J'
|
|
433 |
JavaMethod typeFromSignature:'''first''J'
|
|
434 |
"
|
10
|
435 |
! !
|
|
436 |
|
|
437 |
!JavaMethod methodsFor:'accessing'!
|
|
438 |
|
29
|
439 |
argSignature
|
|
440 |
^ self class argSigArrayFromSignature:signature
|
|
441 |
!
|
|
442 |
|
10
|
443 |
constantPool
|
|
444 |
^ javaClass constantPool
|
|
445 |
|
|
446 |
"Modified: 16.4.1996 / 12:36:27 / cg"
|
|
447 |
"Created: 16.4.1996 / 15:28:50 / cg"
|
|
448 |
!
|
|
449 |
|
129
|
450 |
containingClass
|
|
451 |
^ javaClass
|
|
452 |
|
|
453 |
!
|
|
454 |
|
75
|
455 |
decompiledSource
|
|
456 |
|s|
|
|
457 |
|
|
458 |
s := '' writeStream.
|
|
459 |
self decompileTo:s.
|
|
460 |
^ s contents
|
|
461 |
!
|
|
462 |
|
135
|
463 |
exceptionHandlerTable
|
|
464 |
^ exceptionHandlerTable
|
|
465 |
|
|
466 |
"Modified: 16.4.1996 / 12:49:06 / cg"
|
|
467 |
"Created: 7.2.1997 / 20:04:20 / cg"
|
|
468 |
!
|
|
469 |
|
83
|
470 |
exceptionTable
|
|
471 |
^ exceptionTable
|
|
472 |
|
|
473 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
474 |
"Modified: 16.4.1996 / 12:49:06 / cg"
|
|
475 |
!
|
|
476 |
|
90
|
477 |
hasLineNumberInformation
|
|
478 |
^ lineNumberTable notNil
|
|
479 |
|
|
480 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
481 |
"Modified: 16.4.1996 / 12:49:06 / cg"
|
|
482 |
!
|
|
483 |
|
148
|
484 |
isNOOPMethod:aBoolean
|
|
485 |
isNOOPMethod := aBoolean
|
|
486 |
|
|
487 |
"Created: 18.3.1997 / 13:31:16 / cg"
|
|
488 |
!
|
|
489 |
|
10
|
490 |
javaByteCode
|
|
491 |
^ javaByteCode
|
|
492 |
|
|
493 |
"Modified: 16.4.1996 / 12:36:27 / cg"
|
|
494 |
"Created: 16.4.1996 / 14:55:44 / cg"
|
8
|
495 |
!
|
|
496 |
|
27
|
497 |
javaClass
|
|
498 |
^ javaClass
|
|
499 |
|
|
500 |
"Modified: 16.4.1996 / 12:36:27 / cg"
|
|
501 |
"Created: 16.4.1996 / 14:55:44 / cg"
|
|
502 |
!
|
|
503 |
|
90
|
504 |
lineNumber
|
|
505 |
^ lineNumberTable at:2
|
|
506 |
|
|
507 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
508 |
"Modified: 16.4.1996 / 12:49:06 / cg"
|
|
509 |
!
|
|
510 |
|
50
|
511 |
lineNumberTable
|
|
512 |
^ lineNumberTable
|
|
513 |
|
|
514 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
515 |
"Modified: 16.4.1996 / 12:49:06 / cg"
|
|
516 |
!
|
|
517 |
|
85
|
518 |
localVariableTable
|
|
519 |
^ localVariableTable
|
|
520 |
|
|
521 |
"
|
|
522 |
JavaMethod allInstancesDo:[:m| m localVariableTable notNil ifTrue:[self halt]]
|
|
523 |
"
|
|
524 |
!
|
|
525 |
|
31
|
526 |
methodArgAndVarNames
|
|
527 |
^ ((1 to:self numArgs) collect:[:i | 'arg' , i printString])
|
|
528 |
,
|
|
529 |
((1 to:self numVars) collect:[:i | 'local' , i printString])
|
|
530 |
|
|
531 |
!
|
|
532 |
|
|
533 |
methodArgNames
|
102
|
534 |
localVariableTable notNil ifTrue:[
|
|
535 |
^ (1 to:self numArgs) collect:
|
|
536 |
[:argIndex | |slot name|
|
|
537 |
"/ search for an entry with that index (slot),
|
|
538 |
"/ which has is valid at PC 0
|
|
539 |
|
|
540 |
self isStatic ifTrue:[
|
|
541 |
slot := argIndex
|
|
542 |
] ifFalse:[
|
|
543 |
slot := argIndex + 1
|
|
544 |
].
|
|
545 |
name := localVariableTable nameForSlot:slot atPC:0.
|
|
546 |
name isNil ifTrue:[
|
|
547 |
'arg' , argIndex printString
|
|
548 |
] ifFalse:[
|
|
549 |
name
|
|
550 |
].
|
|
551 |
]
|
|
552 |
].
|
31
|
553 |
^ (1 to:self numArgs) collect:[:i | 'arg' , i printString]
|
|
554 |
!
|
|
555 |
|
29
|
556 |
name
|
|
557 |
^ name
|
|
558 |
|
|
559 |
"Created: 16.4.1996 / 11:34:22 / cg"
|
|
560 |
!
|
|
561 |
|
27
|
562 |
numArgs
|
29
|
563 |
numArgs isNil ifTrue:[^ 0].
|
27
|
564 |
^ numArgs
|
|
565 |
!
|
|
566 |
|
118
|
567 |
numLocals
|
|
568 |
numLocals isNil ifTrue:[^ 0].
|
|
569 |
^ numLocals
|
|
570 |
!
|
|
571 |
|
|
572 |
numStack
|
|
573 |
numStack isNil ifTrue:[^ 0].
|
|
574 |
^ numStack
|
|
575 |
!
|
|
576 |
|
29
|
577 |
numVars
|
|
578 |
numLocals isNil ifTrue:[^ 0].
|
118
|
579 |
numArgs isNil ifTrue:[^ numLocals].
|
|
580 |
^ numLocals - numArgs
|
29
|
581 |
!
|
|
582 |
|
27
|
583 |
numberOfMethodArgs:n
|
|
584 |
numArgs := n
|
|
585 |
!
|
|
586 |
|
29
|
587 |
retValSignature
|
|
588 |
^ self class retValSpecFromSignature:signature
|
|
589 |
|
|
590 |
!
|
|
591 |
|
123
|
592 |
returnType
|
|
593 |
^ returnType
|
|
594 |
!
|
|
595 |
|
116
|
596 |
returnsDouble
|
|
597 |
^ returnType == #double
|
|
598 |
!
|
|
599 |
|
72
|
600 |
returnsLong
|
|
601 |
^ returnType == #long
|
|
602 |
!
|
|
603 |
|
27
|
604 |
returnsVoid
|
72
|
605 |
^ returnType == #void
|
27
|
606 |
!
|
|
607 |
|
5
|
608 |
setAccessFlags:flags
|
|
609 |
accessFlags := flags.
|
|
610 |
|
|
611 |
"Created: 16.4.1996 / 11:34:14 / cg"
|
|
612 |
!
|
|
613 |
|
29
|
614 |
setCode:codeBytes maxStack:max_stack maxLocals:max_locals u1:unknown1 u2:unknown2
|
|
615 |
javaByteCode := codeBytes.
|
|
616 |
numStack := max_stack.
|
|
617 |
numLocals := max_locals.
|
5
|
618 |
|
43
|
619 |
"/ self displayString printNL.
|
|
620 |
"/ ' nStack: ' print. numStack print.
|
|
621 |
"/ ' nLocal: ' print. numLocals print.
|
|
622 |
"/ ' u1: ' print. unknown1 print.
|
|
623 |
"/ ' u2: ' print. unknown2 printNL.
|
29
|
624 |
|
5
|
625 |
!
|
|
626 |
|
83
|
627 |
setExceptionHandlerTable:anArray
|
|
628 |
exceptionHandlerTable := anArray.
|
|
629 |
|
|
630 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
631 |
!
|
|
632 |
|
5
|
633 |
setExceptionTable:anArray
|
|
634 |
exceptionTable := anArray.
|
|
635 |
|
|
636 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
637 |
!
|
|
638 |
|
|
639 |
setJavaClass:aJavaClass
|
|
640 |
javaClass := aJavaClass
|
|
641 |
|
|
642 |
"Modified: 16.4.1996 / 12:36:27 / cg"
|
|
643 |
"Created: 16.4.1996 / 15:28:15 / cg"
|
|
644 |
!
|
|
645 |
|
90
|
646 |
setLineNumberTable:anArrayOfPCtoLineAssociations
|
|
647 |
"since this uses up lots of memory, compress it"
|
|
648 |
|
|
649 |
|allBytes allWords idx|
|
|
650 |
|
|
651 |
allBytes := allWords := true.
|
|
652 |
|
|
653 |
anArrayOfPCtoLineAssociations do:[:assoc |
|
|
654 |
assoc key > 255 ifTrue:[
|
|
655 |
allBytes := false.
|
|
656 |
assoc key > 16rFFFF ifTrue:[
|
|
657 |
allWords := false.
|
|
658 |
].
|
|
659 |
].
|
|
660 |
assoc value > 255 ifTrue:[
|
|
661 |
allBytes := false.
|
|
662 |
assoc value > 16rFFFF ifTrue:[
|
|
663 |
allWords := false
|
|
664 |
].
|
|
665 |
].
|
|
666 |
].
|
|
667 |
allBytes ifTrue:[
|
|
668 |
lineNumberTable := ByteArray new:(anArrayOfPCtoLineAssociations size * 2).
|
|
669 |
] ifFalse:[
|
|
670 |
allWords ifTrue:[
|
|
671 |
lineNumberTable := WordArray new:(anArrayOfPCtoLineAssociations size * 2).
|
|
672 |
] ifFalse:[
|
|
673 |
lineNumberTable := Array new:(anArrayOfPCtoLineAssociations size * 2).
|
|
674 |
]
|
|
675 |
].
|
|
676 |
|
|
677 |
idx := 1.
|
|
678 |
anArrayOfPCtoLineAssociations do:[:assoc |
|
|
679 |
lineNumberTable at:idx put:assoc key.
|
|
680 |
lineNumberTable at:idx+1 put:assoc value.
|
|
681 |
idx := idx + 2.
|
|
682 |
].
|
5
|
683 |
|
|
684 |
"Created: 16.4.1996 / 12:34:04 / cg"
|
|
685 |
"Modified: 16.4.1996 / 12:49:06 / cg"
|
|
686 |
!
|
|
687 |
|
50
|
688 |
setLocalVariableTable:anArray
|
83
|
689 |
localVariableTable := anArray.
|
50
|
690 |
!
|
|
691 |
|
5
|
692 |
setName:aString
|
29
|
693 |
name := aString asSymbol.
|
5
|
694 |
|
|
695 |
"Created: 16.4.1996 / 11:34:22 / cg"
|
|
696 |
!
|
|
697 |
|
|
698 |
setSignature:aString
|
29
|
699 |
signature := aString asSymbol.
|
|
700 |
|
27
|
701 |
self numberOfMethodArgs:(self class numArgsFromSignature:aString).
|
83
|
702 |
returnType := self class typeFromSignature:aString.
|
27
|
703 |
|
|
704 |
"Created: 16.4.1996 / 11:34:29 / cg"
|
|
705 |
!
|
|
706 |
|
|
707 |
signature
|
|
708 |
^ signature
|
5
|
709 |
|
|
710 |
"Created: 16.4.1996 / 11:34:29 / cg"
|
31
|
711 |
!
|
|
712 |
|
|
713 |
source
|
75
|
714 |
|classSource|
|
31
|
715 |
|
75
|
716 |
lineNumberTable notNil ifTrue:[
|
|
717 |
classSource := javaClass source.
|
|
718 |
classSource notNil ifTrue:[^ classSource].
|
|
719 |
].
|
|
720 |
|
|
721 |
^ self decompiledSource
|
31
|
722 |
!
|
|
723 |
|
|
724 |
sourceFilename
|
|
725 |
^ javaClass sourceFile
|
8
|
726 |
! !
|
|
727 |
|
18
|
728 |
!JavaMethod methodsFor:'decompiling'!
|
|
729 |
|
|
730 |
decompileTo:aStream
|
|
731 |
JavaDecompiler decompile:self to:aStream.
|
|
732 |
^ true
|
|
733 |
|
|
734 |
|
|
735 |
! !
|
|
736 |
|
118
|
737 |
!JavaMethod methodsFor:'methodref interchangability'!
|
|
738 |
|
|
739 |
method
|
|
740 |
^ self
|
|
741 |
! !
|
|
742 |
|
148
|
743 |
!JavaMethod methodsFor:'misc'!
|
|
744 |
|
|
745 |
checkForNOOPMethod
|
|
746 |
javaByteCode notNil ifTrue:[
|
|
747 |
(javaByteCode at:1) == 177 "RETURN" ifTrue:[
|
|
748 |
'dummy static method: ' print. self displayString printCR.
|
|
749 |
isNOOPMethod := true.
|
|
750 |
^ self
|
|
751 |
].
|
|
752 |
].
|
|
753 |
^ self
|
|
754 |
|
|
755 |
"Created: 18.3.1997 / 13:31:50 / cg"
|
|
756 |
"Modified: 18.3.1997 / 13:42:48 / cg"
|
|
757 |
! !
|
|
758 |
|
8
|
759 |
!JavaMethod methodsFor:'printing & storing'!
|
|
760 |
|
29
|
761 |
displayString
|
|
762 |
^ 'JavaMethod(' , javaClass name , '::' , self signatureName , ')'
|
|
763 |
!
|
|
764 |
|
8
|
765 |
printStringForBrowserWithSelector:selector
|
43
|
766 |
"/ self isStatic ifTrue:[
|
|
767 |
"/ ^ 'static ' , self signatureName
|
|
768 |
"/ ].
|
80
|
769 |
self isBreakpointed ifTrue:[
|
|
770 |
^ '!! ' , self signatureName
|
|
771 |
].
|
8
|
772 |
^ self signatureName
|
10
|
773 |
!
|
|
774 |
|
118
|
775 |
shortDisplayString
|
|
776 |
^ javaClass name , '::' , self signatureNameWithoutReturnType
|
|
777 |
!
|
|
778 |
|
10
|
779 |
signatureName
|
|
780 |
"return a string to be used when browsing"
|
|
781 |
|
|
782 |
^ self class specFromSignature:signature withName:name
|
113
|
783 |
!
|
|
784 |
|
142
|
785 |
signatureNameIn:aPackage
|
|
786 |
"return a string to be used when browsing"
|
|
787 |
|
|
788 |
^ self class specFromSignature:signature withName:name in:aPackage
|
|
789 |
|
|
790 |
"Created: 18.3.1997 / 11:11:01 / cg"
|
|
791 |
!
|
|
792 |
|
113
|
793 |
signatureNameWithoutReturnType
|
|
794 |
"return a string to be used when browsing"
|
|
795 |
|
|
796 |
^ self class argSpecFromSignature:signature withName:name
|
|
797 |
|
8
|
798 |
! !
|
|
799 |
|
|
800 |
!JavaMethod methodsFor:'queries'!
|
|
801 |
|
111
|
802 |
handlerFor:anException at:pc
|
|
803 |
exceptionHandlerTable isNil ifTrue:[^ nil].
|
83
|
804 |
exceptionHandlerTable do:[:entry |
|
48
|
805 |
|hpc|
|
|
806 |
|
|
807 |
hpc := entry handlerPCFor:anException at:pc in:self.
|
111
|
808 |
hpc notNil ifTrue:[^ hpc].
|
48
|
809 |
].
|
|
810 |
|
111
|
811 |
^ nil
|
31
|
812 |
!
|
|
813 |
|
127
|
814 |
hasResource
|
|
815 |
^ false
|
|
816 |
!
|
|
817 |
|
19
|
818 |
isAbstract
|
|
819 |
^ (accessFlags bitAnd:16r0400) ~~ 0
|
|
820 |
!
|
|
821 |
|
80
|
822 |
isBreakpointed
|
|
823 |
^ false
|
|
824 |
!
|
|
825 |
|
19
|
826 |
isFinal
|
|
827 |
^ (accessFlags bitAnd:16r0010) ~~ 0
|
|
828 |
!
|
|
829 |
|
148
|
830 |
isNOOPMethod
|
|
831 |
^ isNOOPMethod == true
|
|
832 |
|
|
833 |
"Modified: 18.3.1997 / 13:30:56 / cg"
|
|
834 |
!
|
|
835 |
|
19
|
836 |
isNative
|
|
837 |
^ (accessFlags bitAnd:16r0100) ~~ 0
|
|
838 |
!
|
|
839 |
|
|
840 |
isPrivate
|
|
841 |
^ (accessFlags bitAnd:16r0002) ~~ 0
|
|
842 |
|
|
843 |
!
|
|
844 |
|
|
845 |
isProtected
|
|
846 |
^ (accessFlags bitAnd:16r0004) ~~ 0
|
|
847 |
!
|
|
848 |
|
|
849 |
isPublic
|
|
850 |
^ (accessFlags bitAnd:16r0001) ~~ 0
|
|
851 |
|
|
852 |
!
|
|
853 |
|
|
854 |
isStatic
|
|
855 |
^ (accessFlags bitAnd:16r0008) ~~ 0
|
|
856 |
!
|
|
857 |
|
|
858 |
isSynchronized
|
|
859 |
^ (accessFlags bitAnd:16r0020) ~~ 0
|
18
|
860 |
!
|
|
861 |
|
8
|
862 |
isUnloaded
|
|
863 |
^ false
|
18
|
864 |
!
|
|
865 |
|
31
|
866 |
lineNumberForPC:pc
|
75
|
867 |
|last num text classSource|
|
31
|
868 |
|
|
869 |
num := nil.
|
|
870 |
|
46
|
871 |
lineNumberTable notNil ifTrue:[
|
75
|
872 |
classSource := javaClass source.
|
|
873 |
classSource notNil ifTrue:[
|
90
|
874 |
lineNumberTable pairWiseDo:[:lPc :lNr |
|
|
875 |
lPc >= pc ifTrue:[
|
143
|
876 |
"/ lPc == pc ifTrue:[^ lNr].
|
90
|
877 |
last isNil ifTrue:[^ lNr].
|
|
878 |
^ last.
|
75
|
879 |
].
|
90
|
880 |
last := lNr.
|
75
|
881 |
].
|
141
|
882 |
last notNil ifTrue:[
|
|
883 |
^ last
|
|
884 |
].
|
90
|
885 |
^ lineNumberTable at:2
|
75
|
886 |
].
|
46
|
887 |
].
|
31
|
888 |
|
46
|
889 |
"/ decompile and look which line the pc falls into
|
75
|
890 |
text := self decompiledSource asCollectionOfLines.
|
31
|
891 |
|
46
|
892 |
text keysAndValuesDo:[:lineNr :line |
|
|
893 |
|nr|
|
|
894 |
|
83
|
895 |
(line startsWith:' ') ifFalse:[
|
|
896 |
nr := Integer readFrom:line onError:0.
|
|
897 |
nr >= pc ifTrue:[
|
|
898 |
^ lineNr
|
|
899 |
]
|
46
|
900 |
]
|
31
|
901 |
].
|
|
902 |
^ num
|
141
|
903 |
|
143
|
904 |
"Modified: 18.3.1997 / 12:30:07 / cg"
|
31
|
905 |
!
|
|
906 |
|
18
|
907 |
who
|
|
908 |
"return the class and selector of where I am defined in."
|
|
909 |
|
64
|
910 |
|sel|
|
18
|
911 |
|
64
|
912 |
sel := javaClass methodDictionary keyAtValue:self ifAbsent:nil.
|
|
913 |
sel isNil ifTrue:[^ nil].
|
129
|
914 |
^ Method::MethodWhoInfo class:javaClass selector:sel.
|
5
|
915 |
! !
|
|
916 |
|
129
|
917 |
!JavaMethod class methodsFor:'documentation'!
|
2
|
918 |
|
|
919 |
version
|
148
|
920 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaMethod.st,v 1.34 1997/03/18 16:52:18 cg Exp $'
|
2
|
921 |
! !
|
8
|
922 |
JavaMethod initialize!
|