Skip to content

Commit 0aa9c77

Browse files
authored
Merge pull request #392 from adetaylor/namespace-forward-declarations
Namespace forward declarations
2 parents 630af88 + f921362 commit 0aa9c77

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

gen/src/write.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub(super) fn gen<'a>(apis: &[Api], types: &'a Types, opt: &Opt, header: bool) -
3232

3333
let apis_by_namespace = NamespaceEntries::new(apis);
3434

35+
gen_namespace_forward_declarations(&apis_by_namespace, out);
3536
gen_namespace_contents(&apis_by_namespace, types, opt, header, out);
3637

3738
if !header {
@@ -44,13 +45,7 @@ pub(super) fn gen<'a>(apis: &[Api], types: &'a Types, opt: &Opt, header: bool) -
4445
out_file
4546
}
4647

47-
fn gen_namespace_contents(
48-
ns_entries: &NamespaceEntries,
49-
types: &Types,
50-
opt: &Opt,
51-
header: bool,
52-
out: &mut OutFile,
53-
) {
48+
fn gen_namespace_forward_declarations(ns_entries: &NamespaceEntries, out: &mut OutFile) {
5449
let apis = ns_entries.entries();
5550

5651
out.next_section();
@@ -63,6 +58,24 @@ fn gen_namespace_contents(
6358
}
6459
}
6560

61+
out.next_section();
62+
63+
for (child_ns, child_ns_entries) in ns_entries.children() {
64+
writeln!(out, "namespace {} {{", child_ns);
65+
gen_namespace_forward_declarations(&child_ns_entries, out);
66+
writeln!(out, "}} // namespace {}", child_ns);
67+
}
68+
}
69+
70+
fn gen_namespace_contents(
71+
ns_entries: &NamespaceEntries,
72+
types: &Types,
73+
opt: &Opt,
74+
header: bool,
75+
out: &mut OutFile,
76+
) {
77+
let apis = ns_entries.entries();
78+
6679
let mut methods_for_type = HashMap::new();
6780
for api in apis {
6881
if let Api::RustFunction(efn) = api {

tests/ffi/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ pub mod ffi {
101101
z: usize,
102102
}
103103

104+
#[namespace = "first"]
105+
struct First {
106+
second: Box<Second>,
107+
}
108+
109+
#[namespace = "second"]
110+
struct Second {
111+
i: i32,
112+
}
113+
104114
extern "C" {
105115
include!("tests/ffi/tests.h");
106116

0 commit comments

Comments
 (0)