commit 059db20030fa0fc6c1e516d071b758cf3475b960
parent 75779e99755712e7582be3d69e91e608633d0e02
Author: Alexey Yerin <yyp@disroot.org>
Date: Sun, 18 Apr 2021 23:57:32 +0300
Add support for static aborts
Diffstat:
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -443,19 +443,26 @@ check_expr_assert(struct context *ctx,
cond = false;
}
// XXX: Should these abort immediately?
- if (aexpr->assert.message != NULL) {
- if (!cond) {
+ if (!cond) {
+ if (aexpr->assert.message != NULL) {
char format[40];
snprintf(format, 40, "Static assertion failed %%%lds",
expr->assert.message->constant.string.len);
- return error(aexpr->assert.cond->loc,
- expr,
- errors, format,
- expr->assert.message->constant.string.value);
+ if (aexpr->assert.cond == NULL) {
+ return error(aexpr->loc,
+ expr,
+ errors, format,
+ expr->assert.message->constant.string.value);
+ } else {
+ return error(aexpr->assert.cond->loc,
+ expr,
+ errors, format,
+ expr->assert.message->constant.string.value);
+ };
+ } else {
+ return error(aexpr->loc, expr, errors,
+ "Static assertion failed");
}
- } else if (!cond) {
- return error(aexpr->loc, expr, errors,
- "Static assertion failed");
}
}
return errors;
diff --git a/src/parse.c b/src/parse.c
@@ -1087,9 +1087,6 @@ parse_assertion_expression(struct lexer *lexer, bool is_static)
want(lexer, T_RPAREN, &tok);
break;
case T_ABORT:
- if (exp->assert.is_static) {
- synassert(false, &tok, T_ASSERT, T_EOF);
- }
want(lexer, T_LPAREN, &tok);
if (lex(lexer, &tok) != T_RPAREN) {
unlex(lexer, &tok);
@@ -2059,11 +2056,12 @@ parse_expression(struct lexer *lexer)
case T_CONST:
unlex(lexer, &tok);
return parse_binding_list(lexer, true);
+ case T_ABORT:
case T_ASSERT:
unlex(lexer, &tok);
return parse_assertion_expression(lexer, true);
default:
- synassert(false, &tok, T_LET, T_CONST, T_ASSERT, T_EOF);
+ synassert(false, &tok, T_LET, T_CONST, T_ABORT, T_ASSERT, T_EOF);
}
assert(0); // Unreachable
case T_BREAK: