author | Claus Gittinger <cg@exept.de> |
Thu, 22 Oct 2009 19:34:44 +0200 | |
changeset 12331 | 02c0437d7817 |
parent 12302 | 656c61777a20 |
child 12354 | f83a21cef1ba |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
154 | 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 |
" |
|
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
13 |
|
1 | 14 |
Object subclass:#Behavior |
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
15 |
instanceVariableNames:'superclass flags methodDictionary instSize' |
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
16 |
classVariableNames:'SubclassInfo' |
1088 | 17 |
poolDictionaries:'' |
18 |
category:'Kernel-Classes' |
|
1 | 19 |
! |
20 |
||
1760 | 21 |
!Behavior class methodsFor:'documentation'! |
47 | 22 |
|
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
154 | 26 |
All Rights Reserved |
88 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
47 | 37 |
documentation |
38 |
" |
|
68 | 39 |
Every class in the system inherits from Behavior (via Class, ClassDescription); |
40 |
so here is where most of the class messages end up being implemented. |
|
41 |
(to answer a FAQ: 'Point basicNew' will be done here :-) |
|
42 |
||
356 | 43 |
Beginners should keep in mind, that all classes are instances (of subclasses) |
12094 | 44 |
of Behavior, therefore you will find the above mentioned 'basicNew:' method |
45 |
under the 'instance'-methods of Behavior - NOT under the class methods |
|
46 |
('Behavior new' will create and return a new class, while sending 'new' to |
|
154 | 47 |
any instance of Behavior (i.e. any class) will return an instance of that class). |
68 | 48 |
|
2226 | 49 |
|
68 | 50 |
Behavior provides minimum support for all classes - additional stuff is |
77 | 51 |
found in ClassDescription and Class. Behaviors provides all mechanisms needed |
12094 | 52 |
to create instances, and send messages to those. However, Behavior does not provide |
77 | 53 |
all the (symbolic) information needed to compile methods for a class or to get |
54 |
useful information in inspectors. |
|
47 | 55 |
|
2226 | 56 |
for experts: |
57 |
||
58 |
Since instances of Behavior provide all that is needed to interact with the VM's |
|
59 |
message dispatch mechanism, these can be used as 'light weight' classes. |
|
60 |
I.e. it is possible, to generate completely anonymous classes (and instances thereof) |
|
61 |
on the fly - 'Behavior new new' is such a thingy. |
|
62 |
||
12094 | 63 |
The selectors and Methods are organized in a MethodDictionary (which is not a true |
2226 | 64 |
dictionary, but an Array with alternating selector/method entries). |
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
65 |
This avoids the need for knowledge about Dictionaries in the runtime library (VM) |
12094 | 66 |
(lookup and search in these is seldom anyway, so the added benefit from using a |
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
67 |
hashed dictionary is almost void). |
1 | 68 |
|
1285 | 69 |
[Instance variables:] |
70 |
||
2666
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
71 |
superclass <Class> the receivers superclass |
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
72 |
|
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
73 |
methodDictionary <MethodDictionary> inst-selectors and methods |
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
74 |
|
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
75 |
instSize <SmallInteger> the number of instance variables |
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
76 |
|
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
77 |
flags <SmallInteger> special flag bits coded in a number |
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
78 |
not for application use |
1 | 79 |
|
81 | 80 |
flag bits (see stc.h): |
47 | 81 |
|
68 | 82 |
NOTICE: layout known by compiler and runtime system; be careful when changing |
1285 | 83 |
|
1292 | 84 |
[author:] |
2666
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
85 |
Claus Gittinger |
1292 | 86 |
|
1285 | 87 |
[see also:] |
2666
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
88 |
Class ClassDescription Metaclass |
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
89 |
Method MethodDictionary |
47 | 90 |
" |
356 | 91 |
! |
92 |
||
12094 | 93 |
virtualMachineRelationship |
356 | 94 |
" |
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
95 |
Expert info follows: |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
96 |
|
12094 | 97 |
NOTICE: |
98 |
the stuff described below may not be available on other |
|
99 |
Smalltalk implementations; be aware that these error mechanisms |
|
100 |
are ST/X specials and applications using these (tricks) may |
|
101 |
not be portable to other systems. |
|
102 |
||
103 |
WARNING: |
|
104 |
do not try the examples below on (some) other smalltalk systems; |
|
105 |
it has been reported, that some crash badly when doing this .... ;-) |
|
357 | 106 |
|
356 | 107 |
Instances of Behavior and subclasses (i.e. in sloppy words: classes) |
108 |
play a special role w.r.t. the VM. Only objects whose class-slot is marked |
|
109 |
as being behaviorLike (in the flag-instvar) are considered to be classLike |
|
110 |
and a message lookup will be done for it in the well known way. |
|
111 |
Thus, if an object has a class for which its class does NOT have |
|
362 | 112 |
this flag bit set, the VM will trigger an error on a message send. |
356 | 113 |
|
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
114 |
|
356 | 115 |
Why is this so: |
116 |
||
117 |
the above lets every object play the role of a class, |
|
118 |
which has been flagged as behaviorLike in its class's flag. |
|
12094 | 119 |
Thus, you can create arbitrary new classLike objects and have the VM |
356 | 120 |
play with them. |
121 |
This may offer the flexibility to create a totally different object scheme |
|
362 | 122 |
on top of ST/X (for example: Self like objects) where any object can play |
123 |
a classRole for another object. |
|
356 | 124 |
|
2148 | 125 |
[A concrete application of this is found in the Structure class, |
126 |
which creates objects which are their own class !! |
|
12094 | 127 |
This may look to be of theoretical value at first sight, |
128 |
however, such a construct saves memory, by not requiring an extra |
|
2148 | 129 |
class object per Structure object.] |
130 |
||
131 |
Be aware, that the VM trusts the isBehaviorLike flag - IF it is set for some |
|
132 |
object, the VM EXPECTS the object selector and methodDictionaries to be found |
|
362 | 133 |
at the instance positions as defined here. |
134 |
(i.e. instanceVariables with contents and semantic corresponding to |
|
12094 | 135 |
superclass |
136 |
flags |
|
137 |
methodDictionary |
|
362 | 138 |
must be present and have the same instVar-index as here). |
139 |
||
356 | 140 |
The VM (and the system) may crash badly, if this is not the case. |
362 | 141 |
|
356 | 142 |
Since every class in the system derives from Behavior, the flag setting |
357 | 143 |
(and instance variable layout) is correct for all 'normal' classes. |
144 |
If you experiment by creating new behaviorLike objects, please take |
|
145 |
care of this flag. If you want to use the VM's lookup function, the |
|
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
146 |
instVars 'superclass' and 'methodDictionary' are required |
357 | 147 |
and have to be at the same instVar index. |
362 | 148 |
(we suggest, you subclass Behavior, to make certain) |
357 | 149 |
|
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
150 |
|
8503 | 151 |
Vice versa, defining 'dumb classes', which have the behaviorLike bit turned |
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
152 |
of may be useful as well; if a message is sent to an instance of such |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
153 |
a thingy, the VM performs a recovery sequence, which is much like the |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
154 |
#doesNotUnderstand: mechanism - however, since the instance is no good |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
155 |
receiver of such a message, a #cannotSendMessage:to: is now sent to the |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
156 |
class (which is not a real class), passing the original message (selector |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
157 |
and arguments) along with the original receiver. |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
158 |
The default behavior for this message is to raise an internalError signal - |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
159 |
however, you may redefine this in your 'dum class' for recovery. |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
160 |
One possible use of this is to provide new message send algorithms - the |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
161 |
class may lookup a method and invoke it directly, via the #valueWithReceiver: |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
162 |
interface. |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
163 |
|
12094 | 164 |
All of the above is pure expert stuff |
2230
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
165 |
- You do not have to care about the above details if you are a 'normal' |
b7a86880ab9c
beahvior documentation updated
Claus Gittinger <cg@exept.de>
parents:
2228
diff
changeset
|
166 |
ST-programmer, though (and even most of those will never use these features). |
357 | 167 |
|
356 | 168 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
746
diff
changeset
|
169 |
Examples (only of theoretical interest): |
12094 | 170 |
take away the behaviorLike-flag from a class. |
171 |
-> The instances will not understand any messages, since the VM will |
|
172 |
not recognize its class as being a class ... |
|
173 |
||
174 |
|newMeta notRecognizedAsClass someInstance| |
|
175 |
||
176 |
newMeta := Metaclass new. |
|
177 |
newMeta flags:0. |
|
178 |
||
179 |
notRecognizedAsClass := newMeta new. |
|
180 |
||
181 |
someInstance := notRecognizedAsClass new. |
|
182 |
someInstance perform:#isNil |
|
356 | 183 |
|
357 | 184 |
|
185 |
Of course, this is an exception which can be handled ...: |
|
186 |
Example: |
|
187 |
||
12094 | 188 |
|newMeta notRecognizedAsClass someInstance| |
189 |
||
190 |
newMeta := Metaclass new. |
|
191 |
newMeta flags:0. |
|
192 |
||
193 |
notRecognizedAsClass := newMeta new. |
|
194 |
||
195 |
someInstance := notRecognizedAsClass new. |
|
196 |
Object errorSignal handle:[:ex | |
|
197 |
ex return |
|
198 |
] do:[ |
|
199 |
someInstance perform:#isNil |
|
200 |
] |
|
357 | 201 |
|
202 |
||
203 |
likewise, a doesNotUnderstand-notUnderstood can be handled: |
|
204 |
Example: |
|
205 |
||
12094 | 206 |
|newMeta funnyClass someInstance| |
207 |
||
208 |
newMeta := Metaclass new. |
|
209 |
||
210 |
funnyClass := newMeta new. |
|
211 |
funnyClass setSuperclass:nil. |
|
212 |
||
213 |
someInstance := funnyClass new. |
|
214 |
Object errorSignal handle:[:ex | |
|
215 |
ex return |
|
216 |
] do:[ |
|
217 |
someInstance perform:#isNil |
|
218 |
] |
|
357 | 219 |
|
220 |
||
362 | 221 |
more examples, which try to trick the VM ;-): |
12094 | 222 |
badly playing around with a classes internals ... |
223 |
||
224 |
|newClass someInstance| |
|
225 |
||
226 |
newClass := Class new. |
|
227 |
newClass setSuperclass:nil. |
|
228 |
someInstance := newClass new. |
|
229 |
someInstance inspect |
|
230 |
||
231 |
||
232 |
|newClass someInstance| |
|
233 |
||
234 |
newClass := Class new. |
|
235 |
newClass setSuperclass:newClass. |
|
236 |
someInstance := newClass new. |
|
237 |
someInstance inspect |
|
238 |
||
239 |
||
240 |
|newClass someInstance| |
|
241 |
||
242 |
newClass := Class new. |
|
243 |
newClass setSuperclass:1. |
|
244 |
someInstance := newClass new. |
|
245 |
someInstance inspect |
|
357 | 246 |
|
247 |
||
356 | 248 |
Example: |
12094 | 249 |
creating totally anonymous classes: |
250 |
||
251 |
|newClass someInstance| |
|
252 |
||
253 |
newClass := Class new. |
|
254 |
someInstance := newClass new. |
|
255 |
someInstance inspect |
|
356 | 256 |
|
357 | 257 |
|
356 | 258 |
Example: |
12094 | 259 |
creating totally anonymous metaclasses: |
260 |
||
261 |
|newMeta newClass someInstance| |
|
262 |
||
263 |
newMeta := Metaclass new. |
|
264 |
newClass := newMeta new. |
|
265 |
someInstance := newClass new. |
|
266 |
someInstance inspect |
|
267 |
||
268 |
||
269 |
PS: if you experiment with new behaviorLike objects, you may want |
|
270 |
to turn off the VM's debugPrintouts |
|
271 |
with: |
|
272 |
'Smalltalk debugPrinting:false' |
|
273 |
and: |
|
274 |
'Smalltalk infoPrinting:false' |
|
356 | 275 |
" |
47 | 276 |
! ! |
1 | 277 |
|
1760 | 278 |
!Behavior class methodsFor:'creating new classes'! |
1 | 279 |
|
280 |
new |
|
356 | 281 |
"creates and return a new behavior (which is like a class, |
282 |
but without the symbolic & name information). |
|
283 |
Not for normal applications. |
|
284 |
Sending the returned behavior the #new message gives you |
|
285 |
an instance if it. |
|
286 |
||
287 |
Notice: the returned class is given a superclass of Object; |
|
288 |
this allows for its new instances to be inspected and the like." |
|
1 | 289 |
|
290 |
|newClass| |
|
291 |
||
292 |
newClass := self basicNew. |
|
12094 | 293 |
newClass |
294 |
setSuperclass:Object |
|
295 |
methodDictionary:(MethodDictionary new) |
|
296 |
instSize:0 |
|
297 |
flags:(self flagBehavior). |
|
1 | 298 |
^ newClass |
356 | 299 |
|
300 |
" |
|
301 |
Behavior new <- a new behavior |
|
302 |
Behavior new new <- an instance of it |
|
303 |
ClassDescription new <- a new classDescription |
|
304 |
ClassDescription new new <- an instance of it |
|
305 |
Class new <- a new class |
|
306 |
Class new new <- an instance of it |
|
307 |
Metaclass new <- a new metaclass |
|
308 |
Metaclass new new <- an instance (i.e. a class) of it |
|
309 |
Metaclass new new new <- an instance of this new class |
|
310 |
" |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
311 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
312 |
"Modified: 7.6.1996 / 15:38:58 / stefan" |
1 | 313 |
! ! |
314 |
||
1760 | 315 |
!Behavior class methodsFor:'flag bit constants'! |
620 | 316 |
|
317 |
flagBehavior |
|
318 |
"return the flag code which marks Behavior-like instances. |
|
7190 | 319 |
Inline C-code and the VM check this single bit in the flag value when |
620 | 320 |
checking for behaviors." |
321 |
||
322 |
%{ /* NOCONTEXT */ |
|
323 |
/* this is defined as a primitive to get defines from stc.h */ |
|
324 |
||
8913 | 325 |
RETURN ( __mkSmallInteger(BEHAVIOR_INSTS) ); |
620 | 326 |
%} |
327 |
||
328 |
"consistency check: |
|
329 |
all class-entries must be behaviors; |
|
330 |
all behaviors must be flagged so (in its class's flags) |
|
331 |
(otherwise, VM will bark) |
|
332 |
all non-behaviors may not be flagged |
|
333 |
||
334 |
|bit| |
|
335 |
bit := Class flagBehavior. |
|
336 |
||
337 |
ObjectMemory allObjectsDo:[:o| |
|
338 |
o isBehavior ifTrue:[ |
|
12094 | 339 |
(o class flags bitTest:bit) ifFalse:[ |
340 |
self halt |
|
341 |
]. |
|
620 | 342 |
] ifFalse:[ |
12094 | 343 |
(o class flags bitTest:bit) ifTrue:[ |
344 |
self halt |
|
345 |
]. |
|
620 | 346 |
]. |
347 |
o class isBehavior ifFalse:[ |
|
12094 | 348 |
self halt |
620 | 349 |
] ifTrue:[ |
12094 | 350 |
(o class class flags bitTest:bit) ifFalse:[ |
351 |
self halt |
|
352 |
] |
|
620 | 353 |
] |
354 |
] |
|
355 |
" |
|
356 |
! |
|
357 |
||
358 |
flagBlock |
|
359 |
"return the flag code which marks Block-like instances. |
|
12094 | 360 |
The VM checks for either this bit or the blockLike bit in the flag |
2236 | 361 |
value when checking for blocks to be evaluated from bytecodes. |
362 |
However, compiled code only checks for the block bit." |
|
620 | 363 |
|
364 |
%{ /* NOCONTEXT */ |
|
365 |
/* this is defined as a primitive to get defines from stc.h */ |
|
366 |
||
8913 | 367 |
RETURN ( __mkSmallInteger(BLOCK_INSTS) ); |
620 | 368 |
%} |
369 |
! |
|
370 |
||
371 |
flagBlockContext |
|
372 |
"return the flag code which marks BlockContext-like instances. |
|
2226 | 373 |
The VM checks this single bit in the flag value when |
620 | 374 |
checking for blockContexts." |
375 |
||
376 |
%{ /* NOCONTEXT */ |
|
377 |
/* this is defined as a primitive to get defines from stc.h */ |
|
378 |
||
8913 | 379 |
RETURN ( __mkSmallInteger(BCONTEXT_INSTS) ); |
620 | 380 |
%} |
381 |
! |
|
382 |
||
2236 | 383 |
flagBlockLike |
384 |
"return the flag code which marks Block-like instances |
|
385 |
with respect to byteCode interpretation. |
|
12094 | 386 |
The VM checks for either this bit or the block bit in the flag |
2236 | 387 |
value when checking for blocks to be evaluated from bytecodes. |
388 |
However, compiled code only checks for the block bit." |
|
389 |
||
390 |
%{ /* NOCONTEXT */ |
|
391 |
/* this is defined as a primitive to get defines from stc.h */ |
|
392 |
||
8913 | 393 |
RETURN ( __mkSmallInteger(BLOCKLIKE_INSTS) ); |
2236 | 394 |
%} |
395 |
! |
|
396 |
||
620 | 397 |
flagBytes |
398 |
"return the flag code for byte-valued indexed instances. |
|
12094 | 399 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 400 |
and compares it to this flag value, when checking for byte valued |
401 |
variable instances." |
|
620 | 402 |
|
403 |
%{ /* NOCONTEXT */ |
|
404 |
/* this is defined as a primitive to get defines from stc.h */ |
|
405 |
||
8913 | 406 |
RETURN ( __mkSmallInteger(BYTEARRAY) ); |
620 | 407 |
%} |
408 |
" |
|
12094 | 409 |
Behavior flagBytes |
620 | 410 |
" |
411 |
! |
|
412 |
||
413 |
flagContext |
|
414 |
"return the flag code which marks Context-like instances. |
|
2226 | 415 |
The VM checks this single bit in the flag value when |
620 | 416 |
checking for contexts." |
417 |
||
418 |
%{ /* NOCONTEXT */ |
|
419 |
/* this is defined as a primitive to get defines from stc.h */ |
|
420 |
||
8913 | 421 |
RETURN ( __mkSmallInteger(CONTEXT_INSTS) ); |
620 | 422 |
%} |
423 |
! |
|
424 |
||
425 |
flagDoubles |
|
426 |
"return the flag code for double-valued indexed instances (i.e. 8-byte reals). |
|
12094 | 427 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 428 |
and compares it to this flag value, when checking for double valued |
429 |
variable instances." |
|
620 | 430 |
|
431 |
%{ /* NOCONTEXT */ |
|
432 |
/* this is defined as a primitive to get defines from stc.h */ |
|
433 |
||
8913 | 434 |
RETURN ( __mkSmallInteger(DOUBLEARRAY) ); |
620 | 435 |
%} |
436 |
" |
|
12094 | 437 |
Behavior flagDoubles |
438 |
||
439 |
(ByteArray flags bitAnd:(Behavior maskIndexType)) == (Behavior flagDoubles) |
|
440 |
(DoubleArray flags bitAnd:(Behavior maskIndexType)) == (Behavior flagDoubles) |
|
441 |
(Object flags bitAnd:(Behavior maskIndexType)) == (Behavior flagDoubles) |
|
620 | 442 |
" |
443 |
! |
|
444 |
||
7190 | 445 |
flagExternalBytes |
446 |
"return the flag code which marks ExternalBytes-like instances. |
|
447 |
Inline C-code and the VM check this single bit in the flag value when |
|
448 |
checking for an externalBytes-like objet." |
|
449 |
||
450 |
%{ /* NOCONTEXT */ |
|
451 |
/* this is defined as a primitive to get defines from stc.h */ |
|
452 |
||
8913 | 453 |
RETURN ( __mkSmallInteger(EXTERNALBYTES_INSTS) ); |
7190 | 454 |
%} |
455 |
! |
|
456 |
||
620 | 457 |
flagFloat |
458 |
"return the flag code which marks Float-like instances. |
|
7190 | 459 |
Inline C-code and the VM check this single bit in the flag value when |
2226 | 460 |
checking for a float." |
620 | 461 |
|
462 |
%{ /* NOCONTEXT */ |
|
463 |
/* this is defined as a primitive to get defines from stc.h */ |
|
464 |
||
8913 | 465 |
RETURN ( __mkSmallInteger(FLOAT_INSTS) ); |
620 | 466 |
%} |
467 |
! |
|
468 |
||
469 |
flagFloats |
|
470 |
"return the flag code for float-valued indexed instances (i.e. 4-byte reals). |
|
12094 | 471 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 472 |
and compares it to this flag value, when checking for double valued |
473 |
variable instances." |
|
620 | 474 |
|
475 |
%{ /* NOCONTEXT */ |
|
476 |
/* this is defined as a primitive to get defines from stc.h */ |
|
477 |
||
8913 | 478 |
RETURN ( __mkSmallInteger(FLOATARRAY) ); |
620 | 479 |
%} |
480 |
" |
|
12094 | 481 |
Behavior flagFloats |
620 | 482 |
" |
483 |
! |
|
484 |
||
1634 | 485 |
flagForSymbolic:aSymbol |
486 |
"return the flag code for indexed instances with aSymbolic type. |
|
12094 | 487 |
The argument may be one of |
488 |
#float, #double, |
|
489 |
#word, #signedWord, |
|
490 |
#long, #signedLong |
|
491 |
#longLong, #signedLongLong, |
|
492 |
#byte |
|
493 |
#weakObjects |
|
6104 | 494 |
For VW compatibility, also accept: |
12094 | 495 |
#objects, #bytes, #weak. |
6104 | 496 |
" |
1634 | 497 |
|
498 |
%{ /* NOCONTEXT */ |
|
499 |
if (aSymbol == @symbol(float)) { |
|
12094 | 500 |
RETURN ( __mkSmallInteger(FLOATARRAY) ); |
1634 | 501 |
} |
502 |
if (aSymbol == @symbol(double)) { |
|
12094 | 503 |
RETURN ( __mkSmallInteger(DOUBLEARRAY) ); |
1634 | 504 |
} |
505 |
if (aSymbol == @symbol(long)) { |
|
12094 | 506 |
RETURN ( __mkSmallInteger(LONGARRAY) ); |
1634 | 507 |
} |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
508 |
if (aSymbol == @symbol(longLong)) { |
12094 | 509 |
RETURN ( __mkSmallInteger(LONGLONGARRAY) ); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
510 |
} |
1634 | 511 |
if (aSymbol == @symbol(word)) { |
12094 | 512 |
RETURN ( __mkSmallInteger(WORDARRAY) ); |
1634 | 513 |
} |
514 |
if (aSymbol == @symbol(signedWord)) { |
|
12094 | 515 |
RETURN ( __mkSmallInteger(SWORDARRAY) ); |
1634 | 516 |
} |
517 |
if (aSymbol == @symbol(signedLong)) { |
|
12094 | 518 |
RETURN ( __mkSmallInteger(SLONGARRAY) ); |
1634 | 519 |
} |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
520 |
if (aSymbol == @symbol(signedLongLong)) { |
12094 | 521 |
RETURN ( __mkSmallInteger(SLONGLONGARRAY) ); |
6104 | 522 |
} |
523 |
if ((aSymbol == @symbol(byte)) || (aSymbol == @symbol(bytes))) { |
|
12094 | 524 |
RETURN ( __mkSmallInteger(BYTEARRAY) ); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
525 |
} |
6104 | 526 |
if (aSymbol == @symbol(objects)) { |
12094 | 527 |
RETURN ( __mkSmallInteger(POINTERARRAY) ); |
6104 | 528 |
} |
10605 | 529 |
if ((aSymbol == @symbol(weakObjects)) || (aSymbol == @symbol(weak))) { |
12094 | 530 |
RETURN ( __mkSmallInteger(WKPOINTERARRAY) ); |
1634 | 531 |
} |
532 |
%}. |
|
2666
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
533 |
^ 0 "/ not indexed |
10605 | 534 |
|
535 |
"Modified: / 07-06-2007 / 11:57:44 / cg" |
|
1634 | 536 |
! |
537 |
||
3141 | 538 |
flagJavaClass |
539 |
"return the flag code which marks JavaClass-like instances. |
|
540 |
The VM checks this single bit in the flag value when |
|
541 |
checking for a javaClass." |
|
542 |
||
543 |
%{ /* NOCONTEXT */ |
|
544 |
/* this is defined as a primitive to get defines from stc.h */ |
|
545 |
||
8913 | 546 |
RETURN ( __mkSmallInteger(JCLASS_INSTS) ); |
3141 | 547 |
%} |
548 |
! |
|
549 |
||
2801 | 550 |
flagJavaMethod |
551 |
"return the flag code which marks JavaMethod-like instances. |
|
7190 | 552 |
Inline C-code and the VM check this single bit in the flag value when |
2801 | 553 |
checking for a method." |
554 |
||
555 |
%{ /* NOCONTEXT */ |
|
556 |
/* this is defined as a primitive to get defines from stc.h */ |
|
557 |
||
8913 | 558 |
RETURN ( __mkSmallInteger(JMETHOD_INSTS) ); |
2801 | 559 |
%} |
560 |
! |
|
561 |
||
4307 | 562 |
flagLongLongs |
563 |
"return the flag code for longlong-valued indexed instances (i.e. 8-byte). |
|
12094 | 564 |
The VM masks the flag value with the indexMask (maskIndexType) |
565 |
and compares it to this flag value, when checking for |
|
4307 | 566 |
unsigned long valued variable instances." |
567 |
||
568 |
%{ /* NOCONTEXT */ |
|
569 |
/* this is defined as a primitive to get defines from stc.h */ |
|
570 |
||
8913 | 571 |
RETURN ( __mkSmallInteger(LONGLONGARRAY) ); |
4307 | 572 |
%} |
573 |
" |
|
12094 | 574 |
Behavior flagLongLongs |
4307 | 575 |
" |
576 |
! |
|
577 |
||
620 | 578 |
flagLongs |
579 |
"return the flag code for long-valued indexed instances (i.e. 4-byte). |
|
12094 | 580 |
The VM masks the flag value with the indexMask (maskIndexType) |
581 |
and compares it to this flag value, when checking for |
|
2226 | 582 |
unsigned long valued variable instances." |
620 | 583 |
|
584 |
%{ /* NOCONTEXT */ |
|
585 |
/* this is defined as a primitive to get defines from stc.h */ |
|
586 |
||
8913 | 587 |
RETURN ( __mkSmallInteger(LONGARRAY) ); |
620 | 588 |
%} |
589 |
" |
|
12094 | 590 |
Behavior flagLongs |
620 | 591 |
" |
592 |
! |
|
593 |
||
5743 | 594 |
flagMetaMethod |
595 |
"return the flag code which marks MetaMethod-like instances. |
|
7190 | 596 |
Inline C-code and the VM check this single bit in the flag value when |
5743 | 597 |
about to evaluate a method." |
598 |
||
599 |
%{ /* NOCONTEXT */ |
|
600 |
/* this is defined as a primitive to get defines from stc.h */ |
|
601 |
||
8913 | 602 |
RETURN ( __mkSmallInteger(METAMETHOD_INSTS) ); |
5743 | 603 |
%} |
604 |
! |
|
605 |
||
620 | 606 |
flagMethod |
607 |
"return the flag code which marks Method-like instances. |
|
7190 | 608 |
Inline C-code and the VM check this single bit in the flag value when |
2226 | 609 |
checking for a method." |
620 | 610 |
|
611 |
%{ /* NOCONTEXT */ |
|
612 |
/* this is defined as a primitive to get defines from stc.h */ |
|
613 |
||
8913 | 614 |
RETURN ( __mkSmallInteger(METHOD_INSTS) ); |
620 | 615 |
%} |
616 |
! |
|
617 |
||
618 |
flagNonObjectInst |
|
619 |
"return the flag code which marks instances which have a |
|
620 |
non-object instance variable (in slot 1). |
|
621 |
(these are ignored by the garbage collector)" |
|
622 |
||
623 |
%{ /* NOCONTEXT */ |
|
624 |
/* this is defined as a primitive to get defines from stc.h */ |
|
625 |
||
8913 | 626 |
RETURN ( __mkSmallInteger(NONOBJECT_INSTS) ); |
620 | 627 |
%} |
628 |
! |
|
629 |
||
630 |
flagNotIndexed |
|
631 |
"return the flag code for non-indexed instances. |
|
632 |
You have to mask the flag value with indexMask when comparing |
|
633 |
it with flagNotIndexed." |
|
634 |
||
635 |
^ 0 |
|
636 |
! |
|
637 |
||
638 |
flagPointers |
|
639 |
"return the flag code for pointer indexed instances (i.e. Array of object). |
|
12094 | 640 |
The VM masks the flag value with the indexMask (maskIndexType) |
641 |
and compares it to this flag value, when checking for |
|
2226 | 642 |
pointer variable instances." |
620 | 643 |
|
644 |
%{ /* NOCONTEXT */ |
|
645 |
/* this is defined as a primitive to get defines from stc.h */ |
|
646 |
||
8913 | 647 |
RETURN ( __mkSmallInteger(POINTERARRAY) ); |
620 | 648 |
%} |
649 |
" |
|
12094 | 650 |
Behavior flagPointers |
620 | 651 |
" |
652 |
! |
|
653 |
||
1383 | 654 |
flagRegular |
655 |
"return the flag code which marks regular instances." |
|
656 |
||
657 |
^ 0 |
|
658 |
||
659 |
"Created: 12.5.1996 / 17:53:36 / cg" |
|
660 |
! |
|
661 |
||
4307 | 662 |
flagSignedLongLongs |
663 |
"return the flag code for signed longlong-valued indexed instances (i.e. 8-byte). |
|
12094 | 664 |
The VM masks the flag value with the indexMask (maskIndexType) |
665 |
and compares it to this flag value, when checking for |
|
4307 | 666 |
signed long valued variable instances." |
667 |
||
668 |
%{ /* NOCONTEXT */ |
|
669 |
/* this is defined as a primitive to get defines from stc.h */ |
|
670 |
||
8913 | 671 |
RETURN ( __mkSmallInteger(SLONGLONGARRAY) ); |
4307 | 672 |
%} |
673 |
" |
|
674 |
Behavior flagSignedLongLongs |
|
675 |
" |
|
676 |
! |
|
677 |
||
1634 | 678 |
flagSignedLongs |
679 |
"return the flag code for signed long-valued indexed instances (i.e. 4-byte). |
|
12094 | 680 |
The VM masks the flag value with the indexMask (maskIndexType) |
681 |
and compares it to this flag value, when checking for |
|
2226 | 682 |
signed long valued variable instances." |
1634 | 683 |
|
684 |
%{ /* NOCONTEXT */ |
|
685 |
/* this is defined as a primitive to get defines from stc.h */ |
|
686 |
||
8913 | 687 |
RETURN ( __mkSmallInteger(SLONGARRAY) ); |
1634 | 688 |
%} |
689 |
" |
|
690 |
Behavior flagSignedLongs |
|
691 |
" |
|
692 |
! |
|
693 |
||
694 |
flagSignedWords |
|
695 |
"return the flag code for signed word-valued indexed instances (i.e. 2-byte). |
|
12094 | 696 |
The VM masks the flag value with the indexMask (maskIndexType) |
697 |
and compares it to this flag value, when checking for |
|
2226 | 698 |
signed word valued variable instances." |
1634 | 699 |
|
700 |
%{ /* NOCONTEXT */ |
|
701 |
/* this is defined as a primitive to get defines from stc.h */ |
|
702 |
||
8913 | 703 |
RETURN ( __mkSmallInteger(SWORDARRAY) ); |
1634 | 704 |
%} |
705 |
" |
|
706 |
Behavior flagSignedWords |
|
707 |
" |
|
708 |
! |
|
709 |
||
620 | 710 |
flagSymbol |
711 |
"return the flag code which marks Symbol-like instances. |
|
7190 | 712 |
Inline C-code and the VM check this single bit in the flag value when |
620 | 713 |
checking for symbols." |
714 |
||
715 |
%{ /* NOCONTEXT */ |
|
716 |
/* this is defined as a primitive to get defines from stc.h */ |
|
717 |
||
8913 | 718 |
RETURN ( __mkSmallInteger(SYMBOL_INSTS) ); |
620 | 719 |
%} |
720 |
! |
|
721 |
||
10605 | 722 |
flagWeak |
723 |
"return the flag code for weak-object-pointer indexed instances. |
|
12094 | 724 |
The VM masks the flag value with the indexMask (maskIndexType) |
725 |
and compares it to this flag value, when checking for |
|
10605 | 726 |
weak pointer variable instances." |
727 |
||
728 |
%{ /* NOCONTEXT */ |
|
729 |
/* this is defined as a primitive to get defines from stc.h */ |
|
730 |
||
731 |
RETURN ( __mkSmallInteger(WKPOINTERARRAY) ); |
|
732 |
%} |
|
733 |
" |
|
12094 | 734 |
Behavior flagWeak |
10605 | 735 |
" |
736 |
||
737 |
"Created: / 07-06-2007 / 11:59:12 / cg" |
|
738 |
! |
|
739 |
||
620 | 740 |
flagWeakPointers |
741 |
"return the flag code for weak pointer indexed instances (i.e. WeakArray). |
|
12094 | 742 |
The VM masks the flag value with the indexMask (maskIndexType) |
2226 | 743 |
and compares it to this flag value, when checking for weak pointers." |
620 | 744 |
|
745 |
%{ /* NOCONTEXT */ |
|
746 |
/* this is defined as a primitive to get defines from stc.h */ |
|
747 |
||
8913 | 748 |
RETURN ( __mkSmallInteger(WKPOINTERARRAY) ); |
620 | 749 |
%} |
750 |
! |
|
751 |
||
752 |
flagWords |
|
753 |
"return the flag code for word-valued indexed instances (i.e. 2-byte). |
|
12094 | 754 |
The VM masks the flag value with the indexMask (maskIndexType) |
755 |
and compares it to this flag value, when checking for |
|
2226 | 756 |
unsigned word valued variable instances." |
620 | 757 |
|
758 |
%{ /* NOCONTEXT */ |
|
759 |
/* this is defined as a primitive to get defines from stc.h */ |
|
760 |
||
8913 | 761 |
RETURN ( __mkSmallInteger(WORDARRAY) ); |
620 | 762 |
%} |
763 |
" |
|
12094 | 764 |
Behavior flagWords |
620 | 765 |
" |
766 |
! |
|
767 |
||
768 |
maskIndexType |
|
769 |
"return a mask to extract all index-type bits" |
|
770 |
||
771 |
%{ /* NOCONTEXT */ |
|
772 |
/* this is defined as a primitive to get defines from stc.h */ |
|
773 |
||
8913 | 774 |
RETURN ( __mkSmallInteger(ARRAYMASK) ); |
620 | 775 |
%} |
776 |
! ! |
|
777 |
||
8962 | 778 |
!Behavior class methodsFor:'helpers'! |
779 |
||
9849 | 780 |
classesSortedByLoadOrder:someClasses |
781 |
"return a copy of the given collection of classes, which is sorted |
|
782 |
by inheritance and superclass-of-any-private class. |
|
783 |
This is the optimal order for loading, and the required order for compilation" |
|
784 |
||
785 |
|remaining classesInLoadOrder| |
|
786 |
||
10008
85b80de0562a
fix private class dependency handling in #classesSortedByLoadOrder:
Stefan Vogel <sv@exept.de>
parents:
9849
diff
changeset
|
787 |
"private classes are not loaded directly, so ignore them" |
10866
49e2ad93cb32
#classesSortedByLoadOrder: - use IdentitySet
Stefan Vogel <sv@exept.de>
parents:
10854
diff
changeset
|
788 |
remaining := someClasses asIdentitySet reject:[:eachClass| eachClass isPrivate]. |
10008
85b80de0562a
fix private class dependency handling in #classesSortedByLoadOrder:
Stefan Vogel <sv@exept.de>
parents:
9849
diff
changeset
|
789 |
classesInLoadOrder := OrderedCollection new:(remaining size). |
85b80de0562a
fix private class dependency handling in #classesSortedByLoadOrder:
Stefan Vogel <sv@exept.de>
parents:
9849
diff
changeset
|
790 |
|
9849 | 791 |
[remaining notEmpty] whileTrue:[ |
12094 | 792 |
|thoseWithOtherSuperclasses thoseWhichCanBeLoadedNow| |
793 |
||
794 |
"find the next class(es) to be loaded. |
|
795 |
Consider first: |
|
796 |
all those, which do not have a superclass in the remaining set. |
|
797 |
and which do not use a shared pool defined in the remaining set" |
|
798 |
||
799 |
thoseWithOtherSuperclasses := |
|
800 |
remaining |
|
801 |
reject:[:eachClass | |
|
802 |
(remaining includes:eachClass superclass) |
|
803 |
or:[eachClass sharedPools contains:[:eachPoolSymbol| |
|
804 |
remaining contains:[:eachRemainingClass| eachPoolSymbol = eachRemainingClass name] |
|
805 |
] |
|
806 |
]. |
|
807 |
]. |
|
808 |
||
809 |
"second: the subset with all those having no private classes, |
|
810 |
or having private classes, whose superclasses are NOT in the remaining set" |
|
811 |
||
812 |
thoseWhichCanBeLoadedNow := |
|
813 |
thoseWithOtherSuperclasses |
|
814 |
reject:[:eachClass | |
|
815 |
eachClass allPrivateClasses contains:[:eachPrivateClass| |superClassesOwner| |
|
816 |
superClassesOwner := eachPrivateClass superclass. |
|
817 |
"take care of classes inheriting from nil or ProtoObject" |
|
818 |
superClassesOwner isBehavior ifTrue:[ |
|
819 |
superClassesOwner := superClassesOwner owningClassOrYourself. |
|
820 |
]. |
|
821 |
superClassesOwner ~~ eachClass |
|
822 |
and:[remaining includes:superClassesOwner] |
|
823 |
]. |
|
824 |
]. |
|
825 |
||
826 |
thoseWhichCanBeLoadedNow isEmpty ifTrue:[ |
|
827 |
thoseWithOtherSuperclasses isEmpty ifTrue:[ |
|
828 |
"this does not normally happen" |
|
829 |
self error:'superclass order is cyclic'. |
|
830 |
] ifFalse:[ |
|
831 |
"no class found, that may be loaded - maybe there is a cyclic |
|
832 |
dependency involving private classes. |
|
833 |
If you proceed here, private class dependencies are ignored |
|
834 |
for this pass" |
|
835 |
self error:'load order is cyclic (care for private classes)' mayProceed:true. |
|
836 |
thoseWhichCanBeLoadedNow := thoseWithOtherSuperclasses. |
|
837 |
]. |
|
838 |
]. |
|
839 |
remaining removeAllFoundIn:thoseWhichCanBeLoadedNow. |
|
840 |
classesInLoadOrder addAll:(thoseWhichCanBeLoadedNow asArray sort:[:a :b | a name < b name]). |
|
9849 | 841 |
]. |
842 |
^ classesInLoadOrder |
|
843 |
||
844 |
" |
|
12094 | 845 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libbasic') |
846 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libbasic3') |
|
847 |
Class classesSortedByLoadOrder:(Smalltalk allClassesInPackage:'stx:libwidg') |
|
9849 | 848 |
" |
849 |
||
850 |
"Created: / 14-09-2006 / 11:21:25 / cg" |
|
851 |
! |
|
852 |
||
8962 | 853 |
commonSuperclassOf:listOfClassesOrClassNames |
11984 | 854 |
"given a list of classes, return the common superclass. |
855 |
A helper for the browser, some dialogs and some refactorings" |
|
856 |
||
8962 | 857 |
|common| |
858 |
||
859 |
listOfClassesOrClassNames do:[:classOrClassName | |
|
12094 | 860 |
|class| |
861 |
||
862 |
class := classOrClassName isBehavior |
|
863 |
ifTrue:[classOrClassName] |
|
864 |
ifFalse:[Smalltalk classNamed:classOrClassName]. |
|
865 |
||
866 |
common isNil ifTrue:[ |
|
867 |
common := class |
|
868 |
] ifFalse:[ |
|
869 |
(class isSubclassOf:common) ifTrue:[ |
|
870 |
"keep common" |
|
871 |
] ifFalse:[ |
|
872 |
(common isSubclassOf:class) ifTrue:[ |
|
873 |
common := class |
|
874 |
] ifFalse:[ |
|
875 |
common := common commonSuperclass:class. |
|
8962 | 876 |
|
877 |
"/ "walk up, checking" |
|
878 |
"/ found := false. |
|
879 |
"/ |
|
880 |
"/ common allSuperclassesDo:[:sup | |
|
881 |
"/ (found not and:[class isSubclassOf:sup]) ifTrue:[ |
|
882 |
"/ common := sup. |
|
883 |
"/ found := true. |
|
884 |
"/ ] |
|
885 |
"/ ]. |
|
886 |
"/ found ifFalse:[ |
|
887 |
"/ class allSuperclassesDo:[:sup | |
|
888 |
"/ (found not and:[common isSubclassOf:sup]) ifTrue:[ |
|
889 |
"/ common := sup. |
|
890 |
"/ found := true. |
|
891 |
"/ ] |
|
892 |
"/ ]. |
|
893 |
"/ ]. |
|
12094 | 894 |
] |
895 |
]. |
|
896 |
]. |
|
897 |
(common isNil or:[common == Object]) ifTrue:[^ common]. |
|
8962 | 898 |
]. |
899 |
^ common |
|
900 |
||
11984 | 901 |
" |
902 |
Class commonSuperclassOf:#(Array OrderedCollection Set) |
|
903 |
Class commonSuperclassOf:#(Character Number Point) |
|
904 |
" |
|
905 |
||
8962 | 906 |
"Modified: 17.6.1996 / 17:09:21 / stefan" |
907 |
"Modified: 5.9.1996 / 19:34:41 / cg" |
|
908 |
! ! |
|
909 |
||
4964 | 910 |
!Behavior class methodsFor:'misc'! |
911 |
||
912 |
autoload |
|
913 |
"for compatibility with autoloaded classes - dummy here" |
|
914 |
||
915 |
^ self |
|
916 |
||
917 |
! ! |
|
918 |
||
1760 | 919 |
!Behavior class methodsFor:'queries'! |
620 | 920 |
|
4332
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
921 |
definitionSelectorFirstParts |
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
922 |
"return a collection of partial class-definition selectors" |
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
923 |
|
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
924 |
^ #( #'subclass:' |
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
925 |
#'variableSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
926 |
#'variableByteSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
927 |
#'variableWordSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
928 |
#'variableLongSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
929 |
#'variableSignedWordSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
930 |
#'variableSignedLongSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
931 |
#'variableLongLongSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
932 |
#'variableSignedLongLongSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
933 |
#'variableFloatSubclass:' |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
934 |
#'variableDoubleSubclass:' |
12094 | 935 |
) |
4332
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
936 |
! |
c672bf261fbd
added query for class-def selectors.
Claus Gittinger <cg@exept.de>
parents:
4307
diff
changeset
|
937 |
|
4428 | 938 |
definitionSelectors |
939 |
"return a collection class-definition selectors" |
|
940 |
||
12094 | 941 |
^ #( |
12113
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
942 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
943 |
#'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
944 |
#'variableByteSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
945 |
#'variableWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
946 |
#'variableLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
947 |
#'variableSignedWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
948 |
#'variableSignedLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
949 |
#'variableLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
950 |
#'variableSignedLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
951 |
#'variableFloatSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
952 |
#'variableDoubleSubclass:instanceVariableNames:classVariableNames:poolDictionaries:category:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
953 |
|
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
954 |
"/ ST/X private subclasses |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
955 |
|
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
956 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
957 |
#'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
958 |
#'variableByteSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
959 |
#'variableWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
960 |
#'variableLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
961 |
#'variableSignedWordSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
962 |
#'variableSignedLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
963 |
#'variableLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
964 |
#'variableSignedLongLongSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
965 |
#'variableFloatSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
966 |
#'variableDoubleSubclass:instanceVariableNames:classVariableNames:poolDictionaries:privateIn:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
967 |
|
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
968 |
"/ ST/V subclass messages |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
969 |
|
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
970 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
971 |
#'variableByteSubclass:classVariableNames:poolDictionaries:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
972 |
#'variableSubclass:instanceVariableNames:classVariableNames:poolDictionaries:' |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
973 |
|
12114
53048e0b6bf7
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12113
diff
changeset
|
974 |
"/ Dolphin |
12113
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
975 |
#'subclass:instanceVariableNames:classVariableNames:poolDictionaries:classInstanceVariableNames:' |
12094 | 976 |
) |
9194 | 977 |
! |
978 |
||
979 |
isBuiltInClass |
|
980 |
"return true if this class is known by the run-time-system. |
|
981 |
Here, true is returned for myself, false for subclasses." |
|
982 |
||
983 |
^ (self == Behavior class) or:[self == Behavior] |
|
984 |
||
985 |
"Modified: 23.4.1996 / 15:55:52 / cg" |
|
986 |
! ! |
|
987 |
||
988 |
!Behavior methodsFor:'Camp Smalltalk'! |
|
989 |
||
990 |
sunitAllSelectors |
|
991 |
^self allSelectors asSortedCollection asOrderedCollection |
|
992 |
! |
|
8531
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
993 |
|
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
994 |
sunitSelectors |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
995 |
^self selectors asSortedCollection asOrderedCollection |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
996 |
|
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
997 |
"Created: / 20.6.2000 / 11:54:54 / Sames" |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
998 |
! ! |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
999 |
|
7269 | 1000 |
!Behavior methodsFor:'Compatibility-Dolphin'! |
6329 | 1001 |
|
1002 |
allSubinstances |
|
11953 | 1003 |
"Compatibility method - do not use in new code. |
1004 |
Same as allSubInstances; added for Dolphin compatibility" |
|
1005 |
||
6865 | 1006 |
^ self allSubInstances |
1007 |
! |
|
1008 |
||
6889
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1009 |
fromString:aString |
11953 | 1010 |
"reconstruct an instance of myself from the ascii-store string. |
1011 |
These bytes are typically the result from storing into a string/stream. |
|
1012 |
Same as readFrom:, for Dolphin compatibility." |
|
1013 |
||
6889
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1014 |
^ self readFrom:aString |
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1015 |
! |
7efa6d375ef7
+fromBinaryStoreBytes; +fromString.
Claus Gittinger <cg@exept.de>
parents:
6865
diff
changeset
|
1016 |
|
6865 | 1017 |
guid:aUUID |
11953 | 1018 |
"Compatibility method - do not use in new code. |
1019 |
An ignored dummy; for Dolphin compatibility." |
|
1020 |
||
1021 |
"/ intentionally left blank - for now |
|
11158 | 1022 |
! |
1023 |
||
1024 |
lookupMethod:selector |
|
11953 | 1025 |
"Compatibility method - do not use in new code. |
1026 |
Return the method for given selector aSelector or nil. |
|
1027 |
Only methods in the receiver - not in the superclass chain are returned. |
|
1028 |
For dolphin compatibility. |
|
1029 |
TODO: fixme if I am wrong, and dolphin does a full lookup here. If that is the case, |
|
1030 |
change to use lookupMethodFor:aSelector below." |
|
1031 |
||
11158 | 1032 |
^ self compiledMethodAt:selector |
6329 | 1033 |
! ! |
1034 |
||
7269 | 1035 |
!Behavior methodsFor:'Compatibility-Squeak'! |
4889 | 1036 |
|
9194 | 1037 |
defaultNameStemForInstances |
1038 |
"Answer a basis for names of default instances of the receiver" |
|
1039 |
||
1040 |
^ self name |
|
1041 |
||
1042 |
! |
|
5753
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1043 |
|
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1044 |
lookupSelector:aSelector |
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1045 |
"return the method for a selector - Squeak compatibility" |
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1046 |
|
65cce9486ee9
added #lookupSelector: for Squeak compatibility
Claus Gittinger <cg@exept.de>
parents:
5743
diff
changeset
|
1047 |
^ self lookupMethodFor:aSelector |
6147 | 1048 |
! |
1049 |
||
12094 | 1050 |
selectorsWithArgs:numberOfArgs |
6147 | 1051 |
"Return all selectors defined in this class that take this number of arguments." |
1052 |
||
12094 | 1053 |
^ self selectors |
1054 |
select:[:sel | sel numArgs == numberOfArgs] |
|
6147 | 1055 |
|
1056 |
" |
|
12094 | 1057 |
SmallInteger selectorsWithArgs:0 |
1058 |
SmallInteger selectorsWithArgs:2 |
|
6147 | 1059 |
SmallInteger selectorsWithArgs:3 |
12094 | 1060 |
SmallInteger selectorsWithArgs:4 |
6147 | 1061 |
" |
4889 | 1062 |
! ! |
1063 |
||
7269 | 1064 |
!Behavior methodsFor:'Compatibility-VW'! |
5964 | 1065 |
|
1066 |
>> aSelector |
|
1067 |
"return the method stored under the given selector; nil if there is none" |
|
1068 |
||
1069 |
^ self compiledMethodAt:aSelector |
|
1070 |
||
1071 |
" |
|
1072 |
self compiledMethodAt:#compiledMethodAt: |
|
1073 |
self >> #compiledMethodAt: |
|
1074 |
" |
|
6115 | 1075 |
! |
1076 |
||
1077 |
fixedFieldsMask |
|
1078 |
"Mask on the format word to indicate the number of fixed fields in instances |
|
1079 |
of a behavior. If this is non-zero, the behavior must be pointer-type" |
|
1080 |
||
1081 |
^ 255 |
|
1082 |
||
1083 |
! |
|
1084 |
||
1085 |
format |
|
1086 |
"Answer an Integer that encodes the kinds and numbers of |
|
1087 |
variables of instances of the receiver. |
|
1088 |
||
1089 |
See instSize method for reference to the fixedFieldsMask bit mask of the format. |
|
1090 |
See isVariable method for reference to the indexableMask bit mask of the format. |
|
1091 |
See isBits method for reference to the pointersMask bit mask of the format. |
|
1092 |
All other bits of the format are unused and should be 0." |
|
1093 |
||
1094 |
"/ simulate a VW5i mask |
|
1095 |
||
1096 |
^ (self instSize |
|
1097 |
bitOr:( self isPointers ifTrue:[16384] ifFalse:[0])) |
|
1098 |
bitOr:( self isVariable ifTrue:[ 4096] ifFalse:[0]) |
|
1099 |
||
1100 |
! |
|
1101 |
||
10085 | 1102 |
getMethodDictionary |
1103 |
"ST 80 compatibility: return the receivers method dictionary." |
|
1104 |
||
1105 |
^ self methodDictionary |
|
1106 |
||
1107 |
"Modified: / 6.3.1998 / 15:45:50 / stefan" |
|
1108 |
! |
|
1109 |
||
6115 | 1110 |
instanceBehavior |
12094 | 1111 |
"Answer the instance behavior of the receiver. |
1112 |
This is the receiver for non metaclasses. |
|
6115 | 1113 |
Metaclass overrides this to answer a Metaclass's sole instance. |
1114 |
Same as #theNonMetaclass - for VW compatibility |
|
1115 |
" |
|
1116 |
||
1117 |
^ self theNonMetaclass |
|
1118 |
||
6968 | 1119 |
! |
1120 |
||
1121 |
shortName |
|
1122 |
^ self nameWithoutPrefix |
|
5964 | 1123 |
! ! |
1124 |
||
9196
a6d45629bb3b
readFromString allows for whiteSpace after reading
Claus Gittinger <cg@exept.de>
parents:
9194
diff
changeset
|
1125 |
|
620 | 1126 |
!Behavior methodsFor:'accessing'! |
1127 |
||
1128 |
addSelector:newSelector withMethod:newMethod |
|
1129 |
"add the method given by 2nd argument under the selector given by |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1130 |
1st argument to the methodDictionary. Flushes all caches." |
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1131 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1132 |
|oldMethod| |
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1133 |
|
7800 | 1134 |
(newSelector isMemberOf:Symbol) ifFalse:[ |
12094 | 1135 |
self error:'invalid selector'. |
7800 | 1136 |
]. |
8865
1f4824500318
#addSelectorWithMethod no longer returns a boolean
Stefan Vogel <sv@exept.de>
parents:
8857
diff
changeset
|
1137 |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1138 |
oldMethod := self compiledMethodAt:newSelector. |
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1139 |
oldMethod notNil ifTrue:[ |
12094 | 1140 |
newMethod restricted:(oldMethod isRestricted). |
1141 |
newMethod setPrivacy:(oldMethod privacy) flushCaches:false. |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1142 |
]. |
11578 | 1143 |
|
1144 |
(self primAddSelector:newSelector withMethod:newMethod) ifFalse:[^ false]. |
|
734
a4378f483a86
pass original method as changeArg when doing method changes;
Claus Gittinger <cg@exept.de>
parents:
662
diff
changeset
|
1145 |
|
620 | 1146 |
" |
1147 |
if I have no subclasses, all we have to flush is cached |
|
1148 |
data for myself ... (actually, in any case all that needs |
|
1149 |
to be flushed is info for myself and all of my subclasses) |
|
1150 |
" |
|
1151 |
" |
|
1152 |
problem: this is slower; since looking for all subclasses is (currently) |
|
12094 | 1153 |
a bit slow :-( |
1154 |
We need the hasSubclasses-info bit in Behavior; now |
|
620 | 1155 |
|
1156 |
self withAllSubclassesDo:[:aClass | |
|
12094 | 1157 |
ObjectMemory flushInlineCachesFor:aClass withArgs:nargs. |
1158 |
ObjectMemory flushMethodCacheFor:aClass |
|
620 | 1159 |
]. |
1160 |
" |
|
1161 |
||
3805
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1162 |
"/ |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1163 |
"/ pass the selector AND the old method as changeArg |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1164 |
"/ - this allows for watchers to find out if its a new method or a method-change |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1165 |
"/ |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1166 |
self changed:#methodDictionary with:(Array with:newSelector with:oldMethod). |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1167 |
|
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1168 |
"/ |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1169 |
"/ also notify a change of Smalltalk; |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1170 |
"/ this allows a dependent of Smalltalk to watch all class |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1171 |
"/ changes (no need for observing all classes) |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1172 |
"/ - this allows for watchers to find out if its a new method or a method-change |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1173 |
"/ |
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1174 |
Smalltalk changed:#methodInClass with:(Array with:self with:newSelector with:oldMethod). |
11574 | 1175 |
^ true. |
3805
d525b3acc091
flush cache first in addMethod - then do a change notification
Claus Gittinger <cg@exept.de>
parents:
3641
diff
changeset
|
1176 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1177 |
"Created: / 11-12-1995 / 13:59:37 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
1178 |
"Modified: / 04-08-2006 / 11:39:28 / cg" |
620 | 1179 |
! |
1180 |
||
9445 | 1181 |
basicAddSelector:newSelector withMethod:newMethod |
1182 |
"add the method given by 2nd argument under the selector given by |
|
1183 |
1st argument to the methodDictionary. Flushes all caches." |
|
1184 |
||
1185 |
|nargs | |
|
1186 |
||
1187 |
self primAddSelector:newSelector withMethod:newMethod. |
|
1188 |
||
1189 |
nargs := newSelector numArgs. |
|
1190 |
||
1191 |
ObjectMemory flushMethodCacheForSelector:newSelector. |
|
1192 |
"/ ObjectMemory flushMethodCache. |
|
1193 |
ObjectMemory flushInlineCachesWithArgs:nargs. |
|
1194 |
ObjectMemory flushCachesForSelector:newSelector |
|
1195 |
||
1196 |
"Created: / 15-07-2006 / 16:56:43 / cg" |
|
1197 |
! |
|
1198 |
||
10535 | 1199 |
basicRemoveSelector:aSelector |
12094 | 1200 |
"remove the selector, aSelector and its associated method |
10535 | 1201 |
from the methodDictionary" |
1202 |
||
1203 |
|dict newDict| |
|
1204 |
||
12094 | 1205 |
(Smalltalk |
1206 |
changeRequest:#methodInClassRemoved |
|
1207 |
with:(Array with:self with:aSelector)) ifFalse:[ |
|
1208 |
^ false |
|
11578 | 1209 |
]. |
1210 |
||
10535 | 1211 |
dict := self methodDictionary. |
1212 |
newDict := dict removeKeyAndCompress:aSelector. |
|
12094 | 1213 |
newDict isNil ifTrue:[ |
1214 |
^ false. |
|
10535 | 1215 |
]. |
1216 |
self setMethodDictionary:newDict. |
|
1217 |
||
1218 |
" |
|
1219 |
actually, we would do better with less flushing ... |
|
1220 |
" |
|
1221 |
"/ObjectMemory flushCaches. |
|
1222 |
||
1223 |
"yes, we can:" |
|
1224 |
ObjectMemory flushCachesForSelector:aSelector. |
|
1225 |
^ true |
|
1226 |
||
1227 |
"Modified: 12.6.1996 / 11:54:29 / stefan" |
|
1228 |
! |
|
1229 |
||
620 | 1230 |
flags |
1231 |
"return the receivers flag bits" |
|
1232 |
||
1233 |
^ flags |
|
1234 |
! |
|
1235 |
||
1236 |
instSize |
|
1237 |
"return the number of instance variables of the receiver. |
|
1238 |
This includes all superclass instance variables." |
|
1239 |
||
1240 |
^ instSize |
|
1241 |
! |
|
1242 |
||
1243 |
methodDictionary |
|
1634 | 1244 |
"return the receivers method dictionary." |
620 | 1245 |
|
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
1246 |
^ methodDictionary |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1247 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1248 |
"Modified: 12.6.1996 / 13:47:08 / stefan" |
1634 | 1249 |
"Modified: 16.8.1996 / 14:55:21 / cg" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1250 |
! |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1251 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1252 |
methodDictionary:dict |
12094 | 1253 |
"set the receivers method dictionary and flush inline caches." |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1254 |
|
1814 | 1255 |
dict isNil ifTrue:[ |
12094 | 1256 |
self error:'attempt to set methodDictionary to nil.' mayProceed:true. |
1257 |
^ self |
|
1814 | 1258 |
]. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1259 |
self setMethodDictionary:dict. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1260 |
ObjectMemory flushCaches. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1261 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1262 |
"Created: 5.6.1996 / 11:29:36 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1263 |
"Modified: 7.6.1996 / 08:39:51 / stefan" |
620 | 1264 |
! |
1265 |
||
7605
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1266 |
package |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1267 |
"for protocol compatibility with class" |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1268 |
|
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1269 |
^ '' |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1270 |
! |
945a2cd8115c
moved some stuff from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7435
diff
changeset
|
1271 |
|
620 | 1272 |
removeSelector:aSelector |
12094 | 1273 |
"remove the selector, aSelector and its associated method |
620 | 1274 |
from the methodDictionary" |
1275 |
||
10535 | 1276 |
^ self basicRemoveSelector:aSelector |
620 | 1277 |
! |
1278 |
||
1279 |
selectors |
|
1280 |
"return the receivers selector array as an orderedCollection. |
|
1281 |
Notice: this may not be compatible with ST-80. |
|
1282 |
(should we return a Set ?)" |
|
1283 |
||
1814 | 1284 |
|md| |
1285 |
||
1967
e8a6fb1e14ce
oops - iNil instead of isNil
Claus Gittinger <cg@exept.de>
parents:
1918
diff
changeset
|
1286 |
(md := self methodDictionary) isNil ifTrue:[ |
2666
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
1287 |
'oops - nil methodDictionary' errorPrintCR. |
7981b615b48a
Make Metaclass a subclass of ClassDescription instead of Class.
Stefan Vogel <sv@exept.de>
parents:
2569
diff
changeset
|
1288 |
^ #() |
1814 | 1289 |
]. |
1290 |
^ md keys |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1291 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
1292 |
"Modified: 7.6.1996 / 15:33:18 / stefan" |
1967
e8a6fb1e14ce
oops - iNil instead of isNil
Claus Gittinger <cg@exept.de>
parents:
1918
diff
changeset
|
1293 |
"Modified: 12.11.1996 / 11:31:51 / cg" |
620 | 1294 |
! |
1295 |
||
1296 |
superclass |
|
1297 |
"return the receivers superclass" |
|
1298 |
||
1299 |
^ superclass |
|
1300 |
! |
|
1301 |
||
1302 |
superclass:aClass |
|
1303 |
"set the superclass - this actually creates a new class, |
|
1304 |
recompiling all methods for the new one. The receiving class stays |
|
1305 |
around anonymous to allow existing instances some life. |
|
1306 |
This may change in the future (adjusting existing instances)" |
|
1307 |
||
2054
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1308 |
|owner ns name| |
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1309 |
|
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
1310 |
Class flushSubclassInfo. |
620 | 1311 |
|
1312 |
"must flush caches since lookup chain changes" |
|
1313 |
ObjectMemory flushCaches. |
|
1314 |
||
2054
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1315 |
"/ for correct recompilation, just create a new class ... |
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1316 |
"/ but care to avoid a nameSpace change, by giving my |
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1317 |
"/ full name and answering with Smalltalk to a nameSpace query. |
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1318 |
|
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1319 |
(owner := self owningClass) notNil ifTrue:[ |
12094 | 1320 |
ns := owner. |
1321 |
name := self nameWithoutPrefix asSymbol |
|
2054
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1322 |
] ifFalse:[ |
12094 | 1323 |
ns := Smalltalk. |
1324 |
name := self name |
|
2054
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1325 |
]. |
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1326 |
|
8838
81ee56a49ac3
Rename #xxxRedefinitionSignal to #xxxRedefinitionNotification.
Stefan Vogel <sv@exept.de>
parents:
8725
diff
changeset
|
1327 |
Class classRedefinitionNotification answer:#keep do:[ |
12094 | 1328 |
Class nameSpaceQuerySignal answer:ns |
1329 |
do:[ |
|
1330 |
aClass |
|
1331 |
perform:(self definitionSelector) |
|
1332 |
withArguments:(Array with:name |
|
1333 |
with:(self instanceVariableString) |
|
1334 |
with:(self classVariableString) |
|
1335 |
with:'' "/ pool |
|
1336 |
with:(self category)). |
|
1337 |
] |
|
2054
1601ad49cf59
care for nameSpace and owning class when changing the superClass.
Claus Gittinger <cg@exept.de>
parents:
2053
diff
changeset
|
1338 |
] |
2436 | 1339 |
|
3628
5b58b3b8644a
auto-keep package - when changing superclass
Claus Gittinger <cg@exept.de>
parents:
3623
diff
changeset
|
1340 |
"Modified: / 20.6.1998 / 18:17:37 / cg" |
620 | 1341 |
! ! |
1342 |
||
1343 |
!Behavior methodsFor:'autoload check'! |
|
1344 |
||
1345 |
autoload |
|
12094 | 1346 |
"force autoloading - do nothing here; |
620 | 1347 |
redefined in Autoload; see comment there" |
1348 |
||
1349 |
^ self |
|
1350 |
! |
|
1351 |
||
1352 |
isLoaded |
|
12094 | 1353 |
"return true, if the class has been loaded; |
620 | 1354 |
redefined in Autoload; see comment there" |
1355 |
||
1356 |
^ true |
|
6727 | 1357 |
! |
1358 |
||
1359 |
wasAutoloaded |
|
1360 |
"return true, if this class came into the system via an |
|
1361 |
autoload; false otherwise. |
|
1362 |
Returning false here. This allows different Behavior-like objects |
|
1363 |
(alien classes) to be handled by the browser as well." |
|
1364 |
||
1365 |
^ false |
|
1366 |
||
1367 |
"Created: 16.4.1996 / 16:27:16 / cg" |
|
620 | 1368 |
! ! |
1369 |
||
11160
4a413380f57c
support for dolphin binary storage format
Claus Gittinger <cg@exept.de>
parents:
11158
diff
changeset
|
1370 |
|
9639 | 1371 |
!Behavior methodsFor:'compiler interface'! |
1372 |
||
1373 |
browserClass |
|
12094 | 1374 |
"return the browser to use for this class - |
9639 | 1375 |
this can be redefined in special classes, to get different browsers" |
1376 |
||
1377 |
^ self class browserClass. |
|
1378 |
! |
|
1379 |
||
1380 |
compilerClass |
|
12094 | 1381 |
"return the compiler to use for this class - |
9639 | 1382 |
this can be redefined in special classes, to compile classes with |
1383 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1384 |
||
1385 |
^ self class compilerClass. |
|
1386 |
! |
|
1387 |
||
1388 |
evaluatorClass |
|
12094 | 1389 |
"return the compiler to use for expression evaluation for this class - |
9639 | 1390 |
this can be redefined in special classes, to evaluate expressions with |
1391 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1392 |
||
1393 |
^ self class evaluatorClass. |
|
1394 |
! |
|
1395 |
||
1396 |
formatterClass |
|
12094 | 1397 |
"return the parser to use for formatting (prettyPrinting) this class - |
9639 | 1398 |
this can be redefined in special classes, to format classes with |
1399 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1400 |
||
1401 |
^ self class formatterClass. |
|
620 | 1402 |
! |
1403 |
||
11990 | 1404 |
language |
12195 | 1405 |
self halt:'should no longer be reached - use #programmingLanguage or Smalltalk language'. |
12148
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1406 |
^ self class programmingLanguage |
11990 | 1407 |
|
1408 |
"Created: / 15-08-2009 / 09:06:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
1409 |
! |
|
1410 |
||
9639 | 1411 |
parserClass |
12094 | 1412 |
"return the parser to use for parsing this class - |
9639 | 1413 |
this can be redefined in special classes, to parse classes with |
1414 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1415 |
||
1416 |
^ self class parserClass. |
|
1417 |
! |
|
1418 |
||
12148
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1419 |
programmingLanguage |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1420 |
|
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1421 |
^self class programmingLanguage |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1422 |
|
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1423 |
"Created: / 15-08-2009 / 09:06:46 / Jan Vrany <vranyj1@fel.cvut.cz>" |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1424 |
! |
e7a761017355
added: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
12114
diff
changeset
|
1425 |
|
9639 | 1426 |
subclassDefinerClass |
12094 | 1427 |
"Answer an evaluator class appropriate for evaluating definitions of new |
9639 | 1428 |
subclasses of this class." |
1429 |
||
1430 |
^ self class subclassDefinerClass. |
|
1431 |
! |
|
1432 |
||
1433 |
syntaxHighlighterClass |
|
12094 | 1434 |
"return the class to use for syntaxHighlighting (prettyPrinting) this class - |
9639 | 1435 |
this can be redefined in special classes, to highlight classes with |
1436 |
Lisp, Prolog, ASN1, Basic :-) or whatever syntax." |
|
1437 |
||
1438 |
^ self class syntaxHighlighterClass. |
|
1439 |
! ! |
|
1440 |
||
1441 |
!Behavior methodsFor:'compiling'! |
|
1442 |
||
1443 |
compile:code notifying:requestor |
|
1444 |
"compile code, aString for this class; on any error, notify |
|
1445 |
requestor, anObject with the error reason. |
|
1446 |
Returns the new method or nil (on failure)." |
|
1447 |
||
1448 |
^ self compilerClass |
|
1449 |
compile:code |
|
1450 |
forClass:self |
|
1451 |
notifying:requestor |
|
1452 |
||
1453 |
"Modified: 13.12.1995 / 11:02:40 / cg" |
|
1454 |
"Created: 1.4.1997 / 23:43:43 / stefan" |
|
1455 |
! ! |
|
1456 |
||
1457 |
!Behavior methodsFor:'copying'! |
|
1458 |
||
12094 | 1459 |
canCloneFrom:anObject |
620 | 1460 |
"return true, if this class can clone an obsolete object as retrieved |
1461 |
by a binary load. Subclasses which do not want to have obsolete objects |
|
1462 |
be converted, should redefine this method to return false. |
|
1463 |
(However, conversion is never done silently in a binary load; you |
|
1464 |
have to have a handler for the binaryload errors and for the conversion |
|
1465 |
request signal.)" |
|
1466 |
||
1467 |
^ true |
|
1468 |
! |
|
1469 |
||
1470 |
cloneFrom:aPrototype |
|
1471 |
"return an instance of myself with variables initialized from |
|
1472 |
a prototype. This is used when instances of obsolete classes are |
|
12094 | 1473 |
binary loaded and a conversion is done on the obsolete object. |
620 | 1474 |
UserClasses may redefine this for better conversions." |
1475 |
||
4738 | 1476 |
|newInst indexed| |
620 | 1477 |
|
1478 |
indexed := false. |
|
1479 |
aPrototype class isVariable ifTrue:[ |
|
5321 | 1480 |
self isVariable ifTrue:[ |
1481 |
indexed := true. |
|
1482 |
]. |
|
1483 |
"otherwise, these are lost ..." |
|
620 | 1484 |
]. |
1485 |
indexed ifTrue:[ |
|
5321 | 1486 |
newInst := self basicNew:aPrototype basicSize |
620 | 1487 |
] ifFalse:[ |
5321 | 1488 |
newInst := self basicNew |
620 | 1489 |
]. |
1490 |
||
4692
055edf6e95af
Redefine #cloneFrom: using #cloneInstanceVariablesFrom:.
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
1491 |
newInst cloneInstanceVariablesFrom:aPrototype. |
055edf6e95af
Redefine #cloneFrom: using #cloneInstanceVariablesFrom:.
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
1492 |
|
620 | 1493 |
^ newInst |
1494 |
||
1495 |
" |
|
1496 |
Class withoutUpdatingChangesDo:[ |
|
5321 | 1497 |
Point subclass:#Point3D |
1498 |
instanceVariableNames:'z' |
|
1499 |
classVariableNames:'' |
|
1500 |
poolDictionaries:'' |
|
1501 |
category:'testing'. |
|
1502 |
(Point3D cloneFrom:1@2) inspect. |
|
620 | 1503 |
] |
1504 |
" |
|
1505 |
||
1506 |
" |
|
1507 |
Class withoutUpdatingChangesDo:[ |
|
5321 | 1508 |
Point variableSubclass:#Point3D |
1509 |
instanceVariableNames:'z' |
|
1510 |
classVariableNames:'' |
|
1511 |
poolDictionaries:'' |
|
1512 |
category:'testing'. |
|
1513 |
(Point3D cloneFrom:#(1 2 3)) inspect. |
|
620 | 1514 |
] |
1515 |
" |
|
1516 |
||
1517 |
" |
|
1518 |
|someObject| |
|
1519 |
||
1520 |
Class withoutUpdatingChangesDo:[ |
|
12094 | 1521 |
Object subclass:#TestClass1 |
5321 | 1522 |
instanceVariableNames:'foo bar' |
1523 |
classVariableNames:'' |
|
1524 |
poolDictionaries:'' |
|
1525 |
category:'testing'. |
|
1526 |
someObject := TestClass1 new. |
|
1527 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
12094 | 1528 |
Object subclass:#TestClass2 |
5321 | 1529 |
instanceVariableNames:'bar foo' |
1530 |
classVariableNames:'' |
|
1531 |
poolDictionaries:'' |
|
1532 |
category:'testing'. |
|
1533 |
(TestClass2 cloneFrom:someObject) inspect. |
|
620 | 1534 |
] |
1535 |
" |
|
1536 |
! |
|
1537 |
||
10949 | 1538 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
620 | 1539 |
"return a deep copy of the receiver |
1540 |
- return the receiver here - time will show if this is ok" |
|
1541 |
||
1542 |
^ self |
|
1543 |
! |
|
1544 |
||
1545 |
simpleDeepCopy |
|
1546 |
"return a deep copy of the receiver |
|
1547 |
- return the receiver here - time will show if this is ok" |
|
1548 |
||
1549 |
^ self |
|
1550 |
! ! |
|
1551 |
||
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1552 |
!Behavior methodsFor:'dummy changes management'! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1553 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1554 |
addChangeRecordForClassRemove:aClassName |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1555 |
"add a change record that some class has been removed. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1556 |
Defined as dummy here, since Behavior does not know about change management. |
9194 | 1557 |
(only Classes do). This allows different Behavior-like objects |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1558 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1559 |
|
9194 | 1560 |
"Created: 16.4.1996 / 16:30:09 / cg" |
1561 |
"Modified: 16.4.1996 / 18:10:35 / cg" |
|
1562 |
! ! |
|
1563 |
||
1564 |
!Behavior methodsFor:'dummy fileOut'! |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1565 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1566 |
fileOutDefinitionOn:aStream |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1567 |
"dummy fileOut defined here. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1568 |
This allows different Behavior-like objects |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1569 |
(alien classes) to be handled by the browser as well." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1570 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1571 |
^ self |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1572 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1573 |
"Created: 16.4.1996 / 16:28:01 / cg" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1574 |
! ! |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
1575 |
|
620 | 1576 |
!Behavior methodsFor:'enumerating'! |
1577 |
||
1578 |
allDerivedInstancesDo:aBlock |
|
1579 |
"evaluate aBlock for all of my instances and all instances of subclasses. |
|
1580 |
This method is going to be removed for protocol compatibility with |
|
1581 |
other STs; use allSubInstancesDo:" |
|
1582 |
||
5862 | 1583 |
<resource:#obsolete> |
1584 |
||
9194 | 1585 |
self obsoleteMethodWarning:'use #allSubInstancesDo:'. |
1586 |
self allSubInstancesDo:aBlock |
|
1587 |
||
1588 |
" |
|
1589 |
StandardSystemView allDerivedInstancesDo:[:v | Transcript showCR:(v name)] |
|
1590 |
" |
|
1591 |
||
1592 |
"Modified: 31.7.1997 / 23:05:04 / cg" |
|
1593 |
! |
|
620 | 1594 |
|
1595 |
allInstancesDo:aBlock |
|
1596 |
"evaluate aBlock for all of my instances" |
|
1597 |
||
1598 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
1599 |
aBlock value:anObject |
|
1600 |
] |
|
1601 |
||
1602 |
" |
|
1422 | 1603 |
StandardSystemView allInstancesDo:[:v | Transcript showCR:(v name)] |
620 | 1604 |
" |
1605 |
! |
|
1606 |
||
7809 | 1607 |
allOwningclassesDo:aBlock |
1608 |
"evaluate aBlock for all of my owners (i.e. owner, owner-of-owner etc)." |
|
1609 |
||
1610 |
|owner| |
|
1611 |
||
1612 |
owner := self owningClass. |
|
1613 |
[owner notNil] whileTrue:[ |
|
12094 | 1614 |
aBlock value:owner. |
1615 |
owner := owner owningClass. |
|
9194 | 1616 |
]. |
1617 |
||
1618 |
" |
|
1619 |
Method::MethodWhoInfo allOwningclassesDo:[:c | Transcript showCR:(c name)] |
|
1620 |
" |
|
1621 |
! |
|
7809 | 1622 |
|
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1623 |
allSelectorsAndMethodsDo:aTwoArgBlock |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1624 |
"evaluate the argument, aBlock for all selectors of mySelf and my metaclass, |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1625 |
passing the corresponding method as second argument" |
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1626 |
|
8353 | 1627 |
<resource: #obsolete> |
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1628 |
self obsoleteMethodWarning:'use #instAndClassSelectorsAndMethodsDo:'. |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1629 |
|
6022 | 1630 |
self selectorsAndMethodsDo:aTwoArgBlock. |
9194 | 1631 |
self class selectorsAndMethodsDo:aTwoArgBlock. |
1632 |
! |
|
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1633 |
|
620 | 1634 |
allSubInstancesDo:aBlock |
1635 |
"evaluate aBlock for all of my instances and all instances of subclasses" |
|
1636 |
||
1637 |
ObjectMemory allObjectsDo:[:anObject | |
|
1638 |
(anObject isKindOf:self) ifTrue:[ |
|
1639 |
aBlock value:anObject |
|
1640 |
] |
|
1641 |
] |
|
1642 |
||
1643 |
" |
|
1422 | 1644 |
StandardSystemView allSubInstancesDo:[:v | Transcript showCR:(v name)] |
620 | 1645 |
" |
1646 |
! |
|
1647 |
||
1648 |
allSubclassesDo:aBlock |
|
1649 |
"evaluate aBlock for all of my subclasses. |
|
1650 |
There is no specific order, in which the entries are enumerated. |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1651 |
Warning: |
12094 | 1652 |
This will only enumerate globally known classes - for anonymous |
1653 |
behaviors, you have to walk over all instances of Behavior." |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1654 |
|
6931 | 1655 |
self allSubclassesInOrderDo:aBlock |
1656 |
||
1657 |
"/ self isMeta ifTrue:[ |
|
1658 |
"/ "/ metaclasses are not found via Smalltalk allClassesDo: |
|
1659 |
"/ "/ here, walk over classes and enumerate corresponding metas. |
|
1660 |
"/ self soleInstance allSubclassesDo:[:aSubClass | |
|
1661 |
"/ aBlock value:(aSubClass class) |
|
1662 |
"/ ]. |
|
1663 |
"/ ] ifFalse:[ |
|
1664 |
"/ Smalltalk allClassesDo:[:aClass | |
|
1665 |
"/ (aClass isSubclassOf:self) ifTrue:[ |
|
1666 |
"/ aBlock value:aClass |
|
1667 |
"/ ] |
|
1668 |
"/ ] |
|
1669 |
"/ ] |
|
620 | 1670 |
|
1671 |
" |
|
1422 | 1672 |
Collection allSubclassesDo:[:c | Transcript showCR:(c name)] |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1673 |
Collection class allSubclassesDo:[:c | Transcript showCR:(c name)] |
620 | 1674 |
" |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1675 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1676 |
"Modified: / 25.10.1997 / 21:17:13 / cg" |
9194 | 1677 |
! |
1678 |
||
1679 |
allSubclassesInOrderDo:aBlock |
|
620 | 1680 |
"evaluate aBlock for all of my subclasses. |
6931 | 1681 |
There is no specific order, in which the entries are enumerated. |
1682 |
Warning: |
|
12094 | 1683 |
This will only enumerate globally known classes - for anonymous |
1684 |
behaviors, you have to walk over all instances of Behavior." |
|
6931 | 1685 |
|
1686 |
|meta toDo cls| |
|
1687 |
||
1688 |
meta := self isMeta. |
|
12094 | 1689 |
|
6931 | 1690 |
toDo := OrderedCollection new. |
1691 |
toDo addAll:self theNonMetaclass subclasses. |
|
1692 |
[toDo notEmpty] whileTrue:[ |
|
12094 | 1693 |
cls := toDo removeFirst. |
1694 |
toDo addAll:cls subclasses. |
|
1695 |
meta ifTrue:[ |
|
1696 |
aBlock value:cls class. |
|
1697 |
] ifFalse:[ |
|
1698 |
aBlock value:cls. |
|
1699 |
] |
|
6931 | 1700 |
]. |
1701 |
||
1702 |
"/ self isMeta ifTrue:[ |
|
1703 |
"/ "/ metaclasses are not found via Smalltalk allClassesDo: |
|
1704 |
"/ "/ here, walk over classes and enumerate corresponding metas. |
|
1705 |
"/ self soleInstance allSubclassesDo:[:aSubClass | |
|
1706 |
"/ aBlock value:(aSubClass class) |
|
1707 |
"/ ]. |
|
1708 |
"/ ] ifFalse:[ |
|
1709 |
"/ Smalltalk allClassesDo:[:aClass | |
|
1710 |
"/ (aClass isSubclassOf:self) ifTrue:[ |
|
1711 |
"/ aBlock value:aClass |
|
1712 |
"/ ] |
|
1713 |
"/ ] |
|
1714 |
"/ ] |
|
620 | 1715 |
|
1716 |
" |
|
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
1717 |
Collection allSubclassesInOrderDo:[:c | Transcript showCR:(c name)] |
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
1718 |
Collection class allSubclassesInOrderDo:[:c | Transcript showCR:(c name)] |
620 | 1719 |
" |
6931 | 1720 |
|
1721 |
"Modified: / 25.10.1997 / 21:17:13 / cg" |
|
9194 | 1722 |
! |
1723 |
||
1724 |
allSuperclassesDo:aBlock |
|
1725 |
"evaluate aBlock for all of my superclasses" |
|
1726 |
||
1727 |
|theClass| |
|
1728 |
||
1729 |
theClass := self superclass. |
|
1730 |
[theClass notNil] whileTrue:[ |
|
12094 | 1731 |
aBlock value:theClass. |
1732 |
theClass := theClass superclass |
|
9194 | 1733 |
] |
1734 |
||
1735 |
" |
|
1736 |
String allSuperclassesDo:[:c | Transcript showCR:(c name)] |
|
1737 |
" |
|
1738 |
! |
|
620 | 1739 |
|
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1740 |
instAndClassMethodsDo:aOneArgBlock |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1741 |
"evaluate the argument, aBlock for all methods of mySelf and my metaclass |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1742 |
(i.e. for both instance- and class methods)" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1743 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1744 |
self theNonMetaclass methodsDo:aOneArgBlock. |
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1745 |
self theMetaclass methodsDo:aOneArgBlock. |
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1746 |
! |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1747 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1748 |
instAndClassSelectorsAndMethodsDo:aTwoArgBlock |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1749 |
"evaluate the argument, aBlock for all selectors of mySelf and my metaclass, |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1750 |
passing the corresponding method as second argument" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1751 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1752 |
self selectorsAndMethodsDo:aTwoArgBlock. |
9194 | 1753 |
self class selectorsAndMethodsDo:aTwoArgBlock. |
1754 |
! |
|
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1755 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1756 |
methodsDo:aOneArgBlock |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1757 |
"evaluate the argument, aBlock for all my methods" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1758 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1759 |
self methodDictionary do:aOneArgBlock |
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1760 |
|
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1761 |
" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1762 |
UndefinedObject methodsDo:[:m | Transcript showCR:m whoString] |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1763 |
UndefinedObject selectorsDo:[:sym | Transcript showCR:sym] |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1764 |
" |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1765 |
! |
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1766 |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1767 |
selectorsAndMethodsDo:aTwoArgBlock |
5368
192acdc335e6
added #allSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
5327
diff
changeset
|
1768 |
"evaluate the argument, aBlock for all my selectors, |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1769 |
passing the corresponding method as second argument" |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1770 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
1771 |
self methodDictionary keysAndValuesDo:aTwoArgBlock |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1772 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1773 |
"Created: / 27.10.1997 / 14:09:27 / cg" |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1774 |
! |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
1775 |
|
9194 | 1776 |
selectorsDo:aOneArgBlock |
1777 |
"evaluate the argument, aBlock for all my selectors" |
|
1778 |
||
1779 |
self methodDictionary keysDo:aOneArgBlock |
|
1780 |
! |
|
6076
2f75076b5597
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6030
diff
changeset
|
1781 |
|
620 | 1782 |
subclassesDo:aBlock |
1783 |
"evaluate the argument, aBlock for all immediate subclasses. |
|
1784 |
This will only enumerate globally known classes - for anonymous |
|
1785 |
behaviors, you have to walk over all instances of Behavior." |
|
1786 |
||
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
1787 |
"Do it the hard way. Subclasses redefine this" |
5581 | 1788 |
Smalltalk allClassesDo:[:aClass | |
12094 | 1789 |
(aClass superclass == self) ifTrue:[ |
1790 |
aBlock value:aClass |
|
1791 |
] |
|
9194 | 1792 |
] |
1793 |
! |
|
5638 | 1794 |
|
12094 | 1795 |
whichClassSatisfies: aBlock |
6727 | 1796 |
|superclass| |
1797 |
||
1798 |
(aBlock value: self) ifTrue: [^self]. |
|
1799 |
superclass := self superclass. |
|
12094 | 1800 |
^ superclass isNil |
1801 |
ifTrue: [nil] |
|
1802 |
ifFalse: [superclass whichClassSatisfies: aBlock] |
|
6727 | 1803 |
! |
1804 |
||
5638 | 1805 |
withAllSubclassesDo:aBlock |
1806 |
"evaluate aBlock for mySelf and all of my subclasses. |
|
1807 |
There is no specific order, in which the entries are enumerated. |
|
1808 |
Warning: |
|
12094 | 1809 |
This will only enumerate globally known classes - for anonymous |
1810 |
behaviors, you have to walk over all instances of Behavior." |
|
5638 | 1811 |
|
1812 |
aBlock value:self. |
|
1813 |
self allSubclassesDo:aBlock |
|
1814 |
||
1815 |
" |
|
1816 |
Collection withAllSubclassesDo:[:c | Transcript showCR:(c name)] |
|
1817 |
Collection class withAllSubclassesDo:[:c | Transcript showCR:(c name)] |
|
1818 |
" |
|
9194 | 1819 |
! |
1820 |
||
1821 |
withAllSuperclassesDo:aBlock |
|
1822 |
"evaluate aBlock for the class and all of its superclasses" |
|
1823 |
||
1824 |
|theSuperClass| |
|
1825 |
||
1826 |
aBlock value:self. |
|
1827 |
theSuperClass := self superclass. |
|
1828 |
[theSuperClass notNil] whileTrue:[ |
|
12094 | 1829 |
aBlock value:theSuperClass. |
1830 |
theSuperClass := theSuperClass superclass |
|
9194 | 1831 |
]. |
1832 |
||
1833 |
" |
|
12094 | 1834 |
String withAllSuperclassesDo:[:each| Transcript showCR:each] |
9194 | 1835 |
" |
1836 |
! ! |
|
1837 |
||
1838 |
!Behavior methodsFor:'initialization'! |
|
1 | 1839 |
|
620 | 1840 |
deinitialize |
1841 |
"deinitialize is sent to a class before it is physically unloaded. |
|
1842 |
This is only done with classes which have been loaded in from a binary |
|
1843 |
file. Classes may release any primitive memory or other stuff which is |
|
1844 |
not visible to smalltalk (for example, release internal memory). |
|
1845 |
The default action here is to do nothing." |
|
1846 |
||
1847 |
^ self |
|
1848 |
! |
|
1849 |
||
1 | 1850 |
initialize |
442 | 1851 |
"initialize is sent to a class either during startup, |
1852 |
(for all statically compiled-in classes) or after a class |
|
1853 |
has been loaded into the system (either bytecodes or machinecode). |
|
1854 |
The default action here is to do nothing." |
|
1 | 1855 |
|
1856 |
^ self |
|
1857 |
! |
|
1858 |
||
3442
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1859 |
initializeWithAllPrivateClasses |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1860 |
"if implemented, send #initialize to myself and any private |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1861 |
class which does so. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1862 |
This is sent to a class after it |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1863 |
has been loaded into the system. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1864 |
Statically compiled classes are initialized by the VM" |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1865 |
|
6412
4d6aaac56707
implements -> includesSelector
Claus Gittinger <cg@exept.de>
parents:
6395
diff
changeset
|
1866 |
(self class includesSelector:#initialize) ifTrue:[ |
12094 | 1867 |
self initialize. |
3442
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1868 |
]. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1869 |
self privateClassesSorted do:[:aPrivateClass | |
12094 | 1870 |
aPrivateClass initializeWithAllPrivateClasses. |
3442
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1871 |
]. |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1872 |
|
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1873 |
"Created: / 13.5.1998 / 23:33:16 / cg" |
d22afbb5864f
added #initializeWithAllPrivateClasses
Claus Gittinger <cg@exept.de>
parents:
3411
diff
changeset
|
1874 |
"Modified: / 13.5.1998 / 23:34:06 / cg" |
9194 | 1875 |
! |
1876 |
||
1877 |
postAutoload |
|
1878 |
"postAutoload is sent to a class after it has been autoloaded. |
|
1879 |
This gives it a chance to arrange for automatic unloading to be done |
|
1880 |
after a while ... |
|
1881 |
This is NOT sent to statically compiled in or explicitely filedIn |
|
1882 |
classes. |
|
1883 |
The default action here is to do nothing." |
|
1884 |
||
1885 |
^ self |
|
1886 |
! |
|
328 | 1887 |
|
1 | 1888 |
reinitialize |
442 | 1889 |
"reinitialize is sent to a class when an image has been restarted. |
1890 |
I.e. when the system is restarted. |
|
1891 |
This gives classes a chance to flush any device dependent or otherwise |
|
1892 |
obsolete data which may be a leftover from the previous live. |
|
1893 |
The default action here is to do nothing." |
|
1894 |
||
9194 | 1895 |
^ self |
1896 |
! ! |
|
1897 |
||
1898 |
!Behavior methodsFor:'instance creation'! |
|
1899 |
||
1900 |
basicNew |
|
54 | 1901 |
"return an instance of myself without indexed variables. |
1 | 1902 |
If the receiver-class has indexed instvars, the new object will have |
12094 | 1903 |
a basicSize of zero - |
91 | 1904 |
i.e. 'aClass basicNew' is equivalent to 'aClass basicNew:0'. |
54 | 1905 |
|
1 | 1906 |
** Do not redefine this method in any class **" |
1907 |
||
1908 |
%{ /* NOCONTEXT */ |
|
81 | 1909 |
REGISTER OBJ newobj; |
1910 |
REGISTER char *nextPtr; |
|
91 | 1911 |
unsigned int instsize; |
1912 |
REGISTER unsigned int nInstVars; |
|
1 | 1913 |
|
54 | 1914 |
/* |
369 | 1915 |
* the following ugly code is nothing more than a __new() followed |
54 | 1916 |
* by a nilling of the new instance. |
12094 | 1917 |
* Unrolled for a bit more speed since this is one of the central object |
91 | 1918 |
* allocation methods in the system |
54 | 1919 |
*/ |
1133 | 1920 |
nInstVars = __intVal(__INST(instSize)); |
92 | 1921 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
54 | 1922 |
|
983 | 1923 |
newobj = (OBJ) __newNextPtr; |
81 | 1924 |
nextPtr = ((char *)newobj) + instsize; |
1925 |
||
1926 |
/* |
|
12094 | 1927 |
* dont argue about the goto and the arrangement below - it saves |
81 | 1928 |
* an extra nil-compare and branch in the common case ... |
91 | 1929 |
* (i.e. if no GC is needed, we fall through without a branch) |
81 | 1930 |
*/ |
983 | 1931 |
if (nextPtr < __newEndPtr) { |
154 | 1932 |
_objPtr(newobj)->o_size = instsize; |
1933 |
/* o_allFlags(newobj) = 0; */ |
|
983 | 1934 |
/* _objPtr(newobj)->o_space = __newSpace; */ |
1935 |
o_setAllFlags(newobj, __newSpace); |
|
2894 | 1936 |
#ifdef __HAS_ALIGN4__ |
1937 |
/* |
|
1938 |
* if the alignment is 4, we are already sat, |
|
1939 |
* since a non-indexed object always has a word-aligned size. |
|
1940 |
*/ |
|
983 | 1941 |
__newNextPtr = nextPtr; |
91 | 1942 |
#else |
2894 | 1943 |
if (instsize & (__ALIGN__-1)) { |
1944 |
__newNextPtr = (char *)newobj + (instsize & ~(__ALIGN__-1)) + __ALIGN__; |
|
154 | 1945 |
} else { |
983 | 1946 |
__newNextPtr = nextPtr; |
154 | 1947 |
} |
91 | 1948 |
#endif |
82 | 1949 |
|
1950 |
ok: |
|
1133 | 1951 |
__InstPtr(newobj)->o_class = self; |
369 | 1952 |
__qSTORE(newobj, self); |
82 | 1953 |
|
154 | 1954 |
if (nInstVars) { |
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
1955 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
1133 | 1956 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
82 | 1957 |
#else |
154 | 1958 |
REGISTER OBJ *op; |
82 | 1959 |
|
1133 | 1960 |
op = __InstPtr(newobj)->i_instvars; |
82 | 1961 |
|
154 | 1962 |
/* |
1963 |
* knowing that nil is 0 |
|
1964 |
*/ |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1965 |
# if defined(FAST_OBJECT_MEMSET_DOUBLES_UNROLLED) |
154 | 1966 |
if (nInstVars > 8) { |
1967 |
*op++ = nil; /* for alignment */ |
|
1968 |
nInstVars--; |
|
1969 |
while (nInstVars >= 8) { |
|
1970 |
*(double *)op = 0.0; |
|
1971 |
((double *)op)[1] = 0.0; |
|
1972 |
((double *)op)[2] = 0.0; |
|
1973 |
((double *)op)[3] = 0.0; |
|
1974 |
op += 8; |
|
1975 |
nInstVars -= 8; |
|
1976 |
} |
|
1977 |
} |
|
1978 |
while (nInstVars != 0) { |
|
1979 |
*op++ = 0; |
|
1980 |
nInstVars--; |
|
1981 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1982 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
1983 |
# if defined(FAST_OBJECT_MEMSET_LONGLONG_UNROLLED) |
154 | 1984 |
if (nInstVars > 8) { |
1985 |
*op++ = nil; /* for alignment */ |
|
1986 |
nInstVars--; |
|
1987 |
while (nInstVars >= 8) { |
|
1988 |
*(long long *)op = 0; |
|
1989 |
((long long *)op)[1] = 0; |
|
1990 |
((long long *)op)[2] = 0; |
|
1991 |
((long long *)op)[3] = 0; |
|
1992 |
op += 8; |
|
1993 |
nInstVars -= 8; |
|
1994 |
} |
|
1995 |
} |
|
1996 |
while (nInstVars != 0) { |
|
1997 |
*op++ = 0; |
|
1998 |
nInstVars--; |
|
1999 |
} |
|
91 | 2000 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2001 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2002 |
# if defined(FAST_OBJECT_MEMSET_WORDS_UNROLLED) |
154 | 2003 |
while (nInstVars >= 8) { |
2004 |
*op = nil; |
|
2005 |
*(op+1) = nil; |
|
2006 |
*(op+2) = nil; |
|
2007 |
*(op+3) = nil; |
|
2008 |
*(op+4) = nil; |
|
2009 |
*(op+5) = nil; |
|
2010 |
*(op+6) = nil; |
|
2011 |
*(op+7) = nil; |
|
2012 |
op += 8; |
|
2013 |
nInstVars -= 8; |
|
2014 |
} |
|
2015 |
while (nInstVars != 0) { |
|
2016 |
*op++ = nil; |
|
2017 |
nInstVars--; |
|
2018 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2019 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2020 |
# if defined(FAST_MEMSET) |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2021 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
91 | 2022 |
# else |
154 | 2023 |
do { |
2024 |
*op++ = nil; |
|
2025 |
nInstVars--; |
|
2026 |
} while (nInstVars != 0); |
|
82 | 2027 |
# endif |
2028 |
# endif |
|
2029 |
# endif |
|
2030 |
# endif |
|
2031 |
#endif |
|
154 | 2032 |
} |
2033 |
RETURN ( newobj ); |
|
81 | 2034 |
} |
54 | 2035 |
|
92 | 2036 |
/* |
2037 |
* the slow case - a GC will occur |
|
2038 |
*/ |
|
834 | 2039 |
__PROTECT_CONTEXT__ |
3980
8f9443e37693
renamed __new() to __STX___new()
Claus Gittinger <cg@exept.de>
parents:
3935
diff
changeset
|
2040 |
newobj = __STX___new(instsize); |
834 | 2041 |
__UNPROTECT_CONTEXT__ |
82 | 2042 |
if (newobj != nil) goto ok; |
9194 | 2043 |
%} |
2044 |
. |
|
2045 |
" |
|
2046 |
memory allocation failed. |
|
2047 |
When we arrive here, there was no memory, even after |
|
12094 | 2048 |
a garbage collect. |
2049 |
This means, that the VM wanted to get some more memory from the |
|
9194 | 2050 |
Operatingsystem, which was not kind enough to give it. |
2051 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 2052 |
" |
127 | 2053 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 2054 |
! |
2055 |
||
9194 | 2056 |
basicNew:anInteger |
1 | 2057 |
"return an instance of myself with anInteger indexed variables. |
2058 |
If the receiver-class has no indexed instvars, this is only allowed |
|
2059 |
if the argument, anInteger is zero. |
|
2060 |
** Do not redefine this method in any class **" |
|
2061 |
||
2062 |
%{ /* NOCONTEXT */ |
|
2063 |
||
2064 |
OBJ newobj; |
|
154 | 2065 |
unsigned INT instsize, nInstVars; |
2066 |
INT nindexedinstvars; |
|
92 | 2067 |
unsigned INT flags; |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2068 |
#if ! defined(FAST_ARRAY_MEMSET) |
1 | 2069 |
REGISTER char *cp; |
2070 |
short *sp; |
|
2071 |
long *lp; |
|
2072 |
#endif |
|
2073 |
REGISTER OBJ *op; |
|
2074 |
float *fp; |
|
2075 |
double *dp; |
|
2076 |
||
249 | 2077 |
if (__isSmallInteger(anInteger)) { |
12094 | 2078 |
nindexedinstvars = __intVal(anInteger); |
2079 |
if (nindexedinstvars >= 0) { |
|
2080 |
nInstVars = __intVal(__INST(instSize)); |
|
2081 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
2082 |
switch (flags) { |
|
2083 |
case BYTEARRAY: |
|
2084 |
instsize = OHDR_SIZE + nindexedinstvars; |
|
2085 |
if (nInstVars == 0) { |
|
2086 |
if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */ |
|
2087 |
/* |
|
2088 |
* the most common case |
|
2089 |
*/ |
|
2090 |
__qCheckedNew(newobj, instsize); |
|
2091 |
__InstPtr(newobj)->o_class = self; |
|
2092 |
__qSTORE(newobj, self); |
|
7858
65d77eb25fda
Have to call __STORE(), when assigning class.
Stefan Vogel <sv@exept.de>
parents:
7809
diff
changeset
|
2093 |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2094 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
12094 | 2095 |
nInstVars = nindexedinstvars >> 2; |
2096 |
if (nindexedinstvars & 3) nInstVars++; |
|
2097 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars); |
|
357 | 2098 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2099 |
# if defined(FAST_ARRAY_MEMSET) |
12094 | 2100 |
memset(__InstPtr(newobj)->i_instvars, 0, nindexedinstvars); |
357 | 2101 |
# else |
12094 | 2102 |
cp = (char *)__InstPtr(newobj)->i_instvars; |
2103 |
while (nindexedinstvars >= sizeof(long)) { |
|
2104 |
*(long *)cp = 0; |
|
2105 |
cp += sizeof(long); |
|
2106 |
nindexedinstvars -= sizeof(long); |
|
2107 |
} |
|
2108 |
while (nindexedinstvars--) |
|
2109 |
*cp++ = '\0'; |
|
357 | 2110 |
# endif |
92 | 2111 |
#endif |
12094 | 2112 |
RETURN ( newobj ); |
2113 |
} |
|
2114 |
} else { |
|
2115 |
instsize += __OBJS2BYTES__(nInstVars); |
|
2116 |
} |
|
2117 |
__PROTECT_CONTEXT__ |
|
2118 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2119 |
__UNPROTECT_CONTEXT__ |
|
2120 |
if (newobj == nil) { |
|
2121 |
break; |
|
2122 |
} |
|
2123 |
__InstPtr(newobj)->o_class = self; |
|
2124 |
__qSTORE(newobj, self); |
|
369 | 2125 |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2126 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
12094 | 2127 |
nInstVars = (instsize-OHDR_SIZE) >> 2; |
2128 |
if (instsize & 3) nInstVars++; |
|
2129 |
memset4(__InstPtr(newobj)->i_instvars, 0, nInstVars); |
|
357 | 2130 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2131 |
# if defined(FAST_ARRAY_MEMSET) |
12094 | 2132 |
/* |
2133 |
* knowing that nil is 0 |
|
2134 |
*/ |
|
2135 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize-OHDR_SIZE); |
|
357 | 2136 |
# else |
12094 | 2137 |
op = __InstPtr(newobj)->i_instvars; |
2138 |
while (nInstVars--) |
|
2139 |
*op++ = nil; |
|
2140 |
cp = (char *)op; |
|
2141 |
while (nindexedinstvars >= sizeof(long)) { |
|
2142 |
*(long *)cp = 0; |
|
2143 |
cp += sizeof(long); |
|
2144 |
nindexedinstvars -= sizeof(long); |
|
2145 |
} |
|
2146 |
while (nindexedinstvars--) |
|
2147 |
*cp++ = '\0'; |
|
357 | 2148 |
# endif |
1 | 2149 |
#endif |
12094 | 2150 |
RETURN ( newobj ); |
2151 |
break; |
|
2152 |
||
2153 |
case WORDARRAY: |
|
2154 |
case SWORDARRAY: |
|
2155 |
instsize = OHDR_SIZE + |
|
2156 |
__OBJS2BYTES__(nInstVars) + |
|
2157 |
nindexedinstvars * 2; |
|
2158 |
__PROTECT_CONTEXT__ |
|
2159 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2160 |
__UNPROTECT_CONTEXT__ |
|
2161 |
if (newobj == nil) { |
|
2162 |
break; |
|
2163 |
} |
|
2164 |
__InstPtr(newobj)->o_class = self; |
|
2165 |
__qSTORE(newobj, self); |
|
369 | 2166 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2167 |
#if defined(FAST_ARRAY_MEMSET) |
12094 | 2168 |
/* |
2169 |
* knowing that nil is 0 |
|
2170 |
*/ |
|
2171 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 2172 |
#else |
12094 | 2173 |
op = __InstPtr(newobj)->i_instvars; |
2174 |
while (nInstVars--) |
|
2175 |
*op++ = nil; |
|
2176 |
sp = (short *)op; |
|
2177 |
while (nindexedinstvars--) |
|
2178 |
*sp++ = 0; |
|
1 | 2179 |
#endif |
12094 | 2180 |
RETURN ( newobj ); |
2181 |
break; |
|
2182 |
||
2183 |
case LONGARRAY: |
|
2184 |
case SLONGARRAY: |
|
2185 |
instsize = OHDR_SIZE + |
|
2186 |
__OBJS2BYTES__(nInstVars) + |
|
2187 |
nindexedinstvars * 4; |
|
2188 |
__PROTECT_CONTEXT__ |
|
2189 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2190 |
__UNPROTECT_CONTEXT__ |
|
2191 |
if (newobj == nil) { |
|
2192 |
break; |
|
2193 |
} |
|
2194 |
__InstPtr(newobj)->o_class = self; |
|
2195 |
__qSTORE(newobj, self); |
|
369 | 2196 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2197 |
#if defined(memset4) |
12094 | 2198 |
/* |
2199 |
* knowing that nil is 0 |
|
2200 |
*/ |
|
2201 |
{ |
|
2202 |
int n4 = nInstVars + nindexedinstvars; |
|
2203 |
||
2204 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2205 |
} |
|
1 | 2206 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2207 |
# if defined(FAST_ARRAY_MEMSET) |
12094 | 2208 |
/* |
2209 |
* knowing that nil is 0 |
|
2210 |
*/ |
|
2211 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 2212 |
# else |
12094 | 2213 |
op = __InstPtr(newobj)->i_instvars; |
2214 |
while (nInstVars--) |
|
2215 |
*op++ = nil; |
|
2216 |
lp = (long *)op; |
|
2217 |
while (nindexedinstvars--) |
|
2218 |
*lp++ = 0; |
|
1 | 2219 |
# endif |
2220 |
#endif |
|
12094 | 2221 |
RETURN ( newobj ); |
2222 |
break; |
|
2223 |
||
2224 |
case LONGLONGARRAY: |
|
2225 |
case SLONGLONGARRAY: |
|
2226 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2227 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2228 |
#ifdef __NEED_LONGLONG_ALIGN |
12094 | 2229 |
instsize = ((instsize-1) + __LONGLONG_ALIGN) & ~(__LONGLONG_ALIGN-1); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2230 |
#endif |
12094 | 2231 |
instsize += nindexedinstvars * 8; |
2232 |
||
2233 |
__PROTECT_CONTEXT__ |
|
2234 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2235 |
__UNPROTECT_CONTEXT__ |
|
2236 |
if (newobj == nil) { |
|
2237 |
break; |
|
2238 |
} |
|
2239 |
__InstPtr(newobj)->o_class = self; |
|
2240 |
__qSTORE(newobj, self); |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2241 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2242 |
#if defined(memset4) |
12094 | 2243 |
{ |
2244 |
int n4 = (instsize-OHDR_SIZE) / 4; |
|
2245 |
||
2246 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2247 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2248 |
#else |
12094 | 2249 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2250 |
#endif |
12094 | 2251 |
RETURN ( newobj ); |
2252 |
break; |
|
2253 |
||
2254 |
case FLOATARRAY: |
|
2255 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2256 |
instsize += nindexedinstvars * sizeof(float); |
|
2257 |
||
2258 |
__PROTECT_CONTEXT__ |
|
2259 |
__qNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2260 |
__UNPROTECT_CONTEXT__ |
|
2261 |
if (newobj == nil) { |
|
2262 |
break; |
|
2263 |
} |
|
2264 |
__InstPtr(newobj)->o_class = self; |
|
2265 |
__qSTORE(newobj, self); |
|
2266 |
||
2267 |
op = __InstPtr(newobj)->i_instvars; |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2268 |
#if defined(__FLOAT0_IS_INT0) /* knowin that float 0.0 is all-zeros */ |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2269 |
# if defined(memset4) |
12094 | 2270 |
{ |
2271 |
int n4 = (instsize-OHDR_SIZE) / 4; |
|
2272 |
||
2273 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2274 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2275 |
# else |
12094 | 2276 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2277 |
# endif |
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2278 |
#else |
12094 | 2279 |
while (nInstVars--) |
2280 |
*op++ = nil; |
|
2281 |
fp = (float *)op; |
|
2282 |
while (nindexedinstvars--) |
|
2283 |
*fp++ = 0.0; |
|
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2284 |
#endif |
12094 | 2285 |
RETURN ( newobj ); |
2286 |
break; |
|
2287 |
||
2288 |
case DOUBLEARRAY: |
|
2289 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2290 |
#ifdef __NEED_DOUBLE_ALIGN |
12094 | 2291 |
instsize = ((instsize-1) + __DOUBLE_ALIGN) & ~(__DOUBLE_ALIGN-1); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2292 |
#endif |
12094 | 2293 |
instsize += nindexedinstvars * sizeof(double); |
2294 |
||
2295 |
__PROTECT_CONTEXT__ |
|
2296 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2297 |
__UNPROTECT_CONTEXT__ |
|
2298 |
if (newobj == nil) { |
|
2299 |
break; |
|
2300 |
} |
|
2301 |
__InstPtr(newobj)->o_class = self; |
|
2302 |
__qSTORE(newobj, self); |
|
369 | 2303 |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2304 |
#if defined(__DOUBLE0_IS_INT0) /* knowin that double 0.0 is all-zeros */ |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2305 |
# ifdef memset4 |
12094 | 2306 |
{ |
2307 |
int n4 = (instsize-OHDR_SIZE) / 4; |
|
2308 |
||
2309 |
memset4(__InstPtr(newobj)->i_instvars, 0, n4); |
|
2310 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2311 |
# else |
12094 | 2312 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2313 |
# endif |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2314 |
#else |
12094 | 2315 |
op = __InstPtr(newobj)->i_instvars; |
2316 |
while (nInstVars--) |
|
2317 |
*op++ = nil; |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2318 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2319 |
# ifdef __NEED_DOUBLE_ALIGN |
12094 | 2320 |
/* |
2321 |
* care for double alignment |
|
2322 |
* add filler. |
|
2323 |
*/ |
|
2324 |
if ((INT)op & (__DOUBLE_ALIGN-1)) { |
|
2325 |
*op++ = nil; |
|
2326 |
} |
|
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2327 |
# endif |
12094 | 2328 |
dp = (double *)op; |
2329 |
while (nindexedinstvars--) |
|
2330 |
*dp++ = 0.0; |
|
3870
ea7a0f0db4be
use memset to initialize float- and doubleArrays, if float0/double0 is int0
Claus Gittinger <cg@exept.de>
parents:
3805
diff
changeset
|
2331 |
#endif |
12094 | 2332 |
RETURN ( newobj ); |
2333 |
break; |
|
2334 |
||
2335 |
case WKPOINTERARRAY: |
|
2336 |
case POINTERARRAY: |
|
2337 |
nInstVars += nindexedinstvars; |
|
2338 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2339 |
__PROTECT_CONTEXT__ |
|
2340 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2341 |
__UNPROTECT_CONTEXT__ |
|
2342 |
if (newobj == nil) { |
|
2343 |
break; |
|
2344 |
} |
|
2345 |
__InstPtr(newobj)->o_class = self; |
|
2346 |
__qSTORE(newobj, self); |
|
369 | 2347 |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2348 |
#if defined(memset4) && defined(FAST_ARRAY_MEMSET4) || defined(FAST_MEMSET4) |
12094 | 2349 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 2350 |
#else |
12094 | 2351 |
/* |
2352 |
* knowing that nil is 0 |
|
2353 |
*/ |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2354 |
# ifdef sparc |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2355 |
# define FAST_ARRAY_MEMSET_DOUBLES_UNROLLED |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2356 |
# endif |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2357 |
|
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2358 |
# if defined(FAST_ARRAY_MEMSET_DOUBLES_UNROLLED) |
12094 | 2359 |
op = __InstPtr(newobj)->i_instvars; |
2360 |
if (nInstVars > 8) { |
|
2361 |
*op++ = nil; /* for alignment */ |
|
2362 |
nInstVars--; |
|
2363 |
while (nInstVars >= 8) { |
|
2364 |
*(double *)op = 0.0; |
|
2365 |
((double *)op)[1] = 0.0; |
|
2366 |
((double *)op)[2] = 0.0; |
|
2367 |
((double *)op)[3] = 0.0; |
|
2368 |
op += 8; |
|
2369 |
nInstVars -= 8; |
|
2370 |
} |
|
2371 |
} |
|
2372 |
while (nInstVars) { |
|
2373 |
*op++ = 0; |
|
2374 |
nInstVars--; |
|
2375 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2376 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2377 |
# if defined(FAST_ARRAY_MEMSET_LONGLONG_UNROLLED) |
12094 | 2378 |
op = __InstPtr(newobj)->i_instvars; |
2379 |
if (nInstVars > 8) { |
|
2380 |
*op++ = nil; /* for alignment */ |
|
2381 |
nInstVars--; |
|
2382 |
while (nInstVars >= 8) { |
|
2383 |
*(long long *)op = 0; |
|
2384 |
((long long *)op)[1] = 0; |
|
2385 |
((long long *)op)[2] = 0; |
|
2386 |
((long long *)op)[3] = 0; |
|
2387 |
op += 8; |
|
2388 |
nInstVars -= 8; |
|
2389 |
} |
|
2390 |
} |
|
2391 |
while (nInstVars) { |
|
2392 |
*op++ = 0; |
|
2393 |
nInstVars--; |
|
2394 |
} |
|
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2395 |
# else |
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2396 |
# if defined(FAST_ARRAY_MEMSET) |
12094 | 2397 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
91 | 2398 |
# else |
12094 | 2399 |
op = __InstPtr(newobj)->i_instvars; |
2400 |
while (nInstVars--) |
|
2401 |
*op++ = nil; |
|
82 | 2402 |
# endif |
2403 |
# endif |
|
1 | 2404 |
# endif |
2405 |
#endif |
|
12094 | 2406 |
RETURN ( newobj ); |
2407 |
break; |
|
2408 |
||
2409 |
default: |
|
2410 |
/* |
|
2411 |
* new:n for non-variable classes only allowed if |
|
2412 |
* n == 0 |
|
2413 |
*/ |
|
2414 |
if (nindexedinstvars == 0) { |
|
2415 |
instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
|
2416 |
__PROTECT_CONTEXT__ |
|
2417 |
__qAlignedNew(newobj, instsize); /* OBJECT ALLOCATION */ |
|
2418 |
__UNPROTECT_CONTEXT__ |
|
2419 |
if (newobj == nil) { |
|
2420 |
break; |
|
2421 |
} |
|
2422 |
__InstPtr(newobj)->o_class = self; |
|
2423 |
__qSTORE(newobj, self); |
|
2424 |
||
2425 |
if (nInstVars) { |
|
788
e80f1c42b87b
dont use memset4 if its undefined
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2426 |
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4) || defined(FAST_MEMSET4) |
12094 | 2427 |
memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars); |
1 | 2428 |
#else |
3920
0c1b9b2fa23b
added longlong indexed instvars;
Claus Gittinger <cg@exept.de>
parents:
3882
diff
changeset
|
2429 |
# if defined(FAST_MEMSET) |
12094 | 2430 |
/* |
2431 |
* knowing that nil is 0 |
|
2432 |
*/ |
|
2433 |
memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE); |
|
1 | 2434 |
# else |
12094 | 2435 |
op = __InstPtr(newobj)->i_instvars; |
2436 |
do { |
|
2437 |
*op++ = nil; |
|
2438 |
} while (--nInstVars); |
|
1 | 2439 |
# endif |
2440 |
#endif |
|
12094 | 2441 |
} |
2442 |
RETURN ( newobj ); |
|
2443 |
} |
|
2444 |
break; |
|
2445 |
} |
|
2446 |
} |
|
1 | 2447 |
} |
68 | 2448 |
%}. |
2449 |
" |
|
2450 |
arrive here if something went wrong ... |
|
2451 |
figure out what it was |
|
2452 |
" |
|
11 | 2453 |
|
1 | 2454 |
(anInteger isMemberOf:SmallInteger) ifFalse:[ |
12094 | 2455 |
" |
2456 |
the argument is either not an integer, |
|
2457 |
or a LargeInteger (which means that its definitely too big) |
|
2458 |
" |
|
2459 |
self error:'argument to new: must be Integer' mayProceed:true. |
|
2460 |
^ nil |
|
68 | 2461 |
]. |
2462 |
(anInteger < 0) ifTrue:[ |
|
12094 | 2463 |
" |
2464 |
the argument is negative, |
|
2465 |
" |
|
2466 |
self error:'bad (negative) argument to new:'. |
|
2467 |
^ nil |
|
68 | 2468 |
]. |
2469 |
self isVariable ifFalse:[ |
|
12094 | 2470 |
" |
2471 |
this class does not have any indexed instance variables |
|
2472 |
" |
|
2473 |
self error:'class has no indexed instvars - cannot create with new:'. |
|
2474 |
^ nil |
|
68 | 2475 |
]. |
2476 |
" |
|
2477 |
memory allocation failed. |
|
2478 |
When we arrive here, there was no memory, even after |
|
12094 | 2479 |
a garbage collect. |
2480 |
This means, that the VM wanted to get some more memory from the |
|
165 | 2481 |
Operatingsystem, which was not kind enough to give it. |
2482 |
Bad luck - you should increase the swap space on your machine. |
|
68 | 2483 |
" |
127 | 2484 |
^ ObjectMemory allocationFailureSignal raise. |
9194 | 2485 |
! |
2486 |
||
2487 |
decodeFromLiteralArray:anArray |
|
2488 |
"create & return a new instance from information encoded in anArray." |
|
2489 |
||
2490 |
^ self new fromLiteralArrayEncoding:anArray. |
|
2491 |
||
2492 |
" |
|
2493 |
Rectangle |
|
2494 |
decodeFromLiteralArray:#(Rectangle 10 10 100 100) |
|
2495 |
" |
|
2496 |
||
2497 |
"Modified: / 28.1.1998 / 17:40:30 / cg" |
|
2370
694ebbc71f04
added #decodeFromLiteralArray: - ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2236
diff
changeset
|
2498 |
! |
694ebbc71f04
added #decodeFromLiteralArray: - ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2236
diff
changeset
|
2499 |
|
9194 | 2500 |
new |
2501 |
"return an instance of myself without indexed variables" |
|
2502 |
||
2503 |
^ self basicNew |
|
2504 |
! |
|
2505 |
||
2506 |
new:anInteger |
|
2507 |
"return an instance of myself with anInteger indexed variables" |
|
2508 |
||
2509 |
^ self basicNew:anInteger |
|
2510 |
! |
|
2511 |
||
2512 |
niceBasicNew:anInteger |
|
620 | 2513 |
"same as basicNew:anInteger, but tries to avoid long pauses |
2514 |
due to garbage collection. This method checks to see if |
|
2515 |
allocation is possible without a pause, and does a background |
|
2516 |
incremental garbage collect first if there is not enough memory |
|
12094 | 2517 |
available at the moment for fast allocation. |
2518 |
This is useful in low-priority background processes which like to |
|
620 | 2519 |
avoid disturbing any higher priority foreground process while allocating |
2520 |
big amounts of memory. Of course, using this method only makes |
|
2521 |
sense for big or huge objects (say > 200k). |
|
2522 |
||
12094 | 2523 |
EXPERIMENTAL: this is a non-standard interface and should only |
620 | 2524 |
be used for special applications. There is no guarantee, that this |
2525 |
method will be available in future ST/X releases." |
|
2526 |
||
2527 |
|size| |
|
2528 |
||
2529 |
size := self sizeOfInst:anInteger. |
|
2530 |
(ObjectMemory checkForFastNew:size) ifFalse:[ |
|
2531 |
" |
|
2532 |
incrementally collect garbage |
|
2533 |
" |
|
2534 |
ObjectMemory incrementalGC. |
|
2535 |
]. |
|
2536 |
^ self basicNew:anInteger |
|
9194 | 2537 |
! |
2538 |
||
2539 |
readFrom:aStream |
|
12094 | 2540 |
"read an objects printed representation from the argument, aStream |
2541 |
and return it. |
|
154 | 2542 |
The read object must be a kind of myself if its not, an error is raised. |
11 | 2543 |
This is the reverse operation to 'storeOn:'. |
43 | 2544 |
|
12094 | 2545 |
WARNING: storeOn: does not handle circular references and multiple |
2546 |
references to the same object. |
|
2547 |
Use #storeBinary:/readBinaryFrom: for this." |
|
2548 |
||
2549 |
^ self |
|
2550 |
readFrom:aStream |
|
2551 |
onError:[ self conversionErrorSignal |
|
2552 |
raiseErrorString:'conversion error for: ' , self name ] |
|
11 | 2553 |
|
91 | 2554 |
" |
2555 |
|s| |
|
11 | 2556 |
s := WriteStream on:String new. |
2557 |
#(1 2 3 4) storeOn:s. |
|
12094 | 2558 |
Object readFrom:(ReadStream on:s contents) |
11 | 2559 |
" |
9194 | 2560 |
! |
2561 |
||
2562 |
readFrom:aStream onError:exceptionBlock |
|
12094 | 2563 |
"read an objects printed representation from the argument, aStream |
198 | 2564 |
and return it (i.e. the stream should contain some representation of |
12094 | 2565 |
the object which was created using #storeOn:). |
198 | 2566 |
The read object must be a kind of myself if its not, the value of |
2567 |
exceptionBlock is returned. |
|
2568 |
To get any object, use 'Object readFrom:...', |
|
2569 |
To get any number, use 'Number readFrom:...' and so on. |
|
2570 |
This is the reverse operation to 'storeOn:'. |
|
2571 |
||
12094 | 2572 |
WARNING: storeOn: does not handle circular references and multiple |
2573 |
references to the same object. |
|
2574 |
Use #storeBinary:/readBinaryFrom: for this." |
|
198 | 2575 |
|
6627
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2576 |
^ [ |
12094 | 2577 |
|newObject| |
2578 |
newObject := self evaluatorClass evaluate:aStream ifFail:exceptionBlock. |
|
2579 |
(newObject isKindOf:self) ifTrue:[newObject] ifFalse:[exceptionBlock value]. |
|
6627
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2580 |
] on:Error do:exceptionBlock. |
198 | 2581 |
|
2582 |
" |
|
2583 |
|s| |
|
2584 |
s := WriteStream on:String new. |
|
2585 |
#(1 2 3 4) storeOn:s. |
|
1422 | 2586 |
Transcript showCR:( |
12094 | 2587 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
293 | 2588 |
) |
198 | 2589 |
" |
2590 |
" |
|
2591 |
|s| |
|
2592 |
s := WriteStream on:String new. |
|
2593 |
#[1 2 3 4] storeOn:s. |
|
1422 | 2594 |
Transcript showCR:( |
12094 | 2595 |
Array readFrom:(ReadStream on:s contents) onError:'not an Array' |
345 | 2596 |
) |
198 | 2597 |
" |
5842
720736f72cb4
exceptionBlock handling in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5753
diff
changeset
|
2598 |
" |
6627
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2599 |
Object readFrom:'illegal' onError:['bla'] |
685ab6f994f0
Avoid block creation in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
6596
diff
changeset
|
2600 |
String readFrom:'illegal' onError:'bla' |
5842
720736f72cb4
exceptionBlock handling in #readFrom:onError:
Stefan Vogel <sv@exept.de>
parents:
5753
diff
changeset
|
2601 |
" |
9194 | 2602 |
! |
2603 |
||
2604 |
readFromString:aString |
|
275 | 2605 |
"create an object from its printed representation. |
2606 |
For most classes, the string is expected to be in a format created by |
|
2607 |
storeOn: or storeString; however, some (Time, Date) expect a user |
|
2608 |
readable string here. |
|
2609 |
See comments in Behavior>>readFromString:onError:, |
|
2610 |
Behavior>>readFrom: and Behavior>>readFrom:onError:" |
|
11 | 2611 |
|
12094 | 2612 |
^ self |
2613 |
readFromString:aString |
|
2614 |
onError:[ self conversionErrorSignal |
|
2615 |
raiseErrorString:'expected: ' , self name ] |
|
91 | 2616 |
|
2617 |
" |
|
12094 | 2618 |
Integer readFromString:'12345678901234567890' |
2619 |
Point readFromString:'1@2' |
|
2620 |
Point readFromString:'1' |
|
91 | 2621 |
" |
198 | 2622 |
! |
2623 |
||
2624 |
readFromString:aString onError:exceptionBlock |
|
275 | 2625 |
"create an object from its printed representation. |
2626 |
Here, the string is expected to be in a format created by |
|
12094 | 2627 |
storeOn: or storeString; |
9196
a6d45629bb3b
readFromString allows for whiteSpace after reading
Claus Gittinger <cg@exept.de>
parents:
9194
diff
changeset
|
2628 |
However, some classes (Time, Date) may redefine it to expect a user readable string here. |
198 | 2629 |
See comments in Behavior>>readFrom: and Behavior>>readFrom:onError:" |
2630 |
||
8531
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2631 |
|str val| |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2632 |
|
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2633 |
str := ReadStream on:aString. |
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2634 |
val := self readFrom:str onError:[^ exceptionBlock value]. |
12094 | 2635 |
str atEnd ifFalse:[ |
2636 |
str skipSeparators. |
|
2637 |
str atEnd ifFalse:[ |
|
2638 |
^ exceptionBlock value |
|
2639 |
] |
|
9196
a6d45629bb3b
readFromString allows for whiteSpace after reading
Claus Gittinger <cg@exept.de>
parents:
9194
diff
changeset
|
2640 |
]. |
8531
2bbe01cfb56f
differenciate between readFrom: (which allows more text after read part)
Claus Gittinger <cg@exept.de>
parents:
8529
diff
changeset
|
2641 |
^ val |
198 | 2642 |
|
2643 |
" |
|
12094 | 2644 |
Integer readFromString:'12345678901234567890' |
2645 |
Integer readFromString:'abc' |
|
275 | 2646 |
Integer readFromString:'abc' onError:0 |
12094 | 2647 |
Point readFromString:'1@2' |
2648 |
Point readFromString:'0' |
|
2649 |
Point readFromString:'0' onError:[0@0] |
|
198 | 2650 |
" |
9194 | 2651 |
! |
2652 |
||
2653 |
uninitializedNew |
|
2654 |
"create an instance of myself with uninitialized contents. |
|
2655 |
For all classes except ByteArray, this is the same as #basicNew." |
|
2656 |
||
2657 |
^ self basicNew |
|
2658 |
! |
|
2659 |
||
2660 |
uninitializedNew:anInteger |
|
2661 |
"create an instance of myself with uninitialized contents. |
|
2662 |
For all classes except ByteArray, this is the same as #basicNew:." |
|
2663 |
||
2664 |
^ self basicNew:anInteger |
|
2665 |
! ! |
|
2666 |
||
2667 |
!Behavior methodsFor:'misc'! |
|
3619 | 2668 |
|
4928 | 2669 |
browse |
5727 | 2670 |
"open a browser showing the receiver" |
2671 |
||
12094 | 2672 |
self browserClass openInClass:self |
4928 | 2673 |
|
2674 |
" |
|
5546 | 2675 |
Array browserClass |
4928 | 2676 |
Array browse |
2677 |
" |
|
2678 |
! |
|
2679 |
||
8725 | 2680 |
classOperationsMenu |
2681 |
"a chance to return additional menu items for the browsers class-menu" |
|
2682 |
||
2683 |
^ nil |
|
2684 |
! |
|
2685 |
||
10667
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2686 |
iconInBrowserSymbol |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2687 |
"can be redefined for a private icon in the browser (for me and my subclasses). |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2688 |
The returned symbol must be a selector of the ToolbarIconLibrary." |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2689 |
|
12094 | 2690 |
(self isBrowserStartable) ifTrue:[ |
2691 |
self isVisualStartable ifTrue:[ |
|
2692 |
^ #visualStartableClassBrowserIcon |
|
2693 |
]. |
|
2694 |
^ #startableClassBrowserIcon |
|
2695 |
]. |
|
2696 |
self isLoaded ifFalse:[ |
|
2697 |
^ #autoloadedClassBrowserIcon |
|
2698 |
]. |
|
2699 |
||
2700 |
"/ give ruby and other special metaclasses a chance ot provide their orn icon... |
|
2701 |
^ self class iconInBrowserSymbol |
|
10667
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2702 |
|
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2703 |
"Created: / 20-07-2007 / 08:52:17 / cg" |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2704 |
! |
8d1076445237
icons in ToolbarIconLibrary
Claus Gittinger <cg@exept.de>
parents:
10605
diff
changeset
|
2705 |
|
3619 | 2706 |
sourceCodeTemplate |
2707 |
^ 'messageSelector and arguments |
|
2708 |
"method comment - purpose of message" |
|
2709 |
||
2710 |
|temporaries| |
|
2711 |
||
2712 |
statements |
|
2713 |
||
2714 |
" |
|
2715 |
example uses |
|
2716 |
" |
|
2717 |
' |
|
2718 |
||
2719 |
"Created: / 19.6.1998 / 02:14:02 / cg" |
|
2720 |
! ! |
|
2721 |
||
9194 | 2722 |
!Behavior methodsFor:'printing & storing'! |
2723 |
||
10085 | 2724 |
displayString |
2725 |
"although behaviors have no name, we return something |
|
2726 |
useful here - there are many places (inspectors) where |
|
2727 |
a classes name is asked for. |
|
2728 |
Implementing this message here allows instances of anonymous classes |
|
2729 |
to show a reasonable name." |
|
2730 |
||
2731 |
^ 'someBehavior' |
|
2732 |
! |
|
2733 |
||
9194 | 2734 |
printOn:aStream |
2735 |
aStream nextPutAll:(self name). |
|
6590 | 2736 |
! ! |
6589 | 2737 |
|
9194 | 2738 |
!Behavior methodsFor:'private-accessing'! |
2739 |
||
2740 |
flags:aNumber |
|
2741 |
"set the flags. |
|
2742 |
this method is for special uses only - there will be no recompilation |
|
12094 | 2743 |
and no change record written here; |
9194 | 2744 |
Do NOT use it." |
2745 |
||
2746 |
flags := aNumber |
|
2747 |
! |
|
620 | 2748 |
|
2749 |
instSize:aNumber |
|
2750 |
"set the instance size. |
|
2751 |
this method is for special uses only - there will be no recompilation |
|
12094 | 2752 |
and no change record written here; |
620 | 2753 |
Do NOT use it." |
2754 |
||
2755 |
instSize := aNumber |
|
2756 |
! |
|
2757 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
2758 |
primAddSelector:aSelector withMethod:newMethod |
620 | 2759 |
"add the method given by 2nd argument under the selector given by |
12094 | 2760 |
the 1st argument to the methodDictionary. |
620 | 2761 |
Does NOT flush any caches, does NOT write a change record. |
2762 |
||
2763 |
Do not use this in normal situations, strange behavior will be |
|
2764 |
the consequence. |
|
12094 | 2765 |
I.e. executing obsolete methods, since the old method will still |
620 | 2766 |
be executed out of the caches." |
2767 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
2768 |
|dict oldMethod| |
620 | 2769 |
|
2770 |
newMethod isNil ifTrue:[ |
|
12094 | 2771 |
self error:'invalid method'. |
620 | 2772 |
]. |
12094 | 2773 |
(Smalltalk |
2774 |
changeRequest:#methodInClass |
|
2775 |
with:(Array with:self with:aSelector with:oldMethod)) ifFalse:[ |
|
2776 |
^ false |
|
11578 | 2777 |
]. |
10693
d397d49e1134
changed #primAddSelector:withMethod:
Claus Gittinger <cg@exept.de>
parents:
10669
diff
changeset
|
2778 |
"/ oldMethod := self compiledMethodAt:aSelector. |
620 | 2779 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2780 |
dict := self methodDictionary. |
10693
d397d49e1134
changed #primAddSelector:withMethod:
Claus Gittinger <cg@exept.de>
parents:
10669
diff
changeset
|
2781 |
"/ oldMethod := dict at:aSelector ifAbsent:nil. |
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
2782 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
2783 |
self setMethodDictionary:(dict at:aSelector putOrAppend:newMethod). |
7123
2af84f5b1447
pre-set the methods mclass cache when adding a method
Claus Gittinger <cg@exept.de>
parents:
6968
diff
changeset
|
2784 |
newMethod mclass:self. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2785 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
2786 |
ObjectMemory flushCachesForSelector:aSelector. |
11578 | 2787 |
^ true |
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
2788 |
|
9445 | 2789 |
"Modified: / 07-06-1996 / 14:48:45 / stefan" |
10693
d397d49e1134
changed #primAddSelector:withMethod:
Claus Gittinger <cg@exept.de>
parents:
10669
diff
changeset
|
2790 |
"Modified: / 31-08-2007 / 16:53:20 / cg" |
9194 | 2791 |
! |
2792 |
||
2793 |
setMethodDictionary:dict |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2794 |
"set the receivers method dictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2795 |
Convert dict to a MethodDictionary if necessary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2796 |
Do not flush inline caches, therefore old cached methods may be executed |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2797 |
after this call" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2798 |
|
2228 | 2799 |
"/ since the only thing the VM is prepared to deal with are |
2800 |
"/ proper methodDictionaries (it cannot do another message send, to |
|
2801 |
"/ find any methods ...), we convert it here if required. |
|
2802 |
"/ No other classes instances are allowed. |
|
2803 |
||
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
2804 |
dict class ~~ MethodDictionary ifTrue:[ |
12094 | 2805 |
methodDictionary := MethodDictionary withAll:dict. |
2806 |
methodDictionary isNil ifTrue:[ |
|
2807 |
||
2808 |
"/ refuse to do this |
|
2809 |
"/ (can only happen in case of memory allocation trouble, |
|
2810 |
"/ where the allocation failed and some exception handler returned |
|
2811 |
"/ nil ...) |
|
2812 |
||
2813 |
self error:'cannot set methodDictionary to nil' mayProceed:true. |
|
2814 |
^ self. |
|
2815 |
] |
|
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
2816 |
] ifFalse:[ |
12094 | 2817 |
methodDictionary := dict. |
620 | 2818 |
]. |
1494
dab70fc90ebc
Remove old methodArray and selectorArray stuff (use MethodDictionary only).
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
2819 |
^ self. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2820 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2821 |
"Created: 5.6.1996 / 11:29:36 / stefan" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2822 |
"Modified: 12.6.1996 / 13:58:55 / stefan" |
2228 | 2823 |
"Modified: 22.1.1997 / 21:10:48 / cg" |
9194 | 2824 |
! |
2825 |
||
2826 |
setSuperclass:aClass |
|
2827 |
"set the superclass of the receiver. |
|
2828 |
this method is for special uses only - there will be no recompilation |
|
2829 |
and no change record written here. Also, if the receiver class has |
|
2830 |
already been in use, future operation of the system is not guaranteed to |
|
2831 |
be correct, since no caches are flushed. |
|
2832 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2833 |
||
2834 |
superclass := aClass |
|
2835 |
||
2836 |
"Modified: 3.3.1997 / 13:27:00 / cg" |
|
2837 |
! |
|
620 | 2838 |
|
12094 | 2839 |
setSuperclass:aClass instSize:i |
2840 |
"set some inst vars. |
|
5906 | 2841 |
this method is for special uses only - there will be no recompilation |
12094 | 2842 |
and no change record is written here. Also, if the receiver class has |
5906 | 2843 |
already been in use, future operation of the system is not guaranteed to |
2844 |
be correct, since no caches are flushed. |
|
2845 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2846 |
||
2847 |
self setSuperclass:aClass. |
|
2848 |
instSize := i. |
|
2849 |
! |
|
2850 |
||
9194 | 2851 |
setSuperclass:aClass methodDictionary:d instSize:i flags:f |
12094 | 2852 |
"set some inst vars. |
9194 | 2853 |
this method is for special uses only - there will be no recompilation |
12094 | 2854 |
and no change record is written here. Also, if the receiver class has |
9194 | 2855 |
already been in use, future operation of the system is not guaranteed to |
2856 |
be correct, since no caches are flushed. |
|
2857 |
Therefore: do NOT use it; use Behavior>>superclass: (or flush the caches, at least)" |
|
2858 |
||
2859 |
self setSuperclass:aClass. |
|
2860 |
self setMethodDictionary:d. |
|
620 | 2861 |
instSize := i. |
2862 |
flags := f |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2863 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
2864 |
"Created: 7.6.1996 / 08:41:20 / stefan" |
2224 | 2865 |
"Modified: 22.1.1997 / 18:42:12 / cg" |
620 | 2866 |
! ! |
2867 |
||
7260 | 2868 |
!Behavior methodsFor:'private-helpers'! |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2869 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2870 |
addAllClassVarNamesTo:aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2871 |
"helper - add the name-strings of the class variables and of the class-vars |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2872 |
of all superclasses to the argument, aCollection. Return aCollection" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2873 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
2874 |
|classvars superclass| |
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
2875 |
|
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
2876 |
superclass := self superclass. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2877 |
(superclass notNil) ifTrue:[ |
12094 | 2878 |
superclass addAllClassVarNamesTo:aCollection |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2879 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2880 |
(classvars := self classVariableString) notNil ifTrue:[ |
12094 | 2881 |
aCollection addAll:(classvars asCollectionOfWords). |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2882 |
]. |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2883 |
^ aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2884 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2885 |
"Created: 16.4.1996 / 18:00:38 / cg" |
9194 | 2886 |
! |
2887 |
||
2888 |
addAllInstVarNamesTo:aCollection |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2889 |
"helper for allInstVarNames - add the name-strings of the instance variables |
12094 | 2890 |
and of the inst-vars of all superclasses to the argument, aCollection. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2891 |
Return aCollection." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2892 |
|
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
2893 |
|superclass| |
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
2894 |
|
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
2895 |
superclass := self superclass. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2896 |
(superclass notNil) ifTrue:[ |
12094 | 2897 |
superclass addAllInstVarNamesTo:aCollection |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2898 |
]. |
5512 | 2899 |
aCollection addAll:self instVarNames. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2900 |
^ aCollection |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2901 |
|
5512 | 2902 |
" |
2903 |
SortedCollection allInstVarNames |
|
2904 |
SortedCollection instVarNames |
|
2905 |
" |
|
4371
dc83645cc903
support to recursively enumerate all private classes
Claus Gittinger <cg@exept.de>
parents:
4366
diff
changeset
|
2906 |
! |
dc83645cc903
support to recursively enumerate all private classes
Claus Gittinger <cg@exept.de>
parents:
4366
diff
changeset
|
2907 |
|
9194 | 2908 |
addAllPrivateClassesTo:aCollection |
2909 |
"add all of my private classes to aCollection" |
|
2910 |
||
2911 |
self privateClassesDo:[:aPrivateClass | |
|
2912 |
aCollection add:aPrivateClass. |
|
2913 |
aPrivateClass addAllPrivateClassesTo:aCollection |
|
2914 |
]. |
|
2915 |
! ! |
|
2916 |
||
2917 |
!Behavior methodsFor:'queries'! |
|
620 | 2918 |
|
6727 | 2919 |
category |
12094 | 2920 |
"return the category of the class. |
6727 | 2921 |
Returning nil here, since Behavior does not define a category |
2922 |
(only ClassDescriptions do)." |
|
2923 |
||
2924 |
^ nil |
|
2925 |
||
2926 |
" |
|
12094 | 2927 |
Point category |
2928 |
Behavior new category |
|
6727 | 2929 |
" |
9194 | 2930 |
! |
6727 | 2931 |
|
2932 |
comment |
|
12094 | 2933 |
"return the comment of the class. |
6727 | 2934 |
Returning nil here, since Behavior does not define a category |
2935 |
(only Classes do). This allows different Behavior-like objects |
|
2936 |
(alien classes) to be handled by the browser as well." |
|
2937 |
||
9194 | 2938 |
^ nil |
2939 |
||
2940 |
"Modified: 16.4.1996 / 16:25:23 / cg" |
|
2941 |
! |
|
6727 | 2942 |
|
2943 |
definitionSelector |
|
2944 |
"return the selector with which I was (can be) defined in my superclass" |
|
2945 |
||
2946 |
^ (self firstDefinitionSelectorPart |
|
2947 |
, |
|
2948 |
'instanceVariableNames:classVariableNames:poolDictionaries:category:') asSymbol |
|
2949 |
||
2950 |
" |
|
2951 |
Object definitionSelector |
|
12094 | 2952 |
Array definitionSelector |
2953 |
ByteArray definitionSelector |
|
2954 |
FloatArray definitionSelector |
|
9194 | 2955 |
" |
2956 |
||
2957 |
"Modified: 3.3.1997 / 11:50:37 / cg" |
|
2958 |
! |
|
6727 | 2959 |
|
2960 |
definitionSelectorPrivate |
|
2961 |
"return the selector with which I was (can be) defined in my superclass |
|
2962 |
as a private class" |
|
2963 |
||
2964 |
^ (self firstDefinitionSelectorPart |
|
2965 |
, |
|
2966 |
'instanceVariableNames:classVariableNames:poolDictionaries:privateIn:') asSymbol |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2967 |
|
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2968 |
" |
12094 | 2969 |
Array definitionSelector |
2970 |
Array definitionSelectorPrivate |
|
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2971 |
" |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
2972 |
|
6727 | 2973 |
"Modified: 23.6.1997 / 10:45:57 / cg" |
620 | 2974 |
! |
2975 |
||
9194 | 2976 |
firstDefinitionSelectorPart |
6727 | 2977 |
"return the first part of the selector with which I was (can be) defined in my superclass" |
2978 |
||
2979 |
self isVariable ifFalse:[ |
|
2980 |
^ #'subclass:' |
|
2981 |
]. |
|
2982 |
self isBytes ifTrue:[ |
|
2983 |
^ #'variableByteSubclass:' |
|
2984 |
]. |
|
2985 |
self isLongs ifTrue:[ |
|
2986 |
^ #'variableLongSubclass:' |
|
2987 |
]. |
|
2988 |
self isFloats ifTrue:[ |
|
2989 |
^ #'variableFloatSubclass:' |
|
2990 |
]. |
|
2991 |
self isDoubles ifTrue:[ |
|
2992 |
^ #'variableDoubleSubclass:' |
|
2993 |
]. |
|
2994 |
self isWords ifTrue:[ |
|
2995 |
^ #'variableWordSubclass:' |
|
2996 |
]. |
|
2997 |
self isSignedWords ifTrue:[ |
|
2998 |
^ #'variableSignedWordSubclass:' |
|
2999 |
]. |
|
3000 |
self isSignedLongs ifTrue:[ |
|
3001 |
^ #'variableSignedLongSubclass:' |
|
3002 |
]. |
|
3003 |
self isSignedLongLongs ifTrue:[ |
|
3004 |
^ #'variableSignedLongLongSubclass:' |
|
3005 |
]. |
|
3006 |
self isLongLongs ifTrue:[ |
|
3007 |
^ #'variableLongLongSubclass:' |
|
3008 |
]. |
|
3009 |
^ #'variableSubclass:' |
|
9194 | 3010 |
! |
3011 |
||
3012 |
fullName |
|
3013 |
"Answer the name of the receiver, fully qualified." |
|
3014 |
||
3015 |
^ self name asString |
|
3016 |
||
3017 |
! |
|
3018 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3019 |
hasExtensions |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3020 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3021 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3022 |
"Created: / 06-08-2006 / 15:23:32 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3023 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3024 |
|
9194 | 3025 |
isBehavior |
9219 | 3026 |
"return true, if the receiver is describing another objects behavior. |
3027 |
Defined to avoid the need to use isKindOf:" |
|
9194 | 3028 |
|
3029 |
^ true |
|
3030 |
||
3031 |
" |
|
12094 | 3032 |
True isBehavior |
9194 | 3033 |
true isBehavior |
3034 |
" |
|
3035 |
! |
|
620 | 3036 |
|
10043
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3037 |
isBrowserStartable |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3038 |
^ false |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3039 |
|
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3040 |
"Created: / 06-10-2006 / 11:33:42 / cg" |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3041 |
! |
22138758483e
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
10008
diff
changeset
|
3042 |
|
6727 | 3043 |
isBuiltInClass |
3044 |
"return true if this class is known by the run-time-system. |
|
3045 |
Here, false is returned as default. |
|
3046 |
Notice, this is instance protocol, which means that any class |
|
3047 |
other than those special ones) are non-builtIn by default." |
|
3048 |
||
3049 |
^ false |
|
3050 |
||
3051 |
"Modified: 23.4.1996 / 15:55:52 / cg" |
|
9194 | 3052 |
"Created: 28.10.1996 / 15:10:02 / cg" |
3053 |
! |
|
3054 |
||
3055 |
isPrivate |
|
3056 |
"return true, if the receiver is some private class" |
|
3057 |
||
3058 |
^ self owningClass notNil |
|
3059 |
||
3060 |
"Modified: 12.10.1996 / 20:11:05 / cg" |
|
3061 |
! |
|
6727 | 3062 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3063 |
isStartableWithMain |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3064 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3065 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3066 |
"Created: / 06-08-2006 / 15:23:50 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3067 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3068 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3069 |
isStartableWithStart |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3070 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3071 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3072 |
"Created: / 06-08-2006 / 15:23:57 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3073 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3074 |
|
6727 | 3075 |
isSubclassOf:aClass |
3076 |
"return true, if I am a subclass of the argument, aClass" |
|
3077 |
||
3078 |
|theClass| |
|
3079 |
||
3080 |
theClass := superclass. |
|
3081 |
[theClass notNil] whileTrue:[ |
|
3082 |
(theClass == aClass) ifTrue:[^ true]. |
|
3083 |
%{ |
|
3084 |
if (__isBehaviorLike(theClass)) { |
|
3085 |
theClass = __ClassInstPtr(theClass)->c_superclass; |
|
3086 |
} else { |
|
3087 |
theClass = nil; |
|
3088 |
} |
|
3089 |
%}. |
|
3090 |
"/ theClass := theClass superclass. |
|
3620
e517c8b18e90
added #allInstancesWeakly for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
3619
diff
changeset
|
3091 |
]. |
9194 | 3092 |
^ false |
3093 |
||
3094 |
" |
|
12094 | 3095 |
String isSubclassOf:Collection |
3096 |
LinkedList isSubclassOf:Array |
|
9194 | 3097 |
1 isSubclassOf:Number <- will fail since 1 is no class |
12094 | 3098 |
" |
6727 | 3099 |
! |
3100 |
||
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3101 |
isVisualStartable |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3102 |
^ false |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3103 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3104 |
"Created: / 06-08-2006 / 15:23:38 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3105 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3106 |
|
6727 | 3107 |
name |
3108 |
"although behaviors have no name, we return something |
|
3109 |
useful here - there are many places (inspectors) where |
|
3110 |
a classes name is asked for. |
|
3111 |
Implementing this message here allows anonymous classes |
|
9194 | 3112 |
and instances of them to be inspected." |
3113 |
||
3114 |
^ #'anonymous Behavior' |
|
3115 |
! |
|
3116 |
||
3117 |
nameInBrowser |
|
3118 |
"return a nameString as shown in browsers" |
|
3119 |
||
3120 |
^ self name ? '?' |
|
3121 |
! |
|
6727 | 3122 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3123 |
nameWithArticle |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3124 |
"return a string consisting of classname preceeded by an article. |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3125 |
(dont expect me to write national variants for this ... :-) |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3126 |
If you have special preferences, redefine it..." |
12094 | 3127 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3128 |
|classname| |
12094 | 3129 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3130 |
classname := self name. |
9445 | 3131 |
classname isEmpty ifTrue:[ ^ 'an anonymous' ]. |
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3132 |
^ classname article , ' ' , classname |
12094 | 3133 |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3134 |
" |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3135 |
SmallInteger nameWithArticle |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3136 |
" |
9445 | 3137 |
|
3138 |
"Modified: / 16-07-2006 / 00:02:23 / cg" |
|
7331
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3139 |
! |
cd0f1492d540
code motion from ClassDescription
Claus Gittinger <cg@exept.de>
parents:
7269
diff
changeset
|
3140 |
|
6727 | 3141 |
owningClass |
3142 |
"return my owning class - nil if I am a public class" |
|
3143 |
||
3144 |
"/ this information is in the metaclass ... |
|
3145 |
||
3146 |
^ self class owningClass |
|
3147 |
||
3148 |
"Created: 15.10.1996 / 21:19:32 / cg" |
|
3149 |
"Modified: 7.11.1996 / 13:49:28 / cg" |
|
3150 |
! |
|
3151 |
||
6733
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3152 |
owningClassOrYourself |
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3153 |
"return my owning class if I am private, myself otherwise" |
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3154 |
|
9194 | 3155 |
self owningClass notNil ifTrue:[^ self topOwningClass]. |
3156 |
^ self |
|
3157 |
! |
|
6733
4f8a80a22261
added #owningClassOrYourself
Claus Gittinger <cg@exept.de>
parents:
6727
diff
changeset
|
3158 |
|
9469
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3159 |
revision |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3160 |
^ nil |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3161 |
|
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3162 |
"Created: / 03-08-2006 / 01:53:44 / cg" |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3163 |
! |
580edc421e81
support for lazy methods ceased.
Claus Gittinger <cg@exept.de>
parents:
9445
diff
changeset
|
3164 |
|
6727 | 3165 |
sourceCodeAt:aSelector |
3166 |
"return the methods source for given selector aSelector or nil. |
|
3167 |
Only methods in the receiver - not in the superclass chain are tested." |
|
3168 |
||
7676 | 3169 |
^ self sourceCodeAt:aSelector ifAbsent:nil |
6727 | 3170 |
|
3171 |
" |
|
3172 |
True sourceCodeAt:#ifTrue: |
|
3173 |
Object sourceCodeAt:#== |
|
3174 |
Behavior sourceCodeAt:#sourceCodeAt: |
|
2053 | 3175 |
" |
3176 |
! |
|
3177 |
||
7676 | 3178 |
sourceCodeAt:aSelector ifAbsent:exceptionalValue |
3179 |
"return the methods source for given selector aSelector or exceptionalValue. |
|
3180 |
Only methods in the receiver - not in the superclass chain are tested." |
|
3181 |
||
3182 |
|method| |
|
3183 |
||
3184 |
method := self compiledMethodAt:aSelector. |
|
3185 |
method isNil ifTrue:[^ exceptionalValue value]. |
|
9194 | 3186 |
^ method source |
3187 |
! |
|
7676 | 3188 |
|
6727 | 3189 |
sourceCodeManager |
12094 | 3190 |
"return the sourceCodeManager of the class. |
6727 | 3191 |
Returning nil here, since Behavior does not define any sourceCode management. |
3192 |
(only Classes do). This allows different Behavior-like objects |
|
3193 |
(alien classes) to be handled by the browser as well." |
|
3194 |
||
3195 |
^ nil |
|
3196 |
||
3197 |
"Created: 16.4.1996 / 16:26:03 / cg" |
|
9194 | 3198 |
! |
6727 | 3199 |
|
3200 |
supportsMethodCategories |
|
3201 |
"return true, if my methods are categorized. |
|
3202 |
This is a hook for the browser to allow alien classes |
|
3203 |
to be handled (aktually, this is not yet used)." |
|
3204 |
||
3205 |
^ true |
|
3206 |
||
3207 |
"Created: 30.7.1997 / 14:59:08 / cg" |
|
3208 |
"Modified: 30.7.1997 / 15:02:03 / cg" |
|
620 | 3209 |
! |
3210 |
||
6727 | 3211 |
theMetaclass |
9696 | 3212 |
"return the metaClass of the class-meta pair. |
3213 |
Here, return my metaclass object, because I am the class. |
|
3214 |
Also implemented in my metaclass, which returns itself." |
|
9194 | 3215 |
|
3216 |
^ self class |
|
3217 |
||
3218 |
"Created: / 30.1.2000 / 23:08:30 / cg" |
|
3219 |
"Modified: / 31.1.2000 / 16:16:52 / cg" |
|
3220 |
! |
|
6727 | 3221 |
|
3222 |
theNonMetaclass |
|
9696 | 3223 |
"return the nonMetaClass of the class-meta pair. |
3224 |
Here, return myself, because I am the nonMetaclass. |
|
3225 |
Also implemented in my metaclass, which also returns me." |
|
6727 | 3226 |
|
3227 |
^ self |
|
3228 |
||
3229 |
"Created: / 30.1.2000 / 23:07:59 / cg" |
|
3230 |
"Modified: / 31.1.2000 / 16:17:46 / cg" |
|
3231 |
! |
|
3232 |
||
3233 |
topOwningClass |
|
3234 |
"return my outermost owning class - nil if I am a public class" |
|
3235 |
||
3236 |
"/ this information is in the metaclass ... |
|
3237 |
||
3238 |
^ self class topOwningClass |
|
3239 |
||
3240 |
"Created: 15.10.1996 / 21:19:32 / cg" |
|
3241 |
"Modified: 3.1.1997 / 19:18:49 / cg" |
|
3242 |
! ! |
|
3243 |
||
9194 | 3244 |
!Behavior methodsFor:'queries-inheritance'! |
6727 | 3245 |
|
620 | 3246 |
allSubclasses |
3247 |
"return a collection of all subclasses (direct AND indirect) of |
|
3248 |
the receiver. There will be no specific order, in which entries |
|
10172 | 3249 |
are returned. NameSpaces are excluded from the list." |
620 | 3250 |
|
3251 |
|newColl| |
|
3252 |
||
3253 |
newColl := OrderedCollection new. |
|
3254 |
self allSubclassesDo:[:aClass | |
|
12094 | 3255 |
(aClass isRealNameSpace) ifFalse:[ |
3256 |
newColl add:aClass |
|
3257 |
] |
|
620 | 3258 |
]. |
3259 |
^ newColl |
|
3260 |
||
3261 |
" |
|
3262 |
Collection allSubclasses |
|
3263 |
" |
|
10172 | 3264 |
|
3265 |
"Modified: / 10-11-2006 / 17:22:58 / cg" |
|
620 | 3266 |
! |
3267 |
||
3268 |
allSubclassesInOrder |
|
3269 |
"return a collection of all subclasses (direct AND indirect) of |
|
10172 | 3270 |
the receiver. Higher level subclasses will come before lower ones. |
3271 |
NameSpaces are excluded from the list." |
|
620 | 3272 |
|
3273 |
|newColl| |
|
3274 |
||
3275 |
newColl := OrderedCollection new. |
|
3276 |
self allSubclassesInOrderDo:[:aClass | |
|
12094 | 3277 |
(aClass isRealNameSpace) ifFalse:[ |
3278 |
newColl add:aClass |
|
3279 |
] |
|
620 | 3280 |
]. |
3281 |
^ newColl |
|
3282 |
||
3283 |
" |
|
9194 | 3284 |
Collection allSubclassesInOrder |
3285 |
" |
|
10172 | 3286 |
|
3287 |
"Modified: / 10-11-2006 / 17:23:06 / cg" |
|
9194 | 3288 |
! |
620 | 3289 |
|
3290 |
allSuperclasses |
|
3291 |
"return a collection of the receivers accumulated superclasses" |
|
3292 |
||
3293 |
|aCollection theSuperClass| |
|
3294 |
||
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
3295 |
theSuperClass := self superclass. |
4451 | 3296 |
theSuperClass isNil ifTrue:[ |
12094 | 3297 |
^ #() |
4451 | 3298 |
]. |
3299 |
aCollection := OrderedCollection new. |
|
3300 |
[theSuperClass notNil] whileTrue:[ |
|
12094 | 3301 |
aCollection add:theSuperClass. |
3302 |
theSuperClass := theSuperClass superclass |
|
620 | 3303 |
]. |
3304 |
^ aCollection |
|
3305 |
||
3306 |
" |
|
12094 | 3307 |
String allSuperclasses |
9194 | 3308 |
" |
3309 |
! |
|
620 | 3310 |
|
3311 |
canBeSubclassed |
|
3312 |
"return true, if its allowed to create subclasses of the receiver. |
|
3313 |
This method is redefined in SmallInteger and UndefinedObject, since |
|
3314 |
instances are detected by their pointer-fields, i.e. they do not have |
|
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
3315 |
a class entry (you don't have to understand this :-)" |
10 | 3316 |
|
3317 |
^ true |
|
3318 |
! |
|
3319 |
||
3641 | 3320 |
commonSuperclass:aClass |
3321 |
"Return the common superclass of the receiver and aClass. |
|
6754
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3322 |
Assumes that there is a common superclass of any two classes. |
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3323 |
(might return nil, if either the receiver or the argument inherit from nil)" |
3641 | 3324 |
|
3325 |
(aClass includesBehavior:self) ifTrue:[^ self]. |
|
3326 |
(self inheritsFrom:aClass) ifTrue:[^ aClass]. |
|
6754
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3327 |
superclass isNil ifTrue:[^ nil]. |
d9c0f178f091
commonSuperClass: care for nil subclass
Claus Gittinger <cg@exept.de>
parents:
6733
diff
changeset
|
3328 |
^ superclass commonSuperclass:aClass |
3641 | 3329 |
|
3330 |
" |
|
12094 | 3331 |
Integer commonSuperclass:Fraction |
3332 |
SmallInteger commonSuperclass:Fraction |
|
3333 |
View commonSuperclass:Form |
|
3334 |
View commonSuperclass:Image |
|
3335 |
View commonSuperclass:View |
|
3336 |
Integer commonSuperclass:Autoload |
|
3337 |
Integer commonSuperclass:Object |
|
3641 | 3338 |
" |
3339 |
||
3340 |
"Modified: / 10.7.1998 / 02:13:04 / cg" |
|
9194 | 3341 |
! |
3342 |
||
3343 |
hasMultipleSuperclasses |
|
12094 | 3344 |
"Return true, if this class inherits from other classes |
3345 |
(beside its primary superclass). |
|
3346 |
This method is a preparation for a future multiple inheritance extension |
|
9194 | 3347 |
- currently it is not supported by the VM" |
3348 |
||
3349 |
^ false |
|
3350 |
! |
|
6727 | 3351 |
|
3352 |
inheritsFrom:aClass |
|
3353 |
"return true, if the receiver inherits methods from aClass; |
|
3354 |
i.e. if aClass is on the receivers superclass chain." |
|
3355 |
||
3356 |
^ self isSubclassOf:aClass |
|
620 | 3357 |
|
293 | 3358 |
" |
6727 | 3359 |
True inheritsFrom:Object |
3360 |
LinkedList inheritsFrom:Array |
|
293 | 3361 |
" |
1088 | 3362 |
|
9194 | 3363 |
"Modified: 19.6.1997 / 18:13:21 / cg" |
3364 |
! |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3365 |
|
6727 | 3366 |
subclasses |
3367 |
"return a collection of the direct subclasses of the receiver" |
|
3368 |
||
3369 |
|newColl| |
|
3370 |
||
3371 |
newColl := OrderedCollection new. |
|
3372 |
self subclassesDo:[:aClass | |
|
12094 | 3373 |
newColl add:aClass |
6727 | 3374 |
]. |
7435
c5afb1b0fd1b
Prepare for moving of SubclassInfo to subclass instcar in Class
Stefan Vogel <sv@exept.de>
parents:
7358
diff
changeset
|
3375 |
^ newColl. |
6727 | 3376 |
! |
3377 |
||
3378 |
superclasses |
|
9194 | 3379 |
"return a collection of the receivers immediate superclasses. |
12094 | 3380 |
This method is a preparation for a future multiple inheritance extension |
9194 | 3381 |
- currently it is not supported by the VM" |
3382 |
||
3383 |
^ Array with:self superclass. |
|
3384 |
||
3385 |
" |
|
12094 | 3386 |
String superclasses |
9194 | 3387 |
" |
3388 |
! |
|
6727 | 3389 |
|
3390 |
withAllSubclasses |
|
12094 | 3391 |
"return a collection containing the receiver and |
6727 | 3392 |
all subclasses (direct AND indirect) of the receiver" |
3393 |
||
3394 |
|coll| |
|
3395 |
||
3396 |
coll := self allSubclasses asOrderedCollection. |
|
3397 |
coll addFirst:self. |
|
3398 |
^ coll |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3399 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3400 |
" |
6727 | 3401 |
Collection withAllSubclasses |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
3402 |
" |
620 | 3403 |
! |
3404 |
||
6727 | 3405 |
withAllSuperclasses |
3406 |
"return a collection containing the receiver and all |
|
3407 |
of the receivers accumulated superclasses" |
|
3408 |
||
3409 |
|aCollection| |
|
3410 |
||
3411 |
aCollection := OrderedCollection new. |
|
3412 |
self withAllSuperclassesDo:[:cls | |
|
12094 | 3413 |
aCollection add:cls |
6727 | 3414 |
]. |
9194 | 3415 |
^ aCollection |
3416 |
||
3417 |
" |
|
12094 | 3418 |
String withAllSuperclasses |
9194 | 3419 |
" |
3420 |
! ! |
|
3421 |
||
3422 |
!Behavior methodsFor:'queries-instances'! |
|
6727 | 3423 |
|
3424 |
allDerivedInstances |
|
12094 | 3425 |
"return a collection of all instances of myself and |
6727 | 3426 |
instances of all subclasses of myself. |
3427 |
This method is going to be removed for protocol compatibility with |
|
3428 |
other STs; use allSubInstances" |
|
3429 |
||
3430 |
<resource:#obsolete> |
|
3431 |
||
3432 |
self obsoleteMethodWarning:'use #allSubInstances'. |
|
3433 |
^ self allSubInstances |
|
3434 |
||
9194 | 3435 |
"Modified: 31.7.1997 / 23:04:59 / cg" |
3436 |
! |
|
2436 | 3437 |
|
6727 | 3438 |
allInstances |
3439 |
"return a collection of all my instances" |
|
3440 |
||
3441 |
"Read the documentation on why there seem to be no |
|
3442 |
instances of SmallInteger and UndefinedObject" |
|
3443 |
||
3444 |
|coll| |
|
3445 |
||
3446 |
coll := OrderedCollection new:100. |
|
3447 |
self allInstancesDo:[:anObject | |
|
3448 |
coll add:anObject |
|
3449 |
]. |
|
12094 | 3450 |
^ coll |
2713 | 3451 |
|
3452 |
" |
|
6727 | 3453 |
ScrollBar allInstances |
2713 | 3454 |
" |
6727 | 3455 |
! |
3456 |
||
3457 |
allInstancesWeakly:doWeakly |
|
3458 |
"return a collection of all my instances. |
|
3459 |
If weakly is true, a weak collection is returned." |
|
3460 |
||
3461 |
"Read the documentation on why there seem to be no |
|
3462 |
instances of SmallInteger and UndefinedObject" |
|
3463 |
||
3464 |
|coll| |
|
3465 |
||
3466 |
coll := self allInstances. |
|
3467 |
doWeakly ifTrue:[ |
|
9194 | 3468 |
coll := WeakArray withAll:coll |
3469 |
]. |
|
3470 |
^ coll |
|
3471 |
||
3472 |
"Created: / 19.6.1998 / 02:17:20 / cg" |
|
3473 |
! |
|
6727 | 3474 |
|
3475 |
allSubInstances |
|
12094 | 3476 |
"return a collection of all instances of myself and |
6727 | 3477 |
instances of all subclasses of myself." |
3478 |
||
3479 |
|coll| |
|
3480 |
||
3481 |
coll := OrderedCollection new:100. |
|
3482 |
self allSubInstancesDo:[:anObject | |
|
3483 |
(anObject isKindOf:self) ifTrue:[ |
|
3484 |
coll add:anObject |
|
3485 |
] |
|
3486 |
]. |
|
12094 | 3487 |
^ coll |
6727 | 3488 |
|
3489 |
" |
|
3490 |
View allSubInstances |
|
3491 |
" |
|
2713 | 3492 |
! |
3493 |
||
10669 | 3494 |
anyInstance |
3495 |
"return any of my instances; raise an error, if there is none" |
|
3496 |
||
3497 |
"Read the documentation on why there seem to be no |
|
3498 |
instances of SmallInteger and UndefinedObject" |
|
3499 |
||
3500 |
self allInstancesDo:[:anObject | ^ anObject]. |
|
3501 |
self errorNotFound |
|
3502 |
||
3503 |
" |
|
3504 |
ScrollBar anyInstance |
|
3505 |
SmallInteger anyInstance |
|
3506 |
" |
|
3507 |
||
3508 |
"Created: / 24-07-2007 / 06:12:27 / cg" |
|
3509 |
! |
|
3510 |
||
620 | 3511 |
derivedInstanceCount |
3512 |
"return the number of instances of myself and of subclasses" |
|
3513 |
||
3514 |
|count| |
|
3515 |
||
3516 |
count := 0. |
|
3517 |
ObjectMemory allObjectsDo:[:anObject | |
|
3518 |
(anObject isKindOf:self) ifTrue:[ |
|
3519 |
count := count + 1 |
|
3520 |
] |
|
3521 |
]. |
|
3522 |
^ count |
|
3523 |
||
293 | 3524 |
" |
620 | 3525 |
View derivedInstanceCount |
9194 | 3526 |
SequenceableCollection derivedInstanceCount |
3527 |
Object derivedInstanceCount |
|
3528 |
" |
|
3529 |
! |
|
983 | 3530 |
|
3531 |
hasDerivedInstances |
|
3532 |
"return true, if there are any instances of myself or of any subclass" |
|
3533 |
||
3534 |
"Read the documentation on why there seem to be no |
|
3535 |
instances of SmallInteger and UndefinedObject" |
|
3536 |
||
3537 |
ObjectMemory allObjectsDo:[:anObject | |
|
3538 |
(anObject isKindOf:self) ifTrue:[ |
|
3539 |
^ true |
|
3540 |
] |
|
3541 |
]. |
|
3542 |
^ false |
|
3543 |
||
3544 |
" |
|
9194 | 3545 |
Object hasDerivedInstances - certainly true |
3546 |
SharedQueue hasDerivedInstances |
|
3547 |
" |
|
3548 |
! |
|
620 | 3549 |
|
2674
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3550 |
hasImmediateInstances |
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3551 |
"return true if this class has immediate instances |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3552 |
i.e. if the instances are represented in the pointer itself and |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3553 |
no real object header/storage is used for the object. |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
3554 |
Redefined in classes which have so (only SmallInteger and UndefinedObject)" |
2674
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3555 |
|
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3556 |
^ false |
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3557 |
|
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3558 |
"Created: 3.6.1997 / 12:01:05 / cg" |
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3559 |
! |
5278213b500c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2666
diff
changeset
|
3560 |
|
620 | 3561 |
hasInstances |
3562 |
"return true, if there are any instances of myself" |
|
3563 |
||
3564 |
"Read the documentation on why there seem to be no |
|
3565 |
instances of SmallInteger and UndefinedObject" |
|
3566 |
||
3567 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
3568 |
"/ (anObject class == self) ifTrue:[ |
|
3569 |
"/ ^ true |
|
3570 |
"/ ] |
|
3571 |
"/ ]. |
|
983 | 3572 |
|
620 | 3573 |
ObjectMemory allInstancesOf:self do:[:anObject | |
983 | 3574 |
^ true |
620 | 3575 |
]. |
3576 |
^ false |
|
3577 |
||
293 | 3578 |
" |
620 | 3579 |
Object hasInstances |
3580 |
SequenceableCollection hasInstances |
|
3581 |
Float hasInstances |
|
3582 |
SmallInteger hasInstances |
|
293 | 3583 |
" |
9194 | 3584 |
! |
3585 |
||
3586 |
hasSharedInstances |
|
3587 |
"return true if this class has shared instances, that is, instances |
|
3588 |
with the same value are identical. |
|
3589 |
False is returned here, only redefined in classes which have unified |
|
3590 |
instances (or should be treated so)." |
|
3591 |
||
3592 |
^ false |
|
3593 |
! |
|
3594 |
||
3595 |
instanceCount |
|
6727 | 3596 |
"return the number of instances of myself." |
3597 |
||
3598 |
"Read the documentation on why there seem to be no |
|
3599 |
instances of SmallInteger and UndefinedObject" |
|
3600 |
||
3601 |
|count| |
|
3602 |
||
3603 |
count := 0. |
|
3604 |
"/ ObjectMemory allObjectsDo:[:anObject | |
|
3605 |
"/ (anObject class == self) ifTrue:[ |
|
3606 |
"/ count := count + 1 |
|
3607 |
"/ ] |
|
3608 |
"/ ]. |
|
3609 |
||
3610 |
ObjectMemory allInstancesOf:self do:[:anObject | |
|
3611 |
count := count + 1 |
|
3612 |
]. |
|
3613 |
^ count |
|
3614 |
||
3615 |
" |
|
3616 |
View instanceCount |
|
3617 |
Object instanceCount |
|
3618 |
Float instanceCount |
|
3619 |
SequenceableCollection instanceCount |
|
3620 |
SmallInteger instanceCount .... mhmh - hear, hear |
|
3621 |
" |
|
9194 | 3622 |
! ! |
3623 |
||
3624 |
!Behavior methodsFor:'queries-instlayout'! |
|
6727 | 3625 |
|
3626 |
elementByteSize |
|
9194 | 3627 |
"for bit-like containers, return the number of bytes stored per |
3628 |
element. For pointer indexed classes, 0 is returned" |
|
3629 |
||
3630 |
self isBitsExtended ifTrue:[ |
|
3631 |
self isBytes ifTrue:[^ 1]. |
|
3632 |
self isWords ifTrue:[^ 2]. |
|
3633 |
self isSignedWords ifTrue:[^ 2]. |
|
3634 |
self isLongs ifTrue:[^ 4]. |
|
3635 |
self isSignedLongs ifTrue:[^ 4]. |
|
3636 |
self isLongLongs ifTrue:[^ 8]. |
|
3637 |
self isSignedLongLongs ifTrue:[^ 8]. |
|
3638 |
]. |
|
3639 |
self isFloats ifTrue:[^ 4]. |
|
3640 |
self isDoubles ifTrue:[^ 8]. |
|
3641 |
||
3642 |
^ 0 |
|
3643 |
||
3644 |
! |
|
6727 | 3645 |
|
3646 |
isBits |
|
3647 |
"return true, if instances have indexed byte or short instance variables. |
|
3648 |
Ignore long, float and double arrays, since ST-80 code using isBits are probably |
|
3649 |
not prepared to handle them correctly." |
|
3650 |
||
3651 |
%{ /* NOCONTEXT */ |
|
3652 |
||
3653 |
REGISTER int what; |
|
3654 |
||
3655 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
|
3656 |
RETURN (( (what == __MASKSMALLINT(BYTEARRAY)) |
|
12094 | 3657 |
|| (what == __MASKSMALLINT(WORDARRAY))) ? true : false ); |
6727 | 3658 |
%}. |
9194 | 3659 |
^ self isBytes or:[self isWords] |
3660 |
! |
|
3661 |
||
3662 |
isBitsExtended |
|
3663 |
"return true, if instances have indexed byte, short, long or longlong instance variables. |
|
3664 |
Ignore float and double arrays. |
|
3665 |
This is really the thing we expect #isBits to return, however, #isBits |
|
3666 |
is defined to only return true for byte- and wordIndexed instances. |
|
3667 |
This avoids confusion of ST80 code, which is not prepared for long or longLong |
|
3668 |
instVars." |
|
3669 |
||
3670 |
%{ /* NOCONTEXT */ |
|
3671 |
||
3672 |
REGISTER int what; |
|
3673 |
||
3674 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
|
6727 | 3675 |
RETURN (( (what == __MASKSMALLINT(BYTEARRAY)) |
3676 |
|| (what == __MASKSMALLINT(WORDARRAY)) |
|
3677 |
|| (what == __MASKSMALLINT(SWORDARRAY)) |
|
3678 |
|| (what == __MASKSMALLINT(LONGARRAY)) |
|
3679 |
|| (what == __MASKSMALLINT(SLONGARRAY)) |
|
3680 |
|| (what == __MASKSMALLINT(LONGLONGARRAY)) |
|
12094 | 3681 |
|| (what == __MASKSMALLINT(SLONGLONGARRAY))) ? true : false ); |
6727 | 3682 |
%} |
3683 |
! |
|
3684 |
||
3685 |
isBytes |
|
3686 |
"return true, if instances have indexed byte instance variables" |
|
3687 |
||
3688 |
"this could also be defined as: |
|
3689 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagBytes |
|
3690 |
" |
|
3691 |
%{ /* NOCONTEXT */ |
|
3692 |
||
12094 | 3693 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(BYTEARRAY)) ? true : false ); |
6727 | 3694 |
%} |
3695 |
! |
|
3696 |
||
3697 |
isDoubles |
|
3698 |
"return true, if instances have indexed double instance variables" |
|
3699 |
||
3700 |
"this could also be defined as: |
|
3701 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagDoubles |
|
3702 |
" |
|
3703 |
%{ /* NOCONTEXT */ |
|
3704 |
||
12094 | 3705 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(DOUBLEARRAY)) ? true : false ); |
9194 | 3706 |
%} |
3707 |
! |
|
6727 | 3708 |
|
3709 |
isFixed |
|
3710 |
"return true, if instances do not have indexed instance variables" |
|
3711 |
||
3712 |
"this could also be defined as: |
|
12094 | 3713 |
^ self isVariable not |
6727 | 3714 |
" |
3715 |
||
3716 |
%{ /* NOCONTEXT */ |
|
3717 |
||
12094 | 3718 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? false : true ); |
6727 | 3719 |
%}. |
3720 |
^ self isVariable not |
|
3721 |
! |
|
3722 |
||
3723 |
isFloats |
|
9194 | 3724 |
"return true, if instances have indexed float instance variables" |
6727 | 3725 |
|
3726 |
"this could also be defined as: |
|
9194 | 3727 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagFloats |
6727 | 3728 |
" |
9194 | 3729 |
%{ /* NOCONTEXT */ |
3730 |
||
12094 | 3731 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(FLOATARRAY)) ? true : false ); |
9194 | 3732 |
%} |
3733 |
! |
|
3734 |
||
3735 |
isFloatsOrDoubles |
|
3736 |
"return true, if instances have indexed float or double instance variables" |
|
3737 |
||
3738 |
%{ /* NOCONTEXT */ |
|
3739 |
||
3740 |
int what; |
|
3741 |
||
3742 |
what = (INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK); |
|
3743 |
RETURN (( (what == __MASKSMALLINT(FLOATARRAY)) |
|
12094 | 3744 |
|| (what == __MASKSMALLINT(DOUBLEARRAY))) ? true : false ); |
9194 | 3745 |
%}. |
3746 |
^ self isFloats or:[self isDoubles] |
|
3747 |
||
3748 |
" |
|
12094 | 3749 |
(Object new) class isFloatsOrDoubles |
3750 |
(Point new) class isFloatsOrDoubles |
|
3751 |
(Array new) class isFloatsOrDoubles |
|
3752 |
(ByteArray new) class isFloatsOrDoubles |
|
3753 |
(FloatArray new) class isFloatsOrDoubles |
|
3754 |
(DoubleArray new) class isFloatsOrDoubles |
|
6727 | 3755 |
" |
3756 |
! |
|
3757 |
||
3758 |
isLongLongs |
|
3759 |
"return true, if instances have indexed long-long instance variables (8 byte uints)" |
|
3760 |
||
3761 |
%{ /* NOCONTEXT */ |
|
3762 |
||
3763 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGLONGARRAY)) ? true : false ); |
|
3764 |
%} |
|
3765 |
! |
|
3766 |
||
3767 |
isLongs |
|
9194 | 3768 |
"return true, if instances have indexed long instance variables (4 byte uints)" |
3769 |
||
3770 |
%{ /* NOCONTEXT */ |
|
3771 |
||
12094 | 3772 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(LONGARRAY)) ? true : false ); |
9194 | 3773 |
%} |
3774 |
! |
|
3775 |
||
3776 |
isPointers |
|
12094 | 3777 |
"return true, if instances have pointer instance variables |
9194 | 3778 |
i.e. are either non-indexed or have indexed pointer variables" |
3779 |
||
3780 |
"QUESTION: should we ignore WeakPointers ?" |
|
6727 | 3781 |
|
3782 |
%{ /* NOCONTEXT */ |
|
3783 |
||
9194 | 3784 |
REGISTER int flags; |
3785 |
||
3786 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
3787 |
switch (flags) { |
|
3788 |
default: |
|
3789 |
/* normal objects */ |
|
3790 |
RETURN ( true ); |
|
3791 |
||
3792 |
case BYTEARRAY: |
|
3793 |
case WORDARRAY: |
|
3794 |
case LONGARRAY: |
|
3795 |
case SWORDARRAY: |
|
3796 |
case SLONGARRAY: |
|
3797 |
case SLONGLONGARRAY: |
|
3798 |
case LONGLONGARRAY: |
|
6727 | 3799 |
case FLOATARRAY: |
3800 |
case DOUBLEARRAY: |
|
3801 |
RETURN (false ); |
|
3802 |
||
3803 |
case WKPOINTERARRAY: |
|
3804 |
/* what about those ? */ |
|
3805 |
RETURN (true ); |
|
3806 |
} |
|
3807 |
%} |
|
3808 |
! |
|
3809 |
||
3810 |
isSignedLongLongs |
|
3811 |
"return true, if instances have indexed signed long-long instance variables (8 byte ints)" |
|
3812 |
||
3813 |
%{ /* NOCONTEXT */ |
|
3814 |
||
3815 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(SLONGLONGARRAY)) ? true : false ); |
|
3816 |
%} |
|
3817 |
! |
|
3818 |
||
3819 |
isSignedLongs |
|
9194 | 3820 |
"return true, if instances have indexed signed long instance variables (4 byte ints)" |
3821 |
||
3822 |
%{ /* NOCONTEXT */ |
|
3823 |
||
3824 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(SLONGARRAY)) ? true : false ); |
|
3825 |
%} |
|
3826 |
! |
|
6727 | 3827 |
|
3828 |
isSignedWords |
|
3829 |
"return true, if instances have indexed signed short instance variables" |
|
3830 |
||
3831 |
%{ /* NOCONTEXT */ |
|
3832 |
||
3833 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(SWORDARRAY)) ? true : false ); |
|
3834 |
%} |
|
3835 |
! |
|
3836 |
||
3837 |
isVariable |
|
3838 |
"return true, if instances have indexed instance variables" |
|
3839 |
||
3840 |
"this could also be defined as: |
|
9194 | 3841 |
^ (flags bitAnd:(Behavior maskIndexType)) ~~ 0 |
3842 |
" |
|
3843 |
||
3844 |
%{ /* NOCONTEXT */ |
|
3845 |
||
12094 | 3846 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) ? true : false ); |
9194 | 3847 |
%} |
3848 |
! |
|
6727 | 3849 |
|
3850 |
isWeakPointers |
|
3851 |
"return true, if instances have weak pointer instance variables" |
|
3852 |
||
3853 |
%{ /* NOCONTEXT */ |
|
3854 |
||
3855 |
REGISTER int flags; |
|
3856 |
||
3857 |
flags = __intVal(__INST(flags)) & ARRAYMASK; |
|
3858 |
if (flags == WKPOINTERARRAY) { |
|
12094 | 3859 |
RETURN ( true ); |
6727 | 3860 |
} |
3861 |
%}. |
|
3862 |
^ false |
|
3863 |
! |
|
3864 |
||
3865 |
isWords |
|
3866 |
"return true, if instances have indexed short instance variables" |
|
3867 |
||
3868 |
"this could also be defined as: |
|
9194 | 3869 |
^ (flags bitAnd:(Behavior maskIndexType)) == Behavior flagWords |
3870 |
" |
|
3871 |
%{ /* NOCONTEXT */ |
|
3872 |
||
12094 | 3873 |
RETURN ( (((INT)(__INST(flags)) & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(WORDARRAY)) ? true : false ); |
6727 | 3874 |
%} |
9194 | 3875 |
! |
3876 |
||
3877 |
sizeOfInst:n |
|
6727 | 3878 |
"return the number of bytes required for an instance of |
12094 | 3879 |
myself with n indexed instance variables. The argument n |
6727 | 3880 |
should be zero for classes without indexed instance variables. |
3881 |
See Behavior>>niceNew: for an application of this." |
|
3882 |
||
3883 |
|nInstvars| |
|
3884 |
||
3885 |
nInstvars := self instSize. |
|
3886 |
%{ |
|
8910 | 3887 |
INT nBytes; |
6727 | 3888 |
|
12094 | 3889 |
nBytes = __intVal(nInstvars) * sizeof(OBJ) + OHDR_SIZE; |
6727 | 3890 |
if (__isSmallInteger(n)) { |
3891 |
int nIndex; |
|
3892 |
||
3893 |
nIndex = __intVal(n); |
|
3894 |
switch (__intVal(__INST(flags)) & ARRAYMASK) { |
|
3895 |
case BYTEARRAY: |
|
3896 |
nBytes += nIndex; |
|
3897 |
if (nBytes & (__ALIGN__ - 1)) { |
|
3898 |
nBytes = (nBytes & ~(__ALIGN__ - 1)) + __ALIGN__; |
|
3899 |
} |
|
3900 |
break; |
|
3901 |
||
3902 |
case WORDARRAY: |
|
3903 |
case SWORDARRAY: |
|
3904 |
nBytes += nIndex * 2; |
|
3905 |
if (nBytes & (__ALIGN__ - 1)) { |
|
3906 |
nBytes = (nBytes & ~(__ALIGN__ - 1)) + __ALIGN__; |
|
3907 |
} |
|
9194 | 3908 |
break; |
3909 |
||
3910 |
case LONGARRAY: |
|
3911 |
case SLONGARRAY: |
|
3912 |
nBytes += nIndex * 4; |
|
3913 |
break; |
|
3914 |
||
3915 |
case LONGLONGARRAY: |
|
3916 |
case SLONGLONGARRAY: |
|
3917 |
nBytes += nIndex * 8; |
|
3918 |
break; |
|
3919 |
||
3920 |
case FLOATARRAY: |
|
3921 |
nBytes += nIndex * sizeof(float); |
|
3922 |
break; |
|
3923 |
||
3924 |
case DOUBLEARRAY: |
|
3925 |
nBytes += nIndex * sizeof(double); |
|
3926 |
break; |
|
3927 |
||
3928 |
default: |
|
3929 |
nBytes += nIndex * sizeof(OBJ); |
|
3930 |
break; |
|
3931 |
} |
|
3932 |
} |
|
3933 |
RETURN (__mkSmallInteger(nBytes)); |
|
3934 |
%} |
|
3935 |
! ! |
|
3936 |
||
3937 |
!Behavior methodsFor:'queries-protocol'! |
|
6727 | 3938 |
|
3939 |
allSelectors |
|
3940 |
"return a collection of all selectors understood by the receiver; |
|
3941 |
this includes my selectors and all superclass selectors |
|
3942 |
(i.e. the receivers full protocol)" |
|
3943 |
||
3944 |
|superclass| |
|
3945 |
||
3946 |
superclass := self superclass. |
|
3947 |
superclass notNil ifTrue:[ |
|
12094 | 3948 |
^ superclass allSelectors addAll:(self selectors); yourself. |
6727 | 3949 |
]. |
3950 |
^ self selectors asIdentitySet |
|
3951 |
||
3952 |
" |
|
3953 |
Point allSelectors |
|
3954 |
View allSelectors |
|
9194 | 3955 |
Array allSelectors |
3956 |
" |
|
3957 |
! |
|
3958 |
||
3959 |
cachedLookupMethodFor:aSelector |
|
3960 |
"return the method, which would be executed if aSelector was sent to |
|
3961 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
3962 |
and all of its superclasses are searched for aSelector. |
|
3963 |
Return the method, or nil if instances do not understand aSelector. |
|
3964 |
This interface provides exactly the same information as #lookupMethodFor:, |
|
12094 | 3965 |
but uses the lookup-cache in the VM for faster search. |
9194 | 3966 |
However, keep in mind, that doing a lookup through the cache also adds new |
12094 | 3967 |
entries and can thus slow down the system by polluting the cache with |
6727 | 3968 |
irrelevant entries. (do NOT loop over all objects calling this method). |
3969 |
Does NOT (currently) handle MI" |
|
3970 |
||
3971 |
%{ /* NOCONTEXT */ |
|
3972 |
RETURN ( __lookup(self, aSelector) ); |
|
3973 |
%} |
|
3974 |
||
3975 |
" |
|
3976 |
String cachedLookupMethodFor:#= |
|
3977 |
String cachedLookupMethodFor:#asOrderedCollection |
|
3978 |
" |
|
3979 |
! |
|
3980 |
||
3981 |
canUnderstand:aSelector |
|
9194 | 3982 |
"return true, if the receiver or one of its superclasses implements aSelector. |
3983 |
(i.e. true if my instances understand aSelector)" |
|
3984 |
||
3985 |
^ (self lookupMethodFor:aSelector) notNil |
|
3986 |
||
3987 |
" |
|
3988 |
True canUnderstand:#ifTrue: |
|
3989 |
True canUnderstand:#== |
|
3990 |
True canUnderstand:#do: |
|
3991 |
" |
|
3992 |
! |
|
6727 | 3993 |
|
3994 |
compiledMethodAt:aSelector |
|
3995 |
"return the method for given selector aSelector or nil. |
|
3996 |
Only methods in the receiver - not in the superclass chain are tested." |
|
3997 |
||
3998 |
^ self compiledMethodAt:aSelector ifAbsent:nil |
|
3999 |
||
4000 |
" |
|
4001 |
Object compiledMethodAt:#== |
|
4002 |
(Object compiledMethodAt:#==) category |
|
4003 |
" |
|
4004 |
||
4005 |
"Modified: / 7.6.1996 / 14:43:32 / stefan" |
|
4006 |
"Modified: / 27.10.1997 / 20:18:55 / cg" |
|
4007 |
! |
|
4008 |
||
4009 |
compiledMethodAt:aSelector ifAbsent:exceptionValue |
|
4010 |
"return the method for given selector aSelector or the value |
|
4011 |
of exceptionValue if not present. |
|
4012 |
Only methods in the receiver - not in the superclass chain are tested." |
|
4013 |
||
4014 |
|dict| |
|
4015 |
||
4016 |
dict := self methodDictionary. |
|
4017 |
dict isNil ifTrue:[ |
|
4018 |
('Behavior [warning]: nil methodDictionary in ' , self name printString) errorPrintCR. |
|
4019 |
^ exceptionValue value |
|
4020 |
]. |
|
4021 |
||
4022 |
^ dict at:aSelector ifAbsent:exceptionValue |
|
4023 |
||
4024 |
" |
|
4025 |
Object compiledMethodAt:#== |
|
4026 |
(Object compiledMethodAt:#==) category |
|
4027 |
" |
|
4028 |
||
4029 |
"Modified: / 7.6.1996 / 14:43:32 / stefan" |
|
4030 |
"Modified: / 10.1.1997 / 17:27:21 / cg" |
|
4031 |
"Created: / 27.10.1997 / 20:18:28 / cg" |
|
9194 | 4032 |
! |
4033 |
||
4034 |
containsMethod:aMethod |
|
4035 |
"Return true, if the argument, aMethod is a method of myself" |
|
4036 |
||
4037 |
|dict| |
|
4038 |
||
12094 | 4039 |
dict := self methodDictionary. |
9194 | 4040 |
dict isNil ifTrue:[^ false]. "degenerated class" |
4041 |
^ (dict keyAtValue:aMethod ifAbsent:[0]) ~~ 0 |
|
4042 |
||
4043 |
"Modified: 12.6.1996 / 13:33:53 / stefan" |
|
4044 |
! |
|
6727 | 4045 |
|
620 | 4046 |
hasMethods |
4047 |
"return true, if there are any (local) methods in this class" |
|
4048 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4049 |
^ (self methodDictionary size ~~ 0) |
620 | 4050 |
|
293 | 4051 |
" |
620 | 4052 |
True hasMethods |
4053 |
True class hasMethods |
|
4054 |
" |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4055 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4056 |
"Modified: 7.6.1996 / 15:43:09 / stefan" |
620 | 4057 |
! |
4058 |
||
4059 |
implements:aSelector |
|
4060 |
"return true, if the receiver implements aSelector. |
|
4061 |
(i.e. implemented in THIS class - NOT in a superclass). |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4062 |
This is semantically equivalent to includesSelector: (which is ST/80/Squeak compatibility). |
983 | 4063 |
|
4064 |
Caveat: |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4065 |
This simply checks for the selector being present in the classes |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4066 |
selector table - therefore, it does not care for ignoredMethods. |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4067 |
(but: you should not use this method for protocol-testing, anyway). |
983 | 4068 |
|
4069 |
Hint: |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4070 |
Dont use this method to check if someone responds to a message - |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4071 |
use #canUnderstand: on the class or #respondsTo: on the instance |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4072 |
to do this." |
983 | 4073 |
|
4074 |
^ self includesSelector:aSelector |
|
620 | 4075 |
|
4076 |
" |
|
983 | 4077 |
notice: this is class protocol |
4078 |
||
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4079 |
True includesSelector:#ifTrue: |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4080 |
True includesSelector:#== |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4081 |
|
12094 | 4082 |
True implements:#ifTrue: |
4083 |
True implements:#== |
|
983 | 4084 |
|
4085 |
notice: this is instance protocol |
|
4086 |
||
12094 | 4087 |
true respondsTo:#ifTrue: |
4088 |
true respondsTo:#== |
|
983 | 4089 |
|
4090 |
notice: this is class protocol |
|
4091 |
||
12094 | 4092 |
True canUnderstand:#ifTrue: |
4093 |
True canUnderstand:#== |
|
620 | 4094 |
" |
983 | 4095 |
|
4096 |
"Modified: 10.2.1996 / 13:15:56 / cg" |
|
620 | 4097 |
! |
4098 |
||
9194 | 4099 |
includesBehavior:aClass |
4100 |
"return true, if the receiver includes the behavior of aClass; |
|
4101 |
i.e. if is either identical to a class or inherits from it." |
|
4102 |
||
4103 |
^ (self == aClass) or:[self isSubclassOf:aClass] |
|
4104 |
||
4105 |
" |
|
12094 | 4106 |
True includesBehavior:Object |
4107 |
True includesBehavior:Boolean |
|
4108 |
True includesBehavior:True |
|
4109 |
True includesBehavior:False |
|
9194 | 4110 |
" |
4111 |
||
4112 |
"Modified: 19.6.1997 / 18:14:35 / cg" |
|
4113 |
! |
|
4114 |
||
4115 |
includesSelector:aSelector |
|
9219 | 4116 |
"return true, if the methodDictionary of THIS class includes a method for aSelector. |
983 | 4117 |
(i.e. if aSelector is implemented in THIS class - NOT in a superclass). |
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4118 |
This is semantically equivalent to implements: (ST/80/Squeak compatibility). |
983 | 4119 |
|
4120 |
Hint: |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4121 |
Dont use this method to check if someone responds to a message - |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4122 |
use #canUnderstand: on the class or #respondsTo: on the instance |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4123 |
to do this. |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4124 |
|
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4125 |
Caveat: |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4126 |
This simply checks for the selector being present in the classes |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4127 |
selector table - therefore, it does not care for ignoredMethods. |
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4128 |
(but: you should not use this method for protocol-testing, anyway)." |
4307 | 4129 |
|
10534 | 4130 |
^ self methodDictionary includesIdenticalKey:aSelector |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4131 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4132 |
" |
9219 | 4133 |
Object includesSelector:#== |
4134 |
Object includesSelector:#murks |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4135 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4136 |
|
3882 | 4137 |
"Modified: / 7.6.1996 / 14:27:24 / stefan" |
4138 |
"Modified: / 16.10.1998 / 13:00:15 / cg" |
|
9194 | 4139 |
! |
4140 |
||
10085 | 4141 |
instAndClassMethods |
4142 |
^ (self theMetaclass methodDictionary values) , (self theNonMetaclass methodDictionary values) |
|
4143 |
||
4144 |
"Created: / 12-10-2006 / 18:36:57 / cg" |
|
4145 |
"Modified: / 12-10-2006 / 20:36:34 / cg" |
|
4146 |
! |
|
4147 |
||
9194 | 4148 |
lookupMethodFor:aSelector |
620 | 4149 |
"return the method, which would be executed if aSelector was sent to |
4150 |
an instance of the receiver. I.e. the selector arrays of the receiver |
|
4151 |
and all of its superclasses are searched for aSelector. |
|
4152 |
Return the method, or nil if instances do not understand aSelector. |
|
4153 |
EXPERIMENTAL: take care of multiple superclasses." |
|
4154 |
||
4155 |
|m cls| |
|
4156 |
||
4157 |
cls := self. |
|
4158 |
[cls notNil] whileTrue:[ |
|
4159 |
m := cls compiledMethodAt:aSelector. |
|
4160 |
m notNil ifTrue:[^ m]. |
|
4161 |
cls hasMultipleSuperclasses ifTrue:[ |
|
4162 |
cls superclasses do:[:aSuperClass | |
|
4163 |
m := aSuperClass lookupMethodFor:aSelector. |
|
4164 |
m notNil ifTrue:[^ m]. |
|
4165 |
]. |
|
4166 |
^ nil |
|
4167 |
] ifFalse:[ |
|
4168 |
cls := cls superclass |
|
4169 |
] |
|
4170 |
]. |
|
4171 |
^ nil |
|
4172 |
! |
|
4173 |
||
6460 | 4174 |
responseTo:aSelector |
12094 | 4175 |
"return the method (from here or the inheritance chain), |
6460 | 4176 |
which implements aSelector; return nil if none." |
4177 |
||
4178 |
|cls| |
|
4179 |
||
4180 |
cls := self whichClassIncludesSelector:aSelector. |
|
4181 |
cls notNil ifTrue:[ |
|
12094 | 4182 |
^ cls compiledMethodAt:aSelector |
6460 | 4183 |
]. |
4184 |
^ nil |
|
4185 |
||
4186 |
" |
|
12094 | 4187 |
String responseTo:#== |
4188 |
String responseTo:#collect: |
|
4189 |
String responseTo:#, |
|
6460 | 4190 |
" |
4191 |
! |
|
4192 |
||
9194 | 4193 |
selectorAtMethod:aMethod |
4194 |
"Return the selector for given method aMethod." |
|
4195 |
||
4196 |
^ self selectorAtMethod:aMethod ifAbsent:[nil] |
|
4197 |
||
620 | 4198 |
" |
9194 | 4199 |
|m| |
4200 |
||
4201 |
m := Object compiledMethodAt:#copy. |
|
4202 |
Fraction selectorAtMethod:m. |
|
4203 |
" |
|
4204 |
" |
|
4205 |
|m| |
|
4206 |
||
4207 |
m := Object compiledMethodAt:#copy. |
|
4208 |
Object selectorAtMethod:m. |
|
4209 |
" |
|
356 | 4210 |
! |
4211 |
||
9194 | 4212 |
selectorAtMethod:aMethod ifAbsent:failBlock |
620 | 4213 |
"return the selector for given method aMethod |
4214 |
or the value of failBlock, if not found." |
|
4215 |
||
1814 | 4216 |
|md| |
4217 |
||
4218 |
md := self methodDictionary. |
|
4219 |
md isNil ifTrue:[ |
|
4220 |
'OOPS - nil methodDictionary' errorPrintCR. |
|
4221 |
^ nil |
|
4222 |
]. |
|
4223 |
^ md keyAtValue:aMethod ifAbsent:failBlock. |
|
216 | 4224 |
|
4225 |
" |
|
620 | 4226 |
|m| |
4227 |
||
4228 |
m := Object compiledMethodAt:#copy. |
|
4229 |
Object selectorAtMethod:m ifAbsent:['oops']. |
|
4230 |
" |
|
216 | 4231 |
" |
620 | 4232 |
|m| |
4233 |
||
4234 |
m := Object compiledMethodAt:#copy. |
|
4235 |
Fraction selectorAtMethod:m ifAbsent:['oops']. |
|
216 | 4236 |
" |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4237 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1449
diff
changeset
|
4238 |
"Modified: 7.6.1996 / 15:15:45 / stefan" |
216 | 4239 |
! |
4240 |
||
2 | 4241 |
whichClassImplements:aSelector |
328 | 4242 |
"obsolete interface; |
4243 |
use whichClassIncludesSelector: for ST-80 compatibility." |
|
4244 |
||
9363 | 4245 |
<resource:#obsolete> |
4246 |
||
328 | 4247 |
^ self whichClassIncludesSelector:aSelector |
4248 |
! |
|
4249 |
||
4250 |
whichClassIncludesSelector:aSelector |
|
68 | 4251 |
"return the class in the inheritance chain, which implements the method |
4252 |
for aSelector; return nil if none. |
|
4253 |
EXPERIMENTAL: handle multiple superclasses" |
|
4254 |
||
4255 |
|cls| |
|
2 | 4256 |
|
68 | 4257 |
cls := self. |
4258 |
[cls notNil] whileTrue:[ |
|
983 | 4259 |
(cls includesSelector:aSelector) ifTrue:[^ cls]. |
154 | 4260 |
cls hasMultipleSuperclasses ifTrue:[ |
4261 |
cls superclasses do:[:aSuperClass | |
|
4262 |
|implementingClass| |
|
2 | 4263 |
|
328 | 4264 |
implementingClass := aSuperClass whichClassIncludesSelector:aSelector. |
154 | 4265 |
implementingClass notNil ifTrue:[^ implementingClass]. |
4266 |
]. |
|
4267 |
^ nil |
|
4268 |
] ifFalse:[ |
|
4269 |
cls := cls superclass |
|
4270 |
] |
|
2 | 4271 |
]. |
4272 |
^ nil |
|
4273 |
||
91 | 4274 |
" |
328 | 4275 |
String whichClassIncludesSelector:#== |
4276 |
String whichClassIncludesSelector:#collect: |
|
91 | 4277 |
" |
6727 | 4278 |
! ! |
4279 |
||
6931 | 4280 |
!Behavior methodsFor:'queries-variables'! |
6727 | 4281 |
|
4282 |
allClassVarNames |
|
4283 |
"return a collection of all the class variable name-strings |
|
4284 |
this includes all superclass-class variables" |
|
4285 |
||
4286 |
^ self addAllClassVarNamesTo:(OrderedCollection new) |
|
4287 |
||
4288 |
" |
|
4289 |
Float allClassVarNames |
|
4290 |
" |
|
4291 |
||
4292 |
"Modified: 16.4.1996 / 18:01:00 / cg" |
|
4293 |
! |
|
4294 |
||
4295 |
allInstVarNames |
|
4296 |
"return a collection of all the instance variable name-strings |
|
4297 |
this includes all superclass-instance variables. |
|
4298 |
Instvars of superclasses come first (i.e. the position matches |
|
4299 |
the instVarAt:-index)." |
|
4300 |
||
4301 |
self superclass isNil ifTrue:[^ self instVarNames]. |
|
4302 |
^ self addAllInstVarNamesTo:(OrderedCollection new) |
|
4303 |
||
4304 |
" |
|
12094 | 4305 |
Dictionary instVarNames |
4306 |
Dictionary allInstVarNames |
|
6727 | 4307 |
" |
4308 |
||
4309 |
"Modified: 16.4.1996 / 18:03:55 / cg" |
|
4310 |
! |
|
4311 |
||
4312 |
allInstanceVariableNames |
|
4313 |
"alias for allInstVarNames" |
|
4314 |
||
4315 |
^ self allInstVarNames |
|
4316 |
! |
|
4317 |
||
4318 |
classVarNames |
|
4319 |
"return a collection of the class variable name-strings. |
|
4320 |
Returning empty here, since Behavior does not define any classVariables. |
|
4321 |
(only Classes do). This allows different Behavior-like objects |
|
4322 |
(alien classes) to be handled by the browser as well." |
|
4323 |
||
4324 |
^ #() |
|
4325 |
||
4326 |
"Created: 16.4.1996 / 17:57:31 / cg" |
|
4327 |
! |
|
4328 |
||
4329 |
classVariableString |
|
4330 |
"return a string of the class variables names. |
|
4331 |
Returning empty here, since Behavior does not define any classVariables. |
|
4332 |
(only Classes do). This allows different Behavior-like objects |
|
4333 |
(alien classes) to be handled by the browser as well." |
|
4334 |
||
4335 |
^ '' |
|
4336 |
||
4337 |
"Created: 16.4.1996 / 16:28:56 / cg" |
|
4338 |
! |
|
4339 |
||
9445 | 4340 |
instVarNameForIndex:index |
4341 |
"Behavior does not provide this info - generate synthetic names." |
|
4342 |
||
4343 |
^ '* instVar' , index printString , ' *' |
|
4344 |
||
4345 |
"Created: / 17-07-2006 / 00:28:24 / cg" |
|
4346 |
! |
|
4347 |
||
6727 | 4348 |
instVarNames |
4349 |
"Behavior does not provide this info - generate synthetic names." |
|
4350 |
||
4351 |
|superclass superInsts| |
|
4352 |
||
4353 |
superclass := self superclass. |
|
4354 |
superclass isNil ifTrue:[ |
|
12094 | 4355 |
superInsts := 0 |
6727 | 4356 |
] ifFalse:[ |
12094 | 4357 |
superInsts := superclass instSize |
6727 | 4358 |
]. |
12094 | 4359 |
^ (superInsts+1 to:self instSize) |
9445 | 4360 |
collect:[:index | self instVarNameForIndex:index] |
4361 |
||
4362 |
"Modified: / 17-07-2006 / 00:28:40 / cg" |
|
6727 | 4363 |
! |
4364 |
||
4365 |
instanceVariableNames |
|
4366 |
"alias for instVarNames." |
|
4367 |
||
4368 |
^ self instVarNames |
|
4369 |
! |
|
4370 |
||
4371 |
instanceVariableString |
|
4372 |
"return a string with dummy names here - typically, your |
|
8857 | 4373 |
objects are instances of Class, not Behavior, |
4374 |
so this is only invoked for very artificial behaviors." |
|
4375 |
||
4376 |
|superclass s superInsts first n "{Class: SmallInteger }"| |
|
6727 | 4377 |
|
4378 |
superclass := self superclass. |
|
4379 |
s := ''. |
|
4380 |
superclass isNil ifTrue:[ |
|
12094 | 4381 |
superInsts := 0 |
6727 | 4382 |
] ifFalse:[ |
12094 | 4383 |
superInsts := superclass instSize |
6727 | 4384 |
]. |
4385 |
n := self instSize. |
|
8857 | 4386 |
first := true. |
6727 | 4387 |
superInsts+1 to:n do:[:i | |
12094 | 4388 |
first ifFalse:[s := s , ' '] ifTrue:[first := false]. |
4389 |
||
4390 |
s := s , 'instvar' , i printString |
|
6727 | 4391 |
]. |
4392 |
^ s |
|
4393 |
||
4394 |
" |
|
12094 | 4395 |
Behavior new instanceVariableString |
4396 |
(Behavior new instSize:2) instanceVariableString |
|
6727 | 4397 |
" |
4398 |
||
4399 |
"Modified: 7.5.1996 / 12:50:25 / cg" |
|
4400 |
"Modified: 3.6.1996 / 16:03:33 / stefan" |
|
4401 |
! |
|
4402 |
||
12094 | 4403 |
whichClassDefinesClassVar: aString |
4404 |
^self whichClassSatisfies: |
|
4405 |
[:aClass | |
|
4406 |
(aClass classVarNames collect: [:each | each asString]) |
|
6727 | 4407 |
includes: aString asString] |
4408 |
! |
|
4409 |
||
12094 | 4410 |
whichClassDefinesInstVar: aString |
6727 | 4411 |
^self whichClassSatisfies: [:aClass | aClass instVarNames includes: aString] |
4412 |
! |
|
4413 |
||
12094 | 4414 |
whichSelectorsAssign: instVarName |
4415 |
"Answer a set of selectors whose methods write the argument, instVarName, |
|
4416 |
as a named instance variable." |
|
4417 |
||
4418 |
^ self whichSelectorsWrite: instVarName |
|
6727 | 4419 |
! |
4420 |
||
12094 | 4421 |
whichSelectorsRead: instVarName |
4422 |
"Answer a set of selectors whose methods read the argument, instVarName, |
|
9194 | 4423 |
as a named instance variable." |
4424 |
||
4425 |
| instVarIndex methodDict| |
|
4426 |
instVarIndex := self allInstVarNames indexOf: instVarName ifAbsent: [^Set new]. |
|
4427 |
methodDict := self methodDictionary. |
|
4428 |
^methodDict keys select: [:sel | (methodDict at: sel) |
|
4429 |
readsField: instVarIndex] |
|
2 | 4430 |
! |
4431 |
||
9194 | 4432 |
whichSelectorsReferTo:someLiteralConstant |
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4433 |
"return a collection of selectors of methods which refer to the argument. |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4434 |
Search the literal arrays of my methods to do this." |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4435 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4436 |
|setOfSelectors| |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4437 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4438 |
setOfSelectors := IdentitySet new. |
6395
2ad7a8e870ab
instance variables should only be accessed by getters/setters
Claus Gittinger <cg@exept.de>
parents:
6329
diff
changeset
|
4439 |
self methodDictionary keysAndValuesDo:[:sel :mthd | |
12094 | 4440 |
(mthd referencesLiteral:someLiteralConstant) ifTrue:[ |
4441 |
setOfSelectors add:sel |
|
4442 |
]. |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4443 |
]. |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4444 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4445 |
^ setOfSelectors |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4446 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4447 |
" |
12094 | 4448 |
String whichSelectorsReferTo:#at: |
4449 |
String whichSelectorsReferTo:CharacterArray |
|
3053
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4450 |
" |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4451 |
|
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4452 |
"Modified: / 28.10.1997 / 13:13:18 / cg" |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4453 |
! |
d6aad366397f
added #whichSelectorsReferTo: and #compiledMethodAt:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
3044
diff
changeset
|
4454 |
|
5297 | 4455 |
whichSelectorsReferToClassVariable:nameOfClassVariable |
4456 |
"return a collection of selectors of methods which refer to the argument. |
|
4457 |
Search the literal arrays of my methods to do this." |
|
4458 |
||
10413 | 4459 |
^ self whichSelectorsReferToGlobal:(self theNonMetaclass globalKeyForClassVar:nameOfClassVariable) |
5297 | 4460 |
|
4461 |
" |
|
4462 |
Object whichSelectorsReferToClassVariable:#Dependencies |
|
4463 |
" |
|
4464 |
||
10185 | 4465 |
"Modified: / 18-11-2006 / 17:14:08 / cg" |
5297 | 4466 |
! |
4467 |
||
4468 |
whichSelectorsReferToGlobal:nameOfGlobal |
|
4469 |
"return a collection of selectors of methods which refer to the argument. |
|
4470 |
Search the literal arrays of my methods to do this." |
|
4471 |
||
4472 |
|internalNameOfVar| |
|
4473 |
||
4474 |
internalNameOfVar := nameOfGlobal asSymbol. |
|
4475 |
^ self whichSelectorsReferTo:internalNameOfVar |
|
4476 |
||
4477 |
" |
|
4478 |
Object whichSelectorsReferToGlobal:#Debugger |
|
4479 |
" |
|
4480 |
||
4481 |
"Modified: / 4.2.2000 / 00:41:10 / cg" |
|
4482 |
! |
|
4483 |
||
12094 | 4484 |
whichSelectorsWrite: instVarName |
4485 |
"Answer a set of selectors whose methods write the argument, instVarName, |
|
6727 | 4486 |
as a named instance variable." |
4487 |
||
4488 |
| instVarIndex methodDict | |
|
4489 |
instVarIndex := self allInstVarNames indexOf: instVarName ifAbsent: [^Set new]. |
|
4490 |
methodDict := self methodDictionary. |
|
4491 |
^methodDict keys select: [:sel | (methodDict at: sel) |
|
4492 |
writesField: instVarIndex] |
|
2 | 4493 |
! ! |
620 | 4494 |
|
4495 |
!Behavior methodsFor:'snapshots'! |
|
4496 |
||
9194 | 4497 |
postSnapshot |
4498 |
"sent by ObjectMemory to all classes, after a snapshot has been written. |
|
4499 |
Nothing done here. This can be redefined in classes which like to know |
|
4500 |
about snapshooting." |
|
4501 |
||
4502 |
"Modified: 16.4.1996 / 18:12:08 / cg" |
|
4503 |
! |
|
9189
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
4504 |
|
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
4505 |
preSnapshot |
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
4506 |
"sent by ObjectMemory to all classes, before a snapshot is written. |
1192
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
4507 |
Nothing done here. This can be redefined in classes which like to know |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
4508 |
about snapshooting." |
b1c2b886f23c
moved some protocol from Class to upper levels; renamed categories
Claus Gittinger <cg@exept.de>
parents:
1191
diff
changeset
|
4509 |
|
9189
3fbc934d46a9
readFromString: - allow for whitespace following the string
Claus Gittinger <cg@exept.de>
parents:
8962
diff
changeset
|
4510 |
"Modified: 16.4.1996 / 18:12:14 / cg" |
620 | 4511 |
! ! |
4512 |
||
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
4513 |
!Behavior methodsFor:'tracing'! |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
4514 |
|
9194 | 4515 |
traceInto:aRequestor level:level from:referrer |
4516 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
4517 |
||
4518 |
^ aRequestor traceBehavior:self level:level from:referrer |
|
4519 |
||
4520 |
||
4657
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
4521 |
! ! |
ace3dc642424
added #hasSharedInstances and tracing support.
Claus Gittinger <cg@exept.de>
parents:
4636
diff
changeset
|
4522 |
|
9194 | 4523 |
!Behavior methodsFor:'visiting'! |
4524 |
||
4525 |
acceptVisitor:aVisitor with:aParameter |
|
8398
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
4526 |
|
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
4527 |
^ aVisitor visitBehavior:self with:aParameter |
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
4528 |
! ! |
666ef609ec93
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8353
diff
changeset
|
4529 |
|
1760 | 4530 |
!Behavior class methodsFor:'documentation'! |
662 | 4531 |
|
4532 |
version |
|
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4533 |
^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.295 2009-10-20 08:38:20 cg Exp $' |
12113
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
4534 |
! |
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
4535 |
|
6fbe0157e258
changed: #definitionSelectors
Claus Gittinger <cg@exept.de>
parents:
12094
diff
changeset
|
4536 |
version_CVS |
12302
656c61777a20
comment/format in: #implements: #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
12195
diff
changeset
|
4537 |
^ '$Header: /cvs/stx/stx/libbasic/Behavior.st,v 1.295 2009-10-20 08:38:20 cg Exp $' |
662 | 4538 |
! ! |