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