Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR documents the existing introspection API (
CType,CField) more thoroughly, and adds some new APIs that would be very useful for a variety of reasons:ffi.list_enums() -> list[str]: Likelist_types()but for enum types (I'd extend the tuple returned bylist_types()but I figured we wouldn't want to break back compatibility).ffi.list_globals() -> list[CGlobal]: Lists defined globals asCGlobalobjects, which expose the kind of global (int_constant,enum,constant,variable,function,python_function), their numerical value (for integer constants) or the CType that its value would have (for the rest). Note that this is defined on ffi, and thus allows introspecting the API thatdlopenwould have without needing a suitable library that exposes all symbols.ffi.includes -> tuple[FFI]: FFI instances of the (directly) included libraries, if any, allowing users to track inherited globals too.This is fully functional, but I made it a draft since I'd like to gather some initial feedback, and (ideally) write tests and replicate these APIs in FFIBuilder as well.
There are some minor things that would be nice to have (for example make the parsing layer preserve which particular typedef, if any, was used to refer to a type, as well as documentation attached to globals, fields and types). But for now, with these introspection APIs it should be feasible to address #230.
WDYT?