Skip to content

Commit

Permalink
Merge pull request #109 from jamie-pate/master
Browse files Browse the repository at this point in the history
Update c_generator to add {} around nested NamedInitializers
  • Loading branch information
eliben committed Dec 15, 2015
2 parents aceb9c9 + 1188ae3 commit bf6aa16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pycparser/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def visit_NamedInitializer(self, n):
s += '.' + name.name
elif isinstance(name, c_ast.Constant):
s += '[' + name.value + ']'
s += ' = ' + self.visit(n.expr)
s += ' = ' + self._visit_expr(n.expr)
return s

def visit_FuncDecl(self, n):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ def test_nest_initializer_list(self):
int i[1][1] = { { 1 } };
}''')

def test_nest_named_initializer(self):
self._assert_ctoc_correct(r'''struct test
{
int i;
struct test_i_t
{
int k;
} test_i;
int j;
};
struct test test_var = {.i = 0, .test_i = {.k = 1}, .j = 2};
''')

def test_expr_list_in_initializer_list(self):
self._assert_ctoc_correct(r'''
int main()
Expand Down

0 comments on commit bf6aa16

Please sign in to comment.