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
|
77
|
14 |
instanceVariableNames:'name category instvars signature'
|
1
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Classes'
|
|
18 |
!
|
|
19 |
|
|
20 |
ClassDescription comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
155
|
22 |
All Rights Reserved
|
92
|
23 |
|
155
|
24 |
$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.9 1994-10-10 00:22:34 claus Exp $
|
68
|
25 |
'!
|
1
|
26 |
|
68
|
27 |
!ClassDescription class methodsFor:'documentation'!
|
1
|
28 |
|
88
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
155
|
32 |
All Rights Reserved
|
88
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
155
|
45 |
$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.9 1994-10-10 00:22:34 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
68
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this class has been added for ST-80 compatibility only.
|
|
52 |
All class stuff used to be in Behavior and Class - but, to be
|
|
53 |
able to file in some PD code, it became nescessary to add it.
|
88
|
54 |
ClassDescription adds some descriptive information to the basic
|
|
55 |
Behavior class.
|
1
|
56 |
|
68
|
57 |
Instance variables:
|
|
58 |
|
|
59 |
name <String> the classes name
|
|
60 |
category <String> the classes category
|
|
61 |
instvars <String> the names of the instance variables
|
|
62 |
"
|
|
63 |
! !
|
1
|
64 |
|
77
|
65 |
!ClassDescription methodsFor:'special accessing'!
|
|
66 |
|
|
67 |
setName:aString
|
|
68 |
"set the classes name - be careful, it will be still
|
|
69 |
in the Smalltalk dictionary - under another key.
|
|
70 |
This is NOT for general use - see renameTo:"
|
|
71 |
|
|
72 |
name := aString
|
|
73 |
!
|
|
74 |
|
|
75 |
setInstanceVariableString:aString
|
|
76 |
"set the classes instvarnames string - no recompilation
|
|
77 |
is done and no change records are written.
|
|
78 |
This is NOT for general use."
|
|
79 |
|
|
80 |
instvars := aString.
|
|
81 |
! !
|
|
82 |
|
1
|
83 |
!ClassDescription methodsFor:'accessing'!
|
|
84 |
|
|
85 |
instanceVariableString
|
|
86 |
"return a string of the instance variable names"
|
|
87 |
|
|
88 |
instvars isNil ifTrue:[^ ''].
|
|
89 |
^ instvars
|
77
|
90 |
|
|
91 |
"
|
|
92 |
Point instanceVariableString
|
|
93 |
"
|
1
|
94 |
!
|
|
95 |
|
|
96 |
instanceVariableString:aString
|
|
97 |
"set the classes instvarnames string - notice, that this
|
|
98 |
should be used only during class creation; the number of
|
|
99 |
instance variables is determined by another instance
|
|
100 |
(see Behavior)."
|
|
101 |
|
|
102 |
instvars := aString.
|
|
103 |
self changed
|
|
104 |
!
|
|
105 |
|
10
|
106 |
instVarNames
|
|
107 |
"return a collection of the instance variable name-strings"
|
|
108 |
|
|
109 |
instvars isNil ifTrue:[
|
155
|
110 |
^ OrderedCollection new
|
10
|
111 |
].
|
|
112 |
^ instvars asCollectionOfWords
|
77
|
113 |
|
|
114 |
"
|
|
115 |
Point instVarNames
|
|
116 |
"
|
10
|
117 |
!
|
|
118 |
|
|
119 |
allInstVarNames
|
|
120 |
"return a collection of all the instance variable name-strings
|
77
|
121 |
this includes all superclass-instance variables.
|
|
122 |
Instvars of superclasses come first (i.e. the position matches
|
|
123 |
the instVarAt:-index)."
|
10
|
124 |
|
|
125 |
^ self addAllInstVarNamesTo:(OrderedCollection new)
|
|
126 |
|
77
|
127 |
"
|
|
128 |
Dictionary instVarNames
|
|
129 |
Dictionary allInstVarNames
|
|
130 |
"
|
1
|
131 |
!
|
|
132 |
|
|
133 |
name
|
77
|
134 |
"return the name of the class. In the current implementation,
|
|
135 |
this returns a string, but will be changed to Symbol soon."
|
1
|
136 |
|
|
137 |
^ name
|
|
138 |
!
|
|
139 |
|
|
140 |
category
|
77
|
141 |
"return the category of the class.
|
|
142 |
The returned value may be a string or symbol."
|
1
|
143 |
|
|
144 |
^ category
|
77
|
145 |
|
|
146 |
"
|
|
147 |
Point category
|
|
148 |
Dictionary category
|
|
149 |
"
|
1
|
150 |
!
|
|
151 |
|
|
152 |
category:aStringOrSymbol
|
77
|
153 |
"set the category of the class to be the argument, aStringOrSymbol"
|
1
|
154 |
|
|
155 |
category := aStringOrSymbol asSymbol
|
|
156 |
! !
|
10
|
157 |
|
77
|
158 |
!ClassDescription methodsFor:'signature checking'!
|
|
159 |
|
|
160 |
signature
|
|
161 |
"return a signature number - this number is useful for a quick
|
|
162 |
check for changed classes, and is done in the binary-object loader,
|
|
163 |
and the dynamic class loader.
|
|
164 |
Do NOT change the algorithm here - others may depend on it.
|
|
165 |
Also, the algorithm may change - so never interpret the returned value
|
92
|
166 |
(if at all, use the access #XXXFromSignature: methods)"
|
77
|
167 |
|
|
168 |
|value "{ Class: SmallInteger }"
|
|
169 |
nameKey "{ Class: SmallInteger }" |
|
|
170 |
|
|
171 |
signature notNil ifTrue:[^ signature].
|
|
172 |
|
|
173 |
value := self flags bitAnd:(Class maskIndexType).
|
|
174 |
value := (value bitShift:3) + ((self class instSize - Class instSize) bitAnd:7).
|
|
175 |
value := (value bitShift:7) + (self instSize bitAnd:16r7F).
|
|
176 |
|
|
177 |
nameKey := 0.
|
|
178 |
self allInstVarNames do:[:name |
|
155
|
179 |
nameKey := nameKey bitShift:1.
|
|
180 |
(nameKey bitAnd:16r10000) ~~ 0 ifTrue:[
|
|
181 |
nameKey := nameKey bitXor:1.
|
|
182 |
nameKey := nameKey bitAnd:16rFFFF.
|
|
183 |
].
|
|
184 |
nameKey := (nameKey + (name at:1) asciiValue) bitAnd:16rFFFF.
|
77
|
185 |
].
|
|
186 |
value := value + (nameKey bitShift:14).
|
|
187 |
signature := value.
|
|
188 |
^ value
|
|
189 |
|
|
190 |
"
|
|
191 |
Array signature
|
|
192 |
ByteArray signature
|
|
193 |
View signature
|
|
194 |
"
|
|
195 |
!
|
|
196 |
|
|
197 |
instSizeFromSignature:aSignature
|
|
198 |
"for checking class compatibility: return the some number based on
|
|
199 |
the instSize from a signature key (not always the real instSize)."
|
|
200 |
|
|
201 |
^ aSignature bitAnd:16r7F
|
|
202 |
|
|
203 |
"
|
|
204 |
Class instSizeFromSignature:Point signature.
|
|
205 |
Class instSizeFromSignature:Association signature.
|
|
206 |
Class instSizeFromSignature:Dictionary signature.
|
|
207 |
"
|
|
208 |
!
|
|
209 |
|
|
210 |
classinstSizeFromSignature:aSignature
|
|
211 |
"for checking class compatibility: return some number based on
|
|
212 |
the classinstSize from a signature key (not always the real classinstsize)."
|
|
213 |
|
|
214 |
^ (aSignature bitShift:-7) bitAnd:7
|
|
215 |
!
|
|
216 |
|
|
217 |
instTypeFromSignature:aSignature
|
|
218 |
"for checking class compatibility: return some number based on
|
|
219 |
the instType (i.e. variableBytes/Pointers etc.) from a signature key."
|
|
220 |
|
|
221 |
^ (aSignature bitShift:-10) bitAnd:(Class maskIndexType)
|
|
222 |
|
|
223 |
"
|
|
224 |
Class instTypeFromSignature:Object signature.
|
|
225 |
Class instTypeFromSignature:Array signature.
|
|
226 |
Class instTypeFromSignature:String signature.
|
|
227 |
Class instTypeFromSignature:OrderedCollection signature.
|
|
228 |
"
|
|
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 |
|
10
|
243 |
!ClassDescription methodsFor:'renaming'!
|
|
244 |
|
|
245 |
renameTo:newName
|
|
246 |
"change the name of the class - this writes a change record"
|
|
247 |
|
|
248 |
|oldName oldSym|
|
|
249 |
|
|
250 |
oldName := name.
|
|
251 |
oldSym := name asSymbol.
|
|
252 |
self setName:newName.
|
|
253 |
|
|
254 |
Smalltalk at:oldSym put:nil.
|
|
255 |
Smalltalk removeKey:oldSym. "26.jun 93"
|
|
256 |
Smalltalk at:(newName asSymbol) put:self.
|
|
257 |
! !
|
|
258 |
|
92
|
259 |
!ClassDescription methodsFor:'printing & storing'!
|
68
|
260 |
|
|
261 |
displayString
|
|
262 |
"return a string for display in inspoectors"
|
|
263 |
|
|
264 |
category == #obsolete ifTrue:[
|
155
|
265 |
"add obsolete - to make life easier ..."
|
|
266 |
^ self name "super displayString" , ' (obsolete)'
|
68
|
267 |
].
|
155
|
268 |
category == #removed ifTrue:[
|
|
269 |
"add removed - to make life easier ..."
|
|
270 |
^ self name "super displayString" , ' (removed)'
|
|
271 |
].
|
|
272 |
^ self name "super displayString"
|
68
|
273 |
! !
|
|
274 |
|
10
|
275 |
!ClassDescription methodsFor:'private'!
|
|
276 |
|
|
277 |
addAllInstVarNamesTo:aCollection
|
|
278 |
"helper - add the name-strings of the instance variables and of the inst-vars
|
|
279 |
of all superclasses to the argument, aCollection. Return aCollection"
|
|
280 |
|
|
281 |
(superclass notNil) ifTrue:[
|
155
|
282 |
superclass addAllInstVarNamesTo:aCollection
|
10
|
283 |
].
|
|
284 |
instvars notNil ifTrue:[
|
155
|
285 |
aCollection addAll:(instvars asCollectionOfWords).
|
10
|
286 |
].
|
|
287 |
^ aCollection
|
|
288 |
! !
|