blob: c992690ff5e9806d22ab3f7512ff8141f7f7dd76 [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;
David Tolnay3caa50a2020-04-19 21:25:34 -070010pub mod mangle;
Myron Ahneba35cf2020-02-05 19:41:51 +070011pub mod mangled;
David Tolnay08419302020-04-19 20:38:20 -070012pub mod namespace;
David Tolnay7db73692019-10-20 14:51:12 -040013mod parse;
14pub mod set;
David Tolnay891061b2020-04-19 22:42:33 -070015pub mod symbol;
David Tolnay7db73692019-10-20 14:51:12 -040016mod tokens;
Myron Ahneba35cf2020-02-05 19:41:51 +070017pub mod typename;
David Tolnay7db73692019-10-20 14:51:12 -040018pub mod types;
19
David Tolnaye3a48152020-04-08 19:38:05 -070020use self::parse::kw;
21use proc_macro2::{Ident, Span};
22use syn::punctuated::Punctuated;
Adrian Taylorf5dd5522020-04-13 16:50:14 -070023use syn::token::{Brace, Bracket, Paren};
David Tolnay0bd50fa2020-04-22 15:31:33 -070024use syn::{Lifetime, LitStr, Token};
David Tolnay7db73692019-10-20 14:51:12 -040025
26pub use self::atom::Atom;
27pub use self::doc::Doc;
28pub use self::parse::parse_items;
29pub use self::types::Types;
30
31pub enum Api {
32 Include(LitStr),
33 Struct(Struct),
34 CxxType(ExternType),
35 CxxFunction(ExternFn),
36 RustType(ExternType),
37 RustFunction(ExternFn),
38}
39
40pub struct ExternType {
41 pub doc: Doc,
42 pub type_token: Token![type],
43 pub ident: Ident,
44}
45
46pub struct Struct {
47 pub doc: Doc,
48 pub derives: Vec<Ident>,
49 pub struct_token: Token![struct],
50 pub ident: Ident,
David Tolnay09462ac2020-03-20 14:58:41 -070051 pub brace_token: Brace,
David Tolnay7db73692019-10-20 14:51:12 -040052 pub fields: Vec<Var>,
53}
54
55pub struct ExternFn {
David Tolnay6cde49f2020-03-16 12:25:45 -070056 pub lang: Lang,
David Tolnay7db73692019-10-20 14:51:12 -040057 pub doc: Doc,
David Tolnay7db73692019-10-20 14:51:12 -040058 pub ident: Ident,
David Tolnay16448732020-03-18 12:39:36 -070059 pub sig: Signature,
60 pub semi_token: Token![;],
61}
62
63pub struct Signature {
64 pub fn_token: Token![fn],
David Tolnay7db73692019-10-20 14:51:12 -040065 pub receiver: Option<Receiver>,
David Tolnaye3a48152020-04-08 19:38:05 -070066 pub args: Punctuated<Var, Token![,]>,
David Tolnay7db73692019-10-20 14:51:12 -040067 pub ret: Option<Type>,
David Tolnay59b7ede2020-03-16 00:30:23 -070068 pub throws: bool,
David Tolnaye3a48152020-04-08 19:38:05 -070069 pub paren_token: Paren,
70 pub throws_tokens: Option<(kw::Result, Token![<], Token![>])>,
David Tolnay7db73692019-10-20 14:51:12 -040071}
72
David Tolnay417305a2020-03-18 13:54:00 -070073#[derive(Eq, PartialEq, Hash)]
David Tolnay7db73692019-10-20 14:51:12 -040074pub struct Var {
75 pub ident: Ident,
76 pub ty: Type,
77}
78
79pub struct Receiver {
David Tolnayfb6e3862020-04-20 01:33:23 -070080 pub ampersand: Token![&],
David Tolnay0bd50fa2020-04-22 15:31:33 -070081 pub lifetime: Option<Lifetime>,
David Tolnay7db73692019-10-20 14:51:12 -040082 pub mutability: Option<Token![mut]>,
David Tolnay05e11cc2020-04-20 02:13:56 -070083 pub var: Token![self],
84 pub ty: Ident,
David Tolnay62d360c2020-04-22 16:26:21 -070085 pub shorthand: bool,
David Tolnay7db73692019-10-20 14:51:12 -040086}
87
David Tolnay7db73692019-10-20 14:51:12 -040088pub enum Type {
89 Ident(Ident),
90 RustBox(Box<Ty1>),
Myron Ahneba35cf2020-02-05 19:41:51 +070091 RustVec(Box<Ty1>),
David Tolnay7db73692019-10-20 14:51:12 -040092 UniquePtr(Box<Ty1>),
93 Ref(Box<Ref>),
94 Str(Box<Ref>),
David Tolnay4377a9e2020-04-24 15:20:26 -070095 CxxVector(Box<Ty1>),
David Tolnay417305a2020-03-18 13:54:00 -070096 Fn(Box<Signature>),
David Tolnay2fb14e92020-03-15 23:11:38 -070097 Void(Span),
Adrian Taylorf5dd5522020-04-13 16:50:14 -070098 Slice(Box<Slice>),
99 SliceRefU8(Box<Ref>),
David Tolnay7db73692019-10-20 14:51:12 -0400100}
101
102pub struct Ty1 {
103 pub name: Ident,
104 pub langle: Token![<],
105 pub inner: Type,
106 pub rangle: Token![>],
107}
108
109pub struct Ref {
110 pub ampersand: Token![&],
David Tolnay0bd50fa2020-04-22 15:31:33 -0700111 pub lifetime: Option<Lifetime>,
David Tolnay7db73692019-10-20 14:51:12 -0400112 pub mutability: Option<Token![mut]>,
113 pub inner: Type,
114}
115
Adrian Taylorf5dd5522020-04-13 16:50:14 -0700116pub struct Slice {
117 pub bracket: Bracket,
118 pub inner: Type,
119}
120
David Tolnay7db73692019-10-20 14:51:12 -0400121#[derive(Copy, Clone, PartialEq)]
David Tolnay6cde49f2020-03-16 12:25:45 -0700122pub enum Lang {
123 Cxx,
124 Rust,
125}
126
127#[derive(Copy, Clone, PartialEq)]
David Tolnay7db73692019-10-20 14:51:12 -0400128pub enum Derive {
129 Clone,
130 Copy,
131}