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