-
Notifications
You must be signed in to change notification settings - Fork 1
Support unnamed structs/unions/enums #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| require 'zlib' | ||
|
|
||
| module FFIGenerate | ||
| module Clang | ||
|
|
||
|
|
@@ -84,7 +86,15 @@ def result_type | |
| end | ||
|
|
||
| def spelling | ||
| String.from_c(C.get_cursor_spelling(@c)).to_s | ||
| spelling = String.from_c(C.get_cursor_spelling(@c)).to_s | ||
| # Fix names for unnamed items | ||
| if [:struct_decl, :union_decl, :enum_decl].include?(kind) && spelling.match?(/(struct|union|enum) \(unnamed at/) | ||
| usr = String.from_c(C.get_cursor_usr(@c)).to_s | ||
| prefix = usr.split('@')[2] | ||
| prefix = 'unnamed' unless prefix | ||
| spelling = prefix + Zlib::crc32(usr).to_s | ||
| end | ||
|
Comment on lines
88
to
+96
|
||
| spelling | ||
| end | ||
|
|
||
| def ==(other) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback
prefix = 'unnamed' unless prefixdoesn’t cover cases whereusr.split('@')[2]returns an empty string (or a numeric-only segment). In that casespellingcan become something like "123…", which later turns into a Ruby class/constant name starting with_(e.g._123…) and is still invalid forclass/FFI::Structconstants. Please treatniland empty/invalid prefixes the same (e.g., default to a leading alpha prefix likeunnamed), so the synthesized identifier is always a valid Ruby constant/symbol.