1
1
use std:: borrow:: Cow ;
2
2
use std:: collections:: HashSet ;
3
3
use std:: hash:: { Hash , Hasher } ;
4
+ use std:: ops:: ControlFlow ;
4
5
use std:: rc:: Rc ;
5
6
use std:: { fmt, iter} ;
6
7
@@ -11,7 +12,7 @@ pub use desc::ClassDesc;
11
12
use crate :: comment:: strip_doxygen_comment_markers;
12
13
use crate :: debug:: { DefinitionLocation , LocationName } ;
13
14
use crate :: element:: ExcludeKind ;
14
- use crate :: entity:: { ToEntity , WalkAction , WalkResult } ;
15
+ use crate :: entity:: { ControlFlowExt , ToEntity } ;
15
16
use crate :: field:: FieldDesc ;
16
17
use crate :: func:: { FuncCppBody , FuncDesc , FuncKind , FuncRustBody , FuncRustExtern , ReturnKind } ;
17
18
use crate :: type_ref:: { Constness , CppNameStyle , StrEnc , StrType , TypeRef , TypeRefDesc , TypeRefTypeHint } ;
@@ -66,9 +67,9 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
66
67
&& !self
67
68
. for_each_field ( |field| {
68
69
let type_ref = field. type_ref ( ) ;
69
- WalkAction :: continue_until ( !type_ref. kind ( ) . is_copy ( type_ref. type_hint ( ) ) )
70
+ ControlFlow :: continue_until ( !type_ref. kind ( ) . is_copy ( type_ref. type_hint ( ) ) )
70
71
} )
71
- . is_interrupted ( )
72
+ . is_break ( )
72
73
}
73
74
74
75
pub fn kind ( & self ) -> ClassKind {
@@ -154,8 +155,8 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
154
155
pub fn is_polymorphic ( & self ) -> bool {
155
156
match self {
156
157
Self :: Clang { entity, .. } => entity
157
- . walk_methods_while ( |f| WalkAction :: continue_until ( f. is_virtual_method ( ) || f. is_pure_virtual_method ( ) ) )
158
- . is_interrupted ( ) ,
158
+ . walk_methods_while ( |f| ControlFlow :: continue_until ( f. is_virtual_method ( ) || f. is_pure_virtual_method ( ) ) )
159
+ . is_break ( ) ,
159
160
Self :: Desc ( _) => false ,
160
161
}
161
162
}
@@ -185,9 +186,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
185
186
186
187
/// Class has an explicit method named `clone()`
187
188
pub fn has_explicit_clone ( & self ) -> bool {
188
- self
189
- . for_each_method ( |m| WalkAction :: continue_until ( m. is_clone ( ) ) )
190
- . is_interrupted ( )
189
+ self . for_each_method ( |m| ControlFlow :: continue_until ( m. is_clone ( ) ) ) . is_break ( )
191
190
}
192
191
193
192
/// Class is simple (i.e. constructor-copiable in C++), but can't be simple in Rust
@@ -200,21 +199,21 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
200
199
& Self :: Clang { entity, .. } => !entity
201
200
. walk_children_while ( |f| {
202
201
if matches ! ( f. get_kind( ) , EntityKind :: Constructor ) {
203
- WalkAction :: Interrupt
202
+ ControlFlow :: Break ( ( ) )
204
203
} else {
205
- WalkAction :: Continue
204
+ ControlFlow :: Continue ( ( ) )
206
205
}
207
206
} )
208
- . is_interrupted ( ) ,
207
+ . is_break ( ) ,
209
208
Self :: Desc ( _) => false ,
210
209
}
211
210
}
212
211
213
212
pub fn has_virtual_destructor ( & self ) -> bool {
214
213
match self {
215
214
Class :: Clang { entity, .. } => entity
216
- . walk_children_while ( |f| WalkAction :: continue_until ( f. get_kind ( ) == EntityKind :: Destructor && f. is_virtual_method ( ) ) )
217
- . is_interrupted ( ) ,
215
+ . walk_children_while ( |f| ControlFlow :: continue_until ( f. get_kind ( ) == EntityKind :: Destructor && f. is_virtual_method ( ) ) )
216
+ . is_break ( ) ,
218
217
Class :: Desc ( _) => false ,
219
218
}
220
219
}
@@ -223,19 +222,19 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
223
222
match self {
224
223
Class :: Clang { entity, .. } => entity
225
224
. walk_children_while ( |f| {
226
- WalkAction :: continue_until (
225
+ ControlFlow :: continue_until (
227
226
f. get_kind ( ) == EntityKind :: Destructor
228
227
&& f. get_accessibility ( ) . map_or ( true , |acc| acc != Accessibility :: Public ) ,
229
228
)
230
229
} )
231
- . is_interrupted ( ) ,
230
+ . is_break ( ) ,
232
231
Class :: Desc ( _) => false ,
233
232
}
234
233
}
235
234
236
235
pub fn has_bases ( & self ) -> bool {
237
236
match self {
238
- & Self :: Clang { entity, .. } => entity. walk_bases_while ( |_| WalkAction :: Interrupt ) . is_interrupted ( ) ,
237
+ & Self :: Clang { entity, .. } => entity. walk_bases_while ( |_| ControlFlow :: Break ( ( ) ) ) . is_break ( ) ,
239
238
Self :: Desc ( desc) => !desc. bases . is_empty ( ) ,
240
239
}
241
240
}
@@ -247,7 +246,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
247
246
let entity = entity. get_template ( ) . unwrap_or ( entity) ;
248
247
entity. walk_bases_while ( |child| {
249
248
out. push ( Self :: new ( Self :: definition_entity ( child) , gen_env) ) ;
250
- WalkAction :: Continue
249
+ ControlFlow :: Continue ( ( ) )
251
250
} ) ;
252
251
out. into ( )
253
252
}
@@ -318,14 +317,14 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
318
317
}
319
318
320
319
pub fn has_methods ( & self ) -> bool {
321
- self . for_each_method ( |_| WalkAction :: Interrupt ) . is_interrupted ( )
320
+ self . for_each_method ( |_| ControlFlow :: Break ( ( ) ) ) . is_break ( )
322
321
}
323
322
324
323
#[ inline]
325
- pub fn for_each_method ( & self , mut predicate : impl FnMut ( Func < ' tu , ' ge > ) -> WalkAction ) -> WalkResult {
324
+ pub fn for_each_method ( & self , mut predicate : impl FnMut ( Func < ' tu , ' ge > ) -> ControlFlow < ( ) > ) -> ControlFlow < ( ) > {
326
325
match self {
327
326
& Self :: Clang { entity, gen_env, .. } => entity. walk_methods_while ( |f| predicate ( Func :: new ( f, gen_env) ) ) ,
328
- Self :: Desc ( _) => WalkResult :: Completed ,
327
+ Self :: Desc ( _) => ControlFlow :: Continue ( ( ) ) ,
329
328
}
330
329
}
331
330
@@ -342,11 +341,11 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
342
341
for spec in specs {
343
342
out. push ( func. clone ( ) . specialize ( spec) ) ;
344
343
}
345
- return WalkAction :: Continue ;
344
+ return ControlFlow :: Continue ( ( ) ) ;
346
345
}
347
346
}
348
347
out. push ( func) ;
349
- WalkAction :: Continue
348
+ ControlFlow :: Continue ( ( ) )
350
349
} ) ;
351
350
let rust_module = match self {
352
351
Class :: Clang { gen_env, .. } => gen_env. module ( ) ,
@@ -364,39 +363,39 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
364
363
}
365
364
366
365
pub fn has_fields ( & self ) -> bool {
367
- self . for_each_field ( |_| WalkAction :: Interrupt ) . is_interrupted ( )
366
+ self . for_each_field ( |_| ControlFlow :: Break ( ( ) ) ) . is_break ( )
368
367
}
369
368
370
369
#[ inline]
371
- pub fn for_each_field ( & self , mut predicate : impl FnMut ( Field < ' tu , ' ge > ) -> WalkAction ) -> WalkResult {
370
+ pub fn for_each_field ( & self , mut predicate : impl FnMut ( Field < ' tu , ' ge > ) -> ControlFlow < ( ) > ) -> ControlFlow < ( ) > {
372
371
match self {
373
372
& Self :: Clang { entity, gen_env, .. } => entity. walk_fields_while ( |f| predicate ( Field :: new ( f, gen_env) ) ) ,
374
- Self :: Desc ( _) => WalkResult :: Completed ,
373
+ Self :: Desc ( _) => ControlFlow :: Continue ( ( ) ) ,
375
374
}
376
375
}
377
376
378
377
pub fn fields ( & self ) -> Vec < Field < ' tu , ' ge > > {
379
378
let mut out = Vec :: with_capacity ( 32 ) ;
380
379
self . for_each_field ( |f| {
381
380
out. push ( f) ;
382
- WalkAction :: Continue
381
+ ControlFlow :: Continue ( ( ) )
383
382
} ) ;
384
383
out
385
384
}
386
385
387
386
#[ inline]
388
- pub fn for_each_const ( & self , mut predicate : impl FnMut ( Const < ' tu > ) -> WalkAction ) -> WalkResult {
387
+ pub fn for_each_const ( & self , mut predicate : impl FnMut ( Const < ' tu > ) -> ControlFlow < ( ) > ) -> ControlFlow < ( ) > {
389
388
match self {
390
389
& Self :: Clang { entity, .. } => entity. walk_consts_while ( |f| predicate ( Const :: new ( f) ) ) ,
391
- Self :: Desc ( _) => WalkResult :: Completed ,
390
+ Self :: Desc ( _) => ControlFlow :: Continue ( ( ) ) ,
392
391
}
393
392
}
394
393
395
394
pub fn consts ( & self ) -> Vec < Const < ' tu > > {
396
395
let mut out = Vec :: with_capacity ( 8 ) ;
397
396
self . for_each_const ( |c| {
398
397
out. push ( c) ;
399
- WalkAction :: Continue
398
+ ControlFlow :: Continue ( ( ) )
400
399
} ) ;
401
400
out
402
401
}
0 commit comments