Skip to content

Support forward declarations for C-like languages#1028

Closed
masnagam wants to merge 7 commits into
mozilla:mainfrom
masnagam:fix-issue-43
Closed

Support forward declarations for C-like languages#1028
masnagam wants to merge 7 commits into
mozilla:mainfrom
masnagam:fix-issue-43

Conversation

@masnagam

@masnagam masnagam commented Nov 6, 2024

Copy link
Copy Markdown

Output forward declarations for C-like languages:

  • Definition for opaque types will not output if those are used as pointer types
  • Declaration order is changed in order to solve problems of recursive type definitions

Limitations:

  • No forward declaration will be output when --style=type is specified
  • Forward declarations for template types in C++ are not supported

Fixes #43

The following files are removed

- tests/expectations/std_lib_both.c
- tests/expectations/std_lib_both.compat.c

because opaque type definitions are replaced with forward
declarations.

@emilio emilio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So... I'm not sure why we need a separate set around, it seems generally this should be tracked as part of Dependencies?

Also, I don't think we should unconditionally create forward declarations for non-problematic cases as you're doing here (anything that is a pointer gets forward-declared).

Comment thread src/bindgen/ir/ty.rs
library: &Library,
out: &mut Dependencies,
ptr_types: &mut IndexSet<GenericPath>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: space. But also rather than having an is_ptr param, it seems this should be handled in Type::Ptr itself?

@masnagam

Copy link
Copy Markdown
Author

So... I'm not sure why we need a separate set around, it seems generally this should be tracked as part of Dependencies?

Also, I don't think we should unconditionally create forward declarations for non-problematic cases as you're doing here (anything that is a pointer gets forward-declared).

i'll check your points and modify this PR when i have time.

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.

Generate forward declarations for structs with cyclical pointer references

2 participants