3826
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
3714
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2015 by eXept Software AG
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
|
14 |
"{ Package: 'stx:libbasic3' }"
|
|
15 |
|
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
|
18 |
SmalltalkChunkFileSourceWriter subclass:#VSEFileSourceWriter
|
3884
|
19 |
instanceVariableNames:'classNameTranslations skipVersionMethods'
|
3714
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Kernel-Classes-Support'
|
|
23 |
!
|
|
24 |
|
|
25 |
Object subclass:#VSESourceRewriter
|
3734
|
26 |
instanceVariableNames:'source method methodClass classNamesToRewrite'
|
3714
|
27 |
classVariableNames:''
|
|
28 |
poolDictionaries:''
|
|
29 |
privateIn:VSEFileSourceWriter
|
|
30 |
!
|
|
31 |
|
|
32 |
!VSEFileSourceWriter class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 2015 by eXept Software AG
|
|
37 |
All Rights Reserved
|
|
38 |
|
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
documentation
|
|
49 |
"
|
|
50 |
fileout in a format which can be read by visualAge.
|
|
51 |
For transporting software.
|
|
52 |
"
|
|
53 |
!
|
|
54 |
|
|
55 |
examples
|
|
56 |
"
|
|
57 |
[exBegin]
|
|
58 |
|s|
|
|
59 |
|
|
60 |
s := 'test.st' asFilename writeStream.
|
|
61 |
[
|
|
62 |
VSEChunkFileSourceWriter new
|
|
63 |
fileOut:OrderedCollection on:s
|
|
64 |
] ensure:[
|
|
65 |
s close
|
|
66 |
]
|
|
67 |
[exEnd]
|
|
68 |
|
|
69 |
[exBegin]
|
|
70 |
|s|
|
|
71 |
|
|
72 |
s := '' writeStream.
|
|
73 |
[
|
|
74 |
VSEChunkFileSourceWriter new
|
|
75 |
fileOut:OrderedCollection on:s
|
|
76 |
] ensure:[
|
|
77 |
s close
|
|
78 |
].
|
|
79 |
s contents
|
|
80 |
[exEnd]
|
|
81 |
"
|
|
82 |
! !
|
|
83 |
|
3734
|
84 |
!VSEFileSourceWriter class methodsFor:'instance creation'!
|
|
85 |
|
|
86 |
new
|
|
87 |
"return an initialized instance"
|
|
88 |
|
|
89 |
^ self basicNew initialize.
|
|
90 |
! !
|
|
91 |
|
3727
|
92 |
!VSEFileSourceWriter class methodsFor:'api'!
|
|
93 |
|
|
94 |
fileOutPackage:currentProject on:aStream
|
|
95 |
self new fileOutPackage:currentProject on:aStream
|
|
96 |
! !
|
|
97 |
|
3714
|
98 |
!VSEFileSourceWriter class methodsFor:'class access'!
|
|
99 |
|
|
100 |
vseSourceRewriter
|
|
101 |
^ VSESourceRewriter
|
|
102 |
! !
|
|
103 |
|
3734
|
104 |
!VSEFileSourceWriter class methodsFor:'defaults'!
|
|
105 |
|
|
106 |
defaultClassNameTranslations
|
|
107 |
"for extensions"
|
|
108 |
|
|
109 |
^ Dictionary new
|
|
110 |
at:#SequenceableCollection put:#IndexedCollection;
|
|
111 |
at:#CharacterArray put:#String;
|
|
112 |
at:#Unicode16String put:#DoubleByteString;
|
3742
|
113 |
at:#UnicodeString put:#DoubleByteString;
|
3734
|
114 |
at:#Timestamp put:#TimeStamp;
|
3827
|
115 |
at:#ProtoObject put:#Object;
|
3734
|
116 |
yourself
|
|
117 |
|
|
118 |
"
|
|
119 |
self defaultClassNameTranslations
|
|
120 |
"
|
3787
|
121 |
!
|
|
122 |
|
|
123 |
extensionClassesSkipped
|
|
124 |
"for classes that do not exist in VSE"
|
|
125 |
|
|
126 |
^ Set new
|
3788
|
127 |
add:Filename;
|
3787
|
128 |
yourself
|
|
129 |
|
|
130 |
"
|
|
131 |
self extensionClassesSkipped
|
|
132 |
"
|
3734
|
133 |
! !
|
|
134 |
|
3884
|
135 |
!VSEFileSourceWriter methodsFor:'accessing'!
|
|
136 |
|
|
137 |
skipVersionMethods:aBoolean
|
|
138 |
skipVersionMethods := aBoolean.
|
|
139 |
! !
|
|
140 |
|
3734
|
141 |
!VSEFileSourceWriter methodsFor:'initialization'!
|
|
142 |
|
|
143 |
initialize
|
3884
|
144 |
classNameTranslations := self class defaultClassNameTranslations.
|
|
145 |
skipVersionMethods := true.
|
3734
|
146 |
! !
|
|
147 |
|
3727
|
148 |
!VSEFileSourceWriter methodsFor:'utilities'!
|
3714
|
149 |
|
|
150 |
ensureNoUnicodeInClass:aClass
|
|
151 |
"/ check if we need UTF8 encoding
|
|
152 |
aClass withAllPrivateClasses do:[:cls |
|
|
153 |
cls instAndClassMethods contains:[:m |
|
|
154 |
self ensureNoUnicodeInMethod:m
|
|
155 |
]
|
|
156 |
].
|
|
157 |
!
|
|
158 |
|
|
159 |
ensureNoUnicodeInMethod:aMethod
|
|
160 |
|src|
|
|
161 |
|
|
162 |
src := aMethod source.
|
|
163 |
src isNil ifTrue:[
|
|
164 |
self error:'missing source in ',aMethod whoString
|
|
165 |
].
|
3827
|
166 |
src asSingleByteStringIfPossible isWideString ifTrue:[
|
3714
|
167 |
self error:(aMethod whoString , ' contains unicode strings or character contants. Cannot be exported to VSE')
|
|
168 |
].
|
|
169 |
!
|
|
170 |
|
|
171 |
extensionMethodsFor:packageID
|
|
172 |
|methodsToFileOut|
|
|
173 |
|
|
174 |
methodsToFileOut := OrderedCollection new.
|
|
175 |
Smalltalk allClassesDo:[:eachClass |
|
3788
|
176 |
eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
|
|
177 |
|mPckg|
|
3714
|
178 |
|
3788
|
179 |
mPckg := mthd package.
|
|
180 |
(mPckg = packageID and:[mPckg ~= eachClass package]) ifTrue:[
|
|
181 |
(self class extensionClassesSkipped includes:eachClass) ifTrue:[
|
|
182 |
Transcript showCR:'skipped extension: ',mthd whoString.
|
|
183 |
] ifFalse:[
|
3787
|
184 |
methodsToFileOut add:mthd.
|
|
185 |
]
|
3714
|
186 |
]
|
|
187 |
]
|
|
188 |
].
|
|
189 |
^ methodsToFileOut
|
3730
|
190 |
!
|
|
191 |
|
|
192 |
rewrittenClassNameOf:aClass
|
3734
|
193 |
|stxName vseName idx|
|
3730
|
194 |
|
3734
|
195 |
stxName := aClass name.
|
|
196 |
vseName := classNameTranslations at:stxName ifAbsent:[stxName].
|
|
197 |
|
|
198 |
(vseName includesString:'::') ifTrue:[
|
|
199 |
idx := vseName indexOfSubCollection:'::'.
|
|
200 |
^ (vseName copyTo:idx-1) , VSESourceRewriter nameSpaceSeparatorReplacement , (vseName copyFrom:idx+2)
|
3730
|
201 |
].
|
3734
|
202 |
^ vseName
|
3714
|
203 |
! !
|
|
204 |
|
3727
|
205 |
!VSEFileSourceWriter::VSESourceRewriter class methodsFor:'defaults'!
|
|
206 |
|
|
207 |
nameSpaceSeparatorReplacement
|
|
208 |
^ '__'
|
|
209 |
! !
|
|
210 |
|
3714
|
211 |
!VSEFileSourceWriter::VSESourceRewriter class methodsFor:'translation'!
|
|
212 |
|
|
213 |
rewriteMethod:method
|
|
214 |
^ self new rewriteMethod:method
|
|
215 |
! !
|
|
216 |
|
|
217 |
!VSEFileSourceWriter::VSESourceRewriter methodsFor:'accessing'!
|
|
218 |
|
3734
|
219 |
classNamesToRewrite:something
|
|
220 |
classNamesToRewrite := something.
|
|
221 |
!
|
|
222 |
|
3714
|
223 |
method
|
|
224 |
^ method
|
|
225 |
!
|
|
226 |
|
|
227 |
method:something
|
|
228 |
method := something.
|
|
229 |
!
|
|
230 |
|
|
231 |
methodClass
|
|
232 |
^ methodClass
|
|
233 |
!
|
|
234 |
|
|
235 |
methodClass:something
|
|
236 |
methodClass := something.
|
|
237 |
!
|
|
238 |
|
|
239 |
source
|
|
240 |
^ source
|
|
241 |
!
|
|
242 |
|
|
243 |
source:something
|
|
244 |
source := something.
|
|
245 |
! !
|
|
246 |
|
|
247 |
!VSEFileSourceWriter::VSESourceRewriter methodsFor:'translation'!
|
|
248 |
|
3752
|
249 |
checkForOldStyleAssignments
|
|
250 |
"check for underscore as assignment token; VSE does not handle those"
|
|
251 |
|
|
252 |
|parser|
|
|
253 |
|
|
254 |
"/ all references to namespace variables
|
|
255 |
parser := Parser new.
|
3782
|
256 |
parser foldConstants:false.
|
3752
|
257 |
parser parserFlags
|
|
258 |
allowOldStyleAssignment:true;
|
|
259 |
warnOldStyleAssignment:true.
|
|
260 |
|
|
261 |
parser
|
|
262 |
parseMethod:source
|
|
263 |
in:methodClass
|
|
264 |
ignoreErrors:false
|
|
265 |
ignoreWarnings:false.
|
|
266 |
|
|
267 |
parser didWarnAboutOldStyleAssignment ifTrue:[
|
|
268 |
self error:'OldStyle assignment. Please rewrite "_" assignments to ":=" in ',method whoString
|
|
269 |
].
|
|
270 |
parser didWarnAboutSqueakExtensions ifTrue:[
|
|
271 |
self error:'Squeak sytax. Please rewrite "{..}" to "Array with:" in ',method whoString
|
|
272 |
].
|
|
273 |
!
|
|
274 |
|
3731
|
275 |
checkForUnimplementedMessages
|
|
276 |
"a naive search for messages which are known to be not implemented,
|
|
277 |
and which should be replaced by other messages"
|
|
278 |
|
|
279 |
|parser|
|
|
280 |
|
|
281 |
"/ all references to namespace variables
|
3782
|
282 |
parser := Parser new.
|
|
283 |
parser foldConstants:false.
|
|
284 |
parser
|
|
285 |
parseMethod:source
|
|
286 |
in:methodClass
|
|
287 |
ignoreErrors:false
|
|
288 |
ignoreWarnings:true.
|
3731
|
289 |
|
|
290 |
(parser messagesSent includesAny: #(
|
|
291 |
'answer:do:'
|
|
292 |
'ignoreIn:'
|
|
293 |
'codePoint'
|
3828
|
294 |
'conform:'
|
3829
|
295 |
'contains:'
|
3826
|
296 |
"/ '->'
|
3731
|
297 |
)) ifTrue:[
|
3826
|
298 |
self error:('please rewrite ',method whoString,' (unimplemented messages). Or proceed') mayProceed:true
|
3731
|
299 |
].
|
|
300 |
!
|
|
301 |
|
3714
|
302 |
doRewrite
|
3752
|
303 |
self checkForOldStyleAssignments.
|
3731
|
304 |
self checkForUnimplementedMessages.
|
|
305 |
|
3714
|
306 |
self rewriteEOLComments.
|
3738
|
307 |
self rewriteAnnotationsToComments.
|
3727
|
308 |
"/ self rewriteGlobalsWithNamespace.
|
3724
|
309 |
self rewriteClassReferences.
|
3725
|
310 |
self rewriteExceptionHandlers.
|
3794
|
311 |
self rewriteOtherMessages.
|
3886
|
312 |
self rewriteThisContext.
|
3714
|
313 |
^ source.
|
|
314 |
!
|
|
315 |
|
3738
|
316 |
rewriteAnnotationsToComments
|
3740
|
317 |
|parser annots|
|
3738
|
318 |
|
|
319 |
parser := Parser new.
|
3782
|
320 |
parser foldConstants:false.
|
3738
|
321 |
parser saveComments:true.
|
|
322 |
parser parseMethod:source in:methodClass ignoreErrors:true ignoreWarnings:true.
|
|
323 |
|
3739
|
324 |
(annots := parser annotationInfo) isEmptyOrNil ifTrue:[^ self].
|
3766
|
325 |
|
|
326 |
Transcript showCR:('- comment out %1 annotations {%1}' bindWith:annots size with:method whoString).
|
|
327 |
|
3739
|
328 |
annots := annots copy sort:[:a :b | a endPosition < b endPosition].
|
3740
|
329 |
"/ methodClass == SOAP::XeComponent class ifTrue:[self halt].
|
3739
|
330 |
"/ last one first, so we don't have to care for changed positions due to insertions
|
|
331 |
annots reverseDo:[:annot |
|
|
332 |
source := (source copyTo:annot startPosition-1)
|
|
333 |
, '"' , (source copyFrom:annot startPosition to:annot endPosition)
|
|
334 |
, '"' , (source copyFrom:annot endPosition+1).
|
|
335 |
].
|
3738
|
336 |
!
|
|
337 |
|
3724
|
338 |
rewriteClassReferences
|
3727
|
339 |
|parser globalsToRename symbolsToRename replacer newSource tree|
|
3724
|
340 |
|
|
341 |
"/ all references to namespace variables
|
3782
|
342 |
parser := Parser new.
|
|
343 |
parser foldConstants:false.
|
|
344 |
parser
|
|
345 |
parseMethod:source
|
|
346 |
in:methodClass
|
|
347 |
ignoreErrors:false
|
|
348 |
ignoreWarnings:false.
|
3724
|
349 |
|
|
350 |
globalsToRename := Dictionary new.
|
|
351 |
symbolsToRename := Dictionary new.
|
|
352 |
|
|
353 |
parser usedGlobals do:[:eachGlobal |
|
|
354 |
|idx nsName clsName|
|
|
355 |
|
|
356 |
(eachGlobal includes:$:) ifTrue:[
|
|
357 |
idx := eachGlobal indexOfSubCollection:'::'.
|
|
358 |
nsName := eachGlobal copyTo:idx-1.
|
|
359 |
clsName := eachGlobal copyFrom:idx+2.
|
3727
|
360 |
globalsToRename at:eachGlobal put:(nsName,(self class nameSpaceSeparatorReplacement),clsName).
|
3724
|
361 |
|
|
362 |
nsName = methodClass nameSpace name ifTrue:[
|
3727
|
363 |
globalsToRename at:clsName put:(nsName,(self class nameSpaceSeparatorReplacement),clsName).
|
3724
|
364 |
]
|
3734
|
365 |
] ifFalse:[
|
3751
|
366 |
(classNamesToRewrite includesKey:eachGlobal) ifTrue:[
|
|
367 |
globalsToRename at:eachGlobal put:(classNamesToRewrite at:eachGlobal).
|
|
368 |
].
|
3724
|
369 |
].
|
|
370 |
].
|
|
371 |
parser usedSymbols do:[:eachSymbol |
|
|
372 |
|idx nsName clsName|
|
|
373 |
|
|
374 |
(eachSymbol includesString:'::') ifTrue:[
|
|
375 |
idx := eachSymbol indexOfSubCollection:'::'.
|
|
376 |
nsName := eachSymbol copyTo:idx-1.
|
|
377 |
clsName := eachSymbol copyFrom:idx+2.
|
|
378 |
(nsName notEmpty
|
|
379 |
and:[ clsName notEmpty
|
|
380 |
and:[ nsName knownAsSymbol
|
|
381 |
and:[ (Smalltalk classNamed:nsName) isNameSpace ]]])
|
|
382 |
ifTrue:[
|
3727
|
383 |
symbolsToRename at:eachSymbol put:(nsName,(self class nameSpaceSeparatorReplacement),clsName) asSymbol.
|
3724
|
384 |
].
|
|
385 |
] ifFalse:[
|
|
386 |
(methodClass nameSpace includesKey:eachSymbol asSymbol) ifTrue:[
|
3727
|
387 |
symbolsToRename at:eachSymbol put:(methodClass nameSpace name,(self class nameSpaceSeparatorReplacement),eachSymbol) asSymbol.
|
3751
|
388 |
] ifFalse:[
|
|
389 |
(classNamesToRewrite includesKey:eachSymbol) ifTrue:[
|
|
390 |
self breakPoint:#cg.
|
|
391 |
globalsToRename at:eachSymbol put:(classNamesToRewrite at:eachSymbol).
|
|
392 |
].
|
|
393 |
].
|
3724
|
394 |
]
|
|
395 |
].
|
|
396 |
(globalsToRename isEmpty and:[symbolsToRename isEmpty]) ifTrue:[^ self ].
|
|
397 |
|
3766
|
398 |
Transcript showCR:('- rewrite refs to %1 globals and %2 literal symbols {%3}'
|
|
399 |
bindWith:globalsToRename size
|
|
400 |
with:symbolsToRename size
|
|
401 |
with:method whoString).
|
|
402 |
|
3724
|
403 |
replacer := ParseTreeSourceRewriter new.
|
|
404 |
replacer alwaysPerformAllSearches:true.
|
|
405 |
|
|
406 |
globalsToRename keysAndValuesDo:[:oldName :newName |
|
|
407 |
replacer replaceVariable: oldName with: newName.
|
|
408 |
].
|
|
409 |
symbolsToRename keysAndValuesDo:[:oldName :newName |
|
|
410 |
replacer replaceLiteral: oldName with: newName.
|
|
411 |
].
|
3727
|
412 |
tree := RBParser
|
|
413 |
parseMethod:source
|
|
414 |
onError:[:aString :pos | self halt. ^self].
|
|
415 |
|
|
416 |
replacer executeTree: tree.
|
3724
|
417 |
newSource := replacer executeReplacementsInSource:source.
|
|
418 |
"/ self halt.
|
3727
|
419 |
|
|
420 |
"/ to verify, check parsability
|
|
421 |
RBParser
|
|
422 |
parseMethod:newSource
|
|
423 |
onError:[:aString :pos | self halt.].
|
|
424 |
|
3724
|
425 |
source := newSource.
|
|
426 |
!
|
|
427 |
|
3714
|
428 |
rewriteEOLComments
|
3911
|
429 |
|tree parser eolComments xlatedComment newSource|
|
3714
|
430 |
|
|
431 |
parser := Parser new.
|
3782
|
432 |
parser foldConstants:false.
|
3714
|
433 |
parser saveComments:true.
|
|
434 |
parser parseMethod:source in:methodClass ignoreErrors:true ignoreWarnings:true.
|
|
435 |
|
|
436 |
tree := parser tree.
|
|
437 |
eolComments := parser comments select:[:each | each isEndOfLineComment].
|
3766
|
438 |
eolComments notEmpty ifTrue:[
|
|
439 |
Transcript showCR:('- rewrite %1 EOL comments {%2}' bindWith:eolComments size with:method whoString).
|
3740
|
440 |
|
3766
|
441 |
"/ start with the last (so I don't have to update the positions)
|
|
442 |
eolComments sort:[:a :b | a startPosition < b startPosition].
|
3740
|
443 |
|
3766
|
444 |
eolComments reverseDo:[:each |
|
|
445 |
(source at:each endPosition) = $" ifTrue:[
|
|
446 |
"/ nothing to do...
|
|
447 |
] ifFalse:[
|
3911
|
448 |
xlatedComment := source copyFrom:(each startPosition+2) to:each endPosition.
|
|
449 |
(xlatedComment includes:$") ifTrue:[
|
|
450 |
"/ self halt.
|
|
451 |
xlatedComment := xlatedComment copyReplaceAll:$" with:$'.
|
|
452 |
].
|
|
453 |
newSource := source copyTo:(each startPosition-1).
|
|
454 |
newSource := newSource,'"',xlatedComment,'"'.
|
|
455 |
newSource := newSource,(source copyFrom:(each endPosition + 1)).
|
|
456 |
source := newSource.
|
3766
|
457 |
].
|
3741
|
458 |
].
|
3766
|
459 |
|
|
460 |
"/ to verify, check parsability
|
|
461 |
RBParser
|
|
462 |
parseMethod:source
|
|
463 |
onError:[:aString :pos | self halt.].
|
3714
|
464 |
].
|
|
465 |
!
|
|
466 |
|
3725
|
467 |
rewriteExceptionHandlers
|
3727
|
468 |
|parser replacer newSource tree|
|
3725
|
469 |
|
3782
|
470 |
parser := Parser new.
|
|
471 |
parser foldConstants:false.
|
|
472 |
parser
|
|
473 |
parseMethod:source
|
|
474 |
in:methodClass
|
|
475 |
ignoreErrors:false
|
|
476 |
ignoreWarnings:false.
|
3725
|
477 |
|
|
478 |
(parser messagesSent includesAny: #( 'answer:do:' 'ignoreIn:' )) ifTrue:[
|
|
479 |
self halt
|
|
480 |
].
|
|
481 |
|
|
482 |
replacer := ParseTreeSourceRewriter new.
|
|
483 |
replacer alwaysPerformAllSearches:true.
|
|
484 |
|
|
485 |
replacer
|
3789
|
486 |
replace:'``@expr subclassesDo: ``@block '
|
3725
|
487 |
"->"
|
3789
|
488 |
with: ' ``@expr subclasses do: ``@block ';
|
3725
|
489 |
|
3789
|
490 |
replace: ' [| `@temps | ``@.Statements. ] valueNowOrOnUnwindDo: ``@block'
|
3725
|
491 |
"->"
|
3789
|
492 |
with: ' [| `@temps | ``@.Statements. ] ensure: ``@block';
|
3725
|
493 |
|
3789
|
494 |
replace: ' [| `@temps | ``@.Statements. ] valueOnUnwindDo: ``@block'
|
3725
|
495 |
"->"
|
3789
|
496 |
with: ' [| `@temps | ``@.Statements. ] ifCurtailed: ``@block';
|
|
497 |
|
|
498 |
replace:' ``@err handle: ``@handler do: ``@expr'
|
|
499 |
"->"
|
|
500 |
with: ' ``@expr on: ``@err do: ``@handler'.
|
3725
|
501 |
|
3727
|
502 |
tree := RBParser
|
|
503 |
parseMethod:source
|
|
504 |
onError:[:aString :pos | self halt. ^ self].
|
|
505 |
|
3782
|
506 |
"/((method selector == #'stackTraceFrom:')
|
|
507 |
"/and:[ methodClass == SOAP::SoPortableUtil class ]) ifTrue:[self halt].
|
|
508 |
|
3727
|
509 |
(replacer executeTree: tree) ifTrue:[
|
3782
|
510 |
newSource := replacer executeReplacementsInSource:source copy.
|
3766
|
511 |
(newSource ~= source) ifTrue:[
|
|
512 |
Transcript showCR:('- rewrote exception handler(s) (%1)' bindWith:method whoString).
|
|
513 |
"/ self halt.
|
3782
|
514 |
|
|
515 |
"/ to verify, check parsability
|
|
516 |
RBParser
|
|
517 |
parseMethod:newSource
|
|
518 |
onError:[:aString :pos | self halt.].
|
|
519 |
|
3766
|
520 |
source := newSource.
|
|
521 |
].
|
3725
|
522 |
].
|
|
523 |
!
|
|
524 |
|
3714
|
525 |
rewriteGlobalsWithNamespace
|
3727
|
526 |
"obsolete old version - now done in rewriteClassReferences"
|
|
527 |
|
|
528 |
|parser namesToRewrite|
|
3714
|
529 |
|
|
530 |
namesToRewrite := OrderedCollection new.
|
|
531 |
|
|
532 |
parser := Parser new.
|
3782
|
533 |
parser foldConstants:false.
|
3714
|
534 |
parser saveComments:true.
|
|
535 |
parser parseMethod:source in:methodClass ignoreErrors:true ignoreWarnings:true.
|
|
536 |
parser tree isNil ifTrue:[ ^ self ].
|
|
537 |
|
|
538 |
parser tree variableNodesDo:[:each |
|
|
539 |
|nameInSource|
|
|
540 |
|
|
541 |
each isGlobalVariable ifTrue:[
|
|
542 |
(each name includes:$:) ifTrue:[
|
|
543 |
nameInSource := source copyFrom:each startPosition to:each endPosition.
|
|
544 |
(nameInSource includes:$:) ifTrue:[
|
|
545 |
namesToRewrite add:each.
|
|
546 |
].
|
|
547 |
].
|
|
548 |
].
|
|
549 |
].
|
|
550 |
|
3766
|
551 |
namesToRewrite notEmpty ifTrue:[
|
|
552 |
Transcript showCR:('- rewrite %1 refs to globals in namespaces {%2}' bindWith:namesToRewrite size with:method whoString).
|
|
553 |
].
|
|
554 |
|
3714
|
555 |
"/ start with the last (so I don't have to update the positions)
|
|
556 |
namesToRewrite sort:[:a :b | a position < b position].
|
|
557 |
namesToRewrite reverseDo:[:each |
|
|
558 |
|idx nameInSource ns nm|
|
|
559 |
|
|
560 |
nameInSource := source copyFrom:each startPosition to:each endPosition.
|
|
561 |
idx := nameInSource indexOf:$:.
|
|
562 |
ns := nameInSource copyTo:idx-1.
|
|
563 |
idx := nameInSource indexOf:$: startingAt:idx+1.
|
|
564 |
nm := nameInSource copyFrom:idx+1.
|
|
565 |
(ns = methodClass nameSpace name) ifFalse:[
|
|
566 |
Transcript show:'reference to other namespace'.
|
|
567 |
] ifTrue:[
|
|
568 |
source := (source copyTo:(each startPosition-1)),nm,(source copyFrom:(each endPosition + 1))
|
|
569 |
].
|
|
570 |
].
|
3727
|
571 |
|
|
572 |
"/ to verify, check parsability
|
|
573 |
RBParser
|
|
574 |
parseMethod:source
|
|
575 |
onError:[:aString :pos | self halt.].
|
3714
|
576 |
!
|
|
577 |
|
|
578 |
rewriteMethod:methodArg
|
|
579 |
method := methodArg.
|
|
580 |
source := method source.
|
|
581 |
methodClass := method mclass.
|
|
582 |
^ self doRewrite.
|
3794
|
583 |
!
|
|
584 |
|
|
585 |
rewriteOtherMessages
|
3798
|
586 |
|parser replacer replaces newSource tree origSource|
|
3794
|
587 |
|
|
588 |
parser := Parser new.
|
|
589 |
parser foldConstants:false.
|
|
590 |
parser
|
|
591 |
parseMethod:source
|
|
592 |
in:methodClass
|
|
593 |
ignoreErrors:false
|
|
594 |
ignoreWarnings:false.
|
|
595 |
|
3798
|
596 |
(parser messagesSent includesAny: #( 'showCR:' 'lf' 'return' )) ifTrue:[
|
3794
|
597 |
self halt
|
|
598 |
].
|
|
599 |
|
3798
|
600 |
replaces := {
|
|
601 |
'(Transcript showCR: ``@string)' -> '(Transcript show: ``@string; cr) ' .
|
|
602 |
'(Character return codePoint)' -> '(13)' .
|
|
603 |
'(Character lf codePoint)' -> '(10)' .
|
|
604 |
'(Character return)' -> '(Character value:13)' .
|
|
605 |
'(Character lf)' -> '(Character value:10)' .
|
|
606 |
}.
|
|
607 |
"/ must do each separately, otherwise rewriter gets confused
|
|
608 |
origSource := source.
|
|
609 |
replaces do:[:each |
|
|
610 |
replacer := ParseTreeSourceRewriter new.
|
|
611 |
replacer alwaysPerformAllSearches:true.
|
3794
|
612 |
|
3798
|
613 |
replacer replace:each key with:each value.
|
3794
|
614 |
|
3798
|
615 |
tree := RBParser
|
|
616 |
parseMethod:source
|
|
617 |
onError:[:aString :pos | self halt. ^ self].
|
3794
|
618 |
|
3798
|
619 |
(replacer executeTree: tree) ifTrue:[
|
|
620 |
newSource := replacer executeReplacementsInSource:source copy.
|
|
621 |
(newSource ~= source) ifTrue:[
|
|
622 |
Transcript showCR:('- rewrote showCR(s) (%1)' bindWith:method whoString).
|
|
623 |
"/ self halt.
|
3794
|
624 |
|
3798
|
625 |
"/ to verify, check parsability
|
|
626 |
RBParser
|
|
627 |
parseMethod:newSource
|
|
628 |
onError:[:aString :pos | self halt.].
|
3794
|
629 |
|
3798
|
630 |
source := newSource.
|
|
631 |
].
|
3794
|
632 |
].
|
|
633 |
].
|
3886
|
634 |
!
|
|
635 |
|
|
636 |
rewriteThisContext
|
|
637 |
|
|
638 |
|parser replacer newSource tree|
|
|
639 |
|
|
640 |
(source includesString:'thisContext') ifFalse:[
|
|
641 |
^ self
|
|
642 |
].
|
|
643 |
|
3911
|
644 |
"/ self halt.
|
3886
|
645 |
|
|
646 |
parser := Parser new.
|
|
647 |
parser foldConstants:false.
|
|
648 |
parser
|
|
649 |
parseMethod:source
|
|
650 |
in:methodClass
|
|
651 |
ignoreErrors:false
|
|
652 |
ignoreWarnings:false.
|
|
653 |
|
|
654 |
replacer := ParseTreeSourceRewriter new.
|
|
655 |
replacer alwaysPerformAllSearches:true.
|
|
656 |
|
|
657 |
replacer
|
|
658 |
replace:'thisContext'
|
|
659 |
"->"
|
|
660 |
with: 'nil "thisContext replaced by nil"'
|
|
661 |
keepComments:true.
|
|
662 |
|
|
663 |
tree := RBParser
|
|
664 |
parseMethod:source
|
|
665 |
onError:[:aString :pos | self halt:'parse error - please check'. ^ self].
|
|
666 |
|
|
667 |
"/((method selector == #'stackTraceFrom:')
|
|
668 |
"/and:[ methodClass == SOAP::SoPortableUtil class ]) ifTrue:[self halt].
|
|
669 |
|
|
670 |
(replacer executeTree: tree) ifTrue:[
|
|
671 |
newSource := replacer executeReplacementsInSource:source copy.
|
|
672 |
(newSource ~= source) ifTrue:[
|
|
673 |
Transcript showCR:('- rewrote thisContext (%1)' bindWith:method whoString).
|
|
674 |
"/ self halt.
|
|
675 |
|
|
676 |
"/ to verify, check parsability
|
|
677 |
RBParser
|
|
678 |
parseMethod:newSource
|
|
679 |
onError:[:aString :pos | self halt:'rewrite error - please check'].
|
|
680 |
|
|
681 |
source := newSource.
|
|
682 |
].
|
|
683 |
].
|
3714
|
684 |
! !
|
|
685 |
|
|
686 |
!VSEFileSourceWriter class methodsFor:'documentation'!
|
|
687 |
|
|
688 |
version
|
3884
|
689 |
^ '$Header$'
|
3714
|
690 |
!
|
|
691 |
|
|
692 |
version_CVS
|
3884
|
693 |
^ '$Header$'
|
3714
|
694 |
! !
|
|
695 |
|