summaryrefslogtreecommitdiff
path: root/src/ir/function.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ir/function.rs')
-rw-r--r--src/ir/function.rs113
1 files changed, 69 insertions, 44 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 241dcefe..3cf48db7 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -8,7 +8,8 @@ use super::traversal::{EdgeKind, Trace, Tracer};
use super::ty::TypeKind;
use clang;
use clang_sys::{self, CXCallingConv};
-use ir::derive::{CanTriviallyDeriveDebug, CanTriviallyDeriveHash, CanTriviallyDerivePartialEq};
+use ir::derive::{CanTriviallyDeriveDebug, CanTriviallyDeriveHash,
+ CanTriviallyDerivePartialEq};
use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult};
use std::io;
use syntax::abi;
@@ -28,8 +29,12 @@ impl FunctionKind {
fn from_cursor(cursor: &clang::Cursor) -> Option<FunctionKind> {
Some(match cursor.kind() {
clang_sys::CXCursor_FunctionDecl => FunctionKind::Function,
- clang_sys::CXCursor_Constructor => FunctionKind::Method(MethodKind::Constructor),
- clang_sys::CXCursor_Destructor => FunctionKind::Method(MethodKind::Destructor),
+ clang_sys::CXCursor_Constructor => FunctionKind::Method(
+ MethodKind::Constructor,
+ ),
+ clang_sys::CXCursor_Destructor => FunctionKind::Method(
+ MethodKind::Destructor,
+ ),
clang_sys::CXCursor_CXXMethod => {
if cursor.method_is_virtual() {
FunctionKind::Method(MethodKind::Virtual)
@@ -68,12 +73,13 @@ pub struct Function {
impl Function {
/// Construct a new function.
- pub fn new(name: String,
- mangled_name: Option<String>,
- sig: ItemId,
- comment: Option<String>,
- kind: FunctionKind)
- -> Self {
+ pub fn new(
+ name: String,
+ mangled_name: Option<String>,
+ sig: ItemId,
+ comment: Option<String>,
+ kind: FunctionKind,
+ ) -> Self {
Function {
name: name,
mangled_name: mangled_name,
@@ -105,17 +111,22 @@ impl Function {
}
impl DotAttributes for Function {
- fn dot_attributes<W>(&self,
- _ctx: &BindgenContext,
- out: &mut W)
- -> io::Result<()>
- where W: io::Write,
+ fn dot_attributes<W>(
+ &self,
+ _ctx: &BindgenContext,
+ out: &mut W,
+ ) -> io::Result<()>
+ where
+ W: io::Write,
{
if let Some(ref mangled) = self.mangled_name {
- let mangled: String = mangled.chars().flat_map(|c| c.escape_default()).collect();
- try!(writeln!(out,
- "<tr><td>mangled name</td><td>{}</td></tr>",
- mangled));
+ let mangled: String =
+ mangled.chars().flat_map(|c| c.escape_default()).collect();
+ try!(writeln!(
+ out,
+ "<tr><td>mangled name</td><td>{}</td></tr>",
+ mangled
+ ));
}
Ok(())
@@ -176,18 +187,23 @@ fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) {
match symbol.chars().next().unwrap() {
// Stripping leading underscore for all names on Darwin and
// C linkage functions on Win32.
- '_' => { symbol.remove(0); }
+ '_' => {
+ symbol.remove(0);
+ }
// Stop Rust from prepending underscore for variables on Win32.
- '?' => { symbol.insert(0, '\x01'); }
+ '?' => {
+ symbol.insert(0, '\x01');
+ }
_ => {}
}
}
}
/// Get the mangled name for the cursor's referent.
-pub fn cursor_mangling(ctx: &BindgenContext,
- cursor: &clang::Cursor)
- -> Option<String> {
+pub fn cursor_mangling(
+ ctx: &BindgenContext,
+ cursor: &clang::Cursor,
+) -> Option<String> {
use clang_sys;
if !ctx.options().enable_mangling {
return None;
@@ -246,11 +262,12 @@ pub fn cursor_mangling(ctx: &BindgenContext,
impl FunctionSig {
/// Construct a new function signature.
- pub fn new(return_type: ItemId,
- arguments: Vec<(Option<String>, ItemId)>,
- is_variadic: bool,
- abi: Abi)
- -> Self {
+ pub fn new(
+ return_type: ItemId,
+ arguments: Vec<(Option<String>, ItemId)>,
+ is_variadic: bool,
+ abi: Abi,
+ ) -> Self {
FunctionSig {
return_type: return_type,
argument_types: arguments,
@@ -260,10 +277,11 @@ impl FunctionSig {
}
/// Construct a new function signature from the given Clang type.
- pub fn from_ty(ty: &clang::Type,
- cursor: &clang::Cursor,
- ctx: &mut BindgenContext)
- -> Result<Self, ParseError> {
+ pub fn from_ty(
+ ty: &clang::Type,
+ cursor: &clang::Cursor,
+ ctx: &mut BindgenContext,
+ ) -> Result<Self, ParseError> {
use clang_sys::*;
debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor);
@@ -292,7 +310,8 @@ impl FunctionSig {
CXCursor_ObjCClassMethodDecl => {
// For CXCursor_FunctionDecl, cursor.args() is the reliable way
// to get parameter names and types.
- cursor.args()
+ cursor
+ .args()
.unwrap()
.iter()
.map(|arg| {
@@ -328,7 +347,8 @@ impl FunctionSig {
let is_constructor = cursor.kind() == CXCursor_Constructor;
let is_destructor = cursor.kind() == CXCursor_Destructor;
if (is_constructor || is_destructor || is_method) &&
- cursor.lexical_parent() != cursor.semantic_parent() {
+ cursor.lexical_parent() != cursor.semantic_parent()
+ {
// Only parse constructors once.
return Err(ParseError::Continue);
}
@@ -352,10 +372,11 @@ impl FunctionSig {
}
let ty_ret_type = if cursor.kind() == CXCursor_ObjCInstanceMethodDecl ||
- cursor.kind() == CXCursor_ObjCClassMethodDecl {
- try!(ty.ret_type()
- .or_else(|| cursor.ret_type())
- .ok_or(ParseError::Continue))
+ cursor.kind() == CXCursor_ObjCClassMethodDecl
+ {
+ try!(ty.ret_type().or_else(|| cursor.ret_type()).ok_or(
+ ParseError::Continue,
+ ))
} else {
try!(ty.ret_type().ok_or(ParseError::Continue))
};
@@ -395,9 +416,10 @@ impl FunctionSig {
}
impl ClangSubItemParser for Function {
- fn parse(cursor: clang::Cursor,
- context: &mut BindgenContext)
- -> Result<ParseResult<Self>, ParseError> {
+ fn parse(
+ cursor: clang::Cursor,
+ context: &mut BindgenContext,
+ ) -> Result<ParseResult<Self>, ParseError> {
use clang_sys::*;
let kind = match FunctionKind::from_cursor(&cursor) {
@@ -417,13 +439,15 @@ impl ClangSubItemParser for Function {
}
if !context.options().generate_inline_functions &&
- cursor.is_inlined_function() {
+ cursor.is_inlined_function()
+ {
return Err(ParseError::Continue);
}
let linkage = cursor.linkage();
if linkage != CXLinkage_External &&
- linkage != CXLinkage_UniqueExternal {
+ linkage != CXLinkage_UniqueExternal
+ {
return Err(ParseError::Continue);
}
@@ -464,7 +488,8 @@ impl Trace for FunctionSig {
type Extra = ();
fn trace<T>(&self, _: &BindgenContext, tracer: &mut T, _: &())
- where T: Tracer,
+ where
+ T: Tracer,
{
tracer.visit_kind(self.return_type(), EdgeKind::FunctionReturn);