mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-24 07:40:19 +00:00
Move C++-only to_mangled function to C++ generator
This commit is contained in:
parent
83a7ec9901
commit
bae50eff4e
24
gen/write.rs
24
gen/write.rs
@ -1,7 +1,6 @@
|
||||
use crate::gen::out::OutFile;
|
||||
use crate::gen::{include, Opt};
|
||||
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::{mangle, Api, ExternFn, ExternType, Signature, Struct, Type, Types, Var};
|
||||
@ -921,6 +920,29 @@ fn to_typename(namespace: &Namespace, ty: &Type) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn to_mangled(namespace: &Namespace, ty: &Type) -> String {
|
||||
match ty {
|
||||
Type::Ident(ident) => {
|
||||
let mut instance = 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 {
|
||||
instance += name;
|
||||
instance += "$";
|
||||
}
|
||||
}
|
||||
instance += &ident.to_string();
|
||||
instance
|
||||
}
|
||||
Type::RustBox(ptr) => format!("rust_box${}", to_mangled(namespace, &ptr.inner)),
|
||||
Type::RustVec(ptr) => format!("rust_vec${}", to_mangled(namespace, &ptr.inner)),
|
||||
Type::UniquePtr(ptr) => format!("std$unique_ptr${}", to_mangled(namespace, &ptr.inner)),
|
||||
Type::CxxVector(ptr) => format!("std$vector${}", to_mangled(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()
|
||||
|
@ -1,25 +0,0 @@
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use crate::syntax::{Atom, Type};
|
||||
|
||||
pub fn to_mangled(namespace: &Namespace, ty: &Type) -> String {
|
||||
match ty {
|
||||
Type::Ident(ident) => {
|
||||
let mut instance = 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 {
|
||||
instance += name;
|
||||
instance += "$";
|
||||
}
|
||||
}
|
||||
instance += &ident.to_string();
|
||||
instance
|
||||
}
|
||||
Type::RustBox(ptr) => format!("rust_box${}", to_mangled(namespace, &ptr.inner)),
|
||||
Type::RustVec(ptr) => format!("rust_vec${}", to_mangled(namespace, &ptr.inner)),
|
||||
Type::UniquePtr(ptr) => format!("std$unique_ptr${}", to_mangled(namespace, &ptr.inner)),
|
||||
Type::CxxVector(ptr) => format!("std$vector${}", to_mangled(namespace, &ptr.inner)),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ pub mod error;
|
||||
pub mod ident;
|
||||
mod impls;
|
||||
pub mod mangle;
|
||||
pub mod mangled;
|
||||
pub mod namespace;
|
||||
mod parse;
|
||||
pub mod set;
|
||||
|
Loading…
Reference in New Issue
Block a user