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 @@ -387,16 +387,26 @@ impl Cursor {
387
387
388
388
/// Given that this cursor's referent is a function, return cursors to its
389
389
/// parameters.
390
- pub fn args ( & self ) -> Vec < Cursor > {
390
+ pub fn args ( & self ) -> Option < Vec < Cursor > > {
391
+ // XXX: We might want to use and keep num_args
392
+ // match self.kind() {
393
+ // CXCursor_FunctionDecl |
394
+ // CXCursor_CXXMethod => {
391
395
unsafe {
392
- let num = self . num_args ( ) . expect ( "expected value, got none" ) as u32 ;
393
- let mut args = vec ! [ ] ;
394
- for i in 0 ..num {
395
- args. push ( Cursor {
396
- x : clang_Cursor_getArgument ( self . x , i as c_uint ) ,
397
- } ) ;
396
+ let w = clang_Cursor_getNumArguments ( self . x ) ;
397
+ if w == -1 {
398
+ None
399
+ } else {
400
+ let num = w as u32 ;
401
+
402
+ let mut args = vec ! [ ] ;
403
+ for i in 0 ..num {
404
+ args. push ( Cursor {
405
+ x : clang_Cursor_getArgument ( self . x , i as c_uint ) ,
406
+ } ) ;
407
+ }
408
+ Some ( args)
398
409
}
399
- args
400
410
}
401
411
}
402
412
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