Skip to content

Commit ab00af8

Browse files
authored
Allow abstract declarator "static" (GH issue #539) (#545)
This is similar to: allow "static" in array parameters (GH issue #21) aac7b27 which was revised shortly after in: Fuller support for qualifiers in array dimensions. 8aad318 The grammar is as defined in C99 6.7.6 Type names, or A.2.2 Declarations (6.7.6). Fixes #539
1 parent 7847544 commit ab00af8

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pycparser/c_parser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,20 @@ def p_direct_abstract_declarator_7(self, p):
15301530
type=c_ast.TypeDecl(None, None, None, None),
15311531
coord=self._token_coord(p, 1))
15321532

1533+
def p_direct_abstract_declarator_8(self, p):
1534+
""" direct_abstract_declarator : LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
1535+
| LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
1536+
"""
1537+
listed_quals = [item if isinstance(item, list) else [item]
1538+
for item in [p[2],p[3]]]
1539+
quals = [qual for sublist in listed_quals for qual in sublist
1540+
if qual is not None]
1541+
p[0] = c_ast.ArrayDecl(
1542+
type=c_ast.TypeDecl(None, None, None, None),
1543+
dim=p[4],
1544+
dim_quals=quals,
1545+
coord=self._token_coord(p, 1))
1546+
15331547
# declaration is a list, statement isn't. To make it consistent, block_item
15341548
# will always be a list
15351549
#

tests/test_c_parser.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,21 @@ def test_func_decls_with_array_dim_qualifiers(self):
483483
[['Decl', 'p', ['ArrayDecl', '10', ['static'],
484484
['TypeDecl', ['IdentifierType', ['int']]]]]],
485485
['TypeDecl', ['IdentifierType', ['int']]]]])
486+
# anonymous function parameter
487+
self.assertEqual(self.get_decl('int zz(int [static 10]);'),
488+
['Decl', 'zz',
489+
['FuncDecl',
490+
[['Typename',
491+
['ArrayDecl', '10', ['static'],
492+
['TypeDecl', ['IdentifierType', ['int']]]]]],
493+
['TypeDecl', ['IdentifierType', ['int']]]]])
494+
self.assertEqual(self.get_decl('int zz(int [static const restrict 10]);'),
495+
['Decl', 'zz',
496+
['FuncDecl',
497+
[['Typename',
498+
['ArrayDecl', '10', ['static', 'const', 'restrict'],
499+
['TypeDecl', ['IdentifierType', ['int']]]]]],
500+
['TypeDecl', ['IdentifierType', ['int']]]]])
486501

487502
self.assertEqual(self.get_decl('int zz(int p[const 10]);'),
488503
['Decl', 'zz',

0 commit comments

Comments
 (0)