diff options
author | Eli Bendersky <eliben@gmail.com> | 2015-05-10 07:56:41 -0700 |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2015-05-10 07:56:41 -0700 |
commit | c830da88193cff670180b57eee95712fe1f01b07 (patch) | |
tree | ed5f48cbc172ce9ea0f2b669725c987e967f6958 | |
parent | 6c5d15d2a035948cb6c83d7331b276a43634071f (diff) | |
download | pycparser-c830da88193cff670180b57eee95712fe1f01b07.tar.gz |
Adding support for empty initializer lists.
The idea comes from #79 but the implementation is somewhat different.
-rw-r--r-- | CHANGES | 8 | ||||
-rw-r--r-- | pycparser/c_parser.py | 8 | ||||
-rwxr-xr-x | tests/test_c_parser.py | 3 |
3 files changed, 15 insertions, 4 deletions
@@ -1,7 +1,11 @@ + Version 2.13 (??) - - Adding support for offsetof() - - Adding faked va_* macros (these are expected to come from stdarg.h) + - Added support for offsetof() the way gcc implements it (special builtin + that takes a type as an argument). + - Added faked va_* macros (these are expected to come from stdarg.h) + - Added a bunch more fake headers and typedefs to support parsing C projects + like Git and SQLite without modifications to pycparser. + - Added support for empty initializer lists (#79). + Version 2.12 (21.04.2015) diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py index e4fa503..11405ed 100644 --- a/pycparser/c_parser.py +++ b/pycparser/c_parser.py @@ -85,6 +85,7 @@ class CParser(PLYParser): 'expression', 'identifier_list', 'init_declarator_list', + 'initializer_list', 'parameter_type_list', 'specifier_qualifier_list', 'block_item_list', @@ -1166,10 +1167,13 @@ class CParser(PLYParser): p[0] = p[1] def p_initializer_2(self, p): - """ initializer : brace_open initializer_list brace_close + """ initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close """ - p[0] = p[2] + if p[2] is None: + p[0] = c_ast.InitList([], self._coord(p.lineno(1))) + else: + p[0] = p[2] def p_initializer_list(self, p): """ initializer_list : designation_opt initializer diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py index ea624d9..c1bf5be 100755 --- a/tests/test_c_parser.py +++ b/tests/test_c_parser.py @@ -1096,6 +1096,9 @@ class TestCParser_fundamentals(TestCParser_base): ['Constant', 'int', '8'], ['Constant', 'int', '9']]) + d21 = 'long ar[4] = {};' + self.assertEqual(self.get_decl_init(d21), []) + d3 = 'char p = j;' self.assertEqual(self.get_decl(d3), ['Decl', 'p', ['TypeDecl', ['IdentifierType', ['char']]]]) |