1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
ClassDescription subclass:#Class
|
2
|
14 |
instanceVariableNames:'classvars comment subclasses classFileName'
|
1
|
15 |
classVariableNames:'updatingChanges'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Classes'
|
|
18 |
!
|
|
19 |
|
|
20 |
Class comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1989-93 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
This class adds more functionality to classes; minimum stuff has already
|
|
26 |
been defined in Behavior; this one adds naming, categories etc.
|
|
27 |
also changes management and recompilation is defined here.
|
|
28 |
|
|
29 |
For a minimum system, the compiler generates classes as instances of
|
|
30 |
Behavior - this excludes all name, source info etc., however, the more
|
|
31 |
usual case is to create instances of Class.
|
|
32 |
|
|
33 |
Instance variables:
|
|
34 |
|
|
35 |
classvars <String> the names of the class variables
|
|
36 |
comment <String> the classes comment
|
|
37 |
subclasses <Collection> cached collection of subclasses
|
|
38 |
(currently unused - but will be soon)
|
2
|
39 |
classFileName <String> the file (or nil) where the classes
|
|
40 |
sources are found
|
1
|
41 |
|
|
42 |
Class variables:
|
|
43 |
|
|
44 |
updatingChanges <Boolean> true if the changes-file shall be updated
|
|
45 |
|
|
46 |
WARNING: layout known by compiler and runtime system
|
|
47 |
|
3
|
48 |
$Header: /cvs/stx/stx/libbasic/Class.st,v 1.3 1993-10-13 00:15:14 claus Exp $
|
1
|
49 |
written Spring 89 by claus
|
|
50 |
'!
|
|
51 |
|
|
52 |
!Class class methodsFor:'initialization'!
|
|
53 |
|
|
54 |
initialize
|
|
55 |
"the classvariable 'updatingChanges' controls if changes are put
|
|
56 |
into the changes-file; normally this variable is set to true, but
|
|
57 |
for example during fileIn or when changes are applied, it is set to false
|
|
58 |
to prevent changes file from getting too much junk."
|
|
59 |
|
|
60 |
updatingChanges := true
|
|
61 |
! !
|
|
62 |
|
|
63 |
!Class class methodsFor:'creating new classes'!
|
|
64 |
|
|
65 |
new
|
|
66 |
"creates and returs a new class"
|
|
67 |
|
|
68 |
|newClass|
|
|
69 |
|
|
70 |
newClass := super new.
|
|
71 |
newClass setComment:(self comment)
|
|
72 |
category:(self category).
|
|
73 |
^ newClass
|
|
74 |
! !
|
|
75 |
|
|
76 |
!Class methodsFor:'autoload check'!
|
|
77 |
|
2
|
78 |
isLoaded
|
|
79 |
"return true, if the class has been loaded; redefined in Autoload;
|
|
80 |
see comment there"
|
|
81 |
|
|
82 |
^ true
|
|
83 |
!
|
|
84 |
|
1
|
85 |
autoload
|
|
86 |
"force autoloading - do nothing here; redefined in Autoload;
|
|
87 |
see comment there"
|
|
88 |
|
|
89 |
^ self
|
|
90 |
! !
|
|
91 |
|
|
92 |
!Class methodsFor:'subclass creation'!
|
|
93 |
|
|
94 |
subclass:t instanceVariableNames:f
|
|
95 |
classVariableNames:d
|
|
96 |
poolDictionaries:s
|
|
97 |
category:cat
|
|
98 |
|
|
99 |
"create a new class as a subclass of an existing class (the receiver).
|
|
100 |
The subclass will have indexed variables if the receiving-class has."
|
|
101 |
|
|
102 |
self isVariable ifFalse:[
|
|
103 |
^ self class
|
|
104 |
name:t
|
|
105 |
inEnvironment:Smalltalk
|
|
106 |
subclassOf:self
|
|
107 |
instanceVariableNames:f
|
|
108 |
variable:false
|
|
109 |
words:true
|
|
110 |
pointers:true
|
|
111 |
classVariableNames:d
|
|
112 |
poolDictionaries:s
|
|
113 |
category:cat
|
|
114 |
comment:nil
|
|
115 |
changed:false
|
|
116 |
].
|
|
117 |
self isBytes ifTrue:[
|
|
118 |
^ self
|
|
119 |
variableByteSubclass:t
|
|
120 |
instanceVariableNames:f
|
|
121 |
classVariableNames:d
|
|
122 |
poolDictionaries:s
|
|
123 |
category:cat
|
|
124 |
].
|
|
125 |
self isLongs ifTrue:[
|
|
126 |
^ self
|
|
127 |
variableLongSubclass:t
|
|
128 |
instanceVariableNames:f
|
|
129 |
classVariableNames:d
|
|
130 |
poolDictionaries:s
|
|
131 |
category:cat
|
|
132 |
].
|
|
133 |
self isFloats ifTrue:[
|
|
134 |
^ self
|
|
135 |
variableFloatSubclass:t
|
|
136 |
instanceVariableNames:f
|
|
137 |
classVariableNames:d
|
|
138 |
poolDictionaries:s
|
|
139 |
category:cat
|
|
140 |
].
|
|
141 |
self isDoubles ifTrue:[
|
|
142 |
^ self
|
|
143 |
variableDoubleSubclass:t
|
|
144 |
instanceVariableNames:f
|
|
145 |
classVariableNames:d
|
|
146 |
poolDictionaries:s
|
|
147 |
category:cat
|
|
148 |
].
|
2
|
149 |
self isWords ifTrue:[
|
|
150 |
^ self
|
|
151 |
variableWordSubclass:t
|
|
152 |
instanceVariableNames:f
|
|
153 |
classVariableNames:d
|
|
154 |
poolDictionaries:s
|
|
155 |
category:cat
|
|
156 |
].
|
1
|
157 |
^ self
|
2
|
158 |
variableSubclass:t
|
1
|
159 |
instanceVariableNames:f
|
|
160 |
classVariableNames:d
|
|
161 |
poolDictionaries:s
|
|
162 |
category:cat
|
|
163 |
!
|
|
164 |
|
|
165 |
variableSubclass:t
|
|
166 |
instanceVariableNames:f
|
|
167 |
classVariableNames:d
|
|
168 |
poolDictionaries:s
|
|
169 |
category:cat
|
|
170 |
|
|
171 |
"create a new class as a subclass of an existing class (the receiver)
|
|
172 |
in which the subclass has indexable pointer variables"
|
|
173 |
|
|
174 |
self isVariable ifTrue:[
|
|
175 |
self isPointers ifFalse:[
|
|
176 |
^ self error:
|
|
177 |
'cannot make a variable pointer subclass of a variable non-pointer class'
|
|
178 |
]
|
|
179 |
].
|
|
180 |
|
|
181 |
^ self class
|
|
182 |
name:t
|
|
183 |
inEnvironment:Smalltalk
|
|
184 |
subclassOf:self
|
|
185 |
instanceVariableNames:f
|
|
186 |
variable:true
|
|
187 |
words:false
|
|
188 |
pointers:true
|
|
189 |
classVariableNames:d
|
|
190 |
poolDictionaries:s
|
|
191 |
category:cat
|
|
192 |
comment:nil
|
|
193 |
changed:false
|
|
194 |
!
|
|
195 |
|
|
196 |
variableByteSubclass:t
|
|
197 |
instanceVariableNames:f
|
|
198 |
classVariableNames:d
|
|
199 |
poolDictionaries:s
|
|
200 |
category:cat
|
|
201 |
|
|
202 |
"create a new class as a subclass of an existing class (the receiver)
|
|
203 |
in which the subclass has indexable byte-sized nonpointer variables"
|
|
204 |
|
|
205 |
self isVariable ifTrue:[
|
|
206 |
self isBytes ifFalse:[
|
|
207 |
^ self error:
|
|
208 |
'cannot make a variable byte subclass of a variable non-byte class'
|
|
209 |
].
|
|
210 |
].
|
|
211 |
|
|
212 |
^ self class
|
|
213 |
name:t
|
|
214 |
inEnvironment:Smalltalk
|
|
215 |
subclassOf:self
|
|
216 |
instanceVariableNames:f
|
|
217 |
variable:true
|
|
218 |
words:false
|
|
219 |
pointers:false
|
|
220 |
classVariableNames:d
|
|
221 |
poolDictionaries:s
|
|
222 |
category:cat
|
|
223 |
comment:nil
|
|
224 |
changed:false
|
|
225 |
!
|
|
226 |
|
|
227 |
variableWordSubclass:t
|
|
228 |
instanceVariableNames:f
|
|
229 |
classVariableNames:d
|
|
230 |
poolDictionaries:s
|
|
231 |
category:cat
|
|
232 |
|
|
233 |
"create a new class as a subclass of an existing class (the receiver)
|
|
234 |
in which the subclass has indexable word-sized nonpointer variables"
|
|
235 |
|
|
236 |
self isVariable ifTrue:[
|
|
237 |
self isWords ifFalse:[
|
|
238 |
^ self error:
|
|
239 |
'cannot make a variable word subclass of a variable non-word class'
|
|
240 |
].
|
|
241 |
].
|
|
242 |
|
|
243 |
^ self class
|
|
244 |
name:t
|
|
245 |
inEnvironment:Smalltalk
|
|
246 |
subclassOf:self
|
|
247 |
instanceVariableNames:f
|
|
248 |
variable:true
|
|
249 |
words:true
|
|
250 |
pointers:false
|
|
251 |
classVariableNames:d
|
|
252 |
poolDictionaries:s
|
|
253 |
category:cat
|
|
254 |
comment:nil
|
|
255 |
changed:false
|
|
256 |
!
|
|
257 |
|
|
258 |
variableLongSubclass:t
|
|
259 |
instanceVariableNames:f
|
|
260 |
classVariableNames:d
|
|
261 |
poolDictionaries:s
|
|
262 |
category:cat
|
|
263 |
|
|
264 |
"create a new class as a subclass of an existing class (the receiver)
|
|
265 |
in which the subclass has indexable long-sized nonpointer variables"
|
|
266 |
|
|
267 |
self isVariable ifTrue:[
|
|
268 |
self isLongs ifFalse:[
|
|
269 |
^ self error:
|
|
270 |
'cannot make a variable long subclass of a variable non-long class'
|
|
271 |
].
|
|
272 |
].
|
|
273 |
|
|
274 |
^ self class
|
|
275 |
name:t
|
|
276 |
inEnvironment:Smalltalk
|
|
277 |
subclassOf:self
|
|
278 |
instanceVariableNames:f
|
|
279 |
variable:#long
|
|
280 |
words:false
|
|
281 |
pointers:false
|
|
282 |
classVariableNames:d
|
|
283 |
poolDictionaries:s
|
|
284 |
category:cat
|
|
285 |
comment:nil
|
|
286 |
changed:false
|
|
287 |
!
|
|
288 |
|
|
289 |
variableFloatSubclass:t
|
|
290 |
instanceVariableNames:f
|
|
291 |
classVariableNames:d
|
|
292 |
poolDictionaries:s
|
|
293 |
category:cat
|
|
294 |
|
|
295 |
"create a new class as a subclass of an existing class (the receiver)
|
|
296 |
in which the subclass has indexable float-sized nonpointer variables"
|
|
297 |
|
|
298 |
self isVariable ifTrue:[
|
|
299 |
self isFloats ifFalse:[
|
|
300 |
^ self error:
|
|
301 |
'cannot make a variable float subclass of a variable non-float class'
|
|
302 |
].
|
|
303 |
].
|
|
304 |
|
|
305 |
^ self class
|
|
306 |
name:t
|
|
307 |
inEnvironment:Smalltalk
|
|
308 |
subclassOf:self
|
|
309 |
instanceVariableNames:f
|
|
310 |
variable:#float
|
|
311 |
words:false
|
|
312 |
pointers:false
|
|
313 |
classVariableNames:d
|
|
314 |
poolDictionaries:s
|
|
315 |
category:cat
|
|
316 |
comment:nil
|
|
317 |
changed:false
|
|
318 |
!
|
|
319 |
|
|
320 |
variableDoubleSubclass:t
|
|
321 |
instanceVariableNames:f
|
|
322 |
classVariableNames:d
|
|
323 |
poolDictionaries:s
|
|
324 |
category:cat
|
|
325 |
|
|
326 |
"create a new class as a subclass of an existing class (the receiver)
|
|
327 |
in which the subclass has indexable double-sized nonpointer variables"
|
|
328 |
|
|
329 |
self isVariable ifTrue:[
|
|
330 |
self isDoubles ifFalse:[
|
|
331 |
^ self error:
|
|
332 |
'cannot make a variable double subclass of a variable non-double class'
|
|
333 |
].
|
|
334 |
].
|
|
335 |
|
|
336 |
^ self class
|
|
337 |
name:t
|
|
338 |
inEnvironment:Smalltalk
|
|
339 |
subclassOf:self
|
|
340 |
instanceVariableNames:f
|
|
341 |
variable:#double
|
|
342 |
words:false
|
|
343 |
pointers:false
|
|
344 |
classVariableNames:d
|
|
345 |
poolDictionaries:s
|
|
346 |
category:cat
|
|
347 |
comment:nil
|
|
348 |
changed:false
|
|
349 |
! !
|
|
350 |
|
|
351 |
!Class methodsFor:'ST/V subclass creation'!
|
|
352 |
|
|
353 |
subclass:t
|
|
354 |
instanceVariableNames:f
|
|
355 |
classVariableNames:d
|
|
356 |
poolDictionaries:s
|
|
357 |
|
|
358 |
"this methods allows fileIn of ST/V classes
|
|
359 |
(which seem to have no category)"
|
|
360 |
|
|
361 |
^ self subclass:t
|
|
362 |
instanceVariableNames:f
|
|
363 |
classVariableNames:d
|
|
364 |
poolDictionaries:s
|
|
365 |
category:'ST/V classes'
|
|
366 |
!
|
|
367 |
|
|
368 |
variableByteSubclass:t
|
|
369 |
classVariableNames:d
|
|
370 |
poolDictionaries:s
|
|
371 |
|
|
372 |
"this methods allows fileIn of ST/V variable byte classes
|
|
373 |
(which seem to have no category and no instvars)"
|
|
374 |
|
|
375 |
^ self variableByteSubclass:t
|
|
376 |
instanceVariableNames:''
|
|
377 |
classVariableNames:d
|
|
378 |
poolDictionaries:s
|
|
379 |
category:'ST/V classes'
|
|
380 |
!
|
|
381 |
|
|
382 |
variableSubclass:t
|
|
383 |
instanceVariableNames:f
|
|
384 |
classVariableNames:d
|
|
385 |
poolDictionaries:s
|
|
386 |
|
|
387 |
"this methods allows fileIn of ST/V variable pointer classes
|
|
388 |
(which seem to have no category)"
|
|
389 |
|
|
390 |
^ self variableSubclass:t
|
|
391 |
instanceVariableNames:f
|
|
392 |
classVariableNames:d
|
|
393 |
poolDictionaries:s
|
|
394 |
category:'ST/V classes'
|
|
395 |
! !
|
|
396 |
|
|
397 |
!Class methodsFor:'accessing'!
|
|
398 |
|
|
399 |
classVariableString
|
|
400 |
"return a string of the class variables names "
|
|
401 |
|
|
402 |
classvars isNil ifTrue:[^ ''].
|
|
403 |
^ classvars
|
|
404 |
!
|
|
405 |
|
|
406 |
classVarNames
|
|
407 |
"return a collection of the class variable name-strings"
|
|
408 |
|
|
409 |
^ self addClassVarNamesTo:(OrderedCollection new)
|
|
410 |
!
|
|
411 |
|
|
412 |
allClassVarNames
|
|
413 |
"return a collection of all the class variable name-strings
|
|
414 |
this includes all superclass-class variables"
|
|
415 |
|
|
416 |
^ self addAllClassVarNamesTo:(OrderedCollection new)
|
|
417 |
!
|
|
418 |
|
|
419 |
instVarNames
|
|
420 |
"return a collection of the instance variable name-strings"
|
|
421 |
|
|
422 |
^ self addInstVarNamesTo:(OrderedCollection new)
|
|
423 |
!
|
|
424 |
|
|
425 |
allInstVarNames
|
|
426 |
"return a collection of all the instance variable name-strings
|
|
427 |
this includes all superclass-instance variables"
|
|
428 |
|
|
429 |
^ self addAllInstVarNamesTo:(OrderedCollection new)
|
|
430 |
!
|
|
431 |
|
|
432 |
comment
|
|
433 |
"return the comment (aString) of the class"
|
|
434 |
|
|
435 |
^ comment
|
|
436 |
!
|
|
437 |
|
|
438 |
setComment:aString
|
|
439 |
"set the comment of the class to be the argument, aString;
|
|
440 |
do NOT create a change record"
|
|
441 |
|
|
442 |
comment := aString
|
|
443 |
!
|
|
444 |
|
|
445 |
comment:aString
|
|
446 |
"set the comment of the class to be the argument, aString;
|
|
447 |
create a change record"
|
|
448 |
|
|
449 |
comment := aString.
|
|
450 |
self addChangeRecordForClassComment:self
|
|
451 |
!
|
|
452 |
|
|
453 |
definition
|
|
454 |
"return an expression-string to define myself"
|
|
455 |
|
|
456 |
|s|
|
|
457 |
|
|
458 |
s := WriteStream on:(String new).
|
|
459 |
self fileOutDefinitionOn:s.
|
|
460 |
^ s contents
|
|
461 |
|
|
462 |
"Object definition"
|
|
463 |
"Point definition"
|
|
464 |
!
|
|
465 |
|
|
466 |
setComment:com category:categoryStringOrSymbol
|
|
467 |
"set the comment and category of the class;
|
|
468 |
do NOT create a change record"
|
|
469 |
|
|
470 |
comment := com.
|
|
471 |
category := categoryStringOrSymbol asSymbol
|
|
472 |
!
|
|
473 |
|
|
474 |
setName:aString
|
|
475 |
"set the classes name"
|
|
476 |
|
|
477 |
name := aString
|
|
478 |
!
|
|
479 |
|
|
480 |
setClassVariableString:aString
|
|
481 |
"set the classes classvarnames string"
|
|
482 |
|
|
483 |
classvars := aString
|
|
484 |
!
|
|
485 |
|
|
486 |
classVariableString:aString
|
|
487 |
"set the classes classvarnames string;
|
|
488 |
initialize new class variables with nil, clear and remove
|
|
489 |
old ones"
|
|
490 |
|
|
491 |
|prevVarNames varNames|
|
|
492 |
|
|
493 |
"ignore for metaclasses except the one"
|
|
494 |
(self isMeta "isKindOf:Metaclass") ifTrue:[
|
|
495 |
(self == Metaclass) ifFalse:[
|
|
496 |
^ self
|
|
497 |
]
|
|
498 |
].
|
|
499 |
(classvars = aString) ifFalse:[
|
|
500 |
prevVarNames := self classVarNames.
|
|
501 |
classvars := aString.
|
|
502 |
varNames := self classVarNames.
|
|
503 |
|
|
504 |
"new ones get initialized to nil;
|
|
505 |
- old ones are nilled and removed from Smalltalk"
|
|
506 |
|
|
507 |
varNames do:[:aName |
|
|
508 |
(prevVarNames includes:aName) ifFalse:[
|
|
509 |
"a new one"
|
|
510 |
Smalltalk at:(self name , ':' , aName) asSymbol put:nil.
|
|
511 |
] ifTrue:[
|
|
512 |
prevVarNames remove:aName
|
|
513 |
]
|
|
514 |
].
|
|
515 |
"left overs are gone"
|
|
516 |
prevVarNames do:[:aName |
|
|
517 |
Smalltalk at:(self name , ':' , aName) asSymbol put:nil.
|
|
518 |
Smalltalk removeKey:(self name , ':' , aName) asSymbol
|
|
519 |
].
|
|
520 |
Smalltalk changed
|
|
521 |
]
|
|
522 |
!
|
|
523 |
|
|
524 |
addClassVarName:aString
|
|
525 |
"add a class variable"
|
|
526 |
|
|
527 |
(self classVarNames includes:aString) ifFalse:[
|
|
528 |
self classVariableString:(self classVariableString , ' ' , aString)
|
|
529 |
]
|
|
530 |
! !
|
|
531 |
|
|
532 |
!Class methodsFor:'adding/removing'!
|
|
533 |
|
|
534 |
addSelector:newSelector withMethod:newMethod
|
|
535 |
"add the method given by 2nd argument under the selector given by
|
|
536 |
1st argument to the methodDictionary"
|
|
537 |
|
|
538 |
|index oldSelectorArray oldMethodArray
|
|
539 |
newSelectorArray newMethodArray nargs|
|
|
540 |
|
|
541 |
(newSelector isMemberOf:Symbol) ifFalse:[^ self error:'invalid selector'].
|
|
542 |
newMethod isNil ifTrue:[^ self error:'invalid method'].
|
|
543 |
|
|
544 |
index := selectors identityIndexOf:newSelector startingAt:1.
|
|
545 |
(index == 0) ifTrue:[
|
|
546 |
newSelectorArray := selectors copyWith:newSelector.
|
|
547 |
newMethodArray := methods copyWith:newMethod.
|
|
548 |
"keep a reference so they wont go away ..."
|
|
549 |
oldSelectorArray := selectors.
|
|
550 |
oldMethodArray := methods.
|
|
551 |
selectors := newSelectorArray.
|
|
552 |
methods := newMethodArray
|
|
553 |
] ifFalse:[
|
|
554 |
methods at:index put:newMethod
|
|
555 |
].
|
|
556 |
|
|
557 |
nargs := newSelector nArgsIfSelector.
|
|
558 |
|
|
559 |
"actually, we would do better with less flushing ..."
|
|
560 |
ObjectMemory flushMethodCache.
|
|
561 |
ObjectMemory flushInlineCachesWithArgs:nargs.
|
|
562 |
|
|
563 |
self addChangeRecordForMethod:newMethod
|
|
564 |
!
|
|
565 |
|
|
566 |
removeSelector:aSelector
|
|
567 |
"remove the selector, aSelector and its associated method
|
|
568 |
from the methodDictionary"
|
|
569 |
|
|
570 |
|index oldSelectorArray oldMethodArray
|
|
571 |
newSelectorArray newMethodArray nargs|
|
|
572 |
|
|
573 |
index := selectors identityIndexOf:aSelector startingAt:1.
|
|
574 |
(index ~~ 0) ifTrue:[
|
|
575 |
newSelectorArray := selectors copyWithoutIndex:index.
|
|
576 |
newMethodArray := methods copyWithoutIndex:index.
|
|
577 |
oldSelectorArray := selectors.
|
|
578 |
oldMethodArray := methods.
|
|
579 |
selectors := newSelectorArray.
|
|
580 |
methods := newMethodArray.
|
|
581 |
"
|
|
582 |
nargs := aSelector nArgsIfSelector.
|
|
583 |
ObjectMemory flushMethodCacheFor:self.
|
|
584 |
ObjectMemory flushInlineCachesWithArgs:nargs.
|
|
585 |
"
|
|
586 |
"actually, we would do better with less flushing ..."
|
|
587 |
ObjectMemory flushCaches.
|
|
588 |
|
|
589 |
self addChangeRecordForRemoveSelector:aSelector
|
|
590 |
]
|
|
591 |
! !
|
|
592 |
|
|
593 |
!Class methodsFor:'changes management'!
|
|
594 |
|
|
595 |
updateChanges:aBoolean
|
|
596 |
"turn on/off changes management"
|
|
597 |
|
|
598 |
|prev|
|
|
599 |
|
|
600 |
prev := updatingChanges.
|
|
601 |
updatingChanges := aBoolean.
|
|
602 |
^ prev
|
|
603 |
!
|
|
604 |
|
|
605 |
changesStream
|
|
606 |
"return a Stream for the changes file"
|
|
607 |
|
|
608 |
|aStream|
|
|
609 |
|
|
610 |
updatingChanges ifTrue:[
|
|
611 |
aStream := FileStream oldFileNamed:'changes'.
|
|
612 |
aStream isNil ifTrue:[
|
|
613 |
aStream := FileStream newFileNamed:'changes'.
|
|
614 |
aStream isNil ifTrue:[
|
|
615 |
self error:'cannot update changes file'
|
|
616 |
]
|
|
617 |
] ifFalse:[
|
|
618 |
aStream setToEnd
|
|
619 |
]
|
|
620 |
].
|
|
621 |
^ aStream
|
|
622 |
!
|
|
623 |
|
|
624 |
addChangeRecordForMethod:aMethod
|
|
625 |
"add a method-change-record to the changes file"
|
|
626 |
|
|
627 |
|aStream p|
|
|
628 |
|
|
629 |
aStream := self changesStream.
|
|
630 |
aStream notNil ifTrue:[
|
|
631 |
p := aStream position.
|
|
632 |
self fileOutMethod:aMethod on:aStream.
|
|
633 |
aStream cr.
|
|
634 |
aStream close.
|
|
635 |
Project current notNil ifTrue:[
|
|
636 |
Project current changeSet addMethodChange:aMethod in:self
|
|
637 |
]
|
|
638 |
]
|
|
639 |
!
|
|
640 |
|
|
641 |
addChangeRecordForRemoveSelector:aSelector
|
|
642 |
"add a method-remove-record to the changes file"
|
|
643 |
|
|
644 |
|aStream|
|
|
645 |
|
|
646 |
aStream := self changesStream.
|
|
647 |
aStream notNil ifTrue:[
|
|
648 |
self printClassNameOn:aStream.
|
|
649 |
aStream nextPutAll:(' removeSelector:#' , aSelector).
|
|
650 |
aStream nextPut:(aStream class chunkSeparator).
|
|
651 |
aStream cr.
|
|
652 |
aStream close
|
|
653 |
]
|
|
654 |
!
|
|
655 |
|
|
656 |
addChangeRecordForClass:aClass
|
|
657 |
"add a class-definition-record to the changes file"
|
|
658 |
|
|
659 |
|aStream|
|
|
660 |
|
|
661 |
aStream := self changesStream.
|
|
662 |
aStream notNil ifTrue:[
|
|
663 |
aClass fileOutDefinitionOn:aStream.
|
|
664 |
aStream nextPut:(aStream class chunkSeparator).
|
|
665 |
aStream cr.
|
|
666 |
aStream close
|
|
667 |
]
|
|
668 |
!
|
|
669 |
|
2
|
670 |
addChangeRecordForClassInstvars:aClass
|
|
671 |
"add a class-instvars-record to the changes file"
|
|
672 |
|
|
673 |
|aStream|
|
|
674 |
|
|
675 |
aStream := self changesStream.
|
|
676 |
aStream notNil ifTrue:[
|
|
677 |
aClass fileOutClassInstVarDefinitionOn:aStream.
|
|
678 |
aStream nextPut:$!!.
|
|
679 |
aStream cr.
|
|
680 |
aStream close
|
|
681 |
]
|
|
682 |
!
|
|
683 |
|
1
|
684 |
addChangeRecordForClassComment:aClass
|
|
685 |
"add a class-comment-record to the changes file"
|
|
686 |
|
|
687 |
|aStream|
|
|
688 |
|
|
689 |
aStream := self changesStream.
|
|
690 |
aStream notNil ifTrue:[
|
|
691 |
aClass fileOutCommentOn:aStream.
|
|
692 |
aStream nextPut:$!!.
|
|
693 |
aStream cr.
|
|
694 |
aStream close
|
|
695 |
]
|
|
696 |
!
|
|
697 |
|
|
698 |
addChangeRecordForSnapshot
|
|
699 |
"add a snapshot-record to the changes file"
|
|
700 |
|
|
701 |
|aStream|
|
|
702 |
|
|
703 |
aStream := self changesStream.
|
|
704 |
aStream notNil ifTrue:[
|
|
705 |
aStream nextPutAll:('''---- snapshot ' ,
|
|
706 |
Date today printString , ' ' ,
|
|
707 |
Time now printString ,
|
3
|
708 |
' ----''!!').
|
1
|
709 |
aStream cr.
|
|
710 |
aStream close
|
|
711 |
]
|
|
712 |
! !
|
|
713 |
|
|
714 |
!Class methodsFor:'compiling'!
|
|
715 |
|
|
716 |
compile:code
|
|
717 |
"compile code, aString for this class; if sucessful update method
|
|
718 |
dictionary."
|
|
719 |
|
|
720 |
(Smalltalk at:#Compiler) compile:code forClass:self
|
|
721 |
!
|
|
722 |
|
|
723 |
compile:code notifying:requestor
|
|
724 |
"compile code, aString for this class; on any error, notify
|
|
725 |
requestor, anObject with the error reason"
|
|
726 |
|
|
727 |
(Smalltalk at:#Compiler) compile:code forClass:self notifying:requestor
|
|
728 |
!
|
|
729 |
|
2
|
730 |
recompileMethodsAccessingAny:setOfNames
|
|
731 |
"recompile all methods accessing a variable from setOfNames"
|
|
732 |
|
|
733 |
|p|
|
|
734 |
|
|
735 |
self selectors do:[:aSelector |
|
|
736 |
|m|
|
|
737 |
|
|
738 |
m := self compiledMethodAt:aSelector.
|
|
739 |
p := Parser parseMethod:(m source) in:self.
|
|
740 |
(p isNil or:[p usedVars notNil and:[p usedVars includesAny:setOfNames]]) ifTrue:[
|
|
741 |
self recompile:aSelector
|
|
742 |
]
|
|
743 |
]
|
|
744 |
!
|
|
745 |
|
1
|
746 |
recompile:aSelector
|
|
747 |
"recompile the method associated with the argument, aSelector;
|
|
748 |
used when a superclass changes instances and we have to recompile
|
|
749 |
subclasses"
|
|
750 |
|
2
|
751 |
|cat code upd|
|
1
|
752 |
|
2
|
753 |
upd := Class updateChanges:false.
|
|
754 |
[
|
|
755 |
cat := (self compiledMethodAt:aSelector) category.
|
|
756 |
code := self sourceCodeAt:aSelector.
|
|
757 |
(Smalltalk at:#Compiler) compile:code forClass:self inCategory:cat
|
|
758 |
] valueNowOrOnUnwindDo:[
|
|
759 |
Class updateChanges:upd
|
|
760 |
]
|
1
|
761 |
!
|
|
762 |
|
|
763 |
recompile
|
|
764 |
"recompile all methods
|
|
765 |
used when a class changes instances and therefore all methods
|
|
766 |
have to be recompiled"
|
|
767 |
|
|
768 |
self selectors do:[:aSelector |
|
|
769 |
self recompile:aSelector
|
|
770 |
]
|
|
771 |
!
|
|
772 |
|
|
773 |
recompileAll
|
|
774 |
"recompile this class and all subclasses"
|
|
775 |
|
2
|
776 |
|classes|
|
|
777 |
|
|
778 |
classes := self subclasses.
|
|
779 |
self recompile.
|
|
780 |
classes do:[:aClass |
|
|
781 |
aClass recompileAll
|
|
782 |
]
|
|
783 |
!
|
|
784 |
|
|
785 |
recompileInvalidatedMethods
|
|
786 |
"recompile all invalidated methods"
|
1
|
787 |
|
2
|
788 |
|trap trapCode trapByteCode|
|
|
789 |
|
|
790 |
trap := Method compiledMethodAt:#invalidMethod.
|
|
791 |
trapCode := trap code.
|
|
792 |
trapByteCode := trap byteCode.
|
|
793 |
|
|
794 |
self selectors do:[:aSelector |
|
|
795 |
|m|
|
|
796 |
|
|
797 |
m := self compiledMethodAt:aSelector.
|
|
798 |
((m code == trapCode) and:[m byteCode == trapByteCode]) ifTrue:[
|
|
799 |
self recompile:aSelector
|
|
800 |
]
|
1
|
801 |
]
|
|
802 |
! !
|
|
803 |
|
|
804 |
!Class methodsFor:'queries'!
|
|
805 |
|
2
|
806 |
isClass
|
|
807 |
"return true, if the receiver is some kind of class (real class, not
|
|
808 |
just behavior);
|
|
809 |
true is returned here - the method is redefined from Object"
|
1
|
810 |
|
2
|
811 |
^ true
|
1
|
812 |
!
|
|
813 |
|
|
814 |
categories
|
|
815 |
"Return a Collection of all method-category strings known in class"
|
|
816 |
|
|
817 |
|newList cat|
|
|
818 |
|
|
819 |
newList := OrderedCollection new.
|
|
820 |
methods do:[:aMethod |
|
|
821 |
cat := aMethod category.
|
|
822 |
newList indexOf:cat ifAbsent:[newList add:cat]
|
|
823 |
].
|
|
824 |
^ newList
|
|
825 |
!
|
|
826 |
|
|
827 |
allCategories
|
|
828 |
"Return a Collection of all method-category strings known in class
|
|
829 |
and all superclasses"
|
|
830 |
|
|
831 |
^ self addAllCategoriesTo:(OrderedCollection new)
|
|
832 |
! !
|
|
833 |
|
|
834 |
!Class methodsFor:'private'!
|
|
835 |
|
|
836 |
addFromString:aString to:aCollection
|
|
837 |
"helper - take individual words from the first argument, aString
|
|
838 |
and add them as strings to the 2nd argument, aCollection.
|
|
839 |
return aCollection"
|
|
840 |
|
|
841 |
|start stop strLen|
|
|
842 |
|
|
843 |
aString isNil ifFalse:[
|
|
844 |
start := 1.
|
|
845 |
strLen := aString size.
|
|
846 |
[start <= strLen] whileTrue:[
|
|
847 |
(aString at:start) isSeparator ifTrue:[
|
|
848 |
start := start + 1
|
|
849 |
] ifFalse:[
|
|
850 |
stop := aString indexOfSeparatorStartingAt:start.
|
|
851 |
stop == 0 ifTrue:[
|
|
852 |
stop := strLen + 1
|
|
853 |
].
|
|
854 |
aCollection add:(aString copyFrom:start to:(stop - 1)).
|
|
855 |
start := stop
|
|
856 |
]
|
|
857 |
]
|
|
858 |
].
|
|
859 |
^ aCollection
|
|
860 |
!
|
|
861 |
|
|
862 |
addInstVarNamesTo:aCollection
|
|
863 |
"add the name-strings of the instance variables
|
|
864 |
to the argument, aCollection. Return aCollection"
|
|
865 |
|
|
866 |
^ self addFromString:instvars to:aCollection
|
|
867 |
!
|
|
868 |
|
|
869 |
addClassVarNamesTo:aCollection
|
|
870 |
"add the name-strings of the class varvariables
|
|
871 |
to the argument, aCollection. Return aCollection"
|
|
872 |
|
|
873 |
^ self addFromString:classvars to:aCollection
|
|
874 |
!
|
|
875 |
|
|
876 |
addAllInstVarNamesTo:aCollection
|
|
877 |
"add the name-strings of the instance variables and of the inst-vars
|
|
878 |
of all superclasses to the argument, aCollection. Return aCollection"
|
|
879 |
|
|
880 |
(superclass notNil) ifTrue:[
|
|
881 |
superclass addAllInstVarNamesTo:aCollection
|
|
882 |
].
|
|
883 |
^ self addInstVarNamesTo:aCollection
|
|
884 |
!
|
|
885 |
|
|
886 |
addAllClassVarNamesTo:aCollection
|
|
887 |
"add the name-strings of the class variables and of the class-vars
|
|
888 |
of all superclasses to the argument, aCollection. Return aCollection"
|
|
889 |
|
|
890 |
(superclass notNil) ifTrue:[
|
|
891 |
superclass addAllClassVarNamesTo:aCollection
|
|
892 |
].
|
|
893 |
^ self addClassVarNamesTo:aCollection
|
|
894 |
!
|
|
895 |
|
|
896 |
addCategoriesTo:aCollection
|
|
897 |
"helper - add categories to the argument, aCollection"
|
|
898 |
|
|
899 |
|cat|
|
|
900 |
|
|
901 |
methods do:[:aMethod |
|
|
902 |
cat := aMethod category.
|
|
903 |
(aCollection detect:[:element | cat = element]
|
|
904 |
ifNone:[nil])
|
|
905 |
isNil ifTrue:[
|
|
906 |
aCollection add:cat
|
|
907 |
]
|
|
908 |
].
|
|
909 |
^ aCollection
|
|
910 |
!
|
|
911 |
|
|
912 |
addAllCategoriesTo:aCollection
|
|
913 |
"helper - add categories and all superclasses categories
|
|
914 |
to the argument, aCollection"
|
|
915 |
|
|
916 |
(superclass notNil) ifTrue:[
|
|
917 |
superclass addAllCategoriesTo:aCollection
|
|
918 |
].
|
|
919 |
^ self addCategoriesTo:aCollection
|
|
920 |
! !
|
|
921 |
|
|
922 |
!Class methodsFor:'fileIn interface'!
|
|
923 |
|
|
924 |
methodsFor:aCategory
|
|
925 |
"return a ClassCategoryReader to read in and compile methods for me"
|
|
926 |
|
|
927 |
^ ClassCategoryReader class:self category:aCategory
|
|
928 |
!
|
|
929 |
|
|
930 |
publicMethodsFor:aCategory
|
|
931 |
"this method allows fileIn of ENVY methods - currently we do not support method visibility.
|
|
932 |
return a ClassCategoryReader to read in and compile methods for me."
|
|
933 |
|
|
934 |
^ self methodsFor:aCategory
|
|
935 |
!
|
|
936 |
|
|
937 |
privateMethodsFor:aCategory
|
|
938 |
"this method allows fileIn of ENVY methods - currently we do not support method visibility.
|
|
939 |
return a ClassCategoryReader to read in and compile methods for me."
|
|
940 |
|
|
941 |
^ self methodsFor:aCategory
|
|
942 |
!
|
|
943 |
|
|
944 |
binaryMethods
|
|
945 |
"return a ClassCategoryReader to read in binary methods for me"
|
|
946 |
|
|
947 |
^ BinaryClassCategoryReader class:self category:'binary'
|
|
948 |
!
|
|
949 |
|
|
950 |
methods
|
|
951 |
"this method allows fileIn of ST/V methods -
|
|
952 |
return a ClassCategoryReader to read in and compile methods for me."
|
|
953 |
|
|
954 |
^ ClassCategoryReader class:self category:'ST/V methods'
|
|
955 |
! !
|
|
956 |
|
|
957 |
!Class methodsFor:'fileOut'!
|
|
958 |
|
|
959 |
printClassNameOn:aStream
|
|
960 |
"helper for fileOut - print my name if I am not a Metaclass;
|
|
961 |
otherwise my name without -class followed by space-class"
|
|
962 |
|
|
963 |
(self isMeta "isMemberOf:Metaclass") ifTrue:[
|
|
964 |
aStream nextPutAll:(name copyFrom:1 to:(name size - 5)).
|
|
965 |
aStream nextPutAll:' class'
|
|
966 |
] ifFalse:[
|
|
967 |
name printOn:aStream
|
|
968 |
]
|
|
969 |
!
|
|
970 |
|
|
971 |
printNameArray:anArray on:aStream indent:indent
|
|
972 |
"print an array of strings separated by spaces; when the stream
|
|
973 |
defines a lineLength, break when this limit is reached; indent
|
|
974 |
every line; used to printOut instanve variable names"
|
|
975 |
|
|
976 |
|thisName nextName arraySize lenMax pos mustBreak line spaces|
|
|
977 |
|
|
978 |
arraySize := 0.
|
|
979 |
anArray notNil ifTrue:[
|
|
980 |
arraySize := anArray size
|
|
981 |
].
|
|
982 |
arraySize ~~ 0 ifTrue:[
|
|
983 |
pos := indent.
|
|
984 |
lenMax := aStream lineLength.
|
|
985 |
thisName := anArray at:1.
|
|
986 |
line := ''.
|
|
987 |
1 to:arraySize do:[:index |
|
|
988 |
line := line , thisName.
|
|
989 |
pos := pos + thisName size.
|
|
990 |
(index == arraySize) ifFalse:[
|
|
991 |
nextName := anArray at:(index + 1).
|
|
992 |
mustBreak := false.
|
|
993 |
(lenMax > 0) ifTrue:[
|
|
994 |
((pos + nextName size) > lenMax) ifTrue:[
|
|
995 |
mustBreak := true
|
|
996 |
]
|
|
997 |
].
|
|
998 |
mustBreak ifTrue:[
|
|
999 |
aStream nextPutAll:line.
|
|
1000 |
aStream cr.
|
|
1001 |
spaces isNil ifTrue:[
|
|
1002 |
spaces := String new:indent
|
|
1003 |
].
|
|
1004 |
line := spaces.
|
|
1005 |
pos := indent
|
|
1006 |
] ifFalse:[
|
|
1007 |
line := line , ' '.
|
|
1008 |
pos := pos + 1
|
|
1009 |
].
|
|
1010 |
thisName := nextName
|
|
1011 |
]
|
|
1012 |
].
|
|
1013 |
aStream nextPutAll:line
|
|
1014 |
]
|
|
1015 |
!
|
|
1016 |
|
|
1017 |
printClassVarNamesOn:aStream indent:indent
|
|
1018 |
"print the class variable names indented and breaking at line end"
|
|
1019 |
|
|
1020 |
self printNameArray:(self classVarNames) on:aStream indent:indent
|
|
1021 |
!
|
|
1022 |
|
|
1023 |
printInstVarNamesOn:aStream indent:indent
|
|
1024 |
"print the instance variable names indented and breaking at line end"
|
|
1025 |
|
|
1026 |
self printNameArray:(self instVarNames) on:aStream indent:indent
|
|
1027 |
!
|
|
1028 |
|
|
1029 |
printHierarchyOn:aStream
|
|
1030 |
"print my class hierarchy on aStream"
|
|
1031 |
|
|
1032 |
self printHierarchyAnswerIndentOn:aStream
|
|
1033 |
!
|
|
1034 |
|
|
1035 |
printHierarchyAnswerIndentOn:aStream
|
|
1036 |
"print my class hierarchy on aStream - return indent
|
|
1037 |
recursively calls itself to print superclass and use returned indent
|
|
1038 |
for my description - used in the browser"
|
|
1039 |
|
|
1040 |
|indent|
|
|
1041 |
|
|
1042 |
indent := 0.
|
|
1043 |
(superclass notNil) ifTrue:[
|
|
1044 |
indent := (superclass printHierarchyAnswerIndentOn:aStream) + 2
|
|
1045 |
].
|
|
1046 |
aStream nextPutAll:(String new:indent).
|
|
1047 |
aStream nextPutAll:name.
|
|
1048 |
aStream nextPutAll:' ('.
|
|
1049 |
self printInstVarNamesOn:aStream indent:(indent + name size + 2).
|
|
1050 |
aStream nextPutAll:')'.
|
|
1051 |
aStream cr.
|
|
1052 |
^ indent
|
|
1053 |
!
|
|
1054 |
|
|
1055 |
printFullHierarchyOn:aStream indent:indent
|
|
1056 |
"print myself and all subclasses on aStream.
|
|
1057 |
recursively calls itself to print subclasses.
|
|
1058 |
Can be used to print hierarchy on the printer."
|
|
1059 |
|
|
1060 |
aStream nextPutAll:(String new:indent).
|
|
1061 |
aStream bold.
|
|
1062 |
aStream nextPutAll:name.
|
|
1063 |
aStream normal.
|
|
1064 |
aStream nextPutAll:' ('.
|
|
1065 |
self printInstVarNamesOn:aStream indent:(indent + name size + 2).
|
|
1066 |
aStream nextPutAll:')'.
|
|
1067 |
aStream cr.
|
|
1068 |
|
|
1069 |
(self subclasses sort:[:a :b | a name < b name]) do:[:aSubclass |
|
|
1070 |
aSubclass printFullHierarchyOn:aStream indent:(indent + 2)
|
|
1071 |
]
|
|
1072 |
|
|
1073 |
"|printStream|
|
|
1074 |
printStream := Printer new.
|
|
1075 |
Object printFullHierarchyOn:printStream indent:0.
|
|
1076 |
printStream close"
|
|
1077 |
!
|
|
1078 |
|
|
1079 |
fileOutCommentOn:aStream
|
|
1080 |
"print an expression on aStream to define my comment"
|
|
1081 |
|
|
1082 |
aStream nextPutAll:name.
|
|
1083 |
aStream nextPutAll:' comment:'.
|
|
1084 |
comment isNil ifTrue:[
|
|
1085 |
aStream nextPutAll:''''''
|
|
1086 |
] ifFalse:[
|
|
1087 |
aStream nextPutAll:(comment storeString)
|
|
1088 |
].
|
|
1089 |
aStream cr
|
|
1090 |
!
|
|
1091 |
|
|
1092 |
fileOutDefinitionOn:aStream
|
|
1093 |
"print an expression to define myself on aStream"
|
|
1094 |
|
|
1095 |
|isVar line|
|
|
1096 |
|
|
1097 |
superclass isNil ifTrue:[
|
|
1098 |
line := 'Object'
|
|
1099 |
] ifFalse:[
|
|
1100 |
line := (superclass name)
|
|
1101 |
].
|
|
1102 |
superclass isNil ifTrue:[
|
|
1103 |
isVar := self isVariable
|
|
1104 |
] ifFalse:[
|
|
1105 |
"I cant remember what this is for ?"
|
|
1106 |
isVar := (self isVariable and:[superclass isVariable not])
|
|
1107 |
].
|
|
1108 |
isVar ifTrue:[
|
2
|
1109 |
self isBytes ifTrue:[
|
|
1110 |
line := line , ' variableByteSubclass:#'
|
1
|
1111 |
] ifFalse:[
|
2
|
1112 |
self isWords ifTrue:[
|
|
1113 |
line := line , ' variableWordSubclass:#'
|
1
|
1114 |
] ifFalse:[
|
2
|
1115 |
self isLongs ifTrue:[
|
|
1116 |
line := line , ' variableLongSubclass:#'
|
1
|
1117 |
] ifFalse:[
|
2
|
1118 |
self isFloats ifTrue:[
|
|
1119 |
line := line , ' variableFloatSubclass:#'
|
1
|
1120 |
] ifFalse:[
|
2
|
1121 |
self isDoubles ifTrue:[
|
|
1122 |
line := line , ' variableDoubleSubclass:#'
|
1
|
1123 |
] ifFalse:[
|
2
|
1124 |
line := line , ' variableSubclass:#'
|
1
|
1125 |
]
|
|
1126 |
]
|
|
1127 |
]
|
|
1128 |
]
|
|
1129 |
]
|
|
1130 |
] ifFalse:[
|
|
1131 |
line := line , ' subclass:#'
|
|
1132 |
].
|
|
1133 |
line := line , name.
|
|
1134 |
aStream nextPutAll:line.
|
|
1135 |
|
|
1136 |
aStream crTab.
|
|
1137 |
aStream nextPutAll:' instanceVariableNames:'''.
|
|
1138 |
self printInstVarNamesOn:aStream indent:16.
|
|
1139 |
aStream nextPutAll:''''.
|
|
1140 |
|
|
1141 |
aStream crTab.
|
|
1142 |
aStream nextPutAll:' classVariableNames:'''.
|
|
1143 |
self printClassVarNamesOn:aStream indent:16.
|
|
1144 |
aStream nextPutAll:''''.
|
|
1145 |
|
|
1146 |
aStream crTab.
|
|
1147 |
aStream nextPutAll:' poolDictionaries:'''''.
|
|
1148 |
|
|
1149 |
aStream crTab.
|
|
1150 |
aStream nextPutAll:' category:'.
|
|
1151 |
category isNil ifTrue:[
|
|
1152 |
aStream nextPutAll:''''''
|
|
1153 |
] ifFalse:[
|
|
1154 |
aStream nextPutAll:(category asString storeString)
|
|
1155 |
].
|
|
1156 |
aStream cr
|
|
1157 |
!
|
|
1158 |
|
|
1159 |
fileOutClassInstVarDefinitionOn:aStream
|
|
1160 |
aStream nextPutAll:(name , ' class instanceVariableNames:''').
|
|
1161 |
self class printInstVarNamesOn:aStream indent:8.
|
|
1162 |
aStream nextPutAll:''''
|
|
1163 |
!
|
|
1164 |
|
|
1165 |
fileOutCategory:aCategory on:aStream
|
|
1166 |
"file out all methods belonging to aCategory, aString onto aStream"
|
|
1167 |
|
|
1168 |
|nMethods count|
|
|
1169 |
|
|
1170 |
methods notNil ifTrue:[
|
|
1171 |
nMethods := 0.
|
|
1172 |
methods do:[:aMethod |
|
|
1173 |
(aCategory = aMethod category) ifTrue:[
|
|
1174 |
nMethods := nMethods + 1
|
|
1175 |
]
|
|
1176 |
].
|
|
1177 |
(nMethods ~~ 0) ifTrue:[
|
|
1178 |
aStream nextPut:$!!.
|
|
1179 |
self printClassNameOn:aStream.
|
|
1180 |
aStream nextPutAll:' methodsFor:'''.
|
|
1181 |
aCategory notNil ifTrue:[
|
|
1182 |
aStream nextPutAll:aCategory
|
|
1183 |
].
|
|
1184 |
aStream nextPut:$'. aStream nextPut:$!!. aStream cr.
|
|
1185 |
aStream cr.
|
|
1186 |
count := 1.
|
|
1187 |
methods do:[:aMethod |
|
|
1188 |
(aCategory = aMethod category) ifTrue:[
|
|
1189 |
aStream nextChunkPut:(aMethod source).
|
|
1190 |
(count ~~ nMethods) ifTrue:[
|
|
1191 |
aStream cr.
|
|
1192 |
aStream cr
|
|
1193 |
].
|
|
1194 |
count := count + 1
|
|
1195 |
]
|
|
1196 |
].
|
|
1197 |
aStream space.
|
|
1198 |
aStream nextPut:$!!.
|
|
1199 |
aStream cr
|
|
1200 |
]
|
|
1201 |
]
|
|
1202 |
!
|
|
1203 |
|
|
1204 |
fileOutMethod:aMethod on:aStream
|
|
1205 |
"file out the method, aMethod onto aStream"
|
|
1206 |
|
|
1207 |
|cat|
|
|
1208 |
|
|
1209 |
methods notNil ifTrue:[
|
|
1210 |
aStream nextPut:$!!.
|
|
1211 |
self printClassNameOn:aStream.
|
|
1212 |
aStream nextPutAll:' methodsFor:'''.
|
|
1213 |
cat := aMethod category.
|
|
1214 |
cat notNil ifTrue:[
|
|
1215 |
aStream nextPutAll:cat
|
|
1216 |
].
|
|
1217 |
aStream nextPut:$'.
|
|
1218 |
aStream nextPut:$!!.
|
|
1219 |
aStream cr.
|
|
1220 |
aStream cr.
|
|
1221 |
aStream nextChunkPut:(aMethod source).
|
|
1222 |
aStream space.
|
|
1223 |
aStream nextPut:$!!.
|
|
1224 |
aStream cr
|
|
1225 |
]
|
|
1226 |
!
|
|
1227 |
|
|
1228 |
fileOutOn:aStream
|
|
1229 |
"file out all methods onto aStream"
|
|
1230 |
|
|
1231 |
|collectionOfCategories|
|
|
1232 |
|
|
1233 |
aStream nextPutAll:(Smalltalk timeStamp).
|
|
1234 |
aStream nextPut:$!.
|
|
1235 |
aStream cr.
|
|
1236 |
aStream cr.
|
|
1237 |
self fileOutDefinitionOn:aStream.
|
|
1238 |
aStream nextPut:$!!.
|
|
1239 |
aStream cr.
|
|
1240 |
aStream cr.
|
|
1241 |
self class instanceVariableString isBlank ifFalse:[
|
|
1242 |
self fileOutClassInstVarDefinitionOn:aStream.
|
|
1243 |
aStream nextPut:$!!.
|
|
1244 |
aStream cr.
|
|
1245 |
aStream cr
|
|
1246 |
].
|
|
1247 |
|
|
1248 |
comment notNil ifTrue:[
|
|
1249 |
aStream nextPutAll:name.
|
|
1250 |
aStream nextPutAll:' comment:'.
|
|
1251 |
aStream nextPutAll:(comment storeString).
|
|
1252 |
aStream nextPut:$!!.
|
|
1253 |
aStream cr.
|
|
1254 |
aStream cr
|
|
1255 |
].
|
|
1256 |
collectionOfCategories := self class categories.
|
|
1257 |
collectionOfCategories notNil ifTrue:[
|
|
1258 |
collectionOfCategories do:[:aCategory |
|
|
1259 |
self class fileOutCategory:aCategory on:aStream.
|
|
1260 |
aStream cr
|
|
1261 |
]
|
|
1262 |
].
|
|
1263 |
collectionOfCategories := self categories.
|
|
1264 |
collectionOfCategories notNil ifTrue:[
|
|
1265 |
collectionOfCategories do:[:aCategory |
|
|
1266 |
self fileOutCategory:aCategory on:aStream.
|
|
1267 |
aStream cr
|
|
1268 |
]
|
|
1269 |
].
|
|
1270 |
(self class implements:#initialize) ifTrue:[
|
|
1271 |
aStream nextPutAll:(name , ' initialize').
|
|
1272 |
aStream nextPut:$!!.
|
|
1273 |
aStream cr
|
|
1274 |
]
|
|
1275 |
!
|
|
1276 |
|
|
1277 |
fileOutCategory:aCategory
|
|
1278 |
"create a file 'class-category.st' consisting of all methods in aCategory"
|
|
1279 |
|
|
1280 |
|aStream fileName|
|
|
1281 |
|
|
1282 |
fileName := name , '-' , aCategory , '.st'.
|
|
1283 |
aStream := FileStream newFileNamed:fileName.
|
|
1284 |
self fileOutCategory:aCategory on:aStream.
|
|
1285 |
aStream close
|
|
1286 |
!
|
|
1287 |
|
|
1288 |
fileOutMethod:aMethod
|
|
1289 |
"create a file 'class-method.st' consisting of the method, aMethod"
|
|
1290 |
|
|
1291 |
|aStream fileName selector|
|
|
1292 |
|
|
1293 |
selector := self selectorForMethod:aMethod.
|
|
1294 |
selector notNil ifTrue:[
|
|
1295 |
fileName := name , '-' , selector, '.st'.
|
|
1296 |
aStream := FileStream newFileNamed:fileName.
|
|
1297 |
self fileOutMethod:aMethod on:aStream.
|
|
1298 |
aStream close
|
|
1299 |
]
|
|
1300 |
!
|
|
1301 |
|
|
1302 |
fileOut
|
|
1303 |
"create a file 'class.st' consisting of all methods in myself"
|
|
1304 |
|
|
1305 |
|aStream fileName|
|
|
1306 |
|
|
1307 |
fileName := (Smalltalk fileNameForClass:self name) , '.st'.
|
|
1308 |
aStream := FileStream newFileNamed:fileName.
|
|
1309 |
aStream isNil ifTrue:[
|
|
1310 |
^ self error:('cannot create source file:', fileName)
|
|
1311 |
].
|
|
1312 |
self fileOutOn:aStream.
|
|
1313 |
aStream close
|
|
1314 |
!
|
|
1315 |
|
|
1316 |
fileOutIn:aFileDirectory
|
|
1317 |
"create a file 'class.st' consisting of all methods in self in
|
|
1318 |
directory aFileDirectory"
|
|
1319 |
|
|
1320 |
|aStream fileName|
|
|
1321 |
|
|
1322 |
fileName := (Smalltalk fileNameForClass:self) , '.st'.
|
|
1323 |
aStream := FileStream newFileNamed:fileName
|
|
1324 |
in:aFileDirectory.
|
|
1325 |
aStream isNil ifTrue:[
|
|
1326 |
^ self error:('cannot create source file:', fileName)
|
|
1327 |
].
|
|
1328 |
self fileOutOn:aStream.
|
|
1329 |
aStream close
|
|
1330 |
!
|
|
1331 |
|
|
1332 |
binaryFileOutMethodsOn:aStream
|
|
1333 |
"binary file out all methods onto aStream"
|
|
1334 |
|
|
1335 |
|temporaryMethod index|
|
|
1336 |
|
|
1337 |
methods notNil ifTrue:[
|
|
1338 |
aStream nextPut:$!!.
|
|
1339 |
self printClassNameOn:aStream.
|
|
1340 |
aStream nextPutAll:' binaryMethods'.
|
|
1341 |
aStream nextPut:$!!.
|
|
1342 |
aStream cr.
|
|
1343 |
index := 1.
|
|
1344 |
methods do:[:aMethod |
|
|
1345 |
(selectors at:index) storeOn:aStream.
|
|
1346 |
aStream nextPut:$!!.
|
|
1347 |
|
|
1348 |
aMethod byteCode isNil ifTrue:[
|
|
1349 |
temporaryMethod := Compiler compile:(aMethod source)
|
|
1350 |
forClass:self
|
|
1351 |
inCategory:(aMethod category)
|
|
1352 |
notifying:nil
|
|
1353 |
install:false.
|
|
1354 |
temporaryMethod binaryFileOutOn:aStream
|
|
1355 |
] ifFalse:[
|
|
1356 |
aMethod binaryFileOutOn:aStream
|
|
1357 |
].
|
|
1358 |
aStream cr.
|
|
1359 |
index := index + 1
|
|
1360 |
].
|
|
1361 |
aStream nextPut:$!!.
|
|
1362 |
aStream cr
|
|
1363 |
]
|
|
1364 |
!
|
|
1365 |
|
|
1366 |
binaryFileOutOn:aStream
|
|
1367 |
"file out all methods onto aStream"
|
|
1368 |
|
|
1369 |
aStream nextPut:$'.
|
|
1370 |
aStream nextPutAll:('From Smalltalk/X, Version:'
|
|
1371 |
, (Smalltalk version)
|
|
1372 |
, ' on ').
|
|
1373 |
aStream nextPutAll:(Date today printString , ' at ' , Time now printString).
|
|
1374 |
aStream nextPut:$'.
|
|
1375 |
aStream nextPut:$!!.
|
|
1376 |
aStream cr.
|
|
1377 |
self fileOutDefinitionOn:aStream.
|
|
1378 |
aStream nextPut:$!!.
|
|
1379 |
aStream cr.
|
|
1380 |
comment notNil ifTrue:[
|
|
1381 |
aStream nextPutAll:name.
|
|
1382 |
aStream nextPutAll:' comment:'.
|
|
1383 |
aStream nextPutAll:(comment storeString).
|
|
1384 |
aStream nextPut:$!!.
|
|
1385 |
aStream cr
|
|
1386 |
].
|
|
1387 |
self class binaryFileOutMethodsOn:aStream.
|
|
1388 |
self binaryFileOutMethodsOn:aStream.
|
|
1389 |
(self class implements:#initialize) ifTrue:[
|
|
1390 |
aStream nextPutAll:(name , ' initialize').
|
|
1391 |
aStream nextPut:$!!.
|
|
1392 |
aStream cr
|
|
1393 |
]
|
|
1394 |
!
|
|
1395 |
|
|
1396 |
binaryFileOut
|
|
1397 |
"create a file 'class.sb' consisting of all methods in myself"
|
|
1398 |
|
|
1399 |
|aStream fileName|
|
|
1400 |
|
|
1401 |
fileName := (Smalltalk fileNameForClass:self name) , '.sb'.
|
|
1402 |
aStream := FileStream newFileNamed:fileName.
|
|
1403 |
aStream isNil ifTrue:[
|
|
1404 |
^ self error:('cannot create class file:', fileName)
|
|
1405 |
].
|
|
1406 |
self binaryFileOutOn:aStream.
|
|
1407 |
aStream close
|
|
1408 |
! !
|
|
1409 |
|
|
1410 |
!Class methodsFor:'printOut'!
|
|
1411 |
|
|
1412 |
printOutDefinitionOn:aPrintStream
|
|
1413 |
"print out my definition"
|
|
1414 |
|
|
1415 |
aPrintStream nextPutAll:'class '.
|
|
1416 |
aPrintStream bold.
|
|
1417 |
aPrintStream nextPutAll:name.
|
|
1418 |
aPrintStream normal.
|
|
1419 |
aPrintStream cr.
|
|
1420 |
|
|
1421 |
aPrintStream nextPutAll:'superclass '.
|
|
1422 |
superclass isNil ifTrue:[
|
|
1423 |
aPrintStream nextPutAll:'Object'
|
|
1424 |
] ifFalse:[
|
|
1425 |
aPrintStream nextPutAll:(superclass name)
|
|
1426 |
].
|
|
1427 |
aPrintStream cr.
|
|
1428 |
|
|
1429 |
aPrintStream nextPutAll:'instance Variables '.
|
|
1430 |
self printInstVarNamesOn:aPrintStream indent:21.
|
|
1431 |
aPrintStream cr.
|
|
1432 |
|
|
1433 |
aPrintStream nextPutAll:'class Variables '.
|
|
1434 |
self printClassVarNamesOn:aPrintStream indent:21.
|
|
1435 |
aPrintStream cr.
|
|
1436 |
|
|
1437 |
category notNil ifTrue:[
|
|
1438 |
aPrintStream nextPutAll:'category '.
|
|
1439 |
aPrintStream nextPutAll:(category printString).
|
|
1440 |
aPrintStream cr
|
|
1441 |
].
|
|
1442 |
|
|
1443 |
comment notNil ifTrue:[
|
|
1444 |
aPrintStream cr.
|
|
1445 |
aPrintStream nextPutAll:'comment:'.
|
|
1446 |
aPrintStream cr.
|
|
1447 |
aPrintStream italic.
|
|
1448 |
aPrintStream nextPutAll:comment.
|
|
1449 |
aPrintStream normal.
|
|
1450 |
aPrintStream cr
|
|
1451 |
]
|
|
1452 |
!
|
|
1453 |
|
|
1454 |
printOutSourceProtocol:aString on:aPrintStream
|
|
1455 |
"given the source in aString, print the methods message specification
|
|
1456 |
and any method comments - without source; used to generate documentation
|
|
1457 |
pages"
|
|
1458 |
|
|
1459 |
|text line nQuote index|
|
|
1460 |
|
|
1461 |
text := aString asText.
|
|
1462 |
(text size < 1) ifTrue:[^self].
|
|
1463 |
aPrintStream bold.
|
|
1464 |
aPrintStream nextPutAll:(text at:1).
|
|
1465 |
aPrintStream cr.
|
|
1466 |
(text size >= 2) ifTrue:[
|
|
1467 |
aPrintStream italic.
|
|
1468 |
line := (text at:2).
|
|
1469 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
1470 |
(nQuote == 2) ifTrue:[
|
|
1471 |
aPrintStream nextPutAll:line.
|
|
1472 |
aPrintStream cr
|
|
1473 |
] ifFalse:[
|
|
1474 |
(nQuote == 1) ifTrue:[
|
|
1475 |
aPrintStream nextPutAll:line.
|
|
1476 |
aPrintStream cr.
|
|
1477 |
index := 3.
|
|
1478 |
line := text at:index.
|
|
1479 |
nQuote := line occurrencesOf:(Character doubleQuote).
|
|
1480 |
[nQuote ~~ 1] whileTrue:[
|
|
1481 |
aPrintStream nextPutAll:line.
|
|
1482 |
aPrintStream cr.
|
|
1483 |
index := index + 1.
|
|
1484 |
line := text at:index.
|
|
1485 |
nQuote := line occurrencesOf:(Character doubleQuote)
|
|
1486 |
].
|
|
1487 |
aPrintStream nextPutAll:(text at:index).
|
|
1488 |
aPrintStream cr
|
|
1489 |
]
|
|
1490 |
]
|
|
1491 |
].
|
|
1492 |
aPrintStream normal
|
|
1493 |
!
|
|
1494 |
|
|
1495 |
printOutSource:aString on:aPrintStream
|
|
1496 |
"print out a source-string; the message-specification is printed bold,
|
|
1497 |
comments are printed italic"
|
|
1498 |
|
|
1499 |
|text textIndex textSize line lineIndex lineSize inComment aCharacter|
|
|
1500 |
text := aString asText.
|
|
1501 |
aPrintStream bold.
|
|
1502 |
aPrintStream nextPutAll:(text at:1).
|
|
1503 |
aPrintStream normal.
|
|
1504 |
aPrintStream cr.
|
|
1505 |
inComment := false.
|
|
1506 |
textSize := text size.
|
|
1507 |
textIndex := 2.
|
|
1508 |
[textIndex <= textSize] whileTrue:[
|
|
1509 |
line := text at:textIndex.
|
|
1510 |
((line occurrencesOf:Character doubleQuote) == 0) ifTrue:[
|
|
1511 |
aPrintStream nextPutAll:line
|
|
1512 |
] ifFalse:[
|
|
1513 |
lineSize := line size.
|
|
1514 |
lineIndex := 1.
|
|
1515 |
[lineIndex <= lineSize] whileTrue:[
|
|
1516 |
aCharacter := line at:lineIndex.
|
|
1517 |
(aCharacter == Character doubleQuote) ifTrue:[
|
|
1518 |
inComment ifTrue:[
|
|
1519 |
aPrintStream normal.
|
|
1520 |
aPrintStream nextPut:aCharacter.
|
|
1521 |
inComment := false
|
|
1522 |
] ifFalse:[
|
|
1523 |
aPrintStream nextPut:aCharacter.
|
|
1524 |
aPrintStream italic.
|
|
1525 |
inComment := true
|
|
1526 |
]
|
|
1527 |
] ifFalse:[
|
|
1528 |
aPrintStream nextPut:aCharacter
|
|
1529 |
].
|
|
1530 |
lineIndex := lineIndex + 1
|
|
1531 |
]
|
|
1532 |
].
|
|
1533 |
aPrintStream cr.
|
|
1534 |
textIndex := textIndex + 1
|
|
1535 |
]
|
|
1536 |
!
|
|
1537 |
|
|
1538 |
printOutCategory:aCategory on:aPrintStream
|
|
1539 |
"print out all methods in aCategory on aPrintStream should be a PrintStream"
|
|
1540 |
|
|
1541 |
|any|
|
|
1542 |
methods notNil ifTrue:[
|
|
1543 |
any := false.
|
|
1544 |
methods do:[:aMethod |
|
|
1545 |
(aCategory = aMethod category) ifTrue:[
|
|
1546 |
any := true
|
|
1547 |
]
|
|
1548 |
].
|
|
1549 |
any ifTrue:[
|
|
1550 |
aPrintStream italic.
|
|
1551 |
aPrintStream nextPutAll:aCategory.
|
|
1552 |
aPrintStream normal.
|
|
1553 |
aPrintStream cr.
|
|
1554 |
aPrintStream cr.
|
|
1555 |
methods do:[:aMethod |
|
|
1556 |
(aCategory = aMethod category) ifTrue:[
|
|
1557 |
self printOutSource:(aMethod source) on:aPrintStream.
|
|
1558 |
aPrintStream cr.
|
|
1559 |
aPrintStream cr
|
|
1560 |
]
|
|
1561 |
].
|
|
1562 |
aPrintStream cr
|
|
1563 |
]
|
|
1564 |
]
|
|
1565 |
!
|
|
1566 |
|
|
1567 |
printOutOn:aPrintStream
|
|
1568 |
"print out all methods on aPrintStream which should be a printStream"
|
|
1569 |
|
|
1570 |
|collectionOfCategories|
|
|
1571 |
self printOutDefinitionOn:aPrintStream.
|
|
1572 |
aPrintStream cr.
|
|
1573 |
collectionOfCategories := self class categories.
|
|
1574 |
collectionOfCategories notNil ifTrue:[
|
|
1575 |
aPrintStream nextPutAll:'class protocol'.
|
|
1576 |
aPrintStream cr. aPrintStream cr.
|
|
1577 |
collectionOfCategories do:[:aCategory |
|
|
1578 |
self class printOutCategory:aCategory on:aPrintStream
|
|
1579 |
]
|
|
1580 |
].
|
|
1581 |
collectionOfCategories := self categories.
|
|
1582 |
collectionOfCategories notNil ifTrue:[
|
|
1583 |
aPrintStream nextPutAll:'instance protocol'.
|
|
1584 |
aPrintStream cr. aPrintStream cr.
|
|
1585 |
collectionOfCategories do:[:aCategory |
|
|
1586 |
self printOutCategory:aCategory on:aPrintStream
|
|
1587 |
]
|
|
1588 |
]
|
|
1589 |
!
|
|
1590 |
|
|
1591 |
printOutCategoryProtocol:aCategory on:aPrintStream
|
|
1592 |
|any|
|
|
1593 |
methods notNil ifTrue:[
|
|
1594 |
any := false.
|
|
1595 |
methods do:[:aMethod |
|
|
1596 |
(aCategory = aMethod category) ifTrue:[
|
|
1597 |
any := true
|
|
1598 |
]
|
|
1599 |
].
|
|
1600 |
any ifTrue:[
|
|
1601 |
aPrintStream italic.
|
|
1602 |
aPrintStream nextPutAll:aCategory.
|
|
1603 |
aPrintStream normal.
|
|
1604 |
aPrintStream cr.
|
|
1605 |
aPrintStream cr.
|
|
1606 |
methods do:[:aMethod |
|
|
1607 |
(aCategory = aMethod category) ifTrue:[
|
|
1608 |
self printOutSourceProtocol:(aMethod source)
|
|
1609 |
on:aPrintStream.
|
|
1610 |
aPrintStream cr.
|
|
1611 |
aPrintStream cr
|
|
1612 |
]
|
|
1613 |
].
|
|
1614 |
aPrintStream cr
|
|
1615 |
]
|
|
1616 |
]
|
|
1617 |
!
|
|
1618 |
|
|
1619 |
printOutProtocolOn:aPrintStream
|
|
1620 |
|collectionOfCategories|
|
|
1621 |
self printOutDefinitionOn:aPrintStream.
|
|
1622 |
aPrintStream cr.
|
|
1623 |
collectionOfCategories := self class categories.
|
|
1624 |
collectionOfCategories notNil ifTrue:[
|
|
1625 |
aPrintStream nextPutAll:'class protocol'.
|
|
1626 |
aPrintStream cr. aPrintStream cr.
|
|
1627 |
collectionOfCategories do:[:aCategory |
|
|
1628 |
self class printOutCategoryProtocol:aCategory on:aPrintStream
|
|
1629 |
]
|
|
1630 |
].
|
|
1631 |
collectionOfCategories := self categories.
|
|
1632 |
collectionOfCategories notNil ifTrue:[
|
|
1633 |
aPrintStream nextPutAll:'instance protocol'.
|
|
1634 |
aPrintStream cr. aPrintStream cr.
|
|
1635 |
collectionOfCategories do:[:aCategory |
|
|
1636 |
self printOutCategoryProtocol:aCategory on:aPrintStream
|
|
1637 |
]
|
|
1638 |
]
|
|
1639 |
! !
|
2
|
1640 |
|
|
1641 |
!Class methodsFor: 'binary storage'!
|
|
1642 |
|
|
1643 |
addGlobalsTo: globalDictionary manager: manager
|
|
1644 |
"
|
|
1645 |
classPool == nil ifFalse: [
|
|
1646 |
classPool associationsDo: [:assoc|
|
|
1647 |
globalDictionary at: assoc put: self
|
|
1648 |
]
|
|
1649 |
]
|
|
1650 |
"
|
|
1651 |
!
|
|
1652 |
|
|
1653 |
storeBinaryDefinitionOf: anAssociation on: stream manager: manager
|
|
1654 |
| string |
|
|
1655 |
|
|
1656 |
string := self name, ' classPool at: ', anAssociation key storeString.
|
|
1657 |
stream nextNumber: 2 put: string size.
|
|
1658 |
string do: [:char| stream nextPut: char asciiValue]
|
|
1659 |
! !
|