author | Stefan Vogel <sv@exept.de> |
Mon, 03 Dec 2018 18:07:46 +0100 | |
changeset 23554 | f82e83c4076c |
parent 23356 | 82fe226c009d |
child 23568 | 3d89374701ba |
permissions | -rw-r--r-- |
23012 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
15 |
|
18480 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Object subclass:#UndefinedObject |
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
19 |
instanceVariableNames:'' |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
20 |
classVariableNames:'CreateMinimumProtocolInNewSubclassQuery' |
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
21 |
poolDictionaries:'' |
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
22 |
category:'Kernel-Objects' |
1 | 23 |
! |
24 |
||
88 | 25 |
!UndefinedObject class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 30 |
All Rights Reserved |
1 | 31 |
|
88 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
20215 | 43 |
there is only one instance of this class: nil, |
1303 | 44 |
representing an undefined or otherwise unspecified object. |
88 | 45 |
|
20215 | 46 |
All instance variables, array elements and even method/block local |
88 | 47 |
variables are initially set to nil. |
1303 | 48 |
|
20215 | 49 |
Since in Smalltalk/X (and in other smalltalks), nil is represented by |
50 |
a special pointer value (NULL), there can be only one instance of UndefinedObject, |
|
51 |
and no subclassing is possible. |
|
52 |
(to be exact: subclassing UndefinedObject is technically possible, |
|
53 |
but instances of it would not be recognized as being nil |
|
1303 | 54 |
- therefore, subclassing is blocked and an error is raised when it is tried) |
55 |
||
56 |
For advanced users: |
|
57 |
Beside the above role, nil can be subclassed (!!). |
|
58 |
This creates a class which inherits no protocol whatsoever - not even |
|
59 |
the basic interfaces as defined by the Object class. Subclasses of nil |
|
60 |
are useful if all messages send to instances should trap into the |
|
61 |
#doesNotUnderstand: method. For example, proxy objects are typically defined |
|
62 |
this way. |
|
1294 | 63 |
|
64 |
[author:] |
|
65 |
Claus Gittinger |
|
88 | 66 |
" |
67 |
! ! |
|
1 | 68 |
|
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
69 |
!UndefinedObject class methodsFor:'initialization'! |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
70 |
|
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
71 |
initialize |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
72 |
CreateMinimumProtocolInNewSubclassQuery isNil ifTrue:[ |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
73 |
CreateMinimumProtocolInNewSubclassQuery := QuerySignal new. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
74 |
CreateMinimumProtocolInNewSubclassQuery nameClass:self message:#createMinimumProtocolInNewSubclassQuery. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
75 |
CreateMinimumProtocolInNewSubclassQuery defaultAnswer:false. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
76 |
]. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
77 |
|
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
78 |
" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
79 |
UndefinedObject initialize |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
80 |
" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
81 |
|
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
82 |
"Created: 3.1.1997 / 15:02:40 / cg" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
83 |
"Modified: 3.1.1997 / 15:18:33 / cg" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
84 |
! ! |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
85 |
|
1 | 86 |
!UndefinedObject class methodsFor:'instance creation'! |
87 |
||
88 |
basicNew |
|
89 |
"catch new - there MUST be only one nil in the system" |
|
90 |
||
91 |
^ nil |
|
92 |
! |
|
93 |
||
94 |
basicNew:size |
|
95 |
"catch new - there MUST be only one nil in the system" |
|
96 |
||
97 |
^ nil |
|
98 |
! ! |
|
99 |
||
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
100 |
!UndefinedObject class methodsFor:'Signal constants'! |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
101 |
|
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
102 |
createMinimumProtocolInNewSubclassQuery |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
103 |
"return the signal used to ask if the minimum required protocol |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
104 |
should be created for nil subclasses. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
105 |
By default, this is not done, however, the browser answers true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
106 |
here, to avoid big trouble with nil subclasses which do not define |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
107 |
some methods which the inspector needs." |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
108 |
|
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
109 |
^ CreateMinimumProtocolInNewSubclassQuery |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
110 |
|
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
111 |
"Created: 3.1.1997 / 15:05:48 / cg" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
112 |
"Modified: 3.1.1997 / 15:06:15 / cg" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
113 |
! ! |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
114 |
|
22640 | 115 |
|
51 | 116 |
!UndefinedObject class methodsFor:'queries'! |
117 |
||
118 |
canBeSubclassed |
|
20215 | 119 |
"return true if it is allowed to create subclasses of the receiver. |
3914 | 120 |
Return false here - since it is NOT possible for UndefinedObject. |
121 |
(due to the representation of nil as a 0-pointer)" |
|
51 | 122 |
|
123 |
^ false |
|
3914 | 124 |
|
125 |
"Modified: / 5.11.1998 / 16:11:43 / cg" |
|
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
126 |
! |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
127 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
128 |
hasImmediateInstances |
4652
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
129 |
"return true if this class has immediate instances |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
130 |
i.e. if the instances are represented in the pointer itself and |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
131 |
no real object header/storage is used for the object. |
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
132 |
Redefined from Behavior" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
133 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
134 |
^ true |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
135 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2416
diff
changeset
|
136 |
"Created: 3.6.1997 / 12:01:39 / cg" |
4321 | 137 |
! |
138 |
||
4652
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
139 |
hasSharedInstances |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
140 |
"return true if this class has shared instances, that is, instances |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
141 |
with the same value are identical. |
4654 | 142 |
True returned here - there is only one nil." |
4652
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
143 |
|
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
144 |
^ true |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
145 |
|
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
146 |
|
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
147 |
! |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
148 |
|
4321 | 149 |
isBuiltInClass |
20215 | 150 |
"return true if this class is known by the run-time-system, |
4321 | 151 |
i.e. you cannot add/remove instance variables without recompiling |
152 |
the VM. |
|
153 |
Here, true is returned for myself, false for subclasses." |
|
154 |
||
155 |
^ self == UndefinedObject |
|
51 | 156 |
! ! |
157 |
||
5699 | 158 |
|
22640 | 159 |
|
160 |
||
2416 | 161 |
!UndefinedObject methodsFor:'converting'! |
162 |
||
8305 | 163 |
asBoolean |
164 |
^ false |
|
165 |
! |
|
166 |
||
22640 | 167 |
asCollectionOrEmptyIfNil |
168 |
"answer an empty collection" |
|
169 |
||
170 |
^ #() |
|
171 |
||
172 |
"Created: / 20-03-2018 / 15:23:56 / stefan" |
|
173 |
! |
|
174 |
||
15081 | 175 |
asNilIfEmpty |
176 |
"I am nil, so answer nil" |
|
177 |
||
178 |
^ self |
|
179 |
! |
|
180 |
||
22640 | 181 |
doIfNotNil:aBlock |
23261 | 182 |
"if I am a collection, then enumerate myself into aBlock. |
183 |
if I am nil, then do nothing. |
|
184 |
Otherwise, evaluate aBlock with myself as argument. |
|
185 |
Here, answer nil" |
|
22640 | 186 |
|
187 |
^ nil |
|
188 |
||
189 |
"Created: / 20-03-2018 / 15:37:11 / stefan" |
|
23261 | 190 |
"Modified (comment): / 05-08-2018 / 11:26:32 / Claus Gittinger" |
22640 | 191 |
! |
192 |
||
2416 | 193 |
literalArrayEncoding |
194 |
"encode myself as an array literal, from which a copy of the receiver |
|
195 |
can be reconstructed with #decodeAsLiteralArray." |
|
196 |
||
197 |
^ self |
|
198 |
||
199 |
"Created: 25.2.1997 / 19:18:47 / cg" |
|
200 |
! ! |
|
201 |
||
695 | 202 |
!UndefinedObject methodsFor:'copying'! |
203 |
||
204 |
copy |
|
205 |
"return a shallow copy of myself |
|
206 |
- since there is only one nil in the system return self" |
|
207 |
||
208 |
^ self |
|
209 |
! |
|
210 |
||
211 |
deepCopy |
|
212 |
"return a deep copy of myself |
|
213 |
- since there is only one nil in the system return self" |
|
214 |
||
215 |
^ self |
|
216 |
! |
|
217 |
||
10945 | 218 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
695 | 219 |
"return a deep copy of myself |
8383 | 220 |
- since there is only one nil in the system, return self" |
695 | 221 |
|
222 |
^ self |
|
223 |
! |
|
224 |
||
225 |
shallowCopy |
|
226 |
"return a shallow copy of myself |
|
227 |
- since there is only one nil in the system return self" |
|
228 |
||
229 |
^ self |
|
230 |
! |
|
231 |
||
232 |
simpleDeepCopy |
|
233 |
"return a deep copy of myself |
|
234 |
- since there is only one nil in the system return self" |
|
235 |
||
236 |
^ self |
|
237 |
! ! |
|
238 |
||
22024 | 239 |
!UndefinedObject methodsFor:'debugging'! |
240 |
||
241 |
haltIfNil |
|
242 |
"halt if the receiver is nil" |
|
243 |
||
244 |
<resource: #skipInDebuggersWalkBack> |
|
245 |
||
246 |
self halt:'nil encountered' |
|
247 |
||
248 |
" |
|
249 |
3 haltIfNil |
|
250 |
nil haltIfNil |
|
251 |
" |
|
252 |
||
253 |
"Created: / 17-07-2017 / 10:52:36 / cg" |
|
254 |
! ! |
|
255 |
||
3166 | 256 |
!UndefinedObject methodsFor:'dependents access'! |
257 |
||
258 |
addDependent:someObject |
|
12968
07761a8bcc6a
comment/format in: #addDependent:
Claus Gittinger <cg@exept.de>
parents:
11821
diff
changeset
|
259 |
"raise an error here - nil may not have dependents (it never changes anyway)" |
3166 | 260 |
|
23012 | 261 |
self proceedableError:'nil may not have dependents' |
4530
793b116fef3e
error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents:
4339
diff
changeset
|
262 |
|
12968
07761a8bcc6a
comment/format in: #addDependent:
Claus Gittinger <cg@exept.de>
parents:
11821
diff
changeset
|
263 |
"Modified: / 28-07-2010 / 19:20:36 / cg" |
23012 | 264 |
"Modified: / 24-05-2018 / 21:05:28 / Claus Gittinger" |
3166 | 265 |
! |
266 |
||
3183 | 267 |
dependents |
268 |
"nil has no dependents" |
|
269 |
||
23554 | 270 |
^ #() |
271 |
||
272 |
"Modified (format): / 30-11-2018 / 18:03:27 / Stefan Vogel" |
|
273 |
! |
|
274 |
||
275 |
onChangeSend:selector to:someOne |
|
276 |
"raise an error here - nil may not have dependents (it never changes anyway)" |
|
277 |
||
278 |
self proceedableError:'nil may not have dependents' |
|
279 |
||
280 |
"Created: / 30-11-2018 / 18:03:49 / Stefan Vogel" |
|
3183 | 281 |
! |
282 |
||
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
283 |
release |
3166 | 284 |
"ignored here - nil has no dependents" |
3183 | 285 |
! |
3166 | 286 |
|
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
287 |
removeDependent:someObject |
3183 | 288 |
"ignored here - nil has no dependents" |
3166 | 289 |
! ! |
290 |
||
1 | 291 |
!UndefinedObject methodsFor:'error catching'! |
292 |
||
293 |
basicAt:index |
|
20700 | 294 |
"catch array access - it's illegal. |
21759 | 295 |
Redefined here since basicAt: in Object omits the nil-check" |
1 | 296 |
|
297 |
^ self notIndexed |
|
21759 | 298 |
|
299 |
"Modified (comment): / 17-05-2017 / 16:36:12 / mawalch" |
|
1 | 300 |
! |
301 |
||
302 |
basicAt:index put:anObject |
|
20700 | 303 |
"catch array access - it's illegal. |
21759 | 304 |
Redefined here since basicAt:put: in Object omits the nil-check" |
1 | 305 |
|
306 |
^ self notIndexed |
|
21759 | 307 |
|
308 |
"Modified (comment): / 17-05-2017 / 16:36:17 / mawalch" |
|
1 | 309 |
! ! |
310 |
||
14678 | 311 |
|
1 | 312 |
!UndefinedObject methodsFor:'printing & storing'! |
313 |
||
63 | 314 |
printOn:aStream |
315 |
"append a printed representation of the receiver to the |
|
316 |
argument, aStream" |
|
317 |
||
318 |
aStream nextPutAll:'nil' |
|
319 |
! |
|
320 |
||
695 | 321 |
printString |
322 |
"return a string for printing myself" |
|
323 |
||
324 |
^ 'nil' |
|
325 |
! |
|
326 |
||
63 | 327 |
storeOn:aStream |
328 |
"append a printed representation of the receiver to the |
|
329 |
argument, aStream, which allows reconstruction of it" |
|
330 |
||
331 |
^ self printOn:aStream |
|
695 | 332 |
! |
333 |
||
334 |
storeString |
|
335 |
"return a string for storing myself" |
|
336 |
||
337 |
^ 'nil' |
|
1 | 338 |
! ! |
2 | 339 |
|
5557 | 340 |
!UndefinedObject methodsFor:'queries'! |
341 |
||
342 |
basicSize |
|
343 |
"return the number of indexed instvars |
|
21759 | 344 |
defined here since size in Object omits the nil-check" |
5557 | 345 |
|
346 |
^ 0 |
|
21759 | 347 |
|
348 |
"Modified (comment): / 17-05-2017 / 16:37:13 / mawalch" |
|
5557 | 349 |
! |
350 |
||
351 |
size |
|
352 |
"return the number of indexed instvars |
|
21759 | 353 |
defined here since size in Object omits the nil-check" |
20215 | 354 |
|
5557 | 355 |
^ 0 |
21759 | 356 |
|
357 |
"Modified (comment): / 17-05-2017 / 16:37:19 / mawalch" |
|
5557 | 358 |
! ! |
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
4682
diff
changeset
|
359 |
|
22640 | 360 |
|
77 | 361 |
!UndefinedObject methodsFor:'subclass creation'! |
362 |
||
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
363 |
nilSubclass:action |
356 | 364 |
"common helper for subclass creation. |
20215 | 365 |
Creates a nil-superclass class. |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
366 |
If the CreateMinimumProtocolInNewSubclassQuery answers true, |
20215 | 367 |
entries for the minimum required protocol (#class, #isBehavior |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
368 |
and #doesNotUnderstand:) are also automatically created. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
369 |
(this query is typically answered by the browser) |
356 | 370 |
These are required to avoid getting into deep trouble when |
371 |
inspecting or debugging instances of this new class. |
|
372 |
The methods get a modified source code to remind you that these |
|
373 |
methods were automatically generated." |
|
374 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
375 |
|newClass methodDict method| |
202 | 376 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
377 |
Class withoutUpdatingChangesDo:[ |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
378 |
newClass := action value |
77 | 379 |
]. |
380 |
newClass notNil ifTrue:[ |
|
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
381 |
newClass setSuperclass:nil. |
1803
754f9205b651
meta's superclass should be class - not Object.
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
382 |
newClass class setSuperclass:Class. |
356 | 383 |
|
21316 | 384 |
newClass hasMethods ifFalse:[ |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
385 |
Class addChangeRecordForClass:newClass. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
386 |
|
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
387 |
CreateMinimumProtocolInNewSubclassQuery query |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
388 |
ifTrue:[ |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
389 |
" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
390 |
copy over method objects from Object |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
391 |
and modify the source code |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
392 |
" |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
393 |
methodDict := MethodDictionary new:3. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
394 |
#(#class #isBehavior #doesNotUnderstand:) do:[:sel| |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
395 |
method := (Object compiledMethodAt:sel) copy. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
396 |
method source: method source , ' |
356 | 397 |
" |
398 |
*** WARNING |
|
399 |
*** |
|
400 |
*** this method has been automatically created, |
|
401 |
*** since all nil-subclasses should respond to some minimum required |
|
402 |
*** protocol. |
|
403 |
*** |
|
404 |
*** Inspection and/or debugging of instances may not be possible, |
|
405 |
*** if you remove/change this method. |
|
406 |
" |
|
407 |
'. |
|
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
408 |
methodDict at:sel put:method. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
409 |
"/ newClass addChangeRecordForMethod:method |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
410 |
]. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
411 |
newClass methodDictionary:methodDict. |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
412 |
] |
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
413 |
] |
77 | 414 |
]. |
415 |
^ newClass |
|
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
416 |
|
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
417 |
"Modified: / 3.1.1997 / 15:53:21 / cg" |
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
418 |
"Created: / 3.1.1997 / 16:00:34 / cg" |
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
419 |
"Modified: / 18.3.1999 / 18:29:58 / stefan" |
202 | 420 |
! |
421 |
||
9256 | 422 |
subclass:nameSymbol instanceVariableNames:instVarNameString classVariableNames:classVarString poolDictionaries:pool |
20215 | 423 |
"create a new class which has nil as superclass |
9256 | 424 |
- i.e. traps into #doesNotUnderstand: for all of its messages." |
425 |
||
14678 | 426 |
"this method allows fileIn of ST/V and V'Age classes |
427 |
(which seem to have no category)" |
|
428 |
||
20215 | 429 |
^ self |
430 |
subclass:nameSymbol |
|
431 |
instanceVariableNames:instVarNameString |
|
432 |
classVariableNames:classVarString |
|
9256 | 433 |
poolDictionaries:pool |
434 |
category:(Class defaultCategoryForSTVorVAGEClasses). |
|
435 |
! |
|
436 |
||
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
437 |
subclass:nameSymbol instanceVariableNames:instVarNameString classVariableNames:classVarString poolDictionaries:pool category:cat |
20215 | 438 |
"create a new class which has nil as superclass |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
439 |
- i.e. traps into #doesNotUnderstand: for all of its messages." |
202 | 440 |
|
20215 | 441 |
^ self |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
442 |
nilSubclass:[ |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
443 |
Object class |
20215 | 444 |
name:nameSymbol |
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
445 |
inEnvironment:(Class nameSpaceQuerySignal query) |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
446 |
subclassOf:self |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
447 |
instanceVariableNames:instVarNameString |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
448 |
variable:false |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
449 |
words:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
450 |
pointers:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
451 |
classVariableNames:classVarString |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
452 |
poolDictionaries:pool |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
453 |
category:cat |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
454 |
comment:nil |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
455 |
changed:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
456 |
] |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
457 |
|
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
458 |
"Modified: / 3.1.1997 / 16:00:39 / cg" |
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
459 |
"Modified: / 18.3.1999 / 18:30:07 / stefan" |
695 | 460 |
! |
461 |
||
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
462 |
variableByteSubclass:nameSymbol instanceVariableNames:instVarNameString classVariableNames:classVarString poolDictionaries:pool category:cat |
20215 | 463 |
"create a new class which has nil as superclass |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
464 |
- i.e. traps into #doesNotUnderstand: for all of its messages." |
695 | 465 |
|
20215 | 466 |
^ self |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
467 |
nilSubclass:[ |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
468 |
Object class |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
469 |
name:nameSymbol |
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
470 |
inEnvironment:(Class nameSpaceQuerySignal query) |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
471 |
subclassOf:self |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
472 |
instanceVariableNames:instVarNameString |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
473 |
variable:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
474 |
words:false |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
475 |
pointers:false |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
476 |
classVariableNames:classVarString |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
477 |
poolDictionaries:pool |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
478 |
category:cat |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
479 |
comment:nil |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
480 |
changed:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
481 |
] |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
482 |
|
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
483 |
"Modified: / 3.1.1997 / 16:00:42 / cg" |
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
484 |
"Modified: / 18.3.1999 / 18:30:11 / stefan" |
695 | 485 |
! |
77 | 486 |
|
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
487 |
variableSubclass:nameSymbol instanceVariableNames:instVarNameString classVariableNames:classVarString poolDictionaries:pool category:cat |
20215 | 488 |
"create a new class which has nil as superclass |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
489 |
- i.e. traps into #doesNotUnderstand: for all of its messages." |
77 | 490 |
|
20215 | 491 |
^ self |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
492 |
nilSubclass:[ |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
493 |
Object class |
20215 | 494 |
name:nameSymbol |
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
495 |
inEnvironment:(Class nameSpaceQuerySignal query) |
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
496 |
subclassOf:self |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
497 |
instanceVariableNames:instVarNameString |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
498 |
variable:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
499 |
words:false |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
500 |
pointers:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
501 |
classVariableNames:classVarString |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
502 |
poolDictionaries:pool |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
503 |
category:cat |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
504 |
comment:nil |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
505 |
changed:true |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
506 |
] |
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
507 |
|
4060
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
508 |
"Modified: / 3.1.1997 / 16:00:45 / cg" |
1048a3abf128
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
509 |
"Modified: / 18.3.1999 / 18:30:16 / stefan" |
695 | 510 |
! ! |
511 |
||
7262 | 512 |
!UndefinedObject methodsFor:'subclass creation-private'! |
5745 | 513 |
|
18480 | 514 |
subclass:nameSymbol instanceVariableNames:instVarNameString classVariableNames:classVarString poolDictionaries:pool privateIn:ownerClassArg |
20215 | 515 |
"create a new private class which has nil as superclass |
5745 | 516 |
- i.e. traps into #doesNotUnderstand: for all of its messages." |
517 |
||
18480 | 518 |
|category ownerClass| |
519 |
||
520 |
(ownerClass := ownerClassArg) isNil ifTrue:[ |
|
23012 | 521 |
self proceedableError:'Nil (undefined) owner class - proceed to define as global'. |
18480 | 522 |
] ifFalse:[ |
523 |
category := ownerClassArg category |
|
524 |
]. |
|
20215 | 525 |
|
526 |
^ self |
|
5745 | 527 |
nilSubclass:[ |
528 |
Object class |
|
20215 | 529 |
name:nameSymbol |
5745 | 530 |
inEnvironment:ownerClass |
531 |
subclassOf:self |
|
532 |
instanceVariableNames:instVarNameString |
|
533 |
variable:false |
|
534 |
words:true |
|
535 |
pointers:true |
|
536 |
classVariableNames:classVarString |
|
537 |
poolDictionaries:pool |
|
18480 | 538 |
category:category |
5745 | 539 |
comment:nil |
540 |
changed:true |
|
541 |
] |
|
542 |
||
23012 | 543 |
"Modified: / 03-01-1997 / 16:00:39 / cg" |
544 |
"Modified: / 18-03-1999 / 18:30:07 / stefan" |
|
545 |
"Modified: / 24-05-2018 / 21:05:47 / Claus Gittinger" |
|
5745 | 546 |
! ! |
547 |
||
695 | 548 |
!UndefinedObject methodsFor:'testing'! |
549 |
||
1868 | 550 |
? defaultValue |
20191 | 551 |
"a syntactic sugar-piece: |
3466 | 552 |
if the receiver is nil, return the defaultValue; |
1868 | 553 |
otherwise, return the receiver. |
554 |
This method is redefined from Object; |
|
20215 | 555 |
the argument is returned unconditionally here. |
1868 | 556 |
|
1958 | 557 |
Thus, if foo and bar are simple variables or constants, |
558 |
foo ? bar |
|
559 |
is the same as: |
|
560 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
|
561 |
||
562 |
if they are message sends, the equivalent code is: |
|
563 |
[ |
|
564 |
|t1 t2| |
|
565 |
||
566 |
t1 := foo. |
|
567 |
t2 := bar. |
|
568 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
569 |
] value |
|
570 |
||
1868 | 571 |
Can be used to provide defaultValues to variables, |
572 |
as in: |
|
1958 | 573 |
foo := arg ? #defaultValue |
1868 | 574 |
" |
575 |
||
576 |
^ defaultValue |
|
577 |
||
578 |
" |
|
579 |
1 ? #default |
|
20191 | 580 |
nil ? #default |
1868 | 581 |
" |
582 |
||
3466 | 583 |
"Created: / 4.11.1996 / 20:37:09 / cg" |
584 |
"Modified: / 19.5.1998 / 17:39:36 / cg" |
|
1868 | 585 |
! |
586 |
||
16127 | 587 |
?+ aOneArgBlock |
588 |
"a syntactic sugar-piece: |
|
589 |
aOneArgBlock is executed with self as argument |
|
590 |
if self is not nil. |
|
591 |
||
592 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
593 |
" |
|
594 |
||
595 |
^ self |
|
596 |
! |
|
597 |
||
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
598 |
?? defaultValue |
11635 | 599 |
"a syntactic sugar-piece: |
3466 | 600 |
much like ?, but sends value to the argument if required. |
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
601 |
If the receiver is nil, return the defaultValues value; |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
602 |
otherwise, return the receiver. |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
603 |
This method is redefined from Object. |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
604 |
|
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
605 |
Thus, if foo and bar are simple variables or constants, |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
606 |
foo ?? bar |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
607 |
is the same as: |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
608 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
609 |
|
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
610 |
if they are message sends, the equivalent code is: |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
611 |
[ |
3466 | 612 |
|t| |
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
613 |
|
3466 | 614 |
t := foo. |
615 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
616 |
] value |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
617 |
|
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
618 |
Can be used to provide defaultValues to variables, |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
619 |
as in: |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
620 |
foo := arg ?? [something] |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
621 |
" |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
622 |
|
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
623 |
^ defaultValue value |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
624 |
|
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
625 |
" |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
626 |
1 ?? #default |
20215 | 627 |
nil ?? #default |
628 |
1 ?? [Date today] |
|
629 |
nil ?? [Date today] |
|
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
630 |
" |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
631 |
|
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
632 |
"Created: / 4.11.1996 / 20:37:09 / cg" |
3466 | 633 |
"Modified: / 19.5.1998 / 17:42:10 / cg" |
3464
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
634 |
! |
b0009b3ea4f2
added ?? - much like ?, but sends #value to its argument.
Claus Gittinger <cg@exept.de>
parents:
3183
diff
changeset
|
635 |
|
7108
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
636 |
checkNilFileStream |
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
637 |
"Do nothing if this is a valid FileStream |
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
638 |
(i.e. the previous open operation was successful). |
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
639 |
Also implemented in UndefinedObject, to raise an Error there. |
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
640 |
|
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
641 |
This is an aid for converting from the old error reporting (returning nil) |
11635 | 642 |
to the new error reporting (with real Exceptions). |
7108
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
643 |
|
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
644 |
It will vanish as soon as the conversion has been done" |
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
645 |
|
16127 | 646 |
^ OpenError raise |
7108
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
647 |
! |
90b7cfc06ab8
More openErrorSignal change preparations
Stefan Vogel <sv@exept.de>
parents:
6932
diff
changeset
|
648 |
|
695 | 649 |
hash |
650 |
"return an integer useful as a hash key" |
|
651 |
||
652 |
^ 0 |
|
653 |
! |
|
654 |
||
655 |
identityHash |
|
656 |
"return an integer useful as a hash key" |
|
657 |
||
658 |
^ 0 |
|
659 |
! |
|
660 |
||
4339
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
661 |
ifNil:aBlockOrValue |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
662 |
"return myself, or the result from evaluating the argument, if I am nil. |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
663 |
This is much like #?, but sends #value to the argument in case of a nil |
5796 | 664 |
receiver. |
665 |
Notice: |
|
666 |
This method is open coded (inlined) by the compiler(s) |
|
667 |
- redefining it may not work as expected." |
|
4339
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
668 |
|
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
669 |
^ aBlockOrValue value |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
670 |
! |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
671 |
|
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
672 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
673 |
"return the value of the first arg, if I am nil, |
5796 | 674 |
the result from evaluating the 2nd argument, if I am not nil. |
675 |
Notice: |
|
676 |
This method is open coded (inlined) by the compiler(s) |
|
677 |
- redefining it may not work as expected." |
|
4339
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
678 |
|
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
679 |
^ nilBlockOrValue value |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
680 |
! |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
681 |
|
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
682 |
ifNotNil:aBlockOrValue |
5796 | 683 |
"return myself if nil, or the result from evaluating the argument, if I am not nil. |
684 |
Notice: |
|
685 |
This method is open coded (inlined) by the compiler(s) |
|
686 |
- redefining it may not work as expected." |
|
4339
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
687 |
|
8574 | 688 |
^ nil |
4339
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
689 |
! |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
690 |
|
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
691 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
692 |
"return the value of the 2nd arg, if I am nil, |
5796 | 693 |
the result from evaluating the 1st argument, if I am not nil. |
694 |
Notice: |
|
695 |
This method is open coded (inlined) by the compiler(s) |
|
696 |
- redefining it may not work as expected." |
|
4339
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
697 |
|
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
698 |
^ nilBlockOrValue value |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
699 |
! |
18c19912a67c
added #ifNil and friends - squeak compatibility.
Claus Gittinger <cg@exept.de>
parents:
4321
diff
changeset
|
700 |
|
8574 | 701 |
ifNotNilDo:aBlock |
20352 | 702 |
"if the receiver is non-nil, return the value of aBlock, passing myself as argument. |
8574 | 703 |
Otherwise do nothing and return nil." |
704 |
||
705 |
^ nil |
|
706 |
! |
|
707 |
||
6181 | 708 |
isEmptyOrNil |
20215 | 709 |
"return true if I am nil or an empty collection |
21809 | 710 |
- since I am nil, return true. (from Squeak)" |
6181 | 711 |
|
712 |
^ true |
|
713 |
||
13588 | 714 |
"Created: / 13-11-2001 / 13:16:40 / cg" |
715 |
"Modified (comment): / 17-08-2011 / 09:29:30 / cg" |
|
21809 | 716 |
"Modified (comment): / 15-06-2017 / 01:46:00 / mawalch" |
6181 | 717 |
! |
718 |
||
23356 | 719 |
isImmediate |
720 |
^ true |
|
721 |
||
722 |
"Created: / 18-09-2018 / 14:48:45 / Stefan Vogel" |
|
723 |
! |
|
724 |
||
695 | 725 |
isLiteral |
20215 | 726 |
"return true if the receiver can be used as a literal constant in ST syntax |
695 | 727 |
(i.e. can be used in constant arrays)" |
77 | 728 |
|
695 | 729 |
^ true |
730 |
! |
|
731 |
||
732 |
isNil |
|
20215 | 733 |
"Return true if the receiver is nil. |
9223 | 734 |
Since I am definitely nil, unconditionally return true here. |
3044 | 735 |
Notice: |
9223 | 736 |
This method is open coded (inlined) by the compiler(s) |
737 |
- redefining it may not work as expected." |
|
695 | 738 |
|
739 |
^ true |
|
740 |
! |
|
741 |
||
6932 | 742 |
notEmptyOrNil |
743 |
"Squeak compatibility: |
|
744 |
return true if I am neither nil nor an empty collection." |
|
745 |
||
746 |
^ false |
|
747 |
! |
|
748 |
||
695 | 749 |
notNil |
20215 | 750 |
"Return true if the receiver is not nil. |
9223 | 751 |
Since I am definitely nil, unconditionally return false here. |
3044 | 752 |
Notice: |
9223 | 753 |
This method is open coded (inlined) by the compiler(s) |
754 |
- redefining it may not work as expected." |
|
77 | 755 |
|
695 | 756 |
^ false |
77 | 757 |
! ! |
695 | 758 |
|
4652
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
759 |
!UndefinedObject methodsFor:'tracing'! |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
760 |
|
4682 | 761 |
traceInto:aRequestor level:level from:referrer |
4652
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
762 |
"double dispatch into tracer, passing my type implicitely in the selector" |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
763 |
|
4682 | 764 |
^ aRequestor traceUndefinedObject:self level:level from:referrer |
4652
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
765 |
|
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
766 |
|
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
767 |
! ! |
8b3118a923d1
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
768 |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
769 |
!UndefinedObject methodsFor:'visiting'! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
770 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
771 |
acceptVisitor:aVisitor with:aParameter |
16721 | 772 |
"dispatch for visitor pattern; send #visitNil:with: to aVisitor." |
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
773 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
774 |
^ aVisitor visitNilWith:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
775 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
776 |
|
22640 | 777 |
|
23356 | 778 |
|
695 | 779 |
!UndefinedObject class methodsFor:'documentation'! |
780 |
||
781 |
version |
|
18480 | 782 |
^ '$Header$' |
12968
07761a8bcc6a
comment/format in: #addDependent:
Claus Gittinger <cg@exept.de>
parents:
11821
diff
changeset
|
783 |
! |
07761a8bcc6a
comment/format in: #addDependent:
Claus Gittinger <cg@exept.de>
parents:
11821
diff
changeset
|
784 |
|
07761a8bcc6a
comment/format in: #addDependent:
Claus Gittinger <cg@exept.de>
parents:
11821
diff
changeset
|
785 |
version_CVS |
18480 | 786 |
^ '$Header$' |
695 | 787 |
! ! |
6932 | 788 |
|
14678 | 789 |
|
2040
8ba8b1002902
avoid intermediate Object subclass creation.
Claus Gittinger <cg@exept.de>
parents:
1958
diff
changeset
|
790 |
UndefinedObject initialize! |