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