Align array dimension grammar with the C standard.
The pycparser grammar for direct-declarators diverged with the C
standard, which permits const, volatile, restrict, and static to
be modifiers in the array dimension. The relevant grammar can be
found in section 6.7.5.
The old p_direct_declarator_3 was split into two rules, and the
remaining p_direct_declarator rules were renumbered, preserving
precedence. So p_direct_declarator_3 now matches array
declarations with optional type qualifiers or assignment
expressions; p_direct_declarator_4 matches declarations with the
static keyword; p_direct_declarator_5 matches the variable-length
array declarations; and p_direct_declarator_6 matches
declarations with parentheses.
diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py
index d0ef741..5c7d723 100644
--- a/tests/test_c_parser.py
+++ b/tests/test_c_parser.py
@@ -396,6 +396,22 @@
['TypeDecl', ['IdentifierType', ['int']]]]]],
['TypeDecl', ['IdentifierType', ['int']]]]])
+ self.assertEqual(self.get_decl('int zz(int p[restrict][5]);'),
+ ['Decl', 'zz',
+ ['FuncDecl',
+ [['Decl', 'p', ['ArrayDecl', '', ['restrict'],
+ ['ArrayDecl', '5', [],
+ ['TypeDecl', ['IdentifierType', ['int']]]]]]],
+ ['TypeDecl', ['IdentifierType', ['int']]]]])
+
+ self.assertEqual(self.get_decl('int zz(int p[const restrict static 10][5]);'),
+ ['Decl', 'zz',
+ ['FuncDecl',
+ [['Decl', 'p', ['ArrayDecl', '10', ['const', 'restrict', 'static'],
+ ['ArrayDecl', '5', [],
+ ['TypeDecl', ['IdentifierType', ['int']]]]]]],
+ ['TypeDecl', ['IdentifierType', ['int']]]]])
+
def test_qualifiers_storage_specifiers(self):
def assert_qs(txt, index, quals, storage):
d = self.parse(txt).ext[index]