Skip to content

translate-c: add detect possible member functions #22

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

Merged
merged 8 commits into from
May 4, 2025

Conversation

flyfish30
Copy link
Contributor

@flyfish30 flyfish30 commented Apr 26, 2025

Fixes #14

If the function where the first argument is a container or a pointer to a container, then add a const variable that store the function, and the variable name is the function name without the prefix.

If the function where the first argument is a container or a pointer to a
container, then add a const variable that store the function, and the
variable name is the function name without the prefix.
src/Scope.zig Outdated
Comment on lines 343 to 344
const last_index = std.mem.lastIndexOf(u8, func_name, "_");
const last_name = if (last_index) |index| func_name[index + 1 ..] else continue;
Copy link
Member

Choose a reason for hiding this comment

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

I think all potential member functions should be added untrimmed and only then should we try to add aliases with prefixes removed. That way you also shouldn't need to mangle the names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't quite understand how to implement this suggestion. How to avoid to mangle the names?

Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it more you'd need to add a const __root = @This() to the global scope to be able to reference the function without an ambiguous reference issue but the idea would be to check if member_names.get(func_name) == null and then add an alias for func_name.

I can do this as a follow up.

@flyfish30
Copy link
Contributor Author

flyfish30 commented Apr 27, 2025

That's because I'm adding the system include dirs in the build script, if you use zig build run -- main.c it should work.

@Vexu It is also failed by use your suggest command, the detail command and error messages is in below:

➜  translate-c git:(detect-member-func-dev) ✗ /opt/zig-0.15.0-dev.384+c06fecd46/zig build run -- examples/compile_c/main.c
main entry!
examples/compile_c/main.c:1:10: fatal error: 'stdio.h' not found
#include <stdio.h>
         ^

@Vexu
Copy link
Member

Vexu commented Apr 27, 2025

I got it mixed because I was still working on #18, it should work now.

Use comparison types instead of comparison variable names
@flyfish30 flyfish30 requested a review from Vexu April 28, 2025 11:49
@flyfish30 flyfish30 requested a review from Vexu April 29, 2025 04:32
@Vexu Vexu merged commit 23d2b45 into ziglang:main May 4, 2025
3 checks passed
@Vexu
Copy link
Member

Vexu commented May 4, 2025

Thanks!

@flyfish30 flyfish30 deleted the detect-member-func branch May 5, 2025 02:07
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.

Translate-c: detect possible member functions
3 participants