mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-24 07:40:19 +00:00
Update ident checker's error reporting to match type checker's
This commit is contained in:
parent
9dcb8339f0
commit
a83301ce5b
@ -10,7 +10,7 @@ use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
use syn::{Error, Result};
|
||||
|
||||
struct Check<'a> {
|
||||
pub(crate) struct Check<'a> {
|
||||
namespace: &'a Namespace,
|
||||
apis: &'a [Api],
|
||||
types: &'a Types<'a>,
|
||||
@ -31,8 +31,9 @@ pub(crate) fn typecheck(namespace: &Namespace, apis: &[Api], types: &Types) -> R
|
||||
|
||||
fn do_typecheck(cx: &mut Check) {
|
||||
for segment in cx.namespace {
|
||||
cx.errors.extend(ident::check(segment).err());
|
||||
ident::check(cx, segment);
|
||||
}
|
||||
ident::check_all(cx, cx.apis);
|
||||
|
||||
for ty in cx.types {
|
||||
match ty {
|
||||
@ -65,12 +66,10 @@ fn do_typecheck(cx: &mut Check) {
|
||||
check_multiple_arg_lifetimes(cx, efn);
|
||||
}
|
||||
}
|
||||
|
||||
ident::check_all(cx.apis, cx.errors);
|
||||
}
|
||||
|
||||
impl Check<'_> {
|
||||
fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
|
||||
pub(crate) fn error(&mut self, sp: impl ToTokens, msg: impl Display) {
|
||||
self.errors.push(Error::new_spanned(sp, msg));
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,40 @@
|
||||
use crate::syntax::check::Check;
|
||||
use crate::syntax::{error, Api};
|
||||
use proc_macro2::Ident;
|
||||
use syn::{Error, Result};
|
||||
|
||||
pub(crate) fn check(ident: &Ident) -> Result<()> {
|
||||
pub(crate) fn check(cx: &mut Check, ident: &Ident) {
|
||||
let s = ident.to_string();
|
||||
if s.starts_with("cxxbridge") {
|
||||
cx.error(ident, error::CXXBRIDGE_RESERVED.msg);
|
||||
}
|
||||
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(())
|
||||
cx.error(ident, error::DOUBLE_UNDERSCORE.msg);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn check_all(apis: &[Api], errors: &mut Vec<Error>) {
|
||||
pub(crate) fn check_all(cx: &mut Check, apis: &[Api]) {
|
||||
for api in apis {
|
||||
match api {
|
||||
Api::Include(_) => {}
|
||||
Api::Struct(strct) => {
|
||||
errors.extend(check(&strct.ident).err());
|
||||
check(cx, &strct.ident);
|
||||
for field in &strct.fields {
|
||||
errors.extend(check(&field.ident).err());
|
||||
check(cx, &field.ident);
|
||||
}
|
||||
}
|
||||
Api::Enum(enm) => {
|
||||
errors.extend(check(&enm.ident).err());
|
||||
check(cx, &enm.ident);
|
||||
for variant in &enm.variants {
|
||||
errors.extend(check(&variant.ident).err());
|
||||
check(cx, &variant.ident);
|
||||
}
|
||||
}
|
||||
Api::CxxType(ety) | Api::RustType(ety) => {
|
||||
errors.extend(check(&ety.ident).err());
|
||||
check(cx, &ety.ident);
|
||||
}
|
||||
Api::CxxFunction(efn) | Api::RustFunction(efn) => {
|
||||
errors.extend(check(&efn.ident).err());
|
||||
check(cx, &efn.ident);
|
||||
for arg in &efn.args {
|
||||
errors.extend(check(&arg.ident).err());
|
||||
check(cx, &arg.ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user