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