author | cg |
Fri, 05 Jul 1996 17:32:14 +0000 | |
changeset 116 | 7d612d4450c0 |
parent 115 | b484eacaf30f |
child 122 | e731a1c1d499 |
permissions | -rw-r--r-- |
1 | 1 |
Object subclass:#JavaClassReader |
91 | 2 |
instanceVariableNames:'inStream msb constants majorVsn minorVsn constNeeds2Slots |
38 | 3 |
constSlot' |
91 | 4 |
classVariableNames:'Verbose ClassPath Silent AbsolutelySilent LazyClassLoading' |
1 | 5 |
poolDictionaries:'' |
6 |
category:'Java-Support' |
|
7 |
! |
|
8 |
||
9 |
||
62 | 10 |
!JavaClassReader class methodsFor:'initialization'! |
1 | 11 |
|
12 |
initialize |
|
91 | 13 |
Verbose := false. |
14 |
Silent := true. |
|
15 |
AbsolutelySilent := false. |
|
16 |
||
17 |
self initializeClassPath. |
|
18 |
LazyClassLoading := false. "/ true. |
|
29 | 19 |
|
20 |
" |
|
21 |
JavaClassReader initialize |
|
22 |
" |
|
23 |
! |
|
24 |
||
25 |
initializeClassPath |
|
116 | 26 |
self initializeClassPath:(Java classPath) |
29 | 27 |
|
28 |
" |
|
29 |
JavaClassReader initializeClassPath |
|
30 |
" |
|
62 | 31 |
! |
32 |
||
33 |
initializeClassPath:aCollectionOfDirectoryPathNames |
|
34 |
ClassPath := aCollectionOfDirectoryPathNames |
|
35 |
||
36 |
" |
|
37 |
JavaClassReader initializeClassPath:#( |
|
38 |
'/home/cg/java/' |
|
39 |
) |
|
40 |
" |
|
1 | 41 |
! ! |
42 |
||
62 | 43 |
!JavaClassReader class methodsFor:'debugging'! |
1 | 44 |
|
45 |
verbose:aBoolean |
|
46 |
Verbose := aBoolean |
|
47 |
||
48 |
" |
|
67 | 49 |
Java flushClasses. |
1 | 50 |
JavaClassReader verbose:true |
51 |
JavaClassReader verbose:false |
|
52 |
" |
|
53 |
! ! |
|
54 |
||
62 | 55 |
!JavaClassReader class methodsFor:'file reading'! |
1 | 56 |
|
21 | 57 |
loadClass:aClassName |
43 | 58 |
"reads a class, installs and returns it. |
59 |
The classes string constants are resolved & <clinit> is called, |
|
60 |
if it implements it." |
|
21 | 61 |
|
62 |
|rslt| |
|
63 |
||
54 | 64 |
rslt := self loadClassLazy:aClassName ignoring:Set new. |
91 | 65 |
rslt notNil ifTrue:[self postLoadActions]. |
40 | 66 |
|
38 | 67 |
^ rslt |
21 | 68 |
|
69 |
" |
|
70 |
JavaClassReader loadClass:'awt/Component' |
|
71 |
JavaClassReader loadClass:'awt/Button' |
|
72 |
JavaClassReader loadClass:'browser/AddButton' |
|
73 |
||
74 |
JavaClassReader loadClass:'java/lang/Object' |
|
75 |
JavaClassReader loadClass:'java/lang/AbstractMethodError' |
|
76 |
JavaClassReader loadClass:'java/lang/Thread' |
|
77 |
" |
|
78 |
||
79 |
"Created: 15.4.1996 / 14:58:53 / cg" |
|
80 |
! |
|
81 |
||
54 | 82 |
loadClassLazy:aClassName ignoring:classesBeingLoaded |
38 | 83 |
"private helper: |
84 |
reads a class, installs and returns it. |
|
85 |
The class is searched along the ClassPath. |
|
43 | 86 |
|
87 |
This is a partial load (to load other classes): |
|
88 |
- The classes stringConstants are not fixed to be JavaStrings |
|
89 |
(i.e they are still ST-Strings). |
|
90 |
- The class is not initialized." |
|
38 | 91 |
|
91 | 92 |
|rslt clsName cls loadedClass| |
50 | 93 |
|
52 | 94 |
(aClassName endsWith:';') ifTrue:[ |
95 |
('oops - loading of ' , aClassName , ' attempted') printNL. |
|
91 | 96 |
self halt:'should not happen'. |
97 |
^ nil |
|
98 |
]. |
|
99 |
(aClassName endsWith:'[]') ifTrue:[ |
|
100 |
('oops - loading of ' , aClassName , ' attempted') printNL. |
|
101 |
self halt:'should not happen'. |
|
52 | 102 |
^ nil |
103 |
]. |
|
104 |
||
50 | 105 |
clsName := aClassName. |
106 |
(clsName includes:$.) ifTrue:[ |
|
107 |
clsName := clsName copy replaceAll:$. by:$/ |
|
108 |
]. |
|
38 | 109 |
|
91 | 110 |
(classesBeingLoaded notNil and:[classesBeingLoaded includes:clsName]) ifTrue:[ |
54 | 111 |
('oops - recursive load of ' , clsName , ' attempted') printNL. |
91 | 112 |
self halt:'should not happen'. |
54 | 113 |
^ JavaUnresolvedClassConstant fullName:clsName |
114 |
]. |
|
115 |
||
91 | 116 |
(cls := Java at:clsName) notNil ifTrue:[ |
117 |
('oops - ' , clsName , ' is already loaded') printNL. |
|
118 |
self halt:'should not happen'. |
|
119 |
^ cls |
|
120 |
]. |
|
121 |
||
122 |
classesBeingLoaded isNil ifTrue:[ |
|
123 |
loadedClass := Set with:clsName |
|
124 |
] ifFalse:[ |
|
125 |
loadedClass := Set withAll:classesBeingLoaded. |
|
126 |
loadedClass add:clsName. |
|
127 |
]. |
|
54 | 128 |
|
38 | 129 |
ClassPath do:[:path | |
91 | 130 |
|nm| |
131 |
||
132 |
(nm := path , clsName , '.class') asFilename exists ifTrue:[ |
|
133 |
rslt := self loadFileLazy:nm |
|
134 |
ignoring:loadedClass. |
|
135 |
rslt notNil ifTrue:[ |
|
136 |
^ rslt |
|
137 |
]. |
|
138 |
] |
|
38 | 139 |
]. |
140 |
||
91 | 141 |
('JAVA: no file found for: ' , clsName) infoPrintCR. |
142 |
^ nil |
|
38 | 143 |
! |
144 |
||
7 | 145 |
loadFile:aFilename |
43 | 146 |
"reads a class from aFilename, installs and returns it. |
147 |
The classes strings are fixed and its class-init function is called." |
|
148 |
||
54 | 149 |
self loadFileLazy:aFilename ignoring:(Set new). |
43 | 150 |
self postLoadActions |
151 |
! |
|
152 |
||
54 | 153 |
loadFileLazy:aFilename ignoring:classesBeingLoaded |
43 | 154 |
"reads a class from aFilename, installs and returns it. |
91 | 155 |
Strings are fixed and classrefs are fixed, |
156 |
but NO no class-init functions are called." |
|
7 | 157 |
|
21 | 158 |
|javaClass pool| |
7 | 159 |
|
54 | 160 |
javaClass := self readFile:aFilename ignoring:classesBeingLoaded. |
7 | 161 |
javaClass notNil ifTrue:[ |
32 | 162 |
Java at:(javaClass fullName asSymbol) put:javaClass. |
21 | 163 |
|
54 | 164 |
classesBeingLoaded remove:javaClass fullName ifAbsent:nil. |
21 | 165 |
|
91 | 166 |
JavaUnresolvedConstant resolveFor:javaClass. |
7 | 167 |
]. |
9 | 168 |
^ javaClass |
7 | 169 |
|
170 |
" |
|
171 |
JavaClassReader loadFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
9 | 172 |
|
173 |
'/phys/ibm3/java/lib/java/lang' asFilename |
|
174 |
directoryContents do:[:nm | |
|
175 |
(nm endsWith:'.class') ifTrue:[ |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
176 |
('/phys/ibm3/java/lib/java/lang/' , nm) printNL. |
9 | 177 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/' , nm |
178 |
] |
|
21 | 179 |
]. |
9 | 180 |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
181 |
'/phys/ibm3/java/lib/java/io' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
182 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
183 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
184 |
('/phys/ibm3/java/lib/java/io/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
185 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/io/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
186 |
] |
21 | 187 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
188 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
189 |
'/phys/ibm3/java/lib/java/net' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
190 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
191 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
192 |
('/phys/ibm3/java/lib/java/net/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
193 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/net/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
194 |
] |
21 | 195 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
196 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
197 |
'/phys/ibm3/java/lib/java/util' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
198 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
199 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
200 |
('/phys/ibm3/java/lib/java/util/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
201 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/util/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
202 |
] |
21 | 203 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
204 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
205 |
'/phys/ibm3/java/lib/java/awt' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
206 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
207 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
208 |
('/phys/ibm3/java/lib/java/awt/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
209 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/awt/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
210 |
] |
21 | 211 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
212 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
213 |
'/phys/ibm3/java/lib/java/applet' asFilename |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
214 |
directoryContents do:[:nm | |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
215 |
(nm endsWith:'.class') ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
216 |
('/phys/ibm3/java/lib/java/applet/' , nm) printNL. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
217 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/applet/' , nm |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
218 |
] |
21 | 219 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
220 |
|
9 | 221 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/AbstractMethodError.class' |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
222 |
JavaClassReader loadFile:'/phys/ibm3/java/lib/java/lang/Thread.class' |
7 | 223 |
" |
224 |
||
225 |
"Created: 15.4.1996 / 14:58:53 / cg" |
|
226 |
! |
|
227 |
||
43 | 228 |
postLoadActions |
229 |
"Resolve all classes' string constants. |
|
230 |
Perform all class initialization functions (of those which are not |
|
231 |
yet initialized)." |
|
232 |
||
91 | 233 |
|classes prevUnresolved newUnresolved| |
43 | 234 |
|
91 | 235 |
"/ need at least java.lang.String, for valid constants |
236 |
Java javaString isNil ifTrue:[ |
|
237 |
self loadClassLazy:'java.lang.String' ignoring:Set new. |
|
54 | 238 |
]. |
239 |
||
91 | 240 |
LazyClassLoading ifFalse:[ |
241 |
prevUnresolved := nil. |
|
242 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
243 |
[prevUnresolved ~= newUnresolved] whileTrue:[ |
|
244 |
newUnresolved do:[:nextUnresolved | |
|
245 |
(Java at:nextUnresolved) isNil ifTrue:[ "/ could have been loaded in the meantime |
|
246 |
Silent ifFalse:[ |
|
247 |
'loading unresolved: ' print. nextUnresolved printCR. |
|
248 |
]. |
|
249 |
||
250 |
self |
|
251 |
loadClassLazy:nextUnresolved |
|
252 |
ignoring:Set new. |
|
253 |
] |
|
254 |
]. |
|
255 |
prevUnresolved := newUnresolved. |
|
256 |
newUnresolved := JavaUnresolvedConstant unresolvedClassNames asArray. |
|
257 |
]. |
|
258 |
||
259 |
newUnresolved size == 0 ifTrue:[ |
|
260 |
"/ nothing unresolved |
|
261 |
||
262 |
(classes := Java allClasses) notNil ifTrue:[ |
|
263 |
"/ init all new classes |
|
264 |
"/ fetch again - there could be new ones ... |
|
265 |
||
266 |
classes := Java allClasses. |
|
267 |
classes do:[:aJavaClass | |
|
268 |
aJavaClass isInitialized ifFalse:[ |
|
269 |
Silent ifFalse:[ |
|
270 |
'performing class initialization of ' print. aJavaClass fullName printCR. |
|
271 |
]. |
|
272 |
aJavaClass classInit |
|
273 |
] |
|
274 |
] |
|
275 |
] |
|
276 |
]. |
|
43 | 277 |
] |
278 |
! |
|
279 |
||
54 | 280 |
readFile:aFilename ignoring:classesBeingLoaded |
7 | 281 |
"reads a class from aFilename and returns it. |
91 | 282 |
The JavaClass is NOT installed as global and unresolved |
283 |
refs are NOT patched." |
|
7 | 284 |
|
73 | 285 |
|inStream javaClass| |
1 | 286 |
|
43 | 287 |
Silent ifFalse:[ |
288 |
'reading ' print. aFilename print. ' ...' printNL. |
|
289 |
]. |
|
21 | 290 |
|
1 | 291 |
inStream := aFilename asFilename readStream. |
91 | 292 |
inStream isNil ifTrue:[ |
293 |
('no file: ' , aFilename) printCR. |
|
294 |
self halt. |
|
295 |
^ nil |
|
296 |
]. |
|
297 |
||
298 |
javaClass := self new readStream:inStream ignoring:classesBeingLoaded. |
|
73 | 299 |
javaClass notNil ifTrue:[ |
300 |
javaClass setBinaryFilePath:(inStream pathName). |
|
301 |
]. |
|
1 | 302 |
inStream close. |
27 | 303 |
|
91 | 304 |
AbsolutelySilent ifFalse:[ |
73 | 305 |
' ... loaded ' print. javaClass displayString printNL. |
43 | 306 |
]. |
27 | 307 |
|
73 | 308 |
^ javaClass |
1 | 309 |
|
310 |
"Created: 15.4.1996 / 14:58:53 / cg" |
|
311 |
! |
|
312 |
||
54 | 313 |
readStream:aStream ignoring:classesBeingLoaded |
7 | 314 |
"reads a class from aStream and returns it. |
315 |
The JavaClass is not installed as global" |
|
316 |
||
54 | 317 |
^ self new readStream:aStream ignoring:classesBeingLoaded |
1 | 318 |
|
319 |
" |
|
320 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
321 |
" |
|
322 |
||
323 |
"Modified: 15.4.1996 / 15:01:30 / cg" |
|
324 |
! ! |
|
325 |
||
326 |
!JavaClassReader methodsFor:'file reading'! |
|
327 |
||
54 | 328 |
readClassFileIgnoring:classesbeingLoaded |
7 | 329 |
"reads a class from inStream and returns it. |
38 | 330 |
The JavaClass is not installed as global and its constants |
331 |
(especially strings) may not be fully resolved." |
|
7 | 332 |
|
9 | 333 |
|magic |
38 | 334 |
access_flags this_class this_class_index super_class super_class_index |
335 |
realSuperClass this_class_ref existingSuperClass |
|
40 | 336 |
fields interfaces staticFields nStatic| |
1 | 337 |
|
338 |
"/ |
|
339 |
"/ read magic, determine byte order |
|
340 |
"/ |
|
341 |
msb := true. |
|
342 |
magic := self nextU4. |
|
343 |
magic = 16rCAFEBABE ifFalse:[ |
|
344 |
magic = 16rBEBAFECA ifFalse:[ |
|
345 |
self error:'not a java class file'. |
|
346 |
^ nil |
|
347 |
]. |
|
348 |
msb := false. |
|
61 | 349 |
Verbose ifTrue:[Transcript showCR:'file is lsb']. |
1 | 350 |
] ifTrue:[ |
61 | 351 |
Verbose ifTrue:[Transcript showCR:'file is msb']. |
1 | 352 |
]. |
353 |
||
354 |
"/ |
|
355 |
"/ get version |
|
356 |
"/ |
|
91 | 357 |
minorVsn := self nextU2. |
358 |
majorVsn := self nextU2. |
|
9 | 359 |
|
99 | 360 |
(majorVsn ~~ 45 or:[minorVsn ~~ 3]) ifTrue:[ |
361 |
Transcript show:'warning this file has version '; show:majorVsn; show:'.'; showCR:minorVsn. |
|
362 |
]. |
|
363 |
||
364 |
Verbose ifTrue:[ |
|
365 |
Transcript show:'version = '; |
|
366 |
show:(majorVsn printString); |
|
367 |
show:'.'; |
|
368 |
showCR:(minorVsn printString). |
|
369 |
]. |
|
1 | 370 |
|
371 |
"/ |
|
372 |
"/ get constant pool |
|
373 |
"/ |
|
374 |
self readConstantPool. |
|
375 |
||
376 |
"/ |
|
377 |
"/ access flags |
|
378 |
"/ |
|
379 |
access_flags := self nextU2. |
|
380 |
this_class_index := self nextU2. |
|
381 |
super_class_index := self nextU2. |
|
382 |
||
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
383 |
super_class_index == 0 ifTrue:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
384 |
super_class := nil |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
385 |
] ifFalse:[ |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
386 |
super_class := constants at:super_class_index. |
32 | 387 |
existingSuperClass := Java classNamed:super_class fullName. |
21 | 388 |
existingSuperClass notNil ifTrue:[ |
389 |
super_class := existingSuperClass |
|
54 | 390 |
] ifFalse:[ |
391 |
(super_class isMemberOf:JavaUnresolvedClassConstant) ifTrue:[ |
|
91 | 392 |
Silent ifFalse:[ |
393 |
'load superClass: ' print. super_class fullName printCR. |
|
54 | 394 |
]. |
91 | 395 |
|
396 |
existingSuperClass := self class |
|
397 |
loadClassLazy:(super_class fullName) |
|
398 |
ignoring:classesbeingLoaded. |
|
399 |
||
72 | 400 |
existingSuperClass isNil ifTrue:[ |
54 | 401 |
self halt:('cannot find superclass: ' , super_class fullName). |
72 | 402 |
]. |
403 |
super_class := existingSuperClass |
|
91 | 404 |
] ifFalse:[ |
405 |
self halt:'oops - superclass ?' |
|
406 |
] |
|
29 | 407 |
]. |
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
408 |
]. |
1 | 409 |
|
410 |
"/ |
|
411 |
"/ get interfaces |
|
412 |
"/ |
|
38 | 413 |
interfaces := self readInterfaces. |
1 | 414 |
|
415 |
"/ |
|
416 |
"/ get fields |
|
417 |
"/ |
|
38 | 418 |
fields := self readFieldInfofields. |
40 | 419 |
|
420 |
"/ |
|
421 |
"/ create the fields as instVars |
|
422 |
"/ static fields are created as class-InstVars |
|
423 |
"/ |
|
424 |
staticFields := fields select:[:f | f isStatic]. |
|
425 |
nStatic := staticFields size. |
|
426 |
||
427 |
this_class_ref := constants at:this_class_index. |
|
428 |
nStatic ~~ 0 ifTrue:[ |
|
429 |
fields := fields select:[:f | f isStatic not]. |
|
430 |
||
431 |
this_class := JavaClass fullName:(this_class_ref fullName) numStatic:nStatic. |
|
91 | 432 |
|
40 | 433 |
JavaClass setInstanceVariableStringFromFields:staticFields in:this_class class. |
59 | 434 |
this_class setStaticFields:staticFields. |
60 | 435 |
this_class initializeStaticFields. |
40 | 436 |
] ifFalse:[ |
91 | 437 |
this_class := JavaClass fullName:(this_class_ref fullName) numStatic:0. |
40 | 438 |
]. |
439 |
||
440 |
this_class setAccessFlags:access_flags. |
|
441 |
this_class setSuperclass:super_class. |
|
442 |
this_class setConstantPool:constants. |
|
443 |
||
52 | 444 |
this_class setFields:fields. |
110 | 445 |
this_class setInterfaces:interfaces. |
1 | 446 |
|
447 |
"/ |
|
448 |
"/ get methods |
|
449 |
"/ |
|
38 | 450 |
self readMethodsFor:this_class. |
1 | 451 |
|
5 | 452 |
self readAttributesFor:this_class. |
453 |
||
91 | 454 |
constants owner:this_class. |
455 |
||
5 | 456 |
^ this_class |
457 |
||
1 | 458 |
" |
459 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
460 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
9 | 461 |
|
462 |
JavaClassReader verbose:true. |
|
463 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/ArithmeticException.class' |
|
464 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/ArithmeticException.class' |
|
1 | 465 |
" |
466 |
||
467 |
"Created: 15.4.1996 / 15:02:47 / cg" |
|
468 |
"Modified: 15.4.1996 / 16:51:48 / cg" |
|
469 |
! |
|
470 |
||
5 | 471 |
readSourceFileAttributeFor:aJavaClass |
472 |
|attribute_length sourceFile_index sourceFile| |
|
473 |
||
474 |
attribute_length := self nextU4. |
|
475 |
||
476 |
sourceFile_index := self nextU2. |
|
477 |
sourceFile := constants at:sourceFile_index. |
|
478 |
||
479 |
aJavaClass setSourceFile:sourceFile. |
|
480 |
||
61 | 481 |
Verbose ifTrue:[Transcript show:'sourceFile: '; showCR:sourceFile]. |
5 | 482 |
^ true |
483 |
||
484 |
" |
|
485 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
486 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
487 |
" |
|
488 |
||
489 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
490 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
491 |
! |
|
492 |
||
54 | 493 |
readStream:aStream ignoring:classesBeingLoaded |
7 | 494 |
"reads a class from aStream and returns it. |
495 |
The JavaClass is not installed as global" |
|
496 |
||
5 | 497 |
inStream := aStream. |
498 |
inStream binary. |
|
38 | 499 |
|
54 | 500 |
^ self readClassFileIgnoring:classesBeingLoaded |
5 | 501 |
|
502 |
" |
|
503 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
504 |
" |
|
505 |
||
506 |
"Created: 15.4.1996 / 15:00:55 / cg" |
|
507 |
"Modified: 15.4.1996 / 15:06:18 / cg" |
|
508 |
! ! |
|
509 |
||
510 |
!JavaClassReader methodsFor:'file reading - attributes'! |
|
511 |
||
512 |
readAttribute:attributeName for:something |
|
83 | 513 |
|
5 | 514 |
(attributeName = 'Code') ifTrue:[ |
515 |
self readCodeAttributeFor:something. |
|
516 |
^ true. |
|
517 |
]. |
|
83 | 518 |
(attributeName = 'Exceptions') ifTrue:[ |
519 |
self readExceptionsAttributeFor:something. |
|
520 |
^ true. |
|
521 |
]. |
|
5 | 522 |
(attributeName = 'LineNumberTable') ifTrue:[ |
523 |
self readLineNumberTableAttributeFor:something. |
|
524 |
^ true. |
|
525 |
]. |
|
526 |
(attributeName = 'LocalVariableTable') ifTrue:[ |
|
527 |
self readLocalVariableTableAttributeFor:something. |
|
528 |
^ true. |
|
529 |
]. |
|
530 |
(attributeName = 'ConstantValue') ifTrue:[ |
|
531 |
self readConstantValueAttributeFor:something. |
|
532 |
^ true. |
|
533 |
]. |
|
534 |
(attributeName = 'SourceFile') ifTrue:[ |
|
535 |
self readSourceFileAttributeFor:something. |
|
536 |
^ true. |
|
537 |
]. |
|
83 | 538 |
|
539 |
('JAVA: unrecognized attribute: ' , attributeName) infoPrintCR. |
|
5 | 540 |
^ false |
541 |
||
542 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
543 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
544 |
! |
|
545 |
||
546 |
readAttributeFor:something |
|
547 |
|attribute_name_index attribute_name attribute_length attribute_info| |
|
548 |
||
61 | 549 |
Verbose ifTrue:[Transcript show:'attrib at pos: '; showCR:inStream position]. |
9 | 550 |
|
5 | 551 |
attribute_name_index := self nextU2. |
9 | 552 |
|
553 |
"/ |
|
554 |
"/ UNDOC feature ? |
|
555 |
"/ |
|
556 |
attribute_name_index > constants size ifTrue:[ |
|
557 |
attribute_name_index == 16rb700 ifTrue:[ |
|
558 |
self halt. |
|
559 |
] |
|
560 |
]. |
|
561 |
||
5 | 562 |
attribute_name := constants at:attribute_name_index. |
9 | 563 |
|
61 | 564 |
Verbose ifTrue:[Transcript show:'attrib name: '; showCR:attribute_name]. |
9 | 565 |
|
5 | 566 |
(self readAttribute:attribute_name for:something) ifFalse:[ |
567 |
attribute_length := self nextU4. |
|
568 |
attribute_info := ByteArray new:(attribute_length). |
|
569 |
inStream nextBytes:attribute_length into:attribute_info startingAt:1. |
|
570 |
||
61 | 571 |
Verbose ifTrue:[Transcript show:'skipped '; show:attribute_name; showCR:'-attribute']. |
5 | 572 |
]. |
573 |
||
574 |
" |
|
575 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
576 |
" |
|
577 |
||
578 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
579 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
580 |
! |
|
581 |
||
582 |
readAttributesFor:something |
|
583 |
|attributes_count| |
|
584 |
||
585 |
attributes_count := self nextU2. |
|
586 |
||
587 |
1 to:attributes_count do:[:i | |
|
588 |
self readAttributeFor:something. |
|
589 |
]. |
|
590 |
||
591 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
592 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
593 |
! ! |
|
594 |
||
595 |
!JavaClassReader methodsFor:'file reading - constants'! |
|
596 |
||
1 | 597 |
readConstant |
598 |
|tag constReader const| |
|
599 |
||
600 |
||
11 | 601 |
constNeeds2Slots := false. |
602 |
||
1 | 603 |
"/ |
604 |
"/ get tag |
|
605 |
"/ |
|
606 |
tag := self nextU1. |
|
61 | 607 |
Verbose ifTrue:[Transcript show:'tag = '; showCR:tag]. |
1 | 608 |
|
609 |
constReader := #( |
|
91 | 610 |
readConstant_Asciz "/ 1 - now called Utf8 |
611 |
readConstant_Unicode "/ 2 |
|
1 | 612 |
readConstant_Integer "/ 3 |
613 |
readConstant_Float "/ 4 |
|
614 |
readConstant_Long "/ 5 |
|
615 |
readConstant_Double "/ 6 |
|
616 |
readConstant_Class "/ 7 |
|
617 |
readConstant_String "/ 8 |
|
618 |
readConstant_Fieldref "/ 9 |
|
619 |
readConstant_Methodref "/ 10 |
|
620 |
readConstant_InterfaceMethodref "/ 11 |
|
91 | 621 |
readConstant_NameAndType "/ 12 |
1 | 622 |
) at:tag ifAbsent:[#readConstant_Undef]. |
623 |
||
624 |
^ self perform:constReader. |
|
625 |
||
626 |
" |
|
627 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
628 |
" |
|
629 |
||
630 |
"Created: 15.4.1996 / 15:46:32 / cg" |
|
631 |
"Modified: 15.4.1996 / 15:47:00 / cg" |
|
632 |
! |
|
633 |
||
634 |
readConstantPool |
|
11 | 635 |
|constantPoolCount const i| |
1 | 636 |
|
637 |
"/ |
|
638 |
"/ get constant pool |
|
639 |
"/ |
|
640 |
constantPoolCount := self nextU2. |
|
61 | 641 |
Verbose ifTrue:[Transcript show:'constantPoolCount = '; showCR:constantPoolCount]. |
1 | 642 |
|
91 | 643 |
constants := JavaConstantPool "Array" new:constantPoolCount-1. |
1 | 644 |
|
21 | 645 |
constSlot := 1. |
646 |
[constSlot < constantPoolCount] whileTrue:[ |
|
61 | 647 |
Verbose ifTrue:[Transcript show:'const: '; showCR:constSlot]. |
1 | 648 |
const := self readConstant. |
21 | 649 |
constants at:constSlot put:const. |
11 | 650 |
constNeeds2Slots ifTrue:[ |
21 | 651 |
constSlot := constSlot + 1. |
11 | 652 |
]. |
21 | 653 |
constSlot := constSlot + 1. |
1 | 654 |
]. |
655 |
||
52 | 656 |
constSlot := -1. |
657 |
||
91 | 658 |
"/ preresolve what can be (especially, strings are resolved here) |
659 |
||
1 | 660 |
1 to:constantPoolCount-1 do:[:i | |
67 | 661 |
|const value| |
1 | 662 |
|
663 |
const := constants at:i. |
|
38 | 664 |
const notNil ifTrue:[ "/ kludge for 2-slot constants (which only take 1 slot in ST/X) |
91 | 665 |
(const isKindOf:JavaUnresolvedConstant) ifTrue:[ |
666 |
value := const preResolve. |
|
667 |
value ~~ const ifTrue:[ |
|
668 |
constants at:i put:value. |
|
669 |
] |
|
670 |
] |
|
11 | 671 |
] |
1 | 672 |
]. |
673 |
||
674 |
" |
|
675 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
676 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
677 |
" |
|
678 |
||
679 |
"Created: 15.4.1996 / 15:14:11 / cg" |
|
680 |
"Modified: 15.4.1996 / 16:41:57 / cg" |
|
681 |
! |
|
682 |
||
683 |
readConstant_Asciz |
|
684 |
|len string| |
|
685 |
||
686 |
len := self nextU2. |
|
687 |
string := String new:len. |
|
688 |
inStream nextBytes:len into:string startingAt:1. |
|
689 |
||
61 | 690 |
Verbose ifTrue:[Transcript show:'asciz; string= '; showCR:string]. |
1 | 691 |
|
692 |
^ string |
|
693 |
||
694 |
" |
|
695 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
696 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
697 |
" |
|
698 |
||
699 |
"Created: 15.4.1996 / 15:15:35 / cg" |
|
700 |
"Modified: 15.4.1996 / 16:33:45 / cg" |
|
701 |
! |
|
702 |
||
703 |
readConstant_Class |
|
52 | 704 |
|name_index name| |
1 | 705 |
|
706 |
name_index := self nextU2. |
|
707 |
||
61 | 708 |
Verbose ifTrue:[Transcript show:'class; index= '; showCR:name_index]. |
1 | 709 |
|
52 | 710 |
name := constants at:name_index. |
711 |
name notNil ifTrue:[ |
|
712 |
self halt |
|
713 |
]. |
|
714 |
||
21 | 715 |
^ JavaUnresolvedClassConstant |
91 | 716 |
pool:constants |
717 |
poolIndex:constSlot |
|
21 | 718 |
nameIndex:name_index |
91 | 719 |
|
1 | 720 |
" |
721 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
722 |
" |
|
723 |
||
724 |
"Created: 15.4.1996 / 15:21:13 / cg" |
|
725 |
"Modified: 15.4.1996 / 15:49:32 / cg" |
|
726 |
! |
|
727 |
||
11 | 728 |
readConstant_Double |
729 |
|high low aFloat| |
|
730 |
||
731 |
high := self nextU4. |
|
732 |
low := self nextU4. |
|
733 |
||
734 |
aFloat := Float new. |
|
735 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
736 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
|
737 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
738 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
739 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
740 |
aFloat basicAt:5 put:((low bitShift:-24) bitAnd:16rFF). |
|
741 |
aFloat basicAt:6 put:((low bitShift:-16) bitAnd:16rFF). |
|
742 |
aFloat basicAt:7 put:((low bitShift:-8) bitAnd:16rFF). |
|
743 |
aFloat basicAt:8 put:(low bitAnd:16rFF). |
|
744 |
] ifFalse:[ |
|
745 |
aFloat basicAt:1 put:(low bitAnd:16rFF). |
|
746 |
aFloat basicAt:2 put:((low bitShift:-8) bitAnd:16rFF). |
|
747 |
aFloat basicAt:3 put:((low bitShift:-16) bitAnd:16rFF). |
|
748 |
aFloat basicAt:4 put:((low bitShift:-24) bitAnd:16rFF). |
|
749 |
aFloat basicAt:5 put:(high bitAnd:16rFF). |
|
750 |
aFloat basicAt:6 put:((high bitShift:-8) bitAnd:16rFF). |
|
751 |
aFloat basicAt:7 put:((high bitShift:-16) bitAnd:16rFF). |
|
752 |
aFloat basicAt:8 put:((high bitShift:-24) bitAnd:16rFF). |
|
753 |
]. |
|
754 |
||
755 |
constNeeds2Slots := true. |
|
756 |
||
61 | 757 |
Verbose ifTrue:[Transcript show:'double; value= '; showCR:aFloat]. |
11 | 758 |
^ aFloat |
759 |
||
760 |
" |
|
761 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
762 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
763 |
" |
|
764 |
||
765 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
766 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
767 |
! |
|
768 |
||
1 | 769 |
readConstant_Fieldref |
770 |
|class_index name_and_type_index| |
|
771 |
||
772 |
class_index := self nextU2. |
|
773 |
name_and_type_index := self nextU2. |
|
774 |
||
61 | 775 |
Verbose ifTrue:[Transcript show:'fieldref; classindex= '; showCR:class_index]. |
776 |
Verbose ifTrue:[Transcript show:'fieldref; name&typeindex= '; showCR:name_and_type_index]. |
|
1 | 777 |
|
91 | 778 |
^ JavaUnresolvedFieldrefConstant |
779 |
pool:constants |
|
780 |
poolIndex:constSlot |
|
1 | 781 |
classIndex:class_index |
782 |
nameandTypeIndex:name_and_type_index |
|
783 |
||
784 |
" |
|
785 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
786 |
" |
|
787 |
||
788 |
"Created: 15.4.1996 / 15:22:18 / cg" |
|
789 |
"Modified: 15.4.1996 / 16:07:01 / cg" |
|
790 |
! |
|
791 |
||
11 | 792 |
readConstant_Float |
793 |
|high aFloat| |
|
794 |
||
795 |
high := self nextU4. |
|
796 |
||
797 |
aFloat := ShortFloat basicNew. |
|
798 |
UninterpretedBytes isBigEndian ifTrue:[ |
|
799 |
aFloat basicAt:1 put:((high bitShift:-24) bitAnd:16rFF). |
|
800 |
aFloat basicAt:2 put:((high bitShift:-16) bitAnd:16rFF). |
|
801 |
aFloat basicAt:3 put:((high bitShift:-8) bitAnd:16rFF). |
|
802 |
aFloat basicAt:4 put:(high bitAnd:16rFF). |
|
803 |
] ifFalse:[ |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
804 |
aFloat basicAt:1 put:(high bitAnd:16rFF). |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
805 |
aFloat basicAt:2 put:((high bitShift:-8) bitAnd:16rFF). |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
806 |
aFloat basicAt:3 put:((high bitShift:-16) bitAnd:16rFF). |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
807 |
aFloat basicAt:4 put:((high bitShift:-24) bitAnd:16rFF). |
11 | 808 |
]. |
809 |
||
61 | 810 |
Verbose ifTrue:[Transcript show:'float; value= '; showCR:aFloat]. |
11 | 811 |
^ aFloat |
812 |
||
813 |
" |
|
814 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
815 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
816 |
" |
|
817 |
||
818 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
819 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
820 |
! |
|
821 |
||
1 | 822 |
readConstant_Integer |
823 |
|value| |
|
824 |
||
60 | 825 |
value := self nextS4. |
1 | 826 |
|
61 | 827 |
Verbose ifTrue:[Transcript show:'integer; value= '; showCR:value]. |
1 | 828 |
|
829 |
^ value |
|
830 |
||
831 |
" |
|
832 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
833 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
834 |
" |
|
835 |
||
836 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
837 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
838 |
! |
|
839 |
||
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
840 |
readConstant_InterfaceMethodref |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
841 |
|class_index name_and_type_index| |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
842 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
843 |
class_index := self nextU2. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
844 |
name_and_type_index := self nextU2. |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
845 |
|
61 | 846 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
847 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
848 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
849 |
^ JavaUnresolvedInterfaceMethodrefConstant |
91 | 850 |
pool:constants |
851 |
poolIndex:constSlot |
|
14
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
852 |
classIndex:class_index |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
853 |
nameandTypeIndex:name_and_type_index |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
854 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
855 |
" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
856 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
857 |
" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
858 |
|
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
859 |
"Created: 15.4.1996 / 15:22:37 / cg" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
860 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
861 |
! |
c1d9f60eb650
can now load all java.class files (see JavaClassReader>>loadFile:)
cg
parents:
11
diff
changeset
|
862 |
|
11 | 863 |
readConstant_Long |
864 |
|high low value| |
|
865 |
||
866 |
high := self nextU4. |
|
867 |
low := self nextU4. |
|
868 |
||
869 |
value := (high bitShift:32) bitOr:low. |
|
60 | 870 |
(high bitTest:16r80000000) ifTrue:[ |
871 |
value := value - 16r10000000000000000. |
|
872 |
]. |
|
11 | 873 |
constNeeds2Slots := true. |
874 |
||
61 | 875 |
Verbose ifTrue:[Transcript show:'long; value= '; showCR:value]. |
11 | 876 |
^ value |
877 |
||
878 |
" |
|
879 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
880 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
881 |
" |
|
882 |
||
883 |
"Modified: 15.4.1996 / 15:42:16 / cg" |
|
884 |
"Created: 15.4.1996 / 16:34:42 / cg" |
|
885 |
! |
|
886 |
||
1 | 887 |
readConstant_Methodref |
888 |
|class_index name_and_type_index| |
|
889 |
||
890 |
class_index := self nextU2. |
|
891 |
name_and_type_index := self nextU2. |
|
892 |
||
61 | 893 |
Verbose ifTrue:[Transcript show:'methodref; classindex= '; showCR:class_index]. |
894 |
Verbose ifTrue:[Transcript show:'methodref; name&typeindex= '; showCR:name_and_type_index]. |
|
1 | 895 |
|
896 |
^ JavaUnresolvedMethodrefConstant |
|
91 | 897 |
pool:constants |
898 |
poolIndex:constSlot |
|
1 | 899 |
classIndex:class_index |
900 |
nameandTypeIndex:name_and_type_index |
|
901 |
||
902 |
" |
|
903 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
904 |
" |
|
905 |
||
906 |
"Created: 15.4.1996 / 15:22:37 / cg" |
|
907 |
"Modified: 15.4.1996 / 16:07:19 / cg" |
|
908 |
! |
|
909 |
||
91 | 910 |
readConstant_NameAndType |
1 | 911 |
|name_index signature_index| |
912 |
||
913 |
name_index := self nextU2. |
|
914 |
signature_index := self nextU2. |
|
915 |
||
61 | 916 |
Verbose ifTrue:[Transcript show:'methodref; nameindex= '; showCR:name_index]. |
917 |
Verbose ifTrue:[Transcript show:'methodref; signatureindex= '; showCR:signature_index]. |
|
1 | 918 |
|
919 |
^ JavaUnresolvedNameandTypeConstant |
|
91 | 920 |
pool:constants |
921 |
poolIndex:constSlot |
|
1 | 922 |
nameIndex:name_index |
91 | 923 |
signatureIndex:signature_index |
1 | 924 |
|
925 |
" |
|
926 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
927 |
" |
|
928 |
||
929 |
"Created: 15.4.1996 / 15:23:43 / cg" |
|
930 |
"Modified: 15.4.1996 / 16:17:16 / cg" |
|
931 |
! |
|
932 |
||
933 |
readConstant_String |
|
934 |
|tag string_index| |
|
935 |
||
936 |
string_index := self nextU2. |
|
937 |
||
61 | 938 |
Verbose ifTrue:[Transcript show:'string; index= '; showCR:string_index]. |
1 | 939 |
|
91 | 940 |
^ JavaUnresolvedStringConstant |
941 |
pool:constants |
|
942 |
poolIndex:constSlot |
|
943 |
stringIndex:string_index |
|
1 | 944 |
|
945 |
" |
|
43 | 946 |
Verbose := true. |
947 |
JavaClassReader readFile:'/phys/ibm3/java/lib/java/lang/System.class' |
|
1 | 948 |
" |
949 |
||
950 |
"Created: 15.4.1996 / 15:20:33 / cg" |
|
951 |
"Modified: 15.4.1996 / 16:01:37 / cg" |
|
5 | 952 |
! ! |
953 |
||
954 |
!JavaClassReader methodsFor:'file reading - fields'! |
|
955 |
||
956 |
readConstantValueAttributeFor:aField |
|
957 |
|attribute_length constantvalue_index constantValue| |
|
958 |
||
959 |
attribute_length := self nextU4. |
|
960 |
||
961 |
constantvalue_index := self nextU2. |
|
962 |
constantValue := constants at:constantvalue_index. |
|
963 |
||
59 | 964 |
aField constantValue:constantValue. |
965 |
||
61 | 966 |
Verbose ifTrue:[Transcript show:'constantValue: '; showCR:constantValue]. |
5 | 967 |
^ true |
968 |
||
969 |
" |
|
970 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
971 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
|
972 |
" |
|
973 |
||
974 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
975 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1 | 976 |
! |
977 |
||
978 |
readFieldInfofield |
|
5 | 979 |
|access_flags name_index signature_index attributes_count field| |
1 | 980 |
|
981 |
access_flags := self nextU2. |
|
982 |
name_index := self nextU2. |
|
983 |
signature_index := self nextU2. |
|
5 | 984 |
|
985 |
field := JavaField new. |
|
986 |
field setAccessFlags:access_flags. |
|
987 |
field setName:(constants at:name_index). |
|
988 |
field setSignature:(constants at:signature_index). |
|
989 |
||
1 | 990 |
attributes_count := self nextU2. |
991 |
||
99 | 992 |
Verbose ifTrue:[Transcript show:' field name: '; show:(constants at:name_index); |
993 |
show:' access: '; show:access_flags; |
|
994 |
show:' attrib_cnt: '; showCR:attributes_count]. |
|
995 |
||
1 | 996 |
1 to:attributes_count do:[:i | |
5 | 997 |
self readAttributeFor:field. |
1 | 998 |
]. |
999 |
||
27 | 1000 |
^ field |
1001 |
||
1 | 1002 |
" |
1003 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1004 |
" |
|
1005 |
||
1006 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1007 |
"Created: 15.4.1996 / 15:38:43 / cg" |
|
1008 |
! |
|
1009 |
||
1010 |
readFieldInfofields |
|
38 | 1011 |
|nFields fields| |
1 | 1012 |
|
1013 |
"/ |
|
38 | 1014 |
"/ get fieldInfos |
1 | 1015 |
"/ |
27 | 1016 |
nFields := self nextU2. |
61 | 1017 |
Verbose ifTrue:[Transcript show:'fieldsCount = '; showCR:nFields]. |
1 | 1018 |
|
27 | 1019 |
fields := Array new:nFields. |
1020 |
||
1021 |
1 to:nFields do:[:i | |
|
61 | 1022 |
Verbose ifTrue:[Transcript show:'field: '; showCR:i]. |
27 | 1023 |
fields at:i put:(self readFieldInfofield) |
1 | 1024 |
]. |
38 | 1025 |
^ fields |
1 | 1026 |
|
1027 |
" |
|
1028 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1029 |
" |
|
1030 |
||
1031 |
"Created: 15.4.1996 / 15:34:41 / cg" |
|
1032 |
"Modified: 15.4.1996 / 15:35:28 / cg" |
|
5 | 1033 |
! ! |
1034 |
||
38 | 1035 |
!JavaClassReader methodsFor:'file reading - interfaces'! |
1036 |
||
1037 |
readInterfaces |
|
110 | 1038 |
|interfacesCount interface_index interface interfaces| |
38 | 1039 |
|
1040 |
"/ |
|
1041 |
"/ get interfaces |
|
1042 |
"/ |
|
1043 |
interfacesCount := self nextU2. |
|
61 | 1044 |
Verbose ifTrue:[Transcript show:'interfacesCount = '; showCR:interfacesCount]. |
38 | 1045 |
|
1046 |
interfaces := Array new:interfacesCount. |
|
1047 |
||
1048 |
1 to:interfacesCount do:[:i | |
|
61 | 1049 |
Verbose ifTrue:[Transcript show:'interface: '; showCR:i]. |
110 | 1050 |
interface_index := self nextU2. |
1051 |
interface := constants at:interface_index. |
|
38 | 1052 |
|
1053 |
interfaces at:i put:interface. |
|
1054 |
]. |
|
1055 |
^ interfaces |
|
1056 |
||
1057 |
" |
|
1058 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1059 |
" |
|
1060 |
||
1061 |
"Created: 15.4.1996 / 15:31:59 / cg" |
|
1062 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1063 |
! ! |
|
1064 |
||
5 | 1065 |
!JavaClassReader methodsFor:'file reading - methods'! |
1066 |
||
1067 |
readCodeAttributeFor:aJavaMethod |
|
1068 |
|attribute_length max_stack max_locals code_length code |
|
9 | 1069 |
exception_table_length exception_table unknown1 unknown2| |
1 | 1070 |
|
5 | 1071 |
attribute_length := self nextU4. |
1 | 1072 |
|
9 | 1073 |
|
61 | 1074 |
Verbose ifTrue:[Transcript show:'attribute_length: 0x'; showCR:(attribute_length printStringRadix:16)]. |
9 | 1075 |
|
99 | 1076 |
minorVsn > 2 ifTrue:[ |
39 | 1077 |
unknown1 := self nextU1. |
1078 |
max_stack := self nextU1. |
|
1079 |
max_locals := self nextU2. |
|
9 | 1080 |
unknown2 := self nextU2. |
61 | 1081 |
Verbose ifTrue:[Transcript show:'?1: '; showCR:unknown1]. |
1082 |
Verbose ifTrue:[Transcript show:'?2: '; showCR:unknown2]. |
|
39 | 1083 |
] ifFalse:[ |
1084 |
max_stack := self nextU1. |
|
1085 |
max_locals := self nextU1. |
|
9 | 1086 |
]. |
1087 |
||
5 | 1088 |
code_length := self nextU2. |
61 | 1089 |
Verbose ifTrue:[Transcript show:'code_length: '; showCR:(code_length printStringRadix:16)]. |
1090 |
Verbose ifTrue:[Transcript show:'code at pos: '; showCR:inStream position]. |
|
38 | 1091 |
|
5 | 1092 |
code := ByteArray new:code_length. |
1093 |
inStream nextBytes:code_length into:code startingAt:1. |
|
1 | 1094 |
|
61 | 1095 |
Verbose ifTrue:[Transcript show:'method code:'; showCR:code.]. |
9 | 1096 |
|
5 | 1097 |
exception_table_length := self nextU2. |
61 | 1098 |
Verbose ifTrue:[Transcript show:'exception_table_length: '; showCR:(exception_table_length printStringRadix:16)]. |
5 | 1099 |
exception_table_length ~~ 0 ifTrue:[ |
61 | 1100 |
Verbose ifTrue:[Transcript show:'exceptionTable length:'; showCR:exception_table_length.]. |
9 | 1101 |
|
5 | 1102 |
exception_table := Array new:exception_table_length. |
1103 |
1 to:exception_table_length do:[:i | |
|
1104 |
|start_pc end_pc handler_pc catch_type| |
|
1 | 1105 |
|
5 | 1106 |
start_pc := self nextU2. |
1107 |
end_pc := self nextU2. |
|
1108 |
handler_pc := self nextU2. |
|
104 | 1109 |
catch_type := constants at:self nextU2. |
5 | 1110 |
exception_table at:i put:(JavaExceptionTableEntry |
1111 |
startPC:start_pc |
|
1112 |
endPC:end_pc |
|
1113 |
handlerPC:handler_pc |
|
1114 |
catchType:catch_type). |
|
1115 |
]. |
|
83 | 1116 |
aJavaMethod setExceptionHandlerTable:exception_table. |
1 | 1117 |
]. |
1118 |
||
29 | 1119 |
aJavaMethod |
1120 |
setCode:code |
|
1121 |
maxStack:max_stack |
|
1122 |
maxLocals:max_locals |
|
1123 |
u1:unknown1 |
|
1124 |
u2:unknown2. |
|
5 | 1125 |
|
1126 |
self readAttributesFor:aJavaMethod. |
|
1127 |
^ true |
|
1128 |
||
1 | 1129 |
" |
1130 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
5 | 1131 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/Alignable.class' |
1 | 1132 |
" |
1133 |
||
1134 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
5 | 1135 |
"Created: 15.4.1996 / 15:40:17 / cg" |
1136 |
! |
|
1137 |
||
83 | 1138 |
readExceptionsAttributeFor:aJavaMethod |
1139 |
|attribute_length exception_table_length exception_table| |
|
1140 |
||
1141 |
attribute_length := self nextU4. |
|
1142 |
||
1143 |
exception_table_length := self nextU2. |
|
1144 |
exception_table_length ~~ 0 ifTrue:[ |
|
1145 |
exception_table := Array new:exception_table_length. |
|
1146 |
1 to:exception_table_length do:[:i | |
|
1147 |
|idx ex| |
|
1148 |
||
1149 |
idx := self nextU2. |
|
1150 |
ex := constants at:idx. |
|
1151 |
exception_table at:i put:ex. |
|
1152 |
]. |
|
1153 |
]. |
|
1154 |
||
1155 |
Verbose ifTrue:[Transcript showCR:'method has an exceptionTable']. |
|
1156 |
||
1157 |
aJavaMethod setExceptionTable:exception_table. |
|
1158 |
^ true |
|
1159 |
||
1160 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1161 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1162 |
! |
|
1163 |
||
5 | 1164 |
readLineNumberTableAttributeFor:aJavaMethod |
1165 |
|attribute_length line_number_table_length line_number_table| |
|
1166 |
||
1167 |
attribute_length := self nextU4. |
|
1168 |
||
1169 |
line_number_table_length := self nextU2. |
|
1170 |
line_number_table_length ~~ 0 ifTrue:[ |
|
1171 |
line_number_table := Array new:line_number_table_length. |
|
1172 |
1 to:line_number_table_length do:[:i | |
|
1173 |
|start_pc line_number| |
|
1174 |
||
1175 |
start_pc := self nextU2. |
|
1176 |
line_number := self nextU2. |
|
1177 |
line_number_table at:i put:(start_pc -> line_number). |
|
1178 |
]. |
|
1179 |
]. |
|
1180 |
||
61 | 1181 |
Verbose ifTrue:[Transcript showCR:'method has a lineNumberTable']. |
9 | 1182 |
|
5 | 1183 |
aJavaMethod setLineNumberTable:line_number_table. |
1184 |
^ true |
|
1185 |
||
1186 |
" |
|
1187 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1188 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
1189 |
" |
|
1190 |
||
1191 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1192 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1 | 1193 |
! |
1194 |
||
50 | 1195 |
readLocalVariableTableAttributeFor:aJavaMethod |
1196 |
|attribute_length local_variable_table_length local_variable_table| |
|
1197 |
||
1198 |
attribute_length := self nextU4. |
|
1199 |
||
1200 |
local_variable_table_length := self nextU2. |
|
1201 |
local_variable_table_length ~~ 0 ifTrue:[ |
|
104 | 1202 |
local_variable_table := JavaLocalVariableTable new:local_variable_table_length. |
50 | 1203 |
1 to:local_variable_table_length do:[:i | |
1204 |
|start_pc length name_index sig_index slot name signature| |
|
1205 |
||
1206 |
start_pc := self nextU2. |
|
1207 |
length := self nextU2. |
|
1208 |
name_index := self nextU2. |
|
86 | 1209 |
name := constants at:name_index. |
50 | 1210 |
sig_index := self nextU2. |
86 | 1211 |
signature := constants at:sig_index. |
50 | 1212 |
slot := self nextU2. |
1213 |
||
1214 |
local_variable_table at:i put:(JavaLocalVariableTableEntry new |
|
1215 |
startPC:start_pc |
|
1216 |
length:length |
|
1217 |
name:name |
|
1218 |
signature:signature |
|
1219 |
slot:slot) |
|
1220 |
]. |
|
1221 |
]. |
|
1222 |
||
61 | 1223 |
Verbose ifTrue:[Transcript showCR:'method has a localvariableTable']. |
50 | 1224 |
|
1225 |
aJavaMethod setLocalVariableTable:local_variable_table. |
|
1226 |
^ true |
|
1227 |
||
1228 |
" |
|
1229 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1230 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/java/lang/Boolean.class' |
|
1231 |
" |
|
1232 |
||
1233 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1234 |
"Created: 15.4.1996 / 15:40:17 / cg" |
|
1235 |
! |
|
1236 |
||
38 | 1237 |
readMethodFor:aJavaClass |
9 | 1238 |
|m access_flags name_index name signature_index signature| |
1 | 1239 |
|
1240 |
"/ |
|
1241 |
"/ get a method |
|
1242 |
"/ |
|
1243 |
access_flags := self nextU2. |
|
1244 |
name_index := self nextU2. |
|
1245 |
signature_index := self nextU2. |
|
1246 |
||
5 | 1247 |
name := constants at:name_index. |
1248 |
signature := constants at:signature_index. |
|
9 | 1249 |
|
61 | 1250 |
Verbose ifTrue:[Transcript show:'method name:'; showCR:name. |
1251 |
Transcript show:'signature:'; showCR:signature.]. |
|
9 | 1252 |
|
5 | 1253 |
m := JavaMethod new. |
1254 |
m setAccessFlags:access_flags. |
|
1255 |
m setSignature:signature. |
|
1256 |
m setName:name. |
|
38 | 1257 |
m setJavaClass:aJavaClass. |
5 | 1258 |
|
1259 |
self readAttributesFor:m. |
|
1260 |
||
38 | 1261 |
aJavaClass addMethod:m name:name signature:signature. |
1 | 1262 |
|
1263 |
" |
|
1264 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1265 |
" |
|
1266 |
||
1267 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1268 |
"Created: 15.4.1996 / 16:48:49 / cg" |
|
1269 |
! |
|
1270 |
||
38 | 1271 |
readMethodsFor:aJavaClass |
1 | 1272 |
|methodsCount method| |
1273 |
||
1274 |
||
1275 |
"/ |
|
1276 |
"/ get methods |
|
1277 |
"/ |
|
1278 |
methodsCount := self nextU2. |
|
61 | 1279 |
Verbose ifTrue:[Transcript show:'methodsCount = '; showCR:methodsCount]. |
1 | 1280 |
|
1281 |
1 to:methodsCount do:[:i | |
|
61 | 1282 |
Verbose ifTrue:[Transcript show:'method: '; showCR:i]. |
38 | 1283 |
method := self readMethodFor:aJavaClass |
1 | 1284 |
]. |
1285 |
||
1286 |
" |
|
1287 |
JavaClassReader readFile:'/phys/ibm3/hotjava/classes/browser/AddButton.class' |
|
1288 |
" |
|
1289 |
||
1290 |
"Modified: 15.4.1996 / 15:33:28 / cg" |
|
1291 |
"Created: 15.4.1996 / 16:46:30 / cg" |
|
1292 |
! ! |
|
1293 |
||
1294 |
!JavaClassReader methodsFor:'low level reading'! |
|
1295 |
||
60 | 1296 |
nextS4 |
1297 |
^ inStream nextLongMSB:msb |
|
1298 |
||
1299 |
"Created: 15.4.1996 / 15:04:28 / cg" |
|
1300 |
! |
|
1301 |
||
1 | 1302 |
nextU1 |
1303 |
^ inStream nextByte |
|
1304 |
||
1305 |
"Created: 15.4.1996 / 15:15:43 / cg" |
|
1306 |
! |
|
1307 |
||
1308 |
nextU2 |
|
1309 |
^ inStream nextUnsignedShortMSB:msb |
|
1310 |
||
1311 |
"Created: 15.4.1996 / 15:12:25 / cg" |
|
1312 |
! |
|
1313 |
||
1314 |
nextU4 |
|
1315 |
^ inStream nextUnsignedLongMSB:msb |
|
1316 |
||
1317 |
"Created: 15.4.1996 / 15:04:28 / cg" |
|
1318 |
! ! |
|
1319 |
||
62 | 1320 |
!JavaClassReader class methodsFor:'documentation'! |
1 | 1321 |
|
1322 |
version |
|
116 | 1323 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaClassReader.st,v 1.35 1996/07/05 17:31:14 cg Exp $' |
1 | 1324 |
! ! |
1325 |
JavaClassReader initialize! |