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