mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
rust: remove offset_of replacement
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
5df3fe062f
commit
b134a09ffa
15 changed files with 16 additions and 239 deletions
|
@ -6,7 +6,7 @@ use proc_macro::TokenStream;
|
|||
use quote::quote;
|
||||
use syn::{
|
||||
parse_macro_input, parse_quote, punctuated::Punctuated, spanned::Spanned, token::Comma, Data,
|
||||
DeriveInput, Field, Fields, FieldsUnnamed, Ident, Meta, Path, Token, Type, Variant, Visibility,
|
||||
DeriveInput, Field, Fields, FieldsUnnamed, Ident, Meta, Path, Token, Variant,
|
||||
};
|
||||
|
||||
mod utils;
|
||||
|
@ -151,33 +151,6 @@ pub fn derive_opaque(input: TokenStream) -> TokenStream {
|
|||
TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
#[rustfmt::skip::macros(quote)]
|
||||
fn derive_offsets_or_error(input: DeriveInput) -> Result<proc_macro2::TokenStream, MacroError> {
|
||||
is_c_repr(&input, "#[derive(offsets)]")?;
|
||||
|
||||
let name = &input.ident;
|
||||
let fields = get_fields(&input, "#[derive(offsets)]")?;
|
||||
let field_names: Vec<&Ident> = fields.iter().map(|f| f.ident.as_ref().unwrap()).collect();
|
||||
let field_types: Vec<&Type> = fields.iter().map(|f| &f.ty).collect();
|
||||
let field_vis: Vec<&Visibility> = fields.iter().map(|f| &f.vis).collect();
|
||||
|
||||
Ok(quote! {
|
||||
::qemu_api::with_offsets! {
|
||||
struct #name {
|
||||
#(#field_vis #field_names: #field_types,)*
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[proc_macro_derive(offsets)]
|
||||
pub fn derive_offsets(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
let expanded = derive_offsets_or_error(input).unwrap_or_else(Into::into);
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
fn get_repr_uN(input: &DeriveInput, msg: &str) -> Result<Path, MacroError> {
|
||||
let repr = input.attrs.iter().find(|attr| attr.path().is_ident("repr"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue