blob: 8c7e5ca15385b74f319af1dee7fcd59ceb86bed3 [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>,
53 pub semi_token: Token![;],
54}
55
56pub struct Var {
57 pub ident: Ident,
58 pub ty: Type,
59}
60
61pub struct Receiver {
62 pub mutability: Option<Token![mut]>,
63 pub ident: Ident,
64}
65
David Tolnay7db73692019-10-20 14:51:12 -040066pub enum Type {
67 Ident(Ident),
68 RustBox(Box<Ty1>),
69 UniquePtr(Box<Ty1>),
70 Ref(Box<Ref>),
71 Str(Box<Ref>),
David Tolnay2fb14e92020-03-15 23:11:38 -070072 Void(Span),
David Tolnay7db73692019-10-20 14:51:12 -040073}
74
75pub struct Ty1 {
76 pub name: Ident,
77 pub langle: Token![<],
78 pub inner: Type,
79 pub rangle: Token![>],
80}
81
82pub struct Ref {
83 pub ampersand: Token![&],
84 pub mutability: Option<Token![mut]>,
85 pub inner: Type,
86}
87
88#[derive(Copy, Clone, PartialEq)]
89pub enum Derive {
90 Clone,
91 Copy,
92}