@@ -15,7 +15,7 @@ use std::{collections::HashMap, fmt};
15
15
16
16
use crate :: { impl_function_trait, UnwrapToError } ;
17
17
18
- // TODO: cleanup adapting from rp2 tp rp3
18
+ // TODO: cleanup adapting from rp2 to rp3
19
19
20
20
use super :: FunctionTrait ;
21
21
@@ -326,6 +326,8 @@ fn get_functions(
326
326
current_class : & mut Vec < StmtClassDef > ,
327
327
lookup_name : & str ,
328
328
) {
329
+ // we create a list of blocks to be processed
330
+ let mut blocks = Vec :: new ( ) ;
329
331
match stmt {
330
332
Stmt :: FunctionDef ( function) if function. name . to_string ( ) == lookup_name => {
331
333
if function. end_location ( ) . is_some ( ) {
@@ -346,77 +348,18 @@ fn get_functions(
346
348
}
347
349
}
348
350
Stmt :: If ( r#if) => {
349
- get_functions_recurisve (
350
- r#if. body ,
351
- map,
352
- functions,
353
- current_parent,
354
- current_class,
355
- lookup_name,
356
- ) ;
357
- get_functions_recurisve (
358
- r#if. orelse ,
359
- map,
360
- functions,
361
- current_parent,
362
- current_class,
363
- lookup_name,
364
- ) ;
351
+ blocks. extend ( [ r#if. body , r#if. orelse ] ) ;
365
352
}
366
353
Stmt :: While ( r#while) => {
367
- get_functions_recurisve (
368
- r#while. body ,
369
- map,
370
- functions,
371
- current_parent,
372
- current_class,
373
- lookup_name,
374
- ) ;
375
- get_functions_recurisve (
376
- r#while. orelse ,
377
- map,
378
- functions,
379
- current_parent,
380
- current_class,
381
- lookup_name,
382
- ) ;
354
+ blocks. extend ( [ r#while. body , r#while. orelse ] ) ;
383
355
}
384
356
Stmt :: For ( r#for) => {
385
- get_functions_recurisve (
386
- r#for. body ,
387
- map,
388
- functions,
389
- current_parent,
390
- current_class,
391
- lookup_name,
392
- ) ;
393
- get_functions_recurisve (
394
- r#for. orelse ,
395
- map,
396
- functions,
397
- current_parent,
398
- current_class,
399
- lookup_name,
400
- ) ;
357
+ blocks. extend ( [ r#for. body , r#for. orelse ] ) ;
401
358
}
402
359
Stmt :: AsyncFor ( r#for) => {
403
- get_functions_recurisve (
404
- r#for. body ,
405
- map,
406
- functions,
407
- current_parent,
408
- current_class,
409
- lookup_name,
410
- ) ;
411
- get_functions_recurisve (
412
- r#for. orelse ,
413
- map,
414
- functions,
415
- current_parent,
416
- current_class,
417
- lookup_name,
418
- ) ;
360
+ blocks. extend ( [ r#for. body , r#for. orelse ] ) ;
419
361
}
362
+ // we do functions/classes not through blocks as they tell us if a function is nested in a class/function
420
363
Stmt :: FunctionDef ( function) => {
421
364
current_parent. push ( function. clone ( ) . into ( ) ) ;
422
365
get_functions_recurisve (
@@ -443,7 +386,6 @@ fn get_functions(
443
386
}
444
387
Stmt :: ClassDef ( class) => {
445
388
current_class. push ( class. clone ( ) ) ;
446
-
447
389
get_functions_recurisve (
448
390
class. body ,
449
391
map,
@@ -454,49 +396,26 @@ fn get_functions(
454
396
) ;
455
397
current_class. pop ( ) ;
456
398
}
457
- Stmt :: With ( with) => get_functions_recurisve (
458
- with. body ,
459
- map,
460
- functions,
461
- current_parent,
462
- current_class,
463
- lookup_name,
464
- ) ,
465
- Stmt :: AsyncWith ( with) => get_functions_recurisve (
466
- with. body ,
399
+ Stmt :: With ( with) => {
400
+ blocks. push ( with. body ) ;
401
+ }
402
+ Stmt :: AsyncWith ( with) => {
403
+ blocks. push ( with. body ) ;
404
+ }
405
+ Stmt :: Try ( r#try) => {
406
+ blocks. extend ( [ r#try. body , r#try. orelse , r#try. finalbody ] ) ;
407
+ }
408
+ _ => { }
409
+ } ;
410
+ for block in blocks {
411
+ get_functions_recurisve (
412
+ block,
467
413
map,
468
414
functions,
469
415
current_parent,
470
416
current_class,
471
417
lookup_name,
472
- ) ,
473
- Stmt :: Try ( r#try) => {
474
- get_functions_recurisve (
475
- r#try. body ,
476
- map,
477
- functions,
478
- current_parent,
479
- current_class,
480
- lookup_name,
481
- ) ;
482
- get_functions_recurisve (
483
- r#try. orelse ,
484
- map,
485
- functions,
486
- current_parent,
487
- current_class,
488
- lookup_name,
489
- ) ;
490
- get_functions_recurisve (
491
- r#try. finalbody ,
492
- map,
493
- functions,
494
- current_parent,
495
- current_class,
496
- lookup_name,
497
- ) ;
498
- }
499
- _ => { }
418
+ ) ;
500
419
}
501
420
}
502
421
// TODO save arg.defaults & arg.kwdefaults and attempt to map them to the write parameters
0 commit comments