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