mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-25 02:20:49 +00:00
Improving Pair construction.
This commit is contained in:
parent
0447e96b84
commit
0f8ab22aee
@ -300,14 +300,22 @@ impl Borrow<Type> for &Impl {
|
|||||||
|
|
||||||
impl Pair {
|
impl Pair {
|
||||||
/// Use this constructor when the item can't have a different
|
/// Use this constructor when the item can't have a different
|
||||||
/// name in Rust and C++. For cases where #[rust_name] and similar
|
/// name in Rust and C++.
|
||||||
/// attributes can be used, construct the object by hand.
|
|
||||||
pub fn new(ns: Namespace, ident: Ident) -> Self {
|
pub fn new(ns: Namespace, ident: Ident) -> Self {
|
||||||
Self {
|
Self {
|
||||||
rust: ident.clone(),
|
rust: ident.clone(),
|
||||||
cxx: CppName::new(ns, ident),
|
cxx: CppName::new(ns, ident),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use this constructor when attributes such as #[rust_name]
|
||||||
|
/// can be used to potentially give a different name in Rust vs C++.
|
||||||
|
pub fn new_from_differing_names(ns: Namespace, cxx_ident: Ident, rust_ident: Ident) -> Self {
|
||||||
|
Self {
|
||||||
|
rust: rust_ident,
|
||||||
|
cxx: CppName::new(ns, cxx_ident),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResolvableName {
|
impl ResolvableName {
|
||||||
|
@ -3,7 +3,7 @@ use crate::syntax::file::{Item, ItemForeignMod};
|
|||||||
use crate::syntax::report::Errors;
|
use crate::syntax::report::Errors;
|
||||||
use crate::syntax::Atom::*;
|
use crate::syntax::Atom::*;
|
||||||
use crate::syntax::{
|
use crate::syntax::{
|
||||||
attrs, error, Api, CppName, Doc, Enum, ExternFn, ExternType, Impl, Include, IncludeKind, Lang,
|
attrs, error, Api, Doc, Enum, ExternFn, ExternType, Impl, Include, IncludeKind, Lang,
|
||||||
Namespace, Pair, Receiver, Ref, ResolvableName, Signature, Slice, Struct, Ty1, Type, TypeAlias,
|
Namespace, Pair, Receiver, Ref, ResolvableName, Signature, Slice, Struct, Ty1, Type, TypeAlias,
|
||||||
Var, Variant,
|
Var, Variant,
|
||||||
};
|
};
|
||||||
@ -398,10 +398,11 @@ fn parse_extern_fn(
|
|||||||
let throws = throws_tokens.is_some();
|
let throws = throws_tokens.is_some();
|
||||||
let unsafety = foreign_fn.sig.unsafety;
|
let unsafety = foreign_fn.sig.unsafety;
|
||||||
let fn_token = foreign_fn.sig.fn_token;
|
let fn_token = foreign_fn.sig.fn_token;
|
||||||
let ident = Pair {
|
let ident = Pair::new_from_differing_names(
|
||||||
cxx: CppName::new(ns, cxx_name.unwrap_or(foreign_fn.sig.ident.clone())),
|
ns,
|
||||||
rust: rust_name.unwrap_or(foreign_fn.sig.ident.clone()),
|
cxx_name.unwrap_or(foreign_fn.sig.ident.clone()),
|
||||||
};
|
rust_name.unwrap_or(foreign_fn.sig.ident.clone()),
|
||||||
|
);
|
||||||
let paren_token = foreign_fn.sig.paren_token;
|
let paren_token = foreign_fn.sig.paren_token;
|
||||||
let semi_token = foreign_fn.semi_token;
|
let semi_token = foreign_fn.semi_token;
|
||||||
let api_function = match lang {
|
let api_function = match lang {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user