blob: 1acb9a500ffcc7ea85209b4ae808ab102b43e715 [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;
David Tolnay2fb14e92020-03-15 23:11:38 -070012mod span;
David Tolnay7db73692019-10-20 14:51:12 -040013mod tokens;
14pub mod types;
15
David Tolnay2fb14e92020-03-15 23:11:38 -070016use self::span::Span;
David Tolnay7db73692019-10-20 14:51:12 -040017use proc_macro2::Ident;
18use syn::{LitStr, Token};
19
20pub use self::atom::Atom;
21pub use self::doc::Doc;
22pub use self::parse::parse_items;
23pub use self::types::Types;
24
25pub enum Api {
26 Include(LitStr),
27 Struct(Struct),
28 CxxType(ExternType),
29 CxxFunction(ExternFn),
30 RustType(ExternType),
31 RustFunction(ExternFn),
32}
33
34pub struct ExternType {
35 pub doc: Doc,
36 pub type_token: Token![type],
37 pub ident: Ident,
38}
39
40pub struct Struct {
41 pub doc: Doc,
42 pub derives: Vec<Ident>,
43 pub struct_token: Token![struct],
44 pub ident: Ident,
45 pub fields: Vec<Var>,
46}
47
48pub struct ExternFn {
49 pub doc: Doc,
50 pub fn_token: Token![fn],
51 pub ident: Ident,
52 pub receiver: Option<Receiver>,
53 pub args: Vec<Var>,
54 pub ret: Option<Type>,
55 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
68#[derive(Hash, Eq, PartialEq)]
69pub enum Type {
70 Ident(Ident),
71 RustBox(Box<Ty1>),
72 UniquePtr(Box<Ty1>),
73 Ref(Box<Ref>),
74 Str(Box<Ref>),
David Tolnay2fb14e92020-03-15 23:11:38 -070075 Void(Span),
David Tolnay7db73692019-10-20 14:51:12 -040076}
77
78pub struct Ty1 {
79 pub name: Ident,
80 pub langle: Token![<],
81 pub inner: Type,
82 pub rangle: Token![>],
83}
84
85pub struct Ref {
86 pub ampersand: Token![&],
87 pub mutability: Option<Token![mut]>,
88 pub inner: Type,
89}
90
91#[derive(Copy, Clone, PartialEq)]
92pub enum Derive {
93 Clone,
94 Copy,
95}