1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Class subclass:#Metaclass
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Classes'
|
|
18 |
!
|
|
19 |
|
|
20 |
Metaclass comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
every class-class is a subclass of Metaclass
|
68
|
26 |
Metaclass provides support for creating new (sub)classes and/or
|
|
27 |
changing the definition of an already existing class.
|
1
|
28 |
|
68
|
29 |
$Header: /cvs/stx/stx/libbasic/Metaclass.st,v 1.10 1994-03-30 09:32:39 claus Exp $
|
1
|
30 |
'!
|
|
31 |
|
|
32 |
!Metaclass methodsFor:'creating classes'!
|
|
33 |
|
|
34 |
name:newName inEnvironment:aSystemDictionary
|
|
35 |
subclassOf:aClass
|
|
36 |
instanceVariableNames:stringOfInstVarNames
|
|
37 |
variable:variableBoolean
|
|
38 |
words:wordsBoolean
|
|
39 |
pointers:pointersBoolean
|
|
40 |
classVariableNames:stringOfClassVarNames
|
|
41 |
poolDictionaries:stringOfPoolNames
|
|
42 |
category:categoryString
|
|
43 |
comment:commentString
|
|
44 |
changed:changed
|
|
45 |
|
13
|
46 |
"this is the main workhorse for installing new classes - special care
|
|
47 |
has to be taken, when changing an existing classes definition. In this
|
|
48 |
case, some or all of the methods and subclasses methods have to be
|
|
49 |
recompiled.
|
|
50 |
Also, the old class(es) are still kept (but not accessable as a global),
|
|
51 |
to allow existing instances some life.
|
|
52 |
This might change in the future.
|
|
53 |
"
|
|
54 |
|
1
|
55 |
|newClass newMetaclass nInstVars nameString classSymbol oldClass
|
|
56 |
allSubclasses classVarChange instVarChange superClassChange newComment
|
10
|
57 |
changeSet1 changeSet2 offset oldOffsets newOffsets addedNames
|
49
|
58 |
anyChange oldInstVars newInstVars oldClassVars newClassVars upd superFlags newFlags|
|
13
|
59 |
|
68
|
60 |
"NOTICE:
|
|
61 |
this method is too complex and should be splitted into managable pieces ...
|
|
62 |
I dont like it anymore :-)
|
|
63 |
"
|
13
|
64 |
|
|
65 |
newName = aClass name ifTrue:[
|
|
66 |
self error:'trying to create circular class definition'.
|
|
67 |
^ nil
|
|
68 |
].
|
1
|
69 |
|
49
|
70 |
"check for invalid subclassing of UndefinedObject and SmallInteger"
|
|
71 |
aClass canBeSubclassed ifFalse:[
|
|
72 |
self error:('it is not possible to subclass ' , aClass name).
|
|
73 |
^ oldClass
|
|
74 |
].
|
|
75 |
|
1
|
76 |
nInstVars := stringOfInstVarNames countWords.
|
|
77 |
nameString := newName asString.
|
13
|
78 |
classSymbol := newName asSymbol.
|
1
|
79 |
newComment := commentString.
|
|
80 |
|
13
|
81 |
"look, if it already exists as a class"
|
68
|
82 |
oldClass := aSystemDictionary at:classSymbol ifAbsent:[nil].
|
|
83 |
oldClass isBehavior ifFalse:[
|
|
84 |
oldClass := nil.
|
|
85 |
] ifTrue:[
|
|
86 |
oldClass superclass notNil ifTrue:[
|
|
87 |
oldClass allSuperclasses do:[:cls |
|
|
88 |
cls name = nameString ifTrue:[
|
|
89 |
self error:'trying to create circular class definition'.
|
|
90 |
^ nil
|
|
91 |
]
|
|
92 |
]
|
|
93 |
].
|
|
94 |
|
|
95 |
aClass superclass notNil ifTrue:[
|
|
96 |
aClass allSuperclasses do:[:cls |
|
|
97 |
cls name = nameString ifTrue:[
|
13
|
98 |
self error:'trying to create circular class definition'.
|
|
99 |
^ nil
|
|
100 |
]
|
|
101 |
].
|
68
|
102 |
].
|
13
|
103 |
|
68
|
104 |
newComment isNil ifTrue:[
|
|
105 |
newComment := oldClass comment
|
|
106 |
].
|
|
107 |
|
|
108 |
"
|
|
109 |
warn, if it exists with different category and different instvars,
|
|
110 |
and the existing is not an autoload class.
|
|
111 |
Usually, this indicates that someone wants to create a new class with
|
|
112 |
a name, which already exists (it happened a few times to myself, while
|
|
113 |
I wanted to create a new class called ReturnNode ...).
|
|
114 |
This will be much less of a problem, once multiple name spaces are
|
|
115 |
implemented and classes can be put into separate packages.
|
|
116 |
"
|
|
117 |
oldClass isLoaded ifTrue:[
|
|
118 |
oldClass category ~= categoryString ifTrue:[
|
|
119 |
oldClass instanceVariableString asCollectionOfWords
|
|
120 |
~= stringOfInstVarNames asCollectionOfWords ifTrue:[
|
|
121 |
(self confirm:'a class named ' , oldClass name , ' already exists -
|
|
122 |
|
|
123 |
create (i.e. change) anyway ?' withCRs)
|
|
124 |
ifFalse:[
|
|
125 |
^ nil
|
|
126 |
]
|
|
127 |
]
|
13
|
128 |
]
|
1
|
129 |
]
|
|
130 |
].
|
|
131 |
|
68
|
132 |
"
|
|
133 |
Check for some 'considered bad-style' things, like lower case names.
|
|
134 |
But only do these checks for new classes -
|
|
135 |
- thus, once confirmed, the warnings will not come again and again.
|
|
136 |
|
|
137 |
NOTICE:
|
|
138 |
I dont like the confirmers below - we need a notifying: argument, to give
|
44
|
139 |
the outer codeview a chance to highlight the error.
|
68
|
140 |
(but thats how its defined in the book - maybe I will change anyway).
|
|
141 |
"
|
44
|
142 |
|
|
143 |
oldClass isNil ifTrue:[
|
|
144 |
"let user confirm, if the classname is no good"
|
|
145 |
newName first isUppercase ifFalse:[
|
|
146 |
(self confirm:'classenames should start with an uppercase letter
|
68
|
147 |
(by convention only)
|
44
|
148 |
|
|
149 |
install anyway ?' withCRs)
|
|
150 |
ifFalse:[
|
|
151 |
^ nil
|
|
152 |
]
|
|
153 |
].
|
|
154 |
|
|
155 |
"let user confirm, if any instvarname is no good"
|
|
156 |
(stringOfInstVarNames asCollectionOfWords
|
|
157 |
inject:true
|
|
158 |
into:[:okSoFar :word |
|
|
159 |
okSoFar and:[word first isLowercase]
|
|
160 |
]
|
|
161 |
|
|
162 |
) ifFalse:[
|
|
163 |
(self confirm:'instance variable names should start with a lowercase letter
|
|
164 |
(by convention only)
|
|
165 |
|
|
166 |
install anyway ?' withCRs)
|
|
167 |
ifFalse:[
|
|
168 |
^ nil
|
|
169 |
]
|
|
170 |
].
|
|
171 |
|
|
172 |
"let user confirm, if any classvarname is no good"
|
|
173 |
(stringOfClassVarNames asCollectionOfWords
|
|
174 |
inject:true
|
|
175 |
into:[:okSoFar :word |
|
|
176 |
okSoFar and:[word first isUppercase]
|
|
177 |
]
|
|
178 |
|
|
179 |
) ifFalse:[
|
|
180 |
(self confirm:'class variable names should start with an uppercase letter
|
|
181 |
(by convention only)
|
|
182 |
|
|
183 |
install anyway ?' withCRs)
|
|
184 |
ifFalse:[
|
|
185 |
^ nil
|
|
186 |
]
|
|
187 |
]
|
|
188 |
].
|
|
189 |
|
1
|
190 |
"create the metaclass first"
|
|
191 |
newMetaclass := Metaclass new.
|
|
192 |
newMetaclass setSuperclass:(aClass class).
|
|
193 |
newMetaclass instSize:(aClass class instSize).
|
|
194 |
newMetaclass setName:(nameString , 'class').
|
|
195 |
newMetaclass classVariableString:'' "stringOfClassVarNames".
|
|
196 |
newMetaclass setComment:newComment category:categoryString.
|
|
197 |
|
68
|
198 |
"the let the meta create the class"
|
1
|
199 |
newClass := newMetaclass new.
|
|
200 |
newClass setSuperclass:aClass.
|
|
201 |
newClass instSize:(aClass instSize + nInstVars).
|
68
|
202 |
newClass setName:nameString.
|
1
|
203 |
|
68
|
204 |
"
|
|
205 |
Allowing non-booleans as variableBoolean
|
|
206 |
is a hack for backward (ST-80) compatibility:
|
|
207 |
|
|
208 |
ST-80 code will pass true or false as variableBoolean,
|
|
209 |
while ST/X also calls it with symbols such as #float, #double etc.
|
|
210 |
"
|
1
|
211 |
(variableBoolean == true) ifTrue:[
|
|
212 |
pointersBoolean ifTrue:[
|
68
|
213 |
newFlags := Behavior flagPointers
|
1
|
214 |
] ifFalse:[
|
|
215 |
wordsBoolean ifTrue:[
|
68
|
216 |
newFlags := Behavior flagWords
|
1
|
217 |
] ifFalse:[
|
68
|
218 |
newFlags := Behavior flagBytes
|
1
|
219 |
]
|
|
220 |
]
|
|
221 |
] ifFalse:[
|
|
222 |
(variableBoolean == #float) ifTrue:[
|
68
|
223 |
newFlags := Behavior flagFloats
|
1
|
224 |
] ifFalse:[
|
|
225 |
(variableBoolean == #double) ifTrue:[
|
68
|
226 |
newFlags := Behavior flagDoubles
|
1
|
227 |
] ifFalse:[
|
|
228 |
(variableBoolean == #long) ifTrue:[
|
68
|
229 |
newFlags := Behavior flagLongs
|
1
|
230 |
] ifFalse:[
|
68
|
231 |
newFlags := Behavior flagNotIndexed
|
1
|
232 |
]
|
|
233 |
]
|
|
234 |
].
|
|
235 |
].
|
68
|
236 |
superFlags := aClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits"
|
|
237 |
oldClass notNil ifTrue:[
|
|
238 |
oldClass isBuiltInClass ifTrue:[
|
|
239 |
"
|
|
240 |
special care when redefining Method, Block and other built-in classes,
|
|
241 |
which might have other flag bits ...
|
|
242 |
"
|
49
|
243 |
|
68
|
244 |
newFlags := newFlags bitOr:(oldClass flags bitAnd:(Behavior maskIndexType bitInvert))
|
|
245 |
]
|
|
246 |
].
|
|
247 |
newClass flags:(newFlags bitOr:superFlags). "preserve inherited special bits"
|
1
|
248 |
|
|
249 |
(nInstVars ~~ 0) ifTrue:[
|
|
250 |
newClass instanceVariableString:stringOfInstVarNames
|
|
251 |
].
|
|
252 |
oldClass notNil ifTrue:[
|
|
253 |
"setting first will make new class clear obsolete classvars"
|
|
254 |
newClass setClassVariableString:(oldClass classVariableString)
|
|
255 |
].
|
|
256 |
newClass classVariableString:stringOfClassVarNames.
|
|
257 |
|
68
|
258 |
"
|
|
259 |
for new classes, we are almost done here
|
|
260 |
"
|
2
|
261 |
oldClass isNil ifTrue:[
|
|
262 |
self addChangeRecordForClass:newClass.
|
1
|
263 |
|
|
264 |
commentString notNil ifTrue:[
|
|
265 |
newClass comment:commentString
|
2
|
266 |
].
|
68
|
267 |
|
2
|
268 |
aSystemDictionary at:classSymbol put:newClass.
|
68
|
269 |
aSystemDictionary changed.
|
2
|
270 |
^ newClass
|
|
271 |
].
|
|
272 |
|
10
|
273 |
|
68
|
274 |
"
|
|
275 |
here comes the hard part - we are actually changing the
|
|
276 |
definition of an existing class ....
|
|
277 |
Try hard to get away WITHOUT recompiling, since it makes all
|
|
278 |
compiled code into interpreted ...
|
|
279 |
"
|
|
280 |
|
10
|
281 |
oldInstVars := oldClass instanceVariableString asCollectionOfWords.
|
|
282 |
newInstVars := newClass instanceVariableString asCollectionOfWords.
|
|
283 |
oldClassVars := oldClass classVariableString asCollectionOfWords.
|
|
284 |
newClassVars := newClass classVariableString asCollectionOfWords.
|
|
285 |
|
68
|
286 |
"
|
|
287 |
we are on the bright side of life, if the instance layout and
|
|
288 |
inheritance do not change.
|
|
289 |
In this case, we can go ahead and patch the class object.
|
|
290 |
"
|
2
|
291 |
(oldClass superclass == newClass superclass) ifTrue:[
|
|
292 |
(oldClass instSize == newClass instSize) ifTrue:[
|
|
293 |
(oldClass flags == newClass flags) ifTrue:[
|
|
294 |
(oldClass name = newClass name) ifTrue:[
|
10
|
295 |
(oldInstVars = newInstVars) ifTrue:[
|
68
|
296 |
|
|
297 |
(newComment ~= oldClass comment) ifTrue:[
|
|
298 |
oldClass comment:newComment. "writes a change-chunk"
|
|
299 |
].
|
|
300 |
|
10
|
301 |
(oldClassVars = newClassVars) ifTrue:[
|
68
|
302 |
"
|
|
303 |
really no change (just comment and/or category)
|
|
304 |
"
|
10
|
305 |
anyChange := false.
|
|
306 |
|
|
307 |
oldClass instanceVariableString:(newClass instanceVariableString).
|
|
308 |
oldClass setClassVariableString:(newClass classVariableString).
|
|
309 |
|
2
|
310 |
oldClass category ~= categoryString ifTrue:[
|
|
311 |
"notify change of organization"
|
68
|
312 |
|
10
|
313 |
oldClass category:categoryString.
|
|
314 |
self addChangeRecordForClass:newClass.
|
68
|
315 |
aSystemDictionary changed
|
2
|
316 |
].
|
|
317 |
"notify change of class"
|
|
318 |
oldClass changed.
|
|
319 |
^ oldClass
|
33
|
320 |
].
|
|
321 |
|
68
|
322 |
"
|
|
323 |
when we arrive here, class variables have changed
|
|
324 |
"
|
33
|
325 |
oldClass category ~= categoryString ifTrue:[
|
|
326 |
"notify change of organization"
|
|
327 |
oldClass category:categoryString.
|
68
|
328 |
aSystemDictionary changed
|
33
|
329 |
].
|
|
330 |
|
68
|
331 |
"
|
|
332 |
set class variable string;
|
|
333 |
this also updates the set of class variables
|
|
334 |
by creating new / deleting obsolete ones.
|
|
335 |
"
|
33
|
336 |
oldClass classVariableString:stringOfClassVarNames.
|
|
337 |
|
68
|
338 |
"
|
|
339 |
get the set of changed class variables
|
|
340 |
"
|
33
|
341 |
changeSet1 := Set new.
|
|
342 |
oldClassVars do:[:nm |
|
|
343 |
(newClassVars includes:nm) ifFalse:[
|
|
344 |
changeSet1 add:nm
|
|
345 |
]
|
|
346 |
].
|
|
347 |
newClassVars do:[:nm |
|
|
348 |
(oldClassVars includes:nm) ifFalse:[
|
|
349 |
changeSet1 add:nm
|
|
350 |
]
|
|
351 |
].
|
|
352 |
|
68
|
353 |
"
|
|
354 |
recompile all methods accessing set of changed classvars
|
|
355 |
here and also in all subclasses ...
|
|
356 |
"
|
33
|
357 |
|
68
|
358 |
"
|
|
359 |
dont update change file for the recompilation
|
|
360 |
"
|
33
|
361 |
upd := Class updateChanges:false.
|
68
|
362 |
[
|
33
|
363 |
" "
|
68
|
364 |
Transcript showCr:'recompiling class & inst methods accessing ' , changeSet1 printString.
|
|
365 |
Transcript endEntry.
|
33
|
366 |
" "
|
68
|
367 |
oldClass withAllSubclasses do:[:aClass |
|
|
368 |
aClass class recompileMethodsAccessingAny:changeSet1.
|
|
369 |
aClass recompileMethodsAccessingAny:changeSet1.
|
|
370 |
].
|
|
371 |
] valueNowOrOnUnwindDo:[
|
|
372 |
Class updateChanges:upd.
|
33
|
373 |
].
|
|
374 |
|
|
375 |
"notify change of class"
|
|
376 |
self addChangeRecordForClass:oldClass.
|
|
377 |
oldClass changed.
|
|
378 |
|
|
379 |
^ oldClass
|
1
|
380 |
]
|
|
381 |
]
|
2
|
382 |
]
|
|
383 |
]
|
|
384 |
].
|
|
385 |
|
68
|
386 |
"tell dependents ..."
|
|
387 |
"OLD:
|
10
|
388 |
oldClass changed.
|
68
|
389 |
"
|
10
|
390 |
|
68
|
391 |
|
|
392 |
"
|
|
393 |
here we enter the darkness of mordor ...
|
|
394 |
"
|
2
|
395 |
|
|
396 |
(newComment ~= oldClass comment) ifTrue:[
|
|
397 |
newClass comment:newComment
|
|
398 |
].
|
|
399 |
|
|
400 |
superClassChange := oldClass superclass ~~ newClass superclass.
|
1
|
401 |
|
68
|
402 |
"
|
|
403 |
dont allow built-in classes to be modified this way
|
|
404 |
"
|
3
|
405 |
(oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[
|
|
406 |
self error:'the inheritance of this class is fixed - you cannot change it'.
|
|
407 |
^ oldClass
|
|
408 |
].
|
|
409 |
|
68
|
410 |
"
|
|
411 |
catch special case, where superclass changed its layout and thus
|
|
412 |
forced redefinition of this class;
|
|
413 |
only log if this is not the case.
|
|
414 |
"
|
2
|
415 |
(superClassChange
|
33
|
416 |
and:[(oldClass superclass isNil or:[oldClass superclass name = newClass superclass name])
|
|
417 |
and:[(oldClassVars = newClassVars)
|
|
418 |
and:[(oldInstVars = newInstVars)
|
|
419 |
and:[newComment = oldClass comment]]]]) ifFalse:[
|
|
420 |
self addChangeRecordForClass:newClass.
|
2
|
421 |
].
|
|
422 |
|
68
|
423 |
"
|
|
424 |
care for class methods ...
|
|
425 |
"
|
2
|
426 |
changeSet1 := Set new.
|
1
|
427 |
|
2
|
428 |
classVarChange := false.
|
|
429 |
|
|
430 |
superClassChange ifTrue:[
|
68
|
431 |
"
|
|
432 |
superclass changed:
|
|
433 |
must recompile all class methods accessing ANY classvar
|
|
434 |
(
|
|
435 |
actually, we could be less strict and handle the case where
|
|
436 |
both the old and the new superclass have a common ancestor,
|
|
437 |
and both have no new classvariables in between.
|
|
438 |
This would speedup the case when a class is inserted into
|
|
439 |
the inheritance chain.
|
|
440 |
)
|
|
441 |
"
|
1
|
442 |
|
2
|
443 |
oldClass allClassVarNames do:[:nm | changeSet1 add:nm].
|
|
444 |
newClass allClassVarNames do:[:nm | changeSet1 add:nm].
|
|
445 |
|
|
446 |
" "
|
|
447 |
Transcript showCr:'recompiling class methods accessing any classvar'.
|
68
|
448 |
Transcript endEntry.
|
2
|
449 |
" "
|
|
450 |
self copyInvalidatedMethodsFrom:(oldClass class) for:newMetaclass accessingAny:changeSet1.
|
|
451 |
newMetaclass recompileInvalidatedMethods.
|
|
452 |
] ifFalse:[
|
68
|
453 |
"
|
|
454 |
same superclass, find out which classvars have changed
|
|
455 |
"
|
10
|
456 |
classVarChange := oldClassVars ~= newClassVars.
|
2
|
457 |
classVarChange ifTrue:[
|
10
|
458 |
oldClassVars do:[:nm |
|
|
459 |
(newClassVars includes:nm) ifFalse:[
|
|
460 |
changeSet1 add:nm
|
|
461 |
]
|
|
462 |
].
|
|
463 |
newClassVars do:[:nm |
|
|
464 |
(oldClassVars includes:nm) ifFalse:[
|
|
465 |
changeSet1 add:nm
|
|
466 |
]
|
2
|
467 |
].
|
1
|
468 |
].
|
|
469 |
|
68
|
470 |
classVarChange ifTrue:[
|
|
471 |
"
|
|
472 |
must recompile some class-methods
|
|
473 |
"
|
2
|
474 |
" "
|
68
|
475 |
Transcript showCr:'recompiling class methods accessing ' , changeSet1 printString.
|
|
476 |
Transcript endEntry.
|
|
477 |
" "
|
2
|
478 |
self copyInvalidatedMethodsFrom:(oldClass class) for:newMetaclass accessingAny:changeSet1.
|
|
479 |
newMetaclass recompileInvalidatedMethods.
|
1
|
480 |
] ifFalse:[
|
68
|
481 |
"
|
|
482 |
class methods still work
|
|
483 |
"
|
1
|
484 |
self copyMethodsFrom:(oldClass class) for:newMetaclass
|
|
485 |
].
|
2
|
486 |
].
|
1
|
487 |
|
68
|
488 |
"
|
|
489 |
care for instance methods ...
|
|
490 |
"
|
|
491 |
changeSet2 := Set new.
|
|
492 |
|
2
|
493 |
superClassChange ifTrue:[
|
|
494 |
"superclass changed,
|
68
|
495 |
must recompile all methods accessing any class or instvar.
|
|
496 |
If number of instvars (i.e. the instances instSize) is the same,
|
|
497 |
we can limit the set of recompiled instance methods to those methods,
|
|
498 |
which refer to an instvar with a different inst-index
|
|
499 |
"
|
13
|
500 |
|
68
|
501 |
"
|
|
502 |
collect the instvar-indices in the old and new class
|
|
503 |
"
|
13
|
504 |
offset := 0. oldOffsets := Dictionary new.
|
33
|
505 |
oldClass allInstVarNames do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset].
|
13
|
506 |
offset := 0. newOffsets := Dictionary new.
|
|
507 |
newClass allInstVarNames do:[:nm | offset := offset + 1. newOffsets at:nm put:offset].
|
|
508 |
|
68
|
509 |
"
|
|
510 |
the changeset consists of instance variables,
|
|
511 |
whith a different position
|
|
512 |
"
|
13
|
513 |
oldOffsets associationsDo:[:a |
|
|
514 |
|k|
|
2
|
515 |
|
13
|
516 |
k := a key.
|
|
517 |
(newOffsets includesKey:k) ifFalse:[
|
|
518 |
changeSet2 add:k
|
|
519 |
] ifTrue:[
|
|
520 |
(a value ~~ (newOffsets at:k)) ifTrue:[
|
|
521 |
changeSet2 add:k
|
|
522 |
]
|
|
523 |
]
|
|
524 |
].
|
|
525 |
newOffsets associationsDo:[:a |
|
|
526 |
|k|
|
|
527 |
|
|
528 |
k := a key.
|
|
529 |
(oldOffsets includesKey:k) ifFalse:[
|
|
530 |
changeSet2 add:k
|
|
531 |
] ifTrue:[
|
|
532 |
(a value ~~ (oldOffsets at:k)) ifTrue:[
|
|
533 |
changeSet2 add:k
|
|
534 |
]
|
|
535 |
]
|
|
536 |
].
|
|
537 |
|
68
|
538 |
"
|
|
539 |
merge in the changed class variables
|
|
540 |
"
|
13
|
541 |
changeSet1 do:[:nm | changeSet2 add:nm].
|
68
|
542 |
|
13
|
543 |
" "
|
68
|
544 |
Transcript showCr:'recompiling instance methods accessing ' , changeSet2 printString , ' ...'.
|
|
545 |
Transcript endEntry.
|
13
|
546 |
" "
|
|
547 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet2.
|
|
548 |
newClass recompileInvalidatedMethods.
|
|
549 |
|
2
|
550 |
] ifFalse:[
|
68
|
551 |
"
|
|
552 |
same inheritance ...
|
|
553 |
"
|
10
|
554 |
instVarChange := oldInstVars ~= newInstVars.
|
2
|
555 |
instVarChange ifFalse:[
|
68
|
556 |
"
|
|
557 |
same instance variables ...
|
|
558 |
"
|
2
|
559 |
classVarChange ifTrue:[
|
68
|
560 |
"recompile all inst methods accessing changed classvars"
|
1
|
561 |
|
2
|
562 |
" "
|
|
563 |
Transcript showCr:'recompiling instance methods accessing ' , changeSet1 printString , ' ...'.
|
68
|
564 |
Transcript endEntry.
|
2
|
565 |
" "
|
|
566 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet1.
|
|
567 |
newClass recompileInvalidatedMethods.
|
|
568 |
]
|
|
569 |
] ifTrue:[
|
68
|
570 |
"
|
|
571 |
dont allow built-in classes to be modified
|
|
572 |
"
|
3
|
573 |
(oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[
|
|
574 |
self error:'the layout of this class is fixed - you cannot change it'.
|
|
575 |
^ oldClass
|
|
576 |
].
|
|
577 |
|
68
|
578 |
((oldInstVars size == 0)
|
|
579 |
or:[newInstVars startsWith:oldInstVars]) ifTrue:[
|
|
580 |
"
|
|
581 |
only new inst variable(s) has/have been added -
|
|
582 |
old methods still work (the existing inst-indices are still valid)
|
|
583 |
"
|
|
584 |
" "
|
|
585 |
Transcript showCr:'copying methods ...'.
|
|
586 |
Transcript endEntry.
|
|
587 |
" "
|
|
588 |
self copyMethodsFrom:oldClass for:newClass.
|
2
|
589 |
|
68
|
590 |
"
|
|
591 |
but: we have to recompile all methods accessing new instars
|
|
592 |
(it might have been a classVar/global before ...)
|
|
593 |
"
|
|
594 |
addedNames := newInstVars select:[:nm | (oldInstVars includes:nm) not].
|
|
595 |
"merge in class variables"
|
|
596 |
changeSet1 do:[:nm | addedNames add:nm].
|
1
|
597 |
|
2
|
598 |
" "
|
68
|
599 |
Transcript showCr:'recompiling instance methods accessing ' , addedNames printString , '...'.
|
|
600 |
Transcript endEntry.
|
2
|
601 |
" "
|
68
|
602 |
newClass recompileMethodsAccessingAny:addedNames.
|
|
603 |
] ifFalse:[
|
|
604 |
"
|
|
605 |
collect the instvar-indices in the old and new class
|
|
606 |
"
|
|
607 |
offset := 0. oldOffsets := Dictionary new.
|
|
608 |
oldInstVars do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset].
|
|
609 |
offset := 0. newOffsets := Dictionary new.
|
|
610 |
newInstVars do:[:nm | offset := offset + 1. newOffsets at:nm put:offset].
|
2
|
611 |
|
68
|
612 |
"
|
|
613 |
the changeset consists of instance variables,
|
|
614 |
whith a different position
|
|
615 |
"
|
|
616 |
oldOffsets associationsDo:[:a |
|
|
617 |
|k|
|
1
|
618 |
|
68
|
619 |
k := a key.
|
|
620 |
(newOffsets includesKey:k) ifFalse:[
|
|
621 |
changeSet2 add:k
|
|
622 |
] ifTrue:[
|
|
623 |
(a value ~~ (newOffsets at:k)) ifTrue:[
|
2
|
624 |
changeSet2 add:k
|
|
625 |
]
|
68
|
626 |
]
|
|
627 |
].
|
|
628 |
newOffsets associationsDo:[:a |
|
|
629 |
|k|
|
1
|
630 |
|
68
|
631 |
k := a key.
|
|
632 |
(oldOffsets includesKey:k) ifFalse:[
|
|
633 |
changeSet2 add:k
|
|
634 |
] ifTrue:[
|
|
635 |
(a value ~~ (oldOffsets at:k)) ifTrue:[
|
2
|
636 |
changeSet2 add:k
|
|
637 |
]
|
68
|
638 |
]
|
|
639 |
].
|
|
640 |
"merge in class variables"
|
|
641 |
changeSet1 do:[:nm | changeSet2 add:nm].
|
2
|
642 |
" "
|
68
|
643 |
Transcript showCr:'recompiling instance methods accessing ' , changeSet2 printString , ' ...'.
|
|
644 |
Transcript endEntry.
|
2
|
645 |
" "
|
68
|
646 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet2.
|
|
647 |
newClass recompileInvalidatedMethods.
|
2
|
648 |
].
|
|
649 |
].
|
|
650 |
].
|
1
|
651 |
|
68
|
652 |
"
|
|
653 |
WOW, everything done for this class
|
|
654 |
what about subclasses ?
|
|
655 |
"
|
2
|
656 |
|
68
|
657 |
"
|
|
658 |
get list of all subclasses - do this before superclass is changed
|
|
659 |
"
|
|
660 |
"no longer needed"
|
|
661 |
"
|
|
662 |
allSubclasses := oldClass allSubclasses.
|
|
663 |
"
|
2
|
664 |
|
68
|
665 |
"
|
|
666 |
update superclass of immediate subclasses -
|
|
667 |
this forces recompilation (recursively) if needed
|
|
668 |
(dont update change file for the subclass changes)
|
|
669 |
"
|
13
|
670 |
upd := Class updateChanges:false.
|
|
671 |
[
|
|
672 |
oldClass subclassesDo:[:aClass |
|
2
|
673 |
" "
|
13
|
674 |
Transcript showCr:'changing superclass of:' , aClass name.
|
68
|
675 |
Transcript endEntry.
|
2
|
676 |
" "
|
13
|
677 |
aClass superclass:newClass
|
|
678 |
]
|
|
679 |
] valueNowOrOnUnwindDo:[
|
|
680 |
Class updateChanges:upd.
|
2
|
681 |
].
|
|
682 |
|
68
|
683 |
"
|
|
684 |
change category in oldClass - so we see immediately what it is ...
|
|
685 |
"
|
|
686 |
oldClass category:'obsolete'.
|
|
687 |
oldClass class category:'obsolete'.
|
|
688 |
|
|
689 |
"
|
|
690 |
and make the new class globally known
|
|
691 |
"
|
2
|
692 |
aSystemDictionary at:classSymbol put:newClass.
|
68
|
693 |
|
|
694 |
oldClass category ~= categoryString ifTrue:[
|
|
695 |
"notify change of organization"
|
|
696 |
aSystemDictionary changed
|
|
697 |
].
|
|
698 |
|
|
699 |
"
|
|
700 |
Not becoming the old class creates some update problems;
|
|
701 |
the browsers must check carefully - a simple identity compare is
|
|
702 |
not enought ...
|
|
703 |
QUESTION: is this a good idea ?
|
|
704 |
"
|
|
705 |
|
|
706 |
newClass dependents:(oldClass dependents).
|
|
707 |
newClass changed.
|
|
708 |
|
|
709 |
"just to make certain ..."
|
|
710 |
oldClass changed.
|
|
711 |
|
2
|
712 |
ObjectMemory flushCaches.
|
68
|
713 |
|
1
|
714 |
^ newClass
|
|
715 |
!
|
|
716 |
|
|
717 |
new
|
2
|
718 |
"create & return a new metaclass (a classes class)"
|
|
719 |
|
1
|
720 |
|newClass|
|
|
721 |
|
|
722 |
newClass := self basicNew.
|
|
723 |
newClass setSuperclass:(Object class)
|
|
724 |
selectors:(Array new:0)
|
|
725 |
methods:(Array new:0)
|
|
726 |
instSize:0
|
|
727 |
flags:0.
|
|
728 |
newClass setComment:(self comment) category:(self category).
|
|
729 |
^ newClass
|
|
730 |
! !
|
|
731 |
|
|
732 |
!Metaclass methodsFor:'class instance variables'!
|
|
733 |
|
|
734 |
instanceVariableNames:aString
|
|
735 |
"changing / adding class-inst vars -
|
2
|
736 |
this actually creates a new metaclass and class."
|
1
|
737 |
|
|
738 |
|newClass newMetaclass nClassInstVars oldClass
|
2
|
739 |
allSubclasses t oldVars
|
|
740 |
oldNames newNames addedNames
|
|
741 |
oldOffsets newOffsets offset changeSet delta
|
|
742 |
oldToNew newSubMeta newSub oldSubMeta oldSuper|
|
1
|
743 |
|
68
|
744 |
"
|
|
745 |
cleanup needed here: extract common things with name:inEnvironment:...
|
|
746 |
and restructure things ... currently way too complex.
|
|
747 |
"
|
44
|
748 |
|
1
|
749 |
oldVars := self instanceVariableString.
|
2
|
750 |
aString = oldVars ifTrue:[
|
|
751 |
"
|
|
752 |
Transcript showCr:'no change (', oldVars , ') -> (', aString , ')'.
|
|
753 |
"
|
|
754 |
^ self
|
|
755 |
].
|
|
756 |
|
|
757 |
oldNames := oldVars asCollectionOfWords.
|
|
758 |
newNames := aString asCollectionOfWords.
|
1
|
759 |
|
2
|
760 |
oldNames = newNames ifTrue:[
|
|
761 |
"
|
|
762 |
Transcript showCr:'no real change'.
|
|
763 |
"
|
|
764 |
"no real change (just formatting)"
|
|
765 |
self instanceVariableString:aString.
|
|
766 |
^ self
|
|
767 |
].
|
|
768 |
|
68
|
769 |
"
|
|
770 |
let user confirm, if any name is no good (and was good before)
|
|
771 |
"
|
44
|
772 |
(oldNames inject:true
|
68
|
773 |
into:[:okSoFar :word |
|
44
|
774 |
okSoFar and:[word first isUppercase]
|
|
775 |
])
|
|
776 |
ifTrue:[
|
|
777 |
"was ok before"
|
|
778 |
(newNames inject:true
|
68
|
779 |
into:[:okSoFar :word |
|
44
|
780 |
okSoFar and:[word first isUppercase]
|
|
781 |
])
|
|
782 |
ifFalse:[
|
|
783 |
(self confirm:'class instance variable names should start with an uppercase letter
|
|
784 |
(by convention only)
|
|
785 |
|
|
786 |
install anyway ?' withCRs)
|
|
787 |
ifFalse:[
|
|
788 |
^ nil
|
|
789 |
]
|
|
790 |
]
|
|
791 |
].
|
|
792 |
|
2
|
793 |
nClassInstVars := newNames size.
|
|
794 |
|
|
795 |
"
|
|
796 |
Transcript showCr:'create new class/metaclass'.
|
|
797 |
"
|
1
|
798 |
|
|
799 |
"create the new metaclass"
|
|
800 |
newMetaclass := Metaclass new.
|
|
801 |
newMetaclass setSuperclass:superclass.
|
|
802 |
newMetaclass instSize:(superclass instSize + nClassInstVars).
|
|
803 |
(nClassInstVars ~~ 0) ifTrue:[
|
|
804 |
newMetaclass instanceVariableString:aString
|
|
805 |
].
|
|
806 |
newMetaclass flags:0. "not indexed"
|
|
807 |
newMetaclass setName:name.
|
|
808 |
newMetaclass classVariableString:classvars.
|
|
809 |
newMetaclass category:category.
|
|
810 |
newMetaclass setComment:comment.
|
|
811 |
|
|
812 |
"find the class which is my sole instance"
|
|
813 |
|
|
814 |
t := Smalltalk allClasses select:[:element | element class == self].
|
|
815 |
(t size ~~ 1) ifTrue:[
|
|
816 |
self error:'oops - I should have exactly one instance'.
|
|
817 |
^ nil
|
|
818 |
].
|
|
819 |
oldClass := t anElement.
|
|
820 |
|
|
821 |
"create a new class"
|
|
822 |
newClass := newMetaclass new.
|
|
823 |
newClass setSuperclass:(oldClass superclass).
|
|
824 |
newClass instSize:(oldClass instSize).
|
|
825 |
newClass flags:(oldClass flags).
|
|
826 |
newClass setName:(oldClass name).
|
|
827 |
newClass instanceVariableString:(oldClass instanceVariableString).
|
|
828 |
newClass classVariableString:(oldClass classVariableString).
|
2
|
829 |
newClass setComment:(oldClass comment).
|
1
|
830 |
newClass category:(oldClass category).
|
|
831 |
|
2
|
832 |
offset := 0. oldOffsets := Dictionary new.
|
|
833 |
oldNames do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset].
|
|
834 |
offset := 0. newOffsets := Dictionary new.
|
|
835 |
newNames do:[:nm | offset := offset + 1. newOffsets at:nm put:offset].
|
|
836 |
changeSet := Set new.
|
1
|
837 |
|
2
|
838 |
oldOffsets associationsDo:[:a |
|
10
|
839 |
|k|
|
|
840 |
|
|
841 |
k := a key.
|
|
842 |
(newOffsets includesKey:k) ifFalse:[
|
|
843 |
changeSet add:k
|
2
|
844 |
] ifTrue:[
|
10
|
845 |
(a value ~~ (newOffsets at:k)) ifTrue:[
|
|
846 |
changeSet add:k
|
2
|
847 |
]
|
|
848 |
]
|
|
849 |
].
|
|
850 |
newOffsets associationsDo:[:a |
|
10
|
851 |
|k|
|
|
852 |
|
|
853 |
k := a key.
|
|
854 |
(oldOffsets includesKey:k) ifFalse:[
|
|
855 |
changeSet add:k
|
2
|
856 |
] ifTrue:[
|
10
|
857 |
(a value ~~ (oldOffsets at:k)) ifTrue:[
|
|
858 |
changeSet add:k
|
2
|
859 |
]
|
|
860 |
]
|
|
861 |
].
|
1
|
862 |
|
2
|
863 |
((oldNames size == 0)
|
|
864 |
or:[newNames startsWith:oldNames]) ifTrue:[
|
|
865 |
"new variable(s) has/have been added - old methods still work"
|
|
866 |
|
68
|
867 |
" "
|
2
|
868 |
Transcript showCr:'copying methods ...'.
|
68
|
869 |
Transcript endEntry.
|
|
870 |
" "
|
1
|
871 |
self copyMethodsFrom:self for:newMetaclass.
|
2
|
872 |
self copyMethodsFrom:oldClass for:newClass.
|
|
873 |
|
|
874 |
"but have to recompile methods accessing stuff now defined
|
|
875 |
(it might have been a global before ...)"
|
|
876 |
|
|
877 |
addedNames := newNames select:[:nm | (oldNames includes:nm) not].
|
|
878 |
"
|
68
|
879 |
Transcript showCr:'recompiling methods accessing ' , addedNames printString , '...'.
|
|
880 |
Transcript endEntry.
|
2
|
881 |
"
|
1
|
882 |
"recompile class-methods"
|
2
|
883 |
newMetaclass recompileMethodsAccessingAny:addedNames.
|
|
884 |
] ifFalse:[
|
|
885 |
"
|
68
|
886 |
Transcript showCr:'recompiling methods accessing ' , changeSet printString , ' ...'.
|
|
887 |
Transcript endEntry.
|
2
|
888 |
"
|
|
889 |
"recompile class-methods"
|
|
890 |
self copyInvalidatedMethodsFrom:self for:newMetaclass accessingAny:changeSet.
|
|
891 |
newMetaclass recompileInvalidatedMethods.
|
1
|
892 |
|
2
|
893 |
self copyMethodsFrom:oldClass for:newClass.
|
1
|
894 |
].
|
|
895 |
|
2
|
896 |
delta := newNames size - oldNames size.
|
|
897 |
|
68
|
898 |
"
|
|
899 |
get list of all subclasses - do before superclass is changed
|
|
900 |
"
|
1
|
901 |
allSubclasses := oldClass allSubclasses.
|
2
|
902 |
allSubclasses := allSubclasses asSortedCollection:[:a :b |
|
|
903 |
b isSubclassOf:a
|
|
904 |
].
|
1
|
905 |
|
2
|
906 |
oldToNew := IdentityDictionary new.
|
|
907 |
|
|
908 |
"create a new class tree, based on new version"
|
|
909 |
|
|
910 |
allSubclasses do:[:aSubclass |
|
|
911 |
oldSuper := aSubclass superclass.
|
|
912 |
oldSubMeta := aSubclass class.
|
1
|
913 |
|
2
|
914 |
newSubMeta := Metaclass new.
|
|
915 |
oldSuper == oldClass ifTrue:[
|
|
916 |
newSubMeta setSuperclass:newMetaclass.
|
|
917 |
] ifFalse:[
|
|
918 |
newSubMeta setSuperclass:(oldToNew at:oldSuper) class.
|
|
919 |
].
|
|
920 |
newSubMeta instSize:(oldSubMeta instSize + delta).
|
|
921 |
newSubMeta flags:(oldSubMeta flags).
|
|
922 |
newSubMeta setName:(oldSubMeta name).
|
|
923 |
newSubMeta classVariableString:(oldSubMeta classVariableString).
|
|
924 |
newSubMeta setComment:(oldSubMeta comment).
|
|
925 |
newSubMeta category:(oldSubMeta category).
|
|
926 |
|
|
927 |
newSub := newSubMeta new.
|
|
928 |
oldSuper == oldClass ifTrue:[
|
|
929 |
newSub setSuperclass:newClass.
|
|
930 |
] ifFalse:[
|
|
931 |
newSub setSuperclass:(oldToNew at:oldSuper).
|
|
932 |
].
|
68
|
933 |
newSub setSelectors:(aSubclass selectorArray).
|
|
934 |
newSub setMethodDictionary:(aSubclass methodArray).
|
2
|
935 |
newSub setName:(aSubclass name).
|
|
936 |
newSub classVariableString:(aSubclass classVariableString).
|
|
937 |
newSub setComment:(aSubclass comment).
|
|
938 |
newSub category:(aSubclass category).
|
|
939 |
|
|
940 |
oldToNew at:aSubclass put:newSub.
|
|
941 |
|
68
|
942 |
"
|
2
|
943 |
aSubclass setName:(aSubclass name , '-old').
|
|
944 |
aSubclass category:'obsolete classes'
|
68
|
945 |
"
|
|
946 |
aSubclass category:'obsolete'.
|
|
947 |
aSubclass class category:'obsolete'.
|
1
|
948 |
].
|
|
949 |
|
2
|
950 |
"recompile what needs to be"
|
|
951 |
|
|
952 |
delta == 0 ifTrue:[
|
|
953 |
"only have to recompile class methods accessing
|
68
|
954 |
class instvars from changeset
|
|
955 |
"
|
1
|
956 |
|
2
|
957 |
allSubclasses do:[:aClass |
|
|
958 |
aClass class recompileMethodsAccessingAny:changeSet.
|
|
959 |
]
|
|
960 |
] ifFalse:[
|
68
|
961 |
"
|
|
962 |
have to recompile all class methods accessing class instvars
|
|
963 |
"
|
2
|
964 |
|
|
965 |
allSubclasses do:[:aClass |
|
|
966 |
|classInstVars|
|
|
967 |
|
|
968 |
classInstVars := aClass class allInstVarNames.
|
|
969 |
aClass class recompileMethodsAccessingAny:classInstVars.
|
|
970 |
]
|
1
|
971 |
].
|
|
972 |
|
2
|
973 |
self addChangeRecordForClassInstvars:newClass.
|
|
974 |
|
|
975 |
"install all new classes"
|
|
976 |
|
|
977 |
Smalltalk at:(oldClass name asSymbol) put:newClass.
|
|
978 |
ObjectMemory flushCachesFor:oldClass.
|
|
979 |
allSubclasses do:[:aClass |
|
|
980 |
Smalltalk at:(oldToNew at:aClass) name asSymbol put:(oldToNew at:aClass).
|
|
981 |
ObjectMemory flushCachesFor:aClass.
|
|
982 |
].
|
|
983 |
|
68
|
984 |
"tell dependents ..."
|
10
|
985 |
|
2
|
986 |
oldClass changed.
|
|
987 |
self changed.
|
68
|
988 |
|
1
|
989 |
^ newMetaclass
|
|
990 |
! !
|
|
991 |
|
|
992 |
!Metaclass methodsFor:'queries'!
|
|
993 |
|
|
994 |
isMeta
|
|
995 |
"return true, if the receiver is some kind of metaclass;
|
|
996 |
true is returned here. Redefines isMeta in Object"
|
|
997 |
|
|
998 |
^ true
|
|
999 |
! !
|
|
1000 |
|
|
1001 |
!Metaclass methodsFor:'private'!
|
|
1002 |
|
68
|
1003 |
invalidMethod
|
|
1004 |
"When recompiling classes after a definition-change, all
|
|
1005 |
uncompilable methods will be bound to this method here,
|
|
1006 |
so that evaluating such an uncompilable method will trigger an error.
|
|
1007 |
Can also happen when Compiler/runtime system is broken."
|
|
1008 |
|
|
1009 |
self error:'invalid method - this method failed to compile when the class was changed'
|
|
1010 |
!
|
|
1011 |
|
1
|
1012 |
copyMethodsFrom:oldClass for:newClass
|
|
1013 |
"when a class has changed, but metaclass is unaffected (i.e. classVars
|
|
1014 |
have not changed) there is no need to recompile them"
|
|
1015 |
|
68
|
1016 |
newClass selectors:(oldClass selectorArray copy)
|
|
1017 |
methods:(oldClass methodArray copy)
|
1
|
1018 |
!
|
|
1019 |
|
|
1020 |
copyInvalidatedMethodsFrom:oldClass for:newClass
|
|
1021 |
"when a class has been changed, copy all old methods into the new class
|
|
1022 |
- changing code to a trap method giving an error message;
|
|
1023 |
this allows us to keep the source while trapping uncompilable (due to
|
|
1024 |
now undefined instvars) methods"
|
|
1025 |
|
2
|
1026 |
|trap trapCode trapByteCode newMethod oldMethodArray newMethodArray|
|
1
|
1027 |
|
68
|
1028 |
trap := Metaclass compiledMethodAt:#invalidMethod.
|
1
|
1029 |
trapCode := trap code.
|
|
1030 |
trapByteCode := trap byteCode.
|
|
1031 |
|
68
|
1032 |
oldMethodArray := oldClass methodArray.
|
2
|
1033 |
newMethodArray := Array new:(oldMethodArray size).
|
68
|
1034 |
newClass selectors:(oldClass selectorArray copy)
|
|
1035 |
methods:newMethodArray.
|
2
|
1036 |
1 to:oldMethodArray size do:[:i |
|
|
1037 |
newMethod := (oldMethodArray at:i) copy.
|
|
1038 |
newMethod code:trapCode.
|
|
1039 |
newMethod literals:nil.
|
|
1040 |
newMethod byteCode:trapByteCode.
|
|
1041 |
newMethodArray at:i put:newMethod
|
|
1042 |
]
|
|
1043 |
!
|
|
1044 |
|
|
1045 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames
|
|
1046 |
"copy all methods from oldClass to newClass. Those methods accessing
|
|
1047 |
a variable in setOfNames will be copied as invalid method, leading to
|
|
1048 |
a trap when its executed."
|
|
1049 |
|
|
1050 |
|trap trapCode trapByteCode p oldMethod newMethod oldMethodArray newMethodArray|
|
|
1051 |
|
68
|
1052 |
trap := Metaclass compiledMethodAt:#invalidMethod.
|
2
|
1053 |
trapCode := trap code.
|
|
1054 |
trapByteCode := trap byteCode.
|
|
1055 |
|
68
|
1056 |
oldMethodArray := oldClass methodArray.
|
2
|
1057 |
newMethodArray := Array new:(oldMethodArray size).
|
68
|
1058 |
newClass selectors:(oldClass selectorArray copy)
|
|
1059 |
methods:newMethodArray.
|
2
|
1060 |
1 to:oldMethodArray size do:[:i |
|
|
1061 |
oldMethod := oldMethodArray at:i.
|
|
1062 |
p := Parser parseMethod:(oldMethod source) in:newClass.
|
|
1063 |
(p isNil or:[p usedVars notNil and:[p usedVars includesAny:setOfNames]]) ifTrue:[
|
|
1064 |
newMethod := oldMethod copy.
|
|
1065 |
newMethod code:trapCode.
|
|
1066 |
newMethod literals:nil.
|
|
1067 |
newMethod byteCode:trapByteCode
|
|
1068 |
] ifFalse:[
|
|
1069 |
newMethod := oldMethod.
|
|
1070 |
].
|
|
1071 |
newMethodArray at:i put:newMethod
|
1
|
1072 |
]
|
|
1073 |
!
|
|
1074 |
|
|
1075 |
anyInvalidatedMethodsIn:aClass
|
|
1076 |
"return true, if aClass has any invalidated methods in it"
|
|
1077 |
|
|
1078 |
|trap trapCode trapByteCode|
|
|
1079 |
|
68
|
1080 |
trap := Metaclass compiledMethodAt:#invalidMethod.
|
1
|
1081 |
trapCode := trap code.
|
|
1082 |
trapByteCode := trap byteCode.
|
|
1083 |
|
68
|
1084 |
aClass methodArray do:[:aMethod |
|
1
|
1085 |
trapCode notNil ifTrue:[
|
|
1086 |
(aMethod code == trapCode) ifTrue:[^ true]
|
|
1087 |
].
|
|
1088 |
trapByteCode notNil ifTrue:[
|
|
1089 |
(aMethod byteCode == trapByteCode) ifTrue:[^ true]
|
|
1090 |
]
|
|
1091 |
].
|
|
1092 |
^ false
|
|
1093 |
! !
|