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 |
|
|
20 |
ClassDescription comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
155
|
22 |
All Rights Reserved
|
92
|
23 |
|
249
|
24 |
$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.12 1995-02-15 10:21:33 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 |
"
|
249
|
45 |
$Header: /cvs/stx/stx/libbasic/ClassDescription.st,v 1.12 1995-02-15 10:21:33 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
|
216
|
62 |
primitiveSpec <Array|nil> describes primitiveIncludes, primitiveFunctions
|
|
63 |
etc.
|
|
64 |
signature <SmallInteger> the classes signature (used to detect obsolete
|
|
65 |
or changed classes with binaryStorage)
|
68
|
66 |
"
|
|
67 |
! !
|
1
|
68 |
|
77
|
69 |
!ClassDescription methodsFor:'special accessing'!
|
|
70 |
|
|
71 |
setName:aString
|
|
72 |
"set the classes name - be careful, it will be still
|
|
73 |
in the Smalltalk dictionary - under another key.
|
|
74 |
This is NOT for general use - see renameTo:"
|
|
75 |
|
|
76 |
name := aString
|
|
77 |
!
|
|
78 |
|
|
79 |
setInstanceVariableString:aString
|
|
80 |
"set the classes instvarnames string - no recompilation
|
200
|
81 |
or updates are done and no changeList records are written.
|
77
|
82 |
This is NOT for general use."
|
|
83 |
|
|
84 |
instvars := aString.
|
|
85 |
! !
|
|
86 |
|
1
|
87 |
!ClassDescription methodsFor:'accessing'!
|
|
88 |
|
|
89 |
instanceVariableString
|
|
90 |
"return a string of the instance variable names"
|
|
91 |
|
|
92 |
instvars isNil ifTrue:[^ ''].
|
|
93 |
^ instvars
|
77
|
94 |
|
|
95 |
"
|
|
96 |
Point instanceVariableString
|
|
97 |
"
|
1
|
98 |
!
|
|
99 |
|
10
|
100 |
instVarNames
|
|
101 |
"return a collection of the instance variable name-strings"
|
|
102 |
|
|
103 |
instvars isNil ifTrue:[
|
155
|
104 |
^ OrderedCollection new
|
10
|
105 |
].
|
|
106 |
^ instvars asCollectionOfWords
|
77
|
107 |
|
|
108 |
"
|
|
109 |
Point instVarNames
|
|
110 |
"
|
10
|
111 |
!
|
|
112 |
|
|
113 |
allInstVarNames
|
|
114 |
"return a collection of all the instance variable name-strings
|
77
|
115 |
this includes all superclass-instance variables.
|
|
116 |
Instvars of superclasses come first (i.e. the position matches
|
|
117 |
the instVarAt:-index)."
|
10
|
118 |
|
|
119 |
^ self addAllInstVarNamesTo:(OrderedCollection new)
|
|
120 |
|
77
|
121 |
"
|
|
122 |
Dictionary instVarNames
|
|
123 |
Dictionary allInstVarNames
|
|
124 |
"
|
1
|
125 |
!
|
|
126 |
|
|
127 |
name
|
77
|
128 |
"return the name of the class. In the current implementation,
|
|
129 |
this returns a string, but will be changed to Symbol soon."
|
1
|
130 |
|
|
131 |
^ name
|
|
132 |
!
|
|
133 |
|
|
134 |
category
|
77
|
135 |
"return the category of the class.
|
|
136 |
The returned value may be a string or symbol."
|
1
|
137 |
|
|
138 |
^ category
|
77
|
139 |
|
|
140 |
"
|
|
141 |
Point category
|
|
142 |
Dictionary category
|
|
143 |
"
|
1
|
144 |
!
|
|
145 |
|
|
146 |
category:aStringOrSymbol
|
77
|
147 |
"set the category of the class to be the argument, aStringOrSymbol"
|
1
|
148 |
|
249
|
149 |
aStringOrSymbol isNil ifTrue:[
|
|
150 |
category := aStringOrSymbol
|
|
151 |
] ifFalse:[
|
|
152 |
category := aStringOrSymbol asSymbol
|
|
153 |
]
|
1
|
154 |
! !
|
10
|
155 |
|
77
|
156 |
!ClassDescription methodsFor:'signature checking'!
|
|
157 |
|
|
158 |
signature
|
|
159 |
"return a signature number - this number is useful for a quick
|
|
160 |
check for changed classes, and is done in the binary-object loader,
|
|
161 |
and the dynamic class loader.
|
|
162 |
Do NOT change the algorithm here - others may depend on it.
|
|
163 |
Also, the algorithm may change - so never interpret the returned value
|
92
|
164 |
(if at all, use the access #XXXFromSignature: methods)"
|
77
|
165 |
|
|
166 |
|value "{ Class: SmallInteger }"
|
|
167 |
nameKey "{ Class: SmallInteger }" |
|
|
168 |
|
|
169 |
signature notNil ifTrue:[^ signature].
|
|
170 |
|
|
171 |
value := self flags bitAnd:(Class maskIndexType).
|
|
172 |
value := (value bitShift:3) + ((self class instSize - Class instSize) bitAnd:7).
|
|
173 |
value := (value bitShift:7) + (self instSize bitAnd:16r7F).
|
|
174 |
|
|
175 |
nameKey := 0.
|
|
176 |
self allInstVarNames do:[:name |
|
155
|
177 |
nameKey := nameKey bitShift:1.
|
|
178 |
(nameKey bitAnd:16r10000) ~~ 0 ifTrue:[
|
|
179 |
nameKey := nameKey bitXor:1.
|
|
180 |
nameKey := nameKey bitAnd:16rFFFF.
|
|
181 |
].
|
|
182 |
nameKey := (nameKey + (name at:1) asciiValue) bitAnd:16rFFFF.
|
77
|
183 |
].
|
|
184 |
value := value + (nameKey bitShift:14).
|
|
185 |
signature := value.
|
|
186 |
^ value
|
|
187 |
|
|
188 |
"
|
|
189 |
Array signature
|
|
190 |
ByteArray signature
|
|
191 |
View signature
|
|
192 |
"
|
|
193 |
!
|
|
194 |
|
|
195 |
instSizeFromSignature:aSignature
|
|
196 |
"for checking class compatibility: return the some number based on
|
|
197 |
the instSize from a signature key (not always the real instSize)."
|
|
198 |
|
|
199 |
^ aSignature bitAnd:16r7F
|
|
200 |
|
|
201 |
"
|
|
202 |
Class instSizeFromSignature:Point signature.
|
|
203 |
Class instSizeFromSignature:Association signature.
|
|
204 |
Class instSizeFromSignature:Dictionary signature.
|
|
205 |
"
|
|
206 |
!
|
|
207 |
|
|
208 |
classinstSizeFromSignature:aSignature
|
|
209 |
"for checking class compatibility: return some number based on
|
|
210 |
the classinstSize from a signature key (not always the real classinstsize)."
|
|
211 |
|
|
212 |
^ (aSignature bitShift:-7) bitAnd:7
|
|
213 |
!
|
|
214 |
|
|
215 |
instTypeFromSignature:aSignature
|
|
216 |
"for checking class compatibility: return some number based on
|
|
217 |
the instType (i.e. variableBytes/Pointers etc.) from a signature key."
|
|
218 |
|
|
219 |
^ (aSignature bitShift:-10) bitAnd:(Class maskIndexType)
|
|
220 |
|
|
221 |
"
|
|
222 |
Class instTypeFromSignature:Object signature.
|
|
223 |
Class instTypeFromSignature:Array signature.
|
|
224 |
Class instTypeFromSignature:String signature.
|
|
225 |
Class instTypeFromSignature:OrderedCollection signature.
|
|
226 |
"
|
|
227 |
!
|
|
228 |
|
|
229 |
instNameKeyFromSignature:aSignature
|
|
230 |
"for checking class compatibility: return a number based on the
|
|
231 |
names and order of the instance variables from a signature key."
|
|
232 |
|
|
233 |
^ (aSignature bitShift:-14) bitAnd:16rFFFF
|
|
234 |
|
|
235 |
"
|
|
236 |
Point instNameKeyFromSignature:Point signature.
|
|
237 |
Association instNameKeyFromSignature:Association signature.
|
|
238 |
"
|
|
239 |
! !
|
|
240 |
|
10
|
241 |
!ClassDescription methodsFor:'renaming'!
|
|
242 |
|
|
243 |
renameTo:newName
|
|
244 |
"change the name of the class - this writes a change record"
|
|
245 |
|
|
246 |
|oldName oldSym|
|
|
247 |
|
|
248 |
oldName := name.
|
|
249 |
oldSym := name asSymbol.
|
|
250 |
self setName:newName.
|
|
251 |
|
|
252 |
Smalltalk at:oldSym put:nil.
|
|
253 |
Smalltalk removeKey:oldSym. "26.jun 93"
|
|
254 |
Smalltalk at:(newName asSymbol) put:self.
|
|
255 |
! !
|
|
256 |
|
92
|
257 |
!ClassDescription methodsFor:'printing & storing'!
|
68
|
258 |
|
|
259 |
displayString
|
|
260 |
"return a string for display in inspoectors"
|
|
261 |
|
|
262 |
category == #obsolete ifTrue:[
|
155
|
263 |
"add obsolete - to make life easier ..."
|
|
264 |
^ self name "super displayString" , ' (obsolete)'
|
68
|
265 |
].
|
155
|
266 |
category == #removed ifTrue:[
|
|
267 |
"add removed - to make life easier ..."
|
|
268 |
^ self name "super displayString" , ' (removed)'
|
|
269 |
].
|
|
270 |
^ self name "super displayString"
|
68
|
271 |
! !
|
|
272 |
|
10
|
273 |
!ClassDescription methodsFor:'private'!
|
|
274 |
|
|
275 |
addAllInstVarNamesTo:aCollection
|
|
276 |
"helper - add the name-strings of the instance variables and of the inst-vars
|
|
277 |
of all superclasses to the argument, aCollection. Return aCollection"
|
|
278 |
|
|
279 |
(superclass notNil) ifTrue:[
|
155
|
280 |
superclass addAllInstVarNamesTo:aCollection
|
10
|
281 |
].
|
|
282 |
instvars notNil ifTrue:[
|
155
|
283 |
aCollection addAll:(instvars asCollectionOfWords).
|
10
|
284 |
].
|
|
285 |
^ aCollection
|
|
286 |
! !
|