diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index 029cfc66b..849f98cb3 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -11,6 +11,8 @@ use std::io::{Read, Write}; use std::path; use std::rc::Rc; +use indexmap::IndexMap; + use crate::bindgen::config::{Config, Language}; use crate::bindgen::ir::{ Constant, Function, ItemContainer, ItemMap, Path as BindgenPath, Static, Struct, Type, Typedef, @@ -28,6 +30,7 @@ pub struct Bindings { struct_map: ItemMap, typedef_map: ItemMap, struct_fileds_memo: RefCell>>>, + pub forward_declarations: IndexMap, pub globals: Vec, pub constants: Vec, pub items: Vec, @@ -45,6 +48,7 @@ impl Bindings { config: Config, struct_map: ItemMap, typedef_map: ItemMap, + forward_declarations: IndexMap, constants: Vec, globals: Vec, items: Vec, @@ -58,6 +62,7 @@ impl Bindings { struct_map, typedef_map, struct_fileds_memo: Default::default(), + forward_declarations, globals, constants, items, diff --git a/src/bindgen/builder.rs b/src/bindgen/builder.rs index d47919b98..643509297 100644 --- a/src/bindgen/builder.rs +++ b/src/bindgen/builder.rs @@ -360,6 +360,7 @@ impl Builder { Default::default(), Default::default(), Default::default(), + Default::default(), true, String::new(), )); diff --git a/src/bindgen/config.rs b/src/bindgen/config.rs index 31316503d..690be5675 100644 --- a/src/bindgen/config.rs +++ b/src/bindgen/config.rs @@ -1076,6 +1076,16 @@ impl Default for Config { } impl Config { + pub(crate) fn forward_declarations_enabled(&self) -> bool { + match self.language { + Language::C | Language::Cxx => { + // Cannot generate forward declarations if `Style::Type` is specified. + self.style.generate_tag() + } + _ => false, + } + } + pub(crate) fn cpp_compatible_c(&self) -> bool { self.language == Language::C && self.cpp_compat } diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index ca6499d87..0303313cc 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -6,6 +6,7 @@ use std::borrow::Cow; use std::collections::HashMap; use std::io::Write; +use indexmap::IndexSet; use syn::ext::IdentExt; use syn::UnOp; @@ -13,8 +14,8 @@ use crate::bindgen::config::{Config, Language}; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, ConditionWrite, Documentation, GenericParams, Item, ItemContainer, Path, - Struct, ToCondition, Type, + AnnotationSet, Cfg, ConditionWrite, Documentation, GenericParams, GenericPath, Item, + ItemContainer, Path, Struct, ToCondition, Type, }; use crate::bindgen::language_backend::LanguageBackend; use crate::bindgen::library::Library; @@ -560,8 +561,13 @@ impl Item for Constant { &self.path } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - self.ty.add_dependencies(library, out); + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { + self.ty.add_dependencies(library, out, ptr_types); } fn export_name(&self) -> &str { diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 8927b8be5..43c5dcf97 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -4,6 +4,7 @@ use std::io::Write; +use indexmap::IndexSet; use syn::ext::IdentExt; use crate::bindgen::config::{Config, Language}; @@ -254,9 +255,14 @@ impl EnumVariant { } } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { if let VariantBody::Body { ref body, .. } = self.body { - body.add_dependencies(library, out); + body.add_dependencies(library, out, ptr_types); } } @@ -634,9 +640,14 @@ impl Item for Enum { out.insert_enum(library, self, monomorph, generic_values.to_owned()); } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { for variant in &self.variants { - variant.add_dependencies(library, out); + variant.add_dependencies(library, out, ptr_types); } } } diff --git a/src/bindgen/ir/function.rs b/src/bindgen/ir/function.rs index f25d2f884..7bdf0795d 100644 --- a/src/bindgen/ir/function.rs +++ b/src/bindgen/ir/function.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; +use indexmap::IndexSet; use syn::ext::IdentExt; use crate::bindgen::config::{Config, Language}; @@ -122,10 +123,15 @@ impl Function { } } - pub fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - self.ret.add_dependencies(library, out); + pub fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { + self.ret.add_dependencies(library, out, ptr_types); for arg in &self.args { - arg.ty.add_dependencies(library, out); + arg.ty.add_dependencies(library, out, ptr_types); } } diff --git a/src/bindgen/ir/global.rs b/src/bindgen/ir/global.rs index 7816a294b..188d34c91 100644 --- a/src/bindgen/ir/global.rs +++ b/src/bindgen/ir/global.rs @@ -2,11 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use indexmap::IndexSet; + use crate::bindgen::config::Config; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, Documentation, GenericParams, Item, ItemContainer, Path, Type, + AnnotationSet, Cfg, Documentation, GenericParams, GenericPath, Item, ItemContainer, Path, Type, }; use crate::bindgen::library::Library; @@ -109,7 +111,12 @@ impl Item for Static { GenericParams::empty() } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - self.ty.add_dependencies(library, out); + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { + self.ty.add_dependencies(library, out, ptr_types); } } diff --git a/src/bindgen/ir/item.rs b/src/bindgen/ir/item.rs index 03e1c153a..f0e9f44b4 100644 --- a/src/bindgen/ir/item.rs +++ b/src/bindgen/ir/item.rs @@ -2,15 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use indexmap::IndexMap; +use indexmap::{IndexMap, IndexSet}; use std::mem; use crate::bindgen::config::Config; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, Constant, Documentation, Enum, GenericArgument, GenericParams, OpaqueItem, - Path, Static, Struct, Typedef, Union, + AnnotationSet, Cfg, Constant, Documentation, Enum, GenericArgument, GenericParams, GenericPath, + OpaqueItem, Path, Static, Struct, Typedef, Union, }; use crate::bindgen::library::Library; use crate::bindgen::monomorph::Monomorphs; @@ -44,7 +44,16 @@ pub trait Item { } fn rename_for_config(&mut self, _config: &Config) {} - fn add_dependencies(&self, _library: &Library, _out: &mut Dependencies) {} + fn add_dependencies( + &self, + _library: &Library, + _out: &mut Dependencies, + // IndexSet is used instead of HashSet in order to keep the insertion order. + // When running `cargo test`, //tests/expectations/* will be updated randomly + // if HashSet is used. + _ptr_types: &mut IndexSet, + ) { + } fn instantiate_monomorph( &self, _generics: &[GenericArgument], diff --git a/src/bindgen/ir/opaque.rs b/src/bindgen/ir/opaque.rs index 4527e3ca8..fc8644fb7 100644 --- a/src/bindgen/ir/opaque.rs +++ b/src/bindgen/ir/opaque.rs @@ -2,11 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use indexmap::IndexSet; + use crate::bindgen::config::Config; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, Documentation, GenericArgument, GenericParams, Item, ItemContainer, Path, + AnnotationSet, Cfg, Documentation, GenericArgument, GenericParams, GenericPath, Item, + ItemContainer, Path, }; use crate::bindgen::library::Library; use crate::bindgen::mangle; @@ -98,7 +101,7 @@ impl Item for OpaqueItem { config.export.rename(&mut self.export_name); } - fn add_dependencies(&self, _: &Library, _: &mut Dependencies) {} + fn add_dependencies(&self, _: &Library, _: &mut Dependencies, _: &mut IndexSet) {} fn instantiate_monomorph( &self, diff --git a/src/bindgen/ir/structure.rs b/src/bindgen/ir/structure.rs index d805d69c9..37fe24159 100644 --- a/src/bindgen/ir/structure.rs +++ b/src/bindgen/ir/structure.rs @@ -4,14 +4,15 @@ use std::io::Write; +use indexmap::IndexSet; use syn::ext::IdentExt; use crate::bindgen::config::{Config, Language, LayoutConfig}; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, Constant, Documentation, Field, GenericArgument, GenericParams, Item, - ItemContainer, Path, Repr, ReprAlign, ReprStyle, Type, Typedef, + AnnotationSet, Cfg, Constant, Documentation, Field, GenericArgument, GenericParams, + GenericPath, Item, ItemContainer, Path, Repr, ReprAlign, ReprStyle, Type, Typedef, }; use crate::bindgen::library::Library; use crate::bindgen::mangle; @@ -372,7 +373,12 @@ impl Item for Struct { } } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { let mut fields = self.fields.iter(); // If there is a tag field, skip it @@ -381,13 +387,17 @@ impl Item for Struct { } for field in fields { - field - .ty - .add_dependencies_ignoring_generics(&self.generic_params, library, out); + field.ty.add_dependencies_ignoring_generics( + &self.generic_params, + library, + out, + ptr_types, + false, + ); } for c in &self.associated_constants { - c.add_dependencies(library, out); + c.add_dependencies(library, out, ptr_types); } } diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index 2d0d692ae..a3eb47663 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -4,6 +4,7 @@ use std::borrow::Cow; +use indexmap::IndexSet; use syn::ext::IdentExt; use crate::bindgen::config::{Config, Language}; @@ -687,15 +688,54 @@ impl Type { generic_params: &GenericParams, library: &Library, out: &mut Dependencies, + ptr_types: &mut IndexSet, + + is_ptr: bool, ) { match *self { Type::Ptr { ref ty, .. } => { - ty.add_dependencies_ignoring_generics(generic_params, library, out); + ty.add_dependencies_ignoring_generics( + generic_params, + library, + out, + ptr_types, + true, + ); } Type::Path(ref generic) => { + // Collecting dependencies of the pointer type at this point causes a declaration + // order issue if there are cyclic pointer references in the soruce files. + // See issue#832 and issue#43. + // + // For avoiding the issue, it's postponed to collect the dependnecies until + // dependencies of all types other than pointer types are collected. + // See `Library::generate()`. + // + // Collect dependencies of the type if it's a generic type. Because instantiation + // of a template type has to be performed after the template type definition in + // C++. + // + // FIXME: Forward declarations for C++ template types are not supported at this + // point. + if is_ptr && generic.generics().is_empty() { + let path = generic.path(); + if !generic_params.iter().any(|param| param.name() == path) + && library.get_items(path).is_some() + && !out.items.contains(path) + { + ptr_types.insert(generic.clone()); + } + return; + } for generic_value in generic.generics() { if let GenericArgument::Type(ref ty) = *generic_value { - ty.add_dependencies_ignoring_generics(generic_params, library, out); + ty.add_dependencies_ignoring_generics( + generic_params, + library, + out, + ptr_types, + false, + ); } } let path = generic.path(); @@ -705,10 +745,10 @@ impl Type { out.items.insert(path.clone()); for item in &items { - item.deref().add_dependencies(library, out); + item.deref().add_dependencies(library, out, ptr_types); } - for item in items { - out.order.push(item); + for item in &items { + out.order.push(item.clone()); } } } else { @@ -722,21 +762,50 @@ impl Type { } Type::Primitive(_) => {} Type::Array(ref ty, _) => { - ty.add_dependencies_ignoring_generics(generic_params, library, out); + ty.add_dependencies_ignoring_generics( + generic_params, + library, + out, + ptr_types, + false, + ); } Type::FuncPtr { ref ret, ref args, .. } => { - ret.add_dependencies_ignoring_generics(generic_params, library, out); + ret.add_dependencies_ignoring_generics( + generic_params, + library, + out, + ptr_types, + false, + ); for (_, ref arg) in args { - arg.add_dependencies_ignoring_generics(generic_params, library, out); + arg.add_dependencies_ignoring_generics( + generic_params, + library, + out, + ptr_types, + false, + ); } } } } - pub fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - self.add_dependencies_ignoring_generics(&GenericParams::default(), library, out) + pub fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { + self.add_dependencies_ignoring_generics( + &GenericParams::default(), + library, + out, + ptr_types, + false, + ); } pub fn add_monomorphs(&self, library: &Library, out: &mut Monomorphs) { diff --git a/src/bindgen/ir/typedef.rs b/src/bindgen/ir/typedef.rs index e775a4e80..47b500d84 100644 --- a/src/bindgen/ir/typedef.rs +++ b/src/bindgen/ir/typedef.rs @@ -4,14 +4,15 @@ use std::collections::HashMap; +use indexmap::IndexSet; use syn::ext::IdentExt; use crate::bindgen::config::Config; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, Documentation, Field, GenericArgument, GenericParams, Item, ItemContainer, - Path, Struct, Type, + AnnotationSet, Cfg, Documentation, Field, GenericArgument, GenericParams, GenericPath, Item, + ItemContainer, Path, Struct, Type, }; use crate::bindgen::library::Library; use crate::bindgen::mangle; @@ -161,9 +162,19 @@ impl Item for Typedef { self.aliased.rename_for_config(config, &self.generic_params); } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { - self.aliased - .add_dependencies_ignoring_generics(&self.generic_params, library, out); + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { + self.aliased.add_dependencies_ignoring_generics( + &self.generic_params, + library, + out, + ptr_types, + false, + ); } fn instantiate_monomorph( diff --git a/src/bindgen/ir/union.rs b/src/bindgen/ir/union.rs index 9c4258372..70793d265 100644 --- a/src/bindgen/ir/union.rs +++ b/src/bindgen/ir/union.rs @@ -2,14 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use indexmap::IndexSet; use syn::ext::IdentExt; use crate::bindgen::config::{Config, LayoutConfig}; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::ir::{ - AnnotationSet, Cfg, Documentation, Field, GenericArgument, GenericParams, Item, ItemContainer, - Path, Repr, ReprAlign, ReprStyle, + AnnotationSet, Cfg, Documentation, Field, GenericArgument, GenericParams, GenericPath, Item, + ItemContainer, Path, Repr, ReprAlign, ReprStyle, }; use crate::bindgen::library::Library; use crate::bindgen::mangle; @@ -212,11 +213,20 @@ impl Item for Union { } } - fn add_dependencies(&self, library: &Library, out: &mut Dependencies) { + fn add_dependencies( + &self, + library: &Library, + out: &mut Dependencies, + ptr_types: &mut IndexSet, + ) { for field in &self.fields { - field - .ty - .add_dependencies_ignoring_generics(&self.generic_params, library, out); + field.ty.add_dependencies_ignoring_generics( + &self.generic_params, + library, + out, + ptr_types, + false, + ); } } diff --git a/src/bindgen/language_backend/clike.rs b/src/bindgen/language_backend/clike.rs index b41a3c462..73084c39a 100644 --- a/src/bindgen/language_backend/clike.rs +++ b/src/bindgen/language_backend/clike.rs @@ -767,6 +767,11 @@ impl LanguageBackend for CLikeLanguageBackend<'_> { condition.write_after(self.config, out); } + fn write_forward_declaration(&mut self, out: &mut SourceWriter, t: &Type) { + cdecl::write_type(self, out, t, self.config); + out.write(";"); + } + fn write_type(&mut self, out: &mut SourceWriter, t: &Type) { cdecl::write_type(self, out, t, self.config); } diff --git a/src/bindgen/language_backend/mod.rs b/src/bindgen/language_backend/mod.rs index 065bade20..be022e7c9 100644 --- a/src/bindgen/language_backend/mod.rs +++ b/src/bindgen/language_backend/mod.rs @@ -26,6 +26,8 @@ pub trait LanguageBackend: Sized { fn write_type_def(&mut self, out: &mut SourceWriter, t: &Typedef); fn write_static(&mut self, out: &mut SourceWriter, s: &Static); + fn write_forward_declaration(&mut self, _out: &mut SourceWriter, _t: &Type) {} + fn write_function( &mut self, config: &Config, @@ -119,6 +121,7 @@ pub trait LanguageBackend: Sized { fn write_bindings(&mut self, out: &mut SourceWriter, b: &Bindings) { self.write_headers(out, &b.package_version); self.open_namespaces(out); + self.write_forward_declarations(out, b); self.write_primitive_constants(out, b); self.write_items(out, b); self.write_non_primitive_constants(out, b); @@ -129,6 +132,17 @@ pub trait LanguageBackend: Sized { self.write_trailer(out, b); } + fn write_forward_declarations(&mut self, out: &mut SourceWriter, b: &Bindings) { + if b.forward_declarations.is_empty() { + return; + } + out.new_line_if_not_start(); + for ty in b.forward_declarations.values() { + self.write_forward_declaration(out, ty); + out.new_line(); + } + } + fn write_primitive_constants(&mut self, out: &mut SourceWriter, b: &Bindings) { for constant in &b.constants { if constant.uses_only_primitive_types() { @@ -168,6 +182,12 @@ pub trait LanguageBackend: Sized { continue; } + // Check the following condition here in order to avoid outputting empty lines. + if matches!(item, ItemContainer::OpaqueItem(ref x) if b.forward_declarations.contains_key(&x.path)) { + // The opaque type has already been declared by the forward declaration. + continue; + } + out.new_line_if_not_start(); match *item { ItemContainer::Constant(..) => unreachable!(), diff --git a/src/bindgen/library.rs b/src/bindgen/library.rs index 9d61257f9..d7fad30c0 100644 --- a/src/bindgen/library.rs +++ b/src/bindgen/library.rs @@ -5,13 +5,15 @@ use std::collections::HashMap; use std::path::PathBuf; +use indexmap::indexmap; + use crate::bindgen::bindings::Bindings; use crate::bindgen::config::{Config, Language, SortKey}; use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver; use crate::bindgen::dependencies::Dependencies; use crate::bindgen::error::Error; use crate::bindgen::ir::{Constant, Enum, Function, Item, ItemContainer, ItemMap}; -use crate::bindgen::ir::{OpaqueItem, Path, Static, Struct, Typedef, Union}; +use crate::bindgen::ir::{OpaqueItem, Path, Static, Struct, Type, Typedef, Union}; use crate::bindgen::monomorph::Monomorphs; use crate::bindgen::ItemType; @@ -73,29 +75,35 @@ impl Library { self.instantiate_monomorphs(); } self.remove_excluded(); + + let mut resolver = DeclarationTypeResolver::default(); + self.collect_declaration_types(&mut resolver); + if self.config.language == Language::C { - self.resolve_declaration_types(); + self.resolve_declaration_types(&resolver); } self.rename_items(); let mut dependencies = Dependencies::new(); + let mut ptr_types = Default::default(); for function in &self.functions { - function.add_dependencies(&self, &mut dependencies); + function.add_dependencies(&self, &mut dependencies, &mut ptr_types); } self.globals.for_all_items(|global| { - global.add_dependencies(&self, &mut dependencies); + global.add_dependencies(&self, &mut dependencies, &mut ptr_types); }); self.constants.for_all_items(|constant| { - constant.add_dependencies(&self, &mut dependencies); + constant.add_dependencies(&self, &mut dependencies, &mut ptr_types); }); for name in &self.config.export.include { let path = Path::new(name.clone()); if let Some(items) = self.get_items(&path) { if dependencies.items.insert(path) { for item in &items { - item.deref().add_dependencies(&self, &mut dependencies); + item.deref() + .add_dependencies(&self, &mut dependencies, &mut ptr_types); } for item in items { dependencies.order.push(item); @@ -104,6 +112,25 @@ impl Library { } } + let mut forward_declarations = indexmap! {}; + while !ptr_types.is_empty() { + let mut remainings = Default::default(); + for path in ptr_types.into_iter() { + if self.config.forward_declarations_enabled() { + let mut path = path.clone(); + // `resolve_declaration_types()` is called on each `GenericPath` + // in order to set `ctype`. + path.resolve_declaration_types(&resolver); + // A `GenericPath` for an alias type has no `ctype`. + if path.ctype().is_some() { + forward_declarations.insert(path.path().clone(), Type::Path(path)); + } + } + Type::Path(path).add_dependencies(&self, &mut dependencies, &mut remainings); + } + ptr_types = remainings; + } + dependencies.sort(); let items = dependencies.order; @@ -138,6 +165,7 @@ impl Library { self.config, self.structs, self.typedefs, + forward_declarations, constants, globals, items, @@ -318,52 +346,56 @@ impl Library { } } - fn resolve_declaration_types(&mut self) { + fn collect_declaration_types(&self, resolver: &mut DeclarationTypeResolver) { if !self.config.style.generate_tag() { return; } - let mut resolver = DeclarationTypeResolver::default(); - self.structs.for_all_items(|x| { - x.collect_declaration_types(&mut resolver); + x.collect_declaration_types(resolver); }); self.enums.for_all_items(|x| { - x.collect_declaration_types(&mut resolver); + x.collect_declaration_types(resolver); }); self.unions.for_all_items(|x| { - x.collect_declaration_types(&mut resolver); + x.collect_declaration_types(resolver); }); self.typedefs.for_all_items(|x| { - x.collect_declaration_types(&mut resolver); + x.collect_declaration_types(resolver); }); // NOTE: Intentionally last, so that in case there's an opaque type // which is conflicting with a non-opaque one, the later wins. self.opaque_items.for_all_items(|x| { - x.collect_declaration_types(&mut resolver); + x.collect_declaration_types(resolver); }); + } + + fn resolve_declaration_types(&mut self, resolver: &DeclarationTypeResolver) { + if !self.config.style.generate_tag() { + return; + } self.enums - .for_all_items_mut(|x| x.resolve_declaration_types(&resolver)); + .for_all_items_mut(|x| x.resolve_declaration_types(resolver)); self.structs - .for_all_items_mut(|x| x.resolve_declaration_types(&resolver)); + .for_all_items_mut(|x| x.resolve_declaration_types(resolver)); self.unions - .for_all_items_mut(|x| x.resolve_declaration_types(&resolver)); + .for_all_items_mut(|x| x.resolve_declaration_types(resolver)); self.typedefs - .for_all_items_mut(|x| x.resolve_declaration_types(&resolver)); + .for_all_items_mut(|x| x.resolve_declaration_types(resolver)); self.globals - .for_all_items_mut(|x| x.resolve_declaration_types(&resolver)); + .for_all_items_mut(|x| x.resolve_declaration_types(resolver)); for item in &mut self.functions { - item.resolve_declaration_types(&resolver); + item.resolve_declaration_types(resolver); } } diff --git a/tests/expectations/bitfield.cpp b/tests/expectations/bitfield.cpp index 640efb03a..5a7a86bad 100644 --- a/tests/expectations/bitfield.cpp +++ b/tests/expectations/bitfield.cpp @@ -4,6 +4,8 @@ #include #include +struct HasBitfields; + struct HasBitfields { uint64_t foo: 8; uint64_t bar: 56; diff --git a/tests/expectations/bitfield_both.c b/tests/expectations/bitfield_both.c index 7505f464f..aea8b7da4 100644 --- a/tests/expectations/bitfield_both.c +++ b/tests/expectations/bitfield_both.c @@ -3,6 +3,8 @@ #include #include +struct HasBitfields; + typedef struct HasBitfields { uint64_t foo: 8; uint64_t bar: 56; diff --git a/tests/expectations/bitfield_both.compat.c b/tests/expectations/bitfield_both.compat.c index 4d4df0e66..7f500b4ce 100644 --- a/tests/expectations/bitfield_both.compat.c +++ b/tests/expectations/bitfield_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct HasBitfields; + typedef struct HasBitfields { uint64_t foo: 8; uint64_t bar: 56; diff --git a/tests/expectations/bitfield_tag.c b/tests/expectations/bitfield_tag.c index db327af29..921420524 100644 --- a/tests/expectations/bitfield_tag.c +++ b/tests/expectations/bitfield_tag.c @@ -3,6 +3,8 @@ #include #include +struct HasBitfields; + struct HasBitfields { uint64_t foo: 8; uint64_t bar: 56; diff --git a/tests/expectations/bitfield_tag.compat.c b/tests/expectations/bitfield_tag.compat.c index 630ed741c..1dd01047a 100644 --- a/tests/expectations/bitfield_tag.compat.c +++ b/tests/expectations/bitfield_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct HasBitfields; + struct HasBitfields { uint64_t foo: 8; uint64_t bar: 56; diff --git a/tests/expectations/box.cpp b/tests/expectations/box.cpp index 76a5ef773..d192011d4 100644 --- a/tests/expectations/box.cpp +++ b/tests/expectations/box.cpp @@ -18,6 +18,8 @@ using Box = T*; #include #include +struct MyStruct; + template struct NotReprC; diff --git a/tests/expectations/box_both.c b/tests/expectations/box_both.c index 3a9f76aea..2b68e614b 100644 --- a/tests/expectations/box_both.c +++ b/tests/expectations/box_both.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct MyStruct; + typedef struct NotReprC_____i32 NotReprC_____i32; typedef struct NotReprC_____i32 Foo; diff --git a/tests/expectations/box_both.compat.c b/tests/expectations/box_both.compat.c index dc8c3cba2..bf494bc12 100644 --- a/tests/expectations/box_both.compat.c +++ b/tests/expectations/box_both.compat.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct MyStruct; + typedef struct NotReprC_____i32 NotReprC_____i32; typedef struct NotReprC_____i32 Foo; diff --git a/tests/expectations/box_tag.c b/tests/expectations/box_tag.c index da0eb4a00..a13a2991f 100644 --- a/tests/expectations/box_tag.c +++ b/tests/expectations/box_tag.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct MyStruct; + struct NotReprC_____i32; typedef struct NotReprC_____i32 Foo; diff --git a/tests/expectations/box_tag.compat.c b/tests/expectations/box_tag.compat.c index 2290dc3b1..b1b368629 100644 --- a/tests/expectations/box_tag.compat.c +++ b/tests/expectations/box_tag.compat.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct MyStruct; + struct NotReprC_____i32; typedef struct NotReprC_____i32 Foo; diff --git a/tests/expectations/cell.cpp b/tests/expectations/cell.cpp index f863e794c..48655c3ca 100644 --- a/tests/expectations/cell.cpp +++ b/tests/expectations/cell.cpp @@ -4,6 +4,8 @@ #include #include +struct MyStruct; + template struct NotReprC; diff --git a/tests/expectations/cell_both.c b/tests/expectations/cell_both.c index 444742237..01e3a28f1 100644 --- a/tests/expectations/cell_both.c +++ b/tests/expectations/cell_both.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + typedef struct NotReprC_RefCell_i32 NotReprC_RefCell_i32; typedef struct NotReprC_RefCell_i32 Foo; diff --git a/tests/expectations/cell_both.compat.c b/tests/expectations/cell_both.compat.c index 53ea3efae..60f1d8a3a 100644 --- a/tests/expectations/cell_both.compat.c +++ b/tests/expectations/cell_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + typedef struct NotReprC_RefCell_i32 NotReprC_RefCell_i32; typedef struct NotReprC_RefCell_i32 Foo; diff --git a/tests/expectations/cell_tag.c b/tests/expectations/cell_tag.c index 0e39870ff..e9626ed30 100644 --- a/tests/expectations/cell_tag.c +++ b/tests/expectations/cell_tag.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + struct NotReprC_RefCell_i32; typedef struct NotReprC_RefCell_i32 Foo; diff --git a/tests/expectations/cell_tag.compat.c b/tests/expectations/cell_tag.compat.c index ed26a79a1..467822af0 100644 --- a/tests/expectations/cell_tag.compat.c +++ b/tests/expectations/cell_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + struct NotReprC_RefCell_i32; typedef struct NotReprC_RefCell_i32 Foo; diff --git a/tests/expectations/const_generics.cpp b/tests/expectations/const_generics.cpp index 68a0ae734..2bb112d1b 100644 --- a/tests/expectations/const_generics.cpp +++ b/tests/expectations/const_generics.cpp @@ -4,6 +4,8 @@ #include #include +struct Book; + constexpr static const uintptr_t TITLE_SIZE = 80; template diff --git a/tests/expectations/const_generics_arrayvec_both.c b/tests/expectations/const_generics_arrayvec_both.c index e3cc9a076..129f6c544 100644 --- a/tests/expectations/const_generics_arrayvec_both.c +++ b/tests/expectations/const_generics_arrayvec_both.c @@ -3,6 +3,8 @@ #include #include +struct ArrayVec_____u8__100; + typedef struct ArrayVec_____u8__100 { uint8_t *xs[100]; uint32_t len; diff --git a/tests/expectations/const_generics_arrayvec_both.compat.c b/tests/expectations/const_generics_arrayvec_both.compat.c index 313d761d2..e4dd24e8c 100644 --- a/tests/expectations/const_generics_arrayvec_both.compat.c +++ b/tests/expectations/const_generics_arrayvec_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct ArrayVec_____u8__100; + typedef struct ArrayVec_____u8__100 { uint8_t *xs[100]; uint32_t len; diff --git a/tests/expectations/const_generics_arrayvec_tag.c b/tests/expectations/const_generics_arrayvec_tag.c index 1f45babca..216afc9f9 100644 --- a/tests/expectations/const_generics_arrayvec_tag.c +++ b/tests/expectations/const_generics_arrayvec_tag.c @@ -3,6 +3,8 @@ #include #include +struct ArrayVec_____u8__100; + struct ArrayVec_____u8__100 { uint8_t *xs[100]; uint32_t len; diff --git a/tests/expectations/const_generics_arrayvec_tag.compat.c b/tests/expectations/const_generics_arrayvec_tag.compat.c index 019aaa531..1d918e13a 100644 --- a/tests/expectations/const_generics_arrayvec_tag.compat.c +++ b/tests/expectations/const_generics_arrayvec_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct ArrayVec_____u8__100; + struct ArrayVec_____u8__100 { uint8_t *xs[100]; uint32_t len; diff --git a/tests/expectations/const_generics_bool.c b/tests/expectations/const_generics_bool.c index 3ed168da9..7cf9ed28b 100644 --- a/tests/expectations/const_generics_bool.c +++ b/tests/expectations/const_generics_bool.c @@ -5,6 +5,10 @@ typedef const char *Str; +typedef void (*SetCallback)(Str key); + +typedef void (*MapCallback)(Str key, uint64_t val); + typedef struct { uintptr_t num_buckets; uintptr_t capacity; @@ -15,8 +19,6 @@ typedef struct { typedef HashTable_Str__c_char__false MySet; -typedef void (*SetCallback)(Str key); - typedef struct { uintptr_t num_buckets; uintptr_t capacity; @@ -25,8 +27,6 @@ typedef struct { uint64_t *vals; } HashTable_Str__u64__true; -typedef void (*MapCallback)(Str key, uint64_t val); - MySet *new_set(void); void set_for_each(const MySet *set, SetCallback callback); diff --git a/tests/expectations/const_generics_bool.compat.c b/tests/expectations/const_generics_bool.compat.c index 9110e228c..ecf1c100d 100644 --- a/tests/expectations/const_generics_bool.compat.c +++ b/tests/expectations/const_generics_bool.compat.c @@ -5,6 +5,10 @@ typedef const char *Str; +typedef void (*SetCallback)(Str key); + +typedef void (*MapCallback)(Str key, uint64_t val); + typedef struct { uintptr_t num_buckets; uintptr_t capacity; @@ -15,8 +19,6 @@ typedef struct { typedef HashTable_Str__c_char__false MySet; -typedef void (*SetCallback)(Str key); - typedef struct { uintptr_t num_buckets; uintptr_t capacity; @@ -25,8 +27,6 @@ typedef struct { uint64_t *vals; } HashTable_Str__u64__true; -typedef void (*MapCallback)(Str key, uint64_t val); - #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/tests/expectations/const_generics_bool.cpp b/tests/expectations/const_generics_bool.cpp index 90b594d52..a5ae6bc42 100644 --- a/tests/expectations/const_generics_bool.cpp +++ b/tests/expectations/const_generics_bool.cpp @@ -9,6 +9,8 @@ struct MaybeUninit; using Str = const char*; +using SetCallback = void(*)(Str key); + template struct HashTable { uintptr_t num_buckets; @@ -18,12 +20,10 @@ struct HashTable { MaybeUninit *vals; }; -using MySet = HashTable; - -using SetCallback = void(*)(Str key); - using MapCallback = void(*)(Str key, uint64_t val); +using MySet = HashTable; + extern "C" { MySet *new_set(); diff --git a/tests/expectations/const_generics_bool.pyx b/tests/expectations/const_generics_bool.pyx index a21999298..e7e730579 100644 --- a/tests/expectations/const_generics_bool.pyx +++ b/tests/expectations/const_generics_bool.pyx @@ -8,6 +8,10 @@ cdef extern from *: ctypedef const char *Str; + ctypedef void (*SetCallback)(Str key); + + ctypedef void (*MapCallback)(Str key, uint64_t val); + ctypedef struct HashTable_Str__c_char__false: uintptr_t num_buckets; uintptr_t capacity; @@ -17,8 +21,6 @@ cdef extern from *: ctypedef HashTable_Str__c_char__false MySet; - ctypedef void (*SetCallback)(Str key); - ctypedef struct HashTable_Str__u64__true: uintptr_t num_buckets; uintptr_t capacity; @@ -26,8 +28,6 @@ cdef extern from *: Str *keys; uint64_t *vals; - ctypedef void (*MapCallback)(Str key, uint64_t val); - MySet *new_set(); void set_for_each(const MySet *set, SetCallback callback); diff --git a/tests/expectations/const_generics_bool_both.c b/tests/expectations/const_generics_bool_both.c index c693f41b6..2735a79a5 100644 --- a/tests/expectations/const_generics_bool_both.c +++ b/tests/expectations/const_generics_bool_both.c @@ -3,8 +3,14 @@ #include #include +struct HashTable_Str__u64__true; + typedef const char *Str; +typedef void (*SetCallback)(Str key); + +typedef void (*MapCallback)(Str key, uint64_t val); + typedef struct HashTable_Str__c_char__false { uintptr_t num_buckets; uintptr_t capacity; @@ -15,8 +21,6 @@ typedef struct HashTable_Str__c_char__false { typedef struct HashTable_Str__c_char__false MySet; -typedef void (*SetCallback)(Str key); - typedef struct HashTable_Str__u64__true { uintptr_t num_buckets; uintptr_t capacity; @@ -25,8 +29,6 @@ typedef struct HashTable_Str__u64__true { uint64_t *vals; } HashTable_Str__u64__true; -typedef void (*MapCallback)(Str key, uint64_t val); - MySet *new_set(void); void set_for_each(const MySet *set, SetCallback callback); diff --git a/tests/expectations/const_generics_bool_both.compat.c b/tests/expectations/const_generics_bool_both.compat.c index c1a44cde3..f5c69c6b6 100644 --- a/tests/expectations/const_generics_bool_both.compat.c +++ b/tests/expectations/const_generics_bool_both.compat.c @@ -3,8 +3,14 @@ #include #include +struct HashTable_Str__u64__true; + typedef const char *Str; +typedef void (*SetCallback)(Str key); + +typedef void (*MapCallback)(Str key, uint64_t val); + typedef struct HashTable_Str__c_char__false { uintptr_t num_buckets; uintptr_t capacity; @@ -15,8 +21,6 @@ typedef struct HashTable_Str__c_char__false { typedef struct HashTable_Str__c_char__false MySet; -typedef void (*SetCallback)(Str key); - typedef struct HashTable_Str__u64__true { uintptr_t num_buckets; uintptr_t capacity; @@ -25,8 +29,6 @@ typedef struct HashTable_Str__u64__true { uint64_t *vals; } HashTable_Str__u64__true; -typedef void (*MapCallback)(Str key, uint64_t val); - #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/tests/expectations/const_generics_bool_tag.c b/tests/expectations/const_generics_bool_tag.c index 8cb1df013..68be4f20b 100644 --- a/tests/expectations/const_generics_bool_tag.c +++ b/tests/expectations/const_generics_bool_tag.c @@ -3,8 +3,14 @@ #include #include +struct HashTable_Str__u64__true; + typedef const char *Str; +typedef void (*SetCallback)(Str key); + +typedef void (*MapCallback)(Str key, uint64_t val); + struct HashTable_Str__c_char__false { uintptr_t num_buckets; uintptr_t capacity; @@ -15,8 +21,6 @@ struct HashTable_Str__c_char__false { typedef struct HashTable_Str__c_char__false MySet; -typedef void (*SetCallback)(Str key); - struct HashTable_Str__u64__true { uintptr_t num_buckets; uintptr_t capacity; @@ -25,8 +29,6 @@ struct HashTable_Str__u64__true { uint64_t *vals; }; -typedef void (*MapCallback)(Str key, uint64_t val); - MySet *new_set(void); void set_for_each(const MySet *set, SetCallback callback); diff --git a/tests/expectations/const_generics_bool_tag.compat.c b/tests/expectations/const_generics_bool_tag.compat.c index 87faa6d73..0ecbb731d 100644 --- a/tests/expectations/const_generics_bool_tag.compat.c +++ b/tests/expectations/const_generics_bool_tag.compat.c @@ -3,8 +3,14 @@ #include #include +struct HashTable_Str__u64__true; + typedef const char *Str; +typedef void (*SetCallback)(Str key); + +typedef void (*MapCallback)(Str key, uint64_t val); + struct HashTable_Str__c_char__false { uintptr_t num_buckets; uintptr_t capacity; @@ -15,8 +21,6 @@ struct HashTable_Str__c_char__false { typedef struct HashTable_Str__c_char__false MySet; -typedef void (*SetCallback)(Str key); - struct HashTable_Str__u64__true { uintptr_t num_buckets; uintptr_t capacity; @@ -25,8 +29,6 @@ struct HashTable_Str__u64__true { uint64_t *vals; }; -typedef void (*MapCallback)(Str key, uint64_t val); - #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/tests/expectations/const_generics_bool_tag.pyx b/tests/expectations/const_generics_bool_tag.pyx index 54cf04ae9..6d777d3bb 100644 --- a/tests/expectations/const_generics_bool_tag.pyx +++ b/tests/expectations/const_generics_bool_tag.pyx @@ -8,6 +8,10 @@ cdef extern from *: ctypedef const char *Str; + ctypedef void (*SetCallback)(Str key); + + ctypedef void (*MapCallback)(Str key, uint64_t val); + cdef struct HashTable_Str__c_char__false: uintptr_t num_buckets; uintptr_t capacity; @@ -17,8 +21,6 @@ cdef extern from *: ctypedef HashTable_Str__c_char__false MySet; - ctypedef void (*SetCallback)(Str key); - cdef struct HashTable_Str__u64__true: uintptr_t num_buckets; uintptr_t capacity; @@ -26,8 +28,6 @@ cdef extern from *: Str *keys; uint64_t *vals; - ctypedef void (*MapCallback)(Str key, uint64_t val); - MySet *new_set(); void set_for_each(const MySet *set, SetCallback callback); diff --git a/tests/expectations/const_generics_both.c b/tests/expectations/const_generics_both.c index 78399bc52..91a562547 100644 --- a/tests/expectations/const_generics_both.c +++ b/tests/expectations/const_generics_both.c @@ -3,6 +3,8 @@ #include #include +struct Book; + #define TITLE_SIZE 80 typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE]; diff --git a/tests/expectations/const_generics_both.compat.c b/tests/expectations/const_generics_both.compat.c index 245cc46fa..107dc110a 100644 --- a/tests/expectations/const_generics_both.compat.c +++ b/tests/expectations/const_generics_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct Book; + #define TITLE_SIZE 80 typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE]; diff --git a/tests/expectations/const_generics_byte_both.c b/tests/expectations/const_generics_byte_both.c index ccfcebc98..07fd2e368 100644 --- a/tests/expectations/const_generics_byte_both.c +++ b/tests/expectations/const_generics_byte_both.c @@ -3,6 +3,9 @@ #include #include +struct Parser_40__41; +struct Parser_123__125; + typedef struct Parser_40__41 { uint8_t *buf; uintptr_t len; diff --git a/tests/expectations/const_generics_byte_both.compat.c b/tests/expectations/const_generics_byte_both.compat.c index c3ae14be2..6006f326f 100644 --- a/tests/expectations/const_generics_byte_both.compat.c +++ b/tests/expectations/const_generics_byte_both.compat.c @@ -3,6 +3,9 @@ #include #include +struct Parser_40__41; +struct Parser_123__125; + typedef struct Parser_40__41 { uint8_t *buf; uintptr_t len; diff --git a/tests/expectations/const_generics_byte_tag.c b/tests/expectations/const_generics_byte_tag.c index 4d2d5f844..e50c2a558 100644 --- a/tests/expectations/const_generics_byte_tag.c +++ b/tests/expectations/const_generics_byte_tag.c @@ -3,6 +3,9 @@ #include #include +struct Parser_40__41; +struct Parser_123__125; + struct Parser_40__41 { uint8_t *buf; uintptr_t len; diff --git a/tests/expectations/const_generics_byte_tag.compat.c b/tests/expectations/const_generics_byte_tag.compat.c index a25480e33..b6b30259c 100644 --- a/tests/expectations/const_generics_byte_tag.compat.c +++ b/tests/expectations/const_generics_byte_tag.compat.c @@ -3,6 +3,9 @@ #include #include +struct Parser_40__41; +struct Parser_123__125; + struct Parser_40__41 { uint8_t *buf; uintptr_t len; diff --git a/tests/expectations/const_generics_tag.c b/tests/expectations/const_generics_tag.c index 09e47666d..8c2fea2b4 100644 --- a/tests/expectations/const_generics_tag.c +++ b/tests/expectations/const_generics_tag.c @@ -3,6 +3,8 @@ #include #include +struct Book; + #define TITLE_SIZE 80 typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE]; diff --git a/tests/expectations/const_generics_tag.compat.c b/tests/expectations/const_generics_tag.compat.c index 1d9b90d45..27ca162ca 100644 --- a/tests/expectations/const_generics_tag.compat.c +++ b/tests/expectations/const_generics_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct Book; + #define TITLE_SIZE 80 typedef int8_t CArrayString_TITLE_SIZE[TITLE_SIZE]; diff --git a/tests/expectations/dep_v2.cpp b/tests/expectations/dep_v2.cpp index 1190c297b..a1446c8c8 100644 --- a/tests/expectations/dep_v2.cpp +++ b/tests/expectations/dep_v2.cpp @@ -4,6 +4,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/dep_v2_both.c b/tests/expectations/dep_v2_both.c index 9a91a4fe4..9613d2e6b 100644 --- a/tests/expectations/dep_v2_both.c +++ b/tests/expectations/dep_v2_both.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + typedef struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/dep_v2_both.compat.c b/tests/expectations/dep_v2_both.compat.c index 9b6c2e3c2..07cc7e6d1 100644 --- a/tests/expectations/dep_v2_both.compat.c +++ b/tests/expectations/dep_v2_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + typedef struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/dep_v2_tag.c b/tests/expectations/dep_v2_tag.c index 45fcba665..319107c86 100644 --- a/tests/expectations/dep_v2_tag.c +++ b/tests/expectations/dep_v2_tag.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/dep_v2_tag.compat.c b/tests/expectations/dep_v2_tag.compat.c index 51aee8fcd..081fe059e 100644 --- a/tests/expectations/dep_v2_tag.compat.c +++ b/tests/expectations/dep_v2_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/destructor_and_copy_ctor.c b/tests/expectations/destructor_and_copy_ctor.c index 0f616ab26..bc8a1486c 100644 --- a/tests/expectations/destructor_and_copy_ctor.c +++ b/tests/expectations/destructor_and_copy_ctor.c @@ -13,6 +13,20 @@ enum FillRule { }; typedef uint8_t FillRule; +enum Tazz_Tag { + Bar4, + Taz2, +}; +typedef uint8_t Tazz_Tag; + +typedef union { + Tazz_Tag tag; + struct { + Tazz_Tag taz2_tag; + int32_t taz2; + }; +} Tazz; + /** * This will have a destructor manually implemented via variant_body, and * similarly a Drop impl in Rust. @@ -137,20 +151,6 @@ typedef union { }; } Taz; -enum Tazz_Tag { - Bar4, - Taz2, -}; -typedef uint8_t Tazz_Tag; - -typedef union { - Tazz_Tag tag; - struct { - Tazz_Tag taz2_tag; - int32_t taz2; - }; -} Tazz; - enum Tazzz_Tag { Bar5, Taz5, diff --git a/tests/expectations/destructor_and_copy_ctor.compat.c b/tests/expectations/destructor_and_copy_ctor.compat.c index f12119b0d..57448cc01 100644 --- a/tests/expectations/destructor_and_copy_ctor.compat.c +++ b/tests/expectations/destructor_and_copy_ctor.compat.c @@ -19,6 +19,26 @@ enum FillRule typedef uint8_t FillRule; #endif // __cplusplus +enum Tazz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Bar4, + Taz2, +}; +#ifndef __cplusplus +typedef uint8_t Tazz_Tag; +#endif // __cplusplus + +typedef union { + Tazz_Tag tag; + struct { + Tazz_Tag taz2_tag; + int32_t taz2; + }; +} Tazz; + /** * This will have a destructor manually implemented via variant_body, and * similarly a Drop impl in Rust. @@ -161,26 +181,6 @@ typedef union { }; } Taz; -enum Tazz_Tag -#ifdef __cplusplus - : uint8_t -#endif // __cplusplus - { - Bar4, - Taz2, -}; -#ifndef __cplusplus -typedef uint8_t Tazz_Tag; -#endif // __cplusplus - -typedef union { - Tazz_Tag tag; - struct { - Tazz_Tag taz2_tag; - int32_t taz2; - }; -} Tazz; - enum Tazzz_Tag #ifdef __cplusplus : uint8_t diff --git a/tests/expectations/destructor_and_copy_ctor.cpp b/tests/expectations/destructor_and_copy_ctor.cpp index 005b0863e..03fd7f19f 100644 --- a/tests/expectations/destructor_and_copy_ctor.cpp +++ b/tests/expectations/destructor_and_copy_ctor.cpp @@ -8,6 +8,11 @@ #include #include +union Taz; +union Tazzz; +union Tazzzz; +union Qux; + enum class FillRule : uint8_t { A, B, @@ -331,6 +336,51 @@ union Baz { } }; +union Tazz { + enum class Tag : uint8_t { + Bar4, + Taz2, + }; + + struct Taz2_Body { + Tag tag; + int32_t _0; + }; + + struct { + Tag tag; + }; + Taz2_Body taz2; + + static Tazz Bar4() { + Tazz result; + result.tag = Tag::Bar4; + return result; + } + + bool IsBar4() const { + return tag == Tag::Bar4; + } + + static Tazz Taz2(const int32_t &_0) { + Tazz result; + ::new (&result.taz2._0) (int32_t)(_0); + result.tag = Tag::Taz2; + return result; + } + + bool IsTaz2() const { + return tag == Tag::Taz2; + } + + private: + Tazz() { + + } + public: + +}; + union Taz { enum class Tag : uint8_t { Bar3, @@ -418,51 +468,6 @@ union Taz { } }; -union Tazz { - enum class Tag : uint8_t { - Bar4, - Taz2, - }; - - struct Taz2_Body { - Tag tag; - int32_t _0; - }; - - struct { - Tag tag; - }; - Taz2_Body taz2; - - static Tazz Bar4() { - Tazz result; - result.tag = Tag::Bar4; - return result; - } - - bool IsBar4() const { - return tag == Tag::Bar4; - } - - static Tazz Taz2(const int32_t &_0) { - Tazz result; - ::new (&result.taz2._0) (int32_t)(_0); - result.tag = Tag::Taz2; - return result; - } - - bool IsTaz2() const { - return tag == Tag::Taz2; - } - - private: - Tazz() { - - } - public: - -}; - union Tazzz { enum class Tag : uint8_t { Bar5, diff --git a/tests/expectations/destructor_and_copy_ctor.pyx b/tests/expectations/destructor_and_copy_ctor.pyx index 745e04d45..b3da01461 100644 --- a/tests/expectations/destructor_and_copy_ctor.pyx +++ b/tests/expectations/destructor_and_copy_ctor.pyx @@ -15,6 +15,15 @@ cdef extern from *: B, ctypedef uint8_t FillRule; + cdef enum: + Bar4, + Taz2, + ctypedef uint8_t Tazz_Tag; + + ctypedef union Tazz: + Tazz_Tag tag; + int32_t taz2; + # This will have a destructor manually implemented via variant_body, and # similarly a Drop impl in Rust. ctypedef struct OwnedSlice_u32: @@ -98,15 +107,6 @@ cdef extern from *: int32_t taz1; OwnedSlice_i32 taz3; - cdef enum: - Bar4, - Taz2, - ctypedef uint8_t Tazz_Tag; - - ctypedef union Tazz: - Tazz_Tag tag; - int32_t taz2; - cdef enum: Bar5, Taz5, diff --git a/tests/expectations/destructor_and_copy_ctor_both.c b/tests/expectations/destructor_and_copy_ctor_both.c index 12910395b..102ca5980 100644 --- a/tests/expectations/destructor_and_copy_ctor_both.c +++ b/tests/expectations/destructor_and_copy_ctor_both.c @@ -7,12 +7,33 @@ #include #include +struct Foo_u32; +union Baz_i32; +union Taz; +union Tazzz; +union Tazzzz; +union Qux; + enum FillRule { A, B, }; typedef uint8_t FillRule; +enum Tazz_Tag { + Bar4, + Taz2, +}; +typedef uint8_t Tazz_Tag; + +typedef union Tazz { + Tazz_Tag tag; + struct { + Tazz_Tag taz2_tag; + int32_t taz2; + }; +} Tazz; + /** * This will have a destructor manually implemented via variant_body, and * similarly a Drop impl in Rust. @@ -137,20 +158,6 @@ typedef union Taz { }; } Taz; -enum Tazz_Tag { - Bar4, - Taz2, -}; -typedef uint8_t Tazz_Tag; - -typedef union Tazz { - Tazz_Tag tag; - struct { - Tazz_Tag taz2_tag; - int32_t taz2; - }; -} Tazz; - enum Tazzz_Tag { Bar5, Taz5, diff --git a/tests/expectations/destructor_and_copy_ctor_both.compat.c b/tests/expectations/destructor_and_copy_ctor_both.compat.c index d151c7d81..ee1660dec 100644 --- a/tests/expectations/destructor_and_copy_ctor_both.compat.c +++ b/tests/expectations/destructor_and_copy_ctor_both.compat.c @@ -7,6 +7,13 @@ #include #include +struct Foo_u32; +union Baz_i32; +union Taz; +union Tazzz; +union Tazzzz; +union Qux; + enum FillRule #ifdef __cplusplus : uint8_t @@ -19,6 +26,26 @@ enum FillRule typedef uint8_t FillRule; #endif // __cplusplus +enum Tazz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Bar4, + Taz2, +}; +#ifndef __cplusplus +typedef uint8_t Tazz_Tag; +#endif // __cplusplus + +typedef union Tazz { + Tazz_Tag tag; + struct { + Tazz_Tag taz2_tag; + int32_t taz2; + }; +} Tazz; + /** * This will have a destructor manually implemented via variant_body, and * similarly a Drop impl in Rust. @@ -161,26 +188,6 @@ typedef union Taz { }; } Taz; -enum Tazz_Tag -#ifdef __cplusplus - : uint8_t -#endif // __cplusplus - { - Bar4, - Taz2, -}; -#ifndef __cplusplus -typedef uint8_t Tazz_Tag; -#endif // __cplusplus - -typedef union Tazz { - Tazz_Tag tag; - struct { - Tazz_Tag taz2_tag; - int32_t taz2; - }; -} Tazz; - enum Tazzz_Tag #ifdef __cplusplus : uint8_t diff --git a/tests/expectations/destructor_and_copy_ctor_tag.c b/tests/expectations/destructor_and_copy_ctor_tag.c index 537ec6f73..aefb0df96 100644 --- a/tests/expectations/destructor_and_copy_ctor_tag.c +++ b/tests/expectations/destructor_and_copy_ctor_tag.c @@ -7,12 +7,33 @@ #include #include +struct Foo_u32; +union Baz_i32; +union Taz; +union Tazzz; +union Tazzzz; +union Qux; + enum FillRule { A, B, }; typedef uint8_t FillRule; +enum Tazz_Tag { + Bar4, + Taz2, +}; +typedef uint8_t Tazz_Tag; + +union Tazz { + Tazz_Tag tag; + struct { + Tazz_Tag taz2_tag; + int32_t taz2; + }; +}; + /** * This will have a destructor manually implemented via variant_body, and * similarly a Drop impl in Rust. @@ -137,20 +158,6 @@ union Taz { }; }; -enum Tazz_Tag { - Bar4, - Taz2, -}; -typedef uint8_t Tazz_Tag; - -union Tazz { - Tazz_Tag tag; - struct { - Tazz_Tag taz2_tag; - int32_t taz2; - }; -}; - enum Tazzz_Tag { Bar5, Taz5, diff --git a/tests/expectations/destructor_and_copy_ctor_tag.compat.c b/tests/expectations/destructor_and_copy_ctor_tag.compat.c index e6233263b..57723f9f4 100644 --- a/tests/expectations/destructor_and_copy_ctor_tag.compat.c +++ b/tests/expectations/destructor_and_copy_ctor_tag.compat.c @@ -7,6 +7,13 @@ #include #include +struct Foo_u32; +union Baz_i32; +union Taz; +union Tazzz; +union Tazzzz; +union Qux; + enum FillRule #ifdef __cplusplus : uint8_t @@ -19,6 +26,26 @@ enum FillRule typedef uint8_t FillRule; #endif // __cplusplus +enum Tazz_Tag +#ifdef __cplusplus + : uint8_t +#endif // __cplusplus + { + Bar4, + Taz2, +}; +#ifndef __cplusplus +typedef uint8_t Tazz_Tag; +#endif // __cplusplus + +union Tazz { + Tazz_Tag tag; + struct { + Tazz_Tag taz2_tag; + int32_t taz2; + }; +}; + /** * This will have a destructor manually implemented via variant_body, and * similarly a Drop impl in Rust. @@ -161,26 +188,6 @@ union Taz { }; }; -enum Tazz_Tag -#ifdef __cplusplus - : uint8_t -#endif // __cplusplus - { - Bar4, - Taz2, -}; -#ifndef __cplusplus -typedef uint8_t Tazz_Tag; -#endif // __cplusplus - -union Tazz { - Tazz_Tag tag; - struct { - Tazz_Tag taz2_tag; - int32_t taz2; - }; -}; - enum Tazzz_Tag #ifdef __cplusplus : uint8_t diff --git a/tests/expectations/destructor_and_copy_ctor_tag.pyx b/tests/expectations/destructor_and_copy_ctor_tag.pyx index 49619ebf2..a201385d6 100644 --- a/tests/expectations/destructor_and_copy_ctor_tag.pyx +++ b/tests/expectations/destructor_and_copy_ctor_tag.pyx @@ -15,6 +15,15 @@ cdef extern from *: B, ctypedef uint8_t FillRule; + cdef enum: + Bar4, + Taz2, + ctypedef uint8_t Tazz_Tag; + + cdef union Tazz: + Tazz_Tag tag; + int32_t taz2; + # This will have a destructor manually implemented via variant_body, and # similarly a Drop impl in Rust. cdef struct OwnedSlice_u32: @@ -98,15 +107,6 @@ cdef extern from *: int32_t taz1; OwnedSlice_i32 taz3; - cdef enum: - Bar4, - Taz2, - ctypedef uint8_t Tazz_Tag; - - cdef union Tazz: - Tazz_Tag tag; - int32_t taz2; - cdef enum: Bar5, Taz5, diff --git a/tests/expectations/enum.cpp b/tests/expectations/enum.cpp index 66d9209bf..72cdee3c1 100644 --- a/tests/expectations/enum.cpp +++ b/tests/expectations/enum.cpp @@ -18,6 +18,8 @@ using Box = T*; #include #include +struct Opaque; + enum class A : uint64_t { a1 = 0, a2 = 2, @@ -91,8 +93,6 @@ struct J; struct K; -struct Opaque; - union G { enum class Tag : uint8_t { Foo, diff --git a/tests/expectations/enum_both.c b/tests/expectations/enum_both.c index a0f88c13e..58a310283 100644 --- a/tests/expectations/enum_both.c +++ b/tests/expectations/enum_both.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct Opaque; + enum A { a1 = 0, a2 = 2, @@ -98,8 +100,6 @@ typedef struct J J; typedef struct K K; -typedef struct Opaque Opaque; - enum G_Tag { Foo, Bar, diff --git a/tests/expectations/enum_both.compat.c b/tests/expectations/enum_both.compat.c index 35488252b..fc46bc8c2 100644 --- a/tests/expectations/enum_both.compat.c +++ b/tests/expectations/enum_both.compat.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct Opaque; + enum A #ifdef __cplusplus : uint64_t @@ -146,8 +148,6 @@ typedef struct J J; typedef struct K K; -typedef struct Opaque Opaque; - enum G_Tag #ifdef __cplusplus : uint8_t diff --git a/tests/expectations/enum_tag.c b/tests/expectations/enum_tag.c index a7f104688..058752f4b 100644 --- a/tests/expectations/enum_tag.c +++ b/tests/expectations/enum_tag.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct Opaque; + enum A { a1 = 0, a2 = 2, @@ -98,8 +100,6 @@ struct J; struct K; -struct Opaque; - enum G_Tag { Foo, Bar, diff --git a/tests/expectations/enum_tag.compat.c b/tests/expectations/enum_tag.compat.c index 9662a6529..90f1bc4bd 100644 --- a/tests/expectations/enum_tag.compat.c +++ b/tests/expectations/enum_tag.compat.c @@ -17,6 +17,8 @@ using Box = T*; #include #include +struct Opaque; + enum A #ifdef __cplusplus : uint64_t @@ -146,8 +148,6 @@ struct J; struct K; -struct Opaque; - enum G_Tag #ifdef __cplusplus : uint8_t diff --git a/tests/expectations/expand_dep.cpp b/tests/expectations/expand_dep.cpp index 1190c297b..a1446c8c8 100644 --- a/tests/expectations/expand_dep.cpp +++ b/tests/expectations/expand_dep.cpp @@ -4,6 +4,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_both.c b/tests/expectations/expand_dep_both.c index 9a91a4fe4..9613d2e6b 100644 --- a/tests/expectations/expand_dep_both.c +++ b/tests/expectations/expand_dep_both.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + typedef struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_both.compat.c b/tests/expectations/expand_dep_both.compat.c index 9b6c2e3c2..07cc7e6d1 100644 --- a/tests/expectations/expand_dep_both.compat.c +++ b/tests/expectations/expand_dep_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + typedef struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_tag.c b/tests/expectations/expand_dep_tag.c index 45fcba665..319107c86 100644 --- a/tests/expectations/expand_dep_tag.c +++ b/tests/expectations/expand_dep_tag.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_tag.compat.c b/tests/expectations/expand_dep_tag.compat.c index 51aee8fcd..081fe059e 100644 --- a/tests/expectations/expand_dep_tag.compat.c +++ b/tests/expectations/expand_dep_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_v2.cpp b/tests/expectations/expand_dep_v2.cpp index 1190c297b..a1446c8c8 100644 --- a/tests/expectations/expand_dep_v2.cpp +++ b/tests/expectations/expand_dep_v2.cpp @@ -4,6 +4,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_v2_both.c b/tests/expectations/expand_dep_v2_both.c index 9a91a4fe4..9613d2e6b 100644 --- a/tests/expectations/expand_dep_v2_both.c +++ b/tests/expectations/expand_dep_v2_both.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + typedef struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_v2_both.compat.c b/tests/expectations/expand_dep_v2_both.compat.c index 9b6c2e3c2..07cc7e6d1 100644 --- a/tests/expectations/expand_dep_v2_both.compat.c +++ b/tests/expectations/expand_dep_v2_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + typedef struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_v2_tag.c b/tests/expectations/expand_dep_v2_tag.c index 45fcba665..319107c86 100644 --- a/tests/expectations/expand_dep_v2_tag.c +++ b/tests/expectations/expand_dep_v2_tag.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/expand_dep_v2_tag.compat.c b/tests/expectations/expand_dep_v2_tag.compat.c index 51aee8fcd..081fe059e 100644 --- a/tests/expectations/expand_dep_v2_tag.compat.c +++ b/tests/expectations/expand_dep_v2_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct dep_struct; + struct dep_struct { uint32_t x; double y; diff --git a/tests/expectations/manuallydrop.c b/tests/expectations/manuallydrop.c index 869dea727..5ad34ae3e 100644 --- a/tests/expectations/manuallydrop.c +++ b/tests/expectations/manuallydrop.c @@ -19,13 +19,13 @@ using ManuallyDrop = T; typedef struct NotReprC_Point NotReprC_Point; -typedef NotReprC_Point Foo; - typedef struct { int32_t x; int32_t y; } Point; +typedef NotReprC_Point Foo; + typedef struct { Point point; } MyStruct; diff --git a/tests/expectations/manuallydrop.compat.c b/tests/expectations/manuallydrop.compat.c index b8bdf43ed..1fc16d9ca 100644 --- a/tests/expectations/manuallydrop.compat.c +++ b/tests/expectations/manuallydrop.compat.c @@ -19,13 +19,13 @@ using ManuallyDrop = T; typedef struct NotReprC_Point NotReprC_Point; -typedef NotReprC_Point Foo; - typedef struct { int32_t x; int32_t y; } Point; +typedef NotReprC_Point Foo; + typedef struct { Point point; } MyStruct; diff --git a/tests/expectations/manuallydrop.cpp b/tests/expectations/manuallydrop.cpp index df517dcba..17674945f 100644 --- a/tests/expectations/manuallydrop.cpp +++ b/tests/expectations/manuallydrop.cpp @@ -18,6 +18,8 @@ using ManuallyDrop = T; #include #include +struct MyStruct; + template struct NotReprC; diff --git a/tests/expectations/manuallydrop.pyx b/tests/expectations/manuallydrop.pyx index 370d0df8a..ac8294e58 100644 --- a/tests/expectations/manuallydrop.pyx +++ b/tests/expectations/manuallydrop.pyx @@ -23,12 +23,12 @@ cdef extern from *: ctypedef struct NotReprC_Point: pass - ctypedef NotReprC_Point Foo; - ctypedef struct Point: int32_t x; int32_t y; + ctypedef NotReprC_Point Foo; + ctypedef struct MyStruct: Point point; diff --git a/tests/expectations/manuallydrop_both.c b/tests/expectations/manuallydrop_both.c index 255f4f520..73cca975b 100644 --- a/tests/expectations/manuallydrop_both.c +++ b/tests/expectations/manuallydrop_both.c @@ -17,15 +17,17 @@ using ManuallyDrop = T; #include #include -typedef struct NotReprC_Point NotReprC_Point; +struct MyStruct; -typedef struct NotReprC_Point Foo; +typedef struct NotReprC_Point NotReprC_Point; typedef struct Point { int32_t x; int32_t y; } Point; +typedef struct NotReprC_Point Foo; + typedef struct MyStruct { struct Point point; } MyStruct; diff --git a/tests/expectations/manuallydrop_both.compat.c b/tests/expectations/manuallydrop_both.compat.c index 1975e2684..a8c208944 100644 --- a/tests/expectations/manuallydrop_both.compat.c +++ b/tests/expectations/manuallydrop_both.compat.c @@ -17,15 +17,17 @@ using ManuallyDrop = T; #include #include -typedef struct NotReprC_Point NotReprC_Point; +struct MyStruct; -typedef struct NotReprC_Point Foo; +typedef struct NotReprC_Point NotReprC_Point; typedef struct Point { int32_t x; int32_t y; } Point; +typedef struct NotReprC_Point Foo; + typedef struct MyStruct { struct Point point; } MyStruct; diff --git a/tests/expectations/manuallydrop_tag.c b/tests/expectations/manuallydrop_tag.c index 5d44aa216..b1b31dca4 100644 --- a/tests/expectations/manuallydrop_tag.c +++ b/tests/expectations/manuallydrop_tag.c @@ -17,15 +17,17 @@ using ManuallyDrop = T; #include #include -struct NotReprC_Point; +struct MyStruct; -typedef struct NotReprC_Point Foo; +struct NotReprC_Point; struct Point { int32_t x; int32_t y; }; +typedef struct NotReprC_Point Foo; + struct MyStruct { struct Point point; }; diff --git a/tests/expectations/manuallydrop_tag.compat.c b/tests/expectations/manuallydrop_tag.compat.c index 08d952c8b..80008e8cd 100644 --- a/tests/expectations/manuallydrop_tag.compat.c +++ b/tests/expectations/manuallydrop_tag.compat.c @@ -17,15 +17,17 @@ using ManuallyDrop = T; #include #include -struct NotReprC_Point; +struct MyStruct; -typedef struct NotReprC_Point Foo; +struct NotReprC_Point; struct Point { int32_t x; int32_t y; }; +typedef struct NotReprC_Point Foo; + struct MyStruct { struct Point point; }; diff --git a/tests/expectations/manuallydrop_tag.pyx b/tests/expectations/manuallydrop_tag.pyx index 388c3ef1f..dc843ef83 100644 --- a/tests/expectations/manuallydrop_tag.pyx +++ b/tests/expectations/manuallydrop_tag.pyx @@ -23,12 +23,12 @@ cdef extern from *: cdef struct NotReprC_Point: pass - ctypedef NotReprC_Point Foo; - cdef struct Point: int32_t x; int32_t y; + ctypedef NotReprC_Point Foo; + cdef struct MyStruct: Point point; diff --git a/tests/expectations/maybeuninit.cpp b/tests/expectations/maybeuninit.cpp index 638cdfd16..12bf0452a 100644 --- a/tests/expectations/maybeuninit.cpp +++ b/tests/expectations/maybeuninit.cpp @@ -18,6 +18,8 @@ using MaybeUninit = T; #include #include +struct MyStruct; + template struct NotReprC; diff --git a/tests/expectations/maybeuninit_both.c b/tests/expectations/maybeuninit_both.c index 850e3eb1c..70a2dcfeb 100644 --- a/tests/expectations/maybeuninit_both.c +++ b/tests/expectations/maybeuninit_both.c @@ -17,6 +17,8 @@ using MaybeUninit = T; #include #include +struct MyStruct; + typedef struct NotReprC______i32 NotReprC______i32; typedef struct NotReprC______i32 Foo; diff --git a/tests/expectations/maybeuninit_both.compat.c b/tests/expectations/maybeuninit_both.compat.c index 046822d6e..d3e9ac417 100644 --- a/tests/expectations/maybeuninit_both.compat.c +++ b/tests/expectations/maybeuninit_both.compat.c @@ -17,6 +17,8 @@ using MaybeUninit = T; #include #include +struct MyStruct; + typedef struct NotReprC______i32 NotReprC______i32; typedef struct NotReprC______i32 Foo; diff --git a/tests/expectations/maybeuninit_tag.c b/tests/expectations/maybeuninit_tag.c index a2f5a0845..bd764f1ea 100644 --- a/tests/expectations/maybeuninit_tag.c +++ b/tests/expectations/maybeuninit_tag.c @@ -17,6 +17,8 @@ using MaybeUninit = T; #include #include +struct MyStruct; + struct NotReprC______i32; typedef struct NotReprC______i32 Foo; diff --git a/tests/expectations/maybeuninit_tag.compat.c b/tests/expectations/maybeuninit_tag.compat.c index 8ec05f152..0d2b34acf 100644 --- a/tests/expectations/maybeuninit_tag.compat.c +++ b/tests/expectations/maybeuninit_tag.compat.c @@ -17,6 +17,8 @@ using MaybeUninit = T; #include #include +struct MyStruct; + struct NotReprC______i32; typedef struct NotReprC______i32 Foo; diff --git a/tests/expectations/mod_2015.cpp b/tests/expectations/mod_2015.cpp index 037aaa5f4..fa444d07b 100644 --- a/tests/expectations/mod_2015.cpp +++ b/tests/expectations/mod_2015.cpp @@ -4,6 +4,8 @@ #include #include +struct ExportMe; + constexpr static const uint8_t EXPORT_ME_TOO = 42; struct ExportMe { diff --git a/tests/expectations/mod_2015_both.c b/tests/expectations/mod_2015_both.c index a9c3d2d2d..a9ea1689d 100644 --- a/tests/expectations/mod_2015_both.c +++ b/tests/expectations/mod_2015_both.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 typedef struct ExportMe { diff --git a/tests/expectations/mod_2015_both.compat.c b/tests/expectations/mod_2015_both.compat.c index ffbb82968..dcff38862 100644 --- a/tests/expectations/mod_2015_both.compat.c +++ b/tests/expectations/mod_2015_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 typedef struct ExportMe { diff --git a/tests/expectations/mod_2015_tag.c b/tests/expectations/mod_2015_tag.c index 42233d4d9..187f20b4a 100644 --- a/tests/expectations/mod_2015_tag.c +++ b/tests/expectations/mod_2015_tag.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 struct ExportMe { diff --git a/tests/expectations/mod_2015_tag.compat.c b/tests/expectations/mod_2015_tag.compat.c index 4d459d6c8..2c773d3be 100644 --- a/tests/expectations/mod_2015_tag.compat.c +++ b/tests/expectations/mod_2015_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 struct ExportMe { diff --git a/tests/expectations/mod_2018.cpp b/tests/expectations/mod_2018.cpp index 13cd90fcc..e02227482 100644 --- a/tests/expectations/mod_2018.cpp +++ b/tests/expectations/mod_2018.cpp @@ -4,6 +4,9 @@ #include #include +struct ExportMe; +struct ExportMe2; + constexpr static const uint8_t EXPORT_ME_TOO = 42; struct ExportMe { diff --git a/tests/expectations/mod_2018_both.c b/tests/expectations/mod_2018_both.c index 8c48f8896..59118d8aa 100644 --- a/tests/expectations/mod_2018_both.c +++ b/tests/expectations/mod_2018_both.c @@ -3,6 +3,9 @@ #include #include +struct ExportMe; +struct ExportMe2; + #define EXPORT_ME_TOO 42 typedef struct ExportMe { diff --git a/tests/expectations/mod_2018_both.compat.c b/tests/expectations/mod_2018_both.compat.c index 620b4c3b3..50f13a875 100644 --- a/tests/expectations/mod_2018_both.compat.c +++ b/tests/expectations/mod_2018_both.compat.c @@ -3,6 +3,9 @@ #include #include +struct ExportMe; +struct ExportMe2; + #define EXPORT_ME_TOO 42 typedef struct ExportMe { diff --git a/tests/expectations/mod_2018_tag.c b/tests/expectations/mod_2018_tag.c index 70d9a22a3..b04900a8b 100644 --- a/tests/expectations/mod_2018_tag.c +++ b/tests/expectations/mod_2018_tag.c @@ -3,6 +3,9 @@ #include #include +struct ExportMe; +struct ExportMe2; + #define EXPORT_ME_TOO 42 struct ExportMe { diff --git a/tests/expectations/mod_2018_tag.compat.c b/tests/expectations/mod_2018_tag.compat.c index 6e167de24..4e3772c1a 100644 --- a/tests/expectations/mod_2018_tag.compat.c +++ b/tests/expectations/mod_2018_tag.compat.c @@ -3,6 +3,9 @@ #include #include +struct ExportMe; +struct ExportMe2; + #define EXPORT_ME_TOO 42 struct ExportMe { diff --git a/tests/expectations/mod_attr.cpp b/tests/expectations/mod_attr.cpp index a114c9547..b5e616413 100644 --- a/tests/expectations/mod_attr.cpp +++ b/tests/expectations/mod_attr.cpp @@ -10,6 +10,9 @@ DEF BAR = 0 #include #include +struct Foo; +struct Bar; + #if defined(FOO) constexpr static const int32_t FOO = 1; #endif diff --git a/tests/expectations/mod_attr_both.c b/tests/expectations/mod_attr_both.c index 5bedae05e..61ffd67ba 100644 --- a/tests/expectations/mod_attr_both.c +++ b/tests/expectations/mod_attr_both.c @@ -9,6 +9,9 @@ DEF BAR = 0 #include #include +struct Foo; +struct Bar; + #if defined(FOO) #define FOO 1 #endif diff --git a/tests/expectations/mod_attr_both.compat.c b/tests/expectations/mod_attr_both.compat.c index cc3a389c2..037b8ae2d 100644 --- a/tests/expectations/mod_attr_both.compat.c +++ b/tests/expectations/mod_attr_both.compat.c @@ -9,6 +9,9 @@ DEF BAR = 0 #include #include +struct Foo; +struct Bar; + #if defined(FOO) #define FOO 1 #endif diff --git a/tests/expectations/mod_attr_tag.c b/tests/expectations/mod_attr_tag.c index 0627aebed..fea2558f4 100644 --- a/tests/expectations/mod_attr_tag.c +++ b/tests/expectations/mod_attr_tag.c @@ -9,6 +9,9 @@ DEF BAR = 0 #include #include +struct Foo; +struct Bar; + #if defined(FOO) #define FOO 1 #endif diff --git a/tests/expectations/mod_attr_tag.compat.c b/tests/expectations/mod_attr_tag.compat.c index 6226db942..e103c5cf7 100644 --- a/tests/expectations/mod_attr_tag.compat.c +++ b/tests/expectations/mod_attr_tag.compat.c @@ -9,6 +9,9 @@ DEF BAR = 0 #include #include +struct Foo; +struct Bar; + #if defined(FOO) #define FOO 1 #endif diff --git a/tests/expectations/mod_path.cpp b/tests/expectations/mod_path.cpp index fdc338b4a..5467116c5 100644 --- a/tests/expectations/mod_path.cpp +++ b/tests/expectations/mod_path.cpp @@ -4,6 +4,8 @@ #include #include +struct ExportMe; + constexpr static const uint8_t EXPORT_ME_TOO = 42; struct ExportMe { diff --git a/tests/expectations/mod_path_both.c b/tests/expectations/mod_path_both.c index 387edf8e0..219535c72 100644 --- a/tests/expectations/mod_path_both.c +++ b/tests/expectations/mod_path_both.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 typedef struct ExportMe { diff --git a/tests/expectations/mod_path_both.compat.c b/tests/expectations/mod_path_both.compat.c index e4b41695d..05c45acac 100644 --- a/tests/expectations/mod_path_both.compat.c +++ b/tests/expectations/mod_path_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 typedef struct ExportMe { diff --git a/tests/expectations/mod_path_tag.c b/tests/expectations/mod_path_tag.c index 01a8d5915..ae97c2ea6 100644 --- a/tests/expectations/mod_path_tag.c +++ b/tests/expectations/mod_path_tag.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 struct ExportMe { diff --git a/tests/expectations/mod_path_tag.compat.c b/tests/expectations/mod_path_tag.compat.c index ce06f4a13..23f2363bd 100644 --- a/tests/expectations/mod_path_tag.compat.c +++ b/tests/expectations/mod_path_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct ExportMe; + #define EXPORT_ME_TOO 42 struct ExportMe { diff --git a/tests/expectations/monomorph_2_both.c b/tests/expectations/monomorph_2_both.c index b104c5841..02d50e6e9 100644 --- a/tests/expectations/monomorph_2_both.c +++ b/tests/expectations/monomorph_2_both.c @@ -3,9 +3,8 @@ #include #include -typedef struct A A; - -typedef struct B B; +struct A; +struct B; typedef struct List_A { struct A *members; diff --git a/tests/expectations/monomorph_2_both.compat.c b/tests/expectations/monomorph_2_both.compat.c index cb9fdd80b..f865fcc33 100644 --- a/tests/expectations/monomorph_2_both.compat.c +++ b/tests/expectations/monomorph_2_both.compat.c @@ -3,9 +3,8 @@ #include #include -typedef struct A A; - -typedef struct B B; +struct A; +struct B; typedef struct List_A { struct A *members; diff --git a/tests/expectations/monomorph_2_tag.c b/tests/expectations/monomorph_2_tag.c index e5a212a63..c4c0ecb21 100644 --- a/tests/expectations/monomorph_2_tag.c +++ b/tests/expectations/monomorph_2_tag.c @@ -4,7 +4,6 @@ #include struct A; - struct B; struct List_A { diff --git a/tests/expectations/monomorph_2_tag.compat.c b/tests/expectations/monomorph_2_tag.compat.c index 762994ccc..a8b904ca5 100644 --- a/tests/expectations/monomorph_2_tag.compat.c +++ b/tests/expectations/monomorph_2_tag.compat.c @@ -4,7 +4,6 @@ #include struct A; - struct B; struct List_A { diff --git a/tests/expectations/nonnull_attribute_both.c b/tests/expectations/nonnull_attribute_both.c index 2520f31c3..5dde358b0 100644 --- a/tests/expectations/nonnull_attribute_both.c +++ b/tests/expectations/nonnull_attribute_both.c @@ -10,7 +10,8 @@ #include #include -typedef struct Opaque Opaque; +struct Opaque; +struct Pointers_u64; typedef struct References { const struct Opaque *CBINDGEN_NONNULL a; diff --git a/tests/expectations/nonnull_attribute_both.compat.c b/tests/expectations/nonnull_attribute_both.compat.c index bc81c76fb..a9d49755a 100644 --- a/tests/expectations/nonnull_attribute_both.compat.c +++ b/tests/expectations/nonnull_attribute_both.compat.c @@ -10,7 +10,8 @@ #include #include -typedef struct Opaque Opaque; +struct Opaque; +struct Pointers_u64; typedef struct References { const struct Opaque *CBINDGEN_NONNULL a; diff --git a/tests/expectations/nonnull_attribute_tag.c b/tests/expectations/nonnull_attribute_tag.c index 21d1153b5..6e7ec5b6a 100644 --- a/tests/expectations/nonnull_attribute_tag.c +++ b/tests/expectations/nonnull_attribute_tag.c @@ -11,6 +11,7 @@ #include struct Opaque; +struct Pointers_u64; struct References { const struct Opaque *CBINDGEN_NONNULL a; diff --git a/tests/expectations/nonnull_attribute_tag.compat.c b/tests/expectations/nonnull_attribute_tag.compat.c index 61c119d2d..94a087316 100644 --- a/tests/expectations/nonnull_attribute_tag.compat.c +++ b/tests/expectations/nonnull_attribute_tag.compat.c @@ -11,6 +11,7 @@ #include struct Opaque; +struct Pointers_u64; struct References { const struct Opaque *CBINDGEN_NONNULL a; diff --git a/tests/expectations/nonnull_both.c b/tests/expectations/nonnull_both.c index c4048d30a..52f9eea7d 100644 --- a/tests/expectations/nonnull_both.c +++ b/tests/expectations/nonnull_both.c @@ -3,7 +3,8 @@ #include #include -typedef struct Opaque Opaque; +struct Foo_u64; +struct Opaque; typedef struct Foo_u64 { float *a; diff --git a/tests/expectations/nonnull_both.compat.c b/tests/expectations/nonnull_both.compat.c index f38bc4a32..73a3291e3 100644 --- a/tests/expectations/nonnull_both.compat.c +++ b/tests/expectations/nonnull_both.compat.c @@ -3,7 +3,8 @@ #include #include -typedef struct Opaque Opaque; +struct Foo_u64; +struct Opaque; typedef struct Foo_u64 { float *a; diff --git a/tests/expectations/nonnull_tag.c b/tests/expectations/nonnull_tag.c index 566bb3689..3acae12ec 100644 --- a/tests/expectations/nonnull_tag.c +++ b/tests/expectations/nonnull_tag.c @@ -3,6 +3,7 @@ #include #include +struct Foo_u64; struct Opaque; struct Foo_u64 { diff --git a/tests/expectations/nonnull_tag.compat.c b/tests/expectations/nonnull_tag.compat.c index e7b8dc65c..27e115da7 100644 --- a/tests/expectations/nonnull_tag.compat.c +++ b/tests/expectations/nonnull_tag.compat.c @@ -3,6 +3,7 @@ #include #include +struct Foo_u64; struct Opaque; struct Foo_u64 { diff --git a/tests/expectations/nonzero_both.c b/tests/expectations/nonzero_both.c index 6f47e7511..d077c0ef7 100644 --- a/tests/expectations/nonzero_both.c +++ b/tests/expectations/nonzero_both.c @@ -16,7 +16,7 @@ struct NonZeroI64; #include #include -typedef struct Option_i64 Option_i64; +struct Option_i64; typedef struct NonZeroAliases { uint8_t a; diff --git a/tests/expectations/nonzero_both.compat.c b/tests/expectations/nonzero_both.compat.c index ee8433e23..d5ae8ea44 100644 --- a/tests/expectations/nonzero_both.compat.c +++ b/tests/expectations/nonzero_both.compat.c @@ -16,7 +16,7 @@ struct NonZeroI64; #include #include -typedef struct Option_i64 Option_i64; +struct Option_i64; typedef struct NonZeroAliases { uint8_t a; diff --git a/tests/expectations/package_version.cpp b/tests/expectations/package_version.cpp index f8919d06b..229d337c1 100644 --- a/tests/expectations/package_version.cpp +++ b/tests/expectations/package_version.cpp @@ -6,6 +6,8 @@ #include #include +struct Foo; + struct Foo { uint64_t bar; }; diff --git a/tests/expectations/package_version_both.c b/tests/expectations/package_version_both.c index b09c9468c..dd6c5be25 100644 --- a/tests/expectations/package_version_both.c +++ b/tests/expectations/package_version_both.c @@ -5,6 +5,8 @@ #include #include +struct Foo; + typedef struct Foo { uint64_t bar; } Foo; diff --git a/tests/expectations/package_version_both.compat.c b/tests/expectations/package_version_both.compat.c index c1594453d..750cd5f5f 100644 --- a/tests/expectations/package_version_both.compat.c +++ b/tests/expectations/package_version_both.compat.c @@ -5,6 +5,8 @@ #include #include +struct Foo; + typedef struct Foo { uint64_t bar; } Foo; diff --git a/tests/expectations/package_version_tag.c b/tests/expectations/package_version_tag.c index b46eae6e6..dd5e8e22b 100644 --- a/tests/expectations/package_version_tag.c +++ b/tests/expectations/package_version_tag.c @@ -5,6 +5,8 @@ #include #include +struct Foo; + struct Foo { uint64_t bar; }; diff --git a/tests/expectations/package_version_tag.compat.c b/tests/expectations/package_version_tag.compat.c index 18909d835..9d2e3791f 100644 --- a/tests/expectations/package_version_tag.compat.c +++ b/tests/expectations/package_version_tag.compat.c @@ -5,6 +5,8 @@ #include #include +struct Foo; + struct Foo { uint64_t bar; }; diff --git a/tests/expectations/recursive_type_reference.cpp b/tests/expectations/recursive_type_reference.cpp new file mode 100644 index 000000000..ca58e94b5 --- /dev/null +++ b/tests/expectations/recursive_type_reference.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +struct B; + +struct A { + B *buf; + uintptr_t len; +}; + +struct B { + int32_t something; + A nested; +}; + +extern "C" { + +void root(const B *foo); + +} // extern "C" diff --git a/tests/expectations/recursive_type_reference_both.c b/tests/expectations/recursive_type_reference_both.c new file mode 100644 index 000000000..c88908ed0 --- /dev/null +++ b/tests/expectations/recursive_type_reference_both.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +struct B; + +typedef struct A { + struct B *buf; + uintptr_t len; +} A; + +typedef struct B { + int32_t something; + struct A nested; +} B; + +void root(const struct B *foo); diff --git a/tests/expectations/recursive_type_reference_both.compat.c b/tests/expectations/recursive_type_reference_both.compat.c new file mode 100644 index 000000000..1c1cce77b --- /dev/null +++ b/tests/expectations/recursive_type_reference_both.compat.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +struct B; + +typedef struct A { + struct B *buf; + uintptr_t len; +} A; + +typedef struct B { + int32_t something; + struct A nested; +} B; + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void root(const struct B *foo); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/recursive_type_reference_tag.c b/tests/expectations/recursive_type_reference_tag.c new file mode 100644 index 000000000..b7dad5c42 --- /dev/null +++ b/tests/expectations/recursive_type_reference_tag.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +struct B; + +struct A { + struct B *buf; + uintptr_t len; +}; + +struct B { + int32_t something; + struct A nested; +}; + +void root(const struct B *foo); diff --git a/tests/expectations/recursive_type_reference_tag.compat.c b/tests/expectations/recursive_type_reference_tag.compat.c new file mode 100644 index 000000000..dac8bef94 --- /dev/null +++ b/tests/expectations/recursive_type_reference_tag.compat.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +struct B; + +struct A { + struct B *buf; + uintptr_t len; +}; + +struct B { + int32_t something; + struct A nested; +}; + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void root(const struct B *foo); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/recursive_type_reference_tag.pyx b/tests/expectations/recursive_type_reference_tag.pyx new file mode 100644 index 000000000..db72c8a45 --- /dev/null +++ b/tests/expectations/recursive_type_reference_tag.pyx @@ -0,0 +1,17 @@ +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + cdef struct A: + B *buf; + uintptr_t len; + + cdef struct B: + int32_t something; + A nested; + + void root(const B *foo); diff --git a/tests/expectations/rename.cpp b/tests/expectations/rename.cpp index e27a6360d..ba935a1c4 100644 --- a/tests/expectations/rename.cpp +++ b/tests/expectations/rename.cpp @@ -4,6 +4,8 @@ #include #include +struct C_A; + constexpr static const int32_t C_H = 10; enum class C_E : uint8_t { @@ -11,8 +13,6 @@ enum class C_E : uint8_t { y = 1, }; -struct C_A; - struct C_C; struct C_AwesomeB { diff --git a/tests/expectations/rename_both.c b/tests/expectations/rename_both.c index 6c6e9a5ab..10cc68bb7 100644 --- a/tests/expectations/rename_both.c +++ b/tests/expectations/rename_both.c @@ -3,6 +3,8 @@ #include #include +struct C_A; + #define C_H 10 enum C_E { @@ -11,8 +13,6 @@ enum C_E { }; typedef uint8_t C_E; -typedef struct C_A C_A; - typedef struct C_C C_C; typedef struct C_AwesomeB { diff --git a/tests/expectations/rename_both.compat.c b/tests/expectations/rename_both.compat.c index 9361e68b1..c62803ffb 100644 --- a/tests/expectations/rename_both.compat.c +++ b/tests/expectations/rename_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct C_A; + #define C_H 10 enum C_E @@ -17,8 +19,6 @@ enum C_E typedef uint8_t C_E; #endif // __cplusplus -typedef struct C_A C_A; - typedef struct C_C C_C; typedef struct C_AwesomeB { diff --git a/tests/expectations/rename_tag.c b/tests/expectations/rename_tag.c index ca127187b..3fd4f4381 100644 --- a/tests/expectations/rename_tag.c +++ b/tests/expectations/rename_tag.c @@ -3,6 +3,8 @@ #include #include +struct C_A; + #define C_H 10 enum C_E { @@ -11,8 +13,6 @@ enum C_E { }; typedef uint8_t C_E; -struct C_A; - struct C_C; struct C_AwesomeB { diff --git a/tests/expectations/rename_tag.compat.c b/tests/expectations/rename_tag.compat.c index e952b49eb..39c56bad8 100644 --- a/tests/expectations/rename_tag.compat.c +++ b/tests/expectations/rename_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct C_A; + #define C_H 10 enum C_E @@ -17,8 +19,6 @@ enum C_E typedef uint8_t C_E; #endif // __cplusplus -struct C_A; - struct C_C; struct C_AwesomeB { diff --git a/tests/expectations/renaming_overrides_prefixing_both.c b/tests/expectations/renaming_overrides_prefixing_both.c index e112efa21..7a96c20ac 100644 --- a/tests/expectations/renaming_overrides_prefixing_both.c +++ b/tests/expectations/renaming_overrides_prefixing_both.c @@ -3,7 +3,7 @@ #include #include -typedef struct StyleA StyleA; +struct StyleA; typedef struct B { int32_t x; diff --git a/tests/expectations/renaming_overrides_prefixing_both.compat.c b/tests/expectations/renaming_overrides_prefixing_both.compat.c index d7dd5c518..abc251736 100644 --- a/tests/expectations/renaming_overrides_prefixing_both.compat.c +++ b/tests/expectations/renaming_overrides_prefixing_both.compat.c @@ -3,7 +3,7 @@ #include #include -typedef struct StyleA StyleA; +struct StyleA; typedef struct B { int32_t x; diff --git a/tests/expectations/simplify_option_ptr_both.c b/tests/expectations/simplify_option_ptr_both.c index 04f4656d2..a7baeaa8d 100644 --- a/tests/expectations/simplify_option_ptr_both.c +++ b/tests/expectations/simplify_option_ptr_both.c @@ -3,9 +3,8 @@ #include #include -typedef struct Opaque Opaque; - -typedef struct Option_____Opaque Option_____Opaque; +struct Opaque; +struct Option_____Opaque; typedef struct Foo { const struct Opaque *x; diff --git a/tests/expectations/simplify_option_ptr_both.compat.c b/tests/expectations/simplify_option_ptr_both.compat.c index 2f0fd0b2c..8d4faf835 100644 --- a/tests/expectations/simplify_option_ptr_both.compat.c +++ b/tests/expectations/simplify_option_ptr_both.compat.c @@ -3,9 +3,8 @@ #include #include -typedef struct Opaque Opaque; - -typedef struct Option_____Opaque Option_____Opaque; +struct Opaque; +struct Option_____Opaque; typedef struct Foo { const struct Opaque *x; diff --git a/tests/expectations/simplify_option_ptr_tag.c b/tests/expectations/simplify_option_ptr_tag.c index ad3389ef7..3ac577117 100644 --- a/tests/expectations/simplify_option_ptr_tag.c +++ b/tests/expectations/simplify_option_ptr_tag.c @@ -4,7 +4,6 @@ #include struct Opaque; - struct Option_____Opaque; struct Foo { diff --git a/tests/expectations/simplify_option_ptr_tag.compat.c b/tests/expectations/simplify_option_ptr_tag.compat.c index 10b9905a0..18155ee2f 100644 --- a/tests/expectations/simplify_option_ptr_tag.compat.c +++ b/tests/expectations/simplify_option_ptr_tag.compat.c @@ -4,7 +4,6 @@ #include struct Opaque; - struct Option_____Opaque; struct Foo { diff --git a/tests/expectations/std_lib_both.c b/tests/expectations/std_lib_both.c deleted file mode 100644 index c6f1164bc..000000000 --- a/tests/expectations/std_lib_both.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include -#include -#include - -typedef struct Option_i32 Option_i32; - -typedef struct Result_i32__String Result_i32__String; - -typedef struct Vec_String Vec_String; - -void root(const struct Vec_String *a, - const struct Option_i32 *b, - const struct Result_i32__String *c); diff --git a/tests/expectations/std_lib_both.compat.c b/tests/expectations/std_lib_both.compat.c deleted file mode 100644 index 53f9eadbb..000000000 --- a/tests/expectations/std_lib_both.compat.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include -#include - -typedef struct Option_i32 Option_i32; - -typedef struct Result_i32__String Result_i32__String; - -typedef struct Vec_String Vec_String; - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -void root(const struct Vec_String *a, - const struct Option_i32 *b, - const struct Result_i32__String *c); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus diff --git a/tests/expectations/std_lib_tag.c b/tests/expectations/std_lib_tag.c index f963ddf72..3c0498cbb 100644 --- a/tests/expectations/std_lib_tag.c +++ b/tests/expectations/std_lib_tag.c @@ -3,12 +3,10 @@ #include #include +struct Vec_String; struct Option_i32; - struct Result_i32__String; -struct Vec_String; - void root(const struct Vec_String *a, const struct Option_i32 *b, const struct Result_i32__String *c); diff --git a/tests/expectations/std_lib_tag.compat.c b/tests/expectations/std_lib_tag.compat.c index 74a8c14fc..8e7cfc58e 100644 --- a/tests/expectations/std_lib_tag.compat.c +++ b/tests/expectations/std_lib_tag.compat.c @@ -3,12 +3,10 @@ #include #include +struct Vec_String; struct Option_i32; - struct Result_i32__String; -struct Vec_String; - #ifdef __cplusplus extern "C" { #endif // __cplusplus diff --git a/tests/expectations/struct_both.c b/tests/expectations/struct_both.c index 5664185f9..35f489824 100644 --- a/tests/expectations/struct_both.c +++ b/tests/expectations/struct_both.c @@ -3,7 +3,7 @@ #include #include -typedef struct Opaque Opaque; +struct Opaque; typedef struct Normal { int32_t x; diff --git a/tests/expectations/struct_both.compat.c b/tests/expectations/struct_both.compat.c index ee0f4c761..6e3029af8 100644 --- a/tests/expectations/struct_both.compat.c +++ b/tests/expectations/struct_both.compat.c @@ -3,7 +3,7 @@ #include #include -typedef struct Opaque Opaque; +struct Opaque; typedef struct Normal { int32_t x; diff --git a/tests/expectations/swift_name.cpp b/tests/expectations/swift_name.cpp index 56d422c5a..83bdcf417 100644 --- a/tests/expectations/swift_name.cpp +++ b/tests/expectations/swift_name.cpp @@ -6,11 +6,12 @@ #include #include +struct SelfTypeTestStruct; +struct Opaque; + template struct Box; -struct Opaque; - struct SelfTypeTestStruct { uint8_t times; }; diff --git a/tests/expectations/swift_name_both.c b/tests/expectations/swift_name_both.c index 4911679fa..78bcb7150 100644 --- a/tests/expectations/swift_name_both.c +++ b/tests/expectations/swift_name_both.c @@ -5,7 +5,8 @@ #include #include -typedef struct Opaque Opaque; +struct SelfTypeTestStruct; +struct Opaque; typedef struct SelfTypeTestStruct { uint8_t times; diff --git a/tests/expectations/swift_name_both.compat.c b/tests/expectations/swift_name_both.compat.c index 592a8c7d5..0d71f10c7 100644 --- a/tests/expectations/swift_name_both.compat.c +++ b/tests/expectations/swift_name_both.compat.c @@ -5,7 +5,8 @@ #include #include -typedef struct Opaque Opaque; +struct SelfTypeTestStruct; +struct Opaque; typedef struct SelfTypeTestStruct { uint8_t times; diff --git a/tests/expectations/swift_name_tag.c b/tests/expectations/swift_name_tag.c index 370b88ae2..ddf661b52 100644 --- a/tests/expectations/swift_name_tag.c +++ b/tests/expectations/swift_name_tag.c @@ -5,6 +5,7 @@ #include #include +struct SelfTypeTestStruct; struct Opaque; struct SelfTypeTestStruct { diff --git a/tests/expectations/swift_name_tag.compat.c b/tests/expectations/swift_name_tag.compat.c index 89b1b2bd1..85f2e69a1 100644 --- a/tests/expectations/swift_name_tag.compat.c +++ b/tests/expectations/swift_name_tag.compat.c @@ -5,6 +5,7 @@ #include #include +struct SelfTypeTestStruct; struct Opaque; struct SelfTypeTestStruct { diff --git a/tests/expectations/transform_op.cpp b/tests/expectations/transform_op.cpp index 2d070ba48..c2f0a0a5b 100644 --- a/tests/expectations/transform_op.cpp +++ b/tests/expectations/transform_op.cpp @@ -5,6 +5,9 @@ #include #include +union StyleBaz; +struct StyleTaz; + template struct StylePoint { T x; diff --git a/tests/expectations/transform_op_both.c b/tests/expectations/transform_op_both.c index e9605c39a..0e456c13d 100644 --- a/tests/expectations/transform_op_both.c +++ b/tests/expectations/transform_op_both.c @@ -3,6 +3,11 @@ #include #include +union StyleFoo_i32; +struct StyleBar_i32; +union StyleBaz; +struct StyleTaz; + typedef struct StylePoint_i32 { int32_t x; int32_t y; diff --git a/tests/expectations/transform_op_both.compat.c b/tests/expectations/transform_op_both.compat.c index d4ab94d3b..fb2005171 100644 --- a/tests/expectations/transform_op_both.compat.c +++ b/tests/expectations/transform_op_both.compat.c @@ -3,6 +3,11 @@ #include #include +union StyleFoo_i32; +struct StyleBar_i32; +union StyleBaz; +struct StyleTaz; + typedef struct StylePoint_i32 { int32_t x; int32_t y; diff --git a/tests/expectations/transform_op_tag.c b/tests/expectations/transform_op_tag.c index a97d4ae34..0f538c8e1 100644 --- a/tests/expectations/transform_op_tag.c +++ b/tests/expectations/transform_op_tag.c @@ -3,6 +3,11 @@ #include #include +union StyleFoo_i32; +struct StyleBar_i32; +union StyleBaz; +struct StyleTaz; + struct StylePoint_i32 { int32_t x; int32_t y; diff --git a/tests/expectations/transform_op_tag.compat.c b/tests/expectations/transform_op_tag.compat.c index 3e6c48d8c..45660073b 100644 --- a/tests/expectations/transform_op_tag.compat.c +++ b/tests/expectations/transform_op_tag.compat.c @@ -3,6 +3,11 @@ #include #include +union StyleFoo_i32; +struct StyleBar_i32; +union StyleBaz; +struct StyleTaz; + struct StylePoint_i32 { int32_t x; int32_t y; diff --git a/tests/expectations/union_both.c b/tests/expectations/union_both.c index acef11da5..7bf71b9ad 100644 --- a/tests/expectations/union_both.c +++ b/tests/expectations/union_both.c @@ -3,7 +3,7 @@ #include #include -typedef struct Opaque Opaque; +struct Opaque; typedef union Normal { int32_t x; diff --git a/tests/expectations/union_both.compat.c b/tests/expectations/union_both.compat.c index 31f0a5396..f9aff1f81 100644 --- a/tests/expectations/union_both.compat.c +++ b/tests/expectations/union_both.compat.c @@ -3,7 +3,7 @@ #include #include -typedef struct Opaque Opaque; +struct Opaque; typedef union Normal { int32_t x; diff --git a/tests/expectations/unsafe_cell.cpp b/tests/expectations/unsafe_cell.cpp index d0ae403cb..74dac218c 100644 --- a/tests/expectations/unsafe_cell.cpp +++ b/tests/expectations/unsafe_cell.cpp @@ -4,6 +4,8 @@ #include #include +struct MyStruct; + template struct NotReprC; diff --git a/tests/expectations/unsafe_cell_both.c b/tests/expectations/unsafe_cell_both.c index 61d7ce8a9..aeae8909b 100644 --- a/tests/expectations/unsafe_cell_both.c +++ b/tests/expectations/unsafe_cell_both.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + typedef struct NotReprC_i32 NotReprC_i32; typedef struct NotReprC_i32 Foo; diff --git a/tests/expectations/unsafe_cell_both.compat.c b/tests/expectations/unsafe_cell_both.compat.c index 0f9cd51d6..940d07d35 100644 --- a/tests/expectations/unsafe_cell_both.compat.c +++ b/tests/expectations/unsafe_cell_both.compat.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + typedef struct NotReprC_i32 NotReprC_i32; typedef struct NotReprC_i32 Foo; diff --git a/tests/expectations/unsafe_cell_tag.c b/tests/expectations/unsafe_cell_tag.c index 61c69e774..8bcc5c85a 100644 --- a/tests/expectations/unsafe_cell_tag.c +++ b/tests/expectations/unsafe_cell_tag.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + struct NotReprC_i32; typedef struct NotReprC_i32 Foo; diff --git a/tests/expectations/unsafe_cell_tag.compat.c b/tests/expectations/unsafe_cell_tag.compat.c index e69b5f610..0654e0392 100644 --- a/tests/expectations/unsafe_cell_tag.compat.c +++ b/tests/expectations/unsafe_cell_tag.compat.c @@ -3,6 +3,8 @@ #include #include +struct MyStruct; + struct NotReprC_i32; typedef struct NotReprC_i32 Foo; diff --git a/tests/rust/recursive_type_reference.rs b/tests/rust/recursive_type_reference.rs new file mode 100644 index 000000000..b18bc2e27 --- /dev/null +++ b/tests/rust/recursive_type_reference.rs @@ -0,0 +1,14 @@ +#[repr(C)] +struct A { + buf: *mut B, + len: usize, +} + +#[repr(C)] +struct B { + something: i32, + nested: A, +} + +#[no_mangle] +pub extern "C" fn root(foo: &B) {} diff --git a/tests/tests.rs b/tests/tests.rs index eebabefbe..fe7f21956 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -328,11 +328,16 @@ fn test_file(name: &'static str, filename: &'static str) { .tempdir() .expect("Creating tmp dir failed"); let tmp_dir = tmp_dir.path(); + let recursive = test.file_name().unwrap().to_str().unwrap().starts_with("recursive_"); // Run tests in deduplication priority order. C++ compatibility tests are run first, // otherwise we would lose the C++ compiler run if they were deduplicated. let mut cbindgen_outputs = HashSet::new(); for cpp_compat in &[true, false] { for style in &[Style::Type, Style::Tag, Style::Both] { + if recursive && matches!(style, Style::Type) { + // Test cases for recursive type references do not work with `Style::Type`. + continue; + } run_compile_test( name, test, @@ -360,6 +365,10 @@ fn test_file(name: &'static str, filename: &'static str) { // `Style::Both` should be identical to `Style::Tag` for Cython. let mut cbindgen_outputs = HashSet::new(); for style in &[Style::Type, Style::Tag] { + if recursive && matches!(style, Style::Type) { + // Test cases for recursive type references do not work with `Style::Type`. + continue; + } run_compile_test( name, test,