Commit 4300a9c417

Evan Haas <evan@lagerdata.com>
2024-07-31 01:47:10
aro_translate_c: Make function decls public
1 parent 5cc9e18
Changed files (3)
lib/compiler/aro_translate_c.zig
@@ -297,7 +297,7 @@ fn transDecl(c: *Context, scope: *Scope, decl: NodeIndex) !void {
         .inline_fn_def,
         .inline_static_fn_def,
         => {
-            try transFnDecl(c, decl);
+            try transFnDecl(c, decl, true);
         },
 
         .@"var",
@@ -476,7 +476,7 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_node: NodeIndex, field_nod
     }
 }
 
-fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void {
+fn transFnDecl(c: *Context, fn_decl: NodeIndex, is_pub: bool) Error!void {
     const raw_ty = c.tree.nodes.items(.ty)[@intFromEnum(fn_decl)];
     const fn_ty = raw_ty.canonicalize(.standard);
     const node_data = c.tree.nodes.items(.data)[@intFromEnum(fn_decl)];
@@ -501,6 +501,7 @@ fn transFnDecl(c: *Context, fn_decl: NodeIndex) Error!void {
 
             else => unreachable,
         },
+        .is_pub = is_pub,
     };
 
     const proto_node = transFnType(c, &c.global_scope.base, raw_ty, fn_ty, fn_decl_loc, proto_ctx) catch |err| switch (err) {
test/cases/translate_c/function prototype with parenthesis.c
@@ -0,0 +1,10 @@
+void (f0) (void *L);
+void ((f1)) (void *L);
+void (((f2))) (void *L);
+
+// translate-c
+// c_frontend=clang,aro
+//
+// pub extern fn f0(L: ?*anyopaque) void;
+// pub extern fn f1(L: ?*anyopaque) void;
+// pub extern fn f2(L: ?*anyopaque) void;
test/translate_c.zig
@@ -494,16 +494,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
         \\};
     });
 
-    cases.add("function prototype with parenthesis",
-        \\void (f0) (void *L);
-        \\void ((f1)) (void *L);
-        \\void (((f2))) (void *L);
-    , &[_][]const u8{
-        \\pub extern fn f0(L: ?*anyopaque) void;
-        \\pub extern fn f1(L: ?*anyopaque) void;
-        \\pub extern fn f2(L: ?*anyopaque) void;
-    });
-
     cases.add("array initializer w/ typedef",
         \\typedef unsigned char uuid_t[16];
         \\static const uuid_t UUID_NULL __attribute__ ((unused)) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};