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