diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 654dec051..ed1ddd1f1 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -2119,7 +2119,7 @@ gb_internal bool check_is_not_addressable(CheckerContext *c, Operand *o) { return true; } ast_node(ta, TypeAssertion, expr); - TypeAndValue tv = ta->expr->tav(); + TypeAndValue tv = ta->expr->tav; if (is_type_pointer(tv.type)) { return false; } @@ -2590,7 +2590,7 @@ gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *nod TokenPos pos = ast_token(x->expr).pos; if (x_is_untyped) { if (x->expr != nullptr) { - x->expr->tav().is_lhs = true; + x->expr->tav.is_lhs = true; } x->mode = Addressing_Value; if (type_hint) { @@ -3567,9 +3567,9 @@ gb_internal Operand make_operand_from_node(Ast *node) { GB_ASSERT(node != nullptr); Operand x = {}; x.expr = node; - x.mode = node->tav().mode; - x.type = node->tav().type; - x.value = node->tav().value; + x.mode = node->tav.mode; + x.type = node->tav.type; + x.value = node->tav.value; return x; } @@ -3579,8 +3579,8 @@ gb_internal void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, ExprInfo *old = check_get_expr_info(c, e); if (old == nullptr) { if (type != nullptr && type != t_invalid) { - if (e->tav().type == nullptr || e->tav().type == t_invalid) { - add_type_and_value(c->info, e, e->tav().mode, type ? type : e->tav().type, e->tav().value); + if (e->tav.type == nullptr || e->tav.type == t_invalid) { + add_type_and_value(c->info, e, e->tav.mode, type ? type : e->tav.type, e->tav.value); if (e->kind == Ast_TernaryIfExpr) { update_untyped_expr_type(c, e->TernaryIfExpr.x, type, final); update_untyped_expr_type(c, e->TernaryIfExpr.y, type, final); @@ -4146,7 +4146,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v } if (cl->elems[0]->kind == Ast_FieldValue) { - if (is_type_struct(node->tav().type)) { + if (is_type_struct(node->tav.type)) { bool found = false; for_array(i, cl->elems) { Ast *elem = cl->elems[i]; @@ -4155,10 +4155,10 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v } ast_node(fv, FieldValue, elem); String name = fv->field->Ident.token.string; - Selection sub_sel = lookup_field(node->tav().type, name, false); + Selection sub_sel = lookup_field(node->tav.type, name, false); defer (array_free(&sub_sel.index)); if (sub_sel.index[0] == index) { - value = fv->value->tav().value; + value = fv->value->tav.value; found = true; break; } @@ -4167,7 +4167,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v // Use the zero value if it is not found value = {}; } - } else if (is_type_array(node->tav().type) || is_type_enumerated_array(node->tav().type)) { + } else if (is_type_array(node->tav.type) || is_type_enumerated_array(node->tav.type)) { for_array(i, cl->elems) { Ast *elem = cl->elems[i]; if (elem->kind != Ast_FieldValue) { @@ -4176,8 +4176,8 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -4187,39 +4187,39 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v i64 corrected_index = index; - if (is_type_enumerated_array(node->tav().type)) { - Type *bt = base_type(node->tav().type); + if (is_type_enumerated_array(node->tav.type)) { + Type *bt = base_type(node->tav.type); GB_ASSERT(bt->kind == Type_EnumeratedArray); corrected_index = index + exact_value_to_i64(*bt->EnumeratedArray.min_value); } if (op != Token_RangeHalf) { if (lo <= corrected_index && corrected_index <= hi) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value; } } else { if (lo <= corrected_index && corrected_index < hi) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value; } } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); ExactValue index_value = index_tav.value; - if (is_type_enumerated_array(node->tav().type)) { - Type *bt = base_type(node->tav().type); + if (is_type_enumerated_array(node->tav.type)) { + Type *bt = base_type(node->tav.type); GB_ASSERT(bt->kind == Type_EnumeratedArray); index_value = exact_value_sub(index_value, *bt->EnumeratedArray.min_value); } i64 field_index = exact_value_to_i64(index_value); if (index == field_index) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; if (success_) *success_ = true; if (finish_) *finish_ = false; return tav.value;; @@ -4241,7 +4241,7 @@ gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue v return value; } - TypeAndValue tav = cl->elems[index]->tav(); + TypeAndValue tav = cl->elems[index]->tav; if (tav.mode == Addressing_Constant) { if (success_) *success_ = true; if (finish_) *finish_ = false; @@ -8663,7 +8663,7 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast * Ast *e = cl->elems[i]; GB_ASSERT(e->kind != Ast_FieldValue); - TypeAndValue tav = e->tav(); + TypeAndValue tav = e->tav; if (tav.mode != Addressing_Constant) { continue; } @@ -8863,9 +8863,9 @@ gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast if (se->modified_call) { // Prevent double evaluation o->expr = node; - o->type = node->tav().type; - o->value = node->tav().value; - o->mode = node->tav().mode; + o->type = node->tav.type; + o->value = node->tav.value; + o->mode = node->tav.mode; return Expr_Expr; } @@ -8927,9 +8927,9 @@ gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast } Operand y = {}; - y.mode = first_arg->tav().mode; - y.type = first_arg->tav().type; - y.value = first_arg->tav().value; + y.mode = first_arg->tav.mode; + y.type = first_arg->tav.type; + y.value = first_arg->tav.value; if (check_is_assignable_to(c, &y, first_type)) { // Do nothing, it's valid @@ -9385,7 +9385,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast case_ast_node(bl, BasicLit, node); Type *t = t_invalid; - switch (node->tav().value.kind) { + switch (node->tav.value.kind) { case ExactValue_String: t = t_untyped_string; break; case ExactValue_Float: t = t_untyped_float; break; case ExactValue_Complex: t = t_untyped_complex; break; @@ -9403,7 +9403,7 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast o->mode = Addressing_Constant; o->type = t; - o->value = node->tav().value; + o->value = node->tav.value; case_end; case_ast_node(bd, BasicDirective, node); @@ -9859,12 +9859,12 @@ gb_internal bool is_exact_value_zero(ExactValue const &v) { } else { for_array(i, cl->elems) { Ast *elem = cl->elems[i]; - if (elem->tav().mode != Addressing_Constant) { - // if (elem->tav().value.kind != ExactValue_Invalid) { + if (elem->tav.mode != Addressing_Constant) { + // if (elem->tav.value.kind != ExactValue_Invalid) { return false; // } } - if (!is_exact_value_zero(elem->tav().value)) { + if (!is_exact_value_zero(elem->tav.value)) { return false; } } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 7ba23ac67..cf111e84c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -8,7 +8,7 @@ gb_internal bool is_diverging_expr(Ast *expr) { return name == "panic"; } Ast *proc = unparen_expr(expr->CallExpr.proc); - TypeAndValue tv = proc->tav(); + TypeAndValue tv = proc->tav; if (tv.mode == Addressing_Builtin) { Entity *e = entity_of_node(proc); BuiltinProcId id = BuiltinProc_Invalid; @@ -250,7 +250,7 @@ gb_internal bool check_is_terminating(Ast *node, String const &label) { case_ast_node(ws, WhenStmt, node); // TODO(bill): Is this logic correct for when statements? - auto const &tv = ws->cond->tav(); + auto const &tv = ws->cond->tav; if (tv.mode != Addressing_Constant) { // NOTE(bill): Check the things regardless as a bug occurred earlier if (ws->else_stmt != nullptr) { @@ -411,7 +411,7 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O Ast *ln = unparen_expr(lhs->expr); if (ln->kind == Ast_IndexExpr) { Ast *x = ln->IndexExpr.expr; - TypeAndValue tav = x->tav(); + TypeAndValue tav = x->tav; GB_ASSERT(tav.mode != Addressing_Invalid); if (tav.mode != Addressing_Variable) { if (!is_type_pointer(tav.type)) { @@ -1497,7 +1497,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) break; } - switch (be->left->tav().mode) { + switch (be->left->tav.mode) { case Addressing_Context: case Addressing_Variable: case Addressing_MapIndex: @@ -2331,7 +2331,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) error(e->token, "A static variable declaration with a default value must be constant"); } else { Ast *value = vd->values[i]; - if (value->tav().mode != Addressing_Constant) { + if (value->tav.mode != Addressing_Constant) { error(e->token, "A static variable declaration with a default value must be constant"); } } diff --git a/src/check_type.cpp b/src/check_type.cpp index 3d4bab3e2..4634e1fbe 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2569,8 +2569,8 @@ gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, T case_end; case_ast_node(tt, TypeidType, e); - e->tav().mode = Addressing_Type; - e->tav().type = t_typeid; + e->tav.mode = Addressing_Type; + e->tav.type = t_typeid; *type = t_typeid; set_base_type(named_type, *type); return true; diff --git a/src/checker.cpp b/src/checker.cpp index 0f64c6ae9..14a0e5f4c 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1287,13 +1287,13 @@ gb_internal void destroy_checker(Checker *c) { gb_internal TypeAndValue type_and_value_of_expr(Ast *expr) { TypeAndValue tav = {}; if (expr != nullptr) { - tav = expr->tav(); + tav = expr->tav; } return tav; } gb_internal Type *type_of_expr(Ast *expr) { - TypeAndValue tav = expr->tav(); + TypeAndValue tav = expr->tav; if (tav.mode != Addressing_Invalid) { return tav.type; } @@ -1462,20 +1462,20 @@ gb_internal void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mo Ast *prev_expr = nullptr; while (prev_expr != expr) { prev_expr = expr; - expr->tav().mode = mode; - if (type != nullptr && expr->tav().type != nullptr && - is_type_any(type) && is_type_untyped(expr->tav().type)) { + expr->tav.mode = mode; + if (type != nullptr && expr->tav.type != nullptr && + is_type_any(type) && is_type_untyped(expr->tav.type)) { // ignore } else { - expr->tav().type = type; + expr->tav.type = type; } if (mode == Addressing_Constant || mode == Addressing_Invalid) { - expr->tav().value = value; + expr->tav.value = value; } else if (mode == Addressing_Value && is_type_typeid(type)) { - expr->tav().value = value; + expr->tav.value = value; } else if (mode == Addressing_Value && is_type_proc(type)) { - expr->tav().value = value; + expr->tav.value = value; } expr = unparen_expr(expr); @@ -3635,8 +3635,8 @@ gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) { if (value != nullptr) { if (value->kind == Ast_BasicLit && value->BasicLit.token.kind == Token_String) { String v = {}; - if (value->tav().value.kind == ExactValue_String) { - v = value->tav().value.value_string; + if (value->tav.value.kind == ExactValue_String) { + v = value->tav.value.value_string; } if (v == "file") { kind = EntityVisiblity_PrivateToFile; diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index 6c5bb153f..ee564bbf1 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -57,7 +57,7 @@ gb_internal bool lb_is_const_nil(lbValue value) { gb_internal bool lb_is_expr_constant_zero(Ast *expr) { GB_ASSERT(expr != nullptr); - auto v = exact_value_to_integer(expr->tav().value); + auto v = exact_value_to_integer(expr->tav.value); if (v.kind == ExactValue_Integer) { return big_int_cmp_zero(&v.value_integer) == 0; } @@ -720,8 +720,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -732,7 +732,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -743,11 +743,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -769,7 +769,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->Array.count); for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -804,8 +804,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -816,7 +816,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -827,11 +827,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -853,7 +853,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)type->EnumeratedArray.count); for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -887,8 +887,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -899,7 +899,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo hi += 1; } if (lo == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { values[value_index++] = val; @@ -910,11 +910,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo break; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); if (index == i) { - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; values[value_index++] = val; found = true; @@ -932,7 +932,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo return res; } else { for (isize i = 0; i < elem_count; i++) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); values[i] = lb_const_value(m, elem_type, tav.value, allow_local).value; } @@ -974,7 +974,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, cl->elems[i]); String name = fv->field->Ident.token.string; - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; GB_ASSERT(tav.mode != Addressing_Invalid); Selection sel = lookup_field(type, name, false); @@ -989,7 +989,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo } else { for_array(i, cl->elems) { Entity *f = type->Struct.fields[i]; - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; ExactValue val = {}; if (tav.mode != Addressing_Invalid) { val = tav.value; @@ -1073,7 +1073,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo Ast *e = cl->elems[i]; GB_ASSERT(e->kind != Ast_FieldValue); - TypeAndValue tav = e->tav(); + TypeAndValue tav = e->tav; if (tav.mode != Addressing_Constant) { continue; } @@ -1106,8 +1106,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo ast_node(fv, FieldValue, elem); if (is_ast_range(fv->field)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -1122,7 +1122,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo GB_ASSERT(lo <= hi); - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; for (i64 k = lo; k < hi; k++) { i64 offset = matrix_row_major_index_to_offset(type, k); @@ -1130,11 +1130,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo values[offset] = val; } } else { - TypeAndValue index_tav = fv->field->tav(); + TypeAndValue index_tav = fv->field->tav; GB_ASSERT(index_tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(index_tav.value); GB_ASSERT(index < max_count); - TypeAndValue tav = fv->value->tav(); + TypeAndValue tav = fv->value->tav; LLVMValueRef val = lb_const_value(m, elem_type, tav.value, allow_local).value; i64 offset = matrix_row_major_index_to_offset(type, index); GB_ASSERT(values[offset] == nullptr); @@ -1156,7 +1156,7 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, cast(isize)total_count); for_array(i, cl->elems) { - TypeAndValue tav = cl->elems[i]->tav(); + TypeAndValue tav = cl->elems[i]->tav; GB_ASSERT(tav.mode != Addressing_Invalid); i64 offset = matrix_row_major_index_to_offset(type, i); values[offset] = lb_const_value(m, elem_type, tav.value, allow_local).value; diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index 794ed7720..d574caf4c 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -1330,7 +1330,7 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { TypeAndValue tv = type_and_value_of_expr(expr); - if (is_type_matrix(be->left->tav().type) || is_type_matrix(be->right->tav().type)) { + if (is_type_matrix(be->left->tav.type) || is_type_matrix(be->right->tav.type)) { lbValue left = lb_build_expr(p, be->left); lbValue right = lb_build_expr(p, be->right); return lb_emit_arith_matrix(p, be->op.kind, left, right, default_type(tv.type), false); @@ -1372,12 +1372,12 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { case Token_CmpEq: case Token_NotEq: - if (is_type_untyped_nil(be->right->tav().type)) { + if (is_type_untyped_nil(be->right->tav.type)) { lbValue left = lb_build_expr(p, be->left); lbValue cmp = lb_emit_comp_against_nil(p, be->op.kind, left); Type *type = default_type(tv.type); return lb_emit_conv(p, cmp, type); - } else if (is_type_untyped_nil(be->left->tav().type)) { + } else if (is_type_untyped_nil(be->left->tav.type)) { lbValue right = lb_build_expr(p, be->right); lbValue cmp = lb_emit_comp_against_nil(p, be->op.kind, right); Type *type = default_type(tv.type); @@ -1392,11 +1392,11 @@ gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) { lbValue left = {}; lbValue right = {}; - if (be->left->tav().mode == Addressing_Type) { - left = lb_typeid(p->module, be->left->tav().type); + if (be->left->tav.mode == Addressing_Type) { + left = lb_typeid(p->module, be->left->tav.type); } - if (be->right->tav().mode == Addressing_Type) { - right = lb_typeid(p->module, be->right->tav().type); + if (be->right->tav.mode == Addressing_Type) { + right = lb_typeid(p->module, be->right->tav.type); } if (left.value == nullptr) left = lb_build_expr(p, be->left); if (right.value == nullptr) right = lb_build_expr(p, be->right); @@ -3093,7 +3093,7 @@ gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) { if (tv.value.kind != ExactValue_Invalid) { // NOTE(bill): The commented out code below is just for debug purposes only // if (is_type_untyped(type)) { - // gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav().type), expr); + // gb_printf_err("%s %s : %s @ %p\n", token_pos_to_string(expr_pos), expr_to_string(expr), type_to_string(expr->tav.type), expr); // GB_PANIC("%s\n", type_to_string(tv.type)); // } @@ -3514,8 +3514,8 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slicefield)) { ast_node(ie, BinaryExpr, fv->field); - TypeAndValue lo_tav = ie->left->tav(); - TypeAndValue hi_tav = ie->right->tav(); + TypeAndValue lo_tav = ie->left->tav; + TypeAndValue hi_tav = ie->right->tav; GB_ASSERT(lo_tav.mode == Addressing_Constant); GB_ASSERT(hi_tav.mode == Addressing_Constant); @@ -3556,7 +3556,7 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slicefield->tav(); + auto tav = fv->field->tav; GB_ASSERT(tav.mode == Addressing_Constant); i64 index = exact_value_to_i64(tav.value); @@ -3632,7 +3632,7 @@ gb_internal lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) { return lb_addr_soa_variable(val, index, ie->index); } - if (ie->expr->tav().mode == Addressing_SoaVariable) { + if (ie->expr->tav.mode == Addressing_SoaVariable) { // SOA Structures for slices/dynamic arrays GB_ASSERT(is_type_pointer(type_of_expr(ie->expr))); @@ -4451,8 +4451,8 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { a = lb_addr_get_ptr(p, addr); } - GB_ASSERT(is_type_array(expr->tav().type)); - return lb_addr_swizzle(a, expr->tav().type, swizzle_count, swizzle_indices); + GB_ASSERT(is_type_array(expr->tav.type)); + return lb_addr_swizzle(a, expr->tav.type, swizzle_count, swizzle_indices); } Selection sel = lookup_field(type, selector, false); @@ -4621,7 +4621,7 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { case_ast_node(ce, CallExpr, expr); BuiltinProcId builtin_id = BuiltinProc_Invalid; - if (ce->proc->tav().mode == Addressing_Builtin) { + if (ce->proc->tav.mode == Addressing_Builtin) { Entity *e = entity_of_node(ce->proc); if (e != nullptr) { builtin_id = cast(BuiltinProcId)e->Builtin.id; @@ -4629,7 +4629,7 @@ gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) { builtin_id = BuiltinProc_DIRECTIVE; } } - auto const &tv = expr->tav(); + auto const &tv = expr->tav; if (builtin_id == BuiltinProc_swizzle && is_type_array(tv.type)) { // NOTE(bill, 2021-08-09): `swizzle` has some bizarre semantics so it needs to be diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 546d49027..384d29ca7 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -1516,7 +1516,7 @@ gb_internal lbValue lb_build_builtin_simd_proc(lbProcedure *p, Ast *expr, TypeAn BigInt bi_count = {}; big_int_from_i64(&bi_count, count); - TypeAndValue const &tv = ce->args[1]->tav(); + TypeAndValue const &tv = ce->args[1]->tav; ExactValue val = exact_value_to_integer(tv.value); GB_ASSERT(val.kind == ExactValue_Integer); BigInt *bi = &val.value_integer; @@ -2428,16 +2428,16 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu case BuiltinProc_type_equal_proc: - return lb_equal_proc_for_type(p->module, ce->args[0]->tav().type); + return lb_equal_proc_for_type(p->module, ce->args[0]->tav.type); case BuiltinProc_type_hasher_proc: - return lb_hasher_proc_for_type(p->module, ce->args[0]->tav().type); + return lb_hasher_proc_for_type(p->module, ce->args[0]->tav.type); case BuiltinProc_type_map_info: - return lb_gen_map_info_ptr(p->module, ce->args[0]->tav().type); + return lb_gen_map_info_ptr(p->module, ce->args[0]->tav.type); case BuiltinProc_type_map_cell_info: - return lb_gen_map_cell_info_ptr(p->module, ce->args[0]->tav().type); + return lb_gen_map_cell_info_ptr(p->module, ce->args[0]->tav.type); case BuiltinProc_fixed_point_mul: @@ -2505,7 +2505,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu case BuiltinProc_prefetch_write_data: { lbValue ptr = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), t_rawptr); - unsigned long long locality = cast(unsigned long long)exact_value_to_i64(ce->args[1]->tav().value); + unsigned long long locality = cast(unsigned long long)exact_value_to_i64(ce->args[1]->tav.value); unsigned long long rw = 0; unsigned long long cache = 0; switch (id) { @@ -3060,8 +3060,8 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { } } - if (proc_expr->tav().mode == Addressing_Constant) { - ExactValue v = proc_expr->tav().value; + if (proc_expr->tav.mode == Addressing_Constant) { + ExactValue v = proc_expr->tav.value; switch (v.kind) { case ExactValue_Integer: { @@ -3070,7 +3070,7 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { x.value = LLVMConstInt(lb_type(m, t_uintptr), u, false); x.type = t_uintptr; x = lb_emit_conv(p, x, t_rawptr); - value = lb_emit_conv(p, x, proc_expr->tav().type); + value = lb_emit_conv(p, x, proc_expr->tav.type); break; } case ExactValue_Pointer: @@ -3080,7 +3080,7 @@ gb_internal lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) { x.value = LLVMConstInt(lb_type(m, t_uintptr), u, false); x.type = t_uintptr; x = lb_emit_conv(p, x, t_rawptr); - value = lb_emit_conv(p, x, proc_expr->tav().type); + value = lb_emit_conv(p, x, proc_expr->tav.type); break; } } diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index e0e991b4d..6400a8a9d 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -952,11 +952,11 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt * TokenKind op = expr->BinaryExpr.op.kind; Ast *start_expr = expr->BinaryExpr.left; Ast *end_expr = expr->BinaryExpr.right; - GB_ASSERT(start_expr->tav().mode == Addressing_Constant); - GB_ASSERT(end_expr->tav().mode == Addressing_Constant); + GB_ASSERT(start_expr->tav.mode == Addressing_Constant); + GB_ASSERT(end_expr->tav.mode == Addressing_Constant); - ExactValue start = start_expr->tav().value; - ExactValue end = end_expr->tav().value; + ExactValue start = start_expr->tav.value; + ExactValue end = end_expr->tav.value; if (op != Token_RangeHalf) { // .. [start, end] (or ..=) ExactValue index = exact_value_i64(0); for (ExactValue val = start; @@ -1006,16 +1006,16 @@ gb_internal void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt * if (val0_type) val0_addr = lb_build_addr(p, rs->val0); if (val1_type) val1_addr = lb_build_addr(p, rs->val1); - GB_ASSERT(expr->tav().mode == Addressing_Constant); + GB_ASSERT(expr->tav.mode == Addressing_Constant); - Type *t = base_type(expr->tav().type); + Type *t = base_type(expr->tav.type); switch (t->kind) { case Type_Basic: GB_ASSERT(is_type_string(t)); { - ExactValue value = expr->tav().value; + ExactValue value = expr->tav.value; GB_ASSERT(value.kind == ExactValue_String); String str = value.value_string; Rune codepoint = 0; @@ -1109,7 +1109,7 @@ gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, boo if (is_ast_range(expr)) { return false; } - if (expr->tav().mode == Addressing_Type) { + if (expr->tav.mode == Addressing_Type) { GB_ASSERT(is_typeid); continue; } @@ -1209,12 +1209,12 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * if (switch_instr != nullptr) { lbValue on_val = {}; - if (expr->tav().mode == Addressing_Type) { + if (expr->tav.mode == Addressing_Type) { GB_ASSERT(is_type_typeid(tag.type)); - lbValue e = lb_typeid(p->module, expr->tav().type); + lbValue e = lb_typeid(p->module, expr->tav.type); on_val = lb_emit_conv(p, e, tag.type); } else { - GB_ASSERT(expr->tav().mode == Addressing_Constant); + GB_ASSERT(expr->tav.mode == Addressing_Constant); GB_ASSERT(!is_ast_range(expr)); on_val = lb_build_expr(p, expr); @@ -1245,9 +1245,9 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope * lbValue cond_rhs = lb_emit_comp(p, op, tag, rhs); cond = lb_emit_arith(p, Token_And, cond_lhs, cond_rhs, t_bool); } else { - if (expr->tav().mode == Addressing_Type) { + if (expr->tav.mode == Addressing_Type) { GB_ASSERT(is_type_typeid(tag.type)); - lbValue e = lb_typeid(p->module, expr->tav().type); + lbValue e = lb_typeid(p->module, expr->tav.type); e = lb_emit_conv(p, e, tag.type); cond = lb_emit_comp(p, Token_CmpEq, tag, e); } else { @@ -1476,11 +1476,11 @@ gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) { if (vd->values.count > 0) { GB_ASSERT(vd->names.count == vd->values.count); Ast *ast_value = vd->values[i]; - GB_ASSERT(ast_value->tav().mode == Addressing_Constant || - ast_value->tav().mode == Addressing_Invalid); + GB_ASSERT(ast_value->tav.mode == Addressing_Constant || + ast_value->tav.mode == Addressing_Invalid); bool allow_local = false; - value = lb_const_value(p->module, ast_value->tav().type, ast_value->tav().value, allow_local); + value = lb_const_value(p->module, ast_value->tav.type, ast_value->tav.value, allow_local); } Ast *ident = vd->names[i]; @@ -2068,7 +2068,7 @@ gb_internal void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) { op_ += Token_Add - Token_AddEq; // Convert += to + TokenKind op = cast(TokenKind)op_; if (op == Token_CmpAnd || op == Token_CmpOr) { - Type *type = as->lhs[0]->tav().type; + Type *type = as->lhs[0]->tav.type; lbValue new_value = lb_emit_logical_binary_expr(p, op, as->lhs[0], as->rhs[0], type); lbAddr lhs = lb_build_addr(p, as->lhs[0]); diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 6abcdfc04..dbed32b82 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -1929,7 +1929,7 @@ gb_internal lbAddr lb_handle_objc_find_or_register_selector(lbProcedure *p, Stri gb_internal lbValue lb_handle_objc_find_selector(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; return lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, name)); @@ -1939,7 +1939,7 @@ gb_internal lbValue lb_handle_objc_register_selector(lbProcedure *p, Ast *expr) ast_node(ce, CallExpr, expr); lbModule *m = p->module; - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; lbAddr dst = lb_handle_objc_find_or_register_selector(p, name); @@ -1975,7 +1975,7 @@ gb_internal lbAddr lb_handle_objc_find_or_register_class(lbProcedure *p, String gb_internal lbValue lb_handle_objc_find_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; return lb_addr_load(p, lb_handle_objc_find_or_register_class(p, name)); @@ -1985,7 +1985,7 @@ gb_internal lbValue lb_handle_objc_register_class(lbProcedure *p, Ast *expr) { ast_node(ce, CallExpr, expr); lbModule *m = p->module; - auto tav = ce->args[0]->tav(); + auto tav = ce->args[0]->tav; GB_ASSERT(tav.value.kind == ExactValue_String); String name = tav.value.value_string; lbAddr dst = lb_handle_objc_find_or_register_class(p, name); @@ -2045,8 +2045,8 @@ gb_internal lbValue lb_handle_objc_send(lbProcedure *p, Ast *expr) { lbValue id = lb_handle_objc_id(p, ce->args[1]); Ast *sel_expr = ce->args[2]; - GB_ASSERT(sel_expr->tav().value.kind == ExactValue_String); - lbValue sel = lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, sel_expr->tav().value.value_string)); + GB_ASSERT(sel_expr->tav.value.kind == ExactValue_String); + lbValue sel = lb_addr_load(p, lb_handle_objc_find_or_register_selector(p, sel_expr->tav.value.value_string)); array_add(&args, id); array_add(&args, sel); diff --git a/src/parser.cpp b/src/parser.cpp index 42d8f62cf..436498c51 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -71,7 +71,6 @@ gb_internal Ast *alloc_ast_node(AstFile *f, AstKind kind) { Ast *node = cast(Ast *)gb_alloc(a, size); node->kind = kind; node->file_id = f ? f->id : 0; - node->tav_ = gb_alloc_item(a, TypeAndValue); global_total_node_memory_allocated.fetch_add(size); @@ -107,9 +106,6 @@ gb_internal Ast *clone_ast(Ast *node) { AstFile *f = node->thread_safe_file(); Ast *n = alloc_ast_node(f, node->kind); gb_memmove(n, node, ast_node_size(node->kind)); - TypeAndValue *new_tav = gb_alloc_item(ast_allocator(f), TypeAndValue); - *new_tav = *node->tav_; - n->tav_ = new_tav; switch (n->kind) { default: GB_PANIC("Unhandled Ast %.*s", LIT(ast_strings[n->kind])); break; @@ -654,8 +650,8 @@ gb_internal String string_value_from_token(AstFile *f, Token const &token) { gb_internal Ast *ast_basic_lit(AstFile *f, Token basic_lit) { Ast *result = alloc_ast_node(f, Ast_BasicLit); result->BasicLit.token = basic_lit; - result->tav().mode = Addressing_Constant; - result->tav().value = exact_value_from_token(f, basic_lit); + result->tav.mode = Addressing_Constant; + result->tav.value = exact_value_from_token(f, basic_lit); return result; } diff --git a/src/parser.hpp b/src/parser.hpp index e3d6b42d8..7d292ffce 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -754,7 +754,7 @@ struct AstCommonStuff { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue *tav_; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size }; struct Ast { @@ -762,7 +762,7 @@ struct Ast { u8 state_flags; u8 viral_state_flags; i32 file_id; - TypeAndValue *tav_; // TODO(bill): Make this a pointer to minimize 'Ast' size + TypeAndValue tav; // TODO(bill): Make this a pointer to minimize 'Ast' size // IMPORTANT NOTE(bill): This must be at the end since the AST is allocated to be size of the variant union { @@ -771,9 +771,6 @@ struct Ast { #undef AST_KIND }; - gb_inline TypeAndValue &tav() const { - return *this->tav_; - } // NOTE(bill): I know I dislike methods but this is hopefully a temporary thing // for refactoring purposes