author | Claus Gittinger <cg@exept.de> |
Tue, 22 Oct 1996 21:38:13 +0200 | |
changeset 1803 | 754f9205b651 |
parent 1638 | 8df0060e4d73 |
child 1868 | 1cd4273ea11b |
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 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
180 |
|newClass methodDict method| |
202 | 181 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
182 |
Class withoutUpdatingChangesDo:[ |
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
183 |
newClass := Object perform:selector withArguments:args |
77 | 184 |
]. |
185 |
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
|
186 |
newClass setSuperclass:nil. |
1803
754f9205b651
meta's superclass should be class - not Object.
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
187 |
newClass class setSuperclass:Class. |
356 | 188 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
189 |
newClass methodDictionary size == 0 ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
190 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
191 |
copy over method objects from Object |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
192 |
and modify the source code |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
193 |
" |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
194 |
methodDict := MethodDictionary new:3. |
1638 | 195 |
#(#class #isBehavior #doesNotUnderstand:) do:[:sel| |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
196 |
method := (Object compiledMethodAt:sel) copy. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
197 |
method source: method source , ' |
356 | 198 |
" |
199 |
*** WARNING |
|
200 |
*** |
|
201 |
*** this method has been automatically created, |
|
202 |
*** since all nil-subclasses should respond to some minimum required |
|
203 |
*** protocol. |
|
204 |
*** |
|
205 |
*** Inspection and/or debugging of instances may not be possible, |
|
206 |
*** if you remove/change this method. |
|
207 |
" |
|
208 |
'. |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
209 |
methodDict at:sel put:method. |
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
210 |
]. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
211 |
newClass methodDictionary:methodDict. |
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
212 |
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
|
213 |
] |
77 | 214 |
]. |
215 |
^ newClass |
|
1029
c469a63e88e2
only redefine #class/#isbehavior/#doesNotUnderstand once (if no methods are present yet)
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
216 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1303
diff
changeset
|
217 |
"Modified: 12.6.1996 / 10:46:15 / stefan" |
1803
754f9205b651
meta's superclass should be class - not Object.
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
218 |
"Modified: 22.10.1996 / 20:30:06 / cg" |
202 | 219 |
! |
220 |
||
221 |
subclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat |
|
222 |
"create a new class which has nil as superclass |
|
223 |
- i.e. traps into doesNotUnderstand: for all of its messages." |
|
224 |
||
225 |
^ self nilSubclass:(thisContext selector) args:(thisContext args) |
|
695 | 226 |
! |
227 |
||
228 |
variableByteSubclass: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) |
|
233 |
! |
|
77 | 234 |
|
235 |
variableSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat |
|
159 | 236 |
"create a new class which has nil as superclass |
237 |
- i.e. traps into doesNotUnderstand: for all of its messages." |
|
77 | 238 |
|
202 | 239 |
^ self nilSubclass:(thisContext selector) args:(thisContext args) |
695 | 240 |
! ! |
241 |
||
242 |
!UndefinedObject methodsFor:'testing'! |
|
243 |
||
244 |
basicSize |
|
245 |
"return the number of indexed instvars |
|
246 |
defined here since size in Object ommits the nil-check" |
|
247 |
||
248 |
^ 0 |
|
249 |
! |
|
250 |
||
251 |
hash |
|
252 |
"return an integer useful as a hash key" |
|
253 |
||
254 |
^ 0 |
|
255 |
! |
|
256 |
||
257 |
identityHash |
|
258 |
"return an integer useful as a hash key" |
|
259 |
||
260 |
^ 0 |
|
261 |
! |
|
262 |
||
263 |
isLiteral |
|
264 |
"return true, if the receiver can be used as a literal |
|
265 |
(i.e. can be used in constant arrays)" |
|
77 | 266 |
|
695 | 267 |
^ true |
268 |
! |
|
269 |
||
270 |
isNil |
|
271 |
"return true if I am nil - since I am, return true" |
|
272 |
||
273 |
^ true |
|
274 |
! |
|
275 |
||
276 |
notNil |
|
277 |
"return true if I am not nil - since I am nil, return false" |
|
77 | 278 |
|
695 | 279 |
^ false |
280 |
! |
|
281 |
||
282 |
size |
|
283 |
"return the number of indexed instvars |
|
284 |
defined here since size in Object ommits the nil-check" |
|
285 |
||
286 |
^ 0 |
|
77 | 287 |
! ! |
695 | 288 |
|
289 |
!UndefinedObject class methodsFor:'documentation'! |
|
290 |
||
291 |
version |
|
1803
754f9205b651
meta's superclass should be class - not Object.
Claus Gittinger <cg@exept.de>
parents:
1638
diff
changeset
|
292 |
^ '$Header: /cvs/stx/stx/libbasic/UndefinedObject.st,v 1.26 1996-10-22 19:38:13 cg Exp $' |
695 | 293 |
! ! |