Eliminate unnecessary ToMangled trait
diff --git a/gen/write.rs b/gen/write.rs
index 42352d0..150eb76 100644
--- a/gen/write.rs
+++ b/gen/write.rs
@@ -1,7 +1,7 @@
use crate::gen::out::OutFile;
use crate::gen::{include, Opt};
use crate::syntax::atom::Atom::{self, *};
-use crate::syntax::mangled::ToMangled;
+use crate::syntax::mangled::to_mangled;
use crate::syntax::namespace::Namespace;
use crate::syntax::symbol::Symbol;
use crate::syntax::typename::to_typename;
@@ -979,7 +979,7 @@
fn write_rust_vec_extern(out: &mut OutFile, ty: &Type) {
let inner = to_typename(&out.namespace, ty);
- let instance = ty.to_mangled(&out.namespace);
+ let instance = to_mangled(&out.namespace, ty);
writeln!(out, "#ifndef CXXBRIDGE02_RUST_VEC_{}", instance);
writeln!(out, "#define CXXBRIDGE02_RUST_VEC_{}", instance);
@@ -1018,7 +1018,7 @@
fn write_rust_vec_impl(out: &mut OutFile, ty: &Type) {
let inner = to_typename(&out.namespace, ty);
- let instance = ty.to_mangled(&out.namespace);
+ let instance = to_mangled(&out.namespace, ty);
writeln!(out, "template <>");
writeln!(out, "void Vec<{}>::drop() noexcept {{", inner);
@@ -1038,7 +1038,7 @@
fn write_unique_ptr(out: &mut OutFile, ty: &Type, types: &Types) {
out.include.utility = true;
let inner = to_typename(&out.namespace, ty);
- let instance = ty.to_mangled(&out.namespace);
+ let instance = to_mangled(&out.namespace, ty);
writeln!(out, "#ifndef CXXBRIDGE02_UNIQUE_PTR_{}", instance);
writeln!(out, "#define CXXBRIDGE02_UNIQUE_PTR_{}", instance);
diff --git a/macro/src/expand.rs b/macro/src/expand.rs
index 720680d..8133e6d 100644
--- a/macro/src/expand.rs
+++ b/macro/src/expand.rs
@@ -1,5 +1,5 @@
use crate::syntax::atom::Atom::{self, *};
-use crate::syntax::mangled::ToMangled;
+use crate::syntax::mangled::to_mangled;
use crate::syntax::namespace::Namespace;
use crate::syntax::symbol::Symbol;
use crate::syntax::typename::to_typename;
@@ -548,7 +548,7 @@
fn expand_rust_vec(namespace: &Namespace, ty: &Type, ident: &Ident) -> TokenStream {
let inner = ty;
- let mangled = ty.to_mangled(namespace) + "$";
+ let mangled = to_mangled(namespace, ty) + "$";
let link_prefix = format!("cxxbridge02$rust_vec${}", mangled);
let link_drop = format!("{}drop", link_prefix);
let link_len = format!("{}len", link_prefix);
@@ -575,7 +575,7 @@
fn expand_unique_ptr(namespace: &Namespace, ty: &Type, types: &Types) -> TokenStream {
let name = to_typename(namespace, ty);
let inner = ty;
- let mangled = ty.to_mangled(namespace) + "$";
+ let mangled = to_mangled(namespace, ty) + "$";
let prefix = format!("cxxbridge02$unique_ptr${}", mangled);
let link_null = format!("{}null", prefix);
let link_new = format!("{}new", prefix);
@@ -648,7 +648,7 @@
fn expand_vector(namespace: &Namespace, ty: &Type) -> TokenStream {
let inner = ty;
- let mangled = ty.to_mangled(namespace) + "$";
+ let mangled = to_mangled(namespace, ty) + "$";
let prefix = format!("cxxbridge02$std$vector${}", mangled);
let link_size = format!("{}size", prefix);
let link_get_unchecked = format!("{}get_unchecked", prefix);
diff --git a/syntax/mangled.rs b/syntax/mangled.rs
index a89060d..f52aa43 100644
--- a/syntax/mangled.rs
+++ b/syntax/mangled.rs
@@ -1,31 +1,25 @@
use crate::syntax::namespace::Namespace;
use crate::syntax::{Atom, Type};
-pub trait ToMangled {
- fn to_mangled(&self, namespace: &Namespace) -> String;
-}
-
-impl ToMangled for Type {
- fn to_mangled(&self, namespace: &Namespace) -> String {
- match self {
- 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 += "$";
- }
+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${}", ptr.inner.to_mangled(namespace)),
- Type::RustVec(ptr) => format!("rust_vec${}", ptr.inner.to_mangled(namespace)),
- Type::UniquePtr(ptr) => format!("std$unique_ptr${}", ptr.inner.to_mangled(namespace)),
- Type::CxxVector(ptr) => format!("std$vector${}", ptr.inner.to_mangled(namespace)),
- _ => unimplemented!(),
+ 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!(),
}
}