summaryrefslogtreecommitdiff
path: root/libbindgen/src/codegen/helpers.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2016-12-12 16:11:43 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2016-12-13 14:33:01 +0100
commit883ff74e5f20b68b41f322daa582d9208eece65a (patch)
tree10f0c8aa40dad4a9b48d8a705761074fff9036d3 /libbindgen/src/codegen/helpers.rs
parent5d9c48e59b49135db1ecfd4ff8c3dbab8ed05086 (diff)
Add support for constructors, and integration tests.
Diffstat (limited to 'libbindgen/src/codegen/helpers.rs')
-rw-r--r--libbindgen/src/codegen/helpers.rs22
1 files changed, 22 insertions, 0 deletions
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<P<ast::Expr>> {
+ // 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::<Vec<_>>()
+ }
}