Shim Type#fully_qualified_name for libclang < 21#135
Merged
Conversation
d1c6a4d to
6629e5f
Compare
clang_getFullyQualifiedName landed in libclang 21. Earlier versions have no equivalent native API, so users on those versions hit a NoMethodError when calling the wrapper. Add a Ruby shim that composes existing libclang APIs (declaration, qualified_name, template arguments, pointer/array/reference unwrapping). Type#fully_qualified_name now dispatches: * libclang 21+ → clang_getFullyQualifiedName (native) * libclang < 21 → fqn_impl shim The shim covers approximately 95% of the native API's behavior. Known limitation: STL container typedefs that depend on default template arguments (e.g. std::vector<T>::iterator) don't expand the defaults, so the output is shorter than native but still valid C++. Code is lifted from ruby-bindgen, which has been carrying the shim as a refinement on Type and where it has been battle-tested generating Rice C++ bindings for OpenCV (1k+ classes). Closes #131.
6629e5f to
0bf8543
Compare
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.
Types of Changes
Description
clang_getFullyQualifiedNamelanded in libclang 21. Earlier versions have no equivalent native API, so callingType#fully_qualified_nameon those versions raisesNoMethodError(the FFI symbol isn't attached).Add a Ruby shim that composes existing libclang APIs (
declaration,qualified_name,template_argument_type, pointer/array/reference unwrapping) to produce equivalent output.Type#fully_qualified_namenow dispatches:clang_getFullyQualifiedName(native, unchanged)fqn_implshim (new)Known limitation
STL container typedefs that depend on default template arguments (e.g.
std::vector<T>::iterator) don't expand the defaults — the shim producesstd::vector<Pixel>::iteratorwhere native producesstd::vector<Pixel, std::allocator<Pixel>>::iterator. Output is valid C++ either way; this is the only known semantic gap.Provenance
The shim is lifted from ruby-bindgen, where it has been carried as a refinement on
Typeand battle-tested generating Rice C++ bindings for OpenCV (1k+ classes, 10k+ method signatures across multiple libclang versions). Lifting it into ffi-clang lets ruby-bindgen retire its refinement and makes the same fallback available to other consumers.Tests
The existing
#fully_qualified_namespecs no longer skip on libclang < 21 (they now go through the shim and produce the expected output). A newshim implementation (fqn_impl)describe block exercises the shim directly viafqn_impl(nil), so the shim gets coverage on libclang 21+ CI as well as on older libclang.Eight new examples covering:
Closes
Closes #131.
Contribution