author | Claus Gittinger <cg@exept.de> |
Wed, 07 Sep 2011 15:23:13 +0200 | |
changeset 486 | 6ad7db3428da |
parent 471 | 6ade6cb144aa |
child 487 | e7bdc9fb797e |
permissions | -rw-r--r-- |
52 | 1 |
"{ Package: 'stx:goodies/monticello' }" |
2 |
||
3 |
MCDefinition subclass:#MCMethodDefinition |
|
471 | 4 |
instanceVariableNames:'classIsMeta source category selector className timeStamp |
5 |
installedClassName' |
|
52 | 6 |
classVariableNames:'Definitions' |
7 |
poolDictionaries:'' |
|
8 |
category:'Monticello-Modeling' |
|
9 |
! |
|
10 |
||
11 |
||
12 |
!MCMethodDefinition class methodsFor:'as yet unclassified'! |
|
13 |
||
14 |
cachedDefinitions |
|
187 | 15 |
Definitions ifNil: [Definitions := WeakIdentityDictionary new. WeakArray addDependent: Definitions]. |
16 |
^ Definitions |
|
17 |
||
18 |
"Modified: / 26-08-2009 / 12:20:45 / Jaroslav Havlin <havlij6@fel.cvut.cz>" |
|
52 | 19 |
! |
20 |
||
21 |
className: classString |
|
22 |
classIsMeta: metaBoolean |
|
23 |
selector: selectorString |
|
24 |
category: catString |
|
25 |
timeStamp: timeString |
|
26 |
source: sourceString |
|
27 |
^ self instanceLike: |
|
28 |
(self new initializeWithClassName: classString |
|
29 |
classIsMeta: metaBoolean |
|
30 |
selector: selectorString |
|
31 |
category: catString |
|
32 |
timeStamp: timeString |
|
33 |
source: sourceString) |
|
34 |
! |
|
35 |
||
36 |
className: classString |
|
37 |
selector: selectorString |
|
38 |
category: catString |
|
39 |
timeStamp: timeString |
|
40 |
source: sourceString |
|
41 |
^ self className: classString |
|
42 |
classIsMeta: false |
|
43 |
selector: selectorString |
|
44 |
category: catString |
|
45 |
timeStamp: timeString |
|
46 |
source: sourceString |
|
47 |
! |
|
48 |
||
49 |
forMethodReference: aMethodReference |
|
50 |
| definition | |
|
51 |
definition := self cachedDefinitions at: aMethodReference compiledMethod ifAbsent: []. |
|
52 |
(definition isNil |
|
53 |
or: [definition selector ~= aMethodReference methodSymbol] |
|
54 |
or: [definition className ~= aMethodReference classSymbol] |
|
55 |
or: [definition classIsMeta ~= aMethodReference classIsMeta] |
|
56 |
or: [definition category ~= aMethodReference category]) |
|
57 |
ifTrue: [definition := self |
|
58 |
className: aMethodReference classSymbol |
|
59 |
classIsMeta: aMethodReference classIsMeta |
|
60 |
selector: aMethodReference methodSymbol |
|
61 |
category: aMethodReference category |
|
62 |
timeStamp: aMethodReference timeStamp |
|
63 |
source: aMethodReference source. |
|
64 |
self cachedDefinitions at: aMethodReference compiledMethod put: definition]. |
|
65 |
^ definition |
|
66 |
||
67 |
! |
|
68 |
||
69 |
initialize |
|
187 | 70 |
" |
146
e92158173b96
more porting (but still unfinished)
Claus Gittinger <cg@exept.de>
parents:
52
diff
changeset
|
71 |
Smalltalk addToShutDownList: self |
187 | 72 |
" |
73 |
||
74 |
"Modified: / 13-10-2010 / 14:12:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 | 75 |
! |
76 |
||
77 |
shutDown |
|
78 |
WeakArray removeWeakDependent: Definitions. |
|
187 | 79 |
Definitions := nil. |
52 | 80 |
! ! |
81 |
||
82 |
!MCMethodDefinition methodsFor:'accessing'! |
|
83 |
||
84 |
actualClass |
|
471 | 85 |
^ Smalltalk |
486 | 86 |
at:(installedClassName ? className) |
471 | 87 |
ifPresent: [:class | |
88 |
classIsMeta |
|
89 |
ifTrue: [class theMetaclass "classSide"] |
|
90 |
ifFalse: [class] |
|
91 |
] |
|
465 | 92 |
|
486 | 93 |
"Modified: / 07-09-2011 / 15:23:00 / cg" |
52 | 94 |
! |
95 |
||
96 |
category |
|
97 |
^ category |
|
98 |
! |
|
99 |
||
100 |
classIsMeta |
|
101 |
^ classIsMeta |
|
102 |
! |
|
103 |
||
104 |
className |
|
105 |
^className |
|
106 |
! |
|
107 |
||
108 |
fullTimeStamp |
|
187 | 109 |
^Timestamp fromMethodTimeStamp: timeStamp |
52 | 110 |
! |
111 |
||
471 | 112 |
installedClassName |
113 |
^ installedClassName ? className |
|
114 |
||
115 |
"Created: / 07-09-2011 / 13:36:37 / cg" |
|
116 |
! |
|
117 |
||
52 | 118 |
selector |
119 |
^selector |
|
120 |
! |
|
121 |
||
122 |
source |
|
123 |
^ source |
|
124 |
! |
|
125 |
||
126 |
timeStamp |
|
127 |
^ timeStamp |
|
128 |
! ! |
|
129 |
||
130 |
!MCMethodDefinition methodsFor:'annotations'! |
|
131 |
||
132 |
printAnnotations: requests on: aStream |
|
133 |
"Add a string for an annotation pane, trying to fulfill the annotation requests. |
|
134 |
These might include anything that |
|
135 |
Preferences defaultAnnotationRequests |
|
136 |
might return. Which includes anything in |
|
137 |
Preferences annotationInfo |
|
138 |
To edit these, use:" |
|
139 |
"Preferences editAnnotations" |
|
140 |
||
141 |
requests do: [ :aRequest | |
|
142 |
aRequest == #timeStamp ifTrue: [ aStream nextPutAll: self timeStamp ]. |
|
143 |
aRequest == #messageCategory ifTrue: [ aStream nextPutAll: self category ]. |
|
144 |
aRequest == #requirements ifTrue: [ |
|
145 |
self requirements do: [ :req | |
|
146 |
aStream nextPutAll: req ] separatedBy: [ aStream space ]]. |
|
147 |
] separatedBy: [ aStream space ]. |
|
148 |
! ! |
|
149 |
||
150 |
!MCMethodDefinition methodsFor:'comparing'! |
|
151 |
||
152 |
= aDefinition |
|
187 | 153 |
^(super = aDefinition) |
154 |
and: [aDefinition source = self source |
|
155 |
and: [aDefinition category = self category |
|
156 |
"and: [aDefinition timeStamp = self timeStamp]"]] |
|
157 |
||
158 |
"Modified: / 18-08-2009 / 10:18:43 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
159 |
"Modified: / 14-09-2010 / 19:03:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 | 160 |
! |
161 |
||
162 |
hash |
|
163 |
| hash | |
|
187 | 164 |
hash := String stringHash: classIsMeta asString initialHash: 0. |
165 |
hash := String stringHash: source initialHash: hash. |
|
166 |
hash := String stringHash: category initialHash: hash. |
|
167 |
hash := String stringHash: className initialHash: hash. |
|
52 | 168 |
^ hash |
169 |
! |
|
170 |
||
171 |
requirements |
|
172 |
^ Array with: className |
|
173 |
! |
|
174 |
||
175 |
sortKey |
|
176 |
^ self className, '.', (self classIsMeta ifTrue: ['meta'] ifFalse: ['nonmeta']), '.', self selector |
|
177 |
! ! |
|
178 |
||
187 | 179 |
!MCMethodDefinition methodsFor:'converting'! |
180 |
||
181 |
asChange |
|
182 |
||
183 |
^MethodDefinitionChange new |
|
184 |
mcDefinition: self; |
|
185 |
className: className , (classIsMeta ifTrue:[' class'] ifFalse:['']); |
|
186 |
selector: selector; |
|
187 |
source: source asStringWithNativeLineEndings; |
|
188 |
category: category; |
|
189 |
yourself |
|
190 |
||
191 |
"Created: / 13-10-2010 / 17:17:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
192 |
"Modified: / 08-11-2010 / 17:56:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
193 |
! ! |
|
194 |
||
52 | 195 |
!MCMethodDefinition methodsFor:'installing'! |
196 |
||
197 |
isExtensionMethod |
|
198 |
^ category beginsWith: '*' |
|
199 |
! |
|
200 |
||
201 |
isOverrideMethod |
|
202 |
"this oughta check the package" |
|
203 |
^ self isExtensionMethod and: [category endsWith: '-override'] |
|
204 |
! |
|
205 |
||
187 | 206 |
load |
471 | 207 |
| env package oldMethod newMethod | |
208 |
||
209 |
env := MCStXNamespaceQuery query ? Smalltalk. |
|
210 |
(env ~~ Smalltalk) ifTrue:[ |
|
486 | 211 |
installedClassName := (env name,'::',className) asSymbol |
471 | 212 |
]. |
213 |
||
187 | 214 |
package := MCStXPackageQuery query. |
215 |
oldMethod := self actualClass compiledMethodAt: self selector. |
|
216 |
(oldMethod notNil and:[oldMethod package ~= package]) |
|
217 |
ifTrue:[Class methodRedefinitionNotification |
|
218 |
raiseRequestWith: (oldMethod -> self)]. |
|
219 |
||
220 |
newMethod := self actualClass |
|
221 |
compile: source asStringWithNativeLineEndings |
|
222 |
classified: category |
|
223 |
withStamp: timeStamp |
|
224 |
"notifying: (SyntaxError new category: category)". |
|
225 |
newMethod package: package |
|
226 |
||
227 |
"Modified: / 08-11-2010 / 20:13:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
486 | 228 |
"Modified: / 07-09-2011 / 15:22:53 / cg" |
187 | 229 |
! |
230 |
||
231 |
postloadOver: aDefinition |
|
232 |
super postloadOver: aDefinition. |
|
233 |
(self isInitializer |
|
234 |
and: [ self actualClass isTrait not ] |
|
235 |
and: [ aDefinition isNil or: [ self source ~= aDefinition source ] ]) ifTrue: [ |
|
236 |
self actualClass theNonMetaClass initialize ] |
|
52 | 237 |
! |
238 |
||
239 |
scanForPreviousVersion |
|
240 |
| position prevPos prevFileIndex preamble tokens sourceFilesCopy stamp method file methodCategory | |
|
187 | 241 |
method := self actualClass compiledMethodAt: selector ifAbsent: [^ nil]. |
242 |
position := method filePosition. |
|
243 |
sourceFilesCopy := SourceFiles collect: |
|
52 | 244 |
[:x | x isNil ifTrue: [ nil ] |
245 |
ifFalse: [x readOnlyCopy]]. |
|
246 |
[method fileIndex == 0 ifTrue: [^ nil]. |
|
187 | 247 |
file := sourceFilesCopy at: method fileIndex. |
52 | 248 |
[position notNil & file notNil] |
249 |
whileTrue: |
|
250 |
[file position: (0 max: position-150). "Skip back to before the preamble" |
|
251 |
[file position < (position-1)] "then pick it up from the front" |
|
187 | 252 |
whileTrue: [preamble := file nextChunk]. |
52 | 253 |
|
254 |
"Preamble is likely a linked method preamble, if we're in |
|
255 |
a changes file (not the sources file). Try to parse it |
|
256 |
for prior source position and file index" |
|
187 | 257 |
prevPos := nil. |
258 |
stamp := ''. |
|
52 | 259 |
(preamble findString: 'methodsFor:' startingAt: 1) > 0 |
187 | 260 |
ifTrue: [tokens := Scanner new scanTokens: preamble] |
261 |
ifFalse: [tokens := Array new "ie cant be back ref"]. |
|
52 | 262 |
((tokens size between: 7 and: 8) |
263 |
and: [(tokens at: tokens size-5) = #methodsFor:]) |
|
264 |
ifTrue: |
|
265 |
[(tokens at: tokens size-3) = #stamp: |
|
266 |
ifTrue: ["New format gives change stamp and unified prior pointer" |
|
187 | 267 |
stamp := tokens at: tokens size-2. |
268 |
prevPos := tokens last. |
|
269 |
prevFileIndex := sourceFilesCopy fileIndexFromSourcePointer: prevPos. |
|
270 |
prevPos := sourceFilesCopy filePositionFromSourcePointer: prevPos] |
|
52 | 271 |
ifFalse: ["Old format gives no stamp; prior pointer in two parts" |
187 | 272 |
prevPos := tokens at: tokens size-2. |
273 |
prevFileIndex := tokens last]. |
|
274 |
(prevPos = 0 or: [prevFileIndex = 0]) ifTrue: [prevPos := nil]]. |
|
52 | 275 |
((tokens size between: 5 and: 6) |
276 |
and: [(tokens at: tokens size-3) = #methodsFor:]) |
|
277 |
ifTrue: |
|
278 |
[(tokens at: tokens size-1) = #stamp: |
|
279 |
ifTrue: ["New format gives change stamp and unified prior pointer" |
|
187 | 280 |
stamp := tokens at: tokens size]]. |
281 |
methodCategory := tokens after: #methodsFor: ifAbsent: ['as yet unclassifed']. |
|
52 | 282 |
methodCategory = category ifFalse: |
283 |
[methodCategory = (Smalltalk |
|
284 |
at: #Categorizer |
|
285 |
ifAbsent: [Smalltalk at: #ClassOrganizer]) |
|
187 | 286 |
default ifTrue: [methodCategory := methodCategory, ' ']. |
52 | 287 |
^ ChangeRecord new file: file position: position type: #method |
288 |
class: className category: methodCategory meta: classIsMeta stamp: stamp]. |
|
187 | 289 |
position := prevPos. |
52 | 290 |
prevPos notNil ifTrue: |
187 | 291 |
[file := sourceFilesCopy at: prevFileIndex]]. |
52 | 292 |
^ nil] |
293 |
ensure: [sourceFilesCopy do: [:x | x notNil ifTrue: [x close]]] |
|
294 |
||
295 |
! |
|
296 |
||
297 |
unload |
|
187 | 298 |
| previousVersion class | |
299 |
||
300 |
(class := self actualClass) ifNotNil: [class removeSelector: selector]. |
|
301 |
^self. |
|
302 |
||
303 |
"Original stuff" |
|
471 | 304 |
self todo:'cg: why was the code below removed? see browsers previous versions code'. |
187 | 305 |
|
306 |
self isOverrideMethod ifTrue: [previousVersion := self scanForPreviousVersion]. |
|
307 |
previousVersion |
|
308 |
ifNil: [(class := self actualClass) ifNotNil: [class removeSelector: selector]] |
|
309 |
ifNotNil: [previousVersion fileIn] |
|
310 |
||
311 |
"Modified: / 11-09-2010 / 18:44:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
471 | 312 |
"Modified: / 07-09-2011 / 13:39:38 / cg" |
52 | 313 |
! ! |
314 |
||
315 |
!MCMethodDefinition methodsFor:'printing'! |
|
316 |
||
317 |
description |
|
318 |
^ Array |
|
319 |
with: className |
|
320 |
with: selector |
|
321 |
with: classIsMeta |
|
322 |
! |
|
323 |
||
324 |
fullClassName |
|
187 | 325 |
"Using #class selector for classes for backwards compatibility" |
326 |
||
52 | 327 |
^ self classIsMeta |
328 |
ifFalse: [self className] |
|
187 | 329 |
ifTrue: [ |
330 |
(self actualClass isNil or: [ self actualClass isTrait ]) |
|
331 |
ifFalse: [self className, ' class'] |
|
332 |
ifTrue: [self className, ' classSide']] |
|
52 | 333 |
! |
334 |
||
335 |
summary |
|
336 |
^ self fullClassName , '>>' , selector |
|
337 |
! ! |
|
338 |
||
187 | 339 |
!MCMethodDefinition methodsFor:'private'! |
340 |
||
341 |
existingMethodOrNil |
|
342 |
| actualClass | |
|
343 |
actualClass := self actualClass. |
|
344 |
^actualClass |
|
345 |
ifNil:[nil] |
|
346 |
ifNotNil: [actualClass compiledMethodAt:self selector] |
|
347 |
||
348 |
"Modified: / 08-11-2010 / 17:41:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
349 |
! ! |
|
350 |
||
52 | 351 |
!MCMethodDefinition methodsFor:'serializing'! |
352 |
||
353 |
initializeWithClassName: classString |
|
354 |
classIsMeta: metaBoolean |
|
355 |
selector: selectorString |
|
356 |
category: catString |
|
357 |
timeStamp: timeString |
|
187 | 358 |
source: sourceString |
359 |
className := classString asSymbol. |
|
360 |
selector := selectorString asSymbol. |
|
361 |
category := catString asSymbol. |
|
362 |
timeStamp := timeString. |
|
363 |
classIsMeta := metaBoolean. |
|
364 |
source := sourceString asStringWithSqueakLineEndings. |
|
365 |
||
366 |
"Modified: / 12-09-2010 / 16:02:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 | 367 |
! ! |
368 |
||
369 |
!MCMethodDefinition methodsFor:'testing'! |
|
370 |
||
371 |
isCodeDefinition |
|
372 |
^ true |
|
373 |
! |
|
374 |
||
375 |
isInitializer |
|
376 |
^ selector = #initialize and: [classIsMeta] |
|
377 |
||
378 |
! |
|
379 |
||
380 |
isMethodDefinition |
|
381 |
^true |
|
187 | 382 |
! |
383 |
||
384 |
isOverrideDefinition |
|
385 |
||
386 |
| oldMethod | |
|
387 |
||
388 |
oldMethod := self existingMethodOrNil. |
|
389 |
^oldMethod |
|
390 |
ifNil:[false] |
|
391 |
ifNotNil:[oldMethod package ~= MCStXPackageQuery query] |
|
392 |
||
393 |
"Created: / 08-11-2010 / 17:29:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 | 394 |
! ! |
395 |
||
396 |
!MCMethodDefinition methodsFor:'visiting'! |
|
397 |
||
398 |
accept: aVisitor |
|
399 |
^ aVisitor visitMethodDefinition: self |
|
400 |
! ! |
|
401 |
||
402 |
!MCMethodDefinition class methodsFor:'documentation'! |
|
403 |
||
269 | 404 |
version |
486 | 405 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCMethodDefinition.st,v 1.7 2011-09-07 13:23:13 cg Exp $' |
269 | 406 |
! |
407 |
||
187 | 408 |
version_CVS |
486 | 409 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCMethodDefinition.st,v 1.7 2011-09-07 13:23:13 cg Exp $' |
146
e92158173b96
more porting (but still unfinished)
Claus Gittinger <cg@exept.de>
parents:
52
diff
changeset
|
410 |
! |
e92158173b96
more porting (but still unfinished)
Claus Gittinger <cg@exept.de>
parents:
52
diff
changeset
|
411 |
|
187 | 412 |
version_SVN |
413 |
^ '§Id: MCMethodDefinition.st 24 2010-11-09 14:00:17Z vranyj1 §' |
|
52 | 414 |
! ! |
415 |
||
416 |
MCMethodDefinition initialize! |