Skip to content

Commit

Permalink
Functors & zig declarators;
Browse files Browse the repository at this point in the history
More tests (generated) fixed
  • Loading branch information
kassane committed Apr 23, 2022
1 parent c6dc503 commit f0232b1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/bindgen/cdecl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ impl CDecl {

// When we have an identifier, put a space between the type and the declarators
if ident.is_some() {
out.write(" ");
if config.language == Language::Zig && self.declarators.is_empty() {
write!(out, "");
} else {
out.write(" ");
}
}

// Write the left part of declarators before the identifier
Expand Down Expand Up @@ -257,7 +261,7 @@ impl CDecl {
}
}
CDeclarator::Func(..) => {
if next_is_pointer {
if next_is_pointer && config.language != Language::Zig {
out.write("(");
}
}
Expand Down Expand Up @@ -286,7 +290,11 @@ impl CDecl {
match *declarator {
CDeclarator::Ptr { .. } => {
if config.language == Language::Zig {
write!(out, ": ?*{}", self.type_name);
if !last_was_pointer {
out.write(": ?fn");
} else {
write!(out, ": ?*{}", self.type_name);
}
}
last_was_pointer = true;
}
Expand All @@ -311,7 +319,7 @@ impl CDecl {
last_was_pointer = false;
}
CDeclarator::Func(ref args, layout_vertical) => {
if last_was_pointer {
if last_was_pointer && config.language != Language::Zig {
out.write(")");
}

Expand Down
3 changes: 3 additions & 0 deletions tests/expectations/export_name.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const std = @import("std");

extern fn do_the_thing_with_export_name() anyopaque;
9 changes: 9 additions & 0 deletions tests/expectations/extern.zig
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
const std = @import("std");

pub const Normal = extern struct {
x: i32,
y: f32,
};

extern fn foo() i32;

extern fn bar(a: Normal) anyopaque;
4 changes: 4 additions & 0 deletions tests/expectations/extern_2.zig
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
const std = @import("std");

extern fn first() anyopaque;

extern fn second() anyopaque;
12 changes: 12 additions & 0 deletions tests/expectations/fns.zig
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
const std = @import("std");

pub const Fns = extern struct {
_noArgs: ?fn() anyopaque,
_anonymousArg: ?fn() anyopaque,
_returnsNumber: ?fn() i32,
_namedArgs: ?fn(first: i32, snd: i16) i8,
_namedArgsWildcards: ?fn(_: i32, named: i16, _1: i64) i8,
};

extern fn root(_fns: Fns) anyopaque;

extern fn no_return() anyopaque;
9 changes: 9 additions & 0 deletions tests/expectations/typedef.zig
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
const std = @import("std");

pub const Foo_i32__i32 = extern struct {
x: i32,
y: i32,
};

pub const IntFoo_i32 = Foo_i32__i32;

extern fn root(a: IntFoo_i32) anyopaque;

0 comments on commit f0232b1

Please sign in to comment.