| 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 | |
| 15 | use proc_macro2::Ident; |
| 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 { |
| 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 | |
| 56 | pub struct Var { |
| 57 | pub ident: Ident, |
| 58 | pub ty: Type, |
| 59 | } |
| 60 | |
| 61 | pub struct Receiver { |
| 62 | pub mutability: Option<Token![mut]>, |
| 63 | pub ident: Ident, |
| 64 | } |
| 65 | |
| 66 | #[derive(Hash, Eq, PartialEq)] |
| 67 | pub enum Type { |
| 68 | Ident(Ident), |
| 69 | RustBox(Box<Ty1>), |
| 70 | UniquePtr(Box<Ty1>), |
| 71 | Ref(Box<Ref>), |
| 72 | Str(Box<Ref>), |
| 73 | } |
| 74 | |
| 75 | pub struct Ty1 { |
| 76 | pub name: Ident, |
| 77 | pub langle: Token![<], |
| 78 | pub inner: Type, |
| 79 | pub rangle: Token![>], |
| 80 | } |
| 81 | |
| 82 | pub struct Ref { |
| 83 | pub ampersand: Token![&], |
| 84 | pub mutability: Option<Token![mut]>, |
| 85 | pub inner: Type, |
| 86 | } |
| 87 | |
| 88 | #[derive(Copy, Clone, PartialEq)] |
| 89 | pub enum Derive { |
| 90 | Clone, |
| 91 | Copy, |
| 92 | } |