peepmatic: Introduce the peepmatic-macro crate
This crate provides the derive macros used by `peepmatic`, notable AST-related derives that enumerate child AST nodes, and operator-related derives that provide helpers for type checking.
This commit is contained in:
23
cranelift/peepmatic/crates/macro/src/into_dyn_ast_ref.rs
Normal file
23
cranelift/peepmatic/crates/macro/src/into_dyn_ast_ref.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use quote::quote;
|
||||
use syn::DeriveInput;
|
||||
use syn::Result;
|
||||
|
||||
pub fn derive_into_dyn_ast_ref(input: &DeriveInput) -> Result<impl quote::ToTokens> {
|
||||
let ty = &input.ident;
|
||||
|
||||
let opts = crate::PeepmaticOpts::from_attrs(&mut input.attrs.clone())?;
|
||||
if opts.no_into_dyn_node {
|
||||
return Ok(quote! {});
|
||||
}
|
||||
|
||||
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||
|
||||
Ok(quote! {
|
||||
impl #impl_generics From<&'a #ty #ty_generics> for DynAstRef<'a> #where_clause {
|
||||
#[inline]
|
||||
fn from(x: &'a #ty #ty_generics) -> Self {
|
||||
Self::#ty(x)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user