author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 15:28:26 +0100 | |
changeset 528 | a083413dfbe8 |
parent 459 | 744b144ae909 |
child 620 | c7353f86a302 |
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 |
|
216 | 14 |
instanceVariableNames:'name category instvars primitiveSpec signature' |
1 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Classes' |
|
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 |
||
36 |
version |
|
528
a083413dfbe8
converted version methods from comment-only to returning-a-string
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.20 1995-11-11 14:27:50 cg Exp $' |
88 | 38 |
! |
39 |
||
68 | 40 |
documentation |
41 |
" |
|
42 |
this class has been added for ST-80 compatibility only. |
|
43 |
All class stuff used to be in Behavior and Class - but, to be |
|
356 | 44 |
able to file in some PD code, it became nescessary to add C'Description |
45 |
in between it. |
|
88 | 46 |
ClassDescription adds some descriptive information to the basic |
47 |
Behavior class. |
|
1 | 48 |
|
68 | 49 |
Instance variables: |
50 |
||
308 | 51 |
name <String> the classes name |
52 |
category <String> the classes category |
|
53 |
instvars <String> the names of the instance variables |
|
54 |
primitiveSpec <Array|nil> describes primitiveIncludes, primitiveFunctions etc. |
|
55 |
signature <SmallInteger> the classes signature (used to detect obsolete |
|
56 |
or changed classes with binaryStorage) |
|
68 | 57 |
" |
58 |
! ! |
|
1 | 59 |
|
356 | 60 |
!ClassDescription class methodsFor:'instance creation'! |
61 |
||
62 |
new |
|
63 |
"creates and returns a new class. |
|
64 |
Redefined to give the new class at least some name info" |
|
65 |
||
66 |
|newClass| |
|
67 |
||
68 |
newClass := super new. |
|
69 |
newClass setName:('some' , self name). |
|
70 |
^ newClass |
|
71 |
! ! |
|
72 |
||
77 | 73 |
!ClassDescription methodsFor:'special accessing'! |
74 |
||
75 |
setName:aString |
|
76 |
"set the classes name - be careful, it will be still |
|
77 |
in the Smalltalk dictionary - under another key. |
|
78 |
This is NOT for general use - see renameTo:" |
|
79 |
||
80 |
name := aString |
|
81 |
! |
|
82 |
||
83 |
setInstanceVariableString:aString |
|
84 |
"set the classes instvarnames string - no recompilation |
|
200 | 85 |
or updates are done and no changeList records are written. |
77 | 86 |
This is NOT for general use." |
87 |
||
88 |
instvars := aString. |
|
89 |
! ! |
|
90 |
||
1 | 91 |
!ClassDescription methodsFor:'accessing'! |
92 |
||
93 |
instanceVariableString |
|
94 |
"return a string of the instance variable names" |
|
95 |
||
96 |
instvars isNil ifTrue:[^ '']. |
|
97 |
^ instvars |
|
77 | 98 |
|
99 |
" |
|
100 |
Point instanceVariableString |
|
101 |
" |
|
1 | 102 |
! |
103 |
||
10 | 104 |
instVarNames |
105 |
"return a collection of the instance variable name-strings" |
|
106 |
||
107 |
instvars isNil ifTrue:[ |
|
155 | 108 |
^ OrderedCollection new |
10 | 109 |
]. |
110 |
^ instvars asCollectionOfWords |
|
77 | 111 |
|
112 |
" |
|
113 |
Point instVarNames |
|
114 |
" |
|
10 | 115 |
! |
116 |
||
308 | 117 |
instanceVariableOffsets |
118 |
"returns a dictionary containing the instance variable index |
|
119 |
for each instVar name" |
|
120 |
||
121 |
|dict index| |
|
122 |
||
123 |
index := 0. dict := Dictionary new. |
|
124 |
self allInstVarNames do:[:nm | index := index + 1. dict at:nm put:index]. |
|
125 |
^ dict |
|
126 |
||
127 |
" |
|
128 |
Point instanceVariableOffsets |
|
129 |
GraphicsContext instanceVariableOffsets |
|
130 |
" |
|
131 |
! |
|
132 |
||
10 | 133 |
allInstVarNames |
134 |
"return a collection of all the instance variable name-strings |
|
77 | 135 |
this includes all superclass-instance variables. |
136 |
Instvars of superclasses come first (i.e. the position matches |
|
137 |
the instVarAt:-index)." |
|
10 | 138 |
|
139 |
^ self addAllInstVarNamesTo:(OrderedCollection new) |
|
140 |
||
77 | 141 |
" |
142 |
Dictionary instVarNames |
|
143 |
Dictionary allInstVarNames |
|
144 |
" |
|
1 | 145 |
! |
146 |
||
328 | 147 |
instVarOffsetOf:aVariableName |
148 |
"return the index (as used in instVarAt:/instVarAt:put:) of a named instance |
|
149 |
variable. The returned number is 1..instSize for valid variable names, nil for |
|
150 |
illegal names." |
|
151 |
||
152 |
^ self allInstVarNames indexOf:aVariableName ifAbsent:nil |
|
153 |
! |
|
154 |
||
155 |
instVarAtOffset:index |
|
156 |
"return the name of the instance variable at index" |
|
157 |
||
158 |
^ self allInstanceVariableNames at:index |
|
159 |
! |
|
160 |
||
1 | 161 |
name |
77 | 162 |
"return the name of the class. In the current implementation, |
163 |
this returns a string, but will be changed to Symbol soon." |
|
1 | 164 |
|
165 |
^ name |
|
166 |
! |
|
167 |
||
168 |
category |
|
77 | 169 |
"return the category of the class. |
170 |
The returned value may be a string or symbol." |
|
1 | 171 |
|
172 |
^ category |
|
77 | 173 |
|
174 |
" |
|
175 |
Point category |
|
176 |
Dictionary category |
|
177 |
" |
|
1 | 178 |
! |
179 |
||
180 |
category:aStringOrSymbol |
|
77 | 181 |
"set the category of the class to be the argument, aStringOrSymbol" |
1 | 182 |
|
249 | 183 |
aStringOrSymbol isNil ifTrue:[ |
184 |
category := aStringOrSymbol |
|
185 |
] ifFalse:[ |
|
186 |
category := aStringOrSymbol asSymbol |
|
187 |
] |
|
328 | 188 |
! |
189 |
||
190 |
organization |
|
191 |
"for ST80 compatibility; |
|
192 |
read the documentation in ClassOrganizer for more info." |
|
193 |
||
194 |
^ ClassOrganizer for:self |
|
1 | 195 |
! ! |
10 | 196 |
|
77 | 197 |
!ClassDescription methodsFor:'signature checking'! |
198 |
||
199 |
signature |
|
200 |
"return a signature number - this number is useful for a quick |
|
201 |
check for changed classes, and is done in the binary-object loader, |
|
202 |
and the dynamic class loader. |
|
203 |
Do NOT change the algorithm here - others may depend on it. |
|
204 |
Also, the algorithm may change - so never interpret the returned value |
|
92 | 205 |
(if at all, use the access #XXXFromSignature: methods)" |
77 | 206 |
|
207 |
|value "{ Class: SmallInteger }" |
|
208 |
nameKey "{ Class: SmallInteger }" | |
|
209 |
||
210 |
signature notNil ifTrue:[^ signature]. |
|
211 |
||
212 |
value := self flags bitAnd:(Class maskIndexType). |
|
213 |
value := (value bitShift:3) + ((self class instSize - Class instSize) bitAnd:7). |
|
214 |
value := (value bitShift:7) + (self instSize bitAnd:16r7F). |
|
215 |
||
216 |
nameKey := 0. |
|
217 |
self allInstVarNames do:[:name | |
|
155 | 218 |
nameKey := nameKey bitShift:1. |
219 |
(nameKey bitAnd:16r10000) ~~ 0 ifTrue:[ |
|
220 |
nameKey := nameKey bitXor:1. |
|
221 |
nameKey := nameKey bitAnd:16rFFFF. |
|
222 |
]. |
|
223 |
nameKey := (nameKey + (name at:1) asciiValue) bitAnd:16rFFFF. |
|
77 | 224 |
]. |
225 |
value := value + (nameKey bitShift:14). |
|
226 |
signature := value. |
|
227 |
^ value |
|
228 |
||
229 |
" |
|
230 |
Array signature |
|
231 |
ByteArray signature |
|
232 |
View signature |
|
233 |
" |
|
234 |
! |
|
235 |
||
236 |
instSizeFromSignature:aSignature |
|
237 |
"for checking class compatibility: return the some number based on |
|
238 |
the instSize from a signature key (not always the real instSize)." |
|
239 |
||
240 |
^ aSignature bitAnd:16r7F |
|
241 |
||
242 |
" |
|
243 |
Class instSizeFromSignature:Point signature. |
|
244 |
Class instSizeFromSignature:Association signature. |
|
245 |
Class instSizeFromSignature:Dictionary signature. |
|
246 |
" |
|
247 |
! |
|
248 |
||
249 |
classinstSizeFromSignature:aSignature |
|
250 |
"for checking class compatibility: return some number based on |
|
251 |
the classinstSize from a signature key (not always the real classinstsize)." |
|
252 |
||
253 |
^ (aSignature bitShift:-7) bitAnd:7 |
|
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 |
instNameKeyFromSignature:aSignature |
|
271 |
"for checking class compatibility: return a number based on the |
|
272 |
names and order of the instance variables from a signature key." |
|
273 |
||
274 |
^ (aSignature bitShift:-14) bitAnd:16rFFFF |
|
275 |
||
276 |
" |
|
277 |
Point instNameKeyFromSignature:Point signature. |
|
278 |
Association instNameKeyFromSignature:Association signature. |
|
279 |
" |
|
280 |
! ! |
|
281 |
||
10 | 282 |
!ClassDescription methodsFor:'renaming'! |
283 |
||
284 |
renameTo:newName |
|
293 | 285 |
"change the name of the class" |
10 | 286 |
|
293 | 287 |
|oldSym| |
10 | 288 |
|
289 |
oldSym := name asSymbol. |
|
290 |
self setName:newName. |
|
291 |
||
292 |
Smalltalk at:oldSym put:nil. |
|
293 |
Smalltalk removeKey:oldSym. "26.jun 93" |
|
294 |
Smalltalk at:(newName asSymbol) put:self. |
|
295 |
! ! |
|
296 |
||
92 | 297 |
!ClassDescription methodsFor:'printing & storing'! |
68 | 298 |
|
299 |
displayString |
|
293 | 300 |
"return a string for display in inspectors" |
301 |
||
302 |
|nm more| |
|
68 | 303 |
|
304 |
category == #obsolete ifTrue:[ |
|
155 | 305 |
"add obsolete - to make life easier ..." |
293 | 306 |
more := ' (obsolete)' |
68 | 307 |
]. |
155 | 308 |
category == #removed ifTrue:[ |
309 |
"add removed - to make life easier ..." |
|
293 | 310 |
more := ' (removed)' |
155 | 311 |
]. |
293 | 312 |
|
313 |
nm := self name. |
|
314 |
more isNil ifTrue:[^ nm]. |
|
315 |
^ nm , more |
|
68 | 316 |
! ! |
317 |
||
10 | 318 |
!ClassDescription methodsFor:'private'! |
319 |
||
320 |
addAllInstVarNamesTo:aCollection |
|
308 | 321 |
"helper for allInstVarNames - add the name-strings of the instance variables |
322 |
and of the inst-vars of all superclasses to the argument, aCollection. |
|
323 |
Return aCollection." |
|
10 | 324 |
|
459
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
325 |
|superInsts| |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
326 |
|
10 | 327 |
(superclass notNil) ifTrue:[ |
155 | 328 |
superclass addAllInstVarNamesTo:aCollection |
10 | 329 |
]. |
330 |
instvars notNil ifTrue:[ |
|
155 | 331 |
aCollection addAll:(instvars asCollectionOfWords). |
459
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
332 |
] ifFalse:[ |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
333 |
"/ mhmh - either someone klduged around, or this is |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
334 |
"/ a system running without sourceInfo. Generate |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
335 |
"/ synthetic names. |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
336 |
|
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
337 |
superclass isNil ifTrue:[ |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
338 |
superInsts := 0 |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
339 |
] ifFalse:[ |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
340 |
superInsts := superclass instSize |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
341 |
]. |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
342 |
aCollection addAll:((superInsts+1 to:self instSize) |
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
343 |
collect:[:index | '* instVar' , index printString , ' *']) |
10 | 344 |
]. |
345 |
^ aCollection |
|
459
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
346 |
|
744b144ae909
generate synthetic instvar names (for -sourceInfo)
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
347 |
"Modified: 30.10.1995 / 19:46:21 / cg" |
10 | 348 |
! ! |