diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-07 07:10:53 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 07:10:53 -0600 |
commit | c314a2f1b3b70a1322a23f785995124941ed632a (patch) | |
tree | e1a2edda0f940c68824e1b2207ded5c957515b11 | |
parent | b47f405c0d1ee4235f380d787e603687c8cd57e4 (diff) | |
parent | feb6f673d3261fc249032a7fe281ea7b4135a8f9 (diff) |
Auto merge of #222 - afluth:enum_val_unsigned_option, r=emilio
Wrap enum_val_unsigned in an Option
Patterned after the changes merged in #220.
Fixes #128
-rwxr-xr-x | src/clang.rs | 14 | ||||
-rw-r--r-- | src/ir/enum_ty.rs | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/clang.rs b/src/clang.rs index 0bfd78ef..a11e2924 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -362,11 +362,15 @@ impl Cursor { /// Get the unsigned constant value for this cursor's enum variant referent. /// - /// Returns `ULLONG_MAX` if the cursor's referent is not an enum variant, - /// which is also a valid enum value, so callers should check the cursor - /// kind before calling this method (see issue #128). - pub fn enum_val_unsigned(&self) -> u64 { - unsafe { clang_getEnumConstantDeclUnsignedValue(self.x) as u64 } + /// Returns None if the cursor's referent is not an enum variant. + pub fn enum_val_unsigned(&self) -> Option<u64> { + unsafe { + if self.kind() == CXCursor_EnumConstantDecl { + Some(clang_getEnumConstantDeclUnsignedValue(self.x) as u64) + } else { + None + } + } } /// Given that this cursor's referent is a `typedef`, get the `Type` that is diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 1bcd5b14..8efd9e3b 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -75,7 +75,7 @@ impl Enum { let value = if is_signed { cursor.enum_val_signed().map(EnumVariantValue::Signed) } else { - Some(EnumVariantValue::Unsigned(cursor.enum_val_unsigned())) + cursor.enum_val_unsigned().map(EnumVariantValue::Unsigned) }; if let Some(val) = value { let name = cursor.spelling(); |