mod analysis;
mod api;
mod codegen_cpp;
mod codegen_rs;
#[cfg(test)]
mod conversion_tests;
mod convert_error;
mod parse;
mod utilities;
use analysis::fun::FnAnalyzer;
use autocxx_parser::TypeConfig;
pub(crate) use codegen_cpp::type_to_cpp::type_to_cpp;
pub(crate) use codegen_cpp::CppCodeGenerator;
pub(crate) use codegen_cpp::CppCodegenResults;
pub(crate) use convert_error::ConvertError;
use syn::{Item, ItemMod};
use crate::UnsafePolicy;
use self::{
analysis::{
gc::filter_apis_by_following_edges_from_allowlist, pod::analyze_pod_apis,
remove_ignored::filter_apis_by_ignored_dependents,
},
codegen_rs::RsCodeGenerator,
parse::ParseBindgen,
};
pub(crate) struct BridgeConverter<'a> {
include_list: &'a [String],
type_config: &'a TypeConfig,
}
pub(crate) struct CodegenResults {
pub(crate) rs: Vec<Item>,
pub(crate) cpp: Option<CppCodegenResults>,
}
impl<'a> BridgeConverter<'a> {
pub fn new(include_list: &'a [String], type_config: &'a TypeConfig) -> Self {
Self {
include_list,
type_config,
}
}
pub(crate) fn convert(
&self,
mut bindgen_mod: ItemMod,
exclude_utilities: bool,
unsafe_policy: UnsafePolicy,
inclusions: String,
) -> Result<CodegenResults, ConvertError> {
match &mut bindgen_mod.content {
None => Err(ConvertError::NoContent),
Some((_, items)) => {
let items_to_process = items.drain(..).collect();
let parser = ParseBindgen::new(&self.type_config);
let parse_results = parser.parse_items(items_to_process, exclude_utilities)?;
let mut type_converter = parse_results.type_converter;
let analyzed_apis =
analyze_pod_apis(parse_results.apis, &self.type_config, &mut type_converter)?;
let analyzed_apis = FnAnalyzer::analyze_functions(
analyzed_apis,
unsafe_policy,
&mut type_converter,
self.type_config,
)?;
let analyzed_apis = filter_apis_by_ignored_dependents(analyzed_apis);
let mut analyzed_apis =
filter_apis_by_following_edges_from_allowlist(analyzed_apis, &self.type_config);
analysis::ctypes::append_ctype_information(&mut analyzed_apis);
let cpp = CppCodeGenerator::generate_cpp_code(inclusions, &analyzed_apis)?;
let rs = RsCodeGenerator::generate_rs_code(
analyzed_apis,
self.include_list,
bindgen_mod,
);
Ok(CodegenResults { rs, cpp })
}
}
}
}