--- a/VSEChunkFileSourceWriter.st Tue Jan 20 14:21:28 2015 +0100
+++ b/VSEChunkFileSourceWriter.st Wed Jan 21 10:48:42 2015 +0100
@@ -1,5 +1,5 @@
"
- COPYRIGHT (c) 2012 by eXept Software AG
+ COPYRIGHT (c) 2015 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
@@ -31,7 +31,7 @@
copyright
"
- COPYRIGHT (c) 2012 by eXept Software AG
+ COPYRIGHT (c) 2015 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
@@ -57,7 +57,7 @@
s := 'test.st' asFilename writeStream.
[
- VisualAgeChunkFileSourceWriter new
+ VSEChunkFileSourceWriter new
fileOut:OrderedCollection on:s
] ensure:[
s close
@@ -69,7 +69,7 @@
s := '' writeStream.
[
- VisualAgeChunkFileSourceWriter new
+ VSEChunkFileSourceWriter new
fileOut:OrderedCollection on:s
] ensure:[
s close
@@ -79,6 +79,12 @@
"
! !
+!VSEChunkFileSourceWriter class methodsFor:'class access'!
+
+vseSourceRewriter
+ ^ VSESourceRewriter
+! !
+
!VSEChunkFileSourceWriter methodsFor:'source writing'!
fileOutCategory:aCategory of:aClass except:skippedMethods only:savedMethods methodFilter:methodFilter on:aStream
@@ -235,7 +241,66 @@
!VSEChunkFileSourceWriter::VSESourceRewriter methodsFor:'translation'!
doRewrite
- self halt.
+ self rewriteEOLComments.
+ self rewriteGlobalsWithNamespace.
+ ^ source.
+!
+
+rewriteEOLComments
+ |tree parser eolComments|
+
+ parser := Parser new.
+ parser saveComments:true.
+ parser parseMethod:source in:methodClass ignoreErrors:true ignoreWarnings:true.
+
+ tree := parser tree.
+ eolComments := parser comments select:[:each | each isEndOfLineComment].
+ "/ start with the last (so I don't have to update the positions)
+ eolComments sort:[:a :b | a position < b position].
+ eolComments reverseDo:[:each |
+ source := (source copyTo:(each endPosition)),'"',(source copyFrom:(each endPosition + 1))
+ ].
+!
+
+rewriteGlobalsWithNamespace
+ |tree parser namesToRewrite|
+
+ namesToRewrite := OrderedCollection new.
+
+ parser := Parser new.
+ parser saveComments:true.
+ parser parseMethod:source in:methodClass ignoreErrors:true ignoreWarnings:true.
+ parser tree isNil ifTrue:[ ^ self ].
+
+ parser tree variableNodesDo:[:each |
+ |nameInSource|
+
+ each isGlobalVariable ifTrue:[
+ (each name includes:$:) ifTrue:[
+ nameInSource := source copyFrom:each startPosition to:each endPosition.
+ (nameInSource includes:$:) ifTrue:[
+ namesToRewrite add:each.
+ ].
+ ].
+ ].
+ ].
+
+ "/ start with the last (so I don't have to update the positions)
+ namesToRewrite sort:[:a :b | a position < b position].
+ namesToRewrite reverseDo:[:each |
+ |idx nameInSource ns nm|
+
+ nameInSource := source copyFrom:each startPosition to:each endPosition.
+ idx := nameInSource indexOf:$:.
+ ns := nameInSource copyTo:idx-1.
+ idx := nameInSource indexOf:$: startingAt:idx+1.
+ nm := nameInSource copyFrom:idx+1.
+ (ns = methodClass nameSpace name) ifFalse:[
+ Transcript show:'reference to other namespace'.
+ ] ifTrue:[
+ source := (source copyTo:(each startPosition-1)),nm,(source copyFrom:(each endPosition + 1))
+ ].
+ ].
!
rewriteMethod:methodArg
@@ -243,16 +308,16 @@
source := method source.
methodClass := method mclass.
- self doRewrite.
+ ^ self doRewrite.
! !
!VSEChunkFileSourceWriter class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic3/VSEChunkFileSourceWriter.st,v 1.1 2015-01-20 13:20:43 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic3/VSEChunkFileSourceWriter.st,v 1.2 2015-01-21 09:48:42 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic3/VSEChunkFileSourceWriter.st,v 1.1 2015-01-20 13:20:43 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic3/VSEChunkFileSourceWriter.st,v 1.2 2015-01-21 09:48:42 cg Exp $'
! !