if !gen_types.as_mut().unwrap().learn_generics(&i.generics, types) {
gen_types = None;
}
- 'alias_impls: for (alias, arguments) in aliases {
+ let alias_module = rsplit_once(&resolved_path, "::").unwrap().0;
+
+ 'alias_impls: for (alias_resolved, arguments) in aliases {
let mut new_ty_generics = Vec::new();
let mut need_generics = false;
- let alias_resolved = types.resolve_path(&alias, None);
+ let alias_resolver_override;
+ let alias_resolver = if alias_module != types.module_path {
+ alias_resolver_override = ImportResolver::new(types.types.crate_name, &types.crate_types.lib_ast.dependencies,
+ alias_module, &types.crate_types.lib_ast.modules.get(alias_module).unwrap().items);
+ &alias_resolver_override
+ } else { &types.types };/*.maybe_resolve_path(&alias, None).unwrap();*/
for (idx, gen) in i.generics.params.iter().enumerate() {
match gen {
syn::GenericParam::Type(type_param) => {
if let syn::PathArguments::AngleBracketed(ref t) = &arguments {
assert!(idx < t.args.len());
if let syn::GenericArgument::Type(syn::Type::Path(p)) = &t.args[idx] {
- if let Some(generic_arg) = types.maybe_resolve_path(&p.path, None) {
+ if let Some(generic_arg) = alias_resolver.maybe_resolve_path(&p.path, None) {
new_ty_generics.push((type_param.ident.clone(), syn::Type::Path(p.clone())));
- let generic_bound = types.resolve_path(&trait_bound.path, None);
+ let generic_bound = types.maybe_resolve_path(&trait_bound.path, None)
+ .unwrap_or_else(|| format!("{}::{}", types.module_path, single_ident_generic_path_to_ident(&trait_bound.path).unwrap()));
if let Some(traits_impld) = types.crate_types.trait_impls.get(&generic_arg) {
for trait_impld in traits_impld {
if *trait_impld == generic_bound { continue 'bounds_check; }
}
}
let mut params = syn::punctuated::Punctuated::new();
+ let alias = string_path_to_syn_path(&alias_resolved);
let real_aliased =
if need_generics {
let alias_generics = types.crate_types.opaques.get(&alias_resolved).unwrap().1;
match item {
syn::Item::Mod(m) => convert_priv_mod(w, libast, crate_types, out_dir, &format!("{}::{}", mod_path, module.ident), m),
syn::Item::Impl(i) => {
- if let &syn::Type::Path(ref p) = &*i.self_ty {
- if p.path.get_ident().is_some() {
- writeln_impl(w, i, &mut types);
- }
- }
+ writeln_impl(w, i, &mut types);
},
_ => {},
}
let type_path = format!("{}::{}", module, t.ident);
match &*t.ty {
syn::Type::Path(p) => {
- let t_ident = &t.ident;
-
// If its a path with no generics, assume we don't map the aliased type and map it opaque
- let path_obj = parse_quote!(#t_ident);
let args_obj = p.path.segments.last().unwrap().arguments.clone();
match crate_types.reverse_alias_map.entry(import_resolver.maybe_resolve_path(&p.path, None).unwrap()) {
- hash_map::Entry::Occupied(mut e) => { e.get_mut().push((path_obj, args_obj)); },
- hash_map::Entry::Vacant(e) => { e.insert(vec![(path_obj, args_obj)]); },
+ hash_map::Entry::Occupied(mut e) => { e.get_mut().push((type_path.clone(), args_obj)); },
+ hash_map::Entry::Vacant(e) => { e.insert(vec![(type_path.clone(), args_obj)]); },
}
- crate_types.opaques.insert(type_path, (t_ident, &t.generics));
+ crate_types.opaques.insert(type_path, (&t.ident, &t.generics));
},
_ => {
crate_types.type_aliases.insert(type_path, import_resolver.resolve_imported_refs((*t.ty).clone()));
true
}
+pub fn string_path_to_syn_path(path: &str) -> syn::Path {
+ let mut segments = syn::punctuated::Punctuated::new();
+ for seg in path.split("::") {
+ segments.push(syn::PathSegment {
+ ident: syn::Ident::new(seg, Span::call_site()),
+ arguments: syn::PathArguments::None,
+ });
+ }
+ syn::Path { leading_colon: Some(syn::Token![::](Span::call_site())), segments }
+}
+
#[derive(Debug, PartialEq)]
pub enum ExportStatus {
Export,
}
pub struct ImportResolver<'mod_lifetime, 'crate_lft: 'mod_lifetime> {
- crate_name: &'mod_lifetime str,
+ pub crate_name: &'mod_lifetime str,
dependencies: &'mod_lifetime HashSet<syn::Ident>,
module_path: &'mod_lifetime str,
imports: HashMap<syn::Ident, (String, syn::Path)>,
/// Aliases from paths to some other Type
pub type_aliases: HashMap<String, syn::Type>,
/// Value is an alias to Key (maybe with some generics)
- pub reverse_alias_map: HashMap<String, Vec<(syn::Path, syn::PathArguments)>>,
+ pub reverse_alias_map: HashMap<String, Vec<(String, syn::PathArguments)>>,
/// Template continer types defined, map from mangled type name -> whether a destructor fn
/// exists.
///
pub struct TypeResolver<'mod_lifetime, 'crate_lft: 'mod_lifetime> {
pub module_path: &'mod_lifetime str,
pub crate_types: &'mod_lifetime CrateTypes<'crate_lft>,
- types: ImportResolver<'mod_lifetime, 'crate_lft>,
+ pub types: ImportResolver<'mod_lifetime, 'crate_lft>,
}
/// Returned by write_empty_rust_val_check_suffix to indicate what type of dereferencing needs to
assert!(self.write_c_type_intern(w, t, generics, false, false, ptr_for_ref, true, false));
}
pub fn understood_c_path(&self, p: &syn::Path) -> bool {
- if p.leading_colon.is_some() { return false; }
self.write_c_path_intern(&mut std::io::sink(), p, None, false, false, false, false, true)
}
pub fn understood_c_type(&self, t: &syn::Type, generics: Option<&GenericTypes>) -> bool {