Commits

Eli Bendersky committed 490774a

Issue #89: fix C generation for K&R-style declarations

Comments (0)

Files changed (2)

pycparser/c_generator.py

     def visit_FuncDef(self, n):
         decl = self.visit(n.decl)
         self.indent_level = 0
-        # The body is a Compound node
         body = self.visit(n.body)
-        return decl + '\n' + body + '\n'
+        if n.param_decls:
+            knrdecls = ';\n'.join(self.visit(p) for p in n.param_decls)
+            return decl + '\n' + knrdecls + ';\n' + body + '\n'
+        else:
+            return decl + '\n' + body + '\n'
 
     def visit_FileAST(self, n):
         s = ''

tests/test_c_generator.py

                 b = - - a;
                 return a;
             }''')
-    
+
     def test_casts(self):
         self._assert_ctoc_correct(r'''
             int main() {
                 int data;
             } node;
             ''')
-    
+
+    def test_krstyle(self):
+        self._assert_ctoc_correct(r'''
+            int main(argc, argv)
+            int argc;
+            char** argv;
+            {
+                return 0;
+            }
+        ''')
+
     def test_issue36(self):
         self._assert_ctoc_correct(r'''
             int main() {
             }''')
-    
+
     def test_issue37(self):
         self._assert_ctoc_correct(r'''
             int main(void)