Refactoring variable definition parsing

This commit is contained in:
2026-05-04 06:59:31 +02:00
parent 4dcb3fae7b
commit a4c1f787ff
4 changed files with 92 additions and 53 deletions
+14 -10
View File
@@ -78,7 +78,15 @@ impl RustCodegen {
let params_str = params
.0
.iter()
.map(|(n, (_, t))| format!("{}: {}", n, self.translate_type(t)))
.map(|v| {
format!(
"{name}{}",
v.type_
.as_ref()
.map(|t| format!(": {}", self.translate_type(t)))
.unwrap_or_default()
)
})
.collect::<Vec<_>>()
.join(", ");
@@ -131,15 +139,11 @@ impl RustCodegen {
self.add_indentedln("}");
}
Statement::VarDecl(VarDeclStmt {
mutable,
name,
init,
type_,
}) => {
let mutability = if *mutable { "mut " } else { "" };
Statement::VarDecl(VarDeclStmt { decl, init }) => {
let mutability = if decl.mutable { "mut " } else { "" };
let ty = type_
let ty = decl
.type_
.as_ref()
.map(|t| format!(": {}", self.translate_type(t)))
.unwrap_or_default();
@@ -149,7 +153,7 @@ impl RustCodegen {
.map(|e| format!(" = {}", self.generate_expression(e)))
.unwrap_or_default();
self.add_indentedln(&format!("let {}{}{}{};", mutability, name, ty, init));
self.add_indentedln(&format!("let {}{}{}{};", mutability, decl.name, ty, init));
}
Statement::VarAssign(VarAssignStmt { target, value }) => {