blob: 5b516486d66d0f08e5ffffe8bafa84154728cb23 [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 {
47 pub doc: Doc,
48 pub fn_token: Token![fn],
49 pub ident: Ident,
50 pub receiver: Option<Receiver>,
51 pub args: Vec<Var>,
52 pub ret: Option<Type>,
David Tolnay59b7ede2020-03-16 00:30:23 -070053 pub throws: bool,
David Tolnay7db73692019-10-20 14:51:12 -040054 pub semi_token: Token![;],
55}
56
57pub struct Var {
58 pub ident: Ident,
59 pub ty: Type,
60}
61
62pub struct Receiver {
63 pub mutability: Option<Token![mut]>,
64 pub ident: Ident,
65}
66
David Tolnay7db73692019-10-20 14:51:12 -040067pub enum Type {
68 Ident(Ident),
69 RustBox(Box<Ty1>),
70 UniquePtr(Box<Ty1>),
71 Ref(Box<Ref>),
72 Str(Box<Ref>),
David Tolnay2fb14e92020-03-15 23:11:38 -070073 Void(Span),
David Tolnay7db73692019-10-20 14:51:12 -040074}
75
76pub struct Ty1 {
77 pub name: Ident,
78 pub langle: Token![<],
79 pub inner: Type,
80 pub rangle: Token![>],
81}
82
83pub struct Ref {
84 pub ampersand: Token![&],
85 pub mutability: Option<Token![mut]>,
86 pub inner: Type,
87}
88
89#[derive(Copy, Clone, PartialEq)]
90pub enum Derive {
91 Clone,
92 Copy,
93}