diff options
author | Aurélien Normand <inognitas@bitbucket.org> | 2016-10-31 23:30:34 +0100 |
---|---|---|
committer | Aurélien Normand <inognitas@bitbucket.org> | 2016-10-31 23:30:34 +0100 |
commit | 24bb8e17f3564ad99650c69c9af46ac4456d93ad (patch) | |
tree | 699b927a4be7c6f7e1e4b67b7562b83a30cb9c88 | |
parent | 4ab18e6bc3bd91af27551af031340818316fa0fc (diff) |
rework for elem_type() which now returns Option<Type> instead of Type
-rwxr-xr-x | src/clang.rs | 9 | ||||
-rw-r--r-- | src/ir/ty.rs | 12 |
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 9881c653..25b11927 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -662,7 +662,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) } @@ -694,14 +696,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) } |