File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -349,11 +349,15 @@ impl Cursor {
349
349
350
350
/// Get the signed constant value for this cursor's enum variant referent.
351
351
///
352
- /// Returns `LLONG_MIN` if the cursor's referent is not an enum variant,
353
- /// which is also a valid enum value, so callers should check the cursor
354
- /// kind before calling this method (see issue #127).
355
- pub fn enum_val_signed ( & self ) -> i64 {
356
- unsafe { clang_getEnumConstantDeclValue ( self . x ) as i64 }
352
+ /// Returns None if the cursor's referent is not an enum variant.
353
+ pub fn enum_val_signed ( & self ) -> Option < i64 > {
354
+ unsafe {
355
+ if self . kind ( ) == CXCursor_EnumConstantDecl {
356
+ Some ( clang_getEnumConstantDeclValue ( self . x ) as i64 )
357
+ } else {
358
+ None
359
+ }
360
+ }
357
361
}
358
362
359
363
/// Get the unsigned constant value for this cursor's enum variant referent.
Original file line number Diff line number Diff line change @@ -71,14 +71,18 @@ impl Enum {
71
71
} ;
72
72
73
73
declaration. visit ( |cursor| {
74
- if cursor. kind ( ) == CXCursor_EnumConstantDecl {
74
+ let val = if is_signed {
75
+ cursor. enum_val_signed ( ) . map ( EnumVariantValue :: Signed )
76
+ } else {
77
+ if cursor. kind ( ) == CXCursor_EnumConstantDecl {
78
+ Some ( EnumVariantValue :: Unsigned ( cursor. enum_val_unsigned ( ) ) )
79
+ } else {
80
+ None
81
+ }
82
+ } ;
83
+ if let Some ( val) = val {
75
84
let name = cursor. spelling ( ) ;
76
85
let comment = cursor. raw_comment ( ) ;
77
- let val = if is_signed {
78
- EnumVariantValue :: Signed ( cursor. enum_val_signed ( ) )
79
- } else {
80
- EnumVariantValue :: Unsigned ( cursor. enum_val_unsigned ( ) )
81
- } ;
82
86
variants. push ( EnumVariant :: new ( name, comment, val) ) ;
83
87
}
84
88
CXChildVisit_Continue
You can’t perform that action at this time.
0 commit comments