diff --git a/crates/syntest/src/constants.rs b/crates/syntest/src/constants.rs new file mode 100644 index 0000000..b43105d --- /dev/null +++ b/crates/syntest/src/constants.rs @@ -0,0 +1,24 @@ +use std::rc::Rc; + +/// Helper functions for macros +#[derive(Debug)] +pub struct Const { + file: Rc, +} + +impl Const { + pub fn new(file: Rc) -> Self { + Self { file } + } + + pub fn constants(&self) -> Vec { + self.file + .items + .iter() + .filter_map(|item| match item { + syn::Item::Const(item) => Some(item.clone()), + _ => None, + }) + .collect() + } +} diff --git a/crates/syntest/src/lib.rs b/crates/syntest/src/lib.rs index f655454..fea893d 100644 --- a/crates/syntest/src/lib.rs +++ b/crates/syntest/src/lib.rs @@ -1,9 +1,13 @@ +mod constants; mod func; mod mac; mod mutation; +mod syn; mod syntest; mod var; +pub use constants::Const; pub use mutation::Mutation; +pub use syn::*; pub use syntest::Syntest; pub use var::{LocalVariable, Value}; diff --git a/crates/syntest/src/syn.rs b/crates/syntest/src/syn.rs new file mode 100644 index 0000000..85b8e4f --- /dev/null +++ b/crates/syntest/src/syn.rs @@ -0,0 +1,2 @@ +pub use syn::parse_quote; +pub use syn::Type; diff --git a/crates/syntest/src/syntest.rs b/crates/syntest/src/syntest.rs index 5eded22..dfd71cd 100644 --- a/crates/syntest/src/syntest.rs +++ b/crates/syntest/src/syntest.rs @@ -5,11 +5,12 @@ use syn::{ parse_file, punctuated::Punctuated, token::PathSep, BinOp, Expr, Lit, Pat, PathSegment, Stmt, }; -use crate::{func::Func, mac::Mac, var::LocalVariable, Value}; +use crate::{constants::Const, func::Func, mac::Mac, var::LocalVariable, Value}; pub struct Syntest { - pub file: Rc, pub mac: Mac, + pub constant: Const, + pub file: Rc, } impl Syntest { @@ -18,6 +19,7 @@ impl Syntest { Ok(Self { mac: Mac::new(Rc::clone(&file)), + constant: Const::new(Rc::clone(&file)), file, }) } @@ -27,6 +29,7 @@ impl Syntest { Ok(Self { mac: Mac::new(Rc::clone(&file)), + constant: Const::new(Rc::clone(&file)), file: Rc::new(parse_file(code)?), }) }