From c53b0f336e3bd5ef2e36fb5f94a9928cdd1fd515 Mon Sep 17 00:00:00 2001 From: Akira Hayakawa Date: Sat, 20 Sep 2014 23:07:02 +0900 Subject: fix: Comma operator in Assignment Signed-off-by: Akira Hayakawa --- pycparser/c_generator.py | 2 +- tests/test_c_generator.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pycparser/c_generator.py b/pycparser/c_generator.py index 997a97c..ef30b96 100644 --- a/pycparser/c_generator.py +++ b/pycparser/c_generator.py @@ -379,7 +379,7 @@ class CGenerator(object): """ Visits 'n' and returns its string representation, parenthesized if the condition function applied to the node returns True. """ - s = self.visit(n) + s = self._visit_expr(n) if condition(n): return '(' + s + ')' else: diff --git a/tests/test_c_generator.py b/tests/test_c_generator.py index a21a0b1..7210294 100644 --- a/tests/test_c_generator.py +++ b/tests/test_c_generator.py @@ -21,6 +21,7 @@ def compare_asts(ast1, ast2): return False ast1 = ast1[1] ast2 = ast2[1] + return compare_asts(ast1, ast2) for attr in ast1.attr_names: if getattr(ast1, attr) != getattr(ast2, attr): return False @@ -208,5 +209,12 @@ class TestCtoC(unittest.TestCase): } ''') + def test_comma_op_assignment(self): + self._assert_ctoc_correct(r''' + void f() { + i = (a, b, c); + } + ''') + if __name__ == "__main__": unittest.main() -- cgit v1.2.1