summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2012-12-25 14:07:57 -0800
committerEli Bendersky <eliben@gmail.com>2012-12-25 14:07:57 -0800
commit4476d099d78c0288c8aaf907f236ab94e418bd44 (patch)
tree2da7cfbb1e1905229db0275560cd361e12b623ae
parent91525abfed039ab78182d573d47415c1871c55a5 (diff)
downloadpycparser-4476d099d78c0288c8aaf907f236ab94e418bd44.tar.gz
Issue #84: fix C generation for some statements
-rw-r--r--CHANGES2
-rw-r--r--pycparser/c_generator.py2
-rw-r--r--tests/test_c_generator.py9
-rw-r--r--tests/test_c_parser.py11
4 files changed, 21 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 353f5f2..6cad334 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,7 +7,9 @@
- 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)
diff --git a/pycparser/c_generator.py b/pycparser/c_generator.py
index e474d5a..be709a8 100644
--- a/pycparser/c_generator.py
+++ b/pycparser/c_generator.py
@@ -293,7 +293,7 @@ class CGenerator(object):
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
#
diff --git a/tests/test_c_generator.py b/tests/test_c_generator.py
index 3fc0d0e..5392603 100644
--- a/tests/test_c_generator.py
+++ b/tests/test_c_generator.py
@@ -130,7 +130,14 @@ class TestCtoC(unittest.TestCase):
return 0;
}''')
-
+ def test_issue84(self):
+ self._assert_ctoc_correct(r'''
+ void x(void) {
+ for (int i = 0;;)
+ i;
+ }
+ ''')
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index 8ef01cd..946cee5 100644
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -1390,7 +1390,7 @@ class TestCParser_whole_code(TestCParser_base):
# a ref in the visitor
#
self.assert_num_ID_refs(ps2, 'i', 3)
-
+
s3 = r'''
void x(void)
{
@@ -1406,6 +1406,15 @@ class TestCParser_whole_code(TestCParser_base):
#
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