Skip to content

Commit

Permalink
Merge pull request #169 from google/remove-nested-struct-support
Browse files Browse the repository at this point in the history
Remove nested struct support
  • Loading branch information
adetaylor authored Jan 6, 2021
2 parents 8fd2f02 + aef623b commit 8fb336e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 114 deletions.
12 changes: 4 additions & 8 deletions engine/src/conversion/parse/parse_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,12 @@ impl<'a> ParseBindgen<'a> {
_ => "Opaque",
};
let kind_item = make_ident(kind_item);
let effective_type = self
.type_database
.get_effective_type(&tyname)
.unwrap_or(&tyname);
if self.type_database.is_on_blocklist(effective_type) {
if self.type_database.is_on_blocklist(&tyname) {
return Ok(());
}
let tynamestring = effective_type.to_cpp_name();
let mut for_extern_c_ts = if effective_type.has_namespace() {
let ns_string = effective_type
let tynamestring = tyname.to_cpp_name();
let mut for_extern_c_ts = if tyname.has_namespace() {
let ns_string = tyname
.ns_segment_iter()
.cloned()
.collect::<Vec<String>>()
Expand Down
59 changes: 0 additions & 59 deletions engine/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3309,65 +3309,6 @@ fn test_root_ns_meth_ret_nonpod() {
run_test("", hdr, rs, &["Bob"], &["B::C"]);
}

#[test]
fn test_nested_struct_pod() {
let hdr = indoc! {"
#include <cstdint>
struct A {
uint32_t a;
struct B {
uint32_t b;
};
};
inline void daft(A::B a) {};
"};
let rs = quote! {
let b = ffi::B { b: 12 };
ffi::daft(b);
};
run_test_ex(
"",
hdr,
rs,
&["daft"],
&["B"],
TestMethod::BeQuick,
Some(quote! {
nested_type!("B", "A::B")
}),
);
}

#[test]
fn test_nested_struct_nonpod() {
let hdr = indoc! {"
#include <cstdint>
struct A {
uint32_t a;
struct B {
B() {}
uint32_t b;
};
};
inline void daft(A::B) {}
"};
let rs = quote! {
let b = ffi::B::make_unique();
ffi::daft(b);
};
run_test_ex(
"",
hdr,
rs,
&["daft", "B"],
&[],
TestMethod::BeQuick,
Some(quote! {
nested_type!("B", "A::B")
}),
);
}

#[test]
fn test_forward_declaration() {
let hdr = indoc! {"
Expand Down
10 changes: 0 additions & 10 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,6 @@ impl IncludeCpp {
type_database
.note_pod_request(TypeName::new_from_user_input(&generate.value()));
}
} else if ident == "nested_type" {
let args;
syn::parenthesized!(args in input);
let nested: syn::LitStr = args.parse()?;
args.parse::<syn::Token![,]>()?;
let nested_in: syn::LitStr = args.parse()?;
type_database.note_nested_type(
TypeName::new_from_user_input(&nested.value()),
TypeName::new_from_user_input(&nested_in.value()),
);
} else if ident == "block" {
let args;
syn::parenthesized!(args in input);
Expand Down
12 changes: 1 addition & 11 deletions engine/src/type_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ use itertools::Itertools;
use syn::Type;

use crate::types::TypeName;
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;

/// Central registry of all information known about types.
/// At present this is very minimal; in future we should roll
/// known_types.rs into this and possibly other things as well.
#[derive(Default)]
pub(crate) struct TypeDatabase {
nested_types: HashMap<TypeName, TypeName>,
pod_requests: HashSet<TypeName>,
allowlist: HashSet<String>, // not TypeName as it may be funcs not types.
blocklist: HashSet<String>, // not TypeName as it may be funcs not types.
Expand All @@ -34,18 +33,10 @@ impl TypeDatabase {
Self::default()
}

pub(crate) fn note_nested_type(&mut self, original: TypeName, replacement: TypeName) {
self.nested_types.insert(original, replacement);
}

pub(crate) fn note_pod_request(&mut self, tn: TypeName) {
self.pod_requests.insert(tn);
}

pub(crate) fn get_effective_type(&self, original: &TypeName) -> Option<&TypeName> {
self.nested_types.get(original)
}

pub(crate) fn add_to_allowlist(&mut self, item: String) {
self.allowlist.insert(item);
}
Expand Down Expand Up @@ -88,7 +79,6 @@ impl TypeDatabase {
// If this is a std::unique_ptr we do need to pass
// its argument through.
let root = TypeName::from_type_path(typ);
let root = self.get_effective_type(&root).unwrap_or(&root);
let root = root.to_cpp_name();
if root == "Pin" {
// Strip all Pins from type names when describing them in C++.
Expand Down
26 changes: 0 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,32 +250,6 @@ macro_rules! exclude_utilities {
($($tt:tt)*) => { $crate::usage!{$($tt)*} };
}

/// Specify that a struct (or other type) is nested within
/// some outer type. autocxx can't currently determine
/// this itself; it's hoped that this is a temporary restriction
/// and that the need for this directive will evaporate soon.
/// Meanwhile, specify two arguments - first the path to the
/// type without any nesting; and secondly the path with nesting.
/// So for instance for a situation like
/// ```cpp
/// namespace A {
/// struct B {
/// struct C {
/// uint32_t b;
/// }
/// uint32_t a;
/// }
/// ```
/// specify
/// `nested_type("A::C", "A::B::C")`
///
/// A directive to be included inside
/// [include_cpp] - see [include_cpp] for general information.
#[macro_export]
macro_rules! nested_type {
($($tt:tt)*) => { $crate::usage!{$($tt)*} };
}

/// Entirely block some type from appearing in the generated
/// code. This can be useful if there is a type which is not
/// understood by bindgen or autocxx, and incorrect code is
Expand Down

0 comments on commit 8fb336e

Please sign in to comment.