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