Skip to content

translate-c: add detect possible member functions #23606

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

flyfish30
Copy link
Contributor

Fixes ziglang/translate-c#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.

@flyfish30
Copy link
Contributor Author

@Vexu Please review this PR.

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.
@flyfish30 flyfish30 force-pushed the detect-member-func branch from bac86f4 to cc4a74c Compare April 20, 2025 02:40
@Vexu
Copy link
Member

Vexu commented Apr 24, 2025

If you're going to submit this to https://github.com/ziglang/translate-c then I'd prefer to review it there when you do so.

@flyfish30
Copy link
Contributor Author

flyfish30 commented Apr 25, 2025

If you're going to submit this to https://github.com/ziglang/translate-c then I'd prefer to review it there when you do so.

I had clone https://github.com/ziglang/translate-c into my computer, it failed to build by use command zig build. There isn't any introduction document that describe how to build translate-c.
Could you tell me how to build translate-c project?

The error message is show in bellow:

translate-c git:(main) zig build
/Users/guest/.cache/zig/p/aro-0.0.0-JSD1QgZiJgAHbAL6WgwZx2fEUPB2WbHdYkAQ50URgkCG/src/aro/Parser.zig:113:36: error: type 'u29' has no members
strings: std.ArrayListAligned(u8, .@"4"),
                                  ~^~~~

My zig compiler version is 0.14.0.

@Vexu
Copy link
Member

Vexu commented Apr 25, 2025

In the build.zig.zon there is a minimum_zig_version which is greater than 0.14.0. You need master branch Zig to build it.

@flyfish30
Copy link
Contributor Author

@Vexu I had success to build translate-c project by use last version zig in master branch. But can not translate main.c file to zig file.

The detail command and output messages is show in bellow:

➜  compile_c git:(dev-flyfish30) ../../zig-out/bin/translate-c main.c
main.c:1:10: fatal error: 'stdio.h' not found
#include <stdio.h>
          ^

After I specify the include path by -I parameter, it has more error messages to terminal. The detail command and partial output messages is show in bellow:

➜  compile_c git:(dev-flyfish30) ../../zig-out/bin/translate-c -I /opt/usr/include main.c
/opt/usr/include/sys/stdio.h:51:103: warning: unknown attribute 'availability' ignored [-Wunknown-attributes]
int renamex_np(const char *, const char *, unsigned int) __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0);
                                                                                                       ^
/opt/usr/include/Availability.h:338:51: note: expanded from here
    #define __TVOS_AVAILABLE(_vers)               __OS_AVAILABILITY(tvos,introduced=_vers)

How to fix this problem? My operate system is macOS 15.3.2.

@Vexu
Copy link
Member

Vexu commented Apr 25, 2025

It's a known issue ziglang/translate-c#18, Vexu/arocc#848. You can wait for that PR to be merged or just avoid include stdio.h etc.

@flyfish30
Copy link
Contributor Author

@Vexu I had update source code to your stdio-include branch, It can be successful build compile_c example by use zig 0.15.0-dev. I could start merging my code.

➜  compile_c git:(detect-member-func-dev) /opt/zig-0.15.0-dev.384+c06fecd46/zig build
Hello from my C program!
Hello from my Zig program!

But it is also failed to translate main.c file by use translate-c that built from your latest source code of branch stdio-include.

➜  compile_c git:(detect-member-func-dev) ../../zig-out/bin/translate-c main.c
main.c:1:10: fatal error: 'stdio.h' not found
#include <stdio.h>
         ^

@Vexu
Copy link
Member

Vexu commented Apr 26, 2025

But it is also failed to translate main.c file by use translate-c that built from your latest source code of branch stdio-include.

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.

@flyfish30
Copy link
Contributor Author

But it is also failed to translate main.c file by use translate-c that built from your latest source code of branch stdio-include.

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.

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>
         ^

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
2 participants