Skip to content

Commit ee2fc73

Browse files
committed
fix(c.funcpack): Don't generate validate funcs with unused args
fixes #42
1 parent 7df6021 commit ee2fc73

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

reginald_codegen/src/builtin/c/funcpack/layouts.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ fn generate_layout_validation_func(out: &mut dyn Write, inp: &Input, layout: &La
463463
return Ok(());
464464
}
465465
writeln!(out, "{func_sig} {{")?;
466+
467+
let mut valid_stmt_cnt = 0;
466468
for field in layout.fields_with_content() {
467469
let error_code = field.bits.lsb_pos() + 1;
468470
let field_name = c_code(&field.name);
@@ -472,23 +474,25 @@ fn generate_layout_validation_func(out: &mut dyn Write, inp: &Input, layout: &La
472474
match &field.accepts {
473475
FieldType::UInt => {
474476
writeln!(out, " if ((r->{field_name} & ~({uint_type})0x{unpos_mask:X}) != 0) return {error_code};")?;
477+
valid_stmt_cnt += 1;
475478
}
476479
FieldType::Enum(e) => {
477480
let macro_name = c_macro(&e.name);
478-
479481
writeln!(out, " if (!({macro_prefix}_IS_VALID_{macro_name}(r->{field_name}))) return {error_code};")?;
482+
valid_stmt_cnt += 1;
480483
}
481484
FieldType::Layout(l) => {
482485
let layout_name = c_code(&l.name);
483486
writeln!(out, " if ({code_prefix}_validate_{layout_name}(&r->{field_name})) return {error_code};")?;
487+
valid_stmt_cnt += 1;
484488
}
485489
FieldType::Bool => continue,
486490
FieldType::Fixed(_) => unreachable!(),
487491
}
488492
}
489493

490494
// Prevent unused args warnings:
491-
if layout.fields_with_content().count() == 0 {
495+
if valid_stmt_cnt == 0 {
492496
writeln!(out, " (void)r;")?;
493497
}
494498

0 commit comments

Comments
 (0)