1use crate::syntax::check::Check; 2use crate::syntax::{error, Api, Pair}; 3 4fn check(cx: &mut Check, name: &Pair) { 5 for segment in &name.namespace { 6 check_cxx_ident(cx, &segment.to_string()); 7 } 8 check_cxx_ident(cx, &name.cxx.to_string()); 9 check_rust_ident(cx, &name.rust.to_string()); 10 11 fn check_cxx_ident(cx: &mut Check, ident: &str) { 12 if ident.starts_with("cxxbridge") { 13 cx.error(ident, error::CXXBRIDGE_RESERVED.msg); 14 } 15 if ident.contains("__") { 16 cx.error(ident, error::DOUBLE_UNDERSCORE.msg); 17 } 18 } 19 20 fn check_rust_ident(cx: &mut Check, ident: &str) { 21 if ident.starts_with("cxxbridge") { 22 cx.error(ident, error::CXXBRIDGE_RESERVED.msg); 23 } 24 } 25} 26 27pub(crate) fn check_all(cx: &mut Check, apis: &[Api]) { 28 for api in apis { 29 match api { 30 Api::Include(_) | Api::Impl(_) => {} 31 Api::Struct(strct) => { 32 check(cx, &strct.name); 33 for field in &strct.fields { 34 check(cx, &field.name); 35 } 36 } 37 Api::Enum(enm) => { 38 check(cx, &enm.name); 39 for variant in &enm.variants { 40 check(cx, &variant.name); 41 } 42 } 43 Api::CxxType(ety) | Api::RustType(ety) => { 44 check(cx, &ety.name); 45 } 46 Api::CxxFunction(efn) | Api::RustFunction(efn) => { 47 check(cx, &efn.name); 48 for arg in &efn.args { 49 check(cx, &arg.name); 50 } 51 } 52 Api::TypeAlias(alias) => { 53 check(cx, &alias.name); 54 } 55 } 56 } 57} 58