use std::process;
use proc_macro2::Span;
+use syn::parse_quote;
mod types;
mod blocks;
writeln!(w, "/// Serialize the {} object into a byte array which can be read by {}_read", for_obj, for_obj).unwrap();
writeln!(w, "pub extern \"C\" fn {}_write(obj: &{}) -> crate::c_types::derived::CVec_u8Z {{", for_obj, full_obj_path).unwrap();
- let ref_type = syn::Type::Reference(syn::TypeReference {
- and_token: syn::Token!(&)(Span::call_site()), lifetime: None, mutability: None,
- elem: Box::new(for_ty.clone()) });
+ let ref_type: syn::Type = syn::parse_quote!(&#for_ty);
assert!(!types.write_from_c_conversion_new_var(w, &syn::Ident::new("obj", Span::call_site()), &ref_type, Some(generics)));
write!(w, "\tcrate::c_types::serialize_obj(").unwrap();
},
"lightning::util::ser::Readable"|"lightning::util::ser::ReadableArgs" => {
// Create the Result<Object, DecodeError> syn::Type
- let mut err_segs = syn::punctuated::Punctuated::new();
- err_segs.push(syn::PathSegment { ident: syn::Ident::new("ln", Span::call_site()), arguments: syn::PathArguments::None });
- err_segs.push(syn::PathSegment { ident: syn::Ident::new("msgs", Span::call_site()), arguments: syn::PathArguments::None });
- err_segs.push(syn::PathSegment { ident: syn::Ident::new("DecodeError", Span::call_site()), arguments: syn::PathArguments::None });
- let mut args = syn::punctuated::Punctuated::new();
- args.push(syn::GenericArgument::Type(for_ty.clone()));
- args.push(syn::GenericArgument::Type(syn::Type::Path(syn::TypePath {
- qself: None, path: syn::Path {
- leading_colon: Some(syn::Token![::](Span::call_site())), segments: err_segs,
- }
- })));
- let mut res_segs = syn::punctuated::Punctuated::new();
- res_segs.push(syn::PathSegment {
- ident: syn::Ident::new("Result", Span::call_site()),
- arguments: syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
- colon2_token: None, lt_token: syn::Token![<](Span::call_site()), args, gt_token: syn::Token![>](Span::call_site()),
- })
- });
- let res_ty = syn::Type::Path(syn::TypePath { qself: None, path: syn::Path {
- leading_colon: None, segments: res_segs } });
+ let res_ty: syn::Type = parse_quote!(Result<#for_ty, ::ln::msgs::DecodeError>);
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "/// Read a {} from a byte array, created by {}_write", for_obj, for_obj).unwrap();
use crate::blocks::*;
use proc_macro2::{TokenTree, Span};
+use syn::parse_quote;
// The following utils are used purely to build our known types maps - they break down all the
// types we need to resolve to include the given object, and no more.
let tail_str = split.next().unwrap();
assert!(split.next().is_none());
let len = &tail_str[..tail_str.len() - 1];
- Some(syn::Type::Array(syn::TypeArray {
- bracket_token: syn::token::Bracket { span: Span::call_site() },
- elem: Box::new(syn::Type::Path(syn::TypePath {
- qself: None,
- path: syn::Path::from(syn::PathSegment::from(syn::Ident::new("u8", Span::call_site()))),
- })),
- semi_token: syn::Token!(;)(Span::call_site()),
- len: syn::Expr::Lit(syn::ExprLit { attrs: Vec::new(), lit: syn::Lit::Int(syn::LitInt::new(len, Span::call_site())) }),
- }))
+ Some(parse_quote!([u8; #len]))
} else { None }
} else { None }
}
self.check_create_container(mangled_container, "Vec", vec![&*r.elem], generics, false)
} else { false }
} else if let syn::Type::Tuple(_) = &*s.elem {
- let mut args = syn::punctuated::Punctuated::new();
+ let mut args = syn::punctuated::Punctuated::<_, syn::token::Comma>::new();
args.push(syn::GenericArgument::Type((*s.elem).clone()));
let mut segments = syn::punctuated::Punctuated::new();
- segments.push(syn::PathSegment {
- ident: syn::Ident::new("Vec", Span::call_site()),
- arguments: syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments {
- colon2_token: None, lt_token: syn::Token![<](Span::call_site()), args, gt_token: syn::Token![>](Span::call_site()),
- })
- });
+ segments.push(parse_quote!(Vec<#args>));
self.write_c_type_intern(w, &syn::Type::Path(syn::TypePath { qself: None, path: syn::Path { leading_colon: None, segments } }), generics, false, is_mut, ptr_for_ref)
} else { false }
},