Skip to content

Commit

Permalink
add visitor for struct and check if in impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rmehri01 committed Jan 9, 2025
1 parent 5213e6f commit 56094b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
23 changes: 19 additions & 4 deletions libc-test/test/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct StyleChecker {
errors: Vec<FileError>,
/// Path of the currently active file
path: PathBuf,
in_impl: bool,
}

#[derive(Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -121,7 +122,7 @@ impl StyleChecker {
}

fn set_state(&mut self, new_state: State, span: Span) {
if self.state > new_state {
if self.state > new_state && !self.in_impl {
self.error_with_help(
"incorrect module layout".to_string(),
span,
Expand Down Expand Up @@ -160,8 +161,10 @@ impl StyleChecker {
// (self.on_err)(line, "multiple s! macros in one module");
// }

self.state = new_state;
self.state_span = Some(span);
if self.state != new_state {
self.state = new_state;
self.state_span = Some(span);
}
}

/// Visit the items inside the [ExprCfgIf], restoring the state after
Expand Down Expand Up @@ -212,7 +215,6 @@ impl<'ast> Visit<'ast> for StyleChecker {
let meta_str = meta_list.tokens.to_string();
if meta_list.path.is_ident("cfg")
&& !(meta_str.contains("target_endian") || meta_str.contains("target_arch"))
&& self.state != State::Structs
{
self.error_with_help(
"#[cfg] over cfg_if!".to_string(),
Expand Down Expand Up @@ -256,6 +258,19 @@ impl<'ast> Visit<'ast> for StyleChecker {
visit::visit_item_const(self, item_const);
}

fn visit_item_impl(&mut self, item_impl: &'ast syn::ItemImpl) {
self.in_impl = true;
visit::visit_item_impl(self, item_impl);
self.in_impl = false;
}

fn visit_item_struct(&mut self, item_struct: &'ast syn::ItemStruct) {
let span = item_struct.span();
self.set_state(State::Structs, span);

visit::visit_item_struct(self, item_struct);
}

fn visit_item_type(&mut self, item_type: &'ast syn::ItemType) {
let span = item_type.span();
self.set_state(State::Typedefs, span);
Expand Down
6 changes: 3 additions & 3 deletions src/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ pub type c_long = i64;

pub type c_ulong = u64;

#[repr(align(16))]
pub struct _CLongDouble(pub u128);

// long double in C means A float point value, which has 128bit length.
// but some bit maybe not used, so the real length of long double could be 80(x86) or 128(power pc/IEEE)
// this is different from f128(not stable and not included default) in Rust, so we use u128 for FFI(Rust to C).
Expand Down Expand Up @@ -88,6 +85,9 @@ pub type wctype_t = c_ulong;

pub type cmpfunc = extern "C" fn(x: *const c_void, y: *const c_void) -> c_int;

#[repr(align(16))]
pub struct _CLongDouble(pub u128);

#[repr(align(8))]
#[repr(C)]
pub struct pthread_cond_t {
Expand Down

0 comments on commit 56094b3

Please sign in to comment.