97 lines
2.3 KiB
C
97 lines
2.3 KiB
C
#include "diag.h"
|
|
|
|
#include "ctx.h"
|
|
|
|
#include <assert.h>
|
|
#include <blue/ds/string.h>
|
|
#include <ivy/diag.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
struct diag_c_msg *diag_msg_create(const struct ivy_diag_msg *content)
|
|
{
|
|
struct diag_c_msg *out = malloc(sizeof *out);
|
|
if (!out) {
|
|
return NULL;
|
|
}
|
|
|
|
memset(out, 0x0, sizeof *out);
|
|
|
|
out->msg_base.c_type = DIAG_COMPONENT_MSG;
|
|
out->msg_content = b_strdup(content->msg_content);
|
|
|
|
return out;
|
|
}
|
|
|
|
struct diag_c_snippet *diag_snippet_create(
|
|
unsigned long first_line, unsigned long last_line,
|
|
const struct ivy_diag_amendment *amendments, size_t nr_amendments,
|
|
const struct ivy_diag_highlight *highlights, size_t nr_highlights)
|
|
{
|
|
struct diag_c_snippet *out = malloc(sizeof *out);
|
|
if (!out) {
|
|
return NULL;
|
|
}
|
|
|
|
memset(out, 0x0, sizeof *out);
|
|
|
|
out->s_base.c_type = DIAG_COMPONENT_SNIPPET;
|
|
out->s_first_line = first_line;
|
|
out->s_last_line = last_line;
|
|
|
|
out->s_nr_amendments = nr_amendments;
|
|
out->s_amendments = calloc(nr_amendments, sizeof *amendments);
|
|
if (!out->s_amendments) {
|
|
free(out);
|
|
return NULL;
|
|
}
|
|
memcpy(out->s_amendments, amendments, nr_amendments * sizeof *amendments);
|
|
|
|
out->s_nr_highlights = nr_highlights;
|
|
out->s_highlights = calloc(nr_highlights, sizeof *highlights);
|
|
if (!out->s_highlights) {
|
|
free(out->s_amendments);
|
|
free(out);
|
|
return NULL;
|
|
}
|
|
memcpy(out->s_highlights, highlights, nr_highlights * sizeof *highlights);
|
|
|
|
return out;
|
|
}
|
|
|
|
void ivy_diag_set_location(
|
|
struct ivy_diag *diag, unsigned long row, unsigned long col)
|
|
{
|
|
diag->diag_row = row;
|
|
diag->diag_col = col;
|
|
}
|
|
|
|
void ivy_diag_push_msg(struct ivy_diag *diag, unsigned long msg, ...)
|
|
{
|
|
const struct ivy_diag_msg *msg_info
|
|
= diag_ctx_get_msg(diag->diag_parent, msg);
|
|
assert(msg_info);
|
|
|
|
struct diag_c_msg *c_msg = diag_msg_create(msg_info);
|
|
if (!c_msg) {
|
|
return;
|
|
}
|
|
|
|
b_queue_push_back(&diag->diag_components, &c_msg->msg_base.c_entry);
|
|
}
|
|
|
|
void ivy_diag_push_snippet(
|
|
struct ivy_diag *diag, unsigned long first_line, unsigned long last_line,
|
|
const struct ivy_diag_amendment *amendments, size_t nr_amendments,
|
|
const struct ivy_diag_highlight *highlights, size_t nr_highlights)
|
|
{
|
|
struct diag_c_snippet *c_snippet = diag_snippet_create(
|
|
first_line, last_line, amendments, nr_amendments, highlights,
|
|
nr_highlights);
|
|
if (!c_snippet) {
|
|
return;
|
|
}
|
|
|
|
b_queue_push_back(&diag->diag_components, &c_snippet->s_base.c_entry);
|
|
}
|