trident_derive_flow_executor/
lib.rs

1use proc_macro::TokenStream;
2use quote::ToTokens;
3use syn::{parse_macro_input, ItemFn, ItemImpl};
4use trident_syn::parser::trident_flow_executor::parse_trident_flow_executor;
5
6/// Marks a method to be executed as part of the fuzzing flow
7#[proc_macro_attribute]
8pub fn flow(_attr: TokenStream, item: TokenStream) -> TokenStream {
9    let input_fn = parse_macro_input!(item as ItemFn);
10    quote::quote!(#input_fn).into()
11}
12
13/// Marks a method to run once before any flow methods
14#[proc_macro_attribute]
15pub fn init(_attr: TokenStream, item: TokenStream) -> TokenStream {
16    let input_fn = parse_macro_input!(item as ItemFn);
17    quote::quote!(#input_fn).into()
18}
19
20/// Marks a flow method to be skipped during execution
21#[proc_macro_attribute]
22pub fn flow_ignore(_attr: TokenStream, item: TokenStream) -> TokenStream {
23    let input_fn = parse_macro_input!(item as ItemFn);
24    quote::quote!(#input_fn).into()
25}
26
27/// Implements the flow executor for a struct
28#[proc_macro_attribute]
29pub fn flow_executor(attr: TokenStream, item: TokenStream) -> TokenStream {
30    let input = parse_macro_input!(item as ItemImpl);
31    let attr_tokens: proc_macro2::TokenStream = attr.into();
32
33    match parse_trident_flow_executor(attr_tokens, &input) {
34        Ok(executor) => executor.to_token_stream().into(),
35        Err(err) => err.to_compile_error().into(),
36    }
37}