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