1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
153
|
3 |
All Rights Reserved
|
1
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ClassDescription subclass:#Class
|
384
|
14 |
instanceVariableNames:'classvars comment subclasses classFilename package revision history'
|
362
|
15 |
classVariableNames:'UpdatingChanges FileOutErrorSignal
|
421
|
16 |
CatchMethodRedefinitions MethodRedefinitionSignal
|
|
17 |
UpdateChangeFileQuerySignal'
|
1
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Classes'
|
|
20 |
!
|
|
21 |
|
|
22 |
Class comment:'
|
5
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
153
|
24 |
All Rights Reserved
|
92
|
25 |
|
435
|
26 |
$Header: /cvs/stx/stx/libbasic/Class.st,v 1.62 1995-09-14 23:21:46 claus Exp $
|
1
|
27 |
'!
|
|
28 |
|
68
|
29 |
!Class class methodsFor:'documentation'!
|
|
30 |
|
88
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
153
|
34 |
All Rights Reserved
|
88
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
435
|
47 |
$Header: /cvs/stx/stx/libbasic/Class.st,v 1.62 1995-09-14 23:21:46 claus Exp $
|
88
|
48 |
"
|
|
49 |
!
|
|
50 |
|
68
|
51 |
documentation
|
|
52 |
"
|
|
53 |
Class adds more functionality to classes; minimum stuff has already
|
|
54 |
been defined in Behavior and ClassDescription; this adds naming, categories etc.
|
|
55 |
|
|
56 |
Also change management and recompilation is defined here (since the superclasses
|
|
57 |
do not have enough symbolic information to support compilation).
|
|
58 |
|
168
|
59 |
For production code, the stc compiler is planned to (optionally) generate classes
|
|
60 |
as subclasses of Behavior - to excludes all name, source info etc.,
|
68
|
61 |
however, normally all classes are subclasses of Class.
|
|
62 |
|
|
63 |
Instance variables:
|
|
64 |
|
153
|
65 |
classvars <String> the names of the class variables
|
168
|
66 |
|
|
67 |
comment <String> the classes comment; either a string,
|
|
68 |
a number specifying the offset in classFilename, or nil
|
|
69 |
|
153
|
70 |
subclasses <Collection> cached collection of subclasses
|
|
71 |
(currently unused - but will be soon)
|
168
|
72 |
|
|
73 |
classFilename <String> the file (or nil) where the classes
|
|
74 |
sources are found
|
|
75 |
|
153
|
76 |
package <Symbol> the package, in which the class was defined
|
385
|
77 |
(inserted by compilers)
|
|
78 |
|
391
|
79 |
revision <String> revision string - inserted by stc
|
168
|
80 |
|
|
81 |
history <any> a place for a history string (not currently used)
|
68
|
82 |
|
|
83 |
Class variables:
|
|
84 |
|
153
|
85 |
UpdatingChanges <Boolean> true if the changes-file shall be updated
|
|
86 |
(except during startup and when filing in, this flag
|
|
87 |
is usually true)
|
68
|
88 |
|
421
|
89 |
UpdateChangeFileQuerySignal used as an upQuery from the change management.
|
|
90 |
Whenever a changeRecord is to be written,
|
|
91 |
this signal is raised and a handler (if present)
|
|
92 |
is supposed to return true or false.
|
|
93 |
If unhandled, the value of the global
|
|
94 |
UpdatingChanges is returned for backward
|
|
95 |
compatibility (which means that the old
|
|
96 |
mechanism is used if no query-handler
|
|
97 |
is present).
|
|
98 |
|
168
|
99 |
FileOutErrorSignal raised when an error occurs during fileOut
|
|
100 |
|
362
|
101 |
CatchMethodRedefinitions if true, classes protect themself
|
|
102 |
MethodRedefinitionSignal (by raising MethodRedefinitionSignal)
|
|
103 |
from redefining any existing methods,
|
|
104 |
which are defined in another package.
|
|
105 |
(i.e. a signal will be raised, if you
|
|
106 |
fileIn something which redefines an
|
|
107 |
existing method and the packages do not
|
|
108 |
match).
|
|
109 |
The default is (currently) true.
|
|
110 |
|
68
|
111 |
WARNING: layout known by compiler and runtime system
|
|
112 |
"
|
|
113 |
! !
|
|
114 |
|
1
|
115 |
!Class class methodsFor:'initialization'!
|
|
116 |
|
|
117 |
initialize
|
28
|
118 |
"the classvariable 'UpdatingChanges' controls if changes are put
|
1
|
119 |
into the changes-file; normally this variable is set to true, but
|
68
|
120 |
(for example) during fileIn or when changes are applied, it is set to false
|
|
121 |
to avoid putting too much junk into the changes-file."
|
1
|
122 |
|
153
|
123 |
UpdatingChanges := true.
|
362
|
124 |
CatchMethodRedefinitions := true.
|
|
125 |
|
153
|
126 |
FileOutErrorSignal isNil ifTrue:[
|
421
|
127 |
FileOutErrorSignal := ErrorSignal newSignalMayProceed:false.
|
153
|
128 |
FileOutErrorSignal nameClass:self message:#fileOutErrorSignal.
|
|
129 |
FileOutErrorSignal notifierString:'error during fileOut'.
|
362
|
130 |
|
421
|
131 |
MethodRedefinitionSignal := ErrorSignal newSignalMayProceed:true.
|
362
|
132 |
MethodRedefinitionSignal nameClass:self message:#methodRedefinitionSignal.
|
|
133 |
MethodRedefinitionSignal notifierString:'attempt to redefine method from different package'.
|
421
|
134 |
|
|
135 |
UpdateChangeFileQuerySignal := QuerySignal new mayProceed:true.
|
|
136 |
UpdateChangeFileQuerySignal nameClass:self message:#updateChangeFileQuerySignal.
|
|
137 |
UpdateChangeFileQuerySignal notifierString:'asking if changeFile update is wanted'.
|
|
138 |
UpdateChangeFileQuerySignal handlerBlock:[:ex | ex proceedWith:UpdatingChanges].
|
153
|
139 |
]
|
|
140 |
! !
|
|
141 |
|
345
|
142 |
!Class class methodsFor:'Signal constants'!
|
153
|
143 |
|
|
144 |
fileOutErrorSignal
|
168
|
145 |
"return the signal raised when an error occurs while fileing out.
|
|
146 |
This is signalled to allow browsers some user feed back in case
|
|
147 |
a fileout fails (for example due to disk-full errors)"
|
|
148 |
|
153
|
149 |
^ FileOutErrorSignal
|
362
|
150 |
!
|
|
151 |
|
|
152 |
methodRedefinitionSignal
|
|
153 |
"return the signal raised when a method is about to be installed
|
|
154 |
which redefines an existing method and the methods packages are not
|
|
155 |
equal. This helps when filing in alien code, to prevent existing
|
|
156 |
methods to be overwritten or redefined by incompatible methods"
|
|
157 |
|
|
158 |
^ MethodRedefinitionSignal
|
421
|
159 |
!
|
|
160 |
|
|
161 |
updateChangeFileQuerySignal
|
|
162 |
"return the signal used as an upQuery if the changeFile should be updated.
|
|
163 |
If unhandled, the value of UpdatingChanges is returned by the signals
|
|
164 |
static handler."
|
|
165 |
|
|
166 |
^ UpdateChangeFileQuerySignal
|
|
167 |
|
362
|
168 |
! !
|
|
169 |
|
|
170 |
!Class class methodsFor:'accessing - flags'!
|
|
171 |
|
|
172 |
updateChanges:aBoolean
|
|
173 |
"turn on/off changes management. Return the prior value of the flag."
|
|
174 |
|
|
175 |
|prev|
|
|
176 |
|
|
177 |
prev := UpdatingChanges.
|
|
178 |
UpdatingChanges := aBoolean.
|
|
179 |
^ prev
|
|
180 |
!
|
|
181 |
|
|
182 |
updatingChanges
|
|
183 |
"return true if changes are recorded"
|
|
184 |
|
|
185 |
^ UpdatingChanges
|
|
186 |
!
|
|
187 |
|
|
188 |
catchMethodRedefinitions
|
|
189 |
"return the redefinition catching flag."
|
|
190 |
|
|
191 |
^ CatchMethodRedefinitions
|
|
192 |
!
|
|
193 |
|
|
194 |
catchMethodRedefinitions:aBoolean
|
|
195 |
"turn on/off redefinition catching. Return the prior value of the flag."
|
|
196 |
|
|
197 |
|prev|
|
|
198 |
|
|
199 |
prev := CatchMethodRedefinitions.
|
|
200 |
CatchMethodRedefinitions := aBoolean.
|
|
201 |
^ prev
|
1
|
202 |
! !
|
|
203 |
|
193
|
204 |
!Class class methodsFor:'enumeration '!
|
|
205 |
|
|
206 |
allClassesInCategory:aCategory do:aBlock
|
|
207 |
"evaluate aBlock for all classes in aCategory;
|
|
208 |
no specific order is defined."
|
|
209 |
|
199
|
210 |
Smalltalk allBehaviorsDo:[:aClass |
|
193
|
211 |
aClass isMeta ifFalse:[
|
|
212 |
(aClass category = aCategory) ifTrue:[
|
|
213 |
aBlock value:aClass
|
|
214 |
]
|
|
215 |
].
|
|
216 |
]
|
|
217 |
|
|
218 |
"
|
|
219 |
Class allClassesInCategory:'Kernel-Classes'
|
|
220 |
do:[:class |Transcript showCr:class name]
|
|
221 |
"
|
|
222 |
!
|
|
223 |
|
|
224 |
allClassesInCategory:aCategory inOrderDo:aBlock
|
|
225 |
"evaluate aBlock for all classes in aCategory;
|
|
226 |
superclasses come first - then subclasses."
|
|
227 |
|
|
228 |
|classes|
|
|
229 |
|
|
230 |
classes := OrderedCollection new.
|
199
|
231 |
Smalltalk allBehaviorsDo:[:aClass |
|
193
|
232 |
aClass isMeta ifFalse:[
|
|
233 |
(aClass category = aCategory) ifTrue:[
|
|
234 |
classes add:aClass
|
|
235 |
]
|
|
236 |
]
|
|
237 |
].
|
|
238 |
classes topologicalSort:[:a :b | b isSubclassOf:a].
|
|
239 |
classes do:aBlock
|
|
240 |
! !
|
|
241 |
|
1
|
242 |
!Class methodsFor:'subclass creation'!
|
|
243 |
|
37
|
244 |
subclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
245 |
"create a new class as a subclass of an existing class (the receiver).
|
|
246 |
The subclass will have indexed variables if the receiving-class has."
|
|
247 |
|
|
248 |
self isVariable ifFalse:[
|
153
|
249 |
^ self class
|
|
250 |
name:t
|
|
251 |
inEnvironment:Smalltalk
|
|
252 |
subclassOf:self
|
|
253 |
instanceVariableNames:f
|
|
254 |
variable:false
|
|
255 |
words:true
|
|
256 |
pointers:true
|
|
257 |
classVariableNames:d
|
|
258 |
poolDictionaries:s
|
|
259 |
category:cat
|
|
260 |
comment:nil
|
|
261 |
changed:false
|
1
|
262 |
].
|
|
263 |
self isBytes ifTrue:[
|
153
|
264 |
^ self
|
|
265 |
variableByteSubclass:t
|
|
266 |
instanceVariableNames:f
|
|
267 |
classVariableNames:d
|
|
268 |
poolDictionaries:s
|
|
269 |
category:cat
|
1
|
270 |
].
|
|
271 |
self isLongs ifTrue:[
|
153
|
272 |
^ self
|
|
273 |
variableLongSubclass:t
|
|
274 |
instanceVariableNames:f
|
|
275 |
classVariableNames:d
|
|
276 |
poolDictionaries:s
|
|
277 |
category:cat
|
1
|
278 |
].
|
|
279 |
self isFloats ifTrue:[
|
153
|
280 |
^ self
|
|
281 |
variableFloatSubclass:t
|
|
282 |
instanceVariableNames:f
|
|
283 |
classVariableNames:d
|
|
284 |
poolDictionaries:s
|
|
285 |
category:cat
|
1
|
286 |
].
|
|
287 |
self isDoubles ifTrue:[
|
153
|
288 |
^ self
|
|
289 |
variableDoubleSubclass:t
|
|
290 |
instanceVariableNames:f
|
|
291 |
classVariableNames:d
|
|
292 |
poolDictionaries:s
|
|
293 |
category:cat
|
1
|
294 |
].
|
2
|
295 |
self isWords ifTrue:[
|
153
|
296 |
^ self
|
|
297 |
variableWordSubclass:t
|
|
298 |
instanceVariableNames:f
|
|
299 |
classVariableNames:d
|
|
300 |
poolDictionaries:s
|
|
301 |
category:cat
|
2
|
302 |
].
|
1
|
303 |
^ self
|
153
|
304 |
variableSubclass:t
|
|
305 |
instanceVariableNames:f
|
|
306 |
classVariableNames:d
|
|
307 |
poolDictionaries:s
|
|
308 |
category:cat
|
1
|
309 |
!
|
|
310 |
|
37
|
311 |
variableSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
312 |
"create a new class as a subclass of an existing class (the receiver)
|
|
313 |
in which the subclass has indexable pointer variables"
|
|
314 |
|
|
315 |
self isVariable ifTrue:[
|
153
|
316 |
self isPointers ifFalse:[
|
|
317 |
^ self error:
|
|
318 |
'cannot make a variable pointer subclass of a variable non-pointer class'
|
|
319 |
]
|
1
|
320 |
].
|
|
321 |
|
|
322 |
^ self class
|
153
|
323 |
name:t
|
|
324 |
inEnvironment:Smalltalk
|
|
325 |
subclassOf:self
|
|
326 |
instanceVariableNames:f
|
|
327 |
variable:true
|
|
328 |
words:false
|
|
329 |
pointers:true
|
|
330 |
classVariableNames:d
|
|
331 |
poolDictionaries:s
|
|
332 |
category:cat
|
|
333 |
comment:nil
|
|
334 |
changed:false
|
1
|
335 |
!
|
|
336 |
|
37
|
337 |
variableByteSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
338 |
"create a new class as a subclass of an existing class (the receiver)
|
|
339 |
in which the subclass has indexable byte-sized nonpointer variables"
|
|
340 |
|
|
341 |
self isVariable ifTrue:[
|
153
|
342 |
self isBytes ifFalse:[
|
|
343 |
^ self error:
|
|
344 |
'cannot make a variable byte subclass of a variable non-byte class'
|
|
345 |
].
|
1
|
346 |
].
|
|
347 |
|
|
348 |
^ self class
|
153
|
349 |
name:t
|
|
350 |
inEnvironment:Smalltalk
|
|
351 |
subclassOf:self
|
|
352 |
instanceVariableNames:f
|
|
353 |
variable:true
|
|
354 |
words:false
|
|
355 |
pointers:false
|
|
356 |
classVariableNames:d
|
|
357 |
poolDictionaries:s
|
|
358 |
category:cat
|
|
359 |
comment:nil
|
|
360 |
changed:false
|
1
|
361 |
!
|
|
362 |
|
54
|
363 |
variableWordSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
364 |
"create a new class as a subclass of an existing class (the receiver)
|
|
365 |
in which the subclass has indexable word-sized nonpointer variables"
|
|
366 |
|
|
367 |
self isVariable ifTrue:[
|
153
|
368 |
self isWords ifFalse:[
|
|
369 |
^ self error:
|
|
370 |
'cannot make a variable word subclass of a variable non-word class'
|
|
371 |
].
|
1
|
372 |
].
|
|
373 |
|
|
374 |
^ self class
|
153
|
375 |
name:t
|
|
376 |
inEnvironment:Smalltalk
|
|
377 |
subclassOf:self
|
|
378 |
instanceVariableNames:f
|
|
379 |
variable:true
|
|
380 |
words:true
|
|
381 |
pointers:false
|
|
382 |
classVariableNames:d
|
|
383 |
poolDictionaries:s
|
|
384 |
category:cat
|
|
385 |
comment:nil
|
|
386 |
changed:false
|
1
|
387 |
!
|
|
388 |
|
37
|
389 |
variableLongSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
390 |
"create a new class as a subclass of an existing class (the receiver)
|
|
391 |
in which the subclass has indexable long-sized nonpointer variables"
|
|
392 |
|
|
393 |
self isVariable ifTrue:[
|
153
|
394 |
self isLongs ifFalse:[
|
|
395 |
^ self error:
|
|
396 |
'cannot make a variable long subclass of a variable non-long class'
|
|
397 |
].
|
1
|
398 |
].
|
|
399 |
|
|
400 |
^ self class
|
153
|
401 |
name:t
|
|
402 |
inEnvironment:Smalltalk
|
|
403 |
subclassOf:self
|
|
404 |
instanceVariableNames:f
|
|
405 |
variable:#long
|
|
406 |
words:false
|
|
407 |
pointers:false
|
|
408 |
classVariableNames:d
|
|
409 |
poolDictionaries:s
|
|
410 |
category:cat
|
|
411 |
comment:nil
|
|
412 |
changed:false
|
1
|
413 |
!
|
|
414 |
|
37
|
415 |
variableFloatSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
416 |
|
|
417 |
"create a new class as a subclass of an existing class (the receiver)
|
|
418 |
in which the subclass has indexable float-sized nonpointer variables"
|
|
419 |
|
|
420 |
self isVariable ifTrue:[
|
153
|
421 |
self isFloats ifFalse:[
|
|
422 |
^ self error:
|
|
423 |
'cannot make a variable float subclass of a variable non-float class'
|
|
424 |
].
|
1
|
425 |
].
|
|
426 |
|
|
427 |
^ self class
|
153
|
428 |
name:t
|
|
429 |
inEnvironment:Smalltalk
|
|
430 |
subclassOf:self
|
|
431 |
instanceVariableNames:f
|
|
432 |
variable:#float
|
|
433 |
words:false
|
|
434 |
pointers:false
|
|
435 |
classVariableNames:d
|
|
436 |
poolDictionaries:s
|
|
437 |
category:cat
|
|
438 |
comment:nil
|
|
439 |
changed:false
|
1
|
440 |
!
|
|
441 |
|
37
|
442 |
variableDoubleSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
|
1
|
443 |
|
|
444 |
"create a new class as a subclass of an existing class (the receiver)
|
|
445 |
in which the subclass has indexable double-sized nonpointer variables"
|
|
446 |
|
|
447 |
self isVariable ifTrue:[
|
153
|
448 |
self isDoubles ifFalse:[
|
|
449 |
^ self error:
|
|
450 |
'cannot make a variable double subclass of a variable non-double class'
|
|
451 |
].
|
1
|
452 |
].
|
|
453 |
|
|
454 |
^ self class
|
153
|
455 |
name:t
|
|
456 |
inEnvironment:Smalltalk
|
|
457 |
subclassOf:self
|
|
458 |
instanceVariableNames:f
|
|
459 |
variable:#double
|
|
460 |
words:false
|
|
461 |
pointers:false
|
|
462 |
classVariableNames:d
|
|
463 |
poolDictionaries:s
|
|
464 |
category:cat
|
|
465 |
comment:nil
|
|
466 |
changed:false
|
1
|
467 |
! !
|
|
468 |
|
|
469 |
!Class methodsFor:'ST/V subclass creation'!
|
|
470 |
|
37
|
471 |
subclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s
|
|
472 |
"this method allows fileIn of ST/V classes
|
1
|
473 |
(which seem to have no category)"
|
|
474 |
|
|
475 |
^ self subclass:t
|
153
|
476 |
instanceVariableNames:f
|
|
477 |
classVariableNames:d
|
|
478 |
poolDictionaries:s
|
|
479 |
category:'ST/V classes'
|
1
|
480 |
!
|
|
481 |
|
37
|
482 |
variableByteSubclass:t classVariableNames:d poolDictionaries:s
|
|
483 |
"this method allows fileIn of ST/V variable byte classes
|
1
|
484 |
(which seem to have no category and no instvars)"
|
|
485 |
|
|
486 |
^ self variableByteSubclass:t
|
153
|
487 |
instanceVariableNames:''
|
|
488 |
classVariableNames:d
|
|
489 |
poolDictionaries:s
|
|
490 |
category:'ST/V classes'
|
1
|
491 |
!
|
|
492 |
|
37
|
493 |
variableSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s
|
|
494 |
"this method allows fileIn of ST/V variable pointer classes
|
1
|
495 |
(which seem to have no category)"
|
|
496 |
|
|
497 |
^ self variableSubclass:t
|
153
|
498 |
instanceVariableNames:f
|
|
499 |
classVariableNames:d
|
|
500 |
poolDictionaries:s
|
|
501 |
category:'ST/V classes'
|
1
|
502 |
! !
|
|
503 |
|
|
504 |
!Class methodsFor:'accessing'!
|
|
505 |
|
|
506 |
classVariableString
|
68
|
507 |
"return a string of the class variables names.
|
|
508 |
Only names of class variables defined in this class are in the
|
|
509 |
returned string."
|
1
|
510 |
|
|
511 |
classvars isNil ifTrue:[^ ''].
|
|
512 |
^ classvars
|
153
|
513 |
|
|
514 |
"
|
|
515 |
Object classVariableString
|
|
516 |
Float classVariableString
|
|
517 |
"
|
1
|
518 |
!
|
|
519 |
|
|
520 |
classVarNames
|
68
|
521 |
"return a collection of the class variable name-strings.
|
|
522 |
Only names of class variables defined in this class are included
|
|
523 |
in the returned collection - use allClassVarNames, to get all known names."
|
1
|
524 |
|
10
|
525 |
classvars isNil ifTrue:[
|
153
|
526 |
^ OrderedCollection new
|
10
|
527 |
].
|
|
528 |
^ classvars asCollectionOfWords
|
68
|
529 |
|
153
|
530 |
"
|
|
531 |
Object classVarNames
|
|
532 |
Float classVarNames
|
|
533 |
"
|
|
534 |
!
|
|
535 |
|
|
536 |
classVarAt:aSymbol
|
|
537 |
"return the value of a class variable.
|
|
538 |
Currently, this returns nil if there is no such classvar -
|
|
539 |
this may change."
|
|
540 |
|
|
541 |
"
|
|
542 |
this hides the (current) implementation of classVariables
|
|
543 |
from the outside world. Currently, classvars are stored in
|
|
544 |
the Smalltalk dictionary with a funny name, since there are
|
|
545 |
no classPools yet.
|
|
546 |
"
|
|
547 |
^ Smalltalk at:(self name , ':' , aSymbol) asSymbol
|
|
548 |
!
|
|
549 |
|
|
550 |
classVarAt:aSymbol put:something
|
|
551 |
"store something in a classvariable.
|
|
552 |
Currently this creates a global with a funny name if no such
|
|
553 |
classVar exists - this may change."
|
|
554 |
|
|
555 |
"
|
|
556 |
this hides the (current) implementation of classVariables
|
|
557 |
from the outside world. Currently, classvars are stored in
|
|
558 |
the Smalltalk dictionary with a funny name, since there are
|
|
559 |
no classPools yet.
|
|
560 |
"
|
|
561 |
Smalltalk at:(self name , ':' , aSymbol) asSymbol put:something.
|
1
|
562 |
!
|
|
563 |
|
|
564 |
allClassVarNames
|
|
565 |
"return a collection of all the class variable name-strings
|
|
566 |
this includes all superclass-class variables"
|
|
567 |
|
|
568 |
^ self addAllClassVarNamesTo:(OrderedCollection new)
|
68
|
569 |
|
153
|
570 |
"
|
|
571 |
Float allClassVarNames
|
|
572 |
"
|
1
|
573 |
!
|
|
574 |
|
|
575 |
comment
|
|
576 |
"return the comment (aString) of the class"
|
|
577 |
|
168
|
578 |
|stream string|
|
|
579 |
|
|
580 |
"the comment is either a string, or an integer specifying the
|
|
581 |
position within the classes sourcefile ...
|
|
582 |
"
|
|
583 |
comment isNumber ifTrue:[
|
|
584 |
classFilename notNil ifTrue:[
|
328
|
585 |
stream := Smalltalk sourceFileStreamFor:classFilename.
|
168
|
586 |
stream notNil ifTrue:[
|
|
587 |
stream position:comment.
|
216
|
588 |
string := String readFrom:stream onError:''.
|
168
|
589 |
stream close.
|
|
590 |
^ string
|
|
591 |
]
|
|
592 |
]
|
|
593 |
].
|
1
|
594 |
^ comment
|
153
|
595 |
|
|
596 |
"
|
|
597 |
Object comment
|
|
598 |
"
|
|
599 |
!
|
1
|
600 |
|
|
601 |
setComment:aString
|
|
602 |
"set the comment of the class to be the argument, aString;
|
|
603 |
do NOT create a change record"
|
|
604 |
|
|
605 |
comment := aString
|
|
606 |
!
|
|
607 |
|
|
608 |
comment:aString
|
|
609 |
"set the comment of the class to be the argument, aString;
|
153
|
610 |
create a change record and notify dependents."
|
|
611 |
|
|
612 |
|oldComment|
|
1
|
613 |
|
10
|
614 |
comment ~= aString ifTrue:[
|
168
|
615 |
oldComment := self comment.
|
153
|
616 |
comment := aString.
|
|
617 |
self changed:#comment with:oldComment.
|
|
618 |
self addChangeRecordForClassComment:self.
|
10
|
619 |
]
|
|
620 |
!
|
|
621 |
|
216
|
622 |
package
|
|
623 |
"return the package of the class"
|
|
624 |
|
|
625 |
^ package
|
|
626 |
|
|
627 |
"
|
|
628 |
Object package
|
|
629 |
"
|
|
630 |
!
|
|
631 |
|
|
632 |
setPackage:aStringOrSymbol
|
|
633 |
"set the package of the class."
|
|
634 |
|
|
635 |
package := aStringOrSymbol
|
|
636 |
!
|
|
637 |
|
|
638 |
package:aStringOrSymbol
|
|
639 |
"set the package of the class."
|
|
640 |
|
|
641 |
package := aStringOrSymbol
|
|
642 |
!
|
|
643 |
|
385
|
644 |
revision
|
|
645 |
"return the revision-ID of the class.
|
|
646 |
This is valid for stc-compiled classes only, and corresponds to the
|
|
647 |
rcs-id of the source from which this class was compiled.
|
|
648 |
To check if a source corresponds to a compiled binary, compare this
|
|
649 |
ID with the one found in the version-methods comment."
|
|
650 |
|
|
651 |
^ revision
|
|
652 |
|
|
653 |
"
|
|
654 |
Object revision
|
|
655 |
"
|
|
656 |
!
|
|
657 |
|
|
658 |
revision:aString
|
|
659 |
"set the revision-ID.
|
|
660 |
This should normally not be done in the running system, as the source-manager
|
|
661 |
will need this to validate sourcefiles being correct for a given binary
|
|
662 |
(and optionally: extracting the required sourcefile from the rcs source)"
|
|
663 |
|
|
664 |
revision := aString
|
|
665 |
!
|
|
666 |
|
216
|
667 |
history
|
|
668 |
"return the history of the class"
|
|
669 |
|
|
670 |
^ history
|
|
671 |
|
|
672 |
"
|
|
673 |
Object history
|
|
674 |
"
|
|
675 |
!
|
|
676 |
|
|
677 |
setHistory:aString
|
|
678 |
"set the history of the class."
|
|
679 |
|
|
680 |
history := aString
|
|
681 |
!
|
|
682 |
|
|
683 |
history:aString
|
|
684 |
"set the history of the class."
|
|
685 |
|
|
686 |
history := aString
|
|
687 |
!
|
|
688 |
|
|
689 |
primitiveSpec
|
|
690 |
"return the primitiveSpec or nil"
|
|
691 |
|
|
692 |
^ primitiveSpec
|
|
693 |
!
|
|
694 |
|
357
|
695 |
primitiveSpec:anArrayOf3ElementsOrNil
|
|
696 |
"set the primitiveSpec or nil"
|
|
697 |
|
|
698 |
primitiveSpec := anArrayOf3ElementsOrNil
|
|
699 |
!
|
|
700 |
|
216
|
701 |
primitiveDefinitionsString
|
|
702 |
"return the primitiveDefinition string or nil"
|
|
703 |
|
357
|
704 |
^ self getPrimitiveSpecsAt:1
|
216
|
705 |
|
|
706 |
"
|
|
707 |
Object primitiveDefinitionsString
|
|
708 |
String primitiveDefinitionsString
|
|
709 |
"
|
|
710 |
!
|
|
711 |
|
|
712 |
primitiveVariablesString
|
|
713 |
"return the primitiveVariables string or nil"
|
|
714 |
|
357
|
715 |
^ self getPrimitiveSpecsAt:2
|
216
|
716 |
!
|
|
717 |
|
|
718 |
primitiveFunctionsString
|
|
719 |
"return the primitiveFunctions string or nil"
|
|
720 |
|
357
|
721 |
^ self getPrimitiveSpecsAt:3
|
216
|
722 |
!
|
|
723 |
|
|
724 |
primitiveDefinitions:aString
|
|
725 |
"set the primitiveDefinition string"
|
|
726 |
|
360
|
727 |
self setPrimitiveSpecsAt:1 to:aString.
|
|
728 |
self addChangeRecordForPrimitiveDefinitions:self
|
216
|
729 |
!
|
|
730 |
|
|
731 |
primitiveVariables:aString
|
|
732 |
"set the primitiveVariable string"
|
|
733 |
|
360
|
734 |
self setPrimitiveSpecsAt:2 to:aString.
|
|
735 |
self addChangeRecordForPrimitiveVariables:self
|
216
|
736 |
!
|
|
737 |
|
|
738 |
primitiveFunctions:aString
|
|
739 |
"set the primitiveFunction string"
|
|
740 |
|
360
|
741 |
self setPrimitiveSpecsAt:3 to:aString.
|
|
742 |
self addChangeRecordForPrimitiveFunctions:self
|
216
|
743 |
!
|
|
744 |
|
168
|
745 |
classFilename
|
153
|
746 |
"return the name of the file from which the class was compiled.
|
|
747 |
This is currently NOT used."
|
10
|
748 |
|
168
|
749 |
^ classFilename
|
1
|
750 |
!
|
|
751 |
|
423
|
752 |
setClassFilename:aFilename
|
|
753 |
"set the classes filename.
|
|
754 |
This is a dangerous (low level) operation, since the
|
|
755 |
comment and primitiveSpecs may no longer be accessable, if a wrong filename
|
|
756 |
is set here."
|
|
757 |
|
|
758 |
classFilename := aFilename
|
|
759 |
|
|
760 |
"Modified: 8.9.1995 / 14:16:48 / claus"
|
|
761 |
!
|
|
762 |
|
1
|
763 |
definition
|
|
764 |
"return an expression-string to define myself"
|
|
765 |
|
|
766 |
|s|
|
|
767 |
|
|
768 |
s := WriteStream on:(String new).
|
|
769 |
self fileOutDefinitionOn:s.
|
|
770 |
^ s contents
|
|
771 |
|
153
|
772 |
"
|
|
773 |
Object definition
|
|
774 |
Point definition
|
|
775 |
"
|
1
|
776 |
!
|
|
777 |
|
199
|
778 |
source
|
|
779 |
"return the classes full source code"
|
|
780 |
|
|
781 |
|code aStream|
|
|
782 |
|
|
783 |
" this is too slow for big classes ...
|
|
784 |
code := String new:1000.
|
|
785 |
aStream := WriteStream on:code.
|
|
786 |
self fileOutOn:aStream
|
|
787 |
"
|
|
788 |
aStream := FileStream newFileNamed:'__temp'.
|
|
789 |
aStream isNil ifTrue:[
|
|
790 |
self notify:'cannot create temporary file.'.
|
|
791 |
^ nil
|
|
792 |
].
|
399
|
793 |
FileOutErrorSignal handle:[:ex |
|
|
794 |
aStream nextPutAll:'"no source available"'.
|
|
795 |
] do:[
|
403
|
796 |
self fileOutOn:aStream.
|
399
|
797 |
].
|
199
|
798 |
aStream close.
|
|
799 |
aStream := FileStream oldFileNamed:'__temp'.
|
|
800 |
aStream isNil ifTrue:[
|
|
801 |
self notify:'oops - cannot reopen temp file'.
|
|
802 |
^ nil
|
|
803 |
].
|
|
804 |
code := aStream contents.
|
|
805 |
aStream close.
|
|
806 |
OperatingSystem removeFile:'__temp'.
|
|
807 |
^ code
|
|
808 |
!
|
|
809 |
|
68
|
810 |
sharedPools
|
|
811 |
"ST/X does not (currently) support pools"
|
|
812 |
|
|
813 |
^ #()
|
|
814 |
!
|
|
815 |
|
1
|
816 |
setComment:com category:categoryStringOrSymbol
|
|
817 |
"set the comment and category of the class;
|
|
818 |
do NOT create a change record"
|
|
819 |
|
359
|
820 |
|cat|
|
|
821 |
|
1
|
822 |
comment := com.
|
359
|
823 |
categoryStringOrSymbol isNil ifTrue:[
|
|
824 |
cat := ''
|
|
825 |
] ifFalse:[
|
|
826 |
cat := categoryStringOrSymbol
|
|
827 |
].
|
|
828 |
category := cat asSymbol
|
1
|
829 |
!
|
|
830 |
|
|
831 |
setClassVariableString:aString
|
153
|
832 |
"set the classes classvarnames string.
|
|
833 |
This is a dangerous (low level) operation, since the
|
|
834 |
classvariables are not really created or updated. Also,
|
|
835 |
NO change record is written."
|
1
|
836 |
|
|
837 |
classvars := aString
|
|
838 |
!
|
|
839 |
|
|
840 |
classVariableString:aString
|
153
|
841 |
"set the classes classvarnames string;
|
|
842 |
Initialize new class variables with nil, clear and remove old ones.
|
|
843 |
No change record is written and no classes are recompiled."
|
1
|
844 |
|
199
|
845 |
|prevVarNames varNames any|
|
1
|
846 |
|
|
847 |
"ignore for metaclasses except the one"
|
10
|
848 |
(self isMeta) ifTrue:[
|
153
|
849 |
(self == Metaclass) ifFalse:[
|
|
850 |
^ self
|
|
851 |
]
|
1
|
852 |
].
|
|
853 |
(classvars = aString) ifFalse:[
|
153
|
854 |
prevVarNames := self classVarNames.
|
|
855 |
classvars := aString.
|
|
856 |
varNames := self classVarNames.
|
1
|
857 |
|
153
|
858 |
"new ones get initialized to nil;
|
|
859 |
- old ones are nilled and removed from Smalltalk"
|
199
|
860 |
any := false.
|
1
|
861 |
|
153
|
862 |
varNames do:[:aName |
|
|
863 |
(prevVarNames includes:aName) ifFalse:[
|
|
864 |
"a new one"
|
|
865 |
self classVarAt:aName put:nil.
|
199
|
866 |
any := true.
|
153
|
867 |
] ifTrue:[
|
|
868 |
prevVarNames remove:aName
|
|
869 |
]
|
|
870 |
].
|
|
871 |
"left overs are gone"
|
|
872 |
prevVarNames do:[:aName |
|
|
873 |
self classVarAt:aName put:nil.
|
|
874 |
Smalltalk removeKey:(self name , ':' , aName) asSymbol.
|
|
875 |
].
|
199
|
876 |
any ifTrue:[
|
391
|
877 |
Smalltalk changed:#classVariables with:self
|
|
878 |
].
|
1
|
879 |
]
|
|
880 |
!
|
|
881 |
|
|
882 |
addClassVarName:aString
|
153
|
883 |
"add a class variable if not already there and initialize it with nil.
|
391
|
884 |
Also writes a change record and notifies dependents.
|
153
|
885 |
BUG: Currently, no recompilation is done - this will change."
|
1
|
886 |
|
|
887 |
(self classVarNames includes:aString) ifFalse:[
|
153
|
888 |
self classVariableString:(self classVariableString , ' ' , aString).
|
|
889 |
self addChangeRecordForClass:self.
|
|
890 |
self changed:#definition.
|
|
891 |
]
|
|
892 |
!
|
|
893 |
|
|
894 |
removeClassVarName:aString
|
|
895 |
"remove a class variable if not already there.
|
391
|
896 |
Also writes a change record and notifies dependents.
|
153
|
897 |
BUG: Currently, no recompilation is done - this will change."
|
|
898 |
|
|
899 |
|names newNames|
|
|
900 |
|
|
901 |
names := self classVarNames.
|
|
902 |
(names includes:aString) ifTrue:[
|
|
903 |
newNames := ''.
|
|
904 |
names do:[:nm | nm ~= aString ifTrue:[newNames := newNames , nm , ' ']].
|
|
905 |
self classVariableString:newNames withoutSpaces.
|
|
906 |
self addChangeRecordForClass:self.
|
|
907 |
self changed:#definition.
|
1
|
908 |
]
|
85
|
909 |
!
|
|
910 |
|
|
911 |
renameCategory:oldCategory to:newCategory
|
153
|
912 |
"rename a category (changes category of those methods).
|
391
|
913 |
Appends a change record and notifies dependents."
|
85
|
914 |
|
|
915 |
|any|
|
|
916 |
|
|
917 |
any := false.
|
92
|
918 |
methodArray do:[:aMethod |
|
153
|
919 |
aMethod category = oldCategory ifTrue:[
|
|
920 |
aMethod category:newCategory.
|
|
921 |
any := true.
|
|
922 |
]
|
85
|
923 |
].
|
|
924 |
any ifTrue:[
|
153
|
925 |
self addChangeRecordForRenameCategory:oldCategory to:newCategory.
|
|
926 |
self changed:#methodCategory.
|
85
|
927 |
]
|
1
|
928 |
! !
|
|
929 |
|
|
930 |
!Class methodsFor:'adding/removing'!
|
|
931 |
|
68
|
932 |
addSelector:newSelector withMethod:newMethod
|
|
933 |
"add the method given by 2nd argument under the selector given by
|
92
|
934 |
1st argument to the methodDictionary.
|
153
|
935 |
Append a change record to the changes file and tell dependents."
|
1
|
936 |
|
362
|
937 |
|oldMethod|
|
|
938 |
|
|
939 |
CatchMethodRedefinitions ifTrue:[
|
|
940 |
"check for attempts to redefine a method
|
|
941 |
in a different package. Signal a resumable error if so.
|
|
942 |
This allows tracing redefinitions of existing system methods
|
|
943 |
when filing in alien code ....
|
|
944 |
(which we may want to forbit sometimes)
|
|
945 |
"
|
|
946 |
oldMethod := self compiledMethodAt:newSelector.
|
|
947 |
oldMethod notNil ifTrue:[
|
|
948 |
oldMethod package ~= newMethod package ifTrue:[
|
|
949 |
"
|
|
950 |
attempt to redefine an existing method, which was
|
|
951 |
defined in another package.
|
|
952 |
If you continue in the debugger, the new method gets installed.
|
|
953 |
Otherwise, the existing (old) method remains valid.
|
|
954 |
|
|
955 |
You can turn of the catching of redefinitions by setting
|
|
956 |
CatchMethodRedefinitions to false
|
|
957 |
(also found in the NewLaunchers 'settings-misc' menu)
|
|
958 |
"
|
406
|
959 |
MethodRedefinitionSignal
|
|
960 |
raiseErrorString:(' ' , name , '>>' , newSelector)
|
362
|
961 |
]
|
|
962 |
]
|
|
963 |
].
|
92
|
964 |
(super addSelector:newSelector withMethod:newMethod) ifTrue:[
|
153
|
965 |
self addChangeRecordForMethod:newMethod
|
92
|
966 |
]
|
1
|
967 |
!
|
|
968 |
|
|
969 |
removeSelector:aSelector
|
|
970 |
"remove the selector, aSelector and its associated method
|
92
|
971 |
from the methodDictionary.
|
153
|
972 |
Append a change record to the changes file and tell dependents."
|
1
|
973 |
|
92
|
974 |
(super removeSelector:aSelector) ifTrue:[
|
153
|
975 |
self addChangeRecordForRemoveSelector:aSelector.
|
|
976 |
self changed:#methodDictionary with:aSelector.
|
1
|
977 |
]
|
216
|
978 |
!
|
|
979 |
|
|
980 |
unload
|
293
|
981 |
"if the receiver was autoloaded, unload and reinstall it as
|
|
982 |
autoloaded. Can be used to get rid of no longer needed autoloaded
|
328
|
983 |
classes.
|
|
984 |
(maybe, autoloaded classes should unload themselfes when no
|
|
985 |
longer needed - for example, after some delay when the last instance
|
|
986 |
is gone ...)"
|
293
|
987 |
|
|
988 |
|nm|
|
|
989 |
|
216
|
990 |
self wasAutoloaded ifFalse:[
|
|
991 |
|
|
992 |
"
|
|
993 |
can it be done ?
|
|
994 |
"
|
|
995 |
self methodArray do:[:aMethod |
|
|
996 |
aMethod source isNil ifTrue:[^false].
|
|
997 |
aMethod hasPrimitiveCode ifTrue:[^ false].
|
|
998 |
].
|
|
999 |
].
|
|
1000 |
|
283
|
1001 |
self allSubclassesDo:[:aClass |
|
|
1002 |
aClass unload
|
|
1003 |
].
|
|
1004 |
Transcript showCr:'unloading ' , name.
|
|
1005 |
|
359
|
1006 |
Autoload removeClass:self.
|
293
|
1007 |
nm := name.
|
|
1008 |
Smalltalk at:nm put:nil.
|
|
1009 |
name := nm , ' (leftover)'.
|
288
|
1010 |
ObjectMemory flushInlineCaches.
|
|
1011 |
ObjectMemory flushMethodCache.
|
293
|
1012 |
Autoload addClass:nm inCategory:category.
|
216
|
1013 |
^ true
|
|
1014 |
|
|
1015 |
"
|
|
1016 |
Clock open.
|
|
1017 |
Clock unload.
|
|
1018 |
ClockView unload.
|
|
1019 |
Clock open
|
|
1020 |
"
|
1
|
1021 |
! !
|
|
1022 |
|
|
1023 |
!Class methodsFor:'changes management'!
|
|
1024 |
|
199
|
1025 |
withoutUpdatingChangesDo:aBlock
|
|
1026 |
"turn off change file update while evaluating aBlock.
|
|
1027 |
This method makes sure, that the update-flag is correctly restored
|
|
1028 |
in case of an abort or other error."
|
|
1029 |
|
421
|
1030 |
UpdateChangeFileQuerySignal handle:[:ex |
|
|
1031 |
ex proceedWith:false
|
|
1032 |
] do:[
|
|
1033 |
aBlock value
|
199
|
1034 |
].
|
|
1035 |
!
|
|
1036 |
|
1
|
1037 |
changesStream
|
155
|
1038 |
"return a Stream for the changes file - or nil if no update is wanted"
|
1
|
1039 |
|
199
|
1040 |
|aStream fileName|
|
1
|
1041 |
|
421
|
1042 |
(UpdateChangeFileQuerySignal raise) "UpdatingChanges" ifTrue:[
|
199
|
1043 |
fileName := ObjectMemory nameForChanges.
|
|
1044 |
aStream := FileStream oldFileNamed:fileName.
|
153
|
1045 |
aStream isNil ifTrue:[
|
199
|
1046 |
aStream := FileStream newFileNamed:fileName.
|
153
|
1047 |
aStream isNil ifTrue:[
|
355
|
1048 |
self warn:'cannot create/update changes file'.
|
153
|
1049 |
^ nil
|
|
1050 |
]
|
|
1051 |
].
|
|
1052 |
aStream setToEnd
|
92
|
1053 |
].
|
|
1054 |
^ aStream
|
|
1055 |
!
|
|
1056 |
|
|
1057 |
sourcesStream
|
155
|
1058 |
"return a stream for the sources file"
|
92
|
1059 |
|
199
|
1060 |
|aStream fileName|
|
92
|
1061 |
|
205
|
1062 |
fileName := ObjectMemory nameForSources.
|
|
1063 |
aStream := FileStream oldFileNamed:fileName.
|
|
1064 |
aStream isNil ifTrue:[
|
|
1065 |
aStream := FileStream newFileNamed:fileName.
|
153
|
1066 |
aStream isNil ifTrue:[
|
205
|
1067 |
Transcript showCr:'cannot update sources file'.
|
|
1068 |
^ nil
|
|
1069 |
]
|
1
|
1070 |
].
|
205
|
1071 |
aStream setToEnd.
|
1
|
1072 |
^ aStream
|
|
1073 |
!
|
|
1074 |
|
155
|
1075 |
writingChangeDo:aBlock
|
|
1076 |
"common helper to write a change record.
|
|
1077 |
Opens the changefile and executes aBlock passing the stream
|
168
|
1078 |
as argument. WriteErrors are cought and will lead to a warning.
|
|
1079 |
The changefile is not kept open, to force the change to go to disk
|
|
1080 |
as soon as possible - thus, in case of a crash, no changes should
|
|
1081 |
be lost due to buffering."
|
1
|
1082 |
|
139
|
1083 |
|aStream|
|
1
|
1084 |
|
|
1085 |
aStream := self changesStream.
|
|
1086 |
aStream notNil ifTrue:[
|
155
|
1087 |
FileStream writeErrorSignal handle:[:ex |
|
355
|
1088 |
self warn:('could not update the changes-file\\' , ex errorString) withCRs.
|
155
|
1089 |
ex return
|
|
1090 |
] do:[
|
199
|
1091 |
aBlock value:aStream.
|
|
1092 |
aStream cr.
|
155
|
1093 |
].
|
|
1094 |
aStream close
|
|
1095 |
]
|
|
1096 |
!
|
|
1097 |
|
302
|
1098 |
writingChangePerform:aSelector with:anArgument
|
|
1099 |
|aStream|
|
|
1100 |
|
|
1101 |
aStream := self changesStream.
|
|
1102 |
aStream notNil ifTrue:[
|
|
1103 |
FileStream writeErrorSignal handle:[:ex |
|
355
|
1104 |
self warn:('could not update the changes-file\\' , ex errorString) withCRs.
|
302
|
1105 |
ex return
|
|
1106 |
] do:[
|
|
1107 |
self perform:aSelector with:anArgument with:aStream.
|
|
1108 |
aStream cr.
|
|
1109 |
].
|
|
1110 |
aStream close
|
|
1111 |
]
|
|
1112 |
!
|
|
1113 |
|
155
|
1114 |
addChangeRecordForMethod:aMethod to:aStream
|
|
1115 |
"append a method-change-record to aStream"
|
|
1116 |
|
|
1117 |
self fileOutMethod:aMethod on:aStream.
|
|
1118 |
!
|
|
1119 |
|
|
1120 |
addChangeRecordForRemoveSelector:aSelector to:aStream
|
|
1121 |
"append a method-remove-record to aStream"
|
|
1122 |
|
|
1123 |
self printClassNameOn:aStream.
|
|
1124 |
aStream nextPutAll:(' removeSelector:#' , aSelector).
|
432
|
1125 |
aStream nextPutChunkSeparator.
|
199
|
1126 |
!
|
|
1127 |
|
|
1128 |
addChangeRecordForMethodCategory:aMethod category:newCategory to:aStream
|
|
1129 |
"append a methodCategory-change-record to aStream"
|
|
1130 |
|
|
1131 |
|selector|
|
|
1132 |
|
|
1133 |
selector := aMethod selector.
|
326
|
1134 |
selector notNil ifTrue:[
|
|
1135 |
aStream nextPutAll:'('.
|
|
1136 |
self printClassNameOn:aStream.
|
|
1137 |
aStream nextPutAll:(' compiledMethodAt:' , selector storeString).
|
|
1138 |
aStream nextPutAll:(') category:' , newCategory storeString).
|
432
|
1139 |
aStream nextPutChunkSeparator.
|
326
|
1140 |
]
|
155
|
1141 |
!
|
|
1142 |
|
414
|
1143 |
addChangeRecordForMethodPrivacy:aMethod to:aStream
|
|
1144 |
"append a method-privacy-change-record to aStream"
|
|
1145 |
|
|
1146 |
|selector|
|
|
1147 |
|
|
1148 |
selector := aMethod selector.
|
|
1149 |
selector notNil ifTrue:[
|
|
1150 |
aStream nextPutAll:'('.
|
|
1151 |
self printClassNameOn:aStream.
|
|
1152 |
aStream nextPutAll:(' compiledMethodAt:' , selector storeString).
|
|
1153 |
aStream nextPutAll:(') privacy:' , aMethod privacy storeString).
|
432
|
1154 |
aStream nextPutChunkSeparator.
|
414
|
1155 |
]
|
|
1156 |
|
|
1157 |
"Modified: 27.8.1995 / 22:59:56 / claus"
|
|
1158 |
!
|
|
1159 |
|
155
|
1160 |
addChangeRecordForClass:aClass to:aStream
|
|
1161 |
"append a class-definition-record to aStream"
|
|
1162 |
|
403
|
1163 |
aClass isLoaded ifTrue:[
|
|
1164 |
aClass fileOutDefinitionOn:aStream.
|
432
|
1165 |
aStream nextPutChunkSeparator.
|
403
|
1166 |
]
|
155
|
1167 |
!
|
|
1168 |
|
|
1169 |
addChangeRecordForClassInstvars:aClass to:aStream
|
|
1170 |
"append a class-instvars-record to aStream"
|
|
1171 |
|
|
1172 |
aClass fileOutClassInstVarDefinitionOn:aStream.
|
432
|
1173 |
aStream nextPutChunkSeparator.
|
155
|
1174 |
!
|
|
1175 |
|
|
1176 |
addChangeRecordForClassComment:aClass to:aStream
|
|
1177 |
"append a class-comment-record to aStream"
|
|
1178 |
|
|
1179 |
aClass fileOutCommentOn:aStream.
|
432
|
1180 |
aStream nextPutChunkSeparator.
|
155
|
1181 |
!
|
|
1182 |
|
360
|
1183 |
addChangeRecordForPrimitiveVariables:aClass to:aStream
|
|
1184 |
"append a primitiveVariables-record to aStream"
|
|
1185 |
|
|
1186 |
aStream nextPutAll:aClass name
|
435
|
1187 |
, ' primitiveVariables:'
|
360
|
1188 |
, aClass primitiveVariablesString storeString.
|
432
|
1189 |
aStream nextPutChunkSeparator.
|
360
|
1190 |
!
|
|
1191 |
|
|
1192 |
addChangeRecordForPrimitiveDefinitions:aClass to:aStream
|
|
1193 |
"append a primitiveDefinitions-record to aStream"
|
|
1194 |
|
|
1195 |
aStream nextPutAll:aClass name
|
435
|
1196 |
, ' primitiveDefinitions:'
|
360
|
1197 |
, aClass primitiveDefinitionsString storeString.
|
432
|
1198 |
aStream nextPutChunkSeparator.
|
360
|
1199 |
!
|
|
1200 |
|
|
1201 |
addChangeRecordForPrimitiveFunctions:aClass to:aStream
|
|
1202 |
"append a primitiveFunctions-record to aStream"
|
|
1203 |
|
|
1204 |
aStream nextPutAll:aClass name
|
435
|
1205 |
, ' primitiveFunctions:'
|
360
|
1206 |
, aClass primitiveFunctionsString storeString.
|
432
|
1207 |
aStream nextPutChunkSeparator.
|
360
|
1208 |
!
|
|
1209 |
|
155
|
1210 |
addChangeRecordForClassRename:oldName to:newName to:aStream
|
|
1211 |
"append a class-rename-record to aStream"
|
|
1212 |
|
|
1213 |
aStream nextPutAll:('Smalltalk renameClass:' , oldName , ' to:''' , newName , '''').
|
432
|
1214 |
aStream nextPutChunkSeparator.
|
155
|
1215 |
!
|
|
1216 |
|
|
1217 |
addChangeRecordForClassRemove:oldName to:aStream
|
|
1218 |
"append a class-remove-record to aStream"
|
|
1219 |
|
|
1220 |
aStream nextPutAll:('Smalltalk removeClass:' , oldName).
|
432
|
1221 |
aStream nextPutChunkSeparator.
|
155
|
1222 |
!
|
|
1223 |
|
|
1224 |
addChangeRecordForRenameCategory:oldCategory to:newCategory to:aStream
|
|
1225 |
"append a category-rename record to aStream"
|
|
1226 |
|
|
1227 |
self printClassNameOn:aStream.
|
|
1228 |
aStream nextPutAll:(' renameCategory:' , oldCategory storeString).
|
|
1229 |
aStream nextPutAll:(' to:' , newCategory storeString).
|
432
|
1230 |
aStream nextPutChunkSeparator.
|
155
|
1231 |
!
|
|
1232 |
|
302
|
1233 |
addChangeRecordForChangeCategory:category to:aStream
|
155
|
1234 |
"append a category change record to aStream"
|
|
1235 |
|
|
1236 |
self printClassNameOn:aStream.
|
|
1237 |
aStream nextPutAll:(' category:' , category storeString).
|
432
|
1238 |
aStream nextPutChunkSeparator.
|
199
|
1239 |
!
|
|
1240 |
|
|
1241 |
addInfoRecord:aMessage to:aStream
|
|
1242 |
"append an info-record (snapshot, class fileOut etc.) to aStream"
|
|
1243 |
|
|
1244 |
aStream nextPutAll:('''---- ' , aMessage , ' ',
|
|
1245 |
Date today printString , ' ' ,
|
|
1246 |
Time now printString ,
|
|
1247 |
' ----''').
|
432
|
1248 |
aStream nextPutChunkSeparator.
|
155
|
1249 |
!
|
|
1250 |
|
|
1251 |
addChangeRecordForSnapshot:aFileName to:aStream
|
199
|
1252 |
"add a snapshot-record to aStream"
|
155
|
1253 |
|
199
|
1254 |
self addInfoRecord:('snapshot ' , aFileName) to:aStream
|
155
|
1255 |
!
|
|
1256 |
|
199
|
1257 |
|
155
|
1258 |
addChangeRecordForMethod:aMethod
|
|
1259 |
"add a method-change-record to the changes file"
|
|
1260 |
|
421
|
1261 |
(UpdateChangeFileQuerySignal raise) "UpdatingChanges" ifTrue:[
|
302
|
1262 |
self writingChangePerform:#addChangeRecordForMethod:to: with:aMethod.
|
153
|
1263 |
"this test allows a smalltalk without Projects/ChangeSets"
|
|
1264 |
Project notNil ifTrue:[
|
|
1265 |
Project addMethodChange:aMethod in:self
|
|
1266 |
]
|
1
|
1267 |
]
|
|
1268 |
!
|
|
1269 |
|
|
1270 |
addChangeRecordForRemoveSelector:aSelector
|
|
1271 |
"add a method-remove-record to the changes file"
|
|
1272 |
|
302
|
1273 |
self writingChangePerform:#addChangeRecordForRemoveSelector:to: with:aSelector.
|
1
|
1274 |
!
|
|
1275 |
|
199
|
1276 |
addChangeRecordForMethodCategory:aMethod category:aString
|
|
1277 |
"add a methodCategory-change-record to the changes file"
|
|
1278 |
|
421
|
1279 |
(UpdateChangeFileQuerySignal raise) "UpdatingChanges" ifTrue:[
|
302
|
1280 |
self writingChangeDo:[:aStream |
|
|
1281 |
self addChangeRecordForMethodCategory:aMethod category:aString to:aStream.
|
|
1282 |
].
|
199
|
1283 |
|
|
1284 |
"this test allows a smalltalk without Projects/ChangeSets"
|
|
1285 |
Project notNil ifTrue:[
|
|
1286 |
Project addMethodCategoryChange:aMethod category:aString in:self
|
|
1287 |
]
|
|
1288 |
]
|
|
1289 |
!
|
|
1290 |
|
414
|
1291 |
addChangeRecordForMethodPrivacy:aMethod
|
|
1292 |
"add a method-privacy-change-record to the changes file"
|
|
1293 |
|
421
|
1294 |
(UpdateChangeFileQuerySignal raise) "UpdatingChanges" ifTrue:[
|
414
|
1295 |
self writingChangePerform:#addChangeRecordForMethodPrivacy:to: with:aMethod.
|
|
1296 |
"this test allows a smalltalk without Projects/ChangeSets"
|
|
1297 |
Project notNil ifTrue:[
|
|
1298 |
Project addMethodPrivacyChange:aMethod in:self
|
|
1299 |
]
|
|
1300 |
]
|
|
1301 |
|
|
1302 |
"Modified: 27.8.1995 / 22:47:32 / claus"
|
|
1303 |
!
|
|
1304 |
|
1
|
1305 |
addChangeRecordForClass:aClass
|
|
1306 |
"add a class-definition-record to the changes file"
|
|
1307 |
|
302
|
1308 |
self writingChangePerform:#addChangeRecordForClass:to: with:aClass.
|
1
|
1309 |
!
|
|
1310 |
|
2
|
1311 |
addChangeRecordForClassInstvars:aClass
|
|
1312 |
"add a class-instvars-record to the changes file"
|
|
1313 |
|
302
|
1314 |
self writingChangePerform:#addChangeRecordForClassInstvars:to: with:aClass.
|
2
|
1315 |
!
|
|
1316 |
|
1
|
1317 |
addChangeRecordForClassComment:aClass
|
|
1318 |
"add a class-comment-record to the changes file"
|
|
1319 |
|
302
|
1320 |
self writingChangePerform:#addChangeRecordForClassComment:to: with:aClass.
|
1
|
1321 |
!
|
|
1322 |
|
360
|
1323 |
addChangeRecordForPrimitiveVariables:aClass
|
|
1324 |
"add a primitiveVariables-record to the changes file"
|
|
1325 |
|
|
1326 |
self writingChangePerform:#addChangeRecordForPrimitiveVariables:to: with:aClass.
|
|
1327 |
!
|
|
1328 |
|
|
1329 |
addChangeRecordForPrimitiveDefinitions:aClass
|
|
1330 |
"add a primitiveDefinitions-record to the changes file"
|
|
1331 |
|
|
1332 |
self writingChangePerform:#addChangeRecordForPrimitiveDefinitions:to: with:aClass.
|
|
1333 |
!
|
|
1334 |
|
|
1335 |
addChangeRecordForPrimitiveFunctions:aClass
|
|
1336 |
"add a primitiveFunctions-record to the changes file"
|
|
1337 |
|
|
1338 |
self writingChangePerform:#addChangeRecordForPrimitiveFunctions:to: with:aClass.
|
|
1339 |
!
|
|
1340 |
|
10
|
1341 |
addChangeRecordForClassRename:oldName to:newName
|
|
1342 |
"add a class-rename-record to the changes file"
|
|
1343 |
|
421
|
1344 |
self writingChangeDo:[:aStream |
|
|
1345 |
self addChangeRecordForClassRename:oldName to:newName to:aStream
|
10
|
1346 |
]
|
|
1347 |
!
|
|
1348 |
|
|
1349 |
addChangeRecordForClassRemove:oldName
|
|
1350 |
"add a class-remove-record to the changes file"
|
|
1351 |
|
302
|
1352 |
self writingChangePerform:#addChangeRecordForClassRemove:to: with:oldName.
|
10
|
1353 |
!
|
|
1354 |
|
85
|
1355 |
addChangeRecordForRenameCategory:oldCategory to:newCategory
|
|
1356 |
"add a category-rename record to the changes file"
|
|
1357 |
|
421
|
1358 |
self writingChangeDo:[:aStream |
|
|
1359 |
self addChangeRecordForRenameCategory:oldCategory to:newCategory to:aStream.
|
85
|
1360 |
]
|
|
1361 |
!
|
|
1362 |
|
|
1363 |
addChangeRecordForChangeCategory
|
|
1364 |
"add a category change record to the changes file"
|
|
1365 |
|
302
|
1366 |
self writingChangePerform:#addChangeRecordForChangeCategory:to: with:category.
|
85
|
1367 |
!
|
|
1368 |
|
199
|
1369 |
addInfoRecord:aMessage
|
|
1370 |
"add an info-record (snapshot, class fileOut etc.) to the changes file"
|
|
1371 |
|
302
|
1372 |
self writingChangePerform:#addInfoRecord:to: with:aMessage.
|
199
|
1373 |
!
|
|
1374 |
|
22
|
1375 |
addChangeRecordForSnapshot:aFileName
|
1
|
1376 |
"add a snapshot-record to the changes file"
|
|
1377 |
|
199
|
1378 |
self addInfoRecord:('snapshot ' , aFileName)
|
|
1379 |
!
|
|
1380 |
|
|
1381 |
addChangeRecordForClassFileOut:aClass
|
|
1382 |
"append a class-was-filedOut-record to the changes file"
|
|
1383 |
|
|
1384 |
self addInfoRecord:('fileOut ' , aClass name)
|
1
|
1385 |
! !
|
|
1386 |
|
|
1387 |
!Class methodsFor:'compiling'!
|
|
1388 |
|
|
1389 |
compile:code
|
328
|
1390 |
"compile code, aString for this class;
|
|
1391 |
if sucessful update the method dictionary."
|
|
1392 |
|
|
1393 |
self compilerClass
|
|
1394 |
compile:code
|
|
1395 |
forClass:self
|
|
1396 |
!
|
|
1397 |
|
|
1398 |
compile:code classified:category
|
|
1399 |
"compile code, aString for this class;
|
|
1400 |
if sucessful update the method dictionary.
|
|
1401 |
The method is classified under category."
|
|
1402 |
|
|
1403 |
self compilerClass
|
|
1404 |
compile:code
|
|
1405 |
forClass:self
|
|
1406 |
inCategory:category
|
1
|
1407 |
!
|
|
1408 |
|
|
1409 |
compile:code notifying:requestor
|
|
1410 |
"compile code, aString for this class; on any error, notify
|
328
|
1411 |
requestor, anObject with the error reason."
|
|
1412 |
|
|
1413 |
self compilerClass
|
|
1414 |
compile:code
|
|
1415 |
forClass:self
|
|
1416 |
notifying:requestor
|
1
|
1417 |
!
|
|
1418 |
|
2
|
1419 |
recompileMethodsAccessingAny:setOfNames
|
|
1420 |
"recompile all methods accessing a variable from setOfNames"
|
|
1421 |
|
153
|
1422 |
self recompileMethodsAccessingAny:setOfNames orSuper:false
|
|
1423 |
!
|
|
1424 |
|
|
1425 |
recompileMethodsAccessingAny:setOfNames orSuper:superBoolean
|
|
1426 |
"recompile all methods accessing a variable from setOfNames,
|
|
1427 |
or super (if superBoolean is true)"
|
|
1428 |
|
2
|
1429 |
|p|
|
|
1430 |
|
92
|
1431 |
selectorArray do:[:aSelector |
|
153
|
1432 |
|m|
|
2
|
1433 |
|
153
|
1434 |
m := self compiledMethodAt:aSelector.
|
|
1435 |
p := Parser parseMethod:(m source) in:self.
|
|
1436 |
(p isNil
|
|
1437 |
or:[(p usedVars notNil and:[p usedVars includesAny:setOfNames])
|
|
1438 |
or:[superBoolean and:[p usesSuper]]]) ifTrue:[
|
|
1439 |
self recompile:aSelector
|
|
1440 |
]
|
2
|
1441 |
]
|
|
1442 |
!
|
|
1443 |
|
1
|
1444 |
recompile:aSelector
|
|
1445 |
"recompile the method associated with the argument, aSelector;
|
|
1446 |
used when a superclass changes instances and we have to recompile
|
|
1447 |
subclasses"
|
|
1448 |
|
199
|
1449 |
|cat code|
|
1
|
1450 |
|
199
|
1451 |
Class withoutUpdatingChangesDo:[
|
362
|
1452 |
Class methodRedefinitionSignal handle:[:ex |
|
|
1453 |
ex proceed
|
|
1454 |
] do:[
|
|
1455 |
cat := (self compiledMethodAt:aSelector) category.
|
|
1456 |
code := self sourceCodeAt:aSelector.
|
|
1457 |
self compilerClass compile:code forClass:self inCategory:cat
|
|
1458 |
]
|
2
|
1459 |
]
|
1
|
1460 |
!
|
|
1461 |
|
|
1462 |
recompile
|
|
1463 |
"recompile all methods
|
|
1464 |
used when a class changes instances and therefore all methods
|
|
1465 |
have to be recompiled"
|
|
1466 |
|
92
|
1467 |
selectorArray do:[:aSelector |
|
153
|
1468 |
self recompile:aSelector
|
1
|
1469 |
]
|
|
1470 |
!
|
|
1471 |
|
|
1472 |
recompileAll
|
|
1473 |
"recompile this class and all subclasses"
|
|
1474 |
|
2
|
1475 |
|classes|
|
|
1476 |
|
|
1477 |
classes := self subclasses.
|
|
1478 |
self recompile.
|
|
1479 |
classes do:[:aClass |
|
153
|
1480 |
aClass recompileAll
|
2
|
1481 |
]
|
|
1482 |
!
|
|
1483 |
|
92
|
1484 |
recompileInvalidatedMethods:trap
|
2
|
1485 |
"recompile all invalidated methods"
|
1
|
1486 |
|
92
|
1487 |
|trapCode trapByteCode|
|
2
|
1488 |
|
|
1489 |
trapCode := trap code.
|
|
1490 |
trapByteCode := trap byteCode.
|
|
1491 |
|
92
|
1492 |
selectorArray do:[:aSelector |
|
153
|
1493 |
|m|
|
2
|
1494 |
|
153
|
1495 |
m := self compiledMethodAt:aSelector.
|
362
|
1496 |
((m code = trapCode) and:[m byteCode == trapByteCode]) ifTrue:[
|
153
|
1497 |
self recompile:aSelector
|
|
1498 |
]
|
1
|
1499 |
]
|
|
1500 |
! !
|
|
1501 |
|
|
1502 |
!Class methodsFor:'queries'!
|
|
1503 |
|
2
|
1504 |
isClass
|
10
|
1505 |
"return true, if the receiver is some kind of class
|
|
1506 |
(a real class, not just behavior);
|
193
|
1507 |
true is returned here - the method is redefined from Object.
|
|
1508 |
See also Behavior>>isBehavior."
|
1
|
1509 |
|
2
|
1510 |
^ true
|
193
|
1511 |
|
|
1512 |
"
|
|
1513 |
Point isClass
|
|
1514 |
1 isClass
|
|
1515 |
Behavior new isBehavior
|
|
1516 |
Behavior new isClass
|
|
1517 |
Class new isBehavior
|
|
1518 |
Class new isClass
|
|
1519 |
"
|
1
|
1520 |
!
|
|
1521 |
|
|
1522 |
categories
|
193
|
1523 |
"Return a Collection of all method-category strings known in class.
|
|
1524 |
The returned collection is not sorted by any order."
|
1
|
1525 |
|
|
1526 |
|newList cat|
|
|
1527 |
|
|
1528 |
newList := OrderedCollection new.
|
92
|
1529 |
methodArray do:[:aMethod |
|
153
|
1530 |
cat := aMethod category.
|
|
1531 |
newList indexOf:cat ifAbsent:[newList add:cat]
|
1
|
1532 |
].
|
|
1533 |
^ newList
|
193
|
1534 |
|
|
1535 |
"
|
|
1536 |
Point categories
|
|
1537 |
"
|
1
|
1538 |
!
|
|
1539 |
|
|
1540 |
allCategories
|
|
1541 |
"Return a Collection of all method-category strings known in class
|
193
|
1542 |
and all superclasses. The returned collection is not sorted by any order."
|
1
|
1543 |
|
168
|
1544 |
|coll|
|
|
1545 |
|
|
1546 |
coll := OrderedCollection new.
|
|
1547 |
self addAllCategoriesTo:coll.
|
|
1548 |
^ coll
|
193
|
1549 |
|
|
1550 |
"
|
|
1551 |
Point categories
|
|
1552 |
Point allCategories
|
|
1553 |
"
|
216
|
1554 |
!
|
|
1555 |
|
|
1556 |
wasAutoloaded
|
328
|
1557 |
"return true, if this class came into the system via an
|
|
1558 |
autoload; false otherwise.
|
|
1559 |
This is not an attribute of the class, but instead remembered in
|
|
1560 |
Autoload. The interface here is for covenience."
|
|
1561 |
|
216
|
1562 |
^ Autoload wasAutoloaded:self
|
328
|
1563 |
!
|
|
1564 |
|
|
1565 |
whichClassDefinesInstVar:aVariableName
|
|
1566 |
"return the class which defines the instance variable
|
|
1567 |
named aVariableName. This method should not be used for
|
|
1568 |
repeated searches (i.e. in the compiler/parser), since it creates
|
|
1569 |
many throw away intermediate objects."
|
|
1570 |
|
|
1571 |
|cls|
|
|
1572 |
|
|
1573 |
cls := self.
|
|
1574 |
[cls notNil] whileTrue:[
|
|
1575 |
(cls instVarNames includes:aVariableName) ifTrue:[ ^ cls].
|
|
1576 |
cls := cls superclass
|
|
1577 |
].
|
|
1578 |
^ nil
|
|
1579 |
|
|
1580 |
"
|
|
1581 |
StandardSystemView whichClassDefinesInstVar:'label'
|
|
1582 |
StandardSystemView whichClassDefinesInstVar:'paint'
|
|
1583 |
StandardSystemView whichClassDefinesInstVar:'foo'
|
|
1584 |
"
|
|
1585 |
!
|
|
1586 |
|
|
1587 |
whichClassDefinesClassVar:aVariableName
|
|
1588 |
"return the class which defines the class variable
|
|
1589 |
named aVariableName. This method should not be used for
|
|
1590 |
repeated searches (i.e. in the compiler/parser), since it creates
|
|
1591 |
many throw away intermediate objects."
|
|
1592 |
|
|
1593 |
|cls|
|
|
1594 |
|
|
1595 |
cls := self.
|
|
1596 |
[cls notNil] whileTrue:[
|
|
1597 |
(cls classVarNames includes:aVariableName) ifTrue:[ ^ cls].
|
|
1598 |
cls := cls superclass
|
|
1599 |
].
|
|
1600 |
^ nil
|
|
1601 |
|
|
1602 |
"
|
|
1603 |
StandardSystemView whichClassDefinesClassVar:'ErrorSignal'
|
|
1604 |
StandardSystemView whichClassDefinesClassVar:'Foo'
|
|
1605 |
"
|
1
|
1606 |
! !
|
|
1607 |
|
|
1608 |
!Class methodsFor:'private'!
|
|
1609 |
|
|
1610 |
addAllClassVarNamesTo:aCollection
|
10
|
1611 |
"helper - add the name-strings of the class variables and of the class-vars
|
1
|
1612 |
of all superclasses to the argument, aCollection. Return aCollection"
|
|
1613 |
|
|
1614 |
(superclass notNil) ifTrue:[
|
153
|
1615 |
superclass addAllClassVarNamesTo:aCollection
|
1
|
1616 |
].
|
10
|
1617 |
classvars notNil ifTrue:[
|
153
|
1618 |
aCollection addAll:(classvars asCollectionOfWords).
|
10
|
1619 |
].
|
|
1620 |
^ aCollection
|
1
|
1621 |
!
|
|
1622 |
|
|
1623 |
addCategoriesTo:aCollection
|
|
1624 |
"helper - add categories to the argument, aCollection"
|
|
1625 |
|
168
|
1626 |
methodArray do:[:aMethod |
|
193
|
1627 |
|cat|
|
1
|
1628 |
|
153
|
1629 |
cat := aMethod category.
|
168
|
1630 |
(aCollection includes:cat) ifFalse:[
|
|
1631 |
aCollection add:cat
|
153
|
1632 |
]
|
168
|
1633 |
]
|
1
|
1634 |
!
|
|
1635 |
|
|
1636 |
addAllCategoriesTo:aCollection
|
|
1637 |
"helper - add categories and all superclasses categories
|
|
1638 |
to the argument, aCollection"
|
|
1639 |
|
|
1640 |
(superclass notNil) ifTrue:[
|
153
|
1641 |
superclass addAllCategoriesTo:aCollection
|
1
|
1642 |
].
|
168
|
1643 |
self addCategoriesTo:aCollection
|
216
|
1644 |
!
|
|
1645 |
|
357
|
1646 |
getPrimitiveSpecsAt:index
|
216
|
1647 |
"return a primitiveSpecification component as string or nil"
|
|
1648 |
|
|
1649 |
|pos stream string|
|
|
1650 |
|
|
1651 |
primitiveSpec isNil ifTrue:[^ nil].
|
|
1652 |
pos := primitiveSpec at:index.
|
|
1653 |
pos isNil ifTrue:[^ nil].
|
|
1654 |
|
|
1655 |
"the primitiveSpec is either a string, or an integer specifying the
|
|
1656 |
position within the classes sourcefile ...
|
|
1657 |
"
|
|
1658 |
pos isNumber ifTrue:[
|
|
1659 |
classFilename notNil ifTrue:[
|
328
|
1660 |
stream := Smalltalk sourceFileStreamFor:classFilename.
|
216
|
1661 |
stream notNil ifTrue:[
|
|
1662 |
stream position:pos+1.
|
|
1663 |
string := stream nextChunk.
|
|
1664 |
stream close.
|
|
1665 |
^ string
|
|
1666 |
]
|
|
1667 |
].
|
|
1668 |
^ nil
|
|
1669 |
].
|
|
1670 |
^ pos
|
|
1671 |
!
|
|
1672 |
|
357
|
1673 |
setPrimitiveSpecsAt:index to:aString
|
216
|
1674 |
"set a primitiveSpecification component to aString"
|
|
1675 |
|
|
1676 |
primitiveSpec isNil ifTrue:[
|
|
1677 |
primitiveSpec := Array new:3
|
|
1678 |
].
|
|
1679 |
primitiveSpec at:index put:aString
|
1
|
1680 |
! !
|
|
1681 |
|
|
1682 |
!Class methodsFor:'fileIn interface'!
|
|
1683 |
|
|
1684 |
methodsFor:aCategory
|
10
|
1685 |
"return a ClassCategoryReader to read in and compile methods for me.
|
|
1686 |
This one actually creates the ClassReader when code is filed-in."
|
1
|
1687 |
|
|
1688 |
^ ClassCategoryReader class:self category:aCategory
|
|
1689 |
!
|
|
1690 |
|
|
1691 |
publicMethodsFor:aCategory
|
68
|
1692 |
"this method allows fileIn of ENVY methods
|
|
1693 |
(although ST/X currently does NOT support method visibility).
|
|
1694 |
Returns a ClassCategoryReader to read in and compile methods for me."
|
1
|
1695 |
|
|
1696 |
^ self methodsFor:aCategory
|
|
1697 |
!
|
|
1698 |
|
|
1699 |
privateMethodsFor:aCategory
|
68
|
1700 |
"this method allows fileIn of ENVY methods
|
92
|
1701 |
(although ST/X currently does NOT really enforce method visibility yet).
|
68
|
1702 |
Returns a ClassCategoryReader to read in and compile methods for me."
|
1
|
1703 |
|
68
|
1704 |
^ (self methodsFor:aCategory) privateProtocol
|
1
|
1705 |
!
|
|
1706 |
|
168
|
1707 |
protectedMethodsFor:aCategory
|
|
1708 |
"this method allows fileIn of ENVY methods
|
|
1709 |
(although ST/X currently does NOT really enforce method visibility yet).
|
|
1710 |
Returns a ClassCategoryReader to read in and compile methods for me."
|
|
1711 |
|
|
1712 |
^ (self methodsFor:aCategory) protectedProtocol
|
|
1713 |
!
|
|
1714 |
|
295
|
1715 |
methodsForUndefined:categoryString
|
|
1716 |
"ST-80 compatibility.
|
|
1717 |
I dont yet know what this does - it was encountered by some tester.
|
|
1718 |
For now, simply forward it."
|
|
1719 |
|
|
1720 |
^ self methodsFor:categoryString
|
|
1721 |
!
|
|
1722 |
|
137
|
1723 |
ignoredMethodsFor:aCategory
|
|
1724 |
"this is a speciality of ST/X - it allows quick commenting of methods
|
|
1725 |
from a source-file by replacing the 'methodsFor:' by 'ignoredMethodsFor'.
|
|
1726 |
Returns a ClassCategoryReader to read in and skip methods."
|
1
|
1727 |
|
168
|
1728 |
^ ClassCategoryReader skippingChunks
|
1
|
1729 |
!
|
|
1730 |
|
|
1731 |
methods
|
|
1732 |
"this method allows fileIn of ST/V methods -
|
|
1733 |
return a ClassCategoryReader to read in and compile methods for me."
|
|
1734 |
|
|
1735 |
^ ClassCategoryReader class:self category:'ST/V methods'
|
168
|
1736 |
!
|
|
1737 |
|
|
1738 |
primitiveDefinitions
|
|
1739 |
"this method allows fileIn of classes with primitive code
|
|
1740 |
outside of methods - it returns a CCReader which skips the next chunks"
|
|
1741 |
|
216
|
1742 |
^ ClassCategoryReader class:self primitiveSpec:#primitiveDefinitions:
|
168
|
1743 |
!
|
|
1744 |
|
|
1745 |
primitiveVariables
|
|
1746 |
"this method allows fileIn of classes with primitive code
|
|
1747 |
outside of methods - it returns a CCReader which skips the next chunks"
|
|
1748 |
|
216
|
1749 |
^ ClassCategoryReader class:self primitiveSpec:#primitiveVariables:
|
168
|
1750 |
!
|
|
1751 |
|
|
1752 |
primitiveFunctions
|
|
1753 |
"this method allows fileIn of classes with primitive code
|
|
1754 |
outside of methods - it returns a CCReader which skips the next chunks"
|
|
1755 |
|
216
|
1756 |
^ ClassCategoryReader class:self primitiveSpec:#primitiveFunctions:
|
1
|
1757 |
! !
|
|
1758 |
|
68
|
1759 |
!Class methodsFor:'c function interfacing'!
|
|
1760 |
|
|
1761 |
cInterfaceFunction:selector calling:cFunctionNameString args:argTypeArray returning:returnType
|
|
1762 |
"create an interface to an existing (i.e. already linked in) c function.
|
|
1763 |
The function can be called by sending selector to the receiver class.
|
|
1764 |
The c-function has the name cFunctionNameString, and expects parameters as specified in
|
|
1765 |
argTypeArray. The functions return value has a type as specified by returnType.
|
168
|
1766 |
WARNING:
|
|
1767 |
this interface is EXPERIMENTAL - it may change or even be removed."
|
|
1768 |
|
|
1769 |
StubGenerator isNil ifTrue:[
|
|
1770 |
^ self error:'this system does not support dynamic C Interface functions'.
|
|
1771 |
].
|
68
|
1772 |
|
168
|
1773 |
StubGenerator
|
|
1774 |
createStubFor:selector
|
|
1775 |
calling:cFunctionNameString
|
|
1776 |
args:argTypeArray
|
|
1777 |
returning:returnType
|
|
1778 |
in:self
|
68
|
1779 |
|
|
1780 |
"
|
|
1781 |
Object subclass:#CInterface
|
153
|
1782 |
instanceVariableNames:''
|
|
1783 |
classVariableNames:''
|
|
1784 |
poolDictionaries:''
|
|
1785 |
category:'Examples'.
|
68
|
1786 |
|
|
1787 |
CInterface cInterfaceFunction:#printfOn:format:withFloat:
|
153
|
1788 |
calling:'fprintf'
|
|
1789 |
args:#(ExternalStream String Float)
|
|
1790 |
returning:#SmallInteger.
|
68
|
1791 |
|
|
1792 |
CInterface printfOn:Stdout format:'this is a float: %g' withFloat:(Float pi). Stdout cr
|
|
1793 |
"
|
|
1794 |
! !
|
|
1795 |
|
1
|
1796 |
!Class methodsFor:'fileOut'!
|
|
1797 |
|
|
1798 |
fileOutCommentOn:aStream
|
68
|
1799 |
"append an expression on aStream, which defines my comment"
|
1
|
1800 |
|
333
|
1801 |
|comment s|
|
|
1802 |
|
|
1803 |
aStream nextPutAll:name; nextPutAll:' comment:'.
|
193
|
1804 |
(comment := self comment) isNil ifTrue:[
|
333
|
1805 |
s := ''''''
|
1
|
1806 |
] ifFalse:[
|
333
|
1807 |
s := comment storeString
|
1
|
1808 |
].
|
362
|
1809 |
aStream nextPutAll:s.
|
1
|
1810 |
aStream cr
|
|
1811 |
!
|
|
1812 |
|
|
1813 |
fileOutDefinitionOn:aStream
|
68
|
1814 |
"append an expression on aStream, which defines myself."
|
1
|
1815 |
|
238
|
1816 |
^ self basicFileOutDefinitionOn:aStream
|
|
1817 |
!
|
|
1818 |
|
|
1819 |
basicFileOutDefinitionOn:aStream
|
|
1820 |
"append an expression on aStream, which defines myself."
|
|
1821 |
|
293
|
1822 |
|isVar line s|
|
1
|
1823 |
|
68
|
1824 |
"take care of nil-superclass"
|
1
|
1825 |
superclass isNil ifTrue:[
|
92
|
1826 |
"/ previous versions of stc were not able to compile nil-subclasses;
|
|
1827 |
"/ after 2.10, it can ...
|
|
1828 |
"/ line := 'Object "nil"'.
|
153
|
1829 |
line := 'nil'
|
1
|
1830 |
] ifFalse:[
|
153
|
1831 |
line := (superclass name)
|
1
|
1832 |
].
|
|
1833 |
superclass isNil ifTrue:[
|
153
|
1834 |
isVar := self isVariable
|
1
|
1835 |
] ifFalse:[
|
153
|
1836 |
"I cant remember what this is for ?"
|
|
1837 |
isVar := (self isVariable and:[superclass isVariable not])
|
1
|
1838 |
].
|
293
|
1839 |
|
1
|
1840 |
isVar ifTrue:[
|
153
|
1841 |
self isBytes ifTrue:[
|
293
|
1842 |
s := ' variableByteSubclass:#'
|
153
|
1843 |
] ifFalse:[
|
|
1844 |
self isWords ifTrue:[
|
293
|
1845 |
s := ' variableWordSubclass:#'
|
153
|
1846 |
] ifFalse:[
|
|
1847 |
self isLongs ifTrue:[
|
293
|
1848 |
s := ' variableLongSubclass:#'
|
153
|
1849 |
] ifFalse:[
|
|
1850 |
self isFloats ifTrue:[
|
293
|
1851 |
s := ' variableFloatSubclass:#'
|
153
|
1852 |
] ifFalse:[
|
|
1853 |
self isDoubles ifTrue:[
|
293
|
1854 |
s := ' variableDoubleSubclass:#'
|
153
|
1855 |
] ifFalse:[
|
293
|
1856 |
s := ' variableSubclass:#'
|
153
|
1857 |
]
|
|
1858 |
]
|
|
1859 |
]
|
|
1860 |
]
|
|
1861 |
]
|
1
|
1862 |
] ifFalse:[
|
293
|
1863 |
s := ' subclass:#'
|
1
|
1864 |
].
|
293
|
1865 |
line := line , s , name.
|
1
|
1866 |
aStream nextPutAll:line.
|
|
1867 |
|
345
|
1868 |
aStream crtab.
|
1
|
1869 |
aStream nextPutAll:' instanceVariableNames:'''.
|
|
1870 |
self printInstVarNamesOn:aStream indent:16.
|
|
1871 |
aStream nextPutAll:''''.
|
|
1872 |
|
345
|
1873 |
aStream crtab.
|
1
|
1874 |
aStream nextPutAll:' classVariableNames:'''.
|
|
1875 |
self printClassVarNamesOn:aStream indent:16.
|
|
1876 |
aStream nextPutAll:''''.
|
|
1877 |
|
345
|
1878 |
aStream crtab.
|
1
|
1879 |
aStream nextPutAll:' poolDictionaries:'''''.
|
|
1880 |
|
345
|
1881 |
aStream crtab.
|
1
|
1882 |
aStream nextPutAll:' category:'.
|
|
1883 |
category isNil ifTrue:[
|
333
|
1884 |
s := ''''''
|
1
|
1885 |
] ifFalse:[
|
333
|
1886 |
s := category asString storeString
|
1
|
1887 |
].
|
333
|
1888 |
aStream nextPutAll:s.
|
1
|
1889 |
aStream cr
|
|
1890 |
!
|
|
1891 |
|
216
|
1892 |
fileOutPrimitiveDefinitionsOn:aStream
|
|
1893 |
"append primitive defs (if any) to aStream."
|
|
1894 |
|
432
|
1895 |
|s|
|
|
1896 |
|
216
|
1897 |
"
|
|
1898 |
primitive definitions - if any
|
|
1899 |
"
|
|
1900 |
(s := self primitiveDefinitionsString) notNil ifTrue:[
|
432
|
1901 |
aStream nextPutChunkSeparator;
|
333
|
1902 |
nextPutAll:name; nextPutAll:' primitiveDefinitions';
|
432
|
1903 |
nextPutChunkSeparator;
|
216
|
1904 |
cr.
|
|
1905 |
aStream nextPutAll:s.
|
432
|
1906 |
aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr
|
216
|
1907 |
].
|
|
1908 |
(s := self primitiveVariablesString) notNil ifTrue:[
|
432
|
1909 |
aStream nextPutChunkSeparator;
|
333
|
1910 |
nextPutAll:name; nextPutAll:' primitiveVariables';
|
432
|
1911 |
nextPutChunkSeparator;
|
216
|
1912 |
cr.
|
|
1913 |
aStream nextPutAll:s.
|
432
|
1914 |
aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr
|
216
|
1915 |
].
|
|
1916 |
!
|
|
1917 |
|
|
1918 |
fileOutPrimitiveSpecsOn:aStream
|
|
1919 |
"append primitive defs (if any) to aStream."
|
|
1920 |
|
432
|
1921 |
|s|
|
216
|
1922 |
|
|
1923 |
"
|
|
1924 |
primitive definitions - if any
|
|
1925 |
"
|
|
1926 |
self fileOutPrimitiveDefinitionsOn:aStream.
|
|
1927 |
"
|
|
1928 |
primitive functions - if any
|
|
1929 |
"
|
|
1930 |
(s := self primitiveFunctionsString) notNil ifTrue:[
|
432
|
1931 |
aStream nextPutChunkSeparator;
|
333
|
1932 |
nextPutAll:name; nextPutAll:' primitiveFunctions';
|
432
|
1933 |
nextPutChunkSeparator;
|
216
|
1934 |
cr.
|
|
1935 |
aStream nextPutAll:s.
|
432
|
1936 |
aStream nextPutChunkSeparator; space; nextPutChunkSeparator; cr; cr
|
216
|
1937 |
].
|
|
1938 |
!
|
|
1939 |
|
1
|
1940 |
fileOutClassInstVarDefinitionOn:aStream
|
68
|
1941 |
"append an expression to define my classInstanceVariables on aStream"
|
|
1942 |
|
1
|
1943 |
aStream nextPutAll:(name , ' class instanceVariableNames:''').
|
|
1944 |
self class printInstVarNamesOn:aStream indent:8.
|
314
|
1945 |
aStream nextPutAll:''''.
|
|
1946 |
|
|
1947 |
"mhmh - good idea; saw this in SmallDraw sourcecode ..."
|
|
1948 |
|
333
|
1949 |
aStream cr; cr; nextPut:(Character doubleQuote); cr.
|
314
|
1950 |
aStream space;
|
|
1951 |
nextPutAll:'The following class instance variables are inherited by this class:';
|
|
1952 |
cr; cr.
|
|
1953 |
self allSuperclassesDo:[:aSuperClass |
|
333
|
1954 |
aStream tab; nextPutAll:aSuperClass name; nextPutAll:' - '.
|
314
|
1955 |
aStream nextPutAll:(aSuperClass class instanceVariableString); cr.
|
|
1956 |
].
|
|
1957 |
aStream nextPut:(Character doubleQuote); cr.
|
1
|
1958 |
!
|
|
1959 |
|
|
1960 |
fileOutCategory:aCategory on:aStream
|
|
1961 |
"file out all methods belonging to aCategory, aString onto aStream"
|
|
1962 |
|
432
|
1963 |
|nMethods count source sortedSelectors sortedMethods first
|
415
|
1964 |
privacy|
|
1
|
1965 |
|
92
|
1966 |
methodArray notNil ifTrue:[
|
153
|
1967 |
nMethods := 0.
|
|
1968 |
methodArray do:[:aMethod |
|
|
1969 |
(aCategory = aMethod category) ifTrue:[
|
|
1970 |
nMethods := nMethods + 1
|
|
1971 |
]
|
|
1972 |
].
|
|
1973 |
(nMethods ~~ 0) ifTrue:[
|
|
1974 |
count := 1.
|
412
|
1975 |
first := true.
|
362
|
1976 |
|
|
1977 |
"/
|
|
1978 |
"/ sort by selector
|
|
1979 |
"/
|
|
1980 |
sortedSelectors := selectorArray copy.
|
|
1981 |
sortedMethods := methodArray copy.
|
|
1982 |
sortedSelectors sortWith:sortedMethods.
|
|
1983 |
|
153
|
1984 |
methodArray do:[:aMethod |
|
|
1985 |
(aCategory = aMethod category) ifTrue:[
|
412
|
1986 |
|
|
1987 |
first ifFalse:[
|
415
|
1988 |
privacy ~~ aMethod privacy ifTrue:[
|
412
|
1989 |
first := true.
|
|
1990 |
aStream space.
|
432
|
1991 |
aStream nextPutChunkSeparator.
|
412
|
1992 |
].
|
|
1993 |
aStream cr; cr
|
|
1994 |
].
|
|
1995 |
|
415
|
1996 |
privacy := aMethod privacy.
|
412
|
1997 |
|
|
1998 |
first ifTrue:[
|
432
|
1999 |
aStream nextPutChunkSeparator.
|
412
|
2000 |
self printClassNameOn:aStream.
|
415
|
2001 |
privacy ~~ #public ifTrue:[
|
|
2002 |
aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'''.
|
412
|
2003 |
] ifFalse:[
|
415
|
2004 |
aStream nextPutAll:' methodsFor:'''.
|
412
|
2005 |
].
|
|
2006 |
aCategory notNil ifTrue:[
|
|
2007 |
aStream nextPutAll:aCategory
|
|
2008 |
].
|
432
|
2009 |
aStream nextPut:$'; nextPutChunkSeparator; cr; cr.
|
412
|
2010 |
first := false.
|
|
2011 |
].
|
153
|
2012 |
source := aMethod source.
|
|
2013 |
source isNil ifTrue:[
|
|
2014 |
FileOutErrorSignal raiseRequestWith:'no source for method'
|
|
2015 |
] ifFalse:[
|
362
|
2016 |
aStream nextChunkPut:source.
|
153
|
2017 |
].
|
|
2018 |
count := count + 1
|
|
2019 |
]
|
|
2020 |
].
|
|
2021 |
aStream space.
|
432
|
2022 |
aStream nextPutChunkSeparator.
|
153
|
2023 |
aStream cr
|
|
2024 |
]
|
1
|
2025 |
]
|
412
|
2026 |
|
415
|
2027 |
"Modified: 28.8.1995 / 14:30:41 / claus"
|
1
|
2028 |
!
|
|
2029 |
|
|
2030 |
fileOutMethod:aMethod on:aStream
|
|
2031 |
"file out the method, aMethod onto aStream"
|
|
2032 |
|
432
|
2033 |
|cat source privacy|
|
1
|
2034 |
|
92
|
2035 |
methodArray notNil ifTrue:[
|
432
|
2036 |
aStream nextPutChunkSeparator.
|
153
|
2037 |
self printClassNameOn:aStream.
|
415
|
2038 |
|
|
2039 |
(privacy := aMethod privacy) ~~ #public ifTrue:[
|
|
2040 |
aStream space; nextPutAll:privacy; nextPutAll:'MethodsFor:'''.
|
412
|
2041 |
] ifFalse:[
|
415
|
2042 |
aStream nextPutAll:' methodsFor:'''.
|
412
|
2043 |
].
|
153
|
2044 |
cat := aMethod category.
|
|
2045 |
cat notNil ifTrue:[
|
|
2046 |
aStream nextPutAll:cat
|
|
2047 |
].
|
432
|
2048 |
aStream nextPut:$'; nextPutChunkSeparator; cr; cr.
|
153
|
2049 |
source := aMethod source.
|
|
2050 |
source isNil ifTrue:[
|
|
2051 |
FileOutErrorSignal
|
|
2052 |
raiseRequestWith:self
|
|
2053 |
errorString:('no source for method: ' ,
|
|
2054 |
self name , '>>' ,
|
328
|
2055 |
(self selectorAtMethod:aMethod))
|
153
|
2056 |
] ifFalse:[
|
362
|
2057 |
aStream nextChunkPut:source.
|
153
|
2058 |
].
|
|
2059 |
aStream space.
|
432
|
2060 |
aStream nextPutChunkSeparator.
|
153
|
2061 |
aStream cr
|
1
|
2062 |
]
|
412
|
2063 |
|
|
2064 |
"Modified: 27.8.1995 / 01:23:19 / claus"
|
1
|
2065 |
!
|
|
2066 |
|
|
2067 |
fileOutOn:aStream
|
92
|
2068 |
"file out my definition and all methods onto aStream"
|
|
2069 |
|
432
|
2070 |
|collectionOfCategories copyrightText comment cls|
|
92
|
2071 |
|
403
|
2072 |
self isLoaded ifFalse:[
|
|
2073 |
^ FileOutErrorSignal
|
|
2074 |
raiseRequestWith:self
|
|
2075 |
errorString:'will not fileOut unloaded classes'
|
|
2076 |
].
|
|
2077 |
|
92
|
2078 |
"
|
216
|
2079 |
if there is a copyright method, add a copyright comment
|
|
2080 |
at the beginning, taking the string from the copyright method.
|
199
|
2081 |
We cannot do this unconditionally - that would lead to my copyrights
|
|
2082 |
being put on your code ;-).
|
|
2083 |
On the other hand: I want every file created by myself to have the
|
|
2084 |
copyright string at the beginning be preserved .... even if the
|
|
2085 |
code was edited in the browser and filedOut.
|
92
|
2086 |
"
|
356
|
2087 |
((cls := self class) selectorArray includes:#copyright) ifTrue:[
|
153
|
2088 |
"
|
|
2089 |
get the copyright methods source,
|
|
2090 |
and insert at beginning.
|
|
2091 |
"
|
356
|
2092 |
copyrightText := (cls compiledMethodAt:#copyright) source.
|
153
|
2093 |
copyrightText isNil ifTrue:[
|
|
2094 |
"
|
|
2095 |
no source available - trigger an error
|
|
2096 |
"
|
399
|
2097 |
FileOutErrorSignal
|
|
2098 |
raiseRequestWith:'no source for class ' , name , ' available. Cannot fileOut'.
|
153
|
2099 |
^ self
|
|
2100 |
].
|
|
2101 |
copyrightText := copyrightText asCollectionOfLines.
|
|
2102 |
copyrightText := copyrightText copyFrom:2 to:(copyrightText size).
|
|
2103 |
copyrightText do:[:line | aStream nextPutAll:line. aStream cr.].
|
92
|
2104 |
].
|
1
|
2105 |
|
92
|
2106 |
"
|
|
2107 |
first, a timestamp
|
|
2108 |
"
|
1
|
2109 |
aStream nextPutAll:(Smalltalk timeStamp).
|
432
|
2110 |
aStream nextPutChunkSeparator.
|
333
|
2111 |
aStream cr; cr.
|
92
|
2112 |
|
|
2113 |
"
|
|
2114 |
then the definition
|
|
2115 |
"
|
1
|
2116 |
self fileOutDefinitionOn:aStream.
|
432
|
2117 |
aStream nextPutChunkSeparator.
|
333
|
2118 |
aStream cr; cr.
|
92
|
2119 |
"
|
|
2120 |
optional classInstanceVariables
|
|
2121 |
"
|
1
|
2122 |
self class instanceVariableString isBlank ifFalse:[
|
153
|
2123 |
self fileOutClassInstVarDefinitionOn:aStream.
|
432
|
2124 |
aStream nextPutChunkSeparator.
|
333
|
2125 |
aStream cr; cr
|
1
|
2126 |
].
|
|
2127 |
|
92
|
2128 |
"
|
|
2129 |
a comment - if any
|
|
2130 |
"
|
193
|
2131 |
(comment := self comment) notNil ifTrue:[
|
333
|
2132 |
aStream nextPutAll:name; nextPutAll:' comment:'.
|
153
|
2133 |
aStream nextPutAll:(comment storeString).
|
432
|
2134 |
aStream nextPutChunkSeparator.
|
333
|
2135 |
aStream cr; cr
|
1
|
2136 |
].
|
92
|
2137 |
|
|
2138 |
"
|
216
|
2139 |
primitive definitions - if any
|
|
2140 |
"
|
|
2141 |
self fileOutPrimitiveSpecsOn:aStream.
|
|
2142 |
|
|
2143 |
"
|
92
|
2144 |
methods from all categories in metaclass
|
|
2145 |
"
|
362
|
2146 |
collectionOfCategories := self class categories asSortedCollection.
|
1
|
2147 |
collectionOfCategories notNil ifTrue:[
|
168
|
2148 |
"
|
199
|
2149 |
documentation first (if any)
|
168
|
2150 |
"
|
|
2151 |
(collectionOfCategories includes:'documentation') ifTrue:[
|
|
2152 |
self class fileOutCategory:'documentation' on:aStream.
|
199
|
2153 |
aStream cr.
|
|
2154 |
].
|
|
2155 |
"
|
|
2156 |
initialization next (if any)
|
|
2157 |
"
|
|
2158 |
(collectionOfCategories includes:'initialization') ifTrue:[
|
|
2159 |
self class fileOutCategory:'initialization' on:aStream.
|
|
2160 |
aStream cr.
|
|
2161 |
].
|
|
2162 |
"
|
|
2163 |
instance creation next (if any)
|
|
2164 |
"
|
|
2165 |
(collectionOfCategories includes:'instance creation') ifTrue:[
|
213
|
2166 |
self class fileOutCategory:'instance creation' on:aStream.
|
199
|
2167 |
aStream cr.
|
168
|
2168 |
].
|
153
|
2169 |
collectionOfCategories do:[:aCategory |
|
199
|
2170 |
((aCategory ~= 'documentation')
|
|
2171 |
and:[(aCategory ~= 'initialization')
|
|
2172 |
and:[aCategory ~= 'instance creation']]) ifTrue:[
|
168
|
2173 |
self class fileOutCategory:aCategory on:aStream.
|
|
2174 |
aStream cr
|
|
2175 |
]
|
153
|
2176 |
]
|
1
|
2177 |
].
|
92
|
2178 |
"
|
|
2179 |
methods from all categories in myself
|
|
2180 |
"
|
362
|
2181 |
collectionOfCategories := self categories asSortedCollection.
|
1
|
2182 |
collectionOfCategories notNil ifTrue:[
|
153
|
2183 |
collectionOfCategories do:[:aCategory |
|
|
2184 |
self fileOutCategory:aCategory on:aStream.
|
|
2185 |
aStream cr
|
|
2186 |
]
|
1
|
2187 |
].
|
92
|
2188 |
"
|
|
2189 |
optionally an initialize message
|
|
2190 |
"
|
1
|
2191 |
(self class implements:#initialize) ifTrue:[
|
153
|
2192 |
aStream nextPutAll:(name , ' initialize').
|
432
|
2193 |
aStream nextPutChunkSeparator.
|
153
|
2194 |
aStream cr
|
1
|
2195 |
]
|
|
2196 |
!
|
|
2197 |
|
|
2198 |
fileOutCategory:aCategory
|
54
|
2199 |
"create a file 'class-category.st' consisting of all methods in aCategory.
|
|
2200 |
If the current project is not nil, create the file in the projects
|
|
2201 |
directory."
|
1
|
2202 |
|
139
|
2203 |
|aStream fileName|
|
1
|
2204 |
|
|
2205 |
fileName := name , '-' , aCategory , '.st'.
|
77
|
2206 |
fileName replaceAll:(Character space) by:$_.
|
139
|
2207 |
|
|
2208 |
"
|
|
2209 |
this test allows a smalltalk to be built without Projects/ChangeSets
|
|
2210 |
"
|
68
|
2211 |
Project notNil ifTrue:[
|
153
|
2212 |
fileName := Project currentProjectDirectory , fileName.
|
|
2213 |
].
|
|
2214 |
|
|
2215 |
"
|
|
2216 |
if file exists, save original in a .sav file
|
|
2217 |
"
|
|
2218 |
fileName asFilename exists ifTrue:[
|
|
2219 |
fileName asFilename copyTo:(fileName , '.sav')
|
54
|
2220 |
].
|
1
|
2221 |
aStream := FileStream newFileNamed:fileName.
|
153
|
2222 |
aStream isNil ifTrue:[
|
356
|
2223 |
^ FileOutErrorSignal
|
|
2224 |
raiseRequestWith:fileName
|
|
2225 |
errorString:('cannot create file:', fileName)
|
153
|
2226 |
].
|
1
|
2227 |
self fileOutCategory:aCategory on:aStream.
|
|
2228 |
aStream close
|
|
2229 |
!
|
|
2230 |
|
|
2231 |
fileOutMethod:aMethod
|
54
|
2232 |
"create a file 'class-method.st' consisting of the method, aMethod.
|
|
2233 |
If the current project is not nil, create the file in the projects
|
|
2234 |
directory."
|
1
|
2235 |
|
139
|
2236 |
|aStream fileName selector|
|
1
|
2237 |
|
328
|
2238 |
selector := self selectorAtMethod:aMethod.
|
1
|
2239 |
selector notNil ifTrue:[
|
153
|
2240 |
fileName := name , '-' , selector, '.st'.
|
|
2241 |
fileName replaceAll:$: by:$_.
|
|
2242 |
"
|
|
2243 |
this test allows a smalltalk to be built without Projects/ChangeSets
|
|
2244 |
"
|
|
2245 |
Project notNil ifTrue:[
|
|
2246 |
fileName := Project currentProjectDirectory , fileName.
|
|
2247 |
].
|
|
2248 |
|
|
2249 |
"
|
|
2250 |
if file exists, save original in a .sav file
|
|
2251 |
"
|
|
2252 |
fileName asFilename exists ifTrue:[
|
|
2253 |
fileName asFilename copyTo:(fileName , '.sav')
|
|
2254 |
].
|
|
2255 |
aStream := FileStream newFileNamed:fileName.
|
|
2256 |
aStream isNil ifTrue:[
|
356
|
2257 |
^ FileOutErrorSignal
|
|
2258 |
raiseRequestWith:fileName
|
|
2259 |
errorString:('cannot create file:', fileName)
|
153
|
2260 |
].
|
|
2261 |
self fileOutMethod:aMethod on:aStream.
|
|
2262 |
aStream close
|
1
|
2263 |
]
|
|
2264 |
!
|
|
2265 |
|
|
2266 |
fileOut
|
54
|
2267 |
"create a file 'class.st' consisting of all methods in myself.
|
|
2268 |
If the current project is not nil, create the file in the projects
|
153
|
2269 |
directory. Care is taken, to not clobber any existing file in
|
356
|
2270 |
case of errors (for example: disk full).
|
|
2271 |
Also, since the classes methods need a valid sourcefile, the current
|
|
2272 |
sourceFile may not be rewritten."
|
|
2273 |
|
|
2274 |
|aStream baseName dirName fileName newFileName needRename
|
|
2275 |
mySourceFileName sameFile|
|
1
|
2276 |
|
153
|
2277 |
baseName := (Smalltalk fileNameForClass:self name).
|
|
2278 |
fileName := baseName , '.st'.
|
356
|
2279 |
|
139
|
2280 |
"
|
|
2281 |
this test allows a smalltalk to be built without Projects/ChangeSets
|
|
2282 |
"
|
68
|
2283 |
Project notNil ifTrue:[
|
153
|
2284 |
dirName := Project currentProjectDirectory
|
|
2285 |
] ifFalse:[
|
|
2286 |
dirName := ''
|
54
|
2287 |
].
|
153
|
2288 |
fileName := dirName , fileName.
|
356
|
2289 |
|
153
|
2290 |
"
|
|
2291 |
if file exists, copy the existing to a .sav-file,
|
199
|
2292 |
create the new file as XXX.new-file,
|
153
|
2293 |
and, if that worked rename afterwards ...
|
|
2294 |
"
|
357
|
2295 |
(fileName asFilename exists
|
|
2296 |
and:[classFilename notNil]) ifTrue:[
|
356
|
2297 |
"
|
|
2298 |
check for overwriting my current source file
|
|
2299 |
this is not allowed, since it would clobber my methods source
|
|
2300 |
file ... you have to save it to some other place.
|
|
2301 |
This happens if you ask for a fileOut into the source-directory
|
|
2302 |
(from which my methods get their source)
|
|
2303 |
"
|
|
2304 |
mySourceFileName := Smalltalk getSourceFileName:classFilename.
|
|
2305 |
sameFile := (fileName = mySourceFileName).
|
|
2306 |
sameFile ifFalse:[
|
|
2307 |
sameFile := (fileName asFilename info at:#id) == (mySourceFileName asFilename info at:#id)
|
|
2308 |
].
|
|
2309 |
sameFile ifTrue:[
|
|
2310 |
^ FileOutErrorSignal
|
|
2311 |
raiseRequestWith:fileName
|
|
2312 |
errorString:('may not overwrite sourcefile:', fileName)
|
|
2313 |
].
|
|
2314 |
|
153
|
2315 |
fileName asFilename copyTo:('/tmp/' , baseName , '.sav').
|
|
2316 |
newFileName := dirName , baseName , '.new'.
|
|
2317 |
needRename := true
|
|
2318 |
] ifFalse:[
|
|
2319 |
newFileName := fileName.
|
|
2320 |
needRename := false
|
|
2321 |
].
|
|
2322 |
|
|
2323 |
aStream := FileStream newFileNamed:newFileName.
|
1
|
2324 |
aStream isNil ifTrue:[
|
356
|
2325 |
^ FileOutErrorSignal
|
|
2326 |
raiseRequestWith:newFileName
|
|
2327 |
errorString:('cannot create file:', newFileName)
|
1
|
2328 |
].
|
|
2329 |
self fileOutOn:aStream.
|
153
|
2330 |
aStream close.
|
|
2331 |
|
|
2332 |
"
|
|
2333 |
finally, replace the old-file
|
|
2334 |
be careful, if the old one is a symbolic link; in this case,
|
|
2335 |
we have to do a copy ...
|
|
2336 |
"
|
|
2337 |
needRename ifTrue:[
|
|
2338 |
newFileName asFilename copyTo:fileName.
|
|
2339 |
newFileName asFilename delete
|
|
2340 |
].
|
199
|
2341 |
|
|
2342 |
"
|
|
2343 |
add a change record; that way, administration is much easier,
|
|
2344 |
since we can see in that changeBrowser, which changes have
|
|
2345 |
already found their way into a sourceFile and which must be
|
|
2346 |
applied again
|
|
2347 |
"
|
|
2348 |
self addChangeRecordForClassFileOut:self
|
1
|
2349 |
!
|
|
2350 |
|
|
2351 |
fileOutIn:aFileDirectory
|
|
2352 |
"create a file 'class.st' consisting of all methods in self in
|
139
|
2353 |
directory aFileDirectory (ignoring any directory setting in
|
199
|
2354 |
the current porject).
|
|
2355 |
This is not logged in that change file (should it be ?)."
|
1
|
2356 |
|
|
2357 |
|aStream fileName|
|
|
2358 |
|
54
|
2359 |
fileName := (Smalltalk fileNameForClass:self name) , '.st'.
|
139
|
2360 |
aStream := FileStream newFileNamed:fileName in:aFileDirectory.
|
1
|
2361 |
aStream isNil ifTrue:[
|
356
|
2362 |
^ FileOutErrorSignal
|
|
2363 |
raiseRequestWith:fileName
|
|
2364 |
errorString:('cannot create file:', fileName)
|
1
|
2365 |
].
|
|
2366 |
self fileOutOn:aStream.
|
|
2367 |
aStream close
|
54
|
2368 |
! !
|
|
2369 |
|
1
|
2370 |
!Class methodsFor:'printOut'!
|
|
2371 |
|
54
|
2372 |
printClassNameOn:aStream
|
|
2373 |
"helper for fileOut - print my name if I am not a Metaclass;
|
|
2374 |
otherwise my name without -class followed by space-class"
|
|
2375 |
|
|
2376 |
self isMeta ifTrue:[
|
333
|
2377 |
aStream nextPutAll:(name copyTo:(name size - 5)); nextPutAll:' class'
|
54
|
2378 |
] ifFalse:[
|
153
|
2379 |
name printOn:aStream
|
54
|
2380 |
]
|
|
2381 |
!
|
|
2382 |
|
|
2383 |
printNameArray:anArray on:aStream indent:indent
|
|
2384 |
"print an array of strings separated by spaces; when the stream
|
|
2385 |
defines a lineLength, break when this limit is reached; indent
|
293
|
2386 |
every line; used to printOut instance variable names"
|
54
|
2387 |
|
|
2388 |
|thisName nextName arraySize lenMax pos mustBreak line spaces|
|
|
2389 |
|
|
2390 |
arraySize := anArray size.
|
|
2391 |
arraySize ~~ 0 ifTrue:[
|
153
|
2392 |
pos := indent.
|
|
2393 |
lenMax := aStream lineLength.
|
|
2394 |
thisName := anArray at:1.
|
|
2395 |
line := ''.
|
|
2396 |
1 to:arraySize do:[:index |
|
|
2397 |
line := line , thisName.
|
|
2398 |
pos := pos + thisName size.
|
|
2399 |
(index == arraySize) ifFalse:[
|
|
2400 |
nextName := anArray at:(index + 1).
|
|
2401 |
mustBreak := false.
|
|
2402 |
(lenMax > 0) ifTrue:[
|
|
2403 |
((pos + nextName size) > lenMax) ifTrue:[
|
|
2404 |
mustBreak := true
|
|
2405 |
]
|
|
2406 |
].
|
|
2407 |
mustBreak ifTrue:[
|
|
2408 |
aStream nextPutAll:line.
|
|
2409 |
aStream cr.
|
|
2410 |
spaces isNil ifTrue:[
|
|
2411 |
spaces := String new:indent
|
|
2412 |
].
|
|
2413 |
line := spaces.
|
|
2414 |
pos := indent
|
|
2415 |
] ifFalse:[
|
|
2416 |
line := line , ' '.
|
|
2417 |
pos := pos + 1
|
|
2418 |
].
|
|
2419 |
thisName := nextName
|
|
2420 |
]
|
|
2421 |
].
|
|
2422 |
aStream nextPutAll:line
|
54
|
2423 |
]
|
|
2424 |
!
|
|
2425 |
|
|
2426 |
printClassVarNamesOn:aStream indent:indent
|
|
2427 |
"print the class variable names indented and breaking at line end"
|
|
2428 |
|
|
2429 |
self printNameArray:(self classVarNames) on:aStream indent:indent
|
|
2430 |
!
|
|
2431 |
|
|
2432 |
printInstVarNamesOn:aStream indent:indent
|
|
2433 |
"print the instance variable names indented and breaking at line end"
|
|
2434 |
|
|
2435 |
self printNameArray:(self instVarNames) on:aStream indent:indent
|
|
2436 |
!
|
|
2437 |
|
|
2438 |
printHierarchyOn:aStream
|
|
2439 |
"print my class hierarchy on aStream"
|
|
2440 |
|
|
2441 |
self printHierarchyAnswerIndentOn:aStream
|
|
2442 |
!
|
|
2443 |
|
|
2444 |
printHierarchyAnswerIndentOn:aStream
|
|
2445 |
"print my class hierarchy on aStream - return indent
|
|
2446 |
recursively calls itself to print superclass and use returned indent
|
|
2447 |
for my description - used in the browser"
|
|
2448 |
|
|
2449 |
|indent|
|
|
2450 |
|
|
2451 |
indent := 0.
|
|
2452 |
(superclass notNil) ifTrue:[
|
153
|
2453 |
indent := (superclass printHierarchyAnswerIndentOn:aStream) + 2
|
54
|
2454 |
].
|
|
2455 |
aStream spaces:indent.
|
333
|
2456 |
aStream nextPutAll:name; nextPutAll:' ('.
|
54
|
2457 |
self printInstVarNamesOn:aStream indent:(indent + name size + 2).
|
|
2458 |
aStream nextPutAll:')'.
|
|
2459 |
aStream cr.
|
|
2460 |
^ indent
|
|
2461 |
!
|
|
2462 |
|
|
2463 |
printFullHierarchyOn:aStream indent:indent
|
|
2464 |
"print myself and all subclasses on aStream.
|
|
2465 |
recursively calls itself to print subclasses.
|
|
2466 |
Can be used to print hierarchy on the printer."
|
|
2467 |
|
333
|
2468 |
aStream spaces:indent; bold; nextPutAll:name; normal; nextPutAll:' ('.
|
54
|
2469 |
self printInstVarNamesOn:aStream indent:(indent + name size + 2).
|
|
2470 |
aStream nextPutAll:')'.
|
|
2471 |
aStream cr.
|
|
2472 |
|
|
2473 |
(self subclasses sort:[:a :b | a name < b name]) do:[:aSubclass |
|
153
|
2474 |
aSubclass printFullHierarchyOn:aStream indent:(indent + 2)
|
54
|
2475 |
]
|
|
2476 |
|
|
2477 |
"|printStream|
|
|
2478 |
printStream := Printer new.
|
|
2479 |
Object printFullHierarchyOn:printStream indent:0.
|
|
2480 |
printStream close"
|
|
2481 |
!
|
|
2482 |
|
1
|
2483 |
printOutDefinitionOn:aPrintStream
|
|
2484 |
"print out my definition"
|
|
2485 |
|
333
|
2486 |
|comment s|
|
|
2487 |
|
|
2488 |
aPrintStream nextPutAll:'class '; bold; nextPutAll:name; normal; cr.
|
1
|
2489 |
aPrintStream nextPutAll:'superclass '.
|
|
2490 |
superclass isNil ifTrue:[
|
333
|
2491 |
s := 'Object'
|
1
|
2492 |
] ifFalse:[
|
333
|
2493 |
s := superclass name
|
1
|
2494 |
].
|
333
|
2495 |
aPrintStream nextPutAll:s.
|
1
|
2496 |
aPrintStream cr.
|
|
2497 |
|
|
2498 |
aPrintStream nextPutAll:'instance Variables '.
|
|
2499 |
self printInstVarNamesOn:aPrintStream indent:21.
|
|
2500 |
aPrintStream cr.
|
|
2501 |
|
|
2502 |
aPrintStream nextPutAll:'class Variables '.
|
|
2503 |
self printClassVarNamesOn:aPrintStream indent:21.
|
|
2504 |
aPrintStream cr.
|
|
2505 |
|
|
2506 |
category notNil ifTrue:[
|
333
|
2507 |
aPrintStream nextPutAll:'category '; nextPutAll:(category printString).
|
153
|
2508 |
aPrintStream cr
|
1
|
2509 |
].
|
|
2510 |
|
193
|
2511 |
(comment := self comment) notNil ifTrue:[
|
333
|
2512 |
aPrintStream cr; nextPutAll:'comment:'; cr; italic; nextPutAll:comment; normal; cr
|
1
|
2513 |
]
|
|
2514 |
!
|
|
2515 |
|
155
|
2516 |
printOutSourceProtocol:aMethod on:aPrintStream
|
1
|
2517 |
"given the source in aString, print the methods message specification
|
|
2518 |
and any method comments - without source; used to generate documentation
|
|
2519 |
pages"
|
|
2520 |
|
155
|
2521 |
|text|
|
1
|
2522 |
|
247
|
2523 |
text := aMethod source asStringCollection.
|
1
|
2524 |
(text size < 1) ifTrue:[^self].
|
|
2525 |
aPrintStream bold.
|
|
2526 |
aPrintStream nextPutAll:(text at:1).
|
|
2527 |
aPrintStream cr.
|
|
2528 |
(text size >= 2) ifTrue:[
|
153
|
2529 |
aPrintStream italic.
|
155
|
2530 |
aPrintStream spaces:((text at:2) indexOfNonSeparatorStartingAt:1).
|
|
2531 |
aPrintStream nextPutAll:aMethod comment.
|
|
2532 |
aPrintStream cr.
|
1
|
2533 |
].
|
|
2534 |
aPrintStream normal
|
155
|
2535 |
|
|
2536 |
"
|
|
2537 |
Float printOutProtocolOn:Stdout
|
|
2538 |
"
|
1
|
2539 |
!
|
|
2540 |
|
|
2541 |
printOutSource:aString on:aPrintStream
|
|
2542 |
"print out a source-string; the message-specification is printed bold,
|
|
2543 |
comments are printed italic"
|
|
2544 |
|
|
2545 |
|text textIndex textSize line lineIndex lineSize inComment aCharacter|
|
247
|
2546 |
text := aString asStringCollection.
|
1
|
2547 |
aPrintStream bold.
|
|
2548 |
aPrintStream nextPutAll:(text at:1).
|
|
2549 |
aPrintStream normal.
|
|
2550 |
aPrintStream cr.
|
|
2551 |
inComment := false.
|
|
2552 |
textSize := text size.
|
|
2553 |
textIndex := 2.
|
|
2554 |
[textIndex <= textSize] whileTrue:[
|
153
|
2555 |
line := text at:textIndex.
|
|
2556 |
((line occurrencesOf:Character doubleQuote) == 0) ifTrue:[
|
|
2557 |
aPrintStream nextPutAll:line
|
|
2558 |
] ifFalse:[
|
|
2559 |
lineSize := line size.
|
|
2560 |
lineIndex := 1.
|
|
2561 |
[lineIndex <= lineSize] whileTrue:[
|
|
2562 |
aCharacter := line at:lineIndex.
|
|
2563 |
(aCharacter == Character doubleQuote) ifTrue:[
|
|
2564 |
inComment ifTrue:[
|
|
2565 |
aPrintStream normal.
|
|
2566 |
aPrintStream nextPut:aCharacter.
|
|
2567 |
inComment := false
|
|
2568 |
] ifFalse:[
|
|
2569 |
aPrintStream nextPut:aCharacter.
|
|
2570 |
aPrintStream italic.
|
|
2571 |
inComment := true
|
|
2572 |
]
|
|
2573 |
] ifFalse:[
|
|
2574 |
aPrintStream nextPut:aCharacter
|
|
2575 |
].
|
|
2576 |
lineIndex := lineIndex + 1
|
|
2577 |
]
|
|
2578 |
].
|
|
2579 |
aPrintStream cr.
|
|
2580 |
textIndex := textIndex + 1
|
1
|
2581 |
]
|
|
2582 |
!
|
|
2583 |
|
|
2584 |
printOutCategory:aCategory on:aPrintStream
|
|
2585 |
"print out all methods in aCategory on aPrintStream should be a PrintStream"
|
|
2586 |
|
|
2587 |
|any|
|
92
|
2588 |
methodArray notNil ifTrue:[
|
153
|
2589 |
any := false.
|
|
2590 |
methodArray do:[:aMethod |
|
|
2591 |
(aCategory = aMethod category) ifTrue:[
|
|
2592 |
any := true
|
|
2593 |
]
|
|
2594 |
].
|
|
2595 |
any ifTrue:[
|
|
2596 |
aPrintStream italic.
|
|
2597 |
aPrintStream nextPutAll:aCategory.
|
|
2598 |
aPrintStream normal.
|
333
|
2599 |
aPrintStream cr; cr.
|
153
|
2600 |
methodArray do:[:aMethod |
|
|
2601 |
(aCategory = aMethod category) ifTrue:[
|
|
2602 |
self printOutSource:(aMethod source) on:aPrintStream.
|
333
|
2603 |
aPrintStream cr; cr
|
153
|
2604 |
]
|
|
2605 |
].
|
|
2606 |
aPrintStream cr
|
|
2607 |
]
|
1
|
2608 |
]
|
|
2609 |
!
|
|
2610 |
|
|
2611 |
printOutOn:aPrintStream
|
|
2612 |
"print out all methods on aPrintStream which should be a printStream"
|
|
2613 |
|
|
2614 |
|collectionOfCategories|
|
333
|
2615 |
|
1
|
2616 |
self printOutDefinitionOn:aPrintStream.
|
|
2617 |
aPrintStream cr.
|
|
2618 |
collectionOfCategories := self class categories.
|
|
2619 |
collectionOfCategories notNil ifTrue:[
|
153
|
2620 |
aPrintStream nextPutAll:'class protocol'.
|
333
|
2621 |
aPrintStream cr; cr.
|
153
|
2622 |
collectionOfCategories do:[:aCategory |
|
|
2623 |
self class printOutCategory:aCategory on:aPrintStream
|
|
2624 |
]
|
1
|
2625 |
].
|
|
2626 |
collectionOfCategories := self categories.
|
|
2627 |
collectionOfCategories notNil ifTrue:[
|
153
|
2628 |
aPrintStream nextPutAll:'instance protocol'.
|
333
|
2629 |
aPrintStream cr; cr.
|
153
|
2630 |
collectionOfCategories do:[:aCategory |
|
|
2631 |
self printOutCategory:aCategory on:aPrintStream
|
|
2632 |
]
|
1
|
2633 |
]
|
|
2634 |
!
|
|
2635 |
|
|
2636 |
printOutCategoryProtocol:aCategory on:aPrintStream
|
|
2637 |
|any|
|
54
|
2638 |
|
92
|
2639 |
methodArray notNil ifTrue:[
|
153
|
2640 |
any := false.
|
|
2641 |
methodArray do:[:aMethod |
|
|
2642 |
(aCategory = aMethod category) ifTrue:[
|
|
2643 |
any := true
|
|
2644 |
]
|
|
2645 |
].
|
|
2646 |
any ifTrue:[
|
|
2647 |
aPrintStream italic.
|
|
2648 |
aPrintStream nextPutAll:aCategory.
|
|
2649 |
aPrintStream normal.
|
333
|
2650 |
aPrintStream cr; cr.
|
153
|
2651 |
methodArray do:[:aMethod |
|
|
2652 |
(aCategory = aMethod category) ifTrue:[
|
155
|
2653 |
self printOutSourceProtocol:aMethod
|
153
|
2654 |
on:aPrintStream.
|
333
|
2655 |
aPrintStream cr; cr
|
153
|
2656 |
]
|
|
2657 |
].
|
|
2658 |
aPrintStream cr
|
|
2659 |
]
|
1
|
2660 |
]
|
|
2661 |
!
|
|
2662 |
|
|
2663 |
printOutProtocolOn:aPrintStream
|
|
2664 |
|collectionOfCategories|
|
|
2665 |
self printOutDefinitionOn:aPrintStream.
|
|
2666 |
aPrintStream cr.
|
|
2667 |
collectionOfCategories := self class categories.
|
|
2668 |
collectionOfCategories notNil ifTrue:[
|
153
|
2669 |
aPrintStream nextPutAll:'class protocol'.
|
333
|
2670 |
aPrintStream cr; cr.
|
153
|
2671 |
collectionOfCategories do:[:aCategory |
|
|
2672 |
self class printOutCategoryProtocol:aCategory on:aPrintStream
|
|
2673 |
]
|
1
|
2674 |
].
|
|
2675 |
collectionOfCategories := self categories.
|
|
2676 |
collectionOfCategories notNil ifTrue:[
|
153
|
2677 |
aPrintStream nextPutAll:'instance protocol'.
|
333
|
2678 |
aPrintStream cr; cr.
|
153
|
2679 |
collectionOfCategories do:[:aCategory |
|
|
2680 |
self printOutCategoryProtocol:aCategory on:aPrintStream
|
|
2681 |
]
|
1
|
2682 |
]
|
|
2683 |
! !
|
2
|
2684 |
|
|
2685 |
!Class methodsFor: 'binary storage'!
|
|
2686 |
|
|
2687 |
addGlobalsTo: globalDictionary manager: manager
|
|
2688 |
"
|
|
2689 |
classPool == nil ifFalse: [
|
153
|
2690 |
classPool associationsDo: [:assoc|
|
|
2691 |
globalDictionary at: assoc put: self
|
|
2692 |
]
|
2
|
2693 |
]
|
|
2694 |
"
|
|
2695 |
!
|
|
2696 |
|
293
|
2697 |
storeBinaryDefinitionOn: stream manager: manager
|
|
2698 |
"classes will store the name, signature and instvar names.
|
|
2699 |
They restore by looking for that name in the Smalltalk dictionary.
|
|
2700 |
However, using the signature, a check for being valid is made at
|
|
2701 |
restore time."
|
|
2702 |
|
|
2703 |
|varnames n sz|
|
|
2704 |
|
|
2705 |
"
|
|
2706 |
output the signature
|
|
2707 |
"
|
|
2708 |
stream nextNumber:4 put:self signature.
|
|
2709 |
|
|
2710 |
"
|
345
|
2711 |
output the instance variable name string
|
293
|
2712 |
"
|
|
2713 |
varnames := self allInstVarNames.
|
|
2714 |
n := varnames size.
|
|
2715 |
n == 0 ifTrue:[
|
|
2716 |
sz := 0
|
|
2717 |
] ifFalse:[
|
|
2718 |
sz := varnames inject:0 into:[:sum :nm | sum + nm size].
|
|
2719 |
sz := sz + n - 1.
|
|
2720 |
].
|
|
2721 |
stream nextNumber:2 put:sz.
|
|
2722 |
varnames keysAndValuesDo:[:i :nm |
|
|
2723 |
nm do:[:c |
|
|
2724 |
stream nextPut:c asciiValue
|
|
2725 |
].
|
|
2726 |
i ~~ n ifTrue:[stream nextPut:(Character space asciiValue)]
|
|
2727 |
].
|
|
2728 |
|
|
2729 |
"
|
|
2730 |
output my name
|
|
2731 |
"
|
|
2732 |
stream nextNumber:2 put:name size.
|
|
2733 |
name do:[:c|
|
|
2734 |
stream nextPut:c asciiValue
|
|
2735 |
]
|
|
2736 |
|
|
2737 |
"
|
|
2738 |
|s|
|
|
2739 |
s := WriteStream on:ByteArray new.
|
|
2740 |
Rectangle storeBinaryOn:s.
|
|
2741 |
Object readBinaryFrom:(ReadStream on:s contents)
|
|
2742 |
"
|
|
2743 |
!
|
|
2744 |
|
2
|
2745 |
storeBinaryDefinitionOf: anAssociation on: stream manager: manager
|
37
|
2746 |
"not usable at the moment - there are no classpools currently"
|
|
2747 |
|
2
|
2748 |
| string |
|
|
2749 |
|
|
2750 |
string := self name, ' classPool at: ', anAssociation key storeString.
|
|
2751 |
stream nextNumber: 2 put: string size.
|
|
2752 |
string do: [:char| stream nextPut: char asciiValue]
|
|
2753 |
! !
|