1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1988-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 |
Object subclass:#Behavior
|
|
14 |
instanceVariableNames:'superclass selectors methods
|
|
15 |
instSize flags'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Kernel-Classes'
|
|
19 |
!
|
|
20 |
|
|
21 |
Behavior comment:'
|
|
22 |
|
|
23 |
COPYRIGHT (c) 1988-93 by Claus Gittinger
|
|
24 |
All Rights Reserved
|
|
25 |
|
|
26 |
this class provides minimum support for all classes - additional stuff is
|
|
27 |
found in Class; Behaviors stuff has been extracted to make generation of
|
|
28 |
compact binaries possible.
|
|
29 |
(these do not need all of the functionality in Class)
|
|
30 |
|
|
31 |
Instance variables:
|
|
32 |
|
|
33 |
superclass <Class> the classes superclass
|
|
34 |
selectors <Array> the selectors for which inst-methods are defined here
|
|
35 |
methods <Array> the inst-methods corresponding to the selectors
|
|
36 |
instSize <SmallInteger> the number of instance variables
|
|
37 |
flags <SmallInteger> special flag bits coded in a number
|
|
38 |
|
|
39 |
NOTICE: layout known by compiler and runtime system; be careful when changing
|
|
40 |
|
|
41 |
%W% %E%
|
|
42 |
written Dec 88 by claus
|
|
43 |
'!
|
|
44 |
|
|
45 |
!Behavior class methodsFor:'creating new classes'!
|
|
46 |
|
|
47 |
new
|
|
48 |
"creates and return a new class"
|
|
49 |
|
|
50 |
|newClass|
|
|
51 |
|
|
52 |
newClass := self basicNew.
|
|
53 |
newClass setSuperclass:Object
|
|
54 |
selectors:(Array new:0)
|
|
55 |
methods:(Array new:0)
|
|
56 |
instSize:0
|
|
57 |
flags:0.
|
|
58 |
^ newClass
|
|
59 |
! !
|
|
60 |
|
|
61 |
!Behavior methodsFor:'initialization'!
|
|
62 |
|
|
63 |
initialize
|
|
64 |
"to catch initialize for classes which do not"
|
|
65 |
|
|
66 |
^ self
|
|
67 |
!
|
|
68 |
|
|
69 |
reinitialize
|
|
70 |
"to catch reinitialize for classes which do not"
|
|
71 |
|
|
72 |
^ self
|
|
73 |
! !
|
|
74 |
|
|
75 |
!Behavior methodsFor:'creating an instance of myself'!
|
|
76 |
|
|
77 |
uninitializedNew
|
|
78 |
"same as new"
|
|
79 |
|
|
80 |
^ self basicNew
|
|
81 |
!
|
|
82 |
|
|
83 |
uninitializedNew:anInteger
|
|
84 |
"same as new:anInteger"
|
|
85 |
|
|
86 |
^ self basicNew:anInteger
|
|
87 |
!
|
|
88 |
|
|
89 |
new
|
|
90 |
"return an instance of myself without indexed variables"
|
|
91 |
|
|
92 |
^ self basicNew
|
|
93 |
!
|
|
94 |
|
|
95 |
new:anInteger
|
|
96 |
"return an instance of myself with anInteger indexed variables"
|
|
97 |
|
|
98 |
^ self basicNew:anInteger
|
|
99 |
!
|
|
100 |
|
|
101 |
basicNew
|
|
102 |
"return an instance of myself without indexed variables
|
|
103 |
If the receiver-class has indexed instvars, the new object will have
|
|
104 |
a basicSize of zero.
|
|
105 |
** Do not redefine this method in any class **"
|
|
106 |
|
|
107 |
%{ /* NOCONTEXT */
|
|
108 |
|
|
109 |
extern char *newNextPtr, *newEndPtr;
|
|
110 |
OBJ newobj;
|
|
111 |
int instsize;
|
|
112 |
REGISTER int nInstVars;
|
|
113 |
#if !defined(memset4)
|
|
114 |
# if !defined(FAST_MEMSET) || defined(NEGATIVE_ADDRESSES)
|
|
115 |
REGISTER OBJ *op;
|
|
116 |
# endif
|
|
117 |
#endif
|
|
118 |
|
|
119 |
nInstVars = _intVal(_INST(instSize));
|
|
120 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ);
|
|
121 |
PROTECT(self);
|
|
122 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
123 |
UNPROTECT(self);
|
|
124 |
_InstPtr(newobj)->o_class = self;
|
|
125 |
|
|
126 |
if (nInstVars) {
|
|
127 |
#if defined(memset4)
|
|
128 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
|
129 |
#else
|
|
130 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
131 |
/*
|
|
132 |
* knowing that nil is 0
|
|
133 |
*/
|
|
134 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
135 |
# else
|
|
136 |
op = _InstPtr(newobj)->i_instvars;
|
|
137 |
do {
|
|
138 |
*op++ = nil;
|
|
139 |
} while (--nInstVars);
|
|
140 |
# endif
|
|
141 |
#endif
|
|
142 |
}
|
|
143 |
RETURN ( newobj );
|
|
144 |
%}
|
|
145 |
!
|
|
146 |
|
|
147 |
basicNew:anInteger
|
|
148 |
"return an instance of myself with anInteger indexed variables.
|
|
149 |
If the receiver-class has no indexed instvars, this is only allowed
|
|
150 |
if the argument, anInteger is zero.
|
|
151 |
** Do not redefine this method in any class **"
|
|
152 |
|
|
153 |
%{ /* NOCONTEXT */
|
|
154 |
|
|
155 |
OBJ newobj;
|
|
156 |
INT instsize, nInstVars, nindexedinstvars;
|
|
157 |
INT flags;
|
|
158 |
#if ! defined(FAST_MEMSET) || defined(NEGATIVE_ADDRESSES)
|
|
159 |
REGISTER char *cp;
|
|
160 |
short *sp;
|
|
161 |
long *lp;
|
|
162 |
#endif
|
|
163 |
REGISTER OBJ *op;
|
|
164 |
float *fp;
|
|
165 |
double *dp;
|
|
166 |
extern OBJ new();
|
|
167 |
|
|
168 |
if (_isSmallInteger(anInteger)) {
|
|
169 |
nindexedinstvars = _intVal(anInteger);
|
|
170 |
if (nindexedinstvars >= 0) {
|
|
171 |
nInstVars = _intVal(_INST(instSize));
|
|
172 |
flags = _intVal(_INST(flags)) & ARRAYMASK;
|
|
173 |
switch (flags) {
|
|
174 |
case BYTEARRAY:
|
|
175 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(char);
|
|
176 |
PROTECT(self);
|
|
177 |
_qNew(newobj, instsize, SENDER);
|
|
178 |
UNPROTECT(self);
|
|
179 |
_InstPtr(newobj)->o_class = self;
|
|
180 |
#if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
181 |
/*
|
|
182 |
* knowing that nil is 0
|
|
183 |
*/
|
|
184 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
185 |
#else
|
|
186 |
op = _InstPtr(newobj)->i_instvars;
|
|
187 |
while (nInstVars--)
|
|
188 |
*op++ = nil;
|
|
189 |
cp = (char *)op;
|
|
190 |
while (nindexedinstvars >= sizeof(long)) {
|
|
191 |
*(long *)cp = 0;
|
|
192 |
cp += sizeof(long);
|
|
193 |
nindexedinstvars -= sizeof(long);
|
|
194 |
}
|
|
195 |
while (nindexedinstvars--)
|
|
196 |
*cp++ = '\0';
|
|
197 |
#endif
|
|
198 |
RETURN ( newobj );
|
|
199 |
break;
|
|
200 |
|
|
201 |
case WORDARRAY:
|
|
202 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(short);
|
|
203 |
PROTECT(self);
|
|
204 |
_qNew(newobj, instsize, SENDER);
|
|
205 |
UNPROTECT(self);
|
|
206 |
_InstPtr(newobj)->o_class = self;
|
|
207 |
#if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
208 |
/*
|
|
209 |
* knowing that nil is 0
|
|
210 |
*/
|
|
211 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
212 |
#else
|
|
213 |
op = _InstPtr(newobj)->i_instvars;
|
|
214 |
while (nInstVars--)
|
|
215 |
*op++ = nil;
|
|
216 |
sp = (short *)op;
|
|
217 |
while (nindexedinstvars--)
|
|
218 |
*sp++ = 0;
|
|
219 |
#endif
|
|
220 |
RETURN ( newobj );
|
|
221 |
break;
|
|
222 |
|
|
223 |
case LONGARRAY:
|
|
224 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(long);
|
|
225 |
PROTECT(self);
|
|
226 |
_qNew(newobj, instsize, SENDER);
|
|
227 |
UNPROTECT(self);
|
|
228 |
_InstPtr(newobj)->o_class = self;
|
|
229 |
#if defined(memset4) && ! defined(NEGATIVE_ADDRESSES)
|
|
230 |
/*
|
|
231 |
* knowing that nil is 0
|
|
232 |
*/
|
|
233 |
memset4(_InstPtr(newobj)->i_instvars, 0, nInstVars + nindexedinstvars);
|
|
234 |
#else
|
|
235 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
236 |
/*
|
|
237 |
* knowing that nil is 0
|
|
238 |
*/
|
|
239 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
240 |
# else
|
|
241 |
op = _InstPtr(newobj)->i_instvars;
|
|
242 |
while (nInstVars--)
|
|
243 |
*op++ = nil;
|
|
244 |
lp = (long *)op;
|
|
245 |
while (nindexedinstvars--)
|
|
246 |
*lp++ = 0;
|
|
247 |
# endif
|
|
248 |
#endif
|
|
249 |
RETURN ( newobj );
|
|
250 |
break;
|
|
251 |
|
|
252 |
case FLOATARRAY:
|
|
253 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(float);
|
|
254 |
PROTECT(self);
|
|
255 |
_qNew(newobj, instsize, SENDER);
|
|
256 |
UNPROTECT(self);
|
|
257 |
_InstPtr(newobj)->o_class = self;
|
|
258 |
op = _InstPtr(newobj)->i_instvars;
|
|
259 |
while (nInstVars--)
|
|
260 |
*op++ = nil;
|
|
261 |
fp = (float *)op;
|
|
262 |
while (nindexedinstvars--)
|
|
263 |
*fp++ = 0.0;
|
|
264 |
RETURN ( newobj );
|
|
265 |
break;
|
|
266 |
|
|
267 |
case DOUBLEARRAY:
|
|
268 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ) + nindexedinstvars * sizeof(double);
|
|
269 |
PROTECT(self);
|
|
270 |
_qNew(newobj, instsize, SENDER);
|
|
271 |
UNPROTECT(self);
|
|
272 |
_InstPtr(newobj)->o_class = self;
|
|
273 |
op = _InstPtr(newobj)->i_instvars;
|
|
274 |
while (nInstVars--)
|
|
275 |
*op++ = nil;
|
|
276 |
dp = (double *)op;
|
|
277 |
while (nindexedinstvars--)
|
|
278 |
*dp++ = 0.0;
|
|
279 |
RETURN ( newobj );
|
|
280 |
break;
|
|
281 |
|
|
282 |
case WKPOINTERARRAY:
|
|
283 |
case POINTERARRAY:
|
|
284 |
nInstVars += nindexedinstvars;
|
|
285 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ);
|
|
286 |
PROTECT(self);
|
|
287 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
288 |
UNPROTECT(self);
|
|
289 |
_InstPtr(newobj)->o_class = self;
|
|
290 |
#if defined(memset4)
|
|
291 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
|
292 |
#else
|
|
293 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
294 |
/*
|
|
295 |
* knowing that nil is 0
|
|
296 |
*/
|
|
297 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
298 |
# else
|
|
299 |
op = _InstPtr(newobj)->i_instvars;
|
|
300 |
while (nInstVars--)
|
|
301 |
*op++ = nil;
|
|
302 |
# endif
|
|
303 |
#endif
|
|
304 |
RETURN ( newobj );
|
|
305 |
break;
|
|
306 |
|
|
307 |
default:
|
|
308 |
/*
|
|
309 |
* new:n for non-variable classes only allowed if
|
|
310 |
* n == 0
|
|
311 |
*/
|
|
312 |
if (nindexedinstvars == 0) {
|
|
313 |
instsize = OHDR_SIZE + nInstVars * sizeof(OBJ);
|
|
314 |
PROTECT(self);
|
|
315 |
_qAlignedNew(newobj, instsize, SENDER);
|
|
316 |
UNPROTECT(self);
|
|
317 |
_InstPtr(newobj)->o_class = self;
|
|
318 |
if (nInstVars) {
|
|
319 |
#if defined(memset4)
|
|
320 |
memset4(_InstPtr(newobj)->i_instvars, nil, nInstVars);
|
|
321 |
#else
|
|
322 |
# if defined(FAST_MEMSET) && ! defined(NEGATIVE_ADDRESSES)
|
|
323 |
/*
|
|
324 |
* knowing that nil is 0
|
|
325 |
*/
|
|
326 |
memset(_InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
|
|
327 |
# else
|
|
328 |
op = _InstPtr(newobj)->i_instvars;
|
|
329 |
do {
|
|
330 |
*op++ = nil;
|
|
331 |
} while (--nInstVars);
|
|
332 |
# endif
|
|
333 |
#endif
|
|
334 |
}
|
|
335 |
RETURN ( newobj );
|
|
336 |
}
|
|
337 |
break;
|
|
338 |
}
|
|
339 |
}
|
|
340 |
}
|
|
341 |
%}
|
|
342 |
.
|
|
343 |
(anInteger isMemberOf:SmallInteger) ifFalse:[
|
|
344 |
self error:'argument to new: must be Integer'
|
|
345 |
] ifTrue:[
|
|
346 |
(anInteger >= 0) ifTrue:[
|
|
347 |
"sorry but this class has no indexed instvars - need 'new' "
|
|
348 |
self error:'not indexed - cannot create with new:'
|
|
349 |
] ifFalse:[
|
|
350 |
self error:'bad argument'
|
|
351 |
]
|
|
352 |
]
|
|
353 |
! !
|
|
354 |
|
|
355 |
!Behavior methodsFor:'accessing'!
|
|
356 |
|
|
357 |
superclass
|
|
358 |
"return the receivers superclass"
|
|
359 |
|
|
360 |
^ superclass
|
|
361 |
!
|
|
362 |
|
|
363 |
selectors
|
|
364 |
"return the receivers selector array"
|
|
365 |
|
|
366 |
^ selectors
|
|
367 |
!
|
|
368 |
|
|
369 |
methods
|
|
370 |
"return the receivers method array"
|
|
371 |
|
|
372 |
^ methods
|
|
373 |
!
|
|
374 |
|
|
375 |
methodDictionary
|
|
376 |
"return the receivers method dictionary - since no dictionary is
|
|
377 |
used (for now) just return the method array"
|
|
378 |
|
|
379 |
^ methods
|
|
380 |
!
|
|
381 |
|
|
382 |
instSize
|
|
383 |
"return the number of instance variables of the receiver"
|
|
384 |
|
|
385 |
^ instSize
|
|
386 |
!
|
|
387 |
|
|
388 |
flags
|
|
389 |
"return the receivers flag bits"
|
|
390 |
|
|
391 |
^ flags
|
|
392 |
!
|
|
393 |
|
|
394 |
isVariable
|
|
395 |
"return true, if instances have indexed instance variables"
|
|
396 |
|
|
397 |
"this used to be defined as:
|
|
398 |
^ (flags bitAnd:16r0F) ~~ 0
|
|
399 |
but then, changes in stc.h would not affect us here. Therefore:"
|
|
400 |
|
|
401 |
%{ /* NOCONTEXT */
|
|
402 |
/* this is defined as a primitive to get defines from stc.h */
|
|
403 |
|
|
404 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? true : false );
|
|
405 |
%}
|
|
406 |
!
|
|
407 |
|
|
408 |
isFixed
|
|
409 |
"return true, if instances do not have indexed instance variables"
|
|
410 |
|
|
411 |
%{ /* NOCONTEXT */
|
|
412 |
/* this is defined as a primitive to get defines from stc.h */
|
|
413 |
|
|
414 |
RETURN ( (_intVal(_INST(flags)) & ARRAYMASK) ? false : true );
|
|
415 |
%}
|
|
416 |
!
|
|
417 |
|
|
418 |
isBits
|
|
419 |
"return true, if instances have indexed byte or short instance variables.
|
|
420 |
Ignore long, float and double arrays, since classes using isBits are probably
|
|
421 |
not prepared to handle them correctly."
|
|
422 |
|
|
423 |
%{ /* NOCONTEXT */
|
|
424 |
/* this is defined as a primitive to get defines from stc.h */
|
|
425 |
|
|
426 |
REGISTER int flags;
|
|
427 |
|
|
428 |
RETURN ( (((flags = (_intVal(_INST(flags)) & ARRAYMASK)) == BYTEARRAY)
|
|
429 |
|| (flags == WORDARRAY)) ? true : false );
|
|
430 |
%}
|
|
431 |
!
|
|
432 |
|
|
433 |
isBytes
|
|
434 |
"return true, if instances have indexed byte instance variables"
|
|
435 |
|
|
436 |
%{ /* NOCONTEXT */
|
|
437 |
/* this is defined as a primitive to get defines from stc.h */
|
|
438 |
|
|
439 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == BYTEARRAY) ? true : false );
|
|
440 |
%}
|
|
441 |
!
|
|
442 |
|
|
443 |
isWords
|
|
444 |
"return true, if instances have indexed short instance variables"
|
|
445 |
|
|
446 |
%{ /* NOCONTEXT */
|
|
447 |
/* this is defined as a primitive to get defines from stc.h */
|
|
448 |
|
|
449 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == WORDARRAY) ? true : false );
|
|
450 |
%}
|
|
451 |
!
|
|
452 |
|
|
453 |
isLongs
|
|
454 |
"return true, if instances have indexed long instance variables"
|
|
455 |
|
|
456 |
%{ /* NOCONTEXT */
|
|
457 |
/* this is defined as a primitive to get defines from stc.h */
|
|
458 |
|
|
459 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == LONGARRAY) ? true : false );
|
|
460 |
%}
|
|
461 |
!
|
|
462 |
|
|
463 |
isFloats
|
|
464 |
"return true, if instances have indexed float instance variables"
|
|
465 |
|
|
466 |
%{ /* NOCONTEXT */
|
|
467 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == FLOATARRAY) ? true : false );
|
|
468 |
%}
|
|
469 |
!
|
|
470 |
|
|
471 |
isDoubles
|
|
472 |
"return true, if instances have indexed double instance variables"
|
|
473 |
|
|
474 |
%{ /* NOCONTEXT */
|
|
475 |
RETURN ( ((_intVal(_INST(flags)) & ARRAYMASK) == DOUBLEARRAY) ? true : false );
|
|
476 |
%}
|
|
477 |
!
|
|
478 |
|
|
479 |
isPointers
|
|
480 |
"return true, if instances have pointer instance variables"
|
|
481 |
|
|
482 |
"question: should we ignore WeakPointers ?"
|
|
483 |
%{ /* NOCONTEXT */
|
|
484 |
REGISTER int flags;
|
|
485 |
|
|
486 |
RETURN ( (((flags = (_intVal(_INST(flags)) & ARRAYMASK)) == POINTERARRAY)
|
|
487 |
|| (flags == WKPOINTERARRAY)) ? true : false );
|
|
488 |
%}
|
|
489 |
! !
|
|
490 |
|
|
491 |
!Behavior methodsFor:'queries'!
|
|
492 |
|
|
493 |
isBehavior
|
|
494 |
"return true, if the receiver describing another objecs behavior
|
|
495 |
i.e. is a class."
|
|
496 |
|
|
497 |
^ true
|
|
498 |
!
|
|
499 |
|
|
500 |
hasMultipleSuperclasses
|
|
501 |
"NO multiple inheritance in this system"
|
|
502 |
|
|
503 |
^ false
|
|
504 |
!
|
|
505 |
|
|
506 |
superclasses
|
|
507 |
"return a collection of the receivers immediate superclasses
|
|
508 |
- since we have NO multiple inheritance, there is only one"
|
|
509 |
|
|
510 |
^ Array with:superclass
|
|
511 |
!
|
|
512 |
|
|
513 |
allSuperclasses
|
|
514 |
"return a collection of the receivers accumulated superclasses"
|
|
515 |
|
|
516 |
|aCollection theSuperClass|
|
|
517 |
|
|
518 |
theSuperClass := superclass.
|
|
519 |
theSuperClass notNil ifTrue:[
|
|
520 |
aCollection := OrderedCollection new.
|
|
521 |
[theSuperClass notNil] whileTrue:[
|
|
522 |
aCollection add:theSuperClass.
|
|
523 |
theSuperClass := theSuperClass superclass
|
|
524 |
]
|
|
525 |
].
|
|
526 |
^ aCollection
|
|
527 |
!
|
|
528 |
|
|
529 |
withAllSuperclasses
|
|
530 |
"return a collection containing the receiver and all
|
|
531 |
of the receivers accumulated superclasses"
|
|
532 |
|
|
533 |
|aCollection theSuperClass|
|
|
534 |
|
|
535 |
aCollection := OrderedCollection with:self.
|
|
536 |
theSuperClass := superclass.
|
|
537 |
[theSuperClass notNil] whileTrue:[
|
|
538 |
aCollection add:theSuperClass.
|
|
539 |
theSuperClass := theSuperClass superclass
|
|
540 |
].
|
|
541 |
^ aCollection
|
|
542 |
!
|
|
543 |
|
|
544 |
subclasses
|
|
545 |
"return a collection of the direct subclasses of the receiver"
|
|
546 |
|
|
547 |
|newColl|
|
|
548 |
|
|
549 |
newColl := OrderedCollection new.
|
|
550 |
self subclassesDo:[:aClass |
|
|
551 |
newColl add:aClass
|
|
552 |
].
|
|
553 |
^ newColl
|
|
554 |
!
|
|
555 |
|
|
556 |
allSubclasses
|
|
557 |
"return a collection of all subclasses (direct AND indirect) of
|
|
558 |
the receiver"
|
|
559 |
|
|
560 |
|newColl|
|
|
561 |
|
|
562 |
newColl := OrderedCollection new.
|
|
563 |
self allSubclassesDo:[:aClass |
|
|
564 |
newColl add:aClass
|
|
565 |
].
|
|
566 |
^ newColl
|
|
567 |
!
|
|
568 |
|
|
569 |
withAllSubclasses
|
|
570 |
"return a collection containing the receiver and
|
|
571 |
all subclasses (direct AND indirect) of the receiver"
|
|
572 |
|
|
573 |
|newColl|
|
|
574 |
|
|
575 |
newColl := OrderedCollection with:self.
|
|
576 |
self allSubclassesDo:[:aClass |
|
|
577 |
newColl add:aClass
|
|
578 |
].
|
|
579 |
^ newColl
|
|
580 |
!
|
|
581 |
|
|
582 |
isSubclassOf:aClass
|
|
583 |
"return true, if I am a subclass of the argument, aClass"
|
|
584 |
|
|
585 |
|theClass|
|
|
586 |
theClass := superclass.
|
|
587 |
[theClass notNil] whileTrue:[
|
|
588 |
(theClass == aClass) ifTrue:[^ true].
|
|
589 |
theClass := theClass superclass
|
|
590 |
].
|
|
591 |
^ false
|
|
592 |
!
|
|
593 |
|
|
594 |
allInstances
|
|
595 |
"return a collection of all my instances"
|
|
596 |
|
|
597 |
|coll|
|
|
598 |
|
|
599 |
coll := OrderedCollection new.
|
|
600 |
ObjectMemory allObjectsDo:[:anObject |
|
|
601 |
(anObject class == self) ifTrue:[
|
|
602 |
coll add:anObject
|
|
603 |
]
|
|
604 |
].
|
|
605 |
^ coll asArray
|
|
606 |
!
|
|
607 |
|
|
608 |
instanceCount
|
|
609 |
"return the number of instances of myself"
|
|
610 |
|
|
611 |
|count|
|
|
612 |
|
|
613 |
count := 0.
|
|
614 |
ObjectMemory allObjectsDo:[:anObject |
|
|
615 |
(anObject class == self) ifTrue:[
|
|
616 |
count := count + 1
|
|
617 |
]
|
|
618 |
].
|
|
619 |
^ count
|
|
620 |
! !
|
|
621 |
|
|
622 |
!Behavior methodsFor:'private accessing'!
|
|
623 |
|
|
624 |
setSuperclass:sup selectors:sels methods:m instSize:i flags:f
|
|
625 |
"set some inst vars (private use only)"
|
|
626 |
|
|
627 |
superclass := sup.
|
|
628 |
selectors := sels.
|
|
629 |
methods := m.
|
|
630 |
instSize := i.
|
|
631 |
flags := f
|
|
632 |
!
|
|
633 |
|
|
634 |
setSuperclass:aClass
|
|
635 |
"set the superclass of the receiver"
|
|
636 |
|
|
637 |
superclass := aClass
|
|
638 |
!
|
|
639 |
|
|
640 |
instSize:aNumber
|
|
641 |
"set the instance size"
|
|
642 |
|
|
643 |
instSize := aNumber
|
|
644 |
!
|
|
645 |
|
|
646 |
flags:aNumber
|
|
647 |
"set the flags"
|
|
648 |
|
|
649 |
flags := aNumber
|
|
650 |
!
|
|
651 |
|
|
652 |
setSelectors:anArray
|
|
653 |
"set the selector array of the receiver"
|
|
654 |
|
|
655 |
selectors := anArray
|
|
656 |
!
|
|
657 |
|
|
658 |
setMethodDictionary:anArray
|
|
659 |
"set the method array of the receiver"
|
|
660 |
|
|
661 |
methods := anArray
|
|
662 |
!
|
|
663 |
|
|
664 |
superclass:aClass
|
|
665 |
"set the superclass"
|
|
666 |
|
|
667 |
"must flush caches since lookup chain changes"
|
|
668 |
ObjectMemory flushCaches.
|
|
669 |
superclass := aClass
|
|
670 |
!
|
|
671 |
|
|
672 |
selectors:selectorArray methods:methodArray
|
|
673 |
"set both selector array and method array of the receiver,
|
|
674 |
and flush caches"
|
|
675 |
|
|
676 |
ObjectMemory flushCaches.
|
|
677 |
selectors := selectorArray.
|
|
678 |
methods := methodArray
|
|
679 |
! !
|
|
680 |
|
|
681 |
!Behavior methodsFor:'enumeration'!
|
|
682 |
|
|
683 |
allInstancesDo:aBlock
|
|
684 |
"evaluate a block for all of my instances"
|
|
685 |
|
|
686 |
ObjectMemory allObjectsDo:[:anObject |
|
|
687 |
(anObject class == self) ifTrue:[
|
|
688 |
aBlock value:anObject
|
|
689 |
]
|
|
690 |
]
|
|
691 |
!
|
|
692 |
|
|
693 |
subclassesDo:aBlock
|
|
694 |
"evaluate the argument, aBlock for all immediate subclasses"
|
|
695 |
|
|
696 |
Smalltalk allClassesDo:[:aClass |
|
|
697 |
(aClass superclass == self) ifTrue:[
|
|
698 |
aBlock value:aClass
|
|
699 |
]
|
|
700 |
]
|
|
701 |
!
|
|
702 |
|
|
703 |
allSubclassesDo:aBlock
|
|
704 |
"evaluate a block for all of my subclasses"
|
|
705 |
|
|
706 |
Smalltalk allClassesDo:[:aClass |
|
|
707 |
(aClass isSubclassOf:self) ifTrue:[
|
|
708 |
aBlock value:aClass
|
|
709 |
]
|
|
710 |
]
|
|
711 |
!
|
|
712 |
|
|
713 |
allSubclassesInOrderDo:aBlock
|
|
714 |
"evaluate a block for all of my subclasses where superclasses come
|
|
715 |
first"
|
|
716 |
|
|
717 |
self subclassesDo:[:aClass |
|
|
718 |
aBlock value:aClass.
|
|
719 |
aClass allSubclassesInOrderDo:aBlock
|
|
720 |
]
|
|
721 |
!
|
|
722 |
|
|
723 |
allSuperclassesDo:aBlock
|
|
724 |
"evaluate a block for all of my superclasses"
|
|
725 |
|
|
726 |
|theClass|
|
|
727 |
|
|
728 |
theClass := superclass.
|
|
729 |
[theClass notNil] whileTrue:[
|
|
730 |
aBlock value:theClass.
|
|
731 |
theClass := theClass superclass
|
|
732 |
]
|
|
733 |
! !
|