mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-10-07 09:03:30 +00:00
Rename RustName -> NamedType
This commit is contained in:
parent
95bc57fc47
commit
77a5e758e6
@ -8,7 +8,7 @@ use crate::syntax::set::UnorderedSet;
|
||||
use crate::syntax::symbol::Symbol;
|
||||
use crate::syntax::trivial::{self, TrivialReason};
|
||||
use crate::syntax::{
|
||||
derive, mangle, Api, Enum, ExternFn, ExternType, Pair, RustName, Signature, Struct, Trait,
|
||||
derive, mangle, Api, Enum, ExternFn, ExternType, NamedType, Pair, Signature, Struct, Trait,
|
||||
Type, TypeAlias, Types, Var,
|
||||
};
|
||||
use proc_macro2::Ident;
|
||||
@ -1284,15 +1284,15 @@ fn write_space_after_type(out: &mut OutFile, ty: &Type) {
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum UniquePtr<'a> {
|
||||
Ident(&'a RustName),
|
||||
CxxVector(&'a RustName),
|
||||
Ident(&'a NamedType),
|
||||
CxxVector(&'a NamedType),
|
||||
}
|
||||
|
||||
trait ToTypename {
|
||||
fn to_typename(&self, types: &Types) -> String;
|
||||
}
|
||||
|
||||
impl ToTypename for RustName {
|
||||
impl ToTypename for NamedType {
|
||||
fn to_typename(&self, types: &Types) -> String {
|
||||
types.resolve(self).to_fully_qualified()
|
||||
}
|
||||
@ -1313,7 +1313,7 @@ trait ToMangled {
|
||||
fn to_mangled(&self, types: &Types) -> Symbol;
|
||||
}
|
||||
|
||||
impl ToMangled for RustName {
|
||||
impl ToMangled for NamedType {
|
||||
fn to_mangled(&self, types: &Types) -> Symbol {
|
||||
types.resolve(self).to_symbol()
|
||||
}
|
||||
@ -1457,7 +1457,7 @@ fn write_rust_box_extern(out: &mut OutFile, ident: &Pair) {
|
||||
);
|
||||
}
|
||||
|
||||
fn write_rust_vec_extern(out: &mut OutFile, element: &RustName) {
|
||||
fn write_rust_vec_extern(out: &mut OutFile, element: &NamedType) {
|
||||
let inner = element.to_typename(out.types);
|
||||
let instance = element.to_mangled(out.types);
|
||||
|
||||
@ -1531,7 +1531,7 @@ fn write_rust_box_impl(out: &mut OutFile, ident: &Pair) {
|
||||
writeln!(out, "}}");
|
||||
}
|
||||
|
||||
fn write_rust_vec_impl(out: &mut OutFile, element: &RustName) {
|
||||
fn write_rust_vec_impl(out: &mut OutFile, element: &NamedType) {
|
||||
let inner = element.to_typename(out.types);
|
||||
let instance = element.to_mangled(out.types);
|
||||
|
||||
@ -1608,7 +1608,7 @@ fn write_rust_vec_impl(out: &mut OutFile, element: &RustName) {
|
||||
writeln!(out, "}}");
|
||||
}
|
||||
|
||||
fn write_unique_ptr(out: &mut OutFile, ident: &RustName) {
|
||||
fn write_unique_ptr(out: &mut OutFile, ident: &NamedType) {
|
||||
let ty = UniquePtr::Ident(ident);
|
||||
write_unique_ptr_common(out, ty);
|
||||
}
|
||||
@ -1725,7 +1725,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: UniquePtr) {
|
||||
writeln!(out, "}}");
|
||||
}
|
||||
|
||||
fn write_shared_ptr(out: &mut OutFile, ident: &RustName) {
|
||||
fn write_shared_ptr(out: &mut OutFile, ident: &NamedType) {
|
||||
let resolve = out.types.resolve(ident);
|
||||
let inner = resolve.to_fully_qualified();
|
||||
let instance = resolve.to_symbol();
|
||||
@ -1797,7 +1797,7 @@ fn write_shared_ptr(out: &mut OutFile, ident: &RustName) {
|
||||
writeln!(out, "}}");
|
||||
}
|
||||
|
||||
fn write_weak_ptr(out: &mut OutFile, ident: &RustName) {
|
||||
fn write_weak_ptr(out: &mut OutFile, ident: &NamedType) {
|
||||
let resolve = out.types.resolve(ident);
|
||||
let inner = resolve.to_fully_qualified();
|
||||
let instance = resolve.to_symbol();
|
||||
@ -1856,7 +1856,7 @@ fn write_weak_ptr(out: &mut OutFile, ident: &RustName) {
|
||||
writeln!(out, "}}");
|
||||
}
|
||||
|
||||
fn write_cxx_vector(out: &mut OutFile, element: &RustName) {
|
||||
fn write_cxx_vector(out: &mut OutFile, element: &NamedType) {
|
||||
let inner = element.to_typename(out.types);
|
||||
let instance = element.to_mangled(out.types);
|
||||
|
||||
|
@ -5,7 +5,7 @@ use crate::syntax::file::Module;
|
||||
use crate::syntax::report::Errors;
|
||||
use crate::syntax::symbol::Symbol;
|
||||
use crate::syntax::{
|
||||
self, check, mangle, Api, Doc, Enum, ExternFn, ExternType, Impl, Pair, RustName, Signature,
|
||||
self, check, mangle, Api, Doc, Enum, ExternFn, ExternType, Impl, NamedType, Pair, Signature,
|
||||
Struct, Trait, Type, TypeAlias, Types,
|
||||
};
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
@ -1071,7 +1071,7 @@ fn type_id(name: &Pair) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_rust_box(ident: &RustName, types: &Types) -> TokenStream {
|
||||
fn expand_rust_box(ident: &NamedType, types: &Types) -> TokenStream {
|
||||
let resolve = types.resolve(ident);
|
||||
let link_prefix = format!("cxxbridge1$box${}$", resolve.to_symbol());
|
||||
let link_alloc = format!("{}alloc", link_prefix);
|
||||
@ -1105,7 +1105,7 @@ fn expand_rust_box(ident: &RustName, types: &Types) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_rust_vec(elem: &RustName, types: &Types) -> TokenStream {
|
||||
fn expand_rust_vec(elem: &NamedType, types: &Types) -> TokenStream {
|
||||
let resolve = types.resolve(elem);
|
||||
let link_prefix = format!("cxxbridge1$rust_vec${}$", resolve.to_symbol());
|
||||
let link_new = format!("{}new", link_prefix);
|
||||
@ -1167,7 +1167,11 @@ fn expand_rust_vec(elem: &RustName, types: &Types) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_unique_ptr(ident: &RustName, types: &Types, explicit_impl: Option<&Impl>) -> TokenStream {
|
||||
fn expand_unique_ptr(
|
||||
ident: &NamedType,
|
||||
types: &Types,
|
||||
explicit_impl: Option<&Impl>,
|
||||
) -> TokenStream {
|
||||
let name = ident.rust.to_string();
|
||||
let resolve = types.resolve(ident);
|
||||
let prefix = format!("cxxbridge1$unique_ptr${}$", resolve.to_symbol());
|
||||
@ -1249,7 +1253,11 @@ fn expand_unique_ptr(ident: &RustName, types: &Types, explicit_impl: Option<&Imp
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_shared_ptr(ident: &RustName, types: &Types, explicit_impl: Option<&Impl>) -> TokenStream {
|
||||
fn expand_shared_ptr(
|
||||
ident: &NamedType,
|
||||
types: &Types,
|
||||
explicit_impl: Option<&Impl>,
|
||||
) -> TokenStream {
|
||||
let name = ident.rust.to_string();
|
||||
let resolve = types.resolve(ident);
|
||||
let prefix = format!("cxxbridge1$shared_ptr${}$", resolve.to_symbol());
|
||||
@ -1317,7 +1325,7 @@ fn expand_shared_ptr(ident: &RustName, types: &Types, explicit_impl: Option<&Imp
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_weak_ptr(ident: &RustName, types: &Types, explicit_impl: Option<&Impl>) -> TokenStream {
|
||||
fn expand_weak_ptr(ident: &NamedType, types: &Types, explicit_impl: Option<&Impl>) -> TokenStream {
|
||||
let name = ident.rust.to_string();
|
||||
let resolve = types.resolve(ident);
|
||||
let prefix = format!("cxxbridge1$weak_ptr${}$", resolve.to_symbol());
|
||||
@ -1374,7 +1382,7 @@ fn expand_weak_ptr(ident: &RustName, types: &Types, explicit_impl: Option<&Impl>
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_cxx_vector(elem: &RustName, explicit_impl: Option<&Impl>, types: &Types) -> TokenStream {
|
||||
fn expand_cxx_vector(elem: &NamedType, explicit_impl: Option<&Impl>, types: &Types) -> TokenStream {
|
||||
let name = elem.rust.to_string();
|
||||
let resolve = types.resolve(elem);
|
||||
let prefix = format!("cxxbridge1$std$vector${}$", resolve.to_symbol());
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::syntax::atom::Atom::{self, *};
|
||||
use crate::syntax::report::Errors;
|
||||
use crate::syntax::{
|
||||
error, ident, trivial, Api, Array, Enum, ExternFn, ExternType, Impl, Lang, Receiver, Ref,
|
||||
RustName, Signature, SliceRef, Struct, Trait, Ty1, Type, TypeAlias, Types,
|
||||
error, ident, trivial, Api, Array, Enum, ExternFn, ExternType, Impl, Lang, NamedType, Receiver,
|
||||
Ref, Signature, SliceRef, Struct, Trait, Ty1, Type, TypeAlias, Types,
|
||||
};
|
||||
use proc_macro2::{Delimiter, Group, Ident, TokenStream};
|
||||
use quote::{quote, ToTokens};
|
||||
@ -61,7 +61,7 @@ impl Check<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_type_ident(cx: &mut Check, name: &RustName) {
|
||||
fn check_type_ident(cx: &mut Check, name: &NamedType) {
|
||||
let ident = &name.rust;
|
||||
if Atom::from(ident).is_none()
|
||||
&& !cx.types.structs.contains_key(ident)
|
||||
|
@ -176,7 +176,7 @@ pub struct Receiver {
|
||||
pub lifetime: Option<Lifetime>,
|
||||
pub mutable: bool,
|
||||
pub var: Token![self],
|
||||
pub ty: RustName,
|
||||
pub ty: NamedType,
|
||||
pub shorthand: bool,
|
||||
pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>,
|
||||
pub mutability: Option<Token![mut]>,
|
||||
@ -191,7 +191,7 @@ pub struct Variant {
|
||||
}
|
||||
|
||||
pub enum Type {
|
||||
Ident(RustName),
|
||||
Ident(NamedType),
|
||||
RustBox(Box<Ty1>),
|
||||
RustVec(Box<Ty1>),
|
||||
UniquePtr(Box<Ty1>),
|
||||
@ -258,7 +258,7 @@ pub struct Pair {
|
||||
// Wrapper for a type which needs to be resolved before it can be printed in
|
||||
// C++.
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
pub struct RustName {
|
||||
pub struct NamedType {
|
||||
pub rust: Ident,
|
||||
pub generics: Lifetimes,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::syntax::{Lifetimes, Pair, RustName, Symbol};
|
||||
use crate::syntax::{Lifetimes, NamedType, Pair, Symbol};
|
||||
use proc_macro2::{Ident, Span};
|
||||
use std::iter;
|
||||
use syn::punctuated::Punctuated;
|
||||
@ -22,14 +22,14 @@ impl Pair {
|
||||
}
|
||||
}
|
||||
|
||||
impl RustName {
|
||||
impl NamedType {
|
||||
pub fn new(rust: Ident) -> Self {
|
||||
let generics = Lifetimes {
|
||||
lt_token: None,
|
||||
lifetimes: Punctuated::new(),
|
||||
gt_token: None,
|
||||
};
|
||||
RustName { rust, generics }
|
||||
NamedType { rust, generics }
|
||||
}
|
||||
|
||||
pub fn span(&self) -> Span {
|
||||
|
@ -5,7 +5,7 @@ use crate::syntax::report::Errors;
|
||||
use crate::syntax::Atom::*;
|
||||
use crate::syntax::{
|
||||
attrs, error, Api, Array, Derive, Doc, Enum, ExternFn, ExternType, Impl, Include, IncludeKind,
|
||||
Lang, Lifetimes, Namespace, Pair, Receiver, Ref, RustName, Signature, SliceRef, Struct, Ty1,
|
||||
Lang, Lifetimes, NamedType, Namespace, Pair, Receiver, Ref, Signature, SliceRef, Struct, Ty1,
|
||||
Type, TypeAlias, Var, Variant,
|
||||
};
|
||||
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
|
||||
@ -201,7 +201,7 @@ fn parse_enum(cx: &mut Errors, item: ItemEnum, namespace: &Namespace) -> Result<
|
||||
|
||||
let name = pair(namespace, &item.ident, cxx_name, rust_name);
|
||||
let repr_ident = Ident::new(repr.as_ref(), Span::call_site());
|
||||
let repr_type = Type::Ident(RustName::new(repr_ident));
|
||||
let repr_type = Type::Ident(NamedType::new(repr_ident));
|
||||
|
||||
Ok(Api::Enum(Enum {
|
||||
doc,
|
||||
@ -519,7 +519,7 @@ fn parse_extern_fn(
|
||||
lifetime: lifetime.clone(),
|
||||
mutable: arg.mutability.is_some(),
|
||||
var: arg.self_token,
|
||||
ty: RustName::new(Ident::new("Self", arg.self_token.span)),
|
||||
ty: NamedType::new(Ident::new("Self", arg.self_token.span)),
|
||||
shorthand: true,
|
||||
pin_tokens: None,
|
||||
mutability: arg.mutability,
|
||||
@ -1007,7 +1007,7 @@ fn parse_type_path(ty: &TypePath) -> Result<Type> {
|
||||
let segment = &path.segments[0];
|
||||
let ident = segment.ident.clone();
|
||||
match &segment.arguments {
|
||||
PathArguments::None => return Ok(Type::Ident(RustName::new(ident))),
|
||||
PathArguments::None => return Ok(Type::Ident(NamedType::new(ident))),
|
||||
PathArguments::AngleBracketed(generic) => {
|
||||
if ident == "UniquePtr" && generic.args.len() == 1 {
|
||||
if let GenericArgument::Type(arg) = &generic.args[0] {
|
||||
@ -1096,7 +1096,7 @@ fn parse_type_path(ty: &TypePath) -> Result<Type> {
|
||||
}
|
||||
}
|
||||
if only_lifetimes {
|
||||
return Ok(Type::Ident(RustName {
|
||||
return Ok(Type::Ident(NamedType {
|
||||
rust: ident,
|
||||
generics: Lifetimes {
|
||||
lt_token: Some(generic.lt_token),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::syntax::atom::Atom::*;
|
||||
use crate::syntax::{
|
||||
Array, Atom, Derive, Enum, ExternFn, ExternType, Impl, Lifetimes, Receiver, Ref, RustName,
|
||||
Array, Atom, Derive, Enum, ExternFn, ExternType, Impl, Lifetimes, NamedType, Receiver, Ref,
|
||||
Signature, SliceRef, Struct, Ty1, Type, TypeAlias, Var,
|
||||
};
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
@ -256,9 +256,9 @@ impl ToTokens for Signature {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for RustName {
|
||||
impl ToTokens for NamedType {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
let RustName { rust, generics } = self;
|
||||
let NamedType { rust, generics } = self;
|
||||
rust.to_tokens(tokens);
|
||||
generics.to_tokens(tokens);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::syntax::map::UnorderedMap;
|
||||
use crate::syntax::set::{OrderedSet as Set, UnorderedSet};
|
||||
use crate::syntax::{Api, Enum, ExternFn, Pair, RustName, Struct, Type};
|
||||
use crate::syntax::{Api, Enum, ExternFn, NamedType, Pair, Struct, Type};
|
||||
use proc_macro2::Ident;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
@ -23,7 +23,7 @@ pub fn required_trivial_reasons<'a>(
|
||||
) -> UnorderedMap<&'a Ident, Vec<TrivialReason<'a>>> {
|
||||
let mut required_trivial = UnorderedMap::new();
|
||||
|
||||
let mut insist_extern_types_are_trivial = |ident: &'a RustName, reason| {
|
||||
let mut insist_extern_types_are_trivial = |ident: &'a NamedType, reason| {
|
||||
if cxx.contains(&ident.rust)
|
||||
&& !structs.contains_key(&ident.rust)
|
||||
&& !enums.contains_key(&ident.rust)
|
||||
|
@ -5,7 +5,7 @@ use crate::syntax::report::Errors;
|
||||
use crate::syntax::set::{OrderedSet as Set, UnorderedSet};
|
||||
use crate::syntax::trivial::{self, TrivialReason};
|
||||
use crate::syntax::{
|
||||
toposort, Api, Enum, ExternType, Impl, Pair, RustName, Struct, Type, TypeAlias,
|
||||
toposort, Api, Enum, ExternType, Impl, NamedType, Pair, Struct, Type, TypeAlias,
|
||||
};
|
||||
use proc_macro2::Ident;
|
||||
use quote::ToTokens;
|
||||
@ -240,7 +240,7 @@ impl<'a> Types<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve(&self, ident: &RustName) -> &Pair {
|
||||
pub fn resolve(&self, ident: &NamedType) -> &Pair {
|
||||
self.resolutions
|
||||
.get(&ident.rust)
|
||||
.expect("Unable to resolve type")
|
||||
|
Loading…
Reference in New Issue
Block a user