Skip to main content

luaur_analysis/methods/
state_dot_visit_children_to_dot_alt_b.rs

1use crate::functions::get_type_pack::get_type_pack_id;
2use crate::records::error_type_pack::ErrorTypePack;
3use crate::records::free_type_pack::FreeTypePack;
4use crate::records::generic_type_pack::GenericTypePack;
5use crate::records::state_dot::StateDot;
6use crate::records::type_pack::TypePack;
7use crate::records::variadic_type_pack::VariadicTypePack;
8use crate::type_aliases::bound_type_pack::BoundTypePack;
9use crate::type_aliases::type_pack_id::TypePackId;
10use luaur_common::functions::format_append::formatAppend;
11use luaur_common::macros::luau_assert::LUAU_ASSERT;
12
13impl StateDot {
14    pub fn visit_children_type_pack_id_i32(&mut self, tp: TypePackId, index: i32) {
15        if self.seen_tp.contains(&tp) {
16            return;
17        }
18        self.seen_tp.insert(tp);
19
20        self.start_node(index);
21        self.start_node_label();
22
23        unsafe {
24            let btp = get_type_pack_id::<BoundTypePack>(tp);
25
26            if !btp.is_null() {
27                let btp = &*btp;
28                formatAppend(&mut self.result, format_args!("BoundTypePack {}", index));
29                self.finish_node_label_type_pack_id(tp);
30                self.finish_node();
31
32                self.visit_child_type_pack_id_i32_c_char(btp.boundTo, index, core::ptr::null());
33            } else if !get_type_pack_id::<TypePack>(tp).is_null() {
34                let tpp = &*get_type_pack_id::<TypePack>(tp);
35                formatAppend(&mut self.result, format_args!("TypePack {}", index));
36                self.finish_node_label_type_pack_id(tp);
37                self.finish_node();
38
39                for tv in &tpp.head {
40                    self.visit_child_type_id_i32_c_char(*tv, index, core::ptr::null());
41                }
42                if let Some(tail) = tpp.tail {
43                    self.visit_child_type_pack_id_i32_c_char(tail, index, c"tail".as_ptr());
44                }
45            } else if !get_type_pack_id::<VariadicTypePack>(tp).is_null() {
46                let vtp = &*get_type_pack_id::<VariadicTypePack>(tp);
47                formatAppend(
48                    &mut self.result,
49                    format_args!(
50                        "VariadicTypePack {}{}",
51                        if vtp.hidden { "hidden " } else { "" },
52                        index
53                    ),
54                );
55                self.finish_node_label_type_pack_id(tp);
56                self.finish_node();
57
58                self.visit_child_type_id_i32_c_char(vtp.ty, index, core::ptr::null());
59            } else if !get_type_pack_id::<FreeTypePack>(tp).is_null() {
60                formatAppend(&mut self.result, format_args!("FreeTypePack {}", index));
61                self.finish_node_label_type_pack_id(tp);
62                self.finish_node();
63            } else if !get_type_pack_id::<GenericTypePack>(tp).is_null() {
64                let gtp = &*get_type_pack_id::<GenericTypePack>(tp);
65                if gtp.explicitName {
66                    formatAppend(
67                        &mut self.result,
68                        format_args!("GenericTypePack {}", gtp.name),
69                    );
70                } else {
71                    formatAppend(&mut self.result, format_args!("GenericTypePack {}", index));
72                }
73                self.finish_node_label_type_pack_id(tp);
74                self.finish_node();
75            } else if !get_type_pack_id::<ErrorTypePack>(tp).is_null() {
76                formatAppend(&mut self.result, format_args!("ErrorTypePack {}", index));
77                self.finish_node_label_type_pack_id(tp);
78                self.finish_node();
79            } else {
80                LUAU_ASSERT!(false);
81                self.finish_node_label_type_pack_id(tp);
82                self.finish_node();
83            }
84        }
85    }
86}