Skip to main content

luaur_analysis/methods/
data_flow_graph_builder_make_child_scope.rs

1use crate::enums::scope_type::ScopeType;
2use crate::records::data_flow_graph_builder::DataFlowGraphBuilder;
3use crate::records::dfg_scope::DfgScope;
4use luaur_common::macros::luau_assert::LUAU_ASSERT;
5
6impl DataFlowGraphBuilder {
7    pub fn make_child_scope(&mut self, scope_type: ScopeType) -> *mut DfgScope {
8        let parent_scope = self.current_scope();
9        // C++ `new DfgScope{currentScope(), scopeType}` uses default member
10        // inits: `bindings{Symbol{}}`, `props{nullptr}`.
11        let new_scope = DfgScope {
12            parent: parent_scope,
13            scope_type,
14            bindings: crate::type_aliases::bindings::Bindings::new(
15                crate::records::symbol::Symbol::default(),
16            ),
17            props: crate::type_aliases::props_data_flow_graph::Props::new(core::ptr::null()),
18        };
19        let mut boxed = alloc::boxed::Box::new(new_scope);
20        let ptr = boxed.as_mut() as *mut DfgScope;
21        self.scopes.push(boxed);
22        ptr
23    }
24}