use cpp_data::CppData;
use cpp_data::CppTypeDoc;
use cpp_ffi_data::CppFfiMethod;
use cpp_method::CppMethodDoc;
use cpp_type::CppType;
use rust_type::{CompleteType, RustName, RustType};
use std::path::PathBuf;
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct RustEnumValue {
pub name: String,
pub value: i64,
pub cpp_docs: Vec<CppEnumValueDocItem>,
pub is_dummy: bool,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct CppEnumValueDocItem {
pub variant_name: String,
pub doc: Option<String>,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct RustQtSlotWrapper {
pub arguments: Vec<CompleteType>,
pub receiver_id: String,
pub public_type_name: String,
pub callback_name: String,
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum RustTypeWrapperKind {
Enum {
values: Vec<RustEnumValue>,
is_flaggable: bool,
},
Struct {
size_const_name: Option<String>,
is_deletable: bool,
slot_wrapper: Option<RustQtSlotWrapper>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RustProcessedTypeInfo {
pub cpp_name: String,
pub cpp_doc: Option<CppTypeDoc>,
pub cpp_template_arguments: Option<Vec<CppType>>,
pub kind: RustTypeWrapperKind,
pub rust_name: RustName,
pub is_public: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RustExportInfo {
pub crate_name: String,
pub crate_version: String,
pub output_path: String,
pub rust_types: Vec<RustProcessedTypeInfo>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustMethodDocItem {
pub doc: Option<CppMethodDoc>,
pub rust_fns: Vec<String>,
pub cpp_fn: String,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RustMethodScope {
Impl { target_type: RustType },
TraitImpl,
Free,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustMethodArgument {
pub argument_type: CompleteType,
pub name: String,
pub ffi_index: usize,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustMethodArgumentsVariant {
pub arguments: Vec<RustMethodArgument>,
pub cpp_ffi_method: CppFfiMethod,
pub return_type_ffi_index: Option<usize>,
pub return_type: CompleteType,
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[allow(dead_code)]
pub enum RustMethodArguments {
SingleVariant(RustMethodArgumentsVariant),
MultipleVariants {
params_trait_name: String,
params_trait_lifetime: Option<String>,
common_return_type: Option<RustType>,
shared_arguments: Vec<RustMethodArgument>,
variant_argument_name: String,
cpp_method_name: String,
},
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustMethod {
pub scope: RustMethodScope,
pub is_unsafe: bool,
pub name: RustName,
pub arguments: RustMethodArguments,
pub variant_docs: Vec<RustMethodDocItem>,
pub common_doc: Option<String>,
}
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum RustMethodSelfArgKind {
None,
ConstRef,
MutRef,
Value,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TraitImplExtra {
CppDeletable { deleter_name: String },
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct TraitAssociatedType {
pub name: String,
pub value: RustType,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct TraitImpl {
pub target_type: RustType,
pub trait_type: RustType,
pub associated_types: Vec<TraitAssociatedType>,
pub extra: Option<TraitImplExtra>,
pub methods: Vec<RustMethod>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RustQtReceiverType {
Signal,
Slot,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustQtReceiverDeclaration {
pub type_name: String,
pub method_name: String,
pub original_method_name: String,
pub receiver_type: RustQtReceiverType,
pub receiver_id: String,
pub arguments: Vec<RustType>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum RustTypeDeclarationKind {
CppTypeWrapper {
kind: RustTypeWrapperKind,
cpp_type_name: String,
cpp_template_arguments: Option<Vec<CppType>>,
cpp_doc: Option<CppTypeDoc>,
methods: Vec<RustMethod>,
trait_impls: Vec<TraitImpl>,
qt_receivers: Vec<RustQtReceiverDeclaration>,
},
MethodParametersTrait {
lifetime: Option<String>,
is_unsafe: bool,
shared_arguments: Vec<RustMethodArgument>,
common_return_type: Option<RustType>,
impls: Vec<RustMethodArgumentsVariant>,
method_scope: RustMethodScope,
method_name: RustName,
},
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustTypeDeclaration {
pub is_public: bool,
pub name: RustName,
pub kind: RustTypeDeclarationKind,
pub rust_doc: Option<String>,
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct RustModule {
pub name: String,
pub types: Vec<RustTypeDeclaration>,
pub functions: Vec<RustMethod>,
pub trait_impls: Vec<TraitImpl>,
pub doc: Option<String>,
pub submodules: Vec<RustModule>,
}
#[derive(Debug, Clone)]
pub struct DependencyInfo {
pub cpp_data: CppData,
pub rust_export_info: RustExportInfo,
pub cache_path: PathBuf,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RustMethodCaptionStrategy {
SelfOnly,
UnsafeOnly,
SelfAndArgTypes,
SelfAndArgNames,
SelfAndIndex,
}
impl RustMethodCaptionStrategy {
pub fn all() -> &'static [RustMethodCaptionStrategy] {
use self::RustMethodCaptionStrategy::*;
const LIST: &'static [RustMethodCaptionStrategy] = &[
SelfOnly,
UnsafeOnly,
SelfAndArgTypes,
SelfAndArgNames,
SelfAndIndex,
];
return LIST;
}
}
impl RustProcessedTypeInfo {
pub fn is_declared_in(&self, modules: &[RustModule]) -> bool {
for module in modules {
if module.types.iter().any(|t| match t.kind {
RustTypeDeclarationKind::CppTypeWrapper {
ref cpp_type_name,
ref cpp_template_arguments,
..
} => {
cpp_type_name == &self.cpp_name && cpp_template_arguments == &self.cpp_template_arguments
}
_ => false,
}) {
return true;
}
if self.is_declared_in(&module.submodules) {
return true;
}
}
false
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RustFFIArgument {
pub name: String,
pub argument_type: RustType,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct RustFFIFunction {
pub return_type: RustType,
pub name: String,
pub arguments: Vec<RustFFIArgument>,
}