Removed C style flow control

This commit is contained in:
2026-06-10 04:35:11 +02:00
parent 286894c5db
commit afd3d05e2f
10 changed files with 42 additions and 111 deletions
-11
View File
@@ -97,17 +97,6 @@ impl RustCodegen {
}
}
}
pub fn ensure_brackets_body(&mut self, ctx: &mut Context, body: &StatementBody) {
match body {
StatementBody::Expression(expr) => self.ensure_brackets_expr(ctx, expr),
StatementBody::Statement(expr) => {
ctx.expr_ensure_semicolon = true;
self.ensure_brackets_expr(ctx, expr);
}
}
}
}
impl GenRust for Attribute {
+6 -18
View File
@@ -30,18 +30,6 @@ impl GenRust for Block {
}
}
impl GenRust for StatementBody {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
match self {
Self::Expression(expr) => expr.gen_rust(ctx, cg),
Self::Statement(stmt) => {
ctx.expr_ensure_semicolon = true;
stmt.gen_rust(ctx, cg);
}
}
}
}
impl GenRust for Statement {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
match self {
@@ -97,19 +85,19 @@ impl GenRust for Statement {
ctx.expr_ensure_semicolon = false;
initial.condition.gen_rust(ctx, cg);
cg.add(" ");
cg.ensure_brackets_body(ctx, &initial.body);
initial.body.gen_rust(ctx, cg);
for else_if_branch in else_if {
cg.add(" else if ");
ctx.expr_ensure_semicolon = false;
else_if_branch.condition.gen_rust(ctx, cg);
cg.add(" ");
cg.ensure_brackets_body(ctx, &else_if_branch.body);
else_if_branch.body.gen_rust(ctx, cg);
}
if let Some(else_br) = else_branch {
cg.add(" else ");
cg.ensure_brackets_body(ctx, else_br);
else_br.gen_rust(ctx, cg);
}
}
@@ -117,12 +105,12 @@ impl GenRust for Statement {
cg.add("while ");
condition.gen_rust(ctx, cg);
cg.add(" ");
cg.ensure_brackets_body(ctx, body);
body.gen_rust(ctx, cg);
}
Statement::Loop(body) => {
cg.add("loop ");
cg.ensure_brackets_body(ctx, body);
body.gen_rust(ctx, cg);
}
Statement::CStyleFor {
@@ -176,7 +164,7 @@ impl GenRust for Statement {
pattern.gen_rust(ctx, cg);
cg.add(" in ");
iterator.gen_rust(ctx, cg);
cg.ensure_brackets_body(ctx, body);
body.gen_rust(ctx, cg);
}
Statement::Return(expr) => {