diff options
author | Jean-Philippe DUFRAIGNE <j.dufraigne@gmail.com> | 2016-10-30 20:04:15 +0000 |
---|---|---|
committer | Jean-Philippe DUFRAIGNE <j.dufraigne@gmail.com> | 2016-10-31 14:10:42 +0000 |
commit | 7cc08b1e3b5aed7a402d290b5e663b9be86f87db (patch) | |
tree | e4d4be2a7bd9da0f4d081b5e7e15885520029a04 /src | |
parent | 850457028a92e73cfecf93996b99a7ee518ec4ef (diff) |
clang::Type::num_template_args return Option<u32> fix #135
Diffstat (limited to 'src')
-rwxr-xr-x | src/clang.rs | 19 | ||||
-rw-r--r-- | src/ir/comp.rs | 4 | ||||
-rw-r--r-- | src/ir/ty.rs | 2 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/clang.rs b/src/clang.rs index c48b45d5..69254a24 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -645,19 +645,22 @@ impl Type { } /// If this type is a class template specialization, return its number of - /// template arguments. Otherwise, return -1. - pub fn num_template_args(&self) -> c_int { - unsafe { - clang_Type_getNumTemplateArguments(self.x) + /// template arguments. Otherwise, return None. + pub fn num_template_args(&self) -> Option<u32> { + let n = unsafe { clang_Type_getNumTemplateArguments(self.x) }; + if n >= 0 { + Some(n as u32) + } else { + debug_assert_eq!(n, -1); + None } } /// Get the type of the `i`th template argument for this template /// specialization. - pub fn template_arg_type(&self, i: c_int) -> Type { - unsafe { - Type { x: clang_Type_getTemplateArgumentAsType(self.x, i) } - } + pub fn template_arg_type(&self, i: u32) -> Type { + let n = i as c_int; + Type { x: unsafe { clang_Type_getTemplateArgumentAsType(self.x, n) } } } /// Given that this type is a pointer type, return the type that it points diff --git a/src/ir/comp.rs b/src/ir/comp.rs index a8583607..b9e9ec8b 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -492,8 +492,8 @@ impl CompInfo { ci.template_args = match ty.num_template_args() { // In forward declarations and not specializations, etc, they are in // the ast, we'll meet them in CXCursor_TemplateTypeParameter - -1 => vec![], - len => { + None => vec![], + Some(len) => { let mut list = Vec::with_capacity(len as usize); for i in 0..len { let arg_type = ty.template_arg_type(i); diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 71512c31..b9816f6e 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -506,7 +506,7 @@ impl Type { TypeKind::Function(signature) // Same here, with template specialisations we can safely assume // this is a Comp(..) - } else if ty.num_template_args() > 0 { + } else if ty.num_template_args().unwrap_or(0) > 0 { debug!("Template specialization: {:?}", ty); let complex = CompInfo::from_ty(potential_id, ty, location, ctx) |