mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 07:10:29 +00:00
Support c_char type
This commit is contained in:
parent
248215e206
commit
b3873dcd10
@ -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"),
|
||||
|
@ -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<str> for Atom {
|
||||
use self::Atom::*;
|
||||
match self {
|
||||
Bool => "bool",
|
||||
Char => "c_char",
|
||||
U8 => "u8",
|
||||
U16 => "u16",
|
||||
U32 => "u32",
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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::));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user