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