blob: 79a4a7b89030e6d656932f5330a2f737e8bb27a4 [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,
49 pub fn_token: Token![fn],
50 pub ident: Ident,
51 pub receiver: Option<Receiver>,
52 pub args: Vec<Var>,
53 pub ret: Option<Type>,
David Tolnay59b7ede2020-03-16 00:30:23 -070054 pub throws: bool,
David Tolnay7db73692019-10-20 14:51:12 -040055 pub semi_token: Token![;],
56}
57
58pub struct Var {
59 pub ident: Ident,
60 pub ty: Type,
61}
62
63pub struct Receiver {
64 pub mutability: Option<Token![mut]>,
65 pub ident: Ident,
66}
67
David Tolnay7db73692019-10-20 14:51:12 -040068pub enum Type {
69 Ident(Ident),
70 RustBox(Box<Ty1>),
71 UniquePtr(Box<Ty1>),
72 Ref(Box<Ref>),
73 Str(Box<Ref>),
David Tolnay2fb14e92020-03-15 23:11:38 -070074 Void(Span),
David Tolnay7db73692019-10-20 14:51:12 -040075}
76
77pub struct Ty1 {
78 pub name: Ident,
79 pub langle: Token![<],
80 pub inner: Type,
81 pub rangle: Token![>],
82}
83
84pub struct Ref {
85 pub ampersand: Token![&],
86 pub mutability: Option<Token![mut]>,
87 pub inner: Type,
88}
89
90#[derive(Copy, Clone, PartialEq)]
David Tolnay6cde49f2020-03-16 12:25:45 -070091pub enum Lang {
92 Cxx,
93 Rust,
94}
95
96#[derive(Copy, Clone, PartialEq)]
David Tolnay7db73692019-10-20 14:51:12 -040097pub enum Derive {
98 Clone,
99 Copy,
100}