From a76fd9b5af153773273121c7aec2a9cbeed1dfb7 Mon Sep 17 00:00:00 2001 From: Mel Date: Sun, 24 May 2026 18:18:23 +0200 Subject: Make diagnostics generic over passes, condensing different error handling Signed-off-by: Mel --- boot/catboot.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'boot/catboot.c') diff --git a/boot/catboot.c b/boot/catboot.c index 3919a2a..e340d48 100644 --- a/boot/catboot.c +++ b/boot/catboot.c @@ -130,12 +130,11 @@ debug_lower_pass(struct Source_File source_file) } struct Unit unit = { 0 }; - lower_tree(&tree, source_file, &unit); + lower_tree(&tree, &unit); printer(&unit); - // diagnostics are part of the printed unit, so the caller can read - // them from the dump. always returning success keeps snapshot tests - // viable for both the green and the diagnostic paths. + // always succeed. errors live in the printed unit and snapshot tests + // pick them up from there. return 0; } @@ -156,11 +155,12 @@ debug_transpile_pass(struct Source_File source_file) } struct Unit unit = { 0 }; - lower_tree(&tree, source_file, &unit); - if (unit.had_error) { - log_error("lowering finished with errors\n"); - return 1; + lower_tree(&tree, &unit); + FOR_EACH_ARRAY (struct Lower_Error, err, &unit.lower_errors) { + struct Diagnostic d = lower_error_to_diagnostic(err, &unit, source_file); + diagnostic_display(source_file, &d, stderr); } + if (unit.had_error) return 1; struct Transpile_Output output = transpile_output_from_file(stdout); @@ -294,11 +294,12 @@ default_command(struct Command_Arguments* arguments) } struct Unit unit = { 0 }; - lower_tree(&tree, source_file, &unit); - if (unit.had_error) { - log_error("lowering finished with errors\n"); - return COMMAND_FAIL; + lower_tree(&tree, &unit); + FOR_EACH_ARRAY (struct Lower_Error, err, &unit.lower_errors) { + struct Diagnostic d = lower_error_to_diagnostic(err, &unit, source_file); + diagnostic_display(source_file, &d, stderr); } + if (unit.had_error) return COMMAND_FAIL; struct Transpiler transpiler; transpiler_new(&transpiler, transpile_output_from_string()); -- cgit 1.4.1