stage1 修复错误 提供类型检查
This commit is contained in:
@@ -16,6 +16,7 @@ void spl_comp_init(spl_comp_t *ctx) {
|
||||
map_init(ctx->const_values, MAP_HASH_STR, MAP_CMP_STR);
|
||||
spl_prog_init(&ctx->prog);
|
||||
ctx->error_msg[0] = '\0';
|
||||
ctx->parse_context[0] = '\0';
|
||||
spl_emit_init(&ctx->emit, &ctx->prog);
|
||||
spl_type_ctx_init(&ctx->tctx);
|
||||
ctx->current_ret_type_idx = -1;
|
||||
@@ -67,10 +68,32 @@ void spl_comp_reset(spl_comp_t *ctx) {
|
||||
}
|
||||
|
||||
void spl_comp_error(spl_comp_t *ctx, const char *fmt, ...) {
|
||||
char body[COMP_ERROR_MAX - 64];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(ctx->error_msg, COMP_ERROR_MAX - 1, fmt, args);
|
||||
vsnprintf(body, sizeof(body), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (ctx->error_line > 0)
|
||||
snprintf(ctx->error_msg, COMP_ERROR_MAX - 1, "line %zu:%zu: %s", ctx->error_line,
|
||||
ctx->error_col, body);
|
||||
else
|
||||
snprintf(ctx->error_msg, COMP_ERROR_MAX - 1, "%s", body);
|
||||
ctx->has_error = 1;
|
||||
}
|
||||
|
||||
void spl_comp_err_tok(spl_comp_t *ctx, spl_tok_t *tok, const char *fmt, ...) {
|
||||
char body[COMP_ERROR_MAX - 64];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(body, sizeof(body), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
if (tok) {
|
||||
snprintf(ctx->error_msg, COMP_ERROR_MAX - 1, "line %zu:%zu: %s", tok->line, tok->col, body);
|
||||
} else {
|
||||
snprintf(ctx->error_msg, COMP_ERROR_MAX - 1, "%s", body);
|
||||
}
|
||||
ctx->has_error = 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user