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