author | Claus Gittinger <cg@exept.de> |
Mon, 14 May 2018 02:21:18 +0200 | |
changeset 1048 | 582b3a028cbc |
parent 1024 | 0224846a4acc |
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 |
|
1048 | 268 |
super postloadOver: aDefinition. |
269 |
(self isInitializer |
|
270 |
and: [ self actualClass isTrait not ] |
|
271 |
and: [ aDefinition isNil or: [ self source ~= aDefinition source ] ]) ifTrue: [ |
|
272 |
Error handle:[:ex | |
|
273 |
Dialog warn:('Error during initialization of %1\\%2' |
|
274 |
bindWith:self actualClass theNonMetaClass name |
|
275 |
with:ex description) |
|
276 |
] do:[self actualClass theNonMetaClass initialize] ] |
|
52 | 277 |
! |
278 |
||
279 |
scanForPreviousVersion |
|
280 |
| position prevPos prevFileIndex preamble tokens sourceFilesCopy stamp method file methodCategory | |
|
187 | 281 |
method := self actualClass compiledMethodAt: selector ifAbsent: [^ nil]. |
282 |
position := method filePosition. |
|
283 |
sourceFilesCopy := SourceFiles collect: |
|
52 | 284 |
[:x | x isNil ifTrue: [ nil ] |
285 |
ifFalse: [x readOnlyCopy]]. |
|
286 |
[method fileIndex == 0 ifTrue: [^ nil]. |
|
187 | 287 |
file := sourceFilesCopy at: method fileIndex. |
52 | 288 |
[position notNil & file notNil] |
289 |
whileTrue: |
|
290 |
[file position: (0 max: position-150). "Skip back to before the preamble" |
|
291 |
[file position < (position-1)] "then pick it up from the front" |
|
187 | 292 |
whileTrue: [preamble := file nextChunk]. |
52 | 293 |
|
294 |
"Preamble is likely a linked method preamble, if we're in |
|
295 |
a changes file (not the sources file). Try to parse it |
|
296 |
for prior source position and file index" |
|
187 | 297 |
prevPos := nil. |
298 |
stamp := ''. |
|
52 | 299 |
(preamble findString: 'methodsFor:' startingAt: 1) > 0 |
187 | 300 |
ifTrue: [tokens := Scanner new scanTokens: preamble] |
301 |
ifFalse: [tokens := Array new "ie cant be back ref"]. |
|
52 | 302 |
((tokens size between: 7 and: 8) |
303 |
and: [(tokens at: tokens size-5) = #methodsFor:]) |
|
304 |
ifTrue: |
|
305 |
[(tokens at: tokens size-3) = #stamp: |
|
306 |
ifTrue: ["New format gives change stamp and unified prior pointer" |
|
187 | 307 |
stamp := tokens at: tokens size-2. |
308 |
prevPos := tokens last. |
|
309 |
prevFileIndex := sourceFilesCopy fileIndexFromSourcePointer: prevPos. |
|
310 |
prevPos := sourceFilesCopy filePositionFromSourcePointer: prevPos] |
|
52 | 311 |
ifFalse: ["Old format gives no stamp; prior pointer in two parts" |
187 | 312 |
prevPos := tokens at: tokens size-2. |
313 |
prevFileIndex := tokens last]. |
|
314 |
(prevPos = 0 or: [prevFileIndex = 0]) ifTrue: [prevPos := nil]]. |
|
52 | 315 |
((tokens size between: 5 and: 6) |
316 |
and: [(tokens at: tokens size-3) = #methodsFor:]) |
|
317 |
ifTrue: |
|
318 |
[(tokens at: tokens size-1) = #stamp: |
|
319 |
ifTrue: ["New format gives change stamp and unified prior pointer" |
|
187 | 320 |
stamp := tokens at: tokens size]]. |
321 |
methodCategory := tokens after: #methodsFor: ifAbsent: ['as yet unclassifed']. |
|
52 | 322 |
methodCategory = category ifFalse: |
937 | 323 |
[methodCategory = (Smalltalk |
324 |
at: #Categorizer |
|
325 |
ifAbsent: [Smalltalk at: #ClassOrganizer]) |
|
187 | 326 |
default ifTrue: [methodCategory := methodCategory, ' ']. |
52 | 327 |
^ ChangeRecord new file: file position: position type: #method |
328 |
class: className category: methodCategory meta: classIsMeta stamp: stamp]. |
|
187 | 329 |
position := prevPos. |
52 | 330 |
prevPos notNil ifTrue: |
187 | 331 |
[file := sourceFilesCopy at: prevFileIndex]]. |
52 | 332 |
^ nil] |
333 |
ensure: [sourceFilesCopy do: [:x | x notNil ifTrue: [x close]]] |
|
937 | 334 |
|
52 | 335 |
! |
336 |
||
337 |
unload |
|
187 | 338 |
| previousVersion class | |
339 |
||
941 | 340 |
#todo. "/ cg please check if the code below was not good after all |
187 | 341 |
|
471 | 342 |
self todo:'cg: why was the code below removed? see browsers previous versions code'. |
941 | 343 |
false ifTrue:[ |
344 |
self isOverrideMethod ifTrue: [previousVersion := self scanForPreviousVersion]. |
|
345 |
]. |
|
187 | 346 |
previousVersion |
347 |
ifNil: [(class := self actualClass) ifNotNil: [class removeSelector: selector]] |
|
348 |
ifNotNil: [previousVersion fileIn] |
|
349 |
||
350 |
"Modified: / 11-09-2010 / 18:44:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
471 | 351 |
"Modified: / 07-09-2011 / 13:39:38 / cg" |
52 | 352 |
! ! |
353 |
||
354 |
!MCMethodDefinition methodsFor:'printing'! |
|
355 |
||
356 |
fullClassName |
|
187 | 357 |
"Using #class selector for classes for backwards compatibility" |
358 |
||
52 | 359 |
^ self classIsMeta |
360 |
ifFalse: [self className] |
|
187 | 361 |
ifTrue: [ |
362 |
(self actualClass isNil or: [ self actualClass isTrait ]) |
|
363 |
ifFalse: [self className, ' class'] |
|
364 |
ifTrue: [self className, ' classSide']] |
|
52 | 365 |
! |
366 |
||
367 |
summary |
|
368 |
^ self fullClassName , '>>' , selector |
|
369 |
! ! |
|
370 |
||
187 | 371 |
!MCMethodDefinition methodsFor:'private'! |
372 |
||
373 |
existingMethodOrNil |
|
374 |
| actualClass | |
|
375 |
actualClass := self actualClass. |
|
937 | 376 |
^actualClass |
187 | 377 |
ifNil:[nil] |
378 |
ifNotNil: [actualClass compiledMethodAt:self selector] |
|
379 |
||
380 |
"Modified: / 08-11-2010 / 17:41:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
381 |
! ! |
|
382 |
||
52 | 383 |
!MCMethodDefinition methodsFor:'serializing'! |
384 |
||
385 |
initializeWithClassName: classString |
|
386 |
classIsMeta: metaBoolean |
|
387 |
selector: selectorString |
|
388 |
category: catString |
|
389 |
timeStamp: timeString |
|
937 | 390 |
source: sourceString |
187 | 391 |
className := classString asSymbol. |
392 |
selector := selectorString asSymbol. |
|
393 |
category := catString asSymbol. |
|
394 |
timeStamp := timeString. |
|
395 |
classIsMeta := metaBoolean. |
|
396 |
source := sourceString asStringWithSqueakLineEndings. |
|
397 |
||
398 |
"Modified: / 12-09-2010 / 16:02:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 | 399 |
! ! |
400 |
||
401 |
!MCMethodDefinition methodsFor:'testing'! |
|
402 |
||
403 |
isCodeDefinition |
|
404 |
^ true |
|
405 |
! |
|
406 |
||
407 |
isInitializer |
|
408 |
^ selector = #initialize and: [classIsMeta] |
|
937 | 409 |
|
52 | 410 |
! |
411 |
||
412 |
isMethodDefinition |
|
413 |
^true |
|
187 | 414 |
! |
415 |
||
416 |
isOverrideDefinition |
|
417 |
||
418 |
| oldMethod | |
|
419 |
||
420 |
oldMethod := self existingMethodOrNil. |
|
937 | 421 |
^oldMethod |
187 | 422 |
ifNil:[false] |
423 |
ifNotNil:[oldMethod package ~= MCStXPackageQuery query] |
|
424 |
||
425 |
"Created: / 08-11-2010 / 17:29:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
52 | 426 |
! ! |
427 |
||
428 |
!MCMethodDefinition methodsFor:'visiting'! |
|
429 |
||
430 |
accept: aVisitor |
|
431 |
^ aVisitor visitMethodDefinition: self |
|
432 |
! ! |
|
433 |
||
434 |
!MCMethodDefinition class methodsFor:'documentation'! |
|
435 |
||
269 | 436 |
version |
1024 | 437 |
^ '$Header$' |
269 | 438 |
! |
439 |
||
187 | 440 |
version_CVS |
1024 | 441 |
^ '$Header$' |
146
e92158173b96
more porting (but still unfinished)
Claus Gittinger <cg@exept.de>
parents:
52
diff
changeset
|
442 |
! |
e92158173b96
more porting (but still unfinished)
Claus Gittinger <cg@exept.de>
parents:
52
diff
changeset
|
443 |
|
187 | 444 |
version_SVN |
1024 | 445 |
^ '$Id$' |
52 | 446 |
! ! |
447 |
||
718 | 448 |
|
52 | 449 |
MCMethodDefinition initialize! |