summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-01 05:17:25 -0500
committerGitHub <noreply@github.com>2016-11-01 05:17:25 -0500
commitdaa9ab77c2ade0967a53d76903ee647bfc3d86a0 (patch)
tree670cf06e522f2c122a1de46ecc03b4eda8fed55d
parent63fc240831908fcbe0594275eafe4c5ccf4933d5 (diff)
parent24bb8e17f3564ad99650c69c9af46ac4456d93ad (diff)
Auto merge of #178 - Incognitas:master, r=fitzgen
Fix for #138 : rework for elem_type() which now returns Option<Type> instead of Type Fixes #138 Since I am new to Rust, I hope I didn't do things too badly
-rwxr-xr-xsrc/clang.rs9
-rw-r--r--src/ir/ty.rs12
2 files changed, 15 insertions, 6 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 32eab978..f9b3e083 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -673,9 +673,12 @@ impl Type {
/// Given that this type is an array, vector, or complex type, return the
/// type of its elements.
- pub fn elem_type(&self) -> Type {
- unsafe {
- Type { x: clang_getElementType(self.x) }
+ pub fn elem_type(&self) -> Option<Type> {
+ let current_type = Type { x: unsafe { clang_getElementType(self.x) } };
+ if current_type.kind() != CXType_Invalid {
+ Some(current_type)
+ } else {
+ None
}
}
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index fa37dd03..59f12eb8 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -663,7 +663,9 @@ impl Type {
CXType_VariableArray |
CXType_DependentSizedArray |
CXType_IncompleteArray => {
- let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
+ let inner = Item::from_ty(ty.elem_type().as_ref()
+ .expect("Not an appropriate type?"),
+ location, parent_id, ctx)
.expect("Not able to resolve array element?");
TypeKind::Pointer(inner)
}
@@ -695,14 +697,18 @@ impl Type {
// That being said, that should be fixed eventually.
CXType_Vector |
CXType_ConstantArray => {
- let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
+ let inner = Item::from_ty(ty.elem_type().as_ref()
+ .expect("Not an appropriate type?"),
+ location, parent_id, ctx)
.expect("Not able to resolve array element?");
TypeKind::Array(inner, ty.num_elements().unwrap())
}
// A complex number is always a real and an imaginary part, so
// represent that as a two-item array.
CXType_Complex => {
- let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
+ let inner = Item::from_ty(ty.elem_type().as_ref()
+ .expect("Not an appropriate type?"),
+ location, parent_id, ctx)
.expect("Not able to resolve array element?");
TypeKind::Array(inner, 2)
}