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