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