Skip to content

Commit

Permalink
Merge pull request #992 from google/abstract-detection-prob
Browse files Browse the repository at this point in the history
Fix problem with methods beginning with their class name
  • Loading branch information
adetaylor authored Apr 2, 2022
2 parents bdfd45e + 6d36e79 commit 0bde8f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 16 additions & 1 deletion engine/src/conversion/analysis/fun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ impl<'a> FnAnalyzer<'a> {
params = params.into_iter().skip(1).collect();
param_details.remove(0);
MethodKind::MakeUnique
} else if let Some(constructor_suffix) = rust_name.strip_prefix(nested_type_ident) {
} else if let Some(constructor_suffix) =
constructor_with_suffix(&rust_name, nested_type_ident)
{
// It's a constructor. bindgen generates
// fn Type(this: *mut Type, ...args)
// We want
Expand Down Expand Up @@ -1968,6 +1970,19 @@ impl<'a> FnAnalyzer<'a> {
}
}

/// Attempts to determine whether this function name is a constructor, and if so,
/// returns the suffix.
fn constructor_with_suffix<'a>(rust_name: &'a str, nested_type_ident: &str) -> Option<&'a str> {
let suffix = rust_name.strip_prefix(nested_type_ident);
suffix.and_then(|suffix| {
if suffix.is_empty() || suffix.parse::<u32>().is_ok() {
Some(suffix)
} else {
None
}
})
}

fn error_context_for_method(self_ty: &QualifiedName, rust_name: &str) -> ErrorContext {
ErrorContext::new_for_method(self_ty.get_final_ident(), make_ident(rust_name))
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/conversion/convert_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub enum ConvertError {
MethodOfNonAllowlistedType,
#[error("This type is templated, so we can't generate bindings. We will instead generate bindings for each instantiation.")]
MethodOfGenericType,
#[error("bindgen generated multiple different APIs (functions/types) with this name. autocxx doesn't know how to diambiguate them, so we won't generate bindings for any of them.")]
#[error("bindgen generated multiple different APIs (functions/types) with this name. autocxx doesn't know how to disambiguate them, so we won't generate bindings for any of them.")]
DuplicateItemsFoundInParsing,
#[error(
"bindgen generated a move or copy constructor with an unexpected number of parameters."
Expand Down
11 changes: 11 additions & 0 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8703,6 +8703,17 @@ fn test_abstract_private() {
run_test("", hdr, rs, &["A"], &[]);
}

#[test]
fn test_abstract_issue_979() {
let hdr = indoc! {"
class Test {
virtual void TestBody() = 0;
};
"};
let rs = quote! {};
run_test("", hdr, rs, &["Test"], &[]);
}

#[test]
fn test_class_having_protected_method() {
let hdr = indoc! {"
Expand Down

0 comments on commit 0bde8f9

Please sign in to comment.