From e316a638816a47d7a94cbd3b644c898b296d4d6d Mon Sep 17 00:00:00 2001 From: mox692 Date: Thu, 4 Jan 2024 04:54:57 +0900 Subject: [PATCH] remove change --- or-rs-macros/src/lib.rs | 53 --------------------------------- tests/tests/integration_test.rs | 1 - tests/tests/macro_test.rs | 10 ------- 3 files changed, 64 deletions(-) diff --git a/or-rs-macros/src/lib.rs b/or-rs-macros/src/lib.rs index eb8c672..9c05bef 100644 --- a/or-rs-macros/src/lib.rs +++ b/or-rs-macros/src/lib.rs @@ -58,56 +58,3 @@ use proc_macro::TokenStream; pub fn or_gen(_attr: TokenStream, item: TokenStream) -> TokenStream { parser::MacroParser::parse(item) } - -#[proc_macro] -pub fn my_first_proc_macro(item: TokenStream) -> TokenStream { - item -} - -use proc_macro::TokenStream; -use quote::quote; -use syn::*; - -#[proc_macro_attribute] -pub fn add_print(_attr: TokenStream, item: TokenStream) -> TokenStream { - // 入力をItemFn(関数を表現する構文木データ型に変換) - let input: ItemFn = parse_macro_input!(item as ItemFn); - // 関数名を取得 - let name = &input.sig.ident; - // 関数のブロックを取得 - let block = &input.block; - - // quoteマクロでproc_macro2::TokenStreamを生成 - let expanded: proc_macro2::TokenStream = quote! { - fn #name() { - println!("Function {} is called", stringify!(#name)); - #block - } - }; - - // proc_macro2::TokenStreamからTokenStreamに変換 - TokenStream::from(expanded) -} - -use proc_macro::{TokenStream, TokenTree}; - -#[proc_macro_attribute] -pub fn log(attr: TokenStream, item: TokenStream) -> TokenStream { - let mut iter = item.into_iter(); - - if let Some(TokenTree::Ident(ident)) = iter.next() { - let func_name = ident.to_string(); - let rest_of_stream: TokenStream = iter.collect(); - - let new_stream = format!( - "fn {}() {{ println!(\"Function '{}' called\"); {} }}", - func_name, func_name, rest_of_stream - ); - new_stream.parse().unwrap() - } else { - // トークンストリームが関数宣言でない場合はエラー - "compile_error!(\"Expected function declaration\")" - .parse() - .unwrap() - } -} diff --git a/tests/tests/integration_test.rs b/tests/tests/integration_test.rs index 6155a32..76ceeff 100644 --- a/tests/tests/integration_test.rs +++ b/tests/tests/integration_test.rs @@ -1,7 +1,6 @@ #![feature(proc_macro_hygiene)] // for now, you have to add this unstable feature flag use or_rs::enums::*; -use or_rs_macros::my_first_proc_macro; use or_rs_macros::or_gen; fn main() { diff --git a/tests/tests/macro_test.rs b/tests/tests/macro_test.rs index a756ed1..b2c9cb8 100644 --- a/tests/tests/macro_test.rs +++ b/tests/tests/macro_test.rs @@ -1,8 +1,6 @@ #![feature(proc_macro_hygiene)] #![allow(unused_variables)] -use or_rs_macros::add_print; -use or_rs_macros::my_first_proc_macro; use or_rs_macros::or_gen; #[test] @@ -58,11 +56,3 @@ fn test_compile() { _ => "hello".to_string(), }; } - -// fn foo() { -// my_first_proc_macro!(42); -// } - -#[test] -#[add_print] -fn your_function() {}