Skip to content

Commit

Permalink
Store unwrapped function names in cppname.
Browse files Browse the repository at this point in the history
This is a bit of an experiment.
adetaylor committed Apr 14, 2023
1 parent 78fffd1 commit c12b97c
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions engine/src/conversion/analysis/fun/mod.rs
Original file line number Diff line number Diff line change
@@ -728,7 +728,7 @@ impl<'a> FnAnalyzer<'a> {
// and it would be nice to have some idea of the function name
// for diagnostics whilst we do that.
let initial_rust_name = fun.ident.to_string();
let diagnostic_display_name = cpp_name.as_ref().unwrap_or(&initial_rust_name);
let diagnostic_display_name = cpp_name.as_ref().unwrap_or(&initial_rust_name).clone();

// Now let's analyze all the parameters.
// See if any have annotations which our fork of bindgen has craftily inserted...
@@ -739,7 +739,7 @@ impl<'a> FnAnalyzer<'a> {
self.convert_fn_arg(
i,
ns,
diagnostic_display_name,
&diagnostic_display_name,
&fun.synthesized_this_type,
&fun.references,
true,
@@ -1310,6 +1310,9 @@ impl<'a> FnAnalyzer<'a> {
self.config
.uniquify_name_per_mod(&format!("{cxxbridge_name}{joiner}autocxx_wrapper")),
);
// Retain a memory of the original C++ name so that we can compare
// against allowlists etc. later.
cpp_name = Some(diagnostic_display_name.clone());
let (payload, cpp_function_kind) = match fun.synthetic_cpp.as_ref().cloned() {
Some((payload, cpp_function_kind)) => (payload, cpp_function_kind),
None => match kind {
8 changes: 7 additions & 1 deletion engine/src/conversion/codegen_cpp/type_to_cpp.rs
Original file line number Diff line number Diff line change
@@ -19,8 +19,14 @@ use syn::{Token, Type};
/// Map from QualifiedName to original C++ name. Original C++ name does not
/// include the namespace; this can be assumed to be the same as the namespace
/// in the QualifiedName.
///
/// This is a temporary hash table which can be built from the information
/// stored in any [`ApiVec`].
///
/// The "original C++ name" is mostly relevant in the case of nested types,
/// where the typename might be A::B within a namespace C::D.
/// where the typename might be A::B within a namespace C::D. We also store
/// the original name in here for functions where we've generated a wrapper
/// function, so we can compare the name against the original allowlist.
pub(crate) struct CppNameMap(HashMap<QualifiedName, String>);

impl CppNameMap {
4 changes: 2 additions & 2 deletions engine/src/conversion/mod.rs
Original file line number Diff line number Diff line change
@@ -238,14 +238,14 @@ impl<'a> BridgeConverter<'a> {
let fail_api_reasons: HashMap<_, _> = apis
.iter()
.filter_map(|api| match api {
Api::IgnoredItem { err, .. } => Some((api.name().to_cpp_name(), err.clone())),
Api::IgnoredItem { err, .. } => Some((api.effective_cpp_name().to_string(), err.clone())),
_ => None,
})
.collect();
let successful_api_names: HashSet<_> = apis
.iter()
.filter(|api| !matches!(api, Api::IgnoredItem { .. }))
.map(|api| api.name().to_cpp_name())
.map(|api| api.effective_cpp_name().to_string())
.collect();
for generate_directive in self.config.must_generate_list() {
// Try to give a specific error message if we can.

0 comments on commit c12b97c

Please sign in to comment.