summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Bendersky <eliben@users.noreply.github.com>2014-01-25 06:07:14 -0800
committerEli Bendersky <eliben@users.noreply.github.com>2014-01-25 06:07:14 -0800
commit69246b78d556a5c66ebad0cf2dff15ec8a6b5f6d (patch)
tree129838a7bf079da072af8b02b9dfd5a5bb097bac
parenta3fa2e0e6828f88c67d8343113ed0d161f7b2d7b (diff)
parentaac7b27d7378cf45424b1f5f1b2b450c62636dde (diff)
downloadpycparser-69246b78d556a5c66ebad0cf2dff15ec8a6b5f6d.tar.gz
Merge pull request #23 from rmartinjak/issue-21
allow "static" in array parameters (GH issue #21)
-rw-r--r--pycparser/c_parser.py3
-rw-r--r--tests/test_c_parser.py15
2 files changed, 17 insertions, 1 deletions
diff --git a/pycparser/c_parser.py b/pycparser/c_parser.py
index ae94f74..c66c2c5 100644
--- a/pycparser/c_parser.py
+++ b/pycparser/c_parser.py
@@ -984,10 +984,11 @@ class CParser(PLYParser):
def p_direct_declarator_3(self, p):
""" direct_declarator : direct_declarator LBRACKET assignment_expression_opt RBRACKET
+ | direct_declarator LBRACKET STATIC assignment_expression_opt RBRACKET
"""
arr = c_ast.ArrayDecl(
type=None,
- dim=p[3],
+ dim=p[3] if len(p) == 5 else p[4],
coord=p[1].coord)
p[0] = self._type_modify_decl(decl=p[1], modifier=arr)
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index d695b47..3522071 100644
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -1153,6 +1153,21 @@ class TestCParser_fundamentals(TestCParser_base):
[['ID', 'p']],
['TypeDecl', ['IdentifierType', ['int']]]]])
+ f5 = parse_fdef('''
+ char* zzz(int p[static 10])
+ {
+ return 3;
+ }
+ ''')
+
+ self.assertEqual(fdef_decl(f5),
+ ['Decl', 'zzz',
+ ['FuncDecl',
+ [ ['Decl', 'p', [ 'ArrayDecl', '10',
+ [ 'TypeDecl', ['IdentifierType', ['int']]]]]],
+ ['PtrDecl', ['TypeDecl', ['IdentifierType', ['char']]]]]])
+
+
def test_unified_string_literals(self):
# simple string, for reference
d1 = self.get_decl_init('char* s = "hello";')