Skip to content

change return value of Type::pointee_type() to Option<Type> #203

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 5, 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
16 changes: 12 additions & 4 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,19 @@ impl Type {

/// Given that this type is a pointer type, return the type that it points
/// to.
pub fn pointee_type(&self) -> Type {
unsafe {
Type {
x: clang_getPointeeType(self.x),
pub fn pointee_type(&self) -> Option<Type> {
match self.kind() {
CXType_Pointer |
CXType_RValueReference |
CXType_LValueReference |
CXType_MemberPointer => {
let ret = Type {
x: unsafe { clang_getPointeeType(self.x) },
};
debug_assert!(ret.kind() != CXType_Invalid);
Some(ret)
}
_ => None,
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,19 @@ impl Type {
// process of resolving them.
CXType_MemberPointer |
CXType_Pointer => {
let inner = Item::from_ty_or_ref(ty.pointee_type(),
location,
parent_id,
ctx);
let inner =
Item::from_ty_or_ref(ty.pointee_type().unwrap(), location,
parent_id, ctx);
TypeKind::Pointer(inner)
}
CXType_BlockPointer => TypeKind::BlockPointer,
// XXX: RValueReference is most likely wrong, but I don't think we
// can even add bindings for that, so huh.
CXType_RValueReference |
CXType_LValueReference => {
let inner = Item::from_ty_or_ref(ty.pointee_type(),
location,
parent_id,
ctx);
let inner =
Item::from_ty_or_ref(ty.pointee_type().unwrap(), location,
parent_id, ctx);
TypeKind::Reference(inner)
}
// XXX DependentSizedArray is wrong
Expand Down