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