luaur_analysis/methods/
state_dot_visit_child_to_dot.rs1use crate::functions::get_type_alt_j::get_type_id;
2use crate::functions::to_string_to_string_alt_c::to_string_type_id;
3use crate::records::any_type::AnyType;
4use crate::records::never_type::NeverType;
5use crate::records::primitive_type::PrimitiveType;
6use crate::records::state_dot::StateDot;
7use crate::records::unknown_type::UnknownType;
8use crate::type_aliases::type_id::TypeId;
9use core::ffi::c_char;
10use luaur_common::functions::format_append::formatAppend;
11
12impl StateDot {
13 pub fn visit_child_type_id_i32_c_char(
14 &mut self,
15 ty: TypeId,
16 parent_index: i32,
17 link_name: *const c_char,
18 ) {
19 if !self.ty_to_index.contains_key(&ty)
20 || (self.opts.duplicate_primitives && self.can_duplicate_primitive(ty))
21 {
22 *self.ty_to_index.get_or_insert(ty) = self.next_index;
23 self.next_index += 1;
24 }
25
26 let index = *self.ty_to_index.find(&ty).unwrap();
27
28 if parent_index != 0 {
29 if !link_name.is_null() {
30 let name = unsafe { core::ffi::CStr::from_ptr(link_name).to_string_lossy() };
31 formatAppend(
32 &mut self.result,
33 format_args!("n{} -> n{} [label=\"{}\"];\n", parent_index, index, name),
34 );
35 } else {
36 formatAppend(
37 &mut self.result,
38 format_args!("n{} -> n{};\n", parent_index, index),
39 );
40 }
41 }
42
43 if self.opts.duplicate_primitives && self.can_duplicate_primitive(ty) {
44 unsafe {
45 if get_type_id::<PrimitiveType>(ty).is_null() == false {
46 let s = to_string_type_id(ty);
47 formatAppend(
48 &mut self.result,
49 format_args!("n{} [label=\"{}\"];\n", index, s),
50 );
51 } else if get_type_id::<AnyType>(ty).is_null() == false {
52 formatAppend(
53 &mut self.result,
54 format_args!("n{} [label=\"any\"];\n", index),
55 );
56 } else if get_type_id::<UnknownType>(ty).is_null() == false {
57 formatAppend(
58 &mut self.result,
59 format_args!("n{} [label=\"unknown\"];\n", index),
60 );
61 } else if get_type_id::<NeverType>(ty).is_null() == false {
62 formatAppend(
63 &mut self.result,
64 format_args!("n{} [label=\"never\"];\n", index),
65 );
66 }
67 }
68 } else {
69 self.visit_children_type_id_i32(ty, index);
70 }
71 }
72}