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