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

Add flag to parse matching #define * into enums instead of constants #2174

Open
Emilgardis opened this issue Mar 3, 2022 · 1 comment
Open

Comments

@Emilgardis
Copy link
Contributor

Hi! I have a header file I'd rather not touch, and I want to convert some #define directives that are integers into enums, such that --constified-enum-module, --bitfield-enum etc would work as expected

#define FOO_BAR_A_BAZ 0
#define FOO_BAR_BOB 1
#define FOO_BAR_C 2
#define FOO_BAR_D 3

Given above header, generate the equivalent code as for when parsing

enum FOO_BAR {
    A_BAZ=0,
    BOB=1,
    C=2,
    D=3,
};

This should also keep comments intact.

Is this possible to implement?

@pvdrz
Copy link
Contributor

pvdrz commented Jan 9, 2023

This is definitely possible to implement but at the same time I think it could be quite fragile.

A reasonable API for this would be to provide a list of prefixes that, when matched, turn every constant with that prefix into a variant of an enumeration. However, I see cases where such prefix could be used for something unrelated and end up being part of the enum by accident.

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

2 participants