| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 1 | // Functionality that is shared between the cxxbridge macro and the cmd. |
| 2 | |
| 3 | pub mod atom; |
| 4 | mod attrs; |
| 5 | pub mod check; |
| 6 | mod doc; |
| 7 | pub mod error; |
| 8 | pub mod ident; |
| 9 | mod impls; |
| 10 | mod parse; |
| 11 | pub mod set; |
| 12 | mod tokens; |
| 13 | pub mod types; |
| 14 | |
| David Tolnay | d0bb364 | 2020-03-15 23:27:11 -0700 | [diff] [blame] | 15 | use proc_macro2::{Ident, Span}; |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 16 | use syn::{LitStr, Token}; |
| 17 | |
| 18 | pub use self::atom::Atom; |
| 19 | pub use self::doc::Doc; |
| 20 | pub use self::parse::parse_items; |
| 21 | pub use self::types::Types; |
| 22 | |
| 23 | pub enum Api { |
| 24 | Include(LitStr), |
| 25 | Struct(Struct), |
| 26 | CxxType(ExternType), |
| 27 | CxxFunction(ExternFn), |
| 28 | RustType(ExternType), |
| 29 | RustFunction(ExternFn), |
| 30 | } |
| 31 | |
| 32 | pub struct ExternType { |
| 33 | pub doc: Doc, |
| 34 | pub type_token: Token![type], |
| 35 | pub ident: Ident, |
| 36 | } |
| 37 | |
| 38 | pub 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 | |
| 46 | pub struct ExternFn { |
| David Tolnay | 6cde49f | 2020-03-16 12:25:45 -0700 | [diff] [blame] | 47 | pub lang: Lang, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 48 | pub doc: Doc, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 49 | pub ident: Ident, |
| David Tolnay | 1644873 | 2020-03-18 12:39:36 -0700 | [diff] [blame] | 50 | pub sig: Signature, |
| 51 | pub semi_token: Token![;], |
| 52 | } |
| 53 | |
| 54 | pub struct Signature { |
| 55 | pub fn_token: Token![fn], |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 56 | pub receiver: Option<Receiver>, |
| 57 | pub args: Vec<Var>, |
| 58 | pub ret: Option<Type>, |
| David Tolnay | 59b7ede | 2020-03-16 00:30:23 -0700 | [diff] [blame] | 59 | pub throws: bool, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 60 | } |
| 61 | |
| David Tolnay | 417305a | 2020-03-18 13:54:00 -0700 | [diff] [blame^] | 62 | #[derive(Eq, PartialEq, Hash)] |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 63 | pub struct Var { |
| 64 | pub ident: Ident, |
| 65 | pub ty: Type, |
| 66 | } |
| 67 | |
| 68 | pub struct Receiver { |
| 69 | pub mutability: Option<Token![mut]>, |
| 70 | pub ident: Ident, |
| 71 | } |
| 72 | |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 73 | pub enum Type { |
| 74 | Ident(Ident), |
| 75 | RustBox(Box<Ty1>), |
| 76 | UniquePtr(Box<Ty1>), |
| 77 | Ref(Box<Ref>), |
| 78 | Str(Box<Ref>), |
| David Tolnay | 417305a | 2020-03-18 13:54:00 -0700 | [diff] [blame^] | 79 | Fn(Box<Signature>), |
| David Tolnay | 2fb14e9 | 2020-03-15 23:11:38 -0700 | [diff] [blame] | 80 | Void(Span), |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | pub struct Ty1 { |
| 84 | pub name: Ident, |
| 85 | pub langle: Token![<], |
| 86 | pub inner: Type, |
| 87 | pub rangle: Token![>], |
| 88 | } |
| 89 | |
| 90 | pub struct Ref { |
| 91 | pub ampersand: Token![&], |
| 92 | pub mutability: Option<Token![mut]>, |
| 93 | pub inner: Type, |
| 94 | } |
| 95 | |
| 96 | #[derive(Copy, Clone, PartialEq)] |
| David Tolnay | 6cde49f | 2020-03-16 12:25:45 -0700 | [diff] [blame] | 97 | pub enum Lang { |
| 98 | Cxx, |
| 99 | Rust, |
| 100 | } |
| 101 | |
| 102 | #[derive(Copy, Clone, PartialEq)] |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 103 | pub enum Derive { |
| 104 | Clone, |
| 105 | Copy, |
| 106 | } |