Skip to content

Commit

Permalink
Handle ABIs in fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Jun 22, 2017
1 parent f4835aa commit 73b72c1
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,15 +1054,7 @@ impl<'a> Generator<'a> {
.connect(", ") + if variadic {", ..."} else {""}
};
let cret = self.rust_ty_to_c_ty(ret);
let abi = match abi {
Abi::C => "",
Abi::Stdcall => "__stdcall ",
Abi::System if self.target.contains("i686-pc-windows") => {
"__stdcall "
}
Abi::System => "",
a => panic!("unknown ABI: {}", a),
};
let abi = self.abi2str(abi);
t!(writeln!(self.c, r#"
{ret} ({abi}*__test_fn_{name}(void))({args}) {{
return {cname};
Expand Down Expand Up @@ -1176,12 +1168,13 @@ impl<'a> Generator<'a> {
ast::TyKind::BareFn(ref t) => {
assert!(t.lifetimes.len() == 0);
let (ret, mut args, variadic) = self.decl2rust(&t.decl);
let abi = self.abi2str(t.abi);
if variadic {
args.push("...".to_string());
} else if args.len() == 0 {
args.push("void".to_string());
}
format!("{}(**{})({})", ret, sig, args.connect(", "))
format!("{}({}**{})({})", ret, abi, sig, args.connect(", "))
}
ast::TyKind::FixedLengthVec(ref t, ref e) => {
format!("{}(*{})[{}]", self.ty2name(t, false), sig,
Expand All @@ -1207,6 +1200,18 @@ impl<'a> Generator<'a> {
}
}

fn abi2str(&self, abi: Abi) -> &'static str {
match abi {
Abi::C => "",
Abi::Stdcall => "__stdcall ",
Abi::System if self.target.contains("i686-pc-windows") => {
"__stdcall "
}
Abi::System => "",
a => panic!("unknown ABI: {}", a),
}
}

fn decl2rust(&self, decl: &ast::FnDecl) -> (String, Vec<String>, bool) {
let args = decl.inputs.iter().map(|arg| {
self.ty2name(&arg.ty, false)
Expand Down

0 comments on commit 73b72c1

Please sign in to comment.