diff --git a/crates/header-translator/src/cache.rs b/crates/header-translator/src/cache.rs index ed553b897..25c8aba8a 100644 --- a/crates/header-translator/src/cache.rs +++ b/crates/header-translator/src/cache.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::mem; use tracing::{debug_span, warn}; @@ -182,6 +183,27 @@ impl Cache { } } file.stmts.extend(new_stmts); + + // Fix up a few typedef + enum declarations + let mut iter = mem::take(&mut file.stmts).into_iter().peekable(); + while let Some(stmt) = iter.next() { + if let Stmt::AliasDecl { name, ty } = &stmt { + if let Some(Stmt::EnumDecl { + name: enum_name, + ty: enum_ty, + .. + }) = iter.peek_mut() + { + if enum_ty.is_typedef_to(&name) { + *enum_name = Some(name.clone()); + *enum_ty = ty.clone(); + // Skip adding the now-redundant alias to the list of statements + continue; + } + } + } + file.stmts.push(stmt); + } } fn update_methods(&self, methods: &mut [Method], self_means: &str) { diff --git a/crates/header-translator/src/rust_type.rs b/crates/header-translator/src/rust_type.rs index 4a6b78444..0ac4f1a2f 100644 --- a/crates/header-translator/src/rust_type.rs +++ b/crates/header-translator/src/rust_type.rs @@ -1095,6 +1095,10 @@ impl Ty { } if ty.name == "Self" && ty.generics.is_empty()) } + pub fn is_typedef_to(&self, s: &str) -> bool { + matches!(&self.ty, RustType::TypeDef { name } if name == s) + } + /// Related result types /// pub fn fix_related_result_type(&mut self, is_class: bool, selector: &str) { diff --git a/crates/icrate/src/Foundation/translation-config.toml b/crates/icrate/src/Foundation/translation-config.toml index 01b426423..77f4a7ca1 100644 --- a/crates/icrate/src/Foundation/translation-config.toml +++ b/crates/icrate/src/Foundation/translation-config.toml @@ -198,6 +198,10 @@ skipped = true [class.NSUserNotification.methods.setContentImage] skipped = true +# Outlier that really should have been part of the original enum +[enum.anonymous.constants.NSProprietaryStringEncoding] +skipped = true + # Has the wrong generic parameter [class.NSDictionary.methods] initWithContentsOfURL_error = { skipped = true } diff --git a/crates/icrate/src/generated b/crates/icrate/src/generated index defdca9ee..e2ca9a29a 160000 --- a/crates/icrate/src/generated +++ b/crates/icrate/src/generated @@ -1 +1 @@ -Subproject commit defdca9eec07abf45521a102e06ca789c722efb9 +Subproject commit e2ca9a29a02c1618ec48768c92bfc76f008c5f3d