-
Notifications
You must be signed in to change notification settings - Fork 711
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
Feature 699 constified enum module #741
Changes from 1 commit
5762339
0826846
fb9959a
977ec6f
de155b9
5f4b730
4b10529
465e242
814d28e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Used suggested code from @emilio and also added a test for an alias to an anonymous enum.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ typedef enum foo { | |
AND_ALSO_THIS = 42, | ||
} foo; | ||
|
||
|
||
typedef enum { | ||
Variant1, Variant2, Variant3, | ||
} anon_enum; | ||
|
||
|
||
namespace ns1 { | ||
typedef enum { | ||
THIS, | ||
|
@@ -28,13 +34,21 @@ typedef foo foo_alias1; | |
typedef foo_alias1 foo_alias2; | ||
typedef foo_alias2 foo_alias3; | ||
|
||
typedef anon_enum anon_enum_alias1; | ||
typedef anon_enum_alias1 anon_enum_alias2; | ||
typedef anon_enum_alias2 anon_enum_alias3; | ||
|
||
typedef struct bar { | ||
foo member1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the new option to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the test; the behavior seems to be correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not with namespaces disabled. The following test still fails: // bindgen-flags: --constified-enum-module one_Foo
namespace one {
enum class Foo {
Variant1, Variant2,
};
}
class Bar {
one::Foo* baz;
}; |
||
foo_alias1 member2; | ||
foo_alias2 member3; | ||
foo_alias3 member4; | ||
ns1::foo member5; | ||
ns2::Foo *member6; | ||
anon_enum member7; | ||
anon_enum_alias1 member8; | ||
anon_enum_alias2 member9; | ||
anon_enum_alias3 member10; | ||
} bar; | ||
|
||
class Baz { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what you're trying to do here is resolving through
ResolvedTypeRef
s, but not throughAlias
, right?If so, instead of reinventing the wheel, you can do something like:
And keep the comment on why not through type alias.
We should arguably unify that and the
canonical_type
business, but that also handles some template stuff that may be nontrivial, so it's worth doing on a followup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check needs to "peel back" one layer of
Alias
es. The issue with theresolve()
function is that it resolves through all of theAlias
es.I think that implementation should remain as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I see. I guess I'm not sure why would making an alias claim it's a constified enum module be necessary.
I guess I'll poke a bit at the code this evening when I have the chance and see which tests break with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... Ok, so what breaks in that case is the
typedef enum
case... fun. I still think we should be able to do better, though...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about modifying
ItemResolver
to optionally disable recursive resolving? More generally,ItemResolver
could even take a positive integer indicating through how many layers to resolve.This way,
is_constified_enum_module()
could be simplified to useItemResolver
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is about the number of layers to resolve. I think the logic in
is_constified_enum_module
is wrong, and the "alias to resolved type ref to alias" logic is just masking it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's what I came up with, I think this is what you're really trying to do with that function:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to address the
TODO
if you want, btw :)