Skip to main content

luaur_analysis/methods/
scope_lookup_ex_scope_alt_b.rs

1use crate::records::binding::Binding;
2use crate::records::scope::Scope;
3use crate::records::symbol::Symbol;
4
5impl Scope {
6    pub fn lookup_ex_symbol(&mut self, sym: Symbol) -> Option<(*mut Binding, *mut Scope)> {
7        let mut s: *mut Scope = self as *mut Scope;
8
9        loop {
10            let bindings = unsafe { &(*s).bindings };
11            if let Some(binding) = bindings.get(&sym) {
12                return Some((binding as *const Binding as *mut Binding, s));
13            }
14
15            let parent = unsafe { &(*s).parent };
16            match parent {
17                Some(parent_scope) => {
18                    s = unsafe { parent_scope.as_ref() as *const Scope as *mut Scope };
19                }
20                None => {
21                    return None;
22                }
23            }
24        }
25    }
26}