move to new crates versions

This commit is contained in:
vms 2020-06-30 23:42:26 +03:00
parent 7100cb9475
commit d596f5034d
3 changed files with 23 additions and 55 deletions

View File

@ -18,7 +18,7 @@ all-features = true
proc-macro = true proc-macro = true
[dependencies] [dependencies]
syn = { version = '0.15.44', features = ['full'] } syn = { version = '1.0.33', features = ['full'] }
quote = "0.6.13" quote = "1.0.7"
proc-macro2 = "0.4" proc-macro2 = "1.0.18"
fluence-sdk-main = { path = "../main", version = "=0.1.11" } fluence-sdk-main = { path = "../main", version = "=0.1.11" }

View File

@ -96,75 +96,46 @@ use crate::macro_input_parser::{InputTypeGenerator, ParsedType, ReturnTypeGenera
use proc_macro::TokenStream; use proc_macro::TokenStream;
use quote::quote; use quote::quote;
use syn::spanned::Spanned; use syn::spanned::Spanned;
use syn::{parse::Error, parse_macro_input, ItemFn}; use syn::{parse::Error, parse_macro_input, ItemFn, Visibility};
fn invoke_handler_impl( fn invoke_handler_impl(
attr: proc_macro2::TokenStream, attr: proc_macro2::TokenStream,
fn_item: syn::ItemFn, fn_item: ItemFn,
) -> syn::Result<proc_macro2::TokenStream> { ) -> syn::Result<proc_macro2::TokenStream> {
let ItemFn { let ItemFn {
constness, vis,
unsafety, sig,
abi,
ident,
decl,
.. ..
} = &fn_item; } = &fn_item;
if let Err(e) = (|| { match vis {
if let Some(constness) = constness { Visibility::Public(_) => {},
return Err(Error::new( _ => return Err(Error::new(
constness.span, vis.span(),
"The invocation handler shouldn't be constant", "The #[faas_export] could be applied only to public functions",
)); ))
}
if let Some(unsafety) = unsafety {
return Err(Error::new(
unsafety.span,
"The invocation handler shouldn't be unsage",
));
}
if let Some(abi) = abi {
return Err(Error::new(
abi.extern_token.span,
"The invocation handler shouldn't have any custom linkage",
));
}
if !decl.generics.params.is_empty() || decl.generics.where_clause.is_some() {
return Err(Error::new(
decl.fn_token.span,
"The invocation handler shouldn't use template parameters",
));
}
if let Some(variadic) = decl.variadic {
return Err(Error::new(
variadic.spans[0],
"The invocation handler shouldn't use variadic interface",
));
}
Ok(())
})() {
return Err(e);
} }
let input_type = match decl.inputs.len() { let input_type = match sig.inputs.len() {
0 => ParsedType::Empty, 0 => ParsedType::Empty,
1 => ParsedType::from_fn_arg(decl.inputs.first().unwrap().into_value())?, 1 => ParsedType::from_fn_arg(sig.inputs.first().unwrap())?,
_ => { _ => {
return Err(Error::new( return Err(Error::new(
decl.inputs.span(), sig.inputs.span(),
"The invocation handler shouldn't have more than one argument", "The invocation handler shouldn't have more than one argument",
)) ))
}, },
}; };
let output_type = ParsedType::from_return_type(&decl.output)?;
let output_type = ParsedType::from_return_type(&sig.output)?;
if output_type == ParsedType::Empty { if output_type == ParsedType::Empty {
return Err(Error::new( return Err(Error::new(
decl.output.span(), sig.output.span(),
"The invocation handler should have the return value", "The invocation handler should have the return value",
)); ));
} }
let ident = &sig.ident;
let prolog = input_type.generate_fn_prolog(); let prolog = input_type.generate_fn_prolog();
let prolog = match input_type { let prolog = match input_type {
ParsedType::Empty => quote! { ParsedType::Empty => quote! {

View File

@ -43,13 +43,12 @@ impl ParsedType {
"Unsuitable type in Vec brackets - only Vec<u8> is supported", "Unsuitable type in Vec brackets - only Vec<u8> is supported",
) )
})?; })?;
let arg_val = arg.value();
// converts T to syn::Type // converts T to syn::Type
let arg_type = match arg_val { let arg_type = match arg {
syn::GenericArgument::Type(ty) => Ok(ty), syn::GenericArgument::Type(ty) => Ok(ty),
_ => Err(Error::new( _ => Err(Error::new(
arg_val.span(), arg.span(),
"Unsuitable type in Vec brackets - only Vec<u8> is supported", "Unsuitable type in Vec brackets - only Vec<u8> is supported",
)), )),
}?; }?;
@ -79,7 +78,6 @@ impl ParsedType {
"Unsuitable type in Vec brackets - only Vec<u8> is supported", "Unsuitable type in Vec brackets - only Vec<u8> is supported",
) )
})?; })?;
let arg_segment = arg_segment.value();
Ok(arg_segment.ident.to_string()) Ok(arg_segment.ident.to_string())
} }
@ -103,7 +101,6 @@ impl ParsedType {
"The invocation handler should have a non-empty input argument type", "The invocation handler should have a non-empty input argument type",
) )
})?; })?;
let type_segment = type_segment.value();
match type_segment.ident.to_string().as_str() { match type_segment.ident.to_string().as_str() {
"String" => Ok(ParsedType::Utf8String), "String" => Ok(ParsedType::Utf8String),
@ -126,7 +123,7 @@ impl ParsedType {
pub fn from_fn_arg(fn_arg: &syn::FnArg) -> syn::Result<Self> { pub fn from_fn_arg(fn_arg: &syn::FnArg) -> syn::Result<Self> {
match fn_arg { match fn_arg {
syn::FnArg::Captured(arg) => ParsedType::from_type(&arg.ty), syn::FnArg::Typed(arg) => ParsedType::from_type(&arg.ty),
_ => Err(Error::new(fn_arg.span(), "Unknown argument")), _ => Err(Error::new(fn_arg.span(), "Unknown argument")),
} }
} }