luaur_analysis/records/
ast_expr_table_finder.rs1use crate::type_aliases::type_id::TypeId;
2use core::ffi::c_void;
3use luaur_ast::records::ast_expr::AstExpr;
4use luaur_ast::records::ast_expr_table::AstExprTable;
5use luaur_ast::records::ast_visitor::AstVisitor;
6use luaur_common::records::dense_hash_map::DenseHashMap;
7use luaur_common::records::dense_hash_set::DenseHashSet;
8
9#[derive(Debug, Clone)]
10pub struct AstExprTableFinder {
11 pub result: *mut DenseHashSet<TypeId>,
12 pub ast_types: *const DenseHashMap<*const AstExpr, TypeId>,
13}
14
15impl AstExprTableFinder {
16 pub fn new(
17 result: *mut DenseHashSet<TypeId>,
18 ast_types: *const DenseHashMap<*const AstExpr, TypeId>,
19 ) -> Self {
20 Self { result, ast_types }
21 }
22}
23
24impl AstVisitor for AstExprTableFinder {
25 fn visit_expr(&mut self, _node: *mut c_void) -> bool {
26 false
27 }
28
29 fn visit_expr_table(&mut self, node: *mut c_void) -> bool {
30 let tbl = node as *mut AstExprTable;
31 unsafe {
32 if let Some(ty) = (*self.ast_types).find(&(tbl as *const AstExpr)) {
33 (*self.result).insert(*ty);
34 }
35 }
36 true
37 }
38}