blob: 39198cc2cb21d2f0fb3196a4b1dcedb4f178b97a [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
16use proc_macro2::Ident;
17use syn::{LitStr, Token};
18
19pub use self::atom::Atom;
20pub use self::doc::Doc;
21pub use self::parse::parse_items;
David Tolnayfb134ed2020-03-15 23:17:48 -070022pub use self::span::Span;
David Tolnay7db73692019-10-20 14:51:12 -040023pub 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
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)]
91pub enum Derive {
92 Clone,
93 Copy,
94}