| 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; |
| David Tolnay | 0841930 | 2020-04-19 20:38:20 -0700 | [diff] [blame] | 10 | pub mod namespace; |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 11 | mod parse; |
| 12 | pub mod set; |
| 13 | mod tokens; |
| 14 | pub mod types; |
| 15 | |
| David Tolnay | e3a4815 | 2020-04-08 19:38:05 -0700 | [diff] [blame] | 16 | use self::parse::kw; |
| 17 | use proc_macro2::{Ident, Span}; |
| 18 | use syn::punctuated::Punctuated; |
| Adrian Taylor | f5dd552 | 2020-04-13 16:50:14 -0700 | [diff] [blame] | 19 | use syn::token::{Brace, Bracket, Paren}; |
| David Tolnay | e3a4815 | 2020-04-08 19:38:05 -0700 | [diff] [blame] | 20 | use syn::{LitStr, Token}; |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 21 | |
| 22 | pub use self::atom::Atom; |
| 23 | pub use self::doc::Doc; |
| 24 | pub use self::parse::parse_items; |
| 25 | pub use self::types::Types; |
| 26 | |
| 27 | pub enum Api { |
| 28 | Include(LitStr), |
| 29 | Struct(Struct), |
| 30 | CxxType(ExternType), |
| 31 | CxxFunction(ExternFn), |
| 32 | RustType(ExternType), |
| 33 | RustFunction(ExternFn), |
| 34 | } |
| 35 | |
| 36 | pub struct ExternType { |
| 37 | pub doc: Doc, |
| 38 | pub type_token: Token![type], |
| 39 | pub ident: Ident, |
| 40 | } |
| 41 | |
| 42 | pub struct Struct { |
| 43 | pub doc: Doc, |
| 44 | pub derives: Vec<Ident>, |
| 45 | pub struct_token: Token![struct], |
| 46 | pub ident: Ident, |
| David Tolnay | 09462ac | 2020-03-20 14:58:41 -0700 | [diff] [blame] | 47 | pub brace_token: Brace, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 48 | pub fields: Vec<Var>, |
| 49 | } |
| 50 | |
| 51 | pub struct ExternFn { |
| David Tolnay | 6cde49f | 2020-03-16 12:25:45 -0700 | [diff] [blame] | 52 | pub lang: Lang, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 53 | pub doc: Doc, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 54 | pub ident: Ident, |
| David Tolnay | 1644873 | 2020-03-18 12:39:36 -0700 | [diff] [blame] | 55 | pub sig: Signature, |
| 56 | pub semi_token: Token![;], |
| 57 | } |
| 58 | |
| 59 | pub struct Signature { |
| 60 | pub fn_token: Token![fn], |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 61 | pub receiver: Option<Receiver>, |
| David Tolnay | e3a4815 | 2020-04-08 19:38:05 -0700 | [diff] [blame] | 62 | pub args: Punctuated<Var, Token![,]>, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 63 | pub ret: Option<Type>, |
| David Tolnay | 59b7ede | 2020-03-16 00:30:23 -0700 | [diff] [blame] | 64 | pub throws: bool, |
| David Tolnay | e3a4815 | 2020-04-08 19:38:05 -0700 | [diff] [blame] | 65 | pub paren_token: Paren, |
| 66 | pub throws_tokens: Option<(kw::Result, Token![<], Token![>])>, |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| David Tolnay | 417305a | 2020-03-18 13:54:00 -0700 | [diff] [blame] | 69 | #[derive(Eq, PartialEq, Hash)] |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 70 | pub struct Var { |
| 71 | pub ident: Ident, |
| 72 | pub ty: Type, |
| 73 | } |
| 74 | |
| 75 | pub struct Receiver { |
| 76 | pub mutability: Option<Token![mut]>, |
| 77 | pub ident: Ident, |
| 78 | } |
| 79 | |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 80 | pub enum Type { |
| 81 | Ident(Ident), |
| 82 | RustBox(Box<Ty1>), |
| 83 | UniquePtr(Box<Ty1>), |
| 84 | Ref(Box<Ref>), |
| 85 | Str(Box<Ref>), |
| David Tolnay | 417305a | 2020-03-18 13:54:00 -0700 | [diff] [blame] | 86 | Fn(Box<Signature>), |
| David Tolnay | 2fb14e9 | 2020-03-15 23:11:38 -0700 | [diff] [blame] | 87 | Void(Span), |
| Adrian Taylor | f5dd552 | 2020-04-13 16:50:14 -0700 | [diff] [blame] | 88 | Slice(Box<Slice>), |
| 89 | SliceRefU8(Box<Ref>), |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | pub struct Ty1 { |
| 93 | pub name: Ident, |
| 94 | pub langle: Token![<], |
| 95 | pub inner: Type, |
| 96 | pub rangle: Token![>], |
| 97 | } |
| 98 | |
| 99 | pub struct Ref { |
| 100 | pub ampersand: Token![&], |
| 101 | pub mutability: Option<Token![mut]>, |
| 102 | pub inner: Type, |
| 103 | } |
| 104 | |
| Adrian Taylor | f5dd552 | 2020-04-13 16:50:14 -0700 | [diff] [blame] | 105 | pub struct Slice { |
| 106 | pub bracket: Bracket, |
| 107 | pub inner: Type, |
| 108 | } |
| 109 | |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 110 | #[derive(Copy, Clone, PartialEq)] |
| David Tolnay | 6cde49f | 2020-03-16 12:25:45 -0700 | [diff] [blame] | 111 | pub enum Lang { |
| 112 | Cxx, |
| 113 | Rust, |
| 114 | } |
| 115 | |
| 116 | #[derive(Copy, Clone, PartialEq)] |
| David Tolnay | 7db7369 | 2019-10-20 14:51:12 -0400 | [diff] [blame] | 117 | pub enum Derive { |
| 118 | Clone, |
| 119 | Copy, |
| 120 | } |