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