@@ -7,37 +7,10 @@ use proc_macro::TokenStream;
77use proc_macro2:: { TokenStream as TokenStream2 , TokenTree } ;
88use quote:: { quote, ToTokens , TokenStreamExt } ;
99use syn:: {
10- parse:: { Parse , ParseStream } ,
11- parse_macro_input, parse_quote,
12- spanned:: Spanned ,
13- DeriveInput , Error , Fields , FnArg , Generics , Ident , ItemFn , ItemStruct , ItemType , LitStr , Pat ,
14- Visibility ,
10+ parse_macro_input, parse_quote, spanned:: Spanned , Error , Fields , FnArg , Ident , ItemFn ,
11+ ItemStruct , LitStr , Pat , Visibility ,
1512} ;
1613
17- /// Parses a type definition, extracts its identifier and generic parameters
18- struct TypeDefinition {
19- ident : Ident ,
20- generics : Generics ,
21- }
22-
23- impl Parse for TypeDefinition {
24- fn parse ( input : ParseStream ) -> syn:: Result < Self > {
25- if let Ok ( d) = DeriveInput :: parse ( input) {
26- Ok ( Self {
27- ident : d. ident ,
28- generics : d. generics ,
29- } )
30- } else if let Ok ( t) = ItemType :: parse ( input) {
31- Ok ( Self {
32- ident : t. ident ,
33- generics : t. generics ,
34- } )
35- } else {
36- Err ( input. error ( "Input is not an alias, enum, struct or union definition" ) )
37- }
38- }
39- }
40-
4114macro_rules! err {
4215 ( $span: expr, $message: expr $( , ) ?) => {
4316 Error :: new( $span. span( ) , $message) . to_compile_error( )
@@ -47,40 +20,6 @@ macro_rules! err {
4720 } ;
4821}
4922
50- /// `unsafe_guid` attribute macro, implements the `Identify` trait for any type
51- /// (mostly works like a custom derive, but also supports type aliases)
52- #[ proc_macro_attribute]
53- pub fn unsafe_guid ( args : TokenStream , input : TokenStream ) -> TokenStream {
54- // Parse the arguments and input using Syn
55- let ( time_low, time_mid, time_high_and_version, clock_seq_and_variant, node) =
56- match parse_guid ( parse_macro_input ! ( args as LitStr ) ) {
57- Ok ( data) => data,
58- Err ( tokens) => return tokens. into ( ) ,
59- } ;
60-
61- let mut result: TokenStream2 = input. clone ( ) . into ( ) ;
62-
63- let type_definition = parse_macro_input ! ( input as TypeDefinition ) ;
64-
65- // At this point, we know everything we need to implement Identify
66- let ident = & type_definition. ident ;
67- let ( impl_generics, ty_generics, where_clause) = type_definition. generics . split_for_impl ( ) ;
68-
69- result. append_all ( quote ! {
70- unsafe impl #impl_generics :: uefi:: Identify for #ident #ty_generics #where_clause {
71- #[ doc( hidden) ]
72- const GUID : :: uefi:: Guid = :: uefi:: Guid :: from_values(
73- #time_low,
74- #time_mid,
75- #time_high_and_version,
76- #clock_seq_and_variant,
77- #node,
78- ) ;
79- }
80- } ) ;
81- result. into ( )
82- }
83-
8423/// Attribute macro for marking structs as UEFI protocols.
8524///
8625/// The macro takes one argument, a GUID string.
@@ -243,28 +182,6 @@ fn parse_guid(guid_lit: LitStr) -> Result<(u32, u16, u16, u16, u64), TokenStream
243182 ) )
244183}
245184
246- /// Custom derive for the `Protocol` trait
247- #[ proc_macro_derive( Protocol ) ]
248- pub fn derive_protocol ( item : TokenStream ) -> TokenStream {
249- // Parse the input using Syn
250- let item = parse_macro_input ! ( item as DeriveInput ) ;
251-
252- // Then implement Protocol
253- let ident = item. ident . clone ( ) ;
254- let ( impl_generics, ty_generics, where_clause) = item. generics . split_for_impl ( ) ;
255- let result = quote ! {
256- // Mark this as a `Protocol` implementation
257- impl #impl_generics :: uefi:: proto:: Protocol for #ident #ty_generics #where_clause { }
258-
259- // Most UEFI functions expect to be called on the bootstrap processor.
260- impl #impl_generics !Send for #ident #ty_generics #where_clause { }
261-
262- // Most UEFI functions do not support multithreaded access.
263- impl #impl_generics !Sync for #ident #ty_generics #where_clause { }
264- } ;
265- result. into ( )
266- }
267-
268185/// Get the name of a function's argument at `arg_index`.
269186fn get_function_arg_name ( f : & ItemFn , arg_index : usize , errors : & mut TokenStream2 ) -> Option < Ident > {
270187 if let Some ( FnArg :: Typed ( arg) ) = f. sig . inputs . iter ( ) . nth ( arg_index) {
0 commit comments