use crate::records::def::Def;
use crate::records::def_arena::DefArena;
use crate::records::refinement_key::RefinementKey;
use crate::records::refinement_key_arena::RefinementKeyArena;
use crate::records::symbol::Symbol;
use crate::type_aliases::def_id_def::DefId;
use luaur_ast::records::ast_expr::AstExpr;
use luaur_ast::records::ast_local::AstLocal;
use luaur_ast::records::ast_stat::AstStat;
use luaur_ast::records::ast_stat_declare_function::AstStatDeclareFunction;
use luaur_ast::records::ast_stat_declare_global::AstStatDeclareGlobal;
use luaur_common::macros::luau_assert::LUAU_ASSERT;
use luaur_common::records::dense_hash_map::DenseHashMap;
#[derive(Debug, Clone)]
pub struct DataFlowGraph {
pub(crate) def_arena: *mut DefArena,
pub(crate) key_arena: *mut RefinementKeyArena,
pub(crate) ast_defs: DenseHashMap<*const AstExpr, *const Def>,
pub(crate) local_defs: DenseHashMap<*const AstLocal, *const Def>,
pub(crate) declared_defs: DenseHashMap<*const AstStat, *const Def>,
pub(crate) def_to_symbol: DenseHashMap<*const Def, Symbol>,
pub(crate) ast_refinement_keys: DenseHashMap<*const AstExpr, *const RefinementKey>,
}
impl DataFlowGraph {
pub fn data_flow_graph_data_flow_graph_mut(&mut self) {
unreachable!("C++ DataFlowGraph move-ctor; Rust moves by value — no call site")
}
pub fn data_flow_graph_data_flow_graph(&self) {
unreachable!("C++ DataFlowGraph copy-ctor is `= delete` — non-copyable, no call site")
}
pub fn data_flow_graph_data_flow_graph_not_null_def_arena_not_null_refinement_key_arena(&self) {
unreachable!(
"superseded by DataFlowGraph::data_flow_graph(def_arena, key_arena) — no call site"
)
}
pub fn get_def_ast_expr(&self, expr: *const AstExpr) -> DefId {
let def = self.ast_defs.find(&expr);
LUAU_ASSERT!(def.is_some());
*def.unwrap()
}
pub fn get_def_ast_local(&self, local: *const AstLocal) -> DefId {
let def = self.local_defs.find(&local);
LUAU_ASSERT!(def.is_some());
*def.unwrap()
}
pub fn get_def_ast_stat_declare_global(&self, global: *const AstStatDeclareGlobal) -> DefId {
let def = self.declared_defs.find(&(global as *const AstStat));
LUAU_ASSERT!(def.is_some());
*def.unwrap()
}
pub fn get_def_ast_stat_declare_function(&self, func: *const AstStatDeclareFunction) -> DefId {
let def = self.declared_defs.find(&(func as *const AstStat));
LUAU_ASSERT!(def.is_some());
*def.unwrap()
}
pub fn data_flow_graph_not_null_def_arena_not_null_refinement_key_arena(
&self,
_def_arena: *mut DefArena,
_key_arena: *mut RefinementKeyArena,
) {
unreachable!(
"superseded by DataFlowGraph::data_flow_graph(def_arena, key_arena) — no call site"
)
}
}