//! Common macros for Sequoia's FFI crates.
#![recursion_limit="512"]
use std::collections::HashMap;
use std::io::Write;
use lazy_static::lazy_static;
use syn;
use syn::parse_quote;
use syn::spanned::Spanned;
use proc_macro;
use proc_macro2;
use sha2;
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::{quote, ToTokens};
mod rust2c;
/// Transforms exported functions.
///
/// This macro is used to decorate every function exported from
/// Sequoia. It applies the following transformations:
///
/// - [ffi_catch_abort](attr.ffi_catch_abort.html)
/// - [cdecl](attr.cdecl.html)
#[proc_macro_attribute]
pub fn extern_fn(attr: TokenStream, item: TokenStream) -> TokenStream {
cdecl(attr.clone(), ffi_catch_abort(attr, item))
}
/// Generates a C function declaration.
#[proc_macro_attribute]
pub fn cdecl(_attr: TokenStream, item: TokenStream) -> TokenStream {
// Parse tokens into a function declaration.
let fun = syn::parse_macro_input!(item as syn::ItemFn);
// Extract all information from the parsed function that we need
// to compose the new function.
let summary = fun.attrs.iter().next();
let attrs = fun.attrs.iter().skip(1)
.fold(TokenStream2::new(),
|mut acc, attr| {
acc.extend(attr.clone().into_token_stream());
acc
});
let vis = &fun.vis;
let constness = &fun.sig.constness;
let unsafety = &fun.sig.unsafety;
let asyncness = &fun.sig.asyncness;
let abi = &fun.sig.abi;
let ident = &fun.sig.ident;
let fn_token = &fun.sig.fn_token;
let fn_generics = &fun.sig.generics;
let fn_out = &fun