From 685da0fe4b815c3df8cf51403a8c606c376f8955 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Tue, 5 Jan 2021 13:51:25 -0800 Subject: [PATCH 1/2] Remove nested type support. Currently unused. --- engine/src/conversion/parse/parse_bindgen.rs | 12 +++------ engine/src/lib.rs | 10 -------- engine/src/type_database.rs | 12 +-------- src/lib.rs | 26 -------------------- 4 files changed, 5 insertions(+), 55 deletions(-) diff --git a/engine/src/conversion/parse/parse_bindgen.rs b/engine/src/conversion/parse/parse_bindgen.rs index c54c40357..106555bd7 100644 --- a/engine/src/conversion/parse/parse_bindgen.rs +++ b/engine/src/conversion/parse/parse_bindgen.rs @@ -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::>() diff --git a/engine/src/lib.rs b/engine/src/lib.rs index 6920b01fd..deb7ffa54 100644 --- a/engine/src/lib.rs +++ b/engine/src/lib.rs @@ -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::()?; - 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); diff --git a/engine/src/type_database.rs b/engine/src/type_database.rs index 14bc180b8..b5e241854 100644 --- a/engine/src/type_database.rs +++ b/engine/src/type_database.rs @@ -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, pod_requests: HashSet, allowlist: HashSet, // not TypeName as it may be funcs not types. blocklist: HashSet, // not TypeName as it may be funcs not types. @@ -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); } @@ -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++. diff --git a/src/lib.rs b/src/lib.rs index 618f19183..e7808f0b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 From aef623bcae6d0e7e9dcfce3c51f014696af76638 Mon Sep 17 00:00:00 2001 From: Adrian Taylor Date: Wed, 6 Jan 2021 09:15:06 -0800 Subject: [PATCH 2/2] Remove nested type tests. --- engine/src/integration_tests.rs | 59 --------------------------------- 1 file changed, 59 deletions(-) diff --git a/engine/src/integration_tests.rs b/engine/src/integration_tests.rs index cee78722a..ee9b3aa31 100644 --- a/engine/src/integration_tests.rs +++ b/engine/src/integration_tests.rs @@ -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 - 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 - 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! {"