Skip to content

Commit 725dfec

Browse files
committed
Cleanup
1 parent 4cd4a20 commit 725dfec

File tree

1 file changed

+4
-64
lines changed

1 file changed

+4
-64
lines changed

crates/macros/src/method.rs

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::{anyhow, bail, Result};
22
use quote::ToTokens;
33
use std::collections::HashMap;
4-
use syn::{ReturnType, parse_quote, PathArguments, GenericArgument};
4+
use syn::ReturnType;
55

66
use crate::helpers::get_docs;
77
use crate::{
@@ -11,7 +11,6 @@ use crate::{
1111
use proc_macro2::{Ident, Span, TokenStream};
1212
use quote::quote;
1313
use syn::{punctuated::Punctuated, FnArg, ImplItemMethod, Lit, Pat, Token, Type};
14-
use quote::TokenStreamExt;
1514

1615
#[derive(Debug, Clone)]
1716
pub enum Arg {
@@ -137,9 +136,8 @@ pub fn parser(
137136
} else {
138137
quote! { return; }
139138
};
140-
let mut hack_tokens = quote! {};
141139
let internal_ident = Ident::new(&format!("_internal_php_{ident}"), Span::call_site());
142-
let args = build_args(struct_ty, &mut input.sig.inputs, &defaults, &mut hack_tokens)?;
140+
let args = build_args(struct_ty, &mut input.sig.inputs, &defaults)?;
143141
let optional = function::find_optional_parameter(
144142
args.iter().filter_map(|arg| match arg {
145143
Arg::Typed(arg) => Some(arg),
@@ -177,25 +175,6 @@ pub fn parser(
177175
}
178176
}
179177
} else {
180-
let mut input = input.clone();
181-
if input.sig.asyncness.is_some() {
182-
input.sig.asyncness = None;
183-
let stmts = input.block;
184-
let this = match method_type {
185-
MethodType::Receiver { mutable } => if mutable {
186-
quote! { let this = unsafe { std::mem::transmute::<&mut Self, &'static mut Self>(self) }; }
187-
} else {
188-
quote! { let this = unsafe { std::mem::transmute::<&Self, &'static Self>(self) }; }
189-
},
190-
MethodType::ReceiverClassObject | MethodType::Static => quote! { },
191-
};
192-
input.block = parse_quote! {{
193-
#this
194-
#hack_tokens
195-
196-
::ext_php_rs::zend::EventLoop::suspend_on(async move #stmts)
197-
}};
198-
}
199178
let this = match method_type {
200179
MethodType::Receiver { .. } => quote! { this. },
201180
MethodType::ReceiverClassObject | MethodType::Static => quote! { Self:: },
@@ -322,7 +301,6 @@ fn build_args(
322301
struct_ty: &Type,
323302
inputs: &mut Punctuated<FnArg, Token![,]>,
324303
defaults: &HashMap<String, Lit>,
325-
hack_tokens: &mut TokenStream
326304
) -> Result<Vec<Arg>> {
327305
inputs
328306
.iter_mut()
@@ -350,48 +328,10 @@ fn build_args(
350328
if this {
351329
Ok(Arg::Receiver(MethodType::ReceiverClassObject))
352330
} else {
353-
let param = match &*ty.pat {
354-
Pat::Ident(pat) => &pat.ident,
331+
let name = match &*ty.pat {
332+
Pat::Ident(pat) => pat.ident.to_string(),
355333
_ => bail!("Invalid parameter type."),
356334
};
357-
let name = param.to_string();
358-
359-
let mut ty_inner = &*ty.ty;
360-
let mut is_option = false;
361-
362-
if let Type::Path(t) = ty_inner {
363-
if t.path.segments[0].ident.to_string() == "Option" {
364-
if let PathArguments::AngleBracketed(t) = &t.path.segments[0].arguments {
365-
if let GenericArgument::Type(t) = &t.args[0] {
366-
ty_inner = t;
367-
is_option = true;
368-
}
369-
}
370-
}
371-
}
372-
let mut is_str = false;
373-
if let Type::Reference(t) = ty_inner {
374-
if t.mutability.is_none() {
375-
if let Type::Path(t) = &*t.elem {
376-
is_str = t.path.is_ident("str");
377-
}
378-
}
379-
}
380-
hack_tokens.append_all(if is_str {
381-
if is_option {
382-
quote! { let #param = #param.and_then(|__temp| Some(unsafe { ::core::mem::transmute::<&str, &'static str>(__temp) })); }
383-
} else {
384-
quote! { let #param = unsafe { ::core::mem::transmute::<&str, &'static str>(#param) }; }
385-
}
386-
} else {
387-
if is_option {
388-
quote! { let #param = #param.and_then(|__temp| Some(unsafe { ::ext_php_rs::zend::borrow_unchecked(__temp) })); }
389-
} else {
390-
quote! { let #param = unsafe { ::ext_php_rs::zend::borrow_unchecked(#param) }; }
391-
}
392-
});
393-
394-
395335
let default = defaults.get(&name);
396336
let mut ty = ty.ty.clone();
397337
replace_self(struct_ty, &mut ty);

0 commit comments

Comments
 (0)