author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:47:14 +0200 | |
changeset 1292 | 89497fff7f87 |
parent 1266 | cef9b3cd49df |
child 1554 | c6d19d48d02a |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
155 | 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 |
Behavior subclass:#ClassDescription |
|
1091 | 14 |
instanceVariableNames:'name category instvars primitiveSpec signature' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Classes' |
|
1 | 18 |
! |
19 |
||
68 | 20 |
!ClassDescription class methodsFor:'documentation'! |
1 | 21 |
|
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
155 | 25 |
All Rights Reserved |
88 | 26 |
|
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 |
||
68 | 36 |
documentation |
37 |
" |
|
38 |
this class has been added for ST-80 compatibility only. |
|
39 |
All class stuff used to be in Behavior and Class - but, to be |
|
356 | 40 |
able to file in some PD code, it became nescessary to add C'Description |
41 |
in between it. |
|
88 | 42 |
ClassDescription adds some descriptive information to the basic |
43 |
Behavior class. |
|
1 | 44 |
|
1292 | 45 |
[Instance variables:] |
46 |
||
47 |
name <Symbol> the classes name |
|
68 | 48 |
|
1292 | 49 |
category <String | Symbol> the classes category |
905 | 50 |
|
1292 | 51 |
instvars <String> the names of the instance variables |
905 | 52 |
|
1292 | 53 |
primitiveSpec <Array | nil> describes primitiveIncludes, primitiveFunctions etc. |
905 | 54 |
|
1292 | 55 |
signature <SmallInteger> the classes signature (used to detect obsolete |
56 |
or changed classes with binaryStorage) |
|
57 |
This is filled in lazy - i.e. upon the first signature query. |
|
58 |
||
59 |
[author:] |
|
60 |
Claus Gittinger |
|
68 | 61 |
" |
62 |
! ! |
|
1 | 63 |
|
356 | 64 |
!ClassDescription class methodsFor:'instance creation'! |
65 |
||
66 |
new |
|
67 |
"creates and returns a new class. |
|
68 |
Redefined to give the new class at least some name info" |
|
69 |
||
70 |
|newClass| |
|
71 |
||
72 |
newClass := super new. |
|
73 |
newClass setName:('some' , self name). |
|
74 |
^ newClass |
|
75 |
! ! |
|
76 |
||
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
77 |
!ClassDescription class methodsFor:'queries'! |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
78 |
|
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
79 |
isBuiltInClass |
1266 | 80 |
"return true if this class is known by the run-time-system. |
81 |
Here, true is returned for myself, false for subclasses." |
|
82 |
||
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
83 |
^ self == ClassDescription class or:[self == ClassDescription] |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
84 |
|
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
85 |
"Created: 15.4.1996 / 17:16:59 / cg" |
1266 | 86 |
"Modified: 23.4.1996 / 15:56:54 / cg" |
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
87 |
! ! |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
88 |
|
1 | 89 |
!ClassDescription methodsFor:'accessing'! |
90 |
||
91 |
category |
|
77 | 92 |
"return the category of the class. |
93 |
The returned value may be a string or symbol." |
|
1 | 94 |
|
95 |
^ category |
|
77 | 96 |
|
97 |
" |
|
98 |
Point category |
|
99 |
Dictionary category |
|
100 |
" |
|
1 | 101 |
! |
102 |
||
103 |
category:aStringOrSymbol |
|
77 | 104 |
"set the category of the class to be the argument, aStringOrSymbol" |
1 | 105 |
|
249 | 106 |
aStringOrSymbol isNil ifTrue:[ |
107 |
category := aStringOrSymbol |
|
108 |
] ifFalse:[ |
|
109 |
category := aStringOrSymbol asSymbol |
|
110 |
] |
|
328 | 111 |
! |
112 |
||
620 | 113 |
instVarAtOffset:index |
114 |
"return the name of the instance variable at index" |
|
115 |
||
116 |
^ self allInstanceVariableNames at:index |
|
117 |
! |
|
118 |
||
119 |
instVarNames |
|
120 |
"return a collection of the instance variable name-strings" |
|
121 |
||
122 |
instvars isNil ifTrue:[ |
|
123 |
^ OrderedCollection new |
|
124 |
]. |
|
125 |
^ instvars asCollectionOfWords |
|
126 |
||
127 |
" |
|
128 |
Point instVarNames |
|
129 |
" |
|
130 |
! |
|
131 |
||
132 |
instVarOffsetOf:aVariableName |
|
133 |
"return the index (as used in instVarAt:/instVarAt:put:) of a named instance |
|
134 |
variable. The returned number is 1..instSize for valid variable names, nil for |
|
135 |
illegal names." |
|
136 |
||
137 |
^ self allInstVarNames indexOf:aVariableName ifAbsent:nil |
|
138 |
! |
|
139 |
||
140 |
instanceVariableOffsets |
|
141 |
"returns a dictionary containing the instance variable index |
|
142 |
for each instVar name" |
|
143 |
||
144 |
|dict index| |
|
145 |
||
146 |
index := 0. dict := Dictionary new. |
|
147 |
self allInstVarNames do:[:nm | index := index + 1. dict at:nm put:index]. |
|
148 |
^ dict |
|
149 |
||
150 |
" |
|
151 |
Point instanceVariableOffsets |
|
152 |
GraphicsContext instanceVariableOffsets |
|
153 |
" |
|
154 |
! |
|
155 |
||
156 |
instanceVariableString |
|
157 |
"return a string of the instance variable names" |
|
158 |
||
159 |
instvars isNil ifTrue:[^ '']. |
|
160 |
^ instvars |
|
161 |
||
162 |
" |
|
163 |
Point instanceVariableString |
|
164 |
" |
|
165 |
! |
|
166 |
||
167 |
name |
|
168 |
"return the name of the class. In the current implementation, |
|
169 |
this returns a string, but will be changed to Symbol soon." |
|
170 |
||
171 |
^ name |
|
172 |
! |
|
173 |
||
328 | 174 |
organization |
175 |
"for ST80 compatibility; |
|
176 |
read the documentation in ClassOrganizer for more info." |
|
177 |
||
178 |
^ ClassOrganizer for:self |
|
1 | 179 |
! ! |
10 | 180 |
|
92 | 181 |
!ClassDescription methodsFor:'printing & storing'! |
68 | 182 |
|
183 |
displayString |
|
293 | 184 |
"return a string for display in inspectors" |
185 |
||
186 |
|nm more| |
|
68 | 187 |
|
188 |
category == #obsolete ifTrue:[ |
|
155 | 189 |
"add obsolete - to make life easier ..." |
293 | 190 |
more := ' (obsolete)' |
68 | 191 |
]. |
155 | 192 |
category == #removed ifTrue:[ |
193 |
"add removed - to make life easier ..." |
|
293 | 194 |
more := ' (removed)' |
155 | 195 |
]. |
293 | 196 |
|
197 |
nm := self name. |
|
198 |
more isNil ifTrue:[^ nm]. |
|
199 |
^ nm , more |
|
1091 | 200 |
! |
201 |
||
202 |
isObsolete |
|
203 |
"return true, if the receiver is obsolete |
|
204 |
(i.e. has been replaced by a different class or was removed, |
|
205 |
but is still referenced by instanced)" |
|
206 |
||
207 |
^ category == #obsolete or:[category == #removed] |
|
68 | 208 |
! ! |
209 |
||
620 | 210 |
!ClassDescription methodsFor:'renaming'! |
211 |
||
212 |
renameTo:newName |
|
213 |
"change the name of the class" |
|
214 |
||
215 |
|oldSym| |
|
216 |
||
217 |
oldSym := name asSymbol. |
|
218 |
self setName:newName. |
|
219 |
||
220 |
Smalltalk at:oldSym put:nil. |
|
221 |
Smalltalk removeKey:oldSym. "26.jun 93" |
|
222 |
Smalltalk at:(newName asSymbol) put:self. |
|
223 |
! ! |
|
224 |
||
225 |
!ClassDescription methodsFor:'signature checking'! |
|
226 |
||
227 |
classinstSizeFromSignature:aSignature |
|
228 |
"for checking class compatibility: return some number based on |
|
229 |
the classinstSize from a signature key (not always the real classinstsize)." |
|
230 |
||
231 |
^ (aSignature bitShift:-7) bitAnd:7 |
|
232 |
! |
|
233 |
||
234 |
instNameKeyFromSignature:aSignature |
|
235 |
"for checking class compatibility: return a number based on the |
|
236 |
names and order of the instance variables from a signature key." |
|
237 |
||
238 |
^ (aSignature bitShift:-14) bitAnd:16rFFFF |
|
239 |
||
240 |
" |
|
241 |
Point instNameKeyFromSignature:Point signature. |
|
242 |
Association instNameKeyFromSignature:Association signature. |
|
243 |
" |
|
244 |
! |
|
245 |
||
246 |
instSizeFromSignature:aSignature |
|
247 |
"for checking class compatibility: return the some number based on |
|
248 |
the instSize from a signature key (not always the real instSize)." |
|
249 |
||
250 |
^ aSignature bitAnd:16r7F |
|
251 |
||
252 |
" |
|
253 |
Class instSizeFromSignature:Point signature. |
|
254 |
Class instSizeFromSignature:Association signature. |
|
255 |
Class instSizeFromSignature:Dictionary signature. |
|
256 |
" |
|
257 |
! |
|
258 |
||
259 |
instTypeFromSignature:aSignature |
|
260 |
"for checking class compatibility: return some number based on |
|
261 |
the instType (i.e. variableBytes/Pointers etc.) from a signature key." |
|
262 |
||
263 |
^ (aSignature bitShift:-10) bitAnd:(Class maskIndexType) |
|
264 |
||
265 |
" |
|
266 |
Class instTypeFromSignature:Object signature. |
|
267 |
Class instTypeFromSignature:Array signature. |
|
268 |
Class instTypeFromSignature:String signature. |
|
269 |
Class instTypeFromSignature:OrderedCollection signature. |
|
270 |
" |
|
271 |
! |
|
272 |
||
273 |
signature |
|
274 |
"return a signature number - this number is useful for a quick |
|
275 |
check for changed classes, and is done in the binary-object loader, |
|
276 |
and the dynamic class loader. |
|
277 |
Do NOT change the algorithm here - others may depend on it. |
|
278 |
Also, the algorithm may change - so never interpret the returned value |
|
279 |
(if at all, use the access #XXXFromSignature: methods)" |
|
280 |
||
281 |
|value "{ Class: SmallInteger }" |
|
282 |
nameKey "{ Class: SmallInteger }" | |
|
283 |
||
284 |
signature notNil ifTrue:[^ signature]. |
|
285 |
||
286 |
value := self flags bitAnd:(Class maskIndexType). |
|
287 |
value := (value bitShift:3) + ((self class instSize - Class instSize) bitAnd:7). |
|
288 |
value := (value bitShift:7) + (self instSize bitAnd:16r7F). |
|
289 |
||
290 |
nameKey := 0. |
|
291 |
self allInstVarNames do:[:name | |
|
292 |
nameKey := nameKey bitShift:1. |
|
293 |
(nameKey bitAnd:16r10000) ~~ 0 ifTrue:[ |
|
294 |
nameKey := nameKey bitXor:1. |
|
295 |
nameKey := nameKey bitAnd:16rFFFF. |
|
296 |
]. |
|
297 |
nameKey := (nameKey + (name at:1) asciiValue) bitAnd:16rFFFF. |
|
298 |
]. |
|
299 |
value := value + (nameKey bitShift:14). |
|
300 |
signature := value. |
|
301 |
^ value |
|
302 |
||
303 |
" |
|
304 |
Array signature |
|
305 |
ByteArray signature |
|
306 |
View signature |
|
307 |
" |
|
308 |
! ! |
|
309 |
||
310 |
!ClassDescription methodsFor:'special accessing'! |
|
311 |
||
312 |
setInstanceVariableString:aString |
|
313 |
"set the classes instvarnames string - no recompilation |
|
314 |
or updates are done and no changeList records are written. |
|
315 |
This is NOT for general use." |
|
316 |
||
317 |
instvars := aString. |
|
318 |
! |
|
319 |
||
320 |
setName:aString |
|
321 |
"set the classes name - be careful, it will be still |
|
322 |
in the Smalltalk dictionary - under another key. |
|
323 |
This is NOT for general use - see renameTo:" |
|
324 |
||
325 |
name := aString |
|
326 |
! ! |
|
327 |
||
662 | 328 |
!ClassDescription class methodsFor:'documentation'! |
329 |
||
330 |
version |
|
1292 | 331 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/ClassDescr.st,v 1.28 1996-04-25 16:45:33 cg Exp $' |
662 | 332 |
! ! |