diff options
Diffstat (limited to 'syntax/symbol.rs')
-rw-r--r-- | syntax/symbol.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/syntax/symbol.rs b/syntax/symbol.rs index 253f57dc..a13a4f3c 100644 --- a/syntax/symbol.rs +++ b/syntax/symbol.rs @@ -1,11 +1,11 @@ use crate::syntax::namespace::Namespace; -use crate::syntax::Pair; +use crate::syntax::{ForeignName, Pair}; use proc_macro2::{Ident, TokenStream}; use quote::ToTokens; use std::fmt::{self, Display, Write}; // A mangled symbol consisting of segments separated by '$'. -// For example: cxxbridge05$string$new +// For example: cxxbridge1$string$new pub struct Symbol(String); impl Display for Symbol { @@ -30,7 +30,7 @@ impl Symbol { assert!(self.0.len() > len_before); } - pub fn from_idents<'a, T: Iterator<Item = &'a Ident>>(it: T) -> Self { + pub fn from_idents<'a>(it: impl Iterator<Item = &'a dyn Segment>) -> Self { let mut symbol = Symbol(String::new()); for segment in it { segment.write(&mut symbol); @@ -55,16 +55,19 @@ impl Segment for str { symbol.push(&self); } } + impl Segment for usize { fn write(&self, symbol: &mut Symbol) { symbol.push(&self); } } + impl Segment for Ident { fn write(&self, symbol: &mut Symbol) { symbol.push(&self); } } + impl Segment for Symbol { fn write(&self, symbol: &mut Symbol) { symbol.push(&self); @@ -86,6 +89,14 @@ impl Segment for Pair { } } +impl Segment for ForeignName { + fn write(&self, symbol: &mut Symbol) { + // TODO: support C++ names containing whitespace (`unsigned int`) or + // non-alphanumeric characters (`operator++`). + self.to_string().write(symbol); + } +} + impl<T> Segment for &'_ T where T: ?Sized + Segment + Display, |