author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:47:14 +0200 | |
changeset 1292 | 89497fff7f87 |
parent 1266 | cef9b3cd49df |
child 1392 | 63bfe7f167e6 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
|
1047 | 14 |
instanceVariableNames:'myClass' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Classes' |
|
1 | 18 |
! |
19 |
||
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
20 |
!Metaclass class methodsFor:'documentation'! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
21 |
|
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
621 | 34 |
! |
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
every classes class is a subclass of Metaclass. |
|
39 |
(i.e. every class is the sole instance of its Metaclass) |
|
40 |
Metaclass provides support for creating new (sub)classes and/or |
|
41 |
changing the definition of an already existing class. |
|
1292 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
621 | 45 |
" |
88 | 46 |
! ! |
1 | 47 |
|
356 | 48 |
!Metaclass class methodsFor:'creating metaclasses'! |
49 |
||
50 |
new |
|
51 |
"creating a new metaclass - have to set the new classes |
|
52 |
flags correctly to have it behave like a metaclass ... |
|
53 |
Not for normal applications - creating new metaclasses is a very |
|
54 |
tricky thing; should be left to the gurus ;-)" |
|
55 |
||
56 |
|newMetaclass| |
|
57 |
||
58 |
newMetaclass := super new. |
|
59 |
newMetaclass instSize:(Class instSize). |
|
60 |
newMetaclass setSuperclass:Class. |
|
61 |
||
62 |
^ newMetaclass |
|
63 |
||
64 |
" |
|
65 |
Metaclass new <- new metaclass |
|
66 |
Metaclass new new <- new class |
|
67 |
Metaclass new new new <- new instance |
|
68 |
" |
|
69 |
! ! |
|
70 |
||
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
71 |
!Metaclass class methodsFor:'queries'! |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
72 |
|
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
73 |
isBuiltInClass |
1266 | 74 |
"return true if this class is known by the run-time-system. |
75 |
Here, true is returned for myself, false for subclasses." |
|
76 |
||
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
77 |
^ self == Metaclass class or:[self == Metaclass] |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
78 |
|
1266 | 79 |
"Modified: 23.4.1996 / 15:59:44 / cg" |
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
80 |
! ! |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
81 |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
82 |
!Metaclass methodsFor:'accessing'! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
83 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
84 |
name |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
85 |
"return my name - that is the name of my sole class, with 'class' |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
86 |
appended. Currently, this is incompatible to ST-80 (which appends ' class') |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
87 |
and will be changed (have to check for side effects first ...)" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
88 |
|
682
a10f434805a7
be somewhat more robust against bad classnames ...
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
89 |
|nm| |
a10f434805a7
be somewhat more robust against bad classnames ...
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
90 |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
91 |
myClass isNil ifTrue:[ |
1087 | 92 |
^ 'someMetaclass' |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
93 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
94 |
"/ ^ myClass name , ' class' |
682
a10f434805a7
be somewhat more robust against bad classnames ...
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
95 |
|
a10f434805a7
be somewhat more robust against bad classnames ...
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
96 |
(nm := myClass name) isNil ifTrue:[ |
1087 | 97 |
'METACLASS: oops - no name in my class' errorPrintNL. |
98 |
name notNil ifTrue:[ |
|
99 |
^ name |
|
100 |
]. |
|
682
a10f434805a7
be somewhat more robust against bad classnames ...
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
101 |
]. |
a10f434805a7
be somewhat more robust against bad classnames ...
Claus Gittinger <cg@exept.de>
parents:
657
diff
changeset
|
102 |
^ nm , 'class' |
1087 | 103 |
|
104 |
"Modified: 7.3.1996 / 19:18:53 / cg" |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
105 |
! ! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
106 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
107 |
!Metaclass methodsFor:'class instance variables'! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
108 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
109 |
instanceVariableNames:aString |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
110 |
"changing / adding class-inst vars - |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
111 |
this actually creates a new metaclass and class, leaving the original |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
112 |
classes around as obsolete classes. This may also be true for all subclasses, |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
113 |
if class instance variables are added/removed. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
114 |
Existing instances continue to be defined by their original classes. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
115 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
116 |
Time will show, if this is an acceptable behavior or if we should migrate |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
117 |
instances to become insts. of the new classes." |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
118 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
119 |
|newClass newMetaclass nClassInstVars oldClass |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
120 |
allSubclasses oldVars |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
121 |
oldNames newNames addedNames |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
122 |
oldOffsets newOffsets offset changeSet delta |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
123 |
oldToNew newSubMeta newSub oldSubMeta oldSuper |
986 | 124 |
commonClassInstVars t| |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
125 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
126 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
127 |
cleanup needed here: extract common things with name:inEnvironment:... |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
128 |
and restructure things ... currently way too complex. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
129 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
130 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
131 |
oldVars := self instanceVariableString. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
132 |
aString = oldVars ifTrue:[ |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
133 |
" |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
134 |
Transcript showCr:'no change (', oldVars , ') -> (', aString , ')'. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
135 |
" |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
136 |
^ self |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
137 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
138 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
139 |
oldNames := oldVars asCollectionOfWords. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
140 |
newNames := aString asCollectionOfWords. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
141 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
142 |
oldNames = newNames ifTrue:[ |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
143 |
" |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
144 |
Transcript showCr:'no real change'. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
145 |
" |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
146 |
"no real change (just formatting)" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
147 |
self setInstanceVariableString:aString. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
148 |
^ self |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
149 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
150 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
151 |
"/ " |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
152 |
"/ let user confirm, if any name is no good (and was good before) |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
153 |
"/ " |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
154 |
"/ (oldNames inject:true |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
155 |
"/ into:[:okSoFar :word | |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
156 |
"/ okSoFar and:[word first isUppercase] |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
157 |
"/ ]) |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
158 |
"/ ifTrue:[ |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
159 |
"/ "was ok before" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
160 |
"/ (newNames inject:true |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
161 |
"/ into:[:okSoFar :word | |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
162 |
"/ okSoFar and:[word first isUppercase] |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
163 |
"/ ]) |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
164 |
"/ ifFalse:[ |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
165 |
"/ (self confirm:'class instance variable names should start with an uppercase letter |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
166 |
"/(by convention only) |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
167 |
"/ |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
168 |
"/install anyway ?' withCRs) |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
169 |
"/ ifFalse:[ |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
170 |
"/ ^ nil |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
171 |
"/ ] |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
172 |
"/ ] |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
173 |
"/ ]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
174 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
175 |
nClassInstVars := newNames size. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
176 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
177 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
178 |
Transcript showCr:'create new class/metaclass'. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
179 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
180 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
181 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
182 |
create the new metaclass |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
183 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
184 |
newMetaclass := Metaclass new. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
185 |
newMetaclass setSuperclass:superclass. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
186 |
newMetaclass instSize:(superclass instSize + nClassInstVars). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
187 |
(nClassInstVars ~~ 0) ifTrue:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
188 |
newMetaclass setInstanceVariableString:aString |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
189 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
190 |
"/ newMetaclass flags:(Behavior flagBehavior "flagNotIndexed"). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
191 |
newMetaclass setName:name. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
192 |
newMetaclass classVariableString:classvars. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
193 |
newMetaclass category:category. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
194 |
newMetaclass setComment:(self comment). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
195 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
196 |
"find the class which is my sole instance" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
197 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
198 |
t := Smalltalk allClasses select:[:element | element class == self]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
199 |
(t size ~~ 1) ifTrue:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
200 |
self error:'oops - I should have exactly one instance'. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
201 |
^ nil |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
202 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
203 |
oldClass := t anElement. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
204 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
205 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
206 |
create the new class |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
207 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
208 |
newClass := newMetaclass new. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
209 |
newClass setSuperclass:(oldClass superclass). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
210 |
newClass instSize:(oldClass instSize). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
211 |
newClass flags:(oldClass flags). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
212 |
newClass setName:(oldClass name). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
213 |
newClass setInstanceVariableString:(oldClass instanceVariableString). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
214 |
newClass classVariableString:(oldClass classVariableString). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
215 |
newClass setComment:(oldClass comment). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
216 |
newClass category:(oldClass category). |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
217 |
(t := oldClass primitiveSpec) notNil ifTrue:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
218 |
newClass primitiveSpec:t. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
219 |
newClass setClassFilename:(oldClass classFilename). |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
220 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
221 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
222 |
"/ set the new classes package |
566
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
223 |
"/ from the old package |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
224 |
|
566
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
225 |
t := oldClass package. |
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
226 |
newMetaclass package:t. |
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
227 |
newClass package:t. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
228 |
|
723
ebc969b4678d
preserve binaryRevision when adding instVars
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
229 |
"/ and keep the binary revision |
ebc969b4678d
preserve binaryRevision when adding instVars
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
230 |
newClass setBinaryRevision:(oldClass revision). |
ebc969b4678d
preserve binaryRevision when adding instVars
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
231 |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
232 |
changeSet := Set new. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
233 |
((oldNames size == 0) |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
234 |
or:[newNames startsWith:oldNames]) ifTrue:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
235 |
"new variable(s) has/have been added - old methods still work" |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
236 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
237 |
" " |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
238 |
Transcript showCr:'copying methods ...'. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
239 |
Transcript endEntry. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
240 |
" " |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
241 |
self copyMethodsFrom:self for:newMetaclass. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
242 |
self copyMethodsFrom:oldClass for:newClass. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
243 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
244 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
245 |
but have to recompile methods accessing stuff now defined |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
246 |
(it might have been a global before ...) |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
247 |
" |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
248 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
249 |
addedNames := newNames select:[:nm | (oldNames includes:nm) not]. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
250 |
" " |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
251 |
Transcript showCr:'recompiling methods accessing ' , addedNames printString , '...'. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
252 |
Transcript endEntry. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
253 |
" " |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
254 |
"recompile class-methods" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
255 |
newMetaclass recompileMethodsAccessingAny:addedNames. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
256 |
] ifFalse:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
257 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
258 |
create the changeSet; thats the set of class instvar names |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
259 |
which have changed their position or are new |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
260 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
261 |
offset := 0. oldOffsets := Dictionary new. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
262 |
oldNames do:[:nm | offset := offset + 1. oldOffsets at:nm put:offset]. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
263 |
offset := 0. newOffsets := Dictionary new. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
264 |
newNames do:[:nm | offset := offset + 1. newOffsets at:nm put:offset]. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
265 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
266 |
oldOffsets associationsDo:[:a | |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
267 |
|k| |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
268 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
269 |
k := a key. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
270 |
(newOffsets includesKey:k) ifFalse:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
271 |
changeSet add:k |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
272 |
] ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
273 |
(a value ~~ (newOffsets at:k)) ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
274 |
changeSet add:k |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
275 |
] |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
276 |
] |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
277 |
]. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
278 |
newOffsets associationsDo:[:a | |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
279 |
|k| |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
280 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
281 |
k := a key. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
282 |
(oldOffsets includesKey:k) ifFalse:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
283 |
changeSet add:k |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
284 |
] ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
285 |
(a value ~~ (oldOffsets at:k)) ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
286 |
changeSet add:k |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
287 |
] |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
288 |
] |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
289 |
]. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
290 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
291 |
" " |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
292 |
Transcript showCr:'recompiling methods accessing ' , changeSet printString , ' ...'. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
293 |
Transcript endEntry. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
294 |
" " |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
295 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
296 |
recompile class-methods |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
297 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
298 |
self copyInvalidatedMethodsFrom:self for:newMetaclass accessingAny:changeSet. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
299 |
newMetaclass recompileInvalidatedMethods:(Metaclass compiledMethodAt:#invalidCodeObject). |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
300 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
301 |
self copyMethodsFrom:oldClass for:newClass. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
302 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
303 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
304 |
delta := newNames size - oldNames size. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
305 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
306 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
307 |
get list of all subclasses - do before superclass is changed |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
308 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
309 |
allSubclasses := oldClass allSubclasses. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
310 |
allSubclasses := allSubclasses asSortedCollection:[:a :b | |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
311 |
b isSubclassOf:a |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
312 |
]. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
313 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
314 |
oldToNew := IdentityDictionary new. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
315 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
316 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
317 |
create a new class tree, based on new version |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
318 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
319 |
allSubclasses do:[:aSubclass | |
943
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
320 |
|sels methods| |
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
321 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
322 |
oldSuper := aSubclass superclass. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
323 |
oldSubMeta := aSubclass class. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
324 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
325 |
newSubMeta := Metaclass new. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
326 |
oldSuper == oldClass ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
327 |
newSubMeta setSuperclass:newMetaclass. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
328 |
] ifFalse:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
329 |
newSubMeta setSuperclass:(oldToNew at:oldSuper) class. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
330 |
]. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
331 |
newSubMeta instSize:(oldSubMeta instSize + delta). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
332 |
newSubMeta flags:(oldSubMeta flags). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
333 |
newSubMeta setName:(oldSubMeta name). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
334 |
newSubMeta setInstanceVariableString:(oldSubMeta instanceVariableString). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
335 |
newSubMeta classVariableString:(oldSubMeta classVariableString). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
336 |
newSubMeta setComment:(oldSubMeta comment). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
337 |
newSubMeta category:(oldSubMeta category). |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
338 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
339 |
newSub := newSubMeta new. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
340 |
oldSuper == oldClass ifTrue:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
341 |
newSub setSuperclass:newClass. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
342 |
] ifFalse:[ |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
343 |
newSub setSuperclass:(oldToNew at:oldSuper). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
344 |
]. |
943
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
345 |
sels := aSubclass selectorArray copy. |
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
346 |
methods := aSubclass methodArray copy. |
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
347 |
newSub setSelectorArray:sels. |
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
348 |
newSub setMethodArray:methods. |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
349 |
newSub setName:(aSubclass name). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
350 |
newSub classVariableString:(aSubclass classVariableString). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
351 |
newSub setComment:(aSubclass comment). |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
352 |
newSub category:(aSubclass category). |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
353 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
354 |
oldToNew at:aSubclass put:newSub. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
355 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
356 |
aSubclass category:'obsolete'. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
357 |
aSubclass class category:'obsolete'. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
358 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
359 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
360 |
"recompile what needs to be" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
361 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
362 |
delta == 0 ifTrue:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
363 |
"only have to recompile class methods accessing |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
364 |
class instvars from changeset |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
365 |
" |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
366 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
367 |
allSubclasses do:[:oldSubclass | |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
368 |
|newSubclass| |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
369 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
370 |
newSubclass := oldToNew at:oldSubclass. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
371 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
372 |
Transcript showCr:'recompiling class methods of ' , newSubclass class name , |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
373 |
' accessing any of ' , changeSet printString. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
374 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
375 |
newSubclass class recompileMethodsAccessingAny:changeSet. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
376 |
] |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
377 |
] ifFalse:[ |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
378 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
379 |
have to recompile all class methods accessing class instvars |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
380 |
" |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
381 |
commonClassInstVars := oldClass class allInstVarNames. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
382 |
changeSet do:[:v | |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
383 |
commonClassInstVars remove:v ifAbsent:[] |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
384 |
]. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
385 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
386 |
allSubclasses do:[:oldSubclass | |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
387 |
|newSubclass classInstVars| |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
388 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
389 |
newSubclass := oldToNew at:oldSubclass. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
390 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
391 |
classInstVars := newSubclass class allInstVarNames asSet. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
392 |
classInstVars removeAll:commonClassInstVars. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
393 |
classInstVars addAll:changeSet. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
394 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
395 |
Transcript showCr:'recompiling class methods of ' , newSubclass class name , |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
396 |
' accessing any of ' , classInstVars printString. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
397 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
398 |
newSubclass class recompileMethodsAccessingAny:classInstVars. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
399 |
] |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
400 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
401 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
402 |
self addChangeRecordForClassInstvars:newClass. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
403 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
404 |
"install all new classes" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
405 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
406 |
Smalltalk at:(oldClass name asSymbol) put:newClass. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
407 |
ObjectMemory flushCachesFor:oldClass. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
408 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
409 |
allSubclasses do:[:oldClass | |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
410 |
|newClass| |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
411 |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
412 |
newClass := oldToNew at:oldClass. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
413 |
" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
414 |
Transcript showCr:'install ' , newClass name , '(' , newClass category , ')' , |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
415 |
' as ' , newClass name. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
416 |
" |
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
417 |
Smalltalk at:newClass name asSymbol put:newClass. |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
418 |
ObjectMemory flushCachesFor:oldClass. |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
419 |
]. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
420 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
421 |
"tell dependents ..." |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
422 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
423 |
oldClass changed:#definition. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
424 |
self changed:#definition. |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
425 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
426 |
^ newMetaclass |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
427 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
428 |
"Created: 29.10.1995 / 19:57:08 / cg" |
723
ebc969b4678d
preserve binaryRevision when adding instVars
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
429 |
"Modified: 9.12.1995 / 17:05:44 / cg" |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
430 |
! ! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
431 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
432 |
!Metaclass methodsFor:'copying'! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
433 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
434 |
postCopy |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
435 |
"redefined - a copy may have a new instance" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
436 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
437 |
myClass := nil |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
438 |
! ! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
439 |
|
1 | 440 |
!Metaclass methodsFor:'creating classes'! |
441 |
||
442 |
name:newName inEnvironment:aSystemDictionary |
|
739
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
443 |
subclassOf:aClass |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
444 |
instanceVariableNames:stringOfInstVarNames |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
445 |
variable:variableBoolean |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
446 |
words:wordsBoolean |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
447 |
pointers:pointersBoolean |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
448 |
classVariableNames:stringOfClassVarNames |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
449 |
poolDictionaries:stringOfPoolNames |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
450 |
category:categoryString |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
451 |
comment:commentString |
63566c9b691a
oops - after autoloading, the metaClasses soleInstance still pointed to the
Claus Gittinger <cg@exept.de>
parents:
723
diff
changeset
|
452 |
changed:changed |
1 | 453 |
|
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
454 |
^ self |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
455 |
name:newName |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
456 |
inEnvironment:aSystemDictionary |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
457 |
subclassOf:aClass |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
458 |
instanceVariableNames:stringOfInstVarNames |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
459 |
variable:variableBoolean |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
460 |
words:wordsBoolean |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
461 |
pointers:pointersBoolean |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
462 |
classVariableNames:stringOfClassVarNames |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
463 |
poolDictionaries:stringOfPoolNames |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
464 |
category:categoryString |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
465 |
comment:commentString |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
466 |
changed:changed |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
467 |
classInstanceVariableNames:'' |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
468 |
|
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
469 |
"Modified: 22.1.1996 / 13:18:08 / cg" |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
470 |
! |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
471 |
|
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
472 |
name:newName inEnvironment:aSystemDictionary |
1047 | 473 |
subclassOf:aClass |
474 |
instanceVariableNames:stringOfInstVarNames |
|
475 |
variable:variableBoolean |
|
476 |
words:wordsBoolean |
|
477 |
pointers:pointersBoolean |
|
478 |
classVariableNames:stringOfClassVarNames |
|
479 |
poolDictionaries:stringOfPoolNames |
|
480 |
category:categoryString |
|
481 |
comment:commentString |
|
482 |
changed:changed |
|
483 |
classInstanceVariableNames:stringOfClassInstVarNames |
|
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
484 |
|
13 | 485 |
"this is the main workhorse for installing new classes - special care |
486 |
has to be taken, when changing an existing classes definition. In this |
|
487 |
case, some or all of the methods and subclasses methods have to be |
|
488 |
recompiled. |
|
489 |
Also, the old class(es) are still kept (but not accessable as a global), |
|
490 |
to allow existing instances some life. |
|
491 |
This might change in the future. |
|
492 |
" |
|
493 |
||
1 | 494 |
|newClass newMetaclass nInstVars nameString classSymbol oldClass |
175 | 495 |
classVarChange instVarChange superClassChange newComment |
308 | 496 |
changeSet1 changeSet2 addedNames |
326 | 497 |
anyChange oldInstVars newInstVars oldClassVars newClassVars superFlags newFlags |
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
498 |
project currentProject t nClassInstVars| |
13 | 499 |
|
68 | 500 |
"NOTICE: |
501 |
this method is too complex and should be splitted into managable pieces ... |
|
159 | 502 |
I dont like it anymore :-) |
356 | 503 |
(well, at least, its a good test for the compilers ability |
504 |
to handle big, complex methods ;-) |
|
505 |
take it as an example of bad coding style ... |
|
506 |
||
507 |
ST-80 uses a ClassBuilder object to collect the work and perform all updates; |
|
508 |
this method may be changed to do something similar in the future ... |
|
68 | 509 |
" |
13 | 510 |
|
328 | 511 |
project := Project. "/ have to fetch this before, in case its autoloaded |
512 |
||
13 | 513 |
newName = aClass name ifTrue:[ |
1047 | 514 |
self error:'trying to create circular class definition'. |
515 |
^ nil |
|
13 | 516 |
]. |
1 | 517 |
|
49 | 518 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
519 |
aClass canBeSubclassed ifFalse:[ |
|
1047 | 520 |
self error:('it is not possible to subclass ' , aClass name). |
521 |
^ nil |
|
49 | 522 |
]. |
523 |
||
1 | 524 |
nInstVars := stringOfInstVarNames countWords. |
525 |
nameString := newName asString. |
|
13 | 526 |
classSymbol := newName asSymbol. |
1 | 527 |
newComment := commentString. |
528 |
||
13 | 529 |
"look, if it already exists as a class" |
870 | 530 |
aSystemDictionary notNil ifTrue:[ |
1047 | 531 |
oldClass := aSystemDictionary at:classSymbol ifAbsent:[nil]. |
870 | 532 |
]. |
866
615ea25db48b
dont copy comment from autoloaded classes
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
533 |
(oldClass isBehavior and:[oldClass isLoaded]) ifFalse:[ |
1047 | 534 |
oldClass := nil. |
68 | 535 |
] ifTrue:[ |
1047 | 536 |
oldClass name ~= classSymbol ifTrue:[ |
537 |
(self confirm:(classSymbol , ' is an alias for ' , oldClass name , '\\continue ?') withCRs) |
|
538 |
ifFalse:[^ self]. |
|
539 |
oldClass := nil |
|
540 |
] ifFalse:[ |
|
541 |
"/ |
|
542 |
"/ some consisteny checks |
|
543 |
"/ |
|
544 |
oldClass superclass notNil ifTrue:[ |
|
545 |
oldClass allSuperclasses do:[:cls | |
|
546 |
cls name = nameString ifTrue:[ |
|
547 |
self error:'trying to create circular class definition'. |
|
548 |
^ nil |
|
549 |
] |
|
550 |
] |
|
551 |
]. |
|
13 | 552 |
|
1047 | 553 |
aClass superclass notNil ifTrue:[ |
554 |
aClass allSuperclasses do:[:cls | |
|
555 |
cls name = nameString ifTrue:[ |
|
556 |
self error:'trying to create circular class definition'. |
|
557 |
^ nil |
|
558 |
] |
|
559 |
]. |
|
560 |
]. |
|
328 | 561 |
|
1047 | 562 |
newComment isNil ifTrue:[ |
563 |
newComment := oldClass comment |
|
564 |
]. |
|
68 | 565 |
|
1047 | 566 |
" |
567 |
warn, if it exists with different category and different instvars, |
|
568 |
and the existing is not an autoload class. |
|
569 |
Usually, this indicates that someone wants to create a new class with |
|
570 |
a name, which already exists (it happened a few times to myself, while |
|
571 |
I wanted to create a new class called ReturnNode ...). |
|
572 |
This will be much less of a problem, once multiple name spaces are |
|
573 |
implemented and classes can be put into separate packages. |
|
574 |
" |
|
575 |
oldClass isLoaded ifTrue:[ |
|
576 |
oldClass category ~= categoryString ifTrue:[ |
|
577 |
oldClass instanceVariableString asCollectionOfWords |
|
578 |
~= stringOfInstVarNames asCollectionOfWords ifTrue:[ |
|
579 |
(self confirm:'a class named ' , oldClass name , |
|
580 |
' already exists -\\create (i.e. change) anyway ?' withCRs) |
|
581 |
ifFalse:[ |
|
582 |
^ nil |
|
583 |
] |
|
584 |
] |
|
585 |
] |
|
586 |
]. |
|
362 | 587 |
|
1047 | 588 |
"/ |
589 |
"/ hints - warn, if creating a variableSubclass of a Set |
|
590 |
"/ (common error - containers in ST/X do not use variable-slots) |
|
591 |
"/ |
|
592 |
((variableBoolean == true) and:[pointersBoolean]) ifTrue:[ |
|
593 |
(oldClass isKindOf:Set class) ifTrue:[ |
|
594 |
(self confirm:'ST/X Set & Dictionary are not variable-classes\create anyway ?' withCRs) |
|
595 |
ifFalse:[ |
|
596 |
^ nil |
|
597 |
] |
|
598 |
] |
|
599 |
] |
|
600 |
] |
|
1 | 601 |
]. |
602 |
||
68 | 603 |
" |
604 |
Check for some 'considered bad-style' things, like lower case names. |
|
605 |
But only do these checks for new classes - |
|
606 |
- thus, once confirmed, the warnings will not come again and again. |
|
607 |
||
608 |
NOTICE: |
|
195 | 609 |
I dont like the confirmers there - we need a notifying: argument, to give |
44 | 610 |
the outer codeview a chance to highlight the error. |
68 | 611 |
(but thats how its defined in the book - maybe I will change anyway). |
612 |
" |
|
44 | 613 |
oldClass isNil ifTrue:[ |
1047 | 614 |
(self checkConventionsFor:newName |
615 |
instVarNames:stringOfInstVarNames |
|
616 |
classVarNames:stringOfClassVarNames) ifFalse:[ |
|
617 |
^ nil |
|
618 |
] |
|
44 | 619 |
]. |
620 |
||
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
621 |
nClassInstVars := stringOfClassInstVarNames countWords. |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
622 |
|
1 | 623 |
"create the metaclass first" |
624 |
newMetaclass := Metaclass new. |
|
625 |
newMetaclass setSuperclass:(aClass class). |
|
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
626 |
newMetaclass instSize:(aClass class instSize + nClassInstVars). |
175 | 627 |
newMetaclass setName:(nameString , 'class') asSymbol. |
1 | 628 |
newMetaclass classVariableString:'' "stringOfClassVarNames". |
226 | 629 |
"/ newMetaclass setComment:newComment category:categoryString. |
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
630 |
newMetaclass setInstanceVariableString:stringOfClassInstVarNames. |
326 | 631 |
|
195 | 632 |
"then let the new meta create the class" |
1 | 633 |
newClass := newMetaclass new. |
634 |
newClass setSuperclass:aClass. |
|
635 |
newClass instSize:(aClass instSize + nInstVars). |
|
175 | 636 |
newClass setName:classSymbol. |
637 |
newClass setComment:newComment category:categoryString. |
|
1 | 638 |
|
362 | 639 |
"/ set the new classes package |
566
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
640 |
"/ but prefer the old package |
362 | 641 |
|
566
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
642 |
oldClass notNil ifTrue:[ |
1047 | 643 |
t := oldClass package. |
644 |
newClass setBinaryRevision:(oldClass binaryRevision). |
|
566
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
645 |
] ifFalse:[ |
1047 | 646 |
project notNil ifTrue:[ |
647 |
currentProject := project current. |
|
648 |
currentProject notNil ifTrue:[ |
|
649 |
t := currentProject packageName. |
|
650 |
] |
|
651 |
]. |
|
566
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
652 |
]. |
3d2527a9e96d
preserve package when class definition changes - its required for the SourceCodeManager
Claus Gittinger <cg@exept.de>
parents:
544
diff
changeset
|
653 |
t notNil ifTrue:[ |
1047 | 654 |
newMetaclass package:t. |
655 |
newClass package:t. |
|
362 | 656 |
]. |
657 |
||
68 | 658 |
" |
659 |
Allowing non-booleans as variableBoolean |
|
660 |
is a hack for backward (ST-80) compatibility: |
|
661 |
||
662 |
ST-80 code will pass true or false as variableBoolean, |
|
663 |
while ST/X also calls it with symbols such as #float, #double etc. |
|
664 |
" |
|
1 | 665 |
(variableBoolean == true) ifTrue:[ |
1047 | 666 |
pointersBoolean ifTrue:[ |
667 |
newFlags := Behavior flagPointers |
|
668 |
] ifFalse:[ |
|
669 |
wordsBoolean ifTrue:[ |
|
670 |
newFlags := Behavior flagWords |
|
671 |
] ifFalse:[ |
|
672 |
newFlags := Behavior flagBytes |
|
673 |
] |
|
674 |
] |
|
1 | 675 |
] ifFalse:[ |
1047 | 676 |
(variableBoolean == #float) ifTrue:[ |
677 |
newFlags := Behavior flagFloats |
|
678 |
] ifFalse:[ |
|
679 |
(variableBoolean == #double) ifTrue:[ |
|
680 |
newFlags := Behavior flagDoubles |
|
681 |
] ifFalse:[ |
|
682 |
(variableBoolean == #long) ifTrue:[ |
|
683 |
newFlags := Behavior flagLongs |
|
684 |
] ifFalse:[ |
|
685 |
newFlags := Behavior flagNotIndexed |
|
686 |
] |
|
687 |
] |
|
688 |
]. |
|
1 | 689 |
]. |
68 | 690 |
superFlags := aClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits" |
691 |
oldClass notNil ifTrue:[ |
|
1047 | 692 |
oldClass isBuiltInClass ifTrue:[ |
693 |
" |
|
694 |
special care when redefining Method, Block and other built-in classes, |
|
695 |
which might have other flag bits ... |
|
696 |
" |
|
49 | 697 |
|
1047 | 698 |
newFlags := newFlags bitOr:(oldClass flags bitAnd:(Behavior maskIndexType bitInvert)) |
699 |
] |
|
68 | 700 |
]. |
701 |
newClass flags:(newFlags bitOr:superFlags). "preserve inherited special bits" |
|
1 | 702 |
|
703 |
(nInstVars ~~ 0) ifTrue:[ |
|
1047 | 704 |
newClass setInstanceVariableString:stringOfInstVarNames |
1 | 705 |
]. |
706 |
oldClass notNil ifTrue:[ |
|
1047 | 707 |
" |
708 |
setting first will make new class clear obsolete classvars |
|
709 |
" |
|
710 |
newClass setClassVariableString:(oldClass classVariableString). |
|
711 |
(t := oldClass primitiveSpec) notNil ifTrue:[ |
|
712 |
newClass primitiveSpec:t. |
|
713 |
newClass setClassFilename:(oldClass classFilename). |
|
714 |
] |
|
1 | 715 |
]. |
716 |
newClass classVariableString:stringOfClassVarNames. |
|
717 |
||
68 | 718 |
" |
719 |
for new classes, we are almost done here |
|
77 | 720 |
(also for autoloaded classes) |
68 | 721 |
" |
77 | 722 |
(oldClass isNil or:[oldClass isLoaded not]) ifTrue:[ |
1047 | 723 |
(oldClass isNil and:[changed]) ifTrue:[ |
724 |
self addChangeRecordForClass:newClass. |
|
725 |
]. |
|
1 | 726 |
|
1047 | 727 |
commentString notNil ifTrue:[ |
728 |
newClass comment:commentString |
|
729 |
]. |
|
68 | 730 |
|
1047 | 731 |
aSystemDictionary notNil ifTrue:[ |
732 |
aSystemDictionary at:classSymbol put:newClass. |
|
733 |
]. |
|
314 | 734 |
|
1047 | 735 |
oldClass isNil ifTrue:[ |
736 |
project notNil ifTrue:[ |
|
737 |
currentProject := project current. |
|
738 |
currentProject notNil ifTrue:[ |
|
739 |
" |
|
740 |
new classes get the package assigned |
|
741 |
" |
|
742 |
newClass package:(currentProject packageName asSymbol) |
|
743 |
] |
|
744 |
]. |
|
745 |
]. |
|
314 | 746 |
|
1047 | 747 |
aSystemDictionary notNil ifTrue:[ |
748 |
aSystemDictionary changed:#newClass with:newClass. |
|
749 |
]. |
|
750 |
^ newClass |
|
2 | 751 |
]. |
752 |
||
10 | 753 |
|
68 | 754 |
" |
755 |
here comes the hard part - we are actually changing the |
|
756 |
definition of an existing class .... |
|
757 |
Try hard to get away WITHOUT recompiling, since it makes all |
|
758 |
compiled code into interpreted ... |
|
759 |
" |
|
760 |
||
10 | 761 |
oldInstVars := oldClass instanceVariableString asCollectionOfWords. |
762 |
newInstVars := newClass instanceVariableString asCollectionOfWords. |
|
763 |
oldClassVars := oldClass classVariableString asCollectionOfWords. |
|
764 |
newClassVars := newClass classVariableString asCollectionOfWords. |
|
765 |
||
68 | 766 |
" |
767 |
we are on the bright side of life, if the instance layout and |
|
768 |
inheritance do not change. |
|
769 |
In this case, we can go ahead and patch the class object. |
|
770 |
" |
|
2 | 771 |
(oldClass superclass == newClass superclass) ifTrue:[ |
772 |
(oldClass instSize == newClass instSize) ifTrue:[ |
|
1047 | 773 |
(oldClass flags == newClass flags) ifTrue:[ |
774 |
(oldClass name = newClass name) ifTrue:[ |
|
775 |
(oldInstVars = newInstVars) ifTrue:[ |
|
68 | 776 |
|
1047 | 777 |
(newComment ~= oldClass comment) ifTrue:[ |
778 |
oldClass setComment:newComment. "writes a change-chunk" |
|
779 |
oldClass changed:#comment with:oldClass comment. |
|
780 |
changed ifTrue:[ |
|
781 |
self addChangeRecordForClassComment:oldClass. |
|
782 |
] |
|
783 |
]. |
|
10 | 784 |
|
1047 | 785 |
(oldClassVars = newClassVars) ifTrue:[ |
786 |
" |
|
787 |
really no change (just comment and/or category) |
|
788 |
" |
|
789 |
anyChange := false. |
|
10 | 790 |
|
1047 | 791 |
oldClass setInstanceVariableString:(newClass instanceVariableString). |
792 |
oldClass setClassVariableString:(newClass classVariableString). |
|
68 | 793 |
|
1047 | 794 |
oldClass category ~= categoryString ifTrue:[ |
795 |
oldClass category:categoryString. |
|
796 |
changed ifTrue:[ |
|
797 |
self addChangeRecordForClass:newClass. |
|
798 |
]. |
|
799 |
aSystemDictionary notNil ifTrue:[ |
|
800 |
"notify change of category" |
|
801 |
aSystemDictionary changed:#organization |
|
802 |
] |
|
803 |
]. |
|
804 |
"notify change of class" |
|
159 | 805 |
"/ oldClass changed. |
1047 | 806 |
^ oldClass |
807 |
]. |
|
33 | 808 |
|
1047 | 809 |
" |
810 |
when we arrive here, class variables have changed |
|
811 |
" |
|
812 |
oldClass category ~= categoryString ifTrue:[ |
|
813 |
"notify change of organization" |
|
814 |
oldClass category:categoryString. |
|
815 |
aSystemDictionary notNil ifTrue:[ |
|
816 |
"notify change of organization" |
|
817 |
aSystemDictionary changed:#organization |
|
818 |
]. |
|
819 |
]. |
|
33 | 820 |
|
1047 | 821 |
" |
822 |
set class variable string; |
|
823 |
this also updates the set of class variables |
|
824 |
by creating new / deleting obsolete ones. |
|
825 |
" |
|
826 |
oldClass classVariableString:stringOfClassVarNames. |
|
33 | 827 |
|
1047 | 828 |
" |
829 |
get the set of changed class variables |
|
830 |
" |
|
831 |
changeSet1 := Set new. |
|
832 |
oldClassVars do:[:nm | |
|
833 |
(newClassVars includes:nm) ifFalse:[ |
|
834 |
changeSet1 add:nm |
|
835 |
] |
|
836 |
]. |
|
837 |
newClassVars do:[:nm | |
|
838 |
(oldClassVars includes:nm) ifFalse:[ |
|
839 |
changeSet1 add:nm |
|
840 |
] |
|
841 |
]. |
|
33 | 842 |
|
1047 | 843 |
" |
844 |
recompile all methods accessing set of changed classvars |
|
845 |
here and also in all subclasses ... |
|
846 |
" |
|
159 | 847 |
|
1047 | 848 |
" |
849 |
dont update change file for the recompilation |
|
850 |
" |
|
851 |
Class withoutUpdatingChangesDo:[ |
|
33 | 852 |
" " |
1047 | 853 |
Transcript showCr:'recompiling class & inst methods accessing ' , changeSet1 printString. |
854 |
Transcript endEntry. |
|
33 | 855 |
" " |
1047 | 856 |
oldClass withAllSubclasses do:[:aClass | |
857 |
aClass class recompileMethodsAccessingAny:changeSet1. |
|
858 |
aClass recompileMethodsAccessingAny:changeSet1. |
|
859 |
]. |
|
860 |
]. |
|
33 | 861 |
|
1047 | 862 |
"notify change of class" |
863 |
changed ifTrue:[ |
|
864 |
self addChangeRecordForClass:oldClass. |
|
865 |
]. |
|
866 |
oldClass changed:#definition. |
|
33 | 867 |
|
1047 | 868 |
^ oldClass |
869 |
] |
|
870 |
] |
|
871 |
] |
|
2 | 872 |
] |
873 |
]. |
|
874 |
||
68 | 875 |
" |
876 |
here we enter the darkness of mordor ... |
|
159 | 877 |
since instance variable layout and/or inheritance has changed. |
68 | 878 |
" |
2 | 879 |
(newComment ~= oldClass comment) ifTrue:[ |
1047 | 880 |
newClass comment:newComment |
2 | 881 |
]. |
882 |
||
883 |
superClassChange := oldClass superclass ~~ newClass superclass. |
|
1 | 884 |
|
68 | 885 |
" |
886 |
dont allow built-in classes to be modified this way |
|
887 |
" |
|
3 | 888 |
(oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[ |
1047 | 889 |
self error:'the inheritance of this class is fixed - you cannot change it'. |
890 |
^ oldClass |
|
3 | 891 |
]. |
892 |
||
68 | 893 |
" |
894 |
catch special case, where superclass changed its layout and thus |
|
895 |
forced redefinition of this class; |
|
896 |
only log if this is not the case. |
|
897 |
" |
|
904
be65513cde2a
dont write change records if the changed: arg is false
Claus Gittinger <cg@exept.de>
parents:
885
diff
changeset
|
898 |
changed ifTrue:[ |
1047 | 899 |
(superClassChange |
900 |
and:[(oldClass superclass isNil or:[oldClass superclass name = newClass superclass name]) |
|
901 |
and:[(oldClassVars = newClassVars) |
|
902 |
and:[(oldInstVars = newInstVars) |
|
903 |
and:[newComment = oldClass comment]]]]) ifFalse:[ |
|
904 |
self addChangeRecordForClass:newClass. |
|
905 |
] |
|
2 | 906 |
]. |
907 |
||
68 | 908 |
" |
909 |
care for class methods ... |
|
910 |
" |
|
2 | 911 |
changeSet1 := Set new. |
1 | 912 |
|
2 | 913 |
classVarChange := false. |
914 |
||
915 |
superClassChange ifTrue:[ |
|
1047 | 916 |
" |
917 |
superclass changed: |
|
918 |
must recompile all class methods accessing ANY classvar |
|
919 |
( |
|
920 |
actually, we could be less strict and handle the case where |
|
921 |
both the old and the new superclass have a common ancestor, |
|
922 |
and both have no new classvariables in between. |
|
923 |
This would speedup the case when a class is inserted into |
|
924 |
the inheritance chain. |
|
925 |
) |
|
926 |
" |
|
1 | 927 |
|
1047 | 928 |
oldClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
929 |
newClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
|
2 | 930 |
|
931 |
" " |
|
1047 | 932 |
Transcript showCr:'recompiling class methods accessing any classvar'. |
933 |
Transcript endEntry. |
|
2 | 934 |
" " |
1047 | 935 |
self copyInvalidatedMethodsFrom:(oldClass class) |
936 |
for:newMetaclass |
|
937 |
accessingAny:changeSet1 |
|
938 |
orSuper:true. |
|
939 |
newMetaclass recompileInvalidatedMethods:(Metaclass compiledMethodAt:#invalidCodeObject). |
|
2 | 940 |
] ifFalse:[ |
1047 | 941 |
" |
942 |
same superclass, find out which classvars have changed |
|
943 |
" |
|
944 |
classVarChange := oldClassVars ~= newClassVars. |
|
945 |
classVarChange ifTrue:[ |
|
946 |
oldClassVars do:[:nm | |
|
947 |
(newClassVars includes:nm) ifFalse:[ |
|
948 |
changeSet1 add:nm |
|
949 |
] |
|
950 |
]. |
|
951 |
newClassVars do:[:nm | |
|
952 |
(oldClassVars includes:nm) ifFalse:[ |
|
953 |
changeSet1 add:nm |
|
954 |
] |
|
955 |
]. |
|
956 |
]. |
|
1 | 957 |
|
1047 | 958 |
classVarChange ifTrue:[ |
959 |
" |
|
960 |
must recompile some class-methods |
|
961 |
" |
|
2 | 962 |
" " |
1047 | 963 |
Transcript showCr:'recompiling class methods accessing ' , changeSet1 printString. |
964 |
Transcript endEntry. |
|
68 | 965 |
" " |
1047 | 966 |
self copyInvalidatedMethodsFrom:(oldClass class) for:newMetaclass accessingAny:changeSet1. |
967 |
newMetaclass recompileInvalidatedMethods:(Metaclass compiledMethodAt:#invalidCodeObject). |
|
968 |
] ifFalse:[ |
|
969 |
" |
|
970 |
class methods still work |
|
971 |
" |
|
972 |
self copyMethodsFrom:(oldClass class) for:newMetaclass |
|
973 |
]. |
|
2 | 974 |
]. |
1 | 975 |
|
68 | 976 |
" |
977 |
care for instance methods ... |
|
978 |
" |
|
979 |
||
2 | 980 |
superClassChange ifTrue:[ |
1047 | 981 |
"superclass changed, |
982 |
must recompile all methods accessing any class or instvar. |
|
983 |
If number of instvars (i.e. the instances instSize) is the same, |
|
984 |
we can limit the set of recompiled instance methods to those methods, |
|
985 |
which refer to an instvar with a different inst-index |
|
986 |
" |
|
13 | 987 |
|
1047 | 988 |
" |
989 |
the changeset consists of instance variables, |
|
990 |
with a different position |
|
991 |
" |
|
992 |
changeSet2 := self differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
13 | 993 |
|
1047 | 994 |
" |
995 |
merge in the changed class variables |
|
996 |
" |
|
997 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
68 | 998 |
|
13 | 999 |
" " |
1047 | 1000 |
Transcript showCr:'recompiling instance methods accessing ' , changeSet2 printString , ' ...'. |
1001 |
Transcript endEntry. |
|
13 | 1002 |
" " |
1047 | 1003 |
self copyInvalidatedMethodsFrom:oldClass |
1004 |
for:newClass |
|
1005 |
accessingAny:changeSet2 |
|
1006 |
orSuper:true. |
|
1007 |
newClass recompileInvalidatedMethods:(Metaclass compiledMethodAt:#invalidCodeObject). |
|
13 | 1008 |
|
2 | 1009 |
] ifFalse:[ |
1047 | 1010 |
" |
1011 |
same inheritance ... |
|
1012 |
" |
|
1013 |
instVarChange := oldInstVars ~= newInstVars. |
|
1014 |
instVarChange ifFalse:[ |
|
1015 |
" |
|
1016 |
same instance variables ... |
|
1017 |
" |
|
1018 |
classVarChange ifTrue:[ |
|
1019 |
"recompile all inst methods accessing changed classvars" |
|
1 | 1020 |
|
2 | 1021 |
" " |
1047 | 1022 |
Transcript showCr:'recompiling instance methods accessing ' , changeSet1 printString , ' ...'. |
1023 |
Transcript endEntry. |
|
2 | 1024 |
" " |
1047 | 1025 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet1. |
1026 |
newClass recompileInvalidatedMethods:(Metaclass compiledMethodAt:#invalidCodeObject). |
|
1027 |
] |
|
1028 |
] ifTrue:[ |
|
1029 |
" |
|
1030 |
dont allow built-in classes to be modified |
|
1031 |
" |
|
1032 |
(oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[ |
|
1033 |
self error:'the layout of this class is fixed - you cannot change it'. |
|
1034 |
^ oldClass |
|
1035 |
]. |
|
3 | 1036 |
|
1047 | 1037 |
((oldInstVars size == 0) |
1038 |
or:[newInstVars startsWith:oldInstVars]) ifTrue:[ |
|
1039 |
" |
|
1040 |
only new inst variable(s) has/have been added - |
|
1041 |
old methods still work (the existing inst-indices are still valid) |
|
1042 |
" |
|
68 | 1043 |
" " |
1047 | 1044 |
Transcript showCr:'copying methods ...'. |
1045 |
Transcript endEntry. |
|
68 | 1046 |
" " |
1047 | 1047 |
self copyMethodsFrom:oldClass for:newClass. |
2 | 1048 |
|
1047 | 1049 |
" |
1050 |
but: we have to recompile all methods accessing new instars |
|
1051 |
(it might have been a classVar/global before ...) |
|
1052 |
" |
|
1053 |
addedNames := newInstVars select:[:nm | (oldInstVars includes:nm) not]. |
|
1054 |
"merge in class variables" |
|
1055 |
changeSet1 do:[:nm | addedNames add:nm]. |
|
1 | 1056 |
|
2 | 1057 |
" " |
1047 | 1058 |
Transcript showCr:'recompiling instance methods accessing ' , addedNames printString , '...'. |
1059 |
Transcript endEntry. |
|
2 | 1060 |
" " |
1047 | 1061 |
newClass recompileMethodsAccessingAny:addedNames. |
1062 |
] ifFalse:[ |
|
2 | 1063 |
|
1047 | 1064 |
" |
1065 |
the changeset consists of instance variables, |
|
1066 |
with a different position |
|
1067 |
" |
|
1068 |
changeSet2 := self differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1 | 1069 |
|
1047 | 1070 |
"merge in the class variables" |
1071 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
2 | 1072 |
" " |
1047 | 1073 |
Transcript showCr:'recompiling instance methods accessing ' , changeSet2 printString , ' ...'. |
1074 |
Transcript endEntry. |
|
2 | 1075 |
" " |
1047 | 1076 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet2. |
1077 |
newClass recompileInvalidatedMethods:(Metaclass compiledMethodAt:#invalidCodeObject). |
|
1078 |
]. |
|
1079 |
]. |
|
2 | 1080 |
]. |
1 | 1081 |
|
68 | 1082 |
" |
1083 |
WOW, everything done for this class |
|
1084 |
what about subclasses ? |
|
1085 |
" |
|
2 | 1086 |
|
68 | 1087 |
" |
1088 |
update superclass of immediate subclasses - |
|
1089 |
this forces recompilation (recursively) if needed |
|
1090 |
(dont update change file for the subclass changes) |
|
1091 |
" |
|
202 | 1092 |
Class withoutUpdatingChangesDo:[ |
1047 | 1093 |
oldClass subclassesDo:[:aClass | |
2 | 1094 |
" " |
1047 | 1095 |
Transcript showCr:'changing superclass of:' , aClass name. |
1096 |
Transcript endEntry. |
|
2 | 1097 |
" " |
1047 | 1098 |
aClass superclass:newClass |
1099 |
] |
|
2 | 1100 |
]. |
1101 |
||
68 | 1102 |
" |
1103 |
change category in oldClass - so we see immediately what it is ... |
|
1104 |
" |
|
1105 |
oldClass category:'obsolete'. |
|
1106 |
oldClass class category:'obsolete'. |
|
1107 |
||
1108 |
" |
|
1109 |
and make the new class globally known |
|
1110 |
" |
|
870 | 1111 |
aSystemDictionary notNil ifTrue:[ |
1047 | 1112 |
aSystemDictionary at:classSymbol put:newClass. |
68 | 1113 |
|
1047 | 1114 |
oldClass category ~= categoryString ifTrue:[ |
1115 |
"notify change of organization" |
|
1116 |
aSystemDictionary changed:#organization |
|
1117 |
]. |
|
68 | 1118 |
]. |
1119 |
||
1120 |
" |
|
1121 |
Not becoming the old class creates some update problems; |
|
1122 |
the browsers must check carefully - a simple identity compare is |
|
159 | 1123 |
not enough ... |
68 | 1124 |
QUESTION: is this a good idea ? |
1125 |
" |
|
1126 |
||
1127 |
newClass dependents:(oldClass dependents). |
|
202 | 1128 |
newClass changed:#definition. |
68 | 1129 |
|
159 | 1130 |
"just to make certain ... - tell dependents of oldClass, that something changed |
85 | 1131 |
(systemBrowsers will react on this, and update their views)" |
159 | 1132 |
oldClass changed:#definition with:newClass. |
68 | 1133 |
|
2 | 1134 |
ObjectMemory flushCaches. |
68 | 1135 |
|
1 | 1136 |
^ newClass |
723
ebc969b4678d
preserve binaryRevision when adding instVars
Claus Gittinger <cg@exept.de>
parents:
682
diff
changeset
|
1137 |
|
885
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
1138 |
"Modified: 22.1.1996 / 13:17:13 / cg" |
621 | 1139 |
! |
1140 |
||
1141 |
new |
|
1142 |
"create & return a new metaclass (a classes class). |
|
1143 |
Since metaclasses only have one instance (the class), |
|
1144 |
complain if there is already one. |
|
1145 |
You get a new class by sending #new to the returned metaclass |
|
1146 |
(confusing - isn't it ?)" |
|
1147 |
||
1148 |
|newClass| |
|
1149 |
||
1150 |
myClass notNil ifTrue:[ |
|
1151 |
^ self error:'Each metaclass may only have one instance'. |
|
1152 |
]. |
|
1153 |
newClass := self basicNew. |
|
1154 |
newClass setSuperclass:Object |
|
1155 |
selectors:(Array new:0) |
|
1156 |
methods:(Array new:0) |
|
1157 |
instSize:0 |
|
1158 |
flags:(Behavior flagBehavior). |
|
1159 |
newClass setName:'someClass'. |
|
1160 |
myClass := newClass. |
|
1161 |
^ newClass |
|
1 | 1162 |
! ! |
1163 |
||
1164 |
!Metaclass methodsFor:'private'! |
|
1165 |
||
621 | 1166 |
anyInvalidatedMethodsIn:aClass |
1167 |
"return true, if aClass has any invalidated methods in it" |
|
1168 |
||
1169 |
|trap trapCode trapByteCode| |
|
1170 |
||
1171 |
trap := Metaclass compiledMethodAt:#invalidCodeObject. |
|
1172 |
trapCode := trap code. |
|
1173 |
trapByteCode := trap byteCode. |
|
68 | 1174 |
|
943
57641242a972
be careful with self modifying selectorArrays
Claus Gittinger <cg@exept.de>
parents:
912
diff
changeset
|
1175 |
aClass methodArray copy do:[:aMethod | |
621 | 1176 |
trapCode notNil ifTrue:[ |
1177 |
(aMethod code = trapCode) ifTrue:[^ true] |
|
1178 |
]. |
|
1179 |
trapByteCode notNil ifTrue:[ |
|
1180 |
(aMethod byteCode == trapByteCode) ifTrue:[^ true] |
|
1181 |
] |
|
1182 |
]. |
|
1183 |
^ false |
|
68 | 1184 |
! |
1185 |
||
621 | 1186 |
checkConventionsFor:className instVarNames:instVarNameString classVarNames:classVarNameString |
1187 |
"Check for some 'considered bad-style' things, like lower case names. |
|
1188 |
NOTICE: |
|
1189 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
1190 |
the outer codeview a chance to highlight the error. |
|
1191 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
308 | 1192 |
" |
621 | 1193 |
|
1194 |
"let user confirm, if the classname is no good" |
|
1195 |
className first isUppercase ifFalse:[ |
|
1196 |
(self confirm:'classename ''' , className , ''' should start with an uppercase letter |
|
1197 |
(by convention only) |
|
308 | 1198 |
|
621 | 1199 |
install anyway ?' withCRs) |
1200 |
ifFalse:[ |
|
1201 |
^ false |
|
308 | 1202 |
] |
621 | 1203 |
]. |
1204 |
||
1205 |
"let user confirm, if any instvarname is no good" |
|
1206 |
(instVarNameString asCollectionOfWords |
|
1207 |
findFirst:[:word | word first isUppercase]) ~~ 0 ifTrue:[ |
|
1208 |
(self confirm:'instance variable names should start with a lowercase letter |
|
1209 |
(by convention only) |
|
1210 |
||
1211 |
install anyway ?' withCRs) |
|
1212 |
ifFalse:[ |
|
1213 |
^ false |
|
308 | 1214 |
] |
1215 |
]. |
|
621 | 1216 |
|
1217 |
"let user confirm, if any classvarname is no good" |
|
1218 |
(classVarNameString asCollectionOfWords |
|
1219 |
findFirst:[:word | word first isLowercase]) ~~ 0 ifTrue:[ |
|
1220 |
(self confirm:'class variable names should start with an uppercase letter |
|
1221 |
(by convention only) |
|
308 | 1222 |
|
621 | 1223 |
install anyway ?' withCRs) |
1224 |
ifFalse:[ |
|
1225 |
^ false |
|
1226 |
]. |
|
1227 |
]. |
|
308 | 1228 |
|
621 | 1229 |
^ true |
1 | 1230 |
! |
1231 |
||
1232 |
copyInvalidatedMethodsFrom:oldClass for:newClass |
|
159 | 1233 |
"copy all methods from oldClass to newClass and change their code |
1234 |
to a trap method reporting an error. |
|
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1235 |
This is done when a class has changed its layout or inheritance, |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1236 |
before recompilation is attempted. |
159 | 1237 |
This allows us to keep the source while trapping uncompilable (due to |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1238 |
now undefined instvars) methods. Later compilation of these methods will show |
159 | 1239 |
an error on the transcript and lead to the debugger once called." |
1 | 1240 |
|
986 | 1241 |
|trap trapCode trapByteCode oldMethod newMethod |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1242 |
newSelectorArray newMethodArray |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1243 |
nMethods "{ Class: SmallInteger }"| |
1 | 1244 |
|
328 | 1245 |
trap := Metaclass compiledMethodAt:#invalidCodeObject. |
1 | 1246 |
trapCode := trap code. |
1247 |
trapByteCode := trap byteCode. |
|
1248 |
||
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1249 |
newMethodArray := oldClass methodArray copy. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1250 |
newSelectorArray := oldClass selectorArray copy. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1251 |
newClass selectors:newSelectorArray methods:newMethodArray. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1252 |
|
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1253 |
nMethods := newMethodArray size. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1254 |
1 to:nMethods do:[:i | |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1255 |
oldMethod := newMethodArray at:i. |
251 | 1256 |
oldMethod isWrapped ifTrue:[ |
1257 |
oldMethod := oldMethod originalMethod |
|
1258 |
]. |
|
1259 |
newMethod := oldMethod copy. |
|
159 | 1260 |
newMethod code:trapCode. |
1261 |
newMethod literals:nil. |
|
1262 |
newMethod byteCode:trapByteCode. |
|
1263 |
newMethodArray at:i put:newMethod |
|
2 | 1264 |
] |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1265 |
|
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1266 |
"Modified: 27.1.1996 / 17:57:48 / cg" |
2 | 1267 |
! |
1268 |
||
1269 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames |
|
1270 |
"copy all methods from oldClass to newClass. Those methods accessing |
|
1271 |
a variable in setOfNames will be copied as invalid method, leading to |
|
159 | 1272 |
a trap when its executed. This is used when a class has changed its |
1273 |
layout for all methods which are affected by the change." |
|
1274 |
||
1275 |
self copyInvalidatedMethodsFrom:oldClass |
|
1276 |
for:newClass |
|
1277 |
accessingAny:setOfNames |
|
1278 |
orSuper:false |
|
1279 |
! |
|
1280 |
||
1281 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames orSuper:superBoolean |
|
1282 |
"copy all methods from oldClass to newClass. |
|
1283 |
Those methods accessing a variable in setOfNames will be copied as invalid method, |
|
1284 |
leading to a trap when its executed. If superBoolean is true, this is also done |
|
1285 |
for methods accessing super. This is used when a class has changed its |
|
1286 |
layout for all methods which are affected by the change." |
|
2 | 1287 |
|
251 | 1288 |
|trap trapCode trapByteCode p source mustInvalidate |
986 | 1289 |
oldMethod newMethod newSelectorArray newMethodArray |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1290 |
nMethods "{ Class: SmallInteger }" |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1291 |
nNames usedVars| |
2 | 1292 |
|
328 | 1293 |
trap := Metaclass compiledMethodAt:#invalidCodeObject. |
2 | 1294 |
trapCode := trap code. |
1295 |
trapByteCode := trap byteCode. |
|
1296 |
||
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1297 |
newMethodArray := oldClass methodArray copy. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1298 |
newSelectorArray := oldClass selectorArray copy. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1299 |
|
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1300 |
newClass selectors:newSelectorArray methods:newMethodArray. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1301 |
|
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1302 |
nNames := setOfNames size. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1303 |
|
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1304 |
nMethods := newMethodArray size. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1305 |
1 to:nMethods do:[:i | |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1306 |
oldMethod := newMethodArray at:i. |
251 | 1307 |
oldMethod isWrapped ifTrue:[ |
1308 |
oldMethod := oldMethod originalMethod |
|
1309 |
]. |
|
202 | 1310 |
|
1311 |
"before parsing (which may take some time), |
|
1312 |
do a string search if its only one variable, |
|
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1313 |
we are looking for. |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1314 |
Could look for more than one variable by string compare, but then |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1315 |
parsing it right away may be faster ..." |
202 | 1316 |
|
251 | 1317 |
source := oldMethod source. |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1318 |
((nNames == 1) and:[superBoolean not]) ifTrue:[ |
251 | 1319 |
mustInvalidate := (source findString:(setOfNames first)) ~~ 0. |
202 | 1320 |
] ifFalse:[ |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1321 |
((nNames == 0) and:[superBoolean]) ifTrue:[ |
251 | 1322 |
mustInvalidate := (source findString:'super') ~~ 0. |
1323 |
] ifFalse:[ |
|
1324 |
mustInvalidate := true |
|
1325 |
]. |
|
202 | 1326 |
]. |
1327 |
||
1328 |
mustInvalidate ifTrue:[ |
|
251 | 1329 |
"we have to parse it ..." |
1330 |
p := Parser parseMethod:source in:newClass. |
|
202 | 1331 |
(p isNil |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1332 |
or:[((usedVars := p usedVars) notNil and:[usedVars includesAny:setOfNames]) |
202 | 1333 |
or:[superBoolean and:[p usesSuper]]]) ifFalse:[ |
1334 |
mustInvalidate := false |
|
1335 |
] |
|
1336 |
]. |
|
1337 |
||
1338 |
mustInvalidate ifTrue:[ |
|
159 | 1339 |
newMethod := oldMethod copy. |
1340 |
newMethod code:trapCode. |
|
1341 |
newMethod literals:nil. |
|
1342 |
newMethod byteCode:trapByteCode |
|
1343 |
] ifFalse:[ |
|
1344 |
newMethod := oldMethod. |
|
1345 |
]. |
|
1346 |
newMethodArray at:i put:newMethod |
|
1 | 1347 |
] |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1348 |
|
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1349 |
"Modified: 27.1.1996 / 17:56:44 / cg" |
1 | 1350 |
! |
1351 |
||
621 | 1352 |
copyMethodsFrom:oldClass for:newClass |
1353 |
"copy all methods from oldClass to newClass. |
|
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1354 |
This is used for class-methods when a class has changed, but its metaclass is |
621 | 1355 |
unaffected (i.e. classVars/inheritance have not changed) so there is no need |
1356 |
to recompile the class methods." |
|
195 | 1357 |
|
621 | 1358 |
newClass selectors:(oldClass selectorArray copy) |
1359 |
methods:(oldClass methodArray copy) |
|
1360 |
! |
|
1361 |
||
1362 |
differentInstanceVariableOffsetsIn:class1 and:class2 |
|
1363 |
"return a set of instance variable names which have different |
|
1364 |
positions in class1 and class2. |
|
1365 |
Also, variables which are only present in one class are returned. |
|
1366 |
This is used to find methods which need recompilation after a |
|
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1367 |
change in the instance variable layout." |
621 | 1368 |
|
1369 |
|offsets1 offsets2 changeSet| |
|
195 | 1370 |
|
621 | 1371 |
changeSet := Set new. |
1372 |
||
1373 |
" |
|
1374 |
collect the instvar-indices in the old and new class |
|
1375 |
" |
|
1376 |
offsets1 := class1 instanceVariableOffsets. |
|
1377 |
offsets2 := class2 instanceVariableOffsets. |
|
195 | 1378 |
|
621 | 1379 |
" |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1380 |
compute the changeset as a set of instance variables, |
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1381 |
which have a different position |
621 | 1382 |
" |
1383 |
offsets1 keysAndValuesDo:[:varName :varIndex | |
|
1384 |
(offsets2 includesKey:varName) ifFalse:[ |
|
1385 |
changeSet add:varName |
|
1386 |
] ifTrue:[ |
|
1387 |
(varIndex ~~ (offsets2 at:varName)) ifTrue:[ |
|
1388 |
changeSet add:varName |
|
1389 |
] |
|
195 | 1390 |
] |
1391 |
]. |
|
621 | 1392 |
offsets2 keysAndValuesDo:[:varName :varIndex | |
1393 |
(offsets1 includesKey:varName) ifFalse:[ |
|
1394 |
changeSet add:varName |
|
1395 |
] ifTrue:[ |
|
1396 |
(varIndex ~~ (offsets1 at:varName)) ifTrue:[ |
|
1397 |
changeSet add:varName |
|
1398 |
] |
|
1399 |
] |
|
1400 |
]. |
|
1401 |
^ changeSet |
|
195 | 1402 |
|
621 | 1403 |
" |
1404 |
View class |
|
1405 |
differentInstanceVariableOffsetsIn:View |
|
1406 |
and:StandardSystemView |
|
1407 |
View class |
|
1408 |
differentInstanceVariableOffsetsIn:Object |
|
1409 |
and:Point |
|
1410 |
" |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1411 |
! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1412 |
|
621 | 1413 |
invalidCodeObject |
1414 |
"When recompiling classes after a definition-change, all |
|
1415 |
uncompilable methods will be bound to this method here, |
|
1416 |
so that evaluating such an uncompilable method will trigger an error. |
|
1417 |
Can also happen when Compiler/runtime system is broken." |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1418 |
|
621 | 1419 |
self error:'invalid method - this method failed to compile when the class was changed' |
1047 | 1420 |
! |
1421 |
||
1422 |
setSoleInstance:aClass |
|
1423 |
myClass := aClass |
|
1424 |
||
1425 |
"Created: 12.12.1995 / 13:46:22 / cg" |
|
1 | 1426 |
! ! |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1427 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1428 |
!Metaclass methodsFor:'queries'! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1429 |
|
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1430 |
isBuiltInClass |
1266 | 1431 |
"return true if this class is known by the run-time-system. |
1432 |
Here, true is returned for myself, false for subclasses." |
|
1433 |
||
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1434 |
^ self == Metaclass class or:[self == Metaclass] |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1435 |
|
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1436 |
"Created: 15.4.1996 / 17:17:34 / cg" |
1266 | 1437 |
"Modified: 23.4.1996 / 15:59:37 / cg" |
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1438 |
! |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1439 |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1440 |
isMeta |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1441 |
"return true, if the receiver is some kind of metaclass; |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1442 |
true is returned here. Redefines isMeta in Object" |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1443 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1444 |
^ true |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1445 |
! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1446 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1447 |
soleInstance |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1448 |
"return my sole class." |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1449 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1450 |
^ myClass |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1451 |
! ! |
621 | 1452 |
|
639 | 1453 |
!Metaclass class methodsFor:'documentation'! |
1454 |
||
1455 |
version |
|
1292 | 1456 |
^ '$Header: /cvs/stx/stx/libbasic/Metaclass.st,v 1.53 1996-04-25 16:45:49 cg Exp $' |
639 | 1457 |
! ! |