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