use super::*;
pub(super) fn nested_funcs_with_span(body: &[Stmt]) -> Vec<(&str, Span)> {
let mut out = Vec::new();
collect_nested_funcs(body, &mut out);
out
}
pub(super) fn nested_func_names(body: &[Stmt]) -> HashSet<String> {
nested_funcs_with_span(body)
.into_iter()
.map(|(name, _)| name.to_string())
.collect()
}
pub(super) fn collect_var_bindings(body: &[Stmt], out: &mut HashSet<String>) {
for stmt in body {
match stmt {
Stmt::ConstDecl { name, .. } => {
out.insert(name.clone());
}
Stmt::Decl { names, rest, .. } => {
out.extend(names.iter().cloned());
out.extend(rest.iter().cloned());
}
Stmt::For { vars, rest, .. } => {
out.extend(vars.iter().cloned());
out.extend(rest.iter().cloned());
}
Stmt::Try { err_name, .. } => {
out.insert(err_name.clone());
}
_ => {}
}
for_each_child_block(stmt, &mut |block| collect_var_bindings(block, out));
}
}
pub(super) fn collect_nested_funcs<'a>(body: &'a [Stmt], out: &mut Vec<(&'a str, Span)>) {
for stmt in body {
if let Stmt::FuncDef { name, span, .. } = stmt {
out.push((name, *span));
}
for_each_child_block(stmt, &mut |block| collect_nested_funcs(block, out));
}
}