commit d321a4b765b94818c4a483a784bb6fc9048c64ba (tree)
parent e8236551abdb7bb74811e5e9dc9890cb2abbd269
Author: Evan Haas <evan@lagerdata.com>
Date: Fri, 7 May 2021 10:23:43 -0700
translate-c: Translate FnDecl's that appear within functions
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/src/translate_c.zig b/src/translate_c.zig
@@ -1682,6 +1682,9 @@ fn transDeclStmtOne(
.Enum => {
try transEnumDecl(c, scope, @ptrCast(*const clang.EnumDecl, decl));
},
+ .Function => {
+ try visitFnDecl(c, @ptrCast(*const clang.FunctionDecl, decl));
+ },
else => |kind| return fail(
c,
error.UnsupportedTranslation,
diff --git a/test/translate_c.zig b/test/translate_c.zig
@@ -3529,4 +3529,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\warning: unable to translate function, demoted to extern
\\pub extern fn initialize() void;
});
+
+ cases.add("Function prototype declared within function",
+ \\int foo(void) {
+ \\ extern int bar(int, int);
+ \\ return bar(1, 2);
+ \\}
+ , &[_][]const u8{
+ \\pub extern fn bar(c_int, c_int) c_int;
+ \\pub export fn foo() c_int {
+ \\ return bar(@as(c_int, 1), @as(c_int, 2));
+ \\}
+ });
}