mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
Other macros might also want to parse generics. Additionally this makes the code easier to read, as the next commit will introduce more code in `#[pin_data]`. Also add more comments to explain how parsing generics work. Signed-off-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Link: https://lore.kernel.org/r/20230424081112.99890-2-benno.lossin@proton.me Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
27 lines
766 B
Rust
27 lines
766 B
Rust
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
use crate::helpers::{parse_generics, Generics};
|
|
use proc_macro::TokenStream;
|
|
|
|
pub(crate) fn pin_data(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
// This proc-macro only does some pre-parsing and then delegates the actual parsing to
|
|
// `kernel::__pin_data!`.
|
|
|
|
let (
|
|
Generics {
|
|
impl_generics,
|
|
ty_generics,
|
|
},
|
|
mut rest,
|
|
) = parse_generics(input);
|
|
// This should be the body of the struct `{...}`.
|
|
let last = rest.pop();
|
|
quote!(::kernel::__pin_data! {
|
|
parse_input:
|
|
@args(#args),
|
|
@sig(#(#rest)*),
|
|
@impl_generics(#(#impl_generics)*),
|
|
@ty_generics(#(#ty_generics)*),
|
|
@body(#last),
|
|
})
|
|
}
|