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