blob: 6274cf1a8281a6e0dab93504a163a66458f21811 [file] [log] [blame]
David Tolnay7db73692019-10-20 14:51:12 -04001// Functionality that is shared between the cxxbridge macro and the cmd.
2
3pub mod atom;
4mod attrs;
5pub mod check;
6mod doc;
7pub mod error;
8pub mod ident;
9mod impls;
10mod parse;
11pub mod set;
12mod tokens;
13pub mod types;
14
David Tolnayd0bb3642020-03-15 23:27:11 -070015use proc_macro2::{Ident, Span};
David Tolnay7db73692019-10-20 14:51:12 -040016use syn::{LitStr, Token};
17
18pub use self::atom::Atom;
19pub use self::doc::Doc;
20pub use self::parse::parse_items;
21pub use self::types::Types;
22
23pub enum Api {
24 Include(LitStr),
25 Struct(Struct),
26 CxxType(ExternType),
27 CxxFunction(ExternFn),
28 RustType(ExternType),
29 RustFunction(ExternFn),
30}
31
32pub struct ExternType {
33 pub doc: Doc,
34 pub type_token: Token![type],
35 pub ident: Ident,
36}
37
38pub struct Struct {
39 pub doc: Doc,
40 pub derives: Vec<Ident>,
41 pub struct_token: Token![struct],
42 pub ident: Ident,
43 pub fields: Vec<Var>,
44}
45
46pub struct ExternFn {
David Tolnay6cde49f2020-03-16 12:25:45 -070047 pub lang: Lang,
David Tolnay7db73692019-10-20 14:51:12 -040048 pub doc: Doc,
David Tolnay7db73692019-10-20 14:51:12 -040049 pub ident: Ident,
David Tolnay16448732020-03-18 12:39:36 -070050 pub sig: Signature,
51 pub semi_token: Token![;],
52}
53
54pub struct Signature {
55 pub fn_token: Token![fn],
David Tolnay7db73692019-10-20 14:51:12 -040056 pub receiver: Option<Receiver>,
57 pub args: Vec<Var>,
58 pub ret: Option<Type>,
David Tolnay59b7ede2020-03-16 00:30:23 -070059 pub throws: bool,
David Tolnay7db73692019-10-20 14:51:12 -040060}
61
David Tolnay417305a2020-03-18 13:54:00 -070062#[derive(Eq, PartialEq, Hash)]
David Tolnay7db73692019-10-20 14:51:12 -040063pub struct Var {
64 pub ident: Ident,
65 pub ty: Type,
66}
67
68pub struct Receiver {
69 pub mutability: Option<Token![mut]>,
70 pub ident: Ident,
71}
72
David Tolnay7db73692019-10-20 14:51:12 -040073pub enum Type {
74 Ident(Ident),
75 RustBox(Box<Ty1>),
76 UniquePtr(Box<Ty1>),
77 Ref(Box<Ref>),
78 Str(Box<Ref>),
David Tolnay417305a2020-03-18 13:54:00 -070079 Fn(Box<Signature>),
David Tolnay2fb14e92020-03-15 23:11:38 -070080 Void(Span),
David Tolnay7db73692019-10-20 14:51:12 -040081}
82
83pub struct Ty1 {
84 pub name: Ident,
85 pub langle: Token![<],
86 pub inner: Type,
87 pub rangle: Token![>],
88}
89
90pub struct Ref {
91 pub ampersand: Token![&],
92 pub mutability: Option<Token![mut]>,
93 pub inner: Type,
94}
95
96#[derive(Copy, Clone, PartialEq)]
David Tolnay6cde49f2020-03-16 12:25:45 -070097pub enum Lang {
98 Cxx,
99 Rust,
100}
101
102#[derive(Copy, Clone, PartialEq)]
David Tolnay7db73692019-10-20 14:51:12 -0400103pub enum Derive {
104 Clone,
105 Copy,
106}