From 883ff74e5f20b68b41f322daa582d9208eece65a Mon Sep 17 00:00:00 2001 From: Emilio Cobos Álvarez Date: Mon, 12 Dec 2016 16:11:43 +0100 Subject: Add support for constructors, and integration tests. --- libbindgen/src/codegen/helpers.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libbindgen/src/codegen/helpers.rs') diff --git a/libbindgen/src/codegen/helpers.rs b/libbindgen/src/codegen/helpers.rs index f1a0f314..c09f0071 100644 --- a/libbindgen/src/codegen/helpers.rs +++ b/libbindgen/src/codegen/helpers.rs @@ -75,6 +75,7 @@ impl BlobTyBuilder { pub mod ast_ty { use aster; use ir::context::BindgenContext; + use ir::function::FunctionSig; use ir::ty::FloatKind; use syntax::ast; use syntax::ptr::P; @@ -164,4 +165,25 @@ pub mod ast_ty { let kind = ast::LitKind::FloatUnsuffixed(interned_str); aster::AstBuilder::new().expr().lit().build_lit(kind) } + + pub fn arguments_from_signature(signature: &FunctionSig, + ctx: &BindgenContext) + -> Vec> { + // TODO: We need to keep in sync the argument names, so we should unify + // this with the other loop that decides them. + let mut unnamed_arguments = 0; + signature.argument_types() + .iter() + .map(|&(ref name, _ty)| { + let arg_name = match *name { + Some(ref name) => ctx.rust_mangle(name).into_owned(), + None => { + unnamed_arguments += 1; + format!("arg{}", unnamed_arguments) + } + }; + aster::expr::ExprBuilder::new().id(arg_name) + }) + .collect::>() + } } -- cgit v1.2.3