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