Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underscores in inner types #552

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions engine/src/conversion/analysis/name_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
error_reporter::convert_item_apis,
ConvertError,
},
types::{validate_ident_ok_for_rust, QualifiedName},
types::{validate_ident_ok_for_cxx, QualifiedName},
};

use super::fun::FnAnalysis;
Expand All @@ -37,15 +37,11 @@ pub(crate) fn check_names(apis: Vec<Api<FnAnalysis>>) -> Vec<Api<FnAnalysis>> {
| ApiDetail::Const { .. }
| ApiDetail::Enum { .. }
| ApiDetail::Struct { .. } => {
let cxx_name = api
.cpp_name
.as_ref()
.map(|s|
QualifiedName::new_from_cpp_name(&s)
)
.unwrap_or_else(|| api.name.clone());
for seg in cxx_name.segment_iter() {
validate_ident_ok_for_rust(&seg)?;
validate_all_segments_ok_for_cxx(api.name.segment_iter())?;
if let Some(ref cpp_name) = api.cpp_name {
// The C++ name might itself be outer_type::inner_type and thus may
// have multiple segments.
validate_all_segments_ok_for_cxx(QualifiedName::new_from_cpp_name(cpp_name).segment_iter())?;
}
Ok(Some(api))
}
Expand Down Expand Up @@ -85,6 +81,15 @@ pub(crate) fn check_names(apis: Vec<Api<FnAnalysis>>) -> Vec<Api<FnAnalysis>> {
results
}

fn validate_all_segments_ok_for_cxx(
items: impl Iterator<Item = String>,
) -> Result<(), ConvertError> {
for seg in items {
validate_ident_ok_for_cxx(&seg)?;
}
Ok(())
}

fn cxxbridge_name(api: &Api<FnAnalysis>) -> Option<Ident> {
match api.detail {
ApiDetail::Function { ref analysis, .. } => Some(analysis.cxxbridge_name.clone()),
Expand Down
17 changes: 17 additions & 0 deletions engine/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5213,6 +5213,23 @@ fn test_closure() {
run_test("", hdr, rs, &["get_a"], &[]);
}

#[test]
fn test_underscored_namespace_for_inner_type() {
let hdr = indoc! {"
namespace __foo {
struct daft {
struct bob {
int a;
};
int a;
};
}
inline void bar(__foo::daft::bob) {}
"};
let rs = quote! {};
run_test("", hdr, rs, &["bar"], &[]);
}

#[test]
fn test_blocklist_not_overly_broad() {
// This is a regression test. We used to block anything that starts with "rust" or "std",
Expand Down