Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
makai410 committed Sep 18, 2024
1 parent 827fd85 commit 7f18ebd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
30 changes: 15 additions & 15 deletions gen/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::gen::nested::NamespaceEntries;
use crate::gen::out::OutFile;
use crate::gen::{builtin, include, Opt};
use crate::syntax::atom::Atom::{self, *};
use crate::syntax::instantiate::{CxxVectorPayloadImplKey, ImplKey, NamedImplKey, PtrConstness};
use crate::syntax::instantiate::{CxxVectorPayloadImplKey, ImplKey, NamedImplKey, PtrMutability};
use crate::syntax::map::UnorderedMap as Map;
use crate::syntax::set::UnorderedSet;
use crate::syntax::symbol::{self, Symbol};
Expand Down Expand Up @@ -1352,7 +1352,7 @@ fn write_space_after_type(out: &mut OutFile, ty: &Type) {
enum UniquePtr<'a> {
Ident(&'a Ident),
CxxVector(&'a Ident),
CxxVectorPtr(&'a Ident, PtrConstness),
CxxVectorPtr(PtrMutability, &'a Ident),
}

trait ToTypename {
Expand All @@ -1372,10 +1372,10 @@ impl<'a> ToTypename for UniquePtr<'a> {
UniquePtr::CxxVector(element) => {
format!("::std::vector<{}>", element.to_typename(types))
}
UniquePtr::CxxVectorPtr(element, constness) => {
let const_prefix = match constness {
PtrConstness::Const => "const ",
PtrConstness::Mut => "",
UniquePtr::CxxVectorPtr(mutability, element) => {
let const_prefix = match mutability {
PtrMutability::Const => "const ",
PtrMutability::Mut => "",
};
format!(
"::std::vector<{}{}*>",
Expand Down Expand Up @@ -1404,10 +1404,10 @@ impl<'a> ToMangled for UniquePtr<'a> {
UniquePtr::CxxVector(element) => {
symbol::join(&[&"std", &"vector", &element.to_mangled(types)])
}
UniquePtr::CxxVectorPtr(element, constness) => {
let prefix = match constness {
PtrConstness::Const => "ptrc",
PtrConstness::Mut => "ptrm",
UniquePtr::CxxVectorPtr(mutability, element) => {
let prefix = match mutability {
PtrMutability::Const => "ptrc",
PtrMutability::Mut => "ptrm",
};
symbol::join(&[&"std", &"vector", &prefix, &element.to_mangled(types)])
}
Expand Down Expand Up @@ -1917,12 +1917,12 @@ fn write_weak_ptr(out: &mut OutFile, key: NamedImplKey) {
fn write_cxx_vector(out: &mut OutFile, payload: CxxVectorPayloadImplKey) {
let (key, ptr_prefix, unique_ptr_payload) = match payload {
CxxVectorPayloadImplKey::Named(id) => (id, "", UniquePtr::CxxVector(id.rust)),
CxxVectorPayloadImplKey::Ptr(id, constness) => {
let prefix = match constness {
PtrConstness::Const => "ptrc$",
PtrConstness::Mut => "ptrm$",
CxxVectorPayloadImplKey::Ptr(id, mutability) => {
let prefix = match mutability {
PtrMutability::Const => "ptrc$",
PtrMutability::Mut => "ptrm$",
};
(id, prefix, UniquePtr::CxxVectorPtr(id.rust, constness))
(id, prefix, UniquePtr::CxxVectorPtr(mutability, id.rust))
}
};
let element = key.rust;
Expand Down
6 changes: 3 additions & 3 deletions macro/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::syntax::atom::Atom::*;
use crate::syntax::attrs::{self, OtherAttrs};
use crate::syntax::cfg::CfgExpr;
use crate::syntax::file::Module;
use crate::syntax::instantiate::{CxxVectorPayloadImplKey, ImplKey, NamedImplKey, PtrConstness};
use crate::syntax::instantiate::{CxxVectorPayloadImplKey, ImplKey, NamedImplKey, PtrMutability};
use crate::syntax::qualified::QualifiedName;
use crate::syntax::report::Errors;
use crate::syntax::symbol::Symbol;
Expand Down Expand Up @@ -1676,8 +1676,8 @@ fn expand_cxx_vector(
) -> TokenStream {
let (ptr_prefix, key, ty_prefix) = match payload {
CxxVectorPayloadImplKey::Named(id) => ("", id, quote! {}),
CxxVectorPayloadImplKey::Ptr(id, PtrConstness::Const) => ("ptrc$", id, quote! { *const }),
CxxVectorPayloadImplKey::Ptr(id, PtrConstness::Mut) => ("ptrm$", id, quote! { *mut }),
CxxVectorPayloadImplKey::Ptr(id, PtrMutability::Const) => ("ptrc$", id, quote! { *const }),
CxxVectorPayloadImplKey::Ptr(id, PtrMutability::Mut) => ("ptrm$", id, quote! { *mut }),
};
let elem = key.rust;

Expand Down
12 changes: 6 additions & 6 deletions syntax/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ pub(crate) enum ImplKey<'a> {
}

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub enum PtrConstness {
pub enum PtrMutability {
Const,
Mut,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) enum CxxVectorPayloadImplKey<'a> {
Named(NamedImplKey<'a>),
Ptr(NamedImplKey<'a>, PtrConstness),
Ptr(NamedImplKey<'a>, PtrMutability),
}

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -68,14 +68,14 @@ impl Type {
}
if let Type::Ptr(ptr) = &ty.inner {
if let Type::Ident(ident) = &ptr.inner {
let constness = if ptr.constness.is_some() {
PtrConstness::Const
let mutability = if ptr.constness.is_some() {
PtrMutability::Const
} else {
PtrConstness::Mut
PtrMutability::Mut
};
return Some(ImplKey::CxxVector(CxxVectorPayloadImplKey::Ptr(
NamedImplKey::new(ty, ident),
constness,
mutability,
)));
}
}
Expand Down

0 comments on commit 7f18ebd

Please sign in to comment.