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