author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 16:28:41 +0100 | |
changeset 530 | 07d0bce293c9 |
parent 384 | cc3d110ea879 |
child 695 | 20ec350f92ca |
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 |
" |
|
12 |
||
13 |
Object subclass:#UndefinedObject |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Objects' |
|
18 |
! |
|
19 |
||
88 | 20 |
!UndefinedObject class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
version |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/UndefinedObject.st,v 1.18 1995-11-11 15:28:05 cg Exp $' |
88 | 38 |
! |
1 | 39 |
|
88 | 40 |
documentation |
41 |
" |
|
42 |
there is only one instance of this class: nil, representing an undefined |
|
43 |
or otherwise unspecified object. |
|
44 |
||
45 |
All instance variables, array elements and even method/block local |
|
46 |
variables are initially set to nil. |
|
47 |
Since in Smalltalk/X, nil is represented by a special pointer value, |
|
48 |
there can be only one instance of UndefinedObject, and no subclassing is |
|
49 |
possible. |
|
50 |
(to be exact: subclassing is technically possible, but instances of it |
|
51 |
would not be recognized as being nil - therefore, subclassing is blocked) |
|
52 |
" |
|
53 |
! ! |
|
1 | 54 |
|
55 |
!UndefinedObject class methodsFor:'instance creation'! |
|
56 |
||
57 |
basicNew |
|
58 |
"catch new - there MUST be only one nil in the system" |
|
59 |
||
60 |
^ nil |
|
61 |
! |
|
62 |
||
63 |
basicNew:size |
|
64 |
"catch new - there MUST be only one nil in the system" |
|
65 |
||
66 |
^ nil |
|
67 |
! ! |
|
68 |
||
51 | 69 |
!UndefinedObject class methodsFor:'queries'! |
70 |
||
71 |
canBeSubclassed |
|
72 |
"return true, if its allowed to create subclasses of the receiver. |
|
73 |
Return nil here - since it is NOT possible for UndefinedObject" |
|
74 |
||
75 |
^ false |
|
76 |
! ! |
|
77 |
||
1 | 78 |
!UndefinedObject methodsFor:'error catching'! |
79 |
||
80 |
basicAt:index |
|
81 |
"catch array access - its illegal |
|
82 |
defined here since basicAt: in Object ommits the nil-check" |
|
83 |
||
84 |
^ self notIndexed |
|
85 |
! |
|
86 |
||
87 |
basicAt:index put:anObject |
|
88 |
"catch array access - its illegal |
|
89 |
defined here since basicAt:put: in Object ommits the nil-check" |
|
90 |
||
91 |
^ self notIndexed |
|
92 |
! ! |
|
93 |
||
94 |
!UndefinedObject methodsFor:'testing'! |
|
95 |
||
96 |
isNil |
|
97 |
"return true if I am nil - since I am, return true" |
|
98 |
||
99 |
^ true |
|
100 |
! |
|
101 |
||
102 |
notNil |
|
103 |
"return true if I am not nil - since I am nil, return false" |
|
104 |
||
105 |
^ false |
|
106 |
! |
|
107 |
||
108 |
size |
|
109 |
"return the number of indexed instvars |
|
110 |
defined here since size in Object ommits the nil-check" |
|
111 |
||
112 |
^ 0 |
|
113 |
! |
|
114 |
||
115 |
basicSize |
|
116 |
"return the number of indexed instvars |
|
117 |
defined here since size in Object ommits the nil-check" |
|
118 |
||
119 |
^ 0 |
|
120 |
! |
|
121 |
||
122 |
hash |
|
123 |
"return an integer useful as a hash key" |
|
124 |
||
125 |
^ 0 |
|
126 |
! |
|
127 |
||
128 |
identityHash |
|
129 |
"return an integer useful as a hash key" |
|
130 |
||
131 |
^ 0 |
|
41 | 132 |
! |
133 |
||
134 |
isLiteral |
|
135 |
"return true, if the receiver can be used as a literal |
|
136 |
(i.e. can be used in constant arrays)" |
|
137 |
||
138 |
^ true |
|
1 | 139 |
! ! |
140 |
||
141 |
!UndefinedObject methodsFor:'copying'! |
|
142 |
||
159 | 143 |
copy |
144 |
"return a shallow copy of myself |
|
145 |
- since there is only one nil in the system return self" |
|
146 |
||
147 |
^ self |
|
148 |
! |
|
149 |
||
1 | 150 |
shallowCopy |
151 |
"return a shallow copy of myself |
|
152 |
- since there is only one nil in the system return self" |
|
153 |
||
154 |
^ self |
|
155 |
! |
|
156 |
||
159 | 157 |
deepCopy |
158 |
"return a deep copy of myself |
|
159 |
- since there is only one nil in the system return self" |
|
160 |
||
161 |
^ self |
|
162 |
! |
|
163 |
||
13 | 164 |
simpleDeepCopy |
165 |
"return a deep copy of myself |
|
166 |
- since there is only one nil in the system return self" |
|
167 |
||
168 |
^ self |
|
169 |
! |
|
170 |
||
171 |
deepCopyUsing:aDictionary |
|
172 |
"return a deep copy of myself |
|
173 |
- since there is only one nil in the system return self" |
|
174 |
||
175 |
^ self |
|
1 | 176 |
! ! |
177 |
||
178 |
!UndefinedObject methodsFor:'printing & storing'! |
|
179 |
||
180 |
printString |
|
181 |
"return a string for printing myself" |
|
182 |
||
183 |
^ 'nil' |
|
184 |
! |
|
185 |
||
186 |
storeString |
|
187 |
"return a string for storing myself" |
|
188 |
||
189 |
^ 'nil' |
|
63 | 190 |
! |
191 |
||
192 |
printOn:aStream |
|
193 |
"append a printed representation of the receiver to the |
|
194 |
argument, aStream" |
|
195 |
||
196 |
aStream nextPutAll:'nil' |
|
197 |
! |
|
198 |
||
199 |
storeOn:aStream |
|
200 |
"append a printed representation of the receiver to the |
|
201 |
argument, aStream, which allows reconstruction of it" |
|
202 |
||
203 |
^ self printOn:aStream |
|
1 | 204 |
! ! |
2 | 205 |
|
77 | 206 |
!UndefinedObject methodsFor:'subclass creation'! |
207 |
||
202 | 208 |
nilSubclass:selector args:args |
356 | 209 |
"common helper for subclass creation. |
210 |
Creates a nil-superclass class with entries for the minimum |
|
211 |
required protocol (#class, #isBehavior and #doesNotUnderstand:). |
|
212 |
These are required to avoid getting into deep trouble when |
|
213 |
inspecting or debugging instances of this new class. |
|
77 | 214 |
|
356 | 215 |
The methods get a modified source code to remind you that these |
216 |
methods were automatically generated." |
|
217 |
||
218 |
|newClass mA| |
|
202 | 219 |
|
220 |
Class withoutUpdatingChangesDo: |
|
77 | 221 |
[ |
202 | 222 |
newClass := Object perform:selector withArguments:args |
77 | 223 |
]. |
224 |
newClass notNil ifTrue:[ |
|
159 | 225 |
newClass setSuperclass:nil. |
356 | 226 |
|
227 |
" |
|
228 |
copy over method objects from Object |
|
229 |
" |
|
159 | 230 |
newClass |
356 | 231 |
setSelectors:(Array |
232 |
with:#class |
|
233 |
with:#isBehavior |
|
234 |
with:#doesNotUnderstand:) |
|
235 |
methods:(mA := Array |
|
236 |
with:(Object compiledMethodAt:#class) copy |
|
237 |
with:(Object compiledMethodAt:#isBehavior) copy |
|
238 |
with:(Object compiledMethodAt:#doesNotUnderstand:) copy). |
|
239 |
||
240 |
" |
|
241 |
and modify the source code |
|
242 |
" |
|
243 |
mA do:[:m | |
|
244 |
m source:m source , ' |
|
245 |
" |
|
246 |
*** WARNING |
|
247 |
*** |
|
248 |
*** this method has been automatically created, |
|
249 |
*** since all nil-subclasses should respond to some minimum required |
|
250 |
*** protocol. |
|
251 |
*** |
|
252 |
*** Inspection and/or debugging of instances may not be possible, |
|
253 |
*** if you remove/change this method. |
|
254 |
" |
|
255 |
'. |
|
256 |
]. |
|
159 | 257 |
Class addChangeRecordForClass:newClass. |
77 | 258 |
]. |
259 |
^ newClass |
|
202 | 260 |
! |
261 |
||
262 |
subclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat |
|
263 |
"create a new class which has nil as superclass |
|
264 |
- i.e. traps into doesNotUnderstand: for all of its messages." |
|
265 |
||
266 |
^ self nilSubclass:(thisContext selector) args:(thisContext args) |
|
77 | 267 |
! |
268 |
||
269 |
variableSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat |
|
159 | 270 |
"create a new class which has nil as superclass |
271 |
- i.e. traps into doesNotUnderstand: for all of its messages." |
|
77 | 272 |
|
202 | 273 |
^ self nilSubclass:(thisContext selector) args:(thisContext args) |
77 | 274 |
! |
275 |
||
276 |
variableByteSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat |
|
159 | 277 |
"create a new class which has nil as superclass |
278 |
- i.e. traps into doesNotUnderstand: for all of its messages." |
|
77 | 279 |
|
202 | 280 |
^ self nilSubclass:(thisContext selector) args:(thisContext args) |
77 | 281 |
! ! |