mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-28 01:41:05 +00:00
Move C++-specific to_typename to C++ code generator
This commit is contained in:
parent
3b40b6f8f0
commit
2eca4a0ce9
30
gen/write.rs
30
gen/write.rs
@ -4,7 +4,6 @@ use crate::syntax::atom::Atom::{self, *};
|
||||
use crate::syntax::mangled::to_mangled;
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use crate::syntax::symbol::Symbol;
|
||||
use crate::syntax::typename::to_typename;
|
||||
use crate::syntax::{mangle, Api, ExternFn, ExternType, Signature, Struct, Type, Types, Var};
|
||||
use proc_macro2::Ident;
|
||||
use std::collections::HashMap;
|
||||
@ -889,6 +888,35 @@ fn write_space_after_type(out: &mut OutFile, ty: &Type) {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_typename(namespace: &Namespace, ty: &Type) -> String {
|
||||
match ty {
|
||||
Type::Ident(ident) => {
|
||||
let mut inner = String::new();
|
||||
// Do not apply namespace to built-in type
|
||||
let is_user_type = Atom::from(ident).is_none();
|
||||
if is_user_type {
|
||||
for name in namespace {
|
||||
inner += name;
|
||||
inner += "::";
|
||||
}
|
||||
}
|
||||
if let Some(ti) = Atom::from(ident) {
|
||||
inner += ti.to_cxx();
|
||||
} else {
|
||||
inner += &ident.to_string();
|
||||
};
|
||||
inner
|
||||
}
|
||||
Type::RustBox(ptr) => format!("rust_box<{}>", to_typename(namespace, &ptr.inner)),
|
||||
Type::RustVec(ptr) => format!("rust_vec<{}>", to_typename(namespace, &ptr.inner)),
|
||||
Type::UniquePtr(ptr) => {
|
||||
format!("::std::unique_ptr<{}>", to_typename(namespace, &ptr.inner))
|
||||
}
|
||||
Type::CxxVector(ptr) => format!("::std::vector<{}>", to_typename(namespace, &ptr.inner)),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn write_generic_instantiations(out: &mut OutFile, types: &Types) {
|
||||
fn allow_unique_ptr(ident: &Ident) -> bool {
|
||||
Atom::from(ident).is_none()
|
||||
|
@ -14,7 +14,6 @@ mod parse;
|
||||
pub mod set;
|
||||
pub mod symbol;
|
||||
mod tokens;
|
||||
pub mod typename;
|
||||
pub mod types;
|
||||
|
||||
use self::parse::kw;
|
||||
|
@ -1,31 +0,0 @@
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use crate::syntax::{Atom, Type};
|
||||
|
||||
pub fn to_typename(namespace: &Namespace, ty: &Type) -> String {
|
||||
match ty {
|
||||
Type::Ident(ident) => {
|
||||
let mut inner = String::new();
|
||||
// Do not apply namespace to built-in type
|
||||
let is_user_type = Atom::from(ident).is_none();
|
||||
if is_user_type {
|
||||
for name in namespace {
|
||||
inner += name;
|
||||
inner += "::";
|
||||
}
|
||||
}
|
||||
if let Some(ti) = Atom::from(ident) {
|
||||
inner += ti.to_cxx();
|
||||
} else {
|
||||
inner += &ident.to_string();
|
||||
};
|
||||
inner
|
||||
}
|
||||
Type::RustBox(ptr) => format!("rust_box<{}>", to_typename(namespace, &ptr.inner)),
|
||||
Type::RustVec(ptr) => format!("rust_vec<{}>", to_typename(namespace, &ptr.inner)),
|
||||
Type::UniquePtr(ptr) => {
|
||||
format!("::std::unique_ptr<{}>", to_typename(namespace, &ptr.inner))
|
||||
}
|
||||
Type::CxxVector(ptr) => format!("::std::vector<{}>", to_typename(namespace, &ptr.inner)),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user