blob: f2e1c1c04c2a011ed4a104c28cdfed26354f0e87 [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
62pub struct Var {
63 pub ident: Ident,
64 pub ty: Type,
65}
66
67pub struct Receiver {
68 pub mutability: Option<Token![mut]>,
69 pub ident: Ident,
70}
71
David Tolnay7db73692019-10-20 14:51:12 -040072pub enum Type {
73 Ident(Ident),
74 RustBox(Box<Ty1>),
75 UniquePtr(Box<Ty1>),
76 Ref(Box<Ref>),
77 Str(Box<Ref>),
David Tolnay2fb14e92020-03-15 23:11:38 -070078 Void(Span),
David Tolnay7db73692019-10-20 14:51:12 -040079}
80
81pub struct Ty1 {
82 pub name: Ident,
83 pub langle: Token![<],
84 pub inner: Type,
85 pub rangle: Token![>],
86}
87
88pub struct Ref {
89 pub ampersand: Token![&],
90 pub mutability: Option<Token![mut]>,
91 pub inner: Type,
92}
93
94#[derive(Copy, Clone, PartialEq)]
David Tolnay6cde49f2020-03-16 12:25:45 -070095pub enum Lang {
96 Cxx,
97 Rust,
98}
99
100#[derive(Copy, Clone, PartialEq)]
David Tolnay7db73692019-10-20 14:51:12 -0400101pub enum Derive {
102 Clone,
103 Copy,
104}