1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![recursion_limit="128"]

extern crate proc_macro;
extern crate syn;
#[macro_use]
extern crate quote;

mod api;
mod multi_api;
mod wrapper;
mod common;



use proc_macro::TokenStream;
use api::impl_library_api;
use wrapper::impl_wrapper_api;
use multi_api::impl_wrapper_multi_api;

#[proc_macro_derive(WrapperApi, attributes(dlopen_name, dlopen_allow_null))]
pub fn wrapper_api(input: TokenStream) -> TokenStream {
    // Construct a string representation of the type definition
    let s = input.to_string();

    // Parse the string representation
    let ast = syn::parse_derive_input(&s).unwrap();

    // Build the impl
    let gen = impl_wrapper_api(&ast);

    // Return the generated impl
    gen.parse().unwrap()
}

#[proc_macro_derive(WrapperMultiApi)]
pub fn wrapper_multi_api(input: TokenStream) -> TokenStream {
    // Construct a string representation of the type definition
    let s = input.to_string();

    // Parse the string representation
    let ast = syn::parse_derive_input(&s).unwrap();

    // Build the impl
    let gen = impl_wrapper_multi_api(&ast);

    // Return the generated impl
    gen.parse().unwrap()
}

#[proc_macro_derive(SymBorApi, attributes(dlopen_name))]
pub fn library_api(input: TokenStream) -> TokenStream {
    // Construct a string representation of the type definition
    let s = input.to_string();

    // Parse the string representation
    let ast = syn::parse_derive_input(&s).unwrap();

    // Build the impl
    let gen = impl_library_api(&ast);

    // Return the generated impl
    gen.parse().unwrap()
}