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