1. Graham Markall
  2. pycparser

Commits

Eli Bendersky  committed 2aa370b

Issue #84: fix C generation for some statements

  • Participants
  • Parent commits 490774a
  • Branches default

Comments (0)

Files changed (4)

File CHANGES

View file
  • Ignore whitespace
   - pycparser now carries its PLY dependency along. The pycparser/ply directory
     contains the source of PLY for the currently supported version. This makes
     distribution and testing easier.
+  - Issue #84: fix C generation for some statements.
   - Issues #86 and #87: improve location reporting for parse errors.
+  - Issue #89: fix C generation for K&R-style function definitions.
 
 + Version 2.08 (10.08.2012)
 

File pycparser/c_generator.py

View file
  • Ignore whitespace
         if typ in ( 
                 c_ast.Decl, c_ast.Assignment, c_ast.Cast, c_ast.UnaryOp,
                 c_ast.BinaryOp, c_ast.TernaryOp, c_ast.FuncCall, c_ast.ArrayRef,
-                c_ast.StructRef):
+                c_ast.StructRef, c_ast.Constant, c_ast.ID, c_ast.Typedef):
             # These can also appear in an expression context so no semicolon
             # is added to them automatically
             #

File tests/test_c_generator.py

View file
  • Ignore whitespace
               return 0;
             }''')
 
-        
+    def test_issue84(self):
+        self._assert_ctoc_correct(r'''
+            void x(void) {
+                for (int i = 0;;)
+                    i;
+            }
+            ''')
+
 
 if __name__ == "__main__":
     unittest.main()

File tests/test_c_parser.py

View file
  • Ignore whitespace
         # a ref in the visitor
         #
         self.assert_num_ID_refs(ps2, 'i', 3)
-        
+
         s3 = r'''
         void x(void)
         {
         #
         self.assert_num_ID_refs(ps3, 'i', 2)
 
+        s4 = r'''
+        void x(void) {
+            for (int i = 0;;)
+                i;
+        }
+        '''
+        ps4 = self.parse(s4)
+        self.assert_num_ID_refs(ps4, 'i', 1)
+
     def _open_c_file(self, name):
         """ Find a c file by name, taking into account the current dir can be
             in a couple of typical places