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
Translate-c-2 the rest #3935
Translate-c-2 the rest #3935
Conversation
|
||
// TODO https://github.com/ziglang/zig/issues/3756 | ||
// TODO https://github.com/ziglang/zig/issues/1802 | ||
const checked_name = if (isZigPrimitiveType(var_name)) try std.fmt.allocPrint(c.a(), "_{}", .{var_name}) else var_name; |
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.
Am I correct in thinking this introduces a workaround for #3756?
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.
Yes. I don't like the how it makes translated names slightly less predictable, but at least it won't break on import.
I noticed that the translate-c tests are failing on master for me (even without my changes), and I'm not sure the cause. I also can't separate those bugs from anything my changes have caused, so I am a little blocked. I'm going to be mostly unavailable for the holidays pretty shortly, so if you want to hijack my pull request into your work then please go for it! |
Seems like an issue with
Will do. |
I think I already fixed this. |
src-self-hosted/translate_c.zig
Outdated
} | ||
const lhs_node = try transExpr(rp, scope, ZigClangBinaryOperator_getLHS(stmt), .used, .l_value); | ||
switch (op) { | ||
.PtrMemD, .PtrMemI, .Cmp => return revertAndWarn( |
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.
I think .*
(PtrMemD
) and ->*
(PtrMemI
) should be unreachable, because they're C++ things?
https://github.com/llvm-mirror/clang/blob/master/include/clang/AST/OperationKinds.def#L357
Also the spaceship <=>
(Cmp
) operator:
https://github.com/llvm-mirror/clang/blob/master/include/clang/AST/OperationKinds.def#L370
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.
Definitely agree, thanks for looking them up.
int main() {
int len = 2;
switch (len) {
case 0:
break;
case 1 ... 3:
break;
case 4 ... 6:
break;
default:
;
}
return 0;
} => pub export fn main() c_int {
var len: c_int = 2;
__switch: {
__default: {
__case_2: {
__case_1: {
__case_0: {
switch (len) {
0 => break :__case_0,
1...1 => break :__case_1,
4...4 => break :__case_2,
else => break :__default,
}
}
break :__switch;
}
break :__switch;
}
break :__switch;
}
{}
}
return 0;
} Of course, this is GCC's extension, and there is not much of a code like that. |
@Vexu after this is merged I would like to invite you to do the honors of deleting the C++ implementation from the repo. I think you deserve to have all those deleted lines under your name 😁 |
I went ahead and made all non-namespaced enums integers to match stage 1 behavior with anonymous enums. I also made the change for named enums since the current implementation of The benefit from this is that if you need an integer you can just use the identifier as you would in C and if you need an enum all you need to do is prefix the it with a period. |
- make non-namespaced enums ints - fix .used compound assignments not being grouped - fix macro calls with casts producing invalid Zig
//#include <stdint.h>
int a = 1;
int64_t b = 1;
If
...and many errors Would be nice not to take integer definitions from clang. |
Because they are not
Currently this behaves same as stage 1 which also requires you to include stdint.h |
Ready to merge? |
Yes, works as good as stage1 on everything I've tried. |
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.
I am delighted to merge this enormous contribution to Zig. Excellent work, @Vexu.
@Vexu want to do the honors of hooking up |
I've already done so. |
Statements
visitFnDecl
Casts
Macros
zig/src-self-hosted/translate_c.zig
Line 3057 in d8499f7