Skip to content

Commit 037bd31

Browse files
authored
fix: preserve parentheses for statement exprs (#566)
1 parent 9cecc09 commit 037bd31

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pycparser/c_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def visit_IdentifierType(self, n):
133133
def _visit_expr(self, n):
134134
if isinstance(n, c_ast.InitList):
135135
return '{' + self.visit(n) + '}'
136-
elif isinstance(n, c_ast.ExprList):
136+
elif isinstance(n, (c_ast.ExprList, c_ast.Compound)):
137137
return '(' + self.visit(n) + ')'
138138
else:
139139
return self.visit(n)

tests/test_c_generator.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ def test_exprlist_with_semi(self):
306306
}
307307
''')
308308

309+
def test_exprlist_with_compound(self):
310+
self._assert_ctoc_correct(r'''
311+
void test(){
312+
(sizeof (0), ({ if (0) ; else ; }));
313+
}
314+
''')
315+
309316
def test_exprlist_with_subexprlist(self):
310317
self._assert_ctoc_correct(r'''
311318
void x() {

0 commit comments

Comments
 (0)