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
|
|
14 |
Definitions ifNil: [Definitions _ WeakIdentityKeyDictionary new. WeakArray addWeakDependent: Definitions].
|
|
15 |
^ Definitions
|
|
16 |
!
|
|
17 |
|
|
18 |
className: classString
|
|
19 |
classIsMeta: metaBoolean
|
|
20 |
selector: selectorString
|
|
21 |
category: catString
|
|
22 |
timeStamp: timeString
|
|
23 |
source: sourceString
|
|
24 |
^ self instanceLike:
|
|
25 |
(self new initializeWithClassName: classString
|
|
26 |
classIsMeta: metaBoolean
|
|
27 |
selector: selectorString
|
|
28 |
category: catString
|
|
29 |
timeStamp: timeString
|
|
30 |
source: sourceString)
|
|
31 |
!
|
|
32 |
|
|
33 |
className: classString
|
|
34 |
selector: selectorString
|
|
35 |
category: catString
|
|
36 |
timeStamp: timeString
|
|
37 |
source: sourceString
|
|
38 |
^ self className: classString
|
|
39 |
classIsMeta: false
|
|
40 |
selector: selectorString
|
|
41 |
category: catString
|
|
42 |
timeStamp: timeString
|
|
43 |
source: sourceString
|
|
44 |
!
|
|
45 |
|
|
46 |
forMethodReference: aMethodReference
|
|
47 |
| definition |
|
|
48 |
definition := self cachedDefinitions at: aMethodReference compiledMethod ifAbsent: [].
|
|
49 |
(definition isNil
|
|
50 |
or: [definition selector ~= aMethodReference methodSymbol]
|
|
51 |
or: [definition className ~= aMethodReference classSymbol]
|
|
52 |
or: [definition classIsMeta ~= aMethodReference classIsMeta]
|
|
53 |
or: [definition category ~= aMethodReference category])
|
|
54 |
ifTrue: [definition := self
|
|
55 |
className: aMethodReference classSymbol
|
|
56 |
classIsMeta: aMethodReference classIsMeta
|
|
57 |
selector: aMethodReference methodSymbol
|
|
58 |
category: aMethodReference category
|
|
59 |
timeStamp: aMethodReference timeStamp
|
|
60 |
source: aMethodReference source.
|
|
61 |
self cachedDefinitions at: aMethodReference compiledMethod put: definition].
|
|
62 |
^ definition
|
|
63 |
|
|
64 |
!
|
|
65 |
|
|
66 |
initialize
|
|
67 |
Smalltalk addToShutDownList: self
|
|
68 |
!
|
|
69 |
|
|
70 |
shutDown
|
|
71 |
WeakArray removeWeakDependent: Definitions.
|
|
72 |
Definitions _ nil.
|
|
73 |
! !
|
|
74 |
|
|
75 |
!MCMethodDefinition methodsFor:'accessing'!
|
|
76 |
|
|
77 |
actualClass
|
|
78 |
^Smalltalk at: className
|
|
79 |
ifPresent: [:class | classIsMeta ifTrue: [class class] ifFalse: [class]]
|
|
80 |
!
|
|
81 |
|
|
82 |
category
|
|
83 |
^ category
|
|
84 |
!
|
|
85 |
|
|
86 |
classIsMeta
|
|
87 |
^ classIsMeta
|
|
88 |
!
|
|
89 |
|
|
90 |
className
|
|
91 |
^className
|
|
92 |
!
|
|
93 |
|
|
94 |
fullTimeStamp
|
|
95 |
^TimeStamp fromMethodTimeStamp: timeStamp
|
|
96 |
!
|
|
97 |
|
|
98 |
load
|
|
99 |
self actualClass
|
|
100 |
compile: source
|
|
101 |
classified: category
|
|
102 |
withStamp: timeStamp
|
|
103 |
notifying: (SyntaxError new category: category)
|
|
104 |
!
|
|
105 |
|
|
106 |
selector
|
|
107 |
^selector
|
|
108 |
!
|
|
109 |
|
|
110 |
source
|
|
111 |
^ source
|
|
112 |
!
|
|
113 |
|
|
114 |
timeStamp
|
|
115 |
^ timeStamp
|
|
116 |
! !
|
|
117 |
|
|
118 |
!MCMethodDefinition methodsFor:'annotations'!
|
|
119 |
|
|
120 |
printAnnotations: requests on: aStream
|
|
121 |
"Add a string for an annotation pane, trying to fulfill the annotation requests.
|
|
122 |
These might include anything that
|
|
123 |
Preferences defaultAnnotationRequests
|
|
124 |
might return. Which includes anything in
|
|
125 |
Preferences annotationInfo
|
|
126 |
To edit these, use:"
|
|
127 |
"Preferences editAnnotations"
|
|
128 |
|
|
129 |
requests do: [ :aRequest |
|
|
130 |
aRequest == #timeStamp ifTrue: [ aStream nextPutAll: self timeStamp ].
|
|
131 |
aRequest == #messageCategory ifTrue: [ aStream nextPutAll: self category ].
|
|
132 |
aRequest == #requirements ifTrue: [
|
|
133 |
self requirements do: [ :req |
|
|
134 |
aStream nextPutAll: req ] separatedBy: [ aStream space ]].
|
|
135 |
] separatedBy: [ aStream space ].
|
|
136 |
! !
|
|
137 |
|
|
138 |
!MCMethodDefinition methodsFor:'comparing'!
|
|
139 |
|
|
140 |
= aDefinition
|
|
141 |
^(super = aDefinition)
|
|
142 |
and: [aDefinition source = self source]
|
|
143 |
and: [aDefinition category = self category]
|
|
144 |
and: [aDefinition timeStamp = self timeStamp]
|
|
145 |
!
|
|
146 |
|
|
147 |
hash
|
|
148 |
| hash |
|
|
149 |
hash _ String stringHash: classIsMeta asString initialHash: 0.
|
|
150 |
hash _ String stringHash: source initialHash: hash.
|
|
151 |
hash _ String stringHash: category initialHash: hash.
|
|
152 |
hash _ String stringHash: className initialHash: hash.
|
|
153 |
^ hash
|
|
154 |
!
|
|
155 |
|
|
156 |
requirements
|
|
157 |
^ Array with: className
|
|
158 |
!
|
|
159 |
|
|
160 |
sortKey
|
|
161 |
^ self className, '.', (self classIsMeta ifTrue: ['meta'] ifFalse: ['nonmeta']), '.', self selector
|
|
162 |
! !
|
|
163 |
|
|
164 |
!MCMethodDefinition methodsFor:'installing'!
|
|
165 |
|
|
166 |
isExtensionMethod
|
|
167 |
^ category beginsWith: '*'
|
|
168 |
!
|
|
169 |
|
|
170 |
isOverrideMethod
|
|
171 |
"this oughta check the package"
|
|
172 |
^ self isExtensionMethod and: [category endsWith: '-override']
|
|
173 |
!
|
|
174 |
|
|
175 |
postload
|
|
176 |
self isInitializer ifTrue: [self actualClass theNonMetaClass initialize]
|
|
177 |
!
|
|
178 |
|
|
179 |
scanForPreviousVersion
|
|
180 |
| position prevPos prevFileIndex preamble tokens sourceFilesCopy stamp method file methodCategory |
|
|
181 |
method _ self actualClass compiledMethodAt: selector ifAbsent: [^ nil].
|
|
182 |
position _ method filePosition.
|
|
183 |
sourceFilesCopy _ SourceFiles collect:
|
|
184 |
[:x | x isNil ifTrue: [ nil ]
|
|
185 |
ifFalse: [x readOnlyCopy]].
|
|
186 |
[method fileIndex == 0 ifTrue: [^ nil].
|
|
187 |
file _ sourceFilesCopy at: method fileIndex.
|
|
188 |
[position notNil & file notNil]
|
|
189 |
whileTrue:
|
|
190 |
[file position: (0 max: position-150). "Skip back to before the preamble"
|
|
191 |
[file position < (position-1)] "then pick it up from the front"
|
|
192 |
whileTrue: [preamble _ file nextChunk].
|
|
193 |
|
|
194 |
"Preamble is likely a linked method preamble, if we're in
|
|
195 |
a changes file (not the sources file). Try to parse it
|
|
196 |
for prior source position and file index"
|
|
197 |
prevPos _ nil.
|
|
198 |
stamp _ ''.
|
|
199 |
(preamble findString: 'methodsFor:' startingAt: 1) > 0
|
|
200 |
ifTrue: [tokens _ Scanner new scanTokens: preamble]
|
|
201 |
ifFalse: [tokens _ Array new "ie cant be back ref"].
|
|
202 |
((tokens size between: 7 and: 8)
|
|
203 |
and: [(tokens at: tokens size-5) = #methodsFor:])
|
|
204 |
ifTrue:
|
|
205 |
[(tokens at: tokens size-3) = #stamp:
|
|
206 |
ifTrue: ["New format gives change stamp and unified prior pointer"
|
|
207 |
stamp _ tokens at: tokens size-2.
|
|
208 |
prevPos _ tokens last.
|
|
209 |
prevFileIndex _ sourceFilesCopy fileIndexFromSourcePointer: prevPos.
|
|
210 |
prevPos _ sourceFilesCopy filePositionFromSourcePointer: prevPos]
|
|
211 |
ifFalse: ["Old format gives no stamp; prior pointer in two parts"
|
|
212 |
prevPos _ tokens at: tokens size-2.
|
|
213 |
prevFileIndex _ tokens last].
|
|
214 |
(prevPos = 0 or: [prevFileIndex = 0]) ifTrue: [prevPos _ nil]].
|
|
215 |
((tokens size between: 5 and: 6)
|
|
216 |
and: [(tokens at: tokens size-3) = #methodsFor:])
|
|
217 |
ifTrue:
|
|
218 |
[(tokens at: tokens size-1) = #stamp:
|
|
219 |
ifTrue: ["New format gives change stamp and unified prior pointer"
|
|
220 |
stamp _ tokens at: tokens size]].
|
|
221 |
methodCategory _ tokens after: #methodsFor: ifAbsent: ['as yet unclassifed'].
|
|
222 |
methodCategory = category ifFalse:
|
|
223 |
[methodCategory = (Smalltalk
|
|
224 |
at: #Categorizer
|
|
225 |
ifAbsent: [Smalltalk at: #ClassOrganizer])
|
|
226 |
default ifTrue: [methodCategory _ methodCategory, ' '].
|
|
227 |
^ ChangeRecord new file: file position: position type: #method
|
|
228 |
class: className category: methodCategory meta: classIsMeta stamp: stamp].
|
|
229 |
position _ prevPos.
|
|
230 |
prevPos notNil ifTrue:
|
|
231 |
[file _ sourceFilesCopy at: prevFileIndex]].
|
|
232 |
^ nil]
|
|
233 |
ensure: [sourceFilesCopy do: [:x | x notNil ifTrue: [x close]]]
|
|
234 |
|
|
235 |
!
|
|
236 |
|
|
237 |
unload
|
|
238 |
| previousVersion |
|
|
239 |
self isOverrideMethod ifTrue: [previousVersion _ self scanForPreviousVersion].
|
|
240 |
previousVersion
|
|
241 |
ifNil: [self actualClass ifNotNilDo: [:class | class removeSelector: selector]]
|
|
242 |
ifNotNil: [previousVersion fileIn]
|
|
243 |
! !
|
|
244 |
|
|
245 |
!MCMethodDefinition methodsFor:'printing'!
|
|
246 |
|
|
247 |
description
|
|
248 |
^ Array
|
|
249 |
with: className
|
|
250 |
with: selector
|
|
251 |
with: classIsMeta
|
|
252 |
!
|
|
253 |
|
|
254 |
fullClassName
|
|
255 |
^ self classIsMeta
|
|
256 |
ifFalse: [self className]
|
|
257 |
ifTrue: [self className, ' class']
|
|
258 |
!
|
|
259 |
|
|
260 |
summary
|
|
261 |
^ self fullClassName , '>>' , selector
|
|
262 |
! !
|
|
263 |
|
|
264 |
!MCMethodDefinition methodsFor:'serializing'!
|
|
265 |
|
|
266 |
initializeWithClassName: classString
|
|
267 |
classIsMeta: metaBoolean
|
|
268 |
selector: selectorString
|
|
269 |
category: catString
|
|
270 |
timeStamp: timeString
|
|
271 |
source: sourceString
|
|
272 |
className _ classString asSymbol.
|
|
273 |
selector _ selectorString asSymbol.
|
|
274 |
category _ catString asSymbol.
|
|
275 |
timeStamp _ timeString.
|
|
276 |
classIsMeta _ metaBoolean.
|
|
277 |
source _ sourceString withSqueakLineEndings.
|
|
278 |
! !
|
|
279 |
|
|
280 |
!MCMethodDefinition methodsFor:'testing'!
|
|
281 |
|
|
282 |
isCodeDefinition
|
|
283 |
^ true
|
|
284 |
!
|
|
285 |
|
|
286 |
isInitializer
|
|
287 |
^ selector = #initialize and: [classIsMeta]
|
|
288 |
|
|
289 |
!
|
|
290 |
|
|
291 |
isMethodDefinition
|
|
292 |
^true
|
|
293 |
! !
|
|
294 |
|
|
295 |
!MCMethodDefinition methodsFor:'visiting'!
|
|
296 |
|
|
297 |
accept: aVisitor
|
|
298 |
^ aVisitor visitMethodDefinition: self
|
|
299 |
! !
|
|
300 |
|
|
301 |
!MCMethodDefinition class methodsFor:'documentation'!
|
|
302 |
|
|
303 |
version
|
|
304 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCMethodDefinition.st,v 1.1 2006-11-22 13:09:36 cg Exp $'
|
|
305 |
! !
|
|
306 |
|
|
307 |
MCMethodDefinition initialize!
|