Skip to content

Commit

Permalink
exclude working
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-ant committed Oct 25, 2024
1 parent a6623cb commit 7be66a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
10 changes: 8 additions & 2 deletions rust/psibase-macros-test/services/add-check-init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ pub mod service {
table.put(&InitRow {}).unwrap();
}

#[pre_action(exclude = "init")]
#[action]
fn init2() {
let table = InitTable::new();
table.put(&InitRow {}).unwrap();
}

#[pre_action(exclude(init, init2))]
// #[pre_action(exclude)]
fn check_initialize() {
fn bobs_init() {
// name is not important
let table = InitTable::new();
check(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use darling::{ast::NestedMeta, FromMeta};
use darling::{ast::NestedMeta, util::PathList, FromMeta};
use proc_macro_error::abort;
use quote::{quote, ToTokens};
use syn::{AttrStyle, Attribute, FnArg, Ident, Item, ItemFn, Meta, Pat, ReturnType};
use syn::{AttrStyle, Attribute, FnArg, Ident, Item, ItemFn, Meta, Pat, Path, ReturnType};

#[derive(Debug, FromMeta)]
#[darling(default)]
Expand Down Expand Up @@ -192,15 +192,15 @@ pub fn process_action_schema(
pub struct PreAction {
pub exists: bool,
pub fn_name: Option<Ident>,
pub exclude: Option<String>,
pub exclude: PathList,
}

impl Default for PreAction {
fn default() -> Self {
PreAction {
exists: false,
fn_name: None,
exclude: None,
exclude: PathList::from(vec![]),
}
}
}
Expand All @@ -221,7 +221,7 @@ fn is_pre_action_attr(attr: &Attribute) -> bool {
// }
#[derive(Debug, FromMeta)]
struct PreActionOptions {
exclude: String, // PreActionExclude,
exclude: PathList,
}

pub fn check_for_pre_action(pre_action_info: &mut PreAction, items: &mut Vec<Item>) {
Expand All @@ -238,7 +238,7 @@ pub fn check_for_pre_action(pre_action_info: &mut PreAction, items: &mut Vec<Ite
// println!("1: processing pre_action_attr args");
let attr_args_ts = match pre_action_attr.meta.clone() {
Meta::List(args) => {
// println!("List: {:?}", args);
println!("List: {:?}", args);
args.tokens
}
Meta::Path(args) => panic!("expected list; got path."),
Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn check_for_pre_action(pre_action_info: &mut PreAction, items: &mut Vec<Ite
}
};
println!("pre-action options: {:?}", options);
pre_action_info.exclude = Some(options.exclude);
pre_action_info.exclude = options.exclude;

if let Some(pre_action_pos) = f.attrs.iter().position(is_pre_action_attr) {
f.attrs.remove(pre_action_pos);
Expand All @@ -284,7 +284,11 @@ pub fn check_for_pre_action(pre_action_info: &mut PreAction, items: &mut Vec<Ite

pub fn add_pre_action_call(pre_action_info: &PreAction, f: &mut ItemFn) {
// println!("adding check_init to {}", f.sig.ident.to_string());
if Some(f.sig.ident.to_string()) == pre_action_info.exclude {
if pre_action_info
.exclude
.to_strings()
.contains(&f.sig.ident.to_string())
{
println!(
"{} is in exclude list; skipping adding pre_action call",
f.sig.ident.to_string()
Expand Down
12 changes: 0 additions & 12 deletions rust/psibase_macros/psibase-macros-lib/src/service_macro/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,6 @@ fn process_mod(
let mut action_callers = proc_macro2::TokenStream::new();
let mut dispatch_body = proc_macro2::TokenStream::new();
let mut with_action_struct = proc_macro2::TokenStream::new();
// for fn_index in non_action_fns.iter() {
// if let Item::Fn(f) = &mut items[*fn_index] {
// let fn_name = f.sig.ident.to_string();
// if fn_name == "check_init" {
// // println!("found check_init(): {:#?}", fn_name);
// // TODO: Replace this with PreAction mechanism
// has_check_init = true;
// } else {
// // println!("not check_init(): {:#?}", fn_name);
// }
// }
// }

for fn_index in action_fns.iter() {
if let Item::Fn(f) = &mut items[*fn_index] {
Expand Down

0 comments on commit 7be66a7

Please sign in to comment.