stage1 整理代码 修复错误
This commit is contained in:
@@ -402,7 +402,10 @@ static void parse_one_field_init(spl_comp_t *ctx, spl_type_item_vec_t *items, in
|
||||
}
|
||||
emit_dup(&ctx->emit);
|
||||
emit_ptr_add(&ctx->emit, i * stride);
|
||||
int saved_aom = ctx->addr_of_mode;
|
||||
ctx->addr_of_mode = 0;
|
||||
spl_parse_expr(ctx, PREC_MIN);
|
||||
ctx->addr_of_mode = saved_aom;
|
||||
if (elem_type_idx >= 0 && !spl_type_is_scalar(&ctx->tctx, elem_type_idx)) {
|
||||
emit_copy_addr_to_addr(&ctx->emit,
|
||||
spl_type_slot_count(&ctx->tctx, elem_type_idx), 1);
|
||||
@@ -618,9 +621,9 @@ static void spl_check_arg_type(spl_comp_t *ctx, const char *fname, int arg_type_
|
||||
strcmp(spl_type_name(&ctx->tctx, arg_type_idx),
|
||||
spl_type_name(&ctx->tctx, spl_type_elem_type(&ctx->tctx, param_type_idx))) == 0) {
|
||||
fprintf(stderr,
|
||||
"%s warning: argument %d of '%s' expects '%s*', "
|
||||
"%s: warning: argument %d of '%s' expects '%s*', "
|
||||
"got '%s' (missing '&'?)\n",
|
||||
spl_tok_loc_str(ctx), arg_idx + 1, fname,
|
||||
ctx->fname, arg_idx + 1, fname,
|
||||
spl_type_name(&ctx->tctx, spl_type_elem_type(&ctx->tctx, param_type_idx)),
|
||||
spl_type_name(&ctx->tctx, arg_type_idx));
|
||||
}
|
||||
@@ -878,7 +881,7 @@ static spl_expr_result_t parse_primary_expr(spl_comp_t *ctx) {
|
||||
expect(ctx, TOK_R_PAREN);
|
||||
if (ti < 0) {
|
||||
spl_comp_error(ctx, "@sizeof: invalid type");
|
||||
spl_expr_result_t r = { -1, 0 };
|
||||
spl_expr_result_t r = {-1, 0};
|
||||
return r;
|
||||
}
|
||||
usize sz = spl_type_size(&ctx->tctx, ti);
|
||||
@@ -1080,14 +1083,20 @@ static spl_expr_result_t parse_postfix_expr(spl_comp_t *ctx, spl_expr_result_t l
|
||||
continue;
|
||||
}
|
||||
|
||||
int saved_aom = ctx->addr_of_mode;
|
||||
ctx->addr_of_mode = 0;
|
||||
spl_parse_expr(ctx, PREC_MIN);
|
||||
ctx->addr_of_mode = saved_aom;
|
||||
|
||||
if (peek(ctx)->type == TOK_RANGE) {
|
||||
advance(ctx);
|
||||
spl_expr_result_t end_expr = {-1, 0};
|
||||
int has_explicit_end = (peek(ctx)->type != TOK_R_BRACKET);
|
||||
if (has_explicit_end) {
|
||||
int saved_aom = ctx->addr_of_mode;
|
||||
ctx->addr_of_mode = 0;
|
||||
end_expr = spl_parse_expr(ctx, PREC_MIN);
|
||||
ctx->addr_of_mode = saved_aom;
|
||||
}
|
||||
(void)end_expr;
|
||||
expect(ctx, TOK_R_BRACKET);
|
||||
@@ -1145,6 +1154,11 @@ static spl_expr_result_t parse_postfix_expr(spl_comp_t *ctx, spl_expr_result_t l
|
||||
spl_type_kind(&ctx->tctx, left.type_idx) == TYPE_PTR ||
|
||||
spl_type_kind(&ctx->tctx, left.type_idx) == TYPE_SLICE)) {
|
||||
int idx_elem_idx = spl_type_elem_type(&ctx->tctx, left.type_idx);
|
||||
/* void* -> treat as u8* */
|
||||
if (idx_elem_idx >= 0 && spl_type_kind(&ctx->tctx, idx_elem_idx) == TYPE_BASIC &&
|
||||
spl_type_basic_type(&ctx->tctx, idx_elem_idx) == SPL_VOID) {
|
||||
idx_elem_idx = spl_type_basic(&ctx->tctx, SPL_U8);
|
||||
}
|
||||
|
||||
if (spl_type_kind(&ctx->tctx, left.type_idx) == TYPE_SLICE) {
|
||||
emit_slice_index(ctx, idx_elem_idx);
|
||||
|
||||
Reference in New Issue
Block a user