1
1
use anyhow:: { anyhow, bail, Result } ;
2
2
use quote:: ToTokens ;
3
3
use std:: collections:: HashMap ;
4
- use syn:: { ReturnType , parse_quote , PathArguments , GenericArgument } ;
4
+ use syn:: ReturnType ;
5
5
6
6
use crate :: helpers:: get_docs;
7
7
use crate :: {
@@ -11,7 +11,6 @@ use crate::{
11
11
use proc_macro2:: { Ident , Span , TokenStream } ;
12
12
use quote:: quote;
13
13
use syn:: { punctuated:: Punctuated , FnArg , ImplItemMethod , Lit , Pat , Token , Type } ;
14
- use quote:: TokenStreamExt ;
15
14
16
15
#[ derive( Debug , Clone ) ]
17
16
pub enum Arg {
@@ -137,9 +136,8 @@ pub fn parser(
137
136
} else {
138
137
quote ! { return ; }
139
138
} ;
140
- let mut hack_tokens = quote ! { } ;
141
139
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) ?;
143
141
let optional = function:: find_optional_parameter (
144
142
args. iter ( ) . filter_map ( |arg| match arg {
145
143
Arg :: Typed ( arg) => Some ( arg) ,
@@ -177,25 +175,6 @@ pub fn parser(
177
175
}
178
176
}
179
177
} 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
- }
199
178
let this = match method_type {
200
179
MethodType :: Receiver { .. } => quote ! { this. } ,
201
180
MethodType :: ReceiverClassObject | MethodType :: Static => quote ! { Self :: } ,
@@ -322,7 +301,6 @@ fn build_args(
322
301
struct_ty : & Type ,
323
302
inputs : & mut Punctuated < FnArg , Token ! [ , ] > ,
324
303
defaults : & HashMap < String , Lit > ,
325
- hack_tokens : & mut TokenStream
326
304
) -> Result < Vec < Arg > > {
327
305
inputs
328
306
. iter_mut ( )
@@ -350,48 +328,10 @@ fn build_args(
350
328
if this {
351
329
Ok ( Arg :: Receiver ( MethodType :: ReceiverClassObject ) )
352
330
} 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 ( ) ,
355
333
_ => bail ! ( "Invalid parameter type." ) ,
356
334
} ;
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
-
395
335
let default = defaults. get ( & name) ;
396
336
let mut ty = ty. ty . clone ( ) ;
397
337
replace_self ( struct_ty, & mut ty) ;
0 commit comments