Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive macro: Printable #30

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ intertrait = "0.2.2"
linkme = "0.2"
paste = "1.0"
inventory = "0.3"
combine = "4.6.6"
combine.workspace = true
regex = "1.10.2"
dyn-clone = "1.0.16"

Expand All @@ -52,3 +52,4 @@ proc-macro2 = "1.0.72"
quote = "1.0.33"
prettyplease = "0.2.16"
syn = { version = "2.0.43", features = ["derive"] }
combine = "4.6.6"
1 change: 1 addition & 0 deletions pliron-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ proc-macro = true
proc-macro2.workspace = true
quote.workspace = true
syn.workspace = true
combine.workspace = true

[dev-dependencies]
prettyplease.workspace = true
Expand Down
14 changes: 10 additions & 4 deletions pliron-derive/src/derive_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use syn::{DeriveInput, LitStr, Result};

const PROC_MACRO_NAME: &str = "def_attribute";

use crate::derive_shared::VerifiersRegister;
use crate::{
derive_shared::{mark_ir_kind, VerifiersRegister},
macro_attr::IRKind,
};

pub(crate) fn def_attribute(
args: impl Into<TokenStream>,
Expand Down Expand Up @@ -50,11 +53,12 @@ impl DefAttribute {
));
}

let attrs: Vec<_> = input
let attrs = input
.attrs
.into_iter()
.filter(|attr| !attr.path().is_ident(PROC_MACRO_NAME))
.collect();
.filter(|attr| !attr.path().is_ident(PROC_MACRO_NAME));
let attrs: Vec<_> = mark_ir_kind(attrs, IRKind::Attribute).collect();

let input = DeriveInput { attrs, ..input };

let verifiers = VerifiersRegister {
Expand Down Expand Up @@ -157,6 +161,8 @@ mod tests {

expect![[r##"
#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(::pliron_derive::DeriveAttribAcceptor)]
#[ir_kind = "attribute"]
pub struct UnitAttr();
#[allow(non_camel_case_types)]
pub struct AttrInterfaceVerifier_UnitAttr(
Expand Down
14 changes: 10 additions & 4 deletions pliron-derive/src/derive_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use proc_macro2::TokenStream;
use quote::{format_ident, quote, ToTokens};
use syn::{DeriveInput, LitStr, Result};

use crate::derive_shared::VerifiersRegister;
use crate::{
derive_shared::{mark_ir_kind, VerifiersRegister},
macro_attr::IRKind,
};

const PROC_MACRO_NAME: &str = "def_op";

Expand Down Expand Up @@ -52,11 +55,12 @@ impl DefOp {
));
}

let attrs: Vec<_> = input
let attrs = input
.attrs
.into_iter()
.filter(|attr| !attr.path().is_ident(PROC_MACRO_NAME))
.collect();
.filter(|attr| !attr.path().is_ident(PROC_MACRO_NAME));
let attrs: Vec<_> = mark_ir_kind(attrs, IRKind::Op).collect();

let input = DeriveInput { attrs, ..input };

let verifiers = VerifiersRegister {
Expand Down Expand Up @@ -171,6 +175,8 @@ mod tests {

expect![[r##"
#[derive(Clone, Copy)]
#[derive(::pliron_derive::DeriveAttribAcceptor)]
#[ir_kind = "op"]
struct TestOp {
op: ::pliron::context::Ptr<::pliron::operation::Operation>,
}
Expand Down
Loading
Loading