author | hlopkmar |
Thu, 12 May 2011 15:40:53 +0000 | |
branch | jk_new_structure |
changeset 774 | ac54730a2b74 |
parent 772 | 0f92c23b80ee |
child 775 | 8b0e1974c289 |
permissions | -rw-r--r-- |
752 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libjava' }" |
|
13 |
||
14 |
Object subclass:#JavaClassReader |
|
15 |
instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
|
771 | 16 |
constSlot classBeingRead' |
752 | 17 |
classVariableNames:'Verbose AnnotationsVerbose Silent AbsolutelySilent |
18 |
LazyClassLoading InvalidClassFormatSignal ClassLoaderQuerySignal |
|
771 | 19 |
JavaArchiveCache UsedJavaClassReaderClass' |
752 | 20 |
poolDictionaries:'' |
21 |
category:'Languages-Java-Support' |
|
22 |
! |
|
23 |
||
24 |
!JavaClassReader class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! ! |
|
41 |
||
42 |
!JavaClassReader class methodsFor:'initialization'! |
|
43 |
||
44 |
initialize |
|
45 |
InvalidClassFormatSignal := Signal new mayProceed: true. |
|
46 |
InvalidClassFormatSignal notifierString: 'class load failure'. |
|
47 |
InvalidClassFormatSignal nameClass: self message: #invalidClassFormatSignal. |
|
772
0f92c23b80ee
testing new project structure + fixing tiny litle bug which caused java not to work at all :)
hlopkmar
parents:
771
diff
changeset
|
48 |
UsedJavaClassReaderClass := JavaClassReader. |
752 | 49 |
Verbose := false. |
50 |
Silent := true. |
|
51 |
AbsolutelySilent := false. |
|
52 |
||
53 |
"/LazyClassLoading := false. |
|
54 |
||
55 |
LazyClassLoading := true. |
|
56 |
ClassLoaderQuerySignal := QuerySignal new. |
|
57 |
JavaArchiveCache := CacheDictionary new: 32. |
|
58 |
AnnotationsVerbose := false. |
|
771 | 59 |
|
752 | 60 |
" |
61 |
JavaClassReader initialize" |
|
62 |
||
63 |
"Modified: / 27-01-1998 / 17:54:23 / cg" |
|
64 |
"Modified: / 17-12-2010 / 17:37:45 / Marcel Hlopko <hlopik@gmail.com>" |
|
65 |
"Modified: / 10-02-2011 / 23:16:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
772
0f92c23b80ee
testing new project structure + fixing tiny litle bug which caused java not to work at all :)
hlopkmar
parents:
771
diff
changeset
|
66 |
"Modified: / 10-05-2011 / 23:59:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 67 |
! ! |
68 |
||
69 |
!JavaClassReader class methodsFor:'Signal constants'! |
|
70 |
||
71 |
classLoaderQuerySignal |
|
72 |
^ ClassLoaderQuerySignal |
|
73 |
||
74 |
"Created: 14.8.1997 / 19:56:03 / cg" |
|
75 |
! |
|
76 |
||
77 |
invalidClassFormatSignal |
|
78 |
^ InvalidClassFormatSignal |
|
79 |
||
80 |
"Created: 3.8.1997 / 18:17:21 / cg" |
|
81 |
! ! |
|
82 |
||
83 |
!JavaClassReader class methodsFor:'constants'! |
|
84 |
||
85 |
fileMajorVersions |
|
86 |
^ #( |
|
87 |
45 "Java 1.2" |
|
88 |
49 "Java 6" |
|
89 |
) |
|
90 |
||
91 |
"Created: / 19-10-2010 / 21:40:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
92 |
! |
|
93 |
||
94 |
fileMinorVersions |
|
95 |
^ #( |
|
96 |
3 "Java 1.2" |
|
97 |
0 "Java 6" |
|
98 |
) |
|
99 |
||
100 |
"Created: / 19-10-2010 / 21:41:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
101 |
! |
|
102 |
||
103 |
magic_LSB |
|
104 |
^ 16rBEBAFECA |
|
105 |
||
106 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
107 |
"Created: / 7.5.1998 / 13:15:05 / cg" |
|
108 |
! |
|
109 |
||
110 |
magic_MSB |
|
111 |
^ 16rCAFEBABE |
|
112 |
||
113 |
"Modified: / 7.5.1998 / 13:14:27 / cg" |
|
114 |
! ! |
|
115 |
||
116 |
!JavaClassReader class methodsFor:'debugging'! |
|
117 |
||
118 |
annotationsVerbose:aBoolean |
|
119 |
AnnotationsVerbose := aBoolean |
|
120 |
||
121 |
" |
|
122 |
Java flushClasses. |
|
123 |
JavaClassReader verbose:true |
|
124 |
JavaClassReader verbose:false" |
|
125 |
||
126 |
"Created: / 25-02-2011 / 12:25:23 / Marcel Hlopko <hlopik@gmail.com>" |
|
127 |
! |
|
128 |
||
129 |
verbose:aBoolean |
|
130 |
Verbose := aBoolean |
|
131 |
||
132 |
" |
|
133 |
Java flushClasses. |
|
134 |
JavaClassReader verbose:true |
|
135 |
JavaClassReader verbose:false |
|
136 |
" |
|
137 |
! ! |
|
138 |
||
139 |
!JavaClassReader class methodsFor:'file reading'! |
|
140 |
||
141 |
loadClass:aClassName |
|
142 |
"reads a class, installs and returns it. |
|
143 |
The classes string constants are resolved & <clinit> is called, |
|
144 |
if it implements it." |
|
145 |
||
146 |
|rslt loader| |
|
147 |
||
148 |
loader := ClassLoaderQuerySignal query. |
|
149 |
loader isNil ifTrue:[ |
|
150 |
^ self loadSystemClass:aClassName |
|
151 |
]. |
|
152 |
||
153 |
^ loader loadClass:aClassName |
|
154 |
||
155 |
" |
|
156 |
JavaClassReader loadClass:'awt/Component' |
|
157 |
JavaClassReader loadClass:'awt/Button' |
|
158 |
JavaClassReader loadClass:'browser/AddButton' |
|
159 |
||
160 |
JavaClassReader loadClass:'java/lang/Object' |
|
161 |
JavaClassReader loadClass:'java/lang/AbstractMethodError' |
|
162 |
JavaClassReader loadClass:'java/lang/Thread' |
|
163 |
" |
|
164 |
||
165 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
|
166 |
"Modified: / 20.10.1998 / 17:24:54 / cg" |
|
167 |
! |
|
168 |
||
761 | 169 |
loadClassLazy: internalJavaClassName |
170 |
^ self loadClassLazy: internalJavaClassName ignoring: Set new. |
|
758 | 171 |
|
172 |
"Created: / 08-04-2011 / 18:00:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
761 | 173 |
"Modified: / 11-04-2011 / 19:31:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
758 | 174 |
! |
175 |
||
752 | 176 |
loadClassLazy: aClassName ignoring: classesBeingLoaded |
177 |
"private helper: |
|
178 |
reads a class, installs and returns it. |
|
179 |
The class is searched along the ClassPath. |
|
180 |
||
181 |
This is a partial load (to load other classes): |
|
182 |
- The classes stringConstants are not fixed to be JavaStrings |
|
183 |
(i.e they are still ST-Strings). |
|
184 |
- The class is NOT initialized." |
|
185 |
||
186 |
| rslt clsName cls loadedClass | |
|
187 |
||
188 |
clsName := aClassName. |
|
189 |
(clsName endsWith: ';') |
|
190 |
ifTrue: |
|
191 |
[ (clsName startsWith: '[L') |
|
192 |
ifTrue: [ clsName := clsName copyFrom: 3 to: clsName size - 1. ] |
|
193 |
ifFalse: |
|
194 |
[ ('oops - loading of ' , clsName , ' attempted') printNL. |
|
195 |
self halt: 'should not happen'. |
|
196 |
^ nil. ] ]. |
|
197 |
(clsName endsWith: '[]') |
|
198 |
ifTrue: |
|
199 |
[ ('oops - loading of ' , clsName , ' attempted') printNL. |
|
200 |
self halt: 'should not happen'. |
|
201 |
^ nil ]. |
|
202 |
(clsName includes: $.) |
|
203 |
ifTrue: [ clsName := clsName asString copyReplaceAll: $. with: $/ ]. |
|
204 |
(classesBeingLoaded notNil and: [ classesBeingLoaded includes: clsName ]) |
|
205 |
ifTrue: |
|
206 |
[ ('oops - recursive load of ' , clsName , ' attempted') printNL. |
|
207 |
self halt: 'should not happen'. |
|
208 |
^ JavaUnresolvedClassConstant fullName: clsName ]. |
|
209 |
(cls := Java at: clsName) notNil |
|
210 |
ifTrue: |
|
211 |
[ ('oops - ' , clsName , ' is already loaded') printNL. |
|
212 |
||
213 |
"/self halt:clsName , ' is already loaded - should not happen'. |
|
214 |
||
215 |
^ cls ]. |
|
216 |
classesBeingLoaded isNil |
|
217 |
ifTrue: [ loadedClass := Set with: clsName ] |
|
218 |
ifFalse: |
|
219 |
[ loadedClass := Set withAll: classesBeingLoaded. |
|
220 |
loadedClass add: clsName. ]. |
|
221 |
Java effectiveClassPath do: |
|
222 |
[:path | |
|
223 |
| nm p zar entry zipFile read | |
|
224 |
||
225 |
Verbose == true |
|
226 |
ifTrue: [ Transcript showCR: 'trying ' , path asFilename pathName , ' ...'. ]. |
|
227 |
p := path. |
|
228 |
p asFilename isDirectory |
|
229 |
ifTrue: |
|
230 |
[ (p endsWith: Filename separator) |
|
231 |
ifFalse: [ p := p , (Filename separator asString) ]. |
|
232 |
(Array |
|
233 |
with: clsName |
|
234 |
with: clsName asLowercase |
|
235 |
with: clsName asUppercase) do: |
|
236 |
[:tryName | |
|
237 |
nm := p , tryName , '.class'. |
|
238 |
Verbose == true ifTrue: [ Transcript showCR: 'trying ' , nm , ' ...'. ]. |
|
239 |
nm asFilename exists |
|
240 |
ifTrue: |
|
241 |
[ (Java isExcludedFromClassPath: nm) |
|
242 |
ifFalse: |
|
243 |
[ rslt := self loadFileLazy: nm ignoring: loadedClass. |
|
244 |
rslt notNil ifTrue: [ ^ rslt ]. ] ]. ] ] |
|
245 |
ifFalse: |
|
246 |
[ Verbose == true |
|
247 |
ifTrue: |
|
248 |
[ Transcript |
|
249 |
showCR: 'trying ' , (p asFilename withSuffix: 'jar') pathName , ' ...'. |
|
250 |
Transcript |
|
251 |
showCR: 'and ' , (p asFilename withSuffix: 'zip') pathName , ' ...'. ]. |
|
252 |
((zipFile := p asFilename withSuffix: 'jar') exists |
|
253 |
or: [ (zipFile := p asFilename withSuffix: 'zip') exists ]) |
|
254 |
ifTrue: |
|
255 |
[ |
|
256 |
zar := JavaArchiveCache at: zipFile |
|
257 |
ifAbsentPut: [ ZipArchive oldFileNamed: zipFile ]. |
|
258 |
read := |
|
259 |
[ nm := clsName , '.class'. |
|
260 |
entry := zar extract: nm. |
|
261 |
entry notNil |
|
262 |
ifTrue: |
|
263 |
[ (Java isExcludedFromClassPath: nm) |
|
264 |
ifFalse: |
|
265 |
[ rslt := self loadStreamLazy: (entry readStream) ignoring: loadedClass. |
|
266 |
rslt notNil ifTrue: [ ^ rslt ]. ] ] ]. |
|
267 |
JavaClassReader invalidClassFormatSignal handle: |
|
268 |
[ "Kludge, sometimes zar gets corrupted" |
|
269 |
||
270 |
zar := JavaArchiveCache at: zipFile put: (ZipArchive oldFileNamed: zipFile). |
|
271 |
read value ] |
|
272 |
do: [ read value ]. ] ] ]. |
|
273 |
('JAVA [info]: no file found for: ' , clsName) infoPrintCR. |
|
274 |
^ nil |
|
275 |
||
276 |
"Modified: / 14-08-1997 / 11:38:42 / stefan" |
|
277 |
"Modified: / 17-09-1998 / 20:51:25 / cg" |
|
278 |
"Modified: / 18-03-2011 / 16:06:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
279 |
"Modified: / 21-03-2011 / 12:42:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
280 |
! |
|
281 |
||
282 |
loadClassesIn: directory |
|
283 |
"load all classes (.class files, strictly speaking) found in given directory |
|
284 |
or .jar file. The argument is string containing the name of the directory. |
|
758 | 285 |
Returns a set of loaded classes." |
752 | 286 |
|
758 | 287 |
| dir dirString className loadedClasses | |
288 |
||
752 | 289 |
dir := directory asFilename. |
290 |
loadedClasses := Set new. |
|
291 |
Java addToClassPath: dir pathName. |
|
292 |
dir recursiveDirectoryContentsAsFilenamesDo: |
|
293 |
[:filename | |
|
294 |
(filename isRegularFile and: [ filename suffix = #class ]) |
|
295 |
ifTrue: |
|
296 |
[ dirString := dir asAbsoluteFilename pathName. |
|
297 |
className := filename withoutSuffix pathName. |
|
298 |
className := className subString: dirString size + 2 to: className size. |
|
761 | 299 |
loadedClasses add: (self loadClass: className). ]. ]. |
300 |
^ loadedClasses. |
|
752 | 301 |
|
302 |
"Created: / 15-03-2011 / 15:39:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
303 |
"Modified: / 01-04-2011 / 15:44:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
761 | 304 |
"Modified: / 29-04-2011 / 17:43:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 305 |
! |
306 |
||
307 |
loadFile:aFilename |
|
308 |
"reads a class from aFilename, installs and returns it. |
|
309 |
The classes strings are fixed and its class-init function is called." |
|
310 |
||
311 |
self loadFileLazy:aFilename ignoring:(Set new). |
|
312 |
self postLoadActions |
|
313 |
! |
|
314 |
||
315 |
loadFileLazy:aFilename ignoring:classesBeingLoaded |
|
316 |
"reads a class from aFilename, installs and returns it. |
|
317 |
Strings are fixed and classrefs are fixed, |
|
318 |
but NO no class-init functions are called." |
|
319 |
||
320 |
|aClass pool| |
|
321 |
||
322 |
aClass := self readFile:aFilename ignoring:classesBeingLoaded. |
|
323 |
aClass notNil ifTrue:[ |
|
324 |
aClass isJavaClass ifTrue:[ |
|
325 |
"/ a java class |
|
326 |
Java at:(aClass fullName asSymbol) put:aClass. |
|
327 |
||
328 |
classesBeingLoaded remove:aClass fullName ifAbsent:nil. |
|
329 |
||
330 |
JavaUnresolvedConstant resolveFor:aClass. |
|
331 |
] ifFalse:[ |
|
332 |
"/ a smalltalk class |
|
333 |
"/ self halt. |
|
334 |
aClass inspect. |
|
335 |
] |
|
336 |
]. |
|
337 |
^ aClass |
|
338 |
||
339 |
" |
|
340 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
341 |
||
342 |
'/phys/ibm3/java/lib/java/lang' asFilename |
|
343 |
directoryContents do:[:nm | |
|
344 |
(nm endsWith:'.class') ifTrue:[ |
|
345 |
('/phys/ibm3/java/lib/java/lang/' , nm) printNL. |
|
346 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/' , nm |
|
347 |
] |
|
348 |
]. |
|
349 |
||
350 |
'/phys/ibm3/java/lib/java/io' asFilename |
|
351 |
directoryContents do:[:nm | |
|
352 |
(nm endsWith:'.class') ifTrue:[ |
|
353 |
('/phys/ibm3/java/lib/java/io/' , nm) printNL. |
|
354 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/io/' , nm |
|
355 |
] |
|
356 |
]. |
|
357 |
||
358 |
'/phys/ibm3/java/lib/java/net' asFilename |
|
359 |
directoryContents do:[:nm | |
|
360 |
(nm endsWith:'.class') ifTrue:[ |
|
361 |
('/phys/ibm3/java/lib/java/net/' , nm) printNL. |
|
362 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/net/' , nm |
|
363 |
] |
|
364 |
]. |
|
365 |
||
366 |
'/phys/ibm3/java/lib/java/util' asFilename |
|
367 |
directoryContents do:[:nm | |
|
368 |
(nm endsWith:'.class') ifTrue:[ |
|
369 |
('/phys/ibm3/java/lib/java/util/' , nm) printNL. |
|
370 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/util/' , nm |
|
371 |
] |
|
372 |
]. |
|
373 |
||
374 |
'/phys/ibm3/java/lib/java/awt' asFilename |
|
375 |
directoryContents do:[:nm | |
|
376 |
(nm endsWith:'.class') ifTrue:[ |
|
377 |
('/phys/ibm3/java/lib/java/awt/' , nm) printNL. |
|
378 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/awt/' , nm |
|
379 |
] |
|
380 |
]. |
|
381 |
||
382 |
'/phys/ibm3/java/lib/java/applet' asFilename |
|
383 |
directoryContents do:[:nm | |
|
384 |
(nm endsWith:'.class') ifTrue:[ |
|
385 |
('/phys/ibm3/java/lib/java/applet/' , nm) printNL. |
|
386 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/applet/' , nm |
|
387 |
] |
|
388 |
]. |
|
389 |
||
390 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/AbstractMethodError.class' |
|
391 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/Thread.class' |
|
392 |
" |
|
393 |
||
394 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
|
395 |
"Modified: / 12.5.1998 / 22:06:52 / cg" |
|
396 |
! |
|
397 |
||
398 |
loadStreamLazy:aStream ignoring:classesBeingLoaded |
|
399 |
"reads a class from aStream, installs and returns it. |
|
400 |
Strings are fixed and classrefs are fixed, |
|
401 |
but NO no class-init functions are called." |
|
402 |
||
403 |
|javaClass pool| |
|
404 |
||
405 |
javaClass := self readStream:aStream ignoring:classesBeingLoaded. |
|
406 |
javaClass notNil ifTrue:[ |
|
407 |
Java at:(javaClass fullName asSymbol) put:javaClass. |
|
408 |
||
409 |
classesBeingLoaded remove:javaClass fullName ifAbsent:nil. |
|
410 |
||
411 |
JavaUnresolvedConstant resolveFor:javaClass. |
|
412 |
]. |
|
413 |
^ javaClass |
|
414 |
||
415 |
"Created: / 30.3.1998 / 17:59:02 / cg" |
|
416 |
! |
|
417 |
||
771 | 418 |
loadSystemClass: aClassName |
752 | 419 |
"reads a class, installs and returns it. |
420 |
The classes string constants are resolved & <clinit> is called, |
|
421 |
if it implements it. |
|
422 |
This only loads local classes (i.e. any Java classReader is not used)" |
|
771 | 423 |
|
424 |
| rslt | |
|
425 |
||
426 |
rslt := UsedJavaClassReaderClass loadClassLazy: aClassName ignoring: (Set new). |
|
427 |
rslt notNil ifTrue: [ UsedJavaClassReaderClass postLoadActions ]. |
|
752 | 428 |
^ rslt |
429 |
||
430 |
" |
|
431 |
JavaClassReader loadSystemClass:'awt/Component' |
|
432 |
JavaClassReader loadSystemClass:'awt/Button' |
|
433 |
JavaClassReader loadSystemClass:'browser/AddButton' |
|
434 |
||
435 |
JavaClassReader loadSystemClass:'java/lang/Object' |
|
436 |
JavaClassReader loadSystemClass:'java/lang/AbstractMethodError' |
|
771 | 437 |
JavaClassReader loadSystemClass:'java/lang/Thread'" |
438 |
||
439 |
"Created: / 20-10-1998 / 17:24:40 / cg" |
|
440 |
"Modified: / 09-05-2011 / 23:12:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 441 |
! |
442 |
||
443 |
postLoadActions |
|
444 |
"Resolve all classes' string constants. |
|
445 |
Perform all class initialization functions (of those which are not |
|
446 |
yet initialized)." |
|
447 |
||
448 |
^ self postLoadActions:true |
|
449 |
||
450 |
"Modified: 15.8.1997 / 01:02:17 / cg" |
|
451 |
! |
|
452 |
||
453 |
postLoadActions:loadUnresolved |
|
454 |
"Resolve all classes' string constants. |
|
455 |
Perform all class initialization functions |
|
456 |
(of those which are not yet initialized)." |
|
457 |
||
458 |
|classes prevUnresolved newUnresolved loader| |
|
459 |
||
460 |
"/ need at least java.lang.String, for valid constants |
|
461 |
Java java_lang_String isNil ifTrue:[ |
|
462 |
self loadClassLazy:'java.lang.String' ignoring:(Set new). |
|
463 |
]. |
|
464 |
||
465 |
LazyClassLoading ifFalse:[ |
|
466 |
loader := ClassLoaderQuerySignal query. |
|
467 |
||
468 |
prevUnresolved := nil. |
|
469 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
470 |
loadUnresolved ifTrue:[ |
|
471 |
[prevUnresolved ~= newUnresolved] whileTrue:[ |
|
472 |
newUnresolved do:[:nextUnresolved | |
|
473 |
|classURL| |
|
474 |
||
475 |
(Java at:nextUnresolved) isNil ifTrue:[ "/ could have been loaded in the meantime |
|
476 |
Silent ifFalse:[ |
|
477 |
'loading unresolved: ' print. nextUnresolved printCR. |
|
478 |
]. |
|
479 |
loader isNil ifTrue:[ |
|
480 |
self |
|
481 |
loadClassLazy:nextUnresolved |
|
482 |
ignoring:(Set new). |
|
483 |
] ifFalse:[ |
|
484 |
"/ |
|
485 |
"/ the aquired loader is a javaClassLoader |
|
486 |
"/ which expects an URL as arg. |
|
487 |
"/ |
|
488 |
"/ classURL := Java as_URL:('file:' , nextUnresolved asString , '.class'). |
|
489 |
"/ loader loadClass:classURL |
|
490 |
loader |
|
491 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
492 |
with:(Java as_String:(nextUnresolved asString)). |
|
493 |
] |
|
494 |
] |
|
495 |
]. |
|
496 |
prevUnresolved := newUnresolved. |
|
497 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
498 |
]. |
|
499 |
]. |
|
500 |
false ifTrue:[ |
|
501 |
newUnresolved size == 0 ifTrue:[ |
|
502 |
"/ nothing unresolved |
|
503 |
||
504 |
(classes := Java allClasses) notNil ifTrue:[ |
|
505 |
"/ init all new classes |
|
506 |
"/ fetch again - there could be new ones ... |
|
507 |
||
508 |
classes := Java allClasses. |
|
509 |
classes do:[:aJavaClass | |
|
510 |
aJavaClass isInitialized ifFalse:[ |
|
511 |
Silent ifFalse:[ |
|
512 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
513 |
]. |
|
514 |
aJavaClass classInit |
|
515 |
] |
|
516 |
] |
|
517 |
] |
|
518 |
]. |
|
519 |
]. |
|
520 |
] |
|
521 |
||
522 |
"Created: / 15.8.1997 / 01:01:44 / cg" |
|
523 |
"Modified: / 21.10.1998 / 01:18:35 / cg" |
|
524 |
! |
|
525 |
||
526 |
readFile:aFilename ignoring:classesBeingLoaded |
|
527 |
"reads a class from aFilename and returns it. |
|
528 |
The JavaClass is NOT installed as global and unresolved |
|
529 |
refs are NOT patched." |
|
530 |
||
531 |
|inStream javaClass| |
|
532 |
||
533 |
"Silent"false ifFalse:[ |
|
534 |
'reading ' print. aFilename print. ' ...' printCR. |
|
535 |
]. |
|
536 |
ObjectMemory compressingGarbageCollect. |
|
537 |
||
538 |
[ |
|
539 |
inStream := aFilename asFilename readStream. |
|
540 |
] on:StreamError do:[:ex| |
|
541 |
('JAVA [info]: no file: ' , aFilename asString) printCR. |
|
542 |
self halt. |
|
543 |
^ nil |
|
544 |
]. |
|
545 |
||
546 |
javaClass := self new readStream:inStream ignoring:classesBeingLoaded. |
|
547 |
(javaClass notNil and:[javaClass isJavaClass]) ifTrue:[ |
|
548 |
javaClass setBinaryFilePath:(inStream pathName). |
|
549 |
]. |
|
550 |
inStream close. |
|
551 |
||
552 |
ObjectMemory compressingGarbageCollect. |
|
553 |
AbsolutelySilent ifFalse:[ |
|
554 |
' ... loaded ' print. javaClass displayString printNL. |
|
555 |
]. |
|
556 |
||
557 |
||
558 |
^ javaClass |
|
559 |
||
560 |
"Created: / 15.4.1996 / 14:58:53 / cg" |
|
561 |
"Modified: / 9.5.1998 / 01:44:24 / cg" |
|
562 |
! |
|
563 |
||
564 |
readStream:aStream |
|
565 |
"reads a class from aStream and returns it. |
|
566 |
The JavaClass is installed as global. |
|
567 |
If new classes are required to be loaded, a new standard loader |
|
568 |
is created." |
|
569 |
||
570 |
^ self readStream:aStream loader:nil |
|
571 |
||
572 |
"Modified: 14.8.1997 / 19:51:50 / cg" |
|
573 |
! |
|
574 |
||
771 | 575 |
readStream: aStream ignoring: classesBeingLoaded |
752 | 576 |
"reads a class from aStream and returns it. |
577 |
The JavaClass is not installed as global" |
|
771 | 578 |
|
579 |
| javaClass | |
|
580 |
||
581 |
javaClass := UsedJavaClassReaderClass new readStream: aStream ignoring: classesBeingLoaded. |
|
582 |
AbsolutelySilent |
|
583 |
ifFalse: |
|
584 |
[ ' ... loaded ' print. |
|
585 |
javaClass displayString printNL. ]. |
|
752 | 586 |
^ javaClass |
587 |
||
771 | 588 |
"Modified: / 30-03-1998 / 18:14:40 / cg" |
589 |
"Modified: / 09-05-2011 / 23:15:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 590 |
! |
591 |
||
592 |
readStream:aStream loader:aClassLoader |
|
593 |
"reads a class from aStream and returns it. |
|
594 |
The JavaClass is installed as global. |
|
595 |
If new classes are required to be loaded, aClassLoader is |
|
596 |
asked to do it. If aClassLoader is nil, a new standard loader |
|
597 |
is created." |
|
598 |
||
599 |
^ self |
|
600 |
readStream:aStream |
|
601 |
loader:aClassLoader |
|
602 |
loadUnresolved:true |
|
603 |
||
604 |
"Modified: 15.8.1997 / 01:00:35 / cg" |
|
605 |
! |
|
606 |
||
771 | 607 |
readStream: aStream loader: aClassLoader loadUnresolved: loadUnresolved |
752 | 608 |
"reads a class from aStream and returns it. |
609 |
The JavaClass is installed as global. |
|
610 |
If new classes are required to be loaded, aClassLoader is |
|
611 |
asked to do it. If aClassLoader is nil, a new standard loader |
|
612 |
is created." |
|
771 | 613 |
|
614 |
| javaClass | |
|
615 |
||
616 |
ClassLoaderQuerySignal answer: aClassLoader |
|
617 |
do: |
|
618 |
[ javaClass := self readStream: aStream ignoring: (Set new). |
|
619 |
javaClass notNil |
|
620 |
ifTrue: |
|
621 |
[ UsedJavaClassReaderClass postLoadActions: loadUnresolved. |
|
622 |
Java at: (javaClass fullName asSymbol) put: javaClass. |
|
623 |
JavaUnresolvedConstant resolveFor: javaClass. ]. ]. |
|
752 | 624 |
^ javaClass |
625 |
||
771 | 626 |
"Created: / 15-08-1997 / 00:59:24 / cg" |
627 |
"Modified: / 23-01-1998 / 17:14:09 / cg" |
|
628 |
"Modified: / 09-05-2011 / 23:15:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
752 | 629 |
! |
630 |
||
631 |
resolveClass:aJavaClass |
|
632 |
"Resolve a particular classes' constants. |
|
633 |
Perform all class initialization functions |
|
634 |
(of those which are not yet initialized)." |
|
635 |
||
636 |
|loader classToLoad| |
|
637 |
||
638 |
LazyClassLoading ifFalse:[ |
|
639 |
loader := (aJavaClass classLoader). "/ ? (ClassLoaderQuerySignal raise). |
|
640 |
||
641 |
[ |
|
642 |
classToLoad := nil. |
|
643 |
aJavaClass constantPool do:[:item | |
|
644 |
|itemClass | |
|
645 |
||
646 |
itemClass := item class. |
|
647 |
itemClass == JavaUnresolvedClassConstant ifTrue:[ |
|
648 |
classToLoad := item className. |
|
649 |
"/ ] ifFalse:[ |
|
650 |
"/ itemClass == JavaUnresolvedMethodrefConstant ifTrue:[ |
|
651 |
"/self halt. |
|
652 |
"/ ] ifFalse:[ |
|
653 |
"/ itemClass == JavaUnresolvedInterfaceMethodrefConstant ifTrue:[ |
|
654 |
"/self halt. |
|
655 |
"/ ] |
|
656 |
"/ ] |
|
657 |
]. |
|
658 |
]. |
|
659 |
||
660 |
classToLoad notNil ifTrue:[ |
|
661 |
loader isNil ifTrue:[ |
|
662 |
self |
|
663 |
loadClassLazy:classToLoad |
|
664 |
ignoring:(Set new). |
|
665 |
] ifFalse:[ |
|
666 |
"/ |
|
667 |
"/ the aquired loader is a javaClassLoader |
|
668 |
"/ which expects an URL as arg. |
|
669 |
"/ |
|
670 |
"/ classURL := Java as_URL:('file:' , nextUnresolved asString , '.class'). |
|
671 |
"/ loader loadClass:classURL |
|
672 |
loader |
|
673 |
perform:#'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
674 |
with:(Java as_String:(classToLoad asString)). |
|
675 |
] |
|
676 |
]. |
|
677 |
classToLoad notNil. |
|
678 |
] whileTrue. |
|
679 |
||
680 |
aJavaClass isInitialized ifFalse:[ |
|
681 |
Silent ifFalse:[ |
|
682 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
683 |
]. |
|
684 |
aJavaClass classInit |
|
685 |
]. |
|
686 |
] |
|
687 |
||
688 |
"Created: / 20.10.1998 / 17:53:22 / cg" |
|
689 |
"Modified: / 20.10.1998 / 17:59:09 / cg" |
|
690 |
! ! |
|
691 |
||
771 | 692 |
!JavaClassReader class methodsFor:'mode setting'! |
693 |
||
694 |
useNewClassReader |
|
695 |
UsedJavaClassReaderClass := JavaClassReader2. |
|
696 |
||
697 |
"Created: / 09-05-2011 / 23:11:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
698 |
! |
|
699 |
||
700 |
useOldClassReader |
|
701 |
UsedJavaClassReaderClass := JavaClassReader. |
|
702 |
||
703 |
"Created: / 09-05-2011 / 23:11:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
704 |
! ! |
|
705 |
||
706 |
!JavaClassReader methodsFor:'* uncategorized *'! |
|
707 |
||
774 | 708 |
updateOwnerInCPItem: each |
709 |
((each isJavaRef and: [ each isNewJavaRef ]) |
|
710 |
or: [ each isJavaNameAndType and: [ each isNewJavaNameAndType ] ]) |
|
771 | 711 |
ifTrue: [ each owner: classBeingRead ]. |
712 |
||
774 | 713 |
"Created: / 12-05-2011 / 17:40:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
771 | 714 |
! ! |
715 |
||
716 |
!JavaClassReader methodsFor:'accessing'! |
|
717 |
||
718 |
constants |
|
719 |
^ constants. |
|
720 |
||
721 |
"Created: / 10-05-2011 / 13:48:30 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
722 |
! |
|
723 |
||
724 |
constants: aJavaConstantPool |
|
725 |
constants := aJavaConstantPool. |
|
726 |
||
727 |
"Created: / 10-05-2011 / 13:48:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
728 |
! |
|
729 |
||
730 |
stream |
|
731 |
^ inStream. |
|
732 |
||
733 |
"Created: / 09-05-2011 / 23:22:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
734 |
! |
|
735 |
||
736 |
stream:aReadStream |
|
737 |
inStream := aReadStream. |
|
738 |
||
739 |
"Created: / 09-05-2011 / 23:23:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
740 |
! ! |
|
741 |
||
752 | 742 |
!JavaClassReader methodsFor:'file reading'! |
743 |
||
771 | 744 |
readClassFileIgnoring: classesbeingLoaded |
752 | 745 |
"reads a class from inStream and returns it. |
746 |
The JavaClass is not installed as global and its constants |
|
747 |
(especially strings) may not be fully resolved." |
|
748 |
||
771 | 749 |
| magic access_flags this_class_index super_class super_class_index realSuperClass this_class_ref existingSuperClass fields interfaces staticFields nStatic jSuperClass loader superClassName thisClassName existing_class thisMetaClass | |
752 | 750 |
|
751 |
"/ |
|
752 |
"/ read magic, determine byte order |
|
753 |
"/ |
|
754 |
msb := true. |
|
771 | 755 |
magic := inStream nextUnsignedLongMSB: true. |
756 |
magic = (self class magic_MSB) |
|
757 |
ifFalse: |
|
758 |
[ magic = (self class magic_LSB) |
|
759 |
ifFalse: |
|
760 |
[ InvalidClassFormatSignal raiseErrorString: 'not a java class file'. |
|
761 |
^ nil ]. |
|
762 |
msb := false. |
|
763 |
Verbose ifTrue: [ Transcript showCR: 'file is lsb' ]. ] |
|
764 |
ifTrue: [ Verbose ifTrue: [ Transcript showCR: 'file is msb' ]. ]. |
|
752 | 765 |
|
766 |
"/ |
|
767 |
"/ get version |
|
768 |
"/ |
|
769 |
||
771 | 770 |
minorVsn := inStream nextUnsignedShortMSB: msb. |
771 |
majorVsn := inStream nextUnsignedShortMSB: msb. |
|
772 |
((self class fileMajorVersions includes: majorVsn) not |
|
773 |
or: [ (self class fileMinorVersions includes: minorVsn) not ]) |
|
774 |
ifTrue: |
|
775 |
[ Transcript |
|
776 |
show: 'warning this file has version '; |
|
777 |
show: majorVsn; |
|
778 |
show: '.'; |
|
779 |
showCR: minorVsn. ]. |
|
780 |
Verbose |
|
781 |
ifTrue: |
|
782 |
[ Transcript |
|
783 |
show: 'version = '; |
|
784 |
show: (majorVsn printString); |
|
785 |
show: '.'; |
|
786 |
showCR: (minorVsn printString). ]. |
|
752 | 787 |
|
788 |
"/ |
|
789 |
"/ get constant pool |
|
790 |
"/ |
|
791 |
||
792 |
self readConstantPool. |
|
793 |
||
794 |
"/ |
|
795 |
"/ access flags |
|
796 |
"/ |
|
797 |
||
771 | 798 |
access_flags := inStream nextUnsignedShortMSB: msb. |
799 |
this_class_index := inStream nextUnsignedShortMSB: msb. |
|
800 |
super_class_index := inStream nextUnsignedShortMSB: msb. |
|
801 |
super_class_index == 0 |
|
802 |
ifTrue: [ super_class := nil ] |
|
803 |
ifFalse: |
|
804 |
[ super_class := constants at: super_class_index. |
|
805 |
superClassName := super_class fullName. |
|
806 |
||
807 |
"/ special for ST-classes |
|
808 |
||
809 |
(superClassName startsWith: 'smalltalk.') |
|
810 |
ifTrue: |
|
811 |
[ "/ a Smalltalk class |
|
812 |
superClassName := superClassName copyFrom: 11. |
|
813 |
existingSuperClass := Smalltalk at: superClassName asSymbol. |
|
814 |
existingSuperClass notNil |
|
815 |
ifTrue: [ super_class := existingSuperClass ] |
|
816 |
ifFalse: |
|
817 |
[ "/ self halt - must load superclass ... |
|
818 |
] ] |
|
819 |
ifFalse: |
|
820 |
[ "/ a JAVA class |
|
821 |
existingSuperClass := Java classNamed: superClassName. |
|
822 |
existingSuperClass notNil |
|
823 |
ifTrue: [ super_class := existingSuperClass ] |
|
824 |
ifFalse: |
|
825 |
[ (super_class isMemberOf: JavaUnresolvedClassConstant) |
|
826 |
ifTrue: |
|
827 |
[ Silent |
|
828 |
ifFalse: |
|
829 |
[ 'load superClass: ' print. |
|
830 |
superClassName printCR. ]. |
|
831 |
loader := ClassLoaderQuerySignal query. |
|
832 |
loader isNil |
|
833 |
ifTrue: |
|
834 |
[ existingSuperClass := self class loadClassLazy: superClassName |
|
835 |
ignoring: classesbeingLoaded. ] |
|
836 |
ifFalse: |
|
837 |
[ jSuperClass := loader |
|
838 |
perform: #'loadClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
839 |
with: (Java as_String: superClassName). |
|
840 |
existingSuperClass := JavaVM reflection |
|
841 |
classForJavaClassObject: jSuperClass. ]. |
|
842 |
existingSuperClass isNil |
|
843 |
ifTrue: |
|
844 |
[ ('JAVA: cannot find superclass: ' , superClassName) infoPrintCR. |
|
845 |
||
846 |
"/ self halt:('cannot find superclass: ' , superClassName). |
|
847 |
||
848 |
^ nil. ]. |
|
849 |
super_class := existingSuperClass ] |
|
850 |
ifFalse: [ self halt: 'oops - superclass ?' ] ]. ]. ]. |
|
752 | 851 |
|
852 |
"/ |
|
853 |
"/ get interfaces |
|
854 |
"/ |
|
855 |
||
856 |
interfaces := self readInterfaces. |
|
857 |
||
858 |
"/ |
|
859 |
"/ get fields |
|
860 |
"/ |
|
861 |
||
862 |
fields := self readFieldInfofields. |
|
863 |
||
864 |
"/ |
|
865 |
"/ create the fields as instVars |
|
866 |
"/ static fields are created as class-InstVars |
|
867 |
"/ |
|
868 |
||
771 | 869 |
staticFields := fields select: [:f | f isStatic ]. |
752 | 870 |
nStatic := staticFields size. |
771 | 871 |
this_class_ref := constants at: this_class_index. |
752 | 872 |
thisClassName := this_class_ref fullName. |
873 |
||
874 |
"/ care for smalltalk classes ... |
|
875 |
||
771 | 876 |
(thisClassName startsWith: 'smalltalk.') |
877 |
ifTrue: |
|
878 |
[ thisClassName := thisClassName copyFrom: 11. |
|
879 |
existing_class := Smalltalk at: thisClassName asSymbol. |
|
880 |
existing_class notNil |
|
881 |
ifTrue: |
|
882 |
[ self halt: ('overloading existing class: ' , thisClassName). |
|
883 |
thisClassName := (thisClassName , '_new') asSymbol. ]. |
|
884 |
thisMetaClass := Metaclass new. |
|
885 |
thisMetaClass setSuperclass: super_class class. |
|
886 |
thisMetaClass instSize: (super_class class instSize + nStatic). |
|
887 |
classBeingRead := thisMetaClass new. |
|
888 |
classBeingRead setSuperclass: super_class. |
|
889 |
classBeingRead setName: thisClassName asSymbol. ] |
|
890 |
ifFalse: |
|
891 |
[ "/ a java class |
|
892 |
classBeingRead := JavaClass fullName: thisClassName numStatic: nStatic. |
|
893 |
nStatic ~~ 0 |
|
894 |
ifTrue: |
|
895 |
[ fields := fields select: [:f | f isStatic not ]. |
|
896 |
JavaClass setInstanceVariableStringFromFields: staticFields |
|
897 |
in: classBeingRead class. |
|
898 |
classBeingRead setStaticFields: staticFields. |
|
899 |
classBeingRead initializeStaticFields. ]. |
|
900 |
classBeingRead setAccessFlags: access_flags. |
|
901 |
classBeingRead setSuperclass: super_class. |
|
902 |
classBeingRead setConstantPool: constants. |
|
903 |
classBeingRead setFields: fields. |
|
904 |
classBeingRead setInterfaces: interfaces. |
|
905 |
constants owner: classBeingRead. ]. |
|
752 | 906 |
|
907 |
"/ |
|
908 |
"/ get methods |
|
909 |
"/ |
|
910 |
||
771 | 911 |
self readMethodsFor: classBeingRead. |
912 |
self readAttributesFor: classBeingRead. |
|
774 | 913 |
classBeingRead constantPool do: [:each | self updateOwnerInCPItem: each ]. |
771 | 914 |
^ classBeingRead. |
752 | 915 |
|
916 |
" |
|
917 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
918 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
919 |
JavaClassReader loadFile:'foo.cls' |
|
920 |
||
921 |
JavaClassReader verbose:true. |
|
922 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/java/lang/ArithmeticException.class' |
|
923 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/ArithmeticException.class'" |
|
924 |
||
925 |
"Created: / 15-04-1996 / 15:02:47 / cg" |
|
926 |
"Modified: / 12-11-1998 / 21:14:45 / cg" |
|
927 |
"Modified: / 15-10-2010 / 17:37:38 / Jan Kurs <kurs.jan@post.cz>" |
|
928 |
"Modified: / 19-10-2010 / 21:43:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
929 |
"Modified: / 28-01-2011 / 15:09:48 / Marcel Hlopko <hlopik@gmail.com>" |
|
774 | 930 |
"Modified: / 12-05-2011 / 17:40:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
752 | 931 |
! |
932 |
||
933 |
readStream:aStream ignoring:classesBeingLoaded |
|
934 |
"reads a class from aStream and returns it. |
|
935 |
The JavaClass is not installed as global" |
|
936 |
||
937 |
inStream := aStream. |
|
938 |
inStream binary. |
|
939 |
||
940 |
^ self readClassFileIgnoring:classesBeingLoaded |
|
941 |
||
942 |
" |
|
943 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
944 |
" |
|
945 |
||
946 |
"Created: 15.4.1996 / 15:00:55 / cg" |
|
947 |
"Modified: 15.4.1996 / 15:06:18 / cg" |
|
948 |
! ! |
|
949 |
||
950 |
!JavaClassReader methodsFor:'file reading - attributes'! |
|
951 |
||
952 |
readAnnotationDefaultAttributeFor:something |
|
953 |
"/ ('JAVA [info]: unhandled attribute: AnnotationDefault') infoPrintCR. |
|
954 |
||
955 |
|len startPos endPos annotationDefault| |
|
956 |
||
957 |
self assert:something isJavaMethod |
|
958 |
description:'AnnotationDefault may only occure for methods!!'. |
|
959 |
len := inStream nextUnsignedLongMSB:msb. |
|
960 |
startPos := inStream position. |
|
961 |
annotationDefault := (something ensureHasAnnotations) |
|
962 |
default:(JavaAnnotationDefault new |
|
963 |
value:(self readAnnotationValueFor:something)); |
|
964 |
default. |
|
965 |
endPos := inStream position. |
|
966 |
inStream position:startPos. |
|
967 |
annotationDefault bytes:(inStream next:len). |
|
968 |
self assert:inStream position = endPos |
|
969 |
description:'self readAnnotationValueFor: something is reading what it shouldn'. |
|
970 |
||
971 |
"Modified: / 28-02-2011 / 17:08:28 / Marcel Hlopko <hlopik@gmail.com>" |
|
972 |
"Modified: / 03-03-2011 / 23:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
973 |
! |
|
974 |
||
975 |
readAnnotationFor:something |
|
976 |
| typeIndex type result attrsCount | |
|
977 |
||
978 |
typeIndex := inStream nextUnsignedShortMSB:msb. |
|
979 |
type := something constantPool at:typeIndex. |
|
980 |
attrsCount := inStream nextUnsignedShortMSB:msb. |
|
981 |
result := JavaAnnotation for:something. |
|
982 |
result name:type. |
|
983 |
attrsCount timesRepeat: |
|
984 |
[ | nameIndex name valueIndex attr | |
|
985 |
||
986 |
nameIndex := inStream nextUnsignedShortMSB:msb. |
|
987 |
name := something constantPool at:nameIndex. |
|
988 |
attr := self readAnnotationValueFor:something. |
|
989 |
attr name:name. |
|
990 |
result values at:attr name put:attr. |
|
991 |
AnnotationsVerbose |
|
992 |
ifTrue:[ ('JAVA [INFO]: Reading annotation attribute: ' , name) infoPrintCR. ]. ]. |
|
993 |
^ result. |
|
994 |
||
995 |
"Created: / 17-12-2010 / 16:21:28 / Marcel Hlopko <hlopik@gmail.com>" |
|
996 |
"Modified: / 25-02-2011 / 12:25:36 / Marcel Hlopko <hlopik@gmail.com>" |
|
997 |
! |
|
998 |
||
999 |
readAnnotationValueFor:something |
|
1000 |
| tag result | |
|
1001 |
||
1002 |
tag := (inStream nextByte) asCharacter. |
|
1003 |
tag = $e |
|
1004 |
ifTrue: |
|
1005 |
[ result := JavaAnnotationEnumValue for:something. |
|
1006 |
result nameIndex:(inStream nextUnsignedShortMSB:msb). |
|
1007 |
result valueIndex:(inStream nextUnsignedShortMSB:msb). |
|
1008 |
AnnotationsVerbose |
|
1009 |
ifTrue: |
|
1010 |
[ ('JAVA [INFO]: Reading annotation enum value: ' , result name printString, ' -> ' |
|
1011 |
, result value printString) infoPrintCR ]. |
|
1012 |
^ result ]. |
|
1013 |
tag = $c |
|
1014 |
ifTrue: |
|
1015 |
[ result := JavaAnnotationClassValue for:something. |
|
1016 |
result classIndex:(inStream nextUnsignedShortMSB:msb). |
|
1017 |
AnnotationsVerbose |
|
1018 |
ifTrue: |
|
1019 |
[ ('JAVA [INFO]: Reading annotation class value: ' , result name printString, ' -> ' |
|
1020 |
, result value printString) infoPrintCR ]. |
|
1021 |
^ result ]. |
|
1022 |
tag = $@ |
|
1023 |
ifTrue: |
|
1024 |
[ result := JavaAnnotationNestedAnnotationValue for:something. |
|
1025 |
result classIndex:(inStream nextUnsignedShortMSB:msb). |
|
1026 |
AnnotationsVerbose |
|
1027 |
ifTrue: |
|
1028 |
[ ('JAVA [INFO]: Reading annotation nested annotation value: ' , result name printString |
|
1029 |
, ' -> ' , result value printString) |
|
1030 |
infoPrintCR ]. |
|
1031 |
^ result ]. |
|
1032 |
tag = $[ |
|
1033 |
ifTrue: |
|
1034 |
[ result := JavaAnnotationArrayValue for:something. |
|
1035 |
result count:(inStream nextUnsignedShortMSB:msb). |
|
1036 |
AnnotationsVerbose |
|
1037 |
ifTrue:[ ('JAVA [INFO]: Reading annotation array value') infoPrintCR ]. |
|
1038 |
1 to:result count |
|
1039 |
do:[:index | result values at:index put:(self readAnnotationValueFor:something) ]. |
|
1040 |
AnnotationsVerbose |
|
1041 |
ifTrue: |
|
1042 |
[ ('JAVA [INFO]: Finished reading annotation array value: ' |
|
1043 |
, result value printString) infoPrintCR ]. |
|
1044 |
^ result ]. |
|
1045 |
result := JavaAnnotationPrimitiveValue for:something. |
|
1046 |
result valueIndex:(inStream nextUnsignedShortMSB:msb). |
|
1047 |
AnnotationsVerbose |
|
1048 |
ifTrue: |
|
1049 |
[ ('JAVA [INFO]: Finished reading annotation primitive value: ' |
|
1050 |
, result name printString , ' -> ' , result value printString) infoPrintCR ]. |
|
1051 |
^ result. |
|
1052 |
||
1053 |
"Created: / 17-12-2010 / 16:44:14 / Marcel Hlopko <hlopik@gmail.com>" |
|
1054 |
"Modified: / 28-02-2011 / 16:12:09 / Marcel Hlopko <hlopik@gmail.com>" |
|
1055 |
! |
|
1056 |
||
1057 |
readAttribute:attributeName for:something |
|
1058 |
"/ implemented JAVA attributes |
|
1059 |
||
1060 |
(attributeName = 'ConstantValue') |
|
1061 |
ifTrue: |
|
1062 |
[ self readConstantValueAttributeFor:something. |
|
1063 |
^ self. ]. |
|
1064 |
(attributeName = 'Code') |
|
1065 |
ifTrue: |
|
1066 |
[ self readCodeAttributeFor:something. |
|
1067 |
^ self. ]. |
|
1068 |
(attributeName = 'Exceptions') |
|
1069 |
ifTrue: |
|
1070 |
[ self readExceptionsAttributeFor:something. |
|
1071 |
^ self. ]. |
|
1072 |
(attributeName = 'InnerClasses') |
|
1073 |
ifTrue: |
|
1074 |
[ self readInnerClassesAttributeFor:something. |
|
1075 |
^ self. ]. |
|
1076 |
(attributeName = 'EnclosingMethod') |
|
1077 |
ifTrue: |
|
1078 |
[ self readEnclosingMethodAttributeFor:something. |
|
1079 |
^ self. ]. |
|
1080 |
(attributeName = 'LineNumberTable') |
|
1081 |
ifTrue: |
|
1082 |
[ self readLineNumberTableAttributeFor:something. |
|
1083 |
^ self. ]. |
|
1084 |
(attributeName = 'LocalVariableTable') |
|
1085 |
ifTrue: |
|
1086 |
[ self readLocalVariableTableAttributeFor:something. |
|
1087 |
^ self. ]. |
|
1088 |
(attributeName = 'LocalVariableTypeTable') |
|
1089 |
ifTrue: |
|
1090 |
[ self readLocalVariableTypeTableAttributeFor:something. |
|
1091 |
^ self. ]. |
|
1092 |
(attributeName = 'SourceFile') |
|
1093 |
ifTrue: |
|
1094 |
[ self readSourceFileAttributeFor:something. |
|
1095 |
^ self. ]. |
|
1096 |
(attributeName = 'SourceDebugExtension') |
|
1097 |
ifTrue: |
|
1098 |
[ self readSourceDebugExtensionAttributeFor:something. |
|
1099 |
^ self. ]. |
|
1100 |
(attributeName = 'Synthetic') |
|
1101 |
ifTrue: |
|
1102 |
[ self readSyntheticAttributeFor:something. |
|
1103 |
^ self. ]. |
|
1104 |
(attributeName = 'Signature') |
|
1105 |
ifTrue: |
|
1106 |
[ self readSignatureAttributeFor:something. |
|
1107 |
^ self. ]. |
|
1108 |
(attributeName = 'Deprecated') |
|
1109 |
ifTrue: |
|
1110 |
[ self readDeprecatedAttributeFor:something. |
|
1111 |
^ self. ]. |
|
1112 |
(attributeName = 'RuntimeVisibleAnnotations') |
|
1113 |
ifTrue: |
|
1114 |
[ self readRuntimeAnnotationsAttributeFor:something visible:true. |
|
1115 |
^ self. ]. |
|
1116 |
(attributeName = 'RuntimeInvisibleAnnotations') |
|
1117 |
ifTrue: |
|
1118 |
[ self readRuntimeAnnotationsAttributeFor:something visible:false. |
|
1119 |
^ self. ]. |
|
1120 |
(attributeName = 'RuntimeVisibleParameterAnnotations') |
|
1121 |
ifTrue: |
|
1122 |
[ self readRuntimeParameterAnnotationsAttributeFor:something visible:true. |
|
1123 |
^ self. ]. |
|
1124 |
(attributeName = 'RuntimeInvisibleParameterAnnotations') |
|
1125 |
ifTrue: |
|
1126 |
[ self readRuntimeParameterAnnotationsAttributeFor:something visible:false. |
|
1127 |
^ self. ]. |
|
1128 |
(attributeName = 'AnnotationDefault') |
|
1129 |
ifTrue: |
|
1130 |
[ self readAnnotationDefaultAttributeFor:something. |
|
1131 |
^ self. ]. |
|
1132 |
||
1133 |
"/ ignored JAVA attributes |
|
1134 |
||
1135 |
(attributeName = 'FastJavac1.0') |
|
1136 |
ifTrue: |
|
1137 |
[ "/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1138 |
self skipAttribute:attributeName. |
|
1139 |
^ self. ]. |
|
1140 |
(attributeName = 'AbsoluteSourcePath') |
|
1141 |
ifTrue: |
|
1142 |
[ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1143 |
self skipAttribute:attributeName. |
|
1144 |
^ self. ]. |
|
1145 |
(attributeName startsWith:((Character value:13) asString , 'WARNING:')) |
|
1146 |
ifTrue: |
|
1147 |
[ "/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1148 |
self skipAttribute:attributeName. |
|
1149 |
^ self. ]. |
|
1150 |
(attributeName = 'StackMapTable') |
|
1151 |
ifTrue: |
|
1152 |
[ "/ ('JAVA [info]: unhandled attribute: ' , attributeName) infoPrintCR. |
|
1153 |
self readStackMapTableAttributeFor:something. |
|
1154 |
^ self. ]. |
|
1155 |
||
1156 |
"/ implemented ST attributes |
|
1157 |
||
1158 |
(attributeName = 'STLiterals') |
|
1159 |
ifTrue: |
|
1160 |
[ self readSTLiteralsAttributeFor:something. |
|
1161 |
^ self. ]. |
|
1162 |
(attributeName = 'ClassRevision') |
|
1163 |
ifTrue: |
|
1164 |
[ self readSTClassRevisionAttributeFor:something. |
|
1165 |
^ self. ]. |
|
1166 |
(attributeName = 'ClassPackage') |
|
1167 |
ifTrue: |
|
1168 |
[ self readSTClassPackageAttributeFor:something. |
|
1169 |
^ self. ]. |
|
1170 |
(attributeName = 'ClassCategory') |
|
1171 |
ifTrue: |
|
1172 |
[ self readSTClassCategoryAttributeFor:something. |
|
1173 |
^ self. ]. |
|
1174 |
(attributeName = 'ClassVarNames') |
|
1175 |
ifTrue: |
|
1176 |
[ self readSTClassVarNamesAttributeFor:something. |
|
1177 |
^ self. ]. |
|
1178 |
(attributeName = 'ClassInstVarNames') |
|
1179 |
ifTrue: |
|
1180 |
[ self readSTClassInstVarNamesAttributeFor:something. |
|
1181 |
^ self. ]. |
|
1182 |
(attributeName = 'InstVarNames') |
|
1183 |
ifTrue: |
|
1184 |
[ self readSTInstVarNamesAttributeFor:something. |
|
1185 |
^ self. ]. |
|
1186 |
(attributeName = 'STCode') |
|
1187 |
ifTrue: |
|
1188 |
[ self readSTCodeAttributeFor:something. |
|
1189 |
^ self. ]. |
|
1190 |
(attributeName = 'MethodCategory') |
|
1191 |
ifTrue: |
|
1192 |
[ self readSTMethodCategoryAttributeFor:something. |
|
1193 |
^ self. ]. |
|
1194 |
||
1195 |
"/ unknown attributes |
|
1196 |
||
1197 |
('JAVA [warning]: unrecognized attribute: ' , attributeName) infoPrintCR. |
|
1198 |
self skipAttribute:attributeName. |
|
1199 |
||
1200 |
"Modified: / 03-12-1998 / 13:13:42 / cg" |
|
1201 |
"Modified: / 25-02-2011 / 18:09:21 / Marcel Hlopko <hlopik@gmail.com>" |
|
1202 |
! |
|
1203 |
||
1204 |
readAttributeFor:something |
|
1205 |
|attribute_name_index attribute_name attribute_length attribute_info| |
|
1206 |
||
1207 |
Verbose ifTrue:[Transcript show:'attrib at pos: '; showCR:inStream position]. |
|
1208 |
||
1209 |
attribute_name_index := inStream nextUnsignedShortMSB:msb. |
|
1210 |
attribute_name_index == 0 ifTrue:[ |
|
1211 |
self halt. |
|
1212 |
"/self skipAttribute:'unnamed'. |
|
1213 |
^ self. |
|
1214 |
]. |
|
1215 |
||
1216 |
"/ |
|
1217 |
"/ UNDOC feature ? |
|
1218 |
"/ |
|
1219 |
attribute_name_index > constants size ifTrue:[ |
|
1220 |
attribute_name_index == 16rb700 ifTrue:[ |
|
1221 |
self halt. |
|
1222 |
] |
|
1223 |
]. |
|
1224 |
||
1225 |
attribute_name := constants at:attribute_name_index. |
|
1226 |
||
1227 |
Verbose ifTrue:[Transcript show:'attrib name: '; showCR:attribute_name]. |
|
1228 |
||
1229 |
self readAttribute:attribute_name for:something. |
|
1230 |
||
1231 |
" |
|
1232 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1233 |
" |
|
1234 |
||
1235 |
"Created: / 15-04-1996 / 15:40:17 / cg" |
|
1236 |
"Modified: / 09-04-1998 / 18:13:34 / cg" |
|
1237 |
"Modified: / 19-10-2010 / 21:43:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1238 |
! |
|
1239 |
||
1240 |
readAttributesFor:something |
|
1241 |
|attributes_count| |
|
1242 |
||
1243 |
attributes_count := inStream nextUnsignedShortMSB:msb. |
|
1244 |
||
1245 |
1 to:attributes_count do:[:i | |
|
1246 |
self readAttributeFor:something. |
|
1247 |
]. |
|
1248 |
||
1249 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1250 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1251 |
! |
|
1252 |
||
1253 |
readDeprecatedAttributeFor:aJavaMethodWithHandler |
|
1254 |
||
1255 |
self skipAttribute:'Deprecated'. |
|
1256 |
^self |
|
1257 |
||
1258 |
"Created: / 18-10-2010 / 22:26:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1259 |
! |
|
1260 |
||
1261 |
readEnclosingMethodAttributeFor:something |
|
1262 |
"/ ('JAVA [info]: unhandled attribute: EnclosingMethod') infoPrintCR. |
|
1263 |
self skipAttribute:'EnclosingMethod'. |
|
1264 |
! |
|
1265 |
||
1266 |
readInnerClassesAttributeFor:something |
|
1267 |
"/ ('JAVA [info]: unhandled attribute: InnerClasses') infoPrintCR. |
|
1268 |
self skipAttribute:'InnerClasses'. |
|
1269 |
! |
|
1270 |
||
1271 |
readLocalVariableTypeTableAttributeFor:something |
|
1272 |
"/ ('JAVA [info]: unhandled attribute: LocalVariableTypeTable') infoPrintCR. |
|
1273 |
self skipAttribute:'LocalVariableTypeTable'. |
|
1274 |
! |
|
1275 |
||
1276 |
readRuntimeAnnotationsAttributeFor: something visible: visible |
|
1277 |
| length annotationsCount annotations rawAnnotations startPos endPos | |
|
1278 |
||
1279 |
self assert: inStream isPositionable |
|
1280 |
message: '.class file stream must be positionable'. |
|
1281 |
length := inStream nextUnsignedLongMSB: msb. |
|
1282 |
startPos := inStream position. |
|
1283 |
annotationsCount := inStream nextUnsignedShortMSB: msb. |
|
1284 |
annotationsCount = 0 ifTrue: [ ^ nil ]. |
|
1285 |
annotations := visible ifTrue: [something ensureHasAnnotations ensureRuntimeVisible] ifFalse: [something ensureHasAnnotations ensureRuntimeInvisible]. |
|
1286 |
annotationsCount timesRepeat: |
|
1287 |
[ | currentAnnotation | |
|
1288 |
||
1289 |
currentAnnotation := self readAnnotationFor: something. |
|
1290 |
annotations at: currentAnnotation name put: currentAnnotation. ]. |
|
1291 |
"Cut raw annotations as required by getRawAnnotations()" |
|
1292 |
endPos := inStream position. |
|
1293 |
inStream position: startPos. |
|
1294 |
rawAnnotations := inStream next: length. |
|
1295 |
inStream position ~= endPos |
|
1296 |
ifTrue: [ self halt: 'annotations are probably reading what they shouldnt' ]. |
|
1297 |
annotations rawAnnotations: rawAnnotations. |
|
1298 |
||
1299 |
"Modified: / 07-01-2011 / 22:00:07 / Jan Kurs <kurs.jan@post.cz>" |
|
1300 |
"Modified: / 25-02-2011 / 18:45:58 / Marcel Hlopko <hlopik@gmail.com>" |
|
1301 |
"Modified: / 03-03-2011 / 23:01:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1302 |
"Modified: / 16-03-2011 / 16:57:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1303 |
! |
|
1304 |
||
1305 |
readRuntimeParameterAnnotationsAttributeFor: javaMethod visible: visible |
|
1306 |
| length paramsCount annotationsCount rawAnnotations startPos endPos | |
|
1307 |
||
1308 |
self assert: inStream isPositionable |
|
1309 |
message: '.class file stream must be positionable'. |
|
1310 |
length := inStream nextUnsignedLongMSB: msb. |
|
1311 |
startPos := inStream position. |
|
1312 |
paramsCount := inStream nextByte. |
|
1313 |
paramsCount = 0 ifTrue: [ ^ nil ]. |
|
1314 |
1 to: paramsCount |
|
1315 |
do: |
|
1316 |
[:paramIndex | |
|
1317 |
annotationsCount := inStream nextUnsignedShortMSB: msb. |
|
1318 |
annotationsCount > 0 |
|
1319 |
ifTrue: |
|
1320 |
[ | annotations | |
|
1321 |
annotations := visible |
|
1322 |
ifTrue: |
|
1323 |
[ javaMethod ensureHasAnnotations ensureVisibleParameterAnnotationsAt: paramIndex ] |
|
1324 |
ifFalse: |
|
1325 |
[javaMethod ensureHasAnnotations ensureInvisibleParameterAnnotationsAt: paramIndex ]. |
|
1326 |
annotationsCount timesRepeat: |
|
1327 |
[ | annotation | |
|
1328 |
||
1329 |
annotation := self readAnnotationFor: javaMethod. |
|
1330 |
annotations at: (annotation name) put: annotation. ] ]]. |
|
1331 |
endPos := inStream position. |
|
1332 |
rawAnnotations := inStream position: startPos. |
|
1333 |
rawAnnotations := inStream next: length. |
|
1334 |
inStream position ~= endPos |
|
1335 |
ifTrue: [ self halt: 'annotations are probably reading what they shouldnt' ]. |
|
1336 |
javaMethod annotations rawAnnotations: rawAnnotations. |
|
1337 |
||
1338 |
"Modified: / 28-02-2011 / 17:05:47 / Marcel Hlopko <hlopik@gmail.com>" |
|
1339 |
"Modified: / 16-03-2011 / 17:26:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
1340 |
! |
|
1341 |
||
1342 |
readSignatureAttributeFor:something |
|
1343 |
"/ ('JAVA [info]: unhandled attribute: Signature') infoPrintCR. |
|
1344 |
self skipAttribute:'Signature'. |
|
1345 |
! |
|
1346 |
||
1347 |
readSourceDebugExtensionAttributeFor:something |
|
1348 |
"/ ('JAVA [info]: unhandled attribute: SourceDebugExtension') infoPrintCR. |
|
1349 |
self skipAttribute:'SourceDebugExtension'. |
|
1350 |
! |
|
1351 |
||
1352 |
readSourceFileAttributeFor:aClass |
|
1353 |
|attribute_length sourceFile_index sourceFile| |
|
1354 |
||
1355 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1356 |
||
1357 |
sourceFile_index := inStream nextUnsignedShortMSB:msb. |
|
1358 |
sourceFile := constants at:sourceFile_index. |
|
1359 |
||
1360 |
aClass isJavaClass ifTrue:[ |
|
1361 |
aClass setSourceFile:sourceFile. |
|
1362 |
] ifFalse:[ |
|
1363 |
aClass setClassFilename:sourceFile |
|
1364 |
]. |
|
1365 |
||
1366 |
Verbose ifTrue:[Transcript show:'sourceFile: '; showCR:sourceFile]. |
|
1367 |
^ true |
|
1368 |
||
1369 |
" |
|
1370 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1371 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1372 |
JavaClassReader loadFile:'foo.cls' |
|
1373 |
" |
|
1374 |
||
1375 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
|
1376 |
"Modified: / 12.5.1998 / 22:01:07 / cg" |
|
1377 |
! |
|
1378 |
||
1379 |
readStackMapTableAttributeFor:something |
|
1380 |
"/ ('JAVA [info]: unhandled attribute: StackMapTable') infoPrintCR. |
|
1381 |
self skipAttribute:'StackMapTable'. |
|
1382 |
||
1383 |
"Created: / 09-02-2011 / 01:19:20 / Marcel Hlopko <hlopik@gmail.com>" |
|
1384 |
! |
|
1385 |
||
1386 |
readSyntheticAttributeFor:something |
|
1387 |
"/ ('JAVA [info]: unhandled attribute: Synthetic') infoPrintCR. |
|
1388 |
self skipAttribute:'Synthetic'. |
|
1389 |
! |
|
1390 |
||
1391 |
skipAttribute:attributeName |
|
1392 |
"dont know about this attribute - skip it here" |
|
1393 |
||
1394 |
|attribute_length attribute_info| |
|
1395 |
||
1396 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1397 |
attribute_info := ByteArray new:(attribute_length). |
|
1398 |
inStream nextBytes:attribute_length into:attribute_info startingAt:1. |
|
1399 |
||
1400 |
Verbose ifTrue:[Transcript show:'skipped '; show:attributeName; showCR:'-attribute']. |
|
1401 |
||
1402 |
"Created: / 9.4.1998 / 18:12:46 / cg" |
|
1403 |
"Modified: / 9.4.1998 / 18:13:20 / cg" |
|
1404 |
! ! |
|
1405 |
||
1406 |
!JavaClassReader methodsFor:'file reading - attributes-ST'! |
|
1407 |
||
1408 |
readSTClassCategoryAttributeFor:aClass |
|
1409 |
|attribute_length categoryString_index categoryString| |
|
1410 |
||
1411 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1412 |
||
1413 |
categoryString_index := inStream nextUnsignedShortMSB:msb. |
|
1414 |
categoryString := constants at:categoryString_index. |
|
1415 |
||
1416 |
aClass category:categoryString. |
|
1417 |
||
1418 |
Verbose ifTrue:[Transcript show:'categoryString: '; showCR:categoryString]. |
|
1419 |
^ true |
|
1420 |
||
1421 |
" |
|
1422 |
JavaClassReader loadFile:'foo.cls' |
|
1423 |
" |
|
1424 |
||
1425 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1426 |
"Modified: / 9.5.1998 / 02:36:55 / cg" |
|
1427 |
! |
|
1428 |
||
1429 |
readSTClassInstVarNamesAttributeFor:aClass |
|
1430 |
|attribute_length nameString_index nameString| |
|
1431 |
||
1432 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1433 |
||
1434 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1435 |
nameString := constants at:nameString_index. |
|
1436 |
||
1437 |
aClass class instanceVariableString:nameString. |
|
1438 |
||
1439 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1440 |
^ true |
|
1441 |
||
1442 |
" |
|
1443 |
JavaClassReader loadFile:'foo.cls' |
|
1444 |
" |
|
1445 |
||
1446 |
"Modified: / 12.5.1998 / 22:18:03 / cg" |
|
1447 |
"Created: / 12.5.1998 / 22:18:24 / cg" |
|
1448 |
! |
|
1449 |
||
1450 |
readSTClassPackageAttributeFor:aClass |
|
1451 |
|attribute_length packageString_index packageString| |
|
1452 |
||
1453 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1454 |
||
1455 |
packageString_index := inStream nextUnsignedShortMSB:msb. |
|
1456 |
packageString := constants at:packageString_index. |
|
1457 |
||
1458 |
aClass package:packageString asSymbol. |
|
1459 |
||
1460 |
Verbose ifTrue:[Transcript show:'packageString: '; showCR:packageString]. |
|
1461 |
^ true |
|
1462 |
||
1463 |
" |
|
1464 |
JavaClassReader loadFile:'foo.cls' |
|
1465 |
" |
|
1466 |
||
1467 |
"Modified: / 9.5.1998 / 02:32:38 / cg" |
|
1468 |
"Created: / 9.5.1998 / 02:33:44 / cg" |
|
1469 |
! |
|
1470 |
||
1471 |
readSTClassRevisionAttributeFor:aClass |
|
1472 |
|attribute_length revisionString_index revisionString| |
|
1473 |
||
1474 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1475 |
||
1476 |
revisionString_index := inStream nextUnsignedShortMSB:msb. |
|
1477 |
revisionString := constants at:revisionString_index. |
|
1478 |
||
1479 |
aClass setBinaryRevision:revisionString. |
|
1480 |
||
1481 |
Verbose ifTrue:[Transcript show:'revisionString: '; showCR:revisionString]. |
|
1482 |
^ true |
|
1483 |
||
1484 |
" |
|
1485 |
JavaClassReader loadFile:'foo.cls' |
|
1486 |
" |
|
1487 |
||
1488 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1489 |
"Modified: / 9.5.1998 / 02:35:01 / cg" |
|
1490 |
! |
|
1491 |
||
1492 |
readSTClassVarNamesAttributeFor:aClass |
|
1493 |
|attribute_length nameString_index nameString| |
|
1494 |
||
1495 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1496 |
||
1497 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1498 |
nameString := constants at:nameString_index. |
|
1499 |
||
1500 |
aClass classVariableString:nameString. |
|
1501 |
||
1502 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1503 |
^ true |
|
1504 |
||
1505 |
" |
|
1506 |
JavaClassReader loadFile:'foo.cls' |
|
1507 |
" |
|
1508 |
||
1509 |
"Created: / 9.5.1998 / 02:33:13 / cg" |
|
1510 |
"Modified: / 12.5.1998 / 22:18:03 / cg" |
|
1511 |
! |
|
1512 |
||
1513 |
readSTInstVarNamesAttributeFor:aClass |
|
1514 |
|attribute_length nameString_index nameString| |
|
1515 |
||
1516 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
1517 |
||
1518 |
nameString_index := inStream nextUnsignedShortMSB:msb. |
|
1519 |
nameString := constants at:nameString_index. |
|
1520 |
||
1521 |
aClass setInstanceVariableString:nameString. |
|
1522 |
||
1523 |
Verbose ifTrue:[Transcript show:'nameString: '; showCR:nameString]. |
|
1524 |
^ true |
|
1525 |
||
1526 |
" |
|
1527 |
JavaClassReader loadFile:'foo.cls' |
|
1528 |
" |
|
1529 |
||
1530 |
"Created: / 12.5.1998 / 22:18:14 / cg" |
|
1531 |
"Modified: / 12.5.1998 / 22:21:10 / cg" |
|
1532 |
! ! |
|
1533 |
||
1534 |
!JavaClassReader methodsFor:'file reading - constants'! |
|
1535 |
||
1536 |
readConstant |
|
1537 |
|tag constReader const| |
|
1538 |
||
1539 |
||
1540 |
constNeeds2Slots := false. |
|
1541 |
||
1542 |
"/ |
|
1543 |
"/ get tag |
|
1544 |
"/ |
|
1545 |
tag := inStream nextByte. |
|
1546 |
Verbose ifTrue:[Transcript show:'tag = '; showCR:tag]. |
|
1547 |
||
1548 |
tag >= 250 ifTrue:[ |
|
1549 |
constReader := #( |
|
1550 |
"/ ST types |
|
1551 |
readConstant_ST_Large "/ 249 |
|
1552 |
readConstant_ST_Special "/ 250 |
|
1553 |
readConstant_ST_Character "/ 251 |
|
1554 |
readConstant_ST_ByteArray "/ 252 |
|
1555 |
readConstant_ST_Array "/ 253 |
|
1556 |
readConstant_ST_Symbol "/ 254 |
|
1557 |
readConstant_ST_Reserved "/ 255 |
|
1558 |
) at:tag-249+1. |
|
1559 |
] ifFalse:[ |
|
1560 |
constReader := #( |
|
1561 |
"/ JAVA types |
|
1562 |
readConstant_Utf8 "/ 1 - now called Utf8 |
|
1563 |
readConstant_Unicode "/ 2 |
|
1564 |
readConstant_Integer "/ 3 |
|
1565 |
readConstant_Float "/ 4 |
|
1566 |
readConstant_Long "/ 5 |
|
1567 |
readConstant_Double "/ 6 |
|
1568 |
readConstant_Class "/ 7 |
|
1569 |
readConstant_String "/ 8 |
|
1570 |
readConstant_Fieldref "/ 9 |
|
1571 |
readConstant_Methodref "/ 10 |
|
1572 |
readConstant_InterfaceMethodref "/ 11 |
|
1573 |
readConstant_NameAndType "/ 12 |
|
1574 |
) at:tag ifAbsent:[#readConstant_Undef]. |
|
1575 |
]. |
|
1576 |
^ self perform:constReader. |
|
1577 |
||
1578 |
" |
|
1579 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1580 |
" |
|
1581 |
||
1582 |
"Created: / 15.4.1996 / 15:46:32 / cg" |
|
1583 |
"Modified: / 9.5.1998 / 01:26:05 / cg" |
|
1584 |
! |
|
1585 |
||
1586 |
readConstantPool |
|
1587 |
|constantPoolCount const i| |
|
1588 |
||
1589 |
"/ |
|
1590 |
"/ get constant pool |
|
1591 |
"/ |
|
1592 |
constantPoolCount := inStream nextUnsignedShortMSB:msb. |
|
1593 |
Verbose ifTrue:[Transcript show:'constantPoolCount = '; showCR:constantPoolCount]. |
|
1594 |
||
1595 |
constants := JavaConstantPool "Array" new:constantPoolCount-1. |
|
1596 |
||
1597 |
constSlot := 1. |
|
1598 |
[constSlot < constantPoolCount] whileTrue:[ |
|
1599 |
Verbose ifTrue:[Transcript show:'const: '; showCR:constSlot]. |
|
1600 |
const := self readConstant. |
|
1601 |
constants at:constSlot put:const. |
|
1602 |
||
1603 |
"/ long & double consts take 2 slots |
|
1604 |
"/ (only first is used) |
|
1605 |
constNeeds2Slots ifTrue:[ |
|
1606 |
constSlot := constSlot + 2. |
|
1607 |
] ifFalse:[ |
|
1608 |
constSlot := constSlot + 1. |
|
1609 |
] |
|
1610 |
]. |
|
1611 |
||
1612 |
constSlot := -1. |
|
1613 |
||
1614 |
"/ preresolve what can be (especially, strings are resolved here) |
|
1615 |
||
1616 |
1 to:constantPoolCount-1 do:[:i | |
|
1617 |
|const value| |
|
1618 |
||
1619 |
const := constants at:i. |
|
1620 |
const notNil ifTrue:[ "/ kludge for 2-slot constants (which only take 1 slot in ST/X) |
|
1621 |
(const isKindOf:JavaUnresolvedConstant) ifTrue:[ |
|
1622 |
value := const preResolve. |
|
1623 |
value ~~ const ifTrue:[ |
|
1624 |
constants at:i put:value. |
|
1625 |
] |
|
1626 |
] |
|
1627 |
] |
|
1628 |
]. |
|
1629 |
||
1630 |
" |
|
1631 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1632 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1633 |
" |
|
1634 |
||
1635 |
"Created: / 15.4.1996 / 15:14:11 / cg" |
|
1636 |
"Modified: / 7.5.1998 / 11:44:06 / cg" |
|
1637 |
! |
|
1638 |
||
1639 |
readConstant_Asciz |
|
1640 |
|len string| |
|
1641 |
||
1642 |
len := inStream nextUnsignedShortMSB:msb. |
|
1643 |
string := String new:len. |
|
1644 |
inStream nextBytes:len into:string startingAt:1. |
|
1645 |
||
1646 |
Verbose ifTrue:[Transcript show:'asciz; string= '; showCR:string]. |
|
1647 |
||
1648 |
^ string |
|
1649 |
||
1650 |
" |
|
1651 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1652 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1653 |
" |
|
1654 |
||
1655 |
"Created: 15.4.1996 / 15:15:35 / cg" |
|
1656 |
"Modified: 15.4.1996 / 16:33:45 / cg" |
|
1657 |
! |
|
1658 |
||
1659 |
readConstant_Class |
|
1660 |
|name_index name| |
|
1661 |
||
1662 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
1663 |
||
1664 |
Verbose ifTrue:[Transcript show:'class; index= '; showCR:name_index]. |
|
1665 |
||
1666 |
name := constants at:name_index. |
|
1667 |
name notNil ifTrue:[ |
|
1668 |
Verbose ifTrue:[Transcript showCR:'name in constant_class already resolved']. |
|
1669 |
"/ self halt |
|
1670 |
]. |
|
1671 |
||
1672 |
^ JavaUnresolvedClassConstant |
|
1673 |
pool:constants |
|
1674 |
poolIndex:constSlot |
|
1675 |
nameIndex:name_index |
|
1676 |
||
1677 |
" |
|
1678 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1679 |
" |
|
1680 |
||
1681 |
"Created: / 15.4.1996 / 15:21:13 / cg" |
|
1682 |
"Modified: / 8.5.1998 / 21:53:16 / cg" |
|
1683 |
! |
|
1684 |
||
1685 |
readConstant_Double |
|
1686 |
|high low aFloat bytes| |
|
1687 |
||
1688 |
"/ new code - to be tested |
|
1689 |
"/ bytes := ByteArray new:8. |
|
1690 |
"/ |
|
1691 |
"/ inStream nextBytes:8 into:bytes startingAt:1. |
|
1692 |
"/ msb ~~ UninterpretedBytes isBigEndian ifTrue:[ |
|
1693 |
"/ bytes reverse |
|
1694 |
"/ ]. |
|
1695 |
"/ aFloat := bytes doubleAt:1. |
|
1696 |
||
1697 |
"/ old code |
|
1698 |
||
1699 |
high := inStream nextUnsignedLongMSB:msb. |
|
1700 |
low := inStream nextUnsignedLongMSB:msb. |
|
1701 |
||
1702 |
aFloat := Float new. |
|
1703 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
1704 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
|
1705 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
1706 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
1707 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
1708 |
aFloat basicAt:5 put:((low bitShift:-24) bitAnd:16rFF). |
|
1709 |
aFloat basicAt:6 put:((low bitShift:-16) bitAnd:16rFF). |
|
1710 |
aFloat basicAt:7 put:((low bitShift:-8) bitAnd:16rFF). |
|
1711 |
aFloat basicAt:8 put:(low bitAnd:16rFF). |
|
1712 |
] ifFalse:[ |
|
1713 |
aFloat basicAt:1 put:(low bitAnd:16rFF). |
|
1714 |
aFloat basicAt:2 put:((low bitShift:-8) bitAnd:16rFF). |
|
1715 |
aFloat basicAt:3 put:((low bitShift:-16) bitAnd:16rFF). |
|
1716 |
aFloat basicAt:4 put:((low bitShift:-24) bitAnd:16rFF). |
|
1717 |
aFloat basicAt:5 put:(high bitAnd:16rFF). |
|
1718 |
aFloat basicAt:6 put:((high bitShift:-8) bitAnd:16rFF). |
|
1719 |
aFloat basicAt:7 put:((high bitShift:-16) bitAnd:16rFF). |
|
1720 |
aFloat basicAt:8 put:((high bitShift:-24) bitAnd:16rFF). |
|
1721 |
]. |
|
1722 |
||
1723 |
constNeeds2Slots := true. |
|
1724 |
||
1725 |
Verbose ifTrue:[Transcript show:'double; value= '; showCR:aFloat]. |
|
1726 |
^ aFloat |
|
1727 |
||
1728 |
" |
|
1729 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1730 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1731 |
" |
|
1732 |
||
1733 |
"Created: / 15.4.1996 / 16:34:42 / cg" |
|
1734 |
"Modified: / 8.5.1998 / 22:06:07 / cg" |
|
1735 |
! |
|
1736 |
||
1737 |
readConstant_Fieldref |
|
1738 |
|class_index name_and_type_index| |
|
1739 |
||
1740 |
class_index := inStream nextUnsignedShortMSB:msb. |
|
1741 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1742 |
||
1743 |
Verbose ifTrue:[Transcript show:'fieldref; classindex= '; showCR:class_index]. |
|
1744 |
Verbose ifTrue:[Transcript show:'fieldref; name&typeindex= '; showCR:name_and_type_index]. |
|
1745 |
||
1746 |
^ JavaUnresolvedFieldrefConstant |
|
1747 |
pool:constants |
|
1748 |
poolIndex:constSlot |
|
1749 |
classIndex:class_index |
|
1750 |
nameandTypeIndex:name_and_type_index |
|
1751 |
||
1752 |
" |
|
1753 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1754 |
" |
|
1755 |
||
1756 |
"Created: 15.4.1996 / 15:22:18 / cg" |
|
1757 |
"Modified: 15.4.1996 / 16:07:01 / cg" |
|
1758 |
! |
|
1759 |
||
1760 |
readConstant_Float |
|
1761 |
|b1 b2 b3 b4 aFloat bytes| |
|
1762 |
||
1763 |
"/ new code - to be tested ... |
|
1764 |
"/ |
|
1765 |
"/ bytes := ByteArray new:4. |
|
1766 |
"/ inStream nextBytes:4 into:bytes startingAt:1. |
|
1767 |
"/ msb ~~ UninterpretedBytes isBigEndian ifTrue:[ |
|
1768 |
"/ bytes reverse |
|
1769 |
"/ ]. |
|
1770 |
"/ aFloat := bytes floatAt:1. |
|
1771 |
"/ Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
|
1772 |
"/ ^ aFloat. |
|
1773 |
||
1774 |
"/ old code |
|
1775 |
||
1776 |
aFloat := ShortFloat basicNew. |
|
1777 |
||
1778 |
b1 := inStream nextByte. |
|
1779 |
b2 := inStream nextByte. |
|
1780 |
b3 := inStream nextByte. |
|
1781 |
b4 := inStream nextByte. |
|
1782 |
||
1783 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
1784 |
aFloat basicAt:1 put:b1. |
|
1785 |
aFloat basicAt:2 put:b2. |
|
1786 |
aFloat basicAt:3 put:b3. |
|
1787 |
aFloat basicAt:4 put:b4. |
|
1788 |
] ifFalse:[ |
|
1789 |
aFloat basicAt:4 put:b1. |
|
1790 |
aFloat basicAt:3 put:b2. |
|
1791 |
aFloat basicAt:2 put:b3. |
|
1792 |
aFloat basicAt:1 put:b4. |
|
1793 |
]. |
|
1794 |
Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
|
1795 |
^ aFloat |
|
1796 |
||
1797 |
" |
|
1798 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1799 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1800 |
" |
|
1801 |
||
1802 |
"Created: / 15.4.1996 / 16:34:42 / cg" |
|
1803 |
"Modified: / 10.11.1998 / 22:04:59 / cg" |
|
1804 |
! |
|
1805 |
||
1806 |
readConstant_Integer |
|
1807 |
|value| |
|
1808 |
||
1809 |
value := inStream nextLongMSB:msb. |
|
1810 |
||
1811 |
Verbose ifTrue:[Transcript show:'integer; value= '; showCR:value]. |
|
1812 |
||
1813 |
^ value |
|
1814 |
||
1815 |
" |
|
1816 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1817 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1818 |
" |
|
1819 |
||
1820 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
1821 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
1822 |
! |
|
1823 |
||
1824 |
readConstant_InterfaceMethodref |
|
1825 |
|class_index name_and_type_index| |
|
1826 |
||
1827 |
class_index := inStream nextUnsignedShortMSB:msb. |
|
1828 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1829 |
||
1830 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
|
1831 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
1832 |
||
1833 |
^ JavaUnresolvedInterfaceMethodrefConstant |
|
1834 |
pool:constants |
|
1835 |
poolIndex:constSlot |
|
1836 |
classIndex:class_index |
|
1837 |
nameandTypeIndex:name_and_type_index |
|
1838 |
||
1839 |
" |
|
1840 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1841 |
" |
|
1842 |
||
1843 |
"Created: 15.4.1996 / 15:22:37 / cg" |
|
1844 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
|
1845 |
! |
|
1846 |
||
1847 |
readConstant_Long |
|
1848 |
|high low value| |
|
1849 |
||
1850 |
high := inStream nextUnsignedLongMSB:msb. |
|
1851 |
low := inStream nextUnsignedLongMSB:msb. |
|
1852 |
||
1853 |
value := (high bitShift:32) bitOr:low. |
|
1854 |
(high bitTest:16r80000000) ifTrue:[ |
|
1855 |
value := value - 16r10000000000000000. |
|
1856 |
]. |
|
1857 |
constNeeds2Slots := true. |
|
1858 |
||
1859 |
Verbose ifTrue:[Transcript show:'long; value= '; showCR:value]. |
|
1860 |
^ value |
|
1861 |
||
1862 |
" |
|
1863 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1864 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
1865 |
" |
|
1866 |
||
1867 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
1868 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
1869 |
! |
|
1870 |
||
1871 |
readConstant_Methodref |
|
1872 |
|class_index name_and_type_index| |
|
1873 |
||
1874 |
class_index := inStream nextUnsignedShortMSB:msb. |
|
1875 |
name_and_type_index := inStream nextUnsignedShortMSB:msb. |
|
1876 |
||
1877 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
|
1878 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
1879 |
||
1880 |
^ JavaUnresolvedMethodrefConstant |
|
1881 |
pool:constants |
|
1882 |
poolIndex:constSlot |
|
1883 |
classIndex:class_index |
|
1884 |
nameandTypeIndex:name_and_type_index |
|
1885 |
||
1886 |
" |
|
1887 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1888 |
" |
|
1889 |
||
1890 |
"Created: 15.4.1996 / 15:22:37 / cg" |
|
1891 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
|
1892 |
! |
|
1893 |
||
1894 |
readConstant_NameAndType |
|
1895 |
|name_index signature_index| |
|
1896 |
||
1897 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
1898 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
1899 |
||
1900 |
Verbose ifTrue:[Transcript show:'methodref; nameindex= '; showCR:name_index]. |
|
1901 |
Verbose ifTrue:[Transcript show:'methodref; signatureindex= '; showCR:signature_index]. |
|
1902 |
||
1903 |
^ JavaUnresolvedNameandTypeConstant |
|
1904 |
pool:constants |
|
1905 |
poolIndex:constSlot |
|
1906 |
nameIndex:name_index |
|
1907 |
signatureIndex:signature_index |
|
1908 |
||
1909 |
" |
|
1910 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1911 |
" |
|
1912 |
||
1913 |
"Created: 15.4.1996 / 15:23:43 / cg" |
|
1914 |
"Modified: 15.4.1996 / 16:17:16 / cg" |
|
1915 |
! |
|
1916 |
||
1917 |
readConstant_String |
|
1918 |
|tag string_index chars jString| |
|
1919 |
||
1920 |
string_index := inStream nextUnsignedShortMSB:msb. |
|
1921 |
||
1922 |
Verbose ifTrue:[Transcript show:'string; index= '; showCR:string_index]. |
|
1923 |
||
1924 |
"/ resolve here if possible |
|
1925 |
string_index < constSlot ifTrue:[ |
|
1926 |
Java java_lang_String notNil ifTrue:[ |
|
1927 |
chars := (constants at:string_index). |
|
1928 |
chars isString ifFalse:[ |
|
1929 |
self halt:'should not happen' |
|
1930 |
]. |
|
1931 |
jString := Java as_String:chars. |
|
1932 |
^ jString. |
|
1933 |
] |
|
1934 |
]. |
|
1935 |
||
1936 |
^ JavaUnresolvedStringConstant |
|
1937 |
pool:constants |
|
1938 |
poolIndex:constSlot |
|
1939 |
stringIndex:string_index |
|
1940 |
||
1941 |
" |
|
1942 |
Verbose := true. |
|
1943 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/System.class' |
|
1944 |
" |
|
1945 |
||
1946 |
"Created: / 15.4.1996 / 15:20:33 / cg" |
|
1947 |
"Modified: / 7.5.1998 / 11:42:45 / cg" |
|
1948 |
! |
|
1949 |
||
1950 |
readConstant_Unicode |
|
1951 |
|len string ascii| |
|
1952 |
||
1953 |
len := inStream nextUnsignedShortMSB:msb. |
|
1954 |
string := TwoByteString new:len. |
|
1955 |
1 to:len do:[:idx | |
|
1956 |
ascii := inStream nextUnsignedShortMSB:msb. |
|
1957 |
string at:idx put:(Character value:ascii). |
|
1958 |
]. |
|
1959 |
||
1960 |
Verbose ifTrue:[Transcript show:'asciz; unicodeString= '; showCR:string]. |
|
1961 |
||
1962 |
^ string |
|
1963 |
! |
|
1964 |
||
1965 |
readConstant_Utf8 |
|
1966 |
|len bytes string| |
|
1967 |
||
1968 |
len := inStream nextUnsignedShortMSB:msb. |
|
1969 |
bytes := ByteArray new:len. |
|
1970 |
inStream nextBytes:len into:bytes startingAt:1. |
|
1971 |
string := CharacterArray fromJavaUTF8Bytes:bytes. |
|
1972 |
||
1973 |
Verbose ifTrue:[Transcript show:'asciz; string= '; showCR:string]. |
|
1974 |
||
1975 |
^ string |
|
1976 |
||
1977 |
"Modified: / 19-10-2010 / 12:38:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1978 |
! ! |
|
1979 |
||
1980 |
!JavaClassReader methodsFor:'file reading - constants-ST'! |
|
1981 |
||
1982 |
readConstant_ST_Array |
|
1983 |
|aSize arr| |
|
1984 |
||
1985 |
aSize := inStream nextUnsignedShortMSB:msb. |
|
1986 |
arr := Array new:aSize. |
|
1987 |
||
1988 |
1 to:aSize do:[:i | |
|
1989 |
|element_index element| |
|
1990 |
||
1991 |
element_index := inStream nextUnsignedShortMSB:msb. |
|
1992 |
arr at:i put:element_index. |
|
1993 |
]. |
|
1994 |
Verbose ifTrue:[Transcript show:'array; size= '; showCR:aSize]. |
|
1995 |
||
1996 |
^ JavaUnresolvedSTArrayConstant |
|
1997 |
pool:constants |
|
1998 |
poolIndex:constSlot |
|
1999 |
array:arr |
|
2000 |
||
2001 |
"Created: / 7.5.1998 / 11:47:01 / cg" |
|
2002 |
"Modified: / 9.5.1998 / 00:25:34 / cg" |
|
2003 |
! |
|
2004 |
||
2005 |
readConstant_ST_ByteArray |
|
2006 |
|aSize arr| |
|
2007 |
||
2008 |
aSize := inStream nextUnsignedShortMSB:msb. |
|
2009 |
arr := ByteArray new:aSize. |
|
2010 |
||
2011 |
1 to:aSize do:[:i | |
|
2012 |
|element_index| |
|
2013 |
||
2014 |
arr at:i put:(inStream nextByte). |
|
2015 |
]. |
|
2016 |
Verbose ifTrue:[Transcript show:'byteArray; size= '; showCR:aSize]. |
|
2017 |
||
2018 |
^ arr |
|
2019 |
||
2020 |
"Created: / 7.5.1998 / 11:47:12 / cg" |
|
2021 |
! |
|
2022 |
||
2023 |
readConstant_ST_Character |
|
2024 |
|ascii| |
|
2025 |
||
2026 |
ascii := inStream nextUnsignedShortMSB:msb. |
|
2027 |
||
2028 |
Verbose ifTrue:[Transcript show:'char; ascii= '; showCR:ascii]. |
|
2029 |
^ Character value:ascii |
|
2030 |
||
2031 |
"Created: / 7.5.1998 / 11:48:12 / cg" |
|
2032 |
! |
|
2033 |
||
2034 |
readConstant_ST_Special |
|
2035 |
|type| |
|
2036 |
||
2037 |
type := inStream nextUnsignedShortMSB:msb. |
|
2038 |
^ #( |
|
2039 |
nil |
|
2040 |
true |
|
2041 |
false |
|
2042 |
) at:(type + 1) |
|
2043 |
||
2044 |
"Created: / 8.5.1998 / 23:06:56 / cg" |
|
2045 |
"Modified: / 9.5.1998 / 00:40:14 / cg" |
|
2046 |
! |
|
2047 |
||
2048 |
readConstant_ST_String |
|
2049 |
|tag string_index chars| |
|
2050 |
||
2051 |
string_index := inStream nextUnsignedShortMSB:msb. |
|
2052 |
||
2053 |
Verbose ifTrue:[Transcript show:'string; index= '; showCR:string_index]. |
|
2054 |
||
2055 |
"/ resolve here if possible |
|
2056 |
string_index < constSlot ifTrue:[ |
|
2057 |
chars := (constants at:string_index). |
|
2058 |
^ chars |
|
2059 |
]. |
|
2060 |
||
2061 |
^ JavaUnresolvedSTStringConstant |
|
2062 |
pool:constants |
|
2063 |
poolIndex:constSlot |
|
2064 |
stringIndex:string_index |
|
2065 |
||
2066 |
"Modified: / 7.5.1998 / 11:48:28 / cg" |
|
2067 |
"Created: / 7.5.1998 / 11:49:55 / cg" |
|
2068 |
! |
|
2069 |
||
2070 |
readConstant_ST_Symbol |
|
2071 |
|tag string_index chars| |
|
2072 |
||
2073 |
string_index := inStream nextUnsignedShortMSB:msb. |
|
2074 |
||
2075 |
Verbose ifTrue:[Transcript show:'symbol; index= '; showCR:string_index]. |
|
2076 |
||
2077 |
"/ resolve here if possible |
|
2078 |
string_index < constSlot ifTrue:[ |
|
2079 |
chars := (constants at:string_index). |
|
2080 |
chars isString ifFalse:[ |
|
2081 |
self halt:'should not happen' |
|
2082 |
]. |
|
2083 |
^ chars asSymbol |
|
2084 |
]. |
|
2085 |
||
2086 |
^ JavaUnresolvedSTSymbolConstant |
|
2087 |
pool:constants |
|
2088 |
poolIndex:constSlot |
|
2089 |
stringIndex:string_index |
|
2090 |
||
2091 |
"Modified: / 7.5.1998 / 11:48:28 / cg" |
|
2092 |
! ! |
|
2093 |
||
2094 |
!JavaClassReader methodsFor:'file reading - fields'! |
|
2095 |
||
2096 |
readConstantValueAttributeFor:aField |
|
2097 |
|attribute_length constantvalue_index constantValue| |
|
2098 |
||
2099 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2100 |
||
2101 |
constantvalue_index := inStream nextUnsignedShortMSB:msb. |
|
2102 |
constantValue := constants at:constantvalue_index. |
|
2103 |
||
2104 |
aField constantValue:constantValue. |
|
2105 |
||
2106 |
Verbose ifTrue:[Transcript show:'constantValue: '; showCR:constantValue]. |
|
2107 |
^ true |
|
2108 |
||
2109 |
" |
|
2110 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2111 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
2112 |
" |
|
2113 |
||
2114 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2115 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2116 |
! |
|
2117 |
||
2118 |
readFieldInfofield |
|
2119 |
| access_flags name_index signature_index attributes_count field | |
|
2120 |
||
2121 |
access_flags := inStream nextUnsignedShortMSB: msb. |
|
2122 |
name_index := inStream nextUnsignedShortMSB: msb. |
|
2123 |
signature_index := inStream nextUnsignedShortMSB: msb. |
|
2124 |
field := JavaField new. |
|
2125 |
field setAccessFlags: access_flags. |
|
2126 |
field setName: (constants at: name_index) asSymbol. |
|
2127 |
field setSignature: (constants at: signature_index) asSymbol. |
|
2128 |
field constantPool: constants. |
|
2129 |
attributes_count := inStream nextUnsignedShortMSB: msb. |
|
2130 |
Verbose |
|
2131 |
ifTrue: |
|
2132 |
[ Transcript |
|
2133 |
show: ' field name: '; |
|
2134 |
show: (constants at: name_index); |
|
2135 |
show: ' access: '; |
|
2136 |
show: access_flags; |
|
2137 |
show: ' attrib_cnt: '; |
|
2138 |
showCR: attributes_count ]. |
|
2139 |
1 to: attributes_count do: [:i | self readAttributeFor: field. ]. |
|
2140 |
^ field. |
|
2141 |
||
2142 |
" |
|
2143 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class'" |
|
2144 |
||
2145 |
"Created: / 15-04-1996 / 15:38:43 / cg" |
|
2146 |
"Modified: / 15-10-1998 / 10:38:01 / cg" |
|
2147 |
"Modified: / 17-12-2010 / 18:44:30 / Marcel Hlopko <hlopik@gmail.com>" |
|
2148 |
"Modified: / 01-04-2011 / 11:38:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>" |
|
2149 |
! |
|
2150 |
||
2151 |
readFieldInfofields |
|
2152 |
|nFields fields| |
|
2153 |
||
2154 |
"/ |
|
2155 |
"/ get fieldInfos |
|
2156 |
"/ |
|
2157 |
nFields := inStream nextUnsignedShortMSB:msb. |
|
2158 |
Verbose ifTrue:[Transcript show:'fieldsCount = '; showCR:nFields]. |
|
2159 |
||
2160 |
fields := Array new:nFields. |
|
2161 |
||
2162 |
1 to:nFields do:[:i | |
|
2163 |
Verbose ifTrue:[Transcript show:'field: '; showCR:i]. |
|
2164 |
fields at:i put:(self readFieldInfofield) |
|
2165 |
]. |
|
2166 |
^ fields |
|
2167 |
||
2168 |
" |
|
2169 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2170 |
" |
|
2171 |
||
2172 |
"Created: 15.4.1996 / 15:34:41 / cg" |
|
2173 |
"Modified: 15.4.1996 / 15:35:28 / cg" |
|
2174 |
! ! |
|
2175 |
||
2176 |
!JavaClassReader methodsFor:'file reading - interfaces'! |
|
2177 |
||
2178 |
readInterfaces |
|
2179 |
|interfacesCount interface_index interface interfaces| |
|
2180 |
||
2181 |
"/ |
|
2182 |
"/ get interfaces |
|
2183 |
"/ |
|
2184 |
interfacesCount := inStream nextUnsignedShortMSB:msb. |
|
2185 |
Verbose ifTrue:[Transcript show:'interfacesCount = '; showCR:interfacesCount]. |
|
2186 |
||
2187 |
interfaces := Array new:interfacesCount. |
|
2188 |
||
2189 |
1 to:interfacesCount do:[:i | |
|
2190 |
Verbose ifTrue:[Transcript show:'interface: '; showCR:i]. |
|
2191 |
interface_index := inStream nextUnsignedShortMSB:msb. |
|
2192 |
interface := constants at:interface_index. |
|
2193 |
||
2194 |
interfaces at:i put:interface. |
|
2195 |
]. |
|
2196 |
^ interfaces |
|
2197 |
||
2198 |
" |
|
2199 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2200 |
" |
|
2201 |
||
2202 |
"Created: 15.4.1996 / 15:31:59 / cg" |
|
2203 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2204 |
! ! |
|
2205 |
||
2206 |
!JavaClassReader methodsFor:'file reading - methods'! |
|
2207 |
||
2208 |
readCodeAttributeFor:aJavaMethod |
|
2209 |
|attribute_length max_stack max_locals code_length code |
|
2210 |
exception_table_length exception_table unknown1 unknown2| |
|
2211 |
||
2212 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2213 |
||
2214 |
Verbose ifTrue:[Transcript show:'code_attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
|
2215 |
||
2216 |
((minorVsn > 2) or:[majorVsn > 45]) ifTrue:[ |
|
2217 |
"/ should be: |
|
2218 |
max_stack := inStream nextUnsignedShortMSB:msb. |
|
2219 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
2220 |
code_length := inStream nextUnsignedLongMSB:msb. |
|
2221 |
||
2222 |
"/ unknown1 := inStream nextByte. |
|
2223 |
"/ max_stack := inStream nextByte. |
|
2224 |
"/ max_locals := inStream nextUnsignedShortMSB:msb. |
|
2225 |
"/ unknown2 := inStream nextUnsignedShortMSB:msb. |
|
2226 |
"/ code_length := inStream nextUnsignedShortMSB:msb. |
|
2227 |
"/ Verbose ifTrue:[Transcript show:'?1: '; showCR:unknown1]. |
|
2228 |
"/ Verbose ifTrue:[Transcript show:'?2: '; showCR:unknown2]. |
|
2229 |
] ifFalse:[ |
|
2230 |
max_stack := inStream nextByte. |
|
2231 |
max_locals := inStream nextByte. |
|
2232 |
code_length := inStream nextUnsignedShortMSB:msb. |
|
2233 |
]. |
|
2234 |
||
2235 |
Verbose ifTrue:[ |
|
2236 |
Transcript show:'code_length: '; showCR:(code_length printStringRadix:16). |
|
2237 |
Transcript show:'code at pos: '; showCR:inStream position |
|
2238 |
]. |
|
2239 |
||
2240 |
code_length ~~ 0 ifTrue:[ |
|
2241 |
code := ByteArray new:code_length. |
|
2242 |
inStream nextBytes:code_length into:code startingAt:1. |
|
2243 |
]. |
|
2244 |
Verbose ifTrue:[Transcript show:'method code: '; showCR:code.]. |
|
2245 |
||
2246 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2247 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
|
2248 |
exception_table_length ~~ 0 ifTrue:[ |
|
2249 |
Verbose ifTrue:[Transcript show:'exceptionTable length:'; showCR:exception_table_length.]. |
|
2250 |
||
2251 |
exception_table := Array new:exception_table_length. |
|
2252 |
1 to:exception_table_length do:[:i | |
|
2253 |
|start_pc end_pc handler_pc catch_type| |
|
2254 |
||
2255 |
start_pc := inStream nextUnsignedShortMSB:msb. |
|
2256 |
end_pc := inStream nextUnsignedShortMSB:msb. |
|
2257 |
handler_pc := inStream nextUnsignedShortMSB:msb. |
|
2258 |
catch_type := inStream nextUnsignedShortMSB:msb. |
|
2259 |
catch_type ~= 0 ifTrue:[ |
|
2260 |
catch_type := constants at:catch_type. |
|
2261 |
]. |
|
2262 |
exception_table at:i put:(JavaExceptionTableEntry |
|
2263 |
startPC:start_pc |
|
2264 |
endPC:end_pc |
|
2265 |
handlerPC:handler_pc |
|
2266 |
catchType:catch_type). |
|
2267 |
]. |
|
2268 |
aJavaMethod setExceptionHandlerTable:exception_table. |
|
2269 |
]. |
|
2270 |
||
2271 |
aJavaMethod |
|
2272 |
setCode:code |
|
2273 |
maxStack:max_stack |
|
2274 |
maxLocals:max_locals |
|
2275 |
u1:unknown1 |
|
2276 |
u2:unknown2. |
|
2277 |
||
2278 |
self readAttributesFor:aJavaMethod. |
|
2279 |
^ true |
|
2280 |
||
2281 |
" |
|
2282 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2283 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
2284 |
" |
|
2285 |
||
2286 |
"Created: / 15-04-1996 / 15:40:17 / cg" |
|
2287 |
"Modified: / 16-05-1998 / 01:39:42 / cg" |
|
2288 |
"Modified: / 17-12-2010 / 00:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2289 |
! |
|
2290 |
||
2291 |
readExceptionsAttributeFor:aJavaMethod |
|
2292 |
|attribute_length exception_table_length exception_table| |
|
2293 |
||
2294 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2295 |
||
2296 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2297 |
exception_table_length ~~ 0 ifTrue:[ |
|
2298 |
exception_table := Array new:exception_table_length. |
|
2299 |
1 to:exception_table_length do:[:i | |
|
2300 |
|idx ex| |
|
2301 |
||
2302 |
idx := inStream nextUnsignedShortMSB:msb. |
|
2303 |
ex := constants at:idx. |
|
2304 |
exception_table at:i put:ex. |
|
2305 |
]. |
|
2306 |
]. |
|
2307 |
||
2308 |
Verbose ifTrue:[Transcript showCR:'method has an exceptionTable']. |
|
2309 |
||
2310 |
aJavaMethod setExceptionTable:exception_table. |
|
2311 |
^ true |
|
2312 |
||
2313 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2314 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2315 |
! |
|
2316 |
||
2317 |
readLineNumberTableAttributeFor:aJavaMethod |
|
2318 |
|attribute_length line_number_table_length line_number_table| |
|
2319 |
||
2320 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2321 |
||
2322 |
line_number_table_length := inStream nextUnsignedShortMSB:msb. |
|
2323 |
line_number_table_length ~~ 0 ifTrue:[ |
|
2324 |
line_number_table := Array new:line_number_table_length. |
|
2325 |
1 to:line_number_table_length do:[:i | |
|
2326 |
|start_pc line_number| |
|
2327 |
||
2328 |
start_pc := inStream nextUnsignedShortMSB:msb. |
|
2329 |
line_number := inStream nextUnsignedShortMSB:msb. |
|
2330 |
line_number_table at:i put:(start_pc -> line_number). |
|
2331 |
]. |
|
2332 |
Verbose ifTrue:[Transcript showCR:'method has a lineNumberTable']. |
|
2333 |
||
2334 |
aJavaMethod setLineNumberTable:line_number_table. |
|
2335 |
]. |
|
2336 |
||
2337 |
^ true |
|
2338 |
||
2339 |
" |
|
2340 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2341 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
2342 |
" |
|
2343 |
||
2344 |
"Created: / 15.4.1996 / 15:40:17 / cg" |
|
2345 |
"Modified: / 7.4.1998 / 19:08:42 / cg" |
|
2346 |
! |
|
2347 |
||
2348 |
readLocalVariableTableAttributeFor:aJavaMethod |
|
2349 |
|attribute_length local_variable_table_length local_variable_table| |
|
2350 |
||
2351 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2352 |
||
2353 |
local_variable_table_length := inStream nextUnsignedShortMSB:msb. |
|
2354 |
local_variable_table_length ~~ 0 ifTrue:[ |
|
2355 |
local_variable_table := JavaLocalVariableTable new:local_variable_table_length. |
|
2356 |
1 to:local_variable_table_length do:[:i | |
|
2357 |
|start_pc length name_index sig_index slot name signature| |
|
2358 |
||
2359 |
start_pc := inStream nextUnsignedShortMSB:msb. |
|
2360 |
length := inStream nextUnsignedShortMSB:msb. |
|
2361 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2362 |
name := constants at:name_index. |
|
2363 |
sig_index := inStream nextUnsignedShortMSB:msb. |
|
2364 |
signature := constants at:sig_index. |
|
2365 |
slot := inStream nextUnsignedShortMSB:msb. |
|
2366 |
||
2367 |
local_variable_table at:i put:(JavaLocalVariableTableEntry new |
|
2368 |
startPC:start_pc |
|
2369 |
length:length |
|
2370 |
name:name |
|
2371 |
signature:signature |
|
2372 |
slot:slot) |
|
2373 |
]. |
|
2374 |
]. |
|
2375 |
||
2376 |
Verbose ifTrue:[Transcript showCR:'method has a localvariableTable']. |
|
2377 |
||
2378 |
aJavaMethod setLocalVariableTable:local_variable_table. |
|
2379 |
^ true |
|
2380 |
||
2381 |
" |
|
2382 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2383 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
2384 |
" |
|
2385 |
||
2386 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
2387 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
2388 |
! |
|
2389 |
||
2390 |
readMethodFor:aClass |
|
2391 |
|m access_flags name_index name signature_index signature |
|
2392 |
tooManyArgs| |
|
2393 |
||
2394 |
"/ |
|
2395 |
"/ get a method |
|
2396 |
"/ |
|
2397 |
access_flags := inStream nextUnsignedShortMSB:msb. |
|
2398 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2399 |
signature_index := inStream nextUnsignedShortMSB:msb. |
|
2400 |
||
2401 |
name := constants at:name_index. |
|
2402 |
signature := constants at:signature_index. |
|
2403 |
||
2404 |
Verbose ifTrue:[ |
|
2405 |
Transcript show:'method name:'; showCR:name. |
|
2406 |
Transcript show:'signature:'; showCR:signature. |
|
2407 |
]. |
|
2408 |
||
2409 |
aClass isJavaClass ifTrue:[ |
|
2410 |
(access_flags bitAnd:JavaMethod A_NATIVE) ~~ 0 ifTrue:[ |
|
2411 |
m := JavaNativeMethod new. |
|
2412 |
] ifFalse:[ |
|
2413 |
m := JavaMethodWithHandler new. |
|
2414 |
]. |
|
2415 |
m setAccessFlags:access_flags. |
|
2416 |
tooManyArgs := false. |
|
2417 |
ArgumentError handle:[:ex | |
|
2418 |
'JAVA: ***** java method has too many arguments - will fail to execute' infoPrintCR. |
|
2419 |
tooManyArgs := true. |
|
2420 |
ex proceed. |
|
2421 |
] do:[ |
|
2422 |
m setName:name signature:signature. |
|
2423 |
]. |
|
2424 |
m setJavaClass:aClass. |
|
2425 |
||
2426 |
self readAttributesFor:m. |
|
2427 |
||
2428 |
tooManyArgs ifTrue:[ |
|
2429 |
m code:nil. |
|
2430 |
m byteCode:nil. |
|
2431 |
]. |
|
2432 |
(m exceptionHandlerTable isNil) ifTrue:[ |
|
2433 |
m isNative ifFalse:[ |
|
2434 |
m getExceptionTable isNil ifTrue:[ |
|
2435 |
m := JavaMethod fromMethod:m |
|
2436 |
] ifFalse:[ |
|
2437 |
m := JavaMethodWithException fromMethod:m |
|
2438 |
] |
|
2439 |
] |
|
2440 |
] ifFalse:[ |
|
2441 |
m setAccessFlags:(m accessFlags bitOr:JavaMethod A_HASHANDLER) |
|
2442 |
]. |
|
2443 |
aClass addMethod:m name:name signature:signature. |
|
2444 |
] ifFalse:[ |
|
2445 |
m := Method new. |
|
2446 |
self readAttributesFor:m. |
|
2447 |
(access_flags bitTest:JavaMethod A_STATIC) ifTrue:[ |
|
2448 |
aClass class primAddSelector:name asSymbol withMethod:m. |
|
2449 |
] ifFalse:[ |
|
2450 |
aClass primAddSelector:name asSymbol withMethod:m. |
|
2451 |
] |
|
2452 |
]. |
|
2453 |
||
2454 |
" |
|
2455 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2456 |
" |
|
2457 |
||
2458 |
"Created: / 15-04-1996 / 16:48:49 / cg" |
|
2459 |
"Modified: / 25-09-1999 / 23:16:25 / cg" |
|
2460 |
"Modified: / 04-02-2011 / 23:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
2461 |
! |
|
2462 |
||
2463 |
readMethodsFor:aJavaClass |
|
2464 |
|methodsCount method| |
|
2465 |
||
2466 |
"/ |
|
2467 |
"/ get methods |
|
2468 |
"/ |
|
2469 |
methodsCount := inStream nextUnsignedShortMSB:msb. |
|
2470 |
Verbose ifTrue:[Transcript show:'methodsCount = '; showCR:methodsCount]. |
|
2471 |
||
2472 |
1 to:methodsCount do:[:i | |
|
2473 |
Verbose ifTrue:[Transcript show:'method: '; showCR:i]. |
|
2474 |
method := self readMethodFor:aJavaClass |
|
2475 |
]. |
|
2476 |
||
2477 |
" |
|
2478 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
2479 |
" |
|
2480 |
||
2481 |
"Created: / 15.4.1996 / 16:46:30 / cg" |
|
2482 |
"Modified: / 8.5.1998 / 21:20:59 / cg" |
|
2483 |
! ! |
|
2484 |
||
2485 |
!JavaClassReader methodsFor:'file reading - methods-ST'! |
|
2486 |
||
2487 |
readSTCodeAttributeFor:aSmalltalkMethod |
|
2488 |
|attribute_length max_stack max_locals code_length code |
|
2489 |
exception_table_length unknown1 unknown2| |
|
2490 |
||
2491 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2492 |
||
2493 |
Verbose ifTrue:[Transcript show:'attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
|
2494 |
||
2495 |
max_stack := inStream nextUnsignedShortMSB:msb. |
|
2496 |
max_locals := inStream nextUnsignedShortMSB:msb. |
|
2497 |
||
2498 |
code_length := inStream nextUnsignedLongMSB:msb. |
|
2499 |
Verbose ifTrue:[Transcript show:'code_length: '; showCR:(code_length printStringRadix:16)]. |
|
2500 |
Verbose ifTrue:[Transcript show:'code at pos: '; showCR:inStream position]. |
|
2501 |
||
2502 |
code_length ~~ 0 ifTrue:[ |
|
2503 |
code := ByteArray new:code_length. |
|
2504 |
inStream nextBytes:code_length into:code startingAt:1. |
|
2505 |
]. |
|
2506 |
Verbose ifTrue:[Transcript show:'method code: '; showCR:code.]. |
|
2507 |
||
2508 |
exception_table_length := inStream nextUnsignedShortMSB:msb. |
|
2509 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
|
2510 |
exception_table_length ~~ 0 ifTrue:[ |
|
2511 |
self error:'unexpected exceptionTable length'. |
|
2512 |
"/ skip it. |
|
2513 |
1 to:exception_table_length do:[:i | |
|
2514 |
"start_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2515 |
"end_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2516 |
"handler_pc :=" inStream nextUnsignedShortMSB:msb. |
|
2517 |
"catch_type :=" inStream nextUnsignedShortMSB:msb. |
|
2518 |
]. |
|
2519 |
]. |
|
2520 |
||
2521 |
aSmalltalkMethod byteCode:code. |
|
2522 |
aSmalltalkMethod stackSize:max_stack . |
|
2523 |
aSmalltalkMethod numberOfVars:max_locals. |
|
2524 |
||
2525 |
self readAttributesFor:aSmalltalkMethod. |
|
2526 |
^ true |
|
2527 |
||
2528 |
"Modified: / 16.5.1998 / 01:39:30 / cg" |
|
2529 |
! |
|
2530 |
||
2531 |
readSTLiteralsAttributeFor:aSmalltalkMethod |
|
2532 |
|attribute_length literal_table_length literal_table litIndex literal| |
|
2533 |
||
2534 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2535 |
||
2536 |
literal_table_length := inStream nextUnsignedShortMSB:msb. |
|
2537 |
literal_table_length ~~ 0 ifTrue:[ |
|
2538 |
literal_table := Array new:literal_table_length. |
|
2539 |
1 to:literal_table_length do:[:i | |
|
2540 |
litIndex := inStream nextUnsignedShortMSB:msb. |
|
2541 |
literal := (constants at:litIndex). |
|
2542 |
literal_table at:i put:literal. |
|
2543 |
]. |
|
2544 |
]. |
|
2545 |
Verbose ifTrue:[Transcript show:'literals: '; showCR:literal_table storeString.]. |
|
2546 |
||
2547 |
"Created: / 7.5.1998 / 11:52:28 / cg" |
|
2548 |
"Modified: / 16.5.1998 / 01:52:27 / cg" |
|
2549 |
! |
|
2550 |
||
2551 |
readSTMethodCategoryAttributeFor:aSmalltalkMethod |
|
2552 |
|attribute_length name_index name| |
|
2553 |
||
2554 |
attribute_length := inStream nextUnsignedLongMSB:msb. |
|
2555 |
||
2556 |
name_index := inStream nextUnsignedShortMSB:msb. |
|
2557 |
name := (constants at:name_index). |
|
2558 |
||
2559 |
aSmalltalkMethod category:name. |
|
2560 |
||
2561 |
"Modified: / 8.5.1998 / 20:39:59 / cg" |
|
2562 |
"Created: / 16.5.1998 / 01:04:19 / cg" |
|
2563 |
! ! |
|
2564 |
||
2565 |
!JavaClassReader class methodsFor:'documentation'! |
|
2566 |
||
2567 |
version |
|
2568 |
^ '$Id$' |
|
2569 |
! |
|
2570 |
||
2571 |
version_CVS |
|
2572 |
^ '§Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClassReader.st,v 1.92 2009/10/09 14:21:53 cg Exp §' |
|
2573 |
! |
|
2574 |
||
2575 |
version_SVN |
|
2576 |
^ '$Id$' |
|
2577 |
! ! |
|
2578 |
||
2579 |
JavaClassReader initialize! |