]> thyrsus.com Git - mad.git/commitdiff
Handle function pointers as function arguments.
authorEric S. Raymond <esr@thyrsus,com>
Sat, 14 Feb 2004 06:56:25 +0000 (06:56 +0000)
committerEric S. Raymond <esr@thyrsus,com>
Sat, 14 Feb 2004 06:56:25 +0000 (06:56 +0000)
mad

diff --git a/mad b/mad
index 7302d99ad209fcdcb807b27b591e14bbcc19d847..c0ab70dc258b6d200c7c96efab430a50c841a5fb 100755 (executable)
--- a/mad
+++ b/mad
@@ -473,7 +473,7 @@ def p_function_application(t):
 def p_expression_funcall0(t):
     'expression : FUNCALL'
     var = t[1]
-    t[0] = ('variable', var)
+    t[0] = ('funptr', var[:-1])
     refcount[var] = refcount.get(var, 0) + 1 
 
 def p_expression_name(t):
@@ -745,10 +745,10 @@ def prinC1(t):
     elif t[0] in ('intnum', 'doublenum'):
         return t[1]
     elif type(t) == type(()) and t[0] == 'range':
-        if t[2] == ('intnum', '1'):
+        if t[2] == ('intnum', '0'):
             return print_C_expr(('variable', t[1]))
         else:
-            return print_C_expr(('+',('variable', t[1]),('-',t[2],('intnum', '1'))))
+            return print_C_expr(('+',('variable', t[1]), t[2]))
     else:
         return '***'+`t`
 
@@ -865,14 +865,19 @@ def print_C_statement(statement):
         rep = "\n" + returntypes.get(currentfunc, normalmode) + " " + currentfunc[:-1] + "("
         defaulted = []
         if len(statement) > 2:
-            for (dummy, var) in statement[2]:
-                declarator = ("*" * arraydepths.get(var, 0)) + var
-                if var in typedict:
-                    rep += typedict[var] + " " + declarator + ", "
-                    del typedict[var]
-                else:
-                    rep += normalmode + " " + declarator + ", "
-                    defaulted.append(var)
+            for (vtype, var) in statement[2]:
+                if vtype == 'funptr':
+                    # we lose if a passed-in function has a type other than the
+                    # normal mode -- there's no way to deduce this.
+                    rep += "%s (*%s)()" % (normalmode, var)
+                elif vtype == 'variable':
+                    declarator = ("*" * arraydepths.get(var, 0)) + var
+                    if var in typedict:
+                        rep += typedict[var] + " " + declarator + ", "
+                        del typedict[var]
+                    else:
+                        rep += normalmode + " " + declarator + ", "
+                        defaulted.append(var)
             if rep.endswith(", "):
                 rep = rep[:-2]
         rep  = rep + ") {"