From 9622e30e0f30af26867410151e7595fb06def207 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Thu, 6 Nov 2025 10:38:58 +0000 Subject: [PATCH] diag: update bluelib api usage --- diag/CMakeLists.txt | 2 +- diag/ctx.c | 7 ++++--- diag/diag.c | 2 +- diag/write/pretty.c | 39 +++++++++++++++++++-------------------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/diag/CMakeLists.txt b/diag/CMakeLists.txt index 1815925..f5a9a32 100644 --- a/diag/CMakeLists.txt +++ b/diag/CMakeLists.txt @@ -12,4 +12,4 @@ endif () target_include_directories(ivy-diag PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include/) target_compile_definitions(ivy-diag PRIVATE IVY_EXPORT=1 IVY_STATIC=${IVY_STATIC}) -target_link_libraries(ivy-diag ivy-common Bluelib::Core Bluelib::Object Bluelib::Term) +target_link_libraries(ivy-diag ivy-common Bluelib::Core Bluelib::Ds Bluelib::Term) diff --git a/diag/ctx.c b/diag/ctx.c index 39a7152..44ad399 100644 --- a/diag/ctx.c +++ b/diag/ctx.c @@ -52,11 +52,12 @@ void ivy_diag_ctx_write( struct ivy_diag_ctx *ctx, enum ivy_diag_format format, struct ivy_diag_stream *stream) { - b_queue_iterator it; - b_queue_foreach (&it, &ctx->ctx_diags) { + b_queue_entry *entry = b_queue_first(&ctx->ctx_diags); + while (entry) { struct ivy_diag *diag - = b_unbox(struct ivy_diag, it.entry, diag_entry); + = b_unbox(struct ivy_diag, entry, diag_entry); diag_write(ctx, diag, format, stream); + entry = b_queue_next(entry); } } diff --git a/diag/diag.c b/diag/diag.c index 24a1339..eee938b 100644 --- a/diag/diag.c +++ b/diag/diag.c @@ -3,7 +3,7 @@ #include "ctx.h" #include -#include +#include #include #include #include diff --git a/diag/write/pretty.c b/diag/write/pretty.c index 7bd9c3c..cce1fe7 100644 --- a/diag/write/pretty.c +++ b/diag/write/pretty.c @@ -25,7 +25,7 @@ struct snippet_print_ctx { size_t ctx_line_buf_ptr; bool ctx_has_underline; - b_stringstream ctx_underline; + b_stringstream *ctx_underline; struct diag_c_snippet *ctx_snippet; @@ -67,23 +67,23 @@ struct snippet_print_ctx { #define STREAM_COLOUR_ERROR_B(stream, str) \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ - b_stringstream_add(str, __STREAM_COLOUR_ERROR); \ + b_stream_write_string(str, __STREAM_COLOUR_ERROR, NULL); \ } #define STREAM_COLOUR_WARN_B(stream, str) \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ - b_stringstream_add(str, __STREAM_COLOUR_WARN); \ + b_stream_write_string(str, __STREAM_COLOUR_WARN, NULL); \ } #define STREAM_COLOUR_HINT_B(stream, str) \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ - b_stringstream_add(str, __STREAM_COLOUR_HINT); \ + b_stream_write_string(str, __STREAM_COLOUR_HINT, NULL); \ } #define STREAM_COLOUR_ACCENT_B(stream, str) \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ - b_stringstream_add(str, __STREAM_COLOUR_ACCENT); \ + b_stream_write_string(str, __STREAM_COLOUR_ACCENT, NULL); \ } #define STREAM_COLOUR_RESET_B(stream, str) \ if (DIAG_STREAM_FLAG_SET(stream, IVY_DIAG_STREAM_F_COLOUR)) { \ - b_stringstream_add(str, __STREAM_COLOUR_RESET); \ + b_stream_write_string(str, __STREAM_COLOUR_RESET, NULL); \ } static void print_header( @@ -233,7 +233,6 @@ static bool amendment_contains_cell( static struct ivy_diag_highlight *find_highlight( struct diag_c_snippet *snippet, size_t row, size_t col) { - b_queue_iterator it; for (size_t i = 0; i < snippet->s_nr_highlights; i++) { struct ivy_diag_highlight *hl = &snippet->s_highlights[i]; @@ -248,7 +247,6 @@ static struct ivy_diag_highlight *find_highlight( static struct ivy_diag_amendment *find_amendment( struct diag_c_snippet *snippet, size_t row, size_t col) { - b_queue_iterator it; for (size_t i = 0; i < snippet->s_nr_amendments; i++) { struct ivy_diag_amendment *a = &snippet->s_amendments[i]; @@ -296,15 +294,15 @@ static void update_highlighting(struct snippet_print_ctx *ctx) switch (ctx->ctx_hl->h_type) { case IVY_DIAG_HIGHLIGHT_ERROR: STREAM_COLOUR_ERROR(ctx->ctx_stream); - STREAM_COLOUR_ERROR_B(ctx->ctx_stream, &ctx->ctx_underline); + STREAM_COLOUR_ERROR_B(ctx->ctx_stream, ctx->ctx_underline); break; case IVY_DIAG_HIGHLIGHT_WARNING: STREAM_COLOUR_WARN(ctx->ctx_stream); - STREAM_COLOUR_WARN_B(ctx->ctx_stream, &ctx->ctx_underline); + STREAM_COLOUR_WARN_B(ctx->ctx_stream, ctx->ctx_underline); break; case IVY_DIAG_HIGHLIGHT_HINT: STREAM_COLOUR_HINT(ctx->ctx_stream); - STREAM_COLOUR_HINT_B(ctx->ctx_stream, &ctx->ctx_underline); + STREAM_COLOUR_HINT_B(ctx->ctx_stream, ctx->ctx_underline); break; default: break; @@ -318,9 +316,8 @@ static enum ivy_status read_row(struct snippet_print_ctx *ctx, size_t row) ctx->ctx_line_buf_ptr = 0; ctx->ctx_has_underline = false; - b_stringstream_begin( - &ctx->ctx_underline, ctx->ctx_underline_buf, - sizeof ctx->ctx_underline_buf); + ctx->ctx_underline = b_stringstream_create_with_buffer( + ctx->ctx_underline_buf, sizeof ctx->ctx_underline_buf); size_t nr_read; return ivy_line_source_get_row( @@ -383,7 +380,7 @@ static int get_char(struct snippet_print_ctx *ctx) static void update_underline(struct snippet_print_ctx *ctx) { if (!ctx->ctx_hl) { - b_stringstream_add(&ctx->ctx_underline, " "); + b_stream_write_char(ctx->ctx_underline, ' '); return; } @@ -391,10 +388,10 @@ static void update_underline(struct snippet_print_ctx *ctx) case IVY_DIAG_HIGHLIGHT_ERROR: case IVY_DIAG_HIGHLIGHT_WARNING: case IVY_DIAG_HIGHLIGHT_HINT: - b_stringstream_add(&ctx->ctx_underline, "^"); + b_stream_write_char(ctx->ctx_underline, '^'); break; default: - b_stringstream_add(&ctx->ctx_underline, " "); + b_stream_write_char(ctx->ctx_underline, ' '); break; } } @@ -484,13 +481,15 @@ static enum ivy_status write( print_header(ctx, diag, stream); print_location(ctx, diag, stream); - b_queue_iterator it; - b_queue_foreach (&it, &diag->diag_components) { + b_queue_entry *entry = b_queue_first(&diag->diag_components); + while (entry) { struct diag_component *c - = b_unbox(struct diag_component, it.entry, c_entry); + = b_unbox(struct diag_component, entry, c_entry); diag_stream_putc(stream, '\n'); print_component(ctx, diag, c, stream); + + entry = b_queue_next(entry); } return IVY_OK;