Factor out metadata in FuncInfo.
This commit is contained in:
parent
0286a52084
commit
ef920e2b8d
@ -430,10 +430,11 @@ impl Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut func_infos = self.iter_fn().collect::<Vec<_>>();
|
let mut func_infos = self.iter_fn().collect::<Vec<_>>();
|
||||||
func_infos.sort_by(|a, b| match a.name.cmp(&b.name) {
|
func_infos.sort_by(|a, b| match a.metadata.name.cmp(&b.metadata.name) {
|
||||||
Ordering::Equal => match a.num_params.cmp(&b.num_params) {
|
Ordering::Equal => match a.metadata.num_params.cmp(&b.metadata.num_params) {
|
||||||
Ordering::Equal => (a.params_info.join("") + a.return_type.as_str())
|
Ordering::Equal => (a.metadata.params_info.join("")
|
||||||
.cmp(&(b.params_info.join("") + b.return_type.as_str())),
|
+ a.metadata.return_type.as_str())
|
||||||
|
.cmp(&(b.metadata.params_info.join("") + b.metadata.return_type.as_str())),
|
||||||
o => o,
|
o => o,
|
||||||
},
|
},
|
||||||
o => o,
|
o => o,
|
||||||
@ -445,8 +446,9 @@ impl Module {
|
|||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
if f.access != FnAccess::Private {
|
if f.metadata.access != FnAccess::Private {
|
||||||
let operator = !f.name.contains('$') && !is_valid_function_name(&f.name);
|
let operator =
|
||||||
|
!f.metadata.name.contains('$') && !is_valid_function_name(&f.metadata.name);
|
||||||
|
|
||||||
#[cfg(not(feature = "no_custom_syntax"))]
|
#[cfg(not(feature = "no_custom_syntax"))]
|
||||||
let operator = operator
|
let operator = operator
|
||||||
@ -454,7 +456,7 @@ impl Module {
|
|||||||
.engine
|
.engine
|
||||||
.custom_keywords
|
.custom_keywords
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |m| m.contains_key(f.name.as_str()));
|
.map_or(false, |m| m.contains_key(f.metadata.name.as_str()));
|
||||||
|
|
||||||
f.write_definition(writer, def, operator)?;
|
f.write_definition(writer, def, operator)?;
|
||||||
}
|
}
|
||||||
@ -472,7 +474,7 @@ impl FuncInfo {
|
|||||||
def: &Definitions,
|
def: &Definitions,
|
||||||
operator: bool,
|
operator: bool,
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
for comment in &*self.comments {
|
for comment in &*self.metadata.comments {
|
||||||
writeln!(writer, "{comment}")?;
|
writeln!(writer, "{comment}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -482,22 +484,26 @@ impl FuncInfo {
|
|||||||
writer.write_str("fn ")?;
|
writer.write_str("fn ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(name) = self.name.strip_prefix("get$") {
|
if let Some(name) = self.metadata.name.strip_prefix("get$") {
|
||||||
write!(writer, "get {name}(")?;
|
write!(writer, "get {name}(")?;
|
||||||
} else if let Some(name) = self.name.strip_prefix("set$") {
|
} else if let Some(name) = self.metadata.name.strip_prefix("set$") {
|
||||||
write!(writer, "set {name}(")?;
|
write!(writer, "set {name}(")?;
|
||||||
} else {
|
} else {
|
||||||
write!(writer, "{}(", self.name)?;
|
write!(writer, "{}(", self.metadata.name)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut first = true;
|
let mut first = true;
|
||||||
for i in 0..self.num_params {
|
for i in 0..self.metadata.num_params {
|
||||||
if !first {
|
if !first {
|
||||||
writer.write_str(", ")?;
|
writer.write_str(", ")?;
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
let (param_name, param_type) = self.params_info.get(i).map_or(("_", "?".into()), |s| {
|
let (param_name, param_type) =
|
||||||
|
self.metadata
|
||||||
|
.params_info
|
||||||
|
.get(i)
|
||||||
|
.map_or(("_", "?".into()), |s| {
|
||||||
let mut s = s.splitn(2, ':');
|
let mut s = s.splitn(2, ':');
|
||||||
(
|
(
|
||||||
s.next().unwrap_or("_").split(' ').last().unwrap(),
|
s.next().unwrap_or("_").split(' ').last().unwrap(),
|
||||||
@ -516,7 +522,7 @@ impl FuncInfo {
|
|||||||
write!(
|
write!(
|
||||||
writer,
|
writer,
|
||||||
") -> {};",
|
") -> {};",
|
||||||
def_type_name(&self.return_type, def.engine)
|
def_type_name(&self.metadata.return_type, def.engine)
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -25,6 +25,9 @@ use std::{
|
|||||||
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
||||||
use crate::func::register::Mut;
|
use crate::func::register::Mut;
|
||||||
|
|
||||||
|
/// Initial capacity of the hashmap for functions.
|
||||||
|
const FN_MAP_SIZE: usize = 16;
|
||||||
|
|
||||||
/// A type representing the namespace of a function.
|
/// A type representing the namespace of a function.
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||||
#[cfg_attr(feature = "metadata", derive(serde::Serialize))]
|
#[cfg_attr(feature = "metadata", derive(serde::Serialize))]
|
||||||
@ -60,12 +63,10 @@ impl FnNamespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type containing a single registered function.
|
/// A type containing the metadata of a single registered function.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct FuncInfo {
|
pub struct FuncInfoMetadata {
|
||||||
/// Function instance.
|
|
||||||
pub func: CallableFunction,
|
|
||||||
/// Function namespace.
|
/// Function namespace.
|
||||||
pub namespace: FnNamespace,
|
pub namespace: FnNamespace,
|
||||||
/// Function access mode.
|
/// Function access mode.
|
||||||
@ -87,25 +88,35 @@ pub struct FuncInfo {
|
|||||||
pub comments: Box<[Box<str>]>,
|
pub comments: Box<[Box<str>]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type containing a single registered function.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct FuncInfo {
|
||||||
|
/// Function instance.
|
||||||
|
pub func: CallableFunction,
|
||||||
|
/// Function metadata.
|
||||||
|
pub metadata: Box<FuncInfoMetadata>,
|
||||||
|
}
|
||||||
|
|
||||||
impl FuncInfo {
|
impl FuncInfo {
|
||||||
/// _(metadata)_ Generate a signature of the function.
|
/// _(metadata)_ Generate a signature of the function.
|
||||||
/// Exported under the `metadata` feature only.
|
/// Exported under the `metadata` feature only.
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn gen_signature(&self) -> String {
|
pub fn gen_signature(&self) -> String {
|
||||||
let mut signature = format!("{}(", self.name);
|
let mut signature = format!("{}(", self.metadata.name);
|
||||||
|
|
||||||
let return_type = format_type(&self.return_type, true);
|
let return_type = format_type(&self.metadata.return_type, true);
|
||||||
|
|
||||||
if self.params_info.is_empty() {
|
if self.metadata.params_info.is_empty() {
|
||||||
for x in 0..self.num_params {
|
for x in 0..self.metadata.num_params {
|
||||||
signature.push('_');
|
signature.push('_');
|
||||||
if x < self.num_params - 1 {
|
if x < self.metadata.num_params - 1 {
|
||||||
signature.push_str(", ");
|
signature.push_str(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let params: StaticVec<_> = self
|
let params: StaticVec<_> = self
|
||||||
|
.metadata
|
||||||
.params_info
|
.params_info
|
||||||
.iter()
|
.iter()
|
||||||
.map(|param| {
|
.map(|param| {
|
||||||
@ -177,7 +188,7 @@ pub struct Module {
|
|||||||
id: Option<ImmutableString>,
|
id: Option<ImmutableString>,
|
||||||
/// Module documentation.
|
/// Module documentation.
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
doc: Option<crate::SmartString>,
|
doc: Option<Box<SmartString>>,
|
||||||
/// Custom types.
|
/// Custom types.
|
||||||
custom_types: Option<Box<CustomTypesCollection>>,
|
custom_types: Option<Box<CustomTypesCollection>>,
|
||||||
/// Sub-modules.
|
/// Sub-modules.
|
||||||
@ -187,12 +198,12 @@ pub struct Module {
|
|||||||
/// Flattened collection of all [`Module`] variables, including those in sub-modules.
|
/// Flattened collection of all [`Module`] variables, including those in sub-modules.
|
||||||
all_variables: Option<Box<StraightHashMap<Dynamic>>>,
|
all_variables: Option<Box<StraightHashMap<Dynamic>>>,
|
||||||
/// Functions (both native Rust and scripted).
|
/// Functions (both native Rust and scripted).
|
||||||
functions: Option<Box<StraightHashMap<FuncInfo>>>,
|
functions: Option<StraightHashMap<FuncInfo>>,
|
||||||
/// Flattened collection of all functions, native Rust and scripted.
|
/// Flattened collection of all functions, native Rust and scripted.
|
||||||
/// including those in sub-modules.
|
/// including those in sub-modules.
|
||||||
all_functions: Option<Box<StraightHashMap<CallableFunction>>>,
|
all_functions: Option<Box<StraightHashMap<CallableFunction>>>,
|
||||||
/// Bloom filter on native Rust functions (in scripted hash format) that contain [`Dynamic`] parameters.
|
/// Bloom filter on native Rust functions (in scripted hash format) that contain [`Dynamic`] parameters.
|
||||||
dynamic_functions_filter: BloomFilterU64,
|
dynamic_functions_filter: Option<Box<BloomFilterU64>>,
|
||||||
/// Iterator functions, keyed by the type producing the iterator.
|
/// Iterator functions, keyed by the type producing the iterator.
|
||||||
type_iterators: Option<Box<BTreeMap<TypeId, Shared<IteratorFn>>>>,
|
type_iterators: Option<Box<BTreeMap<TypeId, Shared<IteratorFn>>>>,
|
||||||
/// Flattened collection of iterator functions, including those in sub-modules.
|
/// Flattened collection of iterator functions, including those in sub-modules.
|
||||||
@ -293,7 +304,7 @@ impl Module {
|
|||||||
all_variables: None,
|
all_variables: None,
|
||||||
functions: None,
|
functions: None,
|
||||||
all_functions: None,
|
all_functions: None,
|
||||||
dynamic_functions_filter: BloomFilterU64::new(),
|
dynamic_functions_filter: None,
|
||||||
type_iterators: None,
|
type_iterators: None,
|
||||||
all_type_iterators: None,
|
all_type_iterators: None,
|
||||||
flags: ModuleFlags::INDEXED,
|
flags: ModuleFlags::INDEXED,
|
||||||
@ -400,7 +411,7 @@ impl Module {
|
|||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set_doc(&mut self, doc: impl Into<crate::SmartString>) -> &mut Self {
|
pub fn set_doc(&mut self, doc: impl Into<crate::SmartString>) -> &mut Self {
|
||||||
self.doc = Some(doc.into());
|
self.doc = Some(Box::new(doc.into()));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +447,7 @@ impl Module {
|
|||||||
self.all_variables = None;
|
self.all_variables = None;
|
||||||
self.functions = None;
|
self.functions = None;
|
||||||
self.all_functions = None;
|
self.all_functions = None;
|
||||||
self.dynamic_functions_filter.clear();
|
self.dynamic_functions_filter = None;
|
||||||
self.type_iterators = None;
|
self.type_iterators = None;
|
||||||
self.all_type_iterators = None;
|
self.all_type_iterators = None;
|
||||||
self.flags &= !ModuleFlags::INDEXED & !ModuleFlags::INDEXED_GLOBAL_FUNCTIONS;
|
self.flags &= !ModuleFlags::INDEXED & !ModuleFlags::INDEXED_GLOBAL_FUNCTIONS;
|
||||||
@ -575,7 +586,7 @@ impl Module {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
|
pub fn gen_fn_signatures(&self) -> impl Iterator<Item = String> + '_ {
|
||||||
self.iter_fn()
|
self.iter_fn()
|
||||||
.filter(|&f| match f.access {
|
.filter(|&f| match f.metadata.access {
|
||||||
FnAccess::Public => true,
|
FnAccess::Public => true,
|
||||||
FnAccess::Private => false,
|
FnAccess::Private => false,
|
||||||
})
|
})
|
||||||
@ -687,9 +698,14 @@ impl Module {
|
|||||||
let hash_script = crate::calc_fn_hash(None, &fn_def.name, num_params);
|
let hash_script = crate::calc_fn_hash(None, &fn_def.name, num_params);
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
let params_info = fn_def.params.iter().map(Into::into).collect();
|
let params_info = fn_def.params.iter().map(Into::into).collect();
|
||||||
self.functions.get_or_insert_with(Default::default).insert(
|
self.functions
|
||||||
|
.get_or_insert_with(|| {
|
||||||
|
StraightHashMap::with_capacity_and_hasher(FN_MAP_SIZE, Default::default())
|
||||||
|
})
|
||||||
|
.insert(
|
||||||
hash_script,
|
hash_script,
|
||||||
FuncInfo {
|
FuncInfo {
|
||||||
|
metadata: FuncInfoMetadata {
|
||||||
name: fn_def.name.as_str().into(),
|
name: fn_def.name.as_str().into(),
|
||||||
namespace: FnNamespace::Internal,
|
namespace: FnNamespace::Internal,
|
||||||
access: fn_def.access,
|
access: fn_def.access,
|
||||||
@ -701,6 +717,8 @@ impl Module {
|
|||||||
return_type: "".into(),
|
return_type: "".into(),
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
comments: Box::default(),
|
comments: Box::default(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
func: fn_def.into(),
|
func: fn_def.into(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -722,7 +740,7 @@ impl Module {
|
|||||||
let name = name.as_ref();
|
let name = name.as_ref();
|
||||||
|
|
||||||
lib.values()
|
lib.values()
|
||||||
.find(|&f| f.num_params == num_params && f.name == name)
|
.find(|&f| f.metadata.num_params == num_params && f.metadata.name == name)
|
||||||
.and_then(|f| f.func.get_script_fn_def())
|
.and_then(|f| f.func.get_script_fn_def())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -860,14 +878,14 @@ impl Module {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if let Some(f) = self.functions.as_mut().and_then(|m| m.get_mut(&hash_fn)) {
|
if let Some(f) = self.functions.as_mut().and_then(|m| m.get_mut(&hash_fn)) {
|
||||||
let (param_names, return_type_name) = if param_names.len() > f.num_params {
|
let (param_names, return_type_name) = if param_names.len() > f.metadata.num_params {
|
||||||
let return_type = param_names.pop().unwrap();
|
let return_type = param_names.pop().unwrap();
|
||||||
(param_names, return_type)
|
(param_names, return_type)
|
||||||
} else {
|
} else {
|
||||||
(param_names, crate::SmartString::new_const())
|
(param_names, crate::SmartString::new_const())
|
||||||
};
|
};
|
||||||
f.params_info = param_names;
|
f.metadata.params_info = param_names;
|
||||||
f.return_type = return_type_name;
|
f.metadata.return_type = return_type_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -913,7 +931,7 @@ impl Module {
|
|||||||
.as_mut()
|
.as_mut()
|
||||||
.and_then(|m| m.get_mut(&hash_fn))
|
.and_then(|m| m.get_mut(&hash_fn))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
f.comments = comments.iter().map(|s| s.as_ref().into()).collect();
|
f.metadata.comments = comments.iter().map(|s| s.as_ref().into()).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
@ -925,7 +943,7 @@ impl Module {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn update_fn_namespace(&mut self, hash_fn: u64, namespace: FnNamespace) -> &mut Self {
|
pub fn update_fn_namespace(&mut self, hash_fn: u64, namespace: FnNamespace) -> &mut Self {
|
||||||
if let Some(f) = self.functions.as_mut().and_then(|m| m.get_mut(&hash_fn)) {
|
if let Some(f) = self.functions.as_mut().and_then(|m| m.get_mut(&hash_fn)) {
|
||||||
f.namespace = namespace;
|
f.metadata.namespace = namespace;
|
||||||
self.flags &= !ModuleFlags::INDEXED & !ModuleFlags::INDEXED_GLOBAL_FUNCTIONS;
|
self.flags &= !ModuleFlags::INDEXED & !ModuleFlags::INDEXED_GLOBAL_FUNCTIONS;
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
@ -1013,17 +1031,20 @@ impl Module {
|
|||||||
let hash_fn = calc_fn_hash_full(hash_script, param_types.iter().copied());
|
let hash_fn = calc_fn_hash_full(hash_script, param_types.iter().copied());
|
||||||
|
|
||||||
if is_dynamic {
|
if is_dynamic {
|
||||||
self.dynamic_functions_filter.mark(hash_script);
|
self.dynamic_functions_filter
|
||||||
|
.get_or_insert_with(Default::default)
|
||||||
|
.mark(hash_script);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.functions
|
self.functions
|
||||||
.get_or_insert_with(|| {
|
.get_or_insert_with(|| {
|
||||||
StraightHashMap::with_capacity_and_hasher(16, Default::default()).into()
|
StraightHashMap::with_capacity_and_hasher(FN_MAP_SIZE, Default::default())
|
||||||
})
|
})
|
||||||
.insert(
|
.insert(
|
||||||
hash_fn,
|
hash_fn,
|
||||||
FuncInfo {
|
FuncInfo {
|
||||||
func,
|
func,
|
||||||
|
metadata: FuncInfoMetadata {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
namespace,
|
namespace,
|
||||||
access,
|
access,
|
||||||
@ -1035,6 +1056,8 @@ impl Module {
|
|||||||
return_type: return_type_name,
|
return_type: return_type_name,
|
||||||
#[cfg(feature = "metadata")]
|
#[cfg(feature = "metadata")]
|
||||||
comments: Box::default(),
|
comments: Box::default(),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1087,7 +1110,7 @@ impl Module {
|
|||||||
|
|
||||||
if !comments.is_empty() {
|
if !comments.is_empty() {
|
||||||
let f = self.functions.as_mut().unwrap().get_mut(&hash).unwrap();
|
let f = self.functions.as_mut().unwrap().get_mut(&hash).unwrap();
|
||||||
f.comments = comments.iter().map(|s| s.as_ref().into()).collect();
|
f.metadata.comments = comments.iter().map(|s| s.as_ref().into()).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
hash
|
hash
|
||||||
@ -1533,10 +1556,13 @@ impl Module {
|
|||||||
/// Can the particular function with [`Dynamic`] parameter(s) exist in the [`Module`]?
|
/// Can the particular function with [`Dynamic`] parameter(s) exist in the [`Module`]?
|
||||||
///
|
///
|
||||||
/// A `true` return value does not automatically imply that the function _must_ exist.
|
/// A `true` return value does not automatically imply that the function _must_ exist.
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn may_contain_dynamic_fn(&self, hash_script: u64) -> bool {
|
pub(crate) fn may_contain_dynamic_fn(&self, hash_script: u64) -> bool {
|
||||||
!self.dynamic_functions_filter.is_absent(hash_script)
|
!self
|
||||||
|
.dynamic_functions_filter
|
||||||
|
.as_ref()
|
||||||
|
.map_or(false, |f| f.is_absent(hash_script))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Does the particular namespace-qualified function exist in the [`Module`]?
|
/// Does the particular namespace-qualified function exist in the [`Module`]?
|
||||||
@ -1587,7 +1613,13 @@ impl Module {
|
|||||||
Some(_) => (),
|
Some(_) => (),
|
||||||
None => self.functions = other.functions,
|
None => self.functions = other.functions,
|
||||||
}
|
}
|
||||||
self.dynamic_functions_filter += &other.dynamic_functions_filter;
|
match self.dynamic_functions_filter {
|
||||||
|
Some(ref mut m) if other.dynamic_functions_filter.is_some() => {
|
||||||
|
**m += &**other.dynamic_functions_filter.as_ref().unwrap()
|
||||||
|
}
|
||||||
|
Some(_) => (),
|
||||||
|
None => self.dynamic_functions_filter = other.dynamic_functions_filter,
|
||||||
|
}
|
||||||
match self.type_iterators {
|
match self.type_iterators {
|
||||||
Some(ref mut m) if other.type_iterators.is_some() => {
|
Some(ref mut m) if other.type_iterators.is_some() => {
|
||||||
m.extend(other.type_iterators.unwrap().into_iter())
|
m.extend(other.type_iterators.unwrap().into_iter())
|
||||||
@ -1637,7 +1669,13 @@ impl Module {
|
|||||||
Some(_) => (),
|
Some(_) => (),
|
||||||
None => self.functions = other.functions,
|
None => self.functions = other.functions,
|
||||||
}
|
}
|
||||||
self.dynamic_functions_filter += &other.dynamic_functions_filter;
|
match self.dynamic_functions_filter {
|
||||||
|
Some(ref mut m) if other.dynamic_functions_filter.is_some() => {
|
||||||
|
**m += &**other.dynamic_functions_filter.as_ref().unwrap()
|
||||||
|
}
|
||||||
|
Some(_) => (),
|
||||||
|
None => self.dynamic_functions_filter = other.dynamic_functions_filter,
|
||||||
|
}
|
||||||
match self.type_iterators {
|
match self.type_iterators {
|
||||||
Some(ref mut m) if other.type_iterators.is_some() => {
|
Some(ref mut m) if other.type_iterators.is_some() => {
|
||||||
m.extend(other.type_iterators.unwrap().into_iter())
|
m.extend(other.type_iterators.unwrap().into_iter())
|
||||||
@ -1686,15 +1724,23 @@ impl Module {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(ref functions) = other.functions {
|
if let Some(ref functions) = other.functions {
|
||||||
for (k, f) in functions.iter() {
|
let others_len = functions.len();
|
||||||
let map = self.functions.get_or_insert_with(Default::default);
|
|
||||||
|
|
||||||
if !map.contains_key(k) {
|
for (&k, f) in functions.iter() {
|
||||||
map.insert(*k, f.clone());
|
let map = self.functions.get_or_insert_with(|| {
|
||||||
|
StraightHashMap::with_capacity_and_hasher(others_len, Default::default())
|
||||||
|
});
|
||||||
|
map.reserve(others_len);
|
||||||
|
map.entry(k).or_insert_with(|| f.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match self.dynamic_functions_filter {
|
||||||
|
Some(ref mut m) if other.dynamic_functions_filter.is_some() => {
|
||||||
|
**m += &**other.dynamic_functions_filter.as_ref().unwrap()
|
||||||
|
}
|
||||||
|
Some(_) => (),
|
||||||
|
None => self.dynamic_functions_filter = other.dynamic_functions_filter.clone(),
|
||||||
}
|
}
|
||||||
self.dynamic_functions_filter += &other.dynamic_functions_filter;
|
|
||||||
if let Some(ref type_iterators) = other.type_iterators {
|
if let Some(ref type_iterators) = other.type_iterators {
|
||||||
let t = self.type_iterators.get_or_insert_with(Default::default);
|
let t = self.type_iterators.get_or_insert_with(Default::default);
|
||||||
|
|
||||||
@ -1759,11 +1805,11 @@ impl Module {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|&(.., f)| {
|
.filter(|&(.., f)| {
|
||||||
_filter(
|
_filter(
|
||||||
f.namespace,
|
f.metadata.namespace,
|
||||||
f.access,
|
f.metadata.access,
|
||||||
f.func.is_script(),
|
f.func.is_script(),
|
||||||
f.name.as_str(),
|
f.metadata.name.as_str(),
|
||||||
f.num_params,
|
f.metadata.num_params,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.map(|(&k, f)| (k, f.clone())),
|
.map(|(&k, f)| (k, f.clone())),
|
||||||
@ -1771,7 +1817,13 @@ impl Module {
|
|||||||
None => self.functions = other.functions.clone(),
|
None => self.functions = other.functions.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.dynamic_functions_filter += &other.dynamic_functions_filter;
|
match self.dynamic_functions_filter {
|
||||||
|
Some(ref mut m) if other.dynamic_functions_filter.is_some() => {
|
||||||
|
**m += &**other.dynamic_functions_filter.as_ref().unwrap()
|
||||||
|
}
|
||||||
|
Some(_) => (),
|
||||||
|
None => self.dynamic_functions_filter = other.dynamic_functions_filter.clone(),
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref type_iterators) = other.type_iterators {
|
if let Some(ref type_iterators) = other.type_iterators {
|
||||||
match self.type_iterators {
|
match self.type_iterators {
|
||||||
@ -1805,20 +1857,23 @@ impl Module {
|
|||||||
filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool,
|
filter: impl Fn(FnNamespace, FnAccess, &str, usize) -> bool,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.functions = std::mem::take(&mut self.functions).map(|m| {
|
self.functions = std::mem::take(&mut self.functions).map(|m| {
|
||||||
Box::new(
|
|
||||||
m.into_iter()
|
m.into_iter()
|
||||||
.filter(|(.., f)| {
|
.filter(|(.., f)| {
|
||||||
if f.func.is_script() {
|
if f.func.is_script() {
|
||||||
filter(f.namespace, f.access, f.name.as_str(), f.num_params)
|
filter(
|
||||||
|
f.metadata.namespace,
|
||||||
|
f.metadata.access,
|
||||||
|
f.metadata.name.as_str(),
|
||||||
|
f.metadata.num_params,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect()
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.dynamic_functions_filter.clear();
|
self.dynamic_functions_filter = None;
|
||||||
self.all_functions = None;
|
self.all_functions = None;
|
||||||
self.all_variables = None;
|
self.all_variables = None;
|
||||||
self.all_type_iterators = None;
|
self.all_type_iterators = None;
|
||||||
@ -1883,10 +1938,10 @@ impl Module {
|
|||||||
> + '_ {
|
> + '_ {
|
||||||
self.iter_fn().filter(|&f| f.func.is_script()).map(|f| {
|
self.iter_fn().filter(|&f| f.func.is_script()).map(|f| {
|
||||||
(
|
(
|
||||||
f.namespace,
|
f.metadata.namespace,
|
||||||
f.access,
|
f.metadata.access,
|
||||||
f.name.as_str(),
|
f.metadata.name.as_str(),
|
||||||
f.num_params,
|
f.metadata.num_params,
|
||||||
f.func.get_script_fn_def().expect("script-defined function"),
|
f.func.get_script_fn_def().expect("script-defined function"),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -2080,7 +2135,7 @@ impl Module {
|
|||||||
|
|
||||||
ast.shared_lib()
|
ast.shared_lib()
|
||||||
.iter_fn()
|
.iter_fn()
|
||||||
.filter(|&f| match f.access {
|
.filter(|&f| match f.metadata.access {
|
||||||
FnAccess::Public => true,
|
FnAccess::Public => true,
|
||||||
FnAccess::Private => false,
|
FnAccess::Private => false,
|
||||||
})
|
})
|
||||||
@ -2164,7 +2219,7 @@ impl Module {
|
|||||||
|
|
||||||
// Index all Rust functions
|
// Index all Rust functions
|
||||||
for (&hash, f) in module.functions.iter().flat_map(|m| m.iter()) {
|
for (&hash, f) in module.functions.iter().flat_map(|m| m.iter()) {
|
||||||
match f.namespace {
|
match f.metadata.namespace {
|
||||||
FnNamespace::Global => {
|
FnNamespace::Global => {
|
||||||
// Flatten all functions with global namespace
|
// Flatten all functions with global namespace
|
||||||
functions.insert(hash, f.func.clone());
|
functions.insert(hash, f.func.clone());
|
||||||
@ -2172,18 +2227,24 @@ impl Module {
|
|||||||
}
|
}
|
||||||
FnNamespace::Internal => (),
|
FnNamespace::Internal => (),
|
||||||
}
|
}
|
||||||
match f.access {
|
match f.metadata.access {
|
||||||
FnAccess::Public => (),
|
FnAccess::Public => (),
|
||||||
FnAccess::Private => continue, // Do not index private functions
|
FnAccess::Private => continue, // Do not index private functions
|
||||||
}
|
}
|
||||||
|
|
||||||
if !f.func.is_script() {
|
if !f.func.is_script() {
|
||||||
let hash_qualified_fn =
|
let hash_qualified_fn = calc_native_fn_hash(
|
||||||
calc_native_fn_hash(path.iter().copied(), f.name.as_str(), &f.param_types);
|
path.iter().copied(),
|
||||||
|
f.metadata.name.as_str(),
|
||||||
|
&f.metadata.param_types,
|
||||||
|
);
|
||||||
functions.insert(hash_qualified_fn, f.func.clone());
|
functions.insert(hash_qualified_fn, f.func.clone());
|
||||||
} else if cfg!(not(feature = "no_function")) {
|
} else if cfg!(not(feature = "no_function")) {
|
||||||
let hash_qualified_script =
|
let hash_qualified_script = crate::calc_fn_hash(
|
||||||
crate::calc_fn_hash(path.iter().copied(), &f.name, f.num_params);
|
path.iter().copied(),
|
||||||
|
&f.metadata.name,
|
||||||
|
f.metadata.num_params,
|
||||||
|
);
|
||||||
functions.insert(hash_qualified_script, f.func.clone());
|
functions.insert(hash_qualified_script, f.func.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2193,8 +2254,14 @@ impl Module {
|
|||||||
|
|
||||||
if !self.is_indexed() {
|
if !self.is_indexed() {
|
||||||
let mut path = Vec::with_capacity(4);
|
let mut path = Vec::with_capacity(4);
|
||||||
let mut variables = StraightHashMap::default();
|
let mut variables = StraightHashMap::with_capacity_and_hasher(
|
||||||
let mut functions = StraightHashMap::default();
|
self.variables.as_ref().map_or(0, |m| m.len()),
|
||||||
|
Default::default(),
|
||||||
|
);
|
||||||
|
let mut functions = StraightHashMap::with_capacity_and_hasher(
|
||||||
|
self.functions.as_ref().map_or(0, |m| m.len()),
|
||||||
|
Default::default(),
|
||||||
|
);
|
||||||
let mut type_iterators = BTreeMap::new();
|
let mut type_iterators = BTreeMap::new();
|
||||||
|
|
||||||
path.push("");
|
path.push("");
|
||||||
|
@ -66,13 +66,13 @@ impl Ord for FnMetadata<'_> {
|
|||||||
|
|
||||||
impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
||||||
fn from(info: &'a FuncInfo) -> Self {
|
fn from(info: &'a FuncInfo) -> Self {
|
||||||
let base_hash = calc_fn_hash(None, &info.name, info.num_params);
|
let base_hash = calc_fn_hash(None, &info.metadata.name, info.metadata.num_params);
|
||||||
let (typ, full_hash) = if info.func.is_script() {
|
let (typ, full_hash) = if info.func.is_script() {
|
||||||
(FnType::Script, base_hash)
|
(FnType::Script, base_hash)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
FnType::Native,
|
FnType::Native,
|
||||||
calc_native_fn_hash(None, &info.name, &info.param_types),
|
calc_native_fn_hash(None, &info.metadata.name, &info.metadata.param_types),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,12 +80,13 @@ impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
|||||||
base_hash,
|
base_hash,
|
||||||
full_hash,
|
full_hash,
|
||||||
#[cfg(not(feature = "no_module"))]
|
#[cfg(not(feature = "no_module"))]
|
||||||
namespace: info.namespace,
|
namespace: info.metadata.namespace,
|
||||||
access: info.access,
|
access: info.metadata.access,
|
||||||
name: &info.name,
|
name: &info.metadata.name,
|
||||||
typ,
|
typ,
|
||||||
num_params: info.num_params,
|
num_params: info.metadata.num_params,
|
||||||
params: info
|
params: info
|
||||||
|
.metadata
|
||||||
.params_info
|
.params_info
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
@ -99,7 +100,7 @@ impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
|||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
_dummy: None,
|
_dummy: None,
|
||||||
return_type: format_type(&info.return_type, true),
|
return_type: format_type(&info.metadata.return_type, true),
|
||||||
signature: info.gen_signature().into(),
|
signature: info.gen_signature().into(),
|
||||||
doc_comments: if info.func.is_script() {
|
doc_comments: if info.func.is_script() {
|
||||||
#[cfg(feature = "no_function")]
|
#[cfg(feature = "no_function")]
|
||||||
@ -114,7 +115,7 @@ impl<'a> From<&'a FuncInfo> for FnMetadata<'a> {
|
|||||||
.map(<_>::as_ref)
|
.map(<_>::as_ref)
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
info.comments.iter().map(<_>::as_ref).collect()
|
info.metadata.comments.iter().map(<_>::as_ref).collect()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user