Commits

Graham Markall committed f791d06

Fix nested initialiser lists.

Comments (0)

Files changed (2)

pycparser/c_generator.py

     def visit_InitList(self, n):
         visited_subexprs = []
         for expr in n.exprs:
-            if isinstance(expr, c_ast.InitList):
+            if isinstance(expr, c_ast.ExprList):
                 visited_subexprs.append('(' + self.visit(expr) + ')')
+            elif isinstance(expr, c_ast.InitList):
+                visited_subexprs.append('{' + self.visit(expr) + '}')
             else:
                 visited_subexprs.append(self.visit(expr))
         return ', '.join(visited_subexprs)

tests/test_c_generator.py

         }
         ''')
 
+    def test_nest_initializer_list(self):
+        self._assert_ctoc_correct(r'''
+        int main()
+        {
+           int i[1][1] = { { 1 } };
+        }''')
+
+    def test_expr_list_in_initializer_list(self):
+        self._assert_ctoc_correct(r'''
+        int main()
+        {
+           int i[1] = { (1, 2) };
+        }''')
+
     def test_issue36(self):
         self._assert_ctoc_correct(r'''
             int main() {