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