summaryrefslogtreecommitdiff
path: root/src/codegen/helpers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen/helpers.rs')
-rw-r--r--src/codegen/helpers.rs66
1 files changed, 46 insertions, 20 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 4a64f799..2bc3ad44 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -11,19 +11,35 @@ pub mod attributes {
use syntax::ast;
pub fn allow(which_ones: &[&str]) -> ast::Attribute {
- aster::AstBuilder::new().attr().list("allow").words(which_ones).build()
+ aster::AstBuilder::new()
+ .attr()
+ .list("allow")
+ .words(which_ones)
+ .build()
}
pub fn repr(which: &str) -> ast::Attribute {
- aster::AstBuilder::new().attr().list("repr").words(&[which]).build()
+ aster::AstBuilder::new()
+ .attr()
+ .list("repr")
+ .words(&[which])
+ .build()
}
pub fn repr_list(which_ones: &[&str]) -> ast::Attribute {
- aster::AstBuilder::new().attr().list("repr").words(which_ones).build()
+ aster::AstBuilder::new()
+ .attr()
+ .list("repr")
+ .words(which_ones)
+ .build()
}
pub fn derives(which_ones: &[&str]) -> ast::Attribute {
- aster::AstBuilder::new().attr().list("derive").words(which_ones).build()
+ aster::AstBuilder::new()
+ .attr()
+ .list("derive")
+ .words(which_ones)
+ .build()
}
pub fn inline() -> ast::Attribute {
@@ -35,7 +51,10 @@ pub mod attributes {
}
pub fn link_name(name: &str) -> ast::Attribute {
- aster::AstBuilder::new().attr().name_value("link_name").str(name)
+ aster::AstBuilder::new()
+ .attr()
+ .name_value("link_name")
+ .str(name)
}
}
@@ -97,9 +116,10 @@ pub mod ast_ty {
}
}
- pub fn float_kind_rust_type(ctx: &BindgenContext,
- fk: FloatKind)
- -> P<ast::Ty> {
+ pub fn float_kind_rust_type(
+ ctx: &BindgenContext,
+ fk: FloatKind,
+ ) -> P<ast::Ty> {
// TODO: we probably should just take the type layout into
// account?
//
@@ -153,14 +173,17 @@ pub mod ast_ty {
pub fn cstr_expr(mut string: String) -> P<ast::Expr> {
string.push('\0');
- aster::AstBuilder::new()
- .expr()
- .build_lit(aster::AstBuilder::new().lit().byte_str(string))
+ aster::AstBuilder::new().expr().build_lit(
+ aster::AstBuilder::new()
+ .lit()
+ .byte_str(string),
+ )
}
- pub fn float_expr(ctx: &BindgenContext,
- f: f64)
- -> Result<P<ast::Expr>, ()> {
+ pub fn float_expr(
+ ctx: &BindgenContext,
+ f: f64,
+ ) -> Result<P<ast::Expr>, ()> {
use aster::symbol::ToSymbol;
if f.is_finite() {
@@ -171,8 +194,9 @@ pub mod ast_ty {
string.push('.');
}
- let kind = ast::LitKind::FloatUnsuffixed(string.as_str().to_symbol());
- return Ok(aster::AstBuilder::new().expr().lit().build_lit(kind))
+ let kind =
+ ast::LitKind::FloatUnsuffixed(string.as_str().to_symbol());
+ return Ok(aster::AstBuilder::new().expr().lit().build_lit(kind));
}
let prefix = ctx.trait_prefix();
@@ -192,13 +216,15 @@ pub mod ast_ty {
return Err(());
}
- pub fn arguments_from_signature(signature: &FunctionSig,
- ctx: &BindgenContext)
- -> Vec<P<ast::Expr>> {
+ 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()
+ signature
+ .argument_types()
.iter()
.map(|&(ref name, _ty)| {
let arg_name = match *name {