Skip to content

Commit

Permalink
Validate namespace path elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
adetaylor committed Jun 2, 2021
1 parent 30ac0fb commit a069fdc
Showing 1 changed file with 15 additions and 10 deletions.
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

0 comments on commit a069fdc

Please sign in to comment.