]> thyrsus.com Git - ctopy.git/commitdiff
Restore translation of function headers.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 2 Oct 2006 00:12:53 +0000 (00:12 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 2 Oct 2006 00:12:53 +0000 (00:12 +0000)
ctopy

diff --git a/ctopy b/ctopy
index 8131e56c57fb0b242096e9d69f572a39a85434a8..55f51d8412e84549a9d2cf3492ad72c1073dd72a 100755 (executable)
--- a/ctopy
+++ b/ctopy
@@ -77,18 +77,22 @@ repeat_transformations = (
     ),
 )
 
-# These get applied once within regions.
-region_transformations = (
+# These get applied once within regions, before type info has been stripped
+pre_transformations = (
+    # function headers
+    (r"\n(?:static\s+)?(?:%(type)s) +(.*\)) *\n", r"\ndef \1:\n"),
+    (r"\(void\):\n", r"():\n"),
+    (r"def(.*):\n\Z", r"def\1:\n    "),        # indent comment on line after def
+    )
+
+# These get applied once within regions, after type info has been stripped
+post_transformations = (
     # externs can just disappear -- this may discard a following comment
     (r"extern[^;]+;.*\n", r""),
     # macros
     (r"#define\s+(%(id)s)\s+(.*)", r"\1\t= \2"),
     (r"#define\s+(%(id)s)\(([^)]*)\)\s+(.*\))", r"def \1(\2):\treturn \3"),
     (r"#define\s+(%(id)s)\(([^)]*)\)\s+([^(].*)", r"def \1(\2):\t\3"),
-    # function headers
-    (r"\n(?:static\s+)?(?:%(type)s) +(.*\)) *\n", r"\ndef \1:\n"),
-    (r"\(void\):\n", r"():\n"),
-    (r"def(.*):\n\Z", r"def\1:\n    "),        # indent comment on line after def
     # control structure
     (r"if *\(", r"if "),
     (r"while *\(", r"while "), 
@@ -265,9 +269,10 @@ def ctopy(input):
             elif regions[i][0] != '"':
                 if debug >= 2:
                     print "Doing repeated transformations"
+                regions[i] = single_apply(pre_transformations, regions[i])
                 for hack in repeat_transformations:
                     regions[i] = repeat_apply(hack, regions[i])
-                regions[i] = single_apply(region_transformations, regions[i])
+                regions[i] = single_apply(post_transformations, regions[i])
     except IndexError:
         sys.stderr.write("ctopy: pathological string literal at %d.\n" % boundaries[i])
         raise SystemExit, 1