| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
mod ast; |
| 6 |
mod parse; |
| 7 |
mod render; |
| 8 |
|
| 9 |
use proc_macro2::TokenStream; |
| 10 |
use quote::quote; |
| 11 |
|
| 12 |
use ast::*; |
| 13 |
|
| 14 |
pub fn expand_node(node: Node) -> syn::Result<TokenStream> { |
| 15 |
let type_ident = &node.ident; |
| 16 |
let (impl_generics, ty_generics, where_clause) = node.split_generics_for_node_impl(); |
| 17 |
let type_name = type_ident.to_string(); |
| 18 |
let visit_children = node.render_visit_children(); |
| 19 |
let visit_children_mut = node.render_visit_children_mut(); |
| 20 |
let take_into_value = node.render_take_into_value(); |
| 21 |
let try_from_value = node.render_try_from_value(); |
| 22 |
let default = node.render_default(); |
| 23 |
|
| 24 |
Ok(quote! { |
| 25 |
#[automatically_derived] |
| 26 |
impl #impl_generics ::uniffi_pipeline::Node for #type_ident #ty_generics #where_clause { |
| 27 |
#visit_children |
| 28 |
|
| 29 |
#visit_children_mut |
| 30 |
|
| 31 |
#take_into_value |
| 32 |
|
| 33 |
#try_from_value |
| 34 |
|
| 35 |
fn type_name(&self) -> Option<&'static str> { |
| 36 |
Some(#type_name) |
| 37 |
} |
| 38 |
|
| 39 |
fn as_any(&self) -> &dyn ::std::any::Any { |
| 40 |
self |
| 41 |
} |
| 42 |
|
| 43 |
fn as_any_mut(&mut self) -> &mut dyn ::std::any::Any { |
| 44 |
self |
| 45 |
} |
| 46 |
|
| 47 |
fn to_box_any(self: Box<Self>) -> Box<dyn ::std::any::Any> { |
| 48 |
self |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
#[automatically_derived] |
| 53 |
impl #impl_generics ::std::default::Default for #type_ident #ty_generics #where_clause { |
| 54 |
#default |
| 55 |
} |
| 56 |
}) |
| 57 |
} |