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