@@ -2,7 +2,7 @@ use darling::util::Flag;
2
2
use darling:: FromAttributes ;
3
3
use proc_macro2:: TokenStream ;
4
4
use quote:: quote;
5
- use std:: collections:: HashMap ;
5
+ use std:: collections:: { HashMap , HashSet } ;
6
6
use syn:: { Ident , ItemImpl , Lit } ;
7
7
8
8
use crate :: constant:: PhpConstAttribute ;
@@ -124,14 +124,30 @@ struct ParsedImpl<'a> {
124
124
constants : Vec < Constant < ' a > > ,
125
125
}
126
126
127
+ #[ derive( Debug , Eq , Hash , PartialEq ) ]
128
+ enum MethodModifier {
129
+ Abstract ,
130
+ Static ,
131
+ }
132
+
133
+ impl quote:: ToTokens for MethodModifier {
134
+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
135
+ match * self {
136
+ Self :: Abstract => quote ! { :: ext_php_rs:: flags:: MethodFlags :: Abstract } ,
137
+ Self :: Static => quote ! { :: ext_php_rs:: flags:: MethodFlags :: Static } ,
138
+ }
139
+ . to_tokens ( tokens) ;
140
+ }
141
+ }
142
+
127
143
#[ derive( Debug ) ]
128
144
struct FnBuilder {
129
145
/// Tokens which represent the `FunctionBuilder` for this function.
130
146
pub builder : TokenStream ,
131
147
/// The visibility of this method.
132
148
pub vis : Visibility ,
133
149
/// Whether this method is abstract.
134
- pub r#abstract : bool ,
150
+ pub modifiers : HashSet < MethodModifier > ,
135
151
}
136
152
137
153
#[ derive( Debug ) ]
@@ -190,6 +206,8 @@ impl<'a> ParsedImpl<'a> {
190
206
let args = Args :: parse_from_fnargs ( method. sig . inputs . iter ( ) , opts. defaults ) ?;
191
207
let mut func = Function :: new ( & method. sig , opts. name , args, opts. optional , docs) ;
192
208
209
+ let mut modifiers: HashSet < MethodModifier > = HashSet :: new ( ) ;
210
+
193
211
if matches ! ( opts. ty, MethodTy :: Constructor ) {
194
212
if self . constructor . replace ( func) . is_some ( ) {
195
213
bail ! ( method => "Only one constructor can be provided per class." ) ;
@@ -211,15 +229,21 @@ impl<'a> ParsedImpl<'a> {
211
229
func. args . typed . pop ( ) ;
212
230
MethodReceiver :: ZendClassObject
213
231
} else {
232
+ modifiers. insert ( MethodModifier :: Static ) ;
214
233
// Static method
215
234
MethodReceiver :: Static
216
235
} ,
217
236
} ;
237
+ if matches ! ( opts. ty, MethodTy :: Abstract ) {
238
+ modifiers. insert ( MethodModifier :: Abstract ) ;
239
+ }
240
+
218
241
let builder = func. function_builder ( call_type) ;
242
+
219
243
self . functions . push ( FnBuilder {
220
244
builder,
221
245
vis : opts. vis ,
222
- r#abstract : matches ! ( opts . ty , MethodTy :: Abstract ) ,
246
+ modifiers ,
223
247
} ) ;
224
248
}
225
249
}
@@ -284,9 +308,10 @@ impl quote::ToTokens for FnBuilder {
284
308
Visibility :: Protected => quote ! { :: ext_php_rs:: flags:: MethodFlags :: Protected } ,
285
309
Visibility :: Private => quote ! { :: ext_php_rs:: flags:: MethodFlags :: Private } ,
286
310
} ) ;
287
- if self . r#abstract {
288
- flags. push ( quote ! { :: ext_php_rs :: flags :: MethodFlags :: Abstract } ) ;
311
+ for flag in & self . modifiers {
312
+ flags. push ( quote ! { #flag } )
289
313
}
314
+
290
315
quote ! {
291
316
( #builder, #( #flags) |* )
292
317
}
0 commit comments