luaur_analysis/methods/
scope_linear_search_for_binding_pair.rs1use crate::records::binding::Binding;
2use crate::records::scope::Scope;
3use crate::records::symbol::Symbol;
4use alloc::string::String;
5
6impl Scope {
7 pub fn linear_search_for_binding_pair(
8 &self,
9 name: &String,
10 traverse_scope_chain: bool,
11 ) -> Option<(Symbol, Binding)> {
12 let mut scope: Option<&Scope> = Some(self);
13
14 while let Some(current_scope) = scope {
15 for (symbol, binding) in ¤t_scope.bindings {
16 let sym_name =
17 unsafe { core::ffi::CStr::from_ptr(symbol.c_str()).to_string_lossy() };
18 if sym_name == *name {
19 return Some((symbol.clone(), binding.clone()));
20 }
21 }
22
23 if !traverse_scope_chain {
24 break;
25 }
26
27 scope = current_scope.parent.as_ref().map(|p| p.as_ref());
28 }
29
30 None
31 }
32}