Closed VarLad closed 1 year ago
@Gnimuc Is to possible to translate the above to
@cenum X::UInt32 begin
A,
B,
C
end
using Clang.jl (using some config in generator.toml)?
This is technically valid C code.
you set the bar too low.
the code below is also valid C code, but I believe you can not translate it elegantly to any other main stream languages without implementing the insane namespace machanisim of C.
typedef struct A {
int x;
} B;
typedef struct B {
float y;
} A;
however, you should not get this error/crash. the expected behavior is that the generator yields above statement as error logs.
@Gnimuc C doesn't have a way to deal with the alternative of something like:
@cenum Name::UInt32 begin
Param
end
Languages like Rust, (when exporting to C headers via some autogen tool), do
enum Name {
Param
};
typedef uint32_t Name;
to convey the above.
Does it make sense to make a feature request to have an optional parameter (false by default) in generator.toml to accept the above code and translate it to appropriate Julia code (for convenience)? I can try looking into making a PR as well!
I would suggest the following pattern:
enum {
A,
B,
C
};
// the purpose here is to prevent users in any way from using C's mysterious enum types.
typedef int name;
but I'm always open for PRs.
We can have both patterns. :) Can you point me to the file I need to look into to make this change?
https://github.com/JuliaInterop/Clang.jl/issues/412#issuecomment-1360637892 is already supported.
This pattern violates the assumption used for merging translation units, so you probably need to check all down-stream passes.
I fixed the issue in the OP: AssertionError: ptr_ref[] != C_NULL
You can checkout the master branch and give it a test.
I also added a "no audit" config entry to make it easy to work around these kinda problems.
The pattern seems to be:
Skip
)Skip
and replace the tag node with the newly inserted idI would suggest the following pattern:
enum { A, B, C }; // the purpose here is to prevent users in any way from using C's mysterious enum types. typedef int name;
but I'm always open for PRs.
@Gnimuc I tried this, it generates:
@cenum var"##Ctag#293"::UInt32 begin
A = 0
B = 1
C = 2
end
const name = Cint
I'm not sure how to use this. Would it be possible to deanonymize this like we have for structs? I've opened an issue here: https://github.com/JuliaInterop/Clang.jl/issues/420
@VarLad I actually implemented https://github.com/JuliaInterop/Clang.jl/pull/413/files for you. Have you tried that?
Apparently, Clang.jl errors when translating this bit of code:
The error is:
This is technically valid C code.