2019-10-20 14:51:12 -04:00
|
|
|
use crate::syntax::{error, Api};
|
|
|
|
use proc_macro2::Ident;
|
|
|
|
use syn::{Error, Result};
|
|
|
|
|
|
|
|
pub(crate) fn check(ident: &Ident) -> Result<()> {
|
|
|
|
let s = ident.to_string();
|
|
|
|
if s.contains("__") {
|
|
|
|
Err(Error::new(ident.span(), error::DOUBLE_UNDERSCORE.msg))
|
|
|
|
} else if s.starts_with("cxxbridge") {
|
|
|
|
Err(Error::new(ident.span(), error::CXXBRIDGE_RESERVED.msg))
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn check_all(apis: &[Api], errors: &mut Vec<Error>) {
|
|
|
|
for api in apis {
|
|
|
|
match api {
|
|
|
|
Api::Include(_) => {}
|
|
|
|
Api::Struct(strct) => {
|
|
|
|
errors.extend(check(&strct.ident).err());
|
|
|
|
for field in &strct.fields {
|
|
|
|
errors.extend(check(&field.ident).err());
|
|
|
|
}
|
|
|
|
}
|
2020-04-23 17:31:09 -07:00
|
|
|
Api::Enum(enm) => {
|
|
|
|
errors.extend(check(&enm.ident).err());
|
|
|
|
for variant in &enm.variants {
|
|
|
|
errors.extend(check(&variant.ident).err());
|
|
|
|
}
|
|
|
|
}
|
2019-10-20 14:51:12 -04:00
|
|
|
Api::CxxType(ety) | Api::RustType(ety) => {
|
|
|
|
errors.extend(check(&ety.ident).err());
|
|
|
|
}
|
|
|
|
Api::CxxFunction(efn) | Api::RustFunction(efn) => {
|
|
|
|
errors.extend(check(&efn.ident).err());
|
|
|
|
for arg in &efn.args {
|
|
|
|
errors.extend(check(&arg.ident).err());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|