module_path: &'mod_lifetime str,
imports: HashMap<syn::Ident, (String, syn::Path)>,
declared: HashMap<syn::Ident, DeclType<'crate_lft>>,
+ priv_modules: HashSet<syn::Ident>,
}
impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'crate_lft> {
fn process_use_intern(imports: &mut HashMap<syn::Ident, (String, syn::Path)>, u: &syn::UseTree, partial_path: &str, mut path: syn::punctuated::Punctuated<syn::PathSegment, syn::token::Colon2>) {
Self::insert_primitive(&mut imports, "Option");
let mut declared = HashMap::new();
+ let mut priv_modules = HashSet::new();
for item in contents.iter() {
match item {
}
}
},
+ syn::Item::Type(t) if export_status(&t.attrs) == ExportStatus::Export => {
+ if let syn::Visibility::Public(_) = t.vis {
+ let mut process_alias = true;
+ for tok in t.generics.params.iter() {
+ if let syn::GenericParam::Lifetime(_) = tok {}
+ else { process_alias = false; }
+ }
+ if process_alias {
+ match &*t.ty {
+ syn::Type::Path(_) => { declared.insert(t.ident.clone(), DeclType::StructImported); },
+ _ => {},
+ }
+ }
+ }
+ },
syn::Item::Enum(e) => {
if let syn::Visibility::Public(_) = e.vis {
match export_status(&e.attrs) {
declared.insert(t.ident.clone(), DeclType::Trait(t));
}
},
+ syn::Item::Mod(m) => {
+ priv_modules.insert(m.ident.clone());
+ },
_ => {},
}
}
- Self { module_path, imports, declared }
+ Self { module_path, imports, declared, priv_modules }
}
pub fn get_declared_type(&self, ident: &syn::Ident) -> Option<&DeclType<'crate_lft>> {
} else {
Some(imp.clone())
}
+ } else if let Some(_) = self.priv_modules.get(&first_seg.ident) {
+ Some(format!("{}::{}{}", self.module_path, first_seg.ident, remaining))
} else { None }
}
}
pub traits: HashMap<String, &'a syn::ItemTrait>,
/// 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)>>,
/// Template continer types defined, map from mangled type name -> whether a destructor fn
/// exists.
///
pub template_file: &'a mut File,
/// Set of containers which are clonable
pub clonable_types: HashSet<String>,
+ /// Key impls Value
+ pub trait_impls: HashMap<String, Vec<String>>,
}
/// A struct which tracks resolving rust types into C-mapped equivalents, exists for one specific
// Override the default since Records contain an fmt with a lifetime:
"util::logger::Record" => Some("*const std::os::raw::c_char"),
- // List of structs we map that aren't detected:
- "ln::features::InitFeatures" if is_ref && ptr_for_ref => Some("crate::ln::features::InitFeatures"),
- "ln::features::InitFeatures" if is_ref => Some("*const crate::ln::features::InitFeatures"),
- "ln::features::InitFeatures" => Some("crate::ln::features::InitFeatures"),
_ => None,
}
}
"ln::channelmanager::PaymentPreimage" if is_ref => Some("&::lightning::ln::channelmanager::PaymentPreimage(unsafe { *"),
"ln::channelmanager::PaymentSecret" => Some("::lightning::ln::channelmanager::PaymentSecret("),
- // List of structs we map (possibly during processing of other files):
- "ln::features::InitFeatures" if !is_ref => Some("*unsafe { Box::from_raw("),
-
// List of traits we map (possibly during processing of other files):
"crate::util::logger::Logger" => Some(""),
"ln::channelmanager::PaymentPreimage" if is_ref => Some(" })"),
"ln::channelmanager::PaymentSecret" => Some(".data)"),
- // List of structs we map (possibly during processing of other files):
- "ln::features::InitFeatures" if is_ref => Some(".inner) }"),
- "ln::features::InitFeatures" if !is_ref => Some(".take_inner()) }"),
-
// List of traits we map (possibly during processing of other files):
"crate::util::logger::Logger" => Some(""),
// Override the default since Records contain an fmt with a lifetime:
"util::logger::Record" => Some("local_"),
- // List of structs we map (possibly during processing of other files):
- "ln::features::InitFeatures" if is_ref && ptr_for_ref => Some("crate::ln::features::InitFeatures { inner: &mut "),
- "ln::features::InitFeatures" if is_ref => Some("Box::into_raw(Box::new(crate::ln::features::InitFeatures { inner: &mut "),
- "ln::features::InitFeatures" if !is_ref => Some("crate::ln::features::InitFeatures { inner: Box::into_raw(Box::new("),
-
_ => None,
}.map(|s| s.to_owned())
}
// Override the default since Records contain an fmt with a lifetime:
"util::logger::Record" => Some(".as_ptr()"),
- // List of structs we map (possibly during processing of other files):
- "ln::features::InitFeatures" if is_ref && ptr_for_ref => Some(", is_owned: false }"),
- "ln::features::InitFeatures" if is_ref => Some(", is_owned: false }))"),
- "ln::features::InitFeatures" => Some(")), is_owned: true }"),
-
_ => None,
}.map(|s| s.to_owned())
}