| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 1 | use crate::syntax::{error, Api}; |
| 2 | use proc_macro2::Ident; |
| 3 | use syn::{Error, Result}; |
| 4 | |
| 5 | pub(crate) fn check(ident: &Ident) -> Result<()> { |
| 6 | let s = ident.to_string(); |
| 7 | if s.contains("__") { |
| 8 | Err(Error::new(ident.span(), error::DOUBLE_UNDERSCORE.msg)) |
| 9 | } else if s.starts_with("cxxbridge") { |
| 10 | Err(Error::new(ident.span(), error::CXXBRIDGE_RESERVED.msg)) |
| 11 | } else { |
| 12 | Ok(()) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | pub(crate) fn check_all(apis: &[Api], errors: &mut Vec<Error>) { |
| 17 | for api in apis { |
| 18 | match api { |
| 19 | Api::Include(_) => {} |
| 20 | Api::Struct(strct) => { |
| 21 | errors.extend(check(&strct.ident).err()); |
| 22 | for field in &strct.fields { |
| 23 | errors.extend(check(&field.ident).err()); |
| 24 | } |
| 25 | } |
| 26 | Api::CxxType(ety) | Api::RustType(ety) => { |
| 27 | errors.extend(check(&ety.ident).err()); |
| 28 | } |
| 29 | Api::CxxFunction(efn) | Api::RustFunction(efn) => { |
| 30 | errors.extend(check(&efn.ident).err()); |
| 31 | for arg in &efn.args { |
| 32 | errors.extend(check(&arg.ident).err()); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |