aboutsummaryrefslogtreecommitdiff
path: root/src/ir/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/function.rs')
-rw-r--r--src/ir/function.rs37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs
index a6f63a6..a3a2bbf 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -28,7 +28,9 @@ pub enum FunctionKind {
}
impl FunctionKind {
- fn from_cursor(cursor: &clang::Cursor) -> Option<FunctionKind> {
+ /// Given a clang cursor, return the kind of function it represents, or
+ /// `None` otherwise.
+ pub fn from_cursor(cursor: &clang::Cursor) -> Option<FunctionKind> {
// FIXME(emilio): Deduplicate logic with `ir::comp`.
Some(match cursor.kind() {
clang_sys::CXCursor_FunctionDecl => FunctionKind::Function,
@@ -121,7 +123,7 @@ impl Function {
/// Get this function's name.
pub fn mangled_name(&self) -> Option<&str> {
- self.mangled_name.as_ref().map(|n| &**n)
+ self.mangled_name.as_deref()
}
/// Get this function's signature type.
@@ -185,10 +187,7 @@ pub enum Abi {
impl Abi {
/// Returns whether this Abi is known or not.
fn is_unknown(&self) -> bool {
- match *self {
- Abi::Unknown(..) => true,
- _ => false,
- }
+ matches!(*self, Abi::Unknown(..))
}
}
@@ -338,7 +337,7 @@ fn args_from_ty_and_cursor(
});
let cursor = arg_cur.unwrap_or(*cursor);
- let ty = arg_ty.unwrap_or(cursor.cur_type());
+ let ty = arg_ty.unwrap_or_else(|| cursor.cur_type());
(name, Item::from_ty_or_ref(ty, cursor, None, ctx))
})
.collect()
@@ -358,7 +357,7 @@ impl FunctionSig {
argument_types,
is_variadic,
must_use,
- abi: abi,
+ abi,
}
}
@@ -409,7 +408,7 @@ impl FunctionSig {
CXCursor_CXXMethod |
CXCursor_ObjCInstanceMethodDecl |
CXCursor_ObjCClassMethodDecl => {
- args_from_ty_and_cursor(&ty, &cursor, ctx)
+ args_from_ty_and_cursor(ty, &cursor, ctx)
}
_ => {
// For non-CXCursor_FunctionDecl, visiting the cursor's children
@@ -432,7 +431,7 @@ impl FunctionSig {
// right AST for functions tagged as stdcall and such...
//
// https://bugs.llvm.org/show_bug.cgi?id=45919
- args_from_ty_and_cursor(&ty, &cursor, ctx)
+ args_from_ty_and_cursor(ty, &cursor, ctx)
} else {
args
}
@@ -520,7 +519,7 @@ impl FunctionSig {
warn!("Unknown calling convention: {:?}", call_conv);
}
- Ok(Self::new(ret.into(), args, ty.is_variadic(), must_use, abi))
+ Ok(Self::new(ret, args, ty.is_variadic(), must_use, abi))
}
/// Get this function signature's return type.
@@ -565,10 +564,7 @@ impl FunctionSig {
return false;
}
- match self.abi {
- Abi::C | Abi::Unknown(..) => true,
- _ => false,
- }
+ matches!(self.abi, Abi::C | Abi::Unknown(..))
}
}
@@ -595,10 +591,13 @@ impl ClangSubItemParser for Function {
return Err(ParseError::Continue);
}
- if !context.options().generate_inline_functions &&
- cursor.is_inlined_function()
- {
- return Err(ParseError::Continue);
+ if cursor.is_inlined_function() {
+ if !context.options().generate_inline_functions {
+ return Err(ParseError::Continue);
+ }
+ if cursor.is_deleted_function() {
+ return Err(ParseError::Continue);
+ }
}
let linkage = cursor.linkage();