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

Support "named" variadic macros #164

Open
jefftrull opened this issue Jun 16, 2022 · 6 comments
Open

Support "named" variadic macros #164

jefftrull opened this issue Jun 16, 2022 · 6 comments

Comments

@jefftrull
Copy link
Collaborator

This piece of code appears in recent Ubuntu distributions, in /usr/include/linux/stddef.h:

#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
        union { \
                struct { MEMBERS } ATTRS; \
                struct TAG { MEMBERS } ATTRS NAME; \
        }

The gcc manual notes that names other than __VA_ARGS__ - in this case, MEMBERS - may be used to refer to the variadic arguments "as an extension". Given the ubiquity of this header it may be useful to add support for this extension.

@hkaiser
Copy link
Collaborator

hkaiser commented Jun 16, 2022

Isn't this dangerous/ambiguous? Wasn't the comma right before the ... optional? I don't remember the details...

@jefftrull
Copy link
Collaborator Author

It seems unambiguous to me. If there is some identifier token prior to the ... we use that instead of __VA_ARGS__.

Can you give an example?

@hkaiser
Copy link
Collaborator

hkaiser commented Jun 17, 2022

It seems unambiguous to me. If there is some identifier token prior to the ... we use that instead of __VA_ARGS__.

Can you give an example?

Most likely I'm misremembering things. Please feel free to implement this gcc extension if you feel it is valuable. However, as wave was always meant to be strictly conforming, I'd suggest enabling this feature only based on an explicit option the user has to provide. Wave could even mention this new option in the error message if it discovers the construct, but the option was not enabled.

@jwnhy
Copy link
Contributor

jwnhy commented Jul 31, 2024

Is this still ongoing?

I need this feature to compile kernel code and I'd like to help.
But I am quite new to Wave too...
Could anyone provide rough guidance about which file I should learn and modify to add this feature?

@jefftrull
Copy link
Collaborator Author

Like many open source libraries, Wave progresses at a rate determined by the energy level and availability of its maintainers :) I think your contribution would be very welcome, particularly given the use of this syntax in the Linux kernel (a popular target of analysis)! I'd be happy to help you get involved.

Given that this is a non-standard extension we would need to create a feature flag for it. We support certain MSVC extensions with a macro flag BOOST_WAVE_SUPPORT_MS_EXTENSIONS at compile time; another model would be to connect into the language support feature flags available at runtime in this file. The latter might be more appropriate given that the lexer itself (probably) does not need to be modified.

The actual code implementing variadic macros definition starts about here while the expansion is handled here. You are looking for a way to conditionally use a different token (probably an identifier) with a specific name instead of __VA_ARGS__. And some minimal unit tests would be required.

@jwnhy
Copy link
Contributor

jwnhy commented Sep 8, 2024

@jefftrull Hi, thank you for the suggestion.

I just opened up a PR to support this feature.

Please let me know if anything is missing or wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants