Skip to main content

luaur_analysis/records/
user_defined_function_data.rs

1use crate::records::module::Module;
2use crate::records::type_fun::TypeFun;
3use crate::type_aliases::name_type_infer::Name;
4use alloc::string::String;
5use alloc::sync::Weak;
6use luaur_ast::records::ast_stat_type_function::AstStatTypeFunction;
7use luaur_common::records::dense_hash_map::DenseHashMap;
8
9#[derive(Debug, Clone)]
10pub struct User_Defined_Function_Data {
11    /// Store a weak module reference to ensure the lifetime requirements are preserved
12    pub(crate) owner: Weak<Module>,
13
14    /// References to AST elements are owned by the Module allocator which also stores this type
15    pub(crate) definition: *mut AstStatTypeFunction,
16
17    pub(crate) environment_function: DenseHashMap<Name, (*mut AstStatTypeFunction, usize)>,
18    pub(crate) environment_alias: DenseHashMap<Name, (*mut TypeFun, usize)>,
19}
20
21#[allow(non_upper_case_globals)]
22impl User_Defined_Function_Data {
23    pub(crate) fn new(owner: Weak<Module>) -> Self {
24        Self {
25            owner,
26            definition: core::ptr::null_mut(),
27            environment_function: DenseHashMap::new(String::new()),
28            environment_alias: DenseHashMap::new(String::new()),
29        }
30    }
31
32    /// Creates an empty instance with no owning module (used when no owner is present).
33    pub(crate) fn new_empty() -> Self {
34        Self {
35            owner: Weak::new(),
36            definition: core::ptr::null_mut(),
37            environment_function: DenseHashMap::new(String::new()),
38            environment_alias: DenseHashMap::new(String::new()),
39        }
40    }
41}
42
43#[allow(non_camel_case_types)]
44pub type UserDefinedFunctionData = User_Defined_Function_Data;