-
Notifications
You must be signed in to change notification settings - Fork 314
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
Generate forward declarations for structs with cyclical pointer references #43
Comments
Hello :-), Thanks for using cbindgen! I'm facing this issue right now. Any idea how to solve it? |
#832 has some pointers into how to fix this. |
I was having a go at this issue because it also affects me. The forward declarations I have to put in I managed to record what is being declared during output to use as reference but now I'm kinda lost. Currently it parses to IR first, fixes some stuff, then does transformations while outputting, which means I have to predict what transformations will occur (error prone) or move even more stuff to the output stage. In my view the language backends should affect the syn parse stage, generating and transforming IR stuff according to the config and language, reflecting what will really be generated. The output stage should be limited to generating the header according to style choices, no transformations. @emilio Any advice on how I should proceed? |
After analyzing the source this flowchart appears to be what was originally intended. flowchart TD
bindgen::builder::Builder -->|parse stage => build IR from rust code| bindgen::library::Library
bindgen::library::Library -->|transform stage => mutate IR| bindgen::bindings::Bindings
bindgen::bindings::Bindings -->|write stage => translate IR to text| files(header file and depfile)
If this is true, then transformations that happen after Bindings should be moved to before it is generated. Is this interpretation correct? |
Example
Possible output
This would require the dependency ordering algorithm to understand when a reference needs a declaration and when it needs a definition. If in the previous example, the data members were not pointers then it wouldn't work.
The text was updated successfully, but these errors were encountered: