author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 07 Sep 2012 13:46:06 +0100 | |
branch | jv |
changeset 17965 | a8a04402986c |
parent 17942 | fcc608457255 |
child 17966 | 8b5df02e171f |
permissions | -rw-r--r-- |
7592 | 1 |
" |
2 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5905 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
Object subclass:#ClassBuilder |
|
17856
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
15 |
instanceVariableNames:'metaclass classClass className environment superClass |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
16 |
instanceVariableNames flags classVariableNames poolDictionaries |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
17 |
category comment changed classInstanceVariableNames oldMetaClass |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
18 |
oldClass oldPoolDictionaries oldSuperClass oldClassVars |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
19 |
oldInstVars realNewName buildPrivateClass buildingPrivateClass |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
20 |
nameKey newSuperClass superClassChange newClassVars newInstVars |
17862 | 21 |
newPoolDictionaries classVarChange instVarChange poolChange |
22 |
recompileGlobalAccessTo oldClassToBecomeNew oldClassInstVars |
|
23 |
newClassInstVars' |
|
17856
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
24 |
classVariableNames:'LastNamespace LastNamespaceName LastClassesInNameSpace |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
25 |
LastClassNamesInNameSpace' |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
26 |
poolDictionaries:'' |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
27 |
category:'Kernel-Support' |
5905 | 28 |
! |
29 |
||
7592 | 30 |
!ClassBuilder class methodsFor:'documentation'! |
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
35 |
All Rights Reserved |
|
36 |
||
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
44 |
! ! |
|
5905 | 45 |
|
17850 | 46 |
!ClassBuilder class methodsFor:'change & update'! |
47 |
||
48 |
initialize |
|
49 |
Smalltalk addDependent:self. |
|
50 |
||
51 |
"Created: / 18-08-2011 / 14:32:27 / cg" |
|
52 |
! |
|
53 |
||
54 |
update:something with:aParameter from:changedObject |
|
55 |
"keep track of the namespace->classnames cache" |
|
56 |
||
57 |
something == #projectOrganization ifTrue:[^ self]. |
|
58 |
something == #classVariables ifTrue:[^ self]. |
|
59 |
something == #methodInClass ifTrue:[^ self]. |
|
60 |
||
61 |
something == #newClass ifTrue:[ |
|
62 |
aParameter nameSpace name = LastNamespaceName ifTrue:[ |
|
63 |
LastClassNamesInNameSpace add:aParameter name |
|
64 |
]. |
|
65 |
^ self. |
|
66 |
]. |
|
67 |
something == #classRemove ifTrue:[ |
|
68 |
aParameter nameSpace name = LastNamespaceName ifTrue:[ |
|
17892 | 69 |
LastClassNamesInNameSpace remove:aParameter name ifAbsent:[] |
17850 | 70 |
]. |
71 |
^ self. |
|
72 |
]. |
|
73 |
||
74 |
"/ Transcript show:something. |
|
75 |
"/ Transcript show:' -> '. |
|
76 |
"/ Transcript showCR:aParameter. |
|
77 |
||
78 |
"Created: / 18-08-2011 / 14:32:16 / cg" |
|
79 |
! ! |
|
80 |
||
5905 | 81 |
!ClassBuilder class methodsFor:'checks'! |
82 |
||
5907 | 83 |
checkForAliasesOf:oldClass with:newClass |
84 |
"oldClass changed its identity (now use newClass). |
|
85 |
check if there are any global aliases, which should also be changed" |
|
86 |
||
87 |
Smalltalk keysAndValuesDo:[:nm :o | |
|
88 |
o == oldClass ifTrue:[ |
|
89 |
nm ~~ oldClass name ifTrue:[ |
|
17907 | 90 |
true "/ (self confirm:('The global/classVar `' , nm , ''' is an alias for ' , oldClass name , '.\\Change it to the new class ?') withCRs) |
5907 | 91 |
ifTrue:[ |
92 |
Smalltalk at:nm put:newClass |
|
93 |
] |
|
94 |
] |
|
95 |
] |
|
96 |
]. |
|
17907 | 97 |
|
98 |
"Modified: / 20-12-2011 / 12:22:42 / cg" |
|
5907 | 99 |
! |
100 |
||
5905 | 101 |
differentInstanceVariableOffsetsIn:class1 and:class2 |
102 |
"return a set of instance variable names which have different |
|
103 |
positions in class1 and class2. |
|
104 |
Also, variables which are only present in one class are returned. |
|
105 |
This is used to find methods which need recompilation after a |
|
106 |
change in the instance variable layout." |
|
107 |
||
108 |
|offsets1 offsets2 changeSet| |
|
109 |
||
110 |
changeSet := Set new. |
|
111 |
||
112 |
" |
|
113 |
collect the instvar-indices in the old and new class |
|
114 |
" |
|
115 |
offsets1 := class1 instanceVariableOffsets. |
|
116 |
offsets2 := class2 instanceVariableOffsets. |
|
117 |
||
118 |
" |
|
119 |
compute the changeset as a set of instance variables, |
|
120 |
which have a different position |
|
121 |
" |
|
122 |
offsets1 keysAndValuesDo:[:varName :varIndex | |
|
123 |
(offsets2 includesKey:varName) ifFalse:[ |
|
124 |
changeSet add:varName |
|
125 |
] ifTrue:[ |
|
126 |
(varIndex ~~ (offsets2 at:varName)) ifTrue:[ |
|
127 |
changeSet add:varName |
|
128 |
] |
|
129 |
] |
|
130 |
]. |
|
131 |
offsets2 keysAndValuesDo:[:varName :varIndex | |
|
132 |
(offsets1 includesKey:varName) ifFalse:[ |
|
133 |
changeSet add:varName |
|
134 |
] ifTrue:[ |
|
135 |
(varIndex ~~ (offsets1 at:varName)) ifTrue:[ |
|
136 |
changeSet add:varName |
|
137 |
] |
|
138 |
] |
|
139 |
]. |
|
140 |
^ changeSet |
|
141 |
||
142 |
" |
|
143 |
View class |
|
144 |
differentInstanceVariableOffsetsIn:View |
|
145 |
and:StandardSystemView |
|
146 |
View class |
|
147 |
differentInstanceVariableOffsetsIn:Object |
|
148 |
and:Point |
|
149 |
" |
|
150 |
! ! |
|
151 |
||
152 |
!ClassBuilder class methodsFor:'recompiling'! |
|
153 |
||
6024 | 154 |
copyInvalidatedMethodsFrom:oldClass for:newClass |
155 |
"copy all methods from oldClass to newClass and change their code |
|
156 |
to a trap method reporting an error. |
|
157 |
This is done when a class has changed its layout or inheritance, |
|
158 |
before recompilation is attempted. |
|
159 |
This allows us to keep the source while trapping uncompilable (due to |
|
160 |
now undefined instvars) methods. Later compilation of these methods will show |
|
161 |
an error on the transcript and lead to the debugger once called." |
|
162 |
||
163 |
|trap trapCode trapByteCode oldMethod newMethod |
|
164 |
oldDict newDict| |
|
165 |
||
166 |
oldDict := oldClass methodDictionary. |
|
167 |
newDict := MethodDictionary new:oldDict size. |
|
168 |
||
169 |
oldDict keysAndValuesDo:[ :sel :mthd | |
|
170 |
trap := mthd trapMethodForNumArgs:(mthd numArgs). |
|
171 |
trapCode := trap code. |
|
172 |
trapByteCode := trap byteCode. |
|
173 |
||
17807 | 174 |
oldMethod := mthd originalMethodIfWrapped. |
6024 | 175 |
|
176 |
newMethod := oldMethod copy. |
|
177 |
newMethod makeInvalid. |
|
178 |
newDict at:sel put:newMethod |
|
179 |
]. |
|
180 |
||
181 |
newClass methodDictionary:newDict. |
|
182 |
||
17807 | 183 |
"Modified: / 12-06-1996 / 10:44:27 / stefan" |
184 |
"Modified: / 22-10-2010 / 11:47:27 / cg" |
|
6024 | 185 |
! |
186 |
||
5905 | 187 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames |
188 |
"copy all methods from oldClass to newClass. Those methods accessing |
|
189 |
a variable in setOfNames will be copied as invalid method, leading to |
|
190 |
a trap when its executed. This is used when a class has changed its |
|
191 |
layout for all methods which are affected by the change." |
|
192 |
||
17795 | 193 |
self |
194 |
copyInvalidatedMethodsFrom:oldClass |
|
195 |
for:newClass |
|
196 |
accessingAny:setOfNames |
|
197 |
orSuper:false |
|
198 |
||
199 |
"Modified: / 02-08-2010 / 16:40:30 / cg" |
|
5905 | 200 |
! |
201 |
||
202 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames orSuper:superBoolean |
|
203 |
"copy all methods from oldClass to newClass. |
|
204 |
Those methods accessing a variable in setOfNames will be copied as invalid method, |
|
205 |
leading to a trap when its executed. If superBoolean is true, this is also done |
|
206 |
for methods accessing super. This is used when a class has changed its |
|
207 |
layout for all methods which are affected by the change." |
|
208 |
||
209 |
|p source mustInvalidate |
|
210 |
oldMethod newMethod methodDict newMethodDict nNames| |
|
211 |
||
212 |
methodDict := oldClass methodDictionary. |
|
213 |
newMethodDict := methodDict copy. |
|
214 |
nNames := setOfNames size. |
|
215 |
||
216 |
methodDict keysAndValuesDo:[:selector :method | |
|
17807 | 217 |
oldMethod := method originalMethodIfWrapped. |
5905 | 218 |
|
219 |
"before parsing (which may take some time), |
|
220 |
do a string search if its only one variable, |
|
221 |
we are looking for. |
|
222 |
Could look for more than one variable by string compare, but then |
|
223 |
parsing it right away may be faster ..." |
|
224 |
||
225 |
source := oldMethod source. |
|
226 |
((nNames == 1) and:[superBoolean not]) ifTrue:[ |
|
227 |
mustInvalidate := (source findString:(setOfNames first)) ~~ 0. |
|
228 |
] ifFalse:[ |
|
229 |
((nNames == 0) and:[superBoolean]) ifTrue:[ |
|
230 |
mustInvalidate := (source findString:'super') ~~ 0. |
|
231 |
] ifFalse:[ |
|
232 |
mustInvalidate := true |
|
233 |
]. |
|
234 |
]. |
|
235 |
||
236 |
mustInvalidate ifTrue:[ |
|
237 |
"we have to parse it ..." |
|
17729
4187f74d2df8
- small improvements in multi-language support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
238 |
p := newClass parserClass parseMethod:source in:newClass. |
5905 | 239 |
(p isNil |
240 |
or:[(p usedVars includesAny:setOfNames) |
|
241 |
or:[superBoolean and:[p usesSuper]]]) ifFalse:[ |
|
242 |
mustInvalidate := false |
|
243 |
] |
|
244 |
]. |
|
245 |
||
246 |
mustInvalidate ifTrue:[ |
|
247 |
newMethod := oldMethod copy. |
|
248 |
"/ Smalltalk silentLoading ifFalse:[ |
|
249 |
"/ Transcript showCR:'invalidating ' , selector , '...'. |
|
250 |
"/ ]. |
|
251 |
newMethod makeInvalid. |
|
252 |
] ifFalse:[ |
|
253 |
newMethod := oldMethod. |
|
254 |
newMethod mclass:nil. |
|
255 |
]. |
|
256 |
newMethodDict at:selector put:newMethod |
|
257 |
]. |
|
258 |
newClass methodDictionary:newMethodDict. |
|
259 |
||
17729
4187f74d2df8
- small improvements in multi-language support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
260 |
"Modified: / 07-06-1996 / 08:33:52 / stefan" |
4187f74d2df8
- small improvements in multi-language support
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17728
diff
changeset
|
261 |
"Modified: / 21-08-2009 / 10:14:49 / Jan Vrany <vranyj1@fel.cvut.cz>" |
17807 | 262 |
"Modified: / 22-10-2010 / 11:47:39 / cg" |
5905 | 263 |
! |
264 |
||
265 |
copyMethodsFrom:oldClass for:newClass |
|
266 |
"copy all methods from oldClass to newClass. |
|
267 |
This is used for class-methods when a class has changed, but its metaclass is |
|
268 |
unaffected (i.e. classVars/inheritance have not changed) so there is no need |
|
269 |
to recompile the class methods." |
|
270 |
||
271 |
newClass methodDictionary:(oldClass methodDictionary copy). |
|
8467 | 272 |
newClass methodDictionary do:[:mthd | mthd mclass:nil.]. |
5905 | 273 |
|
8467 | 274 |
"Modified: / 05-08-2004 / 19:52:28 / stefan" |
5905 | 275 |
! |
276 |
||
277 |
recompileGlobalAccessorsTo:aGlobalKey in:aNamespace except:someClass |
|
278 |
"when a new class enters a namespace, all accessors to the same-named |
|
17850 | 279 |
class in that namespace must be recompiled. |
280 |
Because that is used heavily during package loading (for the same namespace), cache it." |
|
281 |
||
282 |
|privateClassNames| |
|
5905 | 283 |
|
17850 | 284 |
aNamespace name = LastNamespaceName ifTrue:[ |
285 |
privateClassNames := LastClassNamesInNameSpace |
|
286 |
] ifFalse:[ |
|
17859 | 287 |
privateClassNames := aNamespace allPrivateClasses |
288 |
reject:[:cls | cls isJavaClass or:[cls isNameSpace] ] |
|
289 |
thenCollect:[:each | each name]. |
|
17850 | 290 |
LastNamespaceName := aNamespace name. |
17859 | 291 |
LastClassNamesInNameSpace := privateClassNames asOrderedCollection. |
17850 | 292 |
]. |
293 |
||
294 |
privateClassNames do:[:eachClassName | |
|
295 |
|cls| |
|
296 |
||
297 |
cls := Smalltalk classNamed:eachClassName. |
|
298 |
(cls notNil and:[cls ~~ someClass]) ifTrue:[ |
|
299 |
cls isLoaded ifTrue:[ |
|
5905 | 300 |
|
301 |
"/ Smalltalk silentLoading ifFalse:[ |
|
302 |
"/ Transcript showCR:'recompiling methods in ''' , aClass name , ''' accessing ''' , aGlobalKey , ''''. |
|
303 |
"/ Transcript endEntry. |
|
304 |
"/ ]. |
|
305 |
||
17850 | 306 |
cls recompileMethodsAccessingGlobal:aGlobalKey. |
307 |
cls class recompileMethodsAccessingGlobal:aGlobalKey. |
|
5905 | 308 |
"/ actually - must eventually recompile USERS of this namespace too |
309 |
] |
|
310 |
] |
|
6408
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
311 |
]. |
17850 | 312 |
|
6414 | 313 |
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
|
314 |
aNamespace recompileMethodsAccessingGlobal:aGlobalKey. |
32ed2e990c09
fixed recompilation of accessors when a private class shadows a global
Claus Gittinger <cg@exept.de>
parents:
6385
diff
changeset
|
315 |
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
|
316 |
]. |
5905 | 317 |
|
17859 | 318 |
"Modified: / 24-08-2011 / 13:32:22 / cg" |
17856
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
319 |
"Modified: / 01-09-2011 / 11:58:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5905 | 320 |
! |
321 |
||
322 |
recompileMachineCodeMethodsIn:aClass |
|
323 |
"recompile all machine-code methods in aClass." |
|
324 |
||
325 |
aClass recompileMethodsWithMachineCode. |
|
326 |
aClass class recompileMethodsWithMachineCode. |
|
327 |
! ! |
|
328 |
||
17859 | 329 |
!ClassBuilder methodsFor:'Compatibility-Squeak'! |
330 |
||
331 |
name:newName |
|
332 |
inEnvironment:aSystemDictionaryOrClass |
|
333 |
subclassOf:aClass |
|
334 |
type: type |
|
335 |
instanceVariableNames: stringOfInstVarNames |
|
336 |
classVariableNames: stringOfClassVarNames |
|
337 |
poolDictionaries: stringOfPoolNames |
|
338 |
category: categoryString |
|
339 |
||
340 |
"this returns the created class; it is not a simple accessor" |
|
341 |
||
342 |
|variableBoolean wordsBoolean pointersBoolean| |
|
343 |
||
344 |
variableBoolean := wordsBoolean := pointersBoolean := false. |
|
345 |
type ~~ #normal ifTrue:[ |
|
346 |
type == #words ifTrue:[ |
|
347 |
wordsBoolean := true |
|
348 |
] ifFalse:[ |
|
349 |
self halt:'todo'. |
|
350 |
] |
|
351 |
]. |
|
352 |
||
353 |
self |
|
354 |
name:newName |
|
355 |
inEnvironment:aSystemDictionaryOrClass |
|
356 |
subclassOf:aClass |
|
357 |
instanceVariableNames:stringOfInstVarNames |
|
358 |
variable:variableBoolean |
|
359 |
words:wordsBoolean |
|
360 |
pointers:pointersBoolean |
|
361 |
classVariableNames:stringOfClassVarNames |
|
362 |
poolDictionaries:stringOfPoolNames |
|
363 |
category:categoryString |
|
364 |
comment:'' |
|
365 |
changed:false |
|
366 |
classInstanceVariableNames:''. |
|
367 |
||
368 |
^ self buildClass |
|
369 |
||
370 |
"Modified: / 07-09-2011 / 15:21:09 / cg" |
|
371 |
! ! |
|
372 |
||
5905 | 373 |
!ClassBuilder methodsFor:'accessing'! |
374 |
||
8724 | 375 |
classClass |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
376 |
^ classClass ? Class |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
377 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
378 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
379 |
classClass:aClass |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
380 |
classClass := aClass. |
8724 | 381 |
! |
382 |
||
7617 | 383 |
metaclass:metaclassOrASubclassOfIt |
384 |
metaclass := metaclassOrASubclassOfIt. |
|
385 |
! |
|
386 |
||
17815 | 387 |
name:newName inEnvironment:aSystemDictionaryOrClass subclassOf:aClass |
388 |
instanceVariableNames:stringOfInstVarNames |
|
389 |
variable:variableBoolean |
|
390 |
words:wordsBoolean pointers:pointersBoolean |
|
391 |
classVariableNames:stringOfClassVarNames |
|
392 |
poolDictionaries:stringOfPoolNames |
|
393 |
category:categoryString |
|
394 |
comment:commentString |
|
395 |
changed:changedBoolean |
|
396 |
classInstanceVariableNames:stringOfClassInstVarNamesOrNil |
|
397 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
398 |
className := newName asSymbol. |
5905 | 399 |
environment := aSystemDictionaryOrClass. |
400 |
superClass := aClass. |
|
401 |
instanceVariableNames := stringOfInstVarNames. |
|
10602 | 402 |
|
403 |
"/ Allowing non-booleans as variableBoolean |
|
404 |
"/ is a hack for backward (ST-80) compatibility: |
|
405 |
"/ ST-80 code will pass true or false as variableBoolean, |
|
406 |
"/ while ST/X also calls it with symbols such as #float, #double etc. |
|
407 |
||
408 |
flags := self flagsForVariable:variableBoolean pointers:pointersBoolean words:wordsBoolean. |
|
409 |
||
5905 | 410 |
classVariableNames := stringOfClassVarNames. |
411 |
poolDictionaries := stringOfPoolNames. |
|
412 |
category := categoryString. |
|
413 |
comment := commentString. |
|
414 |
changed := changedBoolean. |
|
415 |
classInstanceVariableNames := stringOfClassInstVarNamesOrNil |
|
10602 | 416 |
|
17815 | 417 |
"Modified: / 30-01-2011 / 10:07:36 / cg" |
5907 | 418 |
! |
419 |
||
420 |
oldMetaclass:aMetaclass instanceVariableNames:stringOfInstVarNames |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
421 |
|instrVarNames| |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
422 |
|
5907 | 423 |
oldMetaClass := aMetaclass. |
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
424 |
instrVarNames := oldMetaClass superclass allInstanceVariableNames asBag. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
425 |
instrVarNames addAll:(stringOfInstVarNames asStringCollection). |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
426 |
(instrVarNames contents includesValue:2) ifTrue:[ |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
427 |
self error:'duplicate variable name'. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
428 |
]. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
429 |
|
5907 | 430 |
instanceVariableNames := stringOfInstVarNames. |
5905 | 431 |
! ! |
432 |
||
433 |
!ClassBuilder methodsFor:'building'! |
|
434 |
||
435 |
buildClass |
|
436 |
"this is the main workhorse for installing new classes - special care |
|
437 |
has to be taken, when changing an existing classes definition. In this |
|
438 |
case, some or all of the methods and subclasses methods have to be |
|
439 |
recompiled. |
|
440 |
Also, the old class(es) are still kept (but not accessable as a global), |
|
441 |
to allow existing instances some life. |
|
10130
e16908ae50a8
Do not change existing class filenames when filing in a class (e.g. from CVS)
Stefan Vogel <sv@exept.de>
parents:
10112
diff
changeset
|
442 |
This might change in the future." |
5905 | 443 |
|
10003
a9aff80f9541
Set classes source container name on fileIn
Stefan Vogel <sv@exept.de>
parents:
9802
diff
changeset
|
444 |
|newClass newMetaclass newComment sourceContainer| |
5905 | 445 |
|
446 |
"NOTICE: |
|
447 |
this method is too complex and should be splitted into managable pieces ... |
|
448 |
I dont like it anymore :-) |
|
449 |
(well, at least, its a good test for the compilers ability |
|
450 |
to handle big, complex methods ;-) |
|
451 |
take it as an example of bad coding style ... |
|
452 |
||
453 |
ST-80 uses a ClassBuilder object to collect the work and perform all updates; |
|
454 |
this method may be changed to do something similar in the future ... |
|
455 |
" |
|
456 |
||
9270
9600acaa300c
no name checking, if class is not going to be installed into
Claus Gittinger <cg@exept.de>
parents:
9238
diff
changeset
|
457 |
environment notNil ifTrue:[ self checkClassName ]. |
5905 | 458 |
self checkValidSubclassing. |
459 |
||
7230
82934cb163d4
autoload is understood by all classes (dummy if already loaded)
Claus Gittinger <cg@exept.de>
parents:
7201
diff
changeset
|
460 |
environment notNil ifTrue:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
461 |
environment autoload "/ owner must be loaded |
5905 | 462 |
]. |
463 |
||
8764
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
464 |
instanceVariableNames notNil ifTrue:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
465 |
instanceVariableNames isString ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
466 |
instanceVariableNames := instanceVariableNames asStringWith:Character space |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
467 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
468 |
] ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
469 |
instanceVariableNames := '' |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
470 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
471 |
classVariableNames notNil ifTrue:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
472 |
classVariableNames isString ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
473 |
classVariableNames := classVariableNames asStringWith:Character space |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
474 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
475 |
] ifFalse:[ |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
476 |
classVariableNames := '' |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
477 |
]. |
1fe531dc199b
allow nil instance/class VariableNames
Claus Gittinger <cg@exept.de>
parents:
8743
diff
changeset
|
478 |
|
10602 | 479 |
buildingPrivateClass := false. |
9270
9600acaa300c
no name checking, if class is not going to be installed into
Claus Gittinger <cg@exept.de>
parents:
9238
diff
changeset
|
480 |
environment notNil ifTrue:[ |
10602 | 481 |
self determineNewName ifFalse:[ |
9270
9600acaa300c
no name checking, if class is not going to be installed into
Claus Gittinger <cg@exept.de>
parents:
9238
diff
changeset
|
482 |
^ nil. |
9600acaa300c
no name checking, if class is not going to be installed into
Claus Gittinger <cg@exept.de>
parents:
9238
diff
changeset
|
483 |
]. |
5905 | 484 |
]. |
485 |
||
486 |
(superClass notNil and:[realNewName = superClass name]) ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
487 |
ClassBuildError raiseErrorString:'trying to create circular class definition'. |
5905 | 488 |
^ nil |
489 |
]. |
|
490 |
||
491 |
"look, if it already exists as a class" |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
492 |
environment notNil ifTrue:[ |
10724
9e47c9f24655
oops: autoLoad vs. autoload
Claus Gittinger <cg@exept.de>
parents:
10602
diff
changeset
|
493 |
environment isLoaded ifFalse:[ environment autoload ]. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
494 |
buildingPrivateClass ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
495 |
oldClass := environment at:className ifAbsent:[nil]. |
5905 | 496 |
] ifTrue:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
497 |
oldClass := environment privateClassesAt:className. |
5905 | 498 |
] |
499 |
]. |
|
500 |
||
17735 | 501 |
(instanceVariableNames size > 0 |
502 |
or:[classVariableNames size > 0]) ifTrue:[ |
|
503 |
(self |
|
504 |
checkValidVarNamesFor:className |
|
505 |
subClassOf:superClass |
|
506 |
instVarNames:instanceVariableNames |
|
507 |
classVarNames:classVariableNames) |
|
508 |
ifFalse:[ |
|
509 |
^ nil |
|
510 |
]. |
|
511 |
]. |
|
512 |
||
9676 | 513 |
oldClass notNil ifTrue:[ |
10174 | 514 |
(oldClass isRealNameSpace) ifTrue:[ |
17850 | 515 |
(superClass == NameSpace or:[superClass isNameSpace]) ifFalse:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
516 |
ClassBuildError raiseErrorString:'class exists as namespace'. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
517 |
^ nil. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
518 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
519 |
^ oldClass |
9676 | 520 |
]. |
6713
6f197bcc0958
catch class exists as nameSpace
Claus Gittinger <cg@exept.de>
parents:
6514
diff
changeset
|
521 |
|
9676 | 522 |
(oldClass isBehavior and:[oldClass isLoaded not]) ifTrue:[ |
523 |
oldClassToBecomeNew := oldClass |
|
524 |
]. |
|
5905 | 525 |
]. |
526 |
||
9528 | 527 |
(oldClass notNil and:[oldClass isBehavior and:[oldClass isLoaded]]) ifFalse:[ |
5905 | 528 |
oldClass := nil. |
529 |
||
9098 | 530 |
(buildingPrivateClass and:[ParserFlags warnings and:[ParserFlags warnSTXSpecials]]) ifTrue:[ |
531 |
(self confirm:('Support for private classes is an ST/X extension.\\continue ?') withCRs) |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
532 |
ifFalse:[^ nil]. |
5905 | 533 |
]. |
534 |
] ifTrue:[ |
|
535 |
oldClass name ~= realNewName ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
536 |
(self confirm:(className , ' is an alias for ' , oldClass name , '\\continue ?') withCRs) |
5905 | 537 |
ifFalse:[^ nil]. |
538 |
oldClass := nil |
|
539 |
] ifFalse:[ |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
540 |
(self checkForCircularDefinitionFrom:oldClass) ifTrue:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
541 |
ClassBuildError raiseErrorString:'trying to create circular class definition'. |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
542 |
^ nil |
5905 | 543 |
]. |
544 |
||
545 |
" |
|
546 |
warn, if it exists with different category and different instvars, |
|
547 |
and the existing is not an autoload class. |
|
548 |
Usually, this indicates that someone wants to create a new class with |
|
549 |
a name, which already exists (it happened a few times to myself, while |
|
550 |
I wanted to create a new class called ReturnNode ...). |
|
551 |
This will be much less of a problem, once multiple name spaces are |
|
552 |
implemented and classes can be put into separate packages. |
|
553 |
" |
|
554 |
oldClass isLoaded ifTrue:[ |
|
555 |
oldClass category ~= category ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
556 |
oldClass instanceVariableString asCollectionOfWords ~= instanceVariableNames asCollectionOfWords ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
557 |
(self confirm:'a class named ' , oldClass name , ' already exists -\\create (i.e. change) anyway ?' withCRs) |
5905 | 558 |
ifFalse:[ |
559 |
^ nil |
|
560 |
] |
|
561 |
] |
|
562 |
] |
|
563 |
]. |
|
564 |
||
565 |
"/ |
|
566 |
"/ hints - warn, if creating a variableSubclass of a Set |
|
567 |
"/ (common error - containers in ST/X do not use variable-slots) |
|
568 |
"/ |
|
10602 | 569 |
|
570 |
(flags bitAnd:Behavior maskIndexType) == (Behavior flagForSymbolic:#objects) |
|
571 |
"((variable == true) and:[pointers])" ifTrue:[ |
|
5905 | 572 |
(oldClass isKindOf:Set class) ifTrue:[ |
8743
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
573 |
(self confirm:('ST/X Set & Dictionary are not variable-classes.\Create %1 anyway ?' bindWith:className) withCRs) |
5905 | 574 |
ifFalse:[ |
575 |
^ nil |
|
576 |
] |
|
577 |
] |
|
578 |
] |
|
579 |
] |
|
580 |
]. |
|
581 |
||
582 |
"/ Check for some 'considered bad-style' things, like lower case names. |
|
583 |
"/ But only do these checks for new classes - |
|
584 |
"/ - thus, once confirmed, the warnings will not come again and again. |
|
585 |
||
586 |
"/ NOTICE: |
|
587 |
"/ I dont like the confirmers there - we need a notifying: argument, to give |
|
588 |
"/ the outer codeview a chance to highlight the error. |
|
589 |
"/ (but thats how its defined in the book - maybe I will change anyway). |
|
590 |
"/ - or use upQueries in future versions. |
|
591 |
||
592 |
oldClass isNil ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
593 |
(instanceVariableNames size > 0 or:[classVariableNames size > 0]) ifTrue:[ |
5905 | 594 |
(self |
595 |
checkConventionsFor:className |
|
596 |
subClassOf:superClass |
|
597 |
instVarNames:instanceVariableNames |
|
598 |
classVarNames:classVariableNames) |
|
599 |
ifFalse:[ |
|
600 |
^ nil |
|
601 |
] |
|
602 |
]. |
|
7132 | 603 |
]. |
5905 | 604 |
|
7132 | 605 |
(self |
606 |
checkInstvarRedefsWith:instanceVariableNames |
|
607 |
subclassOf:superClass |
|
608 |
old:oldClass |
|
609 |
name:className) ifFalse:[^ nil]. |
|
5905 | 610 |
|
8610 | 611 |
self checkValidPools. |
612 |
||
6514 | 613 |
newMetaclass := self instantiateMetaclass. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
614 |
newClass := self instantiateNewClassFrom:newMetaclass. |
5905 | 615 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
616 |
(environment notNil and:[environment ~~ Smalltalk]) ifTrue:[ |
5905 | 617 |
newClass setName:realNewName. |
618 |
"/ |
|
619 |
"/ if that key exists in smalltalk, |
|
620 |
"/ must recompile everything in that nameSpace, |
|
621 |
"/ which refers to the unprefixed global. |
|
622 |
"/ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
623 |
recompileGlobalAccessTo := className. |
5905 | 624 |
] ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
625 |
newClass setName:className. |
5905 | 626 |
recompileGlobalAccessTo := nil. |
627 |
]. |
|
628 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
629 |
newComment := comment. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
630 |
newComment isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
631 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
632 |
newComment := oldClass comment |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
633 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
634 |
]. |
5905 | 635 |
newClass setComment:newComment category:category. |
8610 | 636 |
poolDictionaries notEmptyOrNil ifTrue:[ |
637 |
newClass sharedPools:poolDictionaries |
|
638 |
]. |
|
5905 | 639 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
640 |
"/ for new classes, we are almost done here |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
641 |
"/ (also for autoloaded classes) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
642 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
643 |
(oldClass isNil or:[oldClass isLoaded not]) ifTrue:[ |
10148
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
644 |
"/ do not set the classFileName here, because we do not know here, |
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
645 |
"/ if this is a normal fileIn, or a fileIn from a temporary file. |
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
646 |
"/ it MUST be done by the fileInClass:lazy:... method in Smalltalk or whereever. |
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
647 |
"/ sourceContainer := PeekableStream currentSourceContainer. |
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
648 |
"/ sourceContainer isFileStream ifTrue:[ |
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
649 |
"/ newClass setClassFilename:sourceContainer pathName asFilename baseName. |
4008d7b4a364
do NOT set the classFileName here - MUST be done somewhere else
Claus Gittinger <cg@exept.de>
parents:
10130
diff
changeset
|
650 |
"/ ]. |
17735 | 651 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
652 |
self handleNewlyCreatedClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
653 |
^ newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
654 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
655 |
|
10130
e16908ae50a8
Do not change existing class filenames when filing in a class (e.g. from CVS)
Stefan Vogel <sv@exept.de>
parents:
10112
diff
changeset
|
656 |
newClass setClassFilename:oldClass getClassFilename. |
e16908ae50a8
Do not change existing class filenames when filing in a class (e.g. from CVS)
Stefan Vogel <sv@exept.de>
parents:
10112
diff
changeset
|
657 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
658 |
"/ here comes the hard part - we are actually changing the |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
659 |
"/ definition of an existing class .... |
8610 | 660 |
"/ Try hard to get away WITHOUT recompiling, since it is both slow |
661 |
"/ and it makes all compiled code into interpreted (which is reJITed then)... |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
662 |
oldInstVars := oldClass instanceVariableString asCollectionOfWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
663 |
newInstVars := newClass instanceVariableString asCollectionOfWords. |
11414 | 664 |
oldClassInstVars := oldClass class instanceVariableString asCollectionOfWords. |
665 |
newClassInstVars := newClass class instanceVariableString asCollectionOfWords. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
666 |
oldClassVars := oldClass classVariableString asCollectionOfWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
667 |
newClassVars := newClass classVariableString asCollectionOfWords. |
17862 | 668 |
oldPoolDictionaries := oldClass sharedPoolNames. |
669 |
newPoolDictionaries := newClass sharedPoolNames. |
|
670 |
poolChange := (oldPoolDictionaries ~= newPoolDictionaries). |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
671 |
|
8610 | 672 |
"/ We are on the bright side of life, if the instance layout and inheritance do not change. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
673 |
"/ In this case, we can go ahead and patch the class object. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
674 |
"/ (only comment and/or classVars have changed) |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
675 |
oldSuperClass := oldClass superclass. |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
676 |
newSuperClass := newClass superclass. |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
677 |
superClassChange := (oldSuperClass ~~ newSuperClass). |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
678 |
|
17763 | 679 |
Class flushSubclassInfoFor:oldSuperClass. |
680 |
Class flushSubclassInfoFor:newSuperClass. |
|
681 |
||
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
682 |
superClassChange ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
683 |
(oldClass instSize == newClass instSize) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
684 |
(oldClass flags == newClass flags) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
685 |
(oldClass name = newClass name) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
686 |
(oldInstVars = newInstVars) ifTrue:[ |
11414 | 687 |
(oldClassInstVars = newClassInstVars) ifTrue:[ |
17862 | 688 |
poolChange ifFalse:[ |
11414 | 689 |
self handleEasyNewClass:newClass. |
690 |
^ oldClass |
|
691 |
] |
|
9114 | 692 |
] |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
693 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
694 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
695 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
696 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
697 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
698 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
699 |
self handleHardNewClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
700 |
^ newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
701 |
|
9528 | 702 |
"Created: / 26-05-1996 / 11:55:26 / cg" |
703 |
"Modified: / 18-03-1999 / 18:23:31 / stefan" |
|
17862 | 704 |
"Modified: / 15-09-2011 / 13:47:56 / cg" |
10602 | 705 |
! |
706 |
||
707 |
newSubclassOf:baseClass type:typeOfClass instanceVariables:instanceVariables from:oldClassArg |
|
708 |
"anonymous classes can be built with this entry" |
|
709 |
||
710 |
superClass := baseClass. |
|
711 |
flags := Behavior flagForSymbolic:typeOfClass. |
|
712 |
instanceVariableNames := instanceVariables. |
|
713 |
oldClass := oldClassArg. |
|
714 |
^ self buildClass. |
|
715 |
||
716 |
"Created: / 07-06-2007 / 12:04:47 / cg" |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
717 |
! ! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
718 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
719 |
!ClassBuilder methodsFor:'building-helpers'! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
720 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
721 |
changeReferencesFrom:oldClass to:newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
722 |
| refs| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
723 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
724 |
refs := OrderedCollection new. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
725 |
ObjectMemory allObjectsDo:[:obj | |
9563
9a35c86805a1
code cleanup - remove old obsolete Project code
Claus Gittinger <cg@exept.de>
parents:
9528
diff
changeset
|
726 |
Exception handle:[:ex | |
9a35c86805a1
code cleanup - remove old obsolete Project code
Claus Gittinger <cg@exept.de>
parents:
9528
diff
changeset
|
727 |
] do:[ |
17736 | 728 |
((obj class isSubclassOf:Object) and:[obj isLazyValue not]) ifTrue:[ |
17735 | 729 |
(obj referencesObject:oldClass) ifTrue:[ |
730 |
obj isContext ifFalse:[ |
|
731 |
refs add:obj |
|
732 |
]. |
|
9563
9a35c86805a1
code cleanup - remove old obsolete Project code
Claus Gittinger <cg@exept.de>
parents:
9528
diff
changeset
|
733 |
]. |
17735 | 734 |
] |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
735 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
736 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
737 |
refs isEmpty ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
738 |
^ self |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
739 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
740 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
741 |
"/ answer := OptionBox |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
742 |
"/ request:('Update References (from old class to new class) ?') withCRs |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
743 |
"/ label:'Confirm' |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
744 |
"/ buttonLabels:#('no' 'browse references' 'update') |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
745 |
"/ values:#(false #browse true) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
746 |
"/ default:#true |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
747 |
"/ onCancel:false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
748 |
"/ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
749 |
"/ answer == #browse ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
750 |
"/ refs inspect. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
751 |
"/ answer := self confirm:('Update References (from old class to new class) ?') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
752 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
753 |
"/ answer == false ifTrue:[^ self]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
754 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
755 |
refs do:[:obj | |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
756 |
|skip| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
757 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
758 |
skip := false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
759 |
obj isBehavior ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
760 |
skip := true. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
761 |
obj isObsolete ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
762 |
obj isMeta ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
763 |
"/ the owner-slot ? |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
764 |
obj owningClass == oldClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
765 |
"/ self halt. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
766 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
767 |
obj theNonMetaclass == oldClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
768 |
"/ self halt. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
769 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
770 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
771 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
772 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
773 |
skip ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
774 |
obj replaceReferencesTo:oldClass with:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
775 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
776 |
]. |
9563
9a35c86805a1
code cleanup - remove old obsolete Project code
Claus Gittinger <cg@exept.de>
parents:
9528
diff
changeset
|
777 |
|
9a35c86805a1
code cleanup - remove old obsolete Project code
Claus Gittinger <cg@exept.de>
parents:
9528
diff
changeset
|
778 |
"Modified: / 17-08-2006 / 12:48:22 / cg" |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
779 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
780 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
781 |
copyClassInstanceVariablesFrom:oldClass to:newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
782 |
|oldCIVNames newCIVNames| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
783 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
784 |
"/ copy over classInstanceVariables |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
785 |
"/ but not those inherited from class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
786 |
|
5905 | 787 |
oldClass notNil ifTrue:[ |
788 |
oldCIVNames := oldClass class allInstVarNames asSet. |
|
789 |
newCIVNames := newClass class allInstVarNames asSet. |
|
790 |
Class class allInstVarNames do:[:n | |
|
791 |
oldCIVNames remove:n ifAbsent:nil. |
|
792 |
newCIVNames remove:n ifAbsent:nil. |
|
793 |
]. |
|
794 |
||
795 |
newCIVNames size > 0 ifTrue:[ |
|
796 |
newCIVNames do:[:n | |
|
797 |
(oldCIVNames includes:n) ifTrue:[ |
|
798 |
newClass instVarNamed:n put:(oldClass instVarNamed:n) |
|
799 |
] |
|
800 |
] |
|
801 |
]. |
|
802 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
803 |
! |
5905 | 804 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
805 |
determineNewName |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
806 |
|doCreate namespace classSymbol idx nsName| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
807 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
808 |
classSymbol := className asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
809 |
namespace := environment. |
5905 | 810 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
811 |
(namespace notNil |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
812 |
and:[namespace isNameSpace not]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
813 |
buildingPrivateClass := true. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
814 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
815 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
816 |
buildingPrivateClass := false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
817 |
realNewName := classSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
818 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
819 |
"/ does the name imply a nameSpace ? |
9528 | 820 |
idx := realNewName indexOf:$: . |
821 |
(idx > 1 and:[ (realNewName at:(idx+1)) == $: ]) ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
822 |
"/ check for this namespace to exist |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
823 |
nsName := realNewName copyTo:(idx - 1). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
824 |
nsName := nsName asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
825 |
(realNewName indexOf:$: startingAt:(idx+2)) ~~ 0 ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
826 |
(Smalltalk at:nsName) isNameSpace ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
827 |
self warn:('Nested namespaces are not (yet) implemented.') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
828 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
829 |
self warn:('Trying to define a private class with a non-private definition selector.') withCRs. |
5905 | 830 |
]. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
831 |
^ false |
5905 | 832 |
]. |
833 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
834 |
namespace := Smalltalk at:nsName ifAbsent:nil. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
835 |
namespace isNameSpace ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
836 |
namespace isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
837 |
doCreate := Class createNameSpaceQuerySignal query. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
838 |
doCreate ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
839 |
doCreate := Dialog |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
840 |
confirmWithCancel:('Nonexistent Namespace: `' , nsName , '''.\\Create ?') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
841 |
doCreate isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
842 |
"/ cancelled |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
843 |
AbortSignal raise. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
844 |
^ false. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
845 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
846 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
847 |
doCreate ifFalse:[^ false]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
848 |
namespace := NameSpace name:nsName. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
849 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
850 |
(namespace isBehavior |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
851 |
and:[namespace isMeta not]) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
852 |
ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
853 |
buildingPrivateClass := true. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
854 |
realNewName := classSymbol asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
855 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
856 |
self warn:('A global named ' , nsName , ' exists, but is no namespace.') withCRs. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
857 |
^ false |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
858 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
859 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
860 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
861 |
namespace isNameSpace ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
862 |
nameKey := (classSymbol copyFrom:(nsName size + 3)) asSymbol. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
863 |
] |
5905 | 864 |
] ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
865 |
(namespace notNil and:[namespace ~~ Smalltalk]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
866 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
5905 | 867 |
] |
868 |
] |
|
869 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
870 |
^ true |
9528 | 871 |
|
872 |
"Modified: / 11-08-2006 / 12:49:46 / cg" |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
873 |
! |
5905 | 874 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
875 |
environmentChanged:how with:argument |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
876 |
environment changed:how with:argument. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
877 |
environment ~~ Smalltalk ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
878 |
Smalltalk changed:how with:argument. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
879 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
880 |
! |
5905 | 881 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
882 |
environmentChangedOrganization |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
883 |
environment changed:#organization. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
884 |
environment ~~ Smalltalk ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
885 |
Smalltalk changed:#organization. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
886 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
887 |
! |
5905 | 888 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
889 |
fixMethodsIn:newClass |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
890 |
|changeSet1 changeSet2 newMetaclass addedNames| |
5905 | 891 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
892 |
newMetaclass := newClass class. |
5905 | 893 |
|
894 |
"/ care for class methods ... |
|
895 |
||
896 |
changeSet1 := Set new. |
|
897 |
||
898 |
classVarChange := false. |
|
899 |
||
900 |
superClassChange ifTrue:[ |
|
901 |
(oldSuperClass notNil |
|
902 |
and:[newSuperClass notNil |
|
903 |
and:[oldSuperClass allClassVarNames = newSuperClass allClassVarNames |
|
904 |
and:[oldSuperClass name = newSuperClass name |
|
17862 | 905 |
and:[oldClassVars = newClassVars |
906 |
and:[poolChange not]]]]]) |
|
5905 | 907 |
ifTrue:[ |
908 |
||
909 |
"/ Transcript showCR:'keep class methods (same classvars)'. |
|
910 |
"/ Transcript endEntry. |
|
911 |
||
912 |
"/ class methods still work |
|
913 |
||
914 |
self class copyMethodsFrom:(oldClass class) for:newMetaclass. |
|
915 |
||
916 |
"/ Smalltalk silentLoading ifFalse:[ |
|
917 |
"/ Transcript showCR:'recompiling class methods accessing super ...'. |
|
918 |
"/ Transcript endEntry. |
|
919 |
"/ ]. |
|
920 |
||
921 |
"/ however, those accessing super must be recompiled |
|
922 |
||
923 |
self class |
|
924 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
925 |
for:newMetaclass |
|
926 |
accessingAny:#() |
|
927 |
orSuper:true. |
|
928 |
] ifFalse:[ |
|
929 |
"/ superclass changed: |
|
930 |
"/ must recompile all class methods accessing ANY classvar |
|
931 |
"/ (actually, we could be less strict and handle the case where |
|
932 |
"/ both the old and the new superclass have a common ancestor, |
|
933 |
"/ and both have no new classvariables in between. |
|
934 |
"/ This would speedup the case when a class is inserted into |
|
935 |
"/ the inheritance chain.) |
|
936 |
||
937 |
oldClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
938 |
newClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
17892 | 939 |
oldPoolDictionaries do:[:eachPoolName | changeSet1 addAll:(self namesInPoolNamed:eachPoolName ofClass:oldClass)]. |
940 |
newPoolDictionaries do:[:eachPoolName | changeSet1 addAll:(self namesInPoolNamed:eachPoolName ofClass:newClass)]. |
|
941 |
"/ oldPoolDictionaries do:[:eachPoolName | |eachPool| eachPool := Smalltalk at:eachPoolName asSymbol. eachPool allClassVarNames do:[:nm | changeSet1 add:nm]]. |
|
942 |
"/ newPoolDictionaries do:[:eachPoolName | |eachPool| eachPool := Smalltalk at:eachPoolName asSymbol. eachPool allClassVarNames do:[:nm | changeSet1 add:nm]]. |
|
5905 | 943 |
|
944 |
"/ Smalltalk silentLoading ifFalse:[ |
|
945 |
"/ Transcript showCR:'recompiling class methods accessing any classvar or super ...'. |
|
946 |
"/ Transcript endEntry. |
|
947 |
"/ ]. |
|
948 |
||
949 |
self class |
|
950 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
951 |
for:newMetaclass |
|
952 |
accessingAny:changeSet1 |
|
953 |
orSuper:true. |
|
954 |
]. |
|
955 |
newMetaclass recompileInvalidatedMethods. |
|
956 |
] ifFalse:[ |
|
957 |
"/ same superclass, find out which classvars have changed |
|
958 |
||
959 |
classVarChange := oldClassVars ~= newClassVars. |
|
17862 | 960 |
(classVarChange or:[poolChange]) ifTrue:[ |
5905 | 961 |
oldClassVars do:[:nm | |
962 |
(newClassVars includes:nm) ifFalse:[ |
|
963 |
changeSet1 add:nm |
|
964 |
] |
|
965 |
]. |
|
966 |
newClassVars do:[:nm | |
|
967 |
(oldClassVars includes:nm) ifFalse:[ |
|
968 |
changeSet1 add:nm |
|
969 |
] |
|
970 |
]. |
|
17892 | 971 |
oldPoolDictionaries do:[:eachPoolName | changeSet1 addAll:(self namesInPoolNamed:eachPoolName ofClass:oldClass)]. |
972 |
newPoolDictionaries do:[:eachPoolName | changeSet1 addAll:(self namesInPoolNamed:eachPoolName ofClass:newClass)]. |
|
973 |
"/ oldPoolDictionaries do:[:eachPoolName | |eachPool| eachPool := Smalltalk at:eachPoolName asSymbol. eachPool allClassVarNames do:[:nm | changeSet1 add:nm]]. |
|
974 |
"/ newPoolDictionaries do:[:eachPoolName | |eachPool| eachPool := Smalltalk at:eachPoolName asSymbol. eachPool allClassVarNames do:[:nm | changeSet1 add:nm]]. |
|
5905 | 975 |
|
976 |
"/ must recompile some class-methods |
|
977 |
||
978 |
"/ Smalltalk silentLoading ifFalse:[ |
|
979 |
"/ Transcript showCR:'recompiling class methods accessing ' , changeSet1 printString. |
|
980 |
"/ Transcript endEntry. |
|
981 |
"/ ]. |
|
982 |
||
983 |
self class |
|
984 |
copyInvalidatedMethodsFrom:(oldClass class) |
|
985 |
for:newMetaclass |
|
986 |
accessingAny:changeSet1. |
|
987 |
newMetaclass recompileInvalidatedMethods. |
|
988 |
] ifFalse:[ |
|
989 |
||
990 |
"/ class methods still work |
|
991 |
||
992 |
self class copyMethodsFrom:(oldClass class) for:newMetaclass |
|
993 |
]. |
|
994 |
]. |
|
995 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
996 |
|
5905 | 997 |
"/ care for instance methods ... |
998 |
||
999 |
superClassChange ifTrue:[ |
|
1000 |
"/ superclass changed, |
|
1001 |
"/ must recompile all methods accessing any class or instvar. |
|
1002 |
"/ If number of instvars (i.e. the instances instSize) is the same, |
|
1003 |
"/ we can limit the set of recompiled instance methods to those methods, |
|
1004 |
"/ which refer to an instvar with a different inst-index |
|
1005 |
||
1006 |
"/ the changeset consists of instance variables, |
|
1007 |
"/ with a different position |
|
1008 |
||
1009 |
changeSet2 := self class differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1010 |
||
1011 |
"/ merge in the changed class variables |
|
1012 |
||
1013 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
1014 |
||
1015 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1016 |
"/ Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' [superclass change]...'. |
|
1017 |
"/ Transcript endEntry. |
|
1018 |
"/ ]. |
|
1019 |
||
1020 |
self class |
|
1021 |
copyInvalidatedMethodsFrom:oldClass |
|
1022 |
for:newClass |
|
1023 |
accessingAny:changeSet2 |
|
1024 |
orSuper:true. |
|
1025 |
newClass recompileInvalidatedMethods. |
|
1026 |
||
1027 |
] ifFalse:[ |
|
1028 |
||
1029 |
"/ same inheritance ... |
|
1030 |
||
1031 |
instVarChange := oldInstVars ~= newInstVars. |
|
1032 |
instVarChange ifFalse:[ |
|
1033 |
||
1034 |
"/ same instance variables ... |
|
1035 |
||
1036 |
classVarChange ifTrue:[ |
|
1037 |
"recompile all inst methods accessing changed classvars" |
|
1038 |
||
1039 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1040 |
"/ Transcript showCR:'recompiling instance methods accessing classvars ' , changeSet1 printString , ' ...'. |
|
1041 |
"/ Transcript endEntry. |
|
1042 |
"/ ]. |
|
1043 |
self class |
|
1044 |
copyInvalidatedMethodsFrom:oldClass |
|
1045 |
for:newClass |
|
1046 |
accessingAny:changeSet1. |
|
1047 |
newClass recompileInvalidatedMethods. |
|
1048 |
] ifFalse:[ |
|
1049 |
"/ instance methods still work |
|
1050 |
||
1051 |
self class copyMethodsFrom:oldClass for:newClass |
|
1052 |
] |
|
1053 |
] ifTrue:[ |
|
1054 |
||
1055 |
"/ dont allow built-in classes to be modified |
|
1056 |
||
1057 |
(oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
1058 |
ClassBuildError raiseErrorString:'the layout of this class is fixed - you cannot change it'. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1059 |
AbortSignal raise |
5905 | 1060 |
]. |
1061 |
||
1062 |
((oldInstVars size == 0) |
|
1063 |
or:[newInstVars startsWith:oldInstVars]) ifTrue:[ |
|
1064 |
||
1065 |
"/ only new inst variable(s) has/have been added - |
|
1066 |
"/ old methods still work (the existing inst-indices are still valid) |
|
1067 |
||
1068 |
"/ Transcript showCR:'copying methods ...'. |
|
1069 |
"/ Transcript endEntry. |
|
1070 |
||
1071 |
self class copyMethodsFrom:oldClass for:newClass. |
|
1072 |
||
1073 |
"/ but: we have to recompile all methods accessing new instars |
|
1074 |
"/ (it might have been a classVar/global before ...) |
|
1075 |
||
17780 | 1076 |
addedNames := newInstVars reject:[:nm | oldInstVars includes:nm]. |
5905 | 1077 |
"merge in class variables" |
1078 |
changeSet1 do:[:nm | addedNames add:nm]. |
|
1079 |
||
1080 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1081 |
"/ Transcript showCR:'recompiling instance methods accessing ' , addedNames printString , '... [added instvars]'. |
|
1082 |
"/ Transcript endEntry. |
|
1083 |
"/ ]. |
|
1084 |
||
1085 |
newClass recompileMethodsAccessingAny:addedNames. |
|
1086 |
] ifFalse:[ |
|
1087 |
||
1088 |
"/ the changeset consists of instance variables, |
|
1089 |
"/ with a different position |
|
1090 |
||
1091 |
changeSet2 := self class differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1092 |
||
1093 |
"merge in the class variables" |
|
1094 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
1095 |
||
1096 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1097 |
"/ Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' ... [changed instvars]'. |
|
1098 |
"/ Transcript endEntry. |
|
1099 |
"/ ]. |
|
1100 |
||
1101 |
self class |
|
1102 |
copyInvalidatedMethodsFrom:oldClass |
|
1103 |
for:newClass |
|
1104 |
accessingAny:changeSet2. |
|
1105 |
newClass recompileInvalidatedMethods. |
|
1106 |
]. |
|
1107 |
]. |
|
1108 |
]. |
|
17780 | 1109 |
|
17892 | 1110 |
"Modified: / 30-10-2011 / 12:07:49 / cg" |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1111 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1112 |
|
10602 | 1113 |
flagsForVariable:variable pointers:pointers words:words |
1114 |
"/ Allowing non-booleans as variable is a hack for STX / ST80 compatibility: |
|
1115 |
"/ ST80 code will pass true or false as variableBoolean, |
|
1116 |
"/ STX also calls it with symbols such as #float, #double, #longLong etc. |
|
1117 |
||
1118 |
variable isSymbol ifTrue:[ |
|
1119 |
^ Behavior flagForSymbolic:variable. |
|
1120 |
]. |
|
1121 |
||
1122 |
variable ifFalse:[ |
|
1123 |
^ Behavior flagRegular |
|
1124 |
]. |
|
1125 |
||
1126 |
pointers ifTrue:[ |
|
1127 |
^ Behavior flagPointers |
|
1128 |
]. |
|
1129 |
words ifTrue:[ |
|
1130 |
^ Behavior flagWords |
|
1131 |
]. |
|
1132 |
^ Behavior flagBytes |
|
1133 |
||
1134 |
"Created: / 07-06-2007 / 12:08:47 / cg" |
|
1135 |
! |
|
1136 |
||
9802 | 1137 |
handleEasyNewClass:newClass |
1138 |
"instance layout remains the same. |
|
1139 |
We only have to recompile methods which access changed class variables |
|
1140 |
and changed pool variables." |
|
1141 |
||
1142 |
|newComment anyChange setOfChangedVariables oldPoolVars newPoolVars| |
|
1143 |
||
1144 |
oldPoolVars := oldClass sharedPools collectAll:[:pool | pool keys]. |
|
1145 |
newPoolVars := newClass sharedPools collectAll:[:pool | pool keys]. |
|
1146 |
||
1147 |
newComment := newClass comment. |
|
1148 |
||
1149 |
(newComment ~= oldClass comment) ifTrue:[ |
|
1150 |
oldClass setComment:newComment. "writes a change-chunk" |
|
1151 |
oldClass changed:#comment with:oldClass comment. |
|
1152 |
changed ifTrue:[ |
|
1153 |
oldClass addChangeRecordForClassComment:oldClass. |
|
1154 |
] |
|
1155 |
]. |
|
1156 |
||
1157 |
oldClass package ~= newClass package ifTrue:[ |
|
1158 |
"notify change of organization" |
|
1159 |
oldClass setPackage:newClass package. |
|
1160 |
]. |
|
1161 |
||
1162 |
((oldClassVars = newClassVars) |
|
1163 |
and:[oldPoolVars = newPoolVars]) ifTrue:[ |
|
1164 |
"/ really no change (just comment and/or category) |
|
1165 |
||
1166 |
anyChange := false. |
|
1167 |
||
1168 |
oldClass setInstanceVariableString:(newClass instanceVariableString). |
|
1169 |
oldClass setClassVariableString:(newClass classVariableString). |
|
1170 |
||
1171 |
oldClass category ~= category ifTrue:[ |
|
1172 |
oldClass setCategory:category. |
|
1173 |
changed ifTrue:[ |
|
1174 |
newClass addChangeRecordForClass:newClass. |
|
1175 |
]. |
|
1176 |
environment notNil ifTrue:[ |
|
1177 |
buildingPrivateClass ifFalse:[ |
|
1178 |
self environmentChangedOrganization. |
|
1179 |
] |
|
1180 |
] |
|
1181 |
]. |
|
1182 |
^ oldClass |
|
1183 |
]. |
|
1184 |
||
1185 |
"/ when we arrive here, class variables have changed |
|
1186 |
||
1187 |
oldClass category ~= category ifTrue:[ |
|
1188 |
"notify change of organization" |
|
1189 |
oldClass setCategory:category. |
|
1190 |
environment notNil ifTrue:[ |
|
1191 |
buildingPrivateClass ifFalse:[ |
|
1192 |
self environmentChangedOrganization. |
|
1193 |
] |
|
1194 |
]. |
|
1195 |
]. |
|
1196 |
||
1197 |
"/ set class variable string; |
|
1198 |
"/ this also updates the set of class variables |
|
1199 |
"/ by creating new / deleting obsolete ones. |
|
1200 |
||
1201 |
oldClass classVariableString:classVariableNames. |
|
1202 |
oldClass sharedPools:newClass sharedPools. |
|
1203 |
||
1204 |
" |
|
1205 |
get the set of changed class variables |
|
1206 |
" |
|
1207 |
setOfChangedVariables := Set new. |
|
1208 |
||
1209 |
" |
|
1210 |
add the set of changed class variables (those which are not in both) |
|
1211 |
" |
|
1212 |
setOfChangedVariables addAll:(oldClassVars xor:newClassVars). |
|
1213 |
||
1214 |
" |
|
1215 |
add the set of changed pool variables (those which are not in both) |
|
1216 |
" |
|
1217 |
setOfChangedVariables addAll:(oldPoolVars xor:newPoolVars). |
|
1218 |
||
1219 |
" |
|
1220 |
add the set of pool vars which are now classVars and vice versa |
|
1221 |
" |
|
1222 |
setOfChangedVariables addAll:(oldPoolVars intersect:newClassVars). |
|
1223 |
setOfChangedVariables addAll:(oldClassVars intersect:newPoolVars). |
|
1224 |
||
1225 |
setOfChangedVariables notEmpty ifTrue:[ |
|
1226 |
||
1227 |
"/ recompile all methods accessing set of changed classvars |
|
1228 |
"/ here and also in all subclasses ... |
|
1229 |
||
1230 |
"/ dont update change file for the recompilation |
|
1231 |
||
1232 |
Class withoutUpdatingChangesDo:[ |
|
1233 |
||
1234 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1235 |
"/ Transcript showCR:'recompiling class & inst methods accessing ' , setOfChangedVariables printString. |
|
1236 |
"/ Transcript endEntry. |
|
1237 |
"/ ]. |
|
1238 |
oldClass withAllSubclasses do:[:aClass | |
|
1239 |
aClass class recompileMethodsAccessingAnyClassvarOrGlobal:setOfChangedVariables. |
|
1240 |
aClass recompileMethodsAccessingAnyClassvarOrGlobal:setOfChangedVariables. |
|
1241 |
]. |
|
1242 |
]. |
|
1243 |
]. |
|
1244 |
||
17751 | 1245 |
Class flushSubclassInfoFor:oldClass superclass. |
1246 |
Class flushSubclassInfoFor:newClass superclass. |
|
1247 |
Class flushSubclassInfoFor:oldClass. |
|
1248 |
Class flushSubclassInfoFor:newClass. |
|
9802 | 1249 |
|
1250 |
"notify change of class" |
|
1251 |
changed ifTrue:[ |
|
1252 |
oldClass addChangeRecordForClass:oldClass. |
|
1253 |
]. |
|
1254 |
oldClass changed:#definition. |
|
1255 |
||
1256 |
self environmentChanged:#classDefinition with:newClass. |
|
1257 |
||
17815 | 1258 |
"Modified: / 18-01-2011 / 20:45:34 / cg" |
9802 | 1259 |
! |
1260 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1261 |
handleHardNewClass:newClass |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1262 |
|oldCategory| |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1263 |
|
17735 | 1264 |
Class flushSubclassInfoFor:oldSuperClass. |
1265 |
Class flushSubclassInfoFor:newSuperClass. |
|
1266 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1267 |
"/ dont allow built-in classes to be modified this way |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1268 |
(oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
1269 |
ClassBuildError raiseErrorString:'the inheritance of this class is fixed - you cannot change it'. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1270 |
^ oldClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1271 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1272 |
|
17735 | 1273 |
"/ "/ since we will change the inheritance of some class(es) |
1274 |
"/ Class flushSubclassInfo. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1275 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1276 |
"/ catch special case, where superclass changed its layout and thus |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1277 |
"/ forced redefinition of this class; |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1278 |
"/ only log if this is not the case. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1279 |
changed ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1280 |
(superClassChange |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1281 |
and:[(oldSuperClass isNil or:[newSuperClass notNil and:[oldSuperClass name = newSuperClass name]]) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1282 |
and:[(oldClassVars = newClassVars) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1283 |
and:[(oldInstVars = newInstVars) |
17862 | 1284 |
and:[poolChange not |
1285 |
and:[(oldPoolDictionaries = newClass sharedPoolNames) |
|
1286 |
and:[oldClass comment = newClass comment]]]]]]) ifFalse:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1287 |
newClass addChangeRecordForClass:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1288 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1289 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1290 |
self fixMethodsIn:newClass. |
5905 | 1291 |
|
1292 |
"/ finally, if the oldClass came from a dynamically loaded |
|
1293 |
"/ classLibrary, we must recompile the methods in the newClass. |
|
1294 |
"/ otherwise, the methods code will vanish when the old (obsolete) |
|
1295 |
"/ class eventually vanishes ... |
|
1296 |
self class recompileMachineCodeMethodsIn:newClass. |
|
1297 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1298 |
"/ (oldPkg notNil and:[oldPkg ~= pkg]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1299 |
"/ "/ we have to change all methods package info |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1300 |
"/ "/ to belong to the old package. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1301 |
"/ newClass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1302 |
"/ mthd setPackage:oldPkg |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1303 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1304 |
"/ ]. |
5905 | 1305 |
|
1306 |
"/ WOW, everything done for this class |
|
1307 |
"/ what about subclasses ? |
|
1308 |
||
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1309 |
"/ "/ update superclass of immediate subclasses - |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1310 |
"/ "/ this forces recompilation (recursively) if needed |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1311 |
"/ "/ (dont update change file for the subclass changes) |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1312 |
"/ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1313 |
"/ Class classRedefinitionNotification answer:#keep do:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1314 |
"/ Class withoutUpdatingChangesDo:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1315 |
"/ oldClass subclasses copy do:[:aClass | |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1316 |
"/ aClass superclass:newClass |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1317 |
"/ ] |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1318 |
"/ ] |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1319 |
"/ ]. |
5905 | 1320 |
|
1321 |
"/ change any private subclasses' owners |
|
1322 |
||
1323 |
oldClass privateClassesDo:[:aClass | |
|
1324 |
aClass isLoaded ifTrue:[ |
|
1325 |
aClass class setOwningClass:newClass |
|
1326 |
] |
|
1327 |
]. |
|
1328 |
||
1329 |
"/ change category in oldClass - so we see immediately what it is ... |
|
1330 |
||
1331 |
oldCategory := oldClass category. |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1332 |
oldClass setCategory:#'* obsolete *'. |
5905 | 1333 |
oldClass wasAutoloaded ifTrue:[ Autoload removeClass:oldClass ]. |
1334 |
Smalltalk flushCachedClass:oldClass. |
|
1335 |
||
1336 |
"/ and make the new class globally known |
|
1337 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1338 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1339 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1340 |
environment privateClassesAt:className put:newClass. |
5905 | 1341 |
] ifFalse:[ |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1342 |
environment at:className put:newClass. |
5905 | 1343 |
|
1344 |
oldCategory ~= category ifTrue:[ |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1345 |
self environmentChangedOrganization. |
5905 | 1346 |
] |
1347 |
]. |
|
1348 |
]. |
|
1349 |
||
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1350 |
"/ update superclass of immediate subclasses - |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1351 |
"/ this forces recompilation (recursively) if needed |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1352 |
"/ (dont update change file for the subclass changes) |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1353 |
|
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1354 |
Class classRedefinitionNotification answer:#keep do:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1355 |
Class withoutUpdatingChangesDo:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1356 |
oldClass subclasses copy do:[:aClass | |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1357 |
aClass superclass:newClass |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1358 |
] |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1359 |
] |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1360 |
]. |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1361 |
|
5905 | 1362 |
"/ Not becoming the old class creates some update problems; |
1363 |
"/ the browsers must check carefully - a simple identity compare is |
|
1364 |
"/ not enough ... |
|
1365 |
"/ QUESTION: is this a good idea ? |
|
1366 |
newClass dependents:(oldClass dependents). |
|
1367 |
newClass changed:#definition. |
|
1368 |
||
1369 |
"just to make certain ... - tell dependents of oldClass, that something changed |
|
1370 |
(systemBrowsers will react on this, and update their views)" |
|
1371 |
oldClass changed:#definition with:newClass. |
|
1372 |
||
17763 | 1373 |
Class flushSubclassInfoFor:oldClass. |
1374 |
Class flushSubclassInfoFor:newClass. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1375 |
self environmentChanged:#classDefinition with:newClass. |
5905 | 1376 |
|
1377 |
ObjectMemory flushCaches. |
|
1378 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1379 |
buildingPrivateClass ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1380 |
oldClass ~~ newClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1381 |
environment == Smalltalk ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1382 |
ClassBuilder checkForAliasesOf:oldClass with:newClass. |
5905 | 1383 |
] |
1384 |
] |
|
1385 |
]. |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1386 |
(instVarChange or:[classVarChange]) ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1387 |
self changeReferencesFrom:oldClass to:newClass. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1388 |
]. |
17751 | 1389 |
oldClass subclasses do:[:cls | Class flushSubclassInfoFor:cls]. |
1390 |
Class flushSubclassInfoFor:oldClass. |
|
5905 | 1391 |
^ newClass |
1392 |
||
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1393 |
"Created: / 26-05-1996 / 11:55:26 / cg" |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
1394 |
"Modified: / 18-03-1999 / 18:23:31 / stefan" |
17862 | 1395 |
"Modified: / 15-09-2011 / 13:49:01 / cg" |
5907 | 1396 |
! |
1397 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1398 |
handleNewlyCreatedClass:newClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1399 |
"/ comment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1400 |
"/ newClass comment:comment |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1401 |
"/ ]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1402 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1403 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1404 |
environment privateClassesAt:className put:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1405 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1406 |
environment at:className put:newClass. |
8351 | 1407 |
]. |
1408 |
(oldClass isNil and:[changed and:[superClass ~~ Autoload]]) ifTrue:[ |
|
1409 |
newClass addChangeRecordForClass:newClass. |
|
1410 |
]. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1411 |
]. |
6035 | 1412 |
|
17763 | 1413 |
oldClass notNil ifTrue:[ Class flushSubclassInfoFor:oldClass superclass]. |
1414 |
Class flushSubclassInfoFor:newClass superclass. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1415 |
|
17735 | 1416 |
"/ oldClass notNil ifTrue:[ |
1417 |
"/ "/ since we changed the classes inheritance (from Autoloaded) |
|
1418 |
"/ |
|
1419 |
"/ "/ actually, could optimize to: |
|
1420 |
"/ "/ Class updateSuperclassInfoFor:oldClass superclass. |
|
1421 |
"/ "/ Class updateSuperclassInfoFor:newClass superclass. |
|
1422 |
"/ |
|
1423 |
"/ Class flushSubclassInfo. |
|
1424 |
"/ ]. |
|
6037 | 1425 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1426 |
oldClassToBecomeNew notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1427 |
"/ old was an autoloaded class - make it the new one |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1428 |
"/ and flush ... |
10447
b794fbbce924
do not #becomeSameAs on the Metaclass.
Claus Gittinger <cg@exept.de>
parents:
10442
diff
changeset
|
1429 |
|
b794fbbce924
do not #becomeSameAs on the Metaclass.
Claus Gittinger <cg@exept.de>
parents:
10442
diff
changeset
|
1430 |
"/ (ObjectMemory whoReferences:oldClassToBecomeNew class) notEmpty ifTrue:[ |
b794fbbce924
do not #becomeSameAs on the Metaclass.
Claus Gittinger <cg@exept.de>
parents:
10442
diff
changeset
|
1431 |
"/ self halt. |
b794fbbce924
do not #becomeSameAs on the Metaclass.
Claus Gittinger <cg@exept.de>
parents:
10442
diff
changeset
|
1432 |
"/ ]. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1433 |
oldClassToBecomeNew becomeSameAs:newClass. |
10447
b794fbbce924
do not #becomeSameAs on the Metaclass.
Claus Gittinger <cg@exept.de>
parents:
10442
diff
changeset
|
1434 |
"/ oldClassToBecomeNew class becomeSameAs:newClass class. |
b794fbbce924
do not #becomeSameAs on the Metaclass.
Claus Gittinger <cg@exept.de>
parents:
10442
diff
changeset
|
1435 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1436 |
ObjectMemory flushCaches. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1437 |
]. |
6035 | 1438 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1439 |
environment notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1440 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1441 |
environment changed. |
8351 | 1442 |
]. |
1443 |
self environmentChanged:#newClass with:newClass. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1444 |
]. |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1445 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1446 |
"/ be very careful, when adding classes |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1447 |
"/ to a namespace or adding a privateClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1448 |
"/ When adding, all methods within that namespace/owning class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1449 |
"/ which access the unprefixed-global, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1450 |
"/ must be recompiled (so they access the new class) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1451 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1452 |
recompileGlobalAccessTo notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1453 |
self class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1454 |
recompileGlobalAccessorsTo:recompileGlobalAccessTo |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1455 |
in:environment except:newClass. |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1456 |
]. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1457 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1458 |
(buildingPrivateClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1459 |
and:[newClass owningClass nameSpace notNil]) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1460 |
"/ namespace is a class; |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1461 |
"/ if this owner is itself in a namespace, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1462 |
"/ must recompile all from owners namespace |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1463 |
"/ accessing the new class (without namespace prefix) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1464 |
self class |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1465 |
recompileGlobalAccessorsTo:(newClass nameWithoutNameSpacePrefix asSymbol) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1466 |
in:(newClass owningClass nameSpace) except:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1467 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1468 |
^ newClass |
17763 | 1469 |
|
1470 |
"Modified: / 27-04-2010 / 00:03:42 / cg" |
|
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1471 |
! |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
1472 |
|
6514 | 1473 |
instantiateMetaclass |
1474 |
"create the metaclass proper" |
|
1475 |
||
10602 | 1476 |
|metaclassClass newMetaclass classesSuperclass| |
6514 | 1477 |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1478 |
classInstanceVariableNames isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1479 |
oldClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1480 |
classInstanceVariableNames := '' |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1481 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1482 |
classInstanceVariableNames := oldClass class instanceVariableString |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1483 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1484 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1485 |
|
10602 | 1486 |
metaclassClass := metaclass ? Metaclass. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1487 |
buildingPrivateClass ifTrue:[ |
10602 | 1488 |
metaclassClass := metaclassClass asPrivate |
6514 | 1489 |
]. |
10602 | 1490 |
newMetaclass := metaclassClass new. |
6514 | 1491 |
superClass isNil ifTrue:[ |
8724 | 1492 |
classesSuperclass := self classClass. |
6514 | 1493 |
] ifFalse:[ |
1494 |
classesSuperclass := superClass class. |
|
1495 |
]. |
|
1496 |
newMetaclass setSuperclass:classesSuperclass instSize:(classesSuperclass instSize + classInstanceVariableNames countWords). |
|
1497 |
newMetaclass setInstanceVariableString:classInstanceVariableNames. |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1498 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1499 |
newMetaclass setOwningClass:environment. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1500 |
]. |
6514 | 1501 |
^ newMetaclass |
10602 | 1502 |
|
1503 |
"Modified: / 07-06-2007 / 12:24:34 / cg" |
|
6514 | 1504 |
! |
1505 |
||
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1506 |
instantiateNewClassFrom:newMetaclass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1507 |
"create the class proper" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1508 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1509 |
|newClass nInstVars newInstSize| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1510 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1511 |
"let the new meta create the class" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1512 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1513 |
instanceVariableNames size > 0 ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1514 |
nInstVars := instanceVariableNames countWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1515 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1516 |
nInstVars := 0. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1517 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1518 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1519 |
newClass := newMetaclass new. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1520 |
superClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1521 |
newInstSize := nInstVars. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1522 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1523 |
newInstSize := superClass instSize + nInstVars. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1524 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1525 |
newClass setSuperclass:superClass instSize:newInstSize. |
10168
5fa1c09dc61c
set name of new class early (so inspector has more to show)
Claus Gittinger <cg@exept.de>
parents:
10148
diff
changeset
|
1526 |
newClass setName:realNewName. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1527 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1528 |
self copyClassInstanceVariablesFrom:oldClass to:newClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1529 |
self setPackageInNewClass:newClass fromOld:oldClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1530 |
self setupNewClass:newClass fromOld:oldClass. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1531 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1532 |
^ newClass |
10168
5fa1c09dc61c
set name of new class early (so inspector has more to show)
Claus Gittinger <cg@exept.de>
parents:
10148
diff
changeset
|
1533 |
|
5fa1c09dc61c
set name of new class early (so inspector has more to show)
Claus Gittinger <cg@exept.de>
parents:
10148
diff
changeset
|
1534 |
"Modified: / 10-11-2006 / 14:36:28 / cg" |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1535 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1536 |
|
17892 | 1537 |
namesInPoolNamed:poolName ofClass:aClass |
1538 |
|pool ns| |
|
1539 |
||
1540 |
aClass notNil ifTrue:[ |
|
1541 |
ns := aClass nameSpace. |
|
1542 |
]. |
|
1543 |
pool := ns at:poolName asSymbol. |
|
1544 |
pool isNil ifTrue:[ |
|
1545 |
ns ~= Smalltalk ifTrue:[ |
|
1546 |
pool := Smalltalk at:poolName asSymbol. |
|
17921 | 1547 |
]. |
1548 |
"/ pool is not yet there |
|
1549 |
pool isNil ifTrue:[^ #() ]. |
|
17892 | 1550 |
]. |
1551 |
^ pool allClassVarNames |
|
1552 |
||
1553 |
"Created: / 30-10-2011 / 12:04:56 / cg" |
|
1554 |
! |
|
1555 |
||
5907 | 1556 |
rebuildForChangedInstanceVariables |
1557 |
"changing / adding class-inst vars - |
|
1558 |
this actually creates a new metaclass and class, leaving the original |
|
1559 |
classes around as obsolete classes. This may also be true for all subclasses, |
|
1560 |
if class instance variables are added/removed. |
|
1561 |
Existing instances continue to be defined by their original classes. |
|
1562 |
||
1563 |
Time will show, if this is an acceptable behavior or if we should migrate |
|
1564 |
instances to become insts. of the new classes." |
|
1565 |
||
1566 |
|newClass newMetaclass nClassInstVars oldClass |
|
1567 |
allSubclasses oldVars |
|
1568 |
oldNames newNames addedNames |
|
1569 |
oldOffsets newOffsets offset changeSet delta |
|
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1570 |
oldToNew newSubMeta newSub oldSubMeta |
5907 | 1571 |
commonClassInstVars t superclass| |
1572 |
||
1573 |
" |
|
1574 |
cleanup needed here: extract common things with name:inEnvironment:... |
|
1575 |
and restructure things ... currently way too complex. |
|
1576 |
" |
|
1577 |
||
1578 |
oldVars := oldMetaClass instanceVariableString. |
|
1579 |
instanceVariableNames = oldVars ifTrue:[ |
|
1580 |
" |
|
1581 |
Transcript showCR:'no change (', oldVars , ') -> (', instanceVariableNames , ')'. |
|
1582 |
" |
|
1583 |
^ self |
|
1584 |
]. |
|
1585 |
||
1586 |
oldNames := oldVars asCollectionOfWords. |
|
1587 |
newNames := instanceVariableNames asCollectionOfWords. |
|
1588 |
||
1589 |
oldNames = newNames ifTrue:[ |
|
1590 |
" |
|
1591 |
Transcript showCR:'no real change'. |
|
1592 |
" |
|
1593 |
"no real change (just formatting)" |
|
1594 |
oldMetaClass setInstanceVariableString:instanceVariableNames. |
|
1595 |
^ self |
|
1596 |
]. |
|
1597 |
||
1598 |
"/ " |
|
1599 |
"/ let user confirm, if any name is no good (and was good before) |
|
1600 |
"/ " |
|
1601 |
"/ (oldNames inject:true |
|
1602 |
"/ into:[:okSoFar :word | |
|
1603 |
"/ okSoFar and:[word first isUppercase] |
|
1604 |
"/ ]) |
|
1605 |
"/ ifTrue:[ |
|
1606 |
"/ "was ok before" |
|
1607 |
"/ (newNames inject:true |
|
1608 |
"/ into:[:okSoFar :word | |
|
1609 |
"/ okSoFar and:[word first isUppercase] |
|
1610 |
"/ ]) |
|
1611 |
"/ ifFalse:[ |
|
1612 |
"/ (self confirm:'class instance variable names should start with an uppercase letter |
|
1613 |
"/(by convention only) |
|
1614 |
"/ |
|
1615 |
"/install anyway ?' withCRs) |
|
1616 |
"/ ifFalse:[ |
|
1617 |
"/ ^ nil |
|
1618 |
"/ ] |
|
1619 |
"/ ] |
|
1620 |
"/ ]. |
|
1621 |
||
1622 |
nClassInstVars := newNames size. |
|
1623 |
||
1624 |
" |
|
1625 |
Transcript showCR:'create new class/metaclass'. |
|
1626 |
" |
|
1627 |
||
1628 |
" |
|
1629 |
create the new metaclass |
|
1630 |
" |
|
1631 |
oldMetaClass isPrivate ifTrue:[ |
|
6514 | 1632 |
newMetaclass := oldMetaClass class "PrivateMetaclass" new. |
5907 | 1633 |
newMetaclass setOwningClass:(oldMetaClass owningClass). |
1634 |
] ifFalse:[ |
|
6514 | 1635 |
newMetaclass := oldMetaClass class "Metaclass" new. |
5907 | 1636 |
]. |
1637 |
superclass := oldMetaClass superclass. |
|
1638 |
newMetaclass setSuperclass:superclass. |
|
1639 |
newMetaclass instSize:(superclass instSize + nClassInstVars). |
|
1640 |
(nClassInstVars ~~ 0) ifTrue:[ |
|
1641 |
newMetaclass setInstanceVariableString:instanceVariableNames |
|
1642 |
]. |
|
1643 |
"/ newMetaclass flags:(Behavior flagBehavior "flagNotIndexed"). |
|
1644 |
"/ newMetaclass setName:name. |
|
1645 |
"/ newMetaclass classVariableString:classvars. |
|
1646 |
"/ newMetaclass setComment:(self comment). |
|
1647 |
||
1648 |
"find the class which is my sole instance" |
|
1649 |
||
1650 |
oldClass := oldMetaClass theNonMetaclass. |
|
1651 |
||
1652 |
" |
|
1653 |
create the new class |
|
1654 |
" |
|
1655 |
newClass := newMetaclass new. |
|
1656 |
newClass setSuperclass:(oldClass superclass) instSize:(oldClass instSize). |
|
1657 |
newClass flags:(oldClass flags). |
|
1658 |
newClass setName:(oldClass name). |
|
1659 |
newClass setInstanceVariableString:(oldClass instanceVariableString). |
|
1660 |
newClass classVariableString:(oldClass classVariableString). |
|
1661 |
newClass setComment:(oldClass comment). |
|
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1662 |
newClass setCategory:(oldClass category). |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
1663 |
(t := oldClass attributes) notNil ifTrue:[ |
7487 | 1664 |
newClass classAttributes:t. |
5907 | 1665 |
]. |
10048 | 1666 |
newClass setClassFilename:(oldClass getClassFilename). |
5907 | 1667 |
|
1668 |
"/ set the new classes package |
|
1669 |
"/ from the old package |
|
1670 |
||
9722 | 1671 |
newClass setPackage:(oldClass getPackage). |
5907 | 1672 |
|
1673 |
"/ and keep the binary revision |
|
17892 | 1674 |
newClass setBinaryRevision:(oldClass binaryRevisionString). |
5907 | 1675 |
|
1676 |
changeSet := Set new. |
|
1677 |
((oldNames size == 0) |
|
1678 |
or:[newNames startsWith:oldNames]) ifTrue:[ |
|
1679 |
"new variable(s) has/have been added - old methods still work" |
|
1680 |
||
1681 |
"/ Transcript showCR:'copying methods ...'. |
|
1682 |
"/ Transcript endEntry. |
|
1683 |
||
1684 |
ClassBuilder copyMethodsFrom:oldMetaClass for:newMetaclass. |
|
1685 |
ClassBuilder copyMethodsFrom:oldClass for:newClass. |
|
1686 |
||
1687 |
" |
|
1688 |
but have to recompile methods accessing stuff now defined |
|
1689 |
(it might have been a global/undeclared before ...) |
|
1690 |
" |
|
1691 |
||
17780 | 1692 |
addedNames := newNames reject:[:nm | oldNames includes:nm ]. |
5907 | 1693 |
|
1694 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1695 |
"/ Transcript showCR:'recompiling class methods of ' , newMetaclass name , |
|
1696 |
"/ ' accessing any of ' , addedNames printString. |
|
1697 |
"/ ]. |
|
1698 |
||
1699 |
"recompile class-methods" |
|
1700 |
newMetaclass recompileMethodsAccessingAny:addedNames. |
|
1701 |
] ifFalse:[ |
|
1702 |
" |
|
1703 |
create the changeSet; thats the set of class instvar names |
|
1704 |
which have changed their position or are new |
|
1705 |
" |
|
1706 |
offset := 0. oldOffsets := Dictionary new. |
|
1707 |
oldNames do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset]. |
|
1708 |
offset := 0. newOffsets := Dictionary new. |
|
1709 |
newNames do:[:nm | offset := offset + 1. newOffsets at:nm put:offset]. |
|
1710 |
||
1711 |
oldOffsets associationsDo:[:a | |
|
1712 |
|k| |
|
1713 |
||
1714 |
k := a key. |
|
1715 |
(newOffsets includesKey:k) ifFalse:[ |
|
1716 |
changeSet add:k |
|
1717 |
] ifTrue:[ |
|
1718 |
(a value ~~ (newOffsets at:k)) ifTrue:[ |
|
1719 |
changeSet add:k |
|
1720 |
] |
|
1721 |
] |
|
1722 |
]. |
|
1723 |
newOffsets associationsDo:[:a | |
|
1724 |
|k| |
|
1725 |
||
1726 |
k := a key. |
|
1727 |
(oldOffsets includesKey:k) ifFalse:[ |
|
1728 |
changeSet add:k |
|
1729 |
] ifTrue:[ |
|
1730 |
(a value ~~ (oldOffsets at:k)) ifTrue:[ |
|
1731 |
changeSet add:k |
|
1732 |
] |
|
1733 |
] |
|
1734 |
]. |
|
1735 |
||
1736 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1737 |
"/ Transcript showCR:'recompiling class methods of ' , newMetaclass name , |
|
1738 |
"/ ' accessing any of ' , changeSet printString. |
|
1739 |
"/ ]. |
|
1740 |
||
1741 |
" |
|
1742 |
recompile class-methods accessing any c-instvar with a changed position |
|
1743 |
" |
|
1744 |
ClassBuilder copyInvalidatedMethodsFrom:oldMetaClass for:newMetaclass accessingAny:changeSet. |
|
1745 |
newMetaclass recompileInvalidatedMethods. |
|
1746 |
||
1747 |
ClassBuilder copyMethodsFrom:oldClass for:newClass. |
|
1748 |
]. |
|
1749 |
||
1750 |
delta := newNames size - oldNames size. |
|
1751 |
||
1752 |
"/ preserve existing classInstVar values (but not those from Class) |
|
1753 |
newMetaclass allInstVarNames do:[:nm | |
|
1754 |
|v| |
|
1755 |
||
1756 |
(Class class allInstVarNames includes:nm) ifFalse:[ |
|
1757 |
v := oldClass instVarNamed:nm ifAbsent:nil. |
|
1758 |
v notNil ifTrue:[ |
|
1759 |
newClass instVarNamed:nm put:v. |
|
1760 |
]. |
|
1761 |
]. |
|
1762 |
]. |
|
1763 |
||
1764 |
" |
|
1765 |
get list of all subclasses - do before superclass is changed |
|
1766 |
" |
|
1767 |
allSubclasses := oldClass allSubclasses asOrderedCollection. |
|
1768 |
"/ cg: wrong: allSubclasses := allSubclasses asSortedCollection:[:a :b | b isSubclassOf:a]. |
|
1769 |
allSubclasses := allSubclasses topologicalSort:[:a :b | b isSubclassOf:a]. |
|
1770 |
||
1771 |
oldToNew := IdentityDictionary new. |
|
1772 |
||
1773 |
" |
|
1774 |
create a new class tree, based on the new version |
|
1775 |
" |
|
6957
562b88083688
more cache flushing when instvars change
Claus Gittinger <cg@exept.de>
parents:
6825
diff
changeset
|
1776 |
Smalltalk flushCachedClasses. |
17763 | 1777 |
Class flushSubclassInfoFor:oldClass. |
5907 | 1778 |
allSubclasses do:[:aSubclass | |
8235
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1779 |
|oldSuper| |
4cb26959673c
oops - did not care for changed superclass
Claus Gittinger <cg@exept.de>
parents:
8234
diff
changeset
|
1780 |
|
17751 | 1781 |
Class flushSubclassInfoFor:aSubclass. |
5907 | 1782 |
oldSuper := aSubclass superclass. |
1783 |
oldSubMeta := aSubclass class. |
|
1784 |
||
1785 |
newSubMeta := Metaclass new. |
|
1786 |
oldSuper == oldClass ifTrue:[ |
|
1787 |
newSubMeta setSuperclass:newMetaclass. |
|
1788 |
] ifFalse:[ |
|
1789 |
newSubMeta setSuperclass:(oldToNew at:oldSuper) class. |
|
1790 |
]. |
|
1791 |
newSubMeta instSize:(oldSubMeta instSize + delta). |
|
1792 |
newSubMeta flags:(oldSubMeta flags). |
|
1793 |
"/ newSubMeta setName:(oldSubMeta name). |
|
1794 |
newSubMeta setInstanceVariableString:(oldSubMeta instanceVariableString). |
|
1795 |
"/ newSubMeta setComment:(oldSubMeta comment). |
|
1796 |
||
1797 |
newSub := newSubMeta new. |
|
1798 |
oldSuper == oldClass ifTrue:[ |
|
1799 |
newSub setSuperclass:newClass. |
|
1800 |
] ifFalse:[ |
|
1801 |
newSub setSuperclass:(oldToNew at:oldSuper). |
|
1802 |
]. |
|
1803 |
||
1804 |
"/ newSub setMethodDictionary:(aSubclass methodDictionary copy). |
|
1805 |
"/ newSub class setMethodDictionary:(aSubclass class methodDictionary copy). |
|
1806 |
newSub setName:(aSubclass name). |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1807 |
newSub setClassVariableString:(aSubclass classVariableString). |
17815 | 1808 |
newSub setSharedPoolNames:(aSubclass sharedPoolNames). |
5907 | 1809 |
newSub setInstanceVariableString:(aSubclass instanceVariableString). |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
1810 |
(t := aSubclass attributes) notNil ifTrue:[ |
7487 | 1811 |
newSub classAttributes:t. |
7370
1ed996a6e7bf
primitiveSpec changed to attributes.
Claus Gittinger <cg@exept.de>
parents:
7230
diff
changeset
|
1812 |
]. |
5907 | 1813 |
newSub package:(aSubclass package). |
17850 | 1814 |
newSub setClassFilename:(aSubclass classFilename). |
5907 | 1815 |
newSub setComment:(aSubclass comment). |
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1816 |
newSub setCategory:(aSubclass category). |
5907 | 1817 |
newSub instSize:(aSubclass instSize). |
17892 | 1818 |
newSub setBinaryRevision:(aSubclass binaryRevisionString). |
5907 | 1819 |
|
1820 |
oldToNew at:aSubclass put:newSub. |
|
1821 |
||
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1822 |
aSubclass setCategory:#'* obsolete *'. |
5907 | 1823 |
|
1824 |
"/ preserve existing classInstVar values (but not those from Class) |
|
1825 |
||
1826 |
newSubMeta allInstVarNames do:[:nm | |
|
1827 |
|v| |
|
1828 |
||
1829 |
(Class class allInstVarNames includes:nm) ifFalse:[ |
|
1830 |
v := aSubclass instVarNamed:nm ifAbsent:nil. |
|
1831 |
v notNil ifTrue:[ |
|
1832 |
newSub instVarNamed:nm put:v. |
|
1833 |
]. |
|
1834 |
]. |
|
1835 |
]. |
|
1836 |
||
1837 |
]. |
|
1838 |
||
1839 |
"recompile what needs to be" |
|
1840 |
||
1841 |
delta == 0 ifTrue:[ |
|
1842 |
"only have to recompile class methods accessing |
|
1843 |
class instvars from changeset |
|
1844 |
" |
|
1845 |
||
1846 |
allSubclasses do:[:oldSubclass | |
|
1847 |
|newSubclass| |
|
1848 |
||
1849 |
newSubclass := oldToNew at:oldSubclass. |
|
1850 |
||
1851 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1852 |
"/ Transcript showCR:'recompiling class methods of ' , newSubclass class name , |
|
1853 |
"/ ' accessing any of ' , changeSet printString. |
|
1854 |
"/ ]. |
|
1855 |
||
1856 |
ClassBuilder |
|
1857 |
copyInvalidatedMethodsFrom:oldSubclass class for:newSubclass class |
|
1858 |
accessingAny:changeSet orSuper:true. |
|
1859 |
||
1860 |
ClassBuilder |
|
1861 |
copyInvalidatedMethodsFrom:oldSubclass for:newSubclass |
|
1862 |
accessingAny:#() orSuper:true. |
|
1863 |
||
1864 |
newSubclass class recompileInvalidatedMethods. |
|
1865 |
newSubclass recompileInvalidatedMethods. |
|
1866 |
] |
|
1867 |
] ifFalse:[ |
|
1868 |
" |
|
1869 |
have to recompile all class methods accessing class instvars |
|
1870 |
" |
|
1871 |
commonClassInstVars := oldClass class allInstVarNames. |
|
1872 |
changeSet do:[:v | |
|
1873 |
commonClassInstVars remove:v ifAbsent:[] |
|
1874 |
]. |
|
1875 |
||
1876 |
allSubclasses do:[:oldSubclass | |
|
1877 |
|newSubclass classInstVars| |
|
1878 |
||
1879 |
newSubclass := oldToNew at:oldSubclass. |
|
1880 |
||
1881 |
classInstVars := newSubclass class allInstVarNames asSet. |
|
1882 |
classInstVars removeAll:commonClassInstVars. |
|
1883 |
classInstVars addAll:changeSet. |
|
1884 |
||
1885 |
"/ Smalltalk silentLoading ifFalse:[ |
|
1886 |
"/ Transcript showCR:'recompiling class methods of ' , newSubclass class name , |
|
1887 |
"/ ' accessing any of ' , classInstVars printString. |
|
1888 |
"/ ]. |
|
1889 |
||
1890 |
ClassBuilder |
|
1891 |
copyInvalidatedMethodsFrom:oldSubclass class for:newSubclass class |
|
1892 |
accessingAny:classInstVars orSuper:true. |
|
1893 |
||
1894 |
ClassBuilder |
|
1895 |
copyInvalidatedMethodsFrom:oldSubclass for:newSubclass |
|
1896 |
accessingAny:#() orSuper:true. |
|
1897 |
||
1898 |
newSubclass class recompileInvalidatedMethods. |
|
1899 |
newSubclass recompileInvalidatedMethods. |
|
1900 |
] |
|
1901 |
]. |
|
1902 |
||
1903 |
newClass addChangeRecordForClassInstvars:newClass. |
|
1904 |
||
1905 |
"install all new classes" |
|
1906 |
||
1907 |
(Smalltalk at:(oldClass name asSymbol) ifAbsent:nil) == oldClass ifTrue:[ |
|
1908 |
Smalltalk at:(oldClass name asSymbol) put:newClass. |
|
1909 |
ClassBuilder checkForAliasesOf:oldClass with:newClass. |
|
1910 |
||
1911 |
" |
|
1912 |
change any private subclasses' owners |
|
1913 |
" |
|
1914 |
oldClass privateClassesDo:[:aClass | |
|
1915 |
aClass class setOwningClass:newClass |
|
1916 |
]. |
|
1917 |
||
1918 |
]. |
|
1919 |
ObjectMemory flushCachesFor:oldClass. |
|
1920 |
||
1921 |
allSubclasses do:[:oldSubClass | |
|
1922 |
|newSubClass| |
|
1923 |
||
1924 |
newSubClass := oldToNew at:oldSubClass. |
|
1925 |
||
1926 |
"/ Transcript showCR:'install ' , newSubClass name , '(' , newSubClass category , ')' , |
|
1927 |
"/ ' as ' , newSubClass name. |
|
1928 |
||
1929 |
(Smalltalk at:(oldSubClass name asSymbol) ifAbsent:nil) == oldSubClass ifTrue:[ |
|
1930 |
Smalltalk at:oldSubClass name asSymbol put:newSubClass. |
|
1931 |
ClassBuilder checkForAliasesOf:oldSubClass with:newSubClass. |
|
1932 |
]. |
|
1933 |
ObjectMemory flushCachesFor:oldSubClass. |
|
1934 |
||
1935 |
oldSubClass privateClassesDo:[:aClass | |
|
1936 |
aClass class setOwningClass:newSubClass |
|
1937 |
]. |
|
1938 |
]. |
|
1939 |
||
1940 |
"tell dependents ..." |
|
1941 |
||
1942 |
oldClass changed:#definition. |
|
7516
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1943 |
"/ oldClass nameSpace changed:#classDefinition with:oldClass. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1944 |
"/ oldClass nameSpace ~~ Smalltalk ifTrue:[ |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1945 |
"/ Smalltalk changed:#classDefinition with:oldClass. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1946 |
"/ ]. |
42c5b199db20
change notifications for classInstVar change
Claus Gittinger <cg@exept.de>
parents:
7487
diff
changeset
|
1947 |
|
5907 | 1948 |
oldMetaClass changed:#definition. |
1949 |
oldMetaClass nameSpace changed:#classDefinition with:oldMetaClass. |
|
1950 |
oldMetaClass nameSpace ~~ Smalltalk ifTrue:[ |
|
1951 |
Smalltalk changed:#classDefinition with:oldMetaClass. |
|
1952 |
]. |
|
1953 |
||
7580
0a49277831d9
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
7528
diff
changeset
|
1954 |
oldClass setCategory:#'* obsolete *'. |
5907 | 1955 |
^ newMetaclass |
1956 |
||
10048 | 1957 |
"Created: / 29-10-1995 / 19:57:08 / cg" |
1958 |
"Modified: / 01-04-1997 / 15:44:09 / stefan" |
|
17892 | 1959 |
"Modified: / 29-09-2011 / 16:02:51 / cg" |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1960 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1961 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1962 |
setPackageInNewClass:newClass fromOld:oldClass |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1963 |
|pkg oldPkg answer| |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1964 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1965 |
"/ set the new classes package |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1966 |
"/ but be careful here ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1967 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1968 |
oldClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1969 |
"/ new classes get the current package ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1970 |
pkg := Class packageQuerySignal query. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1971 |
] ifFalse:[ |
17850 | 1972 |
"/ cg: is this correct ? |
10048 | 1973 |
newClass setClassFilename:(oldClass getClassFilename). |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1974 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1975 |
oldPkg := oldClass package. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1976 |
oldClass isLoaded ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1977 |
"/ autoloaded classes get the package of the autoload stub ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1978 |
pkg := oldPkg |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1979 |
] ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1980 |
"/ not autoloading, check for packageRedef ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1981 |
buildingPrivateClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1982 |
pkg := environment package. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1983 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1984 |
pkg := Class packageQuerySignal query. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
1985 |
oldPkg ~= pkg ifTrue:[ |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
1986 |
pkg == PackageId noProjectID ifTrue:[ |
11020
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1987 |
pkg := oldPkg. |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1988 |
] ifFalse:[ |
17742 | 1989 |
newClass setPackage:pkg. "/ so the notification handler knows, what we are talking about |
11020
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1990 |
answer := Class classRedefinitionNotification |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1991 |
raiseRequestWith:(oldClass -> newClass) |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1992 |
errorString:('redefinition of class: ' , oldClass name). |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1993 |
answer == #keep ifTrue:[ |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1994 |
pkg := oldPkg. "/ keep old package |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1995 |
] ifFalse:[ |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1996 |
answer ~~ #continue ifTrue:[ |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1997 |
newClass package:pkg. |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1998 |
^ nil "/ cancel |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
1999 |
]. |
91b10ace8d96
oops - care to keep the package information cnsistent !
Claus Gittinger <cg@exept.de>
parents:
10842
diff
changeset
|
2000 |
"/ take new package |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2001 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2002 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2003 |
]. |
17892 | 2004 |
newClass setBinaryRevision:(oldClass binaryRevisionString). |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2005 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2006 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2007 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2008 |
pkg notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2009 |
"/ Transcript showCR:('set package of class: ' , newClass name , ' to ' , pkg printString). |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2010 |
newClass package:pkg. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2011 |
]. |
10048 | 2012 |
|
17892 | 2013 |
"Modified: / 29-09-2011 / 15:58:56 / cg" |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2014 |
! |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2015 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2016 |
setupNewClass:newClass fromOld:oldClass |
9114 | 2017 |
|newFlags superFlags nInstVars| |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2018 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2019 |
(instanceVariableNames size > 0) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2020 |
nInstVars := instanceVariableNames countWords. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2021 |
] ifFalse:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2022 |
nInstVars := 0. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2023 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2024 |
|
10602 | 2025 |
newFlags := flags. "/ self flagsForVariable:variable pointers:pointers words:words. |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2026 |
superClass isNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2027 |
superFlags := 0 |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2028 |
] ifFalse:[ |
17965 | 2029 |
| flags | |
2030 |
||
2031 |
"JV@2012-09-07: Certain classes define class method #flags which |
|
2032 |
returns something different than behavior's flag bits. |
|
2033 |
Obtaing superclass's flags by |
|
2034 |
||
2035 |
superClass flags |
|
2036 |
||
2037 |
won't then work as expected. Ask JV for details |
|
2038 |
||
2039 |
Hence this hack :-( |
|
2040 |
" |
|
2041 |
flags := (Behavior compiledMethodAt: #flags) valueWithReceiver: superClass arguments: #(). |
|
2042 |
superFlags := flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits" |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2043 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2044 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2045 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2046 |
oldClass isBuiltInClass ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2047 |
" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2048 |
special care when redefining Method, Block and other built-in classes, |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2049 |
which might have other flag bits ... |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2050 |
" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2051 |
newFlags := newFlags bitOr:(oldClass flags bitAnd:(Behavior maskIndexType bitInvert)) |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2052 |
] |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2053 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2054 |
newClass flags:(newFlags bitOr:superFlags). "preserve inherited special bits" |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2055 |
|
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2056 |
(nInstVars ~~ 0) ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2057 |
newClass setInstanceVariableString:instanceVariableNames |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2058 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2059 |
oldClass notNil ifTrue:[ |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2060 |
"/ setting first will make new class clear obsolete classvars |
17942 | 2061 |
newClass setLookupObject: (oldClass lookupObject). |
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2062 |
newClass setClassVariableString:(oldClass classVariableString). |
17815 | 2063 |
newClass setSharedPoolNames:(oldClass sharedPoolNames). |
10048 | 2064 |
newClass setClassFilename:(oldClass getClassFilename). |
9114 | 2065 |
newClass setPrimitiveDefinitions:(oldClass primitiveDefinitionsString). |
2066 |
newClass setPrimitiveFunctions:(oldClass primitiveFunctionsString). |
|
2067 |
newClass setPrimitiveVariables:(oldClass primitiveVariablesString). |
|
8073
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2068 |
]. |
42c37438e0dc
refactored for shorter methods
Claus Gittinger <cg@exept.de>
parents:
7617
diff
changeset
|
2069 |
newClass setClassVariableString:classVariableNames. |
10048 | 2070 |
|
17815 | 2071 |
"Modified: / 18-01-2011 / 20:44:04 / cg" |
17965 | 2072 |
"Modified: / 07-09-2012 / 13:44:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5905 | 2073 |
! ! |
2074 |
||
2075 |
!ClassBuilder methodsFor:'checks'! |
|
2076 |
||
2077 |
checkClassName |
|
8743
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2078 |
|fullNameString idx environmentName| |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2079 |
|
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2080 |
"/ check if the given name implies a (sub-) namespace |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2081 |
"/ happens (currently) when installing autoloaded classes |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2082 |
(className includes:$:) ifTrue:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2083 |
environment notNil ifTrue:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2084 |
fullNameString := environment name , '::' , className |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2085 |
] ifFalse:[ |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2086 |
fullNameString := className |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2087 |
]. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2088 |
idx := fullNameString lastIndexOf:$:. |
9528 | 2089 |
(idx > 1 and:[(fullNameString at:idx-1) == $:]) ifTrue:[ |
2090 |
className := (fullNameString copyFrom:idx+1) asSymbol. |
|
2091 |
environmentName := fullNameString copyTo:idx-2. |
|
2092 |
environment := Smalltalk at:environmentName asSymbol. |
|
2093 |
environment isNil ifTrue:[ |
|
2094 |
environment := NameSpace fullName:environmentName |
|
2095 |
]. |
|
8743
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2096 |
]. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2097 |
]. |
3992e2ac5c7f
care for the case when defining a class with a name-space name but
Claus Gittinger <cg@exept.de>
parents:
8724
diff
changeset
|
2098 |
|
8421 | 2099 |
environment isNil ifTrue:[ |
2100 |
"/ no constraints |
|
2101 |
^ self |
|
2102 |
]. |
|
2103 |
||
5905 | 2104 |
(className isSymbol not |
2105 |
or:[className size == 0]) ifTrue:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
2106 |
ClassBuildError raiseErrorString:'invalid class name (must be a nonEmpty symbol)'. |
5905 | 2107 |
]. |
2108 |
className first isLetter ifFalse:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
2109 |
ClassBuildError raiseErrorString:'invalid class name (must start with a letter)'. |
5905 | 2110 |
]. |
9528 | 2111 |
|
2112 |
"Modified: / 11-08-2006 / 12:46:54 / cg" |
|
5905 | 2113 |
! |
2114 |
||
2115 |
checkConventionsFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
|
2116 |
"Check for some 'considered bad-style' things, like lower case names. |
|
2117 |
NOTICE: |
|
2118 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
2119 |
the outer codeview a chance to highlight the error. |
|
2120 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
2121 |
" |
|
2122 |
||
2123 |
|names idx what doChecks answ| |
|
2124 |
||
2125 |
doChecks := Metaclass confirmationQuerySignal query. |
|
2126 |
doChecks == false ifTrue:[^ true]. |
|
10392
21183db20168
dont check name conventions, if there is no name (no environment)
Claus Gittinger <cg@exept.de>
parents:
10384
diff
changeset
|
2127 |
environment isNil ifTrue:[^ true]. |
5905 | 2128 |
|
2129 |
"let user confirm, if the classname is no good" |
|
9238 | 2130 |
className isUppercaseFirst ifFalse:[ |
5905 | 2131 |
aClass == NameSpace ifTrue:[ |
2132 |
what := 'namespace' |
|
2133 |
] ifFalse:[ |
|
2134 |
what := 'class' |
|
2135 |
]. |
|
2136 |
||
2137 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
2138 |
answ notNil ifTrue:[^ answ]. |
|
2139 |
||
10392
21183db20168
dont check name conventions, if there is no name (no environment)
Claus Gittinger <cg@exept.de>
parents:
10384
diff
changeset
|
2140 |
(self confirm:('%1 name "%2" should start with an uppercase letter\(by convention only)\\install anyway ?' |
21183db20168
dont check name conventions, if there is no name (no environment)
Claus Gittinger <cg@exept.de>
parents:
10384
diff
changeset
|
2141 |
bindWith:what with:className) withCRs) |
5905 | 2142 |
ifFalse:[ |
2143 |
^ false |
|
2144 |
] |
|
2145 |
]. |
|
2146 |
||
2147 |
names := instVarNameString asCollectionOfWords. |
|
2148 |
||
2149 |
"let user confirm, if any instvarname is no good" |
|
9238 | 2150 |
(idx := names findFirst:[:word | word isUppercaseFirst]) ~~ 0 ifTrue:[ |
5905 | 2151 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
2152 |
answ notNil ifTrue:[^ answ]. |
|
2153 |
||
2154 |
(self confirm:className , ': instance variable named ''' , (names at:idx) allBold , ''' |
|
2155 |
should start with a lowercase letter (by convention only). |
|
2156 |
||
2157 |
Install anyway ?' withCRs) |
|
2158 |
ifFalse:[ |
|
2159 |
^ false |
|
2160 |
] |
|
2161 |
]. |
|
2162 |
||
2163 |
names := classVarNameString asCollectionOfWords. |
|
2164 |
||
2165 |
"let user confirm, if any classvarname is no good" |
|
2166 |
(idx := names findFirst:[:word | word first isLowercase]) ~~ 0 ifTrue:[ |
|
2167 |
answ := Class classConventionViolationConfirmationQuerySignal query. |
|
2168 |
answ notNil ifTrue:[^ answ]. |
|
2169 |
||
2170 |
(self confirm:className , ': class variable named ''' , (names at:idx) allBold , ''' |
|
2171 |
should start with an uppercase letter (by convention only). |
|
2172 |
||
2173 |
Install anyway ?' withCRs) |
|
2174 |
ifFalse:[ |
|
2175 |
^ false |
|
2176 |
]. |
|
2177 |
]. |
|
2178 |
||
2179 |
^ true |
|
2180 |
||
10392
21183db20168
dont check name conventions, if there is no name (no environment)
Claus Gittinger <cg@exept.de>
parents:
10384
diff
changeset
|
2181 |
"Created: / 15-10-1996 / 11:56:38 / cg" |
21183db20168
dont check name conventions, if there is no name (no environment)
Claus Gittinger <cg@exept.de>
parents:
10384
diff
changeset
|
2182 |
"Modified: / 18-03-1999 / 18:22:47 / stefan" |
21183db20168
dont check name conventions, if there is no name (no environment)
Claus Gittinger <cg@exept.de>
parents:
10384
diff
changeset
|
2183 |
"Modified: / 18-02-2007 / 12:46:10 / cg" |
5905 | 2184 |
! |
2185 |
||
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2186 |
checkForCircularDefinitionFrom:oldClass |
9238 | 2187 |
oldClass allSuperclassesDo:[:cls | |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2188 |
cls name = realNewName ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2189 |
^ true |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2190 |
] |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2191 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2192 |
|
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2193 |
superClass notNil ifTrue:[ |
9238 | 2194 |
superClass allSuperclassesDo:[:cls | |
6034
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2195 |
cls name = realNewName ifTrue:[ |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2196 |
^ true |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2197 |
] |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2198 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2199 |
]. |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2200 |
^ false |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2201 |
! |
837b3fd25342
optionally replaceReferencesTo oldClass with references to newClass
Claus Gittinger <cg@exept.de>
parents:
6024
diff
changeset
|
2202 |
|
5905 | 2203 |
checkInstvarRedefsWith:stringOfInstVarNames subclassOf:aClass old:oldClass name:newName |
2204 |
|superInstVars msg| |
|
2205 |
||
2206 |
aClass notNil ifTrue:[ |
|
2207 |
" |
|
2208 |
check for instVar redef of superClass instVars |
|
2209 |
" |
|
2210 |
superInstVars := aClass allInstVarNames. |
|
2211 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
2212 |
(superInstVars includes:nm) ifTrue:[ |
|
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2213 |
msg := 'instVar "%1" is already defined in a superclass of "%2"' bindWith:nm allBold with:newName allBold. |
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2214 |
Tools::ToDoListBrowser notNil ifTrue:[ |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2215 |
"/ experimental |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2216 |
self |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2217 |
notifyTodo:msg position:nil |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2218 |
className:newName selector:nil |
10464
93632325fcef
oops - should not need to know about ToDoList
Claus Gittinger <cg@exept.de>
parents:
10447
diff
changeset
|
2219 |
severity:#error priority:#high |
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2220 |
equalityParameter:nm |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2221 |
checkAction:[:e | |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2222 |
|superClass class| |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2223 |
|
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2224 |
superClass := Smalltalk classNamed:aClass name. |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2225 |
class := Smalltalk classNamed:newName. |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2226 |
|
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2227 |
(superClass allInstVarNames includes:nm) and:[class instVarNames includes:nm]]. |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2228 |
]. |
10382 | 2229 |
|
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2230 |
ParserFlags warnings ifTrue:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2231 |
(oldClass notNil |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2232 |
and:[stringOfInstVarNames = oldClass instanceVariableString]) |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2233 |
ifTrue:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2234 |
msg := 'InstVar conflict in "%1" for "%2" due to superclass change.\You now have two different instVar slots with the same name.\\Don''t forget to fix this later.' bindWith:newName allBold with:nm allBold. |
9278
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2235 |
self warn:msg withCRs. |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2236 |
] ifFalse:[ |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2237 |
msg := 'instVar "%1" is already defined in a superclass.\Change the definition of "%2" anyway ?\\Don''t forget to fix this later.' bindWith:nm allBold with:newName allBold. |
9278
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2238 |
^ self confirm:msg withCRs |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2239 |
]. |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2240 |
] |
5905 | 2241 |
] |
2242 |
]. |
|
2243 |
]. |
|
2244 |
||
2245 |
oldClass notNil ifTrue:[ |
|
2246 |
" |
|
2247 |
check for instVar redefs in subclass instVars |
|
2248 |
" |
|
2249 |
oldClass allSubclassesDo:[:sub | |
|
2250 |
|vars| |
|
2251 |
||
2252 |
vars := sub instVarNames. |
|
2253 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
9278
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2254 |
|msg| |
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2255 |
|
5905 | 2256 |
(vars includes:nm) ifTrue:[ |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2257 |
msg := 'subclass "%1" also defines an instVar named "%2"' bindWith:sub name allBold with:nm allBold. |
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2258 |
Tools::ToDoListBrowser notNil ifTrue:[ |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2259 |
"/ experimental |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2260 |
self |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2261 |
notifyTodo:msg position:nil |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2262 |
className:newName selector:nil |
10464
93632325fcef
oops - should not need to know about ToDoList
Claus Gittinger <cg@exept.de>
parents:
10447
diff
changeset
|
2263 |
severity:#error priority:#high |
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2264 |
equalityParameter:nm |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2265 |
checkAction:[:e | |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2266 |
|class| |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2267 |
|
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2268 |
Class flushSubclassInfo. |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2269 |
class := Smalltalk classNamed:newName. |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2270 |
|
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2271 |
(class instVarNames includes:nm) |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2272 |
and:[ class allSubclasses contains:[:aSubclass | aSubclass instVarNames includes:nm]]]. |
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2273 |
]. |
9278
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2274 |
ParserFlags warnings ifTrue:[ |
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2275 |
msg := ('subclass "%1" also defines an instVar named "%2".\\Change the definition of "%3" anyway ?\Notice: you must fix this later.' |
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2276 |
bindWith:sub name allBold with:nm allBold with:newName allBold) withCRs. |
9278
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2277 |
^ self confirm:msg |
dbe49e4d9203
honor warnings setting in ParserFlags.
Claus Gittinger <cg@exept.de>
parents:
9270
diff
changeset
|
2278 |
] |
5905 | 2279 |
] |
2280 |
] |
|
2281 |
] |
|
2282 |
]. |
|
2283 |
^ true |
|
2284 |
||
10105
092d290344cc
experimental toDoList support
Claus Gittinger <cg@exept.de>
parents:
10048
diff
changeset
|
2285 |
"Created: / 29-01-1997 / 17:42:11 / cg" |
10384
f9222be927dc
changed #checkInstvarRedefsWith:subclassOf:old:name:
Claus Gittinger <cg@exept.de>
parents:
10382
diff
changeset
|
2286 |
"Modified: / 10-02-2007 / 21:35:22 / cg" |
5905 | 2287 |
! |
2288 |
||
8539 | 2289 |
checkValidPools |
2290 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
|
2291 |
||
2292 |
poolDictionaries notNil ifTrue:[ |
|
2293 |
poolDictionaries asCollectionOfWords do:[:eachPoolName | |
|
2294 |
|pool| |
|
2295 |
||
9187
9e9eb3e21448
send #isNameSpace instead of obsolete #isNamespace
Stefan Vogel <sv@exept.de>
parents:
9114
diff
changeset
|
2296 |
environment isNameSpace ifTrue:[ |
9114 | 2297 |
pool := environment classNamed:eachPoolName. |
2298 |
] ifFalse:[ |
|
2299 |
pool := environment nameSpace classNamed:eachPoolName. |
|
2300 |
]. |
|
8636 | 2301 |
pool isNil ifTrue:[ |
2302 |
pool := Smalltalk classNamed:eachPoolName. |
|
2303 |
]. |
|
8639 | 2304 |
(pool notNil and:[pool isBehavior]) ifTrue:[ |
2305 |
pool autoload. |
|
2306 |
pool isSharedPool ifFalse:[ |
|
2307 |
self error:('Not a valid pool: ' , eachPoolName) mayProceed:true. |
|
2308 |
] |
|
8539 | 2309 |
] |
2310 |
] |
|
2311 |
]. |
|
2312 |
! |
|
2313 |
||
5905 | 2314 |
checkValidSubclassing |
2315 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
|
2316 |
superClass notNil ifTrue:[ |
|
2317 |
superClass canBeSubclassed ifFalse:[ |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
2318 |
ClassBuildError raiseErrorString:('it is not possible to subclass ' , superClass name). |
5905 | 2319 |
] |
2320 |
]. |
|
2321 |
! |
|
2322 |
||
2323 |
checkValidVarNamesFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
|
2324 |
"Check for some 'considered bad-style' things, like lower case names. |
|
2325 |
NOTICE: |
|
17735 | 2326 |
I dont like the confirmers below - we need a notifying: argument, or a |
2327 |
notifierSignal to give the outer codeview a chance to highlight the error. |
|
2328 |
(but that's how its defined in the book - maybe I will change it anyway). |
|
5905 | 2329 |
" |
2330 |
||
17735 | 2331 |
|instVarNames classVarNames privateClassNames conflicts| |
5905 | 2332 |
|
17735 | 2333 |
instVarNames := instVarNameString asCollectionOfWords. |
5905 | 2334 |
|
2335 |
"check for instvar redefs within local instvars" |
|
17735 | 2336 |
instVarNames keysAndValuesDo:[:index :aName | |
2337 |
(instVarNames indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
10842 | 2338 |
self warn:('instance variable "%1"\occurs multiple times in instVarString.\\Class %2 not installed.' |
2339 |
bindWith:aName |
|
2340 |
with:className) withCRs. |
|
5905 | 2341 |
^ false. |
2342 |
] |
|
2343 |
]. |
|
2344 |
||
17735 | 2345 |
classVarNames := classVarNameString asCollectionOfWords. |
5905 | 2346 |
|
2347 |
"check for classvar redefs within local instvars" |
|
17735 | 2348 |
classVarNames keysAndValuesDo:[:index :aName | |
2349 |
(classVarNames indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
5905 | 2350 |
self warn:'class variable ''' , aName , '''\occurs multiple times in classVarString.\\Class not installed.' withCRs. |
2351 |
^ false. |
|
2352 |
] |
|
2353 |
]. |
|
17735 | 2354 |
|
2355 |
oldClass notNil ifTrue:[ |
|
2356 |
"check against private classes" |
|
2357 |
||
2358 |
privateClassNames := oldClass theNonMetaclass privateClasses collect:[:cls | cls nameWithoutPrefix]. |
|
2359 |
conflicts := classVarNames intersect:privateClassNames. |
|
2360 |
conflicts notEmpty ifTrue:[ |
|
2361 |
conflicts size == 1 ifTrue:[ |
|
2362 |
self warn:('Class variable "%1"\conflicts with corresponding private classes name.' |
|
2363 |
bindWith:conflicts first) withCRs. |
|
2364 |
] ifFalse:[ |
|
2365 |
self warn:('Some class variables conflict with corresponding private classes name.'). |
|
2366 |
]. |
|
2367 |
^ true. |
|
2368 |
] |
|
2369 |
]. |
|
2370 |
||
5905 | 2371 |
^ true |
2372 |
||
2373 |
"Created: 8.1.1997 / 21:09:14 / cg" |
|
2374 |
"Modified: 9.1.1997 / 02:10:02 / cg" |
|
2375 |
! ! |
|
2376 |
||
2377 |
!ClassBuilder class methodsFor:'documentation'! |
|
2378 |
||
2379 |
version |
|
17965 | 2380 |
^ '$Id: ClassBuilder.st 10843 2012-09-07 12:46:06Z vranyj1 $' |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
2381 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
2382 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17729
diff
changeset
|
2383 |
version_CVS |
17942 | 2384 |
^ '§Header: /cvs/stx/stx/libbasic/ClassBuilder.st,v 1.114 2012/01/31 13:14:34 cg Exp §' |
17856
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
2385 |
! |
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
2386 |
|
de6908f9b372
Fix for LastNamespaceName cache
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17851
diff
changeset
|
2387 |
version_SVN |
17965 | 2388 |
^ '$Id: ClassBuilder.st 10843 2012-09-07 12:46:06Z vranyj1 $' |
17846 | 2389 |
! ! |
17850 | 2390 |
|
2391 |
ClassBuilder initialize! |