Skip to content

Translate-c-2 enums #3908

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

Merged
merged 3 commits into from
Dec 15, 2019
Merged

Translate-c-2 enums #3908

merged 3 commits into from
Dec 15, 2019

Conversation

Vexu
Copy link
Member

@Vexu Vexu commented Dec 14, 2019

Currently this implementation works different from stage 1 in hopes that #2115 (comment) is accepted.
For specifics see the test I added.

\\ p,
\\};
, &[_][]const u8{
\\pub const a = enum_unnamed_1.a;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be made to match C even bettee by using @enumToInt

Copy link
Member Author

@Vexu Vexu Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewrk since integer operations on extern enums didn't (understandably) get accepted, could we do this instead?

Using enums as flags might be abuse of the type system but it is still a common thing. This would cut out all the @enumToInt conversions but you would still get the awkwardness of abusing the type system with @intToEnum.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could make sense to translate the non-namespaced enum values as integers rather than the enum values (is that what you are proposing?). Then people have the choice of using enum literals (or fully qualified enum values) to get the enum type, or the non-namespaced values to get the integer.

The downside would be that using the integer types would not coerce to the enum type if, for example, it was used as a function parameter type.

I'm definitely open to considering this but I don't think the choice is clear. Would you mind opening a separate proposal for this?

@andrewrk andrewrk merged commit cf0d300 into ziglang:master Dec 15, 2019
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

Successfully merging this pull request may close these issues.

2 participants