Skip to content
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

Only output types and methods from the original header #13

Closed
jonas opened this issue May 28, 2018 · 8 comments
Closed

Only output types and methods from the original header #13

jonas opened this issue May 28, 2018 · 8 comments
Labels
bindgen Binding generator
Milestone

Comments

@jonas
Copy link
Member

jonas commented May 28, 2018

In the native types test both the uchar.h and stddef.h header files are included which depending on the platform will generate additional type aliases and structs definitions for types read from those headers even if those types are unused.

@jonas
Copy link
Member Author

jonas commented May 31, 2018

Depends on the IR work done in #6

@kornilova203
Copy link
Member

kornilova203 commented Jun 2, 2018

@jonas, should we remove unused types and structs that are declared only in included headers or all unused types and structs?

I wrote code that removes unused types in filter-unused-types branch but it is not aware from where these types came from

@jonas jonas added the bindgen Binding generator label Jun 25, 2018
@jonas
Copy link
Member Author

jonas commented Jun 26, 2018

Depends on type representation in the IR: #52

@kornilova203
Copy link
Member

How do we decide that type may be removed?
We already have filtering by prefix by prefix that should remove platform specific types.
We should not remove all unused typedefs simply because they may be used by other bindings.

@jonas
Copy link
Member Author

jonas commented Jul 6, 2018

This issue can be repurposed as an initial step towards #2. We need to track which header file declared a type and based on that we can prune (or ignore) any type not declared in the header file for which we are generating bindings.

Note that eventually we need to support generating bindings for multiple header files.

@jonas jonas changed the title Prune unused types when generating code Only output types and methods from the original header Jul 6, 2018
@jonas
Copy link
Member Author

jonas commented Jul 6, 2018

I've retitled the issue based on the above comment.

@jonas jonas added this to the 0.2 milestone Jul 6, 2018
@jonas
Copy link
Member Author

jonas commented Jul 7, 2018

From looking into this, it should be possible to use clang::ASTContext.getSourceManager() to get the file name of any clang::Decl processed by TreeVisitor.

Methods not in the original header can be discarded right away, while types will have to be added to the IR in case we have to reference it, e.g. stdio.FILE, or resolve it, e.g. type a = __darwin_a; type __darwin_a = native.CInt => type a = native.CInt.

On macOS I noticed that some standard headers are merely wrappers, e.g. /usr/include/ctype.h leaves all declarations to /usr/include/_ctype.h. So a lightweight way to configure and support such a use case is necessary.

@jonas
Copy link
Member Author

jonas commented Jul 7, 2018

I'm also wondering if we should put in place a proper class to track the origin of a declaration. Main can then add the initial instance to the IR and load+add known instances from stdHeader.config.

The class should contain:

  • Include path or basename (ideally paths and basenames)
  • Scala package+object name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindgen Binding generator
Projects
None yet
Development

No branches or pull requests

2 participants