Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow abstract declarator "static" (GH issue #539) #545

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pycparser/c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,20 @@ def p_direct_abstract_declarator_7(self, p):
type=c_ast.TypeDecl(None, None, None, None),
coord=self._token_coord(p, 1))

def p_direct_abstract_declarator_8(self, p):
""" direct_abstract_declarator : LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
| LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
"""
listed_quals = [item if isinstance(item, list) else [item]
for item in [p[2],p[3]]]
quals = [qual for sublist in listed_quals for qual in sublist
if qual is not None]
p[0] = c_ast.ArrayDecl(
type=c_ast.TypeDecl(None, None, None, None),
dim=p[4],
dim_quals=quals,
coord=self._token_coord(p, 1))

# declaration is a list, statement isn't. To make it consistent, block_item
# will always be a list
#
Expand Down
15 changes: 15 additions & 0 deletions tests/test_c_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,21 @@ def test_func_decls_with_array_dim_qualifiers(self):
[['Decl', 'p', ['ArrayDecl', '10', ['static'],
['TypeDecl', ['IdentifierType', ['int']]]]]],
['TypeDecl', ['IdentifierType', ['int']]]]])
# anonymous function parameter
self.assertEqual(self.get_decl('int zz(int [static 10]);'),
['Decl', 'zz',
['FuncDecl',
[['Typename',
['ArrayDecl', '10', ['static'],
['TypeDecl', ['IdentifierType', ['int']]]]]],
['TypeDecl', ['IdentifierType', ['int']]]]])
self.assertEqual(self.get_decl('int zz(int [static const restrict 10]);'),
['Decl', 'zz',
['FuncDecl',
[['Typename',
['ArrayDecl', '10', ['static', 'const', 'restrict'],
['TypeDecl', ['IdentifierType', ['int']]]]]],
['TypeDecl', ['IdentifierType', ['int']]]]])

self.assertEqual(self.get_decl('int zz(int p[const 10]);'),
['Decl', 'zz',
Expand Down
Loading