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