Core: Fix casting from array to pointer of same base, improve errors

This commit is contained in:
Krzosa Karol
2023-04-21 09:33:29 +02:00
parent 8c80f609af
commit 9edb03e1bb
3 changed files with 21 additions and 20 deletions

View File

@@ -27,10 +27,16 @@ static void core_log_trace(int line, const char *file, const char *str, ...) {
String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message *msg, int color_codes_enabled = false) {
String_Builder &b = pctx->helper_builder;
if (msg->kind == CORE_ERROR) b.addf("Error! ");
else if (msg->kind == CORE_WARNING) b.addf("Warning! ");
else if (msg->kind == CORE_TRACE) b.addf("Trace: ");
else invalid_codepath;
for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) {
Token *it = msg->tokens[i];
if (it) {
b.addf("\n%s(%d): ", it->file.str, (S64)it->line + 1);
if (msg->kind == CORE_ERROR) b.addf("error ");
else if (msg->kind == CORE_WARNING) b.addf("warning ");
else if (msg->kind == CORE_TRACE) b.addf("trace ");
else invalid_codepath;
}
}
for (int i = 0; i < buff_cap(msg->tokens); i += 1) {
Token *it = msg->tokens[i];
@@ -67,13 +73,6 @@ String core_stringify_message(Core_Ctx *pctx, Allocator *allocator, Core_Message
}
}
for (S64 i = 0; i < buff_cap(msg->tokens); i += 1) {
Token *it = msg->tokens[i];
if (it) {
b.addf("\n%s(%d): error", it->file.str, (S64)it->line + 1);
}
}
String result = string_flatten(allocator, &b);
return result;
}