diff options
| author | gingerBill <bill@gingerbill.org> | 2023-08-03 13:14:09 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-08-03 13:14:09 +0100 |
| commit | b495a302b016d37a19a95cac56dc7f67fdc4ba73 (patch) | |
| tree | 8fb72c3f264a61ce442c0a71e84483b31389ca6e /src/check_expr.cpp | |
| parent | c39a3603720917d6970026e5c0595d468ea9b372 (diff) | |
| parent | 9453b2387b2cc7c473547997703c305e7982f5e4 (diff) | |
Merge branch 'master' into tilde
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 8bc73229e..b9419bf9e 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -349,6 +349,10 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E return false; } + if (base_entity->flags & EntityFlag_Disabled) { + return false; + } + String name = base_entity->token.string; Type *src = base_type(base_entity->type); @@ -462,7 +466,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E { - // LEAK TODO(bill): This is technically a memory leak as it has to generate the type twice + // LEAK NOTE(bill): This is technically a memory leak as it has to generate the type twice bool prev_no_polymorphic_errors = nctx.no_polymorphic_errors; defer (nctx.no_polymorphic_errors = prev_no_polymorphic_errors); nctx.no_polymorphic_errors = false; @@ -470,7 +474,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E // NOTE(bill): Reset scope from the failed procedure type scope_reset(scope); - // LEAK TODO(bill): Cloning this AST may be leaky + // LEAK NOTE(bill): Cloning this AST may be leaky but this is not really an issue due to arena-based allocation Ast *cloned_proc_type_node = clone_ast(pt->node); success = check_procedure_type(&nctx, final_proc_type, cloned_proc_type_node, &operands); if (!success) { @@ -778,16 +782,6 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand } } - // ^T <- rawptr -#if 0 - // TODO(bill): Should C-style (not C++) pointer cast be allowed? - if (is_type_pointer(dst) && is_type_rawptr(src)) { - return true; - } -#endif -#if 1 - - // rawptr <- ^T if (are_types_identical(type, t_rawptr) && is_type_pointer(src)) { return 5; @@ -808,7 +802,6 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand return 4; } } -#endif if (is_type_polymorphic(dst) && !is_type_polymorphic(src)) { bool modify_type = !c->no_polymorphic_errors; @@ -824,7 +817,6 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand } } - // TODO(bill): Determine which rule is a better on in practice if (dst->Union.variants.count == 1) { Type *vt = dst->Union.variants[0]; i64 score = check_distance_between_types(c, operand, vt); @@ -1093,7 +1085,7 @@ gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *typ // TODO(bill): is this a good enough error message? error(operand->expr, - "Cannot assign overloaded procedure '%s' to '%s' in %.*s", + "Cannot assign overloaded procedure group '%s' to '%s' in %.*s", expr_str, op_type_str, LIT(context_name)); @@ -1120,7 +1112,6 @@ gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *typ switch (operand->mode) { case Addressing_Builtin: - // TODO(bill): Actually allow built in procedures to be passed around and thus be created on use error(operand->expr, "Cannot assign built-in procedure '%s' in %.*s", expr_str, @@ -1412,9 +1403,6 @@ gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, T return false; case Type_Proc: if (source->kind == Type_Proc) { - // return check_is_assignable_to(c, &o, poly); - // TODO(bill): Polymorphic type assignment - #if 1 TypeProc *x = &poly->Proc; TypeProc *y = &source->Proc; if (x->calling_convention != y->calling_convention) { @@ -1447,7 +1435,6 @@ gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, T } return true; - #endif } return false; case Type_Map: @@ -1699,7 +1686,6 @@ gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) { gb_string_free(str); return false; } - // TODO(bill): Handle errors correctly Type *type = base_type(core_array_type(o->type)); gbString str = nullptr; switch (op.kind) { @@ -1743,7 +1729,6 @@ gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) { gb_internal bool check_binary_op(CheckerContext *c, Operand *o, Token op) { Type *main_type = o->type; - // TODO(bill): Handle errors correctly Type *type = base_type(core_array_type(main_type)); Type *ct = core_type(type); @@ -2261,7 +2246,7 @@ gb_internal bool check_is_not_addressable(CheckerContext *c, Operand *o) { } gb_internal void check_old_for_or_switch_value_usage(Ast *expr) { - if (!build_context.strict_style) { + if (!(build_context.strict_style || (check_vet_flags(expr) & VetFlag_Style))) { return; } @@ -2351,7 +2336,7 @@ gb_internal void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast * o->type = alloc_type_pointer(o->type); } } else { - if (build_context.strict_style && ast_node_expect(node, Ast_UnaryExpr)) { + if (ast_node_expect(node, Ast_UnaryExpr)) { ast_node(ue, UnaryExpr, node); check_old_for_or_switch_value_usage(ue->expr); } @@ -2775,8 +2760,6 @@ gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *nod gb_string_free(err_str); } - // TODO(bill): Should we support shifts for fixed arrays and #simd vectors? - if (!is_type_integer(x->type)) { gbString err_str = expr_to_string(x->expr); error(node, "Shift operand '%s' must be an integer", err_str); @@ -3099,7 +3082,7 @@ gb_internal void check_cast(CheckerContext *c, Operand *x, Type *type) { update_untyped_expr_type(c, x->expr, final_type, true); } - if (build_context.vet_extra) { + if (check_vet_flags(x->expr) & VetFlag_Extra) { if (are_types_identical(x->type, type)) { gbString str = type_to_string(type); warning(x->expr, "Unneeded cast to the same type '%s'", str); @@ -3171,7 +3154,7 @@ gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type return false; } - if (build_context.vet_extra) { + if (check_vet_flags(node) & VetFlag_Extra) { if (are_types_identical(o->type, dst_t)) { gbString str = type_to_string(dst_t); warning(o->expr, "Unneeded transmute to the same type '%s'", str); @@ -4437,7 +4420,6 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v case_end; default: - // TODO(bill): Should this be a general fallback? if (success_) *success_ = true; if (finish_) *finish_ = true; return empty_exact_value; @@ -4793,8 +4775,6 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod } if (entity == nullptr && selector->kind == Ast_Ident && is_type_array(type_deref(operand->type))) { - // TODO(bill): Simd_Vector swizzling - String field_name = selector->Ident.token.string; if (1 < field_name.len && field_name.len <= 4) { u8 swizzles_xyzw[4] = {'x', 'y', 'z', 'w'}; @@ -5989,8 +5969,8 @@ gb_internal bool check_call_arguments_single(CheckerContext *c, Ast *call, Opera } Entity *entity_to_use = data->gen_entity != nullptr ? data->gen_entity : e; - add_entity_use(c, ident, entity_to_use); if (!return_on_failure && entity_to_use != nullptr) { + add_entity_use(c, ident, entity_to_use); update_untyped_expr_type(c, operand->expr, entity_to_use->type, true); add_type_and_value(c, operand->expr, operand->mode, entity_to_use->type, operand->value); } @@ -7157,7 +7137,7 @@ gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *c i32 id = operand->builtin_id; Entity *e = entity_of_node(operand->expr); if (e != nullptr && e->token.string == "expand_to_tuple") { - warning(operand->expr, "'expand_to_tuple' has been replaced with 'expand_values'"); + error(operand->expr, "'expand_to_tuple' has been replaced with 'expand_values'"); } if (!check_builtin_procedure(c, operand, call, id, type_hint)) { operand->mode = Addressing_Invalid; @@ -10033,7 +10013,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast Type *type = type_of_expr(ac->expr); check_cast(c, o, type_hint); if (is_type_typed(type) && are_types_identical(type, type_hint)) { - if (build_context.vet_extra) { + if (check_vet_flags(node) & VetFlag_Extra) { error(node, "Redundant 'auto_cast' applied to expression"); } } |