author | Claus Gittinger <cg@exept.de> |
Fri, 29 Aug 2003 21:16:52 +0200 | |
changeset 7587 | 89864caa2665 |
parent 7580 | 0a49277831d9 |
child 7592 | aaa6a17f80a4 |
permissions | -rw-r--r-- |
5905 | 1 |
"{ Package: 'stx:libbasic' }" |
2 |
||
3 |
Object subclass:#ClassBuilder |
|
6057 | 4 |
instanceVariableNames:'className environment superClass instanceVariableNames variable |
5 |
words pointers classVariableNames poolDictionaries category |
|
6 |
comment changed classInstanceVariableNames oldMetaClass |
|
6514 | 7 |
realNewName buildPrivateClass' |
6057 | 8 |
classVariableNames:'' |
9 |
poolDictionaries:'' |
|
10 |
category:'Kernel-Support' |
|
5905 | 11 |
! |
12 |
||
13 |
||
14 |
!ClassBuilder class methodsFor:'checks'! |
|
15 |
||
5907 | 16 |
checkForAliasesOf:oldClass with:newClass |
17 |
"oldClass changed its identity (now use newClass). |
|
18 |
check if there are any global aliases, which should also be changed" |
|
19 |
||
20 |
Smalltalk keysAndValuesDo:[:nm :o | |
|
21 |
o == oldClass ifTrue:[ |
|
22 |
nm ~~ oldClass name ifTrue:[ |
|
23 |
(self confirm:('The global/classVar `' , nm , ''' is an alias for ' , oldClass name , '.\\Change it to the new class ?') withCRs) |
|
24 |
ifTrue:[ |
|
25 |
Smalltalk at:nm put:newClass |
|
26 |
] |
|
27 |
] |
|
28 |
] |
|
29 |
]. |
|
30 |
! |
|
31 |
||
5905 | 32 |
differentInstanceVariableOffsetsIn:class1 and:class2 |
33 |
"return a set of instance variable names which have different |
|
34 |
positions in class1 and class2. |
|
35 |
Also, variables which are only present in one class are returned. |
|
36 |
This is used to find methods which need recompilation after a |
|
37 |
change in the instance variable layout." |
|
38 |
||
39 |
|offsets1 offsets2 changeSet| |
|
40 |
||
41 |
changeSet := Set new. |
|
42 |
||
43 |
" |
|
44 |
collect the instvar-indices in the old and new class |
|
45 |
" |
|
46 |
offsets1 := class1 instanceVariableOffsets. |
|
47 |
offsets2 := class2 instanceVariableOffsets. |
|
48 |
||
49 |
" |
|
50 |
compute the changeset as a set of instance variables, |
|
51 |
which have a different position |
|
52 |
" |
|
53 |
offsets1 keysAndValuesDo:[:varName :varIndex | |
|
54 |
(offsets2 includesKey:varName) ifFalse:[ |
|
55 |
changeSet add:varName |
|
56 |
] ifTrue:[ |
|
57 |
(varIndex ~~ (offsets2 at:varName)) ifTrue:[ |
|
58 |
changeSet add:varName |
|
59 |
] |
|
60 |
] |
|
61 |
]. |
|
62 |
offsets2 keysAndValuesDo:[:varName :varIndex | |
|
63 |
(offsets1 includesKey:varName) ifFalse:[ |
|
64 |
changeSet add:varName |
|
65 |
] ifTrue:[ |
|
66 |
(varIndex ~~ (offsets1 at:varName)) ifTrue:[ |
|
67 |
changeSet add:varName |
|
68 |
] |
|
69 |
] |
|
70 |
]. |
|
71 |
^ changeSet |
|
72 |
||
73 |
" |
|
74 |
View class |
|
75 |
differentInstanceVariableOffsetsIn:View |
|
76 |
and:StandardSystemView |
|
77 |
View class |
|
78 |
differentInstanceVariableOffsetsIn:Object |
|
79 |
and:Point |
|
80 |
" |
|
81 |
! ! |
|
82 |
||
83 |
!ClassBuilder class methodsFor:'recompiling'! |
|
84 |
||
6024 | 85 |
copyInvalidatedMethodsFrom:oldClass for:newClass |
86 |
"copy all methods from oldClass to newClass and change their code |
|
87 |
to a trap method reporting an error. |
|
88 |
This is done when a class has changed its layout or inheritance, |
|
89 |
before recompilation is attempted. |
|
90 |
This allows us to keep the source while trapping uncompilable (due to |
|
91 |
now undefined instvars) methods. Later compilation of these methods will show |
|
92 |
an error on the transcript and lead to the debugger once called." |
|
93 |
||
94 |
|trap trapCode trapByteCode oldMethod newMethod |
|
95 |
oldDict newDict| |
|
96 |
||
97 |
oldDict := oldClass methodDictionary. |
|
98 |
newDict := MethodDictionary new:oldDict size. |
|
99 |
||
100 |
oldDict keysAndValuesDo:[ :sel :mthd | |
|
101 |
trap := mthd trapMethodForNumArgs:(mthd numArgs). |
|
102 |
trapCode := trap code. |
|
103 |
trapByteCode := trap byteCode. |
|
104 |
||
105 |
mthd isWrapped ifTrue:[ |
|
106 |
oldMethod := mthd originalMethod |
|
107 |
] ifFalse:[ |
|
108 |
oldMethod := mthd. |
|
109 |
]. |
|
110 |
||
111 |
newMethod := oldMethod copy. |
|
112 |
newMethod makeInvalid. |
|
113 |
newDict at:sel put:newMethod |
|
114 |
]. |
|
115 |
||
116 |
newClass methodDictionary:newDict. |
|
117 |
||
118 |
"Modified: 12.6.1996 / 10:44:27 / stefan" |
|
119 |
"Modified: 4.11.1996 / 22:55:57 / cg" |
|
120 |
! |
|
121 |
||
5905 | 122 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames |
123 |
"copy all methods from oldClass to newClass. Those methods accessing |
|
124 |
a variable in setOfNames will be copied as invalid method, leading to |
|
125 |
a trap when its executed. This is used when a class has changed its |
|
126 |
layout for all methods which are affected by the change." |
|
127 |
||
128 |
self copyInvalidatedMethodsFrom:oldClass |
|
129 |
for:newClass |
|
130 |
accessingAny:setOfNames |
|
131 |
orSuper:false |
|
132 |
! |
|
133 |
||
134 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames orSuper:superBoolean |
|
135 |
"copy all methods from oldClass to newClass. |
|
136 |
Those methods accessing a variable in setOfNames will be copied as invalid method, |
|
137 |
leading to a trap when its executed. If superBoolean is true, this is also done |
|
138 |
for methods accessing super. This is used when a class has changed its |
|
139 |
layout for all methods which are affected by the change." |
|
140 |
||
141 |
|p source mustInvalidate |
|
142 |
oldMethod newMethod methodDict newMethodDict nNames| |
|
143 |
||
144 |
methodDict := oldClass methodDictionary. |
|
145 |
newMethodDict := methodDict copy. |
|
146 |
nNames := setOfNames size. |
|
147 |
||
148 |
methodDict keysAndValuesDo:[:selector :method | |
|
149 |
method isWrapped ifTrue:[ |
|
150 |
oldMethod := method originalMethod |
|
151 |
] ifFalse:[ |
|
152 |
oldMethod := method |
|
153 |
]. |
|
154 |
||
155 |
"before parsing (which may take some time), |
|
156 |
do a string search if its only one variable, |
|
157 |
we are looking for. |
|
158 |
Could look for more than one variable by string compare, but then |
|
159 |
parsing it right away may be faster ..." |
|
160 |
||
161 |
source := oldMethod source. |
|
162 |
((nNames == 1) and:[superBoolean not]) ifTrue:[ |
|
163 |
mustInvalidate := (source findString:(setOfNames first)) ~~ 0. |
|
164 |
] ifFalse:[ |
|
165 |
((nNames == 0) and:[superBoolean]) ifTrue:[ |
|
166 |
mustInvalidate := (source findString:'super') ~~ 0. |
|
167 |
] ifFalse:[ |
|
168 |
mustInvalidate := true |
|
169 |
]. |
|
170 |
]. |
|
171 |
||
172 |
mustInvalidate ifTrue:[ |
|
173 |
"we have to parse it ..." |
|
174 |
p := Parser parseMethod:source in:newClass. |
|
175 |
(p isNil |
|
176 |
or:[(p usedVars includesAny:setOfNames) |
|
177 |
or:[superBoolean and:[p usesSuper]]]) ifFalse:[ |
|
178 |
mustInvalidate := false |
|
179 |
] |
|
180 |
]. |
|
181 |
||
182 |
mustInvalidate ifTrue:[ |
|
183 |
newMethod := oldMethod copy. |
|
184 |
"/ Smalltalk silentLoading ifFalse:[ |
|
185 |
"/ Transcript showCR:'invalidating ' , selector , '...'. |
|
186 |
"/ ]. |
|
187 |
newMethod makeInvalid. |
|
188 |
] ifFalse:[ |
|
189 |
newMethod := oldMethod. |
|
190 |
newMethod mclass:nil. |
|
191 |
]. |
|
192 |
newMethodDict at:selector put:newMethod |
|
193 |
]. |
|
194 |
newClass methodDictionary:newMethodDict. |
|
195 |
||
196 |
"Modified: 7.6.1996 / 08:33:52 / stefan" |
|
197 |
"Modified: 19.6.1997 / 18:27:09 / cg" |
|
198 |
! |
|
199 |
||
200 |
copyMethodsFrom:oldClass for:newClass |
|
201 |
"copy all methods from oldClass to newClass. |
|
202 |
This is used for class-methods when a class has changed, but its metaclass is |
|
203 |
unaffected (i.e. classVars/inheritance have not changed) so there is no need |
|
204 |
to recompile the class methods." |
|
205 |
||
206 |
newClass methodDictionary:(oldClass methodDictionary copy). |
|
207 |
newClass methodDictionary keysAndValuesDo:[:sel :mthd | mthd mclass:nil.]. |
|
208 |
||
209 |
"Modified: 7.6.1996 / 08:34:43 / stefan" |
|
210 |
! |
|
211 |
||
212 |
recompileGlobalAccessorsTo:aGlobalKey in:aNamespace except:someClass |
|
213 |
"when a new class enters a namespace, all accessors to the same-named |
|
214 |
class in that namespace must be recompiled" |
|
215 |
||
216 |
aNamespace allPrivateClassesDo:[:aClass | |
|
217 |
aClass ~~ someClass ifTrue:[ |
|
218 |
aClass isLoaded ifTrue:[ |
|
219 |
||
220 |
"/ Smalltalk silentLoading ifFalse:[ |
|
221 |
"/ Transcript showCR:'recompiling methods in ''' , aClass name , ''' accessing ''' , aGlobalKey , ''''. |
|
222 |
"/ Transcript endEntry. |
|
223 |
"/ ]. |
|
224 |
||
225 |
aClass recompileMethodsAccessingGlobal:aGlobalKey. |
|
226 |
aClass class recompileMethodsAccessingGlobal:aGlobalKey. |
|
227 |
"/ actually - must eventually recompile USERS of this namespace too |
|
228 |
] |
|
229 |
] |
|
6408
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
230 |
]. |
6414 | 231 |
aNamespace isNameSpace ifFalse:[ |
6408
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
232 |
aNamespace recompileMethodsAccessingGlobal:aGlobalKey. |
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
233 |
aNamespace class recompileMethodsAccessingGlobal:aGlobalKey. |
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
234 |
]. |
5905 | 235 |
|
236 |
"Modified: 31.1.1997 / 11:22:57 / cg" |
|
237 |
! |
|
238 |
||
239 |
recompileMachineCodeMethodsIn:aClass |
|
240 |
"recompile all machine-code methods in aClass." |
|
241 |
||
242 |
aClass recompileMethodsWithMachineCode. |
|
243 |
aClass class recompileMethodsWithMachineCode. |
|
244 |
! ! |
|
245 |
||
246 |
!ClassBuilder methodsFor:'accessing'! |
|
247 |
||
6825 | 248 |
name:newName inEnvironment:aSystemDictionaryOrClass subclassOf:aClass instanceVariableNames:stringOfInstVarNames variable:variableBoolean words:wordsBoolean pointers:pointersBoolean classVariableNames:stringOfClassVarNames poolDictionaries:stringOfPoolNames category:categoryString comment:commentString changed:changedBoolean classInstanceVariableNames:stringOfClassInstVarNamesOrNil |
5905 | 249 |
className := newName. |
250 |
environment := aSystemDictionaryOrClass. |
|
251 |
superClass := aClass. |
|
252 |
instanceVariableNames := stringOfInstVarNames. |
|
253 |
variable := variableBoolean. |
|
254 |
words := wordsBoolean. |
|
255 |
pointers := pointersBoolean. |
|
256 |
classVariableNames := stringOfClassVarNames. |
|
257 |
poolDictionaries := stringOfPoolNames. |
|
258 |
category := categoryString. |
|
259 |
comment := commentString. |
|
260 |
changed := changedBoolean. |
|
261 |
classInstanceVariableNames := stringOfClassInstVarNamesOrNil |
|
5907 | 262 |
! |
263 |
||
264 |
oldMetaclass:aMetaclass instanceVariableNames:stringOfInstVarNames |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
265 |
|instrVarNames| |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
266 |
|
5907 | 267 |
oldMetaClass := aMetaclass. |
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
268 |
instrVarNames := oldMetaClass superclass allInstanceVariableNames asBag. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
269 |
instrVarNames addAll:(stringOfInstVarNames asStringCollection). |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
270 |
(instrVarNames contents includesValue:2) ifTrue:[ |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
271 |
self error:'duplicate variable name'. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
272 |
]. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
273 |
|
5907 | 274 |
instanceVariableNames := stringOfInstVarNames. |
5905 | 275 |
! ! |
276 |
||
277 |
!ClassBuilder methodsFor:'building'! |
|
278 |
||
279 |
buildClass |
|
280 |
||
281 |
"this is the main workhorse for installing new classes - special care |
|
282 |
has to be taken, when changing an existing classes definition. In this |
|
283 |
case, some or all of the methods and subclasses methods have to be |
|
284 |
recompiled. |
|
285 |
Also, the old class(es) are still kept (but not accessable as a global), |
|
286 |
to allow existing instances some life. |
|
287 |
This might change in the future. |
|
288 |
" |
|
289 |
||
290 |
|newClass newMetaclass nInstVars nameString classSymbol nameKey oldClass |
|
291 |
classVarChange instVarChange superClassChange newComment |
|
292 |
changeSet1 changeSet2 addedNames |
|
293 |
anyChange oldInstVars newInstVars oldClassVars newClassVars superFlags newFlags |
|
6514 | 294 |
pkg oldPkg idx spec |
295 |
oldCIVNames newCIVNames nsName namespace |
|
5905 | 296 |
oldSuperClass newSuperClass oldCategory |
6514 | 297 |
recompileGlobalAccessTo answer |
298 |
oldClassToBecomeNew newInstSize doCreate| |
|
5905 | 299 |
|
300 |
"NOTICE: |
|
301 |
this method is too complex and should be splitted into managable pieces ... |
|
302 |
I dont like it anymore :-) |
|
303 |
(well, at least, its a good test for the compilers ability |
|
304 |
to handle big, complex methods ;-) |
|
305 |
take it as an example of bad coding style ... |
|
306 |
||
307 |
ST-80 uses a ClassBuilder object to collect the work and perform all updates; |
|
308 |
this method may be changed to do something similar in the future ... |
|
309 |
" |
|
310 |
||
311 |
self checkClassName. |
|
312 |
self checkValidSubclassing. |
|
313 |
||
314 |
"/ owner must be loaded |
|
7230
82934cb163d4
autoload is understood by all classes (dummy if already loaded)
Claus Gittinger <cg@exept.de>
parents:
7201
diff
changeset
|
315 |
environment notNil ifTrue:[ |
5905 | 316 |
environment autoload |
317 |
]. |
|
318 |
||
319 |
(instanceVariableNames size > 0 |
|
320 |
or:[classVariableNames size > 0]) ifTrue:[ |
|
321 |
" |
|
322 |
Check for invalid variable names (duplicates) |
|
323 |
" |
|
324 |
(self |
|
325 |
checkValidVarNamesFor:className |
|
326 |
subClassOf:superClass |
|
327 |
instVarNames:instanceVariableNames |
|
328 |
classVarNames:classVariableNames) |
|
329 |
ifFalse:[ |
|
330 |
^ nil |
|
331 |
]. |
|
332 |
nInstVars := instanceVariableNames countWords. |
|
333 |
] ifFalse:[ |
|
334 |
nInstVars := 0. |
|
335 |
]. |
|
336 |
||
337 |
nameString := className asString. |
|
338 |
classSymbol := className asSymbol. |
|
339 |
newComment := comment. |
|
340 |
||
341 |
namespace := environment. |
|
342 |
nameKey := classSymbol. |
|
343 |
||
344 |
(namespace notNil |
|
345 |
and:[namespace isNameSpace not]) ifTrue:[ |
|
6514 | 346 |
buildPrivateClass := true. |
5905 | 347 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
348 |
] ifFalse:[ |
|
6514 | 349 |
buildPrivateClass := false. |
5905 | 350 |
realNewName := classSymbol. |
351 |
||
352 |
"/ does the name imply a nameSpace ? |
|
353 |
((idx := realNewName indexOf:$:)) ~~ 0 ifTrue:[ |
|
354 |
"/ check for this namespace to exist |
|
355 |
nsName := realNewName copyTo:(idx - 1). |
|
356 |
nsName := nsName asSymbol. |
|
357 |
(realNewName indexOf:$: startingAt:(idx+2)) ~~ 0 ifTrue:[ |
|
7201
aa6ae96acc53
better error message, when defining a private class with
Claus Gittinger <cg@exept.de>
parents:
7180
diff
changeset
|
358 |
(Smalltalk at:nsName) isNameSpace ifTrue:[ |
aa6ae96acc53
better error message, when defining a private class with
Claus Gittinger <cg@exept.de>
parents:
7180
diff
changeset
|
359 |
self warn:('Nested namespaces are not (yet) implemented.') withCRs. |
aa6ae96acc53
better error message, when defining a private class with
Claus Gittinger <cg@exept.de>
parents:
7180
diff
changeset
|
360 |
] ifFalse:[ |
aa6ae96acc53
better error message, when defining a private class with
Claus Gittinger <cg@exept.de>
parents:
7180
diff
changeset
|
361 |
self warn:('Trying to define a private class with a non-private definition selector.') withCRs. |
aa6ae96acc53
better error message, when defining a private class with
Claus Gittinger <cg@exept.de>
parents:
7180
diff
changeset
|
362 |
]. |
5905 | 363 |
^ nil |
364 |
]. |
|
365 |
||
366 |
namespace := Smalltalk at:nsName ifAbsent:nil. |
|
367 |
namespace isNameSpace ifFalse:[ |
|
368 |
namespace isNil ifTrue:[ |
|
6385
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
369 |
doCreate := Class createNameSpaceQuerySignal query. |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
370 |
doCreate ifFalse:[ |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
371 |
doCreate := Dialog |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
372 |
confirmWithCancel:('Nonexistent Namespace: `' , nsName , '''.\\Create ?') withCRs. |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
373 |
doCreate isNil ifTrue:[ |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
374 |
"/ cancelled |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
375 |
AbortSignal raise. |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
376 |
] |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
377 |
]. |
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
378 |
doCreate ifFalse:[^ nil]. |
5905 | 379 |
namespace := NameSpace name:nsName. |
380 |
] ifFalse:[ |
|
381 |
(namespace isBehavior |
|
382 |
and:[namespace isMeta not]) |
|
383 |
ifTrue:[ |
|
6514 | 384 |
buildPrivateClass := true. |
5905 | 385 |
realNewName := classSymbol asSymbol. |
386 |
] ifFalse:[ |
|
6385
13220cec589e
doCreateNamespace confirmation
Claus Gittinger <cg@exept.de>
parents:
6105
diff
changeset
|
387 |
self warn:('A global named ' , nsName , ' exists, but is no namespace.') withCRs. |
5905 | 388 |
^ nil |
389 |
]. |
|
390 |
] |
|
391 |
]. |
|
392 |
namespace isNameSpace ifTrue:[ |
|
393 |
nameKey := (classSymbol copyFrom:(nsName size + 3)) asSymbol. |
|
394 |
] |
|
395 |
] ifFalse:[ |
|
396 |
(namespace notNil and:[namespace ~~ Smalltalk]) ifTrue:[ |
|
397 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
|
398 |
] |
|
399 |
] |
|
400 |
]. |
|
401 |
||
402 |
(superClass notNil and:[realNewName = superClass name]) ifTrue:[ |
|
403 |
self error:'trying to create circular class definition'. |
|
404 |
^ nil |
|
405 |
]. |
|
406 |
||
407 |
"look, if it already exists as a class" |
|
408 |
namespace notNil ifTrue:[ |
|
6514 | 409 |
buildPrivateClass ifFalse:[ |
5905 | 410 |
oldClass := namespace at:nameKey ifAbsent:[nil]. |
411 |
] ifTrue:[ |
|
412 |
oldClass := namespace privateClassesAt:classSymbol. |
|
413 |
] |
|
414 |
]. |
|
415 |
||
7528 | 416 |
(oldClass notNil and:[oldClass isNameSpace and:[oldClass ~~ Smalltalk]]) ifTrue:[ |
6713
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
417 |
self error:'class exists as namespace'. |
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
418 |
^ nil |
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
419 |
]. |
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
420 |
|
5905 | 421 |
(oldClass isBehavior and:[oldClass isLoaded not]) ifTrue:[ |
422 |
oldClassToBecomeNew := oldClass |
|
423 |
]. |
|
424 |
||
425 |
(oldClass isBehavior and:[oldClass isLoaded]) ifFalse:[ |
|
426 |
oldClass := nil. |
|
427 |
||
6514 | 428 |
buildPrivateClass ifTrue:[ |
5905 | 429 |
Compiler warnSTXSpecials ifTrue:[ |
430 |
(self confirm:('support for private classes is an ST/X extension.\\continue ?') withCRs) |
|
431 |
ifFalse:[^ nil]. |
|
432 |
] |
|
433 |
]. |
|
434 |
] ifTrue:[ |
|
435 |
oldClass name ~= realNewName ifTrue:[ |
|
436 |
(self confirm:(classSymbol , ' is an alias for ' , oldClass name , '\\continue ?') withCRs) |
|
437 |
ifFalse:[^ nil]. |
|
438 |
oldClass := nil |
|
439 |
] ifFalse:[ |
|
440 |
"/ |
|
441 |
"/ some consisteny checks |
|
442 |
"/ |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
443 |
(self checkForCircularDefinitionFrom:oldClass) ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
444 |
self error:'trying to create circular class definition'. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
445 |
^ nil |
5905 | 446 |
]. |
447 |
||
448 |
newComment isNil ifTrue:[ |
|
449 |
newComment := oldClass comment |
|
450 |
]. |
|
451 |
||
452 |
" |
|
453 |
warn, if it exists with different category and different instvars, |
|
454 |
and the existing is not an autoload class. |
|
455 |
Usually, this indicates that someone wants to create a new class with |
|
456 |
a name, which already exists (it happened a few times to myself, while |
|
457 |
I wanted to create a new class called ReturnNode ...). |
|
458 |
This will be much less of a problem, once multiple name spaces are |
|
459 |
implemented and classes can be put into separate packages. |
|
460 |
" |
|
461 |
oldClass isLoaded ifTrue:[ |
|
462 |
oldClass category ~= category ifTrue:[ |
|
463 |
oldClass instanceVariableString asCollectionOfWords |
|
464 |
~= instanceVariableNames asCollectionOfWords ifTrue:[ |
|
465 |
(self confirm:'a class named ' , oldClass name , |
|
466 |
' already exists -\\create (i.e. change) anyway ?' withCRs) |
|
467 |
ifFalse:[ |
|
468 |
^ nil |
|
469 |
] |
|
470 |
] |
|
471 |
] |
|
472 |
]. |
|
473 |
||
474 |
"/ |
|
475 |
"/ hints - warn, if creating a variableSubclass of a Set |
|
476 |
"/ (common error - containers in ST/X do not use variable-slots) |
|
477 |
"/ |
|
478 |
((variable == true) and:[pointers]) ifTrue:[ |
|
479 |
(oldClass isKindOf:Set class) ifTrue:[ |
|
6057 | 480 |
(self confirm:('ST/X Set & Dictionary are not variable-classes.\Create %1 anyway ?' bindWith:nameString) withCRs) |
5905 | 481 |
ifFalse:[ |
482 |
^ nil |
|
483 |
] |
|
484 |
] |
|
485 |
] |
|
486 |
] |
|
487 |
]. |
|
488 |
||
489 |
"/ Check for some 'considered bad-style' things, like lower case names. |
|
490 |
"/ But only do these checks for new classes - |
|
491 |
"/ - thus, once confirmed, the warnings will not come again and again. |
|
492 |
||
493 |
"/ NOTICE: |
|
494 |
"/ I dont like the confirmers there - we need a notifying: argument, to give |
|
495 |
"/ the outer codeview a chance to highlight the error. |
|
496 |
"/ (but thats how its defined in the book - maybe I will change anyway). |
|
497 |
"/ - or use upQueries in future versions. |
|
498 |
||
499 |
oldClass isNil ifTrue:[ |
|
500 |
(instanceVariableNames size > 0 |
|
501 |
or:[classVariableNames size > 0]) ifTrue:[ |
|
502 |
(self |
|
503 |
checkConventionsFor:className |
|
504 |
subClassOf:superClass |
|
505 |
instVarNames:instanceVariableNames |
|
506 |
classVarNames:classVariableNames) |
|
507 |
ifFalse:[ |
|
508 |
^ nil |
|
509 |
] |
|
510 |
]. |
|
7132 | 511 |
]. |
5905 | 512 |
|
7132 | 513 |
(self |
514 |
checkInstvarRedefsWith:instanceVariableNames |
|
515 |
subclassOf:superClass |
|
516 |
old:oldClass |
|
517 |
name:className) ifFalse:[^ nil]. |
|
5905 | 518 |
|
519 |
classInstanceVariableNames isNil ifTrue:[ |
|
520 |
oldClass isNil ifTrue:[ |
|
6514 | 521 |
classInstanceVariableNames := '' |
5905 | 522 |
] ifFalse:[ |
6514 | 523 |
classInstanceVariableNames := oldClass class instanceVariableString |
5905 | 524 |
] |
525 |
]. |
|
526 |
||
527 |
"create the metaclass first" |
|
6514 | 528 |
newMetaclass := self instantiateMetaclass. |
5905 | 529 |
|
530 |
"then let the new meta create the class" |
|
531 |
newClass := newMetaclass new. |
|
532 |
superClass isNil ifTrue:[ |
|
5907 | 533 |
newInstSize := nInstVars. |
5905 | 534 |
] ifFalse:[ |
5907 | 535 |
newInstSize := superClass instSize + nInstVars. |
5905 | 536 |
]. |
5907 | 537 |
newClass setSuperclass:superClass instSize:newInstSize. |
5905 | 538 |
|
6514 | 539 |
buildPrivateClass ifTrue:[ |
5905 | 540 |
"/ some private class |
541 |
newMetaclass setOwningClass:namespace. |
|
542 |
]. |
|
543 |
||
5907 | 544 |
(namespace notNil and:[namespace ~~ Smalltalk]) ifTrue:[ |
5905 | 545 |
newClass setName:realNewName. |
546 |
"/ |
|
547 |
"/ if that key exists in smalltalk, |
|
548 |
"/ must recompile everything in that nameSpace, |
|
549 |
"/ which refers to the unprefixed global. |
|
550 |
"/ |
|
551 |
recompileGlobalAccessTo := nameKey. |
|
552 |
] ifFalse:[ |
|
553 |
newClass setName:classSymbol. |
|
554 |
recompileGlobalAccessTo := nil. |
|
555 |
]. |
|
556 |
||
557 |
newClass setComment:newComment category:category. |
|
558 |
||
559 |
oldClass notNil ifTrue:[ |
|
560 |
"/ copy over classInstanceVariables |
|
561 |
"/ but not those inherited from class |
|
562 |
||
563 |
oldCIVNames := oldClass class allInstVarNames asSet. |
|
564 |
newCIVNames := newClass class allInstVarNames asSet. |
|
565 |
Class class allInstVarNames do:[:n | |
|
566 |
oldCIVNames remove:n ifAbsent:nil. |
|
567 |
newCIVNames remove:n ifAbsent:nil. |
|
568 |
]. |
|
569 |
||
570 |
newCIVNames size > 0 ifTrue:[ |
|
571 |
"/ Smalltalk silentLoading ifFalse:[ |
|
572 |
"/ Transcript show:'preserving classInstVar values: '; showCR:newCIVNames. |
|
573 |
"/ ]. |
|
574 |
newCIVNames do:[:n | |
|
575 |
(oldCIVNames includes:n) ifTrue:[ |
|
576 |
newClass instVarNamed:n put:(oldClass instVarNamed:n) |
|
577 |
] |
|
578 |
] |
|
579 |
]. |
|
580 |
]. |
|
581 |
||
582 |
"/ set the new classes package |
|
583 |
"/ but be careful here ... |
|
584 |
||
585 |
oldClass isNil ifTrue:[ |
|
586 |
"/ new classes get the current package ... |
|
587 |
pkg := Class packageQuerySignal query. |
|
588 |
] ifFalse:[ |
|
589 |
newClass setClassFilename:(oldClass classFilename). |
|
590 |
||
591 |
oldPkg := oldClass package. |
|
592 |
oldClass isLoaded ifFalse:[ |
|
593 |
"/ autoloaded classes get the package of the autoload stub ... |
|
594 |
pkg := oldPkg |
|
595 |
] ifTrue:[ |
|
596 |
"/ not autoloading, check for packageRedef ... |
|
6514 | 597 |
buildPrivateClass ifTrue:[ |
5905 | 598 |
pkg := namespace package. |
599 |
] ifFalse:[ |
|
600 |
pkg := Class packageQuerySignal query. |
|
601 |
oldPkg ~= pkg ifTrue:[ |
|
602 |
newClass package:pkg. |
|
603 |
answer := Class classRedefinitionSignal |
|
604 |
raiseRequestWith:(oldClass -> newClass) |
|
605 |
errorString:('redefinition of class: ' , oldClass name). |
|
606 |
answer == #keep ifTrue:[ |
|
607 |
"/ keep old package |
|
608 |
pkg := oldPkg. |
|
609 |
] ifFalse:[ |
|
610 |
answer ~~ #continue ifTrue:[ |
|
611 |
"/ cancel |
|
612 |
^ nil |
|
613 |
]. |
|
614 |
"/ take new package |
|
615 |
]. |
|
616 |
]. |
|
617 |
newClass setBinaryRevision:(oldClass binaryRevision). |
|
618 |
]. |
|
619 |
]. |
|
620 |
]. |
|
621 |
pkg notNil ifTrue:[ |
|
622 |
"/ Transcript showCR:('set package of class: ' , newClass name , ' to ' , pkg printString). |
|
623 |
newClass package:pkg. |
|
624 |
]. |
|
625 |
||
626 |
"/ Allowing non-booleans as variableBoolean |
|
627 |
"/ is a hack for backward (ST-80) compatibility: |
|
628 |
"/ ST-80 code will pass true or false as variableBoolean, |
|
629 |
"/ while ST/X also calls it with symbols such as #float, #double etc. |
|
630 |
||
631 |
(variable == true) ifTrue:[ |
|
632 |
pointers ifTrue:[ |
|
633 |
newFlags := Behavior flagPointers |
|
634 |
] ifFalse:[ |
|
635 |
words ifTrue:[ |
|
636 |
newFlags := Behavior flagWords |
|
637 |
] ifFalse:[ |
|
638 |
newFlags := Behavior flagBytes |
|
639 |
] |
|
640 |
] |
|
641 |
] ifFalse:[ |
|
642 |
"/ false or symbol. |
|
643 |
newFlags := Behavior flagForSymbolic:variable. |
|
644 |
]. |
|
645 |
superClass isNil ifTrue:[ |
|
646 |
superFlags := 0 |
|
647 |
] ifFalse:[ |
|
648 |
superFlags := superClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits" |
|
649 |
]. |
|
650 |
||
651 |
oldClass notNil ifTrue:[ |
|
652 |
oldClass isBuiltInClass ifTrue:[ |
|
653 |
" |
|
654 |
special care when redefining Method, Block and other built-in classes, |
|
655 |
which might have other flag bits ... |
|
656 |
" |
|
657 |
newFlags := newFlags bitOr:(oldClass flags bitAnd:(Behavior maskIndexType bitInvert)) |
|
658 |
] |
|
659 |
]. |
|
660 |
newClass flags:(newFlags bitOr:superFlags). "preserve inherited special bits" |
|
661 |
||
662 |
(nInstVars ~~ 0) ifTrue:[ |
|
663 |
newClass setInstanceVariableString:instanceVariableNames |
|
664 |
]. |
|
665 |
oldClass notNil ifTrue:[ |
|
666 |
"/ setting first will make new class clear obsolete classvars |
|
667 |
newClass setClassVariableString:(oldClass classVariableString). |
|
7370
1ed996a6e7bf
primitiveSpec changed to attributes.
Claus Gittinger <cg@exept.de>
parents:
7230
diff
changeset
|
668 |
newClass setClassFilename:(oldClass classFilename). |
7487 | 669 |
(spec := oldClass classAttributes) notNil ifTrue:[ |
670 |
newClass classAttributes:spec. |
|
7370
1ed996a6e7bf
primitiveSpec changed to attributes.
Claus Gittinger <cg@exept.de>
parents:
7230
diff
changeset
|
671 |
]. |
5905 | 672 |
]. |
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
673 |
newClass setClassVariableString:classVariableNames. |
5905 | 674 |
|
675 |
"/ for new classes, we are almost done here |
|
676 |
"/ (also for autoloaded classes) |
|
677 |
||
678 |
(oldClass isNil or:[oldClass isLoaded not]) ifTrue:[ |
|
7180 | 679 |
"/ (oldClass isNil and:[changed]) ifTrue:[ |
680 |
"/ superClass ~~ Autoload ifTrue:[ |
|
681 |
"/ newClass addChangeRecordForClass:newClass. |
|
682 |
"/ ] |
|
683 |
"/ ]. |
|
5905 | 684 |
|
685 |
comment notNil ifTrue:[ |
|
686 |
newClass comment:comment |
|
687 |
]. |
|
688 |
namespace notNil ifTrue:[ |
|
6514 | 689 |
buildPrivateClass ifTrue:[ |
5905 | 690 |
namespace privateClassesAt:classSymbol put:newClass. |
691 |
] ifFalse:[ |
|
692 |
namespace at:nameKey put:newClass. |
|
693 |
] |
|
694 |
]. |
|
7180 | 695 |
(oldClass isNil and:[changed]) ifTrue:[ |
696 |
superClass ~~ Autoload ifTrue:[ |
|
697 |
newClass addChangeRecordForClass:newClass. |
|
698 |
] |
|
699 |
]. |
|
5905 | 700 |
|
701 |
"/ oldClass isNil ifTrue:[ |
|
702 |
"/ newClass package:(Class packageQuerySignal query) |
|
703 |
"/ ]. |
|
704 |
||
705 |
oldClass notNil ifTrue:[ |
|
706 |
"/ since we changed the classes inheritance (from Autoloaded) |
|
707 |
||
708 |
"/ actually, could optimize to: |
|
7434
aa0faab58aaf
SubclassInfo moved from Behavior to Class
Stefan Vogel <sv@exept.de>
parents:
7370
diff
changeset
|
709 |
"/ Class updateSuperclassInfoFor:oldClass superclass. |
aa0faab58aaf
SubclassInfo moved from Behavior to Class
Stefan Vogel <sv@exept.de>
parents:
7370
diff
changeset
|
710 |
"/ Class updateSuperclassInfoFor:newClass superclass. |
5905 | 711 |
|
7434
aa0faab58aaf
SubclassInfo moved from Behavior to Class
Stefan Vogel <sv@exept.de>
parents:
7370
diff
changeset
|
712 |
Class flushSubclassInfo. |
5905 | 713 |
]. |
714 |
||
715 |
oldClassToBecomeNew notNil ifTrue:[ |
|
716 |
"/ old was an autoloaded class - make it the new one |
|
717 |
"/ and flush ... |
|
718 |
oldClassToBecomeNew class becomeSameAs:newClass class. |
|
719 |
oldClassToBecomeNew becomeSameAs:newClass. |
|
720 |
ObjectMemory flushCaches. |
|
721 |
]. |
|
722 |
||
723 |
Smalltalk changed:#newClass with:newClass. |
|
724 |
namespace notNil ifTrue:[ |
|
6514 | 725 |
buildPrivateClass ifTrue:[ |
5905 | 726 |
namespace changed. |
727 |
] ifFalse:[ |
|
728 |
namespace ~~ Smalltalk ifTrue:[ |
|
729 |
namespace changed:#newClass with:newClass. |
|
730 |
] |
|
731 |
] |
|
732 |
]. |
|
733 |
||
734 |
"/ be very careful, when adding classes |
|
735 |
"/ to a namespace or adding a privateClass. |
|
736 |
"/ When adding, all methods within that namespace/owning class |
|
737 |
"/ which access the unprefixed-global, |
|
738 |
"/ must be recompiled (so they access the new class) |
|
739 |
||
740 |
recompileGlobalAccessTo notNil ifTrue:[ |
|
5907 | 741 |
self class |
742 |
recompileGlobalAccessorsTo:recompileGlobalAccessTo |
|
743 |
in:namespace except:newClass. |
|
5905 | 744 |
]. |
745 |
||
6514 | 746 |
(buildPrivateClass |
5905 | 747 |
and:[newClass owningClass nameSpace notNil]) ifTrue:[ |
748 |
"/ namespace is a class; |
|
749 |
"/ if this owner is itself in a namespace, |
|
750 |
"/ must recompile all from owners namespace |
|
751 |
"/ accessing the new class (without namespace prefix) |
|
5907 | 752 |
self class |
753 |
recompileGlobalAccessorsTo:(newClass nameWithoutNameSpacePrefix asSymbol) |
|
754 |
in:(newClass owningClass nameSpace) except:newClass. |
|
5905 | 755 |
]. |
756 |
^ newClass |
|
757 |
]. |
|
758 |
||
759 |
"/ here comes the hard part - we are actually changing the |
|
760 |
"/ definition of an existing class .... |
|
761 |
"/ Try hard to get away WITHOUT recompiling, since it makes all |
|
762 |
"/ compiled code into interpreted ... |
|
763 |
||
764 |
oldInstVars := oldClass instanceVariableString asCollectionOfWords. |
|
765 |
newInstVars := newClass instanceVariableString asCollectionOfWords. |
|
766 |
oldClassVars := oldClass classVariableString asCollectionOfWords. |
|
767 |
newClassVars := newClass classVariableString asCollectionOfWords. |
|
768 |
||
769 |
oldSuperClass := oldClass superclass. |
|
770 |
newSuperClass := newClass superclass. |
|
771 |
superClassChange := oldSuperClass ~~ newSuperClass. |
|
772 |
||
773 |
"/ we are on the bright side of life, if the instance layout and |
|
774 |
"/ inheritance do not change. |
|
775 |
"/ In this case, we can go ahead and patch the class object. |
|
776 |
"/ (only comment and/or classVars have changed) |
|
777 |
||
778 |
superClassChange ifFalse:[ |
|
779 |
(oldClass instSize == newClass instSize) ifTrue:[ |
|
780 |
(oldClass flags == newClass flags) ifTrue:[ |
|
781 |
(oldClass name = newClass name) ifTrue:[ |
|
782 |
(oldInstVars = newInstVars) ifTrue:[ |
|
783 |
||
784 |
(newComment ~= oldClass comment) ifTrue:[ |
|
785 |
oldClass setComment:newComment. "writes a change-chunk" |
|
786 |
oldClass changed:#comment with:oldClass comment. |
|
787 |
changed ifTrue:[ |
|
788 |
oldClass addChangeRecordForClassComment:oldClass. |
|
789 |
] |
|
790 |
]. |
|
791 |
"/ mhmh - dont do this here ... |
|
792 |
"/ ... otherwise, we have to change all methods package info |
|
793 |
"/ to belong to the old package. |
|
794 |
"/ oldClass package:pkg. |
|
795 |
||
796 |
(oldClassVars = newClassVars) ifTrue:[ |
|
797 |
"/ really no change (just comment and/or category) |
|
798 |
||
799 |
anyChange := false. |
|
800 |
||
801 |
oldClass setInstanceVariableString:(newClass instanceVariableString). |
|
802 |
oldClass setClassVariableString:(newClass classVariableString). |
|
803 |
||
804 |
oldClass category ~= category ifTrue:[ |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
805 |
oldClass setCategory:category. |
5905 | 806 |
changed ifTrue:[ |
807 |
newClass addChangeRecordForClass:newClass. |
|
808 |
]. |
|
809 |
namespace notNil ifTrue:[ |
|
6514 | 810 |
buildPrivateClass ifFalse:[ |
5905 | 811 |
"notify change of category" |
812 |
namespace changed:#organization. |
|
813 |
namespace ~~ Smalltalk ifTrue:[ |
|
814 |
Smalltalk changed:#organization. |
|
815 |
] |
|
816 |
] |
|
817 |
] |
|
818 |
]. |
|
819 |
"notify change of class" |
|
820 |
"/ oldClass changed. |
|
821 |
^ oldClass |
|
822 |
]. |
|
823 |
||
824 |
"/ when we arrive here, class variables have changed |
|
825 |
||
826 |
oldClass category ~= category ifTrue:[ |
|
827 |
"notify change of organization" |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
828 |
oldClass setCategory:category. |
5905 | 829 |
namespace notNil ifTrue:[ |
6514 | 830 |
buildPrivateClass ifFalse:[ |
5905 | 831 |
"notify change of organization" |
832 |
namespace changed:#organization. |
|
833 |
namespace ~~ Smalltalk ifTrue:[ |
|
834 |
Smalltalk changed:#organization. |
|
835 |
] |
|
836 |
] |
|
837 |
]. |
|
838 |
]. |
|
839 |
||
840 |
"/ set class variable string; |
|
841 |
"/ this also updates the set of class variables |
|
842 |
"/ by creating new / deleting obsolete ones. |
|
843 |
||
844 |
oldClass classVariableString:classVariableNames. |
|
845 |
||
846 |
" |
|
847 |
get the set of changed class variables |
|
848 |
" |
|
849 |
changeSet1 := Set new. |
|
850 |
oldClassVars do:[:nm | |
|
851 |
(newClassVars includes:nm) ifFalse:[ |
|
852 |
"/ a removed classVar; |
|
853 |
"/ must recompile methods accessing that one: |
|
854 |
"/ access was: classVar; now: global. |
|
855 |
changeSet1 add:nm |
|
856 |
] |
|
857 |
]. |
|
858 |
newClassVars do:[:nm | |
|
859 |
(oldClassVars includes:nm) ifFalse:[ |
|
860 |
"/ an added classVar; |
|
861 |
"/ must recompile methods accessing that one: |
|
862 |
"/ access was: global; now: classVar. |
|
863 |
"/ but only, if such a global existed in the first |
|
864 |
"/ place. (otherwise, it is a brand-new name) |
|
865 |
"/ cg: no, this is not a good check. |
|
866 |
"/ (Smalltalk includesKey:nm asSymbol) ifTrue:[ |
|
867 |
changeSet1 add:nm |
|
868 |
"/ ] |
|
869 |
] |
|
870 |
]. |
|
871 |
||
872 |
changeSet1 notEmpty ifTrue:[ |
|
873 |
||
874 |
"/ recompile all methods accessing set of changed classvars |
|
875 |
"/ here and also in all subclasses ... |
|
876 |
||
877 |
"/ dont update change file for the recompilation |
|
878 |
||
879 |
Class withoutUpdatingChangesDo:[ |
|
880 |
||
881 |
"/ Smalltalk silentLoading ifFalse:[ |
|
882 |
"/ Transcript showCR:'recompiling class & inst methods accessing ' , changeSet1 printString. |
|
883 |
"/ Transcript endEntry. |
|
884 |
"/ ]. |
|
885 |
oldClass withAllSubclasses do:[:aClass | |
|
886 |
aClass class recompileMethodsAccessingAnyClassvarOrGlobal:changeSet1. |
|
887 |
aClass recompileMethodsAccessingAnyClassvarOrGlobal:changeSet1. |
|
888 |
]. |
|
889 |
]. |
|
890 |
]. |
|
891 |
||
892 |
"notify change of class" |
|
893 |
changed ifTrue:[ |
|
894 |
oldClass addChangeRecordForClass:oldClass. |
|
895 |
]. |
|
896 |
oldClass changed:#definition. |
|
897 |
||
898 |
namespace changed:#classDefinition with:oldClass. |
|
899 |
namespace ~~ Smalltalk ifTrue:[ |
|
900 |
Smalltalk changed:#classDefinition with:oldClass. |
|
901 |
]. |
|
902 |
||
903 |
^ oldClass |
|
904 |
] |
|
905 |
] |
|
906 |
] |
|
907 |
] |
|
908 |
]. |
|
909 |
||
910 |
"/ here we enter the darkness of mordor ... |
|
911 |
"/ since instance variable layout and/or inheritance has changed. |
|
912 |
||
913 |
(newComment ~= oldClass comment) ifTrue:[ |
|
914 |
newClass comment:newComment |
|
915 |
]. |
|
916 |
||
917 |
"/ dont allow built-in classes to be modified this way |
|
918 |
||
919 |
(oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[ |
|
920 |
self error:'the inheritance of this class is fixed - you cannot change it'. |
|
921 |
^ oldClass |
|
922 |
]. |
|
923 |
||
924 |
"/ since we will change the inheritance of some class(es) |
|
7434
aa0faab58aaf
SubclassInfo moved from Behavior to Class
Stefan Vogel <sv@exept.de>
parents:
7370
diff
changeset
|
925 |
Class flushSubclassInfo. |
5905 | 926 |
|
927 |
"/ catch special case, where superclass changed its layout and thus |
|
928 |
"/ forced redefinition of this class; |
|
929 |
"/ only log if this is not the case. |
|
930 |
||
931 |
changed ifTrue:[ |
|
932 |
(superClassChange |
|
933 |
and:[(oldSuperClass isNil or:[newSuperClass notNil and:[oldSuperClass name = newSuperClass name]]) |
|
934 |
and:[(oldClassVars = newClassVars) |
|
935 |
and:[(oldInstVars = newInstVars) |
|
936 |
and:[newComment = oldClass comment]]]]) ifFalse:[ |
|
937 |
newClass addChangeRecordForClass:newClass. |
|
938 |
] |
|
939 |
]. |
|
940 |
||
941 |
"/ care for class methods ... |
|
942 |
||
943 |
changeSet1 := Set new. |
|
944 |
||
945 |
classVarChange := false. |
|
946 |
||
947 |
superClassChange ifTrue:[ |
|
948 |
(oldSuperClass notNil |
|
949 |
and:[newSuperClass notNil |
|
950 |
and:[oldSuperClass allClassVarNames = newSuperClass allClassVarNames |
|
951 |
and:[oldSuperClass name = newSuperClass name |
|
952 |
and:[oldClassVars = newClassVars]]]]) |
|
953 |
ifTrue:[ |
|
954 |
||
955 |
"/ Transcript showCR:'keep class methods (same classvars)'. |
|
956 |
"/ Transcript endEntry. |
|
957 |
||
958 |
"/ class methods still work |
|
959 |
||
960 |
self class copyMethodsFrom:(oldClass class) for:newMetaclass. |
|
961 |
||
962 |
"/ Smalltalk silentLoading ifFalse:[ |
|
963 |
"/ Transcript showCR:'recompiling class methods accessing super ...'. |
|
964 |
"/ Transcript endEntry. |
|
965 |
"/ ]. |
|
966 |
||
967 |
"/ however, those accessing super must be recompiled |
|
968 |
||
969 |
self class |
|
970 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
971 |
for:newMetaclass |
|
972 |
accessingAny:#() |
|
973 |
orSuper:true. |
|
974 |
] ifFalse:[ |
|
975 |
"/ superclass changed: |
|
976 |
"/ must recompile all class methods accessing ANY classvar |
|
977 |
"/ (actually, we could be less strict and handle the case where |
|
978 |
"/ both the old and the new superclass have a common ancestor, |
|
979 |
"/ and both have no new classvariables in between. |
|
980 |
"/ This would speedup the case when a class is inserted into |
|
981 |
"/ the inheritance chain.) |
|
982 |
||
983 |
oldClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
984 |
newClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
985 |
||
986 |
"/ Smalltalk silentLoading ifFalse:[ |
|
987 |
"/ Transcript showCR:'recompiling class methods accessing any classvar or super ...'. |
|
988 |
"/ Transcript endEntry. |
|
989 |
"/ ]. |
|
990 |
||
991 |
self class |
|
992 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
993 |
for:newMetaclass |
|
994 |
accessingAny:changeSet1 |
|
995 |
orSuper:true. |
|
996 |
]. |
|
997 |
newMetaclass recompileInvalidatedMethods. |
|
998 |
] ifFalse:[ |
|
999 |
"/ same superclass, find out which classvars have changed |
|
1000 |
||
1001 |
classVarChange := oldClassVars ~= newClassVars. |
|
1002 |
classVarChange ifTrue:[ |
|
1003 |
oldClassVars do:[:nm | |
|
1004 |
(newClassVars includes:nm) ifFalse:[ |
|
1005 |
changeSet1 add:nm |
|
1006 |
] |
|
1007 |
]. |
|
1008 |
newClassVars do:[:nm | |
|
1009 |
(oldClassVars includes:nm) ifFalse:[ |
|
1010 |
changeSet1 add:nm |
|
1011 |
] |
|
1012 |
]. |
|
1013 |
||
1014 |
"/ must recompile some class-methods |
|
1015 |
||
1016 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1017 |
"/ Transcript showCR:'recompiling class methods accessing ' , changeSet1 printString. |
|
1018 |
"/ Transcript endEntry. |
|
1019 |
"/ ]. |
|
1020 |
||
1021 |
self class |
|
1022 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
1023 |
for:newMetaclass |
|
1024 |
accessingAny:changeSet1. |
|
1025 |
newMetaclass recompileInvalidatedMethods. |
|
1026 |
] ifFalse:[ |
|
1027 |
||
1028 |
"/ class methods still work |
|
1029 |
||
1030 |
self class copyMethodsFrom:(oldClass class) for:newMetaclass |
|
1031 |
]. |
|
1032 |
]. |
|
1033 |
||
1034 |
"/ care for instance methods ... |
|
1035 |
||
1036 |
superClassChange ifTrue:[ |
|
1037 |
"/ superclass changed, |
|
1038 |
"/ must recompile all methods accessing any class or instvar. |
|
1039 |
"/ If number of instvars (i.e. the instances instSize) is the same, |
|
1040 |
"/ we can limit the set of recompiled instance methods to those methods, |
|
1041 |
"/ which refer to an instvar with a different inst-index |
|
1042 |
||
1043 |
"/ the changeset consists of instance variables, |
|
1044 |
"/ with a different position |
|
1045 |
||
1046 |
changeSet2 := self class differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1047 |
||
1048 |
"/ merge in the changed class variables |
|
1049 |
||
1050 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
1051 |
||
1052 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1053 |
"/ Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' [superclass change]...'. |
|
1054 |
"/ Transcript endEntry. |
|
1055 |
"/ ]. |
|
1056 |
||
1057 |
self class |
|
1058 |
copyInvalidatedMethodsFrom:oldClass |
|
1059 |
for:newClass |
|
1060 |
accessingAny:changeSet2 |
|
1061 |
orSuper:true. |
|
1062 |
newClass recompileInvalidatedMethods. |
|
1063 |
||
1064 |
] ifFalse:[ |
|
1065 |
||
1066 |
"/ same inheritance ... |
|
1067 |
||
1068 |
instVarChange := oldInstVars ~= newInstVars. |
|
1069 |
instVarChange ifFalse:[ |
|
1070 |
||
1071 |
"/ same instance variables ... |
|
1072 |
||
1073 |
classVarChange ifTrue:[ |
|
1074 |
"recompile all inst methods accessing changed classvars" |
|
1075 |
||
1076 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1077 |
"/ Transcript showCR:'recompiling instance methods accessing classvars ' , changeSet1 printString , ' ...'. |
|
1078 |
"/ Transcript endEntry. |
|
1079 |
"/ ]. |
|
1080 |
self class |
|
1081 |
copyInvalidatedMethodsFrom:oldClass |
|
1082 |
for:newClass |
|
1083 |
accessingAny:changeSet1. |
|
1084 |
newClass recompileInvalidatedMethods. |
|
1085 |
] ifFalse:[ |
|
1086 |
"/ instance methods still work |
|
1087 |
||
1088 |
self class copyMethodsFrom:oldClass for:newClass |
|
1089 |
] |
|
1090 |
] ifTrue:[ |
|
1091 |
||
1092 |
"/ dont allow built-in classes to be modified |
|
1093 |
||
1094 |
(oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[ |
|
1095 |
self error:'the layout of this class is fixed - you cannot change it'. |
|
1096 |
^ oldClass |
|
1097 |
]. |
|
1098 |
||
1099 |
((oldInstVars size == 0) |
|
1100 |
or:[newInstVars startsWith:oldInstVars]) ifTrue:[ |
|
1101 |
||
1102 |
"/ only new inst variable(s) has/have been added - |
|
1103 |
"/ old methods still work (the existing inst-indices are still valid) |
|
1104 |
||
1105 |
"/ Transcript showCR:'copying methods ...'. |
|
1106 |
"/ Transcript endEntry. |
|
1107 |
||
1108 |
self class copyMethodsFrom:oldClass for:newClass. |
|
1109 |
||
1110 |
"/ but: we have to recompile all methods accessing new instars |
|
1111 |
"/ (it might have been a classVar/global before ...) |
|
1112 |
||
1113 |
addedNames := newInstVars select:[:nm | (oldInstVars includes:nm) not]. |
|
1114 |
"merge in class variables" |
|
1115 |
changeSet1 do:[:nm | addedNames add:nm]. |
|
1116 |
||
1117 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1118 |
"/ Transcript showCR:'recompiling instance methods accessing ' , addedNames printString , '... [added instvars]'. |
|
1119 |
"/ Transcript endEntry. |
|
1120 |
"/ ]. |
|
1121 |
||
1122 |
newClass recompileMethodsAccessingAny:addedNames. |
|
1123 |
] ifFalse:[ |
|
1124 |
||
1125 |
"/ the changeset consists of instance variables, |
|
1126 |
"/ with a different position |
|
1127 |
||
1128 |
changeSet2 := self class differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1129 |
||
1130 |
"merge in the class variables" |
|
1131 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
1132 |
||
1133 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1134 |
"/ Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' ... [changed instvars]'. |
|
1135 |
"/ Transcript endEntry. |
|
1136 |
"/ ]. |
|
1137 |
||
1138 |
self class |
|
1139 |
copyInvalidatedMethodsFrom:oldClass |
|
1140 |
for:newClass |
|
1141 |
accessingAny:changeSet2. |
|
1142 |
newClass recompileInvalidatedMethods. |
|
1143 |
]. |
|
1144 |
]. |
|
1145 |
]. |
|
1146 |
||
1147 |
"/ finally, if the oldClass came from a dynamically loaded |
|
1148 |
"/ classLibrary, we must recompile the methods in the newClass. |
|
1149 |
"/ otherwise, the methods code will vanish when the old (obsolete) |
|
1150 |
"/ class eventually vanishes ... |
|
1151 |
self class recompileMachineCodeMethodsIn:newClass. |
|
1152 |
||
1153 |
(oldPkg notNil and:[oldPkg ~= pkg]) ifTrue:[ |
|
1154 |
"/ we have to change all methods package info |
|
1155 |
"/ to belong to the old package. |
|
6078
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1156 |
newClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
5905 | 1157 |
mthd setPackage:oldPkg |
1158 |
]. |
|
1159 |
]. |
|
1160 |
||
1161 |
"/ WOW, everything done for this class |
|
1162 |
"/ what about subclasses ? |
|
1163 |
||
1164 |
"/ update superclass of immediate subclasses - |
|
1165 |
"/ this forces recompilation (recursively) if needed |
|
1166 |
"/ (dont update change file for the subclass changes) |
|
1167 |
||
1168 |
Class classRedefinitionSignal answer:#keep do:[ |
|
1169 |
Class withoutUpdatingChangesDo:[ |
|
1170 |
oldClass subclasses copy do:[:aClass | |
|
1171 |
||
1172 |
"/ Transcript showCR:'changing superclass of:' , aClass name. |
|
1173 |
"/ Transcript endEntry. |
|
1174 |
||
1175 |
aClass superclass:newClass |
|
1176 |
] |
|
1177 |
] |
|
1178 |
]. |
|
1179 |
||
1180 |
"/ change any private subclasses' owners |
|
1181 |
||
1182 |
oldClass privateClassesDo:[:aClass | |
|
1183 |
aClass isLoaded ifTrue:[ |
|
1184 |
aClass class setOwningClass:newClass |
|
1185 |
] |
|
1186 |
]. |
|
1187 |
||
1188 |
"/ change category in oldClass - so we see immediately what it is ... |
|
1189 |
||
1190 |
oldCategory := oldClass category. |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1191 |
oldClass setCategory:#'* obsolete *'. |
5905 | 1192 |
oldClass wasAutoloaded ifTrue:[ Autoload removeClass:oldClass ]. |
1193 |
Smalltalk flushCachedClass:oldClass. |
|
1194 |
||
1195 |
"/ and make the new class globally known |
|
1196 |
||
1197 |
namespace notNil ifTrue:[ |
|
6514 | 1198 |
buildPrivateClass ifTrue:[ |
5905 | 1199 |
namespace privateClassesAt:classSymbol put:newClass. |
1200 |
] ifFalse:[ |
|
1201 |
namespace at:nameKey put:newClass. |
|
1202 |
||
1203 |
oldCategory ~= category ifTrue:[ |
|
1204 |
"notify change of organization" |
|
1205 |
namespace changed:#organization. |
|
1206 |
namespace ~~ Smalltalk ifTrue:[ |
|
1207 |
Smalltalk changed:#organization. |
|
1208 |
] |
|
1209 |
] |
|
1210 |
]. |
|
1211 |
]. |
|
1212 |
||
1213 |
"/ Not becoming the old class creates some update problems; |
|
1214 |
"/ the browsers must check carefully - a simple identity compare is |
|
1215 |
"/ not enough ... |
|
1216 |
"/ QUESTION: is this a good idea ? |
|
1217 |
||
1218 |
||
1219 |
newClass dependents:(oldClass dependents). |
|
1220 |
newClass changed:#definition. |
|
1221 |
||
1222 |
"just to make certain ... - tell dependents of oldClass, that something changed |
|
1223 |
(systemBrowsers will react on this, and update their views)" |
|
1224 |
oldClass changed:#definition with:newClass. |
|
1225 |
||
1226 |
namespace changed:#classDefinition with:newClass. |
|
1227 |
namespace ~~ Smalltalk ifTrue:[ |
|
1228 |
Smalltalk changed:#classDefinition with:newClass. |
|
1229 |
]. |
|
1230 |
||
1231 |
ObjectMemory flushCaches. |
|
1232 |
||
1233 |
oldClass ~~ newClass ifTrue:[ |
|
1234 |
namespace notNil ifTrue:[ |
|
6514 | 1235 |
buildPrivateClass ifFalse:[ |
5905 | 1236 |
namespace == Smalltalk ifTrue:[ |
5907 | 1237 |
ClassBuilder checkForAliasesOf:oldClass with:newClass. |
5905 | 1238 |
]. |
1239 |
] |
|
1240 |
] |
|
1241 |
]. |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1242 |
(instVarChange or:[classVarChange]) ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1243 |
self changeReferencesFrom:oldClass to:newClass. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1244 |
]. |
7434
aa0faab58aaf
SubclassInfo moved from Behavior to Class
Stefan Vogel <sv@exept.de>
parents:
7370
diff
changeset
|
1245 |
Class flushSubclassInfo. |
5905 | 1246 |
^ newClass |
1247 |
||
1248 |
"Created: / 26.5.1996 / 11:55:26 / cg" |
|
1249 |
"Modified: / 18.3.1999 / 18:23:31 / stefan" |
|
1250 |
"Modified: / 13.2.2000 / 22:59:57 / cg" |
|
5907 | 1251 |
! |
1252 |
||
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1253 |
changeReferencesFrom:oldClass to:newClass |
6514 | 1254 |
| refs| |
6035 | 1255 |
|
1256 |
refs := OrderedCollection new. |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1257 |
ObjectMemory allObjectsDo:[:obj | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1258 |
(obj referencesObject:oldClass) ifTrue:[ |
6035 | 1259 |
obj isContext ifFalse:[ |
1260 |
refs add:obj |
|
1261 |
]. |
|
1262 |
]. |
|
1263 |
]. |
|
6037 | 1264 |
refs isEmpty ifTrue:[ |
1265 |
^ self |
|
1266 |
]. |
|
1267 |
||
6070
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1268 |
"/ answer := OptionBox |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1269 |
"/ request:('Update References (from old class to new class) ?') withCRs |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1270 |
"/ label:'Confirm' |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1271 |
"/ buttonLabels:#('no' 'browse references' 'update') |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1272 |
"/ values:#(false #browse true) |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1273 |
"/ default:#true |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1274 |
"/ onCancel:false. |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1275 |
"/ |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1276 |
"/ answer == #browse ifTrue:[ |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1277 |
"/ refs inspect. |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1278 |
"/ answer := self confirm:('Update References (from old class to new class) ?') withCRs. |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1279 |
"/ ]. |
28abbfdcbd4d
no longer ask if references to class should be searched for
Claus Gittinger <cg@exept.de>
parents:
6057
diff
changeset
|
1280 |
"/ answer == false ifTrue:[^ self]. |
6035 | 1281 |
|
1282 |
refs do:[:obj | |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1283 |
|skip| |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1284 |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1285 |
skip := false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1286 |
obj isBehavior ifTrue:[ |
6078
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1287 |
skip := true. |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1288 |
obj isObsolete ifFalse:[ |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1289 |
obj isMeta ifTrue:[ |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1290 |
"/ the owner-slot ? |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1291 |
obj owningClass == oldClass ifTrue:[ |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1292 |
"/ self halt. |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1293 |
]. |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1294 |
obj theNonMetaclass == oldClass ifTrue:[ |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1295 |
"/ self halt. |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1296 |
] |
13d651d69246
renamed: #allSelectorsAndMethodsDo: into: #instAndClassSelectorsAndMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
1297 |
] |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1298 |
] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1299 |
]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1300 |
skip ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1301 |
obj replaceReferencesTo:oldClass with:newClass. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6070
diff
changeset
|
1302 |
]. |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1303 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1304 |
! |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1305 |
|
6514 | 1306 |
instantiateMetaclass |
1307 |
"create the metaclass proper" |
|
1308 |
||
1309 |
|newMetaclass classesSuperclass| |
|
1310 |
||
1311 |
buildPrivateClass ifTrue:[ |
|
1312 |
newMetaclass := PrivateMetaclass new |
|
1313 |
] ifFalse:[ |
|
1314 |
newMetaclass := Metaclass new. |
|
1315 |
]. |
|
1316 |
superClass isNil ifTrue:[ |
|
1317 |
classesSuperclass := Class. |
|
1318 |
] ifFalse:[ |
|
1319 |
classesSuperclass := superClass class. |
|
1320 |
]. |
|
1321 |
newMetaclass setSuperclass:classesSuperclass instSize:(classesSuperclass instSize + classInstanceVariableNames countWords). |
|
1322 |
newMetaclass setInstanceVariableString:classInstanceVariableNames. |
|
1323 |
^ newMetaclass |
|
1324 |
! |
|
1325 |
||
5907 | 1326 |
rebuildForChangedInstanceVariables |
1327 |
"changing / adding class-inst vars - |
|
1328 |
this actually creates a new metaclass and class, leaving the original |
|
1329 |
classes around as obsolete classes. This may also be true for all subclasses, |
|
1330 |
if class instance variables are added/removed. |
|
1331 |
Existing instances continue to be defined by their original classes. |
|
1332 |
||
1333 |
Time will show, if this is an acceptable behavior or if we should migrate |
|
1334 |
instances to become insts. of the new classes." |
|
1335 |
||
1336 |
|newClass newMetaclass nClassInstVars oldClass |
|
1337 |
allSubclasses oldVars |
|
1338 |
oldNames newNames addedNames |
|
1339 |
oldOffsets newOffsets offset changeSet delta |
|
1340 |
oldToNew newSubMeta newSub oldSubMeta oldSuper |
|
1341 |
commonClassInstVars t superclass| |
|
1342 |
||
1343 |
" |
|
1344 |
cleanup needed here: extract common things with name:inEnvironment:... |
|
1345 |
and restructure things ... currently way too complex. |
|
1346 |
" |
|
1347 |
||
1348 |
oldVars := oldMetaClass instanceVariableString. |
|
1349 |
instanceVariableNames = oldVars ifTrue:[ |
|
1350 |
" |
|
1351 |
Transcript showCR:'no change (', oldVars , ') -> (', instanceVariableNames , ')'. |
|
1352 |
" |
|
1353 |
^ self |
|
1354 |
]. |
|
1355 |
||
1356 |
oldNames := oldVars asCollectionOfWords. |
|
1357 |
newNames := instanceVariableNames asCollectionOfWords. |
|
1358 |
||
1359 |
oldNames = newNames ifTrue:[ |
|
1360 |
" |
|
1361 |
Transcript showCR:'no real change'. |
|
1362 |
" |
|
1363 |
"no real change (just formatting)" |
|
1364 |
oldMetaClass setInstanceVariableString:instanceVariableNames. |
|
1365 |
^ self |
|
1366 |
]. |
|
1367 |
||
1368 |
"/ " |
|
1369 |
"/ let user confirm, if any name is no good (and was good before) |
|
1370 |
"/ " |
|
1371 |
"/ (oldNames inject:true |
|
1372 |
"/ into:[:okSoFar :word | |
|
1373 |
"/ okSoFar and:[word first isUppercase] |
|
1374 |
"/ ]) |
|
1375 |
"/ ifTrue:[ |
|
1376 |
"/ "was ok before" |
|
1377 |
"/ (newNames inject:true |
|
1378 |
"/ into:[:okSoFar :word | |
|
1379 |
"/ okSoFar and:[word first isUppercase] |
|
1380 |
"/ ]) |
|
1381 |
"/ ifFalse:[ |
|
1382 |
"/ (self confirm:'class instance variable names should start with an uppercase letter |
|
1383 |
"/(by convention only) |
|
1384 |
"/ |
|
1385 |
"/install anyway ?' withCRs) |
|
1386 |
"/ ifFalse:[ |
|
1387 |
"/ ^ nil |
|
1388 |
"/ ] |
|
1389 |
"/ ] |
|
1390 |
"/ ]. |
|
1391 |
||
1392 |
nClassInstVars := newNames size. |
|
1393 |
||
1394 |
" |
|
1395 |
Transcript showCR:'create new class/metaclass'. |
|
1396 |
" |
|
1397 |
||
1398 |
" |
|
1399 |
create the new metaclass |
|
1400 |
" |
|
1401 |
oldMetaClass isPrivate ifTrue:[ |
|
6514 | 1402 |
newMetaclass := oldMetaClass class "PrivateMetaclass" new. |
5907 | 1403 |
newMetaclass setOwningClass:(oldMetaClass owningClass). |
1404 |
] ifFalse:[ |
|
6514 | 1405 |
newMetaclass := oldMetaClass class "Metaclass" new. |
5907 | 1406 |
]. |
1407 |
superclass := oldMetaClass superclass. |
|
1408 |
newMetaclass setSuperclass:superclass. |
|
1409 |
newMetaclass instSize:(superclass instSize + nClassInstVars). |
|
1410 |
(nClassInstVars ~~ 0) ifTrue:[ |
|
1411 |
newMetaclass setInstanceVariableString:instanceVariableNames |
|
1412 |
]. |
|
1413 |
"/ newMetaclass flags:(Behavior flagBehavior "flagNotIndexed"). |
|
1414 |
"/ newMetaclass setName:name. |
|
1415 |
"/ newMetaclass classVariableString:classvars. |
|
1416 |
"/ newMetaclass setComment:(self comment). |
|
1417 |
||
1418 |
"find the class which is my sole instance" |
|
1419 |
||
1420 |
oldClass := oldMetaClass theNonMetaclass. |
|
1421 |
||
1422 |
" |
|
1423 |
create the new class |
|
1424 |
" |
|
1425 |
newClass := newMetaclass new. |
|
1426 |
newClass setSuperclass:(oldClass superclass) instSize:(oldClass instSize). |
|
1427 |
newClass flags:(oldClass flags). |
|
1428 |
newClass setName:(oldClass name). |
|
1429 |
newClass setInstanceVariableString:(oldClass instanceVariableString). |
|
1430 |
newClass classVariableString:(oldClass classVariableString). |
|
1431 |
newClass setComment:(oldClass comment). |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1432 |
newClass setCategory:(oldClass category). |
7487 | 1433 |
(t := oldClass classAttributes) notNil ifTrue:[ |
1434 |
newClass classAttributes:t. |
|
5907 | 1435 |
]. |
1436 |
newClass setClassFilename:(oldClass classFilename). |
|
1437 |
||
1438 |
"/ set the new classes package |
|
1439 |
"/ from the old package |
|
1440 |
||
1441 |
newClass package:(oldClass package). |
|
1442 |
||
1443 |
"/ and keep the binary revision |
|
1444 |
newClass setBinaryRevision:(oldClass binaryRevision). |
|
1445 |
||
1446 |
changeSet := Set new. |
|
1447 |
((oldNames size == 0) |
|
1448 |
or:[newNames startsWith:oldNames]) ifTrue:[ |
|
1449 |
"new variable(s) has/have been added - old methods still work" |
|
1450 |
||
1451 |
"/ Transcript showCR:'copying methods ...'. |
|
1452 |
"/ Transcript endEntry. |
|
1453 |
||
1454 |
ClassBuilder copyMethodsFrom:oldMetaClass for:newMetaclass. |
|
1455 |
ClassBuilder copyMethodsFrom:oldClass for:newClass. |
|
1456 |
||
1457 |
" |
|
1458 |
but have to recompile methods accessing stuff now defined |
|
1459 |
(it might have been a global/undeclared before ...) |
|
1460 |
" |
|
1461 |
||
1462 |
addedNames := newNames select:[:nm | (oldNames includes:nm) not]. |
|
1463 |
||
1464 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1465 |
"/ Transcript showCR:'recompiling class methods of ' , newMetaclass name , |
|
1466 |
"/ ' accessing any of ' , addedNames printString. |
|
1467 |
"/ ]. |
|
1468 |
||
1469 |
"recompile class-methods" |
|
1470 |
newMetaclass recompileMethodsAccessingAny:addedNames. |
|
1471 |
] ifFalse:[ |
|
1472 |
" |
|
1473 |
create the changeSet; thats the set of class instvar names |
|
1474 |
which have changed their position or are new |
|
1475 |
" |
|
1476 |
offset := 0. oldOffsets := Dictionary new. |
|
1477 |
oldNames do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset]. |
|
1478 |
offset := 0. newOffsets := Dictionary new. |
|
1479 |
newNames do:[:nm | offset := offset + 1. newOffsets at:nm put:offset]. |
|
1480 |
||
1481 |
oldOffsets associationsDo:[:a | |
|
1482 |
|k| |
|
1483 |
||
1484 |
k := a key. |
|
1485 |
(newOffsets includesKey:k) ifFalse:[ |
|
1486 |
changeSet add:k |
|
1487 |
] ifTrue:[ |
|
1488 |
(a value ~~ (newOffsets at:k)) ifTrue:[ |
|
1489 |
changeSet add:k |
|
1490 |
] |
|
1491 |
] |
|
1492 |
]. |
|
1493 |
newOffsets associationsDo:[:a | |
|
1494 |
|k| |
|
1495 |
||
1496 |
k := a key. |
|
1497 |
(oldOffsets includesKey:k) ifFalse:[ |
|
1498 |
changeSet add:k |
|
1499 |
] ifTrue:[ |
|
1500 |
(a value ~~ (oldOffsets at:k)) ifTrue:[ |
|
1501 |
changeSet add:k |
|
1502 |
] |
|
1503 |
] |
|
1504 |
]. |
|
1505 |
||
1506 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1507 |
"/ Transcript showCR:'recompiling class methods of ' , newMetaclass name , |
|
1508 |
"/ ' accessing any of ' , changeSet printString. |
|
1509 |
"/ ]. |
|
1510 |
||
1511 |
" |
|
1512 |
recompile class-methods accessing any c-instvar with a changed position |
|
1513 |
" |
|
1514 |
ClassBuilder copyInvalidatedMethodsFrom:oldMetaClass for:newMetaclass accessingAny:changeSet. |
|
1515 |
newMetaclass recompileInvalidatedMethods. |
|
1516 |
||
1517 |
ClassBuilder copyMethodsFrom:oldClass for:newClass. |
|
1518 |
]. |
|
1519 |
||
1520 |
delta := newNames size - oldNames size. |
|
1521 |
||
1522 |
"/ preserve existing classInstVar values (but not those from Class) |
|
1523 |
newMetaclass allInstVarNames do:[:nm | |
|
1524 |
|v| |
|
1525 |
||
1526 |
(Class class allInstVarNames includes:nm) ifFalse:[ |
|
1527 |
v := oldClass instVarNamed:nm ifAbsent:nil. |
|
1528 |
v notNil ifTrue:[ |
|
1529 |
newClass instVarNamed:nm put:v. |
|
1530 |
]. |
|
1531 |
]. |
|
1532 |
]. |
|
1533 |
||
1534 |
" |
|
1535 |
get list of all subclasses - do before superclass is changed |
|
1536 |
" |
|
1537 |
allSubclasses := oldClass allSubclasses asOrderedCollection. |
|
1538 |
"/ cg: wrong: allSubclasses := allSubclasses asSortedCollection:[:a :b | b isSubclassOf:a]. |
|
1539 |
allSubclasses := allSubclasses topologicalSort:[:a :b | b isSubclassOf:a]. |
|
1540 |
||
1541 |
oldToNew := IdentityDictionary new. |
|
1542 |
||
1543 |
" |
|
1544 |
create a new class tree, based on the new version |
|
1545 |
" |
|
6957
562b88083688
more cache flushing when instvars change
Claus Gittinger <cg@exept.de>
parents:
6825
diff
changeset
|
1546 |
Smalltalk flushCachedClasses. |
562b88083688
more cache flushing when instvars change
Claus Gittinger <cg@exept.de>
parents:
6825
diff
changeset
|
1547 |
Class flushSubclassInfo. |
5907 | 1548 |
allSubclasses do:[:aSubclass | |
1549 |
oldSuper := aSubclass superclass. |
|
1550 |
oldSubMeta := aSubclass class. |
|
1551 |
||
1552 |
newSubMeta := Metaclass new. |
|
1553 |
oldSuper == oldClass ifTrue:[ |
|
1554 |
newSubMeta setSuperclass:newMetaclass. |
|
1555 |
] ifFalse:[ |
|
1556 |
newSubMeta setSuperclass:(oldToNew at:oldSuper) class. |
|
1557 |
]. |
|
1558 |
newSubMeta instSize:(oldSubMeta instSize + delta). |
|
1559 |
newSubMeta flags:(oldSubMeta flags). |
|
1560 |
"/ newSubMeta setName:(oldSubMeta name). |
|
1561 |
newSubMeta setInstanceVariableString:(oldSubMeta instanceVariableString). |
|
1562 |
"/ newSubMeta setComment:(oldSubMeta comment). |
|
1563 |
||
1564 |
newSub := newSubMeta new. |
|
1565 |
oldSuper == oldClass ifTrue:[ |
|
1566 |
newSub setSuperclass:newClass. |
|
1567 |
] ifFalse:[ |
|
1568 |
newSub setSuperclass:(oldToNew at:oldSuper). |
|
1569 |
]. |
|
1570 |
||
1571 |
"/ newSub setMethodDictionary:(aSubclass methodDictionary copy). |
|
1572 |
"/ newSub class setMethodDictionary:(aSubclass class methodDictionary copy). |
|
1573 |
newSub setName:(aSubclass name). |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1574 |
newSub setClassVariableString:(aSubclass classVariableString). |
5907 | 1575 |
newSub setInstanceVariableString:(aSubclass instanceVariableString). |
7487 | 1576 |
(t := aSubclass classAttributes) notNil ifTrue:[ |
1577 |
newSub classAttributes:t. |
|
7370
1ed996a6e7bf
primitiveSpec changed to attributes.
Claus Gittinger <cg@exept.de>
parents:
7230
diff
changeset
|
1578 |
]. |
5907 | 1579 |
newSub package:(aSubclass package). |
1580 |
newSub setClassFilename:(oldClass classFilename). |
|
1581 |
newSub setComment:(aSubclass comment). |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1582 |
newSub setCategory:(aSubclass category). |
5907 | 1583 |
newSub instSize:(aSubclass instSize). |
1584 |
newSub setBinaryRevision:(aSubclass binaryRevision). |
|
1585 |
||
1586 |
oldToNew at:aSubclass put:newSub. |
|
1587 |
||
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1588 |
aSubclass setCategory:#'* obsolete *'. |
5907 | 1589 |
|
1590 |
"/ preserve existing classInstVar values (but not those from Class) |
|
1591 |
||
1592 |
newSubMeta allInstVarNames do:[:nm | |
|
1593 |
|v| |
|
1594 |
||
1595 |
(Class class allInstVarNames includes:nm) ifFalse:[ |
|
1596 |
v := aSubclass instVarNamed:nm ifAbsent:nil. |
|
1597 |
v notNil ifTrue:[ |
|
1598 |
newSub instVarNamed:nm put:v. |
|
1599 |
]. |
|
1600 |
]. |
|
1601 |
]. |
|
1602 |
||
1603 |
]. |
|
1604 |
||
1605 |
"recompile what needs to be" |
|
1606 |
||
1607 |
delta == 0 ifTrue:[ |
|
1608 |
"only have to recompile class methods accessing |
|
1609 |
class instvars from changeset |
|
1610 |
" |
|
1611 |
||
1612 |
allSubclasses do:[:oldSubclass | |
|
1613 |
|newSubclass| |
|
1614 |
||
1615 |
newSubclass := oldToNew at:oldSubclass. |
|
1616 |
||
1617 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1618 |
"/ Transcript showCR:'recompiling class methods of ' , newSubclass class name , |
|
1619 |
"/ ' accessing any of ' , changeSet printString. |
|
1620 |
"/ ]. |
|
1621 |
||
1622 |
ClassBuilder |
|
1623 |
copyInvalidatedMethodsFrom:oldSubclass class for:newSubclass class |
|
1624 |
accessingAny:changeSet orSuper:true. |
|
1625 |
||
1626 |
ClassBuilder |
|
1627 |
copyInvalidatedMethodsFrom:oldSubclass for:newSubclass |
|
1628 |
accessingAny:#() orSuper:true. |
|
1629 |
||
1630 |
newSubclass class recompileInvalidatedMethods. |
|
1631 |
newSubclass recompileInvalidatedMethods. |
|
1632 |
] |
|
1633 |
] ifFalse:[ |
|
1634 |
" |
|
1635 |
have to recompile all class methods accessing class instvars |
|
1636 |
" |
|
1637 |
commonClassInstVars := oldClass class allInstVarNames. |
|
1638 |
changeSet do:[:v | |
|
1639 |
commonClassInstVars remove:v ifAbsent:[] |
|
1640 |
]. |
|
1641 |
||
1642 |
allSubclasses do:[:oldSubclass | |
|
1643 |
|newSubclass classInstVars| |
|
1644 |
||
1645 |
newSubclass := oldToNew at:oldSubclass. |
|
1646 |
||
1647 |
classInstVars := newSubclass class allInstVarNames asSet. |
|
1648 |
classInstVars removeAll:commonClassInstVars. |
|
1649 |
classInstVars addAll:changeSet. |
|
1650 |
||
1651 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1652 |
"/ Transcript showCR:'recompiling class methods of ' , newSubclass class name , |
|
1653 |
"/ ' accessing any of ' , classInstVars printString. |
|
1654 |
"/ ]. |
|
1655 |
||
1656 |
ClassBuilder |
|
1657 |
copyInvalidatedMethodsFrom:oldSubclass class for:newSubclass class |
|
1658 |
accessingAny:classInstVars orSuper:true. |
|
1659 |
||
1660 |
ClassBuilder |
|
1661 |
copyInvalidatedMethodsFrom:oldSubclass for:newSubclass |
|
1662 |
accessingAny:#() orSuper:true. |
|
1663 |
||
1664 |
newSubclass class recompileInvalidatedMethods. |
|
1665 |
newSubclass recompileInvalidatedMethods. |
|
1666 |
] |
|
1667 |
]. |
|
1668 |
||
1669 |
newClass addChangeRecordForClassInstvars:newClass. |
|
1670 |
||
1671 |
"install all new classes" |
|
1672 |
||
1673 |
(Smalltalk at:(oldClass name asSymbol) ifAbsent:nil) == oldClass ifTrue:[ |
|
1674 |
Smalltalk at:(oldClass name asSymbol) put:newClass. |
|
1675 |
ClassBuilder checkForAliasesOf:oldClass with:newClass. |
|
1676 |
||
1677 |
" |
|
1678 |
change any private subclasses' owners |
|
1679 |
" |
|
1680 |
oldClass privateClassesDo:[:aClass | |
|
1681 |
aClass class setOwningClass:newClass |
|
1682 |
]. |
|
1683 |
||
1684 |
]. |
|
1685 |
ObjectMemory flushCachesFor:oldClass. |
|
1686 |
||
1687 |
allSubclasses do:[:oldSubClass | |
|
1688 |
|newSubClass| |
|
1689 |
||
1690 |
newSubClass := oldToNew at:oldSubClass. |
|
1691 |
||
1692 |
"/ Transcript showCR:'install ' , newSubClass name , '(' , newSubClass category , ')' , |
|
1693 |
"/ ' as ' , newSubClass name. |
|
1694 |
||
1695 |
(Smalltalk at:(oldSubClass name asSymbol) ifAbsent:nil) == oldSubClass ifTrue:[ |
|
1696 |
Smalltalk at:oldSubClass name asSymbol put:newSubClass. |
|
1697 |
ClassBuilder checkForAliasesOf:oldSubClass with:newSubClass. |
|
1698 |
]. |
|
1699 |
ObjectMemory flushCachesFor:oldSubClass. |
|
1700 |
||
1701 |
oldSubClass privateClassesDo:[:aClass | |
|
1702 |
aClass class setOwningClass:newSubClass |
|
1703 |
]. |
|
1704 |
]. |
|
1705 |
||
1706 |
"tell dependents ..." |
|
1707 |
||
1708 |
oldClass changed:#definition. |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1709 |
"/ oldClass nameSpace changed:#classDefinition with:oldClass. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1710 |
"/ oldClass nameSpace ~~ Smalltalk ifTrue:[ |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1711 |
"/ Smalltalk changed:#classDefinition with:oldClass. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1712 |
"/ ]. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1713 |
|
5907 | 1714 |
oldMetaClass changed:#definition. |
1715 |
oldMetaClass nameSpace changed:#classDefinition with:oldMetaClass. |
|
1716 |
oldMetaClass nameSpace ~~ Smalltalk ifTrue:[ |
|
1717 |
Smalltalk changed:#classDefinition with:oldMetaClass. |
|
1718 |
]. |
|
1719 |
||
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1720 |
oldClass setCategory:#'* obsolete *'. |
5907 | 1721 |
^ newMetaclass |
1722 |
||
1723 |
"Created: / 29.10.1995 / 19:57:08 / cg" |
|
1724 |
"Modified: / 1.4.1997 / 15:44:09 / stefan" |
|
1725 |
"Modified: / 31.7.1998 / 18:02:00 / cg" |
|
5905 | 1726 |
! ! |
1727 |
||
1728 |
!ClassBuilder methodsFor:'checks'! |
|
1729 |
||
1730 |
checkClassName |
|
1731 |
(className isSymbol not |
|
1732 |
or:[className size == 0]) ifTrue:[ |
|
1733 |
self error:'invalid class name (must be a nonEmpty symbol)'. |
|
1734 |
]. |
|
1735 |
className first isLetter ifFalse:[ |
|
1736 |
self error:'invalid class name (must start with a letter)'. |
|
1737 |
]. |
|
1738 |
! |
|
1739 |
||
1740 |
checkConventionsFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
|
1741 |
"Check for some 'considered bad-style' things, like lower case names. |
|
1742 |
NOTICE: |
|
1743 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
1744 |
the outer codeview a chance to highlight the error. |
|
1745 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
1746 |
" |
|
1747 |
||
1748 |
|names idx what doChecks answ| |
|
1749 |
||
1750 |
doChecks := Metaclass confirmationQuerySignal query. |
|
1751 |
doChecks == false ifTrue:[^ true]. |
|
1752 |
||
1753 |
"let user confirm, if the classname is no good" |
|
1754 |
className first isUppercase ifFalse:[ |
|
1755 |
aClass == NameSpace ifTrue:[ |
|
1756 |
what := 'namespace' |
|
1757 |
] ifFalse:[ |
|
1758 |
what := 'class' |
|
1759 |
]. |
|
1760 |
||
1761 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
1762 |
answ notNil ifTrue:[^ answ]. |
|
1763 |
||
1764 |
(self confirm:(what , ' name ''' , className , |
|
1765 |
''' should start with an uppercase letter |
|
1766 |
(by convention only) |
|
1767 |
||
1768 |
install anyway ?') withCRs) |
|
1769 |
ifFalse:[ |
|
1770 |
^ false |
|
1771 |
] |
|
1772 |
]. |
|
1773 |
||
1774 |
names := instVarNameString asCollectionOfWords. |
|
1775 |
||
1776 |
"let user confirm, if any instvarname is no good" |
|
1777 |
(idx := names findFirst:[:word | word first isUppercase]) ~~ 0 ifTrue:[ |
|
1778 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
1779 |
answ notNil ifTrue:[^ answ]. |
|
1780 |
||
1781 |
(self confirm:className , ': instance variable named ''' , (names at:idx) allBold , ''' |
|
1782 |
should start with a lowercase letter (by convention only). |
|
1783 |
||
1784 |
Install anyway ?' withCRs) |
|
1785 |
ifFalse:[ |
|
1786 |
^ false |
|
1787 |
] |
|
1788 |
]. |
|
1789 |
||
1790 |
names := classVarNameString asCollectionOfWords. |
|
1791 |
||
1792 |
"let user confirm, if any classvarname is no good" |
|
1793 |
(idx := names findFirst:[:word | word first isLowercase]) ~~ 0 ifTrue:[ |
|
1794 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
1795 |
answ notNil ifTrue:[^ answ]. |
|
1796 |
||
1797 |
(self confirm:className , ': class variable named ''' , (names at:idx) allBold , ''' |
|
1798 |
should start with an uppercase letter (by convention only). |
|
1799 |
||
1800 |
Install anyway ?' withCRs) |
|
1801 |
ifFalse:[ |
|
1802 |
^ false |
|
1803 |
]. |
|
1804 |
]. |
|
1805 |
||
1806 |
^ true |
|
1807 |
||
1808 |
"Created: / 15.10.1996 / 11:56:38 / cg" |
|
1809 |
"Modified: / 3.2.1999 / 11:24:52 / cg" |
|
1810 |
"Modified: / 18.3.1999 / 18:22:47 / stefan" |
|
1811 |
! |
|
1812 |
||
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1813 |
checkForCircularDefinitionFrom:oldClass |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1814 |
oldClass allSuperclasses do:[:cls | |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1815 |
cls name = realNewName ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1816 |
^ true |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1817 |
] |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1818 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1819 |
|
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1820 |
superClass notNil ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1821 |
superClass allSuperclasses do:[:cls | |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1822 |
cls name = realNewName ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1823 |
^ true |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1824 |
] |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1825 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1826 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1827 |
^ false |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1828 |
! |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1829 |
|
5905 | 1830 |
checkInstvarRedefsWith:stringOfInstVarNames subclassOf:aClass old:oldClass name:newName |
1831 |
|superInstVars msg| |
|
1832 |
||
1833 |
aClass notNil ifTrue:[ |
|
1834 |
" |
|
1835 |
check for instVar redef of superClass instVars |
|
1836 |
" |
|
1837 |
superInstVars := aClass allInstVarNames. |
|
1838 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
1839 |
(superInstVars includes:nm) ifTrue:[ |
|
1840 |
(oldClass notNil |
|
1841 |
and:[stringOfInstVarNames = oldClass instanceVariableString]) |
|
1842 |
ifTrue:[ |
|
1843 |
Transcript showCR:('instVar conflict in `' , newName , ''' for `' , nm , ''' due to superclass change.'). |
|
7132 | 1844 |
msg := 'InstVar conflict in `' , newName allBold , ''' for `' , nm allBold, ''' due to superclass change.\You now have two different instVar slots with the same name.\\Don''t forget to fix this later.'. |
5905 | 1845 |
self warn:msg withCRs. |
1846 |
] ifFalse:[ |
|
1847 |
Transcript showCR:('instVar `' , nm , ''' is already defined in a superclass of `' , newName , '''.'). |
|
7132 | 1848 |
msg := 'instVar `' , nm allBold, ''' is already defined in a superclass.\Change the definition of `' , newName allBold, ''' anyway ?\\Don''t forget to fix this later.'. |
5905 | 1849 |
^ self confirm:msg withCRs |
1850 |
]. |
|
1851 |
] |
|
1852 |
]. |
|
1853 |
]. |
|
1854 |
||
1855 |
oldClass notNil ifTrue:[ |
|
1856 |
" |
|
1857 |
check for instVar redefs in subclass instVars |
|
1858 |
" |
|
1859 |
oldClass allSubclassesDo:[:sub | |
|
1860 |
|vars| |
|
1861 |
||
1862 |
vars := sub instVarNames. |
|
1863 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
1864 |
(vars includes:nm) ifTrue:[ |
|
7132 | 1865 |
^ self confirm:('subclass `' |
1866 |
, sub name allBold |
|
1867 |
, ''' already defines an instVar named `' |
|
1868 |
, nm allBold |
|
5905 | 1869 |
, '''.\\Change the definition of `' |
7132 | 1870 |
, newName allBold |
1871 |
, ''' anyway ?\Notice: you must fix this later.' |
|
5905 | 1872 |
) withCRs |
1873 |
] |
|
1874 |
] |
|
1875 |
] |
|
1876 |
]. |
|
1877 |
^ true |
|
1878 |
||
1879 |
"Created: 29.1.1997 / 17:42:11 / cg" |
|
1880 |
! |
|
1881 |
||
1882 |
checkValidSubclassing |
|
1883 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
|
1884 |
superClass notNil ifTrue:[ |
|
1885 |
superClass canBeSubclassed ifFalse:[ |
|
1886 |
self error:('it is not possible to subclass ' , superClass name). |
|
1887 |
] |
|
1888 |
]. |
|
1889 |
! |
|
1890 |
||
1891 |
checkValidVarNamesFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
|
1892 |
"Check for some 'considered bad-style' things, like lower case names. |
|
1893 |
NOTICE: |
|
1894 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
1895 |
the outer codeview a chance to highlight the error. |
|
1896 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
1897 |
" |
|
1898 |
||
1899 |
|names| |
|
1900 |
||
1901 |
names := instVarNameString asCollectionOfWords. |
|
1902 |
||
1903 |
"check for instvar redefs within local instvars" |
|
1904 |
names keysAndValuesDo:[:index :aName | |
|
1905 |
(names indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
1906 |
self warn:'instance variable ''' , aName , '''\occurs multiple times in instVarString.\\Class not installed.' withCRs. |
|
1907 |
^ false. |
|
1908 |
] |
|
1909 |
]. |
|
1910 |
||
1911 |
names := classVarNameString asCollectionOfWords. |
|
1912 |
||
1913 |
"check for classvar redefs within local instvars" |
|
1914 |
names keysAndValuesDo:[:index :aName | |
|
1915 |
(names indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
1916 |
self warn:'class variable ''' , aName , '''\occurs multiple times in classVarString.\\Class not installed.' withCRs. |
|
1917 |
^ false. |
|
1918 |
] |
|
1919 |
]. |
|
1920 |
^ true |
|
1921 |
||
1922 |
"Created: 8.1.1997 / 21:09:14 / cg" |
|
1923 |
"Modified: 9.1.1997 / 02:10:02 / cg" |
|
1924 |
! ! |
|
1925 |
||
1926 |
!ClassBuilder class methodsFor:'documentation'! |
|
1927 |
||
1928 |
version |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1929 |
^ '$Header: /cvs/stx/stx/libbasic/ClassBuilder.st,v 1.29 2003-08-29 16:34:33 cg Exp $' |
5905 | 1930 |
! ! |