treat and parse structs without repr attributes as unit structs

This commit is contained in:
yamachu 2023-09-06 19:30:21 +09:00
parent 7b614935e5
commit dd6330a573

View File

@ -170,6 +170,15 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
is_union: true,
});
} else if let Item::Struct(t) = item {
let mut repr = None;
for attr in &t.attrs {
let last_segment = attr.path.segments.last().unwrap();
if last_segment.ident == "repr" {
repr = Some(attr.tokens.to_string());
}
}
if let Some(_) = repr {
if let syn::Fields::Named(f) = &t.fields {
let struct_name = t.ident.to_string();
let fields = collect_fields(f);
@ -195,6 +204,16 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
is_union: false,
});
}
} else {
// non #[repr(?)] struct, treat as Unit struct
let struct_name = t.ident.to_string();
let fields: Vec<FieldMember> = Vec::new();
result.push(RustStruct {
struct_name,
fields,
is_union: false,
});
}
}
}
}