// Functionality that is shared between the cxxbridge macro and the cmd. pub mod atom; pub mod attrs; pub mod check; pub mod derive; mod discriminant; mod doc; pub mod error; pub mod file; pub mod ident; mod impls; mod improper; pub mod instantiate; pub mod mangle; pub mod map; mod names; pub mod namespace; mod parse; mod pod; pub mod qualified; pub mod report; pub mod resolve; pub mod set; pub mod symbol; mod tokens; mod toposort; pub mod trivial; pub mod types; mod visit; use self::attrs::OtherAttrs; use self::discriminant::Discriminant; use self::namespace::Namespace; use self::parse::kw; use self::symbol::Symbol; use proc_macro2::{Ident, Span}; use syn::punctuated::Punctuated; use syn::token::{Brace, Bracket, Paren}; use syn::{Expr, Generics, Lifetime, LitInt, Token, Type as RustType}; pub use self::atom::Atom; pub use self::derive::{Derive, Trait}; pub use self::doc::Doc; pub use self::names::ForeignName; pub use self::parse::parse_items; pub use self::types::Types; pub enum Api { Include(Include), Struct(Struct), Enum(Enum), CxxType(ExternType), CxxFunction(ExternFn), RustType(ExternType), RustFunction(ExternFn), TypeAlias(TypeAlias), Impl(Impl), } pub struct Include { pub path: String, pub kind: IncludeKind, pub begin_span: Span, pub end_span: Span, } /// Whether to emit `#include "path"` or `#include `. #[derive(Copy, Clone, PartialEq, Debug)] pub enum IncludeKind { /// `#include "quoted/path/to"` Quoted, /// `#include ` Bracketed, } pub struct ExternType { pub lang: Lang, pub doc: Doc, pub derives: Vec, pub attrs: OtherAttrs, pub visibility: Token![pub], pub type_token: Token![type], pub name: Pair, pub generics: Lifetimes, pub colon_token: Option, pub bounds: Vec, pub semi_token: Token![;], pub trusted: bool, } pub struct Struct { pub doc: Doc, pub derives: Vec, pub attrs: OtherAttrs, pub visibility: Token![pub], pub struct_token: Token![struct], pub name: Pair, pub generics: Lifetimes, pub brace_token: Brace, pub fields: Vec, } pub struct Enum { pub doc: Doc, pub derives: Vec, pub attrs: OtherAttrs, pub visibility: Token![pub], pub enum_token: Token![enum], pub name: Pair, pub generics: Lifetimes, pub brace_token: Brace, pub variants: Vec, pub repr: Atom, pub repr_type: Type, pub explicit_repr: bool, } pub struct ExternFn { pub lang: Lang, pub doc: Doc, pub attrs: OtherAttrs, pub visibility: Token![pub], pub name: Pair, pub sig: Signature, pub semi_token: Token![;], pub trusted: bool, } pub struct TypeAlias { pub doc: Doc, pub derives: Vec, pub attrs: OtherAttrs, pub visibility: Token![pub], pub type_token: Token![type], pub name: Pair, pub generics: Lifetimes, pub eq_token: Token![=], pub ty: RustType, pub semi_token: Token![;], } pub struct Impl { pub impl_token: Token![impl], pub impl_generics: Lifetimes, pub negative: bool, pub ty: Type, pub ty_generics: Lifetimes, pub brace_token: Brace, pub negative_token: Option, } #[derive(Clone, Default)] pub struct Lifetimes { pub lt_token: Option, pub lifetimes: Punctuated, pub gt_token: Option]>, } pub struct Signature { pub unsafety: Option, pub fn_token: Token![fn], pub generics: Generics, pub receiver: Option, pub args: Punctuated, pub ret: Option, pub throws: bool, pub paren_token: Paren, pub throws_tokens: Option<(kw::Result, Token![<], Token![>])>, } pub struct Var { pub doc: Doc, pub attrs: OtherAttrs, pub visibility: Token![pub], pub name: Pair, pub ty: Type, } pub struct Receiver { pub pinned: bool, pub ampersand: Token![&], pub lifetime: Option, pub mutable: bool, pub var: Token![self], pub ty: NamedType, pub shorthand: bool, pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>, pub mutability: Option, } pub struct Variant { pub doc: Doc, pub attrs: OtherAttrs, pub name: Pair, pub discriminant: Discriminant, pub expr: Option, } pub enum Type { Ident(NamedType), RustBox(Box), RustVec(Box), UniquePtr(Box), SharedPtr(Box), WeakPtr(Box), Ref(Box), Ptr(Box), Str(Box), CxxVector(Box), Fn(Box), Void(Span), SliceRef(Box), Array(Box), } pub struct Ty1 { pub name: Ident, pub langle: Token![<], pub inner: Type, pub rangle: Token![>], } pub struct Ref { pub pinned: bool, pub ampersand: Token![&], pub lifetime: Option, pub mutable: bool, pub inner: Type, pub pin_tokens: Option<(kw::Pin, Token![<], Token![>])>, pub mutability: Option, } pub struct Ptr { pub star: Token![*], pub mutable: bool, pub inner: Type, pub mutability: Option, pub constness: Option, } pub struct SliceRef { pub ampersand: Token![&], pub lifetime: Option, pub mutable: bool, pub bracket: Bracket, pub inner: Type, pub mutability: Option, } pub struct Array { pub bracket: Bracket, pub inner: Type, pub semi_token: Token![;], pub len: usize, pub len_token: LitInt, } #[derive(Copy, Clone, PartialEq)] pub enum Lang { Cxx, Rust, } // An association of a defined Rust name with a fully resolved, namespace // qualified C++ name. #[derive(Clone)] pub struct Pair { pub namespace: Namespace, pub cxx: ForeignName, pub rust: Ident, } // Wrapper for a type which needs to be resolved before it can be printed in // C++. #[derive(PartialEq, Eq, Hash)] pub struct NamedType { pub rust: Ident, pub generics: Lifetimes, }