diff --git a/pycparserext/ext_c_parser.py b/pycparserext/ext_c_parser.py index 157e63e..c2c1141 100644 --- a/pycparserext/ext_c_parser.py +++ b/pycparserext/ext_c_parser.py @@ -392,9 +392,11 @@ def p_xxx_declarator_1(self, p): if p[2] or p[3].exprs: if isinstance(p[1], (c_ast.ArrayDecl, c_ast.FuncDecl)): decl_ext = to_decl_ext(p[1].type) + p[1].type = decl_ext elif isinstance(p[1], c_ast.TypeDecl): decl_ext = to_decl_ext(p[1]) + p[1] = decl_ext else: raise NotImplementedError( @@ -407,8 +409,6 @@ def p_xxx_declarator_1(self, p): if p[3].exprs: decl_ext.attributes = p[3] - p[1] = decl_ext - p[0] = p[1] @parameterized(('id', 'ID'), ('typeid', 'TYPEID'), ('typeid_noparen', 'TYPEID')) @@ -430,9 +430,11 @@ def p_xxx_declarator_2(self, p): if asm_label or attr_decl.exprs: if isinstance(decl, (c_ast.ArrayDecl, c_ast.FuncDecl)): decl_ext = to_decl_ext(decl.type) + decl.type = decl_ext elif isinstance(decl, c_ast.TypeDecl): decl_ext = to_decl_ext(decl) + decl = decl_ext else: raise NotImplementedError( @@ -445,8 +447,6 @@ def p_xxx_declarator_2(self, p): if attr_decl.exprs: decl_ext.attributes = attr_decl - p[1] = decl_ext - p[0] = self._type_modify_decl(decl, p[1]) @parameterized(('id', 'ID'), ('typeid', 'TYPEID'), ('typeid_noparen', 'TYPEID')) diff --git a/test/test_pycparserext.py b/test/test_pycparserext.py index 183769f..5e098b5 100644 --- a/test/test_pycparserext.py +++ b/test/test_pycparserext.py @@ -300,6 +300,23 @@ def test_array_ptr_decl_attribute(): print(GnuCGenerator().visit(ast)) +def test_array_attribute(): + src = """ + int arr[2] __attribute__((deprecated)); + """ + + from pycparser.c_ast import ArrayDecl + from pycparserext.ext_c_parser import GnuCParser + p = GnuCParser() + ast = p.parse(src) + ast.show() + + assert isinstance(ast.ext[0].type, ArrayDecl) + + from pycparserext.ext_c_generator import GnuCGenerator + print(GnuCGenerator().visit(ast)) + + def test_gnu_statement_expression(): src = """ int func(int a) {