Skip to content

Wrap enum_val_unsigned in an Option #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ir/enum_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down