use fuels_code_gen::Abigen;
use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};
use crate::{
abigen::MacroAbigenTargets,
derive::{
parameterize::generate_parameterize_impl, tokenizable::generate_tokenizable_impl,
try_from::generate_try_from_impl,
},
setup_program_test::{generate_setup_program_test_code, TestProgramCommands},
};
mod abigen;
mod derive;
mod parse_utils;
mod setup_program_test;
#[proc_macro]
pub fn abigen(input: TokenStream) -> TokenStream {
let targets = parse_macro_input!(input as MacroAbigenTargets);
Abigen::generate(targets.into(), false).unwrap().into()
}
#[proc_macro]
pub fn wasm_abigen(input: TokenStream) -> TokenStream {
let targets = parse_macro_input!(input as MacroAbigenTargets);
Abigen::generate(targets.into(), true).unwrap().into()
}
#[proc_macro]
pub fn setup_program_test(input: TokenStream) -> TokenStream {
let test_program_commands = parse_macro_input!(input as TestProgramCommands);
generate_setup_program_test_code(test_program_commands)
.unwrap_or_else(|e| e.to_compile_error())
.into()
}
#[proc_macro_derive(Parameterize, attributes(FuelsTypesPath, NoStd))]
pub fn parameterize(stream: TokenStream) -> TokenStream {
let input = parse_macro_input!(stream as DeriveInput);
generate_parameterize_impl(input)
.unwrap_or_else(|e| e.to_compile_error())
.into()
}
#[proc_macro_derive(Tokenizable, attributes(FuelsTypesPath, NoStd))]
pub fn tokenizable(stream: TokenStream) -> TokenStream {
let input = parse_macro_input!(stream as DeriveInput);
generate_tokenizable_impl(input)
.unwrap_or_else(|e| e.to_compile_error())
.into()
}
#[proc_macro_derive(TryFrom, attributes(FuelsCorePath, NoStd))]
pub fn try_from(stream: TokenStream) -> TokenStream {
let input = parse_macro_input!(stream as DeriveInput);
generate_try_from_impl(input)
.unwrap_or_else(|e| e.to_compile_error())
.into()
}