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)>,
Self { crate_name, dependencies, module_path, imports, declared, priv_modules }
}
- pub fn get_declared_type(&self, ident: &syn::Ident) -> Option<&DeclType<'crate_lft>> {
- self.declared.get(ident)
- }
-
pub fn maybe_resolve_declared(&self, id: &syn::Ident) -> Option<&DeclType<'crate_lft>> {
self.declared.get(id)
}
} else { None }
}
- pub fn maybe_resolve_non_ignored_ident(&self, id: &syn::Ident) -> Option<String> {
- if let Some((imp, _)) = self.imports.get(id) {
- Some(imp.clone())
- } else if let Some(decl_type) = self.declared.get(id) {
- match decl_type {
- DeclType::StructIgnored => None,
- _ => Some(self.module_path.to_string() + "::" + &format!("{}", id)),
- }
- } else { None }
- }
-
pub fn maybe_resolve_path(&self, p: &syn::Path, generics: Option<&GenericTypes>) -> Option<String> {
if let Some(gen_types) = generics {
if let Some(resp) = gen_types.maybe_resolve_path(p) {
/// 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
"bitcoin::bech32::u5"|"bech32::u5" => Some("crate::c_types::u5"),
"core::num::NonZeroU8" => Some("u8"),
- "bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
- => Some("crate::c_types::PublicKey"),
- "bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature"),
- "bitcoin::secp256k1::recovery::RecoverableSignature" => Some("crate::c_types::RecoverableSignature"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if is_ref => Some("*const [u8; 32]"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if !is_ref => Some("crate::c_types::SecretKey"),
+ "bitcoin::secp256k1::PublicKey" => Some("crate::c_types::PublicKey"),
+ "bitcoin::secp256k1::ecdsa::Signature" => Some("crate::c_types::Signature"),
+ "bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature"),
+ "bitcoin::secp256k1::SecretKey" if is_ref => Some("*const [u8; 32]"),
+ "bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey"),
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice"),
"bitcoin::blockdata::script::Script" if !is_ref => Some("crate::c_types::derived::CVec_u8Z"),
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::lightning::chain::transaction::OutPoint"),
"bitcoin::bech32::u5"|"bech32::u5" => Some(""),
"core::num::NonZeroU8" => Some("core::num::NonZeroU8::new("),
- "bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
- if is_ref => Some("&"),
- "bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
- => Some(""),
- "bitcoin::secp256k1::Signature" if is_ref => Some("&"),
- "bitcoin::secp256k1::Signature" => Some(""),
- "bitcoin::secp256k1::recovery::RecoverableSignature" => Some(""),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if is_ref => Some("&::bitcoin::secp256k1::key::SecretKey::from_slice(&unsafe { *"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if !is_ref => Some(""),
+ "bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" if is_ref => Some("&"),
+ "bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some(""),
+ "bitcoin::secp256k1::ecdsa::Signature" if is_ref => Some("&"),
+ "bitcoin::secp256k1::ecdsa::Signature" => Some(""),
+ "bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(""),
+ "bitcoin::secp256k1::SecretKey" if is_ref => Some("&::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *"),
+ "bitcoin::secp256k1::SecretKey" if !is_ref => Some(""),
"bitcoin::blockdata::script::Script" if is_ref => Some("&::bitcoin::blockdata::script::Script::from(Vec::from("),
"bitcoin::blockdata::script::Script" if !is_ref => Some("::bitcoin::blockdata::script::Script::from("),
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("&"),
"bitcoin::bech32::u5"|"bech32::u5" => Some(".into()"),
"core::num::NonZeroU8" => Some(").expect(\"Value must be non-zero\")"),
- "bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
- => Some(".into_rust()"),
- "bitcoin::secp256k1::Signature" => Some(".into_rust()"),
- "bitcoin::secp256k1::recovery::RecoverableSignature" => Some(".into_rust()"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if !is_ref => Some(".into_rust()"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if is_ref => Some("}[..]).unwrap()"),
+ "bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some(".into_rust()"),
+ "bitcoin::secp256k1::ecdsa::Signature" => Some(".into_rust()"),
+ "bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(".into_rust()"),
+ "bitcoin::secp256k1::SecretKey" if !is_ref => Some(".into_rust()"),
+ "bitcoin::secp256k1::SecretKey" if is_ref => Some("}[..]).unwrap()"),
"bitcoin::blockdata::script::Script" if is_ref => Some(".to_slice()))"),
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_rust())"),
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(".into_bitcoin()"),
"bitcoin::bech32::u5"|"bech32::u5" => Some(""),
- "bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
- => Some("crate::c_types::PublicKey::from_rust(&"),
- "bitcoin::secp256k1::Signature" => Some("crate::c_types::Signature::from_rust(&"),
- "bitcoin::secp256k1::recovery::RecoverableSignature" => Some("crate::c_types::RecoverableSignature::from_rust(&"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if is_ref => Some(""),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if !is_ref => Some("crate::c_types::SecretKey::from_rust("),
+ "bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some("crate::c_types::PublicKey::from_rust(&"),
+ "bitcoin::secp256k1::ecdsa::Signature" => Some("crate::c_types::Signature::from_rust(&"),
+ "bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature::from_rust(&"),
+ "bitcoin::secp256k1::SecretKey" if is_ref => Some(""),
+ "bitcoin::secp256k1::SecretKey" if !is_ref => Some("crate::c_types::SecretKey::from_rust("),
"bitcoin::blockdata::script::Script" if is_ref => Some("crate::c_types::u8slice::from_slice(&"),
"bitcoin::blockdata::script::Script" if !is_ref => Some(""),
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" if is_ref => Some("crate::c_types::Transaction::from_bitcoin("),
"bitcoin::bech32::u5"|"bech32::u5" => Some(".into()"),
- "bitcoin::secp256k1::key::PublicKey"|"bitcoin::secp256k1::PublicKey"|"secp256k1::key::PublicKey"
- => Some(")"),
- "bitcoin::secp256k1::Signature" => Some(")"),
- "bitcoin::secp256k1::recovery::RecoverableSignature" => Some(")"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if !is_ref => Some(")"),
- "bitcoin::secp256k1::key::SecretKey"|"bitcoin::secp256k1::SecretKey"
- if is_ref => Some(".as_ref()"),
+ "bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some(")"),
+ "bitcoin::secp256k1::ecdsa::Signature" => Some(")"),
+ "bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(")"),
+ "bitcoin::secp256k1::SecretKey" if !is_ref => Some(")"),
+ "bitcoin::secp256k1::SecretKey" if is_ref => Some(".as_ref()"),
"bitcoin::blockdata::script::Script" if is_ref => Some("[..])"),
"bitcoin::blockdata::script::Script" if !is_ref => Some(".into_bytes().into()"),
"bitcoin::blockdata::transaction::Transaction"|"bitcoin::Transaction" => Some(")"),
fn empty_val_check_suffix_from_path(&self, full_path: &str) -> Option<&str> {
match full_path {
"lightning::ln::PaymentSecret" => Some(".data == [0; 32]"),
- "secp256k1::key::PublicKey"|"bitcoin::secp256k1::key::PublicKey" => Some(".is_null()"),
- "bitcoin::secp256k1::Signature" => Some(".is_null()"),
+ "secp256k1::PublicKey"|"bitcoin::secp256k1::PublicKey" => Some(".is_null()"),
+ "bitcoin::secp256k1::ecdsa::Signature" => Some(".is_null()"),
_ => None
}
}
// *** Type definition during main.rs processing ***
// *************************************************
- pub fn get_declared_type(&'a self, ident: &syn::Ident) -> Option<&'a DeclType<'c>> {
- self.types.get_declared_type(ident)
- }
/// Returns true if the object at the given path is mapped as X { inner: *mut origX, .. }.
pub fn c_type_has_inner_from_path(&self, full_path: &str) -> bool {
self.crate_types.opaques.get(full_path).is_some()
self.types.maybe_resolve_ident(id)
}
- pub fn maybe_resolve_non_ignored_ident(&self, id: &syn::Ident) -> Option<String> {
- self.types.maybe_resolve_non_ignored_ident(id)
- }
-
pub fn maybe_resolve_path(&self, p_arg: &syn::Path, generics: Option<&GenericTypes>) -> Option<String> {
self.types.maybe_resolve_path(p_arg, generics)
}
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 {