Skip to content

Commit

Permalink
Fix a few enums
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Dec 23, 2022
1 parent 457164f commit e03db13
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
22 changes: 22 additions & 0 deletions crates/header-translator/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
use std::mem;

use tracing::{debug_span, warn};

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions crates/header-translator/src/rust_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#related-result-types>
pub fn fix_related_result_type(&mut self, is_class: bool, selector: &str) {
Expand Down
4 changes: 4 additions & 0 deletions crates/icrate/src/Foundation/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion crates/icrate/src/generated

0 comments on commit e03db13

Please sign in to comment.