From 2db03cb4a54eaa594ca0d3ccb6819a8d56e7efed Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Thu, 6 Jul 2017 22:43:55 +0100 Subject: [PATCH] Fix aprint* bug; NULL -> nullptr; Better error messages for overloaded functions --- core/fmt.odin | 12 +- src/array.cpp | 10 +- src/build_settings.cpp | 14 +- src/check_decl.cpp | 98 +++--- src/check_expr.cpp | 515 ++++++++++++++-------------- src/check_stmt.cpp | 162 ++++----- src/checker.cpp | 206 ++++++------ src/common.cpp | 26 +- src/docs.cpp | 4 +- src/entity.cpp | 14 +- src/integer128.cpp | 8 +- src/ir.cpp | 736 ++++++++++++++++++++--------------------- src/ir_opt.cpp | 24 +- src/ir_print.cpp | 56 ++-- src/main.cpp | 4 +- src/map.cpp | 12 +- src/parser.cpp | 266 +++++++-------- src/printer.cpp | 2 +- src/ssa.cpp | 186 +++++------ src/string.cpp | 22 +- src/tokenizer.cpp | 4 +- src/types.cpp | 226 ++++++------- 22 files changed, 1319 insertions(+), 1288 deletions(-) diff --git a/core/fmt.odin b/core/fmt.odin index 2953adf00..45e4cbe60 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -484,11 +484,11 @@ fmt_bool :: proc(using fi: ^FmtInfo, b: bool, verb: rune) { fmt_write_padding :: proc(fi: ^FmtInfo, width: int) { if width <= 0 do return; - pad_byte := u8(fi.space ? ' ' : '0'); + pad_byte: u8 = fi.space ? ' ' : '0'; - data := string_buffer_data(fi.buf^); - count := min(width, cap(data)-len(data)); - for _ in 0.. array_make(T *data, isize count, isize capacity) { template void array_free(Array *array) { - if (array->allocator.proc != NULL) { + if (array->allocator.proc != nullptr) { gb_free(array->allocator, array->data); } array->count = 0; @@ -123,7 +123,7 @@ void array_set_capacity(Array *array, isize capacity) { array_resize(array, capacity); } - T *new_data = NULL; + T *new_data = nullptr; if (capacity > 0) { new_data = gb_alloc_array(array->allocator, T, capacity); gb_memmove(new_data, array->data, gb_size_of(T) * array->capacity); @@ -147,7 +147,7 @@ typedef Array(void) ArrayVoid; #define array_init_reserve(x_, allocator_, init_capacity_) do { \ void **e = cast(void **)&((x_)->e); \ - GB_ASSERT((x_) != NULL); \ + GB_ASSERT((x_) != nullptr); \ (x_)->allocator = (allocator_); \ (x_)->count = 0; \ (x_)->capacity = (init_capacity_); \ @@ -156,7 +156,7 @@ typedef Array(void) ArrayVoid; #define array_init_count(x_, allocator_, init_count_) do { \ void **e = cast(void **)&((x_)->e); \ - GB_ASSERT((x_) != NULL); \ + GB_ASSERT((x_) != nullptr); \ (x_)->allocator = (allocator_); \ (x_)->count = (init_count_); \ (x_)->capacity = (init_count_); \ @@ -203,7 +203,7 @@ typedef Array(void) ArrayVoid; void array__set_capacity(void *ptr, isize capacity, isize element_size) { ArrayVoid *x = cast(ArrayVoid *)ptr; - GB_ASSERT(ptr != NULL); + GB_ASSERT(ptr != nullptr); GB_ASSERT(element_size > 0); diff --git a/src/build_settings.cpp b/src/build_settings.cpp index b27c40148..b17313c4c 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -53,9 +53,9 @@ String odin_root_dir(void) { len = 0; for (;;) { - len = GetModuleFileNameW(NULL, &path_buf[0], path_buf.count); + len = GetModuleFileNameW(nullptr, &path_buf[0], path_buf.count); if (len == 0) { - return make_string(NULL, 0); + return make_string(nullptr, 0); } if (len < path_buf.count) { break; @@ -69,7 +69,7 @@ String odin_root_dir(void) { text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1); - GetModuleFileNameW(NULL, text, len); + GetModuleFileNameW(nullptr, text, len); path = string16_to_string(heap_allocator(), make_string16(text, len)); for (i = path.len-1; i >= 0; i--) { @@ -168,7 +168,7 @@ String odin_root_dir(void) { // path without checking this link. Sorry. len = readlink("/proc/self/exe", &path_buf[0], path_buf.count); if(len == 0) { - return make_string(NULL, 0); + return make_string(nullptr, 0); } if (len < path_buf.count) { break; @@ -208,10 +208,10 @@ String path_to_fullpath(gbAllocator a, String s) { String16 string16 = string_to_string16(string_buffer_allocator, s); String result = {0}; - DWORD len = GetFullPathNameW(&string16[0], 0, NULL, NULL); + DWORD len = GetFullPathNameW(&string16[0], 0, nullptr, nullptr); if (len != 0) { wchar_t *text = gb_alloc_array(string_buffer_allocator, wchar_t, len+1); - GetFullPathNameW(&string16[0], len, text, NULL); + GetFullPathNameW(&string16[0], len, text, nullptr); text[len] = 0; result = string16_to_string(a, make_string16(text, len)); } @@ -221,7 +221,7 @@ String path_to_fullpath(gbAllocator a, String s) { #elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX) String path_to_fullpath(gbAllocator a, String s) { char *p = realpath(cast(char *)&s[0], 0); - if(p == NULL) return make_string_c(""); + if(p == nullptr) return make_string_c(""); return make_string_c(p); } diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 35f74b91a..b6e2acb26 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -23,39 +23,39 @@ Type *check_init_variable(Checker *c, Entity *e, Operand *operand, String contex } - if (e->type == NULL) { + if (e->type == nullptr) { e->type = t_invalid; } - return NULL; + return nullptr; } - if (e->type == NULL) { + if (e->type == nullptr) { // NOTE(bill): Use the type of the operand Type *t = operand->type; if (is_type_untyped(t)) { if (t == t_invalid || is_type_untyped_nil(t)) { error(e->token, "Invalid use of untyped nil in %.*s", LIT(context_name)); e->type = t_invalid; - return NULL; + return nullptr; } if (t == t_invalid || is_type_untyped_undef(t)) { error(e->token, "Invalid use of --- in %.*s", LIT(context_name)); e->type = t_invalid; - return NULL; + return nullptr; } t = default_type(t); } if (is_type_polymorphic(t)) { error(e->token, "Invalid use of a polymorphic type in %.*s", LIT(context_name)); e->type = t_invalid; - return NULL; + return nullptr; } if (is_type_bit_field_value(t)) { t = default_bit_field_value_type(t); } if (is_type_variant(t)) { Type *st = base_type(t); - GB_ASSERT(st->Record.variant_parent != NULL); + GB_ASSERT(st->Record.variant_parent != nullptr); t = st->Record.variant_parent; } GB_ASSERT(is_type_typed(t)); @@ -66,14 +66,14 @@ Type *check_init_variable(Checker *c, Entity *e, Operand *operand, String contex check_assignment(c, operand, e->type, context_name); if (operand->mode == Addressing_Invalid) { - return NULL; + return nullptr; } return e->type; } void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, Array inits, String context_name) { - if ((lhs == NULL || lhs_count == 0) && inits.count == 0) { + if ((lhs == nullptr || lhs_count == 0) && inits.count == 0) { return; } @@ -109,7 +109,7 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) { if (operand->mode == Addressing_Invalid || operand->type == t_invalid || e->type == t_invalid) { - if (e->type == NULL) { + if (e->type == nullptr) { e->type = t_invalid; } return; @@ -120,7 +120,7 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) { gbString str = expr_to_string(operand->expr); error(operand->expr, "`%s` is not a constant", str); gb_string_free(str); - if (e->type == NULL) { + if (e->type == nullptr) { e->type = t_invalid; } return; @@ -129,13 +129,13 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) { gbString type_str = type_to_string(operand->type); error(operand->expr, "Invalid constant type: `%s`", type_str); gb_string_free(type_str); - if (e->type == NULL) { + if (e->type == nullptr) { e->type = t_invalid; } return; } - if (e->type == NULL) { // NOTE(bill): type inference + if (e->type == nullptr) { // NOTE(bill): type inference e->type = operand->type; } @@ -150,11 +150,11 @@ void check_init_constant(Checker *c, Entity *e, Operand *operand) { } void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def) { - GB_ASSERT(e->type == NULL); + GB_ASSERT(e->type == nullptr); String name = e->token.string; - Type *named = make_type_named(c->allocator, name, NULL, e); + Type *named = make_type_named(c->allocator, name, nullptr, e); named->Named.type_name = e; - if (def != NULL && def->kind == Type_Named) { + if (def != nullptr && def->kind == Type_Named) { def->Named.base = named; } e->type = named; @@ -169,7 +169,7 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def) { } void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, Type *named_type) { - GB_ASSERT(e->type == NULL); + GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Constant); if (e->flags & EntityFlag_Visited) { @@ -192,10 +192,10 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, Operand operand = {}; - if (init != NULL) { - Entity *entity = NULL; + if (init != nullptr) { + Entity *entity = nullptr; if (init->kind == AstNode_Ident) { - entity = check_ident(c, &operand, init, NULL, e->type, true); + entity = check_ident(c, &operand, init, nullptr, e->type, true); } else if (init->kind == AstNode_SelectorExpr) { entity = check_selector(c, &operand, init, e->type); } else { @@ -207,7 +207,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, e->kind = Entity_TypeName; DeclInfo *d = c->context.decl; - if (d->type_expr != NULL) { + if (d->type_expr != nullptr) { error(e->token, "A type declaration cannot have an type parameter"); } d->type_expr = d->init_expr; @@ -217,7 +217,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, // NOTE(bill): Check to see if the expression it to be aliases case Addressing_Builtin: - if (e->type != NULL) { + if (e->type != nullptr) { error(type_expr, "A constant alias of a built-in procedure may not have a type initializer"); } e->kind = Entity_Builtin; @@ -232,7 +232,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, return; } - if (entity != NULL) { + if (entity != nullptr) { switch (entity->kind) { case Entity_Alias: e->kind = Entity_Alias; @@ -263,7 +263,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, } } - if (init != NULL) { + if (init != nullptr) { check_expr_or_type(c, &operand, init, e->type); } @@ -334,8 +334,8 @@ bool are_signatures_similar_enough(Type *a_, Type *b_) { } void init_entity_foreign_library(Checker *c, Entity *e) { - AstNode *ident = NULL; - Entity **foreign_library = NULL; + AstNode *ident = nullptr; + Entity **foreign_library = nullptr; switch (e->kind) { case Entity_Procedure: @@ -350,14 +350,14 @@ void init_entity_foreign_library(Checker *c, Entity *e) { return; } - if (ident == NULL) { + if (ident == nullptr) { error(e->token, "foreign entiies must declare which library they are from"); } else if (ident->kind != AstNode_Ident) { error(ident, "foreign library names must be an identifier"); } else { String name = ident->Ident.token.string; Entity *found = scope_lookup_entity(c->context.scope, name); - if (found == NULL) { + if (found == nullptr) { if (name == "_") { error(ident, "`_` cannot be used as a value type"); } else { @@ -374,7 +374,7 @@ void init_entity_foreign_library(Checker *c, Entity *e) { } void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { - GB_ASSERT(e->type == NULL); + GB_ASSERT(e->type == nullptr); if (d->proc_lit->kind != AstNode_ProcLit) { // TOOD(bill): Better error message error(d->proc_lit, "Expected a procedure to check"); @@ -382,10 +382,10 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { } Type *proc_type = e->type; - if (d->gen_proc_type != NULL) { + if (d->gen_proc_type != nullptr) { proc_type = d->gen_proc_type; } else { - proc_type = make_type_proc(c->allocator, e->scope, NULL, 0, NULL, 0, false, ProcCC_Odin); + proc_type = make_type_proc(c->allocator, e->scope, nullptr, 0, nullptr, 0, false, ProcCC_Odin); } e->type = proc_type; ast_node(pl, ProcLit, d->proc_lit); @@ -437,7 +437,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { } if (pt->is_polymorphic) { - if (pl->body == NULL) { + if (pl->body == nullptr) { error(e->token, "Polymorphic procedures must have a body"); } @@ -447,7 +447,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { } } - if (pl->body != NULL) { + if (pl->body != nullptr) { if (is_foreign) { error(pl->body, "A foreign procedure cannot have a body"); } @@ -537,7 +537,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { } void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, AstNode *init_expr) { - GB_ASSERT(e->type == NULL); + GB_ASSERT(e->type == nullptr); GB_ASSERT(e->kind == Entity_Variable); if (e->flags & EntityFlag_Visited) { @@ -548,17 +548,17 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count String context_name = str_lit("variable declaration"); - if (type_expr != NULL) { + if (type_expr != nullptr) { e->type = check_type(c, type_expr); } - if (e->type != NULL && is_type_polymorphic(e->type)) { + if (e->type != nullptr && is_type_polymorphic(e->type)) { error(e->token, "Invalid use of a polymorphic type in %.*s", LIT(context_name)); e->type = t_invalid; } if (e->Variable.is_foreign) { - if (init_expr != NULL) { + if (init_expr != nullptr) { error(e->token, "A foreign variable declaration cannot have a default value"); } init_entity_foreign_library(c, e); @@ -583,21 +583,21 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count } } - if (init_expr == NULL) { - if (type_expr == NULL) { + if (init_expr == nullptr) { + if (type_expr == nullptr) { e->type = t_invalid; } return; } - if (entities == NULL || entity_count == 1) { - GB_ASSERT(entities == NULL || entities[0] == e); + if (entities == nullptr || entity_count == 1) { + GB_ASSERT(entities == nullptr || entities[0] == e); Operand operand = {}; check_expr(c, &operand, init_expr); check_init_variable(c, e, &operand, context_name); } - if (type_expr != NULL) { + if (type_expr != nullptr) { for (isize i = 0; i < entity_count; i++) { entities[i]->type = e->type; } @@ -611,13 +611,13 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count } void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) { - if (e->type != NULL) { + if (e->type != nullptr) { return; } - if (d == NULL) { + if (d == nullptr) { d = decl_info_of_entity(&c->info, e); - if (d == NULL) { + if (d == nullptr) { // TODO(bill): Err here? e->type = t_invalid; set_base_type(named_type, t_invalid); @@ -653,7 +653,7 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) { void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNode *body) { - if (body == NULL) { + if (body == nullptr) { return; } GB_ASSERT(body->kind == AstNode_BlockStmt); @@ -690,14 +690,14 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod Type *t = base_type(type_deref(e->type)); if (is_type_struct(t) || is_type_raw_union(t)) { Scope *scope = scope_of_node(&c->info, t->Record.node); - GB_ASSERT(scope != NULL); + GB_ASSERT(scope != nullptr); for_array(i, scope->elements.entries) { Entity *f = scope->elements.entries[i].value; if (f->kind == Entity_Variable) { Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type); uvar->Variable.is_immutable = is_immutable; Entity *prev = scope_insert_entity(c->context.scope, uvar); - if (prev != NULL) { + if (prev != nullptr) { error(e->token, "Namespace collision while `using` `%.*s` of: %.*s", LIT(name), LIT(prev->token.string)); break; } @@ -729,7 +729,7 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod check_scope_usage(c, c->context.scope); - if (decl->parent != NULL) { + if (decl->parent != nullptr) { // NOTE(bill): Add the dependencies from the procedure literal (lambda) for_array(i, decl->deps.entries) { HashKey key = decl->deps.entries[i].key; diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 10ff78609..07bd90aff 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -33,10 +33,10 @@ typedef CALL_ARGUMENT_CHECKER(CallArgumentCheckerType); void check_expr (Checker *c, Operand *operand, AstNode *expression); void check_multi_expr (Checker *c, Operand *operand, AstNode *expression); -void check_expr_or_type (Checker *c, Operand *operand, AstNode *expression, Type *type_hint = NULL); +void check_expr_or_type (Checker *c, Operand *operand, AstNode *expression, Type *type_hint = nullptr); ExprKind check_expr_base (Checker *c, Operand *operand, AstNode *expression, Type *type_hint); void check_expr_with_type_hint (Checker *c, Operand *o, AstNode *e, Type *t); -Type * check_type (Checker *c, AstNode *expression, Type *named_type = NULL); +Type * check_type (Checker *c, AstNode *expression, Type *named_type = nullptr); void check_type_decl (Checker *c, Entity *e, AstNode *type_expr, Type *def); Entity * check_selector (Checker *c, Operand *operand, AstNode *node, Type *type_hint); void check_not_tuple (Checker *c, Operand *operand); @@ -91,8 +91,8 @@ void check_scope_decls(Checker *c, Array nodes, isize reserve_size) { continue; } DeclInfo *d = decl_info_of_entity(&c->info, e); - if (d != NULL) { - check_entity_decl(c, e, d, NULL); + if (d != nullptr) { + check_entity_decl(c, e, d, nullptr); } } @@ -190,7 +190,7 @@ i64 check_distance_between_types(Checker *c, Operand *operand, Type *type) { } if (dst->kind == Type_Basic) { if (operand->mode == Addressing_Constant) { - if (check_representable_as_constant(c, operand->value, dst, NULL)) { + if (check_representable_as_constant(c, operand->value, dst, nullptr)) { if (is_type_typed(dst) && src->kind == Type_Basic) { switch (src->Basic.kind) { case Basic_UntypedRune: @@ -358,26 +358,26 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n if (is_type_untyped(operand->type)) { Type *target_type = type; - if (type == NULL || is_type_any(type)) { - if (type == NULL && is_type_untyped_nil(operand->type)) { + if (type == nullptr || is_type_any(type)) { + if (type == nullptr && is_type_untyped_nil(operand->type)) { error(operand->expr, "Use of untyped nil in %.*s", LIT(context_name)); operand->mode = Addressing_Invalid; return; } - if (type == NULL && is_type_untyped_undef(operand->type)) { + if (type == nullptr && is_type_untyped_undef(operand->type)) { error(operand->expr, "Use of --- in %.*s", LIT(context_name)); operand->mode = Addressing_Invalid; return; } target_type = default_type(operand->type); - if (type != NULL && !is_type_any(type)) { + if (type != nullptr && !is_type_any(type)) { GB_ASSERT_MSG(is_type_typed(target_type), "%s", type_to_string(type)); } add_type_info_type(c, type); add_type_info_type(c, target_type); } - if (target_type != NULL && is_type_vector(target_type)) { + if (target_type != nullptr && is_type_vector(target_type)) { // NOTE(bill): continue to below } else { convert_to_typed(c, operand, target_type, 0); @@ -387,7 +387,7 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n } } - if (type == NULL) { + if (type == nullptr) { return; } @@ -424,8 +424,8 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n void populate_using_entity_map(Checker *c, AstNode *node, Type *t, Map *entity_map) { t = base_type(type_deref(t)); - gbString str = NULL; - if (node != NULL) { + gbString str = nullptr; + if (node != nullptr) { expr_to_string(node); } @@ -436,17 +436,17 @@ void populate_using_entity_map(Checker *c, AstNode *node, Type *t, Map String name = f->token.string; HashKey key = hash_string(name); Entity **found = map_get(entity_map, key); - if (found != NULL) { + if (found != nullptr) { Entity *e = *found; // TODO(bill): Better type error - if (str != NULL) { + if (str != nullptr) { error(e->token, "`%.*s` is already declared in `%s`", LIT(name), str); } else { error(e->token, "`%.*s` is already declared`", LIT(name)); } } else { map_set(entity_map, key, f); - add_entity(c, c->context.scope, NULL, f); + add_entity(c, c->context.scope, nullptr, f); if (f->flags & EntityFlag_Using) { populate_using_entity_map(c, node, f->type, entity_map); } @@ -467,9 +467,9 @@ isize check_fields(Checker *c, AstNode *node, Array decls, Map entity_map = {}; map_init_with_reserve(&entity_map, c->tmp_allocator, 2*field_count); - Entity *using_index_expr = NULL; + Entity *using_index_expr = nullptr; - if (node != NULL) { + if (node != nullptr) { GB_ASSERT(node->kind != AstNode_UnionType); } @@ -508,7 +508,7 @@ isize check_fields(Checker *c, AstNode *node, Array decls, } else { HashKey key = hash_string(name_token.string); Entity **found = map_get(&entity_map, key); - if (found != NULL) { + if (found != nullptr) { Entity *e = *found; // NOTE(bill): Scope checking already checks the declaration but in many cases, this can happen so why not? // This may be a little janky but it's not really that much of a problem @@ -580,8 +580,8 @@ GB_COMPARE_PROC(cmp_reorder_struct_fields) { // if same size: order by source order Entity *x = *(Entity **)a; Entity *y = *(Entity **)b; - GB_ASSERT(x != NULL); - GB_ASSERT(y != NULL); + GB_ASSERT(x != nullptr); + GB_ASSERT(y != nullptr); GB_ASSERT(x->kind == Entity_Variable); GB_ASSERT(y->kind == Entity_Variable); bool xu = (x->flags & EntityFlag_Using) != 0; @@ -644,7 +644,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) { if (!struct_type->failure && !st->is_packed && !st->is_ordered) { struct_type->failure = false; struct_type->Record.are_offsets_set = false; - struct_type->Record.offsets = NULL; + struct_type->Record.offsets = nullptr; // NOTE(bill): Reorder fields for reduced size/performance Entity **reordered_fields = gb_alloc_array(c->allocator, Entity *, field_count); @@ -668,7 +668,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) { type_set_offsets(c->allocator, struct_type); - if (st->align != NULL) { + if (st->align != nullptr) { if (st->is_packed) { syntax_error(st->align, "`#align` cannot be applied with `#packed`"); return; @@ -727,15 +727,15 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n Map entity_map = {}; // Key: String map_init_with_reserve(&entity_map, c->tmp_allocator, 2*variant_count); - Entity *using_index_expr = NULL; + Entity *using_index_expr = nullptr; Entity **variants = gb_alloc_array(c->allocator, Entity *, variant_count); Entity **fields = gb_alloc_array(c->allocator, Entity *, field_count); isize variant_index = 0; - variants[variant_index++] = make_entity_type_name(c->allocator, c->context.scope, empty_token, NULL); + variants[variant_index++] = make_entity_type_name(c->allocator, c->context.scope, empty_token, nullptr); - field_count = check_fields(c, NULL, ut->fields, fields, field_count, str_lit("union")); + field_count = check_fields(c, nullptr, ut->fields, fields, field_count, str_lit("union")); for (isize i = 0; i < field_count; i++) { Entity *f = fields[i]; @@ -749,7 +749,7 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n union_type->Record.are_offsets_set = false; union_type->Record.is_ordered = true; { - Entity *__tag = make_entity_field(c->allocator, NULL, make_token_ident(str_lit("__tag")), t_int, false, -1); + Entity *__tag = make_entity_field(c->allocator, nullptr, make_token_ident(str_lit("__tag")), t_int, false, -1); union_type->Record.union__tag = __tag; } @@ -780,7 +780,7 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n Token token = name_token; token.kind = Token_struct; - AstNode *dummy_struct = ast_struct_type(c->curr_ast_file, token, list, list_count, false, true, NULL); + AstNode *dummy_struct = ast_struct_type(c->curr_ast_file, token, list, list_count, false, true, nullptr); check_open_scope(c, dummy_struct); Entity **fields = gb_alloc_array(c->allocator, Entity *, list_count); @@ -792,7 +792,7 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n base_type->Record.field_count = field_count; base_type->Record.names = make_names_field_for_record(c, c->context.scope); base_type->Record.node = dummy_struct; - base_type->Record.variant_parent = named_type != NULL ? named_type : union_type; + base_type->Record.variant_parent = named_type != nullptr ? named_type : union_type; base_type->Record.variant_index = variant_index; @@ -801,7 +801,7 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n check_close_scope(c); } - Type *type = make_type_named(c->allocator, name_token.string, base_type, NULL); + Type *type = make_type_named(c->allocator, name_token.string, base_type, nullptr); Entity *e = make_entity_type_name(c->allocator, c->context.scope, name_token, type); type->Named.type_name = e; add_entity(c, c->context.scope, f->name, e); @@ -812,7 +812,7 @@ void check_union_type(Checker *c, Type *named_type, Type *union_type, AstNode *n } HashKey key = hash_string(name_token.string); - if (map_get(&entity_map, key) != NULL) { + if (map_get(&entity_map, key) != nullptr) { // NOTE(bill): Scope checking already checks the declaration error(name_token, "`%.*s` is already declared in this union", LIT(name_token.string)); } else { @@ -862,11 +862,11 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); Type *base_type = t_int; - if (et->base_type != NULL) { + if (et->base_type != nullptr) { base_type = check_type(c, et->base_type); } - if (base_type == NULL || !(is_type_integer(base_type) || is_type_float(base_type))) { + if (base_type == nullptr || !(is_type_integer(base_type) || is_type_float(base_type))) { error(node, "Base type for enumeration must be numeric"); return; } @@ -885,7 +885,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod isize field_count = 0; Type *constant_type = enum_type; - if (named_type != NULL) { + if (named_type != nullptr) { constant_type = named_type; } @@ -895,11 +895,11 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod for_array(i, et->fields) { AstNode *field = et->fields[i]; - AstNode *ident = NULL; - AstNode *init = NULL; + AstNode *ident = nullptr; + AstNode *init = nullptr; if (field->kind == AstNode_FieldValue) { ast_node(fv, FieldValue, field); - if (fv->field == NULL || fv->field->kind != AstNode_Ident) { + if (fv->field == nullptr || fv->field->kind != AstNode_Ident) { error(field, "An enum field's name must be an identifier"); continue; } @@ -913,7 +913,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod } String name = ident->Ident.token.string; - if (init != NULL) { + if (init != nullptr) { Operand o = {}; check_expr(c, &o, init); if (o.mode != Addressing_Constant) { @@ -965,11 +965,11 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod e->flags |= EntityFlag_Visited; HashKey key = hash_string(name); - if (map_get(&entity_map, key) != NULL) { + if (map_get(&entity_map, key) != nullptr) { error(ident, "`%.*s` is already declared in this enumeration", LIT(name)); } else { map_set(&entity_map, key, e); - add_entity(c, c->context.scope, NULL, e); + add_entity(c, c->context.scope, nullptr, e); fields[field_count++] = e; add_entity_use(c, field, e); } @@ -1044,11 +1044,11 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As HashKey key = hash_string(name); if (name != "_" && - map_get(&entity_map, key) != NULL) { + map_get(&entity_map, key) != nullptr) { error(ident, "`%.*s` is already declared in this bit field", LIT(name)); } else { map_set(&entity_map, key, e); - add_entity(c, c->context.scope, NULL, e); + add_entity(c, c->context.scope, nullptr, e); add_entity_use(c, field, e); fields [field_count] = e; @@ -1068,7 +1068,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As bit_field_type->BitField.offsets = offsets; - if (bft->align != NULL) { + if (bft->align != nullptr) { Operand o = {}; check_expr(c, &o, bft->align); if (o.mode != Addressing_Constant) { @@ -1203,8 +1203,8 @@ Type *determine_type_from_polymorphic(Checker *c, Type *poly_type, Operand opera } Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_variadic_, bool *success_, Array *operands) { - if (_params == NULL) { - return NULL; + if (_params == nullptr) { + return nullptr; } bool allow_polymorphic_types = c->context.allow_polymorphic_types; @@ -1215,7 +1215,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari if (params.count == 0) { if (success_) *success_ = success; - return NULL; + return nullptr; } @@ -1229,7 +1229,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } } - if (operands != NULL) { + if (operands != nullptr) { GB_ASSERT_MSG(operands->count >= variable_count, "%td vs %td", operands->count, variable_count); } @@ -1245,7 +1245,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } ast_node(p, Field, param); AstNode *type_expr = p->type; - Type *type = NULL; + Type *type = nullptr; AstNode *default_value = unparen_expr(p->default_value); ExactValue value = {}; bool default_is_nil = false; @@ -1255,7 +1255,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari bool detemine_type_from_operand = false; - if (type_expr == NULL) { + if (type_expr == nullptr) { if (default_value->kind == AstNode_BasicDirective && default_value->BasicDirective.name == "caller_location") { init_preload(c); @@ -1286,7 +1286,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } if (type_expr->kind == AstNode_TypeType) { is_type_param = true; - if (operands != NULL) { + if (operands != nullptr) { detemine_type_from_operand = true; type = t_invalid; } else { @@ -1294,7 +1294,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } } else { bool prev = c->context.allow_polymorphic_types; - if (operands != NULL) { + if (operands != nullptr) { c->context.allow_polymorphic_types = true; } type = check_type(c, type_expr); @@ -1306,7 +1306,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } } - if (default_value != NULL) { + if (default_value != nullptr) { if (type_expr->kind == AstNode_TypeType) { error(default_value, "A type parameter may not have a default value"); } else { @@ -1334,7 +1334,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } } - if (type == NULL) { + if (type == nullptr) { error(params[i], "Invalid parameter type"); type = t_invalid; } @@ -1349,7 +1349,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari if (p->flags&FieldFlag_c_vararg) { - if (p->type == NULL || + if (p->type == nullptr || p->type->kind != AstNode_Ellipsis) { error(params[i], "`#c_vararg` can only be applied to variadic type fields"); p->flags &= ~FieldFlag_c_vararg; // Remove the flag @@ -1362,9 +1362,9 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari for_array(j, p->names) { AstNode *name = p->names[j]; if (ast_node_expect(name, AstNode_Ident)) { - Entity *param = NULL; + Entity *param = nullptr; if (is_type_param) { - if (operands != NULL) { + if (operands != nullptr) { Operand o = (*operands)[variable_index]; if (o.mode == Addressing_Type) { type = o.type; @@ -1379,7 +1379,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari param = make_entity_type_name(c->allocator, scope, name->Ident.token, type); param->TypeName.is_type_alias = true; } else { - if (operands != NULL && is_type_polymorphic_type) { + if (operands != nullptr && is_type_polymorphic_type) { Operand op = (*operands)[variable_index]; type = determine_type_from_polymorphic(c, type, op); if (type == t_invalid) { @@ -1436,14 +1436,14 @@ Type *check_get_params(Checker *c, Scope *scope, AstNode *_params, bool *is_vari } Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) { - if (_results == NULL) { - return NULL; + if (_results == nullptr) { + return nullptr; } ast_node(field_list, FieldList, _results); Array results = field_list->list; if (results.count == 0) { - return NULL; + return nullptr; } Type *tuple = make_type_tuple(c->allocator); @@ -1464,8 +1464,8 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) { ExactValue value = {}; bool default_is_nil = false; - Type *type = NULL; - if (field->type == NULL) { + Type *type = nullptr; + if (field->type == nullptr) { Operand o = {}; check_expr(c, &o, default_value); if (is_operand_nil(o)) { @@ -1480,7 +1480,7 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) { } else { type = check_type(c, field->type); - if (default_value != NULL) { + if (default_value != nullptr) { Operand o = {}; check_expr_with_type_hint(c, &o, default_value, type); @@ -1495,7 +1495,7 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) { } } - if (type == NULL) { + if (type == nullptr) { error(results[i], "Invalid parameter type"); type = t_invalid; } @@ -1515,7 +1515,7 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) { } else { for_array(j, field->names) { Token token = ast_node_token(results[i]); - if (field->type != NULL) { + if (field->type != nullptr) { token = ast_node_token(field->type); } token.string = str_lit(""); @@ -1647,7 +1647,7 @@ Type *type_to_abi_compat_param_type(gbAllocator a, Type *original_type) { } Type *reduce_tuple_to_single_type(Type *original_type) { - if (original_type != NULL) { + if (original_type != nullptr) { Type *t = core_type(original_type); if (t->kind == Type_Tuple && t->Tuple.variable_count == 1) { return t->Tuple.variables[0]->type; @@ -1658,8 +1658,8 @@ Type *reduce_tuple_to_single_type(Type *original_type) { Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type) { Type *new_type = original_type; - if (new_type == NULL) { - return NULL; + if (new_type == nullptr) { + return nullptr; } GB_ASSERT(is_type_tuple(original_type)); @@ -1710,7 +1710,7 @@ Type *type_to_abi_compat_result_type(gbAllocator a, Type *original_type) { } bool abi_compat_return_by_value(gbAllocator a, ProcCallingConvention cc, Type *abi_return_type) { - if (abi_return_type == NULL) { + if (abi_return_type == nullptr) { return false; } switch (cc) { @@ -1737,7 +1737,7 @@ bool abi_compat_return_by_value(gbAllocator a, ProcCallingConvention cc, Type *a } // NOTE(bill): `operands` is for generating non generic procedure type -bool check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node, Array *operands = NULL) { +bool check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node, Array *operands = nullptr) { ast_node(pt, ProcType, proc_type_node); bool variadic = false; @@ -1815,7 +1815,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * String name = n->Ident.token.string; Entity *e = scope_lookup_entity(c->context.scope, name); - if (e == NULL) { + if (e == nullptr) { if (name == "_") { error(n, "`_` cannot be used as a value type"); } else { @@ -1823,19 +1823,19 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * } o->type = t_invalid; o->mode = Addressing_Invalid; - if (named_type != NULL) { + if (named_type != nullptr) { set_base_type(named_type, t_invalid); } - return NULL; + return nullptr; } - if (e->parent_proc_decl != NULL && + if (e->parent_proc_decl != nullptr && e->parent_proc_decl != c->context.curr_proc_decl) { if (e->kind == Entity_Variable) { error(n, "Nested procedures do not capture its parent's variables: %.*s", LIT(name)); - return NULL; + return nullptr; } else if (e->kind == Entity_Label) { error(n, "Nested procedures do not capture its parent's labels: %.*s", LIT(name)); - return NULL; + return nullptr; } } @@ -1844,7 +1844,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * bool is_alias = false; while (e->kind == Entity_Alias) { - GB_ASSERT(e->Alias.base != NULL); + GB_ASSERT(e->Alias.base != nullptr); e = e->Alias.base; is_alias = true; } @@ -1867,7 +1867,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * Entity **procs = gb_alloc_array(heap_allocator(), Entity *, overload_count); multi_map_get_all(&s->elements, key, procs); - if (type_hint != NULL) { + if (type_hint != nullptr) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); // NOTE(bill): These should be done for (isize i = 0; i < overload_count; i++) { @@ -1894,18 +1894,18 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * o->type = t_invalid; o->overload_count = overload_count; o->overload_entities = procs; - return NULL; + return nullptr; } gb_free(heap_allocator(), procs); } add_entity_use(c, n, e); - check_entity_decl(c, e, NULL, named_type); + check_entity_decl(c, e, nullptr, named_type); - if (e->type == NULL) { + if (e->type == nullptr) { compiler_error("How did this happen? type: %s; identifier: %.*s\n", type_to_string(e->type), LIT(name)); - // return NULL; + // return nullptr; } e->flags |= EntityFlag_Used; @@ -1979,7 +1979,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * } i64 check_array_or_map_count(Checker *c, AstNode *e, bool is_map) { - if (e == NULL) { + if (e == nullptr) { return 0; } Operand o = {}; @@ -2031,8 +2031,8 @@ Type *make_optional_ok_type(gbAllocator a, Type *value) { Type *t = make_type_tuple(a); t->Tuple.variables = gb_alloc_array(a, Entity *, 2); t->Tuple.variable_count = 2; - t->Tuple.variables[0] = make_entity_field(a, NULL, blank_token, value, false, 0); - t->Tuple.variables[1] = make_entity_field(a, NULL, blank_token, typed ? t_bool : t_untyped_bool, false, 1); + t->Tuple.variables[0] = make_entity_field(a, nullptr, blank_token, value, false, 0); + t->Tuple.variables[1] = make_entity_field(a, nullptr, blank_token, typed ? t_bool : t_untyped_bool, false, 1); return t; } @@ -2068,7 +2068,7 @@ void check_map_type(Checker *c, Type *type, AstNode *node) { { // NOTE(bill): The preload types may have not been set yet init_preload(c); - GB_ASSERT(t_map_key != NULL); + GB_ASSERT(t_map_key != nullptr); Type *entry_type = make_type_struct(a); @@ -2138,7 +2138,7 @@ void check_map_type(Checker *c, Type *type, AstNode *node) { bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type) { GB_ASSERT_NOT_NULL(type); - if (e == NULL) { + if (e == nullptr) { *type = t_invalid; return true; } @@ -2146,7 +2146,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type) switch (e->kind) { case_ast_node(i, Ident, e); Operand o = {}; - check_ident(c, &o, e, named_type, NULL, false); + check_ident(c, &o, e, named_type, nullptr, false); switch (o.mode) { case Addressing_Invalid: @@ -2194,13 +2194,13 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type) case_ast_node(se, SelectorExpr, e); Operand o = {}; - check_selector(c, &o, e, NULL); + check_selector(c, &o, e, nullptr); switch (o.mode) { case Addressing_Invalid: break; case Addressing_Type: - GB_ASSERT(o.type != NULL); + GB_ASSERT(o.type != nullptr); *type = o.type; return true; case Addressing_NoValue: { @@ -2246,8 +2246,8 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type) case_end; case_ast_node(at, ArrayType, e); - if (at->count != NULL) { - Type *elem = check_type(c, at->elem, NULL); + if (at->count != nullptr) { + Type *elem = check_type(c, at->elem, nullptr); i64 count = check_array_or_map_count(c, at->count, false); if (count < 0) { error(at->count, ".. can only be used in conjuction with compound literals"); @@ -2388,7 +2388,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type) Type *check_type(Checker *c, AstNode *e, Type *named_type) { - Type *type = NULL; + Type *type = nullptr; bool ok = check_type_internal(c, e, &type, named_type); if (!ok) { @@ -2398,12 +2398,12 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) { type = t_invalid; } - if (type == NULL) { + if (type == nullptr) { type = t_invalid; } if (type->kind == Type_Named) { - if (type->Named.base == NULL) { + if (type->Named.base == nullptr) { gbString name = type_to_string(type); error(e, "Invalid type definition of %s", name); gb_string_free(name); @@ -2435,7 +2435,7 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) { bool check_unary_op(Checker *c, Operand *o, Token op) { - if (o->type == NULL) { + if (o->type == nullptr) { gbString str = expr_to_string(o->expr); error(o->expr, "Expression has no value `%s`", str); gb_string_free(str); @@ -2443,7 +2443,7 @@ bool check_unary_op(Checker *c, Operand *o, Token op) { } // TODO(bill): Handle errors correctly Type *type = base_type(base_vector_type(o->type)); - gbString str = NULL; + gbString str = nullptr; switch (op.kind) { case Token_Add: case Token_Sub: @@ -2701,7 +2701,7 @@ bool check_is_expr_vector_index(Checker *c, AstNode *expr) { if (expr->kind == AstNode_IndexExpr) { ast_node(ie, IndexExpr, expr); Type *t = type_deref(type_of_expr(&c->info, ie->expr)); - if (t != NULL) { + if (t != nullptr) { return is_type_vector(t); } } @@ -2714,7 +2714,7 @@ bool check_is_vector_elem(Checker *c, AstNode *expr) { if (expr->kind == AstNode_SelectorExpr) { ast_node(se, SelectorExpr, expr); Type *t = type_deref(type_of_expr(&c->info, se->expr)); - if (t != NULL && is_type_vector(t)) { + if (t != nullptr && is_type_vector(t)) { return true; } } @@ -2786,7 +2786,7 @@ void check_unary_expr(Checker *c, Operand *o, Token op, AstNode *node) { o->value = exact_unary_operator_value(op.kind, o->value, precision); if (is_type_typed(type)) { - if (node != NULL) { + if (node != nullptr) { o->expr = node; } check_is_expressible(c, o, type); @@ -2811,9 +2811,9 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) { return; } - gbString err_str = NULL; + gbString err_str = nullptr; - defer (if (err_str != NULL) { + defer (if (err_str != nullptr) { gb_string_free(err_str); }); gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); @@ -2858,7 +2858,7 @@ void check_comparison(Checker *c, Operand *x, Operand *y, TokenKind op) { gb_string_free(xt); } - if (err_str != NULL) { + if (err_str != nullptr) { error(x->expr, "Cannot compare expression, %s", err_str); x->type = t_untyped_bool; } else { @@ -2954,7 +2954,7 @@ void check_shift(Checker *c, Operand *x, Operand *y, AstNode *node) { TokenPos pos = ast_node_token(x->expr).pos; if (x_is_untyped) { ExprInfo *info = check_get_expr_info(&c->info, x->expr); - if (info != NULL) { + if (info != nullptr) { info->is_lhs = true; } x->mode = Addressing_Value; @@ -3395,7 +3395,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { } x->value = exact_binary_operator_value(op.kind, a, b); if (is_type_typed(type)) { - if (node != NULL) { + if (node != nullptr) { x->expr = node; } check_is_expressible(c, x, type); @@ -3409,7 +3409,7 @@ void check_binary_expr(Checker *c, Operand *x, AstNode *node) { void update_expr_type(Checker *c, AstNode *e, Type *type, bool final) { ExprInfo *found = check_get_expr_info(&c->info, e); - if (found == NULL) { + if (found == nullptr) { return; } ExprInfo old = *found; @@ -3667,7 +3667,7 @@ bool check_index_value(Checker *c, bool open_range, AstNode *index_value, i64 ma isize entity_overload_count(Scope *s, String name) { Entity *e = scope_lookup_entity(s, name); - if (e == NULL) { + if (e == nullptr) { return 0; } if (e->kind == Entity_Procedure) { @@ -3678,7 +3678,7 @@ isize entity_overload_count(Scope *s, String name) { } bool check_is_field_exported(Checker *c, Entity *field) { - if (field == NULL) { + if (field == nullptr) { // NOTE(bill): Just incase return true; } @@ -3686,7 +3686,7 @@ bool check_is_field_exported(Checker *c, Entity *field) { return true; } Scope *file_scope = field->scope; - if (file_scope == NULL) { + if (file_scope == nullptr) { return true; } while (!file_scope->is_file) { @@ -3702,18 +3702,18 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h ast_node(se, SelectorExpr, node); bool check_op_expr = true; - Entity *expr_entity = NULL; - Entity *entity = NULL; + Entity *expr_entity = nullptr; + Entity *entity = nullptr; Selection sel = {}; // NOTE(bill): Not used if it's an import name operand->expr = node; AstNode *op_expr = se->expr; AstNode *selector = unparen_expr(se->selector); - if (selector == NULL) { + if (selector == nullptr) { operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } if (selector->kind != AstNode_Ident && selector->kind != AstNode_BasicLit) { @@ -3721,7 +3721,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h error(selector, "Illegal selector kind: `%.*s`", LIT(ast_node_strings[selector->kind])); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } if (op_expr->kind == AstNode_Ident) { @@ -3732,7 +3732,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h expr_entity = e; Entity *original_e = e; - if (e != NULL && e->kind == Entity_ImportName && selector->kind == AstNode_Ident) { + if (e != nullptr && e->kind == Entity_ImportName && selector->kind == AstNode_Ident) { // IMPORTANT NOTE(bill): This is very sloppy code but it's also very fragile // It pretty much needs to be in this order and this way // If you can clean this up, please do but be really careful @@ -3742,7 +3742,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h check_op_expr = false; entity = scope_lookup_entity(import_scope, entity_name); - bool is_declared = entity != NULL; + bool is_declared = entity != nullptr; if (is_declared) { if (entity->kind == Entity_Builtin) { // NOTE(bill): Builtin's are in the universe scope which is part of every scopes hierarchy @@ -3756,10 +3756,10 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h error(op_expr, "`%.*s` is not declared by `%.*s`", LIT(entity_name), LIT(import_name)); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } - check_entity_decl(c, entity, NULL, NULL); - GB_ASSERT(entity->type != NULL); + check_entity_decl(c, entity, nullptr, nullptr); + GB_ASSERT(entity->type != nullptr); isize overload_count = entity_overload_count(import_scope, entity_name); bool is_overloaded = overload_count > 1; @@ -3778,7 +3778,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h gb_string_free(sel_str); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } if (is_overloaded) { @@ -3805,7 +3805,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h Operand x = {}; x.mode = Addressing_Value; x.type = t; - if (type_hint != NULL) { + if (type_hint != nullptr) { if (check_is_assignable_to(c, &x, type_hint)) { entity = procs[i]; skip = true; @@ -3827,16 +3827,16 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h } if (check_op_expr) { - check_expr_base(c, operand, op_expr, NULL); + check_expr_base(c, operand, op_expr, nullptr); if (operand->mode == Addressing_Invalid) { operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } } - if (entity == NULL && selector->kind == AstNode_Ident) { + if (entity == nullptr && selector->kind == AstNode_Ident) { String field_name = selector->Ident.token.string; sel = lookup_field(c->allocator, operand->type, field_name, operand->mode == Addressing_Type); @@ -3844,16 +3844,16 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h error(op_expr, "`%.*s` is an unexported field", LIT(field_name)); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } entity = sel.entity; // NOTE(bill): Add type info needed for fields like `names` - if (entity != NULL && (entity->flags&EntityFlag_TypeField)) { + if (entity != nullptr && (entity->flags&EntityFlag_TypeField)) { add_type_info_type(c, operand->type); } } - if (entity == NULL && selector->kind == AstNode_BasicLit) { + if (entity == nullptr && selector->kind == AstNode_BasicLit) { if (is_type_struct(operand->type) || is_type_tuple(operand->type)) { Type *type = base_type(operand->type); Operand o = {}; @@ -3863,14 +3863,14 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h error(op_expr, "Indexed based selectors must be a constant integer %s"); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } i64 index = i128_to_i64(o.value.value_integer); if (index < 0) { error(o.expr, "Index %lld cannot be a negative value", index); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } i64 max_count = 0; @@ -3883,32 +3883,32 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h error(o.expr, "Index %lld is out of bounds range 0..<%lld", index, max_count); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } sel = lookup_field_from_index(heap_allocator(), type, index); entity = sel.entity; - GB_ASSERT(entity != NULL); + GB_ASSERT(entity != nullptr); } else { error(op_expr, "Indexed based selectors may only be used on structs or tuples"); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } } - if (entity == NULL && - operand->type != NULL && is_type_untyped(operand->type) && is_type_string(operand->type)) { + if (entity == nullptr && + operand->type != nullptr && is_type_untyped(operand->type) && is_type_string(operand->type)) { String s = operand->value.value_string; operand->mode = Addressing_Constant; operand->value = exact_value_i64(s.len); operand->type = t_untyped_integer; - return NULL; + return nullptr; } - if (entity == NULL) { + if (entity == nullptr) { gbString op_str = expr_to_string(op_expr); gbString type_str = type_to_string(operand->type); gbString sel_str = expr_to_string(selector); @@ -3918,10 +3918,10 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h gb_string_free(op_str); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } - if (expr_entity != NULL && expr_entity->kind == Entity_Constant && entity->kind != Entity_Constant) { + if (expr_entity != nullptr && expr_entity->kind == Entity_Constant && entity->kind != Entity_Constant) { gbString op_str = expr_to_string(op_expr); gbString type_str = type_to_string(operand->type); gbString sel_str = expr_to_string(selector); @@ -3931,7 +3931,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h gb_string_free(op_str); operand->mode = Addressing_Invalid; operand->expr = node; - return NULL; + return nullptr; } @@ -3981,14 +3981,14 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id ast_node(ce, CallExpr, call); BuiltinProc *bp = &builtin_procs[id]; { - char *err = NULL; + char *err = nullptr; if (ce->args.count < bp->arg_count) { err = "Too few"; } else if (ce->args.count > bp->arg_count && !bp->variadic) { err = "Too many"; } - if (err != NULL) { + if (err != nullptr) { gbString expr = expr_to_string(ce->proc); error(ce->close, "%s arguments for `%s`, expected %td, got %td", err, expr, @@ -4044,14 +4044,14 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id } if (ce->args.count > 0) { AstNode *arg = ce->args[0]; - Entity *e = NULL; + Entity *e = nullptr; Operand o = {}; if (arg->kind == AstNode_Ident) { - e = check_ident(c, &o, arg, NULL, NULL, true); + e = check_ident(c, &o, arg, nullptr, nullptr, true); } else if (arg->kind == AstNode_SelectorExpr) { - e = check_selector(c, &o, arg, NULL); + e = check_selector(c, &o, arg, nullptr); } - if (e == NULL) { + if (e == nullptr) { error(ce->args[0], "`#location` expected a valid entity name"); } } @@ -4114,7 +4114,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Operand op = {}; check_expr_or_type(c, &op, ce->args[0]); Type *type = op.type; - if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { + if ((op.mode != Addressing_Type && type == nullptr) || type == t_invalid) { error(ce->args[0], "Expected a type for `new`"); return false; } @@ -4129,7 +4129,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Operand op = {}; check_expr_or_type(c, &op, ce->args[0]); Type *type = op.type; - if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { + if ((op.mode != Addressing_Type && type == nullptr) || type == t_invalid) { error(ce->args[0], "Expected a type for `new_slice`"); return false; } @@ -4167,7 +4167,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Operand op = {}; check_expr_or_type(c, &op, ce->args[0]); Type *type = op.type; - if ((op.mode != Addressing_Type && type == NULL) || type == t_invalid) { + if ((op.mode != Addressing_Type && type == nullptr) || type == t_invalid) { error(ce->args[0], "Expected a type for `make`"); return false; } @@ -4274,7 +4274,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } - operand->type = NULL; + operand->type = nullptr; operand->mode = Addressing_NoValue; } break; #endif @@ -4290,7 +4290,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } - operand->type = NULL; + operand->type = nullptr; operand->mode = Addressing_NoValue; } break; #endif @@ -4319,7 +4319,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } - Type *elem = NULL; + Type *elem = nullptr; if (is_type_dynamic_array(type)) { elem = type->DynamicArray.elem; } else { @@ -4330,9 +4330,9 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Type *proc_type_params = make_type_tuple(c->allocator); proc_type_params->Tuple.variables = gb_alloc_array(c->allocator, Entity *, 2); proc_type_params->Tuple.variable_count = 2; - proc_type_params->Tuple.variables[0] = make_entity_param(c->allocator, NULL, blank_token, operand->type, false, false); - proc_type_params->Tuple.variables[1] = make_entity_param(c->allocator, NULL, blank_token, slice_elem, false, false); - Type *proc_type = make_type_proc(c->allocator, NULL, proc_type_params, 2, NULL, false, true, ProcCC_Odin); + proc_type_params->Tuple.variables[0] = make_entity_param(c->allocator, nullptr, blank_token, operand->type, false, false); + proc_type_params->Tuple.variables[1] = make_entity_param(c->allocator, nullptr, blank_token, slice_elem, false, false); + Type *proc_type = make_type_proc(c->allocator, nullptr, proc_type_params, 2, nullptr, false, true, ProcCC_Odin); check_call_arguments(c, &prev_operand, proc_type, call); @@ -4385,7 +4385,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } Type *t = o.type; - if (t == NULL || t == t_invalid) { + if (t == nullptr || t == t_invalid) { error(ce->args[0], "Invalid argument for `size_of`"); return false; } @@ -4404,7 +4404,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } Type *t = o.type; - if (t == NULL || t == t_invalid) { + if (t == nullptr || t == t_invalid) { error(ce->args[0], "Invalid argument for `align_of`"); return false; } @@ -4421,13 +4421,13 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Operand op = {}; Type *bt = check_type(c, ce->args[0]); Type *type = base_type(bt); - if (type == NULL || type == t_invalid) { + if (type == nullptr || type == t_invalid) { error(ce->args[0], "Expected a type for `offset_of`"); return false; } AstNode *field_arg = unparen_expr(ce->args[1]); - if (field_arg == NULL || + if (field_arg == nullptr || field_arg->kind != AstNode_Ident) { error(field_arg, "Expected an identifier for field argument"); return false; @@ -4440,7 +4440,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id ast_node(arg, Ident, field_arg); Selection sel = lookup_field(c->allocator, type, arg->token.string, operand->mode == Addressing_Type); - if (sel.entity == NULL) { + if (sel.entity == nullptr) { gbString type_str = type_to_string(bt); error(ce->args[0], "`%s` has no field named `%.*s`", type_str, LIT(arg->token.string)); @@ -4463,11 +4463,11 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id case BuiltinProc_type_of: // proc type_of(val: Type) -> type(Type) - check_assignment(c, operand, NULL, str_lit("argument of `type_of`")); + check_assignment(c, operand, nullptr, str_lit("argument of `type_of`")); if (operand->mode == Addressing_Invalid || operand->mode == Addressing_Builtin) { return false; } - if (operand->type == NULL || operand->type == t_invalid) { + if (operand->type == nullptr || operand->type == t_invalid) { error(operand->expr, "Invalid argument to `type_of`"); return false; } @@ -4494,7 +4494,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id return false; } Type *t = o.type; - if (t == NULL || t == t_invalid || is_type_polymorphic(operand->type)) { + if (t == nullptr || t == t_invalid || is_type_polymorphic(operand->type)) { error(ce->args[0], "Invalid argument for `type_info`"); return false; } @@ -5047,7 +5047,7 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id Operand op = {}; check_expr_or_type(c, &op, ce->args[0]); Type *t = op.type; - if ((op.mode != Addressing_Type && t == NULL) || t == t_invalid) { + if ((op.mode != Addressing_Type && t == nullptr) || t == t_invalid) { error(ce->args[0], "Expected a type for `transmute`"); return false; } @@ -5113,7 +5113,7 @@ bool check_unpack_arguments(Checker *c, isize lhs_count, Array *operand bool optional_ok = false; for_array(i, rhs) { Operand o = {}; - check_expr_base(c, &o, rhs[i], NULL); + check_expr_base(c, &o, rhs[i], nullptr); if (o.mode == Addressing_NoValue) { error_operand_no_value(&o); o.mode = Addressing_Invalid; @@ -5121,7 +5121,7 @@ bool check_unpack_arguments(Checker *c, isize lhs_count, Array *operand // check_multi_expr(c, &o, rhs[i]); - if (o.type == NULL || o.type->kind != Type_Tuple) { + if (o.type == nullptr || o.type->kind != Type_Tuple) { if (allow_ok && lhs_count == 2 && rhs.count == 1 && (o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk)) { Type *tuple = make_optional_ok_type(c->allocator, o.type); @@ -5151,7 +5151,7 @@ bool check_unpack_arguments(Checker *c, isize lhs_count, Array *operand return optional_ok; } -// NOTE(bill): Returns `NULL` on failure +// NOTE(bill): Returns `nullptr` on failure Entity *find_or_generate_polymorphic_procedure(Checker *c, AstNode *call, Entity *base_entity, CallArgumentCheckerType *call_checker, Array *operands, ProcedureInfo *proc_info_) { /////////////////////////////////////////////////////////////////////////////// @@ -5159,21 +5159,21 @@ Entity *find_or_generate_polymorphic_procedure(Checker *c, AstNode *call, Entity // TODO CLEANUP(bill): This procedure is very messy and hacky. Clean this!!! // // // /////////////////////////////////////////////////////////////////////////////// - if (base_entity == NULL) { - return NULL; + if (base_entity == nullptr) { + return nullptr; } if (!is_type_proc(base_entity->type)) { - return NULL; + return nullptr; } TypeProc *pt = &base_type(base_entity->type)->Proc; if (!pt->is_polymorphic || pt->is_poly_specialized) { - return NULL; + return nullptr; } DeclInfo *old_decl = decl_info_of_entity(&c->info, base_entity); - GB_ASSERT(old_decl != NULL); + GB_ASSERT(old_decl != nullptr); gbAllocator a = heap_allocator(); @@ -5189,12 +5189,12 @@ Entity *find_or_generate_polymorphic_procedure(Checker *c, AstNode *call, Entity // NOTE(bill): This is slightly memory leaking if the type already exists // Maybe it's better to check with the previous types first? - Type *final_proc_type = make_type_proc(c->allocator, scope, NULL, 0, NULL, 0, false, pt->calling_convention); + Type *final_proc_type = make_type_proc(c->allocator, scope, nullptr, 0, nullptr, 0, false, pt->calling_convention); bool success = check_procedure_type(c, final_proc_type, pt->node, operands); if (!success) { ProcedureInfo proc_info = {}; if (proc_info_) *proc_info_ = proc_info; - return NULL; + return nullptr; } auto *found_gen_procs = map_get(&c->info.gen_procs, hash_pointer(base_entity->identifier)); @@ -5226,7 +5226,7 @@ Entity *find_or_generate_polymorphic_procedure(Checker *c, AstNode *call, Entity if (!success) { ProcedureInfo proc_info = {}; if (proc_info_) *proc_info_ = proc_info; - return NULL; + return nullptr; } if (found_gen_procs) { @@ -5259,17 +5259,17 @@ Entity *find_or_generate_polymorphic_procedure(Checker *c, AstNode *call, Entity d->proc_lit = proc_lit; - Entity *entity = make_entity_procedure(c->allocator, NULL, token, final_proc_type, tags); + Entity *entity = make_entity_procedure(c->allocator, nullptr, token, final_proc_type, tags); entity->identifier = ident; add_entity_and_decl_info(c, ident, entity, d); // NOTE(bill): Set the scope afterwards as this is not real overloading entity->scope = scope->parent; - AstFile *file = NULL; + AstFile *file = nullptr; { Scope *s = entity->scope; - while (s != NULL && s->file == NULL) { + while (s != nullptr && s->file == nullptr) { s = s->parent; } file = s->file; @@ -5293,7 +5293,7 @@ Entity *find_or_generate_polymorphic_procedure(Checker *c, AstNode *call, Entity map_set(&c->info.gen_procs, hash_pointer(base_entity->identifier), array); } - GB_ASSERT(entity != NULL); + GB_ASSERT(entity != nullptr); if (proc_info_) *proc_info_ = proc_info; @@ -5314,9 +5314,9 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { bool show_error = show_error_mode == CallArgumentMode_ShowErrors; - TypeTuple *param_tuple = NULL; + TypeTuple *param_tuple = nullptr; - if (pt->params != NULL) { + if (pt->params != nullptr) { param_tuple = &pt->params->Tuple; param_count = param_tuple->variable_count; @@ -5326,7 +5326,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { } param_count_excluding_defaults = param_count; - if (param_tuple != NULL) { + if (param_tuple != nullptr) { for (isize i = param_count-1; i >= 0; i--) { Entity *e = param_tuple->variables[i]; if (e->kind == Entity_TypeName) { @@ -5346,7 +5346,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { CallArgumentError err = CallArgumentError_None; Type *final_proc_type = proc_type; - Entity *gen_entity = NULL; + Entity *gen_entity = nullptr; if (vari_expand && !variadic) { if (show_error) { @@ -5390,7 +5390,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { if (pt->is_polymorphic && !pt->is_poly_specialized) { gen_entity = find_or_generate_polymorphic_procedure(c, call, entity, check_call_arguments_internal, &operands, &proc_info); - if (gen_entity != NULL) { + if (gen_entity != nullptr) { GB_ASSERT(is_type_proc(gen_entity->type)); final_proc_type = gen_entity->type; } @@ -5399,7 +5399,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { GB_ASSERT(is_type_proc(final_proc_type)); TypeProc *pt = &final_proc_type->Proc; - GB_ASSERT(pt->params != NULL); + GB_ASSERT(pt->params != nullptr); Entity **sig_params = pt->params->Tuple.variables; isize operand_index = 0; isize max_operand_count = gb_min(param_count, operands.count); @@ -5473,12 +5473,12 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { } } - if (gen_entity != NULL && gen_entity->token.string == "append" && err != CallArgumentError_None) { + if (gen_entity != nullptr && gen_entity->token.string == "append" && err != CallArgumentError_None) { gb_printf_err("append %s with score %lld %d\n", type_to_string(final_proc_type), score, err); } - if (gen_entity != NULL && err == CallArgumentError_None) { - if (proc_info.decl != NULL) { + if (gen_entity != nullptr && err == CallArgumentError_None) { + if (proc_info.decl != nullptr) { // NOTE(bill): Check the newly generated procedure body check_procedure_later(c, proc_info); } @@ -5496,7 +5496,7 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) { } bool is_call_expr_field_value(AstNodeCallExpr *ce) { - GB_ASSERT(ce != NULL); + GB_ASSERT(ce != nullptr); if (ce->args.count == 0) { return false; @@ -5620,12 +5620,12 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) { } } - Entity *gen_entity = NULL; + Entity *gen_entity = nullptr; if (pt->is_polymorphic && !pt->is_poly_specialized && err == CallArgumentError_None) { ProcedureInfo proc_info = {}; gen_entity = find_or_generate_polymorphic_procedure(c, call, entity, check_named_call_arguments, &ordered_operands, &proc_info); - if (gen_entity != NULL) { - if (proc_info.decl != NULL) { + if (gen_entity != nullptr) { + if (proc_info.decl != nullptr) { check_procedure_later(c, proc_info); } Type *gept = base_type(gen_entity->type); @@ -5707,7 +5707,7 @@ CallArgumentData check_call_arguments(Checker *c, Operand *operand, Type *proc_t } if (operand->mode == Addressing_Overload) { - GB_ASSERT(operand->overload_entities != NULL && + GB_ASSERT(operand->overload_entities != nullptr && operand->overload_count > 0); isize overload_count = operand->overload_count; Entity ** procs = operand->overload_entities; @@ -5723,14 +5723,14 @@ CallArgumentData check_call_arguments(Checker *c, Operand *operand, Type *proc_t Entity *e = procs[i]; GB_ASSERT(e->token.string == name); DeclInfo *d = decl_info_of_entity(&c->info, e); - GB_ASSERT(d != NULL); - check_entity_decl(c, e, d, NULL); + GB_ASSERT(d != nullptr); + check_entity_decl(c, e, d, nullptr); } for (isize i = 0; i < overload_count; i++) { Entity *p = procs[i]; Type *pt = base_type(p->type); - if (pt != NULL && is_type_proc(pt)) { + if (pt != nullptr && is_type_proc(pt)) { CallArgumentError err = CallArgumentError_None; CallArgumentData data = {}; CheckerContext prev_context = c->context; @@ -5767,25 +5767,58 @@ CallArgumentData check_call_arguments(Checker *c, Operand *operand, Type *proc_t if (valid_count == 0) { error(operand->expr, "No overloads or ambiguous call for `%.*s` that match with the given arguments", LIT(name)); + gb_printf_err("\tGiven argument types -> ("); + for_array(i, operands) { + Operand o = operands[i]; + if (i > 0) gb_printf_err(", "); + gbString type = type_to_string(o.type); + defer (gb_string_free(type)); + gb_printf_err("%s", type); + } + gb_printf_err(")\n"); + if (overload_count > 0) { gb_printf_err("Did you mean to use one of the following:\n"); } for (isize i = 0; i < overload_count; i++) { Entity *proc = procs[i]; TokenPos pos = proc->token.pos; - // gbString pt = type_to_string(proc->type); - gbString pt = expr_to_string(proc->type->Proc.node); - gb_printf_err("\t%.*s :: %s at %.*s(%td:%td)\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column, cast(long long)valids[i].score); + Type *t = base_type(proc->type); GB_ASSERT(t->kind == Type_Proc); + gbString pt; + if (t->Proc.node != NULL) { + pt = expr_to_string(t->Proc.node); + } else { + pt = type_to_string(t); + } + gb_printf_err("\t%.*s :: %s at %.*s(%td:%td) with score %lld\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column, cast(long long)valids[i].score); + // gb_printf_err("\t%.*s :: %s at %.*s(%td:%td)\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column); gb_string_free(pt); } result_type = t_invalid; } else if (valid_count > 1) { - error(operand->expr, "Ambiguous procedure call `%.*s`, could be:", LIT(name)); + error(operand->expr, "Ambiguous procedure call `%.*s` tha match with the given arguments", LIT(name)); + gb_printf_err("\tGiven argument types -> ("); + for_array(i, operands) { + Operand o = operands[i]; + if (i > 0) gb_printf_err(", "); + gbString type = type_to_string(o.type); + defer (gb_string_free(type)); + gb_printf_err("%s", type); + } + gb_printf_err(")\n"); + for (isize i = 0; i < valid_count; i++) { Entity *proc = procs[valids[i].index]; TokenPos pos = proc->token.pos; - gbString pt = type_to_string(proc->type); - gb_printf_err("\t%.*s :: %s at %.*s(%td:%td) with score %lld\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column, cast(long long)valids[i].score); + Type *t = base_type(proc->type); GB_ASSERT(t->kind == Type_Proc); + gbString pt; + if (t->Proc.node != NULL) { + pt = expr_to_string(t->Proc.node); + } else { + pt = type_to_string(t); + } + // gb_printf_err("\t%.*s :: %s at %.*s(%td:%td) with score %lld\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column, cast(long long)valids[i].score); + gb_printf_err("\t%.*s :: %s at %.*s(%td:%td)\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column); gb_string_free(pt); } result_type = t_invalid; @@ -5801,7 +5834,7 @@ CallArgumentData check_call_arguments(Checker *c, Operand *operand, Type *proc_t proc_type = e->type; CallArgumentData data = {}; CallArgumentError err = call_checker(c, call, proc_type, e, operands, CallArgumentMode_ShowErrors, &data); - if (data.gen_entity != NULL) { + if (data.gen_entity != nullptr) { add_entity_use(c, ident, data.gen_entity); } else { add_entity_use(c, ident, e); @@ -5818,7 +5851,7 @@ CallArgumentData check_call_arguments(Checker *c, Operand *operand, Type *proc_t Entity *e = entity_of_ident(&c->info, ident); CallArgumentData data = {}; CallArgumentError err = call_checker(c, call, proc_type, e, operands, CallArgumentMode_ShowErrors, &data); - if (data.gen_entity != NULL) { + if (data.gen_entity != nullptr) { add_entity_use(c, ident, data.gen_entity); } else { add_entity_use(c, ident, e); @@ -5835,7 +5868,7 @@ CallArgumentData check_call_arguments(Checker *c, Operand *operand, Type *proc_t Entity *find_using_index_expr(Type *t) { t = base_type(t); if (t->kind != Type_Record) { - return NULL; + return nullptr; } for (isize i = 0; i < t->Record.field_count; i++) { @@ -5847,18 +5880,18 @@ Entity *find_using_index_expr(Type *t) { return f; } Entity *res = find_using_index_expr(f->type); - if (res != NULL) { + if (res != nullptr) { return res; } } } - return NULL; + return nullptr; } ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) { GB_ASSERT(call->kind == AstNode_CallExpr); ast_node(ce, CallExpr, call); - if (ce->proc != NULL && + if (ce->proc != nullptr && ce->proc->kind == AstNode_BasicDirective) { ast_node(bd, BasicDirective, ce->proc); String name = bd->name; @@ -5902,7 +5935,7 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) { if (arg->kind == AstNode_FieldValue) { arg = arg->FieldValue.value; } - check_expr_base(c, operand, arg, NULL); + check_expr_base(c, operand, arg, nullptr); } operand->mode = Addressing_Invalid; operand->expr = call; @@ -5946,7 +5979,7 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) { Type *proc_type = base_type(operand->type); if (operand->mode != Addressing_Overload) { - bool valid_type = (proc_type != NULL) && is_type_proc(proc_type); + bool valid_type = (proc_type != nullptr) && is_type_proc(proc_type); bool valid_mode = is_operand_value(*operand); if (!valid_type || !valid_mode) { AstNode *e = operand->expr; @@ -5976,7 +6009,7 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) { } Type *pt = base_type(proc_type); - if (result_type == NULL) { + if (result_type == nullptr) { operand->mode = Addressing_NoValue; } else { GB_ASSERT(is_type_tuple(result_type)); @@ -6013,7 +6046,7 @@ ExprKind check_macro_call_expr(Checker *c, Operand *operand, AstNode *call) { void check_expr_with_type_hint(Checker *c, Operand *o, AstNode *e, Type *t) { check_expr_base(c, o, e, t); check_not_tuple(c, o); - char *err_str = NULL; + char *err_str = nullptr; switch (o->mode) { case Addressing_NoValue: err_str = "used as a value"; @@ -6025,7 +6058,7 @@ void check_expr_with_type_hint(Checker *c, Operand *o, AstNode *e, Type *t) { err_str = "must be called"; break; } - if (err_str != NULL) { + if (err_str != nullptr) { gbString str = expr_to_string(e); error(e, "`%s` %s", str, err_str); gb_string_free(str); @@ -6140,7 +6173,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t case_end; case_ast_node(i, Ident, node); - check_ident(c, o, node, NULL, type_hint, false); + check_ident(c, o, node, nullptr, type_hint, false); case_end; case_ast_node(u, Undef, node); @@ -6199,7 +6232,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t case_ast_node(pl, ProcLit, node); CheckerContext prev_context = c->context; - DeclInfo *decl = NULL; + DeclInfo *decl = nullptr; Type *type = alloc_type(c->allocator, Type_Proc); check_open_scope(c, pl->type); { @@ -6221,7 +6254,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t return kind; } - if (pl->body == NULL) { + if (pl->body == nullptr) { error(node, "A procedure literal must have a body"); return kind; } @@ -6247,15 +6280,15 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t Operand y = {Addressing_Invalid}; check_expr_with_type_hint(c, &x, te->x, type_hint); - if (te->y != NULL) { + if (te->y != nullptr) { check_expr_with_type_hint(c, &y, te->y, type_hint); } else { error(node, "A ternary expression must have an else clause"); return kind; } - if (x.type == NULL || x.type == t_invalid || - y.type == NULL || y.type == t_invalid) { + if (x.type == nullptr || x.type == t_invalid || + y.type == nullptr || y.type == t_invalid) { return kind; } @@ -6301,11 +6334,11 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t Type *type = type_hint; bool is_to_be_determined_array_count = false; bool is_constant = true; - if (cl->type != NULL) { - type = NULL; + if (cl->type != nullptr) { + type = nullptr; // [..]Type - if (cl->type->kind == AstNode_ArrayType && cl->type->ArrayType.count != NULL) { + if (cl->type->kind == AstNode_ArrayType && cl->type->ArrayType.count != nullptr) { AstNode *count = cl->type->ArrayType.count; if (count->kind == AstNode_UnaryExpr && count->UnaryExpr.op.kind == Token_Ellipsis) { @@ -6314,12 +6347,12 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t } } - if (type == NULL) { + if (type == nullptr) { type = check_type(c, cl->type); } } - if (type == NULL) { + if (type == nullptr) { error(node, "Missing type in compound literal"); return kind; } @@ -6362,7 +6395,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t String name = fv->field->Ident.token.string; Selection sel = lookup_field(c->allocator, type, name, o->mode == Addressing_Type); - bool is_unknown = sel.entity == NULL; + bool is_unknown = sel.entity == nullptr; if (is_unknown) { error(elem, "Unknown field `%.*s` in structure literal", LIT(name)); continue; @@ -6456,7 +6489,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t case Type_Vector: case Type_DynamicArray: { - Type *elem_type = NULL; + Type *elem_type = nullptr; String context_name = {}; i64 max_type_count = -1; if (t->kind == Type_Slice) { @@ -6488,9 +6521,9 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t } for (; index < elem_count; index++) { - GB_ASSERT(cl->elems.data != NULL); + GB_ASSERT(cl->elems.data != nullptr); AstNode *e = cl->elems[index]; - if (e == NULL) { + if (e == nullptr) { error(node, "Invalid literal element"); continue; } @@ -6559,7 +6592,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t String name = fv->field->Ident.token.string; Selection sel = lookup_field(c->allocator, type, name, o->mode == Addressing_Type); - if (sel.entity == NULL) { + if (sel.entity == nullptr) { error(elem, "Unknown field `%.*s` in `any` literal", LIT(name)); continue; } @@ -6817,7 +6850,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t if (!valid && (is_type_struct(t) || is_type_raw_union(t))) { Entity *found = find_using_index_expr(t); - if (found != NULL) { + if (found != nullptr) { valid = check_set_index_data(o, found->type, is_type_pointer(found->type), &max_count); } } @@ -6835,7 +6868,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t return kind; } - if (ie->index == NULL) { + if (ie->index == nullptr) { gbString str = expr_to_string(o->expr); error(o->expr, "Missing index for `%s`", str); gb_string_free(str); @@ -6916,12 +6949,12 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t o->mode = Addressing_Value; } - if (se->low == NULL && se->high != NULL) { + if (se->low == nullptr && se->high != nullptr) { error(se->interval0, "1st index is required if a 2nd index is specified"); // It is okay to continue as it will assume the 1st index is zero } - if (se->index3 && (se->high == NULL || se->max == NULL)) { + if (se->index3 && (se->high == nullptr || se->max == nullptr)) { error(se->close, "2nd and 3rd indices are required in a 3-index slice"); o->mode = Addressing_Invalid; o->expr = node; @@ -6942,7 +6975,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t AstNode *nodes[3] = {se->low, se->high, se->max}; for (isize i = 0; i < gb_count_of(nodes); i++) { i64 index = max_count; - if (nodes[i] != NULL) { + if (nodes[i] != nullptr) { i64 capacity = -1; if (max_count >= 0) { capacity = max_count; @@ -7025,14 +7058,14 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t ExprKind check_expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) { ExprKind kind = check_expr_base_internal(c, o, node, type_hint); - Type *type = NULL; + Type *type = nullptr; ExactValue value = {ExactValue_Invalid}; switch (o->mode) { case Addressing_Invalid: type = t_invalid; break; case Addressing_NoValue: - type = NULL; + type = nullptr; break; case Addressing_Constant: type = o->type; @@ -7043,7 +7076,7 @@ ExprKind check_expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) break; } - if (type != NULL && is_type_untyped(type)) { + if (type != nullptr && is_type_untyped(type)) { add_untyped(&c->info, node, false, o->mode, type, value); } else { add_type_and_value(&c->info, node, o->mode, type, value); @@ -7054,7 +7087,7 @@ ExprKind check_expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint) void check_multi_expr(Checker *c, Operand *o, AstNode *e) { - check_expr_base(c, o, e, NULL); + check_expr_base(c, o, e, nullptr); switch (o->mode) { default: return; // NOTE(bill): Valid @@ -7115,7 +7148,7 @@ gbString string_append_token(gbString str, Token token) { gbString write_expr_to_string(gbString str, AstNode *node) { - if (node == NULL) + if (node == nullptr) return str; if (is_ast_node_stmt(node)) { @@ -7262,7 +7295,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) { case_ast_node(at, ArrayType, node); str = gb_string_appendc(str, "["); - if (at->count != NULL && + if (at->count != nullptr && at->count->kind == AstNode_UnaryExpr && at->count->UnaryExpr.op.kind == Token_Ellipsis) { str = gb_string_appendc(str, ".."); @@ -7382,7 +7415,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) { str = gb_string_appendc(str, "proc("); str = write_expr_to_string(str, pt->params); str = gb_string_appendc(str, ")"); - if (pt->results != NULL) { + if (pt->results != nullptr) { str = gb_string_appendc(str, " -> "); str = write_expr_to_string(str, pt->results); } @@ -7414,7 +7447,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) { case_ast_node(et, EnumType, node); str = gb_string_appendc(str, "enum "); - if (et->base_type != NULL) { + if (et->base_type != nullptr) { str = write_expr_to_string(str, et->base_type); str = gb_string_appendc(str, " "); } diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index d197e02d5..3f9efda9a 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -75,7 +75,7 @@ bool check_has_break(AstNode *stmt, bool implicit) { case AstNode_IfStmt: if (check_has_break(stmt->IfStmt.body, implicit) || - (stmt->IfStmt.else_stmt != NULL && check_has_break(stmt->IfStmt.else_stmt, implicit))) { + (stmt->IfStmt.else_stmt != nullptr && check_has_break(stmt->IfStmt.else_stmt, implicit))) { return true; } break; @@ -107,7 +107,7 @@ bool check_is_terminating(AstNode *node) { case_end; case_ast_node(is, IfStmt, node); - if (is->else_stmt != NULL) { + if (is->else_stmt != nullptr) { if (check_is_terminating(is->body) && check_is_terminating(is->else_stmt)) { return true; @@ -116,7 +116,7 @@ bool check_is_terminating(AstNode *node) { case_end; case_ast_node(ws, WhenStmt, node); - if (ws->else_stmt != NULL) { + if (ws->else_stmt != nullptr) { if (check_is_terminating(ws->body) && check_is_terminating(ws->else_stmt)) { return true; @@ -125,7 +125,7 @@ bool check_is_terminating(AstNode *node) { case_end; case_ast_node(fs, ForStmt, node); - if (fs->cond == NULL && !check_has_break(fs->body, true)) { + if (fs->cond == nullptr && !check_has_break(fs->body, true)) { return check_is_terminating(fs->body); } case_end; @@ -180,7 +180,7 @@ bool check_is_terminating(AstNode *node) { Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { if (rhs->mode == Addressing_Invalid || (rhs->type == t_invalid && rhs->mode != Addressing_Overload)) { - return NULL; + return nullptr; } AstNode *node = unparen_expr(lhs_node); @@ -188,15 +188,15 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { // NOTE(bill): Ignore assignments to `_` if (node->kind == AstNode_Ident && node->Ident.token.string == "_") { - add_entity_definition(&c->info, node, NULL); - check_assignment(c, rhs, NULL, str_lit("assignment to `_` identifier")); + add_entity_definition(&c->info, node, nullptr); + check_assignment(c, rhs, nullptr, str_lit("assignment to `_` identifier")); if (rhs->mode == Addressing_Invalid) { - return NULL; + return nullptr; } return rhs->type; } - Entity *e = NULL; + Entity *e = nullptr; bool used = false; Operand lhs = {Addressing_Invalid}; @@ -204,13 +204,13 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { check_expr(c, &lhs, lhs_node); if (lhs.mode == Addressing_Invalid || lhs.type == t_invalid) { - return NULL; + return nullptr; } if (rhs->mode == Addressing_Overload) { isize overload_count = rhs->overload_count; Entity **procs = rhs->overload_entities; - GB_ASSERT(procs != NULL && overload_count > 0); + GB_ASSERT(procs != nullptr && overload_count > 0); // NOTE(bill): These should be done for (isize i = 0; i < overload_count; i++) { @@ -228,32 +228,32 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { } } - if (e != NULL) { + if (e != nullptr) { // HACK TODO(bill): Should the entities be freed as it's technically a leak rhs->mode = Addressing_Value; rhs->type = e->type; rhs->overload_count = 0; - rhs->overload_entities = NULL; + rhs->overload_entities = nullptr; } } else { if (node->kind == AstNode_Ident) { ast_node(i, Ident, node); e = scope_lookup_entity(c->context.scope, i->token.string); - if (e != NULL && e->kind == Entity_Variable) { + if (e != nullptr && e->kind == Entity_Variable) { used = (e->flags & EntityFlag_Used) != 0; // TODO(bill): Make backup just in case } } } - if (e != NULL && used) { + if (e != nullptr && used) { e->flags |= EntityFlag_Used; } Type *assignment_type = lhs.type; switch (lhs.mode) { case Addressing_Invalid: - return NULL; + return nullptr; case Addressing_Variable: { if (is_type_bit_field_value(lhs.type)) { @@ -286,7 +286,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { error(rhs->expr, "Cannot assign `%s` to bit field `%s`", rhs_expr, lhs_expr); gb_string_free(rhs_expr); gb_string_free(lhs_expr); - return NULL; + return nullptr; } break; } @@ -302,7 +302,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { gbString str = expr_to_string(lhs.expr); error(lhs.expr, "Cannot assign to the value of a map `%s`", str); gb_string_free(str); - return NULL; + return nullptr; } } } @@ -318,7 +318,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { gbString str = expr_to_string(lhs.expr); error(lhs.expr, "Cannot assign to record field `%s` in map", str); gb_string_free(str); - return NULL; + return nullptr; } } @@ -334,7 +334,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) { check_assignment(c, rhs, assignment_type, str_lit("assignment")); if (rhs->mode == Addressing_Invalid) { - return NULL; + return nullptr; } return rhs->type; @@ -397,7 +397,7 @@ void check_when_stmt(Checker *c, AstNodeWhenStmt *ws, u32 flags) { error(ws->cond, "Non-constant boolean `when` condition"); return; } - if (ws->body == NULL || ws->body->kind != AstNode_BlockStmt) { + if (ws->body == nullptr || ws->body->kind != AstNode_BlockStmt) { error(ws->cond, "Invalid body for `when` statement"); return; } @@ -420,7 +420,7 @@ void check_when_stmt(Checker *c, AstNodeWhenStmt *ws, u32 flags) { } void check_label(Checker *c, AstNode *label) { - if (label == NULL) { + if (label == nullptr) { return; } ast_node(l, Label, label); @@ -439,7 +439,7 @@ void check_label(Checker *c, AstNode *label) { error(l->name, "A label is only allowed within a procedure"); return; } - GB_ASSERT(c->context.decl != NULL); + GB_ASSERT(c->context.decl != nullptr); bool ok = true; for_array(i, c->context.decl->labels) { @@ -463,7 +463,7 @@ void check_label(Checker *c, AstNode *label) { // Returns `true` for `continue`, `false` for `return` bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bool is_selector, Entity *e) { - if (e == NULL) { + if (e == nullptr) { error(us->token, "`using` applied to an unknown entity"); return true; } @@ -479,7 +479,7 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo Entity *f = t->Record.variants[i]; // gb_printf_err("%s\n", type_to_string(f->type)); Entity *found = scope_insert_entity(c->context.scope, f); - if (found != NULL) { + if (found != nullptr) { gbString expr_str = expr_to_string(expr); error(us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string)); gb_string_free(expr_str); @@ -491,7 +491,7 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo for (isize i = 0; i < t->Record.field_count; i++) { Entity *f = t->Record.fields[i]; Entity *found = scope_insert_entity(c->context.scope, f); - if (found != NULL) { + if (found != nullptr) { gbString expr_str = expr_to_string(expr); error(us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string)); gb_string_free(expr_str); @@ -510,7 +510,7 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo for_array(i, scope->elements.entries) { Entity *decl = scope->elements.entries[i].value; Entity *found = scope_insert_entity(c->context.scope, decl); - if (found != NULL) { + if (found != nullptr) { gbString expr_str = expr_to_string(expr); error(us->token, "Namespace collision while `using` `%s` of: %.*s\n" @@ -539,7 +539,7 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo uvar->using_expr = expr; // } Entity *prev = scope_insert_entity(c->context.scope, uvar); - if (prev != NULL) { + if (prev != nullptr) { gbString expr_str = expr_to_string(expr); error(us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(prev->token.string)); gb_string_free(expr_str); @@ -590,7 +590,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_ast_node(es, ExprStmt, node) Operand operand = {Addressing_Invalid}; - ExprKind kind = check_expr_base(c, &operand, es->expr, NULL); + ExprKind kind = check_expr_base(c, &operand, es->expr, nullptr); switch (operand.mode) { case Addressing_Type: { gbString str = type_to_string(operand.type); @@ -747,7 +747,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_ast_node(is, IfStmt, node); check_open_scope(c, node); - if (is->init != NULL) { + if (is->init != nullptr) { check_stmt(c, is->init, 0); } @@ -759,7 +759,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { check_stmt(c, is->body, mod_flags); - if (is->else_stmt != NULL) { + if (is->else_stmt != nullptr) { switch (is->else_stmt->kind) { case AstNode_IfStmt: case AstNode_BlockStmt: @@ -931,17 +931,17 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { check_open_scope(c, node); check_label(c, fs->label); // TODO(bill): What should the label's "scope" be? - if (fs->init != NULL) { + if (fs->init != nullptr) { check_stmt(c, fs->init, 0); } - if (fs->cond != NULL) { + if (fs->cond != nullptr) { Operand o = {Addressing_Invalid}; check_expr(c, &o, fs->cond); if (o.mode != Addressing_Invalid && !is_type_boolean(o.type)) { error(fs->cond, "Non-boolean condition in `for` statement"); } } - if (fs->post != NULL) { + if (fs->post != nullptr) { check_stmt(c, fs->post, 0); if (fs->post->kind != AstNode_AssignStmt && @@ -960,8 +960,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { check_open_scope(c, node); check_label(c, rs->label); - Type *val = NULL; - Type *idx = NULL; + Type *val = nullptr; + Type *idx = nullptr; Entity *entities[2] = {}; isize entity_count = 0; @@ -1105,7 +1105,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } } - if (val == NULL) { + if (val == nullptr) { gbString s = expr_to_string(operand.expr); gbString t = type_to_string(operand.type); error(operand.expr, "Cannot iterate over `%s` of type `%s`", s, t); @@ -1119,22 +1119,22 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { Type * rhs[2] = {val, idx}; for (isize i = 0; i < 2; i++) { - if (lhs[i] == NULL) { + if (lhs[i] == nullptr) { continue; } AstNode *name = lhs[i]; Type * type = rhs[i]; - Entity *entity = NULL; + Entity *entity = nullptr; if (name->kind == AstNode_Ident) { Token token = name->Ident.token; String str = token.string; - Entity *found = NULL; + Entity *found = nullptr; if (str != "_") { found = current_scope_lookup_entity(c->context.scope, str); } - if (found == NULL) { + if (found == nullptr) { entity = make_entity_variable(c->allocator, c->context.scope, token, type, true); add_entity_definition(&c->info, name, entity); } else { @@ -1149,13 +1149,13 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { error(name, "A variable declaration must be an identifier"); } - if (entity == NULL) { + if (entity == nullptr) { entity = make_entity_dummy_variable(c->allocator, c->global_scope, ast_node_token(name)); } entities[entity_count++] = entity; - if (type == NULL) { + if (type == nullptr) { entity->type = t_invalid; entity->flags |= EntityFlag_Used; } @@ -1177,12 +1177,12 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { check_open_scope(c, node); check_label(c, ms->label); // TODO(bill): What should the label's "scope" be? - if (ms->init != NULL) { + if (ms->init != nullptr) { check_stmt(c, ms->init, 0); } - if (ms->tag != NULL) { + if (ms->tag != nullptr) { check_expr(c, &x, ms->tag); - check_assignment(c, &x, NULL, str_lit("match expression")); + check_assignment(c, &x, nullptr, str_lit("match expression")); } else { x.mode = Addressing_Constant; x.type = t_bool; @@ -1202,11 +1202,11 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { // NOTE(bill): Check for multiple defaults - AstNode *first_default = NULL; + AstNode *first_default = nullptr; ast_node(bs, BlockStmt, ms->body); for_array(i, bs->stmts) { AstNode *stmt = bs->stmts[i]; - AstNode *default_stmt = NULL; + AstNode *default_stmt = nullptr; if (stmt->kind == AstNode_CaseClause) { ast_node(cc, CaseClause, stmt); if (cc->list.count == 0) { @@ -1216,8 +1216,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { error(stmt, "Invalid AST - expected case clause"); } - if (default_stmt != NULL) { - if (first_default != NULL) { + if (default_stmt != nullptr) { + if (first_default != nullptr) { TokenPos pos = ast_node_token(first_default).pos; error(stmt, "multiple `default` clauses\n" @@ -1323,7 +1323,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { if (y.value.kind != ExactValue_Invalid) { HashKey key = hash_exact_value(y.value); TypeAndToken *found = map_get(&seen, key); - if (found != NULL) { + if (found != nullptr) { gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena); isize count = multi_map_count(&seen, key); TypeAndToken *taps = gb_alloc_array(c->tmp_allocator, TypeAndToken, count); @@ -1401,7 +1401,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { AstNode *rhs = as->rhs[0]; check_expr(c, &x, rhs); - check_assignment(c, &x, NULL, str_lit("type match expression")); + check_assignment(c, &x, nullptr, str_lit("type match expression")); match_type_kind = check_valid_type_match_type(x.type); if (check_valid_type_match_type(x.type) == MatchType_Invalid) { gbString str = type_to_string(x.type); @@ -1413,11 +1413,11 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { bool is_ptr = is_type_pointer(x.type); // NOTE(bill): Check for multiple defaults - AstNode *first_default = NULL; + AstNode *first_default = nullptr; ast_node(bs, BlockStmt, ms->body); for_array(i, bs->stmts) { AstNode *stmt = bs->stmts[i]; - AstNode *default_stmt = NULL; + AstNode *default_stmt = nullptr; if (stmt->kind == AstNode_CaseClause) { ast_node(cc, CaseClause, stmt); if (cc->list.count == 0) { @@ -1427,8 +1427,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { error(stmt, "Invalid AST - expected case clause"); } - if (default_stmt != NULL) { - if (first_default != NULL) { + if (default_stmt != nullptr) { + if (first_default != nullptr) { TokenPos pos = ast_node_token(first_default).pos; error(stmt, "Multiple `default` clauses\n" @@ -1460,10 +1460,10 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { // TODO(bill): Make robust Type *bt = base_type(type_deref(x.type)); - Type *case_type = NULL; + Type *case_type = nullptr; for_array(type_index, cc->list) { AstNode *type_expr = cc->list[type_index]; - if (type_expr != NULL) { // Otherwise it's a default expression + if (type_expr != nullptr) { // Otherwise it's a default expression Operand y = {}; check_expr_or_type(c, &y, type_expr); @@ -1510,14 +1510,14 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { if (is_ptr && !is_type_any(type_deref(x.type)) && cc->list.count == 1 && - case_type != NULL) { + case_type != nullptr) { case_type = make_type_pointer(c->allocator, case_type); } if (cc->list.count > 1) { - case_type = NULL; + case_type = nullptr; } - if (case_type == NULL) { + if (case_type == nullptr) { case_type = x.type; } add_type_info_type(c, case_type); @@ -1574,7 +1574,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { break; } - if (bs->label != NULL) { + if (bs->label != nullptr) { if (bs->label->kind != AstNode_Ident) { error(bs->label, "A branch statement's label name must be an identifier"); return; @@ -1582,8 +1582,8 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { AstNode *ident = bs->label; String name = ident->Ident.token.string; Operand o = {}; - Entity *e = check_ident(c, &o, ident, NULL, NULL, false); - if (e == NULL) { + Entity *e = check_ident(c, &o, ident, nullptr, nullptr, false); + if (e == nullptr) { error(ident, "Undeclared label name: %.*s", LIT(name)); return; } @@ -1603,15 +1603,15 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } for_array(i, us->list) { AstNode *expr = unparen_expr(us->list[0]); - Entity *e = NULL; + Entity *e = nullptr; bool is_selector = false; if (expr->kind == AstNode_Ident) { Operand o = {}; - e = check_ident(c, &o, expr, NULL, NULL, true); + e = check_ident(c, &o, expr, nullptr, nullptr, true); } else if (expr->kind == AstNode_SelectorExpr) { Operand o = {}; - e = check_selector(c, &o, expr, NULL); + e = check_selector(c, &o, expr, nullptr); is_selector = true; } else if (expr->kind == AstNode_Implicit) { error(us->token, "`using` applied to an implicit value"); @@ -1675,23 +1675,23 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { for_array(i, vd->names) { AstNode *name = vd->names[i]; - Entity *entity = NULL; + Entity *entity = nullptr; if (name->kind != AstNode_Ident) { error(name, "A variable declaration must be an identifier"); } else { Token token = name->Ident.token; String str = token.string; - Entity *found = NULL; + Entity *found = nullptr; // NOTE(bill): Ignore assignments to `_` if (str != "_") { found = current_scope_lookup_entity(c->context.scope, str); } - if (found == NULL) { - entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, false); + if (found == nullptr) { + entity = make_entity_variable(c->allocator, c->context.scope, token, nullptr, false); entity->identifier = name; AstNode *fl = c->context.curr_foreign_library; - if (fl != NULL) { + if (fl != nullptr) { GB_ASSERT(fl->kind == AstNode_Ident); entity->Variable.is_foreign = true; entity->Variable.foreign_library_ident = fl; @@ -1705,17 +1705,17 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { entity = found; } } - if (entity == NULL) { + if (entity == nullptr) { entity = make_entity_dummy_variable(c->allocator, c->global_scope, ast_node_token(name)); } entity->parent_proc_decl = c->context.curr_proc_decl; entities[entity_count++] = entity; } - Type *init_type = NULL; + Type *init_type = nullptr; if (vd->type) { - init_type = check_type(c, vd->type, NULL); - if (init_type == NULL) { + init_type = check_type(c, vd->type, nullptr); + if (init_type == nullptr) { init_type = t_invalid; } else if (is_type_polymorphic(init_type)) { error(vd->type, "Invalid use of a polymorphic type in variable declaration"); @@ -1725,14 +1725,14 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { for (isize i = 0; i < entity_count; i++) { Entity *e = entities[i]; - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); if (e->flags & EntityFlag_Visited) { e->type = t_invalid; continue; } e->flags |= EntityFlag_Visited; - if (e->type == NULL) { + if (e->type == nullptr) { e->type = init_type; } } @@ -1772,14 +1772,14 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { if ((vd->flags & VarDeclFlag_using) != 0) { Token token = ast_node_token(node); - if (vd->type != NULL && entity_count > 1) { + if (vd->type != nullptr && entity_count > 1) { error(token, "`using` can only be applied to one variable of the same type"); // TODO(bill): Should a `continue` happen here? } for (isize entity_index = 0; entity_index < entity_count; entity_index++) { Entity *e = entities[entity_index]; - if (e == NULL) { + if (e == nullptr) { continue; } if (e->kind != Entity_Variable) { @@ -1797,7 +1797,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type); uvar->Variable.is_immutable = is_immutable; Entity *prev = scope_insert_entity(c->context.scope, uvar); - if (prev != NULL) { + if (prev != nullptr) { error(token, "Namespace collision while `using` `%.*s` of: %.*s", LIT(name), LIT(prev->token.string)); return; } diff --git a/src/checker.cpp b/src/checker.cpp index c66f9a63e..178aff62a 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -236,13 +236,13 @@ struct Scope { bool has_been_imported; // This is only applicable to file scopes AstFile * file; }; -gb_global Scope *universal_scope = NULL; +gb_global Scope *universal_scope = nullptr; void scope_reset(Scope *scope) { - if (scope == NULL) return; + if (scope == nullptr) return; - scope->first_child = NULL; - scope->last_child = NULL; + scope->first_child = nullptr; + scope->last_child = nullptr; map_clear (&scope->elements); map_clear (&scope->implicit); array_clear(&scope->shared); @@ -373,13 +373,13 @@ void destroy_declaration_info(DeclInfo *d) { } bool decl_info_has_init(DeclInfo *d) { - if (d->init_expr != NULL) { + if (d->init_expr != nullptr) { return true; } - if (d->proc_lit != NULL) { + if (d->proc_lit != nullptr) { switch (d->proc_lit->kind) { case_ast_node(pl, ProcLit, d->proc_lit); - if (pl->body != NULL) { + if (pl->body != nullptr) { return true; } case_end; @@ -401,7 +401,7 @@ Scope *make_scope(Scope *parent, gbAllocator allocator) { array_init(&s->shared, heap_allocator()); array_init(&s->imported, heap_allocator()); - if (parent != NULL && parent != universal_scope) { + if (parent != nullptr && parent != universal_scope) { DLIST_APPEND(parent->first_child, parent->last_child, s); } return s; @@ -419,7 +419,7 @@ void destroy_scope(Scope *scope) { } } - for (Scope *child = scope->first_child; child != NULL; child = child->next) { + for (Scope *child = scope->first_child; child != nullptr; child = child->next) { destroy_scope(child); } @@ -433,8 +433,8 @@ void destroy_scope(Scope *scope) { void add_scope(Checker *c, AstNode *node, Scope *scope) { - GB_ASSERT(node != NULL); - GB_ASSERT(scope != NULL); + GB_ASSERT(node != nullptr); + GB_ASSERT(scope != nullptr); scope->node = node; map_set(&c->info.scopes, hash_node(node), scope); } @@ -484,14 +484,14 @@ Entity *current_scope_lookup_entity(Scope *s, String name) { return e; } } - return NULL; + return nullptr; } void scope_lookup_parent_entity(Scope *scope, String name, Scope **scope_, Entity **entity_) { bool gone_thru_proc = false; bool gone_thru_file = false; HashKey key = hash_string(name); - for (Scope *s = scope; s != NULL; s = s->parent) { + for (Scope *s = scope; s != nullptr; s = s->parent) { Entity **found = map_get(&s->elements, key); if (found) { Entity *e = *found; @@ -550,13 +550,13 @@ void scope_lookup_parent_entity(Scope *scope, String name, Scope **scope_, Entit } - if (entity_) *entity_ = NULL; - if (scope_) *scope_ = NULL; + if (entity_) *entity_ = nullptr; + if (scope_) *scope_ = nullptr; } Entity *scope_lookup_entity(Scope *s, String name) { - Entity *entity = NULL; - scope_lookup_parent_entity(s, name, NULL, &entity); + Entity *entity = nullptr; + scope_lookup_parent_entity(s, name, nullptr, &entity); return entity; } @@ -569,7 +569,7 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) { #if 1 // IMPORTANT NOTE(bill): Procedure overloading code - Entity *prev = NULL; + Entity *prev = nullptr; if (found) { prev = *found; if (prev->kind != Entity_Procedure || @@ -578,7 +578,7 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) { } } - if (prev != NULL && entity->kind == Entity_Procedure) { + if (prev != nullptr && entity->kind == Entity_Procedure) { // if (s->is_global) return prev; multi_map_insert(&s->elements, key, entity); @@ -591,10 +591,10 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) { } map_set(&s->elements, key, entity); #endif - if (entity->scope == NULL) { + if (entity->scope == nullptr) { entity->scope = s; } - return NULL; + return nullptr; } @@ -608,10 +608,10 @@ void add_dependency(DeclInfo *d, Entity *e) { } void add_declaration_dependency(Checker *c, Entity *e) { - if (e == NULL) { + if (e == nullptr) { return; } - if (c->context.decl != NULL) { + if (c->context.decl != nullptr) { DeclInfo **found = map_get(&c->info.entities, hash_entity(e)); if (found) { add_dependency(c->context.decl, e); @@ -632,7 +632,7 @@ Entity *add_global_entity(Entity *entity) { } void add_global_constant(gbAllocator a, String name, Type *type, ExactValue value) { - Entity *entity = alloc_entity(a, Entity_Constant, NULL, make_token_ident(name), type); + Entity *entity = alloc_entity(a, Entity_Constant, nullptr, make_token_ident(name), type); entity->Constant.value = value; add_global_entity(entity); } @@ -650,15 +650,15 @@ void init_universal_scope(void) { BuildContext *bc = &build_context; // NOTE(bill): No need to free these gbAllocator a = heap_allocator(); - universal_scope = make_scope(NULL, a); + universal_scope = make_scope(nullptr, a); // Types for (isize i = 0; i < gb_count_of(basic_types); i++) { - add_global_entity(make_entity_type_name(a, NULL, make_token_ident(basic_types[i].Basic.name), &basic_types[i])); + add_global_entity(make_entity_type_name(a, nullptr, make_token_ident(basic_types[i].Basic.name), &basic_types[i])); } #if 1 // for (isize i = 0; i < gb_count_of(basic_type_aliases); i++) { - // add_global_entity(make_entity_type_name(a, NULL, make_token_ident(basic_type_aliases[i].Basic.name), &basic_type_aliases[i])); + // add_global_entity(make_entity_type_name(a, nullptr, make_token_ident(basic_type_aliases[i].Basic.name), &basic_type_aliases[i])); // } #else { @@ -689,7 +689,7 @@ void init_universal_scope(void) { BuiltinProcId id = cast(BuiltinProcId)i; String name = builtin_procs[i].name; if (name != "") { - Entity *entity = alloc_entity(a, Entity_Builtin, NULL, make_token_ident(name), t_invalid); + Entity *entity = alloc_entity(a, Entity_Builtin, nullptr, make_token_ident(name), t_invalid); entity->Builtin.id = id; add_global_entity(entity); } @@ -813,7 +813,7 @@ Entity *entity_of_ident(CheckerInfo *i, AstNode *identifier) { return *found; } } - return NULL; + return nullptr; } TypeAndValue type_and_value_of_expr(CheckerInfo *i, AstNode *expr) { @@ -835,30 +835,30 @@ Type *type_of_expr(CheckerInfo *i, AstNode *expr) { } } - return NULL; + return nullptr; } Entity *implicit_entity_of_node(CheckerInfo *i, AstNode *clause) { Entity **found = map_get(&i->implicits, hash_node(clause)); - if (found != NULL) { + if (found != nullptr) { return *found; } - return NULL; + return nullptr; } bool is_entity_implicitly_imported(Entity *import_name, Entity *e) { GB_ASSERT(import_name->kind == Entity_ImportName); - return map_get(&import_name->ImportName.scope->implicit, hash_entity(e)) != NULL; + return map_get(&import_name->ImportName.scope->implicit, hash_entity(e)) != nullptr; } DeclInfo *decl_info_of_entity(CheckerInfo *i, Entity *e) { - if (e != NULL) { + if (e != nullptr) { DeclInfo **found = map_get(&i->entities, hash_entity(e)); - if (found != NULL) { + if (found != nullptr) { return *found; } } - return NULL; + return nullptr; } DeclInfo *decl_info_of_ident(CheckerInfo *i, AstNode *ident) { @@ -867,17 +867,17 @@ DeclInfo *decl_info_of_ident(CheckerInfo *i, AstNode *ident) { AstFile *ast_file_of_filename(CheckerInfo *i, String filename) { AstFile **found = map_get(&i->files, hash_string(filename)); - if (found != NULL) { + if (found != nullptr) { return *found; } - return NULL; + return nullptr; } Scope *scope_of_node(CheckerInfo *i, AstNode *node) { Scope **found = map_get(&i->scopes, hash_node(node)); if (found) { return *found; } - return NULL; + return nullptr; } ExprInfo *check_get_expr_info(CheckerInfo *i, AstNode *expr) { return map_get(&i->untyped, hash_node(expr)); @@ -927,7 +927,7 @@ void add_untyped(CheckerInfo *i, AstNode *expression, bool lhs, AddressingMode m } void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode, Type *type, ExactValue value) { - if (expression == NULL) { + if (expression == nullptr) { return; } if (mode == Addressing_Invalid) { @@ -954,7 +954,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode } void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) { - GB_ASSERT(identifier != NULL); + GB_ASSERT(identifier != nullptr); if (identifier->kind == AstNode_Ident) { if (identifier->Ident.token.string == "_") { return; @@ -967,7 +967,7 @@ void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) } bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { - if (scope == NULL) { + if (scope == nullptr) { return false; } String name = entity->token.string; @@ -976,7 +976,7 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { if (ie) { TokenPos pos = ie->token.pos; Entity *up = ie->using_parent; - if (up != NULL) { + if (up != nullptr) { if (token_pos_eq(pos, up->token.pos)) { // NOTE(bill): Error should have been handled already return false; @@ -1001,14 +1001,14 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) { } } } - if (identifier != NULL) { + if (identifier != nullptr) { add_entity_definition(&c->info, identifier, entity); } return true; } void add_entity_use(Checker *c, AstNode *identifier, Entity *entity) { - GB_ASSERT(identifier != NULL); + GB_ASSERT(identifier != nullptr); if (identifier->kind != AstNode_Ident) { return; } @@ -1020,17 +1020,17 @@ void add_entity_use(Checker *c, AstNode *identifier, Entity *entity) { void add_entity_and_decl_info(Checker *c, AstNode *identifier, Entity *e, DeclInfo *d) { GB_ASSERT(identifier->kind == AstNode_Ident); - GB_ASSERT(e != NULL && d != NULL); + GB_ASSERT(e != nullptr && d != nullptr); GB_ASSERT(identifier->Ident.token.string == e->token.string); - if (e->scope != NULL) add_entity(c, e->scope, identifier, e); + if (e->scope != nullptr) add_entity(c, e->scope, identifier, e); add_entity_definition(&c->info, identifier, e); map_set(&c->info.entities, hash_entity(e), d); } void add_implicit_entity(Checker *c, AstNode *node, Entity *e) { - GB_ASSERT(node != NULL); - GB_ASSERT(e != NULL); + GB_ASSERT(node != nullptr); + GB_ASSERT(e != nullptr); map_set(&c->info.implicits, hash_node(node), e); } @@ -1039,7 +1039,7 @@ void add_implicit_entity(Checker *c, AstNode *node, Entity *e) { void add_type_info_type(Checker *c, Type *t) { - if (t == NULL) { + if (t == nullptr) { return; } t = default_type(t); @@ -1050,7 +1050,7 @@ void add_type_info_type(Checker *c, Type *t) { return; // Could be nil } - if (map_get(&c->info.type_info_map, hash_type(t)) != NULL) { + if (map_get(&c->info.type_info_map, hash_type(t)) != nullptr) { // Types have already been added return; } @@ -1181,7 +1181,7 @@ void add_type_info_type(Checker *c, Type *t) { } void check_procedure_later(Checker *c, ProcedureInfo info) { - if (info.decl != NULL) { + if (info.decl != nullptr) { map_set(&c->procs, hash_decl_info(info.decl), info); } } @@ -1210,11 +1210,11 @@ Type *const curr_procedure_type(Checker *c) { if (count > 0) { return c->proc_stack[count-1]; } - return NULL; + return nullptr; } void add_curr_ast_file(Checker *c, AstFile *file) { - if (file != NULL) { + if (file != nullptr) { TokenPos zero_pos = {}; global_error_collector.prev = zero_pos; c->curr_ast_file = file; @@ -1226,25 +1226,25 @@ void add_curr_ast_file(Checker *c, AstFile *file) { void add_dependency_to_map(Map *map, CheckerInfo *info, Entity *entity) { - if (entity == NULL) { + if (entity == nullptr) { return; } - if (entity->type != NULL && + if (entity->type != nullptr && is_type_polymorphic(entity->type)) { DeclInfo *decl = decl_info_of_entity(info, entity); - if (decl->gen_proc_type == NULL) { + if (decl->gen_proc_type == nullptr) { return; } } - if (map_get(map, hash_entity(entity)) != NULL) { + if (map_get(map, hash_entity(entity)) != nullptr) { return; } map_set(map, hash_entity(entity), entity); DeclInfo *decl = decl_info_of_entity(info, entity); - if (decl == NULL) { + if (decl == nullptr) { return; } @@ -1282,7 +1282,7 @@ Map generate_minimum_dependency_map(CheckerInfo *info, Entity *start) } bool is_entity_in_dependency_map(Map *map, Entity *e) { - return map_get(map, hash_entity(e)) != NULL; + return map_get(map, hash_entity(e)) != nullptr; } @@ -1290,7 +1290,7 @@ bool is_entity_in_dependency_map(Map *map, Entity *e) { Entity *find_core_entity(Checker *c, String name) { Entity *e = current_scope_lookup_entity(c->global_scope, name); - if (e == NULL) { + if (e == nullptr) { compiler_error("Could not find type declaration for `%.*s`\n" "Is `_preload.odin` missing from the `core` directory relative to odin.exe?", LIT(name)); // NOTE(bill): This will exit the program as it's cannot continue without it! @@ -1299,7 +1299,7 @@ Entity *find_core_entity(Checker *c, String name) { } void init_preload(Checker *c) { - if (t_type_info == NULL) { + if (t_type_info == nullptr) { Entity *type_info_entity = find_core_entity(c, str_lit("TypeInfo")); t_type_info = type_info_entity->type; @@ -1364,31 +1364,31 @@ void init_preload(Checker *c) { t_type_info_bit_field_ptr = make_type_pointer(c->allocator, t_type_info_bit_field); } - if (t_allocator == NULL) { + if (t_allocator == nullptr) { Entity *e = find_core_entity(c, str_lit("Allocator")); t_allocator = e->type; t_allocator_ptr = make_type_pointer(c->allocator, t_allocator); } - if (t_context == NULL) { + if (t_context == nullptr) { Entity *e = find_core_entity(c, str_lit("Context")); e_context = e; t_context = e->type; t_context_ptr = make_type_pointer(c->allocator, t_context); } - if (t_source_code_location == NULL) { + if (t_source_code_location == nullptr) { Entity *e = find_core_entity(c, str_lit("SourceCodeLocation")); t_source_code_location = e->type; t_source_code_location_ptr = make_type_pointer(c->allocator, t_allocator); } - if (t_map_key == NULL) { + if (t_map_key == nullptr) { Entity *e = find_core_entity(c, str_lit("__MapKey")); t_map_key = e->type; } - if (t_map_header == NULL) { + if (t_map_header == nullptr) { Entity *e = find_core_entity(c, str_lit("__MapHeader")); t_map_header = e->type; } @@ -1461,7 +1461,7 @@ void check_procedure_overloading(Checker *c, Entity *e) { TokenPos pos = q->token.pos; - if (q->type == NULL || q->type == t_invalid) { + if (q->type == nullptr || q->type == t_invalid) { continue; } @@ -1526,7 +1526,7 @@ bool check_arity_match(Checker *c, AstNodeValueDecl *vd) { isize rhs = vd->values.count; if (rhs == 0) { - if (vd->type == NULL) { + if (vd->type == nullptr) { error(vd->names[0], "Missing type or initial expression"); return false; } @@ -1560,7 +1560,7 @@ void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws, bool if (operand.mode != Addressing_Constant) { error(ws->cond, "Non-constant condition in `when` statement"); } - if (ws->body == NULL || ws->body->kind != AstNode_BlockStmt) { + if (ws->body == nullptr || ws->body->kind != AstNode_BlockStmt) { error(ws->cond, "Invalid body for `when` statement"); } else { if (operand.value.kind == ExactValue_Bool && @@ -1582,7 +1582,7 @@ void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws, bool } } -// NOTE(bill): If file_scopes == NULL, this will act like a local scope +// NOTE(bill): If file_scopes == nullptr, this will act like a local scope void check_collect_entities(Checker *c, Array nodes, bool is_file_scope) { // NOTE(bill): File scope and local scope are different kinds of scopes if (is_file_scope) { @@ -1620,7 +1620,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco isize entity_cap = vd->names.count; isize entity_count = 0; Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_cap); - DeclInfo *di = NULL; + DeclInfo *di = nullptr; if (vd->values.count > 0) { di = make_declaration_info(heap_allocator(), c->context.scope, c->context.decl); di->entities = entities; @@ -1636,7 +1636,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco for_array(i, vd->names) { AstNode *name = vd->names[i]; - AstNode *value = NULL; + AstNode *value = nullptr; if (i < vd->values.count) { value = vd->values[i]; } @@ -1644,7 +1644,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco error(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind])); continue; } - Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident.token, NULL, false); + Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident.token, nullptr, false); e->Variable.is_thread_local = (vd->flags & VarDeclFlag_thread_local) != 0; e->identifier = name; @@ -1654,7 +1654,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco } AstNode *fl = c->context.curr_foreign_library; - if (fl != NULL) { + if (fl != nullptr) { GB_ASSERT(fl->kind == AstNode_Ident); e->Variable.is_foreign = true; e->Variable.foreign_library_ident = fl; @@ -1663,7 +1663,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco entities[entity_count++] = e; DeclInfo *d = di; - if (d == NULL) { + if (d == nullptr) { AstNode *init_expr = value; d = make_declaration_info(heap_allocator(), e->scope, c->context.decl); d->type_expr = vd->type; @@ -1673,7 +1673,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco add_entity_and_decl_info(c, name, e, d); } - if (di != NULL) { + if (di != nullptr) { di->entity_count = entity_count; } @@ -1687,26 +1687,26 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco } AstNode *init = unparen_expr(vd->values[i]); - if (init == NULL) { + if (init == nullptr) { error(name, "Expected a value for this constant value declaration"); continue; } AstNode *fl = c->context.curr_foreign_library; DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl); - Entity *e = NULL; + Entity *e = nullptr; if (is_ast_node_type(init)) { - e = make_entity_type_name(c->allocator, d->scope, name->Ident.token, NULL); - if (vd->type != NULL) { + e = make_entity_type_name(c->allocator, d->scope, name->Ident.token, nullptr); + if (vd->type != nullptr) { error(name, "A type declaration cannot have an type parameter"); } d->type_expr = init; d->init_expr = init; } else if (init->kind == AstNode_ProcLit) { ast_node(pl, ProcLit, init); - e = make_entity_procedure(c->allocator, d->scope, name->Ident.token, NULL, pl->tags); - if (fl != NULL) { + e = make_entity_procedure(c->allocator, d->scope, name->Ident.token, nullptr, pl->tags); + if (fl != nullptr) { GB_ASSERT(fl->kind == AstNode_Ident); e->Procedure.foreign_library_ident = fl; pl->tags |= ProcTag_foreign; @@ -1714,13 +1714,13 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco d->proc_lit = init; d->type_expr = pl->type; } else { - e = make_entity_constant(c->allocator, d->scope, name->Ident.token, NULL, empty_exact_value); + e = make_entity_constant(c->allocator, d->scope, name->Ident.token, nullptr, empty_exact_value); d->type_expr = vd->type; d->init_expr = init; } e->identifier = name; - if (fl != NULL && e->kind != Entity_Procedure) { + if (fl != nullptr && e->kind != Entity_Procedure) { AstNodeKind kind = init->kind; error(name, "Only procedures and variables are allowed to be in a foreign block, got %.*s", LIT(ast_node_strings[kind])); if (kind == AstNode_ProcType) { @@ -1772,7 +1772,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco continue; } - if (fl->cond != NULL) { + if (fl->cond != nullptr) { Operand operand = {Addressing_Invalid}; check_expr(c, &operand, fl->cond); if (operand.mode != Addressing_Constant || !is_type_boolean(operand.type)) { @@ -1796,7 +1796,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco AstNode *foreign_library = fb->foreign_library; if (foreign_library->kind != AstNode_Ident) { error(foreign_library, "foreign library name must be an identifier"); - foreign_library = NULL; + foreign_library = nullptr; } CheckerContext prev_context = c->context; @@ -1814,11 +1814,11 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco // DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl); - // Entity *e = NULL; + // Entity *e = nullptr; - // e = make_entity_procedure(c->allocator, d->scope, name->Ident, NULL, pd->tags); + // e = make_entity_procedure(c->allocator, d->scope, name->Ident, nullptr, pd->tags); // AstNode *fl = c->context.curr_foreign_library; - // if (fl != NULL) { + // if (fl != nullptr) { // GB_ASSERT(fl->kind == AstNode_Ident); // e->Procedure.foreign_library_ident = fl; // pd->tags |= ProcTag_foreign; @@ -1853,7 +1853,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco void check_all_global_entities(Checker *c) { - Scope *prev_file = NULL; + Scope *prev_file = nullptr; for_array(i, c->info.entities.entries) { auto *entry = &c->info.entities.entries[i]; @@ -1886,7 +1886,7 @@ void check_all_global_entities(Checker *c) { CheckerContext prev_context = c->context; c->context.decl = d; c->context.scope = d->scope; - check_entity_decl(c, e, d, NULL); + check_entity_decl(c, e, d, nullptr); c->context = prev_context; @@ -2009,7 +2009,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { HashKey key = hash_string(id->fullpath); Scope **found = map_get(file_scopes, key); - if (found == NULL) { + if (found == nullptr) { for_array(scope_index, file_scopes->entries) { Scope *scope = file_scopes->entries[scope_index].value; gb_printf_err("%.*s\n", LIT(scope->file->tokenizer.fullpath)); @@ -2082,7 +2082,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { HashKey key = hash_string(id->fullpath); Scope **found = map_get(file_scopes, key); - if (found == NULL) { + if (found == nullptr) { for_array(scope_index, file_scopes->entries) { Scope *scope = file_scopes->entries[scope_index].value; gb_printf_err("%.*s\n", LIT(scope->file->tokenizer.fullpath)); @@ -2097,7 +2097,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { continue; } - if (id->cond != NULL) { + if (id->cond != nullptr) { Operand operand = {Addressing_Invalid}; check_expr(c, &operand, id->cond); if (operand.mode != Addressing_Constant || !is_type_boolean(operand.type)) { @@ -2163,7 +2163,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { scope); - add_entity(c, parent_scope, NULL, e); + add_entity(c, parent_scope, nullptr, e); } } } @@ -2190,7 +2190,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { file_str = import_file; } - if (fl->cond != NULL) { + if (fl->cond != nullptr) { Operand operand = {Addressing_Invalid}; check_expr(c, &operand, fl->cond); if (operand.mode != Addressing_Constant || !is_type_boolean(operand.type)) { @@ -2212,7 +2212,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { fl->library_name.string = library_name; Entity *e = make_entity_library_name(c->allocator, parent_scope, fl->library_name, t_invalid, file_str, library_name); - add_entity(c, parent_scope, NULL, e); + add_entity(c, parent_scope, nullptr, e); } } } @@ -2228,7 +2228,7 @@ void check_parsed_files(Checker *c) { // Map full filepaths to Scopes for_array(i, c->parser->files) { AstFile *f = &c->parser->files[i]; - Scope *scope = NULL; + Scope *scope = nullptr; scope = make_scope(c->global_scope, c->allocator); scope->is_global = f->is_global_scope; scope->is_file = true; @@ -2270,7 +2270,7 @@ void check_parsed_files(Checker *c) { // NOTE(bill): Nested procedures bodies will be added to this "queue" for_array(i, c->procs.entries) { ProcedureInfo *pi = &c->procs.entries[i].value; - if (pi->type == NULL) { + if (pi->type == nullptr) { continue; } CheckerContext prev_context = c->context; @@ -2305,7 +2305,7 @@ void check_parsed_files(Checker *c) { HashKey key = entry->key; AstNode *expr = cast(AstNode *)key.ptr; ExprInfo *info = &entry->value; - if (info != NULL && expr != NULL) { + if (info != nullptr && expr != nullptr) { if (is_type_typed(info->type)) { compiler_error("%s (type %s) is typed!", expr_to_string(expr), type_to_string(info->type)); } @@ -2341,7 +2341,7 @@ void check_parsed_files(Checker *c) { for_array(i, c->info.definitions.entries) { Entity *e = c->info.definitions.entries[i].value; if (e->kind == Entity_TypeName) { - if (e->type != NULL) { + if (e->type != nullptr) { // i64 size = type_size_of(c->sizes, c->allocator, e->type); i64 align = type_align_of(c->allocator, e->type); if (align > 0) { @@ -2358,7 +2358,7 @@ void check_parsed_files(Checker *c) { Scope *s = file_scopes.entries[i].value; if (s->is_init) { Entity *e = current_scope_lookup_entity(s, str_lit("main")); - if (e == NULL) { + if (e == nullptr) { Token token = {}; if (s->file->tokens.count > 0) { token = s->file->tokens[0]; diff --git a/src/common.cpp b/src/common.cpp index 54d80f1e7..97a848ffa 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -93,9 +93,9 @@ void pool_init(Pool *pool, } void pool_free_all(Pool *p) { - if (p->current_memblock != NULL) { + if (p->current_memblock != nullptr) { array_add(&p->unused_memblock, p->current_memblock); - p->current_memblock = NULL; + p->current_memblock = nullptr; } for_array(i, p->used_memblock) { @@ -118,19 +118,19 @@ void pool_destroy(Pool *p) { } void pool_cycle_new_block(Pool *p) { - GB_ASSERT_MSG(p->block_allocator.proc != NULL, + GB_ASSERT_MSG(p->block_allocator.proc != nullptr, "You must call pool_init on a Pool before using it!"); - if (p->current_memblock != NULL) { + if (p->current_memblock != nullptr) { array_add(&p->used_memblock, p->current_memblock); } - u8 *new_block = NULL; + u8 *new_block = nullptr; if (p->unused_memblock.count > 0) { new_block = array_pop(&p->unused_memblock); } else { - GB_ASSERT(p->block_allocator.proc != NULL); + GB_ASSERT(p->block_allocator.proc != nullptr); new_block = cast(u8 *)gb_alloc_align(p->block_allocator, p->memblock_size, p->alignment); } @@ -146,9 +146,9 @@ void *pool_get(Pool *p, isize extra = alignment - (size & alignment); size += extra; if (size >= p->out_of_band_size) { - GB_ASSERT(p->block_allocator.proc != NULL); + GB_ASSERT(p->block_allocator.proc != nullptr); u8 *memory = cast(u8 *)gb_alloc_align(p->block_allocator, p->memblock_size, alignment); - if (memory != NULL) { + if (memory != nullptr) { array_add(&p->out_of_band_allocations, memory); } return memory; @@ -156,8 +156,8 @@ void *pool_get(Pool *p, if (p->bytes_left < size) { pool_cycle_new_block(p); - if (p->current_memblock != NULL) { - return NULL; + if (p->current_memblock != nullptr) { + return nullptr; } } @@ -172,7 +172,7 @@ gbAllocator pool_allocator(Pool *pool); GB_ALLOCATOR_PROC(pool_allocator_procedure) { Pool *p = cast(Pool *)allocator_data; - void *ptr = NULL; + void *ptr = nullptr; switch (type) { case gbAllocation_Alloc: @@ -296,7 +296,7 @@ f64 gb_sqrt(f64 x) { } while (0) #define DLIST_APPEND(root_element, curr_element, next_element) do { \ - if ((root_element) == NULL) { \ + if ((root_element) == nullptr) { \ (root_element) = (curr_element) = (next_element); \ } else { \ DLIST_SET(curr_element, next_element); \ @@ -362,7 +362,7 @@ wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc) { i++; } _argv[j] = '\0'; - argv[argc] = NULL; + argv[argc] = nullptr; if (_argc) *_argc = argc; return argv; diff --git a/src/docs.cpp b/src/docs.cpp index 21d2f0ed2..44c969181 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -10,7 +10,7 @@ String alloc_comment_group_string(gbAllocator a, CommentGroup g) { len += 1; // for \n } if (len == 0) { - return make_string(NULL, 0); + return make_string(nullptr, 0); } u8 *text = gb_alloc_array(a, u8, len+1); @@ -70,7 +70,7 @@ void print_proc_decl(AstNodeProcDecl *pd) { gbString params = expr_to_string(proc_type->params); defer (gb_string_free(params)); gb_printf("proc %.*s(%s)", LIT(name), params); - if (proc_type->results != NULL) { + if (proc_type->results != nullptr) { ast_node(fl, FieldList, proc_type->results); isize count = fl->list.count; if (count > 0) { diff --git a/src/entity.cpp b/src/entity.cpp index 1f2478c25..a9b083400 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -71,8 +71,8 @@ struct Entity { Token token; Scope * scope; Type * type; - AstNode * identifier; // Can be NULL - DeclInfo * parent_proc_decl; // NULL if in file/global scope + AstNode * identifier; // Can be nullptr + DeclInfo * parent_proc_decl; // nullptr if in file/global scope // TODO(bill): Cleanup how `using` works for entities Entity * using_parent; @@ -131,7 +131,7 @@ struct Entity { }; }; -gb_global Entity *e_context = NULL; +gb_global Entity *e_context = nullptr; bool is_entity_kind_exported(EntityKind kind) { switch (kind) { @@ -146,7 +146,7 @@ bool is_entity_kind_exported(EntityKind kind) { bool is_entity_exported(Entity *e) { // TODO(bill): Determine the actual exportation rules for imports of entities - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); if (!is_entity_kind_exported(e->kind)) { return false; } @@ -177,7 +177,7 @@ Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *typ } Entity *make_entity_using_variable(gbAllocator a, Entity *parent, Token token, Type *type) { - GB_ASSERT(parent != NULL); + GB_ASSERT(parent != nullptr); token.pos = parent->token.pos; Entity *entity = alloc_entity(a, Entity_Variable, parent->scope, token, type); entity->using_parent = parent; @@ -265,7 +265,7 @@ Entity *make_entity_library_name(gbAllocator a, Scope *scope, Token token, Type Entity *make_entity_nil(gbAllocator a, String name, Type *type) { Token token = make_token_ident(name); - Entity *entity = alloc_entity(a, Entity_Nil, NULL, token, type); + Entity *entity = alloc_entity(a, Entity_Nil, nullptr, token, type); return entity; } @@ -280,6 +280,6 @@ Entity *make_entity_label(gbAllocator a, Scope *scope, Token token, Type *type, Entity *make_entity_dummy_variable(gbAllocator a, Scope *scope, Token token) { token.string = str_lit("_"); - return make_entity_variable(a, scope, token, NULL, false); + return make_entity_variable(a, scope, token, nullptr, false); } diff --git a/src/integer128.cpp b/src/integer128.cpp index ddcdaca76..9a0772266 100644 --- a/src/integer128.cpp +++ b/src/integer128.cpp @@ -520,7 +520,7 @@ u128 u128_quo(u128 a, u128 b) { } u128 res = {0}; - u128_divide(a, b, &res, NULL); + u128_divide(a, b, &res, nullptr); return res; } u128 u128_mod(u128 a, u128 b) { @@ -528,7 +528,7 @@ u128 u128_mod(u128 a, u128 b) { return u128_from_u64(a.lo%b.lo); } u128 res = {0}; - u128_divide(a, b, NULL, &res); + u128_divide(a, b, nullptr, &res); return res; } @@ -716,11 +716,11 @@ void i128_divide(i128 a, i128 b, i128 *quo, i128 *rem) { i128 i128_quo(i128 a, i128 b) { i128 res = {0}; - i128_divide(a, b, &res, NULL); + i128_divide(a, b, &res, nullptr); return res; } i128 i128_mod(i128 a, i128 b) { i128 res = {0}; - i128_divide(a, b, NULL, &res); + i128_divide(a, b, nullptr, &res); return res; } diff --git a/src/ir.cpp b/src/ir.cpp index fc4c97c9a..d74307c81 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -55,7 +55,7 @@ struct irBlock { i32 index; String label; irProcedure *parent; - AstNode * node; // Can be NULL + AstNode * node; // Can be nullptr Scope * scope; isize scope_index; irDomNode dom; @@ -395,14 +395,14 @@ struct irValue { }; }; -gb_global irValue *v_zero = NULL; -gb_global irValue *v_one = NULL; -gb_global irValue *v_zero32 = NULL; -gb_global irValue *v_one32 = NULL; -gb_global irValue *v_two32 = NULL; -gb_global irValue *v_false = NULL; -gb_global irValue *v_true = NULL; -gb_global irValue *v_raw_nil = NULL; +gb_global irValue *v_zero = nullptr; +gb_global irValue *v_one = nullptr; +gb_global irValue *v_zero32 = nullptr; +gb_global irValue *v_one32 = nullptr; +gb_global irValue *v_two32 = nullptr; +gb_global irValue *v_false = nullptr; +gb_global irValue *v_true = nullptr; +gb_global irValue *v_raw_nil = nullptr; enum irAddrKind { irAddr_Default, @@ -616,16 +616,16 @@ Type *ir_instr_type(irInstr *instr) { return ir_type(instr->Select.true_value); case irInstr_Call: { Type *pt = base_type(instr->Call.type); - if (pt != NULL) { + if (pt != nullptr) { if (pt->kind == Type_Tuple && pt->Tuple.variable_count == 1) { return pt->Tuple.variables[0]->type; } return pt; } - return NULL; + return nullptr; } break; } - return NULL; + return nullptr; } Type *ir_type(irValue *value) { @@ -649,7 +649,7 @@ Type *ir_type(irValue *value) { case irValue_Instr: return ir_instr_type(&value->Instr); } - return NULL; + return nullptr; } @@ -663,7 +663,7 @@ bool ir_is_blank_ident(AstNode *node) { irInstr *ir_get_last_instr(irBlock *block) { - if (block != NULL) { + if (block != nullptr) { isize len = block->instrs.count; if (len > 0) { irValue *v = block->instrs[len-1]; @@ -671,12 +671,12 @@ irInstr *ir_get_last_instr(irBlock *block) { return &v->Instr; } } - return NULL; + return nullptr; } bool ir_is_instr_terminating(irInstr *i) { - if (i != NULL) { + if (i != nullptr) { switch (i->kind) { case irInstr_Return: case irInstr_Unreachable: @@ -709,10 +709,10 @@ Array *ir_value_referrers(irValue *v) { case irValue_Param: return &v->Param.referrers; case irValue_Proc: { - if (v->Proc.parent != NULL) { + if (v->Proc.parent != nullptr) { return &v->Proc.referrers; } - return NULL; + return nullptr; } case irValue_Instr: { irInstr *i = &v->Instr; @@ -723,7 +723,7 @@ Array *ir_value_referrers(irValue *v) { } break; } - return NULL; + return nullptr; } @@ -830,7 +830,7 @@ String ir_get_global_name(irModule *m, irValue *v) { Entity *e = g->entity; String name = e->token.string; String *found = map_get(&m->entity_names, hash_entity(e)); - if (found != NULL) { + if (found != nullptr) { name = *found; } return name; @@ -1069,7 +1069,7 @@ irValue *ir_emit(irProcedure *proc, irValue *instr) { GB_ASSERT(instr->kind == irValue_Instr); irBlock *b = proc->curr_block; instr->Instr.parent = b; - if (b != NULL) { + if (b != nullptr) { irInstr *i = ir_get_last_instr(b); if (!ir_is_instr_terminating(i)) { array_add(&b->instrs, instr); @@ -1135,8 +1135,8 @@ irValue *ir_generate_array(irModule *m, Type *elem_type, i64 count, String prefi token.string.text = gb_alloc_array(a, u8, name_len); token.string.len = gb_snprintf(cast(char *)token.string.text, name_len, "%.*s-%llx", LIT(prefix), cast(unsigned long long)id)-1; - Entity *e = make_entity_variable(a, NULL, token, make_type_array(a, elem_type, count), false); - irValue *value = ir_value_global(a, e, NULL); + Entity *e = make_entity_variable(a, nullptr, token, make_type_array(a, elem_type, count), false); + irValue *value = ir_value_global(a, e, nullptr); value->Global.is_private = true; ir_module_add_value(m, e, value); map_set(&m->members, hash_string(token.string), value); @@ -1144,10 +1144,10 @@ irValue *ir_generate_array(irModule *m, Type *elem_type, i64 count, String prefi } irBlock *ir_new_block(irProcedure *proc, AstNode *node, char *label) { - Scope *scope = NULL; - if (node != NULL) { + Scope *scope = nullptr; + if (node != nullptr) { scope = scope_of_node(proc->module->info, node); - GB_ASSERT_MSG(scope != NULL, "Block scope not found for %.*s", LIT(ast_node_strings[node->kind])); + GB_ASSERT_MSG(scope != nullptr, "Block scope not found for %.*s", LIT(ast_node_strings[node->kind])); } irValue *v = ir_alloc_value(proc->module->allocator, irValue_Block); @@ -1180,7 +1180,7 @@ void ir_add_block_to_proc(irProcedure *proc, irBlock *b) { void ir_start_block(irProcedure *proc, irBlock *block) { proc->curr_block = block; - if (block != NULL) { + if (block != nullptr) { ir_add_block_to_proc(proc, block); } } @@ -1235,7 +1235,7 @@ irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) { String name = make_string(str, len-1); - Entity *e = make_entity_constant(a, NULL, make_token_ident(name), t, value); + Entity *e = make_entity_constant(a, nullptr, make_token_ident(name), t, value); irValue *g = ir_value_global(a, e, backing_array); ir_module_add_value(m, e, g); map_set(&m->members, hash_string(name), g); @@ -1262,7 +1262,7 @@ irValue *ir_add_global_string_array(irModule *m, String string) { token.string = name; Type *type = make_type_array(a, t_u8, string.len); ExactValue ev = exact_value_string(string); - Entity *entity = make_entity_constant(a, NULL, token, type, ev); + Entity *entity = make_entity_constant(a, nullptr, token, type, ev); irValue *g = ir_value_global(a, entity, ir_add_module_constant(m, type, ev)); g->Global.is_private = true; // g->Global.is_unnamed_addr = true; @@ -1289,7 +1289,7 @@ irValue *ir_add_local(irProcedure *proc, Entity *e, AstNode *expr, bool zero_ini ir_emit_zero_init(proc, instr); } - if (expr != NULL && proc->entity != NULL) { + if (expr != nullptr && proc->entity != nullptr) { irDebugInfo *di = *map_get(&proc->module->debug_info, hash_entity(proc->entity)); ir_emit(proc, ir_instr_debug_declare(proc, di, expr, e, true, instr)); } @@ -1299,15 +1299,15 @@ irValue *ir_add_local(irProcedure *proc, Entity *e, AstNode *expr, bool zero_ini irValue *ir_add_local_for_identifier(irProcedure *proc, AstNode *name, bool zero_initialized) { Entity *e = entity_of_ident(proc->module->info, name); - if (e != NULL) { + if (e != nullptr) { ir_emit_comment(proc, e->token.string); if (e->kind == Entity_Variable && e->Variable.is_foreign) { HashKey key = hash_string(e->token.string); irValue **prev_value = map_get(&proc->module->members, key); - if (prev_value == NULL) { + if (prev_value == nullptr) { // NOTE(bill): Don't do mutliple declarations in the IR - irValue *g = ir_value_global(proc->module->allocator, e, NULL); + irValue *g = ir_value_global(proc->module->allocator, e, nullptr); g->Global.name = e->token.string; g->Global.is_foreign = true; @@ -1320,13 +1320,13 @@ irValue *ir_add_local_for_identifier(irProcedure *proc, AstNode *name, bool zero } return ir_add_local(proc, e, name, zero_initialized); } - return NULL; + return nullptr; } irValue *ir_add_local_generated(irProcedure *proc, Type *type) { - GB_ASSERT(type != NULL); + GB_ASSERT(type != nullptr); - Scope *scope = NULL; + Scope *scope = nullptr; if (proc->curr_block) { scope = proc->curr_block->scope; } @@ -1334,12 +1334,12 @@ irValue *ir_add_local_generated(irProcedure *proc, Type *type) { scope, empty_token, type, false); - return ir_add_local(proc, e, NULL, true); + return ir_add_local(proc, e, nullptr, true); } irValue *ir_add_global_generated(irModule *m, Type *type, irValue *value) { - GB_ASSERT(type != NULL); + GB_ASSERT(type != nullptr); gbAllocator a = m->allocator; isize max_len = 7+8+1; @@ -1348,7 +1348,7 @@ irValue *ir_add_global_generated(irModule *m, Type *type, irValue *value) { m->global_generated_index++; String name = make_string(str, len-1); - Scope *scope = NULL; + Scope *scope = nullptr; Entity *e = make_entity_variable(a, scope, make_token_ident(name), @@ -1384,7 +1384,7 @@ irValue *ir_add_param(irProcedure *proc, Entity *e, AstNode *expr, Type *abi_typ } GB_PANIC("Unreachable"); - return NULL; + return nullptr; } @@ -1397,10 +1397,10 @@ irValue *ir_add_param(irProcedure *proc, Entity *e, AstNode *expr, Type *abi_typ irDebugInfo *ir_add_debug_info_file(irProcedure *proc, AstFile *file) { // if (!proc->module->generate_debug_info) { - // return NULL; + // return nullptr; // } - GB_ASSERT(file != NULL); + GB_ASSERT(file != nullptr); irDebugInfo *di = ir_alloc_debug_info(proc->module->allocator, irDebugInfo_File); di->File.file = file; @@ -1429,10 +1429,10 @@ irDebugInfo *ir_add_debug_info_file(irProcedure *proc, AstFile *file) { irDebugInfo *ir_add_debug_info_proc(irProcedure *proc, Entity *entity, String name, irDebugInfo *file) { // if (!proc->module->generate_debug_info) { - // return NULL; + // return nullptr; // } - GB_ASSERT(entity != NULL); + GB_ASSERT(entity != nullptr); irDebugInfo *di = ir_alloc_debug_info(proc->module->allocator, irDebugInfo_Proc); di->Proc.entity = entity; di->Proc.name = name; @@ -1463,7 +1463,7 @@ irValue *ir_emit_store(irProcedure *p, irValue *address, irValue *value) { return ir_emit(p, ir_instr_store(p, address, value, is_type_atomic(a))); } irValue *ir_emit_load(irProcedure *p, irValue *address) { - GB_ASSERT(address != NULL); + GB_ASSERT(address != nullptr); return ir_emit(p, ir_instr_load(p, address)); } irValue *ir_emit_select(irProcedure *p, irValue *cond, irValue *t, irValue *f) { @@ -1514,7 +1514,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, irValue **args, isize arg_ GB_ASSERT(pt->kind == Type_Proc); Type *results = pt->Proc.results; - irValue *context_ptr = NULL; + irValue *context_ptr = nullptr; if (pt->Proc.calling_convention == ProcCC_Odin) { context_ptr = ir_find_or_generate_context_ptr(p); } @@ -1546,11 +1546,11 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, irValue **args, isize arg_ if (pt->Proc.return_by_pointer) { irValue *return_ptr = ir_add_local_generated(p, rt); GB_ASSERT(is_type_pointer(ir_type(return_ptr))); - ir_emit(p, ir_instr_call(p, value, return_ptr, args, arg_count, NULL, context_ptr)); + ir_emit(p, ir_instr_call(p, value, return_ptr, args, arg_count, nullptr, context_ptr)); return ir_emit_load(p, return_ptr); } - irValue *result = ir_emit(p, ir_instr_call(p, value, NULL, args, arg_count, abi_rt, context_ptr)); + irValue *result = ir_emit(p, ir_instr_call(p, value, nullptr, args, arg_count, abi_rt, context_ptr)); if (abi_rt != results) { result = ir_emit_transmute(p, result, rt); } @@ -1560,7 +1560,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, irValue **args, isize arg_ irValue *ir_emit_global_call(irProcedure *proc, char *name_, irValue **args, isize arg_count) { String name = make_string_c(name_); irValue **found = map_get(&proc->module->members, hash_string(name)); - GB_ASSERT_MSG(found != NULL, "%.*s", LIT(name)); + GB_ASSERT_MSG(found != nullptr, "%.*s", LIT(name)); irValue *gp = *found; return ir_emit_call(proc, gp, args, arg_count); } @@ -1584,7 +1584,7 @@ void ir_emit_defer_stmts(irProcedure *proc, irDeferExitKind kind, irBlock *block } else if (kind == irDeferExit_Return) { ir_build_defer_stmt(proc, d); } else if (kind == irDeferExit_Branch) { - GB_ASSERT(block != NULL); + GB_ASSERT(block != nullptr); isize lower_limit = block->scope_index+1; if (lower_limit < d.scope_index) { ir_build_defer_stmt(proc, d); @@ -1611,11 +1611,11 @@ void ir_emit_unreachable(irProcedure *proc) { } void ir_emit_return(irProcedure *proc, irValue *v) { - ir_emit_defer_stmts(proc, irDeferExit_Return, NULL); + ir_emit_defer_stmts(proc, irDeferExit_Return, nullptr); if (proc->type->Proc.return_by_pointer) { ir_emit_store(proc, proc->return_ptr, v); - ir_emit(proc, ir_instr_return(proc, NULL)); + ir_emit(proc, ir_instr_return(proc, nullptr)); } else { Type *abi_rt = proc->type->Proc.abi_compat_result_type; if (abi_rt != proc->type->Proc.results) { @@ -1628,27 +1628,27 @@ void ir_emit_return(irProcedure *proc, irValue *v) { void ir_emit_jump(irProcedure *proc, irBlock *target_block) { irBlock *b = proc->curr_block; - if (b == NULL) { + if (b == nullptr) { return; } ir_emit(proc, ir_instr_jump(proc, target_block)); ir_add_edge(b, target_block); - ir_start_block(proc, NULL); + ir_start_block(proc, nullptr); } void ir_emit_if(irProcedure *proc, irValue *cond, irBlock *true_block, irBlock *false_block) { irBlock *b = proc->curr_block; - if (b == NULL) { + if (b == nullptr) { return; } ir_emit(proc, ir_instr_if(proc, cond, true_block, false_block)); ir_add_edge(b, true_block); ir_add_edge(b, false_block); - ir_start_block(proc, NULL); + ir_start_block(proc, nullptr); } void ir_emit_startup_runtime(irProcedure *proc) { - GB_ASSERT(proc->parent == NULL && proc->name == "main"); + GB_ASSERT(proc->parent == nullptr && proc->name == "main"); ir_emit(proc, ir_alloc_instr(proc, irInstr_StartupRuntime)); } @@ -1701,7 +1701,7 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) { irValue *p = ir_emit_conv(proc, key, t_uint); ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, p, hash_type)); } else if (is_type_float(t)) { - irValue *bits = NULL; + irValue *bits = nullptr; i64 size = type_size_of(proc->module->allocator, t); switch (8*size) { case 32: bits = ir_emit_transmute(proc, key, t_u32); break; @@ -1712,7 +1712,7 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) { ir_emit_store(proc, ir_emit_struct_ep(proc, v, 0), ir_emit_conv(proc, bits, hash_type)); } else if (is_type_string(t)) { irValue *str = ir_emit_conv(proc, key, t_string); - irValue *hashed_str = NULL; + irValue *hashed_str = nullptr; if (str->kind == irValue_Constant) { ExactValue ev = str->Constant.value; @@ -1733,7 +1733,7 @@ irValue *ir_gen_map_key(irProcedure *proc, irValue *key, Type *key_type) { return ir_emit_load(proc, v); } -// NOTE(bill): Returns NULL if not possible +// NOTE(bill): Returns nullptr if not possible irValue *ir_address_from_load_or_generate_local(irProcedure *proc, irValue *val) { if (val->kind == irValue_Instr) { if (val->Instr.kind == irInstr_Load) { @@ -1748,8 +1748,8 @@ irValue *ir_address_from_load_or_generate_local(irProcedure *proc, irValue *val) Type *ir_addr_type(irAddr addr) { - if (addr.addr == NULL) { - return NULL; + if (addr.addr == nullptr) { + return nullptr; } if (addr.kind == irAddr_Map) { @@ -1787,8 +1787,8 @@ irValue *ir_emit_ptr_offset(irProcedure *proc, irValue *ptr, irValue *offset); irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue *right, Type *type); irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) { - if (addr.addr == NULL) { - return NULL; + if (addr.addr == nullptr) { + return nullptr; } if (addr.kind == irAddr_Map) { return ir_insert_dynamic_map_key_and_value(proc, addr.addr, addr.map_type, addr.map_key, value); @@ -1807,10 +1807,10 @@ irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) { i32 size_in_bytes = next_pow2((size_in_bits+7)/8); if (size_in_bytes == 0) { GB_ASSERT(size_in_bits == 0); - return NULL; + return nullptr; } - Type *int_type = NULL; + Type *int_type = nullptr; switch (size_in_bytes) { case 1: int_type = t_u8; break; case 2: int_type = t_u16; break; @@ -1818,7 +1818,7 @@ irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) { case 8: int_type = t_u64; break; case 16: int_type = t_u128; break; } - GB_ASSERT(int_type != NULL); + GB_ASSERT(int_type != nullptr); value = ir_emit_conv(proc, value, int_type); @@ -1866,9 +1866,9 @@ irValue *ir_addr_store(irProcedure *proc, irAddr addr, irValue *value) { } irValue *ir_addr_load(irProcedure *proc, irAddr addr) { - if (addr.addr == NULL) { + if (addr.addr == nullptr) { GB_PANIC("Illegal addr load"); - return NULL; + return nullptr; } if (addr.kind == irAddr_Map) { @@ -1886,8 +1886,8 @@ irValue *ir_addr_load(irProcedure *proc, irAddr addr) { irValue *ok = ir_emit_comp(proc, Token_NotEq, ptr, v_raw_nil); ir_emit_store(proc, ir_emit_struct_ep(proc, v, 1), ok); - irBlock *then = ir_new_block(proc, NULL, "map.get.then"); - irBlock *done = ir_new_block(proc, NULL, "map.get.done"); + irBlock *then = ir_new_block(proc, nullptr, "map.get.then"); + irBlock *done = ir_new_block(proc, nullptr, "map.get.done"); ir_emit_if(proc, ok, then, done); ir_start_block(proc, then); { @@ -1925,7 +1925,7 @@ irValue *ir_addr_load(irProcedure *proc, irAddr addr) { return ir_const_i32(a, 0); } - Type *int_type = NULL; + Type *int_type = nullptr; switch (size_in_bytes) { case 1: int_type = t_u8; break; case 2: int_type = t_u16; break; @@ -1933,7 +1933,7 @@ irValue *ir_addr_load(irProcedure *proc, irAddr addr) { case 8: int_type = t_u64; break; case 16: int_type = t_u128; break; } - GB_ASSERT(int_type != NULL); + GB_ASSERT(int_type != nullptr); irValue *bytes = ir_emit_conv(proc, addr.addr, t_u8_ptr); @@ -2051,8 +2051,8 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue * irValue *c = ir_emit_struct_ev(proc, right, 0); irValue *d = ir_emit_struct_ev(proc, right, 1); - irValue *real = NULL; - irValue *imag = NULL; + irValue *real = nullptr; + irValue *imag = nullptr; switch (op) { case Token_Add: @@ -2172,13 +2172,13 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue * if (is_type_i128_or_u128(type)) { // IMPORTANT NOTE(bill): LLVM is goddamn buggy! bool is_unsigned = is_type_unsigned(type); - char *name = NULL; + char *name = nullptr; if (op == Token_Quo) { name = cast(char *)(is_unsigned ? "__udivti3" : "__divti3"); } else if (op == Token_Mod) { name = cast(char *)(is_unsigned ? "__umodti3" : "__modti3"); } - if (name != NULL) { + if (name != nullptr) { irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 2); args[0] = left; args[1] = right; @@ -2262,7 +2262,7 @@ irValue *ir_emit_comp_against_nil(irProcedure *proc, TokenKind op_kind, irValue irValue *tag = ir_emit_union_tag_value(proc, x); return ir_emit_comp(proc, op_kind, tag, v_zero); } - return NULL; + return nullptr; } irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irValue *right) { @@ -2271,13 +2271,13 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal GB_ASSERT(gb_is_between(op_kind, Token__ComparisonBegin+1, Token__ComparisonEnd-1)); - irValue *nil_check = NULL; + irValue *nil_check = nullptr; if (left->kind == irValue_Nil) { nil_check = ir_emit_comp_against_nil(proc, op_kind, right); } else if (right->kind == irValue_Nil) { nil_check = ir_emit_comp_against_nil(proc, op_kind, left); } - if (nil_check != NULL) { + if (nil_check != nullptr) { return nil_check; } @@ -2331,7 +2331,7 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal } irValue *ir_emit_array_ep(irProcedure *proc, irValue *s, irValue *index) { - GB_ASSERT(index != NULL); + GB_ASSERT(index != nullptr); Type *t = ir_type(s); GB_ASSERT(is_type_pointer(t)); Type *st = base_type(type_deref(t)); @@ -2351,7 +2351,7 @@ irValue *ir_emit_array_epi(irProcedure *proc, irValue *s, i32 index) { irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { gbAllocator a = proc->module->allocator; Type *t = base_type(type_deref(ir_type(s))); - Type *result_type = NULL; + Type *result_type = nullptr; if (is_type_struct(t)) { GB_ASSERT(t->Record.field_count > 0); @@ -2410,7 +2410,7 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) { GB_PANIC("TODO(bill): struct_gep type: %s, %d", type_to_string(ir_type(s)), index); } - GB_ASSERT(result_type != NULL); + GB_ASSERT(result_type != nullptr); return ir_emit(proc, ir_instr_struct_element_ptr(proc, s, index, result_type)); } @@ -2421,7 +2421,7 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) { gbAllocator a = proc->module->allocator; Type *t = base_type(ir_type(s)); - Type *result_type = NULL; + Type *result_type = nullptr; if (is_type_struct(t)) { GB_ASSERT(t->Record.field_count > 0); @@ -2479,7 +2479,7 @@ irValue *ir_emit_struct_ev(irProcedure *proc, irValue *s, i32 index) { GB_PANIC("TODO(bill): struct_ev type: %s, %d", type_to_string(ir_type(s)), index); } - GB_ASSERT(result_type != NULL); + GB_ASSERT(result_type != nullptr); return ir_emit(proc, ir_instr_struct_extract_value(proc, s, index, result_type)); } @@ -2690,17 +2690,17 @@ irValue *ir_add_local_slice(irProcedure *proc, Type *slice_type, irValue *base, gbAllocator a = proc->module->allocator; Type *bt = base_type(ir_type(base)); - if (low == NULL) { + if (low == nullptr) { low = v_zero; } - if (high == NULL) { + if (high == nullptr) { switch (bt->kind) { case Type_Array: high = ir_array_len(proc, base); break; case Type_Slice: high = ir_slice_count(proc, base); break; case Type_Pointer: high = v_one; break; } } - if (max == NULL) { + if (max == nullptr) { switch (bt->kind) { case Type_Array: high = ir_array_len(proc, base); break; case Type_Slice: high = ir_slice_capacity(proc, base); break; @@ -2711,7 +2711,7 @@ irValue *ir_add_local_slice(irProcedure *proc, Type *slice_type, irValue *base, irValue *len = ir_emit_arith(proc, Token_Sub, high, low, t_int); irValue *cap = ir_emit_arith(proc, Token_Sub, max, low, t_int); - irValue *elem = NULL; + irValue *elem = nullptr; switch (bt->kind) { case Type_Array: elem = ir_array_elem(proc, base); break; case Type_Slice: elem = ir_slice_elem(proc, base); break; @@ -2729,7 +2729,7 @@ irValue *ir_add_local_slice(irProcedure *proc, Type *slice_type, irValue *base, irValue *ir_find_or_add_entity_string(irModule *m, String str) { irValue **found = map_get(&m->const_strings, hash_string(str)); - if (found != NULL) { + if (found != nullptr) { return *found; } irValue *v = ir_const_string(m->allocator, str); @@ -2985,7 +2985,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { if (field_name.len > 0) { // NOTE(bill): It can be casted Selection sel = lookup_field(proc->module->allocator, st, field_name, false); - if (sel.entity != NULL) { + if (sel.entity != nullptr) { ir_emit_comment(proc, str_lit("cast - polymorphism")); if (st_is_ptr) { irValue *res = ir_emit_deep_field_gep(proc, value, sel); @@ -3074,7 +3074,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { Type *st = default_type(src_type); - irValue *data = NULL; + irValue *data = nullptr; if (value->kind == irValue_Instr && value->Instr.kind == irInstr_Load) { // NOTE(bill): Addreirble value @@ -3107,7 +3107,7 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { type_to_string(src_type), type_to_string(t), LIT(proc->name)); - return NULL; + return nullptr; } bool ir_is_type_aggregate(Type *t) { @@ -3215,7 +3215,7 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token Type *dst = type_deref(dst_ptr); irValue *tag = ir_emit_load(proc, ir_emit_union_tag_ptr(proc, value)); - irValue *dst_tag = NULL; + irValue *dst_tag = nullptr; for (isize i = 1; i < src->Record.variant_count; i++) { Entity *f = src->Record.variants[i]; if (are_types_identical(f->type, dst)) { @@ -3223,10 +3223,10 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token break; } } - GB_ASSERT(dst_tag != NULL); + GB_ASSERT(dst_tag != nullptr); - irBlock *ok_block = ir_new_block(proc, NULL, "union_cast.ok"); - irBlock *end_block = ir_new_block(proc, NULL, "union_cast.end"); + irBlock *ok_block = ir_new_block(proc, nullptr, "union_cast.ok"); + irBlock *end_block = ir_new_block(proc, nullptr, "union_cast.end"); irValue *cond = ir_emit_comp(proc, Token_CmpEq, tag, dst_tag); ir_emit_if(proc, cond, ok_block, end_block); ir_start_block(proc, ok_block); @@ -3250,7 +3250,7 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token irValue *value_ = ir_address_from_load_or_generate_local(proc, value); irValue *tag = ir_emit_load(proc, ir_emit_union_tag_ptr(proc, value_)); - irValue *dst_tag = NULL; + irValue *dst_tag = nullptr; for (isize i = 1; i < src->Record.variant_count; i++) { Entity *f = src->Record.variants[i]; if (are_types_identical(f->type, dst)) { @@ -3258,10 +3258,10 @@ irValue *ir_emit_union_cast(irProcedure *proc, irValue *value, Type *type, Token break; } } - GB_ASSERT(dst_tag != NULL); + GB_ASSERT(dst_tag != nullptr); - irBlock *ok_block = ir_new_block(proc, NULL, "union_cast.ok"); - irBlock *end_block = ir_new_block(proc, NULL, "union_cast.end"); + irBlock *ok_block = ir_new_block(proc, nullptr, "union_cast.ok"); + irBlock *end_block = ir_new_block(proc, nullptr, "union_cast.end"); irValue *cond = ir_emit_comp(proc, Token_CmpEq, tag, dst_tag); ir_emit_if(proc, cond, ok_block, end_block); ir_start_block(proc, ok_block); @@ -3315,8 +3315,8 @@ irAddr ir_emit_any_cast_addr(irProcedure *proc, irValue *value, Type *type, Toke irValue *any_ti = ir_emit_struct_ev(proc, value, 1); - irBlock *ok_block = ir_new_block(proc, NULL, "any_cast.ok"); - irBlock *end_block = ir_new_block(proc, NULL, "any_cast.end"); + irBlock *ok_block = ir_new_block(proc, nullptr, "any_cast.ok"); + irBlock *end_block = ir_new_block(proc, nullptr, "any_cast.end"); irValue *cond = ir_emit_comp(proc, Token_CmpEq, any_ti, ti_ptr); ir_emit_if(proc, cond, ok_block, end_block); ir_start_block(proc, ok_block); @@ -3356,11 +3356,11 @@ irValue *ir_emit_any_cast(irProcedure *proc, irValue *value, Type *type, TokenPo } // TODO(bill): Try and make a lot of this constant aggregate literals in LLVM IR -gb_global irValue *ir_global_type_info_data = NULL; -gb_global irValue *ir_global_type_info_member_types = NULL; -gb_global irValue *ir_global_type_info_member_names = NULL; -gb_global irValue *ir_global_type_info_member_offsets = NULL; -gb_global irValue *ir_global_type_info_member_usings = NULL; +gb_global irValue *ir_global_type_info_data = nullptr; +gb_global irValue *ir_global_type_info_member_types = nullptr; +gb_global irValue *ir_global_type_info_member_names = nullptr; +gb_global irValue *ir_global_type_info_member_offsets = nullptr; +gb_global irValue *ir_global_type_info_member_usings = nullptr; gb_global i32 ir_global_type_info_data_index = 0; gb_global i32 ir_global_type_info_member_types_index = 0; @@ -3386,9 +3386,9 @@ irValue *ir_type_info(irProcedure *proc, Type *type) { irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) { ast_node(be, BinaryExpr, expr); #if 0 - irBlock *true_ = ir_new_block(proc, NULL, "logical.cmp.true"); - irBlock *false_ = ir_new_block(proc, NULL, "logical.cmp.false"); - irBlock *done = ir_new_block(proc, NULL, "logical.cmp.done"); + irBlock *true_ = ir_new_block(proc, nullptr, "logical.cmp.true"); + irBlock *false_ = ir_new_block(proc, nullptr, "logical.cmp.false"); + irBlock *done = ir_new_block(proc, nullptr, "logical.cmp.done"); irValue *result = ir_add_local_generated(proc, t_bool); ir_build_cond(proc, expr, true_, false_); @@ -3405,13 +3405,13 @@ irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) { return ir_emit_load(proc, result); #else - irBlock *rhs = ir_new_block(proc, NULL, "logical.cmp.rhs"); - irBlock *done = ir_new_block(proc, NULL, "logical.cmp.done"); + irBlock *rhs = ir_new_block(proc, nullptr, "logical.cmp.rhs"); + irBlock *done = ir_new_block(proc, nullptr, "logical.cmp.done"); Type *type = type_of_expr(proc->module->info, expr); type = default_type(type); - irValue *short_circuit = NULL; + irValue *short_circuit = nullptr; if (be->op.kind == Token_CmpAnd) { ir_build_cond(proc, be->left, rhs, done); short_circuit = v_false; @@ -3608,12 +3608,12 @@ void ir_push_target_list(irProcedure *proc, AstNode *label, irBlock *break_, irB tl->fallthrough_ = fallthrough_; proc->target_list = tl; - if (label != NULL) { // Set label blocks + if (label != nullptr) { // Set label blocks GB_ASSERT(label->kind == AstNode_Label); for_array(i, proc->branch_blocks) { irBranchBlocks *b = &proc->branch_blocks[i]; - GB_ASSERT(b->label != NULL && label != NULL); + GB_ASSERT(b->label != nullptr && label != nullptr); GB_ASSERT(b->label->kind == AstNode_Label); if (b->label == label) { b->break_ = break_; @@ -3649,10 +3649,10 @@ void ir_gen_global_type_name(irModule *m, Entity *e, String name) { void ir_build_defer_stmt(irProcedure *proc, irDefer d) { - irBlock *b = ir_new_block(proc, NULL, "defer"); + irBlock *b = ir_new_block(proc, nullptr, "defer"); // NOTE(bill): The prev block may defer injection before it's terminator irInstr *last_instr = ir_get_last_instr(proc->curr_block); - if (last_instr == NULL || !ir_is_instr_terminating(last_instr)) { + if (last_instr == nullptr || !ir_is_instr_terminating(last_instr)) { ir_emit_jump(proc, b); } ir_start_block(proc, b); @@ -3668,7 +3668,7 @@ void ir_build_defer_stmt(irProcedure *proc, irDefer d) { irValue *ir_emit_clamp(irProcedure *proc, Type *t, irValue *x, irValue *min, irValue *max) { - irValue *cond = NULL; + irValue *cond = nullptr; ir_emit_comment(proc, str_lit("clamp")); x = ir_emit_conv(proc, x, t); min = ir_emit_conv(proc, min, t); @@ -3684,7 +3684,7 @@ irValue *ir_emit_clamp(irProcedure *proc, Type *t, irValue *x, irValue *min, irV irValue *ir_find_global_variable(irProcedure *proc, String name) { irValue **value = map_get(&proc->module->members, hash_string(name)); - GB_ASSERT_MSG(value != NULL, "Unable to find global variable `%.*s`", LIT(name)); + GB_ASSERT_MSG(value != nullptr, "Unable to find global variable `%.*s`", LIT(name)); return *value; } @@ -3696,7 +3696,7 @@ bool is_double_pointer(Type *t) { return false; } Type *td = type_deref(t); - if (td == NULL || td == t) { + if (td == nullptr || td == t) { return false; } return is_type_pointer(td); @@ -3730,9 +3730,9 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv ident = ident->SelectorExpr.selector; } Entity *e = entity_of_ident(proc->module->info, ident); - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); - if (e->parent_proc_decl != NULL && e->parent_proc_decl->entity_count > 0) { + if (e->parent_proc_decl != nullptr && e->parent_proc_decl->entity_count > 0) { procedure = e->parent_proc_decl->entities[0]->token.string; } else { procedure = str_lit(""); @@ -3818,10 +3818,10 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv i32 variant_index = 0; if (is_type_struct(type)) { Type *st = base_type(type); - if (st->Record.variant_parent != NULL) { + if (st->Record.variant_parent != nullptr) { allocation_type = st->Record.variant_parent; variant_index = st->Record.variant_index; - GB_ASSERT(allocation_type != NULL); + GB_ASSERT(allocation_type != nullptr); } } Type *ptr_type = make_type_pointer(a, type); @@ -3971,11 +3971,11 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv args[1] = da_ptr; ir_emit_global_call(proc, "free_ptr_with_allocator", args, 2); } - return NULL; + return nullptr; } irValue *val = ir_build_expr(proc, node); - irValue *ptr = NULL; + irValue *ptr = nullptr; if (is_type_pointer(type)) { ptr = val; } else if (is_type_slice(type)) { @@ -3986,8 +3986,8 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv GB_PANIC("Invalid type to `free`"); } - if (ptr == NULL) { - return NULL; + if (ptr == nullptr) { + return nullptr; } ptr = ir_emit_conv(proc, ptr, t_rawptr); @@ -4057,7 +4057,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv } else { GB_PANIC("TODO(bill): ir clear for `%s`", type_to_string(t)); } - return NULL; + return nullptr; } break; #endif #if 0 @@ -4079,7 +4079,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv type_to_string(type)); } type = base_type(type_deref(type)); - Type *elem_type = NULL; + Type *elem_type = nullptr; bool is_slice = false; if (is_type_dynamic_array(type)) { elem_type = type->DynamicArray.elem; @@ -4248,7 +4248,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv case BuiltinProc_conj: { ir_emit_comment(proc, str_lit("conj")); irValue *val = ir_build_expr(proc, ce->args[0]); - irValue *res = NULL; + irValue *res = nullptr; Type *t = ir_type(val); if (is_type_complex(t)) { res = ir_add_local_generated(proc, tv.type); @@ -4368,7 +4368,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv } GB_PANIC("Unhandled built-in procedure"); - return NULL; + return nullptr; } @@ -4438,7 +4438,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { GB_PANIC("TODO(bill): ir_build_single_expr Entity_Builtin `%.*s`\n" "\t at %.*s(%td:%td)", LIT(builtin_procs[e->Builtin.id].name), LIT(token.pos.file), token.pos.line, token.pos.column); - return NULL; + return nullptr; } else if (e->kind == Entity_Nil) { return ir_value_nil(proc->module->allocator, tv.type); } @@ -4453,11 +4453,11 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { // return v; // } return ir_emit_load(proc, v); - } else if (e != NULL && e->kind == Entity_Variable) { + } else if (e != nullptr && e->kind == Entity_Variable) { return ir_addr_load(proc, ir_build_addr(proc, expr)); } - GB_PANIC("NULL value for expression from identifier: %.*s : %s @ %p", LIT(i->token.string), type_to_string(e->type), expr); - return NULL; + GB_PANIC("nullptr value for expression from identifier: %.*s : %s @ %p", LIT(i->token.string), type_to_string(e->type), expr); + return nullptr; case_end; case_ast_node(re, RunExpr, expr); @@ -4481,10 +4481,10 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { Array edges = {}; array_init(&edges, proc->module->allocator, 2); - GB_ASSERT(te->y != NULL); - irBlock *then = ir_new_block(proc, NULL, "if.then"); - irBlock *done = ir_new_block(proc, NULL, "if.done"); // NOTE(bill): Append later - irBlock *else_ = ir_new_block(proc, NULL, "if.else"); + GB_ASSERT(te->y != nullptr); + irBlock *then = ir_new_block(proc, nullptr, "if.then"); + irBlock *done = ir_new_block(proc, nullptr, "if.done"); // NOTE(bill): Append later + irBlock *else_ = ir_new_block(proc, nullptr, "if.else"); irValue *cond = ir_build_cond(proc, te->cond, then, else_); ir_start_block(proc, then); @@ -4493,14 +4493,14 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { ir_open_scope(proc); array_add(&edges, ir_emit_conv(proc, ir_build_expr(proc, te->x), type)); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_emit_jump(proc, done); ir_start_block(proc, else_); ir_open_scope(proc); array_add(&edges, ir_emit_conv(proc, ir_build_expr(proc, te->y), type)); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_emit_jump(proc, done); ir_start_block(proc, done); @@ -4511,7 +4511,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { #if 0 case_ast_node(ie, IfExpr, expr); ir_emit_comment(proc, str_lit("IfExpr")); - if (ie->init != NULL) { + if (ie->init != nullptr) { irBlock *init = ir_new_block(proc, expr, "if.init"); ir_emit_jump(proc, init); ir_start_block(proc, init); @@ -4521,7 +4521,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { Array edges = {}; array_init(&edges, proc->module->allocator, 2); - GB_ASSERT(ie->else_expr != NULL); + GB_ASSERT(ie->else_expr != nullptr); irBlock *then = ir_new_block(proc, expr, "if.then"); irBlock *done = ir_new_block(proc, expr, "if.done"); // NOTE(bill): Append later irBlock *else_ = ir_new_block(proc, ie->else_expr, "if.else"); @@ -4531,14 +4531,14 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { ir_open_scope(proc); array_add(&edges, ir_build_expr(proc, ie->body)); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_emit_jump(proc, done); ir_start_block(proc, else_); ir_open_scope(proc); array_add(&edges, ir_build_expr(proc, ie->else_expr)); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_emit_jump(proc, done); ir_start_block(proc, done); @@ -4627,7 +4627,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { Type *type = type_of_expr(proc->module->info, expr); irValue *value = ir_value_procedure(proc->module->allocator, - proc->module, NULL, type, pl->type, pl->body, name); + proc->module, nullptr, type, pl->type, pl->body, name); value->Proc.tags = pl->tags; value->Proc.parent = proc; @@ -4657,13 +4657,13 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { AstNode *p = unparen_expr(ce->proc); if (proc_mode == Addressing_Builtin) { Entity *e = entity_of_ident(proc->module->info, p); - BuiltinProcId id = cast(BuiltinProcId)(e != NULL ? e->Builtin.id : BuiltinProc_DIRECTIVE); + BuiltinProcId id = cast(BuiltinProcId)(e != nullptr ? e->Builtin.id : BuiltinProc_DIRECTIVE); return ir_build_builtin_proc(proc, expr, tv, id); } // NOTE(bill): Regular call irValue *value = ir_build_expr(proc, ce->proc); - GB_ASSERT(value != NULL); + GB_ASSERT(value != nullptr); Type *proc_type_ = base_type(ir_type(value)); GB_ASSERT(proc_type_->kind == Type_Proc); TypeProc *type = &proc_type_->Proc; @@ -4693,7 +4693,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { args[i] = ir_value_nil(proc->module->allocator, e->type); } else { GB_ASSERT(e->kind == Entity_Variable); - if (args[i] == NULL) { + if (args[i] == nullptr) { if (e->Variable.default_value.kind != ExactValue_Invalid) { args[i] = ir_value_constant(proc->module->allocator, e->type, e->Variable.default_value); } else { @@ -4751,7 +4751,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { if (arg_count < type->param_count) { String procedure = {}; - if (proc->entity != NULL) { + if (proc->entity != nullptr) { procedure = proc->entity->token.string; } TokenPos pos = ast_node_token(ce->proc).pos; @@ -4864,7 +4864,7 @@ irValue *ir_build_expr(irProcedure *proc, AstNode *expr) { } GB_PANIC("Unexpected expression: %.*s", LIT(ast_node_strings[expr->kind])); - return NULL; + return nullptr; } irValue *ir_get_using_variable(irProcedure *proc, Entity *e) { @@ -4872,16 +4872,16 @@ irValue *ir_get_using_variable(irProcedure *proc, Entity *e) { String name = e->token.string; Entity *parent = e->using_parent; Selection sel = lookup_field(proc->module->allocator, parent->type, name, false); - GB_ASSERT(sel.entity != NULL); + GB_ASSERT(sel.entity != nullptr); irValue **pv = map_get(&proc->module->values, hash_entity(parent)); - irValue *v = NULL; - if (pv != NULL) { + irValue *v = nullptr; + if (pv != nullptr) { v = *pv; } else { - GB_ASSERT_MSG(e->using_expr != NULL, "%.*s", LIT(name)); + GB_ASSERT_MSG(e->using_expr != nullptr, "%.*s", LIT(name)); v = ir_build_addr(proc, e->using_expr).addr; } - GB_ASSERT(v != NULL); + GB_ASSERT(v != nullptr); GB_ASSERT(parent->type == type_deref(ir_type(v))); return ir_emit_deep_field_gep(proc, v, sel); } @@ -4899,10 +4899,10 @@ bool ir_is_elem_const(irModule *m, AstNode *elem, Type *elem_type) { } irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, AstNode *expr) { - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); GB_ASSERT(e->kind != Entity_Constant); - irValue *v = NULL; + irValue *v = nullptr; irValue **found = map_get(&proc->module->values, hash_entity(e)); if (found) { v = *found; @@ -4911,7 +4911,7 @@ irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, AstNode *expr) { v = ir_get_using_variable(proc, e); } - if (v == NULL) { + if (v == nullptr) { error(expr, "%.*s Unknown value: %.*s, entity: %p %.*s", LIT(proc->name), LIT(e->token.string), e, LIT(entity_strings[e->kind])); @@ -4924,14 +4924,14 @@ irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, AstNode *expr) { irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { switch (expr->kind) { case_ast_node(i, Implicit, expr); - irValue *v = NULL; + irValue *v = nullptr; switch (i->kind) { case Token_context: v = ir_find_or_generate_context_ptr(proc); break; } - GB_ASSERT(v != NULL); + GB_ASSERT(v != nullptr); return ir_addr(v); case_end; @@ -4960,7 +4960,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { if (tav.mode == Addressing_Invalid) { // NOTE(bill): Imports Entity *imp = entity_of_ident(proc->module->info, se->expr); - if (imp != NULL) { + if (imp != nullptr) { GB_ASSERT(imp->kind == Entity_ImportName); } return ir_build_addr(proc, unparen_expr(se->selector)); @@ -4977,7 +4977,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { if (name == "names") { irValue *ti_ptr = ir_type_info(proc, type); - irValue *names_ptr = NULL; + irValue *names_ptr = nullptr; if (is_type_enum(type)) { irValue *enum_info = ir_emit_conv(proc, ti_ptr, t_type_info_enum_ptr); @@ -4994,7 +4994,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } Selection sel = lookup_field(proc->module->allocator, type, selector, false); - GB_ASSERT(sel.entity != NULL); + GB_ASSERT(sel.entity != nullptr); if (sel.entity->type->kind == Type_BitFieldValue) { irAddr addr = ir_build_addr(proc, se->expr); @@ -5024,7 +5024,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { i64 index = i128_to_i64(val.value_integer); Selection sel = lookup_field_from_index(proc->module->allocator, type, index); - GB_ASSERT(sel.entity != NULL); + GB_ASSERT(sel.entity != nullptr); irValue *a = ir_build_addr(proc, se->expr).addr; a = ir_emit_deep_field_gep(proc, a, sel); @@ -5084,11 +5084,11 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { return ir_addr_map(map_val, key, t, result_type); } - irValue *using_addr = NULL; + irValue *using_addr = nullptr; if (!is_type_indexable(t)) { // Using index expression Entity *using_field = find_using_index_expr(t); - if (using_field != NULL) { + if (using_field != nullptr) { Selection sel = lookup_field(a, t, using_field->token.string, false); irValue *e = ir_build_addr(proc, ie->expr).addr; using_addr = ir_emit_deep_field_gep(proc, e, sel); @@ -5100,8 +5100,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { switch (t->kind) { case Type_Vector: { - irValue *vector = NULL; - if (using_addr != NULL) { + irValue *vector = nullptr; + if (using_addr != nullptr) { vector = using_addr; } else { vector = ir_build_addr(proc, ie->expr).addr; @@ -5117,8 +5117,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } break; case Type_Array: { - irValue *array = NULL; - if (using_addr != NULL) { + irValue *array = nullptr; + if (using_addr != nullptr) { array = using_addr; } else { array = ir_build_addr(proc, ie->expr).addr; @@ -5134,8 +5134,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } break; case Type_Slice: { - irValue *slice = NULL; - if (using_addr != NULL) { + irValue *slice = nullptr; + if (using_addr != nullptr) { slice = ir_emit_load(proc, using_addr); } else { slice = ir_build_expr(proc, ie->expr); @@ -5152,8 +5152,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { } break; case Type_DynamicArray: { - irValue *dynamic_array = NULL; - if (using_addr != NULL) { + irValue *dynamic_array = nullptr; + if (using_addr != nullptr) { dynamic_array = ir_emit_load(proc, using_addr); } else { dynamic_array = ir_build_expr(proc, ie->expr); @@ -5176,7 +5176,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { irValue *len; irValue *index; - if (using_addr != NULL) { + if (using_addr != nullptr) { str = ir_emit_load(proc, using_addr); } else { str = ir_build_expr(proc, ie->expr); @@ -5199,18 +5199,18 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { ir_emit_comment(proc, str_lit("SliceExpr")); gbAllocator a = proc->module->allocator; irValue *low = v_zero; - irValue *high = NULL; - irValue *max = NULL; + irValue *high = nullptr; + irValue *max = nullptr; - if (se->low != NULL) low = ir_build_expr(proc, se->low); - if (se->high != NULL) high = ir_build_expr(proc, se->high); - if (se->max != NULL) max = ir_build_expr(proc, se->max); + if (se->low != nullptr) low = ir_build_expr(proc, se->low); + if (se->high != nullptr) high = ir_build_expr(proc, se->high); + if (se->max != nullptr) max = ir_build_expr(proc, se->max); - if (high != NULL && se->interval0.kind == Token_Ellipsis) { + if (high != nullptr && se->interval0.kind == Token_Ellipsis) { high = ir_emit_arith(proc, Token_Add, high, v_one, t_int); } - if (max != NULL && se->interval1.kind == Token_Ellipsis) { + if (max != nullptr && se->interval1.kind == Token_Ellipsis) { max = ir_emit_arith(proc, Token_Add, max, v_one, t_int); } @@ -5229,8 +5229,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case Type_Slice: { Type *slice_type = type; - if (high == NULL) high = ir_slice_count(proc, base); - if (max == NULL) max = ir_slice_capacity(proc, base); + if (high == nullptr) high = ir_slice_count(proc, base); + if (max == nullptr) max = ir_slice_capacity(proc, base); ir_emit_slice_bounds_check(proc, se->open, low, high, max, false); @@ -5247,8 +5247,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *elem_type = type->DynamicArray.elem; Type *slice_type = make_type_slice(a, elem_type); - if (high == NULL) high = ir_dynamic_array_count(proc, base); - if (max == NULL) max = ir_dynamic_array_capacity(proc, base); + if (high == nullptr) high = ir_dynamic_array_count(proc, base); + if (max == nullptr) max = ir_dynamic_array_capacity(proc, base); ir_emit_slice_bounds_check(proc, se->open, low, high, max, false); @@ -5265,8 +5265,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case Type_Array: { Type *slice_type = make_type_slice(a, type->Array.elem); - if (high == NULL) high = ir_array_len(proc, base); - if (max == NULL) max = ir_array_len(proc, base); + if (high == nullptr) high = ir_array_len(proc, base); + if (max == nullptr) max = ir_array_len(proc, base); ir_emit_slice_bounds_check(proc, se->open, low, high, max, false); @@ -5281,10 +5281,10 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { case Type_Basic: { GB_ASSERT(type == t_string); - if (high == NULL) high = ir_string_len(proc, base); - // if (max == NULL) max = ir_string_len(proc, base); + if (high == nullptr) high = ir_string_len(proc, base); + // if (max == nullptr) max = ir_string_len(proc, base); - ir_emit_slice_bounds_check(proc, se->open, low, high, NULL, true); + ir_emit_slice_bounds_check(proc, se->open, low, high, nullptr, true); irValue *elem = ir_emit_ptr_offset(proc, ir_string_elem(proc, base), low); irValue *len = ir_emit_arith(proc, Token_Sub, high, low, t_int); @@ -5319,7 +5319,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { Type *bt = base_type(type); irValue *v = ir_add_local_generated(proc, type); - Type *et = NULL; + Type *et = nullptr; switch (bt->kind) { case Type_Vector: et = bt->Vector.elem; break; case Type_Array: et = bt->Array.elem; break; @@ -5364,8 +5364,8 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { for_array(field_index, cl->elems) { AstNode *elem = cl->elems[field_index]; - irValue *field_expr = NULL; - Entity *field = NULL; + irValue *field_expr = nullptr; + Entity *field = nullptr; isize index = field_index; if (elem->kind == AstNode_FieldValue) { @@ -5520,7 +5520,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { for_array(field_index, cl->elems) { AstNode *elem = cl->elems[field_index]; - irValue *field_expr = NULL; + irValue *field_expr = nullptr; isize index = field_index; if (elem->kind == AstNode_FieldValue) { @@ -5559,7 +5559,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) { LIT(token_pos.file), token_pos.line, token_pos.column); - return ir_addr(NULL); + return ir_addr(nullptr); } void ir_build_assign_op(irProcedure *proc, irAddr lhs, irValue *value, TokenKind op) { @@ -5590,12 +5590,12 @@ irValue *ir_build_cond(irProcedure *proc, AstNode *cond, irBlock *true_block, ir case_ast_node(be, BinaryExpr, cond); if (be->op.kind == Token_CmpAnd) { - irBlock *block = ir_new_block(proc, NULL, "cmp.and"); + irBlock *block = ir_new_block(proc, nullptr, "cmp.and"); ir_build_cond(proc, be->left, block, false_block); ir_start_block(proc, block); return ir_build_cond(proc, be->right, true_block, false_block); } else if (be->op.kind == Token_CmpOr) { - irBlock *block = ir_new_block(proc, NULL, "cmp.or"); + irBlock *block = ir_new_block(proc, nullptr, "cmp.or"); ir_build_cond(proc, be->left, true_block, block); ir_start_block(proc, block); return ir_build_cond(proc, be->right, true_block, false_block); @@ -5610,7 +5610,7 @@ irValue *ir_build_cond(irProcedure *proc, AstNode *cond, irBlock *true_block, ir } void ir_build_poly_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { - GB_ASSERT(pd->body != NULL); + GB_ASSERT(pd->body != nullptr); if (is_entity_in_dependency_map(&proc->module->min_dep_map, e) == false) { // NOTE(bill): Nothing depends upon it so doesn't need to be built @@ -5646,7 +5646,7 @@ void ir_build_poly_proc(irProcedure *proc, AstNodeProcLit *pd, Entity *e) { void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { - if (vd == NULL || vd->is_mutable) { + if (vd == nullptr || vd->is_mutable) { return; } @@ -5654,7 +5654,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { AstNode *ident = vd->names[i]; GB_ASSERT(ident->kind == AstNode_Ident); Entity *e = entity_of_ident(proc->module->info, ident); - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); switch (e->kind) { case Entity_TypeName: case Entity_Procedure: @@ -5665,7 +5665,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { bool polymorphic = is_type_polymorphic(e->type); - if (!polymorphic && map_get(&proc->module->min_dep_map, hash_pointer(e)) == NULL) { + if (!polymorphic && map_get(&proc->module->min_dep_map, hash_pointer(e)) == nullptr) { // NOTE(bill): Nothing depends upon it so doesn't need to be built continue; } @@ -5688,7 +5688,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { CheckerInfo *info = proc->module->info; DeclInfo *decl = decl_info_of_entity(info, e); ast_node(pl, ProcLit, decl->proc_lit); - if (pl->body != NULL) { + if (pl->body != nullptr) { auto *found = map_get(&info->gen_procs, hash_pointer(ident)); if (found) { auto procs = *found; @@ -5720,7 +5720,7 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) { if (value->Proc.tags & ProcTag_foreign) { HashKey key = hash_string(name); irValue **prev_value = map_get(&proc->module->members, key); - if (prev_value == NULL) { + if (prev_value == nullptr) { // NOTE(bill): Don't do mutliple declarations in the IR map_set(&proc->module->members, key, value); } @@ -5807,7 +5807,7 @@ void ir_emit_increment(irProcedure *proc, irValue *addr) { void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, irValue *count_ptr, irValue **val_, irValue **idx_, irBlock **loop_, irBlock **done_) { - irValue *count = NULL; + irValue *count = nullptr; Type *expr_type = base_type(type_deref(ir_type(expr))); switch (expr_type->kind) { case Type_Array: @@ -5818,13 +5818,13 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir break; } - irValue *val = NULL; - irValue *idx = NULL; - irBlock *loop = NULL; - irBlock *done = NULL; - irBlock *body = NULL; + irValue *val = nullptr; + irValue *idx = nullptr; + irBlock *loop = nullptr; + irBlock *done = nullptr; + irBlock *body = nullptr; - irValue *key = NULL; + irValue *key = nullptr; if (expr_type->kind == Type_Map) { key = ir_add_local_generated(proc, expr_type->Map.key); } @@ -5832,16 +5832,16 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir irValue *index = ir_add_local_generated(proc, t_int); ir_emit_store(proc, index, ir_const_int(proc->module->allocator, -1)); - loop = ir_new_block(proc, NULL, "for.index.loop"); + loop = ir_new_block(proc, nullptr, "for.index.loop"); ir_emit_jump(proc, loop); ir_start_block(proc, loop); irValue *incr = ir_emit_arith(proc, Token_Add, ir_emit_load(proc, index), v_one, t_int); ir_emit_store(proc, index, incr); - body = ir_new_block(proc, NULL, "for.index.body"); - done = ir_new_block(proc, NULL, "for.index.done"); - if (count == NULL) { + body = ir_new_block(proc, nullptr, "for.index.body"); + done = ir_new_block(proc, nullptr, "for.index.done"); + if (count == nullptr) { count = ir_emit_load(proc, count_ptr); } irValue *cond = ir_emit_comp(proc, Token_Lt, incr, count); @@ -5849,7 +5849,7 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir ir_start_block(proc, body); idx = ir_emit_load(proc, index); - if (val_type != NULL) { + if (val_type != nullptr) { switch (expr_type->kind) { case Type_Array: { val = ir_emit_load(proc, ir_emit_array_ep(proc, expr, idx)); @@ -5892,7 +5892,7 @@ void ir_build_range_indexed(irProcedure *proc, irValue *expr, Type *val_type, ir } } - if (key != NULL) { + if (key != nullptr) { idx = ir_emit_load(proc, key); } @@ -5916,24 +5916,24 @@ void ir_build_range_string(irProcedure *proc, irValue *expr, Type *val_type, break; } - irValue *val = NULL; - irValue *idx = NULL; - irBlock *loop = NULL; - irBlock *done = NULL; - irBlock *body = NULL; + irValue *val = nullptr; + irValue *idx = nullptr; + irBlock *loop = nullptr; + irBlock *done = nullptr; + irBlock *body = nullptr; irValue *offset_ = ir_add_local_generated(proc, t_int); ir_emit_store(proc, offset_, v_zero); - loop = ir_new_block(proc, NULL, "for.string.loop"); + loop = ir_new_block(proc, nullptr, "for.string.loop"); ir_emit_jump(proc, loop); ir_start_block(proc, loop); - body = ir_new_block(proc, NULL, "for.string.body"); - done = ir_new_block(proc, NULL, "for.string.done"); + body = ir_new_block(proc, nullptr, "for.string.body"); + done = ir_new_block(proc, nullptr, "for.string.done"); irValue *offset = ir_emit_load(proc, offset_); irValue *cond = ir_emit_comp(proc, Token_Lt, offset, count); @@ -5951,7 +5951,7 @@ void ir_build_range_string(irProcedure *proc, irValue *expr, Type *val_type, idx = offset; - if (val_type != NULL) { + if (val_type != nullptr) { val = ir_emit_struct_ev(proc, rune_and_len, 0); } @@ -5967,15 +5967,15 @@ void ir_build_range_interval(irProcedure *proc, AstNodeBinaryExpr *node, Type *v // If `lower` is changed, should `val` do so or is that not typical behaviour? irValue *lower = ir_build_expr(proc, node->left); - irValue *upper = NULL; + irValue *upper = nullptr; - irValue *val = NULL; - irValue *idx = NULL; - irBlock *loop = NULL; - irBlock *done = NULL; - irBlock *body = NULL; + irValue *val = nullptr; + irValue *idx = nullptr; + irBlock *loop = nullptr; + irBlock *done = nullptr; + irBlock *body = nullptr; - if (val_type == NULL) { + if (val_type == nullptr) { val_type = ir_type(lower); } irValue *value = ir_add_local_generated(proc, val_type); @@ -5984,12 +5984,12 @@ void ir_build_range_interval(irProcedure *proc, AstNodeBinaryExpr *node, Type *v irValue *index = ir_add_local_generated(proc, t_int); ir_emit_store(proc, index, ir_const_int(proc->module->allocator, 0)); - loop = ir_new_block(proc, NULL, "for.interval.loop"); + loop = ir_new_block(proc, nullptr, "for.interval.loop"); ir_emit_jump(proc, loop); ir_start_block(proc, loop); - body = ir_new_block(proc, NULL, "for.interval.body"); - done = ir_new_block(proc, NULL, "for.interval.done"); + body = ir_new_block(proc, nullptr, "for.interval.body"); + done = ir_new_block(proc, nullptr, "for.interval.done"); TokenKind op = Token_Lt; @@ -6005,7 +6005,7 @@ void ir_build_range_interval(irProcedure *proc, AstNodeBinaryExpr *node, Type *v ir_emit_if(proc, cond, body, done); ir_start_block(proc, body); - if (value != NULL) { + if (value != nullptr) { val = ir_emit_load(proc, value); } idx = ir_emit_load(proc, index); @@ -6021,15 +6021,15 @@ void ir_build_range_interval(irProcedure *proc, AstNodeBinaryExpr *node, Type *v void ir_store_type_case_implicit(irProcedure *proc, AstNode *clause, irValue *value) { Entity *e = implicit_entity_of_node(proc->module->info, clause); - GB_ASSERT(e != NULL); - irValue *x = ir_add_local(proc, e, NULL, false); + GB_ASSERT(e != nullptr); + irValue *x = ir_add_local(proc, e, nullptr, false); ir_emit_store(proc, x, value); } void ir_type_case_body(irProcedure *proc, AstNode *label, AstNode *clause, irBlock *body, irBlock *done) { ast_node(cc, CaseClause, clause); - ir_push_target_list(proc, label, done, NULL, NULL); + ir_push_target_list(proc, label, done, nullptr, nullptr); ir_open_scope(proc); ir_build_stmt_list(proc, cc->stmts); ir_close_scope(proc, irDeferExit_Default, body); @@ -6090,7 +6090,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { for_array(i, vd->names) { AstNode *name = vd->names[i]; - irAddr lval = ir_addr(NULL); + irAddr lval = ir_addr(nullptr); if (!ir_is_blank_ident(name)) { ir_add_local_for_identifier(proc, name, false); lval = ir_build_addr(proc, name); @@ -6207,7 +6207,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(bs, BlockStmt, node); ir_open_scope(proc); ir_build_stmt_list(proc, bs->stmts); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); case_end; case_ast_node(ds, DeferStmt, node); @@ -6221,7 +6221,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(rs, ReturnStmt, node); ir_emit_comment(proc, str_lit("ReturnStmt")); - irValue *v = NULL; + irValue *v = nullptr; TypeTuple *tuple = &proc->type->Proc.results->Tuple; isize return_count = proc->type->Proc.result_count; isize res_count = rs->results.count; @@ -6247,7 +6247,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { for (isize i = 0; i < return_count; i++) { Entity *e = tuple->variables[i]; GB_ASSERT(e->kind == Entity_Variable); - if (results[i] == NULL) { + if (results[i] == nullptr) { if (e->Variable.default_value.kind != ExactValue_Invalid) { results[i] = ir_value_constant(proc->module->allocator, e->type, e->Variable.default_value); } else { @@ -6313,7 +6313,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { } while (total_index < return_count) { Entity *e = tuple->variables[total_index]; - irValue *res = NULL; + irValue *res = nullptr; if (e->Variable.default_value.kind != ExactValue_Invalid) { res = ir_value_constant(proc->module->allocator, e->type, e->Variable.default_value); } else { @@ -6344,7 +6344,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(is, IfStmt, node); ir_emit_comment(proc, str_lit("IfStmt")); - if (is->init != NULL) { + if (is->init != nullptr) { irBlock *init = ir_new_block(proc, node, "if.init"); ir_emit_jump(proc, init); ir_start_block(proc, init); @@ -6353,7 +6353,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irBlock *then = ir_new_block(proc, node, "if.then"); irBlock *done = ir_new_block(proc, node, "if.done"); irBlock *else_ = done; - if (is->else_stmt != NULL) { + if (is->else_stmt != nullptr) { else_ = ir_new_block(proc, is->else_stmt, "if.else"); } @@ -6362,16 +6362,16 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_open_scope(proc); ir_build_stmt(proc, is->body); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_emit_jump(proc, done); - if (is->else_stmt != NULL) { + if (is->else_stmt != nullptr) { ir_start_block(proc, else_); ir_open_scope(proc); ir_build_stmt(proc, is->else_stmt); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_emit_jump(proc, done); } @@ -6382,7 +6382,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(fs, ForStmt, node); ir_emit_comment(proc, str_lit("ForStmt")); - if (fs->init != NULL) { + if (fs->init != nullptr) { irBlock *init = ir_new_block(proc, node, "for.init"); ir_emit_jump(proc, init); ir_start_block(proc, init); @@ -6391,11 +6391,11 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irBlock *body = ir_new_block(proc, node, "for.body"); irBlock *done = ir_new_block(proc, node, "for.done"); // NOTE(bill): Append later irBlock *loop = body; - if (fs->cond != NULL) { + if (fs->cond != nullptr) { loop = ir_new_block(proc, node, "for.loop"); } irBlock *post = loop; - if (fs->post != NULL) { + if (fs->post != nullptr) { post = ir_new_block(proc, node, "for.post"); } @@ -6408,17 +6408,17 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_start_block(proc, body); } - ir_push_target_list(proc, fs->label, done, post, NULL); + ir_push_target_list(proc, fs->label, done, post, nullptr); ir_open_scope(proc); ir_build_stmt(proc, fs->body); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_pop_target_list(proc); ir_emit_jump(proc, post); - if (fs->post != NULL) { + if (fs->post != nullptr) { ir_start_block(proc, post); ir_build_stmt(proc, fs->post); ir_emit_jump(proc, loop); @@ -6431,26 +6431,26 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(rs, RangeStmt, node); ir_emit_comment(proc, str_lit("RangeStmt")); - Type *val_type = NULL; - Type *idx_type = NULL; - if (rs->value != NULL && !ir_is_blank_ident(rs->value)) { + Type *val_type = nullptr; + Type *idx_type = nullptr; + if (rs->value != nullptr && !ir_is_blank_ident(rs->value)) { val_type = type_of_expr(proc->module->info, rs->value); } - if (rs->index != NULL && !ir_is_blank_ident(rs->index)) { + if (rs->index != nullptr && !ir_is_blank_ident(rs->index)) { idx_type = type_of_expr(proc->module->info, rs->index); } - if (val_type != NULL) { + if (val_type != nullptr) { ir_add_local_for_identifier(proc, rs->value, true); } - if (idx_type != NULL) { + if (idx_type != nullptr) { ir_add_local_for_identifier(proc, rs->index, true); } - irValue *val = NULL; - irValue *index = NULL; - irBlock *loop = NULL; - irBlock *done = NULL; + irValue *val = nullptr; + irValue *index = nullptr; + irBlock *loop = nullptr; + irBlock *done = nullptr; AstNode *expr = unparen_expr(rs->expr); TypeAndValue tav = type_and_value_of_expr(proc->module->info, expr); @@ -6476,12 +6476,12 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irValue *offset_ = ir_add_local_generated(proc, t_int); ir_emit_store(proc, offset_, v_zero); - loop = ir_new_block(proc, NULL, "for.enum.loop"); + loop = ir_new_block(proc, nullptr, "for.enum.loop"); ir_emit_jump(proc, loop); ir_start_block(proc, loop); - irBlock *body = ir_new_block(proc, NULL, "for.enum.body"); - done = ir_new_block(proc, NULL, "for.enum.done"); + irBlock *body = ir_new_block(proc, nullptr, "for.enum.body"); + done = ir_new_block(proc, nullptr, "for.enum.done"); irValue *offset = ir_emit_load(proc, offset_); irValue *cond = ir_emit_comp(proc, Token_Lt, offset, max_count); @@ -6493,7 +6493,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_emit_increment(proc, offset_); index = offset; - if (val_type != NULL) { + if (val_type != nullptr) { if (is_type_float(core_elem)) { irValue *f = ir_emit_load(proc, ir_emit_conv(proc, val_ptr, t_f64_ptr)); val = ir_emit_conv(proc, f, t); @@ -6519,7 +6519,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_build_range_indexed(proc, map, val_type, count_ptr, &val, &index, &loop, &done); } break; case Type_Array: { - irValue *count_ptr = NULL; + irValue *count_ptr = nullptr; irValue *array = ir_build_addr(proc, rs->expr).addr; if (is_type_pointer(type_deref(ir_type(array)))) { array = ir_emit_load(proc, array); @@ -6529,7 +6529,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_build_range_indexed(proc, array, val_type, count_ptr, &val, &index, &loop, &done); } break; case Type_Vector: { - irValue *count_ptr = NULL; + irValue *count_ptr = nullptr; irValue *vector = ir_build_addr(proc, rs->expr).addr; if (is_type_pointer(type_deref(ir_type(vector)))) { vector = ir_emit_load(proc, vector); @@ -6539,7 +6539,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_build_range_indexed(proc, vector, val_type, count_ptr, &val, &index, &loop, &done); } break; case Type_DynamicArray: { - irValue *count_ptr = NULL; + irValue *count_ptr = nullptr; irValue *array = ir_build_addr(proc, rs->expr).addr; if (is_type_pointer(type_deref(ir_type(array)))) { array = ir_emit_load(proc, array); @@ -6548,7 +6548,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_build_range_indexed(proc, array, val_type, count_ptr, &val, &index, &loop, &done); } break; case Type_Slice: { - irValue *count_ptr = NULL; + irValue *count_ptr = nullptr; irValue *slice = ir_build_expr(proc, rs->expr); if (is_type_pointer(ir_type(slice))) { count_ptr = ir_emit_struct_ep(proc, slice, 1); @@ -6579,24 +6579,24 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { irAddr val_addr = {}; irAddr idx_addr = {}; - if (val_type != NULL) { + if (val_type != nullptr) { val_addr = ir_build_addr(proc, rs->value); } - if (idx_type != NULL) { + if (idx_type != nullptr) { idx_addr = ir_build_addr(proc, rs->index); } - if (val_type != NULL) { + if (val_type != nullptr) { ir_addr_store(proc, val_addr, val); } - if (idx_type != NULL) { + if (idx_type != nullptr) { ir_addr_store(proc, idx_addr, index); } - ir_push_target_list(proc, rs->label, done, loop, NULL); + ir_push_target_list(proc, rs->label, done, loop, nullptr); ir_open_scope(proc); ir_build_stmt(proc, rs->body); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); ir_pop_target_list(proc); ir_emit_jump(proc, loop); @@ -6605,11 +6605,11 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_ast_node(ms, MatchStmt, node); ir_emit_comment(proc, str_lit("MatchStmt")); - if (ms->init != NULL) { + if (ms->init != nullptr) { ir_build_stmt(proc, ms->init); } irValue *tag = v_true; - if (ms->tag != NULL) { + if (ms->tag != nullptr) { tag = ir_build_expr(proc, ms->tag); } irBlock *done = ir_new_block(proc, node, "match.done"); // NOTE(bill): Append later @@ -6617,10 +6617,10 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ast_node(body, BlockStmt, ms->body); Array default_stmts = {}; - irBlock *default_fall = NULL; - irBlock *default_block = NULL; + irBlock *default_fall = nullptr; + irBlock *default_block = nullptr; - irBlock *fall = NULL; + irBlock *fall = nullptr; bool append_fall = false; isize case_count = body->stmts.count; @@ -6630,7 +6630,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ast_node(cc, CaseClause, clause); - if (body == NULL) { + if (body == nullptr) { if (cc->list.count == 0) { body = ir_new_block(proc, clause, "match.dflt.body"); } else { @@ -6655,7 +6655,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { continue; } - irBlock *next_cond = NULL; + irBlock *next_cond = nullptr; for_array(j, cc->list) { AstNode *expr = unparen_expr(cc->list[j]); next_cond = ir_new_block(proc, clause, "match.case.next"); @@ -6682,7 +6682,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { } ir_start_block(proc, body); - ir_push_target_list(proc, ms->label, done, NULL, fall); + ir_push_target_list(proc, ms->label, done, nullptr, fall); ir_open_scope(proc); ir_build_stmt_list(proc, cc->stmts); ir_close_scope(proc, irDeferExit_Default, body); @@ -6693,11 +6693,11 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { // ir_start_block(proc, next_cond); } - if (default_block != NULL) { + if (default_block != nullptr) { ir_emit_jump(proc, default_block); ir_start_block(proc, default_block); - ir_push_target_list(proc, ms->label, done, NULL, default_fall); + ir_push_target_list(proc, ms->label, done, nullptr, default_fall); ir_open_scope(proc); ir_build_stmt_list(proc, default_stmts); ir_close_scope(proc, irDeferExit_Default, default_block); @@ -6731,8 +6731,8 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { parent_ptr = ir_address_from_load_or_generate_local(proc, parent_ptr); } - irValue *tag_index = NULL; - irValue *union_data = NULL; + irValue *tag_index = nullptr; + irValue *union_data = nullptr; if (match_type_kind == MatchType_Union) { ir_emit_comment(proc, str_lit("get union's tag")); tag_index = ir_emit_load(proc, ir_emit_union_tag_ptr(proc, parent_ptr)); @@ -6745,7 +6745,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { // NOTE(bill): Append this later irBlock *done = ir_new_block(proc, node, "typematch.done"); - AstNode *default_ = NULL; + AstNode *default_ = nullptr; ast_node(body, BlockStmt, ms->body); @@ -6760,15 +6760,15 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { } irBlock *body = ir_new_block(proc, clause, "typematch.body"); - irBlock *next = NULL; - Type *case_type = NULL; + irBlock *next = nullptr; + Type *case_type = nullptr; for_array(type_index, cc->list) { - next = ir_new_block(proc, NULL, "typematch.next"); + next = ir_new_block(proc, nullptr, "typematch.next"); case_type = type_of_expr(proc->module->info, cc->list[type_index]); - irValue *cond = NULL; + irValue *cond = nullptr; if (match_type_kind == MatchType_Union) { Type *bt = type_deref(case_type); - irValue *index = NULL; + irValue *index = nullptr; Type *ut = base_type(type_deref(parent_type)); GB_ASSERT(ut->Record.kind == TypeRecord_Union); for (isize variant_index = 1; variant_index < ut->Record.variant_count; variant_index++) { @@ -6778,14 +6778,14 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { break; } } - GB_ASSERT(index != NULL); + GB_ASSERT(index != nullptr); cond = ir_emit_comp(proc, Token_CmpEq, tag_index, index); } else if (match_type_kind == MatchType_Any) { irValue *any_ti = ir_emit_load(proc, ir_emit_struct_ep(proc, parent_ptr, 1)); irValue *case_ti = ir_type_info(proc, case_type); cond = ir_emit_comp(proc, Token_CmpEq, any_ti, case_ti); } - GB_ASSERT(cond != NULL); + GB_ASSERT(cond != nullptr); ir_emit_if(proc, cond, body, next); ir_start_block(proc, next); @@ -6805,7 +6805,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ct = make_type_pointer(proc->module->allocator, ct); } GB_ASSERT_MSG(is_type_pointer(ct), "%s", type_to_string(ct)); - irValue *data = NULL; + irValue *data = nullptr; if (match_type_kind == MatchType_Union) { data = union_data; } else if (match_type_kind == MatchType_Any) { @@ -6823,7 +6823,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_start_block(proc, next); } - if (default_ != NULL) { + if (default_ != nullptr) { ir_store_type_case_implicit(proc, default_, parent_value); ir_type_case_body(proc, ms->label, default_, proc->curr_block, done); } else { @@ -6833,9 +6833,9 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_end; case_ast_node(bs, BranchStmt, node); - irBlock *block = NULL; + irBlock *block = nullptr; - if (bs->label != NULL) { + if (bs->label != nullptr) { irBranchBlocks bb = ir_lookup_branch_blocks(proc, bs->label); switch (bs->token.kind) { case Token_break: block = bb.break_; break; @@ -6847,23 +6847,23 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { } else { switch (bs->token.kind) { case Token_break: - for (irTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) { + for (irTargetList *t = proc->target_list; t != nullptr && block == nullptr; t = t->prev) { block = t->break_; } break; case Token_continue: - for (irTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) { + for (irTargetList *t = proc->target_list; t != nullptr && block == nullptr; t = t->prev) { block = t->continue_; } break; case Token_fallthrough: - for (irTargetList *t = proc->target_list; t != NULL && block == NULL; t = t->prev) { + for (irTargetList *t = proc->target_list; t != nullptr && block == nullptr; t = t->prev) { block = t->fallthrough_; } break; } } - if (block != NULL) { + if (block != nullptr) { ir_emit_defer_stmts(proc, irDeferExit_Branch, block); } switch (bs->token.kind) { @@ -6892,7 +6892,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_build_stmt(proc, pa->body); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); case_end; @@ -6909,7 +6909,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { ir_build_stmt(proc, pc->body); - ir_close_scope(proc, irDeferExit_Default, NULL); + ir_close_scope(proc, irDeferExit_Default, nullptr); case_end; @@ -6937,7 +6937,7 @@ void ir_number_proc_registers(irProcedure *proc) { irValue *value = b->instrs[j]; GB_ASSERT_MSG(value->kind == irValue_Instr, "%.*s", LIT(proc->name)); irInstr *instr = &value->Instr; - if (ir_instr_type(instr) == NULL) { // NOTE(bill): Ignore non-returning instructions + if (ir_instr_type(instr) == nullptr) { // NOTE(bill): Ignore non-returning instructions value->index = -1; continue; } @@ -6959,10 +6959,10 @@ void ir_begin_procedure_body(irProcedure *proc) { array_init(&proc->context_stack, heap_allocator()); DeclInfo *decl = decl_info_of_entity(proc->module->info, proc->entity); - if (decl != NULL) { + if (decl != nullptr) { for_array(i, decl->labels) { BlockLabel bl = decl->labels[i]; - irBranchBlocks bb = {bl.label, NULL, NULL}; + irBranchBlocks bb = {bl.label, nullptr, nullptr}; array_add(&proc->branch_blocks, bb); } } @@ -6975,7 +6975,7 @@ void ir_begin_procedure_body(irProcedure *proc) { if (proc->type->Proc.return_by_pointer) { // NOTE(bill): this must be the first parameter stored Type *ptr_type = make_type_pointer(a, reduce_tuple_to_single_type(proc->type->Proc.results)); - Entity *e = make_entity_param(a, NULL, make_token_ident(str_lit("agg.result")), ptr_type, false, false); + Entity *e = make_entity_param(a, nullptr, make_token_ident(str_lit("agg.result")), ptr_type, false, false); e->flags |= EntityFlag_Sret | EntityFlag_NoAlias; irValue *param = ir_value_param(a, proc, e, ptr_type); @@ -6985,7 +6985,7 @@ void ir_begin_procedure_body(irProcedure *proc) { proc->return_ptr = param; } - if (proc->type->Proc.params != NULL) { + if (proc->type->Proc.params != nullptr) { ast_node(pt, ProcType, proc->type_expr); isize param_index = 0; isize q_index = 0; @@ -7018,7 +7018,7 @@ void ir_begin_procedure_body(irProcedure *proc) { if (proc->type->Proc.calling_convention == ProcCC_Odin) { - Entity *e = make_entity_param(a, NULL, make_token_ident(str_lit("__.context_ptr")), t_context_ptr, false, false); + Entity *e = make_entity_param(a, nullptr, make_token_ident(str_lit("__.context_ptr")), t_context_ptr, false, false); e->flags |= EntityFlag_NoAlias; irValue *param = ir_value_param(a, proc, e, e->type); ir_module_add_value(proc->module, e, param); @@ -7029,7 +7029,7 @@ void ir_begin_procedure_body(irProcedure *proc) { void ir_end_procedure_body(irProcedure *proc) { if (proc->type->Proc.result_count == 0) { - ir_emit_return(proc, NULL); + ir_emit_return(proc, nullptr); } if (proc->curr_block->instrs.count == 0) { @@ -7038,14 +7038,14 @@ void ir_end_procedure_body(irProcedure *proc) { proc->curr_block = proc->decl_block; ir_emit_jump(proc, proc->entry_block); - proc->curr_block = NULL; + proc->curr_block = nullptr; ir_number_proc_registers(proc); } void ir_insert_code_before_proc(irProcedure* proc, irProcedure *parent) { - if (parent == NULL) { + if (parent == nullptr) { if (proc->name == "main") { ir_emit_startup_runtime(proc); } @@ -7057,13 +7057,13 @@ void ir_build_proc(irValue *value, irProcedure *parent) { proc->parent = parent; - if (proc->entity != NULL) { + if (proc->entity != nullptr) { irModule *m = proc->module; CheckerInfo *info = m->info; Entity *e = proc->entity; String filename = e->token.pos.file; AstFile *f = ast_file_of_filename(info, filename); - irDebugInfo *di_file = NULL; + irDebugInfo *di_file = nullptr; irDebugInfo **di_file_found = map_get(&m->debug_info, hash_ast_file(f)); if (di_file_found) { @@ -7076,7 +7076,7 @@ void ir_build_proc(irValue *value, irProcedure *parent) { ir_add_debug_info_proc(proc, e, proc->name, di_file); } - if (proc->body != NULL) { + if (proc->body != nullptr) { u32 prev_stmt_state_flags = proc->module->stmt_state_flags; if (proc->tags != 0) { @@ -7159,8 +7159,8 @@ void ir_init_module(irModule *m, Checker *c) { isize max_type_info_count = max_index+1; String name = str_lit(IR_TYPE_INFO_DATA_NAME); - Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), make_type_array(m->allocator, t_type_info, max_type_info_count), false); - irValue *g = ir_value_global(m->allocator, e, NULL); + Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), make_type_array(m->allocator, t_type_info, max_type_info_count), false); + irValue *g = ir_value_global(m->allocator, e, nullptr); g->Global.is_private = true; ir_module_add_value(m, e, g); map_set(&m->members, hash_string(name), g); @@ -7197,27 +7197,27 @@ void ir_init_module(irModule *m, Checker *c) { { String name = str_lit(IR_TYPE_INFO_TYPES_NAME); - Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), + Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), make_type_array(m->allocator, t_type_info_ptr, count), false); - irValue *g = ir_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, nullptr); ir_module_add_value(m, e, g); map_set(&m->members, hash_string(name), g); ir_global_type_info_member_types = g; } { String name = str_lit(IR_TYPE_INFO_NAMES_NAME); - Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), + Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), make_type_array(m->allocator, t_string, count), false); - irValue *g = ir_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, nullptr); ir_module_add_value(m, e, g); map_set(&m->members, hash_string(name), g); ir_global_type_info_member_names = g; } { String name = str_lit(IR_TYPE_INFO_OFFSETS_NAME); - Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), + Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), make_type_array(m->allocator, t_int, count), false); - irValue *g = ir_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, nullptr); ir_module_add_value(m, e, g); map_set(&m->members, hash_string(name), g); ir_global_type_info_member_offsets = g; @@ -7225,9 +7225,9 @@ void ir_init_module(irModule *m, Checker *c) { { String name = str_lit(IR_TYPE_INFO_USINGS_NAME); - Entity *e = make_entity_variable(m->allocator, NULL, make_token_ident(name), + Entity *e = make_entity_variable(m->allocator, nullptr, make_token_ident(name), make_type_array(m->allocator, t_bool, count), false); - irValue *g = ir_value_global(m->allocator, e, NULL); + irValue *g = ir_value_global(m->allocator, e, nullptr); ir_module_add_value(m, e, g); map_set(&m->members, hash_string(name), g); ir_global_type_info_member_usings = g; @@ -7335,7 +7335,7 @@ irValue *ir_type_info_member_usings_offset(irProcedure *proc, isize count) { void ir_add_foreign_library_path(irModule *m, Entity *e) { - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); String library_path = e->LibraryName.path; if (library_path.len == 0) { return; @@ -7360,7 +7360,7 @@ void ir_gen_tree(irGen *s) { CheckerInfo *info = m->info; gbAllocator a = m->allocator; - if (v_zero == NULL) { + if (v_zero == nullptr) { v_zero = ir_const_int (m->allocator, 0); v_one = ir_const_int (m->allocator, 1); v_zero32 = ir_const_i32 (m->allocator, 0); @@ -7372,7 +7372,7 @@ void ir_gen_tree(irGen *s) { } isize global_variable_max_count = 0; - Entity *entry_point = NULL; + Entity *entry_point = nullptr; bool has_dll_main = false; bool has_win_main = false; @@ -7399,7 +7399,7 @@ void ir_gen_tree(irGen *s) { } { // Add global default context - m->global_default_context = ir_add_global_generated(m, t_context, NULL); + m->global_default_context = ir_add_global_generated(m, t_context, nullptr); } struct irGlobalVariable { irValue *var, *init; @@ -7422,7 +7422,7 @@ void ir_gen_tree(irGen *s) { continue; } - if (map_get(&m->min_dep_map, hash_entity(e)) == NULL) { + if (map_get(&m->min_dep_map, hash_entity(e)) == nullptr) { // NOTE(bill): Nothing depends upon it so doesn't need to be built continue; } @@ -7450,7 +7450,7 @@ void ir_gen_tree(irGen *s) { break; case Entity_Variable: { - irValue *g = ir_value_global(a, e, NULL); + irValue *g = ir_value_global(a, e, nullptr); g->Global.name = name; g->Global.is_thread_local = e->Variable.is_thread_local; @@ -7458,7 +7458,7 @@ void ir_gen_tree(irGen *s) { var.var = g; var.decl = decl; - if (decl->init_expr != NULL) { + if (decl->init_expr != nullptr) { if (is_type_any(e->type)) { } else { @@ -7474,7 +7474,7 @@ void ir_gen_tree(irGen *s) { } } - if (g->Global.value == NULL) { + if (g->Global.value == nullptr) { array_add(&global_variables, var); } @@ -7502,7 +7502,7 @@ void ir_gen_tree(irGen *s) { ir_module_add_value(m, e, p); HashKey hash_name = hash_string(name); - if (map_get(&m->members, hash_name) == NULL) { + if (map_get(&m->members, hash_name) == nullptr) { multi_map_insert(&m->members, hash_name, p); } } break; @@ -7513,7 +7513,7 @@ void ir_gen_tree(irGen *s) { auto *entry = &m->members.entries[i]; irValue *v = entry->value; if (v->kind == irValue_Proc) { - ir_build_proc(v, NULL); + ir_build_proc(v, nullptr); } } @@ -7571,8 +7571,8 @@ void ir_gen_tree(irGen *s) { proc_results, 1, false, ProcCC_Std); AstNode *body = gb_alloc_item(a, AstNode); - Entity *e = make_entity_procedure(a, NULL, make_token_ident(name), proc_type, 0); - irValue *p = ir_value_procedure(a, m, e, proc_type, NULL, body, name); + Entity *e = make_entity_procedure(a, nullptr, make_token_ident(name), proc_type, 0); + irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); map_set(&m->values, hash_pointer(e), p); map_set(&m->members, hash_string(name), p); @@ -7586,18 +7586,18 @@ void ir_gen_tree(irGen *s) { // NOTE(bill): https://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx // DLL_PROCESS_ATTACH == 1 - irAddr reason_addr = ir_build_addr_from_entity(proc, proc_params->Tuple.variables[1], NULL); + irAddr reason_addr = ir_build_addr_from_entity(proc, proc_params->Tuple.variables[1], nullptr); irValue *cond = ir_emit_comp(proc, Token_CmpEq, ir_addr_load(proc, reason_addr), v_one32); - irBlock *then = ir_new_block(proc, NULL, "if.then"); - irBlock *done = ir_new_block(proc, NULL, "if.done"); // NOTE(bill): Append later + irBlock *then = ir_new_block(proc, nullptr, "if.then"); + irBlock *done = ir_new_block(proc, nullptr, "if.done"); // NOTE(bill): Append later ir_emit_if(proc, cond, then, done); ir_start_block(proc, then); { String main_name = str_lit("main"); irValue **found = map_get(&m->members, hash_string(main_name)); - if (found != NULL) { - ir_emit_call(proc, *found, NULL, 0); + if (found != nullptr) { + ir_emit_call(proc, *found, nullptr, 0); } else { ir_emit(proc, ir_alloc_instr(proc, irInstr_StartupRuntime)); } @@ -7640,8 +7640,8 @@ void ir_gen_tree(irGen *s) { proc_results, 1, false, ProcCC_Std); AstNode *body = gb_alloc_item(a, AstNode); - Entity *e = make_entity_procedure(a, NULL, make_token_ident(name), proc_type, 0); - irValue *p = ir_value_procedure(a, m, e, proc_type, NULL, body, name); + Entity *e = make_entity_procedure(a, nullptr, make_token_ident(name), proc_type, 0); + irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); m->entry_point_entity = e; @@ -7653,7 +7653,7 @@ void ir_gen_tree(irGen *s) { e->Procedure.link_name = name; ir_begin_procedure_body(proc); - ir_emit_global_call(proc, "main", NULL, 0); + ir_emit_global_call(proc, "main", nullptr, 0); ir_emit_return(proc, v_one32); ir_end_procedure_body(proc); } @@ -7662,12 +7662,12 @@ void ir_gen_tree(irGen *s) { // Cleanup(bill): probably better way of doing code insertion String name = str_lit(IR_STARTUP_RUNTIME_PROC_NAME); Type *proc_type = make_type_proc(a, gb_alloc_item(a, Scope), - NULL, 0, - NULL, 0, false, + nullptr, 0, + nullptr, 0, false, ProcCC_Contextless); AstNode *body = gb_alloc_item(a, AstNode); - Entity *e = make_entity_procedure(a, NULL, make_token_ident(name), proc_type, 0); - irValue *p = ir_value_procedure(a, m, e, proc_type, NULL, body, name); + Entity *e = make_entity_procedure(a, nullptr, make_token_ident(name), proc_type, 0); + irValue *p = ir_value_procedure(a, m, e, proc_type, nullptr, body, name); map_set(&m->values, hash_pointer(e), p); map_set(&m->members, hash_string(name), p); @@ -7687,7 +7687,7 @@ void ir_gen_tree(irGen *s) { // TODO(bill): Should do a dependency graph do check which order to initialize them in? for_array(i, global_variables) { irGlobalVariable *var = &global_variables[i]; - if (var->decl->init_expr != NULL) { + if (var->decl->init_expr != nullptr) { var->init = ir_build_expr(proc, var->decl->init_expr); } } @@ -7695,7 +7695,7 @@ void ir_gen_tree(irGen *s) { // NOTE(bill): Initialize constants first for_array(i, global_variables) { irGlobalVariable *var = &global_variables[i]; - if (var->init != NULL && var->init->kind == irValue_Constant) { + if (var->init != nullptr && var->init->kind == irValue_Constant) { Type *t = type_deref(ir_type(var->var)); if (is_type_any(t)) { // NOTE(bill): Edge case for `any` type @@ -7713,7 +7713,7 @@ void ir_gen_tree(irGen *s) { for_array(i, global_variables) { irGlobalVariable *var = &global_variables[i]; - if (var->init != NULL && var->init->kind != irValue_Constant) { + if (var->init != nullptr && var->init->kind != irValue_Constant) { Type *t = type_deref(ir_type(var->var)); if (is_type_any(t)) { // NOTE(bill): Edge case for `any` type @@ -7763,7 +7763,7 @@ void ir_gen_tree(irGen *s) { isize entry_index = type_info_index(info, t); - irValue *tag = NULL; + irValue *tag = nullptr; irValue *ti_ptr = ir_emit_array_epi(proc, ir_global_type_info_data, entry_index); ir_emit_store(proc, ir_emit_struct_ep(proc, ti_ptr, 0), ir_const_int(a, type_size_of(a, t))); @@ -7903,10 +7903,10 @@ void ir_gen_tree(irGen *s) { irValue *variadic = ir_emit_struct_ep(proc, tag, 4); irValue *convention = ir_emit_struct_ep(proc, tag, 5); - if (t->Proc.params != NULL) { + if (t->Proc.params != nullptr) { ir_emit_store(proc, params, ir_get_type_info_ptr(proc, t->Proc.params)); } - if (t->Proc.results != NULL) { + if (t->Proc.results != nullptr) { ir_emit_store(proc, results, ir_get_type_info_ptr(proc, t->Proc.results)); } ir_emit_store(proc, variadic, ir_const_bool(a, t->Proc.variadic)); @@ -8088,7 +8088,7 @@ void ir_gen_tree(irGen *s) { ir_emit_comment(proc, str_lit("TypeInfoEnum")); tag = ir_emit_conv(proc, ti_ptr, t_type_info_enum_ptr); { - GB_ASSERT(t->Record.enum_base_type != NULL); + GB_ASSERT(t->Record.enum_base_type != nullptr); irValue *base = ir_type_info(proc, t->Record.enum_base_type); ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 2), base); @@ -8165,7 +8165,7 @@ void ir_gen_tree(irGen *s) { for (isize i = 0; i < count; i++) { Entity *f = fields[i]; - GB_ASSERT(f->type != NULL); + GB_ASSERT(f->type != nullptr); GB_ASSERT(f->type->kind == Type_BitFieldValue); irValue *name_ep = ir_emit_array_epi(proc, name_array, i); irValue *bit_ep = ir_emit_array_epi(proc, bit_array, i); @@ -8195,7 +8195,7 @@ void ir_gen_tree(irGen *s) { } - if (tag != NULL) { + if (tag != nullptr) { Type *tag_type = type_deref(ir_type(tag)); GB_ASSERT(is_type_named(tag_type)); Type *ti = base_type(t_type_info); diff --git a/src/ir_opt.cpp b/src/ir_opt.cpp index 1900d2ed2..756eed856 100644 --- a/src/ir_opt.cpp +++ b/src/ir_opt.cpp @@ -39,7 +39,7 @@ void ir_opt_add_operands(Array *ops, irInstr *i) { array_add(ops, i->If.cond); break; case irInstr_Return: - if (i->Return.value != NULL) { + if (i->Return.value != nullptr) { array_add(ops, i->Return.value); } break; @@ -168,7 +168,7 @@ void ir_remove_dead_blocks(irProcedure *proc) { isize j = 0; for_array(i, proc->blocks) { irBlock *b = proc->blocks[i]; - if (b == NULL) { + if (b == nullptr) { continue; } // NOTE(bill): Swap order @@ -210,7 +210,7 @@ void ir_remove_unreachable_blocks(irProcedure *proc) { } // NOTE(bill): Mark as empty but don't actually free it // As it's been allocated with an arena - proc->blocks[i] = NULL; + proc->blocks[i] = nullptr; } } ir_remove_dead_blocks(proc); @@ -245,7 +245,7 @@ bool ir_opt_block_fusion(irProcedure *proc, irBlock *a) { ir_opt_block_replace_pred(b->succs[i], b, a); } - proc->blocks[b->index] = NULL; + proc->blocks[b->index] = nullptr; return true; } @@ -258,7 +258,7 @@ void ir_opt_blocks(irProcedure *proc) { changed = false; for_array(i, proc->blocks) { irBlock *b = proc->blocks[i]; - if (b == NULL) { + if (b == nullptr) { continue; } GB_ASSERT_MSG(b->index == i, "%d, %td", b->index, i); @@ -286,11 +286,11 @@ void ir_opt_build_referrers(irProcedure *proc) { ir_opt_add_operands(&ops, &instr->Instr); for_array(k, ops) { irValue *op = ops[k]; - if (op == NULL) { + if (op == nullptr) { continue; } Array *refs = ir_value_referrers(op); - if (refs != NULL) { + if (refs != nullptr) { array_add(refs, instr); } } @@ -325,10 +325,10 @@ i32 ir_lt_depth_first_search(irLTState *lt, irBlock *p, i32 i, irBlock **preorde preorder[i] = p; p->dom.pre = i++; lt->sdom[p->index] = p; - ir_lt_link(lt, NULL, p); + ir_lt_link(lt, nullptr, p); for_array(index, p->succs) { irBlock *q = p->succs[index]; - if (lt->sdom[q->index] == NULL) { + if (lt->sdom[q->index] == nullptr) { lt->parent[q->index] = p; i = ir_lt_depth_first_search(lt, q, i, preorder); } @@ -339,7 +339,7 @@ i32 ir_lt_depth_first_search(irLTState *lt, irBlock *p, i32 i, irBlock **preorde irBlock *ir_lt_eval(irLTState *lt, irBlock *v) { irBlock *u = v; for (; - lt->ancestor[v->index] != NULL; + lt->ancestor[v->index] != nullptr; v = lt->ancestor[v->index]) { if (lt->sdom[v->index]->dom.pre < lt->sdom[u->index]->dom.pre) { u = v; @@ -432,7 +432,7 @@ void ir_opt_build_dom_tree(irProcedure *proc) { for (isize i = 1; i < n; i++) { irBlock *w = preorder[i]; if (w == root) { - w->dom.idom = NULL; + w->dom.idom = nullptr; } else { // Weird tree relationships here! @@ -441,7 +441,7 @@ void ir_opt_build_dom_tree(irProcedure *proc) { } // Calculate children relation as inverse of idom - if (w->dom.idom->dom.children.data == NULL) { + if (w->dom.idom->dom.children.data == nullptr) { // TODO(bill): Is this good enough for memory allocations? array_init(&w->dom.idom->dom.children, heap_allocator()); } diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 36b0c9855..48935ddf3 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -5,8 +5,8 @@ struct irFileBuffer { }; void ir_file_buffer_init(irFileBuffer *f, gbFile *output) { - isize size = 8*gb_virtual_memory_page_size(NULL); - f->vm = gb_vm_alloc(NULL, size); + isize size = 8*gb_virtual_memory_page_size(nullptr); + f->vm = gb_vm_alloc(nullptr, size); f->offset = 0; f->output = output; } @@ -268,10 +268,6 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) { ir_fprintf(f, "]}"); return; } -/* ir_fprintf(f, "<%lld x ", t->Vector.count); - ir_print_type(f, m, t->Vector.elem); - ir_fprintf(f, ">"); - return; */ case Type_Slice: ir_fprintf(f, "{"); ir_print_type(f, m, t->Slice.elem); @@ -345,7 +341,7 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) { case Type_Named: if (is_type_struct(t) || is_type_union(t)) { String *name = map_get(&m->entity_names, hash_pointer(t->Named.type_name)); - GB_ASSERT_MSG(name != NULL, "%.*s", LIT(t->Named.name)); + GB_ASSERT_MSG(name != nullptr, "%.*s", LIT(t->Named.name)); ir_print_encoded_local(f, *name); } else { ir_print_type(f, m, base_type(t)); @@ -376,7 +372,7 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) { } return; case Type_Map: { - GB_ASSERT(t->Map.generated_struct_type != NULL); + GB_ASSERT(t->Map.generated_struct_type != nullptr); ir_print_type(f, m, t->Map.generated_struct_type); } break; @@ -660,7 +656,7 @@ void ir_print_exact_value(irFileBuffer *f, irModule *m, ExactValue value, Type * } void ir_print_block_name(irFileBuffer *f, irBlock *b) { - if (b != NULL) { + if (b != nullptr) { ir_print_escape_string(f, b->label, false, false); ir_fprintf(f, "-%td", b->index); } else { @@ -669,7 +665,7 @@ void ir_print_block_name(irFileBuffer *f, irBlock *b) { } bool ir_print_is_proc_global(irModule *m, irProcedure *proc) { - if (proc->entity != NULL && + if (proc->entity != nullptr && proc->entity->kind == Entity_Procedure) { if (m->entry_point_entity == proc->entity) { // gb_printf("%.*s\n", LIT(proc->entity->token.string)); @@ -684,8 +680,8 @@ bool ir_print_is_proc_global(irModule *m, irProcedure *proc) { } void ir_print_value(irFileBuffer *f, irModule *m, irValue *value, Type *type_hint) { - if (value == NULL) { - ir_fprintf(f, "!!!NULL_VALUE"); + if (value == nullptr) { + ir_fprintf(f, "!!!nullptr_VALUE"); return; } switch (value->kind) { @@ -697,7 +693,7 @@ void ir_print_value(irFileBuffer *f, irModule *m, irValue *value, Type *type_hin case irValue_ConstantSlice: { irValueConstantSlice *cs = &value->ConstantSlice; - if (cs->backing_array == NULL || cs->count == 0) { + if (cs->backing_array == nullptr || cs->count == 0) { ir_fprintf(f, "zeroinitializer"); } else { Type *at = base_type(type_deref(ir_type(cs->backing_array))); @@ -735,7 +731,7 @@ void ir_print_value(irFileBuffer *f, irModule *m, irValue *value, Type *type_hin Entity *e = value->Global.entity; Scope *scope = e->scope; bool in_global_scope = false; - if (scope != NULL) { + if (scope != nullptr) { // TODO(bill): Fix this rule. What should it be? in_global_scope = scope->is_global || scope->is_init; } @@ -925,8 +921,8 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { } irValue *edge = instr->Phi.edges[i]; - irBlock *block = NULL; - if (instr->parent != NULL && + irBlock *block = nullptr; + if (instr->parent != nullptr && i < instr->parent->preds.count) { block = instr->parent->preds[i]; } @@ -1024,7 +1020,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { case irInstr_Return: { irInstrReturn *ret = &instr->Return; ir_fprintf(f, "ret "); - if (ret->value == NULL) { + if (ret->value == nullptr) { ir_fprintf(f, "void"); } else { Type *t = ir_type(ret->value); @@ -1269,7 +1265,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { ir_fprintf(f, "("); if (proc_type->Proc.return_by_pointer) { - GB_ASSERT(call->return_ptr != NULL); + GB_ASSERT(call->return_ptr != nullptr); ir_print_type(f, m, proc_type->Proc.results); ir_fprintf(f, "* "); ir_print_value(f, m, call->return_ptr, ir_type(call->return_ptr)); @@ -1286,7 +1282,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { isize i = 0; for (; i < params->variable_count-1; i++) { Entity *e = params->variables[i]; - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); if (e->kind != Entity_Variable) continue; if (param_index > 0) ir_fprintf(f, ", "); @@ -1316,7 +1312,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { isize param_count = params->variable_count; for (isize i = 0; i < param_count; i++) { Entity *e = params->variables[i]; - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); if (e->kind != Entity_Variable) continue; if (param_index > 0) ir_fprintf(f, ", "); @@ -1523,7 +1519,7 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) { void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) { - if (proc->body == NULL) { + if (proc->body == nullptr) { ir_fprintf(f, "declare "); // if (proc->tags & ProcTag_dll_import) { // ir_fprintf(f, "dllimport "); @@ -1584,7 +1580,7 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) { if (e->flags&EntityFlag_NoAlias) { ir_fprintf(f, " noalias"); } - if (proc->body != NULL) { + if (proc->body != nullptr) { if (e->token.string != "" && e->token.string != "_") { ir_fprintf(f, " "); @@ -1615,10 +1611,10 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) { } - if (proc->entity != NULL) { - if (proc->body != NULL) { + if (proc->entity != nullptr) { + if (proc->body != nullptr) { irDebugInfo **di_ = map_get(&proc->module->debug_info, hash_pointer(proc->entity)); - if (di_ != NULL) { + if (di_ != nullptr) { irDebugInfo *di = *di_; GB_ASSERT(di->kind == irDebugInfo_Proc); // ir_fprintf(f, "!dbg !%d ", di->id); @@ -1627,7 +1623,7 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) { } - if (proc->body != NULL) { + if (proc->body != nullptr) { // ir_fprintf(f, "nounwind uwtable {\n"); ir_fprintf(f, "{\n"); @@ -1716,7 +1712,7 @@ void print_llvm_ir(irGen *ir) { continue; } - if (v->Proc.body == NULL) { + if (v->Proc.body == nullptr) { ir_print_proc(f, m, &v->Proc); } } @@ -1728,7 +1724,7 @@ void print_llvm_ir(irGen *ir) { continue; } - if (v->Proc.body != NULL) { + if (v->Proc.body != nullptr) { ir_print_proc(f, m, &v->Proc); } } @@ -1742,7 +1738,7 @@ void print_llvm_ir(irGen *ir) { irValueGlobal *g = &v->Global; Scope *scope = g->entity->scope; bool in_global_scope = false; - if (scope != NULL) { + if (scope != nullptr) { // TODO(bill): Fix this rule. What should it be? in_global_scope = scope->is_global || scope->is_init; // in_global_scope = value->Global.name_is_not_mangled; @@ -1773,7 +1769,7 @@ void print_llvm_ir(irGen *ir) { ir_print_type(f, m, g->entity->type); ir_fprintf(f, " "); if (!g->is_foreign) { - if (g->value != NULL) { + if (g->value != nullptr) { ir_print_value(f, m, g->value, g->entity->type); } else { ir_fprintf(f, "zeroinitializer"); diff --git a/src/main.cpp b/src/main.cpp index 9cdf10cc7..e4e921d21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,8 +41,8 @@ i32 system_exec_command_line_app(char *name, bool is_silent, char *fmt, ...) { cmd = string_to_string16(string_buffer_allocator, make_string(cast(u8 *)cmd_line, cmd_len-1)); - if (CreateProcessW(NULL, cmd.text, - NULL, NULL, true, 0, NULL, NULL, + if (CreateProcessW(nullptr, cmd.text, + nullptr, nullptr, true, 0, nullptr, nullptr, &start_info, &pi)) { WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, cast(DWORD *)&exit_code); diff --git a/src/map.cpp b/src/map.cpp index 7732bcfe4..4d75270fb 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -234,7 +234,7 @@ gb_inline T *map_get(Map *h, HashKey key) { if (index >= 0) { return &h->entries[index].value; } - return NULL; + return nullptr; } template @@ -303,7 +303,7 @@ template MapEntry *multi_map_find_first(Map *h, HashKey key) { isize i = map__find(h, key).entry_index; if (i < 0) { - return NULL; + return nullptr; } return &h->entries[i]; } @@ -317,14 +317,14 @@ MapEntry *multi_map_find_next(Map *h, MapEntry *e) { } i = h->entries[i].next; } - return NULL; + return nullptr; } template isize multi_map_count(Map *h, HashKey key) { isize count = 0; MapEntry *e = multi_map_find_first(h, key); - while (e != NULL) { + while (e != nullptr) { count++; e = multi_map_find_next(h, e); } @@ -335,7 +335,7 @@ template void multi_map_get_all(Map *h, HashKey key, T *items) { isize i = 0; MapEntry *e = multi_map_find_first(h, key); - while (e != NULL) { + while (e != nullptr) { items[i++] = e->value; e = multi_map_find_next(h, e); } @@ -374,7 +374,7 @@ void multi_map_remove(Map *h, HashKey key, MapEntry *e) { template void multi_map_remove_all(Map *h, HashKey key) { - while (map_get(h, key) != NULL) { + while (map_get(h, key) != nullptr) { map_remove(h, key); } } diff --git a/src/parser.cpp b/src/parser.cpp index 364f2f339..6a732ba6f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -519,7 +519,7 @@ Token ast_node_token(AstNode *node) { case AstNode_BasicDirective: return node->BasicDirective.token; case AstNode_ProcLit: return ast_node_token(node->ProcLit.type); case AstNode_CompoundLit: - if (node->CompoundLit.type != NULL) { + if (node->CompoundLit.type != nullptr) { return ast_node_token(node->CompoundLit.type); } return node->CompoundLit.open; @@ -534,7 +534,7 @@ Token ast_node_token(AstNode *node) { case AstNode_CallExpr: return ast_node_token(node->CallExpr.proc); case AstNode_MacroCallExpr: return ast_node_token(node->MacroCallExpr.macro); case AstNode_SelectorExpr: - if (node->SelectorExpr.selector != NULL) { + if (node->SelectorExpr.selector != nullptr) { return ast_node_token(node->SelectorExpr.selector); } return node->SelectorExpr.token; @@ -622,8 +622,8 @@ Array clone_ast_node_array(gbAllocator a, Array array) { } AstNode *clone_ast_node(gbAllocator a, AstNode *node) { - if (node == NULL) { - return NULL; + if (node == nullptr) { + return nullptr; } AstNode *n = gb_alloc_item(a, AstNode); gb_memmove(n, node, gb_size_of(AstNode)); @@ -891,7 +891,7 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) { void error(AstNode *node, char *fmt, ...) { Token token = {}; - if (node != NULL) { + if (node != nullptr) { token = ast_node_token(node); } va_list va; @@ -978,11 +978,11 @@ AstNode *ast_unary_expr(AstFile *f, Token op, AstNode *expr) { AstNode *ast_binary_expr(AstFile *f, Token op, AstNode *left, AstNode *right) { AstNode *result = make_ast_node(f, AstNode_BinaryExpr); - if (left == NULL) { + if (left == nullptr) { syntax_error(op, "No lhs expression for binary expression `%.*s`", LIT(op.string)); left = ast_bad_expr(f, op, op); } - if (right == NULL) { + if (right == nullptr) { syntax_error(op, "No rhs expression for binary expression `%.*s`", LIT(op.string)); right = ast_bad_expr(f, op, op); } @@ -1802,7 +1802,7 @@ Token expect_closing(AstFile *f, TokenKind kind, String context) { } bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) { - if (s == NULL) { + if (s == nullptr) { return false; } @@ -1828,7 +1828,7 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) { case AstNode_BitFieldType: return true; case AstNode_ProcLit: - return s->ProcLit.body != NULL; + return s->ProcLit.body != nullptr; case AstNode_ValueDecl: if (s->ValueDecl.is_mutable) { @@ -1875,7 +1875,7 @@ void expect_semicolon(AstFile *f, AstNode *s) { return; } - if (s != NULL) { + if (s != nullptr) { if (prev_token.pos.line != f->curr_token.pos.line) { if (is_semicolon_optional_for_node(f, s)) { return; @@ -1940,8 +1940,8 @@ AstNode *parse_tag_expr(AstFile *f, AstNode *expression) { AstNode *unparen_expr(AstNode *node) { for (;;) { - if (node == NULL) { - return NULL; + if (node == nullptr) { + return nullptr; } if (node->kind != AstNode_ParenExpr) { return node; @@ -1989,7 +1989,7 @@ AstNode *parse_literal_value(AstFile *f, AstNode *type) { AstNode *parse_value(AstFile *f) { if (f->curr_token.kind == Token_OpenBrace) { - return parse_literal_value(f, NULL); + return parse_literal_value(f, nullptr); } AstNode *value = parse_expr(f, false); @@ -2056,13 +2056,13 @@ bool is_foreign_name_valid(String name) { void parse_proc_tags(AstFile *f, u64 *tags, String *link_name, ProcCallingConvention *calling_convention) { // TODO(bill): Add this to procedure literals too - GB_ASSERT(tags != NULL); - GB_ASSERT(link_name != NULL); + GB_ASSERT(tags != nullptr); + GB_ASSERT(link_name != nullptr); ProcCallingConvention cc = ProcCC_Invalid; while (f->curr_token.kind == Token_Hash) { - AstNode *tag_expr = parse_tag_expr(f, NULL); + AstNode *tag_expr = parse_tag_expr(f, nullptr); ast_node(te, TagExpr, tag_expr); String tag_name = te->name.string; @@ -2165,8 +2165,8 @@ AstNode * parse_type (AstFile *f); AstNode * parse_call_expr (AstFile *f, AstNode *operand); AstNode *convert_stmt_to_expr(AstFile *f, AstNode *statement, String kind) { - if (statement == NULL) { - return NULL; + if (statement == nullptr) { + return nullptr; } if (statement->kind == AstNode_ExprStmt) { @@ -2184,7 +2184,7 @@ AstNode *convert_stmt_to_expr(AstFile *f, AstNode *statement, String kind) { AstNode *parse_operand(AstFile *f, bool lhs) { - AstNode *operand = NULL; // Operand + AstNode *operand = nullptr; // Operand switch (f->curr_token.kind) { case Token_Ident: return parse_ident(f); @@ -2285,13 +2285,13 @@ AstNode *parse_operand(AstFile *f, bool lhs) { u64 tags = type->ProcType.tags; if (allow_token(f, Token_Undef)) { - return ast_proc_lit(f, type, NULL, tags, link_name); + return ast_proc_lit(f, type, nullptr, tags, link_name); } else if (f->curr_token.kind == Token_OpenBrace) { if ((tags & ProcTag_foreign) != 0) { syntax_error(token, "A procedure tagged as `#foreign` cannot have a body"); } AstNode *curr_proc = f->curr_proc; - AstNode *body = NULL; + AstNode *body = nullptr; f->curr_proc = type; body = parse_body(f); f->curr_proc = curr_proc; @@ -2302,7 +2302,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { syntax_error(token, "A procedure tagged as `#foreign` cannot have a body"); } AstNode *curr_proc = f->curr_proc; - AstNode *body = NULL; + AstNode *body = nullptr; f->curr_proc = type; body = parse_stmt(f); if (body->kind == AstNode_BlockStmt) { @@ -2320,7 +2320,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } if ((tags & ProcTag_foreign) != 0) { - return ast_proc_lit(f, type, NULL, tags, link_name); + return ast_proc_lit(f, type, nullptr, tags, link_name); } if (tags != 0) { // syntax_error(token, "A procedure type cannot have tags"); @@ -2331,7 +2331,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { default: { AstNode *type = parse_type_or_ident(f); - if (type != NULL) { + if (type != nullptr) { // TODO(bill): Is this correct??? // NOTE(bill): Sanity check as identifiers should be handled already TokenPos pos = ast_node_token(type).pos; @@ -2342,7 +2342,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } } - return NULL; + return nullptr; } bool is_literal_type(AstNode *node) { @@ -2446,7 +2446,7 @@ AstNode *parse_macro_call_expr(AstFile *f, AstNode *operand) { } AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { - if (operand == NULL) { + if (operand == nullptr) { Token begin = f->curr_token; syntax_error(begin, "Expected an operand"); fix_advance_to_next_stmt(f); @@ -2484,7 +2484,7 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { syntax_error(f->curr_token, "Expected a selector"); next_token(f); operand = ast_bad_expr(f, ast_node_token(operand), f->curr_token); - // operand = ast_selector_expr(f, f->curr_token, operand, NULL); + // operand = ast_selector_expr(f, f->curr_token, operand, nullptr); break; } } break; @@ -2532,11 +2532,11 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) { if (ellipsis_count == 2) { index3 = true; // 2nd and 3rd index must be present - if (indices[1] == NULL) { + if (indices[1] == nullptr) { error(ellipses[0], "2nd index required in 3-index slice expression"); indices[1] = ast_bad_expr(f, ellipses[0], ellipses[1]); } - if (indices[2] == NULL) { + if (indices[2] == nullptr) { error(ellipses[1], "3rd index required in 3-index slice expression"); indices[2] = ast_bad_expr(f, ellipses[1], close); } @@ -2591,7 +2591,7 @@ AstNode *parse_unary_expr(AstFile *f, bool lhs) { } bool is_ast_node_a_range(AstNode *expr) { - if (expr == NULL) { + if (expr == nullptr) { return false; } if (expr->kind != AstNode_BinaryExpr) { @@ -2667,7 +2667,7 @@ AstNode *parse_binary_expr(AstFile *f, bool lhs, i32 prec_in) { expr = ast_ternary_expr(f, cond, x, y); } else { AstNode *right = parse_binary_expr(f, false, prec+1); - if (right == NULL) { + if (right == nullptr) { syntax_error(op, "Expected expression on the right-hand side of the binary operator"); } expr = ast_binary_expr(f, op, expr, right); @@ -2725,7 +2725,7 @@ Array parse_ident_list(AstFile *f) { AstNode *parse_type_attempt(AstFile *f) { AstNode *type = parse_type_or_ident(f); - if (type != NULL) { + if (type != nullptr) { // TODO(bill): Handle? } return type; @@ -2733,7 +2733,7 @@ AstNode *parse_type_attempt(AstFile *f) { AstNode *parse_type(AstFile *f) { AstNode *type = parse_type_attempt(f); - if (type == NULL) { + if (type == nullptr) { Token token = f->curr_token; syntax_error(token, "Expected a type"); next_token(f); @@ -2765,7 +2765,7 @@ AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) { if (require_semicolon_after_paren || f->curr_token.pos.line == close.pos.line || open.pos.line == close.pos.line) { - expect_semicolon(f, NULL); + expect_semicolon(f, nullptr); } } else { specs = make_ast_node_array(f, 1); @@ -2781,9 +2781,9 @@ AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) { } PARSE_SPEC_FUNC(parse_import_spec) { - AstNode *spec = NULL; + AstNode *spec = nullptr; if (token.kind == Token_import) { - AstNode *cond = NULL; + AstNode *cond = nullptr; Token import_name = {}; switch (f->curr_token.kind) { @@ -2810,15 +2810,15 @@ PARSE_SPEC_FUNC(parse_import_spec) { cond = parse_expr(f, false); } - expect_semicolon(f, NULL); - if (f->curr_proc != NULL) { + expect_semicolon(f, nullptr); + if (f->curr_proc != nullptr) { syntax_error(import_name, "You cannot use `import` within a procedure. This must be done at the file scope"); spec = ast_bad_decl(f, import_name, file_path); } else { spec = ast_import_spec(f, true, file_path, import_name, cond, docs, f->line_comment); } } else { - AstNode *cond = NULL; + AstNode *cond = nullptr; Token file_path = expect_token_after(f, Token_String, "import_load"); Token import_name = file_path; import_name.string = str_lit("."); @@ -2827,8 +2827,8 @@ PARSE_SPEC_FUNC(parse_import_spec) { cond = parse_expr(f, false); } - expect_semicolon(f, NULL); - if (f->curr_proc != NULL) { + expect_semicolon(f, nullptr); + if (f->curr_proc != nullptr) { syntax_error(import_name, "You cannot use `import_load` within a procedure. This must be done at the file scope"); spec = ast_bad_decl(f, import_name, file_path); } else { @@ -2839,9 +2839,9 @@ PARSE_SPEC_FUNC(parse_import_spec) { } PARSE_SPEC_FUNC(parse_foreign_library_spec) { - AstNode *spec = NULL; + AstNode *spec = nullptr; if (token.kind == Token_foreign_system_library) { - AstNode *cond = NULL; + AstNode *cond = nullptr; Token lib_name = {}; switch (f->curr_token.kind) { @@ -2863,16 +2863,16 @@ PARSE_SPEC_FUNC(parse_foreign_library_spec) { cond = parse_expr(f, false); } - expect_semicolon(f, NULL); + expect_semicolon(f, nullptr); - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { spec = ast_foreign_library_spec(f, file_path, lib_name, cond, true, docs, f->line_comment); } else { syntax_error(lib_name, "You cannot use foreign_system_library within a procedure. This must be done at the file scope"); spec = ast_bad_decl(f, lib_name, file_path); } } else { - AstNode *cond = NULL; + AstNode *cond = nullptr; Token lib_name = {}; switch (f->curr_token.kind) { @@ -2894,9 +2894,9 @@ PARSE_SPEC_FUNC(parse_foreign_library_spec) { cond = parse_expr(f, false); } - expect_semicolon(f, NULL); + expect_semicolon(f, nullptr); - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { spec = ast_foreign_library_spec(f, file_path, lib_name, cond, false, docs, f->line_comment); } else { syntax_error(lib_name, "You cannot use foreign_library within a procedure. This must be done at the file scope"); @@ -2928,7 +2928,7 @@ void parse_foreign_block_decl(AstFile *f, Array *decls) { } AstNode *parse_decl(AstFile *f) { - ParseSpecFunc *func = NULL; + ParseSpecFunc *func = nullptr; switch (f->curr_token.kind) { case Token_import: case Token_import_load: @@ -2984,7 +2984,7 @@ AstNode *parse_decl(AstFile *f) { AstNode *parse_value_decl(AstFile *f, Array names, CommentGroup docs) { bool is_mutable = true; - AstNode *type = NULL; + AstNode *type = nullptr; Array values = {}; Token colon = expect_token_after(f, Token_Colon, "identifier list"); @@ -3006,23 +3006,23 @@ AstNode *parse_value_decl(AstFile *f, Array names, CommentGroup docs) if (is_mutable) { - if (type == NULL && values.count == 0) { + if (type == nullptr && values.count == 0) { syntax_error(f->curr_token, "Missing variable type or initialization"); return ast_bad_decl(f, f->curr_token, f->curr_token); } } else { - if (type == NULL && values.count == 0 && names.count > 0) { + if (type == nullptr && values.count == 0 && names.count > 0) { syntax_error(f->curr_token, "Missing constant value"); return ast_bad_decl(f, f->curr_token, f->curr_token); } } - if (values.data == NULL) { + if (values.data == nullptr) { values = make_ast_node_array(f); } if (f->expr_level >= 0) { - AstNode *end = NULL; + AstNode *end = nullptr; if (!is_mutable && values.count > 0) { end = values[values.count-1]; } @@ -3055,7 +3055,7 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) { case Token_CmpAndEq: case Token_CmpOrEq: { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a simple statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } @@ -3131,7 +3131,7 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) { AstNode *parse_block_stmt(AstFile *f, b32 is_when) { - if (!is_when && f->curr_proc == NULL) { + if (!is_when && f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a block statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } @@ -3143,7 +3143,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok AstNode *parse_results(AstFile *f) { if (!allow_token(f, Token_ArrowRight)) { - return NULL; + return nullptr; } if (f->curr_token.kind != Token_OpenParen) { @@ -3152,23 +3152,23 @@ AstNode *parse_results(AstFile *f) { Array empty_names = {}; Array list = make_ast_node_array(f, 1); AstNode *type = parse_type(f); - array_add(&list, ast_field(f, empty_names, type, NULL, 0, empty_group, empty_group)); + array_add(&list, ast_field(f, empty_names, type, nullptr, 0, empty_group, empty_group)); return ast_field_list(f, begin_token, list); } - AstNode *list = NULL; + AstNode *list = nullptr; expect_token(f, Token_OpenParen); - list = parse_field_list(f, NULL, 0, Token_CloseParen, true); + list = parse_field_list(f, nullptr, 0, Token_CloseParen, true); expect_token_after(f, Token_CloseParen, "parameter list"); return list; } AstNode *parse_proc_type(AstFile *f, Token proc_token, String *link_name_) { - AstNode *params = NULL; - AstNode *results = NULL; + AstNode *params = nullptr; + AstNode *results = nullptr; expect_token(f, Token_OpenParen); - params = parse_field_list(f, NULL, FieldFlag_Signature, Token_CloseParen, true); + params = parse_field_list(f, nullptr, FieldFlag_Signature, Token_CloseParen, true); expect_token_after(f, Token_CloseParen, "parameter list"); results = parse_results(f); @@ -3188,7 +3188,7 @@ AstNode *parse_proc_type(AstFile *f, Token proc_token, String *link_name_) { is_generic = true; break; } - if (f->type != NULL && + if (f->type != nullptr && f->type->kind == AstNode_TypeType) { is_generic = true; break; @@ -3204,20 +3204,20 @@ AstNode *parse_var_type(AstFile *f, bool allow_ellipsis, bool allow_type_token) Token tok = f->curr_token; next_token(f); AstNode *type = parse_type_or_ident(f); - if (type == NULL) { + if (type == nullptr) { error(tok, "variadic field missing type after `...`"); type = ast_bad_expr(f, tok, f->curr_token); } return ast_ellipsis(f, tok, type); } - AstNode *type = NULL; + AstNode *type = nullptr; if (allow_type_token && f->curr_token.kind == Token_type) { type = ast_type_type(f, expect_token(f, Token_type)); } else { type = parse_type_attempt(f); } - if (type == NULL) { + if (type == nullptr) { Token tok = f->curr_token; error(tok, "Expected a type"); type = ast_bad_expr(f, tok, f->curr_token); @@ -3408,8 +3408,8 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok set_flags = check_field_prefixes(f, names.count, allowed_flags, set_flags); total_name_count += names.count; - AstNode *type = NULL; - AstNode *default_value = NULL; + AstNode *type = nullptr; + AstNode *default_value = nullptr; expect_token_after(f, Token_Colon, "field list"); if (f->curr_token.kind != Token_Eq) { @@ -3423,7 +3423,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok } } - if (default_value != NULL && names.count > 1) { + if (default_value != nullptr && names.count > 1) { syntax_error(f->curr_token, "Default parameters can only be applied to single values"); } @@ -3445,8 +3445,8 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok set_flags = check_field_prefixes(f, names.count, allowed_flags, set_flags); total_name_count += names.count; - AstNode *type = NULL; - AstNode *default_value = NULL; + AstNode *type = nullptr; + AstNode *default_value = nullptr; expect_token_after(f, Token_Colon, "field list"); if (f->curr_token.kind != Token_Eq) { type = parse_var_type(f, allow_ellipsis, allow_default_parameters); @@ -3459,7 +3459,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok } } - if (default_value != NULL && names.count > 1) { + if (default_value != nullptr && names.count > 1) { syntax_error(f->curr_token, "Default parameters can only be applied to single values"); } @@ -3486,7 +3486,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok names[0] = ast_ident(f, token); u32 flags = check_field_prefixes(f, list.count, allowed_flags, list[i].flags); - AstNode *param = ast_field(f, names, list[i].node, NULL, flags, docs, f->line_comment); + AstNode *param = ast_field(f, names, list[i].node, nullptr, flags, docs, f->line_comment); array_add(¶ms, param); } @@ -3556,11 +3556,11 @@ AstNode *parse_type_or_ident(AstFile *f) { case Token_OpenBracket: { Token token = expect_token(f, Token_OpenBracket); - AstNode *count_expr = NULL; + AstNode *count_expr = nullptr; bool is_vector = false; if (f->curr_token.kind == Token_Ellipsis) { - count_expr = ast_unary_expr(f, expect_token(f, Token_Ellipsis), NULL); + count_expr = ast_unary_expr(f, expect_token(f, Token_Ellipsis), nullptr); } else if (f->curr_token.kind == Token_vector) { next_token(f); if (f->curr_token.kind != Token_CloseBracket) { @@ -3589,9 +3589,9 @@ AstNode *parse_type_or_ident(AstFile *f) { case Token_map: { Token token = expect_token(f, Token_map); - AstNode *count = NULL; - AstNode *key = NULL; - AstNode *value = NULL; + AstNode *count = nullptr; + AstNode *key = nullptr; + AstNode *value = nullptr; Token open = expect_token_after(f, Token_OpenBracket, "map"); key = parse_expr(f, true); @@ -3609,7 +3609,7 @@ AstNode *parse_type_or_ident(AstFile *f) { Token token = expect_token(f, Token_struct); bool is_packed = false; bool is_ordered = false; - AstNode *align = NULL; + AstNode *align = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; @@ -3648,7 +3648,7 @@ AstNode *parse_type_or_ident(AstFile *f) { Token close = expect_token(f, Token_CloseBrace); Array decls = {}; - if (fields != NULL) { + if (fields != nullptr) { GB_ASSERT(fields->kind == AstNode_FieldList); decls = fields->FieldList.list; } @@ -3676,7 +3676,7 @@ AstNode *parse_type_or_ident(AstFile *f) { total_decl_name_count += names.count; expect_token_after(f, Token_Colon, "field list"); AstNode *type = parse_var_type(f, false, false); - array_add(&decls, ast_field(f, names, type, NULL, set_flags, docs, f->line_comment)); + array_add(&decls, ast_field(f, names, type, nullptr, set_flags, docs, f->line_comment)); } else { Array names = parse_ident_list(f); if (names.count == 0) { @@ -3687,7 +3687,7 @@ AstNode *parse_type_or_ident(AstFile *f) { total_decl_name_count += names.count; expect_token_after(f, Token_Colon, "field list"); AstNode *type = parse_var_type(f, false, false); - array_add(&decls, ast_field(f, names, type, NULL, set_flags, docs, f->line_comment)); + array_add(&decls, ast_field(f, names, type, nullptr, set_flags, docs, f->line_comment)); } else { AstNode *name = names[0]; Token open = expect_token(f, Token_OpenBrace); @@ -3718,7 +3718,7 @@ AstNode *parse_type_or_ident(AstFile *f) { Token close = expect_token(f, Token_CloseBrace); Array decls = {}; - if (fields != NULL) { + if (fields != nullptr) { GB_ASSERT(fields->kind == AstNode_FieldList); decls = fields->FieldList.list; } @@ -3728,7 +3728,7 @@ AstNode *parse_type_or_ident(AstFile *f) { case Token_enum: { Token token = expect_token(f, Token_enum); - AstNode *base_type = NULL; + AstNode *base_type = nullptr; if (f->curr_token.kind != Token_OpenBrace) { base_type = parse_type(f); } @@ -3743,7 +3743,7 @@ AstNode *parse_type_or_ident(AstFile *f) { case Token_bit_field: { Token token = expect_token(f, Token_bit_field); Array fields = make_ast_node_array(f); - AstNode *align = NULL; + AstNode *align = nullptr; Token open, close; isize prev_level = f->expr_level; @@ -3787,7 +3787,7 @@ AstNode *parse_type_or_ident(AstFile *f) { case Token_proc: { Token token = f->curr_token; next_token(f); - AstNode *pt = parse_proc_type(f, token, NULL); + AstNode *pt = parse_proc_type(f, token, nullptr); if (pt->ProcType.tags != 0) { syntax_error(token, "A procedure type cannot have tags"); } @@ -3802,7 +3802,7 @@ AstNode *parse_type_or_ident(AstFile *f) { } break; } - return NULL; + return nullptr; } @@ -3822,16 +3822,16 @@ AstNode *parse_body(AstFile *f) { } AstNode *parse_if_stmt(AstFile *f) { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use an if statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } Token token = expect_token(f, Token_if); - AstNode *init = NULL; - AstNode *cond = NULL; - AstNode *body = NULL; - AstNode *else_stmt = NULL; + AstNode *init = nullptr; + AstNode *cond = nullptr; + AstNode *body = nullptr; + AstNode *else_stmt = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; @@ -3844,13 +3844,13 @@ AstNode *parse_if_stmt(AstFile *f) { cond = parse_expr(f, false); } else { cond = convert_stmt_to_expr(f, init, str_lit("boolean expression")); - init = NULL; + init = nullptr; } } f->expr_level = prev_level; - if (cond == NULL) { + if (cond == nullptr) { syntax_error(f->curr_token, "Expected condition for if statement"); } @@ -3890,9 +3890,9 @@ AstNode *parse_if_stmt(AstFile *f) { AstNode *parse_when_stmt(AstFile *f) { Token token = expect_token(f, Token_when); - AstNode *cond = NULL; - AstNode *body = NULL; - AstNode *else_stmt = NULL; + AstNode *cond = nullptr; + AstNode *body = nullptr; + AstNode *else_stmt = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; @@ -3901,7 +3901,7 @@ AstNode *parse_when_stmt(AstFile *f) { f->expr_level = prev_level; - if (cond == NULL) { + if (cond == nullptr) { syntax_error(f->curr_token, "Expected condition for when statement"); } @@ -3941,7 +3941,7 @@ AstNode *parse_when_stmt(AstFile *f) { AstNode *parse_return_stmt(AstFile *f) { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a return statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } @@ -3969,7 +3969,7 @@ AstNode *parse_return_stmt(AstFile *f) { next_token(f); } - AstNode *end = NULL; + AstNode *end = nullptr; if (results.count > 0) { end = results[results.count-1]; } @@ -3979,7 +3979,7 @@ AstNode *parse_return_stmt(AstFile *f) { // AstNode *parse_give_stmt(AstFile *f) { -// if (f->curr_proc == NULL) { +// if (f->curr_proc == nullptr) { // syntax_error(f->curr_token, "You cannot use a give statement in the file scope"); // return ast_bad_stmt(f, f->curr_token, f->curr_token); // } @@ -4001,17 +4001,17 @@ AstNode *parse_return_stmt(AstFile *f) { // } AstNode *parse_for_stmt(AstFile *f) { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a for statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } Token token = expect_token(f, Token_for); - AstNode *init = NULL; - AstNode *cond = NULL; - AstNode *post = NULL; - AstNode *body = NULL; + AstNode *init = nullptr; + AstNode *cond = nullptr; + AstNode *post = nullptr; + AstNode *body = nullptr; bool is_range = false; if (f->curr_token.kind != Token_OpenBrace && @@ -4028,7 +4028,7 @@ AstNode *parse_for_stmt(AstFile *f) { if (!is_range && f->curr_token.kind == Token_Semicolon) { next_token(f); init = cond; - cond = NULL; + cond = nullptr; if (f->curr_token.kind != Token_Semicolon) { cond = parse_simple_stmt(f, StmtAllowFlag_None); } @@ -4054,8 +4054,8 @@ AstNode *parse_for_stmt(AstFile *f) { if (is_range) { GB_ASSERT(cond->kind == AstNode_AssignStmt); Token in_token = cond->AssignStmt.op; - AstNode *value = NULL; - AstNode *index = NULL; + AstNode *value = nullptr; + AstNode *index = nullptr; switch (cond->AssignStmt.lhs.count) { case 1: value = cond->AssignStmt.lhs[0]; @@ -4069,7 +4069,7 @@ AstNode *parse_for_stmt(AstFile *f) { return ast_bad_stmt(f, token, f->curr_token); } - AstNode *rhs = NULL; + AstNode *rhs = nullptr; if (cond->AssignStmt.rhs.count > 0) { rhs = cond->AssignStmt.rhs[0]; } @@ -4099,15 +4099,15 @@ AstNode *parse_case_clause(AstFile *f, bool is_type) { AstNode *parse_match_stmt(AstFile *f) { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a match statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } Token token = expect_token(f, Token_match); - AstNode *init = NULL; - AstNode *tag = NULL; - AstNode *body = NULL; + AstNode *init = nullptr; + AstNode *tag = nullptr; + AstNode *body = nullptr; Token open, close; bool is_type_match = false; Array list = make_ast_node_array(f); @@ -4122,7 +4122,7 @@ AstNode *parse_match_stmt(AstFile *f) { } else { if (allow_token(f, Token_Semicolon)) { init = tag; - tag = NULL; + tag = nullptr; if (f->curr_token.kind != Token_OpenBrace) { tag = parse_simple_stmt(f, StmtAllowFlag_None); } @@ -4149,7 +4149,7 @@ AstNode *parse_match_stmt(AstFile *f) { } AstNode *parse_defer_stmt(AstFile *f) { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(f->curr_token, "You cannot use a defer statement in the file scope"); return ast_bad_stmt(f, f->curr_token, f->curr_token); } @@ -4178,9 +4178,9 @@ AstNode *parse_asm_stmt(AstFile *f) { Token open, close, code_string; open = expect_token(f, Token_OpenBrace); code_string = expect_token(f, Token_String); - AstNode *output_list = NULL; - AstNode *input_list = NULL; - AstNode *clobber_list = NULL; + AstNode *output_list = nullptr; + AstNode *input_list = nullptr; + AstNode *clobber_list = nullptr; isize output_count = 0; isize input_count = 0; isize clobber_count = 0; @@ -4201,7 +4201,7 @@ AstNode *parse_asm_stmt(AstFile *f) { AstNode *parse_stmt(AstFile *f) { - AstNode *s = NULL; + AstNode *s = nullptr; Token token = f->curr_token; switch (token.kind) { // Operands @@ -4250,7 +4250,7 @@ AstNode *parse_stmt(AstFile *f) { case Token_break: case Token_continue: case Token_fallthrough: { - AstNode *label = NULL; + AstNode *label = nullptr; next_token(f); if (token.kind != Token_fallthrough && f->curr_token.kind == Token_Ident) { @@ -4264,11 +4264,11 @@ AstNode *parse_stmt(AstFile *f) { case Token_using: { CommentGroup docs = f->lead_comment; Token token = expect_token(f, Token_using); - AstNode *decl = NULL; + AstNode *decl = nullptr; Array list = parse_lhs_expr_list(f); if (list.count == 0) { syntax_error(token, "Illegal use of `using` statement"); - expect_semicolon(f, NULL); + expect_semicolon(f, nullptr); return ast_bad_stmt(f, token, f->curr_token); } @@ -4278,12 +4278,12 @@ AstNode *parse_stmt(AstFile *f) { } decl = parse_value_decl(f, list, docs); - if (decl != NULL && decl->kind == AstNode_ValueDecl) { + if (decl != nullptr && decl->kind == AstNode_ValueDecl) { if (!decl->ValueDecl.is_mutable) { syntax_error(token, "`using` may only be applied to variable declarations"); return decl; } - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { syntax_error(token, "`using` is not allowed at the file scope"); } else { decl->ValueDecl.flags |= VarDeclFlag_using; @@ -4297,7 +4297,7 @@ AstNode *parse_stmt(AstFile *f) { case Token_push_allocator: { next_token(f); - AstNode *body = NULL; + AstNode *body = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; AstNode *expr = parse_expr(f, false); @@ -4317,7 +4317,7 @@ AstNode *parse_stmt(AstFile *f) { case Token_push_context: { next_token(f); - AstNode *body = NULL; + AstNode *body = nullptr; isize prev_level = f->expr_level; f->expr_level = -1; AstNode *expr = parse_expr(f, false); @@ -4336,13 +4336,13 @@ AstNode *parse_stmt(AstFile *f) { } break; case Token_Hash: { - AstNode *s = NULL; + AstNode *s = nullptr; Token hash_token = expect_token(f, Token_Hash); Token name = expect_token(f, Token_Ident); String tag = name.string; if (tag == "shared_global_scope") { - if (f->curr_proc == NULL) { + if (f->curr_proc == nullptr) { f->is_global_scope = true; s = ast_empty_stmt(f, f->curr_token); } else { @@ -4358,7 +4358,7 @@ AstNode *parse_stmt(AstFile *f) { if (!s->ValueDecl.is_mutable) { syntax_error(token, "`thread_local` may only be applied to variable declarations"); } - if (f->curr_proc != NULL) { + if (f->curr_proc != nullptr) { syntax_error(token, "`thread_local` is only allowed at the file scope"); } else { s->ValueDecl.flags |= VarDeclFlag_thread_local; @@ -4422,7 +4422,7 @@ Array parse_stmt_list(AstFile *f) { if (stmt && stmt->kind != AstNode_EmptyStmt) { array_add(&list, stmt); if (stmt->kind == AstNode_ExprStmt && - stmt->ExprStmt.expr != NULL && + stmt->ExprStmt.expr != nullptr && stmt->ExprStmt.expr->kind == AstNode_ProcLit) { syntax_error(stmt, "Procedure literal evaluated but not used"); } @@ -4465,7 +4465,7 @@ ParseFileError init_ast_file(AstFile *f, String fullpath) { gb_arena_init_from_allocator(&f->arena, heap_allocator(), arena_size); array_init(&f->comments, heap_allocator()); - f->curr_proc = NULL; + f->curr_proc = nullptr; return ParseFile_None; } diff --git a/src/printer.cpp b/src/printer.cpp index 4d7184631..8db801435 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -6,7 +6,7 @@ gb_inline void print_indent(isize indent) { } void print_ast(AstNode *node, isize indent) { - if (node == NULL) + if (node == nullptr) return; switch (node->kind) { diff --git a/src/ssa.cpp b/src/ssa.cpp index 402976154..2f9588917 100644 --- a/src/ssa.cpp +++ b/src/ssa.cpp @@ -206,7 +206,7 @@ ssaBlock *ssa_new_block(ssaProc *p, ssaBlockKind kind, char *name) { b->kind = kind; b->proc = p; p->scope_level = p->scope_level; - if (name != NULL || name[0] != 0) { + if (name != nullptr || name[0] != 0) { b->name = make_string_c(name); } @@ -218,34 +218,34 @@ ssaBlock *ssa_new_block(ssaProc *p, ssaBlockKind kind, char *name) { } void ssa_clear_block(ssaProc *p, ssaBlock *b) { - GB_ASSERT(b->proc != NULL); + GB_ASSERT(b->proc != nullptr); array_clear(&b->values); array_clear(&b->preds); array_clear(&b->succs); - b->proc = NULL; + b->proc = nullptr; b->kind = ssaBlock_Plain; } void ssa_start_block(ssaProc *p, ssaBlock *b) { - GB_ASSERT(p->curr_block == NULL); + GB_ASSERT(p->curr_block == nullptr); p->curr_block = b; } ssaBlock *ssa_end_block(ssaProc *p) { ssaBlock *b = p->curr_block; - if (b == NULL) { - return NULL; + if (b == nullptr) { + return nullptr; } - p->curr_block = NULL; + p->curr_block = nullptr; return b; } void ssa_add_edge_to(ssaBlock *b, ssaBlock *c) { - if (b == NULL) { + if (b == nullptr) { return; } - GB_ASSERT(c != NULL); + GB_ASSERT(c != nullptr); isize i = b->succs.count; isize j = b->preds.count; ssaEdge s = {c, j}; @@ -255,11 +255,11 @@ void ssa_add_edge_to(ssaBlock *b, ssaBlock *c) { } void ssa_set_control(ssaBlock *b, ssaValue *v) { - if (b->control != NULL) { + if (b->control != nullptr) { b->control->uses--; } b->control = v; - if (v != NULL) { + if (v != nullptr) { v->uses++; } } @@ -295,7 +295,7 @@ void ssa_add_arg(ssaValueArgs *va, ssaValue *arg) { ssaValue *ssa_new_value(ssaProc *p, ssaOp op, Type *t, ssaBlock *b) { - GB_ASSERT(b != NULL); + GB_ASSERT(b != nullptr); ssaValue *v = gb_alloc_item(p->allocator, ssaValue); v->id = p->value_id++; v->op = op; @@ -388,7 +388,7 @@ ssaValue *ssa_const_int(ssaProc *p, Type *t, i64 c) { case 64: return ssa_const_i64(p, t, cast(i64)c); } GB_PANIC("Unknown int size"); - return NULL; + return nullptr; } @@ -416,8 +416,8 @@ void ssa_reset(ssaValue *v, ssaOp op) { } ssaValue *ssa_get_last_value(ssaBlock *b) { - if (b == NULL) { - return NULL; + if (b == nullptr) { + return nullptr; } isize len = b->values.count; if (len <= 0) { @@ -428,7 +428,7 @@ ssaValue *ssa_get_last_value(ssaBlock *b) { } void ssa_emit_comment(ssaProc *p, String s) { - // ssa_new_value0v(p, ssaOp_Comment, NULL, exact_value_string(s)); + // ssa_new_value0v(p, ssaOp_Comment, nullptr, exact_value_string(s)); } void ssa_build_defer_stmt(ssaProc *p, ssaDefer d) { @@ -463,7 +463,7 @@ void ssa_emit_defer_stmts(ssaProc *p, ssaDeferExitKind kind, ssaBlock *b) { } else if (kind == ssaDeferExit_Return) { ssa_build_defer_stmt(p, d); } else if (kind == ssaDeferExit_Branch) { - GB_ASSERT(b != NULL); + GB_ASSERT(b != nullptr); i32 lower_limit = b->scope_level+1; if (lower_limit < d.scope_level) { ssa_build_defer_stmt(p, d); @@ -542,7 +542,7 @@ bool ssa_is_blank_ident(AstNode *node) { ssaAddr ssa_addr(ssaValue *v) { - if (v != NULL) { + if (v != nullptr) { GB_ASSERT(is_type_pointer(v->type)); } ssaAddr addr = {0}; @@ -551,13 +551,13 @@ ssaAddr ssa_addr(ssaValue *v) { } Type *ssa_addr_type(ssaAddr addr) { - if (addr.addr == NULL) { - return NULL; + if (addr.addr == nullptr) { + return nullptr; } if (addr.kind == ssaAddr_Map) { GB_PANIC("TODO: ssa_addr_type"); - return NULL; + return nullptr; } Type *t = addr.addr->type; @@ -603,18 +603,18 @@ ssaAddr ssa_add_local_for_ident(ssaProc *p, AstNode *name) { return ssa_add_local(p, e, name); } - return ssa_addr(NULL); + return ssa_addr(nullptr); } ssaAddr ssa_add_local_generated(ssaProc *p, Type *t) { - GB_ASSERT(t != NULL); + GB_ASSERT(t != nullptr); - Scope *scope = NULL; + Scope *scope = nullptr; if (p->curr_block) { // scope = p->curr_block->scope; } Entity *e = make_entity_variable(p->allocator, scope, empty_token, t, false); - return ssa_add_local(p, e, NULL); + return ssa_add_local(p, e, nullptr); } @@ -667,7 +667,7 @@ bool can_ssa_type(Type *t) { } void ssa_addr_store(ssaProc *p, ssaAddr addr, ssaValue *value) { - if (addr.addr == NULL) { + if (addr.addr == nullptr) { return; } if (addr.kind == ssaAddr_Map) { @@ -679,13 +679,13 @@ void ssa_addr_store(ssaProc *p, ssaAddr addr, ssaValue *value) { } ssaValue *ssa_addr_load(ssaProc *p, ssaAddr addr) { - if (addr.addr == NULL) { - return NULL; + if (addr.addr == nullptr) { + return nullptr; } if (addr.kind == ssaAddr_Map) { GB_PANIC("here\n"); - return NULL; + return nullptr; } Type *t = addr.addr->type; @@ -702,23 +702,23 @@ ssaValue *ssa_get_using_variable(ssaProc *p, Entity *e) { String name = e->token.string; Entity *parent = e->using_parent; Selection sel = lookup_field(p->allocator, parent->type, name, false); - GB_ASSERT(sel.entity != NULL); + GB_ASSERT(sel.entity != nullptr); ssaValue **pv = map_get(&p->module->values, hash_pointer(parent)); - ssaValue *v = NULL; - if (pv != NULL) { + ssaValue *v = nullptr; + if (pv != nullptr) { v = *pv; } else { v = ssa_build_addr(p, e->using_expr).addr; } - GB_ASSERT(v != NULL); + GB_ASSERT(v != nullptr); GB_ASSERT(type_deref(v->type) == parent->type); return ssa_emit_deep_field_ptr_index(p, v, sel); } ssaAddr ssa_build_addr_from_entity(ssaProc *p, Entity *e, AstNode *expr) { - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); - ssaValue *v = NULL; + ssaValue *v = nullptr; ssaValue **found = map_get(&p->module->values, hash_pointer(e)); if (found) { v = *found; @@ -727,7 +727,7 @@ ssaAddr ssa_build_addr_from_entity(ssaProc *p, Entity *e, AstNode *expr) { v = ssa_get_using_variable(p, e); } - if (v == NULL) { + if (v == nullptr) { GB_PANIC("Unknown value: %.*s, entity: %p %.*s\n", LIT(e->token.string), e, LIT(entity_strings[e->kind])); } @@ -773,11 +773,11 @@ ssaValue *ssa_emit_conv(ssaProc *p, ssaValue *v, Type *t) { GB_PANIC("Invalid type conversion: `%s` to `%s`", type_to_string(src_type), type_to_string(t)); - return NULL; + return nullptr; } -// NOTE(bill): Returns NULL if not possible +// NOTE(bill): Returns nullptr if not possible ssaValue *ssa_address_from_load_or_generate_local(ssaProc *p, ssaValue *v) { if (v->op == ssaOp_Load) { return v->args[0]; @@ -789,11 +789,11 @@ ssaValue *ssa_address_from_load_or_generate_local(ssaProc *p, ssaValue *v) { ssaValue *ssa_emit_array_index(ssaProc *p, ssaValue *v, ssaValue *index) { - GB_ASSERT(v != NULL); + GB_ASSERT(v != nullptr); GB_ASSERT(is_type_pointer(v->type)); Type *t = base_type(type_deref(v->type)); GB_ASSERT_MSG(is_type_array(t) || is_type_vector(t), "%s", type_to_string(t)); - Type *elem_ptr = NULL; + Type *elem_ptr = nullptr; if (is_type_array(t)) { elem_ptr = make_type_pointer(p->allocator, t->Array.elem); } else if (is_type_vector(t)) { @@ -806,7 +806,7 @@ ssaValue *ssa_emit_array_index(ssaProc *p, ssaValue *v, ssaValue *index) { ssaValue *ssa_emit_ptr_index(ssaProc *p, ssaValue *s, i64 index) { gbAllocator a = p->allocator; Type *t = base_type(type_deref(s->type)); - Type *result_type = NULL; + Type *result_type = nullptr; if (is_type_struct(t)) { GB_ASSERT(t->Record.field_count > 0); @@ -854,7 +854,7 @@ ssaValue *ssa_emit_ptr_index(ssaProc *p, ssaValue *s, i64 index) { GB_PANIC("TODO(bill): ssa_emit_ptr_index type: %s, %d", type_to_string(s->type), index); } - GB_ASSERT(result_type != NULL); + GB_ASSERT(result_type != nullptr); return ssa_new_value1i(p, ssaOp_PtrIndex, result_type, index, s); } @@ -869,7 +869,7 @@ ssaValue *ssa_emit_value_index(ssaProc *p, ssaValue *s, i64 index) { gbAllocator a = p->allocator; Type *t = base_type(s->type); - Type *result_type = NULL; + Type *result_type = nullptr; if (is_type_struct(t)) { GB_ASSERT(t->Record.field_count > 0); @@ -917,7 +917,7 @@ ssaValue *ssa_emit_value_index(ssaProc *p, ssaValue *s, i64 index) { GB_PANIC("TODO(bill): struct_ev type: %s, %d", type_to_string(s->type), index); } - GB_ASSERT(result_type != NULL); + GB_ASSERT(result_type != nullptr); return ssa_new_value1i(p, ssaOp_ValueIndex, result_type, index, s); } @@ -1054,7 +1054,7 @@ ssaAddr ssa_build_addr(ssaProc *p, AstNode *expr) { if (tav.mode == Addressing_Invalid) { // NOTE(bill): Imports Entity *imp = entity_of_ident(p->module->info, se->expr); - if (imp != NULL) { + if (imp != nullptr) { GB_ASSERT(imp->kind == Entity_ImportName); } return ssa_build_addr(p, se->selector); @@ -1072,7 +1072,7 @@ ssaAddr ssa_build_addr(ssaProc *p, AstNode *expr) { // if (name == "names") { // ssaValue *ti_ptr = ir_type_info(p, type); - // ssaValue *names_ptr = NULL; + // ssaValue *names_ptr = nullptr; // if (is_type_enum(type)) { // ssaValue *enum_info = ssa_emit_conv(p, ti_ptr, t_type_info_enum_ptr); @@ -1089,7 +1089,7 @@ ssaAddr ssa_build_addr(ssaProc *p, AstNode *expr) { } Selection sel = lookup_field(p->allocator, type, selector, false); - GB_ASSERT(sel.entity != NULL); + GB_ASSERT(sel.entity != nullptr); ssaValue *a = ssa_build_addr(p, se->expr).addr; a = ssa_emit_deep_field_ptr_index(p, a, sel); @@ -1101,7 +1101,7 @@ ssaAddr ssa_build_addr(ssaProc *p, AstNode *expr) { i64 index = i128_to_i64(val.value_integer); Selection sel = lookup_field_from_index(p->allocator, type, index); - GB_ASSERT(sel.entity != NULL); + GB_ASSERT(sel.entity != nullptr); ssaValue *a = ssa_build_addr(p, se->expr).addr; a = ssa_emit_deep_field_ptr_index(p, a, sel); @@ -1156,7 +1156,7 @@ ssaAddr ssa_build_addr(ssaProc *p, AstNode *expr) { LIT(token_pos.file), token_pos.line, token_pos.column); - return ssa_addr(NULL); + return ssa_addr(nullptr); } @@ -1382,7 +1382,7 @@ ssaOp ssa_determine_op(TokenKind op, Type *t) { ssaValue *ssa_emit_comp(ssaProc *p, TokenKind op, ssaValue *x, ssaValue *y) { - GB_ASSERT(x != NULL && y != NULL); + GB_ASSERT(x != nullptr && y != nullptr); Type *a = core_type(x->type); Type *b = core_type(y->type); if (are_types_identical(a, b)) { @@ -1486,7 +1486,7 @@ ssaValue *ssa_emit_unary_arith(ssaProc *p, TokenKind op, ssaValue *x, Type *type GB_PANIC("unknown type for -x"); } break; } - return NULL; + return nullptr; } ssaValue *ssa_emit_arith(ssaProc *p, TokenKind op, ssaValue *x, ssaValue *y, Type *type) { if (is_type_vector(x->type)) { @@ -1537,11 +1537,11 @@ ssaValue *ssa_emit_arith(ssaProc *p, TokenKind op, ssaValue *x, ssaValue *y, Typ case Token_Or: case Token_Xor: case Token_AndNot: - GB_ASSERT(x != NULL && y != NULL); + GB_ASSERT(x != nullptr && y != nullptr); return ssa_new_value2(p, ssa_determine_op(op, x->type), type, x, y); } - return NULL; + return nullptr; } @@ -1589,7 +1589,7 @@ ssaValue *ssa_emit_logical_binary_expr(ssaProc *p, AstNode *expr) { ssaBlock *rhs = ssa_new_block(p, ssaBlock_Plain, "logical.cmp.rhs"); ssaBlock *done = ssa_new_block(p, ssaBlock_Plain, "logical.cmp.done"); - GB_ASSERT(p->curr_block != NULL); + GB_ASSERT(p->curr_block != nullptr); Type *type = default_type(type_of_expr(p->module->info, expr)); @@ -1689,10 +1689,10 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) { GB_PANIC("TODO(bill): ssa_build_expr Entity_Builtin `%.*s`\n" "\t at %.*s(%td:%td)", LIT(builtin_procs[e->Builtin.id].name), LIT(token.pos.file), token.pos.line, token.pos.column); - return NULL; + return nullptr; } else if (e->kind == Entity_Nil) { GB_PANIC("TODO(bill): nil"); - return NULL; + return nullptr; } ssaValue **found = map_get(&p->module->values, hash_pointer(e)); @@ -1737,7 +1737,7 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) { case Token_Shl: case Token_Shr: { GB_PANIC("TODO: shifts"); - return NULL; + return nullptr; } case Token_CmpEq: @@ -1772,29 +1772,29 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) { case_ast_node(te, TernaryExpr, expr); ssa_emit_comment(p, str_lit("TernaryExpr")); - ssaValue *yes = NULL; - ssaValue *no = NULL; + ssaValue *yes = nullptr; + ssaValue *no = nullptr; - GB_ASSERT(te->y != NULL); + GB_ASSERT(te->y != nullptr); ssaBlock *then = ssa_new_block(p, ssaBlock_Plain, "if.then"); ssaBlock *done = ssa_new_block(p, ssaBlock_Plain, "if.done"); // NOTE(bill): Append later ssaBlock *else_ = ssa_new_block(p, ssaBlock_Plain, "if.else"); - ssaBlock *v = NULL; + ssaBlock *v = nullptr; ssa_build_cond(p, te->cond, then, else_); ssa_start_block(p, then); // ssa_open_scope(p); yes = ssa_build_expr(p, te->x); - // ssa_close_scope(p, ssaDeferExit_Default, NULL); + // ssa_close_scope(p, ssaDeferExit_Default, nullptr); ssa_emit_jump(p, done); ssa_start_block(p, else_); // ssa_open_scope(p); no = ssa_build_expr(p, te->y); - // ssa_close_scope(p, ssaDeferExit_Default, NULL); + // ssa_close_scope(p, ssaDeferExit_Default, nullptr); ssa_emit_jump(p, done); ssa_start_block(p, done); @@ -1815,7 +1815,7 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) { Type *type = type_of_expr(proc->module->info, expr); irValue *value = ir_value_procedure(proc->module->allocator, - proc->module, NULL, type, pl->type, pl->body, name); + proc->module, nullptr, type, pl->type, pl->body, name); value->Proc.tags = pl->tags; value->Proc.parent = proc; @@ -1854,7 +1854,7 @@ ssaValue *ssa_build_expr(ssaProc *p, AstNode *expr) { GB_PANIC("Unexpected expression: %.*s", LIT(ast_node_strings[expr->kind])); - return NULL; + return nullptr; } @@ -1927,7 +1927,7 @@ void ssa_build_stmt(ssaProc *p, AstNode *node) { p->module->stmt_state_flags = prev_stmt_state_flags; } void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { - if (p->curr_block == NULL) { + if (p->curr_block == nullptr) { ssaBlock *dead_block = ssa_new_block(p, ssaBlock_Plain, ""); ssa_start_block(p, dead_block); } @@ -1939,7 +1939,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { case_ast_node(bs, BlockStmt, node); ssa_open_scope(p); ssa_build_stmt_list(p, bs->stmts); - ssa_close_scope(p, ssaDeferExit_Default, NULL); + ssa_close_scope(p, ssaDeferExit_Default, nullptr); case_end; case_ast_node(us, UsingStmt, node); @@ -2064,7 +2064,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { case_ast_node(is, IfStmt, node); ssa_emit_comment(p, str_lit("IfStmt")); - if (is->init != NULL) { + if (is->init != nullptr) { ssaBlock *init = ssa_new_block(p, ssaBlock_Plain, "if.init"); ssa_emit_jump(p, init); ssa_start_block(p, init); @@ -2073,26 +2073,26 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { ssaBlock *then = ssa_new_block(p, ssaBlock_Plain, "if.then"); ssaBlock *done = ssa_new_block(p, ssaBlock_Plain, "if.done"); ssaBlock *else_ = done; - if (is->else_stmt != NULL) { + if (is->else_stmt != nullptr) { else_ = ssa_new_block(p, ssaBlock_Plain, "if.else"); } - ssaBlock *b = NULL; + ssaBlock *b = nullptr; ssa_build_cond(p, is->cond, then, else_); ssa_start_block(p, then); ssa_open_scope(p); ssa_build_stmt(p, is->body); - ssa_close_scope(p, ssaDeferExit_Default, NULL); + ssa_close_scope(p, ssaDeferExit_Default, nullptr); ssa_emit_jump(p, done); - if (is->else_stmt != NULL) { + if (is->else_stmt != nullptr) { ssa_start_block(p, else_); ssa_open_scope(p); ssa_build_stmt(p, is->else_stmt); - ssa_close_scope(p, ssaDeferExit_Default, NULL); + ssa_close_scope(p, ssaDeferExit_Default, nullptr); ssa_emit_jump(p, done); } @@ -2103,7 +2103,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { case_ast_node(fs, ForStmt, node); ssa_emit_comment(p, str_lit("ForStmt")); - if (fs->init != NULL) { + if (fs->init != nullptr) { ssaBlock *init = ssa_new_block(p, ssaBlock_Plain, "for.init"); ssa_emit_jump(p, init); ssa_start_block(p, init); @@ -2113,11 +2113,11 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { ssaBlock *body = ssa_new_block(p, ssaBlock_Plain, "for.body"); ssaBlock *done = ssa_new_block(p, ssaBlock_Plain, "for.done"); ssaBlock *loop = body; - if (fs->cond != NULL) { + if (fs->cond != nullptr) { loop = ssa_new_block(p, ssaBlock_Plain, "for.loop"); } ssaBlock *post = loop; - if (fs->post != NULL) { + if (fs->post != nullptr) { post = ssa_new_block(p, ssaBlock_Plain, "for.post"); } @@ -2129,15 +2129,15 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { ssa_start_block(p, body); } - ssa_push_target_list(p, done, post, NULL); + ssa_push_target_list(p, done, post, nullptr); ssa_open_scope(p); ssa_build_stmt(p, fs->body); - ssa_close_scope(p, ssaDeferExit_Default, NULL); + ssa_close_scope(p, ssaDeferExit_Default, nullptr); ssa_pop_target_list(p); ssa_emit_jump(p, post); - if (fs->post != NULL) { + if (fs->post != nullptr) { ssa_start_block(p, post); ssa_build_stmt(p, fs->post); ssa_emit_jump(p, post); @@ -2159,25 +2159,25 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { case_end; case_ast_node(bs, BranchStmt, node); - ssaBlock *b = NULL; + ssaBlock *b = nullptr; switch (bs->token.kind) { case Token_break: - for (ssaTargetList *t = p->target_list; t != NULL && b == NULL; t = t->prev) { + for (ssaTargetList *t = p->target_list; t != nullptr && b == nullptr; t = t->prev) { b = t->break_; } break; case Token_continue: - for (ssaTargetList *t = p->target_list; t != NULL && b == NULL; t = t->prev) { + for (ssaTargetList *t = p->target_list; t != nullptr && b == nullptr; t = t->prev) { b = t->continue_; } break; case Token_fallthrough: - for (ssaTargetList *t = p->target_list; t != NULL && b == NULL; t = t->prev) { + for (ssaTargetList *t = p->target_list; t != nullptr && b == nullptr; t = t->prev) { b = t->fallthrough_; } break; } - if (b != NULL) { + if (b != nullptr) { ssa_emit_defer_stmts(p, ssaDeferExit_Branch, b); } switch (bs->token.kind) { @@ -2198,7 +2198,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { } void ssa_print_value(gbFile *f, ssaValue *v) { - if (v == NULL) { + if (v == nullptr) { gb_fprintf(f, "nil"); } gb_fprintf(f, "v%d", v->id); @@ -2249,7 +2249,7 @@ void ssa_print_reg_value(gbFile *f, ssaValue *v) { gb_fprintf(f, " "); gb_fprintf(f, "v%d = %.*s", v->id, LIT(ssa_op_strings[v->op])); - if (v->type != NULL) { + if (v->type != nullptr) { gbString type_str = type_to_string(default_type(v->type)); gb_fprintf(f, " %s", type_str); gb_string_free(type_str); @@ -2313,7 +2313,7 @@ void ssa_print_proc(gbFile *f, ssaProc *p) { bool skip = false; for_array(k, v->args) { ssaValue *w = v->args[k]; - if (w != NULL && w->block == b && !printed[w->id]) { + if (w != nullptr && w->block == b && !printed[w->id]) { skip = true; break; } @@ -2377,13 +2377,13 @@ void ssa_build_proc(ssaModule *m, ssaProc *p) { p->module = m; m->proc = p; - if (p->decl_info->proc_lit == NULL || + if (p->decl_info->proc_lit == nullptr || p->decl_info->proc_lit->kind != AstNode_ProcLit) { return; } ast_node(pl, ProcLit, p->decl_info->proc_lit); - if (pl->body == NULL) { + if (pl->body == nullptr) { return; } p->entry = ssa_new_block(p, ssaBlock_Entry, "entry"); @@ -2392,7 +2392,7 @@ void ssa_build_proc(ssaModule *m, ssaProc *p) { ssa_build_stmt(p, pl->body); if (p->entity->type->Proc.result_count == 0) { - ssa_emit_defer_stmts(p, ssaDeferExit_Return, NULL); + ssa_emit_defer_stmts(p, ssaDeferExit_Return, nullptr); } p->exit = ssa_new_block(p, ssaBlock_Exit, "exit"); @@ -2429,7 +2429,7 @@ bool ssa_generate(Parser *parser, CheckerInfo *info) { } isize global_variable_max_count = 0; - Entity *entry_point = NULL; + Entity *entry_point = nullptr; bool has_dll_main = false; bool has_win_main = false; @@ -2470,7 +2470,7 @@ bool ssa_generate(Parser *parser, CheckerInfo *info) { continue; } - if (map_get(&m.min_dep_map, hash_pointer(e)) == NULL) { + if (map_get(&m.min_dep_map, hash_pointer(e)) == nullptr) { // NOTE(bill): Nothing depends upon it so doesn't need to be built continue; } @@ -2515,7 +2515,7 @@ bool ssa_generate(Parser *parser, CheckerInfo *info) { // ssa_module_add_value(m, e, p); // HashKey hash_name = hash_string(name); - // if (map_get(&m.members, hash_name) == NULL) { + // if (map_get(&m.members, hash_name) == nullptr) { // map_set(&m.members, hash_name, p); // } } break; diff --git a/src/string.cpp b/src/string.cpp index 916e095e2..882bc273c 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -65,7 +65,7 @@ gb_inline String16 make_string16(wchar_t *text, isize len) { } isize string16_len(wchar_t *s) { - if (s == NULL) { + if (s == nullptr) { return 0; } wchar_t *p = s; @@ -256,7 +256,7 @@ String filename_from_path(String s) { s.text += j+1; s.len = i-j-1; } - return make_string(NULL, 0); + return make_string(nullptr, 0); } @@ -271,7 +271,7 @@ String filename_from_path(String s) { return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, multibyte_input, input_length, output, output_size); } int convert_widechar_to_multibyte(wchar_t *widechar_input, int input_length, char *output, int output_size) { - return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, widechar_input, input_length, output, output_size, NULL, NULL); + return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, widechar_input, input_length, output, output_size, nullptr, nullptr); } #elif defined(GB_SYSTEM_UNIX) || defined(GB_SYSTEM_OSX) @@ -305,12 +305,12 @@ String16 string_to_string16(gbAllocator a, String s) { wchar_t *text; if (s.len < 1) { - return make_string16(NULL, 0); + return make_string16(nullptr, 0); } - len = convert_multibyte_to_widechar(cast(char *)s.text, s.len, NULL, 0); + len = convert_multibyte_to_widechar(cast(char *)s.text, s.len, nullptr, 0); if (len == 0) { - return make_string16(NULL, 0); + return make_string16(nullptr, 0); } text = gb_alloc_array(a, wchar_t, len+1); @@ -318,7 +318,7 @@ String16 string_to_string16(gbAllocator a, String s) { len1 = convert_multibyte_to_widechar(cast(char *)s.text, s.len, text, len); if (len1 == 0) { gb_free(a, text); - return make_string16(NULL, 0); + return make_string16(nullptr, 0); } text[len] = 0; @@ -331,12 +331,12 @@ String string16_to_string(gbAllocator a, String16 s) { u8 *text; if (s.len < 1) { - return make_string(NULL, 0); + return make_string(nullptr, 0); } - len = convert_widechar_to_multibyte(s.text, s.len, NULL, 0); + len = convert_widechar_to_multibyte(s.text, s.len, nullptr, 0); if (len == 0) { - return make_string(NULL, 0); + return make_string(nullptr, 0); } len += 1; // NOTE(bill): It needs an extra 1 for some reason @@ -345,7 +345,7 @@ String string16_to_string(gbAllocator a, String16 s) { len1 = convert_widechar_to_multibyte(s.text, s.len, cast(char *)text, len); if (len1 == 0) { gb_free(a, text); - return make_string(NULL, 0); + return make_string(nullptr, 0); } text[len] = 0; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 3adff3e74..78833453d 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -433,7 +433,7 @@ TokenizerInitError init_tokenizer(Tokenizer *t, String fullpath) { // TODO(bill): Memory map rather than copy contents gbFileContents fc = gb_file_read_contents(heap_allocator(), true, c_str); gb_zero_item(t); - if (fc.data != NULL) { + if (fc.data != nullptr) { t->start = cast(u8 *)fc.data; t->line = t->read_curr = t->curr = t->start; t->end = t->start + fc.size; @@ -468,7 +468,7 @@ TokenizerInitError init_tokenizer(Tokenizer *t, String fullpath) { } gb_inline void destroy_tokenizer(Tokenizer *t) { - if (t->start != NULL) { + if (t->start != nullptr) { gb_free(heap_allocator(), t->start); } for_array(i, t->allocated_strings) { diff --git a/src/types.cpp b/src/types.cpp index 294e17cd8..1516cd993 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -221,7 +221,7 @@ void selection_add_index(Selection *s, isize index) { // IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form // of heap allocation // TODO(bill): Find a way to use a backing buffer for initial use as the general case is probably .count<3 - if (s->index.data == NULL) { + if (s->index.data == nullptr) { array_init(&s->index, heap_allocator()); } array_add(&s->index, cast(i32)index); @@ -317,80 +317,80 @@ gb_global Type *t_untyped_nil = &basic_types[Basic_UntypedNil]; gb_global Type *t_untyped_undef = &basic_types[Basic_UntypedUndef]; -gb_global Type *t_u8_ptr = NULL; -gb_global Type *t_int_ptr = NULL; -gb_global Type *t_i64_ptr = NULL; -gb_global Type *t_i128_ptr = NULL; -gb_global Type *t_f64_ptr = NULL; -gb_global Type *t_u8_slice = NULL; -gb_global Type *t_string_slice = NULL; +gb_global Type *t_u8_ptr = nullptr; +gb_global Type *t_int_ptr = nullptr; +gb_global Type *t_i64_ptr = nullptr; +gb_global Type *t_i128_ptr = nullptr; +gb_global Type *t_f64_ptr = nullptr; +gb_global Type *t_u8_slice = nullptr; +gb_global Type *t_string_slice = nullptr; // Type generated for the "preload" file -gb_global Type *t_type_info = NULL; -gb_global Type *t_type_info_record = NULL; -gb_global Type *t_type_info_enum_value = NULL; -gb_global Type *t_type_info_ptr = NULL; -gb_global Type *t_type_info_record_ptr = NULL; -gb_global Type *t_type_info_enum_value_ptr = NULL; +gb_global Type *t_type_info = nullptr; +gb_global Type *t_type_info_record = nullptr; +gb_global Type *t_type_info_enum_value = nullptr; +gb_global Type *t_type_info_ptr = nullptr; +gb_global Type *t_type_info_record_ptr = nullptr; +gb_global Type *t_type_info_enum_value_ptr = nullptr; -gb_global Type *t_type_info_named = NULL; -gb_global Type *t_type_info_integer = NULL; -gb_global Type *t_type_info_rune = NULL; -gb_global Type *t_type_info_float = NULL; -gb_global Type *t_type_info_complex = NULL; -gb_global Type *t_type_info_any = NULL; -gb_global Type *t_type_info_string = NULL; -gb_global Type *t_type_info_boolean = NULL; -gb_global Type *t_type_info_pointer = NULL; -gb_global Type *t_type_info_atomic = NULL; -gb_global Type *t_type_info_procedure = NULL; -gb_global Type *t_type_info_array = NULL; -gb_global Type *t_type_info_dynamic_array = NULL; -gb_global Type *t_type_info_slice = NULL; -gb_global Type *t_type_info_vector = NULL; -gb_global Type *t_type_info_tuple = NULL; -gb_global Type *t_type_info_struct = NULL; -gb_global Type *t_type_info_raw_union = NULL; -gb_global Type *t_type_info_union = NULL; -gb_global Type *t_type_info_enum = NULL; -gb_global Type *t_type_info_map = NULL; -gb_global Type *t_type_info_bit_field = NULL; +gb_global Type *t_type_info_named = nullptr; +gb_global Type *t_type_info_integer = nullptr; +gb_global Type *t_type_info_rune = nullptr; +gb_global Type *t_type_info_float = nullptr; +gb_global Type *t_type_info_complex = nullptr; +gb_global Type *t_type_info_any = nullptr; +gb_global Type *t_type_info_string = nullptr; +gb_global Type *t_type_info_boolean = nullptr; +gb_global Type *t_type_info_pointer = nullptr; +gb_global Type *t_type_info_atomic = nullptr; +gb_global Type *t_type_info_procedure = nullptr; +gb_global Type *t_type_info_array = nullptr; +gb_global Type *t_type_info_dynamic_array = nullptr; +gb_global Type *t_type_info_slice = nullptr; +gb_global Type *t_type_info_vector = nullptr; +gb_global Type *t_type_info_tuple = nullptr; +gb_global Type *t_type_info_struct = nullptr; +gb_global Type *t_type_info_raw_union = nullptr; +gb_global Type *t_type_info_union = nullptr; +gb_global Type *t_type_info_enum = nullptr; +gb_global Type *t_type_info_map = nullptr; +gb_global Type *t_type_info_bit_field = nullptr; -gb_global Type *t_type_info_named_ptr = NULL; -gb_global Type *t_type_info_integer_ptr = NULL; -gb_global Type *t_type_info_rune_ptr = NULL; -gb_global Type *t_type_info_float_ptr = NULL; -gb_global Type *t_type_info_complex_ptr = NULL; -gb_global Type *t_type_info_quaternion_ptr = NULL; -gb_global Type *t_type_info_any_ptr = NULL; -gb_global Type *t_type_info_string_ptr = NULL; -gb_global Type *t_type_info_boolean_ptr = NULL; -gb_global Type *t_type_info_pointer_ptr = NULL; -gb_global Type *t_type_info_atomic_ptr = NULL; -gb_global Type *t_type_info_procedure_ptr = NULL; -gb_global Type *t_type_info_array_ptr = NULL; -gb_global Type *t_type_info_dynamic_array_ptr = NULL; -gb_global Type *t_type_info_slice_ptr = NULL; -gb_global Type *t_type_info_vector_ptr = NULL; -gb_global Type *t_type_info_tuple_ptr = NULL; -gb_global Type *t_type_info_struct_ptr = NULL; -gb_global Type *t_type_info_raw_union_ptr = NULL; -gb_global Type *t_type_info_union_ptr = NULL; -gb_global Type *t_type_info_enum_ptr = NULL; -gb_global Type *t_type_info_map_ptr = NULL; -gb_global Type *t_type_info_bit_field_ptr = NULL; +gb_global Type *t_type_info_named_ptr = nullptr; +gb_global Type *t_type_info_integer_ptr = nullptr; +gb_global Type *t_type_info_rune_ptr = nullptr; +gb_global Type *t_type_info_float_ptr = nullptr; +gb_global Type *t_type_info_complex_ptr = nullptr; +gb_global Type *t_type_info_quaternion_ptr = nullptr; +gb_global Type *t_type_info_any_ptr = nullptr; +gb_global Type *t_type_info_string_ptr = nullptr; +gb_global Type *t_type_info_boolean_ptr = nullptr; +gb_global Type *t_type_info_pointer_ptr = nullptr; +gb_global Type *t_type_info_atomic_ptr = nullptr; +gb_global Type *t_type_info_procedure_ptr = nullptr; +gb_global Type *t_type_info_array_ptr = nullptr; +gb_global Type *t_type_info_dynamic_array_ptr = nullptr; +gb_global Type *t_type_info_slice_ptr = nullptr; +gb_global Type *t_type_info_vector_ptr = nullptr; +gb_global Type *t_type_info_tuple_ptr = nullptr; +gb_global Type *t_type_info_struct_ptr = nullptr; +gb_global Type *t_type_info_raw_union_ptr = nullptr; +gb_global Type *t_type_info_union_ptr = nullptr; +gb_global Type *t_type_info_enum_ptr = nullptr; +gb_global Type *t_type_info_map_ptr = nullptr; +gb_global Type *t_type_info_bit_field_ptr = nullptr; -gb_global Type *t_allocator = NULL; -gb_global Type *t_allocator_ptr = NULL; -gb_global Type *t_context = NULL; -gb_global Type *t_context_ptr = NULL; +gb_global Type *t_allocator = nullptr; +gb_global Type *t_allocator_ptr = nullptr; +gb_global Type *t_context = nullptr; +gb_global Type *t_context_ptr = nullptr; -gb_global Type *t_source_code_location = NULL; -gb_global Type *t_source_code_location_ptr = NULL; +gb_global Type *t_source_code_location = nullptr; +gb_global Type *t_source_code_location_ptr = nullptr; -gb_global Type *t_map_key = NULL; -gb_global Type *t_map_header = NULL; +gb_global Type *t_map_key = nullptr; +gb_global Type *t_map_header = nullptr; @@ -405,7 +405,7 @@ gbString type_to_string(Type *type); Type *base_type(Type *t) { for (;;) { - if (t == NULL) { + if (t == nullptr) { break; } if (t->kind != Type_Named) { @@ -421,7 +421,7 @@ Type *base_type(Type *t) { Type *base_enum_type(Type *t) { Type *bt = base_type(t); - if (bt != NULL && + if (bt != nullptr && bt->kind == Type_Record && bt->Record.kind == TypeRecord_Enum) { return bt->Record.enum_base_type; @@ -431,7 +431,7 @@ Type *base_enum_type(Type *t) { Type *core_type(Type *t) { for (;;) { - if (t == NULL) { + if (t == nullptr) { break; } @@ -572,7 +572,7 @@ Type *make_type_proc(gbAllocator a, Scope *scope, Type *params, isize param_coun if (param_count == 0) { GB_PANIC("variadic procedure must have at least one parameter"); } - GB_ASSERT(params != NULL && params->kind == Type_Tuple); + GB_ASSERT(params != nullptr && params->kind == Type_Tuple); Entity *e = params->Tuple.variables[param_count-1]; if (base_type(e->type)->kind != Type_Slice) { // NOTE(bill): For custom calling convention @@ -594,7 +594,7 @@ bool is_type_valid_for_keys(Type *t); Type *make_type_map(gbAllocator a, i64 count, Type *key, Type *value) { Type *t = alloc_type(a, Type_Map); - if (key != NULL) { + if (key != nullptr) { GB_ASSERT(is_type_valid_for_keys(key)); } t->Map.count = count; @@ -620,11 +620,11 @@ Type *make_type_bit_field(gbAllocator a) { Type *type_deref(Type *t) { - if (t != NULL) { + if (t != nullptr) { Type *bt = base_type(t); - if (bt == NULL) - return NULL; - if (bt != NULL && bt->kind == Type_Pointer) + if (bt == nullptr) + return nullptr; + if (bt != nullptr && bt->kind == Type_Pointer) return bt->Pointer.elem; } return t; @@ -641,7 +641,7 @@ bool is_type_named_alias(Type *t) { return false; } Entity *e = t->Named.type_name; - if (e == NULL) { + if (e == nullptr) { return false; } if (e->kind != Entity_TypeName) { @@ -698,7 +698,7 @@ bool is_type_string(Type *t) { } bool is_type_typed(Type *t) { t = base_type(t); - if (t == NULL) { + if (t == nullptr) { return false; } if (t->kind == Type_Basic) { @@ -865,7 +865,7 @@ bool is_type_union(Type *t) { bool is_type_variant(Type *t) { t = base_type(t); if (t->kind == Type_Record) { - return t->Record.kind == TypeRecord_Struct && t->Record.variant_parent != NULL; + return t->Record.kind == TypeRecord_Struct && t->Record.variant_parent != nullptr; } return false; } @@ -990,7 +990,7 @@ bool is_type_polymorphic(Type *t) { case Type_Record: if (t->Record.kind == TypeRecord_Enum) { - if (t->Record.enum_base_type != NULL) { + if (t->Record.enum_base_type != nullptr) { return is_type_polymorphic(t->Record.enum_base_type); } return false; @@ -1090,8 +1090,8 @@ bool are_types_identical(Type *x, Type *y) { return true; } - if ((x == NULL && y != NULL) || - (x != NULL && y == NULL)) { + if ((x == nullptr && y != nullptr) || + (x != nullptr && y == nullptr)) { return false; } @@ -1160,7 +1160,7 @@ bool are_types_identical(Type *x, Type *y) { return false; } } - // NOTE(bill): zeroth variant is NULL + // NOTE(bill): zeroth variant is nullptr for (isize i = 1; i < x->Record.variant_count; i++) { if (!are_types_identical(x->Record.variants[i]->type, y->Record.variants[i]->type)) { return false; @@ -1230,7 +1230,7 @@ bool are_types_identical(Type *x, Type *y) { } Type *default_bit_field_value_type(Type *type) { - if (type == NULL) { + if (type == nullptr) { return t_invalid; } Type *t = base_type(type); @@ -1250,7 +1250,7 @@ Type *default_bit_field_value_type(Type *type) { } Type *default_type(Type *type) { - if (type == NULL) { + if (type == nullptr) { return t_invalid; } if (type->kind == Type_Basic) { @@ -1347,9 +1347,9 @@ enum ProcTypeOverloadKind { }; ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { - if (x == NULL && y == NULL) return ProcOverload_NotProcedure; - if (x == NULL && y != NULL) return ProcOverload_NotProcedure; - if (x != NULL && y == NULL) return ProcOverload_NotProcedure; + if (x == nullptr && y == nullptr) return ProcOverload_NotProcedure; + if (x == nullptr && y != nullptr) return ProcOverload_NotProcedure; + if (x != nullptr && y == nullptr) return ProcOverload_NotProcedure; if (!is_type_proc(x)) return ProcOverload_NotProcedure; if (!is_type_proc(y)) return ProcOverload_NotProcedure; @@ -1398,7 +1398,7 @@ ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y) { } } - if (px.params != NULL && py.params != NULL) { + if (px.params != nullptr && py.params != nullptr) { Entity *ex = px.params->Tuple.variables[0]; Entity *ey = py.params->Tuple.variables[0]; bool ok = are_types_identical(ex->type, ey->type); @@ -1474,11 +1474,11 @@ Selection lookup_field_from_index(gbAllocator a, Type *type, i64 index) { } -gb_global Entity *entity__any_data = NULL; -gb_global Entity *entity__any_type_info = NULL; +gb_global Entity *entity__any_data = nullptr; +gb_global Entity *entity__any_type_info = nullptr; Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel) { - GB_ASSERT(type_ != NULL); + GB_ASSERT(type_ != nullptr); if (field_name == "_") { return empty_selection; @@ -1498,11 +1498,11 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n // `Raw_Any` type? String data_str = str_lit("data"); String type_info_str = str_lit("type_info"); - if (entity__any_data == NULL) { - entity__any_data = make_entity_field(a, NULL, make_token_ident(data_str), t_rawptr, false, 0); + if (entity__any_data == nullptr) { + entity__any_data = make_entity_field(a, nullptr, make_token_ident(data_str), t_rawptr, false, 0); } - if (entity__any_type_info == NULL) { - entity__any_type_info = make_entity_field(a, NULL, make_token_ident(type_info_str), t_type_info_ptr, false, 1); + if (entity__any_type_info == nullptr) { + entity__any_type_info = make_entity_field(a, nullptr, make_token_ident(type_info_str), t_type_info_ptr, false, 1); } if (field_name == data_str) { @@ -1527,7 +1527,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n case (_length): \ if (field_name == _name) { \ selection_add_index(&sel, (_length)-1); \ - sel.entity = make_entity_vector_elem(a, NULL, make_token_ident(str_lit(_name)), type->Vector.elem, (_length)-1); \ + sel.entity = make_entity_vector_elem(a, nullptr, make_token_ident(str_lit(_name)), type->Vector.elem, (_length)-1); \ return sel; \ } \ /*fallthrough*/ @@ -1545,7 +1545,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n if (is_type) { if (type->kind == Type_Record) { - if (type->Record.names != NULL && + if (type->Record.names != nullptr && field_name == "names") { sel.entity = type->Record.names; return sel; @@ -1566,7 +1566,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n } } else if (is_type_enum(type)) { // NOTE(bill): These may not have been added yet, so check in case - if (type->Record.enum_count != NULL) { + if (type->Record.enum_count != nullptr) { if (field_name == "count") { sel.entity = type->Record.enum_count; return sel; @@ -1612,7 +1612,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n sel = lookup_field_with_selection(a, f->type, field_name, is_type, sel); - if (sel.entity != NULL) { + if (sel.entity != nullptr) { if (is_type_pointer(f->type)) { sel.indirect = true; } @@ -1624,7 +1624,7 @@ Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_n if (type->Record.kind == TypeRecord_Union) { if (field_name == "__tag") { Entity *e = type->Record.union__tag; - GB_ASSERT(e != NULL); + GB_ASSERT(e != nullptr); selection_add_index(&sel, -1); // HACK(bill): Leaky memory sel.entity = e; return sel; @@ -1666,11 +1666,11 @@ void type_path_free(TypePath *tp) { } void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { - GB_ASSERT(tp != NULL); + GB_ASSERT(tp != nullptr); GB_ASSERT(start_index < tp->path.count); Type *t = tp->path[start_index]; - GB_ASSERT(t != NULL); + GB_ASSERT(t != nullptr); GB_ASSERT_MSG(is_type_named(t), "%s", type_to_string(t)); Entity *e = t->Named.type_name; @@ -1689,7 +1689,7 @@ void type_path_print_illegal_cycle(TypePath *tp, isize start_index) { } TypePath *type_path_push(TypePath *tp, Type *t) { - GB_ASSERT(tp != NULL); + GB_ASSERT(tp != nullptr); for (isize i = 0; i < tp->path.count; i++) { if (tp->path[i] == t) { @@ -1704,7 +1704,7 @@ TypePath *type_path_push(TypePath *tp, Type *t) { } void type_path_pop(TypePath *tp) { - if (tp != NULL && tp->path.count > 0) { + if (tp != nullptr && tp->path.count > 0) { array_pop(&tp->path); } } @@ -1726,7 +1726,7 @@ i64 align_formula(i64 size, i64 align) { } i64 type_size_of(gbAllocator allocator, Type *t) { - if (t == NULL) { + if (t == nullptr) { return 0; } i64 size; @@ -1738,7 +1738,7 @@ i64 type_size_of(gbAllocator allocator, Type *t) { } i64 type_align_of(gbAllocator allocator, Type *t) { - if (t == NULL) { + if (t == nullptr) { return 1; } i64 align; @@ -2086,7 +2086,7 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) { if (path->failure) { return FAILURE_SIZE; } - if (t->Record.are_offsets_being_processed && t->Record.offsets == NULL) { + if (t->Record.are_offsets_being_processed && t->Record.offsets == nullptr) { type_path_print_illegal_cycle(path, path->path.count-1); return FAILURE_SIZE; } @@ -2268,7 +2268,7 @@ i64 type_offset_of_from_selection(gbAllocator allocator, Type *type, Selection s } gbString write_type_to_string(gbString str, Type *type) { - if (type == NULL) { + if (type == nullptr) { return gb_string_appendc(str, ""); } @@ -2395,7 +2395,7 @@ gbString write_type_to_string(gbString str, Type *type) { case TypeRecord_Enum: str = gb_string_appendc(str, "enum"); - if (type->Record.enum_base_type != NULL) { + if (type->Record.enum_base_type != nullptr) { str = gb_string_appendc(str, " "); str = write_type_to_string(str, type->Record.enum_base_type); } @@ -2425,7 +2425,7 @@ gbString write_type_to_string(gbString str, Type *type) { } break; case Type_Named: - if (type->Named.type_name != NULL) { + if (type->Named.type_name != nullptr) { str = gb_string_append_length(str, type->Named.name.text, type->Named.name.len); } else { // NOTE(bill): Just in case @@ -2437,7 +2437,7 @@ gbString write_type_to_string(gbString str, Type *type) { if (type->Tuple.variable_count > 0) { for (isize i = 0; i < type->Tuple.variable_count; i++) { Entity *var = type->Tuple.variables[i]; - if (var != NULL) { + if (var != nullptr) { if (i > 0) { str = gb_string_appendc(str, ", "); } @@ -2503,7 +2503,7 @@ gbString write_type_to_string(gbString str, Type *type) { for (isize i = 0; i < type->BitField.field_count; i++) { Entity *f = type->BitField.fields[i]; GB_ASSERT(f->kind == Entity_Variable); - GB_ASSERT(f->type != NULL && f->type->kind == Type_BitFieldValue); + GB_ASSERT(f->type != nullptr && f->type->kind == Type_BitFieldValue); str = gb_string_appendc(str, "{"); if (i > 0) { str = gb_string_appendc(str, ", ");