Fix aprint* bug; NULL -> nullptr; Better error messages for overloaded functions

This commit is contained in:
Ginger Bill
2017-07-06 22:43:55 +01:00
parent eed873c6ec
commit 2db03cb4a5
22 changed files with 1319 additions and 1288 deletions

View File

@@ -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..<count do write_byte(fi.buf, pad_byte);
for _ in 0..<width {
write_byte(fi.buf, pad_byte);
}
}
_fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: int, digits: string) {
@@ -531,7 +531,6 @@ _fmt_int :: proc(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: in
buf: [256]u8;
start := 0;
flags: strconv.IntFlag;
if fi.hash && !fi.zero do flags |= strconv.IntFlag.Prefix;
if fi.plus do flags |= strconv.IntFlag.Plus;
@@ -578,6 +577,7 @@ fmt_int :: proc(fi: ^FmtInfo, u: u128, is_signed: bool, bit_size: int, verb: run
case 'b': _fmt_int(fi, u, 2, is_signed, bit_size, __DIGITS_LOWER);
case 'o': _fmt_int(fi, u, 8, is_signed, bit_size, __DIGITS_LOWER);
case 'd': _fmt_int(fi, u, 10, is_signed, bit_size, __DIGITS_LOWER);
case 'z': _fmt_int(fi, u, 12, is_signed, bit_size, __DIGITS_LOWER);
case 'x': _fmt_int(fi, u, 16, is_signed, bit_size, __DIGITS_LOWER);
case 'X': _fmt_int(fi, u, 16, is_signed, bit_size, __DIGITS_UPPER);
case 'c', 'r':
@@ -601,6 +601,8 @@ _pad :: proc(fi: ^FmtInfo, s: string) {
write_string(fi.buf, s);
return;
}
width := fi.width - utf8.rune_count(s);
if fi.minus { // right pad
write_string(fi.buf, s);

View File

@@ -61,7 +61,7 @@ Array<T> array_make(T *data, isize count, isize capacity) {
template <typename T>
void array_free(Array<T> *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<T> *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);

View File

@@ -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);
}

View File

@@ -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<AstNode *> 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;

File diff suppressed because it is too large Load Diff

View File

@@ -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;
}

View File

@@ -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<Entity *> *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<Entity *> generate_minimum_dependency_map(CheckerInfo *info, Entity *start)
}
bool is_entity_in_dependency_map(Map<Entity *> *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<Entity *> *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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<Scope *> *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<Scope *> *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<Scope *> *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<Scope *> *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<Scope *> *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<Scope *> *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];

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@@ -39,7 +39,7 @@ void ir_opt_add_operands(Array<irValue *> *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<irValue *> *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());
}

View File

@@ -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");

View File

@@ -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);

View File

@@ -234,7 +234,7 @@ gb_inline T *map_get(Map<T> *h, HashKey key) {
if (index >= 0) {
return &h->entries[index].value;
}
return NULL;
return nullptr;
}
template <typename T>
@@ -303,7 +303,7 @@ template <typename T>
MapEntry<T> *multi_map_find_first(Map<T> *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<T> *multi_map_find_next(Map<T> *h, MapEntry<T> *e) {
}
i = h->entries[i].next;
}
return NULL;
return nullptr;
}
template <typename T>
isize multi_map_count(Map<T> *h, HashKey key) {
isize count = 0;
MapEntry<T> *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 <typename T>
void multi_map_get_all(Map<T> *h, HashKey key, T *items) {
isize i = 0;
MapEntry<T> *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<T> *h, HashKey key, MapEntry<T> *e) {
template <typename T>
void multi_map_remove_all(Map<T> *h, HashKey key) {
while (map_get(h, key) != NULL) {
while (map_get(h, key) != nullptr) {
map_remove(h, key);
}
}

View File

@@ -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<AstNode *> clone_ast_node_array(gbAllocator a, Array<AstNode *> 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<AstNode *> 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<AstNode *> *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<AstNode *> names, CommentGroup docs) {
bool is_mutable = true;
AstNode *type = NULL;
AstNode *type = nullptr;
Array<AstNode *> values = {};
Token colon = expect_token_after(f, Token_Colon, "identifier list");
@@ -3006,23 +3006,23 @@ AstNode *parse_value_decl(AstFile *f, Array<AstNode *> 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<AstNode *> empty_names = {};
Array<AstNode *> 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(&params, 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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<AstNode *> 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;
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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, "<no type>");
}
@@ -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, ", ");