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() {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.