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