2019-10-20 14:51:12 -04:00
|
|
|
// Functionality that is shared between the cxxbridge macro and the cmd.
|
|
|
|
|
|
|
|
pub mod atom;
|
2020-12-30 16:18:05 -08:00
|
|
|
pub mod attrs;
|
2019-10-20 14:51:12 -04:00
|
|
|
pub mod check;
|
2020-11-27 14:30:12 -08:00
|
|
|
pub mod derive;
|
2020-05-08 15:55:28 -07:00
|
|
|
mod discriminant;
|
2019-10-20 14:51:12 -04:00
|
|
|
mod doc;
|
|
|
|
pub mod error;
|
2020-08-29 11:27:05 -07:00
|
|
|
pub mod file;
|
2019-10-20 14:51:12 -04:00
|
|
|
pub mod ident;
|
|
|
|
mod impls;
|
2020-11-02 12:57:57 -08:00
|
|
|
mod improper;
|
2020-12-31 15:01:04 -08:00
|
|
|
pub mod instantiate;
|
2020-04-19 21:25:34 -07:00
|
|
|
pub mod mangle;
|
2020-12-31 16:41:05 -08:00
|
|
|
pub mod map;
|
2020-11-01 12:34:51 -08:00
|
|
|
mod names;
|
2020-04-19 20:38:20 -07:00
|
|
|
pub mod namespace;
|
2019-10-20 14:51:12 -04:00
|
|
|
mod parse;
|
2020-12-09 23:42:07 -08:00
|
|
|
mod pod;
|
2020-09-06 23:28:18 -07:00
|
|
|
pub mod qualified;
|
2020-05-03 23:23:18 -07:00
|
|
|
pub mod report;
|
2020-12-31 23:34:53 -08:00
|
|
|
mod resolve;
|
2019-10-20 14:51:12 -04:00
|
|
|
pub mod set;
|
2020-04-19 22:42:33 -07:00
|
|
|
pub mod symbol;
|
2019-10-20 14:51:12 -04:00
|
|
|
mod tokens;
|
2020-11-03 18:27:10 -08:00
|
|
|
mod toposort;
|
2020-12-20 21:04:04 -08:00
|
|
|
pub mod trivial;
|
2019-10-20 14:51:12 -04:00
|
|
|
pub mod types;
|
|
|
|
|
2020-12-30 16:39:21 -08:00
|
|
|
use self::attrs::OtherAttrs;
|
2020-05-08 15:55:28 -07:00
|
|
|
use self::discriminant::Discriminant;
|
2020-10-21 18:20:55 -07:00
|
|
|
use self::namespace::Namespace;
|
2020-04-08 19:38:05 -07:00
|
|
|
use self::parse::kw;
|
2020-10-21 18:20:55 -07:00
|
|
|
use self::symbol::Symbol;
|
2020-04-08 19:38:05 -07:00
|
|
|
use proc_macro2::{Ident, Span};
|
|
|
|
use syn::punctuated::Punctuated;
|
2020-04-13 16:50:14 -07:00
|
|
|
use syn::token::{Brace, Bracket, Paren};
|
2020-12-30 16:39:21 -08:00
|
|
|
use syn::{Expr, Generics, Lifetime, LitInt, Token, Type as RustType};
|
2019-10-20 14:51:12 -04:00
|
|
|
|
|
|
|
pub use self::atom::Atom;
|
2020-11-27 12:06:12 -08:00
|
|
|
pub use self::derive::{Derive, Trait};
|
2019-10-20 14:51:12 -04:00
|
|
|
pub use self::doc::Doc;
|
2021-01-01 14:59:40 -08:00
|
|
|
pub use self::names::ForeignName;
|
2019-10-20 14:51:12 -04:00
|
|
|
pub use self::parse::parse_items;
|
|
|
|
pub use self::types::Types;
|
|
|
|
|
|
|
|
pub enum Api {
|
2020-10-27 21:32:54 -07:00
|
|
|
Include(Include),
|
2019-10-20 14:51:12 -04:00
|
|
|
Struct(Struct),
|
2020-04-23 17:31:09 -07:00
|
|
|
Enum(Enum),
|
2019-10-20 14:51:12 -04:00
|
|
|
CxxType(ExternType),
|
|
|
|
CxxFunction(ExternFn),
|
|
|
|
RustType(ExternType),
|
|
|
|
RustFunction(ExternFn),
|
2020-05-04 02:34:33 -07:00
|
|
|
TypeAlias(TypeAlias),
|
2020-10-03 22:20:22 -07:00
|
|
|
Impl(Impl),
|
2019-10-20 14:51:12 -04:00
|
|
|
}
|
|
|
|
|
2020-10-27 21:32:54 -07:00
|
|
|
pub struct Include {
|
|
|
|
pub path: String,
|
|
|
|
pub kind: IncludeKind,
|
|
|
|
pub begin_span: Span,
|
|
|
|
pub end_span: Span,
|
|
|
|
}
|
|
|
|
|
2020-10-28 12:40:27 -07:00
|
|
|
/// Whether to emit `#include "path"` or `#include <path>`.
|
|
|
|
#[derive(Copy, Clone, PartialEq, Debug)]
|
2020-10-27 21:32:54 -07:00
|
|
|
pub enum IncludeKind {
|
2020-10-28 12:40:27 -07:00
|
|
|
/// `#include "quoted/path/to"`
|
|
|
|
Quoted,
|
|
|
|
/// `#include <bracketed/path/to>`
|
|
|
|
Bracketed,
|
2020-10-27 21:32:54 -07:00
|
|
|
}
|
|
|
|
|
2019-10-20 14:51:12 -04:00
|
|
|
pub struct ExternType {
|
2020-11-27 19:28:37 -08:00
|
|
|
pub lang: Lang,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub doc: Doc,
|
2020-11-27 19:28:37 -08:00
|
|
|
pub derives: Vec<Derive>,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-30 17:25:38 -08:00
|
|
|
pub visibility: Token![pub],
|
2019-10-20 14:51:12 -04:00
|
|
|
pub type_token: Token![type],
|
2020-11-02 00:40:04 -08:00
|
|
|
pub name: Pair,
|
2020-12-28 22:04:10 -08:00
|
|
|
pub generics: Lifetimes,
|
2020-11-27 20:00:53 -08:00
|
|
|
pub colon_token: Option<Token![:]>,
|
|
|
|
pub bounds: Vec<Derive>,
|
2020-08-25 21:57:53 -07:00
|
|
|
pub semi_token: Token![;],
|
2020-08-29 19:07:18 -07:00
|
|
|
pub trusted: bool,
|
2019-10-20 14:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Struct {
|
|
|
|
pub doc: Doc,
|
2020-05-10 14:24:29 -07:00
|
|
|
pub derives: Vec<Derive>,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-30 15:26:06 -08:00
|
|
|
pub visibility: Token![pub],
|
2019-10-20 14:51:12 -04:00
|
|
|
pub struct_token: Token![struct],
|
2020-11-02 00:40:04 -08:00
|
|
|
pub name: Pair,
|
2021-01-01 18:26:26 -08:00
|
|
|
pub generics: Lifetimes,
|
2020-03-20 14:58:41 -07:00
|
|
|
pub brace_token: Brace,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub fields: Vec<Var>,
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:31:09 -07:00
|
|
|
pub struct Enum {
|
|
|
|
pub doc: Doc,
|
2020-11-27 11:33:29 -08:00
|
|
|
pub derives: Vec<Derive>,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-30 17:15:46 -08:00
|
|
|
pub visibility: Token![pub],
|
2020-04-23 17:31:09 -07:00
|
|
|
pub enum_token: Token![enum],
|
2020-11-02 00:40:04 -08:00
|
|
|
pub name: Pair,
|
2021-01-01 18:26:26 -08:00
|
|
|
pub generics: Lifetimes,
|
2020-04-23 17:31:09 -07:00
|
|
|
pub brace_token: Brace,
|
|
|
|
pub variants: Vec<Variant>,
|
2020-05-10 20:52:00 -07:00
|
|
|
pub repr: Atom,
|
2020-11-16 09:16:41 -08:00
|
|
|
pub repr_type: Type,
|
2020-11-20 20:37:58 -08:00
|
|
|
pub explicit_repr: bool,
|
2020-04-23 17:31:09 -07:00
|
|
|
}
|
|
|
|
|
2019-10-20 14:51:12 -04:00
|
|
|
pub struct ExternFn {
|
2020-03-16 12:25:45 -07:00
|
|
|
pub lang: Lang,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub doc: Doc,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-30 18:02:38 -08:00
|
|
|
pub visibility: Token![pub],
|
2020-11-02 00:40:04 -08:00
|
|
|
pub name: Pair,
|
2020-03-18 12:39:36 -07:00
|
|
|
pub sig: Signature,
|
|
|
|
pub semi_token: Token![;],
|
2020-11-15 13:58:44 -08:00
|
|
|
pub trusted: bool,
|
2020-03-18 12:39:36 -07:00
|
|
|
}
|
|
|
|
|
2020-05-04 02:34:33 -07:00
|
|
|
pub struct TypeAlias {
|
2020-09-13 10:34:31 -07:00
|
|
|
pub doc: Doc,
|
2020-11-27 20:00:53 -08:00
|
|
|
pub derives: Vec<Derive>,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-30 17:31:19 -08:00
|
|
|
pub visibility: Token![pub],
|
2020-05-04 02:34:33 -07:00
|
|
|
pub type_token: Token![type],
|
2020-11-02 00:40:04 -08:00
|
|
|
pub name: Pair,
|
2020-12-28 22:04:10 -08:00
|
|
|
pub generics: Lifetimes,
|
2020-05-04 02:34:33 -07:00
|
|
|
pub eq_token: Token![=],
|
|
|
|
pub ty: RustType,
|
|
|
|
pub semi_token: Token![;],
|
|
|
|
}
|
|
|
|
|
2020-10-03 22:20:22 -07:00
|
|
|
pub struct Impl {
|
|
|
|
pub impl_token: Token![impl],
|
2021-01-01 19:39:35 -08:00
|
|
|
pub impl_generics: Lifetimes,
|
2020-11-29 18:09:52 -08:00
|
|
|
pub negative: bool,
|
2020-10-03 22:20:22 -07:00
|
|
|
pub ty: Type,
|
2021-01-01 19:39:35 -08:00
|
|
|
pub ty_generics: Lifetimes,
|
2020-10-03 22:20:22 -07:00
|
|
|
pub brace_token: Brace,
|
2020-11-29 18:09:52 -08:00
|
|
|
pub negative_token: Option<Token![!]>,
|
2020-10-03 22:20:22 -07:00
|
|
|
}
|
|
|
|
|
2021-01-01 19:39:35 -08:00
|
|
|
#[derive(Clone, Default)]
|
2020-12-28 22:04:10 -08:00
|
|
|
pub struct Lifetimes {
|
|
|
|
pub lt_token: Option<Token![<]>,
|
|
|
|
pub lifetimes: Punctuated<Lifetime, Token![,]>,
|
|
|
|
pub gt_token: Option<Token![>]>,
|
|
|
|
}
|
|
|
|
|
2020-03-18 12:39:36 -07:00
|
|
|
pub struct Signature {
|
2020-09-06 23:45:55 -07:00
|
|
|
pub unsafety: Option<Token![unsafe]>,
|
2020-03-18 12:39:36 -07:00
|
|
|
pub fn_token: Token![fn],
|
2020-11-15 18:11:40 -08:00
|
|
|
pub generics: Generics,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub receiver: Option<Receiver>,
|
2020-04-08 19:38:05 -07:00
|
|
|
pub args: Punctuated<Var, Token![,]>,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub ret: Option<Type>,
|
2020-03-16 00:30:23 -07:00
|
|
|
pub throws: bool,
|
2020-04-08 19:38:05 -07:00
|
|
|
pub paren_token: Paren,
|
|
|
|
pub throws_tokens: Option<(kw::Result, Token![<], Token![>])>,
|
2019-10-20 14:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Var {
|
2020-12-30 15:37:01 -08:00
|
|
|
pub doc: Doc,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-30 15:10:40 -08:00
|
|
|
pub visibility: Token![pub],
|
2021-01-01 15:30:14 -08:00
|
|
|
pub name: Pair,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub ty: Type,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Receiver {
|
2020-11-15 16:07:08 -08:00
|
|
|
pub pinned: bool,
|
2020-04-20 01:33:23 -07:00
|
|
|
pub ampersand: Token![&],
|
2020-04-22 15:31:33 -07:00
|
|
|
pub lifetime: Option<Lifetime>,
|
2020-11-15 21:14:03 -08:00
|
|
|
pub mutable: bool,
|
2020-04-20 02:13:56 -07:00
|
|
|
pub var: Token![self],
|
2021-01-01 14:15:18 -08:00
|
|
|
pub ty: NamedType,
|
2020-04-22 16:26:21 -07:00
|
|
|
pub shorthand: bool,
|
2020-11-15 16:07:08 -08:00
|
|
|
pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>,
|
2020-11-15 21:14:03 -08:00
|
|
|
pub mutability: Option<Token![mut]>,
|
2019-10-20 14:51:12 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 17:31:09 -07:00
|
|
|
pub struct Variant {
|
2020-12-30 00:01:26 -08:00
|
|
|
pub doc: Doc,
|
2020-12-30 16:39:21 -08:00
|
|
|
pub attrs: OtherAttrs,
|
2020-12-21 16:00:41 -08:00
|
|
|
pub name: Pair,
|
2020-05-08 15:55:28 -07:00
|
|
|
pub discriminant: Discriminant,
|
2020-05-10 17:37:16 -07:00
|
|
|
pub expr: Option<Expr>,
|
2020-04-23 17:31:09 -07:00
|
|
|
}
|
|
|
|
|
2019-10-20 14:51:12 -04:00
|
|
|
pub enum Type {
|
2021-01-01 14:15:18 -08:00
|
|
|
Ident(NamedType),
|
2019-10-20 14:51:12 -04:00
|
|
|
RustBox(Box<Ty1>),
|
2020-02-05 19:41:51 +07:00
|
|
|
RustVec(Box<Ty1>),
|
2019-10-20 14:51:12 -04:00
|
|
|
UniquePtr(Box<Ty1>),
|
2020-12-01 15:27:43 -08:00
|
|
|
SharedPtr(Box<Ty1>),
|
2020-12-28 17:09:48 -08:00
|
|
|
WeakPtr(Box<Ty1>),
|
2019-10-20 14:51:12 -04:00
|
|
|
Ref(Box<Ref>),
|
|
|
|
Str(Box<Ref>),
|
2020-04-24 15:20:26 -07:00
|
|
|
CxxVector(Box<Ty1>),
|
2020-03-18 13:54:00 -07:00
|
|
|
Fn(Box<Signature>),
|
2020-03-15 23:11:38 -07:00
|
|
|
Void(Span),
|
2020-11-25 17:44:05 -08:00
|
|
|
SliceRef(Box<SliceRef>),
|
2020-11-12 10:24:18 +08:00
|
|
|
Array(Box<Array>),
|
2019-10-20 14:51:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Ty1 {
|
2020-11-02 00:36:00 -08:00
|
|
|
pub name: Ident,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub langle: Token![<],
|
|
|
|
pub inner: Type,
|
|
|
|
pub rangle: Token![>],
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Ref {
|
2020-11-15 15:07:04 -08:00
|
|
|
pub pinned: bool,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub ampersand: Token![&],
|
2020-04-22 15:31:33 -07:00
|
|
|
pub lifetime: Option<Lifetime>,
|
2020-11-15 21:14:03 -08:00
|
|
|
pub mutable: bool,
|
2019-10-20 14:51:12 -04:00
|
|
|
pub inner: Type,
|
2020-11-15 15:07:04 -08:00
|
|
|
pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>,
|
2020-11-15 21:14:03 -08:00
|
|
|
pub mutability: Option<Token![mut]>,
|
2019-10-20 14:51:12 -04:00
|
|
|
}
|
|
|
|
|
2020-11-25 17:18:57 -08:00
|
|
|
pub struct SliceRef {
|
|
|
|
pub ampersand: Token![&],
|
|
|
|
pub lifetime: Option<Lifetime>,
|
|
|
|
pub mutable: bool,
|
2020-04-13 16:50:14 -07:00
|
|
|
pub bracket: Bracket,
|
|
|
|
pub inner: Type,
|
2020-11-25 17:18:57 -08:00
|
|
|
pub mutability: Option<Token![mut]>,
|
2020-04-13 16:50:14 -07:00
|
|
|
}
|
|
|
|
|
2020-11-12 10:24:18 +08:00
|
|
|
pub struct Array {
|
|
|
|
pub bracket: Bracket,
|
|
|
|
pub inner: Type,
|
|
|
|
pub semi_token: Token![;],
|
|
|
|
pub len: usize,
|
2020-11-24 20:45:13 -08:00
|
|
|
pub len_token: LitInt,
|
2020-11-12 10:24:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-16 12:25:45 -07:00
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum Lang {
|
|
|
|
Cxx,
|
|
|
|
Rust,
|
|
|
|
}
|
2020-10-21 18:20:55 -07:00
|
|
|
|
2020-10-30 21:21:23 -07:00
|
|
|
// An association of a defined Rust name with a fully resolved, namespace
|
|
|
|
// qualified C++ name.
|
2020-10-30 21:18:54 -07:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Pair {
|
2020-11-01 20:45:14 -08:00
|
|
|
pub namespace: Namespace,
|
2021-01-01 14:59:40 -08:00
|
|
|
pub cxx: ForeignName,
|
2020-11-02 00:18:19 -08:00
|
|
|
pub rust: Ident,
|
2020-10-30 21:18:54 -07:00
|
|
|
}
|
|
|
|
|
2020-10-30 21:20:07 -07:00
|
|
|
// Wrapper for a type which needs to be resolved before it can be printed in
|
|
|
|
// C++.
|
2020-12-30 19:48:42 -08:00
|
|
|
#[derive(PartialEq, Eq, Hash)]
|
2021-01-01 14:15:18 -08:00
|
|
|
pub struct NamedType {
|
2020-10-30 21:16:03 -07:00
|
|
|
pub rust: Ident,
|
2020-12-30 19:48:42 -08:00
|
|
|
pub generics: Lifetimes,
|
2020-10-21 18:20:55 -07:00
|
|
|
}
|