From 34a048f7daaf93b16ae4121bf5238f9008f3465b Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 9 Dec 2022 11:29:28 +0000 Subject: Replace compiler for loops for the hash-table types to simplify code usage --- src/checker.cpp | 134 +++++++++++++++++++++++++++----------------------------- 1 file changed, 65 insertions(+), 69 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 30a070d06..d5222f615 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -308,8 +308,8 @@ Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { } void destroy_scope(Scope *scope) { - for_array(i, scope->elements.entries) { - Entity *e =scope->elements.entries[i].value; + for (auto const &entry : scope->elements) { + Entity *e = entry.value; if (e->kind == Entity_Variable) { if (!(e->flags & EntityFlag_Used)) { #if 0 @@ -659,8 +659,8 @@ void check_scope_usage(Checker *c, Scope *scope) { Array vetted_entities = {}; array_init(&vetted_entities, heap_allocator()); - MUTEX_GUARD_BLOCK(scope->mutex) for_array(i, scope->elements.entries) { - Entity *e = scope->elements.entries[i].value; + MUTEX_GUARD_BLOCK(scope->mutex) for (auto const &entry : scope->elements) { + Entity *e = entry.value; if (e == nullptr) continue; VettedEntity ve_unused = {}; VettedEntity ve_shadowed = {}; @@ -755,9 +755,8 @@ AstPackage *get_core_package(CheckerInfo *info, String name) { gb_printf_err("Name: %.*s\n", LIT(name)); gb_printf_err("Fullpath: %.*s\n", LIT(path)); - for_array(i, info->packages.entries) { - auto *entry = &info->packages.entries[i]; - gb_printf_err("%.*s\n", LIT(entry->key.string)); + for (auto const &entry : info->packages) { + gb_printf_err("%.*s\n", LIT(entry.key.string)); } GB_ASSERT_MSG(found != nullptr, "Missing core package %.*s", LIT(name)); } @@ -1065,9 +1064,9 @@ void init_universal(void) { } bool defined_values_double_declaration = false; - for_array(i, bc->defined_values.entries) { - char const *name = bc->defined_values.entries[i].key; - ExactValue value = bc->defined_values.entries[i].value; + for (auto const &entry : bc->defined_values) { + char const *name = entry.key; + ExactValue value = entry.value; GB_ASSERT(value.kind != ExactValue_Invalid); Type *type = nullptr; @@ -1418,10 +1417,9 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { if (entry_index < 0) { // NOTE(bill): Do manual search // TODO(bill): This is O(n) and can be very slow - for_array(i, info->type_info_map.entries){ - auto *e = &info->type_info_map.entries[i]; - if (are_types_identical_unique_tuples(e->key, type)) { - entry_index = e->value; + for (auto const &e : info->type_info_map) { + if (are_types_identical_unique_tuples(e.key, type)) { + entry_index = e.value; // NOTE(bill): Add it to the search map map_set(&info->type_info_map, type, entry_index); break; @@ -1781,11 +1779,10 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { bool prev = false; isize ti_index = -1; - for_array(i, c->info->type_info_map.entries) { - auto *e = &c->info->type_info_map.entries[i]; - if (are_types_identical_unique_tuples(t, e->key)) { + for (auto const &e : c->info->type_info_map) { + if (are_types_identical_unique_tuples(t, e.key)) { // Duplicate entry - ti_index = e->value; + ti_index = e.value; prev = true; break; } @@ -1908,8 +1905,8 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { case Type_Struct: if (bt->Struct.scope != nullptr) { - for_array(i, bt->Struct.scope->elements.entries) { - Entity *e = bt->Struct.scope->elements.entries[i].value; + for (auto const &entry : bt->Struct.scope->elements) { + Entity *e = entry.value; switch (bt->Struct.soa_kind) { case StructSoa_Dynamic: add_type_info_type_internal(c, t_allocator); @@ -2132,8 +2129,8 @@ void add_min_dep_type_info(Checker *c, Type *t) { case Type_Struct: if (bt->Struct.scope != nullptr) { - for_array(i, bt->Struct.scope->elements.entries) { - Entity *e = bt->Struct.scope->elements.entries[i].value; + for (auto const &entry : bt->Struct.scope->elements) { + Entity *e = entry.value; switch (bt->Struct.soa_kind) { case StructSoa_Dynamic: add_min_dep_type_info(c, t_allocator); @@ -2230,13 +2227,12 @@ void add_dependency_to_set(Checker *c, Entity *entity) { return; } - for_array(i, decl->type_info_deps.entries) { - Type *type = decl->type_info_deps.entries[i].ptr; - add_min_dep_type_info(c, type); + for (auto const &entry : decl->type_info_deps) { + add_min_dep_type_info(c, entry.ptr); } - for_array(i, decl->deps.entries) { - Entity *e = decl->deps.entries[i].ptr; + for (auto const &entry : decl->deps) { + Entity *e = entry.ptr; add_dependency_to_set(c, e); if (e->kind == Entity_Procedure && e->Procedure.is_foreign) { Entity *fl = e->Procedure.foreign_library; @@ -2430,8 +2426,8 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { Scope *testing_scope = testing_package->scope; // Add all of testing library as a dependency - for_array(i, testing_scope->elements.entries) { - Entity *e = testing_scope->elements.entries[i].value; + for (auto const &entry : testing_scope->elements) { + Entity *e = entry.value; if (e != nullptr) { e->flags |= EntityFlag_Used; add_dependency_to_set(c, e); @@ -2445,8 +2441,8 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { AstPackage *pkg = c->info.init_package; Scope *s = pkg->scope; - for_array(i, s->elements.entries) { - Entity *e = s->elements.entries[i].value; + for (auto const &entry : s->elements) { + Entity *e = entry.value; if (e->kind != Entity_Procedure) { continue; } @@ -2512,15 +2508,15 @@ Array generate_entity_dependency_graph(CheckerInfo *info, gbA TIME_SECTION("generate_entity_dependency_graph: Calculate edges for graph M - Part 1"); // Calculate edges for graph M - for_array(i, M.entries) { - EntityGraphNode *n = M.entries[i].value; + for (auto const &entry : M) { + EntityGraphNode *n = entry.value; Entity *e = n->entity; DeclInfo *decl = decl_info_of_entity(e); GB_ASSERT(decl != nullptr); - for_array(j, decl->deps.entries) { - Entity *dep = decl->deps.entries[j].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; if (dep->flags & EntityFlag_Field) { continue; } @@ -2539,23 +2535,22 @@ Array generate_entity_dependency_graph(CheckerInfo *info, gbA TIME_SECTION("generate_entity_dependency_graph: Calculate edges for graph M - Part 2"); auto G = array_make(allocator, 0, M.entries.count); - for_array(i, M.entries) { - auto *entry = &M.entries[i]; - auto *e = entry->key; - EntityGraphNode *n = entry->value; + for (auto const &m_entry : M) { + auto *e = m_entry.key; + EntityGraphNode *n = m_entry.value; if (e->kind == Entity_Procedure) { // Connect each pred 'p' of 'n' with each succ 's' and from // the procedure node - for_array(j, n->pred.entries) { - EntityGraphNode *p = n->pred.entries[j].ptr; + for (auto const &p_entry : n->pred) { + EntityGraphNode *p = p_entry.ptr; // Ignore self-cycles if (p != n) { // Each succ 's' of 'n' becomes a succ of 'p', and // each pred 'p' of 'n' becomes a pred of 's' - for_array(k, n->succ.entries) { - EntityGraphNode *s = n->succ.entries[k].ptr; + for (auto const &s_entry : n->succ) { + EntityGraphNode *s = s_entry.ptr; // Ignore self-cycles if (s != n) { if (p->entity->kind == Entity_Procedure && @@ -4273,9 +4268,10 @@ Array generate_import_dependency_graph(Checker *c) { Array G = {}; array_init(&G, heap_allocator(), 0, M.entries.count); - for_array(i, M.entries) { - auto n = M.entries[i].value; - n->index = i; + isize i = 0; + for (auto const &entry : M) { + auto n = entry.value; + n->index = i++; n->dep_count = n->succ.entries.count; GB_ASSERT(n->dep_count >= 0); array_add(&G, n); @@ -4376,8 +4372,8 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { } else { AstPackage **found = string_map_get(pkgs, id->fullpath); if (found == nullptr) { - for_array(pkg_index, pkgs->entries) { - AstPackage *pkg = pkgs->entries[pkg_index].value; + for (auto const &entry : *pkgs) { + AstPackage *pkg = entry.value; gb_printf_err("%.*s\n", LIT(pkg->fullpath)); } gb_printf_err("%s\n", token_pos_to_string(token.pos)); @@ -4871,8 +4867,8 @@ void check_import_entities(Checker *c) { } } - for_array(i, n->pred.entries) { - ImportGraphNode *p = n->pred.entries[i].ptr; + for (auto const &entry : n->pred) { + ImportGraphNode *p = entry.ptr; p->dep_count = gb_max(p->dep_count-1, 0); priority_queue_fix(&pq, p->index); } @@ -4979,8 +4975,8 @@ bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, if (var_decl == nullptr) { continue; } - for_array(i, var_decl->deps.entries) { - Entity *dep = var_decl->deps.entries[i].ptr; + for (auto const &entry : var_decl->deps) { + Entity *dep = entry.ptr; if (dep == end) { auto path = array_make(heap_allocator()); array_add(&path, dep); @@ -5032,8 +5028,8 @@ Array find_entity_path(Entity *start, Entity *end, PtrSet *v return path; } } else { - for_array(i, decl->deps.entries) { - Entity *dep = decl->deps.entries[i].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; if (dep == end) { auto path = array_make(heap_allocator()); array_add(&path, dep); @@ -5091,8 +5087,8 @@ void calculate_global_init_order(Checker *c) { } } - for_array(i, n->pred.entries) { - EntityGraphNode *p = n->pred.entries[i].ptr; + for (auto const &entry : n->pred) { + EntityGraphNode *p = entry.ptr; p->dep_count -= 1; p->dep_count = gb_max(p->dep_count, 0); priority_queue_fix(&pq, p->index); @@ -5217,8 +5213,8 @@ void check_unchecked_bodies(Checker *c) { map_init(&untyped, heap_allocator()); defer (map_destroy(&untyped)); - for_array(i, c->info.minimum_dependency_set.entries) { - Entity *e = c->info.minimum_dependency_set.entries[i].ptr; + for (auto const &entry : c->info.minimum_dependency_set) { + Entity *e = entry.ptr; if (e == nullptr || e->kind != Entity_Procedure) { continue; } @@ -5267,8 +5263,8 @@ void check_test_procedures(Checker *c) { AstPackage *pkg = c->info.init_package; Scope *s = pkg->scope; - for_array(i, build_context.test_names.entries) { - String name = build_context.test_names.entries[i].value; + for (auto const &entry : build_context.test_names) { + String name = entry.value; Entity *e = scope_lookup(s, name); if (e == nullptr) { Token tok = {}; @@ -5422,9 +5418,9 @@ void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { if (untyped == nullptr) { return; } - for_array(i, untyped->entries) { - Ast *expr = untyped->entries[i].key; - ExprInfo *info = untyped->entries[i].value; + for (auto const &entry : *untyped) { + Ast *expr = entry.key; + ExprInfo *info = entry.value; if (expr != nullptr && info != nullptr) { mpmc_enqueue(&cinfo->checker->global_untyped_queue, UntypedExprInfo{expr, info}); } @@ -5590,8 +5586,8 @@ void check_unique_package_names(Checker *c) { string_map_init(&pkgs, heap_allocator(), 2*c->info.packages.entries.count); defer (string_map_destroy(&pkgs)); - for_array(i, c->info.packages.entries) { - AstPackage *pkg = c->info.packages.entries[i].value; + for (auto const &entry : c->info.packages) { + AstPackage *pkg = entry.value; if (pkg->files.count == 0) { continue; // Sanity check } @@ -5752,8 +5748,8 @@ void check_parsed_files(Checker *c) { check_merge_queues_into_arrays(c); TIME_SECTION("check scope usage"); - for_array(i, c->info.files.entries) { - AstFile *f = c->info.files.entries[i].value; + for (auto const &entry : c->info.files) { + AstFile *f = entry.value; check_scope_usage(c, f->scope); } @@ -5789,8 +5785,8 @@ void check_parsed_files(Checker *c) { DeclInfo *decl = e->decl_info; ast_node(pl, ProcLit, decl->proc_lit); if (pl->inlining == ProcInlining_inline) { - for_array(j, decl->deps.entries) { - Entity *dep = decl->deps.entries[j].ptr; + for (auto const &entry : decl->deps) { + Entity *dep = entry.ptr; if (dep == e) { error(e->token, "Cannot inline recursive procedure '%.*s'", LIT(e->token.string)); break; -- cgit v1.2.3 From 690666537c8a27d3c418b38b3285899100c9a556 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 21:46:27 +0000 Subject: Add `gb_internal` to checker --- src/check_builtin.cpp | 34 ++--- src/check_decl.cpp | 44 +++--- src/check_expr.cpp | 334 +++++++++++++++++++++--------------------- src/check_stmt.cpp | 46 +++--- src/check_type.cpp | 80 +++++----- src/checker.cpp | 393 +++++++++++++++++++++++++------------------------- src/types.cpp | 3 +- 7 files changed, 466 insertions(+), 468 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 533929200..859fbea28 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1,6 +1,6 @@ typedef bool (BuiltinTypeIsProc)(Type *t); -BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_boolean_end - BuiltinProc__type_simple_boolean_begin] = { +gb_global BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_boolean_end - BuiltinProc__type_simple_boolean_begin] = { nullptr, // BuiltinProc__type_simple_boolean_begin is_type_boolean, @@ -51,7 +51,7 @@ BuiltinTypeIsProc *builtin_type_is_procs[BuiltinProc__type_simple_boolean_end - }; -void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type) { +gb_internal void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type) { if (right_type == nullptr) { return; } @@ -62,7 +62,7 @@ void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, } } -void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { +gb_internal void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { Type *left_type = nullptr; Type *right_type = nullptr; if (x->type->kind == Type_Tuple) { @@ -88,7 +88,7 @@ void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name } -void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint) { +gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint) { // TODO(bill): better error message gbString t = type_to_string(x.type); error(x.expr, "'%.*s' does not return a value, value is of type %s", LIT(name), t); @@ -118,7 +118,7 @@ void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Op } -void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { +gb_internal void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_) { Type *left_type = nullptr; Type *right_type = nullptr; if (x->type->kind == Type_Tuple) { @@ -144,7 +144,7 @@ void check_or_return_split_types(CheckerContext *c, Operand *x, String const &na } -bool does_require_msgSend_stret(Type *return_type) { +gb_internal bool does_require_msgSend_stret(Type *return_type) { if (return_type == nullptr) { return false; } @@ -165,7 +165,7 @@ bool does_require_msgSend_stret(Type *return_type) { return false; } -ObjcMsgKind get_objc_proc_kind(Type *return_type) { +gb_internal ObjcMsgKind get_objc_proc_kind(Type *return_type) { if (return_type == nullptr) { return ObjcMsg_normal; } @@ -189,7 +189,7 @@ ObjcMsgKind get_objc_proc_kind(Type *return_type) { return ObjcMsg_normal; } -void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_type, Slice param_types) { +gb_internal void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_type, Slice param_types) { ObjcMsgKind kind = get_objc_proc_kind(return_type); Scope *scope = create_scope(c->info, nullptr); @@ -230,7 +230,7 @@ void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_type, Sliceproc); String builtin_name = bd->name.string; @@ -1170,7 +1170,7 @@ bool cache_load_file_directive(CheckerContext *c, Ast *call, String const &origi } -bool is_valid_type_for_load(Type *type) { +gb_internal bool is_valid_type_for_load(Type *type) { if (type == t_invalid) { return false; } else if (is_type_string(type)) { @@ -1191,7 +1191,7 @@ bool is_valid_type_for_load(Type *type) { return false; } -LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found) { +gb_internal LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found) { ast_node(ce, CallExpr, call); ast_node(bd, BasicDirective, ce->proc); String name = bd->name.string; @@ -1256,7 +1256,7 @@ LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, As } -bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint) { +gb_internal bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint) { ast_node(ce, CallExpr, call); ast_node(bd, BasicDirective, ce->proc); String name = bd->name.string; @@ -1581,7 +1581,7 @@ bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast return true; } -bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint) { +gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint) { ast_node(ce, CallExpr, call); if (ce->inlining != ProcInlining_none) { error(call, "Inlining operators are not allowed on built-in procedures"); diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 18e5477d6..a976c1b73 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -1,7 +1,7 @@ -void check_stmt (CheckerContext *ctx, Ast *node, u32 flags); +gb_internal void check_stmt(CheckerContext *ctx, Ast *node, u32 flags); // NOTE(bill): 'content_name' is for debugging and error messages -Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, String context_name) { +gb_internal Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, String context_name) { if (operand->mode == Addressing_Invalid || operand->type == t_invalid || e->type == t_invalid) { @@ -110,7 +110,7 @@ Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, Stri return e->type; } -void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Slice const &inits, String context_name) { +gb_internal void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Slice const &inits, String context_name) { if ((lhs == nullptr || lhs_count == 0) && inits.count == 0) { return; } @@ -144,7 +144,7 @@ void check_init_variables(CheckerContext *ctx, Entity **lhs, isize lhs_count, Sl } } -void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { +gb_internal void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { if (operand->mode == Addressing_Invalid || operand->type == t_invalid || e->type == t_invalid) { @@ -184,7 +184,7 @@ void check_init_constant(CheckerContext *ctx, Entity *e, Operand *operand) { } -bool is_type_distinct(Ast *node) { +gb_internal bool is_type_distinct(Ast *node) { for (;;) { if (node == nullptr) { return false; @@ -217,7 +217,7 @@ bool is_type_distinct(Ast *node) { return false; } -Ast *remove_type_alias_clutter(Ast *node) { +gb_internal Ast *remove_type_alias_clutter(Ast *node) { for (;;) { if (node == nullptr) { return nullptr; @@ -232,7 +232,7 @@ Ast *remove_type_alias_clutter(Ast *node) { } } -isize total_attribute_count(DeclInfo *decl) { +gb_internal isize total_attribute_count(DeclInfo *decl) { isize attribute_count = 0; for_array(i, decl->attributes) { Ast *attr = decl->attributes[i]; @@ -242,7 +242,7 @@ isize total_attribute_count(DeclInfo *decl) { return attribute_count; } -Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { +gb_internal Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { // NOTE(bill, 2022-02-05): Stupid edge case for `distinct` declarations // // X :: enum {A, B, C} @@ -288,7 +288,7 @@ Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named return et; } -void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def) { +gb_internal void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def) { GB_ASSERT(e->type == nullptr); DeclInfo *decl = decl_info_of_entity(e); @@ -390,7 +390,7 @@ void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def) } -void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { +gb_internal void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { // NOTE(bill): The original_entity's scope may not be same scope that it was inserted into // e.g. file entity inserted into its package scope String original_name = original_entity->token.string; @@ -433,7 +433,7 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { -void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, Type *named_type) { +gb_internal void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, Type *named_type) { GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Constant); init = unparen_expr(init); @@ -609,12 +609,12 @@ void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init, typedef bool TypeCheckSig(Type *t); -bool sig_compare(TypeCheckSig *a, Type *x, Type *y) { +gb_internal bool sig_compare(TypeCheckSig *a, Type *x, Type *y) { x = core_type(x); y = core_type(y); return (a(x) && a(y)); } -bool sig_compare(TypeCheckSig *a, TypeCheckSig *b, Type *x, Type *y) { +gb_internal bool sig_compare(TypeCheckSig *a, TypeCheckSig *b, Type *x, Type *y) { x = core_type(x); y = core_type(y); if (a == b) { @@ -623,7 +623,7 @@ bool sig_compare(TypeCheckSig *a, TypeCheckSig *b, Type *x, Type *y) { return ((a(x) && b(y)) || (b(x) && a(y))); } -bool signature_parameter_similar_enough(Type *x, Type *y) { +gb_internal bool signature_parameter_similar_enough(Type *x, Type *y) { if (sig_compare(is_type_pointer, x, y)) { return true; } @@ -674,7 +674,7 @@ bool signature_parameter_similar_enough(Type *x, Type *y) { } -bool are_signatures_similar_enough(Type *a_, Type *b_) { +gb_internal bool are_signatures_similar_enough(Type *a_, Type *b_) { GB_ASSERT(a_->kind == Type_Proc); GB_ASSERT(b_->kind == Type_Proc); TypeProc *a = &a_->Proc; @@ -704,7 +704,7 @@ bool are_signatures_similar_enough(Type *a_, Type *b_) { return true; } -Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e) { +gb_internal Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e) { Ast *ident = nullptr; Entity **foreign_library = nullptr; @@ -747,7 +747,7 @@ Entity *init_entity_foreign_library(CheckerContext *ctx, Entity *e) { return nullptr; } -String handle_link_name(CheckerContext *ctx, Token token, String link_name, String link_prefix) { +gb_internal String handle_link_name(CheckerContext *ctx, Token token, String link_name, String link_prefix) { if (link_prefix.len > 0) { if (link_name.len > 0) { error(token, "'link_name' and 'link_prefix' cannot be used together"); @@ -764,7 +764,7 @@ String handle_link_name(CheckerContext *ctx, Token token, String link_name, Stri return link_name; } -void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { +gb_internal void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { GB_ASSERT(e->type == nullptr); if (d->proc_lit->kind != Ast_ProcLit) { // TOOD(bill): Better error message @@ -1121,7 +1121,7 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) { } } -void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr, Ast *init_expr) { +gb_internal void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr, Ast *init_expr) { GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Variable); @@ -1239,7 +1239,7 @@ void check_global_variable_decl(CheckerContext *ctx, Entity *&e, Ast *type_expr, check_rtti_type_disallowed(e->token, e->type, "A variable declaration is using a type, %s, which has been disallowed"); } -void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, DeclInfo *d) { +gb_internal void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, DeclInfo *d) { GB_ASSERT(pg_entity->kind == Entity_ProcGroup); auto *pge = &pg_entity->ProcGroup; String proc_group_name = pg_entity->token.string; @@ -1367,7 +1367,7 @@ void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity, DeclInfo *d) } -void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d, Type *named_type) { +gb_internal void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d, Type *named_type) { if (e->state == EntityState_Resolved) { return; } @@ -1437,7 +1437,7 @@ struct ProcUsingVar { }; -void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *type, Ast *body) { +gb_internal void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *type, Ast *body) { if (body == nullptr) { return; } diff --git a/src/check_expr.cpp b/src/check_expr.cpp index fbc4f8b63..3003e07b6 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -17,7 +17,7 @@ enum CallArgumentError { CallArgumentError_MAX, }; -char const *CallArgumentError_strings[CallArgumentError_MAX] = { +gb_global char const *CallArgumentError_strings[CallArgumentError_MAX] = { "None", "NoneProcedureType", "WrongTypes", @@ -57,7 +57,7 @@ struct ValidIndexAndScore { i64 score; }; -int valid_index_and_score_cmp(void const *a, void const *b) { +gb_internal int valid_index_and_score_cmp(void const *a, void const *b) { i64 si = (cast(ValidIndexAndScore const *)a)->score; i64 sj = (cast(ValidIndexAndScore const *)b)->score; return sj < si ? -1 : sj > si; @@ -70,56 +70,56 @@ typedef CALL_ARGUMENT_CHECKER(CallArgumentCheckerType); -void check_expr (CheckerContext *c, Operand *operand, Ast *expression); -void check_multi_expr (CheckerContext *c, Operand *operand, Ast *expression); -void check_multi_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression); -void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint); -void check_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); -ExprKind check_expr_base (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); -void check_expr_with_type_hint (CheckerContext *c, Operand *o, Ast *e, Type *t); -Type * check_type (CheckerContext *c, Ast *expression); -Type * check_type_expr (CheckerContext *c, Ast *expression, Type *named_type); -Type * make_optional_ok_type (Type *value, bool typed=true); -Entity * check_selector (CheckerContext *c, Operand *operand, Ast *node, Type *type_hint); -Entity * check_ident (CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name); -Entity * find_polymorphic_record_entity (CheckerContext *c, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure); -void check_not_tuple (CheckerContext *c, Operand *operand); -void convert_to_typed (CheckerContext *c, Operand *operand, Type *target_type); -gbString expr_to_string (Ast *expression); -void check_proc_body (CheckerContext *c, Token token, DeclInfo *decl, Type *type, Ast *body); -void update_untyped_expr_type (CheckerContext *c, Ast *e, Type *type, bool final); -bool check_is_terminating (Ast *node, String const &label); -bool check_has_break (Ast *stmt, String const &label, bool implicit); -void check_stmt (CheckerContext *c, Ast *node, u32 flags); -void check_stmt_list (CheckerContext *c, Slice const &stmts, u32 flags); -void check_init_constant (CheckerContext *c, Entity *e, Operand *operand); -bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value); -bool check_procedure_type (CheckerContext *c, Type *type, Ast *proc_type_node, Array *operands = nullptr); -void check_struct_type (CheckerContext *c, Type *struct_type, Ast *node, Array *poly_operands, - Type *named_type = nullptr, Type *original_type_for_poly = nullptr); -void check_union_type (CheckerContext *c, Type *union_type, Ast *node, Array *poly_operands, - Type *named_type = nullptr, Type *original_type_for_poly = nullptr); +gb_internal void check_expr (CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_multi_expr (CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_multi_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint); +gb_internal void check_expr_or_type (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); +gb_internal ExprKind check_expr_base (CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint); +gb_internal void check_expr_with_type_hint (CheckerContext *c, Operand *o, Ast *e, Type *t); +gb_internal Type * check_type (CheckerContext *c, Ast *expression); +gb_internal Type * check_type_expr (CheckerContext *c, Ast *expression, Type *named_type); +gb_internal Type * make_optional_ok_type (Type *value, bool typed=true); +gb_internal Entity * check_selector (CheckerContext *c, Operand *operand, Ast *node, Type *type_hint); +gb_internal Entity * check_ident (CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name); +gb_internal Entity * find_polymorphic_record_entity (CheckerContext *c, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure); +gb_internal void check_not_tuple (CheckerContext *c, Operand *operand); +gb_internal void convert_to_typed (CheckerContext *c, Operand *operand, Type *target_type); +gb_internal gbString expr_to_string (Ast *expression); +gb_internal void check_proc_body (CheckerContext *c, Token token, DeclInfo *decl, Type *type, Ast *body); +gb_internal void update_untyped_expr_type (CheckerContext *c, Ast *e, Type *type, bool final); +gb_internal bool check_is_terminating (Ast *node, String const &label); +gb_internal bool check_has_break (Ast *stmt, String const &label, bool implicit); +gb_internal void check_stmt (CheckerContext *c, Ast *node, u32 flags); +gb_internal void check_stmt_list (CheckerContext *c, Slice const &stmts, u32 flags); +gb_internal void check_init_constant (CheckerContext *c, Entity *e, Operand *operand); +gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value); +gb_internal bool check_procedure_type (CheckerContext *c, Type *type, Ast *proc_type_node, Array *operands = nullptr); +gb_internal void check_struct_type (CheckerContext *c, Type *struct_type, Ast *node, Array *poly_operands, + Type *named_type = nullptr, Type *original_type_for_poly = nullptr); +gb_internal void check_union_type (CheckerContext *c, Type *union_type, Ast *node, Array *poly_operands, + Type *named_type = nullptr, Type *original_type_for_poly = nullptr); -CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Type *proc_type, Ast *call); -Type * check_init_variable (CheckerContext *c, Entity *e, Operand *operand, String context_name); +gb_internal CallArgumentData check_call_arguments (CheckerContext *c, Operand *operand, Type *proc_type, Ast *call); +gb_internal Type * check_init_variable (CheckerContext *c, Entity *e, Operand *operand, String context_name); -void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type); -void add_map_key_type_dependencies(CheckerContext *ctx, Type *key); +gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type); +gb_internal void add_map_key_type_dependencies(CheckerContext *ctx, Type *key); -Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); -Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); +gb_internal Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); +gb_internal Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem); -bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint); +gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32 id, Type *type_hint); -void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_); +gb_internal void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_); -void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type); -void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); -void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint); -void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); +gb_internal void check_or_else_right_type(CheckerContext *c, Ast *expr, String const &name, Type *right_type); +gb_internal void check_or_else_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); +gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint); +gb_internal void check_or_return_split_types(CheckerContext *c, Operand *x, String const &name, Type **left_type_, Type **right_type_); -bool is_diverging_expr(Ast *expr); +gb_internal bool is_diverging_expr(Ast *expr); enum LoadDirectiveResult { @@ -128,7 +128,7 @@ enum LoadDirectiveResult { LoadDirective_NotFound = 2, }; -bool is_load_directive_call(Ast *call) { +gb_internal bool is_load_directive_call(Ast *call) { call = unparen_expr(call); if (call->kind != Ast_CallExpr) { return false; @@ -141,9 +141,9 @@ bool is_load_directive_call(Ast *call) { String name = bd->name.string; return name == "load"; } -LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found); +gb_internal LoadDirectiveResult check_load_directive(CheckerContext *c, Operand *operand, Ast *call, Type *type_hint, bool err_on_not_found); -void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") { +gb_internal void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") { auto results = did_you_mean_results(d); if (results.count != 0) { error_line("\tSuggestion: Did you mean?\n"); @@ -155,7 +155,7 @@ void check_did_you_mean_print(DidYouMeanAnswers *d, char const *prefix = "") { } } -void populate_check_did_you_mean_objc_entity(StringSet *set, Entity *e, bool is_type) { +gb_internal void populate_check_did_you_mean_objc_entity(StringSet *set, Entity *e, bool is_type) { if (e->kind != Entity_TypeName) { return; } @@ -189,7 +189,7 @@ void populate_check_did_you_mean_objc_entity(StringSet *set, Entity *e, bool is_ } -void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, char const *prefix = "") { +gb_internal void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, char const *prefix = "") { ERROR_BLOCK(); GB_ASSERT(e->kind == Entity_TypeName); GB_ASSERT(e->TypeName.objc_metadata != nullptr); @@ -211,7 +211,7 @@ void check_did_you_mean_objc_entity(String const &name, Entity *e, bool is_type, check_did_you_mean_print(&d, prefix); } -void check_did_you_mean_type(String const &name, Array const &fields, char const *prefix = "") { +gb_internal void check_did_you_mean_type(String const &name, Array const &fields, char const *prefix = "") { ERROR_BLOCK(); DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name); @@ -224,7 +224,7 @@ void check_did_you_mean_type(String const &name, Array const &fields, } -void check_did_you_mean_type(String const &name, Slice const &fields, char const *prefix = "") { +gb_internal void check_did_you_mean_type(String const &name, Slice const &fields, char const *prefix = "") { ERROR_BLOCK(); DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), fields.count, name); @@ -236,7 +236,7 @@ void check_did_you_mean_type(String const &name, Slice const &fields, check_did_you_mean_print(&d, prefix); } -void check_did_you_mean_scope(String const &name, Scope *scope, char const *prefix = "") { +gb_internal void check_did_you_mean_scope(String const &name, Scope *scope, char const *prefix = "") { ERROR_BLOCK(); DidYouMeanAnswers d = did_you_mean_make(heap_allocator(), scope->elements.entries.count, name); @@ -249,7 +249,7 @@ void check_did_you_mean_scope(String const &name, Scope *scope, char const *pref check_did_you_mean_print(&d, prefix); } -Entity *entity_from_expr(Ast *expr) { +gb_internal Entity *entity_from_expr(Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case Ast_Ident: @@ -260,7 +260,7 @@ Entity *entity_from_expr(Ast *expr) { return nullptr; } -void error_operand_not_expression(Operand *o) { +gb_internal void error_operand_not_expression(Operand *o) { if (o->mode == Addressing_Type) { gbString err = expr_to_string(o->expr); error(o->expr, "'%s' is not an expression but a type", err); @@ -269,7 +269,7 @@ void error_operand_not_expression(Operand *o) { } } -void error_operand_no_value(Operand *o) { +gb_internal void error_operand_no_value(Operand *o) { if (o->mode == Addressing_NoValue) { gbString err = expr_to_string(o->expr); Ast *x = unparen_expr(o->expr); @@ -283,7 +283,7 @@ void error_operand_no_value(Operand *o) { } } -void add_map_get_dependencies(CheckerContext *c) { +gb_internal void add_map_get_dependencies(CheckerContext *c) { if (build_context.use_static_map_calls) { add_package_dependency(c, "runtime", "map_desired_position"); add_package_dependency(c, "runtime", "map_probe_distance"); @@ -292,7 +292,7 @@ void add_map_get_dependencies(CheckerContext *c) { } } -void add_map_set_dependencies(CheckerContext *c) { +gb_internal void add_map_set_dependencies(CheckerContext *c) { init_core_source_code_location(c->checker); if (t_map_set_proc == nullptr) { @@ -308,14 +308,14 @@ void add_map_set_dependencies(CheckerContext *c) { } } -void add_map_reserve_dependencies(CheckerContext *c) { +gb_internal void add_map_reserve_dependencies(CheckerContext *c) { init_core_source_code_location(c->checker); add_package_dependency(c, "runtime", "__dynamic_map_reserve"); } -void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reserve_size) { +gb_internal void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reserve_size) { Scope *s = c->scope; check_collect_entities(c, nodes); @@ -337,8 +337,8 @@ void check_scope_decls(CheckerContext *c, Slice const &nodes, isize reser } } -bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, Entity *base_entity, Type *type, - Array *param_operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { +gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, Entity *base_entity, Type *type, + Array *param_operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { /////////////////////////////////////////////////////////////////////////////// // // // TODO CLEANUP(bill): This procedure is very messy and hacky. Clean this!!! // @@ -571,24 +571,24 @@ bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, Entity *base_ return true; } -bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, Ast *poly_def_node, PolyProcData *poly_proc_data) { +gb_internal bool check_polymorphic_procedure_assignment(CheckerContext *c, Operand *operand, Type *type, Ast *poly_def_node, PolyProcData *poly_proc_data) { if (operand->expr == nullptr) return false; Entity *base_entity = entity_of_node(operand->expr); if (base_entity == nullptr) return false; return find_or_generate_polymorphic_procedure(c, base_entity, type, nullptr, poly_def_node, poly_proc_data); } -bool find_or_generate_polymorphic_procedure_from_parameters(CheckerContext *c, Entity *base_entity, Array *operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { +gb_internal bool find_or_generate_polymorphic_procedure_from_parameters(CheckerContext *c, Entity *base_entity, Array *operands, Ast *poly_def_node, PolyProcData *poly_proc_data) { return find_or_generate_polymorphic_procedure(c, base_entity, nullptr, operands, poly_def_node, poly_proc_data); } -bool check_type_specialization_to(CheckerContext *c, Type *specialization, Type *type, bool compound, bool modify_type); -bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type); -bool check_cast_internal(CheckerContext *c, Operand *x, Type *type); +gb_internal bool check_type_specialization_to(CheckerContext *c, Type *specialization, Type *type, bool compound, bool modify_type); +gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type); +gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type); #define MAXIMUM_TYPE_DISTANCE 10 -i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type) { +gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type) { if (c == nullptr) { GB_ASSERT(operand->mode == Addressing_Value); GB_ASSERT(is_type_typed(operand->type)); @@ -887,7 +887,7 @@ i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type } -i64 assign_score_function(i64 distance, bool is_variadic=false) { +gb_internal i64 assign_score_function(i64 distance, bool is_variadic=false) { // 3*x^2 + 1 > x^2 + x + 1 (for positive x) i64 const c = 3*MAXIMUM_TYPE_DISTANCE*MAXIMUM_TYPE_DISTANCE + 1; @@ -900,7 +900,7 @@ i64 assign_score_function(i64 distance, bool is_variadic=false) { } -bool check_is_assignable_to_with_score(CheckerContext *c, Operand *operand, Type *type, i64 *score_, bool is_variadic=false) { +gb_internal bool check_is_assignable_to_with_score(CheckerContext *c, Operand *operand, Type *type, i64 *score_, bool is_variadic=false) { i64 score = 0; i64 distance = check_distance_between_types(c, operand, type); bool ok = distance >= 0; @@ -912,19 +912,19 @@ bool check_is_assignable_to_with_score(CheckerContext *c, Operand *operand, Type } -bool check_is_assignable_to(CheckerContext *c, Operand *operand, Type *type) { +gb_internal bool check_is_assignable_to(CheckerContext *c, Operand *operand, Type *type) { i64 score = 0; return check_is_assignable_to_with_score(c, operand, type, &score); } -bool internal_check_is_assignable_to(Type *src, Type *dst) { +gb_internal bool internal_check_is_assignable_to(Type *src, Type *dst) { Operand x = {}; x.type = src; x.mode = Addressing_Value; return check_is_assignable_to(nullptr, &x, dst); } -AstPackage *get_package_of_type(Type *type) { +gb_internal AstPackage *get_package_of_type(Type *type) { for (;;) { if (type == nullptr) { return nullptr; @@ -962,7 +962,7 @@ AstPackage *get_package_of_type(Type *type) { // NOTE(bill): 'content_name' is for debugging and error messages -void check_assignment(CheckerContext *c, Operand *operand, Type *type, String context_name) { +gb_internal void check_assignment(CheckerContext *c, Operand *operand, Type *type, String context_name) { check_not_tuple(c, operand); if (operand->mode == Addressing_Invalid) { return; @@ -1110,7 +1110,7 @@ void check_assignment(CheckerContext *c, Operand *operand, Type *type, String co } } -bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source_count) { +gb_internal bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source_count) { Type *gt = *gt_; GB_ASSERT(gt->kind == Type_Generic); @@ -1139,7 +1139,7 @@ bool polymorphic_assign_index(Type **gt_, i64 *dst_count, i64 source_count) { return false; } -bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type) { +gb_internal bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, bool compound, bool modify_type) { Operand o = {Addressing_Value}; o.type = source; switch (poly->kind) { @@ -1439,7 +1439,7 @@ bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source, return false; } -bool check_cycle(CheckerContext *c, Entity *curr, bool report) { +gb_internal bool check_cycle(CheckerContext *c, Entity *curr, bool report) { if (curr->state != EntityState_InProgress) { return false; } @@ -1461,7 +1461,7 @@ bool check_cycle(CheckerContext *c, Entity *curr, bool report) { return false; } -Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name) { +gb_internal Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Type *type_hint, bool allow_import_name) { GB_ASSERT(n->kind == Ast_Ident); o->mode = Addressing_Invalid; o->expr = n; @@ -1630,7 +1630,7 @@ Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Typ } -bool check_unary_op(CheckerContext *c, Operand *o, Token op) { +gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) { if (o->type == nullptr) { gbString str = expr_to_string(o->expr); error(o->expr, "Expression has no value '%s'", str); @@ -1672,7 +1672,7 @@ bool check_unary_op(CheckerContext *c, Operand *o, Token op) { return true; } -bool check_binary_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 @@ -1783,7 +1783,7 @@ bool check_binary_op(CheckerContext *c, Operand *o, Token op) { } -bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value) { +gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Type *type, ExactValue *out_value) { if (in_value.kind == ExactValue_Invalid) { // NOTE(bill): There's already been an error return true; @@ -1998,7 +1998,7 @@ bool check_representable_as_constant(CheckerContext *c, ExactValue in_value, Typ } -void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type) { +gb_internal void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type) { gbString a = expr_to_string(o->expr); gbString b = type_to_string(type); defer( @@ -2032,7 +2032,7 @@ void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type } } -void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) { +gb_internal void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) { gbString a = expr_to_string(o->expr); gbString b = type_to_string(type); defer( @@ -2074,7 +2074,7 @@ void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) { } -bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type) { +gb_internal bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type) { GB_ASSERT(o->mode == Addressing_Constant); ExactValue out_value = o->value; if (is_type_constant_type(type) && check_representable_as_constant(ctx, o->value, type, &out_value)) { @@ -2112,7 +2112,7 @@ bool check_is_expressible(CheckerContext *ctx, Operand *o, Type *type) { } } -bool check_is_not_addressable(CheckerContext *c, Operand *o) { +gb_internal bool check_is_not_addressable(CheckerContext *c, Operand *o) { if (o->mode == Addressing_OptionalOk) { Ast *expr = unselector_expr(o->expr); if (expr->kind != Ast_TypeAssertion) { @@ -2143,7 +2143,7 @@ bool check_is_not_addressable(CheckerContext *c, Operand *o) { return o->mode != Addressing_Variable && o->mode != Addressing_SoaVariable; } -void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { +gb_internal void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { switch (op.kind) { case Token_And: { // Pointer address if (check_is_not_addressable(c, o)) { @@ -2270,7 +2270,7 @@ void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { o->mode = Addressing_Value; } -void add_comparison_procedures_for_fields(CheckerContext *c, Type *t) { +gb_internal void add_comparison_procedures_for_fields(CheckerContext *c, Type *t) { if (t == nullptr) { return; } @@ -2323,7 +2323,7 @@ void add_comparison_procedures_for_fields(CheckerContext *c, Type *t) { } -void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { +gb_internal void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { if (x->mode == Addressing_Type && y->mode == Addressing_Type) { bool comp = are_types_identical(x->type, y->type); switch (op) { @@ -2516,7 +2516,7 @@ void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) { } -void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node, Type *type_hint) { +gb_internal void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node, Type *type_hint) { GB_ASSERT(node->kind == Ast_BinaryExpr); ast_node(be, BinaryExpr, node); @@ -2635,7 +2635,7 @@ void check_shift(CheckerContext *c, Operand *x, Operand *y, Ast *node, Type *typ -bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { +gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { if (check_is_assignable_to(c, operand, y)) { return true; } @@ -2851,7 +2851,7 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) { return false; } -bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) { +gb_internal bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) { bool is_const_expr = x->mode == Addressing_Constant; Type *bt = base_type(type); @@ -2886,7 +2886,7 @@ bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) { } -void check_cast(CheckerContext *c, Operand *x, Type *type) { +gb_internal void check_cast(CheckerContext *c, Operand *x, Type *type) { if (!is_operand_value(*x)) { error(x->expr, "Only values can be casted"); x->mode = Addressing_Invalid; @@ -2930,7 +2930,7 @@ void check_cast(CheckerContext *c, Operand *x, Type *type) { x->type = type; } -bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { +gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { if (!is_operand_value(*o)) { error(o->expr, "'transmute' can only be applied to values"); o->mode = Addressing_Invalid; @@ -3043,7 +3043,7 @@ bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type *t) { return true; } -bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y) { +gb_internal bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y) { if (is_type_array(x->type) && !is_type_array(y->type)) { if (check_is_assignable_to(c, y, x->type)) { if (check_binary_op(c, x, op)) { @@ -3054,19 +3054,19 @@ bool check_binary_array_expr(CheckerContext *c, Token op, Operand *x, Operand *y return false; } -bool is_ise_expr(Ast *node) { +gb_internal bool is_ise_expr(Ast *node) { node = unparen_expr(node); return node->kind == Ast_ImplicitSelectorExpr; } -bool can_use_other_type_as_type_hint(bool use_lhs_as_type_hint, Type *other_type) { +gb_internal bool can_use_other_type_as_type_hint(bool use_lhs_as_type_hint, Type *other_type) { if (use_lhs_as_type_hint) { // RHS in this case return other_type != nullptr && other_type != t_invalid && is_type_typed(other_type); } return false; } -Type *check_matrix_type_hint(Type *matrix, Type *type_hint) { +gb_internal Type *check_matrix_type_hint(Type *matrix, Type *type_hint) { Type *xt = base_type(matrix); if (type_hint != nullptr) { Type *th = base_type(type_hint); @@ -3086,7 +3086,7 @@ Type *check_matrix_type_hint(Type *matrix, Type *type_hint) { } -void check_binary_matrix(CheckerContext *c, Token const &op, Operand *x, Operand *y, Type *type_hint, bool use_lhs_as_type_hint) { +gb_internal void check_binary_matrix(CheckerContext *c, Token const &op, Operand *x, Operand *y, Type *type_hint, bool use_lhs_as_type_hint) { if (!check_binary_op(c, x, op)) { x->mode = Addressing_Invalid; return; @@ -3197,7 +3197,7 @@ matrix_error: } -void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint, bool use_lhs_as_type_hint=false) { +gb_internal void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint, bool use_lhs_as_type_hint=false) { GB_ASSERT(node->kind == Ast_BinaryExpr); Operand y_ = {}, *y = &y_; @@ -3563,7 +3563,7 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint x->mode = Addressing_Value; } -Operand make_operand_from_node(Ast *node) { +gb_internal Operand make_operand_from_node(Ast *node) { GB_ASSERT(node != nullptr); Operand x = {}; x.expr = node; @@ -3574,7 +3574,7 @@ Operand make_operand_from_node(Ast *node) { } -void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) { +gb_internal void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) { GB_ASSERT(e != nullptr); ExprInfo *old = check_get_expr_info(c, e); if (old == nullptr) { @@ -3689,7 +3689,7 @@ void update_untyped_expr_type(CheckerContext *c, Ast *e, Type *type, bool final) add_type_and_value(c->info, e, old->mode, type, old->value); } -void update_untyped_expr_value(CheckerContext *c, Ast *e, ExactValue value) { +gb_internal void update_untyped_expr_value(CheckerContext *c, Ast *e, ExactValue value) { GB_ASSERT(e != nullptr); ExprInfo *found = check_get_expr_info(c, e); if (found) { @@ -3697,7 +3697,7 @@ void update_untyped_expr_value(CheckerContext *c, Ast *e, ExactValue value) { } } -void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_type) { +gb_internal void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_type) { gbString expr_str = expr_to_string(operand->expr); gbString type_str = type_to_string(target_type); gbString from_type_str = type_to_string(operand->type); @@ -3728,7 +3728,7 @@ void convert_untyped_error(CheckerContext *c, Operand *operand, Type *target_typ operand->mode = Addressing_Invalid; } -ExactValue convert_exact_value_for_type(ExactValue v, Type *type) { +gb_internal ExactValue convert_exact_value_for_type(ExactValue v, Type *type) { Type *t = core_type(type); if (is_type_boolean(t)) { // v = exact_value_to_boolean(v); @@ -3746,7 +3746,7 @@ ExactValue convert_exact_value_for_type(ExactValue v, Type *type) { return v; } -void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { +gb_internal void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { GB_ASSERT_NOT_NULL(target_type); if (operand->mode == Addressing_Invalid || operand->mode == Addressing_Type || @@ -3995,7 +3995,7 @@ void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) { operand->type = target_type; } -bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast *index_value, i64 max_count, i64 *value, Type *type_hint=nullptr) { +gb_internal bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast *index_value, i64 max_count, i64 *value, Type *type_hint=nullptr) { Operand operand = {Addressing_Invalid}; check_expr_with_type_hint(c, &operand, index_value, type_hint); if (operand.mode == Addressing_Invalid) { @@ -4121,7 +4121,7 @@ bool check_index_value(CheckerContext *c, Type *main_type, bool open_range, Ast return true; } -ExactValue get_constant_field_single(CheckerContext *c, ExactValue value, i32 index, bool *success_, bool *finish_) { +gb_internal ExactValue get_constant_field_single(CheckerContext *c, ExactValue value, i32 index, bool *success_, bool *finish_) { if (value.kind == ExactValue_String) { GB_ASSERT(0 <= index && index < value.value_string.len); u8 val = value.value_string[index]; @@ -4269,7 +4269,7 @@ ExactValue get_constant_field_single(CheckerContext *c, ExactValue value, i32 in -ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selection sel, bool *success_) { +gb_internal ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selection sel, bool *success_) { if (operand->mode != Addressing_Constant) { if (success_) *success_ = false; return empty_exact_value; @@ -4349,7 +4349,7 @@ ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selecti return empty_exact_value; } -Type *determine_swizzle_array_type(Type *original_type, Type *type_hint, isize new_count) { +gb_internal Type *determine_swizzle_array_type(Type *original_type, Type *type_hint, isize new_count) { Type *array_type = base_type(type_deref(original_type)); GB_ASSERT(array_type->kind == Type_Array || array_type->kind == Type_SimdVector); if (array_type->kind == Type_SimdVector) { @@ -4376,7 +4376,7 @@ Type *determine_swizzle_array_type(Type *original_type, Type *type_hint, isize n } -bool is_entity_declared_for_selector(Entity *entity, Scope *import_scope, bool *allow_builtin) { +gb_internal bool is_entity_declared_for_selector(Entity *entity, Scope *import_scope, bool *allow_builtin) { bool is_declared = entity != nullptr; if (is_declared) { if (entity->kind == Entity_Builtin) { @@ -4391,7 +4391,7 @@ bool is_entity_declared_for_selector(Entity *entity, Scope *import_scope, bool * } // NOTE(bill, 2022-02-03): see `check_const_decl` for why it exists reasoning -Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool ident_only) { +gb_internal Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool ident_only) { if (node->kind == Ast_Ident) { String name = node->Ident.token.string; return scope_lookup(c->scope, name); @@ -4471,7 +4471,7 @@ Entity *check_entity_from_ident_or_selector(CheckerContext *c, Ast *node, bool i } -Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *type_hint) { +gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *type_hint) { ast_node(se, SelectorExpr, node); bool check_op_expr = true; @@ -4865,7 +4865,7 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ return entity; } -bool is_type_normal_pointer(Type *ptr, Type **elem) { +gb_internal bool is_type_normal_pointer(Type *ptr, Type **elem) { ptr = base_type(ptr); if (is_type_pointer(ptr)) { if (is_type_rawptr(ptr)) { @@ -4877,7 +4877,7 @@ bool is_type_normal_pointer(Type *ptr, Type **elem) { return false; } -bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **out_scope = nullptr) { +gb_internal bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **out_scope = nullptr) { switch (node->kind) { case_ast_node(i, Ident, node); String name = i->token.string; @@ -4907,7 +4907,7 @@ bool check_identifier_exists(Scope *s, Ast *node, bool nested = false, Scope **o return false; } -isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs_count, isize tuple_index, isize tuple_count) { +gb_internal isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs_count, isize tuple_index, isize tuple_count) { if (lhs != nullptr && c->decl != nullptr) { mutex_lock(&c->info->deps_mutex); @@ -4930,7 +4930,7 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs } -bool check_assignment_arguments(CheckerContext *ctx, Array const &lhs, Array *operands, Slice const &rhs) { +gb_internal bool check_assignment_arguments(CheckerContext *ctx, Array const &lhs, Array *operands, Slice const &rhs) { bool optional_ok = false; isize tuple_index = 0; for_array(i, rhs) { @@ -5011,7 +5011,7 @@ bool check_assignment_arguments(CheckerContext *ctx, Array const &lhs, -bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Slice const &rhs, bool allow_ok, bool is_variadic) { +gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array *operands, Slice const &rhs, bool allow_ok, bool is_variadic) { bool optional_ok = false; isize tuple_index = 0; for_array(i, rhs) { @@ -5104,7 +5104,7 @@ bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, } -bool is_expr_constant_zero(Ast *expr) { +gb_internal bool is_expr_constant_zero(Ast *expr) { GB_ASSERT(expr != nullptr); auto v = exact_value_to_integer(expr->tav.value); if (v.kind == ExactValue_Integer) { @@ -5113,7 +5113,7 @@ bool is_expr_constant_zero(Ast *expr) { return false; } -isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { +gb_internal isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { GB_ASSERT(pt != nullptr); GB_ASSERT(pt->kind == Type_Proc); isize param_count = 0; @@ -5167,7 +5167,7 @@ isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_ } -CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { +gb_internal CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { ast_node(ce, CallExpr, call); GB_ASSERT(is_type_proc(proc_type)); proc_type = base_type(proc_type); @@ -5406,7 +5406,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { return err; } -bool is_call_expr_field_value(AstCallExpr *ce) { +gb_internal bool is_call_expr_field_value(AstCallExpr *ce) { GB_ASSERT(ce != nullptr); if (ce->args.count == 0) { @@ -5415,7 +5415,7 @@ bool is_call_expr_field_value(AstCallExpr *ce) { return ce->args[0]->kind == Ast_FieldValue; } -isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { +gb_internal isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { isize param_count = pt->param_count; for (isize i = 0; i < param_count; i++) { Entity *e = pt->params->Tuple.variables[i]; @@ -5429,7 +5429,7 @@ isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) { } return -1; } -isize lookup_procedure_result(TypeProc *pt, String result_name) { +gb_internal isize lookup_procedure_result(TypeProc *pt, String result_name) { isize result_count = pt->result_count; for (isize i = 0; i < result_count; i++) { Entity *e = pt->results->Tuple.variables[i]; @@ -5444,7 +5444,7 @@ isize lookup_procedure_result(TypeProc *pt, String result_name) { return -1; } -CALL_ARGUMENT_CHECKER(check_named_call_arguments) { +gb_internal CALL_ARGUMENT_CHECKER(check_named_call_arguments) { ast_node(ce, CallExpr, call); GB_ASSERT(is_type_proc(proc_type)); proc_type = base_type(proc_type); @@ -5628,7 +5628,7 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) { return err; } -Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize *lhs_count_, bool *is_variadic) { +gb_internal Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize *lhs_count_, bool *is_variadic) { Entity **lhs = nullptr; isize lhs_count = -1; @@ -5667,7 +5667,7 @@ Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize } -bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Slice *clauses, bool print_err) { +gb_internal bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Slice *clauses, bool print_err) { if (clauses != nullptr) { for (Ast *clause : *clauses) { Operand o = {}; @@ -5733,7 +5733,7 @@ bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, S } -CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type *proc_type, Ast *call, Slice const &args) { +gb_internal CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type *proc_type, Ast *call, Slice const &args) { ast_node(ce, CallExpr, call); CallArgumentCheckerType *call_checker = check_call_arguments_internal; @@ -6262,7 +6262,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type } -isize lookup_polymorphic_record_parameter(Type *t, String parameter_name) { +gb_internal isize lookup_polymorphic_record_parameter(Type *t, String parameter_name) { if (!is_type_polymorphic_record(t)) { return -1; } @@ -6285,7 +6285,7 @@ isize lookup_polymorphic_record_parameter(Type *t, String parameter_name) { } -CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *operand, Ast *call) { +gb_internal CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *operand, Ast *call) { ast_node(ce, CallExpr, call); Type *original_type = operand->type; @@ -6605,7 +6605,7 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper -ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *proc, Slice const &args, ProcInlining inlining, Type *type_hint) { +gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *proc, Slice const &args, ProcInlining inlining, Type *type_hint) { if (proc != nullptr && proc->kind == Ast_BasicDirective) { ast_node(bd, BasicDirective, proc); @@ -6880,7 +6880,7 @@ ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *call, Ast *pr } -void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { +gb_internal void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { check_expr_base(c, o, e, t); check_not_tuple(c, o); char const *err_str = nullptr; @@ -6905,7 +6905,7 @@ void check_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *t) { } } -bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, Type *original_type) { +gb_internal bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, Type *original_type) { switch (t->kind) { case Type_Basic: if (t->Basic.kind == Basic_string) { @@ -7018,7 +7018,7 @@ bool check_set_index_data(Operand *o, Type *t, bool indirection, i64 *max_count, return false; } -bool ternary_compare_types(Type *x, Type *y) { +gb_internal bool ternary_compare_types(Type *x, Type *y) { if (is_type_untyped_undef(x) && type_has_undef(y)) { return true; } else if (is_type_untyped_nil(x) && type_has_nil(y)) { @@ -7032,7 +7032,7 @@ bool ternary_compare_types(Type *x, Type *y) { } -bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValue *inline_for_depth_, Type *type_hint=nullptr) { +gb_internal bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValue *inline_for_depth_, Type *type_hint=nullptr) { if (!is_ast_range(node)) { return false; } @@ -7124,7 +7124,7 @@ bool check_range(CheckerContext *c, Ast *node, Operand *x, Operand *y, ExactValu return true; } -bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { +gb_internal bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { if (is_operand_nil(*o)) { return true; } @@ -7143,7 +7143,7 @@ bool check_is_operand_compound_lit_constant(CheckerContext *c, Operand *o) { } -bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSelectorExpr *ise, Type *th) { +gb_internal bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSelectorExpr *ise, Type *th) { if (is_type_enum(th)) { Type *enum_type = base_type(th); GB_ASSERT(enum_type->kind == Type_Enum); @@ -7182,7 +7182,7 @@ bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSe return false; } -ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(ise, ImplicitSelectorExpr, node); o->type = t_invalid; @@ -7226,7 +7226,7 @@ ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node, } -void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_) { +gb_internal void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, Type **ok_type_) { switch (x->mode) { case Addressing_MapIndex: case Addressing_OptionalOk: @@ -7263,7 +7263,7 @@ void check_promote_optional_ok(CheckerContext *c, Operand *x, Type **val_type_, } -void check_matrix_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal void check_matrix_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(ie, MatrixIndexExpr, node); check_expr(c, o, ie->expr); @@ -7336,7 +7336,7 @@ struct TypeAndToken { typedef PtrMap SeenMap; -void add_constant_switch_case(CheckerContext *ctx, SeenMap *seen, Operand operand, bool use_expr = true) { +gb_internal void add_constant_switch_case(CheckerContext *ctx, SeenMap *seen, Operand operand, bool use_expr = true) { if (operand.mode != Addressing_Constant) { return; } @@ -7378,7 +7378,7 @@ void add_constant_switch_case(CheckerContext *ctx, SeenMap *seen, Operand operan } -void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, TokenKind upper_op, Operand const &x, Operand const &lhs, Operand const &rhs) { +gb_internal void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, TokenKind upper_op, Operand const &x, Operand const &lhs, Operand const &rhs) { if (is_type_enum(x.type)) { // TODO(bill): Fix this logic so it's fast!!! @@ -7419,11 +7419,11 @@ void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, TokenKind upper_op, Ope } } } -void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, Operand const &x) { +gb_internal void add_to_seen_map(CheckerContext *ctx, SeenMap *seen, Operand const &x) { add_constant_switch_case(ctx, seen, x); } -ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(bd, BasicDirective, node); ExprKind kind = Expr_Expr; @@ -7477,7 +7477,7 @@ ExprKind check_basic_directive_expr(CheckerContext *c, Operand *o, Ast *node, Ty return kind; } -ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; Operand cond = {Addressing_Invalid}; ast_node(te, TernaryIfExpr, node); @@ -7555,7 +7555,7 @@ ExprKind check_ternary_if_expr(CheckerContext *c, Operand *o, Ast *node, Type *t return kind; } -ExprKind check_ternary_when_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_ternary_when_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; Operand cond = {}; ast_node(te, TernaryWhenExpr, node); @@ -7582,7 +7582,7 @@ ExprKind check_ternary_when_expr(CheckerContext *c, Operand *o, Ast *node, Type return kind; } -ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(oe, OrElseExpr, node); String name = oe->token.string; @@ -7696,7 +7696,7 @@ ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type return Expr_Expr; } -ExprKind check_or_return_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_or_return_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(re, OrReturnExpr, node); String name = re->token.string; @@ -7775,7 +7775,7 @@ ExprKind check_or_return_expr(CheckerContext *c, Operand *o, Ast *node, Type *ty return Expr_Expr; } -ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; ast_node(cl, CompoundLit, node); @@ -8739,7 +8739,7 @@ ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *node, Type * return kind; } -ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; ast_node(ta, TypeAssertion, node); check_expr(c, o, ta->expr); @@ -8868,7 +8868,7 @@ ExprKind check_type_assertion(CheckerContext *c, Operand *o, Ast *node, Type *ty return kind; } -ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ast_node(se, SelectorCallExpr, node); // IMPORTANT NOTE(bill, 2020-05-22): This is a complete hack to get a shorthand which is extremely useful for vtables // COM APIs is a great example of where this kind of thing is extremely useful @@ -9016,7 +9016,7 @@ ExprKind check_selector_call_expr(CheckerContext *c, Operand *o, Ast *node, Type } -ExprKind check_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Expr; ast_node(ie, IndexExpr, node); check_expr(c, o, ie->expr); @@ -9140,7 +9140,7 @@ ExprKind check_index_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_h return kind; } -ExprKind check_slice_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_slice_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = Expr_Stmt; ast_node(se, SliceExpr, node); check_expr(c, o, se->expr); @@ -9328,7 +9328,7 @@ ExprKind check_slice_expr(CheckerContext *c, Operand *o, Ast *node, Type *type_h return kind; } -ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { u32 prev_state_flags = c->state_flags; defer (c->state_flags = prev_state_flags); if (node->state_flags != 0) { @@ -9755,7 +9755,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type -ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { +gb_internal ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hint) { ExprKind kind = check_expr_base_internal(c, o, node, type_hint); if (o->type != nullptr && core_type(o->type) == nullptr) { o->type = t_invalid; @@ -9777,7 +9777,7 @@ ExprKind check_expr_base(CheckerContext *c, Operand *o, Ast *node, Type *type_hi } -void check_multi_expr_or_type(CheckerContext *c, Operand *o, Ast *e) { +gb_internal void check_multi_expr_or_type(CheckerContext *c, Operand *o, Ast *e) { check_expr_base(c, o, e, nullptr); switch (o->mode) { default: @@ -9789,7 +9789,7 @@ void check_multi_expr_or_type(CheckerContext *c, Operand *o, Ast *e) { o->mode = Addressing_Invalid; } -void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { +gb_internal void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { check_expr_base(c, o, e, nullptr); switch (o->mode) { default: @@ -9804,7 +9804,7 @@ void check_multi_expr(CheckerContext *c, Operand *o, Ast *e) { o->mode = Addressing_Invalid; } -void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { +gb_internal void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { check_expr_base(c, o, e, type_hint); switch (o->mode) { default: @@ -9819,7 +9819,7 @@ void check_multi_expr_with_type_hint(CheckerContext *c, Operand *o, Ast *e, Type o->mode = Addressing_Invalid; } -void check_not_tuple(CheckerContext *c, Operand *o) { +gb_internal void check_not_tuple(CheckerContext *c, Operand *o) { if (o->mode == Addressing_Value) { // NOTE(bill): Tuples are not first class thus never named if (o->type->kind == Type_Tuple) { @@ -9832,13 +9832,13 @@ void check_not_tuple(CheckerContext *c, Operand *o) { } } -void check_expr(CheckerContext *c, Operand *o, Ast *e) { +gb_internal void check_expr(CheckerContext *c, Operand *o, Ast *e) { check_multi_expr(c, o, e); check_not_tuple(c, o); } -void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { +gb_internal void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) { check_expr_base(c, o, e, type_hint); check_not_tuple(c, o); error_operand_no_value(o); @@ -9846,7 +9846,7 @@ void check_expr_or_type(CheckerContext *c, Operand *o, Ast *e, Type *type_hint) -bool is_exact_value_zero(ExactValue const &v) { +gb_internal bool is_exact_value_zero(ExactValue const &v) { switch (v.kind) { case ExactValue_Invalid: return true; @@ -9910,9 +9910,9 @@ bool is_exact_value_zero(ExactValue const &v) { -gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); +gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthand); -gbString write_struct_fields_to_string(gbString str, Slice const ¶ms) { +gb_internal gbString write_struct_fields_to_string(gbString str, Slice const ¶ms) { for_array(i, params) { if (i > 0) { str = gb_string_appendc(str, ", "); @@ -9922,7 +9922,7 @@ gbString write_struct_fields_to_string(gbString str, Slice const ¶ms) return str; } -gbString string_append_string(gbString str, String string) { +gb_internal gbString string_append_string(gbString str, String string) { if (string.len > 0) { return gb_string_append_length(str, &string[0], string.len); } @@ -9930,13 +9930,13 @@ gbString string_append_string(gbString str, String string) { } -gbString string_append_token(gbString str, Token token) { +gb_internal gbString string_append_token(gbString str, Token token) { str = string_append_string(str, token.string); return str; } -gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) { +gb_internal gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) { if (node == nullptr) return str; @@ -10501,9 +10501,9 @@ gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) { return str; } -gbString expr_to_string(Ast *expression) { +gb_internal gbString expr_to_string(Ast *expression) { return write_expr_to_string(gb_string_make(heap_allocator(), ""), expression, false); } -gbString expr_to_string_shorthand(Ast *expression) { +gb_internal gbString expr_to_string_shorthand(Ast *expression) { return write_expr_to_string(gb_string_make(heap_allocator(), ""), expression, true); } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 3fe6699ea..cae9c3537 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1,4 +1,4 @@ -bool is_diverging_expr(Ast *expr) { +gb_internal bool is_diverging_expr(Ast *expr) { expr = unparen_expr(expr); if (expr->kind != Ast_CallExpr) { return false; @@ -23,14 +23,14 @@ bool is_diverging_expr(Ast *expr) { t = base_type(t); return t != nullptr && t->kind == Type_Proc && t->Proc.diverging; } -bool is_diverging_stmt(Ast *stmt) { +gb_internal bool is_diverging_stmt(Ast *stmt) { if (stmt->kind != Ast_ExprStmt) { return false; } return is_diverging_expr(stmt->ExprStmt.expr); } -bool contains_deferred_call(Ast *node) { +gb_internal bool contains_deferred_call(Ast *node) { if (node->viral_state_flags & ViralStateFlag_ContainsDeferredProcedure) { return true; } @@ -61,7 +61,7 @@ bool contains_deferred_call(Ast *node) { return false; } -void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) { +gb_internal void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) { if (stmts.count == 0) { return; } @@ -137,7 +137,7 @@ void check_stmt_list(CheckerContext *ctx, Slice const &stmts, u32 flags) } } -bool check_is_terminating_list(Slice const &stmts, String const &label) { +gb_internal bool check_is_terminating_list(Slice const &stmts, String const &label) { // Iterate backwards for (isize n = stmts.count-1; n >= 0; n--) { Ast *stmt = stmts[n]; @@ -155,7 +155,7 @@ bool check_is_terminating_list(Slice const &stmts, String const &label) { return false; } -bool check_has_break_list(Slice const &stmts, String const &label, bool implicit) { +gb_internal bool check_has_break_list(Slice const &stmts, String const &label, bool implicit) { for_array(i, stmts) { Ast *stmt = stmts[i]; if (check_has_break(stmt, label, implicit)) { @@ -166,7 +166,7 @@ bool check_has_break_list(Slice const &stmts, String const &label, bool i } -bool check_has_break(Ast *stmt, String const &label, bool implicit) { +gb_internal bool check_has_break(Ast *stmt, String const &label, bool implicit) { switch (stmt->kind) { case Ast_BranchStmt: if (stmt->BranchStmt.token.kind == Token_break) { @@ -225,7 +225,7 @@ bool check_has_break(Ast *stmt, String const &label, bool implicit) { // NOTE(bill): The last expression has to be a 'return' statement // TODO(bill): This is a mild hack and should be probably handled properly -bool check_is_terminating(Ast *node, String const &label) { +gb_internal bool check_is_terminating(Ast *node, String const &label) { switch (node->kind) { case_ast_node(rs, ReturnStmt, node); return true; @@ -327,7 +327,7 @@ bool check_is_terminating(Ast *node, String const &label) { -Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) { +gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) { if (rhs->mode == Addressing_Invalid) { return nullptr; } @@ -477,8 +477,8 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) } -void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags); -void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { +gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags); +gb_internal void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { u32 prev_state_flags = ctx->state_flags; if (node->state_flags != 0) { @@ -510,7 +510,7 @@ void check_stmt(CheckerContext *ctx, Ast *node, u32 flags) { } -void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { +gb_internal void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { Operand operand = {Addressing_Invalid}; check_expr(ctx, &operand, ws->cond); if (operand.mode != Addressing_Constant || !is_type_boolean(operand.type)) { @@ -539,7 +539,7 @@ void check_when_stmt(CheckerContext *ctx, AstWhenStmt *ws, u32 flags) { } } -void check_label(CheckerContext *ctx, Ast *label, Ast *parent) { +gb_internal void check_label(CheckerContext *ctx, Ast *label, Ast *parent) { if (label == nullptr) { return; } @@ -582,7 +582,7 @@ void check_label(CheckerContext *ctx, Ast *label, Ast *parent) { } // Returns 'true' for 'continue', 'false' for 'return' -bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, bool is_selector, Entity *e) { +gb_internal bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, bool is_selector, Entity *e) { if (e == nullptr) { if (is_blank_ident(expr)) { error(us->token, "'using' in a statement is not allowed with the blank identifier '_'"); @@ -704,7 +704,7 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b return true; } -void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { +gb_internal void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(irs, UnrollRangeStmt, node); check_open_scope(ctx, node); @@ -863,7 +863,7 @@ void check_inline_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { check_close_scope(ctx); } -void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { +gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, SwitchStmt, node); Operand x = {}; @@ -1092,7 +1092,7 @@ enum TypeSwitchKind { TypeSwitch_Any, }; -TypeSwitchKind check_valid_type_switch_type(Type *type) { +gb_internal TypeSwitchKind check_valid_type_switch_type(Type *type) { type = type_deref(type); if (is_type_union(type)) { return TypeSwitch_Union; @@ -1103,7 +1103,7 @@ TypeSwitchKind check_valid_type_switch_type(Type *type) { return TypeSwitch_Invalid; } -void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { +gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { ast_node(ss, TypeSwitchStmt, node); Operand x = {}; @@ -1318,7 +1318,7 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { } } -void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { +gb_internal void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { if (body->kind != Ast_BlockStmt) { return; } @@ -1377,7 +1377,7 @@ void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { } } -bool all_operands_valid(Array const &operands) { +gb_internal bool all_operands_valid(Array const &operands) { if (any_errors()) { for_array(i, operands) { if (operands[i].type == t_invalid) { @@ -1388,7 +1388,7 @@ bool all_operands_valid(Array const &operands) { return true; } -bool check_stmt_internal_builtin_proc_id(Ast *expr, BuiltinProcId *id_) { +gb_internal bool check_stmt_internal_builtin_proc_id(Ast *expr, BuiltinProcId *id_) { BuiltinProcId id = BuiltinProc_Invalid; Entity *e = entity_of_node(expr); if (e != nullptr && e->kind == Entity_Builtin) { @@ -1400,7 +1400,7 @@ bool check_stmt_internal_builtin_proc_id(Ast *expr, BuiltinProcId *id_) { return id != BuiltinProc_Invalid; } -bool check_expr_is_stack_variable(Ast *expr) { +gb_internal bool check_expr_is_stack_variable(Ast *expr) { /* expr = unparen_expr(expr); Entity *e = entity_of_node(expr); @@ -1419,7 +1419,7 @@ bool check_expr_is_stack_variable(Ast *expr) { return false; } -void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { +gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { u32 mod_flags = flags & (~Stmt_FallthroughAllowed); switch (node->kind) { case_ast_node(_, EmptyStmt, node); case_end; diff --git a/src/check_type.cpp b/src/check_type.cpp index 62ca19c57..4634e1fbe 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1,6 +1,6 @@ -ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location); +gb_internal ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location); -void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field, Type *t, String name, i32 idx) { +gb_internal void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field, Type *t, String name, i32 idx) { t = base_type(t); GB_ASSERT(t->kind == Type_Array); Entity *e = scope_lookup_current(ctx->scope, name); @@ -27,7 +27,7 @@ void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field, } } -void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field, Type *t) { +gb_internal void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field, Type *t) { if (t == nullptr) { return; } @@ -81,7 +81,7 @@ void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field } } -bool does_field_type_allow_using(Type *t) { +gb_internal bool does_field_type_allow_using(Type *t) { t = base_type(t); if (is_type_struct(t)) { return true; @@ -91,8 +91,8 @@ bool does_field_type_allow_using(Type *t) { return false; } -void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields, String **tags, Slice const ¶ms, - isize init_field_capacity, Type *struct_type, String context) { +gb_internal void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields, String **tags, Slice const ¶ms, + isize init_field_capacity, Type *struct_type, String context) { auto fields_array = array_make(heap_allocator(), 0, init_field_capacity); auto tags_array = array_make(heap_allocator(), 0, init_field_capacity); @@ -219,7 +219,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice *fields } -bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { +gb_internal bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { GB_ASSERT(align_ != nullptr); Operand o = {}; check_expr(ctx, &o, node); @@ -256,7 +256,7 @@ bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { } -Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure) { +gb_internal Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, isize param_count, Array const &ordered_operands, bool *failure) { mutex_lock(&ctx->info->gen_types_mutex); defer (mutex_unlock(&ctx->info->gen_types_mutex)); @@ -320,7 +320,7 @@ Entity *find_polymorphic_record_entity(CheckerContext *ctx, Type *original_type, } -void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_type, Type *original_type) { +gb_internal void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_type, Type *original_type) { GB_ASSERT(is_type_named(named_type)); gbAllocator a = heap_allocator(); Scope *s = ctx->scope->parent; @@ -358,10 +358,10 @@ void add_polymorphic_record_entity(CheckerContext *ctx, Ast *node, Type *named_t mutex_unlock(&ctx->info->gen_types_mutex); } -Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params, - bool *is_polymorphic_, - Ast *node, Array *poly_operands, - Type *named_type, Type *original_type_for_poly) { +gb_internal Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_params, + bool *is_polymorphic_, + Ast *node, Array *poly_operands, + Type *named_type, Type *original_type_for_poly) { Type *polymorphic_params_type = nullptr; bool can_check_fields = true; GB_ASSERT(is_polymorphic_ != nullptr); @@ -540,7 +540,7 @@ Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_para return polymorphic_params_type; } -bool check_record_poly_operand_specialization(CheckerContext *ctx, Type *record_type, Array *poly_operands, bool *is_polymorphic_) { +gb_internal bool check_record_poly_operand_specialization(CheckerContext *ctx, Type *record_type, Array *poly_operands, bool *is_polymorphic_) { if (poly_operands == nullptr) { return false; } @@ -569,7 +569,7 @@ bool check_record_poly_operand_specialization(CheckerContext *ctx, Type *record_ } -void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { +gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { GB_ASSERT(is_type_struct(struct_type)); ast_node(st, StructType, node); @@ -626,7 +626,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array< } } } -void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { +gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array *poly_operands, Type *named_type, Type *original_type_for_poly) { GB_ASSERT(is_type_union(union_type)); ast_node(ut, UnionType, node); @@ -709,7 +709,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, ArrayEnum.max_value_index = max_value_index; } -bool is_type_valid_bit_set_range(Type *t) { +gb_internal bool is_type_valid_bit_set_range(Type *t) { if (is_type_integer(t)) { return true; } @@ -861,7 +861,7 @@ bool is_type_valid_bit_set_range(Type *t) { return false; } -void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *node) { +gb_internal void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *node) { ast_node(bs, BitSetType, node); GB_ASSERT(type->kind == Type_BitSet); type->BitSet.node = node; @@ -1102,7 +1102,7 @@ void check_bit_set_type(CheckerContext *c, Type *type, Type *named_type, Ast *no } -bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Type *type, bool compound, bool modify_type) { +gb_internal bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Type *type, bool compound, bool modify_type) { if (type == nullptr || type == t_invalid) { return true; @@ -1229,7 +1229,7 @@ bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Typ } -Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Operand const &operand) { +gb_internal Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Operand const &operand) { bool modify_type = !ctx->no_polymorphic_errors; bool show_error = modify_type && !ctx->hide_polymorphic_errors; if (!is_operand_value(operand)) { @@ -1256,7 +1256,7 @@ Type *determine_type_from_polymorphic(CheckerContext *ctx, Type *poly_type, Oper return t_invalid; } -bool is_expr_from_a_parameter(CheckerContext *ctx, Ast *expr) { +gb_internal bool is_expr_from_a_parameter(CheckerContext *ctx, Ast *expr) { if (expr == nullptr) { return false; } @@ -1275,7 +1275,7 @@ bool is_expr_from_a_parameter(CheckerContext *ctx, Ast *expr) { } -ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location) { +gb_internal ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type **out_type_, Ast *expr, bool allow_caller_location) { ParameterValue param_value = {}; param_value.original_ast_expr = expr; if (expr == nullptr) { @@ -1370,7 +1370,7 @@ ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type * } -Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is_variadic_, isize *variadic_index_, bool *success_, isize *specialization_count_, Array *operands) { +gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is_variadic_, isize *variadic_index_, bool *success_, isize *specialization_count_, Array *operands) { if (_params == nullptr) { return nullptr; } @@ -1814,7 +1814,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is return tuple; } -Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { +gb_internal Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { if (_results == nullptr) { return nullptr; } @@ -1928,7 +1928,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) { // NOTE(bill): 'operands' is for generating non generic procedure type -bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array *operands) { +gb_internal bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, Array *operands) { ast_node(pt, ProcType, proc_type_node); if (ctx->polymorphic_scope == nullptr && ctx->allow_polymorphic_types) { @@ -2084,7 +2084,7 @@ bool check_procedure_type(CheckerContext *ctx, Type *type, Ast *proc_type_node, } -i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { +gb_internal i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { if (e == nullptr) { return 0; } @@ -2169,7 +2169,7 @@ i64 check_array_count(CheckerContext *ctx, Operand *o, Ast *e) { return 0; } -Type *make_optional_ok_type(Type *value, bool typed) { +gb_internal Type *make_optional_ok_type(Type *value, bool typed) { gbAllocator a = permanent_allocator(); Type *t = alloc_type_tuple(); slice_init(&t->Tuple.variables, a, 2); @@ -2185,7 +2185,7 @@ enum : i64 { MAP_CACHE_LINE_SIZE = 1 << MAP_CACHE_LINE_LOG2 }; GB_STATIC_ASSERT(MAP_CACHE_LINE_SIZE >= 64); -void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) { +gb_internal void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) { i64 elem_sz = type_size_of(type); i64 len = 1; @@ -2197,7 +2197,7 @@ void map_cell_size_and_len(Type *type, i64 *size_, i64 *len_) { if (len_) *len_ = len; } -void init_map_internal_types(Type *type) { +gb_internal void init_map_internal_types(Type *type) { GB_ASSERT(type->kind == Type_Map); GB_ASSERT(t_allocator != nullptr); if (type->Map.lookup_result_type != nullptr) return; @@ -2210,7 +2210,7 @@ void init_map_internal_types(Type *type) { type->Map.lookup_result_type = make_optional_ok_type(value); } -void add_map_key_type_dependencies(CheckerContext *ctx, Type *key) { +gb_internal void add_map_key_type_dependencies(CheckerContext *ctx, Type *key) { key = core_type(key); if (is_type_cstring(key)) { @@ -2249,7 +2249,7 @@ void add_map_key_type_dependencies(CheckerContext *ctx, Type *key) { } } -void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { +gb_internal void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { GB_ASSERT(type->kind == Type_Map); ast_node(mt, MapType, node); @@ -2282,7 +2282,7 @@ void check_map_type(CheckerContext *ctx, Type *type, Ast *node) { // error(node, "'map' types are not yet implemented"); } -void check_matrix_type(CheckerContext *ctx, Type **type, Ast *node) { +gb_internal void check_matrix_type(CheckerContext *ctx, Type **type, Ast *node) { ast_node(mt, MatrixType, node); Operand row = {}; @@ -2346,7 +2346,7 @@ type_assign:; -Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type, StructSoaKind soa_kind) { +gb_internal Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type, StructSoaKind soa_kind) { Type *bt_elem = base_type(elem); bool is_polymorphic = is_type_polymorphic(elem); @@ -2501,20 +2501,20 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el } -Type *make_soa_struct_fixed(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type) { +gb_internal Type *make_soa_struct_fixed(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem, i64 count, Type *generic_type) { return make_soa_struct_internal(ctx, array_typ_expr, elem_expr, elem, count, generic_type, StructSoa_Fixed); } -Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { +gb_internal Type *make_soa_struct_slice(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { return make_soa_struct_internal(ctx, array_typ_expr, elem_expr, elem, -1, nullptr, StructSoa_Slice); } -Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { +gb_internal Type *make_soa_struct_dynamic_array(CheckerContext *ctx, Ast *array_typ_expr, Ast *elem_expr, Type *elem) { return make_soa_struct_internal(ctx, array_typ_expr, elem_expr, elem, -1, nullptr, StructSoa_Dynamic); } -bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_type) { +gb_internal bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_type) { GB_ASSERT_NOT_NULL(type); if (e == nullptr) { *type = t_invalid; @@ -2997,7 +2997,7 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t return false; } -Type *check_type(CheckerContext *ctx, Ast *e) { +gb_internal Type *check_type(CheckerContext *ctx, Ast *e) { CheckerContext c = *ctx; c.type_path = new_checker_type_path(); defer (destroy_checker_type_path(c.type_path)); @@ -3005,7 +3005,7 @@ Type *check_type(CheckerContext *ctx, Ast *e) { return check_type_expr(&c, e, nullptr); } -Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type) { +gb_internal Type *check_type_expr(CheckerContext *ctx, Ast *e, Type *named_type) { Type *type = nullptr; bool ok = check_type_internal(ctx, e, &type, named_type); diff --git a/src/checker.cpp b/src/checker.cpp index d5222f615..e2c430dc2 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1,12 +1,12 @@ #include "entity.cpp" #include "types.cpp" -void check_expr(CheckerContext *c, Operand *operand, Ast *expression); -void check_expr_or_type(CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint=nullptr); -void add_comparison_procedures_for_fields(CheckerContext *c, Type *t); -Type *check_type(CheckerContext *ctx, Ast *e); +gb_internal void check_expr(CheckerContext *c, Operand *operand, Ast *expression); +gb_internal void check_expr_or_type(CheckerContext *c, Operand *operand, Ast *expression, Type *type_hint=nullptr); +gb_internal void add_comparison_procedures_for_fields(CheckerContext *c, Type *t); +gb_internal Type *check_type(CheckerContext *ctx, Ast *e); -bool is_operand_value(Operand o) { +gb_internal bool is_operand_value(Operand o) { switch (o.mode) { case Addressing_Value: case Addressing_Context: @@ -22,14 +22,14 @@ bool is_operand_value(Operand o) { } return false; } -bool is_operand_nil(Operand o) { +gb_internal bool is_operand_nil(Operand o) { return o.mode == Addressing_Value && o.type == t_untyped_nil; } -bool is_operand_undef(Operand o) { +gb_internal bool is_operand_undef(Operand o) { return o.mode == Addressing_Value && o.type == t_untyped_undef; } -bool check_rtti_type_disallowed(Token const &token, Type *type, char const *format) { +gb_internal bool check_rtti_type_disallowed(Token const &token, Type *type, char const *format) { if (build_context.disallow_rtti && type) { if (is_type_any(type)) { gbString t = type_to_string(type); @@ -41,12 +41,12 @@ bool check_rtti_type_disallowed(Token const &token, Type *type, char const *form return false; } -bool check_rtti_type_disallowed(Ast *expr, Type *type, char const *format) { +gb_internal bool check_rtti_type_disallowed(Ast *expr, Type *type, char const *format) { GB_ASSERT(expr != nullptr); return check_rtti_type_disallowed(ast_token(expr), type, format); } -void scope_reset(Scope *scope) { +gb_internal void scope_reset(Scope *scope) { if (scope == nullptr) return; scope->head_child.store(nullptr, std::memory_order_relaxed); @@ -54,14 +54,14 @@ void scope_reset(Scope *scope) { ptr_set_clear(&scope->imported); } -void scope_reserve(Scope *scope, isize capacity) { +gb_internal void scope_reserve(Scope *scope, isize capacity) { isize cap = 2*capacity; if (cap > scope->elements.hashes.count) { string_map_rehash(&scope->elements, capacity); } } -i32 is_scope_an_ancestor(Scope *parent, Scope *child) { +gb_internal i32 is_scope_an_ancestor(Scope *parent, Scope *child) { i32 i = 0; while (child != nullptr) { if (parent == child) { @@ -73,35 +73,35 @@ i32 is_scope_an_ancestor(Scope *parent, Scope *child) { return -1; } -void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { +gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); } } -void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNode *n) { +gb_internal void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNode *n) { if (s->hashes.data == nullptr) { ptr_set_init(s, heap_allocator()); } ptr_set_add(s, n); } -bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { +gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { return ptr_set_exists(s, n); } -void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { +gb_internal void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { ptr_set_remove(s, n); } -void entity_graph_node_destroy(EntityGraphNode *n, gbAllocator a) { +gb_internal void entity_graph_node_destroy(EntityGraphNode *n, gbAllocator a) { entity_graph_node_set_destroy(&n->pred); entity_graph_node_set_destroy(&n->succ); gb_free(a, n); } -int entity_graph_node_cmp(EntityGraphNode **data, isize i, isize j) { +gb_internal int entity_graph_node_cmp(EntityGraphNode **data, isize i, isize j) { EntityGraphNode *x = data[i]; EntityGraphNode *y = data[j]; u64 a = x->entity->order_in_src; @@ -115,7 +115,7 @@ int entity_graph_node_cmp(EntityGraphNode **data, isize i, isize j) { return +1; } -void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) { +gb_internal void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) { EntityGraphNode *x = data[i]; EntityGraphNode *y = data[j]; data[i] = y; @@ -126,42 +126,42 @@ void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) { -void import_graph_node_set_destroy(ImportGraphNodeSet *s) { +gb_internal void import_graph_node_set_destroy(ImportGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); } } -void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) { +gb_internal void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) { if (s->hashes.data == nullptr) { ptr_set_init(s, heap_allocator()); } ptr_set_add(s, n); } -bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { +gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { return ptr_set_exists(s, n); } -void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { +gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { ptr_set_remove(s, n); } -ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { +gb_internal ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode); n->pkg = pkg; n->scope = pkg->scope; return n; } -void import_graph_node_destroy(ImportGraphNode *n, gbAllocator a) { +gb_internal void import_graph_node_destroy(ImportGraphNode *n, gbAllocator a) { import_graph_node_set_destroy(&n->pred); import_graph_node_set_destroy(&n->succ); gb_free(a, n); } -int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) { +gb_internal int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) { ImportGraphNode *x = data[i]; ImportGraphNode *y = data[j]; GB_ASSERT(x != y); @@ -177,7 +177,7 @@ int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) { return 0; } -void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { +gb_internal void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { ImportGraphNode *x = data[i]; ImportGraphNode *y = data[j]; data[i] = y; @@ -186,7 +186,7 @@ void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) { y->index = i; } -GB_COMPARE_PROC(ast_node_cmp) { +gb_internal GB_COMPARE_PROC(ast_node_cmp) { Ast *x = *cast(Ast **)a; Ast *y = *cast(Ast **)b; Token i = ast_token(x); @@ -199,7 +199,7 @@ GB_COMPARE_PROC(ast_node_cmp) { -void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { +gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { d->parent = parent; d->scope = scope; ptr_set_init(&d->deps, heap_allocator()); @@ -207,18 +207,18 @@ void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { array_init (&d->labels, heap_allocator()); } -DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { +gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { DeclInfo *d = gb_alloc_item(permanent_allocator(), DeclInfo); init_decl_info(d, scope, parent); return d; } -void destroy_declaration_info(DeclInfo *d) { +gb_internal void destroy_declaration_info(DeclInfo *d) { ptr_set_destroy(&d->deps); array_free(&d->labels); } -bool decl_info_has_init(DeclInfo *d) { +gb_internal bool decl_info_has_init(DeclInfo *d) { if (d->init_expr != nullptr) { return true; } @@ -239,7 +239,7 @@ bool decl_info_has_init(DeclInfo *d) { -Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capacity=DEFAULT_SCOPE_CAPACITY) { +gb_internal Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capacity=DEFAULT_SCOPE_CAPACITY) { Scope *s = gb_alloc_item(permanent_allocator(), Scope); s->parent = parent; string_map_init(&s->elements, heap_allocator(), init_elements_capacity); @@ -260,7 +260,7 @@ Scope *create_scope(CheckerInfo *info, Scope *parent, isize init_elements_capaci return s; } -Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { +gb_internal Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { GB_ASSERT(f != nullptr); GB_ASSERT(f->pkg != nullptr); GB_ASSERT(f->pkg->scope != nullptr); @@ -276,7 +276,7 @@ Scope *create_scope_from_file(CheckerInfo *info, AstFile *f) { return s; } -Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { +gb_internal Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { GB_ASSERT(pkg != nullptr); isize total_pkg_decl_count = 0; @@ -307,7 +307,7 @@ Scope *create_scope_from_package(CheckerContext *c, AstPackage *pkg) { return s; } -void destroy_scope(Scope *scope) { +gb_internal void destroy_scope(Scope *scope) { for (auto const &entry : scope->elements) { Entity *e = entry.value; if (e->kind == Entity_Variable) { @@ -331,7 +331,7 @@ void destroy_scope(Scope *scope) { } -void add_scope(CheckerContext *c, Ast *node, Scope *scope) { +gb_internal void add_scope(CheckerContext *c, Ast *node, Scope *scope) { GB_ASSERT(node != nullptr); GB_ASSERT(scope != nullptr); scope->node = node; @@ -352,7 +352,7 @@ void add_scope(CheckerContext *c, Ast *node, Scope *scope) { } } -Scope *scope_of_node(Ast *node) { +gb_internal Scope *scope_of_node(Ast *node) { if (node == nullptr) { return nullptr; } @@ -375,7 +375,7 @@ Scope *scope_of_node(Ast *node) { } -void check_open_scope(CheckerContext *c, Ast *node) { +gb_internal void check_open_scope(CheckerContext *c, Ast *node) { node = unparen_expr(node); GB_ASSERT(node->kind == Ast_Invalid || is_ast_stmt(node) || @@ -397,12 +397,12 @@ void check_open_scope(CheckerContext *c, Ast *node) { c->state_flags |= StateFlag_bounds_check; } -void check_close_scope(CheckerContext *c) { +gb_internal void check_close_scope(CheckerContext *c) { c->scope = c->scope->parent; } -Entity *scope_lookup_current(Scope *s, String const &name) { +gb_internal Entity *scope_lookup_current(Scope *s, String const &name) { Entity **found = string_map_get(&s->elements, name); if (found) { return *found; @@ -410,7 +410,7 @@ Entity *scope_lookup_current(Scope *s, String const &name) { return nullptr; } -void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entity **entity_) { +gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entity **entity_) { if (scope != nullptr) { bool gone_thru_proc = false; bool gone_thru_package = false; @@ -455,7 +455,7 @@ void scope_lookup_parent(Scope *scope, String const &name, Scope **scope_, Entit if (scope_) *scope_ = nullptr; } -Entity *scope_lookup(Scope *s, String const &name) { +gb_internal Entity *scope_lookup(Scope *s, String const &name) { Entity *entity = nullptr; scope_lookup_parent(s, name, nullptr, &entity); return entity; @@ -463,7 +463,7 @@ Entity *scope_lookup(Scope *s, String const &name) { -Entity *scope_insert_with_name(Scope *s, String const &name, Entity *entity, bool use_mutex=true) { +gb_internal Entity *scope_insert_with_name(Scope *s, String const &name, Entity *entity, bool use_mutex=true) { if (name == "") { return nullptr; } @@ -502,7 +502,7 @@ end:; return result; } -Entity *scope_insert(Scope *s, Entity *entity, bool use_mutex) { +gb_internal Entity *scope_insert(Scope *s, Entity *entity, bool use_mutex) { String name = entity->token.string; return scope_insert_with_name(s, name, entity, use_mutex); } @@ -528,14 +528,14 @@ struct VettedEntity { Entity *entity; Entity *other; }; -void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { +gb_internal void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { ve->kind = kind; ve->entity = entity; ve->other = other; } -GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { +gb_internal GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { Entity *x = (cast(VettedEntity *)a)->entity; Entity *y = (cast(VettedEntity *)b)->entity; GB_ASSERT(x != nullptr); @@ -544,7 +544,7 @@ GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { return token_pos_cmp(x->token.pos, y->token.pos); } -bool check_vet_shadowing_assignment(Checker *c, Entity *shadowed, Ast *expr) { +gb_internal bool check_vet_shadowing_assignment(Checker *c, Entity *shadowed, Ast *expr) { Ast *init = unparen_expr(expr); if (init == nullptr) { return false; @@ -568,7 +568,7 @@ bool check_vet_shadowing_assignment(Checker *c, Entity *shadowed, Ast *expr) { } -bool check_vet_shadowing(Checker *c, Entity *e, VettedEntity *ve) { +gb_internal bool check_vet_shadowing(Checker *c, Entity *e, VettedEntity *ve) { if (e->kind != Entity_Variable) { return false; } @@ -634,7 +634,7 @@ bool check_vet_shadowing(Checker *c, Entity *e, VettedEntity *ve) { return true; } -bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) { +gb_internal bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) { if ((e->flags&EntityFlag_Used) == 0) { switch (e->kind) { case Entity_Variable: @@ -652,7 +652,7 @@ bool check_vet_unused(Checker *c, Entity *e, VettedEntity *ve) { return false; } -void check_scope_usage(Checker *c, Scope *scope) { +gb_internal void check_scope_usage(Checker *c, Scope *scope) { bool vet_unused = true; bool vet_shadowing = true; @@ -728,12 +728,12 @@ void check_scope_usage(Checker *c, Scope *scope) { } -void add_dependency(CheckerInfo *info, DeclInfo *d, Entity *e) { +gb_internal void add_dependency(CheckerInfo *info, DeclInfo *d, Entity *e) { mutex_lock(&info->deps_mutex); ptr_set_add(&d->deps, e); mutex_unlock(&info->deps_mutex); } -void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool require_mutex) { +gb_internal void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool require_mutex) { if (d == nullptr) { return; } @@ -746,7 +746,7 @@ void add_type_info_dependency(CheckerInfo *info, DeclInfo *d, Type *type, bool r } } -AstPackage *get_core_package(CheckerInfo *info, String name) { +gb_internal AstPackage *get_core_package(CheckerInfo *info, String name) { gbAllocator a = heap_allocator(); String path = get_fullpath_core(a, name); defer (gb_free(a, path.text)); @@ -764,7 +764,7 @@ AstPackage *get_core_package(CheckerInfo *info, String name) { } -void add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { +gb_internal void add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { String n = make_string_c(name); AstPackage *p = get_core_package(&c->checker->info, make_string_c(package_name)); Entity *e = scope_lookup(p->scope, n); @@ -774,7 +774,7 @@ void add_package_dependency(CheckerContext *c, char const *package_name, char co add_dependency(c->info, c->decl, e); } -void try_to_add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { +gb_internal void try_to_add_package_dependency(CheckerContext *c, char const *package_name, char const *name) { String n = make_string_c(name); AstPackage *p = get_core_package(&c->checker->info, make_string_c(package_name)); Entity *e = scope_lookup(p->scope, n); @@ -787,7 +787,7 @@ void try_to_add_package_dependency(CheckerContext *c, char const *package_name, } -void add_declaration_dependency(CheckerContext *c, Entity *e) { +gb_internal void add_declaration_dependency(CheckerContext *c, Entity *e) { if (e == nullptr) { return; } @@ -797,7 +797,7 @@ void add_declaration_dependency(CheckerContext *c, Entity *e) { } -Entity *add_global_entity(Entity *entity, Scope *scope=builtin_pkg->scope) { +gb_internal Entity *add_global_entity(Entity *entity, Scope *scope=builtin_pkg->scope) { String name = entity->token.string; defer (entity->state = EntityState_Resolved); @@ -810,27 +810,27 @@ Entity *add_global_entity(Entity *entity, Scope *scope=builtin_pkg->scope) { return entity; } -void add_global_constant(char const *name, Type *type, ExactValue value) { +gb_internal void add_global_constant(char const *name, Type *type, ExactValue value) { Entity *entity = alloc_entity(Entity_Constant, nullptr, make_token_ident(name), type); entity->Constant.value = value; add_global_entity(entity); } -void add_global_string_constant(char const *name, String const &value) { +gb_internal void add_global_string_constant(char const *name, String const &value) { add_global_constant(name, t_untyped_string, exact_value_string(value)); } -void add_global_bool_constant(char const *name, bool value) { +gb_internal void add_global_bool_constant(char const *name, bool value) { add_global_constant(name, t_untyped_bool, exact_value_bool(value)); } -void add_global_type_entity(String name, Type *type) { +gb_internal void add_global_type_entity(String name, Type *type) { add_global_entity(alloc_entity_type_name(nullptr, make_token_ident(name), type)); } -AstPackage *create_builtin_package(char const *name) { +gb_internal AstPackage *create_builtin_package(char const *name) { gbAllocator a = permanent_allocator(); AstPackage *pkg = gb_alloc_item(a, AstPackage); pkg->name = make_string_c(name); @@ -847,7 +847,7 @@ struct GlobalEnumValue { i64 value; }; -Slice add_global_enum_type(String const &type_name, GlobalEnumValue *values, isize value_count, Type **enum_type_ = nullptr) { +gb_internal Slice add_global_enum_type(String const &type_name, GlobalEnumValue *values, isize value_count, Type **enum_type_ = nullptr) { Scope *scope = create_scope(nullptr, builtin_pkg->scope); Entity *entity = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved); @@ -882,7 +882,7 @@ Slice add_global_enum_type(String const &type_name, GlobalEnumValue *v return slice_from_array(fields); } -void add_global_enum_constant(Slice const &fields, char const *name, i64 value) { +gb_internal void add_global_enum_constant(Slice const &fields, char const *name, i64 value) { for (Entity *field : fields) { GB_ASSERT(field->kind == Entity_Constant); if (value == exact_value_to_i64(field->Constant.value)) { @@ -893,7 +893,7 @@ void add_global_enum_constant(Slice const &fields, char const *name, i GB_PANIC("Unfound enum value for global constant: %s %lld", name, cast(long long)value); } -Type *add_global_type_name(Scope *scope, String const &type_name, Type *backing_type) { +gb_internal Type *add_global_type_name(Scope *scope, String const &type_name, Type *backing_type) { Entity *e = alloc_entity_type_name(scope, make_token_ident(type_name), nullptr, EntityState_Resolved); Type *named_type = alloc_type_named(type_name, backing_type, e); e->type = named_type; @@ -905,7 +905,7 @@ Type *add_global_type_name(Scope *scope, String const &type_name, Type *backing_ } -void init_universal(void) { +gb_internal void init_universal(void) { BuildContext *bc = &build_context; builtin_pkg = create_builtin_package("builtin"); @@ -1122,7 +1122,7 @@ void init_universal(void) { -void init_checker_info(CheckerInfo *i) { +gb_internal void init_checker_info(CheckerInfo *i) { gbAllocator a = heap_allocator(); TIME_SECTION("checker info: general"); @@ -1180,7 +1180,7 @@ void init_checker_info(CheckerInfo *i) { string_map_init(&i->load_file_cache, a); } -void destroy_checker_info(CheckerInfo *i) { +gb_internal void destroy_checker_info(CheckerInfo *i) { array_free(&i->definitions); array_free(&i->entities); map_destroy(&i->global_untyped); @@ -1217,7 +1217,7 @@ void destroy_checker_info(CheckerInfo *i) { string_map_destroy(&i->load_file_cache); } -CheckerContext make_checker_context(Checker *c) { +gb_internal CheckerContext make_checker_context(Checker *c) { CheckerContext ctx = {}; ctx.checker = c; ctx.info = &c->info; @@ -1230,12 +1230,12 @@ CheckerContext make_checker_context(Checker *c) { ctx.poly_level = 0; return ctx; } -void destroy_checker_context(CheckerContext *ctx) { +gb_internal void destroy_checker_context(CheckerContext *ctx) { destroy_checker_type_path(ctx->type_path); destroy_checker_poly_path(ctx->poly_path); } -void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { +gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { if (file != nullptr) { ctx->file = file; ctx->decl = file->pkg->decl_info; @@ -1243,7 +1243,7 @@ void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { ctx->pkg = file->pkg; } } -void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMap *untyped) { +gb_internal void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMap *untyped) { if (ctx == nullptr) { return; } @@ -1258,7 +1258,7 @@ void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMa -void init_checker(Checker *c) { +gb_internal void init_checker(Checker *c) { gbAllocator a = heap_allocator(); TIME_SECTION("init checker info"); @@ -1278,7 +1278,7 @@ void init_checker(Checker *c) { c->builtin_ctx = make_checker_context(c); } -void destroy_checker(Checker *c) { +gb_internal void destroy_checker(Checker *c) { destroy_checker_info(&c->info); destroy_checker_context(&c->builtin_ctx); @@ -1290,7 +1290,7 @@ void destroy_checker(Checker *c) { } -TypeAndValue type_and_value_of_expr(Ast *expr) { +gb_internal TypeAndValue type_and_value_of_expr(Ast *expr) { TypeAndValue tav = {}; if (expr != nullptr) { tav = expr->tav; @@ -1298,7 +1298,7 @@ TypeAndValue type_and_value_of_expr(Ast *expr) { return tav; } -Type *type_of_expr(Ast *expr) { +gb_internal Type *type_of_expr(Ast *expr) { TypeAndValue tav = expr->tav; if (tav.mode != Addressing_Invalid) { return tav.type; @@ -1313,14 +1313,14 @@ Type *type_of_expr(Ast *expr) { return nullptr; } -Entity *implicit_entity_of_node(Ast *clause) { +gb_internal Entity *implicit_entity_of_node(Ast *clause) { if (clause != nullptr && clause->kind == Ast_CaseClause) { return clause->CaseClause.implicit_entity; } return nullptr; } -Entity *entity_of_node(Ast *expr) { +gb_internal Entity *entity_of_node(Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case_ast_node(ident, Ident, expr); @@ -1341,25 +1341,25 @@ Entity *entity_of_node(Ast *expr) { return nullptr; } -DeclInfo *decl_info_of_entity(Entity *e) { +gb_internal DeclInfo *decl_info_of_entity(Entity *e) { if (e != nullptr) { return e->decl_info; } return nullptr; } -DeclInfo *decl_info_of_ident(Ast *ident) { +gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { return decl_info_of_entity(entity_of_node(ident)); } -AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { +gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { AstFile **found = string_map_get(&i->files, filename); if (found != nullptr) { return *found; } return nullptr; } -ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { +gb_internal ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { if (c->untyped != nullptr) { ExprInfo **found = map_get(c->untyped, expr); if (found) { @@ -1377,7 +1377,7 @@ ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { } } -void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { +gb_internal void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { if (c->untyped != nullptr) { map_set(c->untyped, expr, make_expr_info(mode, type, value, false)); } else { @@ -1387,7 +1387,7 @@ void check_set_expr_info(CheckerContext *c, Ast *expr, AddressingMode mode, Type } } -void check_remove_expr_info(CheckerContext *c, Ast *e) { +gb_internal void check_remove_expr_info(CheckerContext *c, Ast *e) { if (c->untyped != nullptr) { map_remove(c->untyped, e); GB_ASSERT(map_get(c->untyped, e) == nullptr); @@ -1401,7 +1401,7 @@ void check_remove_expr_info(CheckerContext *c, Ast *e) { } -isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { +gb_internal isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { type = default_type(type); if (type == t_llvm_bool) { type = t_bool; @@ -1436,7 +1436,7 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { } -void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { +gb_internal void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { if (expr == nullptr) { return; } @@ -1453,7 +1453,7 @@ void add_untyped(CheckerContext *c, Ast *expr, AddressingMode mode, Type *type, check_set_expr_info(c, expr, mode, type, value); } -void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { +gb_internal void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *type, ExactValue value) { if (expr == nullptr) { return; } @@ -1489,7 +1489,7 @@ void add_type_and_value(CheckerInfo *i, Ast *expr, AddressingMode mode, Type *ty mutex_unlock(&i->type_and_value_mutex); } -void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { +gb_internal void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { GB_ASSERT(identifier != nullptr); GB_ASSERT(identifier->kind == Ast_Ident); // if (is_blank_ident(identifier)) { @@ -1505,7 +1505,7 @@ void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) { mpmc_enqueue(&i->definition_queue, entity); } -bool redeclaration_error(String name, Entity *prev, Entity *found) { +gb_internal bool redeclaration_error(String name, Entity *prev, Entity *found) { TokenPos pos = found->token.pos; Entity *up = found->using_parent; if (up != nullptr) { @@ -1548,7 +1548,7 @@ bool redeclaration_error(String name, Entity *prev, Entity *found) { return false; } -void add_entity_flags_from_file(CheckerContext *c, Entity *e, Scope *scope) { +gb_internal void add_entity_flags_from_file(CheckerContext *c, Entity *e, Scope *scope) { if (c->file != nullptr && (c->file->flags & AstFile_IsLazy) != 0 && scope->flags & ScopeFlag_File) { AstPackage *pkg = c->file->pkg; if (pkg->kind == Package_Init && e->kind == Entity_Procedure && e->token.string == "main") { @@ -1561,7 +1561,7 @@ void add_entity_flags_from_file(CheckerContext *c, Entity *e, Scope *scope) { } } -bool add_entity_with_name(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity, String name) { +gb_internal bool add_entity_with_name(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity, String name) { if (scope == nullptr) { return false; } @@ -1581,11 +1581,11 @@ bool add_entity_with_name(CheckerContext *c, Scope *scope, Ast *identifier, Enti } return true; } -bool add_entity(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity) { +gb_internal bool add_entity(CheckerContext *c, Scope *scope, Ast *identifier, Entity *entity) { return add_entity_with_name(c, scope, identifier, entity, entity->token.string); } -void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { +gb_internal void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { if (entity == nullptr) { return; } @@ -1622,7 +1622,7 @@ void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) { } -bool could_entity_be_lazy(Entity *e, DeclInfo *d) { +gb_internal bool could_entity_be_lazy(Entity *e, DeclInfo *d) { if ((e->flags & EntityFlag_Lazy) == 0) { return false; } @@ -1673,7 +1673,7 @@ bool could_entity_be_lazy(Entity *e, DeclInfo *d) { return true; } -void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported) { +gb_internal void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, DeclInfo *d, bool is_exported) { if (identifier == nullptr) { // NOTE(bill): Should only happen on errors error(e->token, "Invalid variable declaration"); @@ -1738,16 +1738,15 @@ void add_entity_and_decl_info(CheckerContext *c, Ast *identifier, Entity *e, Dec } -void add_implicit_entity(CheckerContext *c, Ast *clause, Entity *e) { +gb_internal void add_implicit_entity(CheckerContext *c, Ast *clause, Entity *e) { GB_ASSERT(clause != nullptr); GB_ASSERT(e != nullptr); GB_ASSERT(clause->kind == Ast_CaseClause); clause->CaseClause.implicit_entity = e; } -void add_type_info_type(CheckerContext *c, Type *t) { - void add_type_info_type_internal(CheckerContext *c, Type *t); - +gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t); +gb_internal void add_type_info_type(CheckerContext *c, Type *t) { if (build_context.disallow_rtti) { return; } @@ -1757,7 +1756,7 @@ void add_type_info_type(CheckerContext *c, Type *t) { mutex_unlock(&c->info->type_info_mutex); } -void add_type_info_type_internal(CheckerContext *c, Type *t) { +gb_internal void add_type_info_type_internal(CheckerContext *c, Type *t) { if (t == nullptr) { return; } @@ -1982,7 +1981,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { gb_global bool global_procedure_body_in_worker_queue = false; -void check_procedure_later(CheckerContext *c, ProcInfo *info) { +gb_internal void check_procedure_later(CheckerContext *c, ProcInfo *info) { GB_ASSERT(info != nullptr); GB_ASSERT(info->decl != nullptr); @@ -1994,7 +1993,7 @@ void check_procedure_later(CheckerContext *c, ProcInfo *info) { mpmc_enqueue(queue, info); } -void check_procedure_later(CheckerContext *c, AstFile *file, Token token, DeclInfo *decl, Type *type, Ast *body, u64 tags) { +gb_internal void check_procedure_later(CheckerContext *c, AstFile *file, Token token, DeclInfo *decl, Type *type, Ast *body, u64 tags) { ProcInfo *info = gb_alloc_item(permanent_allocator(), ProcInfo); info->file = file; info->token = token; @@ -2006,7 +2005,7 @@ void check_procedure_later(CheckerContext *c, AstFile *file, Token token, DeclIn } -void add_min_dep_type_info(Checker *c, Type *t) { +gb_internal void add_min_dep_type_info(Checker *c, Type *t) { if (t == nullptr) { return; } @@ -2201,7 +2200,7 @@ void add_min_dep_type_info(Checker *c, Type *t) { } -void add_dependency_to_set(Checker *c, Entity *entity) { +gb_internal void add_dependency_to_set(Checker *c, Entity *entity) { if (entity == nullptr) { return; } @@ -2254,7 +2253,7 @@ void add_dependency_to_set(Checker *c, Entity *entity) { } } -void force_add_dependency_entity(Checker *c, Scope *scope, String const &name) { +gb_internal void force_add_dependency_entity(Checker *c, Scope *scope, String const &name) { Entity *e = scope_lookup(scope, name); if (e == nullptr) { return; @@ -2266,7 +2265,7 @@ void force_add_dependency_entity(Checker *c, Scope *scope, String const &name) { -void generate_minimum_dependency_set(Checker *c, Entity *start) { +gb_internal void generate_minimum_dependency_set(Checker *c, Entity *start) { isize entity_count = c->info.entities.count; isize min_dep_set_cap = next_pow2_isize(entity_count*4); // empirically determined factor @@ -2479,7 +2478,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { #undef FORCE_ADD_RUNTIME_ENTITIES } -bool is_entity_a_dependency(Entity *e) { +gb_internal bool is_entity_a_dependency(Entity *e) { if (e == nullptr) return false; switch (e->kind) { case Entity_Procedure: @@ -2493,7 +2492,7 @@ bool is_entity_a_dependency(Entity *e) { return false; } -Array generate_entity_dependency_graph(CheckerInfo *info, gbAllocator allocator) { +gb_internal Array generate_entity_dependency_graph(CheckerInfo *info, gbAllocator allocator) { PtrMap M = {}; map_init(&M, allocator, info->entities.count); defer (map_destroy(&M)); @@ -2612,10 +2611,10 @@ Array generate_entity_dependency_graph(CheckerInfo *info, gbA } -void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d); +gb_internal void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d); -Entity *find_core_entity(Checker *c, String name) { +gb_internal Entity *find_core_entity(Checker *c, String name) { Entity *e = scope_lookup_current(c->info.runtime_package->scope, name); if (e == nullptr) { compiler_error("Could not find type declaration for '%.*s'\n" @@ -2625,7 +2624,7 @@ Entity *find_core_entity(Checker *c, String name) { return e; } -Type *find_core_type(Checker *c, String name) { +gb_internal Type *find_core_type(Checker *c, String name) { Entity *e = scope_lookup_current(c->info.runtime_package->scope, name); if (e == nullptr) { compiler_error("Could not find type declaration for '%.*s'\n" @@ -2640,7 +2639,7 @@ Type *find_core_type(Checker *c, String name) { } -Entity *find_entity_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { +gb_internal Entity *find_entity_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { AstPackage *package = get_core_package(info, pkg); Entity *e = scope_lookup_current(package->scope, name); if (e == nullptr) { @@ -2650,7 +2649,7 @@ Entity *find_entity_in_pkg(CheckerInfo *info, String const &pkg, String const &n return e; } -Type *find_type_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { +gb_internal Type *find_type_in_pkg(CheckerInfo *info, String const &pkg, String const &name) { AstPackage *package = get_core_package(info, pkg); Entity *e = scope_lookup_current(package->scope, name); if (e == nullptr) { @@ -2661,58 +2660,58 @@ Type *find_type_in_pkg(CheckerInfo *info, String const &pkg, String const &name) return e->type; } -CheckerTypePath *new_checker_type_path() { +gb_internal CheckerTypePath *new_checker_type_path() { gbAllocator a = heap_allocator(); auto *tp = gb_alloc_item(a, CheckerTypePath); array_init(tp, a, 0, 16); return tp; } -void destroy_checker_type_path(CheckerTypePath *tp) { +gb_internal void destroy_checker_type_path(CheckerTypePath *tp) { array_free(tp); gb_free(heap_allocator(), tp); } -void check_type_path_push(CheckerContext *c, Entity *e) { +gb_internal void check_type_path_push(CheckerContext *c, Entity *e) { GB_ASSERT(c->type_path != nullptr); GB_ASSERT(e != nullptr); array_add(c->type_path, e); } -Entity *check_type_path_pop(CheckerContext *c) { +gb_internal Entity *check_type_path_pop(CheckerContext *c) { GB_ASSERT(c->type_path != nullptr); return array_pop(c->type_path); } -CheckerPolyPath *new_checker_poly_path(void) { +gb_internal CheckerPolyPath *new_checker_poly_path(void) { gbAllocator a = heap_allocator(); auto *pp = gb_alloc_item(a, CheckerPolyPath); array_init(pp, a, 0, 16); return pp; } -void destroy_checker_poly_path(CheckerPolyPath *pp) { +gb_internal void destroy_checker_poly_path(CheckerPolyPath *pp) { array_free(pp); gb_free(heap_allocator(), pp); } -void check_poly_path_push(CheckerContext *c, Type *t) { +gb_internal void check_poly_path_push(CheckerContext *c, Type *t) { GB_ASSERT(c->poly_path != nullptr); GB_ASSERT(t != nullptr); GB_ASSERT(is_type_polymorphic(t)); array_add(c->poly_path, t); } -Type *check_poly_path_pop(CheckerContext *c) { +gb_internal Type *check_poly_path_pop(CheckerContext *c) { GB_ASSERT(c->poly_path != nullptr); return array_pop(c->poly_path); } -Array proc_group_entities(CheckerContext *c, Operand o) { +gb_internal Array proc_group_entities(CheckerContext *c, Operand o) { Array procs = {}; if (o.mode == Addressing_ProcGroup) { GB_ASSERT(o.proc_group != nullptr); @@ -2724,7 +2723,7 @@ Array proc_group_entities(CheckerContext *c, Operand o) { return procs; } -Array proc_group_entities_cloned(CheckerContext *c, Operand o) { +gb_internal Array proc_group_entities_cloned(CheckerContext *c, Operand o) { auto entities = proc_group_entities(c, o); if (entities.count == 0) { return {}; @@ -2735,7 +2734,7 @@ Array proc_group_entities_cloned(CheckerContext *c, Operand o) { -void init_core_type_info(Checker *c) { +gb_internal void init_core_type_info(Checker *c) { if (t_type_info != nullptr) { return; } @@ -2816,7 +2815,7 @@ void init_core_type_info(Checker *c) { t_type_info_soa_pointer_ptr = alloc_type_pointer(t_type_info_soa_pointer); } -void init_mem_allocator(Checker *c) { +gb_internal void init_mem_allocator(Checker *c) { if (t_allocator != nullptr) { return; } @@ -2825,7 +2824,7 @@ void init_mem_allocator(Checker *c) { t_allocator_error = find_core_type(c, str_lit("Allocator_Error")); } -void init_core_context(Checker *c) { +gb_internal void init_core_context(Checker *c) { if (t_context != nullptr) { return; } @@ -2833,7 +2832,7 @@ void init_core_context(Checker *c) { t_context_ptr = alloc_type_pointer(t_context); } -void init_core_source_code_location(Checker *c) { +gb_internal void init_core_source_code_location(Checker *c) { if (t_source_code_location != nullptr) { return; } @@ -2841,7 +2840,7 @@ void init_core_source_code_location(Checker *c) { t_source_code_location_ptr = alloc_type_pointer(t_source_code_location); } -void init_core_map_type(Checker *c) { +gb_internal void init_core_map_type(Checker *c) { if (t_map_info != nullptr) { return; } @@ -2855,7 +2854,7 @@ void init_core_map_type(Checker *c) { t_raw_map_ptr = alloc_type_pointer(t_raw_map); } -void init_preload(Checker *c) { +gb_internal void init_preload(Checker *c) { init_core_type_info(c); init_mem_allocator(c); init_core_context(c); @@ -2863,7 +2862,7 @@ void init_preload(Checker *c) { init_core_map_type(c); } -ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) { +gb_internal ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) { ExactValue ev = {}; if (value != nullptr) { Operand op = {}; @@ -2879,7 +2878,7 @@ ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) { return ev; } -Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { +gb_internal Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { if (value != nullptr) { return check_type(c, value); } @@ -2890,7 +2889,7 @@ Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { #define ATTRIBUTE_USER_TAG_NAME "tag" -DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { ExactValue ev = check_decl_attribute_value(c, value); if (name == ATTRIBUTE_USER_TAG_NAME) { @@ -2945,7 +2944,7 @@ DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(proc_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3242,7 +3241,7 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(var_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(var_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3367,7 +3366,7 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(const_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(const_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3381,7 +3380,7 @@ DECL_ATTRIBUTE_PROC(const_decl_attribute) { return false; } -DECL_ATTRIBUTE_PROC(type_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(type_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -3412,7 +3411,7 @@ DECL_ATTRIBUTE_PROC(type_decl_attribute) { -void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac) { +gb_internal void check_decl_attributes(CheckerContext *c, Array const &attributes, DeclAttributeProc *proc, AttributeContext *ac) { if (attributes.count == 0) return; String original_link_prefix = {}; @@ -3480,7 +3479,7 @@ void check_decl_attributes(CheckerContext *c, Array const &attributes, De } -isize get_total_value_count(Slice const &values) { +gb_internal isize get_total_value_count(Slice const &values) { isize count = 0; for_array(i, values) { Type *t = type_of_expr(values[i]); @@ -3498,7 +3497,7 @@ isize get_total_value_count(Slice const &values) { return count; } -bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { +gb_internal bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { isize lhs = vd->names.count; isize rhs = 0; if (is_global) { @@ -3541,7 +3540,7 @@ bool check_arity_match(CheckerContext *c, AstValueDecl *vd, bool is_global) { return true; } -void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { +gb_internal void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(c, &operand, ws->cond); @@ -3577,7 +3576,7 @@ void check_collect_entities_from_when_stmt(CheckerContext *c, AstWhenStmt *ws) { } } -void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attributes) { +gb_internal void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attributes) { switch (e->kind) { case Entity_ProcGroup: case Entity_Procedure: @@ -3640,7 +3639,7 @@ void check_builtin_attributes(CheckerContext *ctx, Entity *e, Array *attr } } -void check_collect_value_decl(CheckerContext *c, Ast *decl) { +gb_internal void check_collect_value_decl(CheckerContext *c, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -3891,7 +3890,7 @@ void check_collect_value_decl(CheckerContext *c, Ast *decl) { } } -void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { +gb_internal void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -3912,7 +3911,7 @@ void check_add_foreign_block_decl(CheckerContext *ctx, Ast *decl) { check_collect_entities(&c, block->stmts); } -bool correct_single_type_alias(CheckerContext *c, Entity *e) { +gb_internal bool correct_single_type_alias(CheckerContext *c, Entity *e) { if (e->kind == Entity_Constant) { DeclInfo *d = e->decl_info; if (d != nullptr && d->init_expr != nullptr) { @@ -3927,7 +3926,7 @@ bool correct_single_type_alias(CheckerContext *c, Entity *e) { return false; } -bool correct_type_alias_in_scope_backwards(CheckerContext *c, Scope *s) { +gb_internal bool correct_type_alias_in_scope_backwards(CheckerContext *c, Scope *s) { isize n = s->elements.entries.count; bool correction = false; for (isize i = n-1; i >= 0; i--) { @@ -3935,7 +3934,7 @@ bool correct_type_alias_in_scope_backwards(CheckerContext *c, Scope *s) { } return correction; } -bool correct_type_alias_in_scope_forwards(CheckerContext *c, Scope *s) { +gb_internal bool correct_type_alias_in_scope_forwards(CheckerContext *c, Scope *s) { isize n = s->elements.entries.count; bool correction = false; for (isize i = 0; i < n; i++) { @@ -3945,7 +3944,7 @@ bool correct_type_alias_in_scope_forwards(CheckerContext *c, Scope *s) { } -void correct_type_aliases_in_scope(CheckerContext *c, Scope *s) { +gb_internal void correct_type_aliases_in_scope(CheckerContext *c, Scope *s) { // NOTE(bill, 2022-02-04): This is used to solve the problem caused by type aliases // of type aliases being "confused" as constants // @@ -3966,7 +3965,7 @@ void correct_type_aliases_in_scope(CheckerContext *c, Scope *s) { // NOTE(bill): If file_scopes == nullptr, this will act like a local scope -void check_collect_entities(CheckerContext *c, Slice const &nodes) { +gb_internal void check_collect_entities(CheckerContext *c, Slice const &nodes) { AstFile *curr_file = nullptr; if ((c->scope->flags&ScopeFlag_File) != 0) { curr_file = c->scope->file; @@ -4050,13 +4049,13 @@ void check_collect_entities(CheckerContext *c, Slice const &nodes) { } } -CheckerContext *create_checker_context(Checker *c) { +gb_internal CheckerContext *create_checker_context(Checker *c) { CheckerContext *ctx = gb_alloc_item(permanent_allocator(), CheckerContext); *ctx = make_checker_context(c); return ctx; } -void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d) { +gb_internal void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d) { GB_ASSERT(e != nullptr); GB_ASSERT(d != nullptr); @@ -4089,7 +4088,7 @@ void check_single_global_entity(Checker *c, Entity *e, DeclInfo *d) { check_entity_decl(ctx, e, d, nullptr); } -void check_all_global_entities(Checker *c) { +gb_internal void check_all_global_entities(Checker *c) { // NOTE(bill): This must be single threaded // Don't bother trying for_array(i, c->info.entities) { @@ -4107,7 +4106,7 @@ void check_all_global_entities(Checker *c) { } -bool is_string_an_identifier(String s) { +gb_internal bool is_string_an_identifier(String s) { isize offset = 0; if (s.len < 1) { return false; @@ -4131,7 +4130,7 @@ bool is_string_an_identifier(String s) { return offset == s.len; } -String path_to_entity_name(String name, String fullpath, bool strip_extension=true) { +gb_internal String path_to_entity_name(String name, String fullpath, bool strip_extension=true) { if (name.len != 0) { return name; } @@ -4177,7 +4176,7 @@ String path_to_entity_name(String name, String fullpath, bool strip_extension=tr #if 1 -void add_import_dependency_node(Checker *c, Ast *decl, PtrMap *M) { +gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMap *M) { AstPackage *parent_pkg = decl->file()->pkg; switch (decl->kind) { @@ -4242,7 +4241,7 @@ void add_import_dependency_node(Checker *c, Ast *decl, PtrMap generate_import_dependency_graph(Checker *c) { +gb_internal Array generate_import_dependency_graph(Checker *c) { PtrMap M = {}; map_init(&M, heap_allocator(), 2*c->parser->packages.count); defer (map_destroy(&M)); @@ -4285,7 +4284,7 @@ struct ImportPathItem { Ast * decl; }; -Array find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet *visited) { +gb_internal Array find_import_path(Checker *c, AstPackage *start, AstPackage *end, PtrSet *visited) { Array empty_path = {}; if (ptr_set_update(visited, start)) { @@ -4335,7 +4334,7 @@ Array find_import_path(Checker *c, AstPackage *start, AstPackage } #endif -String get_invalid_import_name(String input) { +gb_internal String get_invalid_import_name(String input) { isize slash = 0; for (isize i = input.len-1; i >= 0; i--) { if (input[i] == '/' || input[i] == '\\') { @@ -4347,7 +4346,7 @@ String get_invalid_import_name(String input) { return input; } -void check_add_import_decl(CheckerContext *ctx, Ast *decl) { +gb_internal void check_add_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -4422,7 +4421,7 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) { scope->flags |= ScopeFlag_HasBeenImported; } -DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) { +gb_internal DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) { if (name == ATTRIBUTE_USER_TAG_NAME) { ExactValue ev = check_decl_attribute_value(c, value); if (ev.kind != ExactValue_String) { @@ -4449,7 +4448,7 @@ DECL_ATTRIBUTE_PROC(foreign_import_decl_attribute) { return false; } -void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { +gb_internal void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; @@ -4515,10 +4514,10 @@ void check_add_foreign_import_decl(CheckerContext *ctx, Ast *decl) { } // Returns true if a new package is present -bool collect_file_decls(CheckerContext *ctx, Slice const &decls); -bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws); +gb_internal bool collect_file_decls(CheckerContext *ctx, Slice const &decls); +gb_internal bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws); -bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { +gb_internal bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(ctx, &operand, ws->cond); @@ -4557,7 +4556,7 @@ bool collect_when_stmt_from_file(CheckerContext *ctx, AstWhenStmt *ws) { return false; } -bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { +gb_internal bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { Operand operand = {Addressing_Invalid}; if (!ws->is_cond_determined) { check_expr(ctx, &operand, ws->cond); @@ -4594,7 +4593,7 @@ bool collect_file_decls_from_when_stmt(CheckerContext *ctx, AstWhenStmt *ws) { } -bool collect_file_decl(CheckerContext *ctx, Ast *decl) { +gb_internal bool collect_file_decl(CheckerContext *ctx, Ast *decl) { GB_ASSERT(ctx->scope->flags&ScopeFlag_File); AstFile *curr_file = ctx->scope->file; @@ -4658,7 +4657,7 @@ bool collect_file_decl(CheckerContext *ctx, Ast *decl) { return false; } -bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { +gb_internal bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { GB_ASSERT(ctx->scope->flags&ScopeFlag_File); for_array(i, decls) { @@ -4671,7 +4670,7 @@ bool collect_file_decls(CheckerContext *ctx, Slice const &decls) { return false; } -GB_COMPARE_PROC(sort_file_by_name) { +gb_internal GB_COMPARE_PROC(sort_file_by_name) { AstFile const *x = *cast(AstFile const **)a; AstFile const *y = *cast(AstFile const **)b; String x_name = filename_from_path(x->fullpath); @@ -4679,7 +4678,7 @@ GB_COMPARE_PROC(sort_file_by_name) { return string_compare(x_name, y_name); } -void check_create_file_scopes(Checker *c) { +gb_internal void check_create_file_scopes(Checker *c) { for_array(i, c->parser->packages) { AstPackage *pkg = c->parser->packages[i]; isize total_pkg_decl_count = 0; @@ -4705,7 +4704,7 @@ struct ThreadProcCheckerSection { }; -void check_with_workers(Checker *c, WorkerTaskProc *proc, isize total_count) { +gb_internal void check_with_workers(Checker *c, WorkerTaskProc *proc, isize total_count) { isize thread_count = gb_max(build_context.thread_count, 1); isize worker_count = thread_count-1; // NOTE(bill): The main thread will also be used for work if (!build_context.threaded_checker) { @@ -4744,7 +4743,7 @@ void check_with_workers(Checker *c, WorkerTaskProc *proc, isize total_count) { } -WORKER_TASK_PROC(thread_proc_collect_entities) { +gb_internal WORKER_TASK_PROC(thread_proc_collect_entities) { auto *cs = cast(ThreadProcCheckerSection *)data; Checker *c = cs->checker; CheckerContext collect_entity_ctx = make_checker_context(c); @@ -4775,11 +4774,11 @@ WORKER_TASK_PROC(thread_proc_collect_entities) { } -void check_collect_entities_all(Checker *c) { +gb_internal void check_collect_entities_all(Checker *c) { check_with_workers(c, thread_proc_collect_entities, c->info.files.entries.count); } -void check_export_entities_in_pkg(CheckerContext *ctx, AstPackage *pkg, UntypedExprInfoMap *untyped) { +gb_internal void check_export_entities_in_pkg(CheckerContext *ctx, AstPackage *pkg, UntypedExprInfoMap *untyped) { if (pkg->files.count != 0) { AstPackageExportedEntity item = {}; while (mpmc_dequeue(&pkg->exported_entity_queue, &item)) { @@ -4793,7 +4792,7 @@ void check_export_entities_in_pkg(CheckerContext *ctx, AstPackage *pkg, UntypedE } } -WORKER_TASK_PROC(thread_proc_check_export_entities) { +gb_internal WORKER_TASK_PROC(thread_proc_check_export_entities) { auto cs = cast(ThreadProcCheckerSection *)data; Checker *c = cs->checker; @@ -4815,11 +4814,11 @@ WORKER_TASK_PROC(thread_proc_check_export_entities) { return 0; } -void check_export_entities(Checker *c) { +gb_internal void check_export_entities(Checker *c) { check_with_workers(c, thread_proc_check_export_entities, c->info.packages.entries.count); } -void check_import_entities(Checker *c) { +gb_internal void check_import_entities(Checker *c) { Array dep_graph = generate_import_dependency_graph(c); defer ({ for_array(i, dep_graph) { @@ -4961,9 +4960,9 @@ void check_import_entities(Checker *c) { } -Array find_entity_path(Entity *start, Entity *end, PtrSet *visited = nullptr); +gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet *visited = nullptr); -bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, Array *path_) { +gb_internal bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, Array *path_) { GB_ASSERT(path_ != nullptr); if (tuple == nullptr) { return false; @@ -4995,7 +4994,7 @@ bool find_entity_path_tuple(Type *tuple, Entity *end, PtrSet *visited, return false; } -Array find_entity_path(Entity *start, Entity *end, PtrSet *visited) { +gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet *visited) { PtrSet visited_ = {}; bool made_visited = false; if (visited == nullptr) { @@ -5047,7 +5046,7 @@ Array find_entity_path(Entity *start, Entity *end, PtrSet *v } -void calculate_global_init_order(Checker *c) { +gb_internal void calculate_global_init_order(Checker *c) { CheckerInfo *info = &c->info; TIME_SECTION("calculate_global_init_order: generate entity dependency graph"); @@ -5122,7 +5121,7 @@ void calculate_global_init_order(Checker *c) { } -bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, ProcBodyQueue *procs_to_check_queue) { +gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, ProcBodyQueue *procs_to_check_queue) { if (pi == nullptr) { return false; } @@ -5201,9 +5200,9 @@ bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *untyped, Proc GB_STATIC_ASSERT(sizeof(isize) == sizeof(void *)); -bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped); +gb_internal bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped); -void check_unchecked_bodies(Checker *c) { +gb_internal void check_unchecked_bodies(Checker *c) { // NOTE(2021-02-26, bill): Sanity checker // This is a partial hack to make sure all procedure bodies have been checked // even ones which should not exist, due to the multithreaded nature of the parser @@ -5255,7 +5254,7 @@ void check_unchecked_bodies(Checker *c) { } -void check_test_procedures(Checker *c) { +gb_internal void check_test_procedures(Checker *c) { if (build_context.test_names.entries.count == 0) { return; } @@ -5290,7 +5289,7 @@ void check_test_procedures(Checker *c) { gb_global std::atomic total_bodies_checked; -bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped) { +gb_internal bool consume_proc_info_queue(Checker *c, ProcInfo *pi, ProcBodyQueue *q, UntypedExprInfoMap *untyped) { GB_ASSERT(pi->decl != nullptr); if (pi->decl->parent && pi->decl->parent->entity) { Entity *parent = pi->decl->parent->entity; @@ -5318,7 +5317,7 @@ struct ThreadProcBodyData { ThreadProcBodyData *all_data; }; -WORKER_TASK_PROC(thread_proc_body) { +gb_internal WORKER_TASK_PROC(thread_proc_body) { ThreadProcBodyData *bd = cast(ThreadProcBodyData *)data; Checker *c = bd->checker; GB_ASSERT(c != nullptr); @@ -5338,7 +5337,7 @@ WORKER_TASK_PROC(thread_proc_body) { return 0; } -void check_procedure_bodies(Checker *c) { +gb_internal void check_procedure_bodies(Checker *c) { GB_ASSERT(c != nullptr); u32 thread_count = cast(u32)gb_max(build_context.thread_count, 1); @@ -5414,7 +5413,7 @@ void check_procedure_bodies(Checker *c) { global_procedure_body_in_worker_queue = false; } -void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { +gb_internal void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { if (untyped == nullptr) { return; } @@ -5428,7 +5427,7 @@ void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap *untyped) { map_clear(untyped); } -void check_deferred_procedures(Checker *c) { +gb_internal void check_deferred_procedures(Checker *c) { for (Entity *src = nullptr; mpmc_dequeue(&c->procs_with_deferred_to_check, &src); /**/) { GB_ASSERT(src->kind == Entity_Procedure); @@ -5581,7 +5580,7 @@ void check_deferred_procedures(Checker *c) { } -void check_unique_package_names(Checker *c) { +gb_internal void check_unique_package_names(Checker *c) { StringMap pkgs = {}; // Key: package name string_map_init(&pkgs, heap_allocator(), 2*c->info.packages.entries.count); defer (string_map_destroy(&pkgs)); @@ -5614,7 +5613,7 @@ void check_unique_package_names(Checker *c) { } } -void check_add_entities_from_queues(Checker *c) { +gb_internal void check_add_entities_from_queues(Checker *c) { isize cap = c->info.entities.count + c->info.entity_queue.count.load(std::memory_order_relaxed); array_reserve(&c->info.entities, cap); for (Entity *e; mpmc_dequeue(&c->info.entity_queue, &e); /**/) { @@ -5622,7 +5621,7 @@ void check_add_entities_from_queues(Checker *c) { } } -void check_add_definitions_from_queues(Checker *c) { +gb_internal void check_add_definitions_from_queues(Checker *c) { isize cap = c->info.definitions.count + c->info.definition_queue.count.load(std::memory_order_relaxed); array_reserve(&c->info.definitions, cap); for (Entity *e; mpmc_dequeue(&c->info.definition_queue, &e); /**/) { @@ -5630,12 +5629,12 @@ void check_add_definitions_from_queues(Checker *c) { } } -void check_merge_queues_into_arrays(Checker *c) { +gb_internal void check_merge_queues_into_arrays(Checker *c) { check_add_entities_from_queues(c); check_add_definitions_from_queues(c); } -GB_COMPARE_PROC(init_procedures_cmp) { +gb_internal GB_COMPARE_PROC(init_procedures_cmp) { int cmp = 0; Entity *x = *(Entity **)a; Entity *y = *(Entity **)b; @@ -5673,11 +5672,11 @@ GB_COMPARE_PROC(init_procedures_cmp) { } -void check_sort_init_procedures(Checker *c) { +gb_internal void check_sort_init_procedures(Checker *c) { gb_sort_array(c->info.init_procedures.data, c->info.init_procedures.count, init_procedures_cmp); } -void add_type_info_for_type_definitions(Checker *c) { +gb_internal void add_type_info_for_type_definitions(Checker *c) { for_array(i, c->info.definitions) { Entity *e = c->info.definitions[i]; if (e->kind == Entity_TypeName && e->type != nullptr) { @@ -5689,7 +5688,7 @@ void add_type_info_for_type_definitions(Checker *c) { } } -void check_parsed_files(Checker *c) { +gb_internal void check_parsed_files(Checker *c) { TIME_SECTION("map full filepaths to scope"); add_type_info_type(&c->builtin_ctx, t_invalid); diff --git a/src/types.cpp b/src/types.cpp index 2ab7374c2..c8e24f01d 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -4029,9 +4029,8 @@ gb_internal bool has_type_got_objc_class_attribute(Type *t) { +gb_internal bool internal_check_is_assignable_to(Type *src, Type *dst); gb_internal bool is_type_objc_object(Type *t) { - bool internal_check_is_assignable_to(Type *src, Type *dst); - return internal_check_is_assignable_to(t, t_objc_object); } -- cgit v1.2.3 From c1f5be24e28c41efbbbe6d116d533b55d48bbf82 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Dec 2022 22:49:10 +0000 Subject: Remove dead code in the compiler --- build.bat | 1 + src/build_settings.cpp | 6 +- src/check_decl.cpp | 10 - src/check_expr.cpp | 24 - src/check_stmt.cpp | 6 - src/checker.cpp | 140 ++---- src/checker.hpp | 8 - src/common.cpp | 9 + src/docs.cpp | 9 - src/entity.cpp | 8 - src/exact_value.cpp | 86 ++-- src/llvm_backend.cpp | 10 +- src/llvm_backend_debug.cpp | 6 - src/llvm_backend_general.cpp | 68 --- src/llvm_backend_opt.cpp | 20 +- src/llvm_backend_proc.cpp | 88 ++-- src/llvm_backend_stmt.cpp | 10 - src/llvm_backend_utility.cpp | 12 - src/main.cpp | 77 +--- src/parser.cpp | 36 -- src/parser.hpp | 5 - src/parser_pos.cpp | 2 - src/query_data.cpp | 1030 ------------------------------------------ src/range_cache.cpp | 18 +- src/string.cpp | 14 - src/string_map.cpp | 2 - src/threading.cpp | 50 +- src/types.cpp | 75 --- 28 files changed, 169 insertions(+), 1661 deletions(-) delete mode 100644 src/query_data.cpp (limited to 'src/checker.cpp') diff --git a/build.bat b/build.bat index 7391bd95f..d7a89fe20 100644 --- a/build.bat +++ b/build.bat @@ -62,6 +62,7 @@ if %release_mode% EQU 0 ( rem Debug set compiler_warnings= ^ -W4 -WX ^ -wd4100 -wd4101 -wd4127 -wd4146 ^ + -wd4505 ^ -wd4456 -wd4457 set compiler_includes= ^ diff --git a/src/build_settings.cpp b/src/build_settings.cpp index d66db8099..7d796d775 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -149,7 +149,6 @@ enum CommandKind : u32 { Command_run = 1<<0, Command_build = 1<<1, Command_check = 1<<3, - Command_query = 1<<4, Command_doc = 1<<5, Command_version = 1<<6, Command_test = 1<<7, @@ -157,7 +156,7 @@ enum CommandKind : u32 { Command_strip_semicolon = 1<<8, Command_bug_report = 1<<9, - Command__does_check = Command_run|Command_build|Command_check|Command_query|Command_doc|Command_test|Command_strip_semicolon, + Command__does_check = Command_run|Command_build|Command_check|Command_doc|Command_test|Command_strip_semicolon, Command__does_build = Command_run|Command_build|Command_test, Command_all = ~(u32)0, }; @@ -166,7 +165,6 @@ gb_global char const *odin_command_strings[32] = { "run", "build", "check", - "query", "doc", "version", "test", @@ -316,8 +314,6 @@ struct BuildContext { u32 cmd_doc_flags; Array extra_packages; - QueryDataSetSettings query_data_set_settings; - StringSet test_names; gbAffinity affinity; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index a976c1b73..d982a69fc 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -232,16 +232,6 @@ gb_internal Ast *remove_type_alias_clutter(Ast *node) { } } -gb_internal isize total_attribute_count(DeclInfo *decl) { - isize attribute_count = 0; - for_array(i, decl->attributes) { - Ast *attr = decl->attributes[i]; - if (attr->kind != Ast_Attribute) continue; - attribute_count += attr->Attribute.elems.count; - } - return attribute_count; -} - gb_internal Type *clone_enum_type(CheckerContext *ctx, Type *original_enum_type, Type *named_type) { // NOTE(bill, 2022-02-05): Stupid edge case for `distinct` declarations // diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 3003e07b6..ed1ddd1f1 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5103,16 +5103,6 @@ gb_internal bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize return optional_ok; } - -gb_internal bool is_expr_constant_zero(Ast *expr) { - GB_ASSERT(expr != nullptr); - auto v = exact_value_to_integer(expr->tav.value); - if (v.kind == ExactValue_Integer) { - return big_int_cmp_zero(&v.value_integer) == 0; - } - return false; -} - gb_internal isize get_procedure_param_count_excluding_defaults(Type *pt, isize *param_count_) { GB_ASSERT(pt != nullptr); GB_ASSERT(pt->kind == Type_Proc); @@ -5429,20 +5419,6 @@ gb_internal isize lookup_procedure_parameter(TypeProc *pt, String parameter_name } return -1; } -gb_internal isize lookup_procedure_result(TypeProc *pt, String result_name) { - isize result_count = pt->result_count; - for (isize i = 0; i < result_count; i++) { - Entity *e = pt->results->Tuple.variables[i]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - if (name == result_name) { - return i; - } - } - return -1; -} gb_internal CALL_ARGUMENT_CHECKER(check_named_call_arguments) { ast_node(ce, CallExpr, call); diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index cae9c3537..73adbed8b 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1520,12 +1520,6 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) } case_end; - case_ast_node(ts, TagStmt, node); - // TODO(bill): Tag Statements - error(node, "Tag statements are not supported yet"); - check_stmt(ctx, ts->stmt, flags); - case_end; - case_ast_node(as, AssignStmt, node); switch (as->op.kind) { case Token_Eq: { diff --git a/src/checker.cpp b/src/checker.cpp index e2c430dc2..f130a965f 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -61,18 +61,6 @@ gb_internal void scope_reserve(Scope *scope, isize capacity) { } } -gb_internal i32 is_scope_an_ancestor(Scope *parent, Scope *child) { - i32 i = 0; - while (child != nullptr) { - if (parent == child) { - return i; - } - child = child->parent; - i++; - } - return -1; -} - gb_internal void entity_graph_node_set_destroy(EntityGraphNodeSet *s) { if (s->hashes.data != nullptr) { ptr_set_destroy(s); @@ -86,9 +74,9 @@ gb_internal void entity_graph_node_set_add(EntityGraphNodeSet *s, EntityGraphNod ptr_set_add(s, n); } -gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { - return ptr_set_exists(s, n); -} +// gb_internal bool entity_graph_node_set_exists(EntityGraphNodeSet *s, EntityGraphNode *n) { +// return ptr_set_exists(s, n); +// } gb_internal void entity_graph_node_set_remove(EntityGraphNodeSet *s, EntityGraphNode *n) { ptr_set_remove(s, n); @@ -139,13 +127,13 @@ gb_internal void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNod ptr_set_add(s, n); } -gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { - return ptr_set_exists(s, n); -} +// gb_internal bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) { +// return ptr_set_exists(s, n); +// } -gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { - ptr_set_remove(s, n); -} +// gb_internal void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) { +// ptr_set_remove(s, n); +// } gb_internal ImportGraphNode *import_graph_node_create(gbAllocator a, AstPackage *pkg) { ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode); @@ -186,15 +174,6 @@ gb_internal void import_graph_node_swap(ImportGraphNode **data, isize i, isize j y->index = i; } -gb_internal GB_COMPARE_PROC(ast_node_cmp) { - Ast *x = *cast(Ast **)a; - Ast *y = *cast(Ast **)b; - Token i = ast_token(x); - Token j = ast_token(y); - return token_pos_cmp(i.pos, j.pos); -} - - @@ -213,27 +192,27 @@ gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { return d; } -gb_internal void destroy_declaration_info(DeclInfo *d) { - ptr_set_destroy(&d->deps); - array_free(&d->labels); -} +// gb_internal void destroy_declaration_info(DeclInfo *d) { +// ptr_set_destroy(&d->deps); +// array_free(&d->labels); +// } -gb_internal bool decl_info_has_init(DeclInfo *d) { - if (d->init_expr != nullptr) { - return true; - } - if (d->proc_lit != nullptr) { - switch (d->proc_lit->kind) { - case_ast_node(pl, ProcLit, d->proc_lit); - if (pl->body != nullptr) { - return true; - } - case_end; - } - } +// gb_internal bool decl_info_has_init(DeclInfo *d) { +// if (d->init_expr != nullptr) { +// return true; +// } +// if (d->proc_lit != nullptr) { +// switch (d->proc_lit->kind) { +// case_ast_node(pl, ProcLit, d->proc_lit); +// if (pl->body != nullptr) { +// return true; +// } +// case_end; +// } +// } - return false; -} +// return false; +// } @@ -528,11 +507,6 @@ struct VettedEntity { Entity *entity; Entity *other; }; -gb_internal void init_vetted_entity(VettedEntity *ve, VettedEntityKind kind, Entity *entity, Entity *other=nullptr) { - ve->kind = kind; - ve->entity = entity; - ve->other = other; -} gb_internal GB_COMPARE_PROC(vetted_entity_variable_pos_cmp) { @@ -1144,7 +1118,7 @@ gb_internal void init_checker_info(CheckerInfo *i) { - i->allow_identifier_uses = build_context.query_data_set_settings.kind == QueryDataSet_GoToDefinitions; + i->allow_identifier_uses = false; if (i->allow_identifier_uses) { array_init(&i->identifier_uses, a); } @@ -1226,13 +1200,10 @@ gb_internal CheckerContext make_checker_context(Checker *c) { ctx.type_path = new_checker_type_path(); ctx.type_level = 0; - ctx.poly_path = new_checker_poly_path(); - ctx.poly_level = 0; return ctx; } gb_internal void destroy_checker_context(CheckerContext *ctx) { destroy_checker_type_path(ctx->type_path); - destroy_checker_poly_path(ctx->poly_path); } gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { @@ -1348,17 +1319,17 @@ gb_internal DeclInfo *decl_info_of_entity(Entity *e) { return nullptr; } -gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { - return decl_info_of_entity(entity_of_node(ident)); -} +// gb_internal DeclInfo *decl_info_of_ident(Ast *ident) { +// return decl_info_of_entity(entity_of_node(ident)); +// } -gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { - AstFile **found = string_map_get(&i->files, filename); - if (found != nullptr) { - return *found; - } - return nullptr; -} +// gb_internal AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { +// AstFile **found = string_map_get(&i->files, filename); +// if (found != nullptr) { +// return *found; +// } +// return nullptr; +// } gb_internal ExprInfo *check_get_expr_info(CheckerContext *c, Ast *expr) { if (c->untyped != nullptr) { ExprInfo **found = map_get(c->untyped, expr); @@ -2684,32 +2655,6 @@ gb_internal Entity *check_type_path_pop(CheckerContext *c) { } -gb_internal CheckerPolyPath *new_checker_poly_path(void) { - gbAllocator a = heap_allocator(); - auto *pp = gb_alloc_item(a, CheckerPolyPath); - array_init(pp, a, 0, 16); - return pp; -} - -gb_internal void destroy_checker_poly_path(CheckerPolyPath *pp) { - array_free(pp); - gb_free(heap_allocator(), pp); -} - - -gb_internal void check_poly_path_push(CheckerContext *c, Type *t) { - GB_ASSERT(c->poly_path != nullptr); - GB_ASSERT(t != nullptr); - GB_ASSERT(is_type_polymorphic(t)); - array_add(c->poly_path, t); -} - -gb_internal Type *check_poly_path_pop(CheckerContext *c) { - GB_ASSERT(c->poly_path != nullptr); - return array_pop(c->poly_path); -} - - gb_internal Array proc_group_entities(CheckerContext *c, Operand o) { Array procs = {}; @@ -2878,13 +2823,6 @@ gb_internal ExactValue check_decl_attribute_value(CheckerContext *c, Ast *value) return ev; } -gb_internal Type *check_decl_attribute_type(CheckerContext *c, Ast *value) { - if (value != nullptr) { - return check_type(c, value); - } - return nullptr; -} - #define ATTRIBUTE_USER_TAG_NAME "tag" diff --git a/src/checker.hpp b/src/checker.hpp index e1efd5b89..58f6a027c 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -397,8 +397,6 @@ struct CheckerContext { CheckerTypePath *type_path; isize type_level; // TODO(bill): Actually handle correctly - CheckerPolyPath *poly_path; - isize poly_level; // TODO(bill): Actually handle correctly UntypedExprInfoMap *untyped; @@ -489,12 +487,6 @@ gb_internal void destroy_checker_type_path(CheckerTypePath *tp); gb_internal void check_type_path_push(CheckerContext *c, Entity *e); gb_internal Entity *check_type_path_pop (CheckerContext *c); -gb_internal CheckerPolyPath *new_checker_poly_path(); -gb_internal void destroy_checker_poly_path(CheckerPolyPath *); - -gb_internal void check_poly_path_push(CheckerContext *c, Type *t); -gb_internal Type *check_poly_path_pop (CheckerContext *c); - gb_internal void init_core_context(Checker *c); gb_internal void init_mem_allocator(Checker *c); diff --git a/src/common.cpp b/src/common.cpp index 09203e633..3624446f1 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -50,6 +50,10 @@ gb_internal void debugf(char const *fmt, ...); #include "string.cpp" #include "range_cache.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif gb_internal gb_inline bool is_power_of_two(i64 x) { if (x <= 0) { @@ -900,3 +904,8 @@ gb_internal Slice did_you_mean_results(DidYouMeanAnswers *d) } return slice_array(d->distances, 0, count); } + + +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/docs.cpp b/src/docs.cpp index 33b1e8361..b1efa2b46 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -85,15 +85,6 @@ gb_internal void print_doc_line(i32 indent, char const *fmt, ...) { va_end(va); gb_printf("\n"); } -gb_internal void print_doc_line_no_newline(i32 indent, char const *fmt, ...) { - while (indent --> 0) { - gb_printf("\t"); - } - va_list va; - va_start(va, fmt); - gb_printf_va(fmt, va); - va_end(va); -} gb_internal void print_doc_line_no_newline(i32 indent, String const &data) { while (indent --> 0) { gb_printf("\t"); diff --git a/src/entity.cpp b/src/entity.cpp index 6a3a69950..0605a293a 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -404,14 +404,6 @@ gb_internal Entity *alloc_entity_proc_group(Scope *scope, Token token, Type *typ return entity; } - -gb_internal Entity *alloc_entity_builtin(Scope *scope, Token token, Type *type, i32 id) { - Entity *entity = alloc_entity(Entity_Builtin, scope, token, type); - entity->Builtin.id = id; - entity->state = EntityState_Resolved; - return entity; -} - gb_internal Entity *alloc_entity_import_name(Scope *scope, Token token, Type *type, String path, String name, Scope *import_scope) { Entity *entity = alloc_entity(Entity_ImportName, scope, token, type); diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 453909a15..f4c85505d 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -15,16 +15,6 @@ struct Quaternion256 { f64 imag, jmag, kmag, real; }; -gb_internal Quaternion256 quaternion256_inverse(Quaternion256 x) { - f64 invmag2 = 1.0 / (x.real*x.real + x.imag*x.imag + x.jmag*x.jmag + x.kmag*x.kmag); - x.real = +x.real * invmag2; - x.imag = -x.imag * invmag2; - x.jmag = -x.jmag * invmag2; - x.kmag = -x.kmag * invmag2; - return x; -} - - enum ExactValueKind { ExactValue_Invalid = 0, @@ -453,44 +443,44 @@ gb_internal ExactValue exact_value_kmag(ExactValue v) { return r; } -gb_internal ExactValue exact_value_make_imag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_complex(0, exact_value_to_float(v).value_float); - case ExactValue_Float: - return exact_value_complex(0, v.value_float); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} - -gb_internal ExactValue exact_value_make_jmag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); - case ExactValue_Float: - return exact_value_quaternion(0, 0, v.value_float, 0); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} - -gb_internal ExactValue exact_value_make_kmag(ExactValue v) { - switch (v.kind) { - case ExactValue_Integer: - return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); - case ExactValue_Float: - return exact_value_quaternion(0, 0, 0, v.value_float); - default: - GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); - } - ExactValue r = {ExactValue_Invalid}; - return r; -} +// gb_internal ExactValue exact_value_make_imag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_complex(0, exact_value_to_float(v).value_float); +// case ExactValue_Float: +// return exact_value_complex(0, v.value_float); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_imag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } + +// gb_internal ExactValue exact_value_make_jmag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_quaternion(0, 0, exact_value_to_float(v).value_float, 0); +// case ExactValue_Float: +// return exact_value_quaternion(0, 0, v.value_float, 0); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_jmag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } + +// gb_internal ExactValue exact_value_make_kmag(ExactValue v) { +// switch (v.kind) { +// case ExactValue_Integer: +// return exact_value_quaternion(0, 0, 0, exact_value_to_float(v).value_float); +// case ExactValue_Float: +// return exact_value_quaternion(0, 0, 0, v.value_float); +// default: +// GB_PANIC("Expected an integer or float type for 'exact_value_make_kmag'"); +// } +// ExactValue r = {ExactValue_Invalid}; +// return r; +// } gb_internal i64 exact_value_to_i64(ExactValue v) { v = exact_value_to_integer(v); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index ca4b3b683..c5bc96eb9 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -605,11 +605,11 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) { return {p->value, p->type}; } -gb_internal void lb_debug_print(lbProcedure *p, String const &str) { - auto args = array_make(heap_allocator(), 1); - args[0] = lb_const_string(p->module, str); - lb_emit_runtime_call(p, "print_string", args); -} +// gb_internal void lb_debug_print(lbProcedure *p, String const &str) { +// auto args = array_make(heap_allocator(), 1); +// args[0] = lb_const_string(p->module, str); +// lb_emit_runtime_call(p, "print_string", args); +// } gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) { GB_ASSERT(build_context.use_static_map_calls); diff --git a/src/llvm_backend_debug.cpp b/src/llvm_backend_debug.cpp index 849416579..55c4370a2 100644 --- a/src/llvm_backend_debug.cpp +++ b/src/llvm_backend_debug.cpp @@ -14,12 +14,6 @@ gb_internal void lb_set_llvm_metadata(lbModule *m, void *key, LLVMMetadataRef va } } -gb_internal LLVMMetadataRef lb_get_llvm_file_metadata_from_node(lbModule *m, Ast *node) { - if (node == nullptr) { - return nullptr; - } - return lb_get_llvm_metadata(m, node->file()); -} gb_internal LLVMMetadataRef lb_get_current_debug_scope(lbProcedure *p) { GB_ASSERT_MSG(p->debug_info != nullptr, "missing debug information for %.*s", LIT(p->name)); diff --git a/src/llvm_backend_general.cpp b/src/llvm_backend_general.cpp index f30038da8..e5aa95f10 100644 --- a/src/llvm_backend_general.cpp +++ b/src/llvm_backend_general.cpp @@ -272,12 +272,6 @@ gb_internal lbValue lb_emit_epi(lbModule *m, lbValue const &value, isize index) gb_internal LLVMValueRef llvm_zero(lbModule *m) { return LLVMConstInt(lb_type(m, t_int), 0, false); } -gb_internal LLVMValueRef llvm_zero32(lbModule *m) { - return LLVMConstInt(lb_type(m, t_i32), 0, false); -} -gb_internal LLVMValueRef llvm_one(lbModule *m) { - return LLVMConstInt(lb_type(m, t_i32), 1, false); -} gb_internal LLVMValueRef llvm_alloca(lbProcedure *p, LLVMTypeRef llvm_type, isize alignment, char const *name) { LLVMPositionBuilderAtEnd(p->builder, p->decl_block->block); @@ -874,14 +868,6 @@ gb_internal void lb_addr_store(lbProcedure *p, lbAddr addr, lbValue value) { lb_emit_store(p, addr.addr, value); } -gb_internal void lb_const_store(lbValue ptr, lbValue value) { - GB_ASSERT(lb_is_const(ptr)); - GB_ASSERT(lb_is_const(value)); - GB_ASSERT(is_type_pointer(ptr.type)); - LLVMSetInitializer(ptr.value, value.value); -} - - gb_internal bool lb_is_type_proc_recursive(Type *t) { for (;;) { if (t == nullptr) { @@ -1327,21 +1313,6 @@ gb_internal void lb_clone_struct_type(LLVMTypeRef dst, LLVMTypeRef src) { LLVMStructSetBody(dst, fields, field_count, LLVMIsPackedStruct(src)); } -gb_internal LLVMTypeRef lb_alignment_prefix_type_hack(lbModule *m, i64 alignment) { - switch (alignment) { - case 1: - return LLVMArrayType(lb_type(m, t_u8), 0); - case 2: - return LLVMArrayType(lb_type(m, t_u16), 0); - case 4: - return LLVMArrayType(lb_type(m, t_u32), 0); - case 8: - return LLVMArrayType(lb_type(m, t_u64), 0); - default: case 16: - return LLVMArrayType(LLVMVectorType(lb_type(m, t_u32), 4), 0); - } -} - gb_internal String lb_mangle_name(lbModule *m, Entity *e) { String name = e->token.string; @@ -2202,9 +2173,6 @@ gb_internal void lb_add_member(lbModule *m, String const &name, lbValue val) { string_map_set(&m->members, name, val); } } -gb_internal void lb_add_member(lbModule *m, StringHashKey const &key, lbValue val) { - string_map_set(&m->members, key, val); -} gb_internal void lb_add_procedure_value(lbModule *m, lbProcedure *p) { if (p->entity != nullptr) { map_set(&m->procedure_values, p->value, p->entity); @@ -2493,42 +2461,6 @@ gb_internal lbValue lb_find_or_add_entity_string(lbModule *m, String const &str) return res; } -gb_internal lbValue lb_find_or_add_entity_string_byte_slice(lbModule *m, String const &str) { - LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; - LLVMValueRef data = LLVMConstStringInContext(m->ctx, - cast(char const *)str.text, - cast(unsigned)str.len, - false); - - - char *name = nullptr; - { - isize max_len = 7+8+1; - name = gb_alloc_array(permanent_allocator(), char, max_len); - u32 id = m->gen->global_array_index.fetch_add(1); - isize len = gb_snprintf(name, max_len, "csbs$%x", id); - len -= 1; - } - LLVMTypeRef type = LLVMTypeOf(data); - LLVMValueRef global_data = LLVMAddGlobal(m->mod, type, name); - LLVMSetInitializer(global_data, data); - lb_make_global_private_const(global_data); - LLVMSetAlignment(global_data, 1); - - LLVMValueRef ptr = nullptr; - if (str.len != 0) { - ptr = LLVMConstInBoundsGEP2(type, global_data, indices, 2); - } else { - ptr = LLVMConstNull(lb_type(m, t_u8_ptr)); - } - LLVMValueRef len = LLVMConstInt(lb_type(m, t_int), str.len, true); - LLVMValueRef values[2] = {ptr, len}; - - lbValue res = {}; - res.value = llvm_const_named_struct(m, t_u8_slice, values, 2); - res.type = t_u8_slice; - return res; -} gb_internal lbValue lb_find_or_add_entity_string_byte_slice_with_type(lbModule *m, String const &str, Type *slice_type) { GB_ASSERT(is_type_slice(slice_type)); LLVMValueRef indices[2] = {llvm_zero(m), llvm_zero(m)}; diff --git a/src/llvm_backend_opt.cpp b/src/llvm_backend_opt.cpp index 533264e62..fd6d94361 100644 --- a/src/llvm_backend_opt.cpp +++ b/src/llvm_backend_opt.cpp @@ -37,16 +37,16 @@ gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i3 gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level); gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level); -gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { - lbModule *m = cast(lbModule *)user_data; - if (m == nullptr) { - return false; - } - if (value == nullptr) { - return false; - } - return LLVMIsAAllocaInst(value) != nullptr; -} +// gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) { +// lbModule *m = cast(lbModule *)user_data; +// if (m == nullptr) { +// return false; +// } +// if (value == nullptr) { +// return false; +// } +// return LLVMIsAAllocaInst(value) != nullptr; +// } #if LLVM_VERSION_MAJOR < 12 diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 0789fb2c1..384d29ca7 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -383,46 +383,46 @@ gb_internal lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name } -gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { - lbParamPasskind kind = lbParamPass_Value; - - if (e != nullptr && !are_types_identical(abi_type, e->type)) { - if (is_type_pointer(abi_type)) { - GB_ASSERT(e->kind == Entity_Variable); - Type *av = core_type(type_deref(abi_type)); - if (are_types_identical(av, core_type(e->type))) { - kind = lbParamPass_Pointer; - if (e->flags&EntityFlag_Value) { - kind = lbParamPass_ConstRef; - } - } else { - kind = lbParamPass_BitCast; - } - } else if (is_type_integer(abi_type)) { - kind = lbParamPass_Integer; - } else if (abi_type == t_llvm_bool) { - kind = lbParamPass_Value; - } else if (is_type_boolean(abi_type)) { - kind = lbParamPass_Integer; - } else if (is_type_simd_vector(abi_type)) { - kind = lbParamPass_BitCast; - } else if (is_type_float(abi_type)) { - kind = lbParamPass_BitCast; - } else if (is_type_tuple(abi_type)) { - kind = lbParamPass_Tuple; - } else if (is_type_proc(abi_type)) { - kind = lbParamPass_Value; - } else { - GB_PANIC("Invalid abi type pass kind %s", type_to_string(abi_type)); - } - } - - if (kind_) *kind_ = kind; - lbValue res = {}; - res.value = LLVMGetParam(p->value, cast(unsigned)index); - res.type = abi_type; - return res; -} +// gb_internal lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) { +// lbParamPasskind kind = lbParamPass_Value; + +// if (e != nullptr && !are_types_identical(abi_type, e->type)) { +// if (is_type_pointer(abi_type)) { +// GB_ASSERT(e->kind == Entity_Variable); +// Type *av = core_type(type_deref(abi_type)); +// if (are_types_identical(av, core_type(e->type))) { +// kind = lbParamPass_Pointer; +// if (e->flags&EntityFlag_Value) { +// kind = lbParamPass_ConstRef; +// } +// } else { +// kind = lbParamPass_BitCast; +// } +// } else if (is_type_integer(abi_type)) { +// kind = lbParamPass_Integer; +// } else if (abi_type == t_llvm_bool) { +// kind = lbParamPass_Value; +// } else if (is_type_boolean(abi_type)) { +// kind = lbParamPass_Integer; +// } else if (is_type_simd_vector(abi_type)) { +// kind = lbParamPass_BitCast; +// } else if (is_type_float(abi_type)) { +// kind = lbParamPass_BitCast; +// } else if (is_type_tuple(abi_type)) { +// kind = lbParamPass_Tuple; +// } else if (is_type_proc(abi_type)) { +// kind = lbParamPass_Value; +// } else { +// GB_PANIC("Invalid abi type pass kind %s", type_to_string(abi_type)); +// } +// } + +// if (kind_) *kind_ = kind; +// lbValue res = {}; +// res.value = LLVMGetParam(p->value, cast(unsigned)index); +// res.type = abi_type; +// return res; +// } @@ -1165,14 +1165,6 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array c return result; } -gb_internal LLVMValueRef llvm_splat_float(i64 count, LLVMTypeRef type, f64 value) { - LLVMValueRef v = LLVMConstReal(type, value); - LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); - for (i64 i = 0; i < count; i++) { - values[i] = v; - } - return LLVMConstVector(values, cast(unsigned)count); -} gb_internal LLVMValueRef llvm_splat_int(i64 count, LLVMTypeRef type, i64 value, bool is_signed=false) { LLVMValueRef v = LLVMConstInt(type, value, is_signed); LLVMValueRef *values = gb_alloc_array(temporary_allocator(), LLVMValueRef, count); diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp index 66c422071..6400a8a9d 100644 --- a/src/llvm_backend_stmt.cpp +++ b/src/llvm_backend_stmt.cpp @@ -378,16 +378,6 @@ gb_internal lbValue lb_map_cell_index_static(lbProcedure *p, Type *type, lbValue return lb_emit_ptr_offset(p, elems_ptr, data_index); } -gb_internal void lb_map_kvh_data_static(lbProcedure *p, lbValue map_value, lbValue *ks_, lbValue *vs_, lbValue *hs_) { - lbValue capacity = lb_map_cap(p, map_value); - lbValue ks = lb_map_data_uintptr(p, map_value); - lbValue vs = {}; - lbValue hs = {}; - if (ks_) *ks_ = ks; - if (vs_) *vs_ = vs; - if (hs_) *hs_ = hs; -} - gb_internal lbValue lb_map_hash_is_valid(lbProcedure *p, lbValue hash) { // N :: size_of(uintptr)*8 - 1 // (hash != 0) & (hash>>N == 0) diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 94b900278..dbed32b82 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -599,14 +599,6 @@ gb_internal lbValue lb_emit_reverse_bits(lbProcedure *p, lbValue x, Type *type) } -gb_internal lbValue lb_emit_bit_set_card(lbProcedure *p, lbValue x) { - GB_ASSERT(is_type_bit_set(x.type)); - Type *underlying = bit_set_to_int(x.type); - lbValue card = lb_emit_count_ones(p, x, underlying); - return lb_emit_conv(p, card, t_int); -} - - gb_internal lbValue lb_emit_union_cast_only_ok_check(lbProcedure *p, lbValue value, Type *type, TokenPos pos) { GB_ASSERT(is_type_tuple(type)); lbModule *m = p->module; @@ -1493,10 +1485,6 @@ gb_internal lbValue lb_dynamic_array_cap(lbProcedure *p, lbValue da) { GB_ASSERT(is_type_dynamic_array(da.type)); return lb_emit_struct_ev(p, da, 2); } -gb_internal lbValue lb_dynamic_array_allocator(lbProcedure *p, lbValue da) { - GB_ASSERT(is_type_dynamic_array(da.type)); - return lb_emit_struct_ev(p, da, 3); -} gb_internal lbValue lb_map_len(lbProcedure *p, lbValue value) { GB_ASSERT_MSG(is_type_map(value.type) || are_types_identical(value.type, t_raw_map), "%s", type_to_string(value.type)); diff --git a/src/main.cpp b/src/main.cpp index 614130bb6..c7250aa8b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,14 @@ #include "common.cpp" #include "timings.cpp" #include "tokenizer.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif #include "big_int.cpp" +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif #include "exact_value.cpp" #include "build_settings.cpp" @@ -58,7 +65,6 @@ gb_global Timings global_timings = {0}; #endif #endif -#include "query_data.cpp" #include "bug_report.cpp" // NOTE(bill): 'name' is used in debugging and profiling modes @@ -573,7 +579,6 @@ gb_internal void usage(String argv0) { print_usage_line(1, " one must contain the program's entry point, all must be in the same package."); print_usage_line(1, "run same as 'build', but also then runs the newly compiled executable."); print_usage_line(1, "check parse, and type check a directory of .odin files"); - print_usage_line(1, "query parse, type check, and output a .json file containing information about the program"); print_usage_line(1, "strip-semicolon parse, type check, and remove unneeded semicolons from the entire program"); print_usage_line(1, "test build and runs procedures with the attribute @(test) in the initial package"); print_usage_line(1, "doc generate documentation on a directory of .odin files"); @@ -817,12 +822,6 @@ gb_internal bool parse_build_flags(Array args) { add_flag(&build_flags, BuildFlag_UseStaticMapCalls, str_lit("use-static-map-calls"), BuildFlagParam_None, Command__does_check); - - add_flag(&build_flags, BuildFlag_Compact, str_lit("compact"), BuildFlagParam_None, Command_query); - add_flag(&build_flags, BuildFlag_GlobalDefinitions, str_lit("global-definitions"), BuildFlagParam_None, Command_query); - add_flag(&build_flags, BuildFlag_GoToDefinitions, str_lit("go-to-definitions"), BuildFlagParam_None, Command_query); - - add_flag(&build_flags, BuildFlag_Short, str_lit("short"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_AllPackages, str_lit("all-packages"), BuildFlagParam_None, Command_doc); add_flag(&build_flags, BuildFlag_DocFormat, str_lit("doc-format"), BuildFlagParam_None, Command_doc); @@ -1445,39 +1444,6 @@ gb_internal bool parse_build_flags(Array args) { build_context.strict_style_init_only = true; break; } - case BuildFlag_Compact: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -compact flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.compact = true; - } - break; - } - case BuildFlag_GlobalDefinitions: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -global-definitions flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else if (build_context.query_data_set_settings.kind != QueryDataSet_Invalid) { - gb_printf_err("Invalid use of -global-definitions flag, a previous flag for 'odin query' was set\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.kind = QueryDataSet_GlobalDefinitions; - } - break; - } - case BuildFlag_GoToDefinitions: { - if (!build_context.query_data_set_settings.ok) { - gb_printf_err("Invalid use of -go-to-definitions flag, only allowed with 'odin query'\n"); - bad_flags = true; - } else if (build_context.query_data_set_settings.kind != QueryDataSet_Invalid) { - gb_printf_err("Invalid use of -global-definitions flag, a previous flag for 'odin query' was set\n"); - bad_flags = true; - } else { - build_context.query_data_set_settings.kind = QueryDataSet_GoToDefinitions; - } - break; - } case BuildFlag_Short: build_context.cmd_doc_flags |= CmdDocFlag_Short; break; @@ -1638,16 +1604,6 @@ gb_internal bool parse_build_flags(Array args) { gb_printf_err("`-export-timings:` requires `-show-timings` or `-show-more-timings` to be present\n"); bad_flags = true; } - - if (build_context.query_data_set_settings.ok) { - if (build_context.query_data_set_settings.kind == QueryDataSet_Invalid) { - gb_printf_err("'odin query' requires a flag determining the kind of query data set to be returned\n"); - gb_printf_err("\t-global-definitions : outputs a JSON file of global definitions\n"); - gb_printf_err("\t-go-to-definitions : outputs a OGTD binary file of go to definitions for identifiers within an Odin project\n"); - bad_flags = true; - } - } - return !bad_flags; } @@ -1931,8 +1887,6 @@ gb_internal void print_show_help(String const arg0, String const &command) { print_usage_line(3, "odin check filename.odin -file # Type check single-file package, must contain entry point."); } else if (command == "test") { print_usage_line(1, "test Build ands runs procedures with the attribute @(test) in the initial package"); - } else if (command == "query") { - print_usage_line(1, "query [experimental] Parse, type check, and output a .json file containing information about the program"); } else if (command == "doc") { print_usage_line(1, "doc generate documentation from a directory of .odin files"); print_usage_line(2, "Examples:"); @@ -2627,15 +2581,6 @@ int main(int arg_count, char const **arg_ptr) { build_context.command_kind = Command_strip_semicolon; build_context.no_output_files = true; init_filename = args[2]; - } else if (command == "query") { - if (args.count < 3) { - usage(args[0]); - return 1; - } - build_context.command_kind = Command_query; - build_context.no_output_files = true; - build_context.query_data_set_settings.ok = true; - init_filename = args[2]; } else if (command == "doc") { if (args.count < 3) { usage(args[0]); @@ -2824,12 +2769,8 @@ int main(int arg_count, char const **arg_ptr) { print_show_unused(checker); } - if (build_context.query_data_set_settings.ok) { - generate_and_print_query_data(checker, &global_timings); - } else { - if (build_context.show_timings) { - show_timings(checker, &global_timings); - } + if (build_context.show_timings) { + show_timings(checker, &global_timings); } if (global_error_collector.count != 0) { diff --git a/src/parser.cpp b/src/parser.cpp index 1606f5b47..2ccdac7fa 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -237,9 +237,6 @@ gb_internal Ast *clone_ast(Ast *node) { case Ast_ExprStmt: n->ExprStmt.expr = clone_ast(n->ExprStmt.expr); break; - case Ast_TagStmt: - n->TagStmt.stmt = clone_ast(n->TagStmt.stmt); - break; case Ast_AssignStmt: n->AssignStmt.lhs = clone_ast_array(n->AssignStmt.lhs); n->AssignStmt.rhs = clone_ast_array(n->AssignStmt.rhs); @@ -497,14 +494,6 @@ gb_internal Ast *ast_tag_expr(AstFile *f, Token token, Token name, Ast *expr) { return result; } -gb_internal Ast *ast_tag_stmt(AstFile *f, Token token, Token name, Ast *stmt) { - Ast *result = alloc_ast_node(f, Ast_TagStmt); - result->TagStmt.token = token; - result->TagStmt.name = name; - result->TagStmt.stmt = stmt; - return result; -} - gb_internal Ast *ast_unary_expr(AstFile *f, Token op, Ast *expr) { Ast *result = alloc_ast_node(f, Ast_UnaryExpr); result->UnaryExpr.op = op; @@ -1308,16 +1297,6 @@ gb_internal Token advance_token(AstFile *f) { return prev; } -gb_internal bool peek_token_kind(AstFile *f, TokenKind kind) { - for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { - Token tok = f->tokens[i]; - if (kind != Token_Comment && tok.kind == Token_Comment) { - continue; - } - return tok.kind == kind; - } - return false; -} gb_internal Token peek_token(AstFile *f) { for (isize i = f->curr_token_index+1; i < f->tokens.count; i++) { @@ -1440,17 +1419,6 @@ gb_internal Token expect_operator(AstFile *f) { return prev; } -gb_internal Token expect_keyword(AstFile *f) { - Token prev = f->curr_token; - if (!gb_is_between(prev.kind, Token__KeywordBegin+1, Token__KeywordEnd-1)) { - String p = token_to_string(prev); - syntax_error(f->curr_token, "Expected a keyword, got '%.*s'", - LIT(p)); - } - advance_token(f); - return prev; -} - gb_internal bool allow_token(AstFile *f, TokenKind kind) { Token prev = f->curr_token; if (prev.kind == kind) { @@ -1957,10 +1925,6 @@ gb_internal bool ast_on_same_line(Token const &x, Ast *yp) { return x.pos.line == y.pos.line; } -gb_internal bool ast_on_same_line(Ast *x, Ast *y) { - return ast_on_same_line(ast_token(x), y); -} - gb_internal Ast *parse_force_inlining_operand(AstFile *f, Token token) { Ast *expr = parse_unary_expr(f, false); Ast *e = strip_or_return_expr(expr); diff --git a/src/parser.hpp b/src/parser.hpp index a2d2c038e..f7b3e51ae 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -457,11 +457,6 @@ AST_KIND(_StmtBegin, "", bool) \ AST_KIND(BadStmt, "bad statement", struct { Token begin, end; }) \ AST_KIND(EmptyStmt, "empty statement", struct { Token token; }) \ AST_KIND(ExprStmt, "expression statement", struct { Ast *expr; } ) \ - AST_KIND(TagStmt, "tag statement", struct { \ - Token token; \ - Token name; \ - Ast * stmt; \ - }) \ AST_KIND(AssignStmt, "assign statement", struct { \ Token op; \ Slice lhs, rhs; \ diff --git a/src/parser_pos.cpp b/src/parser_pos.cpp index 19a525e2e..fb7f0c9c2 100644 --- a/src/parser_pos.cpp +++ b/src/parser_pos.cpp @@ -53,7 +53,6 @@ gb_internal Token ast_token(Ast *node) { case Ast_BadStmt: return node->BadStmt.begin; case Ast_EmptyStmt: return node->EmptyStmt.token; case Ast_ExprStmt: return ast_token(node->ExprStmt.expr); - case Ast_TagStmt: return node->TagStmt.token; case Ast_AssignStmt: return node->AssignStmt.op; case Ast_BlockStmt: return node->BlockStmt.open; case Ast_IfStmt: return node->IfStmt.token; @@ -197,7 +196,6 @@ Token ast_end_token(Ast *node) { case Ast_BadStmt: return node->BadStmt.end; case Ast_EmptyStmt: return node->EmptyStmt.token; case Ast_ExprStmt: return ast_end_token(node->ExprStmt.expr); - case Ast_TagStmt: return ast_end_token(node->TagStmt.stmt); case Ast_AssignStmt: if (node->AssignStmt.rhs.count > 0) { return ast_end_token(node->AssignStmt.rhs[node->AssignStmt.rhs.count-1]); diff --git a/src/query_data.cpp b/src/query_data.cpp deleted file mode 100644 index 86487a058..000000000 --- a/src/query_data.cpp +++ /dev/null @@ -1,1030 +0,0 @@ -struct QueryValue; -struct QueryValuePair; - -gb_global gbAllocator query_value_allocator = {}; - -enum QueryKind { - Query_Invalid, - Query_String, - Query_Boolean, - Query_Integer, - Query_Float, - Query_Array, - Query_Map, -}; - -struct QueryValuePair { - String key; - QueryValue *value; -}; - - -struct QueryValue { - QueryKind kind; - bool packed; -}; - -struct QueryValueString : QueryValue { - QueryValueString(String const &v) { - kind = Query_String; - value = v; - packed = false; - } - String value; -}; - -struct QueryValueBoolean : QueryValue { - QueryValueBoolean(bool v) { - kind = Query_Boolean; - value = v; - packed = false; - } - bool value; -}; - -struct QueryValueInteger : QueryValue { - QueryValueInteger(i64 v) { - kind = Query_Integer; - value = v; - packed = false; - } - i64 value; -}; - -struct QueryValueFloat : QueryValue { - QueryValueFloat(f64 v) { - kind = Query_Float; - value = v; - packed = false; - } - f64 value; -}; - -struct QueryValueArray : QueryValue { - QueryValueArray() { - kind = Query_Array; - array_init(&value, query_value_allocator); - packed = false; - } - QueryValueArray(Array const &v) { - kind = Query_Array; - value = v; - packed = false; - } - Array value; - - void reserve(isize cap) { - array_reserve(&value, cap); - } - void add(QueryValue *v) { - array_add(&value, v); - } - void add(char const *v) { - add(make_string_c(cast(char *)v)); - } - void add(String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(val); - } - void add(bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(val); - } - void add(i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(val); - } - void add(f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(val); - } -}; - -struct QueryValueMap : QueryValue { - QueryValueMap() { - kind = Query_Map; - array_init(&value, query_value_allocator); - packed = false; - } - QueryValueMap(Array const &v) { - kind = Query_Map; - value = v; - packed = false; - } - Array value; - - - void reserve(isize cap) { - array_reserve(&value, cap); - } - void add(char const *k, QueryValue *v) { - add(make_string_c(cast(char *)k), v); - } - void add(String const &k, QueryValue *v) { - QueryValuePair kv = {k, v}; - array_add(&value, kv); - } - - void add(char const *k, String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(k, val); - } - void add(char const *k, char const *v) { - add(k, make_string_c(cast(char *)v)); - } - void add(char const *k, bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(k, val); - } - void add(char const *k, i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(k, val); - } - void add(char const *k, f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(k, val); - } - void add(String const &k, String const &v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueString); - *val = QueryValueString(v); - add(k, val); - } - void add(String const &k, char const *v) { - add(k, make_string_c(cast(char *)v)); - } - void add(String const &k, bool v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueBoolean); - *val = QueryValueBoolean(v); - add(k, val); - } - void add(String const &k, i64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueInteger); - *val = QueryValueInteger(v); - add(k, val); - } - void add(String const &k, f64 v) { - auto val = gb_alloc_item(query_value_allocator, QueryValueFloat); - *val = QueryValueFloat(v); - add(k, val); - } -}; - - -#define DEF_QUERY_PROC(TYPE, VALUETYPE, NAME) TYPE *NAME(VALUETYPE value) { \ - auto v = gb_alloc_item(query_value_allocator, TYPE); \ - *v = TYPE(value); \ - return v; \ -} -#define DEF_QUERY_PROC0(TYPE, NAME) TYPE *NAME() { \ - auto v = gb_alloc_item(query_value_allocator, TYPE); \ - *v = TYPE(); \ - return v; \ -} - -gb_internal DEF_QUERY_PROC(QueryValueString, String const &, query_value_string); -gb_internal DEF_QUERY_PROC(QueryValueBoolean, bool, query_value_boolean); -gb_internal DEF_QUERY_PROC(QueryValueInteger, i64, query_value_integer); -gb_internal DEF_QUERY_PROC(QueryValueFloat, f64, query_value_float); -gb_internal DEF_QUERY_PROC(QueryValueArray, Array const &, query_value_array); -gb_internal DEF_QUERY_PROC(QueryValueMap, Array const &, query_value_map); -gb_internal DEF_QUERY_PROC0(QueryValueArray, query_value_array); -gb_internal DEF_QUERY_PROC0(QueryValueMap, query_value_map); - -gb_internal isize qprintf(bool format, isize indent, char const *fmt, ...) { - if (format) while (indent --> 0) { - gb_printf("\t"); - } - va_list va; - va_start(va, fmt); - isize res = gb_printf_va(fmt, va); - va_end(va); - return res; -} - -gb_internal bool qv_valid_char(u8 c) { - if (c >= 0x80) { - return false; - } - - switch (c) { - case '\"': - case '\n': - case '\r': - case '\t': - case '\v': - case '\f': - return false; - } - - return true; -} - -gb_internal void print_query_data_as_json(QueryValue *value, bool format = true, isize indent = 0) { - if (value == nullptr) { - gb_printf("null"); - return; - } - switch (value->kind) { - case Query_String: { - auto v = cast(QueryValueString *)value; - String name = v->value; - isize extra = 0; - for (isize i = 0; i < name.len; i++) { - u8 c = name[i]; - if (!qv_valid_char(c)) { - extra += 5; - } - } - - if (extra == 0) { - gb_printf("\"%.*s\"", LIT(name)); - return; - } - - char const hex_table[] = "0123456789ABCDEF"; - isize buf_len = name.len + extra + 2 + 1; - - u8 *buf = gb_alloc_array(temporary_allocator(), u8, buf_len); - - isize j = 0; - - for (isize i = 0; i < name.len; i++) { - u8 c = name[i]; - if (qv_valid_char(c)) { - buf[j+0] = c; - j += 1; - } else if (c == '"') { - buf[j+0] = '\\'; - buf[j+1] = '\"'; - j += 2; - } else { - switch (c) { - case '\n': buf[j+0] = '\\'; buf[j+1] = 'n'; j += 2; break; - case '\r': buf[j+0] = '\\'; buf[j+1] = 'r'; j += 2; break; - case '\t': buf[j+0] = '\\'; buf[j+1] = 't'; j += 2; break; - case '\v': buf[j+0] = '\\'; buf[j+1] = 'v'; j += 2; break; - case '\f': - default: - buf[j+0] = '\\'; - buf[j+1] = hex_table[0]; - buf[j+2] = hex_table[0]; - buf[j+3] = hex_table[c >> 4]; - buf[j+4] = hex_table[c & 0x0f]; - j += 5; - break; - } - } - } - - gb_printf("\"%s\"", buf); - return; - } - case Query_Boolean: { - auto v = cast(QueryValueBoolean *)value; - if (v->value) { - gb_printf("true"); - } else { - gb_printf("false"); - } - return; - } - case Query_Integer: { - auto v = cast(QueryValueInteger *)value; - gb_printf("%lld", cast(long long)v->value); - return; - } - case Query_Float: { - auto v = cast(QueryValueFloat *)value; - gb_printf("%f", v->value); - return; - } - case Query_Array: { - auto v = cast(QueryValueArray *)value; - if (v->value.count > 0) { - bool ff = format && !v->packed; - gb_printf("["); - if (ff) gb_printf("\n"); - for_array(i, v->value) { - qprintf(ff, indent+1, ""); - print_query_data_as_json(v->value[i], ff, indent+1); - if (i < v->value.count-1) { - gb_printf(","); - if (!ff && format) { - gb_printf(" "); - } - } - if (ff) gb_printf("\n"); - } - qprintf(ff, indent, "]"); - } else { - gb_printf("[]"); - } - return; - } - case Query_Map: { - auto v = cast(QueryValueMap *)value; - if (v->value.count > 0) { - bool ff = format && !v->packed; - gb_printf("{"); - if (ff) gb_printf("\n"); - for_array(i, v->value) { - auto kv = v->value[i]; - qprintf(ff, indent+1, "\"%.*s\":", LIT(kv.key)); - if (format) gb_printf(" "); - print_query_data_as_json(kv.value, ff, indent+1); - if (i < v->value.count-1) { - gb_printf(","); - if (!ff && format) { - gb_printf(" "); - } - } - if (ff) gb_printf("\n"); - } - qprintf(ff, indent, "}"); - } else { - gb_printf("{}"); - } - return; - } - } -} - - - -gb_internal int query_data_package_compare(void const *a, void const *b) { - AstPackage *x = *cast(AstPackage *const *)a; - AstPackage *y = *cast(AstPackage *const *)b; - - if (x == y) { - return 0; - } - - if (x != nullptr && y != nullptr) { - return string_compare(x->name, y->name); - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - return 0; -} - -gb_internal int query_data_definition_compare(void const *a, void const *b) { - Entity *x = *cast(Entity *const *)a; - Entity *y = *cast(Entity *const *)b; - - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - - if (x->pkg != y->pkg) { - i32 res = query_data_package_compare(&x->pkg, &y->pkg); - if (res != 0) { - return res; - } - } - - return string_compare(x->token.string, y->token.string); -} - -gb_internal int entity_name_compare(void const *a, void const *b) { - Entity *x = *cast(Entity *const *)a; - Entity *y = *cast(Entity *const *)b; - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - return string_compare(x->token.string, y->token.string); -} - - -gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings); -gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c); - -gb_internal void generate_and_print_query_data(Checker *c, Timings *timings) { - query_value_allocator = heap_allocator(); - switch (build_context.query_data_set_settings.kind) { - case QueryDataSet_GlobalDefinitions: - generate_and_print_query_data_global_definitions(c, timings); - return; - case QueryDataSet_GoToDefinitions: - generate_and_print_query_data_go_to_definitions(c); - return; - } -} - - -gb_internal void generate_and_print_query_data_global_definitions(Checker *c, Timings *timings) { - auto *root = query_value_map(); - - if (global_error_collector.errors.count > 0) { - auto *errors = query_value_array(); - root->add("errors", errors); - for_array(i, global_error_collector.errors) { - String err = string_trim_whitespace(global_error_collector.errors[i]); - errors->add(err); - } - - } - - { // Packages - auto *packages = query_value_array(); - root->add("packages", packages); - - auto sorted_packages = array_make(query_value_allocator, 0, c->info.packages.entries.count); - defer (array_free(&sorted_packages)); - - for (auto const &entry : c->info.packages) { - AstPackage *pkg = entry.value; - if (pkg != nullptr) { - array_add(&sorted_packages, pkg); - } - } - gb_sort_array(sorted_packages.data, sorted_packages.count, query_data_package_compare); - packages->reserve(sorted_packages.count); - - for_array(i, sorted_packages) { - AstPackage *pkg = sorted_packages[i]; - String name = pkg->name; - String fullpath = pkg->fullpath; - - auto *files = query_value_array(); - files->reserve(pkg->files.count); - for_array(j, pkg->files) { - AstFile *f = pkg->files[j]; - files->add(f->fullpath); - } - - auto *package = query_value_map(); - package->reserve(3); - packages->add(package); - - package->add("name", pkg->name); - package->add("fullpath", pkg->fullpath); - package->add("files", files); - } - } - - if (c->info.definitions.count > 0) { - auto *definitions = query_value_array(); - root->add("definitions", definitions); - - auto sorted_definitions = array_make(query_value_allocator, 0, c->info.definitions.count); - defer (array_free(&sorted_definitions)); - - for_array(i, c->info.definitions) { - Entity *e = c->info.definitions[i]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - if ((e->scope->flags & (ScopeFlag_Pkg|ScopeFlag_File)) == 0) { - continue; - } - if (e->parent_proc_decl != nullptr) { - continue; - } - switch (e->kind) { - case Entity_Builtin: - case Entity_Nil: - case Entity_Label: - continue; - } - if (e->pkg == nullptr) { - continue; - } - if (e->token.pos.line == 0) { - continue; - } - if (e->kind == Entity_Procedure) { - Type *t = base_type(e->type); - if (t->kind != Type_Proc) { - continue; - } - if (t->Proc.is_poly_specialized) { - continue; - } - } - if (e->kind == Entity_TypeName) { - Type *t = base_type(e->type); - if (t->kind == Type_Struct) { - if (t->Struct.is_poly_specialized) { - continue; - } - } - if (t->kind == Type_Union) { - if (t->Union.is_poly_specialized) { - continue; - } - } - } - - array_add(&sorted_definitions, e); - } - - gb_sort_array(sorted_definitions.data, sorted_definitions.count, query_data_definition_compare); - definitions->reserve(sorted_definitions.count); - - for_array(i, sorted_definitions) { - Entity *e = sorted_definitions[i]; - String name = e->token.string; - - auto *def = query_value_map(); - def->reserve(16); - definitions->add(def); - - def->add("package", e->pkg->name); - def->add("name", name); - def->add("filepath", get_file_path_string(e->token.pos.file_id)); - def->add("line", cast(i64)e->token.pos.line); - def->add("column", cast(i64)e->token.pos.column); - def->add("file_offset", cast(i64)e->token.pos.offset); - - switch (e->kind) { - case Entity_Constant: def->add("kind", str_lit("constant")); break; - case Entity_Variable: def->add("kind", str_lit("variable")); break; - case Entity_TypeName: def->add("kind", str_lit("type name")); break; - case Entity_Procedure: def->add("kind", str_lit("procedure")); break; - case Entity_ProcGroup: def->add("kind", str_lit("procedure group")); break; - case Entity_ImportName: def->add("kind", str_lit("import name")); break; - case Entity_LibraryName: def->add("kind", str_lit("library name")); break; - default: GB_PANIC("Invalid entity kind to be added"); - } - - - if (e->type != nullptr && e->type != t_invalid) { - Type *t = e->type; - Type *bt = t; - - switch (e->kind) { - case Entity_TypeName: - if (!e->TypeName.is_type_alias) { - bt = base_type(t); - } - break; - } - - { - gbString str = type_to_string(t); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - def->add("type", type_str); - } - if (t != bt) { - gbString str = type_to_string(bt); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - def->add("base_type", type_str); - } - { - String type_kind = {}; - Type *bt = base_type(t); - switch (bt->kind) { - case Type_Pointer: type_kind = str_lit("pointer"); break; - case Type_Array: type_kind = str_lit("array"); break; - case Type_Slice: type_kind = str_lit("slice"); break; - case Type_DynamicArray: type_kind = str_lit("dynamic array"); break; - case Type_Map: type_kind = str_lit("map"); break; - case Type_Struct: type_kind = str_lit("struct"); break; - case Type_Union: type_kind = str_lit("union"); break; - case Type_Enum: type_kind = str_lit("enum"); break; - case Type_Proc: type_kind = str_lit("procedure"); break; - case Type_BitSet: type_kind = str_lit("bit set"); break; - case Type_SimdVector: type_kind = str_lit("simd vector"); break; - - case Type_Generic: - case Type_Tuple: - GB_PANIC("Invalid definition type"); - break; - } - if (type_kind.len > 0) { - def->add("type_kind", type_kind); - } - } - } - - if (e->kind == Entity_TypeName) { - def->add("size", type_size_of(e->type)); - def->add("align", type_align_of(e->type)); - - - if (is_type_struct(e->type)) { - auto *data = query_value_map(); - data->reserve(6); - - def->add("data", data); - - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Struct); - - if (t->Struct.is_polymorphic) { - data->add("polymorphic", cast(bool)t->Struct.is_polymorphic); - } - if (t->Struct.is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)t->Struct.is_poly_specialized); - } - if (t->Struct.is_packed) { - data->add("packed", cast(bool)t->Struct.is_packed); - } - if (t->Struct.is_raw_union) { - data->add("raw_union", cast(bool)t->Struct.is_raw_union); - } - - auto *fields = query_value_array(); - data->add("fields", fields); - fields->reserve(t->Struct.fields.count); - fields->packed = true; - - for_array(j, t->Struct.fields) { - Entity *e = t->Struct.fields[j]; - String name = e->token.string; - if (is_blank_ident(name)) { - continue; - } - - fields->add(name); - } - } else if (is_type_union(e->type)) { - auto *data = query_value_map(); - data->reserve(4); - - def->add("data", data); - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Union); - - if (t->Union.is_polymorphic) { - data->add("polymorphic", cast(bool)t->Union.is_polymorphic); - } - if (t->Union.is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)t->Union.is_poly_specialized); - } - - auto *variants = query_value_array(); - variants->reserve(t->Union.variants.count); - data->add("variants", variants); - - for_array(j, t->Union.variants) { - Type *vt = t->Union.variants[j]; - - gbString str = type_to_string(vt); - String type_str = make_string(cast(u8 *)str, gb_string_length(str)); - variants->add(type_str); - } - } - } - - if (e->kind == Entity_Procedure) { - Type *t = base_type(e->type); - GB_ASSERT(t->kind == Type_Proc); - - bool is_polymorphic = t->Proc.is_polymorphic; - bool is_poly_specialized = t->Proc.is_poly_specialized; - bool ok = is_polymorphic || is_poly_specialized; - if (ok) { - auto *data = query_value_map(); - data->reserve(4); - - def->add("data", data); - if (is_polymorphic) { - data->add("polymorphic", cast(bool)is_polymorphic); - } - if (is_poly_specialized) { - data->add("polymorphic_specialized", cast(bool)is_poly_specialized); - } - } - } - - if (e->kind == Entity_ProcGroup) { - auto *procedures = query_value_array(); - procedures->reserve(e->ProcGroup.entities.count); - - for_array(j, e->ProcGroup.entities) { - Entity *p = e->ProcGroup.entities[j]; - - auto *procedure = query_value_map(); - procedure->reserve(2); - procedure->packed = true; - - procedures->add(procedure); - - procedure->add("package", p->pkg->name); - procedure->add("name", p->token.string); - } - def->add("procedures", procedures); - } - - DeclInfo *di = e->decl_info; - if (di != nullptr) { - if (di->is_using) { - def->add("using", query_value_boolean(true)); - } - } - } - } - - if (build_context.show_timings) { - Timings *t = timings; - timings__stop_current_section(t); - t->total.finish = time_stamp_time_now(); - isize max_len = gb_min(36, t->total.label.len); - for_array(i, t->sections) { - TimeStamp ts = t->sections[i]; - max_len = gb_max(max_len, ts.label.len); - } - t->total_time_seconds = time_stamp_as_s(t->total, t->freq); - - auto *tims = query_value_map(); - tims->reserve(8); - root->add("timings", tims); - tims->add("time_unit", str_lit("s")); - - tims->add(t->total.label, cast(f64)t->total_time_seconds); - - - Parser *p = c->parser; - if (p != nullptr) { - isize lines = p->total_line_count; - isize tokens = p->total_token_count; - isize files = 0; - isize packages = p->packages.count; - isize total_file_size = 0; - for_array(i, p->packages) { - files += p->packages[i]->files.count; - for_array(j, p->packages[i]->files) { - AstFile *file = p->packages[i]->files[j]; - total_file_size += file->tokenizer.end - file->tokenizer.start; - } - } - - tims->add("total_lines", cast(i64)lines); - tims->add("total_tokens", cast(i64)tokens); - tims->add("total_files", cast(i64)files); - tims->add("total_packages", cast(i64)packages); - tims->add("total_file_size", cast(i64)total_file_size); - - auto *sections = query_value_map(); - sections->reserve(t->sections.count); - tims->add("sections", sections); - for_array(i, t->sections) { - TimeStamp ts = t->sections[i]; - f64 section_time = time_stamp_as_s(ts, t->freq); - - auto *section = query_value_map(); - section->reserve(2); - sections->add(ts.label, section); - section->add("time", cast(f64)section_time); - section->add("total_fraction", cast(f64)(section_time/t->total_time_seconds)); - } - } - } - - - print_query_data_as_json(root, !build_context.query_data_set_settings.compact); - gb_printf("\n"); -} - - - -template -struct BinaryArray { - u32 offset; // Offset in bytes from the top of the file - u32 length; // Number of elements in array of type T -}; - -template -gb_internal Array binary_array_from_data(BinaryArray ba, void *data) { - Array res = {}; - res.data = cast(T *)(cast(u8 *)data + ba.offset); - res.count = ba.length; - res.capacity = ba.length; - return res; -} - -typedef BinaryArray BinaryString; - -struct GoToDefIdent { - u64 use_offset; // offset of identifier use in bytes from the start of the file that contains it - u32 len; // length in bytes of the identifier - u32 def_file_id; - u64 def_offset; // offset of entity definition in bytes from the start of the file that contains it -}; - -struct GoToDefFile { - u32 id; - BinaryString path; - BinaryArray idents; -}; - -struct GoToDefHeader { - u8 magic[4]; // ogtd (odin-go-to-definitions) - u32 version; // 1 - BinaryArray files; -}; - -struct GoToDefFileMap { - AstFile *f; - u32 id; - Array idents; -}; - - -gb_internal int go_to_def_file_map_compare(void const *a, void const *b) { - GoToDefFileMap const *x = cast(GoToDefFileMap const *)a; - GoToDefFileMap const *y = cast(GoToDefFileMap const *)b; - if (x == y) { - return 0; - } else if (x != nullptr && y == nullptr) { - return -1; - } else if (x == nullptr && y != nullptr) { - return +1; - } - if (x->f->id < y->f->id) { - return -1; - } else if (x->f->id > y->f->id) { - return +1; - } - return 0; -} - -gb_internal int quick_ident_compare(void const *a, void const *b) { - Ast *x = *cast(Ast **)a; - Ast *y = *cast(Ast **)b; - - // NOTE(bill): This assumes that the file is same - if (x->Ident.token.pos.offset < y->Ident.token.pos.offset) { - return -1; - } else if (x->Ident.token.pos.offset > y->Ident.token.pos.offset) { - return +1; - } - return 0; -} - - -gb_internal void generate_and_print_query_data_go_to_definitions(Checker *c) { - GB_ASSERT(c->info.allow_identifier_uses); - - gbAllocator a = query_value_allocator; - - isize file_path_memory_needed = 0; - auto files = array_make(a, 0, c->info.files.entries.count); - for (auto const &entry : c->info.files) { - AstFile *f = entry.value; - file_path_memory_needed += f->fullpath.len+1; // add NUL terminator - - - GoToDefFileMap x = {}; - x.f = f; - array_init(&x.idents, a); - array_add(&files, x); - } - gb_sort_array(files.data, files.count, go_to_def_file_map_compare); - - auto file_id_map_to_index = array_make(a, files[files.count-1].f->id + 1); - for_array(i, file_id_map_to_index) { - file_id_map_to_index[i] = -1; - } - for_array(i, files) { - file_id_map_to_index[files[i].f->id] = i; - } - - - - for_array(i, c->info.identifier_uses) { - Ast *ast = c->info.identifier_uses[i]; - GB_ASSERT(ast->kind == Ast_Ident); - TokenPos pos = ast->Ident.token.pos; - Entity *e = ast->Ident.entity; - if (e == nullptr) { - continue; - } - - - AstFile **use_file_found = string_map_get(&c->info.files, get_file_path_string(pos.file_id)); - GB_ASSERT(use_file_found != nullptr); - AstFile *use_file = *use_file_found; - GB_ASSERT(use_file != nullptr); - - if (e->scope == nullptr) { - GB_ASSERT(e->flags & EntityFlag_Field); - continue; - } - if (e->scope->flags & ScopeFlag_Global) { - continue; - } - - isize idx = file_id_map_to_index[use_file->id]; - if (idx >= 0) { - array_add(&files[idx].idents, ast); - } else { - // TODO(bill): Handle invalid map case? - } - } - - for_array(i, files) { - GoToDefFileMap *f = &files[i]; - gb_sort_array(f->idents.data, f->idents.count, quick_ident_compare); - // gb_printf_err("%lld %.*s -> %lld\n", f->f->id, LIT(f->f->fullpath), f->idents.count); - } - - - - isize data_min_size = 0; - - u32 header_offset = cast(u32)data_min_size; gb_unused(header_offset); - data_min_size += gb_size_of(GoToDefHeader); - data_min_size = align_formula_isize(data_min_size, 8); - - u32 file_offset = cast(u32)data_min_size; - data_min_size += gb_size_of(GoToDefFile) * files.count; - data_min_size = align_formula_isize(data_min_size, 8); - - u32 file_path_offset = cast(u32)data_min_size; - data_min_size += file_path_memory_needed; - data_min_size = align_formula_isize(data_min_size, 8); - - u32 idents_offset = cast(u32)data_min_size; - data_min_size += gb_size_of(GoToDefIdent) * c->info.identifier_uses.count; - - - auto data = array_make(a, 0, data_min_size); - defer (array_free(&data)); - - GoToDefHeader header = {}; - gb_memmove(header.magic, "ogtd", 4); - header.version = 1; - header.files.length = cast(u32)files.count; - header.files.offset = file_offset; - - array_add_elems(&data, cast(u8 *)&header, gb_size_of(header)); - - array_resize(&data, data_min_size); - - auto binary_files = binary_array_from_data(header.files, data.data); - - u32 file_path_offset_index = file_path_offset; - u32 idents_offset_index = idents_offset; - for_array(i, files) { - GoToDefFileMap *f_map = &files[i]; - AstFile *f = f_map->f; - binary_files[i].id = cast(u32)f->id; - - binary_files[i].path.offset = file_path_offset_index; - binary_files[i].path.length = cast(u32)f->fullpath.len; - - binary_files[i].idents.offset = idents_offset_index; - binary_files[i].idents.length = cast(u32)f_map->idents.count; - - auto path = binary_array_from_data(binary_files[i].path, data.data); - gb_memmove(path.data, f->fullpath.text, f->fullpath.len); - path.data[f->fullpath.len] = 0; - - - auto idents = binary_array_from_data(binary_files[i].idents, data.data); - for_array(j, f_map->idents) { - Ast *ast = f_map->idents[j]; - GB_ASSERT(ast->kind == Ast_Ident); - - Entity *e = ast->Ident.entity; - TokenPos def = e->token.pos; - AstFile *def_file = e->file; - - if (def_file == nullptr) { - auto *def_file_found = string_map_get(&c->info.files, get_file_path_string(e->token.pos.file_id)); - if (def_file_found == nullptr) { - continue; - } - def_file = *def_file_found; - } - - isize file_index = file_id_map_to_index[def_file->id]; - GB_ASSERT(file_index >= 0); - - idents[j].use_offset = cast(u64)ast->Ident.token.pos.offset; - idents[j].len = cast(u32)ast->Ident.token.string.len; - idents[j].def_file_id = cast(u32)def_file->id; - idents[j].def_offset = cast(u64)e->token.pos.offset; - - // gb_printf_err("%llu %llu %llu %llu\n", idents[j].len, idents[j].use_offset, idents[j].def_file_id, idents[j].def_offset); - } - - file_path_offset_index += cast(u32)(f->fullpath.len + 1); - idents_offset_index += cast(u32)(f_map->idents.count * gb_size_of(GoToDefIdent)); - } - - - gb_file_write(gb_file_get_standard(gbFileStandard_Output), data.data, data.count*gb_size_of(*data.data)); -} - diff --git a/src/range_cache.cpp b/src/range_cache.cpp index 1f98c4b9e..fc85e2a2e 100644 --- a/src/range_cache.cpp +++ b/src/range_cache.cpp @@ -59,12 +59,12 @@ gb_internal bool range_cache_add_range(RangeCache *c, i64 lo, i64 hi) { } -gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { - for_array(i, c->ranges) { - RangeValue v = c->ranges[i]; - if (v.lo <= index && index <= v.hi) { - return true; - } - } - return false; -} +// gb_internal bool range_cache_index_exists(RangeCache *c, i64 index) { +// for_array(i, c->ranges) { +// RangeValue v = c->ranges[i]; +// if (v.lo <= index && index <= v.hi) { +// return true; +// } +// } +// return false; +// } diff --git a/src/string.cpp b/src/string.cpp index aeb31c7b0..8cce0f1ef 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -89,14 +89,6 @@ gb_internal char *alloc_cstring(gbAllocator a, String s) { return c_str; } -gb_internal char *cstring_duplicate(gbAllocator a, char const *s) { - isize len = gb_strlen(s); - char *c_str = gb_alloc_array(a, char, len+1); - gb_memmove(c_str, s, len); - c_str[len] = '\0'; - return c_str; -} - gb_internal gb_inline bool str_eq_ignore_case(String const &a, String const &b) { @@ -166,12 +158,6 @@ gb_internal isize string_index_byte(String const &s, u8 x) { return -1; } -gb_internal GB_COMPARE_PROC(string_cmp_proc) { - String x = *(String *)a; - String y = *(String *)b; - return string_compare(x, y); -} - gb_internal gb_inline bool str_eq(String const &a, String const &b) { if (a.len != b.len) return false; return memcmp(a.text, b.text, a.len) == 0; diff --git a/src/string_map.cpp b/src/string_map.cpp index e289d4c9b..9f9374ece 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -18,8 +18,6 @@ gb_internal gb_inline bool string_hash_key_equal(StringHashKey const &a, StringH } return false; } -gb_internal bool operator==(StringHashKey const &a, StringHashKey const &b) { return string_hash_key_equal(a, b); } -gb_internal bool operator!=(StringHashKey const &a, StringHashKey const &b) { return !string_hash_key_equal(a, b); } template struct StringMapEntry { diff --git a/src/threading.cpp b/src/threading.cpp index 511d1b477..b74d087b4 100644 --- a/src/threading.cpp +++ b/src/threading.cpp @@ -1,6 +1,10 @@ #if defined(GB_SYSTEM_LINUX) #include #endif +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(push) + #pragma warning(disable: 4505) +#endif struct BlockingMutex; struct RecursiveMutex; @@ -269,48 +273,6 @@ struct MutexGuard { } #endif - - -struct Barrier { - BlockingMutex mutex; - Condition cond; - isize index; - isize generation_id; - isize thread_count; -}; - -gb_internal void barrier_init(Barrier *b, isize thread_count) { - mutex_init(&b->mutex); - condition_init(&b->cond); - b->index = 0; - b->generation_id = 0; - b->thread_count = 0; -} - -gb_internal void barrier_destroy(Barrier *b) { - condition_destroy(&b->cond); - mutex_destroy(&b->mutex); -} - -// Returns true if it is the leader -gb_internal bool barrier_wait(Barrier *b) { - mutex_lock(&b->mutex); - defer (mutex_unlock(&b->mutex)); - isize local_gen = b->generation_id; - b->index += 1; - if (b->index < b->thread_count) { - while (local_gen == b->generation_id && b->index < b->thread_count) { - condition_wait(&b->cond, &b->mutex); - } - return false; - } - b->index = 0; - b->generation_id += 1; - condition_broadcast(&b->cond); - return true; -} - - gb_internal u32 thread_current_id(void) { @@ -494,3 +456,7 @@ gb_internal void thread_set_name(Thread *t, char const *name) { #endif } + +#if defined(GB_SYSTEM_WINDOWS) + #pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/types.cpp b/src/types.cpp index c8e24f01d..b1d3883c6 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -430,15 +430,6 @@ gb_internal Selection sub_selection(Selection const &sel, isize offset) { return res; } -gb_internal Selection sub_selection_with_length(Selection const &sel, isize offset, isize len) { - Selection res = {}; - res.index.data = sel.index.data + offset; - res.index.count = gb_max(len, gb_max(sel.index.count - offset, 0)); - res.index.capacity = res.index.count; - return res; -} - - gb_global Type basic_types[] = { {Type_Basic, {Basic_Invalid, 0, 0, STR_LIT("invalid type")}}, @@ -1089,15 +1080,6 @@ gb_internal Type *alloc_type_proc(Scope *scope, Type *params, isize param_count, gb_internal bool is_type_valid_for_keys(Type *t); -gb_internal Type *alloc_type_map(i64 count, Type *key, Type *value) { - if (key != nullptr) { - GB_ASSERT(value != nullptr); - } - Type *t = alloc_type(Type_Map); - t->Map.key = key; - t->Map.value = value; - return t; -} gb_internal Type *alloc_type_bit_set() { Type *t = alloc_type(Type_BitSet); @@ -1152,19 +1134,6 @@ gb_internal bool is_type_named(Type *t) { } return t->kind == Type_Named; } -gb_internal bool is_type_named_alias(Type *t) { - if (!is_type_named(t)) { - return false; - } - Entity *e = t->Named.type_name; - if (e == nullptr) { - return false; - } - if (e->kind != Entity_TypeName) { - return false; - } - return e->TypeName.is_type_alias; -} gb_internal bool is_type_boolean(Type *t) { // t = core_type(t); @@ -1329,27 +1298,6 @@ gb_internal bool is_type_complex_or_quaternion(Type *t) { } return false; } -gb_internal bool is_type_f16(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f16; - } - return false; -} -gb_internal bool is_type_f32(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f32; - } - return false; -} -gb_internal bool is_type_f64(Type *t) { - t = core_type(t); - if (t->kind == Type_Basic) { - return t->Basic.kind == Basic_f64; - } - return false; -} gb_internal bool is_type_pointer(Type *t) { t = base_type(t); if (t->kind == Type_Basic) { @@ -1550,10 +1498,6 @@ gb_internal bool is_type_asm_proc(Type *t) { t = base_type(t); return t->kind == Type_Proc && t->Proc.calling_convention == ProcCC_InlineAsm; } -gb_internal bool is_type_poly_proc(Type *t) { - t = base_type(t); - return t->kind == Type_Proc && t->Proc.is_polymorphic; -} gb_internal bool is_type_simd_vector(Type *t) { t = base_type(t); return t->kind == Type_SimdVector; @@ -1915,11 +1859,6 @@ gb_internal bool is_type_empty_union(Type *t) { t = base_type(t); return t->kind == Type_Union && t->Union.variants.count == 0; } -gb_internal bool is_type_empty_struct(Type *t) { - t = base_type(t); - return t->kind == Type_Struct && !t->Struct.is_raw_union && t->Struct.fields.count == 0; -} - gb_internal bool is_type_valid_for_keys(Type *t) { t = core_type(t); @@ -4051,20 +3990,6 @@ gb_internal Type *reduce_tuple_to_single_type(Type *original_type) { return original_type; } - -gb_internal Type *alloc_type_struct_from_field_types(Type **field_types, isize field_count, bool is_packed) { - Type *t = alloc_type_struct(); - t->Struct.fields = slice_make(heap_allocator(), field_count); - - Scope *scope = nullptr; - for_array(i, t->Struct.fields) { - t->Struct.fields[i] = alloc_entity_field(scope, blank_token, field_types[i], false, cast(i32)i, EntityState_Resolved); - } - t->Struct.is_packed = is_packed; - - return t; -} - gb_internal Type *alloc_type_tuple_from_field_types(Type **field_types, isize field_count, bool is_packed, bool must_be_tuple) { if (field_count == 0) { return nullptr; -- cgit v1.2.3 From a13e2f4578eb5557afb8bc6b21930032bedbbb43 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 19 Dec 2022 00:29:40 +0000 Subject: Fix minor race condition --- src/checker.cpp | 48 ++++++++++++++++++++++++++++++++++++++---------- src/checker.hpp | 5 +++++ 2 files changed, 43 insertions(+), 10 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index f130a965f..7cafcea2e 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -184,6 +184,7 @@ gb_internal void init_decl_info(DeclInfo *d, Scope *scope, DeclInfo *parent) { ptr_set_init(&d->deps, heap_allocator()); ptr_set_init(&d->type_info_deps, heap_allocator()); array_init (&d->labels, heap_allocator()); + mutex_init(&d->proc_checked_mutex); } gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { @@ -193,6 +194,7 @@ gb_internal DeclInfo *make_decl_info(Scope *scope, DeclInfo *parent) { } // gb_internal void destroy_declaration_info(DeclInfo *d) { +// mutex_destroy(&d->proc_checked_mutex); // ptr_set_destroy(&d->deps); // array_free(&d->labels); // } @@ -1200,30 +1202,51 @@ gb_internal CheckerContext make_checker_context(Checker *c) { ctx.type_path = new_checker_type_path(); ctx.type_level = 0; + mutex_init(&ctx.mutex); return ctx; } gb_internal void destroy_checker_context(CheckerContext *ctx) { + mutex_destroy(&ctx->mutex); destroy_checker_type_path(ctx->type_path); } -gb_internal void add_curr_ast_file(CheckerContext *ctx, AstFile *file) { +gb_internal bool add_curr_ast_file(CheckerContext *ctx, AstFile *file) { if (file != nullptr) { ctx->file = file; ctx->decl = file->pkg->decl_info; ctx->scope = file->scope; ctx->pkg = file->pkg; + return true; } + return false; } gb_internal void reset_checker_context(CheckerContext *ctx, AstFile *file, UntypedExprInfoMap *untyped) { if (ctx == nullptr) { return; } - destroy_checker_context(ctx); + GB_ASSERT(ctx->checker != nullptr); + mutex_lock(&ctx->mutex); + auto *queue = ctx->procs_to_check_queue; - *ctx = make_checker_context(ctx->checker); + auto type_path = ctx->type_path; + array_clear(type_path); + + zero_size(&ctx->pkg, gb_size_of(CheckerContext) - gb_offset_of(CheckerContext, pkg)); + + ctx->file = nullptr; + ctx->scope = builtin_pkg->scope; + ctx->pkg = builtin_pkg; + ctx->decl = nullptr; + + ctx->type_path = type_path; + ctx->type_level = 0; + add_curr_ast_file(ctx, file); + ctx->procs_to_check_queue = queue; ctx->untyped = untyped; + + mutex_unlock(&ctx->mutex); } @@ -5067,11 +5090,14 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u return false; } Entity *e = pi->decl->entity; - if (pi->decl->proc_checked) { - if (e != nullptr) { - GB_ASSERT(e->flags & EntityFlag_ProcBodyChecked); + + MUTEX_GUARD_BLOCK(&pi->decl->proc_checked_mutex) { + if (pi->decl->proc_checked) { + if (e != nullptr) { + GB_ASSERT(e->flags & EntityFlag_ProcBodyChecked); + } + return true; } - return true; } CheckerContext ctx = make_checker_context(c); @@ -5128,10 +5154,12 @@ gb_internal bool check_proc_info(Checker *c, ProcInfo *pi, UntypedExprInfoMap *u } check_proc_body(&ctx, pi->token, pi->decl, pi->type, pi->body); - if (e != nullptr) { - e->flags |= EntityFlag_ProcBodyChecked; + MUTEX_GUARD_BLOCK(&pi->decl->proc_checked_mutex) { + if (e != nullptr) { + e->flags |= EntityFlag_ProcBodyChecked; + } + pi->decl->proc_checked = true; } - pi->decl->proc_checked = true; add_untyped_expressions(&c->info, ctx.untyped); return true; } diff --git a/src/checker.hpp b/src/checker.hpp index 58f6a027c..6799503cd 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -158,6 +158,7 @@ struct DeclInfo { bool is_using; bool where_clauses_evaluated; bool proc_checked; + BlockingMutex proc_checked_mutex; isize defer_used; bool defer_use_checked; @@ -377,13 +378,17 @@ struct CheckerInfo { }; struct CheckerContext { + // Order matters here + BlockingMutex mutex; Checker * checker; CheckerInfo * info; + AstPackage * pkg; AstFile * file; Scope * scope; DeclInfo * decl; + // Order doesn't matter after this u32 state_flags; bool in_defer; // TODO(bill): Actually handle correctly Type * type_hint; -- cgit v1.2.3 From 8fc9566a837fbd3fe52f3f1b5e766e122b3c2de2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 20 Dec 2022 14:19:55 +0000 Subject: Use `*_set_update` where possible --- src/check_builtin.cpp | 4 +--- src/check_stmt.cpp | 3 +-- src/checker.cpp | 7 ++----- src/parser.cpp | 3 +-- src/string_set.cpp | 52 +++++++++++++++++++++++++-------------------------- src/types.cpp | 2 +- 6 files changed, 32 insertions(+), 39 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 859fbea28..1c13b6b5e 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -3126,13 +3126,11 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As } - if (string_set_exists(&name_set, name)) { + if (string_set_update(&name_set, name)) { error(op.expr, "Field argument name '%.*s' already exists", LIT(name)); } else { array_add(&types, arg_type->Slice.elem); array_add(&names, name); - - string_set_add(&name_set, name); } } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 73adbed8b..cf111e84c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1237,7 +1237,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ GB_PANIC("Unknown type to type switch statement"); } - if (type_ptr_set_exists(&seen, y.type)) { + if (type_ptr_set_update(&seen, y.type)) { TokenPos pos = cc->token.pos; gbString expr_str = expr_to_string(y.expr); error(y.expr, @@ -1248,7 +1248,6 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ gb_string_free(expr_str); break; } - ptr_set_add(&seen, y.type); } } diff --git a/src/checker.cpp b/src/checker.cpp index 7cafcea2e..14a0e5f4c 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3414,11 +3414,9 @@ gb_internal void check_decl_attributes(CheckerContext *c, Array const &at continue; } - if (string_set_exists(&set, name)) { + if (string_set_update(&set, name)) { error(elem, "Previous declaration of '%.*s'", LIT(name)); continue; - } else { - string_set_add(&set, name); } if (!proc(c, elem, name, value, ac)) { @@ -4969,10 +4967,9 @@ gb_internal Array find_entity_path(Entity *start, Entity *end, PtrSet< Array empty_path = {}; - if (ptr_set_exists(visited, start)) { + if (ptr_set_update(visited, start)) { return empty_path; } - ptr_set_add(visited, start); DeclInfo *decl = start->decl_info; if (decl) { diff --git a/src/parser.cpp b/src/parser.cpp index eb006cb24..ad22ce5ff 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4967,10 +4967,9 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String const &path, Strin String const FILE_EXT = str_lit(".odin"); MUTEX_GUARD_BLOCK(&p->import_mutex) { - if (string_set_exists(&p->imported_files, path)) { + if (string_set_update(&p->imported_files, path)) { return nullptr; } - string_set_add(&p->imported_files, path); } AstPackage *pkg = gb_alloc_item(permanent_allocator(), AstPackage); diff --git a/src/string_set.cpp b/src/string_set.cpp index fce98ec75..1c97d253e 100644 --- a/src/string_set.cpp +++ b/src/string_set.cpp @@ -10,18 +10,18 @@ struct StringSet { }; -void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16); -void string_set_destroy(StringSet *s); -void string_set_add (StringSet *s, String const &str); -bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed -bool string_set_exists (StringSet *s, String const &str); -void string_set_remove (StringSet *s, String const &str); -void string_set_clear (StringSet *s); -void string_set_grow (StringSet *s); -void string_set_rehash (StringSet *s, isize new_count); - - -gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { +gb_internal void string_set_init (StringSet *s, gbAllocator a, isize capacity = 16); +gb_internal void string_set_destroy(StringSet *s); +gb_internal void string_set_add (StringSet *s, String const &str); +gb_internal bool string_set_update (StringSet *s, String const &str); // returns true if it previously existed +gb_internal bool string_set_exists (StringSet *s, String const &str); +gb_internal void string_set_remove (StringSet *s, String const &str); +gb_internal void string_set_clear (StringSet *s); +gb_internal void string_set_grow (StringSet *s); +gb_internal void string_set_rehash (StringSet *s, isize new_count); + + +gb_internal gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { capacity = next_pow2_isize(gb_max(16, capacity)); slice_init(&s->hashes, a, capacity); @@ -31,7 +31,7 @@ gb_inline void string_set_init(StringSet *s, gbAllocator a, isize capacity) { } } -gb_inline void string_set_destroy(StringSet *s) { +gb_internal gb_inline void string_set_destroy(StringSet *s) { slice_free(&s->hashes, s->entries.allocator); array_free(&s->entries); } @@ -82,13 +82,13 @@ gb_internal b32 string_set__full(StringSet *s) { return 0.75f * s->hashes.count <= s->entries.count; } -gb_inline void string_set_grow(StringSet *s) { +gb_internal gb_inline void string_set_grow(StringSet *s) { isize new_count = gb_max(s->hashes.count<<1, 16); string_set_rehash(s, new_count); } -void string_set_reset_entries(StringSet *s) { +gb_internal void string_set_reset_entries(StringSet *s) { for (isize i = 0; i < s->hashes.count; i++) { s->hashes.data[i] = MAP_SENTINEL; } @@ -105,7 +105,7 @@ void string_set_reset_entries(StringSet *s) { } } -void string_set_reserve(StringSet *s, isize cap) { +gb_internal void string_set_reserve(StringSet *s, isize cap) { array_reserve(&s->entries, cap); if (s->entries.count*2 < s->hashes.count) { return; @@ -115,7 +115,7 @@ void string_set_reserve(StringSet *s, isize cap) { } -void string_set_rehash(StringSet *s, isize new_count) { +gb_internal void string_set_rehash(StringSet *s, isize new_count) { string_set_reserve(s, new_count); } @@ -125,7 +125,7 @@ gb_inline bool string_set_exists(StringSet *s, String const &str) { return index != MAP_SENTINEL; } -void string_set_add(StringSet *s, String const &str) { +gb_internal void string_set_add(StringSet *s, String const &str) { MapIndex index; MapFindResult fr; StringHashKey key = string_hash_string(str); @@ -150,7 +150,7 @@ void string_set_add(StringSet *s, String const &str) { } } -bool string_set_update(StringSet *s, String const &str) { +gb_internal bool string_set_update(StringSet *s, String const &str) { bool exists = false; MapIndex index; MapFindResult fr; @@ -179,7 +179,7 @@ bool string_set_update(StringSet *s, String const &str) { } -void string_set__erase(StringSet *s, MapFindResult fr) { +gb_internal void string_set__erase(StringSet *s, MapFindResult fr) { MapFindResult last; if (fr.entry_prev == MAP_SENTINEL) { s->hashes[fr.hash_index] = s->entries[fr.entry_index].next; @@ -201,7 +201,7 @@ void string_set__erase(StringSet *s, MapFindResult fr) { } } -void string_set_remove(StringSet *s, String const &str) { +gb_internal void string_set_remove(StringSet *s, String const &str) { StringHashKey key = string_hash_string(str); MapFindResult fr = string_set__find(s, key); if (fr.entry_index != MAP_SENTINEL) { @@ -209,7 +209,7 @@ void string_set_remove(StringSet *s, String const &str) { } } -gb_inline void string_set_clear(StringSet *s) { +gb_internal gb_inline void string_set_clear(StringSet *s) { array_clear(&s->entries); for_array(i, s->hashes) { s->hashes.data[i] = MAP_SENTINEL; @@ -218,18 +218,18 @@ gb_inline void string_set_clear(StringSet *s) { -StringSetEntry *begin(StringSet &m) { +gb_internal StringSetEntry *begin(StringSet &m) { return m.entries.data; } -StringSetEntry const *begin(StringSet const &m) { +gb_internal StringSetEntry const *begin(StringSet const &m) { return m.entries.data; } -StringSetEntry *end(StringSet &m) { +gb_internal StringSetEntry *end(StringSet &m) { return m.entries.data + m.entries.count; } -StringSetEntry const *end(StringSet const &m) { +gb_internal StringSetEntry const *end(StringSet const &m) { return m.entries.data + m.entries.count; } \ No newline at end of file diff --git a/src/types.cpp b/src/types.cpp index b1d3883c6..890098ad0 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -812,7 +812,7 @@ gb_internal void init_type_mutex(void) { mutex_init(&g_type_mutex); } -gb_internal bool type_ptr_set_exists(PtrSet *s, Type *t) { +gb_internal bool type_ptr_set_update(PtrSet *s, Type *t) { if (ptr_set_exists(s, t)) { return true; } -- cgit v1.2.3 From e98f1a28e68e82753728f58b3465793192b74f9d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 11:53:13 +0000 Subject: Change `tav` to be a pointer internally --- src/check_expr.cpp | 68 ++++++++++++++++++++++---------------------- src/check_stmt.cpp | 10 +++---- src/check_type.cpp | 4 +-- src/checker.cpp | 22 +++++++------- src/llvm_backend_const.cpp | 56 ++++++++++++++++++------------------ src/llvm_backend_expr.cpp | 32 ++++++++++----------- src/llvm_backend_proc.cpp | 20 ++++++------- src/llvm_backend_stmt.cpp | 34 +++++++++++----------- src/llvm_backend_utility.cpp | 12 ++++---- src/parser.cpp | 8 ++++-- src/parser.hpp | 7 +++-- 11 files changed, 140 insertions(+), 133 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index ed1ddd1f1..654dec051 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 cf111e84c..7ba23ac67 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 4634e1fbe..3d4bab3e2 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 14a0e5f4c..0f64c6ae9 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 ee564bbf1..6c5bb153f 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 d574caf4c..794ed7720 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 384d29ca7..546d49027 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 6400a8a9d..e0e991b4d 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 dbed32b82..6abcdfc04 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 436498c51..42d8f62cf 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -71,6 +71,7 @@ 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); @@ -106,6 +107,9 @@ 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; @@ -650,8 +654,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 7d292ffce..e3d6b42d8 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,6 +771,9 @@ 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 -- cgit v1.2.3 From 9b278db9934913367a8e186b9c6aa9c03017f3d4 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 12:01:41 +0000 Subject: Revert "Change `tav` to be a pointer internally" This reverts commit e98f1a28e68e82753728f58b3465793192b74f9d. --- src/check_expr.cpp | 68 ++++++++++++++++++++++---------------------- src/check_stmt.cpp | 10 +++---- src/check_type.cpp | 4 +-- src/checker.cpp | 22 +++++++------- src/llvm_backend_const.cpp | 56 ++++++++++++++++++------------------ src/llvm_backend_expr.cpp | 32 ++++++++++----------- src/llvm_backend_proc.cpp | 20 ++++++------- src/llvm_backend_stmt.cpp | 34 +++++++++++----------- src/llvm_backend_utility.cpp | 12 ++++---- src/parser.cpp | 8 ++---- src/parser.hpp | 7 ++--- 11 files changed, 133 insertions(+), 140 deletions(-) (limited to 'src/checker.cpp') 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 -- cgit v1.2.3 From ffa14c3aad5472aab32711c2500c67df9a368601 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 12:58:23 +0000 Subject: Remove need the MPMC in single threaded case --- src/checker.cpp | 20 +++++++++++--------- src/parser.cpp | 2 +- src/parser.hpp | 5 ++--- 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 14a0e5f4c..29e4b6667 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -3941,7 +3941,7 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n if (c->collect_delayed_decls) { if (decl->state_flags & StateFlag_BeenHandled) return; decl->state_flags |= StateFlag_BeenHandled; - mpmc_enqueue(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], expr); + array_add(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], expr); } continue; } @@ -3969,7 +3969,7 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n continue; } // Will be handled later - mpmc_enqueue(&curr_file->delayed_decls_queues[AstDelayQueue_Import], decl); + array_add(&curr_file->delayed_decls_queues[AstDelayQueue_Import], decl); case_end; case_ast_node(fl, ForeignImportDecl, decl); @@ -4607,7 +4607,7 @@ gb_internal bool collect_file_decl(CheckerContext *ctx, Ast *decl) { if (es->expr->kind == Ast_CallExpr) { ast_node(ce, CallExpr, es->expr); if (ce->proc->kind == Ast_BasicDirective) { - mpmc_enqueue(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], es->expr); + array_add(&curr_file->delayed_decls_queues[AstDelayQueue_Expr], es->expr); } } case_end; @@ -4861,9 +4861,10 @@ gb_internal void check_import_entities(Checker *c) { ctx.collect_delayed_decls = true; // Check import declarations first to simplify things - for (Ast *id = nullptr; mpmc_dequeue(&f->delayed_decls_queues[AstDelayQueue_Import], &id); /**/) { - check_add_import_decl(&ctx, id); + for (Ast *decl : f->delayed_decls_queues[AstDelayQueue_Import]) { + check_add_import_decl(&ctx, decl); } + array_clear(&f->delayed_decls_queues[AstDelayQueue_Import]); if (collect_file_decls(&ctx, f->decls)) { check_export_entities_in_pkg(&ctx, pkg, &untyped); @@ -4889,10 +4890,10 @@ gb_internal void check_import_entities(Checker *c) { AstFile *f = pkg->files[i]; reset_checker_context(&ctx, f, &untyped); - auto *q = &f->delayed_decls_queues[AstDelayQueue_Import]; - for (Ast *decl = nullptr; mpmc_dequeue(q, &decl); /**/) { + for (Ast *decl : f->delayed_decls_queues[AstDelayQueue_Import]) { check_add_import_decl(&ctx, decl); } + array_clear(&f->delayed_decls_queues[AstDelayQueue_Import]); add_untyped_expressions(ctx.info, &untyped); } @@ -4908,11 +4909,12 @@ gb_internal void check_import_entities(Checker *c) { AstFile *f = pkg->files[i]; reset_checker_context(&ctx, f, &untyped); - auto *q = &f->delayed_decls_queues[AstDelayQueue_Expr]; - for (Ast *expr = nullptr; mpmc_dequeue(q, &expr); /**/) { + for (Ast *expr : f->delayed_decls_queues[AstDelayQueue_Expr]) { Operand o = {}; check_expr(&ctx, &o, expr); } + array_clear(&f->delayed_decls_queues[AstDelayQueue_Expr]); + add_untyped_expressions(ctx.info, &untyped); } } diff --git a/src/parser.cpp b/src/parser.cpp index cb9713985..e07f26004 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5651,7 +5651,7 @@ gb_internal bool parse_file(Parser *p, AstFile *f) { f->time_to_parse = cast(f64)(end-start)/cast(f64)time_stamp__freq(); for (int i = 0; i < AstDelayQueue_COUNT; i++) { - mpmc_init(f->delayed_decls_queues+i, heap_allocator(), f->delayed_decl_count); + array_init(f->delayed_decls_queues+i, heap_allocator(), 0, f->delayed_decl_count); } diff --git a/src/parser.hpp b/src/parser.hpp index 4357573c9..c33739ebe 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -132,9 +132,8 @@ struct AstFile { CommentGroup *docs; // current docs Array comments; // All the comments! - // TODO(bill): make this a basic queue as it does not require - // any multiple thread capabilities - MPMCQueue delayed_decls_queues[AstDelayQueue_COUNT]; + // This is effectively a queue but does not require any multi-threading capabilities + Array delayed_decls_queues[AstDelayQueue_COUNT]; #define PARSER_MAX_FIX_COUNT 6 isize fix_count; -- cgit v1.2.3 From 00823ca88c870d49186dbcaa21c54384c0b9364f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 22 Dec 2022 13:03:34 +0000 Subject: Remove a few `TODO`s --- src/build_settings.cpp | 3 +-- src/check_builtin.cpp | 7 ++----- src/check_decl.cpp | 8 -------- src/checker.cpp | 9 ++------- src/checker.hpp | 4 ++-- 5 files changed, 7 insertions(+), 24 deletions(-) (limited to 'src/checker.cpp') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 630cec601..080e9dddc 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -394,7 +394,7 @@ gb_global TargetMetrics target_darwin_arm64 = { TargetArch_arm64, 8, 8, 16, str_lit("arm64-apple-macosx11.0.0"), - str_lit("e-m:o-i64:64-i128:128-n32:64-S128"), // TODO(bill): Is this correct? + str_lit("e-m:o-i64:64-i128:128-n32:64-S128"), }; gb_global TargetMetrics target_freebsd_i386 = { @@ -585,7 +585,6 @@ struct LibraryCollections { gb_global Array library_collections = {0}; gb_internal void add_library_collection(String name, String path) { - // TODO(bill): Check the path is valid and a directory LibraryCollections lc = {name, string_trim_whitespace(path)}; array_add(&library_collections, lc); } diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 1c13b6b5e..99d956f5e 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -89,7 +89,6 @@ gb_internal void check_or_else_split_types(CheckerContext *c, Operand *x, String gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String const &name, Operand const &x, Type *type_hint) { - // TODO(bill): better error message gbString t = type_to_string(x.type); error(x.expr, "'%.*s' does not return a value, value is of type %s", LIT(name), t); if (is_type_union(type_deref(x.type))) { @@ -2559,7 +2558,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As if (is_type_struct(type)) { isize variable_count = type->Struct.fields.count; slice_init(&tuple->Tuple.variables, a, variable_count); - // TODO(bill): Should I copy each of the entities or is this good enough? + // NOTE(bill): don't copy the entities, this should be good enough gb_memmove_array(tuple->Tuple.variables.data, type->Struct.fields.data, variable_count); } else if (is_type_array(type)) { isize variable_count = cast(isize)type->Array.count; @@ -3766,9 +3765,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As mp_err err = mp_pack(rop, max_count, &written, MP_LSB_FIRST, size, endian, nails, &x.value.value_integer); GB_ASSERT(err == MP_OKAY); - if (id == BuiltinProc_reverse_bits) { - // TODO(bill): Should this even be allowed at compile time? - } else { + if (id != BuiltinProc_reverse_bits) { u64 v = 0; switch (id) { case BuiltinProc_count_ones: diff --git a/src/check_decl.cpp b/src/check_decl.cpp index d982a69fc..59beae56d 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -10,7 +10,6 @@ gb_internal Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *o gbString expr_str = expr_to_string(operand->expr); // TODO(bill): is this a good enough error message? - // 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, @@ -122,13 +121,6 @@ gb_internal void check_init_variables(CheckerContext *ctx, Entity **lhs, isize l check_unpack_arguments(ctx, lhs, lhs_count, &operands, inits, true, false); isize rhs_count = operands.count; - for_array(i, operands) { - if (operands[i].mode == Addressing_Invalid) { - // TODO(bill): Should I ignore invalid parameters? - // rhs_count--; - } - } - isize max = gb_min(lhs_count, rhs_count); for (isize i = 0; i < max; i++) { Entity *e = lhs[i]; diff --git a/src/checker.cpp b/src/checker.cpp index 29e4b6667..b78da2827 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -404,7 +404,6 @@ gb_internal void scope_lookup_parent(Scope *scope, String const &name, Scope **s if (found) { Entity *e = *found; if (gone_thru_proc) { - // IMPORTANT TODO(bill): Is this correct?! if (e->kind == Entity_Label) { continue; } @@ -1409,8 +1408,7 @@ gb_internal isize type_info_index(CheckerInfo *info, Type *type, bool error_on_f entry_index = *found_entry_index; } if (entry_index < 0) { - // NOTE(bill): Do manual search - // TODO(bill): This is O(n) and can be very slow + // NOTE(bill): Do manual linear search for (auto const &e : info->type_info_map) { if (are_types_identical_unique_tuples(e.key, type)) { entry_index = e.value; @@ -2350,7 +2348,7 @@ gb_internal void generate_minimum_dependency_set(Checker *c, Entity *start) { for_array(i, c->info.definitions) { Entity *e = c->info.definitions[i]; - if (e->scope == builtin_pkg->scope) { // TODO(bill): is the check enough? + if (e->scope == builtin_pkg->scope) { if (e->type == nullptr) { add_dependency_to_set(c, e); } @@ -3965,7 +3963,6 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n if (curr_file == nullptr) { error(decl, "import declarations are only allowed in the file scope"); // NOTE(bill): _Should_ be caught by the parser - // TODO(bill): Better error handling if it isn't continue; } // Will be handled later @@ -3976,7 +3973,6 @@ gb_internal void check_collect_entities(CheckerContext *c, Slice const &n if ((c->scope->flags&ScopeFlag_File) == 0) { error(decl, "%.*s declarations are only allowed in the file scope", LIT(fl->token.string)); // NOTE(bill): _Should_ be caught by the parser - // TODO(bill): Better error handling if it isn't continue; } check_add_foreign_import_decl(c, decl); @@ -4167,7 +4163,6 @@ gb_internal void add_import_dependency_node(Checker *c, Ast *decl, PtrMapsucc, m); import_graph_node_set_add(&m->pred, n); ptr_set_add(&m->scope->imported, n->scope); diff --git a/src/checker.hpp b/src/checker.hpp index 6799503cd..1d6019b79 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -390,7 +390,7 @@ struct CheckerContext { // Order doesn't matter after this u32 state_flags; - bool in_defer; // TODO(bill): Actually handle correctly + bool in_defer; Type * type_hint; String proc_name; @@ -401,7 +401,7 @@ struct CheckerContext { ForeignContext foreign_context; CheckerTypePath *type_path; - isize type_level; // TODO(bill): Actually handle correctly + isize type_level; UntypedExprInfoMap *untyped; -- cgit v1.2.3