update translate-c and tests for new extern/callconv syntax

This commit is contained in:
Andrew Kelley 2020-01-06 17:54:16 -05:00
parent 3b5c71d2a5
commit 5ada610e09
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 14 additions and 14 deletions

View File

@ -4195,7 +4195,7 @@ fn finishTransFnProto(
is_pub: bool,
) !*ast.Node.FnProto {
const is_export = if (fn_decl_context) |ctx| ctx.is_export else false;
const is_extern = if (fn_decl_context) |ctx| !ctx.has_body else true;
const is_extern = if (fn_decl_context) |ctx| !ctx.has_body else false;
// TODO check for always_inline attribute
// TODO check for align attribute
@ -4308,7 +4308,7 @@ fn finishTransFnProto(
break :blk null;
};
const callconv_expr = if (extern_export_inline_tok != null) null else blk: {
const callconv_expr = if ((is_export or is_extern) and cc == .C) null else blk: {
_ = try appendToken(rp.c, .Keyword_callconv, "callconv");
_ = try appendToken(rp.c, .LParen, "(");
const expr = try transCreateNodeEnumLiteral(rp.c, @tagName(cc));

View File

@ -295,9 +295,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ lws_callback_function *callback_http;
\\};
, &[_][]const u8{
\\pub const lws_callback_function = extern fn () void;
\\pub const lws_callback_function = fn () callconv(.C) void;
\\pub const struct_Foo = extern struct {
\\ func: ?extern fn () void,
\\ func: ?fn () callconv(.C) void,
\\ callback_http: ?lws_callback_function,
\\};
});
@ -377,7 +377,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\};
, &[_][]const u8{
\\pub const struct_Foo = extern struct {
\\ derp: ?extern fn ([*c]struct_Foo) void,
\\ derp: ?fn ([*c]struct_Foo) callconv(.C) void,
\\};
,
\\pub const Foo = struct_Foo;
@ -611,7 +611,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
cases.add("__cdecl doesn't mess up function pointers",
\\void foo(void (__cdecl *fn_ptr)(void));
, &[_][]const u8{
\\pub extern fn foo(fn_ptr: ?extern fn () void) void;
\\pub extern fn foo(fn_ptr: ?fn () callconv(.C) void) void;
});
cases.add("void cast",
@ -953,8 +953,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\typedef void (*fn0)();
\\typedef void (*fn1)(char);
, &[_][]const u8{
\\pub const fn0 = ?extern fn (...) void;
\\pub const fn1 = ?extern fn (u8) void;
\\pub const fn0 = ?fn (...) callconv(.C) void;
\\pub const fn1 = ?fn (u8) callconv(.C) void;
});
cases.addWithTarget("Calling convention", tests.Target{
@ -1157,13 +1157,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\extern char (*fn_ptr2)(int, float);
\\#define bar fn_ptr2
, &[_][]const u8{
\\pub extern var fn_ptr: ?extern fn () void;
\\pub extern var fn_ptr: ?fn () callconv(.C) void;
,
\\pub inline fn foo() void {
\\ return fn_ptr.?();
\\}
,
\\pub extern var fn_ptr2: ?extern fn (c_int, f32) u8;
\\pub extern var fn_ptr2: ?fn (c_int, f32) callconv(.C) u8;
,
\\pub inline fn bar(arg_1: c_int, arg_2: f32) u8 {
\\ return fn_ptr2.?(arg_1, arg_2);
@ -1185,8 +1185,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\#define glClearPFN PFNGLCLEARPROC
, &[_][]const u8{
\\pub const GLbitfield = c_uint;
\\pub const PFNGLCLEARPROC = ?extern fn (GLbitfield) void;
\\pub const OpenGLProc = ?extern fn () void;
\\pub const PFNGLCLEARPROC = ?fn (GLbitfield) callconv(.C) void;
\\pub const OpenGLProc = ?fn () callconv(.C) void;
\\const struct_unnamed_1 = extern struct {
\\ Clear: PFNGLCLEARPROC,
\\};
@ -1976,8 +1976,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ return 0;
\\}
\\pub export fn bar() void {
\\ var f: ?extern fn () void = foo;
\\ var b: ?extern fn () c_int = baz;
\\ var f: ?fn () callconv(.C) void = foo;
\\ var b: ?fn () callconv(.C) c_int = baz;
\\ f.?();
\\ (f).?();
\\ foo();