Skip to main content

uika_codegen/rust_gen/
func_ids.rs

1// Rust FuncId constants generation.
2
3use crate::context::FuncEntry;
4
5/// Generate the `func_ids.rs` file with compile-time constants.
6pub fn generate_rust_func_ids(entries: &[FuncEntry]) -> String {
7    let mut out = String::with_capacity(entries.len() * 60 + 256);
8    out.push_str("// Auto-generated by uika-codegen. Do not edit.\n\n");
9    out.push_str("#![allow(dead_code)]\n\n");
10
11    for entry in entries {
12        let const_name = func_id_const_name(&entry.class_name, &entry.func_name);
13        let id = entry.func_id;
14        out.push_str(&format!("pub const {const_name}: u32 = {id};\n"));
15    }
16
17    out.push('\n');
18    out.push_str(&format!(
19        "pub const FUNC_COUNT: u32 = {};\n",
20        entries.len()
21    ));
22
23    out
24}
25
26/// Build a constant name like ACTOR_GET_OBJECT_COUNT from class + function names.
27pub fn func_id_const_name(class_name: &str, func_name: &str) -> String {
28    let class = to_screaming_snake(class_name);
29    let func = to_screaming_snake(func_name);
30    format!("{class}_{func}")
31}
32
33/// Convert PascalCase to SCREAMING_SNAKE_CASE.
34fn to_screaming_snake(name: &str) -> String {
35    let snake = crate::naming::to_snake_case(name);
36    snake.to_ascii_uppercase()
37}