diff options
Diffstat (limited to 'src/ir/function.rs')
-rw-r--r-- | src/ir/function.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs index 22b9c9b0..5864bbf8 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -1,12 +1,14 @@ //! Intermediate representation for C/C++ functions and methods. use super::context::{BindgenContext, ItemId}; +use super::dot::DotAttributes; use super::item::Item; -use super::traversal::{Trace, Tracer}; +use super::traversal::{EdgeKind, Trace, Tracer}; use super::ty::TypeKind; use clang; use clang_sys::CXCallingConv; use parse::{ClangItemParser, ClangSubItemParser, ParseError, ParseResult}; +use std::io; use syntax::abi; /// A function declaration, with a signature, arguments, and argument names. @@ -59,6 +61,18 @@ impl Function { } } +impl DotAttributes for Function { + fn dot_attributes<W>(&self, _ctx: &BindgenContext, out: &mut W) -> io::Result<()> + where W: io::Write + { + if let Some(ref mangled) = self.mangled_name { + try!(writeln!(out, "<tr><td>mangled name</td><td>{}</td></tr>", mangled)); + } + + Ok(()) + } +} + /// A function signature. #[derive(Debug)] pub struct FunctionSig { @@ -91,7 +105,13 @@ fn get_abi(cc: CXCallingConv) -> Option<abi::Abi> { } /// Get the mangled name for the cursor's referent. -pub fn cursor_mangling(cursor: &clang::Cursor) -> Option<String> { +pub fn cursor_mangling(ctx: &BindgenContext, + cursor: &clang::Cursor) + -> Option<String> { + if !ctx.options().enable_mangling { + return None; + } + // We early return here because libclang may crash in some case // if we pass in a variable inside a partial specialized template. // See servo/rust-bindgen#67, and servo/rust-bindgen#462. @@ -304,7 +324,7 @@ impl ClangSubItemParser for Function { let name = cursor.spelling(); assert!(!name.is_empty(), "Empty function name?"); - let mut mangled_name = cursor_mangling(&cursor); + let mut mangled_name = cursor_mangling(context, &cursor); if mangled_name.as_ref() == Some(&name) { mangled_name = None; } @@ -322,10 +342,10 @@ impl Trace for FunctionSig { fn trace<T>(&self, _: &BindgenContext, tracer: &mut T, _: &()) where T: Tracer, { - tracer.visit(self.return_type()); + tracer.visit_kind(self.return_type(), EdgeKind::FunctionReturn); for &(_, ty) in self.argument_types() { - tracer.visit(ty); + tracer.visit_kind(ty, EdgeKind::FunctionParameter); } } } |