File tree 2 files changed +19
-9
lines changed
2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -420,16 +420,26 @@ impl Cursor {
420
420
421
421
/// Given that this cursor's referent is a function, return cursors to its
422
422
/// parameters.
423
- pub fn args ( & self ) -> Vec < Cursor > {
423
+ pub fn args ( & self ) -> Option < Vec < Cursor > > {
424
+ // XXX: We might want to use and keep num_args
425
+ // match self.kind() {
426
+ // CXCursor_FunctionDecl |
427
+ // CXCursor_CXXMethod => {
424
428
unsafe {
425
- let num = self . num_args ( ) . expect ( "expected value, got none" ) as u32 ;
426
- let mut args = vec ! [ ] ;
427
- for i in 0 ..num {
428
- args. push ( Cursor {
429
- x : clang_Cursor_getArgument ( self . x , i as c_uint ) ,
430
- } ) ;
429
+ let w = clang_Cursor_getNumArguments ( self . x ) ;
430
+ if w == -1 {
431
+ None
432
+ } else {
433
+ let num = w as u32 ;
434
+
435
+ let mut args = vec ! [ ] ;
436
+ for i in 0 ..num {
437
+ args. push ( Cursor {
438
+ x : clang_Cursor_getArgument ( self . x , i as c_uint ) ,
439
+ } ) ;
440
+ }
441
+ Some ( args)
431
442
}
432
- args
433
443
}
434
444
}
435
445
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ impl FunctionSig {
150
150
CXCursor_CXXMethod => {
151
151
// For CXCursor_FunctionDecl, cursor.args() is the reliable way
152
152
// to get parameter names and types.
153
- cursor. args ( )
153
+ cursor. args ( ) . expect ( "It cannot be None because we are in a method/function" )
154
154
. iter ( )
155
155
. map ( |arg| {
156
156
let arg_ty = arg. cur_type ( ) ;
You can’t perform that action at this time.
0 commit comments