From c26e650cb224ebff60ab838b0e981d1c282c9f44 Mon Sep 17 00:00:00 2001 From: raven <7156279+RavenX8@users.noreply.github.com> Date: Wed, 27 Nov 2024 23:21:01 -0500 Subject: [PATCH] - fix: more naming issues when outputting rust --- generator/src/codegen/rust/codegen_source.rs | 23 +++++++++++++++----- generator/src/flat_ast.rs | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/generator/src/codegen/rust/codegen_source.rs b/generator/src/codegen/rust/codegen_source.rs index 98b0ef0..eb8ec4a 100644 --- a/generator/src/codegen/rust/codegen_source.rs +++ b/generator/src/codegen/rust/codegen_source.rs @@ -34,6 +34,16 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> { cg!(self, "/* Generated with IDL v{} */\n", version); cg!(self, r#"use bincode::{{Encode, Decode}};"#); cg!(self, r#"use crate::packet::PacketPayload;"#); + + for content in packet.contents() { + use self::PacketContent::*; + match content { + Include(ref inc, system) => { + cg!(self, r#"use {};"#, inc); + }, + _ => {} + }; + } cg!(self); let iserialize = packet.contents().iter().filter_map(|elem| { @@ -82,7 +92,10 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> { } Some(rust_type) } - // TODO Map complex type + PacketContent::Complex(ref e) => { + let rust_type = (e.name().clone(), e.name().clone()); + Some(rust_type) + } _ => None, } }).collect::>(); // Collect into a HashMap @@ -106,7 +119,7 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> { cg!(self); cg!(self, r#"#[derive(Debug, Encode, Decode)]"#); - cg!(self, "pub struct {} {{", packet.class_name()); + cg!(self, "pub struct {} {{", packet.class_name().to_upper_camel_case()); self.indent(); for content in packet.contents() { use self::PacketContent::*; @@ -119,7 +132,7 @@ impl<'a, W: Write> CodeSourceGenerator<'a, W> { cg!(self, "}}"); cg!(self); - cg!(self, "impl PacketPayload for {} {{}}", packet.class_name()); + cg!(self, "impl PacketPayload for {} {{}}", packet.class_name().to_upper_camel_case()); Ok(()) @@ -270,9 +283,9 @@ fn rename_if_reserved(name: &str) -> String { ]; if reserved_keywords.contains(&name) { - format!("{}_", name) // Append a suffix to avoid conflicts + format!("{}_", name.to_snake_case()) // Append a suffix to avoid conflicts } else { - name.to_string() + name.to_string().to_snake_case() } } diff --git a/generator/src/flat_ast.rs b/generator/src/flat_ast.rs index 34ea636..72f2c97 100644 --- a/generator/src/flat_ast.rs +++ b/generator/src/flat_ast.rs @@ -155,7 +155,7 @@ impl Packet { (name.clone(), name.clone().to_snake_case()) } else { - let name = "srv".to_string() + &name[5..]; + let name = "Srv".to_string() + &name[5..]; (name.clone(), name.clone().to_snake_case()) }