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