harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7ccb4db529b38f76b2d68403c0636b99a8c5108d
parent b05e8dd0599c8a11a540993d1b7568df97212db0
Author: Alexey Yerin <yyp@disroot.org>
Date:   Wed,  4 Aug 2021 15:19:18 +0300

check: emit location for aborts with a message

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Msrc/check.c | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -415,6 +415,18 @@ check_expr_assert(struct context *ctx, return error(aexpr->assert.message->loc, expr, errors, "Assertion message must be string"); } + + assert(expr->assert.message->type == EXPR_CONSTANT); + int n = snprintf(NULL, 0, "%s:%d:%d: %s", + aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno, + expr->assert.message->constant.string.value); + char *s = xcalloc(1, n + 1); + snprintf(s, n + 1, "%s:%d:%d: %s", + aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno, + expr->assert.message->constant.string.value); + + expr->assert.message->constant.string.value = s; + expr->assert.message->constant.string.len = n; } else { int n = snprintf(NULL, 0, "Assertion failed: %s:%d:%d", aexpr->loc.path, aexpr->loc.lineno, aexpr->loc.colno);