Skip to content

Commit ae43dd5

Browse files
committed
Add alias kind to syntax::TypeAlias
1 parent 799a93a commit ae43dd5

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

macro/src/expand.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::syntax::namespace::Namespace;
44
use crate::syntax::report::Errors;
55
use crate::syntax::symbol::Symbol;
66
use crate::syntax::{
7-
self, check, mangle, Api, Enum, ExternFn, ExternType, Signature, Struct, Type, TypeAlias, Types,
7+
self, check, mangle, AliasKind, Api, Enum, ExternFn, ExternType, Signature, Struct, Type,
8+
TypeAlias, Types,
89
};
910
use proc_macro2::{Ident, TokenStream};
1011
use quote::{format_ident, quote, quote_spanned, ToTokens};
@@ -672,11 +673,15 @@ fn expand_type_alias_verify(namespace: &Namespace, alias: &TypeAlias) -> TokenSt
672673
let type_id = type_id(namespace, ident);
673674
let begin_span = alias.type_token.span;
674675
let end_span = alias.semi_token.span;
676+
let kind = match alias.kind {
677+
AliasKind::Shared => quote!(KindShared),
678+
AliasKind::OpaqueCpp => quote!(KindOpaqueCpp),
679+
};
675680
let begin = quote_spanned!(begin_span=> ::cxx::private::verify_extern_type::<);
676681
let end = quote_spanned!(end_span=> >);
677682

678683
quote! {
679-
const _: fn() = #begin #ident, ::cxx::extern_type::KindOpaqueCpp, #type_id #end;
684+
const _: fn() = #begin #ident, ::cxx::extern_type:: #kind, #type_id #end;
680685
}
681686
}
682687

syntax/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ pub struct ExternFn {
7878
pub semi_token: Token![;],
7979
}
8080

81+
pub enum AliasKind {
82+
Shared,
83+
OpaqueCpp,
84+
}
85+
8186
pub struct TypeAlias {
87+
pub kind: AliasKind,
8288
pub doc: Doc,
8389
pub type_token: Token![type],
8490
pub ident: Ident,

syntax/parse.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::syntax::file::{Item, ItemForeignMod};
33
use crate::syntax::report::Errors;
44
use crate::syntax::Atom::*;
55
use crate::syntax::{
6-
attrs, error, Api, Doc, Enum, ExternFn, ExternType, Lang, Receiver, Ref, Signature, Slice,
7-
Struct, Ty1, Type, TypeAlias, Var, Variant,
6+
attrs, error, AliasKind, Api, Doc, Enum, ExternFn, ExternType, Lang, Receiver, Ref, Signature,
7+
Slice, Struct, Ty1, Type, TypeAlias, Var, Variant,
88
};
99
use proc_macro2::{TokenStream, TokenTree};
1010
use quote::{format_ident, quote, quote_spanned};
@@ -399,6 +399,7 @@ fn parse_extern_verbatim(cx: &mut Errors, tokens: &TokenStream, lang: Lang) -> R
399399
let doc = attrs::parse_doc(cx, &attrs);
400400

401401
Ok(TypeAlias {
402+
kind: AliasKind::OpaqueCpp,
402403
doc,
403404
type_token,
404405
ident,

0 commit comments

Comments
 (0)