pycparserext icon indicating copy to clipboard operation
pycparserext copied to clipboard

Add support for __attribute__(()) in enum/struct/union

Open douglas-raillard-arm opened this issue 2 years ago • 5 comments

Add support for GNU __attribute__(()) in enum/struct/union definitions, both on the type itself and on enumerators.

Fixes https://github.com/inducer/pycparserext/issues/42

douglas-raillard-arm avatar Sep 01 '23 15:09 douglas-raillard-arm

Thanks for the contribution! Could you fix the linter failure? Otherwise this LGTM.

inducer avatar Sep 01 '23 18:09 inducer

@inducer I just realized that at least GCC accepts multiple __attribute__(()) on the same declaration. That PR works when they are next to each-other but obviously not if they are in multiple positions. I tried a production like that:

struct_or_union_specifier   : struct_or_union attributes_opt ID brace_open brace_close attributes_opt

But this only matches if there is an __attribute__(()) in each position, so that would lead to pretty bad combinatorial explosion of the number rules. Do you have any suggestion to fix that ?

douglas-raillard-arm avatar Sep 04 '23 09:09 douglas-raillard-arm

But this only matches if there is an __attribute__(()) in each position

Not sure I understand. Wouldn't each attributes_opt be optional individually?

inducer avatar Sep 04 '23 22:09 inducer

Not sure I understand. Wouldn't each attributes_opt be optional individually?

Yes, I did not realize it actually worked because of another issue. I'm reworking the rules to allow __attribute__(()) in multiple position at once, I'll update the PR when it's ready.

douglas-raillard-arm avatar Sep 05 '23 09:09 douglas-raillard-arm

@inducer Unfortunately I stopped using pycparserext (instead of parsing a pre-existing header made by another tool, I made a tool that creates the header in the first place) and I don't have the bandwidth to fix pycparserext. Feel free to re-own this PR if someone else wants to take over.

I did not go super far in the rework of that PR, and I ended up with some sort of conflict where the attribute was parsed then swallowed up by pycparser as that bit of the declaration is deemed irrelevant on that path, and is therefore dropped on the floor. I'm going to push the WIP commit I was working on, but that commit completely breaks the PR (it can just be reverted to get the simpler but incomplete fix that I originally submitted)

douglas-raillard-arm avatar Oct 04 '23 14:10 douglas-raillard-arm