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