diff --git a/gen/src/write.rs b/gen/src/write.rs index 1aa128ff..60936a0b 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -159,7 +159,7 @@ fn pick_includes_and_builtins(out: &mut OutFile, apis: &[Api]) { Some(Isize) => out.builtin.rust_isize = true, Some(CxxString) => out.include.string = true, Some(RustString) => out.builtin.rust_string = true, - Some(Bool) | Some(F32) | Some(F64) | None => {} + Some(Bool) | Some(Char) | Some(F32) | Some(F64) | None => {} }, Type::RustBox(_) => out.builtin.rust_box = true, Type::RustVec(_) => out.builtin.rust_vec = true, @@ -924,6 +924,7 @@ fn write_type(out: &mut OutFile, ty: &Type) { fn write_atom(out: &mut OutFile, atom: Atom) { match atom { Bool => write!(out, "bool"), + Char => write!(out, "char"), U8 => write!(out, "uint8_t"), U16 => write!(out, "uint16_t"), U32 => write!(out, "uint32_t"), diff --git a/syntax/atom.rs b/syntax/atom.rs index 7d0ef6b6..d4ad78f1 100644 --- a/syntax/atom.rs +++ b/syntax/atom.rs @@ -5,6 +5,7 @@ use std::fmt::{self, Display}; #[derive(Copy, Clone, PartialEq)] pub enum Atom { Bool, + Char, // C char, not Rust char U8, U16, U32, @@ -30,6 +31,7 @@ impl Atom { use self::Atom::*; match s { "bool" => Some(Bool), + "c_char" => Some(Char), "u8" => Some(U8), "u16" => Some(U16), "u32" => Some(U32), @@ -60,6 +62,7 @@ impl AsRef for Atom { use self::Atom::*; match self { Bool => "bool", + Char => "c_char", U8 => "u8", U16 => "u16", U32 => "u32", diff --git a/syntax/check.rs b/syntax/check.rs index f5e8e00c..cdf174c8 100644 --- a/syntax/check.rs +++ b/syntax/check.rs @@ -102,7 +102,7 @@ fn check_type_rust_vec(cx: &mut Check, ty: &Ty1) { None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) | Some(RustString) => return, - Some(Bool) => { /* todo */ } + Some(Bool) | Some(Char) => { /* todo */ } Some(CxxString) => {} } } @@ -140,6 +140,7 @@ fn check_type_cxx_vector(cx: &mut Check, ptr: &Ty1) { None | Some(U8) | Some(U16) | Some(U32) | Some(U64) | Some(Usize) | Some(I8) | Some(I16) | Some(I32) | Some(I64) | Some(Isize) | Some(F32) | Some(F64) | Some(CxxString) => return, + Some(Char) => { /* todo */ } Some(Bool) | Some(RustString) => {} } } @@ -503,6 +504,8 @@ fn describe(cx: &mut Check, ty: &Type) -> String { "opaque Rust type".to_owned() } else if Atom::from(&ident.rust) == Some(CxxString) { "C++ string".to_owned() + } else if Atom::from(&ident.rust) == Some(Char) { + "C char".to_owned() } else { ident.rust.to_string() } diff --git a/syntax/tokens.rs b/syntax/tokens.rs index 8ce7ed9e..d450f730 100644 --- a/syntax/tokens.rs +++ b/syntax/tokens.rs @@ -11,7 +11,10 @@ impl ToTokens for Type { fn to_tokens(&self, tokens: &mut TokenStream) { match self { Type::Ident(ident) => { - if ident.rust == CxxString { + if ident.rust == Char { + let span = ident.rust.span(); + tokens.extend(quote_spanned!(span=> ::std::os::raw::)); + } else if ident.rust == CxxString { let span = ident.rust.span(); tokens.extend(quote_spanned!(span=> ::cxx::)); }