author | Claus Gittinger <cg@exept.de> |
Fri, 24 Jan 1997 19:16:48 +0100 | |
changeset 2256 | ffd565c6e084 |
parent 2233 | 0dd796870a34 |
child 2308 | db44ef9a050e |
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:[ |
2132
05d2be2d280e
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2108
diff
changeset
|
98 |
'Metaclass [warning]: no name in my class' errorPrintCR. |
1087 | 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 |
|
1480
df0bea6285f8
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
1461
diff
changeset
|
105 |
"Modified: 19.6.1996 / 14:30:58 / stefan" |
2132
05d2be2d280e
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2108
diff
changeset
|
106 |
"Modified: 10.1.1997 / 17:55:08 / cg" |
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. |
|
1875 | 299 |
newMetaclass recompileInvalidatedMethods. |
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" |
1875 | 438 |
"Modified: 4.11.1996 / 22:12:20 / 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 |
||
1910 | 473 |
|newClass newMetaclass nInstVars nameString classSymbol nameKey oldClass |
1439 | 474 |
classVarChange instVarChange superClassChange newComment |
475 |
changeSet1 changeSet2 addedNames |
|
476 |
anyChange oldInstVars newInstVars oldClassVars newClassVars superFlags newFlags |
|
1897 | 477 |
pkg idx spec nClassInstVars superInstVars |
2039 | 478 |
realNewName thisIsPrivate oldCIVNames newCIVNames msg nsName namespace |
2108 | 479 |
oldSuperClass newSuperClass globalExistedBefore oldCategory| |
1439 | 480 |
|
481 |
"NOTICE: |
|
482 |
this method is too complex and should be splitted into managable pieces ... |
|
483 |
I dont like it anymore :-) |
|
484 |
(well, at least, its a good test for the compilers ability |
|
485 |
to handle big, complex methods ;-) |
|
486 |
take it as an example of bad coding style ... |
|
487 |
||
488 |
ST-80 uses a ClassBuilder object to collect the work and perform all updates; |
|
489 |
this method may be changed to do something similar in the future ... |
|
490 |
" |
|
491 |
||
492 |
Behavior flushSubclassInfo. |
|
493 |
||
1733
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
494 |
(newName isSymbol not |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
495 |
or:[newName size == 0]) ifTrue:[ |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
496 |
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
|
497 |
^ nil |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
498 |
]. |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
499 |
newName first isLetter ifFalse:[ |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
500 |
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
|
501 |
^ nil |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
502 |
]. |
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
503 |
|
1439 | 504 |
"check for invalid subclassing of UndefinedObject and SmallInteger" |
2039 | 505 |
aClass notNil ifTrue:[ |
506 |
aClass canBeSubclassed ifFalse:[ |
|
507 |
self error:('it is not possible to subclass ' , aClass name). |
|
508 |
^ nil |
|
509 |
] |
|
1439 | 510 |
]. |
511 |
||
2103 | 512 |
" |
513 |
Check for invalid variable names (dublicates) |
|
514 |
" |
|
515 |
(self |
|
516 |
checkValidVarNamesFor:newName |
|
517 |
subClassOf:aClass |
|
518 |
instVarNames:stringOfInstVarNames |
|
519 |
classVarNames:stringOfClassVarNames) |
|
520 |
ifFalse:[ |
|
521 |
^ nil |
|
522 |
]. |
|
523 |
||
1439 | 524 |
nInstVars := stringOfInstVarNames countWords. |
525 |
nameString := newName asString. |
|
526 |
classSymbol := newName asSymbol. |
|
527 |
newComment := commentString. |
|
528 |
||
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
529 |
namespace := aSystemDictionaryOrClass. |
1910 | 530 |
nameKey := classSymbol. |
1749 | 531 |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
532 |
(namespace notNil |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
533 |
and:[namespace isNamespace not]) ifTrue:[ |
1749 | 534 |
thisIsPrivate := true. |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
535 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
1742 | 536 |
] ifFalse:[ |
1749 | 537 |
thisIsPrivate := false. |
1742 | 538 |
realNewName := classSymbol. |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
539 |
|
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
540 |
"/ does the name imply a nameSpace ? |
1835
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
541 |
((idx := realNewName indexOf:$:)) ~~ 0 ifTrue:[ |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
542 |
"/ check for this namespace to exist |
1835
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
543 |
nsName := realNewName copyTo:(idx - 1). |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
544 |
nsName := nsName asSymbol. |
1835
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
545 |
(realNewName indexOf:$: startingAt:(idx+2)) ~~ 0 ifTrue:[ |
1830 | 546 |
self warn:('nested namespaces are not (yet) implemented.') withCRs. |
547 |
^ nil |
|
548 |
]. |
|
549 |
||
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
550 |
namespace := Smalltalk at:nsName ifAbsent:nil. |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
551 |
namespace isNamespace ifFalse:[ |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
552 |
namespace isNil ifTrue:[ |
1916
3597f8ae2c50
ask createNameSpaceQuerySignal
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
553 |
(Class createNameSpaceQuerySignal raise |
3597f8ae2c50
ask createNameSpaceQuerySignal
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
554 |
or:[(self |
3597f8ae2c50
ask createNameSpaceQuerySignal
Claus Gittinger <cg@exept.de>
parents:
1910
diff
changeset
|
555 |
confirm:('nonexistent namespace: `' , nsName , '''.\\Create ?') withCRs)]) |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
556 |
ifFalse:[^ nil]. |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
557 |
namespace := Namespace name:nsName. |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
558 |
] ifFalse:[ |
1830 | 559 |
self warn:('a global named ' , nsName , ' exists, but is no namespace.') withCRs. |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
560 |
^ nil |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
561 |
] |
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
562 |
]. |
1910 | 563 |
namespace isNamespace ifTrue:[ |
564 |
nameKey := (classSymbol copyFrom:(nsName size + 3)) asSymbol. |
|
565 |
] |
|
1921 | 566 |
] ifFalse:[ |
2035
5b79c170d6a3
oops - nil environment caused a debug-popup
Claus Gittinger <cg@exept.de>
parents:
2008
diff
changeset
|
567 |
(namespace notNil and:[namespace ~~ Smalltalk]) ifTrue:[ |
1921 | 568 |
realNewName := (namespace name , '::' , classSymbol) asSymbol. |
569 |
] |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
570 |
] |
1742 | 571 |
]. |
572 |
||
2233
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
573 |
(aClass notNil and:[realNewName = aClass name]) ifTrue:[ |
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
574 |
self error:'trying to create circular class definition'. |
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
575 |
^ nil |
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
576 |
]. |
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
577 |
|
1439 | 578 |
"look, if it already exists as a class" |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
579 |
namespace notNil ifTrue:[ |
1749 | 580 |
thisIsPrivate ifFalse:[ |
1910 | 581 |
oldClass := namespace at:nameKey ifAbsent:[nil]. |
1749 | 582 |
] ifTrue:[ |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
583 |
oldClass := namespace privateClassesAt:classSymbol. |
1724 | 584 |
] |
1439 | 585 |
]. |
1742 | 586 |
|
1439 | 587 |
(oldClass isBehavior and:[oldClass isLoaded]) ifFalse:[ |
588 |
oldClass := nil. |
|
1749 | 589 |
|
590 |
thisIsPrivate ifTrue:[ |
|
591 |
Compiler warnSTXSpecials ifTrue:[ |
|
592 |
(self confirm:('support for private classes is an ST/X extension.\\continue ?') withCRs) |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
593 |
ifFalse:[^ nil]. |
1749 | 594 |
] |
595 |
]. |
|
1439 | 596 |
] ifTrue:[ |
1742 | 597 |
oldClass name ~= realNewName ifTrue:[ |
1439 | 598 |
(self confirm:(classSymbol , ' is an alias for ' , oldClass name , '\\continue ?') withCRs) |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
599 |
ifFalse:[^ nil]. |
1439 | 600 |
oldClass := nil |
601 |
] ifFalse:[ |
|
602 |
"/ |
|
603 |
"/ some consisteny checks |
|
604 |
"/ |
|
605 |
oldClass superclass notNil ifTrue:[ |
|
606 |
oldClass allSuperclasses do:[:cls | |
|
1776
794f35149de7
oops - use full name when checking for circular definition
Claus Gittinger <cg@exept.de>
parents:
1757
diff
changeset
|
607 |
cls name = realNewName ifTrue:[ |
1439 | 608 |
self error:'trying to create circular class definition'. |
609 |
^ nil |
|
610 |
] |
|
611 |
] |
|
612 |
]. |
|
613 |
||
2039 | 614 |
aClass notNil ifTrue:[ |
615 |
aClass superclass notNil ifTrue:[ |
|
616 |
aClass allSuperclasses do:[:cls | |
|
617 |
cls name = realNewName ifTrue:[ |
|
618 |
self error:'trying to create circular class definition'. |
|
619 |
^ nil |
|
620 |
] |
|
621 |
]. |
|
1439 | 622 |
]. |
623 |
]. |
|
624 |
||
625 |
newComment isNil ifTrue:[ |
|
626 |
newComment := oldClass comment |
|
627 |
]. |
|
628 |
||
629 |
" |
|
630 |
warn, if it exists with different category and different instvars, |
|
631 |
and the existing is not an autoload class. |
|
632 |
Usually, this indicates that someone wants to create a new class with |
|
633 |
a name, which already exists (it happened a few times to myself, while |
|
634 |
I wanted to create a new class called ReturnNode ...). |
|
635 |
This will be much less of a problem, once multiple name spaces are |
|
636 |
implemented and classes can be put into separate packages. |
|
637 |
" |
|
638 |
oldClass isLoaded ifTrue:[ |
|
639 |
oldClass category ~= categoryString ifTrue:[ |
|
640 |
oldClass instanceVariableString asCollectionOfWords |
|
641 |
~= stringOfInstVarNames asCollectionOfWords ifTrue:[ |
|
642 |
(self confirm:'a class named ' , oldClass name , |
|
643 |
' already exists -\\create (i.e. change) anyway ?' withCRs) |
|
644 |
ifFalse:[ |
|
645 |
^ nil |
|
646 |
] |
|
647 |
] |
|
648 |
] |
|
649 |
]. |
|
650 |
||
651 |
"/ |
|
652 |
"/ hints - warn, if creating a variableSubclass of a Set |
|
653 |
"/ (common error - containers in ST/X do not use variable-slots) |
|
654 |
"/ |
|
655 |
((variableBoolean == true) and:[pointersBoolean]) ifTrue:[ |
|
656 |
(oldClass isKindOf:Set class) ifTrue:[ |
|
657 |
(self confirm:'ST/X Set & Dictionary are not variable-classes\create anyway ?' withCRs) |
|
658 |
ifFalse:[ |
|
659 |
^ nil |
|
660 |
] |
|
661 |
] |
|
662 |
] |
|
663 |
] |
|
664 |
]. |
|
665 |
||
666 |
" |
|
667 |
Check for some 'considered bad-style' things, like lower case names. |
|
668 |
But only do these checks for new classes - |
|
669 |
- thus, once confirmed, the warnings will not come again and again. |
|
670 |
||
671 |
NOTICE: |
|
672 |
I dont like the confirmers there - we need a notifying: argument, to give |
|
673 |
the outer codeview a chance to highlight the error. |
|
674 |
(but thats how its defined in the book - maybe I will change anyway). |
|
675 |
" |
|
676 |
oldClass isNil ifTrue:[ |
|
1752 | 677 |
(self |
678 |
checkConventionsFor:newName |
|
679 |
subClassOf:aClass |
|
680 |
instVarNames:stringOfInstVarNames |
|
681 |
classVarNames:stringOfClassVarNames) |
|
682 |
ifFalse:[ |
|
1439 | 683 |
^ nil |
684 |
] |
|
685 |
]. |
|
686 |
||
1698 | 687 |
aClass notNil ifTrue:[ |
1809
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
688 |
" |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
689 |
check for instVar redef of superClass instVars |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
690 |
" |
1698 | 691 |
superInstVars := aClass allInstVarNames. |
692 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
|
693 |
(superInstVars includes:nm) ifTrue:[ |
|
1809
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
694 |
(oldClass notNil |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
695 |
and:[stringOfInstVarNames = oldClass instanceVariableString]) |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
696 |
ifTrue:[ |
1877 | 697 |
msg := 'instVar conflict in `' , newName , ''' for `' , nm , ''' due to superclass change.\You now have two different instVar slots with the same name.\\Dont forget to fix this later.'. |
1809
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
698 |
self warn:msg withCRs. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
699 |
] ifFalse:[ |
1877 | 700 |
msg := 'instVar `' , nm , ''' is already defined in a superclass.\Change the definition of `' , newName , ''' anyway ?\\Notice: you must fix the superclass later.'. |
1809
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
701 |
(self confirm:msg withCRs) ifFalse:[ |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
702 |
^ nil. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
703 |
] |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
704 |
]. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
705 |
] |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
706 |
]. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
707 |
]. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
708 |
|
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
709 |
oldClass notNil ifTrue:[ |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
710 |
" |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
711 |
check for instVar redefs in subclass instVars |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
712 |
" |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
713 |
oldClass allSubclassesDo:[:sub | |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
714 |
|vars| |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
715 |
|
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
716 |
vars := sub instVarNames. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
717 |
stringOfInstVarNames asCollectionOfWords do:[:nm | |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
718 |
(vars includes:nm) ifTrue:[ |
1877 | 719 |
(self confirm:('subclass ' , sub name , ' already defines an instVar named `' , nm , '''.\\Change the definition of `' , newName , ''' anyway ?\Notice: you must fix the subclass later.') withCRs) |
1809
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
720 |
ifFalse:[ |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
721 |
^ nil. |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
722 |
] |
d5f8d427904b
more care for instVar redefinitions (check subclasses);
Claus Gittinger <cg@exept.de>
parents:
1798
diff
changeset
|
723 |
] |
1698 | 724 |
] |
725 |
] |
|
726 |
]. |
|
727 |
||
1439 | 728 |
nClassInstVars := stringOfClassInstVarNames countWords. |
729 |
||
730 |
"create the metaclass first" |
|
1749 | 731 |
thisIsPrivate ifTrue:[ |
1733
2cc88c50db99
check for valid className (symbol & startsWith a letter).
Claus Gittinger <cg@exept.de>
parents:
1732
diff
changeset
|
732 |
newMetaclass := PrivateMetaclass new |
1725 | 733 |
] ifFalse:[ |
734 |
newMetaclass := Metaclass new. |
|
735 |
]. |
|
2039 | 736 |
aClass isNil ifTrue:[ |
737 |
newMetaclass setSuperclass:Class. |
|
738 |
newMetaclass instSize:(Class instSize + nClassInstVars). |
|
739 |
] ifFalse:[ |
|
740 |
newMetaclass setSuperclass:(aClass class). |
|
741 |
newMetaclass instSize:(aClass class instSize + nClassInstVars). |
|
742 |
]. |
|
1724 | 743 |
newMetaclass classVariableString:''. |
1439 | 744 |
newMetaclass setInstanceVariableString:stringOfClassInstVarNames. |
745 |
||
746 |
"then let the new meta create the class" |
|
747 |
newClass := newMetaclass new. |
|
748 |
newClass setSuperclass:aClass. |
|
2039 | 749 |
aClass isNil ifTrue:[ |
750 |
newClass instSize:nInstVars. |
|
751 |
] ifFalse:[ |
|
752 |
newClass instSize:(aClass instSize + nInstVars). |
|
753 |
]. |
|
1724 | 754 |
|
1749 | 755 |
thisIsPrivate ifTrue:[ |
1724 | 756 |
"/ some private class |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
757 |
newMetaclass setOwningClass:namespace. |
1921 | 758 |
]. |
759 |
||
760 |
(namespace notNil |
|
761 |
and:[namespace ~~ Smalltalk]) ifTrue:[ |
|
1910 | 762 |
newClass setName:(namespace name , '::' , nameKey) asSymbol. |
1724 | 763 |
] ifFalse:[ |
764 |
newClass setName:classSymbol. |
|
765 |
]. |
|
1439 | 766 |
newClass setComment:newComment category:categoryString. |
767 |
||
1778
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
768 |
oldClass notNil ifTrue:[ |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
769 |
"/ copy over classInstanceVariables |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
770 |
"/ 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
|
771 |
|
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
772 |
oldCIVNames := oldClass class allInstVarNames asSet. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
773 |
newCIVNames := newClass class allInstVarNames asSet. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
774 |
Class class allInstVarNames do:[:n | |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
775 |
oldCIVNames remove:n ifAbsent:nil. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
776 |
newCIVNames remove:n ifAbsent:nil. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
777 |
]. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
778 |
|
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
779 |
newCIVNames size > 0 ifTrue:[ |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
780 |
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
|
781 |
newCIVNames do:[:n | |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
782 |
(oldCIVNames includes:n) ifTrue:[ |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
783 |
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
|
784 |
] |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
785 |
] |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
786 |
]. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
787 |
]. |
fd558245c662
preserve values of classInstVars when creating a new class
Claus Gittinger <cg@exept.de>
parents:
1776
diff
changeset
|
788 |
|
1439 | 789 |
"/ set the new classes package |
790 |
"/ but prefer the old package |
|
791 |
||
792 |
oldClass notNil ifTrue:[ |
|
1835
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
793 |
pkg := oldClass package. |
1439 | 794 |
newClass setBinaryRevision:(oldClass binaryRevision). |
795 |
] ifFalse:[ |
|
1897 | 796 |
pkg := Class packageQuerySignal raise |
1439 | 797 |
]. |
1835
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
798 |
pkg notNil ifTrue:[ |
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
799 |
newMetaclass package:pkg. |
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
800 |
newClass package:pkg. |
1439 | 801 |
]. |
802 |
||
803 |
" |
|
804 |
Allowing non-booleans as variableBoolean |
|
805 |
is a hack for backward (ST-80) compatibility: |
|
806 |
||
807 |
ST-80 code will pass true or false as variableBoolean, |
|
808 |
while ST/X also calls it with symbols such as #float, #double etc. |
|
809 |
" |
|
810 |
(variableBoolean == true) ifTrue:[ |
|
811 |
pointersBoolean ifTrue:[ |
|
812 |
newFlags := Behavior flagPointers |
|
813 |
] ifFalse:[ |
|
814 |
wordsBoolean ifTrue:[ |
|
815 |
newFlags := Behavior flagWords |
|
816 |
] ifFalse:[ |
|
817 |
newFlags := Behavior flagBytes |
|
818 |
] |
|
819 |
] |
|
820 |
] ifFalse:[ |
|
1655 | 821 |
"/ false or symbol. |
822 |
newFlags := Behavior flagForSymbolic:variableBoolean. |
|
1439 | 823 |
]. |
2039 | 824 |
aClass isNil ifTrue:[ |
825 |
superFlags := 0 |
|
826 |
] ifFalse:[ |
|
827 |
superFlags := aClass flags bitAnd:(Behavior maskIndexType bitInvert). "preserve other bits" |
|
828 |
]. |
|
829 |
||
1439 | 830 |
oldClass notNil ifTrue:[ |
831 |
oldClass isBuiltInClass ifTrue:[ |
|
832 |
" |
|
833 |
special care when redefining Method, Block and other built-in classes, |
|
834 |
which might have other flag bits ... |
|
835 |
" |
|
836 |
||
837 |
newFlags := newFlags bitOr:(oldClass flags bitAnd:(Behavior maskIndexType bitInvert)) |
|
838 |
] |
|
839 |
]. |
|
840 |
newClass flags:(newFlags bitOr:superFlags). "preserve inherited special bits" |
|
841 |
||
842 |
(nInstVars ~~ 0) ifTrue:[ |
|
843 |
newClass setInstanceVariableString:stringOfInstVarNames |
|
844 |
]. |
|
845 |
oldClass notNil ifTrue:[ |
|
846 |
" |
|
847 |
setting first will make new class clear obsolete classvars |
|
848 |
" |
|
849 |
newClass setClassVariableString:(oldClass classVariableString). |
|
1835
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
850 |
(spec := oldClass primitiveSpec) notNil ifTrue:[ |
e90fe211cdf1
oops - corrupted the package on autolaod
Claus Gittinger <cg@exept.de>
parents:
1830
diff
changeset
|
851 |
newClass primitiveSpec:spec. |
1439 | 852 |
newClass setClassFilename:(oldClass classFilename). |
853 |
] |
|
854 |
]. |
|
855 |
newClass classVariableString:stringOfClassVarNames. |
|
856 |
||
857 |
" |
|
858 |
for new classes, we are almost done here |
|
859 |
(also for autoloaded classes) |
|
860 |
" |
|
861 |
(oldClass isNil or:[oldClass isLoaded not]) ifTrue:[ |
|
862 |
(oldClass isNil and:[changed]) ifTrue:[ |
|
863 |
self addChangeRecordForClass:newClass. |
|
864 |
]. |
|
865 |
||
866 |
commentString notNil ifTrue:[ |
|
867 |
newClass comment:commentString |
|
868 |
]. |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
869 |
namespace notNil ifTrue:[ |
1749 | 870 |
thisIsPrivate ifTrue:[ |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
871 |
namespace privateClassesAt:classSymbol put:newClass. |
1749 | 872 |
] ifFalse:[ |
1910 | 873 |
namespace at:nameKey put:newClass. |
1724 | 874 |
] |
1439 | 875 |
]. |
876 |
||
877 |
oldClass isNil ifTrue:[ |
|
1897 | 878 |
newClass package:(Class packageQuerySignal raise) |
1439 | 879 |
]. |
880 |
||
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
881 |
namespace notNil ifTrue:[ |
1749 | 882 |
thisIsPrivate ifTrue:[ |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
883 |
namespace changed. |
1749 | 884 |
] ifFalse:[ |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
885 |
namespace changed:#newClass with:newClass. |
1922
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
886 |
namespace ~~ Smalltalk ifTrue:[ |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
887 |
Smalltalk changed:#newClass with:newClass. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
888 |
] |
1724 | 889 |
] |
1439 | 890 |
]. |
2103 | 891 |
|
892 |
"/ be very careful, when adding classes |
|
893 |
"/ to a namespace. When adding, all methods within the |
|
894 |
"/ same namespace which access the unprefixed-global |
|
895 |
"/ must be recompiled (so they access the new class) |
|
896 |
||
897 |
(namespace notNil and:[namespace ~~ Smalltalk]) ifTrue:[ |
|
898 |
"/ namespace allBehaviorsDo:[:aClass | |
|
899 |
"/ Transcript showCR:'recompiling methods in ' , aClass name , ' accessing ' , newClass nameWithoutNameSpacePrefix. |
|
900 |
"/ Transcript endEntry. |
|
901 |
"/ aClass recompileMethodsAccessingAny:(newClass nameWithoutNameSpacePrefix) |
|
902 |
"/ ] |
|
903 |
]. |
|
904 |
||
1439 | 905 |
^ newClass |
906 |
]. |
|
907 |
||
908 |
" |
|
909 |
here comes the hard part - we are actually changing the |
|
910 |
definition of an existing class .... |
|
911 |
Try hard to get away WITHOUT recompiling, since it makes all |
|
912 |
compiled code into interpreted ... |
|
913 |
" |
|
914 |
||
915 |
oldInstVars := oldClass instanceVariableString asCollectionOfWords. |
|
916 |
newInstVars := newClass instanceVariableString asCollectionOfWords. |
|
917 |
oldClassVars := oldClass classVariableString asCollectionOfWords. |
|
918 |
newClassVars := newClass classVariableString asCollectionOfWords. |
|
919 |
||
2039 | 920 |
oldSuperClass := oldClass superclass. |
921 |
newSuperClass := newClass superclass. |
|
922 |
superClassChange := oldSuperClass ~~ newSuperClass. |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
923 |
|
1439 | 924 |
" |
925 |
we are on the bright side of life, if the instance layout and |
|
926 |
inheritance do not change. |
|
927 |
In this case, we can go ahead and patch the class object. |
|
928 |
" |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
929 |
|
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
930 |
superClassChange ifFalse:[ |
1439 | 931 |
(oldClass instSize == newClass instSize) ifTrue:[ |
932 |
(oldClass flags == newClass flags) ifTrue:[ |
|
933 |
(oldClass name = newClass name) ifTrue:[ |
|
934 |
(oldInstVars = newInstVars) ifTrue:[ |
|
935 |
||
936 |
(newComment ~= oldClass comment) ifTrue:[ |
|
937 |
oldClass setComment:newComment. "writes a change-chunk" |
|
938 |
oldClass changed:#comment with:oldClass comment. |
|
939 |
changed ifTrue:[ |
|
940 |
self addChangeRecordForClassComment:oldClass. |
|
941 |
] |
|
942 |
]. |
|
943 |
||
944 |
(oldClassVars = newClassVars) ifTrue:[ |
|
945 |
" |
|
946 |
really no change (just comment and/or category) |
|
947 |
" |
|
948 |
anyChange := false. |
|
949 |
||
950 |
oldClass setInstanceVariableString:(newClass instanceVariableString). |
|
951 |
oldClass setClassVariableString:(newClass classVariableString). |
|
952 |
||
953 |
oldClass category ~= categoryString ifTrue:[ |
|
954 |
oldClass category:categoryString. |
|
955 |
changed ifTrue:[ |
|
956 |
self addChangeRecordForClass:newClass. |
|
957 |
]. |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
958 |
namespace notNil ifTrue:[ |
1749 | 959 |
thisIsPrivate ifFalse:[ |
1724 | 960 |
"notify change of category" |
1922
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
961 |
namespace changed:#organization. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
962 |
namespace ~~ Smalltalk ifTrue:[ |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
963 |
Smalltalk changed:#organization. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
964 |
] |
1724 | 965 |
] |
1439 | 966 |
] |
967 |
]. |
|
968 |
"notify change of class" |
|
969 |
"/ oldClass changed. |
|
970 |
^ oldClass |
|
971 |
]. |
|
972 |
||
973 |
" |
|
974 |
when we arrive here, class variables have changed |
|
975 |
" |
|
976 |
oldClass category ~= categoryString ifTrue:[ |
|
977 |
"notify change of organization" |
|
978 |
oldClass category:categoryString. |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
979 |
namespace notNil ifTrue:[ |
1749 | 980 |
thisIsPrivate ifFalse:[ |
1922
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
981 |
"notify change of organization" |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
982 |
namespace changed:#organization. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
983 |
namespace ~~ Smalltalk ifTrue:[ |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
984 |
Smalltalk changed:#organization. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
985 |
] |
1724 | 986 |
] |
1439 | 987 |
]. |
988 |
]. |
|
989 |
||
990 |
" |
|
991 |
set class variable string; |
|
992 |
this also updates the set of class variables |
|
993 |
by creating new / deleting obsolete ones. |
|
994 |
" |
|
995 |
oldClass classVariableString:stringOfClassVarNames. |
|
996 |
||
997 |
" |
|
998 |
get the set of changed class variables |
|
999 |
" |
|
1000 |
changeSet1 := Set new. |
|
1001 |
oldClassVars do:[:nm | |
|
1002 |
(newClassVars includes:nm) ifFalse:[ |
|
2039 | 1003 |
"/ a removed classVar; |
1004 |
"/ must recompile methods accessing that one: |
|
1005 |
"/ access was: classVar; now: global. |
|
1439 | 1006 |
changeSet1 add:nm |
1007 |
] |
|
1008 |
]. |
|
1009 |
newClassVars do:[:nm | |
|
1010 |
(oldClassVars includes:nm) ifFalse:[ |
|
2039 | 1011 |
"/ an added classVar; |
1012 |
"/ must recompile methods accessing that one: |
|
1013 |
"/ access was: global; now: classVar. |
|
1014 |
"/ but only, if such a global existed in the first |
|
1015 |
"/ place. (otherwise, it is a brand-new name) |
|
1016 |
(Smalltalk includesKey:nm asSymbol) ifTrue:[ |
|
1017 |
changeSet1 add:nm |
|
1018 |
] |
|
1439 | 1019 |
] |
1020 |
]. |
|
1021 |
||
2103 | 1022 |
changeSet1 isEmpty ifFalse:[ |
1023 |
" |
|
1024 |
recompile all methods accessing set of changed classvars |
|
1025 |
here and also in all subclasses ... |
|
1026 |
" |
|
1439 | 1027 |
|
2103 | 1028 |
" |
1029 |
dont update change file for the recompilation |
|
1030 |
" |
|
1031 |
Class withoutUpdatingChangesDo:[ |
|
1439 | 1032 |
" " |
2103 | 1033 |
Transcript showCR:'recompiling class & inst methods accessing ' , changeSet1 printString. |
1034 |
Transcript endEntry. |
|
1439 | 1035 |
" " |
2103 | 1036 |
oldClass withAllSubclasses do:[:aClass | |
1037 |
aClass class recompileMethodsAccessingAny:changeSet1. |
|
1038 |
aClass recompileMethodsAccessingAny:changeSet1. |
|
1039 |
]. |
|
1439 | 1040 |
]. |
1041 |
]. |
|
1042 |
||
1043 |
"notify change of class" |
|
1044 |
changed ifTrue:[ |
|
1045 |
self addChangeRecordForClass:oldClass. |
|
1046 |
]. |
|
1047 |
oldClass changed:#definition. |
|
1048 |
||
1049 |
^ oldClass |
|
1050 |
] |
|
1051 |
] |
|
1052 |
] |
|
1053 |
] |
|
1054 |
]. |
|
1055 |
||
1056 |
" |
|
1057 |
here we enter the darkness of mordor ... |
|
1058 |
since instance variable layout and/or inheritance has changed. |
|
1059 |
" |
|
1060 |
(newComment ~= oldClass comment) ifTrue:[ |
|
1061 |
newClass comment:newComment |
|
1062 |
]. |
|
1063 |
||
1064 |
" |
|
1065 |
dont allow built-in classes to be modified this way |
|
1066 |
" |
|
1067 |
(oldClass notNil and:[oldClass isBuiltInClass and:[superClassChange]]) ifTrue:[ |
|
1068 |
self error:'the inheritance of this class is fixed - you cannot change it'. |
|
1069 |
^ oldClass |
|
1070 |
]. |
|
1071 |
||
1072 |
" |
|
1073 |
catch special case, where superclass changed its layout and thus |
|
1074 |
forced redefinition of this class; |
|
1075 |
only log if this is not the case. |
|
1076 |
" |
|
1077 |
changed ifTrue:[ |
|
1078 |
(superClassChange |
|
2039 | 1079 |
and:[(oldSuperClass isNil or:[oldSuperClass name = newSuperClass name]) |
1439 | 1080 |
and:[(oldClassVars = newClassVars) |
1081 |
and:[(oldInstVars = newInstVars) |
|
1082 |
and:[newComment = oldClass comment]]]]) ifFalse:[ |
|
1083 |
self addChangeRecordForClass:newClass. |
|
1084 |
] |
|
1085 |
]. |
|
1086 |
||
1087 |
" |
|
1088 |
care for class methods ... |
|
1089 |
" |
|
1090 |
changeSet1 := Set new. |
|
1091 |
||
1092 |
classVarChange := false. |
|
1093 |
||
1094 |
superClassChange ifTrue:[ |
|
2039 | 1095 |
(oldSuperClass notNil |
1096 |
and:[newSuperClass notNil |
|
1097 |
and:[oldSuperClass allClassVarNames = newSuperClass allClassVarNames |
|
1098 |
and:[oldSuperClass name = newSuperClass name |
|
1099 |
and:[oldClassVars = newClassVars]]]]) |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1100 |
ifTrue:[ |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1101 |
" " |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1102 |
Transcript showCR:'keep class methods (same classvars)'. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1103 |
Transcript endEntry. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1104 |
" " |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1105 |
" |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1106 |
class methods still work |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1107 |
" |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1108 |
self copyMethodsFrom:(oldClass class) for:newMetaclass |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1109 |
] ifFalse:[ |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1110 |
" |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1111 |
superclass changed: |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1112 |
must recompile all class methods accessing ANY classvar |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1113 |
( |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1114 |
actually, we could be less strict and handle the case where |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1115 |
both the old and the new superclass have a common ancestor, |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1116 |
and both have no new classvariables in between. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1117 |
This would speedup the case when a class is inserted into |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1118 |
the inheritance chain. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1119 |
) |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1120 |
" |
1439 | 1121 |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1122 |
oldClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1123 |
newClass allClassVarNames do:[:nm | changeSet1 add:nm]. |
1439 | 1124 |
|
1125 |
" " |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1126 |
Transcript showCR:'recompiling class methods accessing any classvar'. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1127 |
Transcript endEntry. |
1439 | 1128 |
" " |
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1129 |
self copyInvalidatedMethodsFrom:(oldClass class) |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1130 |
for:newMetaclass |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1131 |
accessingAny:changeSet1 |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1132 |
orSuper:true. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1133 |
newMetaclass recompileInvalidatedMethods. |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1134 |
] |
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1135 |
]ifFalse:[ |
1439 | 1136 |
" |
1137 |
same superclass, find out which classvars have changed |
|
1138 |
" |
|
1139 |
classVarChange := oldClassVars ~= newClassVars. |
|
1140 |
classVarChange ifTrue:[ |
|
1141 |
oldClassVars do:[:nm | |
|
1142 |
(newClassVars includes:nm) ifFalse:[ |
|
1143 |
changeSet1 add:nm |
|
1144 |
] |
|
1145 |
]. |
|
1146 |
newClassVars do:[:nm | |
|
1147 |
(oldClassVars includes:nm) ifFalse:[ |
|
1148 |
changeSet1 add:nm |
|
1149 |
] |
|
1150 |
]. |
|
1151 |
" |
|
1152 |
must recompile some class-methods |
|
1153 |
" |
|
1154 |
" " |
|
1155 |
Transcript showCR:'recompiling class methods accessing ' , changeSet1 printString. |
|
1156 |
Transcript endEntry. |
|
1157 |
" " |
|
1158 |
self copyInvalidatedMethodsFrom:(oldClass class) for:newMetaclass accessingAny:changeSet1. |
|
1875 | 1159 |
newMetaclass recompileInvalidatedMethods. |
1439 | 1160 |
] ifFalse:[ |
1161 |
" |
|
1162 |
class methods still work |
|
1163 |
" |
|
1164 |
self copyMethodsFrom:(oldClass class) for:newMetaclass |
|
1165 |
]. |
|
1166 |
]. |
|
1167 |
||
1168 |
" |
|
1169 |
care for instance methods ... |
|
1170 |
" |
|
1171 |
||
1172 |
superClassChange ifTrue:[ |
|
1173 |
"superclass changed, |
|
1174 |
must recompile all methods accessing any class or instvar. |
|
1175 |
If number of instvars (i.e. the instances instSize) is the same, |
|
1176 |
we can limit the set of recompiled instance methods to those methods, |
|
1177 |
which refer to an instvar with a different inst-index |
|
1178 |
" |
|
1179 |
||
1180 |
" |
|
1181 |
the changeset consists of instance variables, |
|
1182 |
with a different position |
|
1183 |
" |
|
1184 |
changeSet2 := self differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1185 |
||
1186 |
" |
|
1187 |
merge in the changed class variables |
|
1188 |
" |
|
1189 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
1190 |
||
1191 |
" " |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1192 |
Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' [superclass change]...'. |
1439 | 1193 |
Transcript endEntry. |
1194 |
" " |
|
1195 |
self copyInvalidatedMethodsFrom:oldClass |
|
1196 |
for:newClass |
|
1197 |
accessingAny:changeSet2 |
|
1198 |
orSuper:true. |
|
1875 | 1199 |
newClass recompileInvalidatedMethods. |
1439 | 1200 |
|
1201 |
] ifFalse:[ |
|
1202 |
" |
|
1203 |
same inheritance ... |
|
1204 |
" |
|
1205 |
instVarChange := oldInstVars ~= newInstVars. |
|
1206 |
instVarChange ifFalse:[ |
|
1207 |
" |
|
1208 |
same instance variables ... |
|
1209 |
" |
|
1210 |
classVarChange ifTrue:[ |
|
1211 |
"recompile all inst methods accessing changed classvars" |
|
1212 |
||
1213 |
" " |
|
2002
6af05dcbebf8
no need to recompile class methods, if
Claus Gittinger <cg@exept.de>
parents:
1937
diff
changeset
|
1214 |
Transcript showCR:'recompiling instance methods accessing classvars ' , changeSet1 printString , ' ...'. |
1439 | 1215 |
Transcript endEntry. |
1216 |
" " |
|
1217 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet1. |
|
1875 | 1218 |
newClass recompileInvalidatedMethods. |
1439 | 1219 |
] |
1220 |
] ifTrue:[ |
|
1221 |
" |
|
1222 |
dont allow built-in classes to be modified |
|
1223 |
" |
|
1224 |
(oldClass notNil and:[oldClass isBuiltInClass and:[instVarChange]]) ifTrue:[ |
|
1225 |
self error:'the layout of this class is fixed - you cannot change it'. |
|
1226 |
^ oldClass |
|
1227 |
]. |
|
1228 |
||
1229 |
((oldInstVars size == 0) |
|
1230 |
or:[newInstVars startsWith:oldInstVars]) ifTrue:[ |
|
1231 |
" |
|
1232 |
only new inst variable(s) has/have been added - |
|
1233 |
old methods still work (the existing inst-indices are still valid) |
|
1234 |
" |
|
1235 |
" " |
|
1236 |
Transcript showCR:'copying methods ...'. |
|
1237 |
Transcript endEntry. |
|
1238 |
" " |
|
1239 |
self copyMethodsFrom:oldClass for:newClass. |
|
1240 |
||
1241 |
" |
|
1242 |
but: we have to recompile all methods accessing new instars |
|
1243 |
(it might have been a classVar/global before ...) |
|
1244 |
" |
|
1245 |
addedNames := newInstVars select:[:nm | (oldInstVars includes:nm) not]. |
|
1246 |
"merge in class variables" |
|
1247 |
changeSet1 do:[:nm | addedNames add:nm]. |
|
1248 |
||
1249 |
" " |
|
1250 |
Transcript showCR:'recompiling instance methods accessing ' , addedNames printString , '...'. |
|
1251 |
Transcript endEntry. |
|
1252 |
" " |
|
1253 |
newClass recompileMethodsAccessingAny:addedNames. |
|
1254 |
] ifFalse:[ |
|
1255 |
||
1256 |
" |
|
1257 |
the changeset consists of instance variables, |
|
1258 |
with a different position |
|
1259 |
" |
|
1260 |
changeSet2 := self differentInstanceVariableOffsetsIn:oldClass and:newClass. |
|
1261 |
||
1262 |
"merge in the class variables" |
|
1263 |
changeSet1 do:[:nm | changeSet2 add:nm]. |
|
1264 |
" " |
|
1265 |
Transcript showCR:'recompiling instance methods accessing ' , changeSet2 printString , ' ...'. |
|
1266 |
Transcript endEntry. |
|
1267 |
" " |
|
1268 |
self copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:changeSet2. |
|
1875 | 1269 |
newClass recompileInvalidatedMethods. |
1439 | 1270 |
]. |
1271 |
]. |
|
1272 |
]. |
|
1273 |
||
1274 |
" |
|
1275 |
WOW, everything done for this class |
|
1276 |
what about subclasses ? |
|
1277 |
" |
|
1278 |
||
1279 |
" |
|
1280 |
update superclass of immediate subclasses - |
|
1281 |
this forces recompilation (recursively) if needed |
|
1282 |
(dont update change file for the subclass changes) |
|
1283 |
" |
|
1284 |
Class withoutUpdatingChangesDo:[ |
|
1285 |
oldClass subclassesDo:[:aClass | |
|
1286 |
" " |
|
1287 |
Transcript showCR:'changing superclass of:' , aClass name. |
|
1288 |
Transcript endEntry. |
|
1289 |
" " |
|
1290 |
aClass superclass:newClass |
|
1291 |
] |
|
1292 |
]. |
|
1293 |
||
1294 |
" |
|
1819
e53f745ed80b
when changing a class, do not forget to move the privateClasses
Claus Gittinger <cg@exept.de>
parents:
1809
diff
changeset
|
1295 |
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
|
1296 |
" |
e53f745ed80b
when changing a class, do not forget to move the privateClasses
Claus Gittinger <cg@exept.de>
parents:
1809
diff
changeset
|
1297 |
oldClass privateClassesDo:[:aClass | |
e53f745ed80b
when changing a class, do not forget to move the privateClasses
Claus Gittinger <cg@exept.de>
parents:
1809
diff
changeset
|
1298 |
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
|
1299 |
]. |
e53f745ed80b
when changing a class, do not forget to move the privateClasses
Claus Gittinger <cg@exept.de>
parents:
1809
diff
changeset
|
1300 |
|
e53f745ed80b
when changing a class, do not forget to move the privateClasses
Claus Gittinger <cg@exept.de>
parents:
1809
diff
changeset
|
1301 |
" |
1439 | 1302 |
change category in oldClass - so we see immediately what it is ... |
1303 |
" |
|
2108 | 1304 |
oldCategory := oldClass category. |
1655 | 1305 |
oldClass category:#'* obsolete *'. |
1306 |
oldClass class category:#'* obsolete *'. |
|
1439 | 1307 |
|
1308 |
" |
|
1309 |
and make the new class globally known |
|
1310 |
" |
|
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
1311 |
namespace notNil ifTrue:[ |
1749 | 1312 |
thisIsPrivate ifTrue:[ |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
1313 |
namespace privateClassesAt:classSymbol put:newClass. |
1749 | 1314 |
] ifFalse:[ |
1910 | 1315 |
namespace at:nameKey put:newClass. |
1829
9e2a9fea35d0
ask to create nameSpace if it does not exist.
Claus Gittinger <cg@exept.de>
parents:
1821
diff
changeset
|
1316 |
namespace == Smalltalk ifTrue:[ |
1798
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1317 |
self checkForAliasesOf:oldClass with:newClass. |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1318 |
]. |
1439 | 1319 |
|
2108 | 1320 |
oldCategory ~= categoryString ifTrue:[ |
1724 | 1321 |
"notify change of organization" |
1922
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
1322 |
namespace changed:#organization. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
1323 |
namespace ~~ Smalltalk ifTrue:[ |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
1324 |
Smalltalk changed:#organization. |
0f0e0c992fc0
also send a change notifiaction for Smalltalk,
Claus Gittinger <cg@exept.de>
parents:
1921
diff
changeset
|
1325 |
] |
1724 | 1326 |
] |
1439 | 1327 |
]. |
1328 |
]. |
|
1329 |
||
1330 |
" |
|
1331 |
Not becoming the old class creates some update problems; |
|
1332 |
the browsers must check carefully - a simple identity compare is |
|
1333 |
not enough ... |
|
1334 |
QUESTION: is this a good idea ? |
|
1335 |
" |
|
1336 |
||
1337 |
newClass dependents:(oldClass dependents). |
|
1338 |
newClass changed:#definition. |
|
1339 |
||
1340 |
"just to make certain ... - tell dependents of oldClass, that something changed |
|
1341 |
(systemBrowsers will react on this, and update their views)" |
|
1342 |
oldClass changed:#definition with:newClass. |
|
1343 |
||
1344 |
ObjectMemory flushCaches. |
|
1345 |
||
1346 |
^ newClass |
|
1347 |
||
1348 |
"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
|
1349 |
"Modified: 18.6.1996 / 14:19:39 / stefan" |
2233
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
1350 |
"Modified: 23.1.1997 / 01:19:54 / cg" |
1439 | 1351 |
! |
1352 |
||
1 | 1353 |
name:newName inEnvironment:aSystemDictionary |
1439 | 1354 |
subclassOf:aClass |
1355 |
instanceVariableNames:stringOfInstVarNames |
|
1356 |
variable:variableBoolean |
|
1357 |
words:wordsBoolean |
|
1358 |
pointers:pointersBoolean |
|
1359 |
classVariableNames:stringOfClassVarNames |
|
1360 |
poolDictionaries:stringOfPoolNames |
|
1361 |
category:categoryString |
|
1362 |
comment:commentString |
|
1363 |
changed:changed |
|
1 | 1364 |
|
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
|
1365 |
^ self |
1439 | 1366 |
name:newName |
1367 |
in:aSystemDictionary |
|
1368 |
subclassOf:aClass |
|
1369 |
instanceVariableNames:stringOfInstVarNames |
|
1370 |
variable:variableBoolean |
|
1371 |
words:wordsBoolean |
|
1372 |
pointers:pointersBoolean |
|
1373 |
classVariableNames:stringOfClassVarNames |
|
1374 |
poolDictionaries:stringOfPoolNames |
|
1375 |
category:categoryString |
|
1376 |
comment:commentString |
|
1377 |
changed:changed |
|
1378 |
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
|
1379 |
|
1439 | 1380 |
"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
|
1381 |
! |
ca805f0f4984
changed class creation to allow create including classInstVars (may be used to avoid recompilation)
Claus Gittinger <cg@exept.de>
parents:
870
diff
changeset
|
1382 |
|
621 | 1383 |
new |
1384 |
"create & return a new metaclass (a classes class). |
|
1385 |
Since metaclasses only have one instance (the class), |
|
1386 |
complain if there is already one. |
|
1387 |
You get a new class by sending #new to the returned metaclass |
|
1388 |
(confusing - isn't it ?)" |
|
1389 |
||
1390 |
|newClass| |
|
1391 |
||
1392 |
myClass notNil ifTrue:[ |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1393 |
^ self error:'Each metaclass may only have one instance'. |
621 | 1394 |
]. |
1395 |
newClass := self basicNew. |
|
1396 |
newClass setSuperclass:Object |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1397 |
methodDictionary:MethodDictionary new |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1398 |
instSize:0 |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1399 |
flags:(Behavior flagBehavior). |
621 | 1400 |
newClass setName:'someClass'. |
1401 |
myClass := newClass. |
|
1402 |
^ newClass |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1403 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1404 |
"Modified: 7.6.1996 / 15:39:11 / stefan" |
1 | 1405 |
! ! |
1406 |
||
1875 | 1407 |
!Metaclass methodsFor:'private'! |
68 | 1408 |
|
1752 | 1409 |
checkConventionsFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
621 | 1410 |
"Check for some 'considered bad-style' things, like lower case names. |
1411 |
NOTICE: |
|
1412 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
1413 |
the outer codeview a chance to highlight the error. |
|
1414 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
308 | 1415 |
" |
621 | 1416 |
|
2008
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1417 |
|superClassInstVarNames names idx what| |
1752 | 1418 |
|
621 | 1419 |
"let user confirm, if the classname is no good" |
1420 |
className first isUppercase ifFalse:[ |
|
2008
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1421 |
aClass == Namespace ifTrue:[ |
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1422 |
what := 'namespace' |
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1423 |
] ifFalse:[ |
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1424 |
what := 'class' |
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1425 |
]. |
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1426 |
(self confirm:(what , ' name ''' , className , |
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1427 |
''' should start with an uppercase letter |
621 | 1428 |
(by convention only) |
308 | 1429 |
|
2008
381a5160be9a
only a nicer warning message
Claus Gittinger <cg@exept.de>
parents:
2002
diff
changeset
|
1430 |
install anyway ?') withCRs) |
1752 | 1431 |
ifFalse:[ |
1432 |
^ false |
|
1433 |
] |
|
621 | 1434 |
]. |
1435 |
||
2103 | 1436 |
names := instVarNameString asCollectionOfWords. |
1437 |
||
621 | 1438 |
"let user confirm, if any instvarname is no good" |
1936 | 1439 |
(idx := names findFirst:[:word | word first isUppercase]) ~~ 0 ifTrue:[ |
1937 | 1440 |
(self confirm:className , ': instance variable named ''' , (names at:idx) asText allBold , ''' |
1441 |
should start with a lowercase letter (by convention only). |
|
621 | 1442 |
|
1937 | 1443 |
Install anyway ?' withCRs) |
1752 | 1444 |
ifFalse:[ |
1445 |
^ false |
|
1446 |
] |
|
308 | 1447 |
]. |
621 | 1448 |
|
2103 | 1449 |
names := classVarNameString asCollectionOfWords. |
1450 |
||
621 | 1451 |
"let user confirm, if any classvarname is no good" |
1936 | 1452 |
(idx := names findFirst:[:word | word first isLowercase]) ~~ 0 ifTrue:[ |
1937 | 1453 |
(self confirm:className , ': class variable named ''' , (names at:idx) asText allBold , ''' |
1454 |
should start with an uppercase letter (by convention only). |
|
308 | 1455 |
|
1937 | 1456 |
Install anyway ?' withCRs) |
1752 | 1457 |
ifFalse:[ |
1458 |
^ false |
|
1459 |
]. |
|
621 | 1460 |
]. |
308 | 1461 |
|
621 | 1462 |
^ true |
1752 | 1463 |
|
1464 |
"Created: 15.10.1996 / 11:56:38 / cg" |
|
2103 | 1465 |
"Modified: 8.1.1997 / 21:09:29 / cg" |
1 | 1466 |
! |
1467 |
||
1798
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1468 |
checkForAliasesOf:oldClass with:newClass |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1469 |
"oldClass changed its identity (now use newClass). |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1470 |
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
|
1471 |
|
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1472 |
Smalltalk keysAndValuesDo:[:nm :o | |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1473 |
o == oldClass ifTrue:[ |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1474 |
nm ~~ oldClass name ifTrue:[ |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1475 |
(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
|
1476 |
ifTrue:[ |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1477 |
Smalltalk at:nm put:newClass |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1478 |
] |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1479 |
] |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1480 |
] |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1481 |
]. |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1482 |
|
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1483 |
"Created: 22.10.1996 / 15:20:59 / cg" |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1484 |
"Modified: 22.10.1996 / 15:25:50 / cg" |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1485 |
! |
543f1601bbeb
look for aliases, when migrating classes
Claus Gittinger <cg@exept.de>
parents:
1778
diff
changeset
|
1486 |
|
2103 | 1487 |
checkValidVarNamesFor:className subClassOf:aClass instVarNames:instVarNameString classVarNames:classVarNameString |
1488 |
"Check for some 'considered bad-style' things, like lower case names. |
|
1489 |
NOTICE: |
|
1490 |
I dont like the confirmers below - we need a notifying: argument, to give |
|
1491 |
the outer codeview a chance to highlight the error. |
|
1492 |
(but thats how its defined in the book - maybe I will change it anyway). |
|
1493 |
" |
|
1494 |
||
1495 |
|names| |
|
1496 |
||
1497 |
names := instVarNameString asCollectionOfWords. |
|
1498 |
||
1499 |
"check for instvar redefs within local instvars" |
|
1500 |
names keysAndValuesDo:[:index :aName | |
|
1501 |
(names indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
2106 | 1502 |
self warn:'instance variable ''' , aName , '''\occurs multiple times in instVarString.\\Class not installed.' withCRs. |
2103 | 1503 |
^ false. |
1504 |
] |
|
1505 |
]. |
|
1506 |
||
1507 |
names := classVarNameString asCollectionOfWords. |
|
1508 |
||
1509 |
"check for classvar redefs within local instvars" |
|
1510 |
names keysAndValuesDo:[:index :aName | |
|
1511 |
(names indexOf:aName startingAt:index+1) ~~ 0 ifTrue:[ |
|
1512 |
self warn:'class variable ''' , aName , '''\occurs multiple times in classVarString.\\Class not installed.' withCRs. |
|
1513 |
^ false. |
|
1514 |
] |
|
1515 |
]. |
|
1516 |
||
1517 |
^ true |
|
1518 |
||
1519 |
"Created: 8.1.1997 / 21:09:14 / cg" |
|
2106 | 1520 |
"Modified: 9.1.1997 / 02:10:02 / cg" |
2103 | 1521 |
! |
1522 |
||
1 | 1523 |
copyInvalidatedMethodsFrom:oldClass for:newClass |
159 | 1524 |
"copy all methods from oldClass to newClass and change their code |
1525 |
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
|
1526 |
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
|
1527 |
before recompilation is attempted. |
159 | 1528 |
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
|
1529 |
now undefined instvars) methods. Later compilation of these methods will show |
159 | 1530 |
an error on the transcript and lead to the debugger once called." |
1 | 1531 |
|
986 | 1532 |
|trap trapCode trapByteCode oldMethod newMethod |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1533 |
oldDict newDict| |
1 | 1534 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1535 |
oldDict := oldClass methodDictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1536 |
newDict := MethodDictionary new:oldDict size. |
1875 | 1537 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1538 |
oldDict keysAndValuesDo:[ :sel :mthd | |
1875 | 1539 |
trap := mthd trapMethodForNumArgs:(mthd numArgs). |
1540 |
trapCode := trap code. |
|
1541 |
trapByteCode := trap byteCode. |
|
1542 |
||
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1543 |
mthd isWrapped ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1544 |
oldMethod := mthd originalMethod |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1545 |
] ifFalse:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1546 |
oldMethod := mthd. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1547 |
]. |
1875 | 1548 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1549 |
newMethod := oldMethod copy. |
1875 | 1550 |
newMethod makeInvalid. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1551 |
newDict at:sel put:newMethod |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1552 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1553 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1554 |
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
|
1555 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1556 |
"Modified: 12.6.1996 / 10:44:27 / stefan" |
1875 | 1557 |
"Modified: 4.11.1996 / 22:55:57 / cg" |
2 | 1558 |
! |
1559 |
||
1560 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames |
|
1561 |
"copy all methods from oldClass to newClass. Those methods accessing |
|
1562 |
a variable in setOfNames will be copied as invalid method, leading to |
|
159 | 1563 |
a trap when its executed. This is used when a class has changed its |
1564 |
layout for all methods which are affected by the change." |
|
1565 |
||
1566 |
self copyInvalidatedMethodsFrom:oldClass |
|
1567 |
for:newClass |
|
1568 |
accessingAny:setOfNames |
|
1569 |
orSuper:false |
|
1570 |
! |
|
1571 |
||
1572 |
copyInvalidatedMethodsFrom:oldClass for:newClass accessingAny:setOfNames orSuper:superBoolean |
|
1573 |
"copy all methods from oldClass to newClass. |
|
1574 |
Those methods accessing a variable in setOfNames will be copied as invalid method, |
|
1575 |
leading to a trap when its executed. If superBoolean is true, this is also done |
|
1576 |
for methods accessing super. This is used when a class has changed its |
|
1577 |
layout for all methods which are affected by the change." |
|
2 | 1578 |
|
1875 | 1579 |
|p source mustInvalidate |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1580 |
oldMethod newMethod methodDict newMethodDict nNames usedVars| |
2 | 1581 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1582 |
methodDict := oldClass methodDictionary. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1583 |
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
|
1584 |
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
|
1585 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1586 |
methodDict keysAndValuesDo:[:selector :method | |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1587 |
method isWrapped ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1588 |
oldMethod := method originalMethod |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1589 |
] ifFalse:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1590 |
oldMethod := method |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1591 |
]. |
202 | 1592 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1593 |
"before parsing (which may take some time), |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1594 |
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
|
1595 |
we are looking for. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1596 |
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
|
1597 |
parsing it right away may be faster ..." |
202 | 1598 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1599 |
source := oldMethod source. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1600 |
((nNames == 1) and:[superBoolean not]) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1601 |
mustInvalidate := (source findString:(setOfNames first)) ~~ 0. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1602 |
] ifFalse:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1603 |
((nNames == 0) and:[superBoolean]) ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1604 |
mustInvalidate := (source findString:'super') ~~ 0. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1605 |
] ifFalse:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1606 |
mustInvalidate := true |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1607 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1608 |
]. |
202 | 1609 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1610 |
mustInvalidate ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1611 |
"we have to parse it ..." |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1612 |
p := Parser parseMethod:source in:newClass. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1613 |
(p isNil |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1614 |
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
|
1615 |
or:[superBoolean and:[p usesSuper]]]) ifFalse:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1616 |
mustInvalidate := false |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1617 |
] |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1618 |
]. |
202 | 1619 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1620 |
mustInvalidate ifTrue:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1621 |
newMethod := oldMethod copy. |
1875 | 1622 |
newMethod makeInvalid. |
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1623 |
] ifFalse:[ |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1624 |
newMethod := oldMethod. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1625 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1626 |
newMethodDict at:selector put:newMethod |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1627 |
]. |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1628 |
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
|
1629 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1630 |
"Modified: 7.6.1996 / 08:33:52 / stefan" |
1875 | 1631 |
"Modified: 4.11.1996 / 22:56:10 / cg" |
1 | 1632 |
! |
1633 |
||
621 | 1634 |
copyMethodsFrom:oldClass for:newClass |
1635 |
"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
|
1636 |
This is used for class-methods when a class has changed, but its metaclass is |
621 | 1637 |
unaffected (i.e. classVars/inheritance have not changed) so there is no need |
1638 |
to recompile the class methods." |
|
195 | 1639 |
|
1461
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1640 |
newClass methodDictionary:(oldClass methodDictionary copy). |
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1641 |
|
dd25bb1e9973
Use methodDictionary instead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
1442
diff
changeset
|
1642 |
"Modified: 7.6.1996 / 08:34:43 / stefan" |
621 | 1643 |
! |
1644 |
||
1645 |
differentInstanceVariableOffsetsIn:class1 and:class2 |
|
1646 |
"return a set of instance variable names which have different |
|
1647 |
positions in class1 and class2. |
|
1648 |
Also, variables which are only present in one class are returned. |
|
1649 |
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
|
1650 |
change in the instance variable layout." |
621 | 1651 |
|
1652 |
|offsets1 offsets2 changeSet| |
|
195 | 1653 |
|
621 | 1654 |
changeSet := Set new. |
1655 |
||
1656 |
" |
|
1657 |
collect the instvar-indices in the old and new class |
|
1658 |
" |
|
1659 |
offsets1 := class1 instanceVariableOffsets. |
|
1660 |
offsets2 := class2 instanceVariableOffsets. |
|
195 | 1661 |
|
621 | 1662 |
" |
912
a009f25a6800
be careful with self-chaning selector/methodArrays (done in VM's lookup)
Claus Gittinger <cg@exept.de>
parents:
904
diff
changeset
|
1663 |
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
|
1664 |
which have a different position |
621 | 1665 |
" |
1666 |
offsets1 keysAndValuesDo:[:varName :varIndex | |
|
1667 |
(offsets2 includesKey:varName) ifFalse:[ |
|
1668 |
changeSet add:varName |
|
1669 |
] ifTrue:[ |
|
1670 |
(varIndex ~~ (offsets2 at:varName)) ifTrue:[ |
|
1671 |
changeSet add:varName |
|
1672 |
] |
|
195 | 1673 |
] |
1674 |
]. |
|
621 | 1675 |
offsets2 keysAndValuesDo:[:varName :varIndex | |
1676 |
(offsets1 includesKey:varName) ifFalse:[ |
|
1677 |
changeSet add:varName |
|
1678 |
] ifTrue:[ |
|
1679 |
(varIndex ~~ (offsets1 at:varName)) ifTrue:[ |
|
1680 |
changeSet add:varName |
|
1681 |
] |
|
1682 |
] |
|
1683 |
]. |
|
1684 |
^ changeSet |
|
195 | 1685 |
|
621 | 1686 |
" |
1687 |
View class |
|
1688 |
differentInstanceVariableOffsetsIn:View |
|
1689 |
and:StandardSystemView |
|
1690 |
View class |
|
1691 |
differentInstanceVariableOffsetsIn:Object |
|
1692 |
and:Point |
|
1693 |
" |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1694 |
! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1695 |
|
1047 | 1696 |
setSoleInstance:aClass |
1697 |
myClass := aClass |
|
1698 |
||
1699 |
"Created: 12.12.1995 / 13:46:22 / cg" |
|
1 | 1700 |
! ! |
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1701 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1702 |
!Metaclass methodsFor:'queries'! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1703 |
|
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1704 |
isBuiltInClass |
1266 | 1705 |
"return true if this class is known by the run-time-system. |
1706 |
Here, true is returned for myself, false for subclasses." |
|
1707 |
||
1179
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1708 |
^ self == Metaclass class or:[self == Metaclass] |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1709 |
|
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1710 |
"Created: 15.4.1996 / 17:17:34 / cg" |
1266 | 1711 |
"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
|
1712 |
! |
3e0f32177af4
allow subclasses of Class to be changed
Claus Gittinger <cg@exept.de>
parents:
1087
diff
changeset
|
1713 |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1714 |
isMeta |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1715 |
"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
|
1716 |
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
|
1717 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1718 |
^ true |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1719 |
! |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1720 |
|
1920 | 1721 |
nameSpace |
1722 |
"return the nameSpace I am contained in. |
|
1723 |
Due to the implementation of nameSpaces (as classVariables), |
|
1724 |
a class can only be contained in one nameSpace (which is the desired)" |
|
1725 |
||
1726 |
"/ this information is in the class |
|
1727 |
||
1728 |
^ myClass nameSpace |
|
1729 |
||
1730 |
"Created: 7.11.1996 / 13:18:52 / cg" |
|
1731 |
! |
|
1732 |
||
1724 | 1733 |
owningClass |
1734 |
"return nil here - regular metaclasses are never private" |
|
1735 |
||
1736 |
^ nil |
|
1737 |
||
1738 |
"Created: 12.10.1996 / 20:12:16 / cg" |
|
1739 |
! |
|
1740 |
||
1757 | 1741 |
package |
1742 |
"return my package-id" |
|
1743 |
||
1744 |
^ myClass package |
|
1745 |
||
1746 |
"Created: 15.10.1996 / 19:44:51 / cg" |
|
1747 |
! |
|
1748 |
||
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1749 |
soleInstance |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1750 |
"return my sole class." |
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1751 |
|
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1752 |
^ myClass |
2047 | 1753 |
! |
1754 |
||
1755 |
topOwningClass |
|
1756 |
"return nil here - regular metaclasses are never private" |
|
1757 |
||
1758 |
^ nil |
|
1759 |
||
1760 |
"Created: 3.1.1997 / 19:18:06 / cg" |
|
457
41c73cbee305
change classes versionString when class changes (prepare for sourceCode system)
Claus Gittinger <cg@exept.de>
parents:
423
diff
changeset
|
1761 |
! ! |
621 | 1762 |
|
1742 | 1763 |
!Metaclass class methodsFor:'documentation'! |
639 | 1764 |
|
1765 |
version |
|
2233
0dd796870a34
a cyclic definition is not always what is seems to be
Claus Gittinger <cg@exept.de>
parents:
2132
diff
changeset
|
1766 |
^ '$Header: /cvs/stx/stx/libbasic/Metaclass.st,v 1.102 1997-01-23 01:11:18 cg Exp $' |
639 | 1767 |
! ! |