-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
translate-c: Remove usage of extern enum
#9164
Conversation
This fixes the immediate issue in #9153 but does not completely remove the use of If desired, I could address that in this PR as well. |
I think that would be preferable, no reason to fix something that is going to be removed. |
832a6ee
to
279865f
Compare
extern enum
Translate enum types as the underlying integer type. Translate enum constants as top-level integer constants of the correct type (which does not necessarily match the enum integer type). If an enum constant's type cannot be translated for some reason, omit it. See discussion ziglang#2115 (comment) Fixes ziglang#9153
279865f
to
9ea73a2
Compare
I believe this also fixes #5656 |
Is it still possible to get former behavior? I am trying to convert integer values back to symbolic names.
|
@kmeaw C enums are translated as individual declarations now, so no, not really possible achieve the old behavior. |
It is possible to iterate over these declarations to build (either in run-time or in compile-time) a map of keys-to-values? In my case all of them have a unique common prefix (like |
@kmeaw Well, it's possible to do so, though not very practical, as you'd have to use One thing to consider is whether it might be beneficial to make a PR to make translate-c put enums into a namespace, though that could very likely result in some extra complexity to handle the case of when those enums are referenced by other translated code. As it stands, you're probably better off just manually creating an enum based off of the declarations. |
The reason translate-c can't do this in general is that C enumerator values are not required to be unique within an enum declaration, e.g. the following is valid C: enum E {
Foo = 1,
Bar = 1,
}; There are other issues with trying to map C enums onto Zig enums, but I don't think they're relevant for your use case. I would also guess that 99% of real-world C code does use unique enumerator values, so perhaps there would be interest in extending translate-c to keep track of the values within an enum and create a non-exhaustive enum if they're unique. |
@InKryption, thank you for your suggestions. I had attempted to iterate over |
If the enum type cannot be translated for some reason, omit it. In that
case the previous behavior will occur - the enum constant's type will be
the enum's tag type.
Fixes #9153