[PATCH] stinst: Allow gst-convert to work for OldSyntax/Squeak syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] stinst: Allow gst-convert to work for OldSyntax/Squeak syntax

Holger Freyther
From: Holger Hans Peter Freyther <[hidden email]>

The gst-convert command

$ gst-convert -r'Osmo.LogManager -> LogManager' -F squeak -f gst

was rewriting the nodes but the exported file contained the original
unmodified sourcecode. The FormattingExporter for the gst syntax is
using the >>#methodFormattedSourceString to format, use it inside the
OldSyntaxExporter as well. Another option would be to subclass the
SqueakSyntaxExporter and OldSyntaxExporter and add the formatting there.

2013-02-10  Holger Hans Peter Freyther  <[hidden email]>

        * OldSyntaxExporter.st: Reformat the method node in
        OldSyntaxExporter>>#oldSyntaxSourceCodeFor:.
        * RewriteTests.st: Add the TestRewrite class.
        * package.xml: Add the TestRewrite test to the testsuite.
---
 packages/stinst/parser/ChangeLog            |    7 +++
 packages/stinst/parser/OldSyntaxExporter.st |    3 +-
 packages/stinst/parser/RewriteTests.st      |   74 +++++++++++++++++++++++++++
 packages/stinst/parser/package.xml          |    1 +
 4 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/packages/stinst/parser/ChangeLog b/packages/stinst/parser/ChangeLog
index 71f4139..df4407e 100644
--- a/packages/stinst/parser/ChangeLog
+++ b/packages/stinst/parser/ChangeLog
@@ -1,3 +1,10 @@
+2013-02-10  Holger Hans Peter Freyther  <[hidden email]>
+
+ * OldSyntaxExporter.st: Reformat the method node in
+ OldSyntaxExporter>>#oldSyntaxSourceCodeFor:.
+ * RewriteTests.st: Add the TestRewrite class.
+ * package.xml: Add the TestRewrite test to the testsuite.
+
 2013-01-29  Holger Hans Peter Freyther  <[hidden email]>
 
  * STLoaderObjs.st: Put class variables into the classVars array.
diff --git a/packages/stinst/parser/OldSyntaxExporter.st b/packages/stinst/parser/OldSyntaxExporter.st
index b02221e..d23cd22 100644
--- a/packages/stinst/parser/OldSyntaxExporter.st
+++ b/packages/stinst/parser/OldSyntaxExporter.st
@@ -171,8 +171,7 @@ FileOutExporter subclass: OldSyntaxExporter [
 
     oldSyntaxSourceCodeFor: aMethod [
  | source cat |
- aMethod isOldSyntax ifTrue: [ ^aMethod methodSourceString ].
- source := aMethod methodSourceString.
+ source := aMethod methodFormattedSourceString.
  source := source copyReplacingRegex: '\s*\[\s*(.*[\S\n])' with: '
  %1'.
  source := source copyReplacingRegex: '\s*]\s*$' with: '
diff --git a/packages/stinst/parser/RewriteTests.st b/packages/stinst/parser/RewriteTests.st
index 018035b..8b09598 100644
--- a/packages/stinst/parser/RewriteTests.st
+++ b/packages/stinst/parser/RewriteTests.st
@@ -249,5 +249,79 @@ behavior stayed the same, at least as much as I care it to stay so.'>
     ]
 ]
 
+TestCase subclass: TestRewrite [
+    <comment: 'I test that rewriting a method for the OldSyntaxExport and
+    SqueakExporter will pick up the new code.'>
+
+    testNamespaceRewrite [
+        | class tree rule rewriter res out|
+
+        tree := RBParser parseRewriteExpression: 'Osmo.LogManager -> LogManager'.
+        rule := RBStringReplaceRule
+                    searchForTree: tree receiver
+                    replaceWith: tree arguments first.
+        rewriter := ParseTreeRewriter new
+                        addRule: rule; yourself.
+
+        class := (STClassLoader new
+                    parseSmalltalkStream: 'Object subclass: TestData [
+                        logManager [
+                            ^Osmo.LogManager default
+                        ]
+                    ]' readStream with: GSTFileInParser) first.
+
+        "Rewrite the method. This will modify the code on inside the class"
+        res := rewriter executeTree: (class >> #logManager) node; tree.
+        self assert: (class >> #logManager) node == res.
+
+        "Now generate the code"
+        out := WriteStream on: (String new).
+        (SqueakSyntaxExporter on: class to: out)
+            completeFileOut: false;
+            fileOutSelectors: (Array with: #logManager) classSelectors: #().
+        self assert: (out contents indexOfSubCollection: 'Osmo.LogManager') = 0.
+    ]
+
+    testOldSyntaxNamespaceRewrite [
+        | class tree rule rewriter res out|
+
+        tree := RBParser parseRewriteExpression: 'Osmo.LogManager -> LogManager'.
+        rule := RBStringReplaceRule
+                    searchForTree: tree receiver
+                    replaceWith: tree arguments first.
+        rewriter := ParseTreeRewriter new
+                        addRule: rule; yourself.
+
+        "Load the old code"
+        class := (STClassLoader new
+                    parseSmalltalkStream:
+'SystemOrganization addCategory: #''osmo-logging-core''!
+Object subclass: #LogManager
+    instanceVariableNames: ''target filter areas''
+    classVariableNames: ''Log''
+    poolDictionaries: ''''
+    category: ''osmo-logging-core''!
+
+!LogManager methodsFor: ''as yet unclassified''!
+
+logManager
+    ^Osmo.LogManager default
+! !' readStream with: SqueakFileInParser) first.
+
+
+        "Rewrite the method. This will modify the code on inside the class"
+        res := rewriter executeTree: (class >> #logManager) node; tree.
+        self assert: (class >> #logManager) node == res.
+        self assert: (class >> #logManager) isOldSyntax.
+
+        "Now generate the code"
+        out := WriteStream on: (String new).
+        (SqueakSyntaxExporter on: class to: out)
+            completeFileOut: false;
+            fileOutSelectors: (Array with: #logManager) classSelectors: #().
+        self assert: (out contents indexOfSubCollection: 'Osmo.LogManager') = 0.
+    ]
+]
+
 ]
 
diff --git a/packages/stinst/parser/package.xml b/packages/stinst/parser/package.xml
index 1c9f2c7..ad33622 100644
--- a/packages/stinst/parser/package.xml
+++ b/packages/stinst/parser/package.xml
@@ -28,6 +28,7 @@
   <test>
    <namespace>STInST.Tests</namespace>
    <sunit>STInST.Tests.TestStandardRewrites</sunit>
+   <sunit>STInST.Tests.TestRewrite</sunit>
    <sunit>STInST.Tests.TestDefaultPoolResolution</sunit>
    <sunit>STInST.Tests.TestClassicPoolResolution</sunit>
    <filein>RewriteTests.st</filein>
--
1.7.10.4


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] stinst: Allow gst-convert to work for OldSyntax/Squeak syntax

Holger Freyther
On Sun, Feb 10, 2013 at 12:00:51PM +0100, Holger Hans Peter Freyther wrote:

Hi,


> OldSyntaxExporter as well. Another option would be to subclass the
> SqueakSyntaxExporter and OldSyntaxExporter and add the formatting there.

my patch changes the semantic of these exporters. Before it would only
convert from new style method definitions to the old one. Right now it
will completely rewrite the code. I am not sure if this is acceptable or
not.

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] stinst: Allow gst-convert to work for OldSyntax/Squeak syntax

Paolo Bonzini-2
Il 10/02/2013 13:18, Holger Hans Peter Freyther ha scritto:

> On Sun, Feb 10, 2013 at 12:00:51PM +0100, Holger Hans Peter Freyther wrote:
>
> Hi,
>
>
>> OldSyntaxExporter as well. Another option would be to subclass the
>> SqueakSyntaxExporter and OldSyntaxExporter and add the formatting there.
>
> my patch changes the semantic of these exporters. Before it would only
> convert from new style method definitions to the old one. Right now it
> will completely rewrite the code. I am not sure if this is acceptable or
> not.

Yes, this was a bug.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk