Change from gbArray(T) to Array<T>

This commit is contained in:
Ginger Bill
2016-10-08 20:37:31 +01:00
parent a5c6340316
commit b705fa7f22
13 changed files with 658 additions and 522 deletions
+58 -58
View File
@@ -118,8 +118,8 @@ struct Scope {
Map<Entity *> elements; // Key: String
Map<Entity *> implicit; // Key: String
gbArray(Scope *) shared;
gbArray(Scope *) imported;
Array<Scope *> shared;
Array<Scope *> imported;
b32 is_proc;
b32 is_global;
b32 is_file;
@@ -240,7 +240,7 @@ struct Checker {
AstFile * curr_ast_file;
BaseTypeSizes sizes;
Scope * global_scope;
gbArray(ProcedureInfo) procs; // NOTE(bill): Procedures to check
Array<ProcedureInfo> procs; // NOTE(bill): Procedures to check
gbArena arena;
gbArena tmp_arena;
@@ -249,31 +249,31 @@ struct Checker {
CheckerContext context;
gbArray(Type *) proc_stack;
Array<Type *> proc_stack;
b32 in_defer; // TODO(bill): Actually handle correctly
};
gb_global Scope *universal_scope = NULL;
struct CycleChecker {
gbArray(Entity *) path; // Entity_TypeName
Array<Entity *> path; // Entity_TypeName
};
CycleChecker *cycle_checker_add(CycleChecker *cc, Entity *e) {
if (cc == NULL) {
return NULL;
}
if (cc->path == NULL) {
gb_array_init(cc->path, gb_heap_allocator());
if (cc->path.data == NULL) {
array_init(&cc->path, gb_heap_allocator());
}
GB_ASSERT(e != NULL && e->kind == Entity_TypeName);
gb_array_append(cc->path, e);
array_add(&cc->path, e);
return cc;
}
void cycle_checker_destroy(CycleChecker *cc) {
if (cc != NULL && cc->path != NULL) {
gb_array_free(cc->path);
if (cc != NULL && cc->path.data != NULL) {
array_free(&cc->path);
}
}
@@ -282,10 +282,10 @@ void cycle_checker_destroy(CycleChecker *cc) {
Scope *make_scope(Scope *parent, gbAllocator allocator) {
Scope *s = gb_alloc_item(allocator, Scope);
s->parent = parent;
map_init(&s->elements, gb_heap_allocator());
map_init(&s->implicit, gb_heap_allocator());
gb_array_init(s->shared, gb_heap_allocator());
gb_array_init(s->imported, gb_heap_allocator());
map_init(&s->elements, gb_heap_allocator());
map_init(&s->implicit, gb_heap_allocator());
array_init(&s->shared, gb_heap_allocator());
array_init(&s->imported, gb_heap_allocator());
if (parent != NULL && parent != universal_scope) {
DLIST_APPEND(parent->first_child, parent->last_child, s);
@@ -294,7 +294,7 @@ Scope *make_scope(Scope *parent, gbAllocator allocator) {
}
void destroy_scope(Scope *scope) {
gb_for_array(i, scope->elements.entries) {
for_array(i, scope->elements.entries) {
Entity *e =scope->elements.entries[i].value;
if (e->kind == Entity_Variable) {
if (!e->Variable.used) {
@@ -311,8 +311,8 @@ void destroy_scope(Scope *scope) {
map_destroy(&scope->elements);
map_destroy(&scope->implicit);
gb_array_free(scope->shared);
gb_array_free(scope->imported);
array_free(&scope->shared);
array_free(&scope->imported);
// NOTE(bill): No need to free scope as it "should" be allocated in an arena (except for the global scope)
}
@@ -366,7 +366,7 @@ void scope_lookup_parent_entity(Scope *scope, String name, Scope **scope_, Entit
gone_thru_proc = true;
} else {
// Check shared scopes - i.e. other files @ global scope
gb_for_array(i, s->shared) {
for_array(i, s->shared) {
Scope *shared = s->shared[i];
Entity **found = map_get(&shared->elements, key);
if (found) {
@@ -409,7 +409,7 @@ Entity *current_scope_lookup_entity(Scope *s, String name) {
if (found) {
return *found;
}
gb_for_array(i, s->shared) {
for_array(i, s->shared) {
Entity **found = map_get(&s->shared[i]->elements, key);
if (found) {
return *found;
@@ -436,7 +436,7 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) {
void check_scope_usage(Checker *c, Scope *scope) {
// TODO(bill): Use this?
#if 0
gb_for_array(i, scope->elements.entries) {
for_array(i, scope->elements.entries) {
auto *entry = scope->elements.entries + i;
Entity *e = entry->value;
if (e->kind == Entity_Variable) {
@@ -557,15 +557,15 @@ void init_checker(Checker *c, Parser *parser, BaseTypeSizes sizes) {
init_checker_info(&c->info);
c->sizes = sizes;
gb_array_init(c->proc_stack, a);
gb_array_init(c->procs, a);
array_init(&c->proc_stack, a);
array_init(&c->procs, a);
// NOTE(bill): Is this big enough or too small?
isize item_size = gb_max(gb_max(gb_size_of(Entity), gb_size_of(Type)), gb_size_of(Scope));
isize total_token_count = 0;
gb_for_array(i, c->parser->files) {
for_array(i, c->parser->files) {
AstFile *f = &c->parser->files[i];
total_token_count += gb_array_count(f->tokens);
total_token_count += f->tokens.count;
}
isize arena_size = 2 * item_size * total_token_count;
gb_arena_init_from_allocator(&c->arena, a, arena_size);
@@ -581,8 +581,8 @@ void init_checker(Checker *c, Parser *parser, BaseTypeSizes sizes) {
void destroy_checker(Checker *c) {
destroy_checker_info(&c->info);
destroy_scope(c->global_scope);
gb_array_free(c->proc_stack);
gb_array_free(c->procs);
array_free(&c->proc_stack);
array_free(&c->procs);
gb_arena_free(&c->arena);
}
@@ -723,7 +723,7 @@ void add_type_info_type(Checker *c, Type *t) {
}
isize ti_index = -1;
gb_for_array(i, c->info.type_info_map.entries) {
for_array(i, c->info.type_info_map.entries) {
auto *e = &c->info.type_info_map.entries[i];
Type *prev_type = cast(Type *)cast(uintptr)e->key.key;
if (are_types_identical(t, prev_type)) {
@@ -814,19 +814,19 @@ void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *dec
info.type = type;
info.body = body;
info.tags = tags;
gb_array_append(c->procs, info);
array_add(&c->procs, info);
}
void push_procedure(Checker *c, Type *type) {
gb_array_append(c->proc_stack, type);
array_add(&c->proc_stack, type);
}
void pop_procedure(Checker *c) {
gb_array_pop(c->proc_stack);
array_pop(&c->proc_stack);
}
Type *const curr_procedure(Checker *c) {
isize count = gb_array_count(c->proc_stack);
isize count = c->proc_stack.count;
if (count > 0) {
return c->proc_stack[count-1];
}
@@ -859,7 +859,7 @@ void add_dependency_to_map(Map<Entity *> *map, CheckerInfo *info, Entity *node)
}
DeclInfo *decl = *found;
gb_for_array(i, decl->deps.entries) {
for_array(i, decl->deps.entries) {
Entity *e = cast(Entity *)cast(uintptr)decl->deps.entries[i].key.key;
add_dependency_to_map(map, info, e);
}
@@ -869,7 +869,7 @@ Map<Entity *> generate_minimum_dependency_map(CheckerInfo *info, Entity *start)
Map<Entity *> map = {}; // Key: Entity *
map_init(&map, gb_heap_allocator());
gb_for_array(i, info->entities.entries) {
for_array(i, info->entities.entries) {
auto *entry = &info->entities.entries[i];
Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
if (e->scope->is_global) {
@@ -948,16 +948,16 @@ void init_preload_types(Checker *c) {
void check_parsed_files(Checker *c) {
gbArray(AstNode *) import_decls;
gb_array_init(import_decls, gb_heap_allocator());
defer (gb_array_free(import_decls));
Array<AstNode *> import_decls;
array_init(&import_decls, gb_heap_allocator());
defer (array_free(&import_decls));
Map<Scope *> file_scopes; // Key: String (fullpath)
map_init(&file_scopes, gb_heap_allocator());
defer (map_destroy(&file_scopes));
// Map full filepaths to Scopes
gb_for_array(i, c->parser->files) {
for_array(i, c->parser->files) {
AstFile *f = &c->parser->files[i];
Scope *scope = NULL;
scope = make_scope(c->global_scope, c->allocator);
@@ -971,7 +971,7 @@ void check_parsed_files(Checker *c) {
}
if (scope->is_global) {
gb_array_append(c->global_scope->shared, scope);
array_add(&c->global_scope->shared, scope);
}
f->scope = scope;
@@ -982,13 +982,13 @@ void check_parsed_files(Checker *c) {
}
// Collect Entities
gb_for_array(i, c->parser->files) {
for_array(i, c->parser->files) {
AstFile *f = &c->parser->files[i];
add_curr_ast_file(c, f);
Scope *file_scope = f->scope;
gb_for_array(decl_index, f->decls) {
for_array(decl_index, f->decls) {
AstNode *decl = f->decls[decl_index];
if (!is_ast_node_decl(decl)) {
continue;
@@ -1005,7 +1005,7 @@ void check_parsed_files(Checker *c) {
case_end;
case_ast_node(cd, ConstDecl, decl);
gb_for_array(i, cd->values) {
for_array(i, cd->values) {
AstNode *name = cd->names[i];
AstNode *value = cd->values[i];
ExactValue v = {ExactValue_Invalid};
@@ -1017,8 +1017,8 @@ void check_parsed_files(Checker *c) {
add_entity_and_decl_info(c, name, e, di);
}
isize lhs_count = gb_array_count(cd->names);
isize rhs_count = gb_array_count(cd->values);
isize lhs_count = cd->names.count;
isize rhs_count = cd->values.count;
if (rhs_count == 0 && cd->type == NULL) {
error(ast_node_token(decl), "Missing type or initial expression");
@@ -1028,11 +1028,11 @@ void check_parsed_files(Checker *c) {
case_end;
case_ast_node(vd, VarDecl, decl);
isize entity_count = gb_array_count(vd->names);
isize entity_count = vd->names.count;
isize entity_index = 0;
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
DeclInfo *di = NULL;
if (gb_array_count(vd->values) > 0) {
if (vd->values.count > 0) {
di = make_declaration_info(gb_heap_allocator(), file_scope);
di->entities = entities;
di->entity_count = entity_count;
@@ -1040,10 +1040,10 @@ void check_parsed_files(Checker *c) {
di->init_expr = vd->values[0];
}
gb_for_array(i, vd->names) {
for_array(i, vd->names) {
AstNode *name = vd->names[i];
AstNode *value = NULL;
if (i < gb_array_count(vd->values)) {
if (i < vd->values.count) {
value = vd->values[i];
}
Entity *e = make_entity_variable(c->allocator, file_scope, name->Ident, NULL);
@@ -1089,13 +1089,13 @@ void check_parsed_files(Checker *c) {
}
}
gb_for_array(i, c->parser->files) {
for_array(i, c->parser->files) {
AstFile *f = &c->parser->files[i];
add_curr_ast_file(c, f);
Scope *file_scope = f->scope;
gb_for_array(decl_index, f->decls) {
for_array(decl_index, f->decls) {
AstNode *decl = f->decls[decl_index];
if (decl->kind != AstNode_ImportDecl) {
continue;
@@ -1107,7 +1107,7 @@ void check_parsed_files(Checker *c) {
GB_ASSERT_MSG(found != NULL, "Unable to find scope for file: %.*s", LIT(id->fullpath));
Scope *scope = *found;
b32 previously_added = false;
gb_for_array(import_index, file_scope->imported) {
for_array(import_index, file_scope->imported) {
Scope *prev = file_scope->imported[import_index];
if (prev == scope) {
previously_added = true;
@@ -1115,14 +1115,14 @@ void check_parsed_files(Checker *c) {
}
}
if (!previously_added) {
gb_array_append(file_scope->imported, scope);
array_add(&file_scope->imported, scope);
} else {
warning(id->token, "Multiple #import of the same file within this scope");
}
if (id->import_name.string == ".") {
// NOTE(bill): Add imported entities to this file's scope
gb_for_array(elem_index, scope->elements.entries) {
for_array(elem_index, scope->elements.entries) {
Entity *e = scope->elements.entries[elem_index].value;
if (e->scope == file_scope) {
continue;
@@ -1186,7 +1186,7 @@ void check_parsed_files(Checker *c) {
}
auto check_global_entity = [](Checker *c, EntityKind kind) {
gb_for_array(i, c->info.entities.entries) {
for_array(i, c->info.entities.entries) {
auto *entry = &c->info.entities.entries[i];
Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
if (e->kind == kind) {
@@ -1222,7 +1222,7 @@ void check_parsed_files(Checker *c) {
check_global_entity(c, Entity_Variable);
// Check procedure bodies
gb_for_array(i, c->procs) {
for_array(i, c->procs) {
ProcedureInfo *pi = &c->procs[i];
add_curr_ast_file(c, pi->file);
@@ -1244,13 +1244,13 @@ void check_parsed_files(Checker *c) {
if (false) {
gb_printf("Dependency graph:\n");
gb_for_array(i, c->info.entities.entries) {
for_array(i, c->info.entities.entries) {
auto *entry = &c->info.entities.entries[i];
Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
DeclInfo *d = entry->value;
if (gb_array_count(d->deps.entries) > 0) {
if (d->deps.entries.count > 0) {
gb_printf("\t%.*s depends on\n", LIT(e->token.string));
gb_for_array(j, d->deps.entries) {
for_array(j, d->deps.entries) {
Entity *e = cast(Entity *)cast(uintptr)d->deps.entries[j].key.key;
gb_printf("\t\t%.*s\n", LIT(e->token.string));
}
@@ -1259,7 +1259,7 @@ void check_parsed_files(Checker *c) {
}
// Add untyped expression values
gb_for_array(i, c->info.untyped.entries) {
for_array(i, c->info.untyped.entries) {
auto *entry = &c->info.untyped.entries[i];
HashKey key = entry->key;
AstNode *expr = cast(AstNode *)cast(uintptr)key.key;
+80 -78
View File
@@ -254,19 +254,19 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
Entity *e;
AstNode *t;
};
gbArray(Delay) delayed_const; gb_array_init_reserve(delayed_const, c->tmp_allocator, other_field_count);
gbArray(Delay) delayed_type; gb_array_init_reserve(delayed_type, c->tmp_allocator, other_field_count);
Array<Delay> delayed_const; array_init(&delayed_const, c->tmp_allocator, other_field_count);
Array<Delay> delayed_type; array_init(&delayed_type, c->tmp_allocator, other_field_count);
gb_for_array(decl_index, decls) {
for_array(decl_index, decls) {
AstNode *decl = decls[decl_index];
if (decl->kind == AstNode_ConstDecl) {
ast_node(cd, ConstDecl, decl);
isize entity_count = gb_array_count(cd->names);
isize entity_count = cd->names.count;
isize entity_index = 0;
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
gb_for_array(i, cd->values) {
for_array(i, cd->values) {
AstNode *name = cd->names[i];
AstNode *value = cd->values[i];
@@ -277,11 +277,11 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
entities[entity_index++] = e;
Delay delay = {e, cd->type};
gb_array_append(delayed_const, delay);
array_add(&delayed_const, delay);
}
isize lhs_count = gb_array_count(cd->names);
isize rhs_count = gb_array_count(cd->values);
isize lhs_count = cd->names.count;
isize rhs_count = cd->values.count;
// TODO(bill): Better error messages or is this good enough?
if (rhs_count == 0 && cd->type == NULL) {
@@ -290,7 +290,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
error(ast_node_token(node), "Extra initial expression");
}
gb_for_array(i, cd->names) {
for_array(i, cd->names) {
AstNode *name = cd->names[i];
Entity *e = entities[i];
Token name_token = name->Ident;
@@ -314,7 +314,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
Entity *e = make_entity_type_name(c->allocator, c->context.scope, name_token, NULL);
Delay delay = {e, td->type};
gb_array_append(delayed_type, delay);
array_add(&delayed_type, delay);
if (name_token.string == "_") {
other_fields[other_field_index++] = e;
@@ -333,17 +333,17 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
}
}
gb_for_array(i, delayed_type) {
for_array(i, delayed_type) {
check_const_decl(c, delayed_type[i].e, delayed_type[i].t, NULL);
}
gb_for_array(i, delayed_const) {
for_array(i, delayed_const) {
check_type_decl(c, delayed_const[i].e, delayed_const[i].t, NULL, NULL);
}
if (node->kind == AstNode_UnionType) {
isize field_index = 0;
fields[field_index++] = make_entity_type_name(c->allocator, c->context.scope, empty_token, NULL);
gb_for_array(decl_index, decls) {
for_array(decl_index, decls) {
AstNode *decl = decls[decl_index];
if (decl->kind != AstNode_VarDecl) {
continue;
@@ -352,7 +352,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
ast_node(vd, VarDecl, decl);
Type *base_type = check_type(c, vd->type, NULL, cycle_checker);
gb_for_array(name_index, vd->names) {
for_array(name_index, vd->names) {
AstNode *name = vd->names[name_index];
Token name_token = name->Ident;
@@ -379,7 +379,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
}
} else {
isize field_index = 0;
gb_for_array(decl_index, decls) {
for_array(decl_index, decls) {
AstNode *decl = decls[decl_index];
if (decl->kind != AstNode_VarDecl) {
continue;
@@ -389,13 +389,13 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
Type *type = check_type(c, vd->type, NULL, cycle_checker);
if (vd->is_using) {
if (gb_array_count(vd->names) > 1) {
if (vd->names.count > 1) {
error(ast_node_token(vd->names[0]),
"Cannot apply `using` to more than one of the same type");
}
}
gb_for_array(name_index, vd->names) {
for_array(name_index, vd->names) {
AstNode *name = vd->names[name_index];
Token name_token = name->Ident;
@@ -424,7 +424,7 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
Token name_token = vd->names[0]->Ident;
if (is_type_indexable(t)) {
b32 ok = true;
gb_for_array(emi, entity_map.entries) {
for_array(emi, entity_map.entries) {
Entity *e = entity_map.entries[emi].value;
if (e->kind == Entity_Variable && e->Variable.anonymous) {
if (is_type_indexable(e->type)) {
@@ -492,15 +492,15 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, CycleChecke
isize field_count = 0;
isize other_field_count = 0;
gb_for_array(decl_index, st->decls) {
for_array(decl_index, st->decls) {
AstNode *decl = st->decls[decl_index];
switch (decl->kind) {
case_ast_node(vd, VarDecl, decl);
field_count += gb_array_count(vd->names);
field_count += vd->names.count;
case_end;
case_ast_node(cd, ConstDecl, decl);
other_field_count += gb_array_count(cd->names);
other_field_count += cd->names.count;
case_end;
case_ast_node(td, TypeDecl, decl);
@@ -554,15 +554,15 @@ void check_union_type(Checker *c, Type *union_type, AstNode *node, CycleChecker
isize field_count = 1;
isize other_field_count = 0;
gb_for_array(decl_index, ut->decls) {
for_array(decl_index, ut->decls) {
AstNode *decl = ut->decls[decl_index];
switch (decl->kind) {
case_ast_node(vd, VarDecl, decl);
field_count += gb_array_count(vd->names);
field_count += vd->names.count;
case_end;
case_ast_node(cd, ConstDecl, decl);
other_field_count += gb_array_count(cd->names);
other_field_count += cd->names.count;
case_end;
case_ast_node(td, TypeDecl, decl);
@@ -589,15 +589,15 @@ void check_raw_union_type(Checker *c, Type *union_type, AstNode *node, CycleChec
isize field_count = 0;
isize other_field_count = 0;
gb_for_array(decl_index, ut->decls) {
for_array(decl_index, ut->decls) {
AstNode *decl = ut->decls[decl_index];
switch (decl->kind) {
case_ast_node(vd, VarDecl, decl);
field_count += gb_array_count(vd->names);
field_count += vd->names.count;
case_end;
case_ast_node(cd, ConstDecl, decl);
other_field_count += gb_array_count(cd->names);
other_field_count += cd->names.count;
case_end;
case_ast_node(td, TypeDecl, decl);
@@ -661,7 +661,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
}
enum_type->Record.enum_base = base_type;
Entity **fields = gb_alloc_array(c->allocator, Entity *, gb_array_count(et->fields));
Entity **fields = gb_alloc_array(c->allocator, Entity *, et->fields.count);
isize field_index = 0;
ExactValue iota = make_exact_value_integer(-1);
i64 min_value = 0;
@@ -673,7 +673,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
}
Entity *blank_entity = make_entity_constant(c->allocator, c->context.scope, blank_token, constant_type, make_exact_value_integer(0));;
gb_for_array(i, et->fields) {
for_array(i, et->fields) {
AstNode *field = et->fields[i];
ast_node(f, FieldValue, field);
@@ -735,10 +735,10 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
add_entity_use(c, f->field, e);
}
gb_sort_array(fields, gb_array_count(et->fields), cmp_enum_order);
gb_sort_array(fields, et->fields.count, cmp_enum_order);
enum_type->Record.other_fields = fields;
enum_type->Record.other_field_count = gb_array_count(et->fields);
enum_type->Record.other_field_count = et->fields.count;
enum_type->Record.enum_count = make_entity_constant(c->allocator, NULL,
make_token_ident(make_string("count")), t_int, make_exact_value_integer(enum_type->Record.other_field_count));
@@ -749,29 +749,30 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
}
Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, b32 *is_variadic_) {
if (params == NULL || gb_array_count(params) == 0)
if (params.count == 0) {
return NULL;
}
b32 is_variadic = false;
Type *tuple = make_type_tuple(c->allocator);
isize variable_count = 0;
gb_for_array(i, params) {
for_array(i, params) {
AstNode *field = params[i];
ast_node(p, Parameter, field);
variable_count += gb_array_count(p->names);
variable_count += p->names.count;
}
Entity **variables = gb_alloc_array(c->allocator, Entity *, variable_count);
isize variable_index = 0;
gb_for_array(i, params) {
for_array(i, params) {
ast_node(p, Parameter, params[i]);
AstNode *type_expr = p->type;
if (type_expr) {
if (type_expr->kind == AstNode_Ellipsis) {
type_expr = type_expr->Ellipsis.expr;
if (i+1 == gb_array_count(params)) {
if (i+1 == params.count) {
is_variadic = true;
} else {
error(ast_node_token(params[i]), "Invalid AST: Invalid variadic parameter");
@@ -779,7 +780,7 @@ Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, b32 *is_va
}
Type *type = check_type(c, type_expr);
gb_for_array(j, p->names) {
for_array(j, p->names) {
AstNode *name = p->names[j];
if (name->kind == AstNode_Ident) {
Entity *param = make_entity_param(c->allocator, scope, name->Ident, type, p->is_using);
@@ -792,10 +793,10 @@ Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, b32 *is_va
}
}
if (is_variadic && gb_array_count(params) > 0) {
if (is_variadic && params.count > 0) {
// NOTE(bill): Change last variadic parameter to be a slice
// Custom Calling convention for variadic parameters
Entity *end = variables[gb_array_count(params)-1];
Entity *end = variables[params.count-1];
end->type = make_type_slice(c->allocator, end->type);
}
@@ -808,14 +809,14 @@ Type *check_get_params(Checker *c, Scope *scope, AstNodeArray params, b32 *is_va
}
Type *check_get_results(Checker *c, Scope *scope, AstNodeArray results) {
if (results == NULL || gb_array_count(results) == 0) {
if (results.count == 0) {
return NULL;
}
Type *tuple = make_type_tuple(c->allocator);
Entity **variables = gb_alloc_array(c->allocator, Entity *, gb_array_count(results));
Entity **variables = gb_alloc_array(c->allocator, Entity *, results.count);
isize variable_index = 0;
gb_for_array(i, results) {
for_array(i, results) {
AstNode *item = results[i];
Type *type = check_type(c, item);
Token token = ast_node_token(item);
@@ -826,7 +827,7 @@ Type *check_get_results(Checker *c, Scope *scope, AstNodeArray results) {
variables[variable_index++] = param;
}
tuple->Tuple.variables = variables;
tuple->Tuple.variable_count = gb_array_count(results);
tuple->Tuple.variable_count = results.count;
return tuple;
}
@@ -915,7 +916,7 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
#if 0
// TODO(bill): Fix cyclical dependancy checker
if (cycle_checker != NULL) {
gb_for_array(i, cycle_checker->path) {
for_array(i, cycle_checker->path) {
Entity *prev = cycle_checker->path[i];
if (prev == e) {
error(e->token, "Illegal declaration cycle for %.*s", LIT(e->token.string));
@@ -2270,15 +2271,17 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
BuiltinProc *bp = &builtin_procs[id];
{
char *err = NULL;
if (gb_array_count(ce->args) < bp->arg_count)
if (ce->args.count < bp->arg_count) {
err = "Too few";
if (gb_array_count(ce->args) > bp->arg_count && !bp->variadic)
} else if (ce->args.count > bp->arg_count && !bp->variadic) {
err = "Too many";
}
if (err) {
ast_node(proc, Ident, ce->proc);
error(ce->close, "`%s` arguments for `%.*s`, expected %td, got %td",
err, LIT(proc->string),
bp->arg_count, gb_array_count(ce->args));
bp->arg_count, ce->args.count);
return false;
}
}
@@ -2321,7 +2324,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
AstNode *len = ce->args[1];
AstNode *cap = NULL;
if (gb_array_count(ce->args) > 2) {
if (ce->args.count > 2) {
cap = ce->args[2];
}
@@ -2349,7 +2352,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
type_str);
return false;
}
if (ce->args[3] != NULL) {
if (ce->args.count > 3) {
error(ast_node_token(call),
"Too many arguments to `new_slice`, expected either 2 or 3");
return false;
@@ -2666,7 +2669,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
isize max_count = vector_type->Vector.count;
isize arg_count = 0;
gb_for_array(i, ce->args) {
for_array(i, ce->args) {
if (i == 0) continue;
AstNode *arg = ce->args[i];
Operand op = {};
@@ -2826,7 +2829,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
AstNode *len = ce->args[1];
AstNode *cap = NULL;
if (gb_array_count(ce->args) > 2) {
if (ce->args.count > 2) {
cap = ce->args[2];
}
@@ -2855,7 +2858,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
type_str);
return false;
}
if (ce->args[2] != NULL) {
if (ce->args.count > 3) {
error(ast_node_token(call),
"Too many arguments to `slice_ptr`, expected either 2 or 3");
return false;
@@ -3083,7 +3086,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
return;
}
if (gb_array_count(ce->args) == 0 && param_count == 0) {
if (ce->args.count == 0 && param_count == 0) {
return;
}
@@ -3091,14 +3094,14 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
defer (gb_temp_arena_memory_end(tmp));
isize operand_count = 0;
gbArray(Operand) operands;
gb_array_init_reserve(operands, c->tmp_allocator, 2*param_count);
Array<Operand> operands;
array_init(&operands, c->tmp_allocator, 2*param_count);
gb_for_array(i, ce->args) {
for_array(i, ce->args) {
Operand o = {};
check_multi_expr(c, &o, ce->args[i]);
if (o.type->kind != Type_Tuple) {
gb_array_append(operands, o);
array_add(&operands, o);
} else {
auto *tuple = &o.type->Tuple;
if (variadic && i >= param_count) {
@@ -3109,12 +3112,12 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
}
for (isize j = 0; j < tuple->variable_count; j++) {
o.type = tuple->variables[j]->type;
gb_array_append(operands, o);
array_add(&operands, o);
}
}
}
operand_count = gb_array_count(operands);
operand_count = operands.count;
i32 error_code = 0;
if (operand_count < param_count) {
error_code = -1;
@@ -3190,7 +3193,7 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) {
check_expr_or_type(c, operand, ce->proc);
if (operand->mode == Addressing_Invalid) {
gb_for_array(i, ce->args) {
for_array(i, ce->args) {
check_expr_base(c, operand, ce->args[i]);
}
operand->mode = Addressing_Invalid;
@@ -3342,9 +3345,10 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
Type *t = base_type(type);
switch (t->kind) {
case Type_Record: {
if (!is_type_struct(t))
if (!is_type_struct(t)) {
break;
if (cl->elems == NULL || gb_array_count(cl->elems) == 0) {
}
if (cl->elems.count == 0) {
break; // NOTE(bill): No need to init
}
{ // Checker values
@@ -3352,7 +3356,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
if (cl->elems[0]->kind == AstNode_FieldValue) {
b32 *fields_visited = gb_alloc_array(c->allocator, b32, field_count);
gb_for_array(i, cl->elems) {
for_array(i, cl->elems) {
AstNode *elem = cl->elems[i];
if (elem->kind != AstNode_FieldValue) {
error(ast_node_token(elem),
@@ -3376,7 +3380,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
continue;
}
if (gb_array_count(sel.index) > 1) {
if (sel.index.count > 1) {
error(ast_node_token(elem),
"Cannot assign to an anonymous field `%.*s` in a structure literal (at the moment)", LIT(name));
continue;
@@ -3401,7 +3405,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
check_assignment(c, o, field->type, make_string("structure literal"));
}
} else {
gb_for_array(index, cl->elems) {
for_array(index, cl->elems) {
AstNode *elem = cl->elems[index];
if (elem->kind == AstNode_FieldValue) {
error(ast_node_token(elem),
@@ -3422,8 +3426,8 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
check_assignment(c, o, field->type, make_string("structure literal"));
}
if (gb_array_count(cl->elems) < field_count) {
error(cl->close, "Too few values in structure literal, expected %td, got %td", field_count, gb_array_count(cl->elems));
if (cl->elems.count < field_count) {
error(cl->close, "Too few values in structure literal, expected %td, got %td", field_count, cl->elems.count);
}
}
}
@@ -3450,10 +3454,8 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
i64 max = 0;
isize index = 0;
isize elem_count = 0;
if (cl->elems != NULL) {
elem_count = gb_array_count(cl->elems);
}
isize elem_count = cl->elems.count;
for (; index < elem_count; index++) {
AstNode *e = cl->elems[index];
if (e->kind == AstNode_FieldValue) {
@@ -3871,7 +3873,7 @@ void check_expr_or_type(Checker *c, Operand *o, AstNode *e) {
gbString write_expr_to_string(gbString str, AstNode *node);
gbString write_params_to_string(gbString str, AstNodeArray params, char *sep) {
gb_for_array(i, params) {
for_array(i, params) {
ast_node(p, Parameter, params[i]);
if (i > 0) {
str = gb_string_appendc(str, sep);
@@ -3918,7 +3920,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
case_ast_node(cl, CompoundLit, node);
str = write_expr_to_string(str, cl->type);
str = gb_string_appendc(str, "{");
gb_for_array(i, cl->elems) {
for_array(i, cl->elems) {
if (i > 0) {
str = gb_string_appendc(str, ", ");
}
@@ -4021,7 +4023,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
if (p->is_using) {
str = gb_string_appendc(str, "using ");
}
gb_for_array(i, p->names) {
for_array(i, p->names) {
AstNode *name = p->names[i];
if (i > 0)
str = gb_string_appendc(str, ", ");
@@ -4036,7 +4038,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
str = write_expr_to_string(str, ce->proc);
str = gb_string_appendc(str, "(");
gb_for_array(i, ce->args) {
for_array(i, ce->args) {
AstNode *arg = ce->args[i];
if (i > 0) {
str = gb_string_appendc(str, ", ");
@@ -4056,7 +4058,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
str = gb_string_appendc(str, "struct ");
if (st->is_packed) str = gb_string_appendc(str, "#packed ");
if (st->is_ordered) str = gb_string_appendc(str, "#ordered ");
gb_for_array(i, st->decls) {
for_array(i, st->decls) {
if (i > 0) {
str = gb_string_appendc(str, "; ");
}
@@ -4068,7 +4070,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
case_ast_node(st, RawUnionType, node);
str = gb_string_appendc(str, "raw_union {");
gb_for_array(i, st->decls) {
for_array(i, st->decls) {
if (i > 0) {
str = gb_string_appendc(str, "; ");
}
@@ -4080,7 +4082,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
case_ast_node(st, UnionType, node);
str = gb_string_appendc(str, "union {");
gb_for_array(i, st->decls) {
for_array(i, st->decls) {
if (i > 0) {
str = gb_string_appendc(str, "; ");
}
+60 -60
View File
@@ -11,7 +11,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags);
void check_proc_decl(Checker *c, Entity *e, DeclInfo *d);
void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) {
if (stmts == NULL) {
if (stmts.count == 0) {
return;
}
@@ -22,14 +22,14 @@ void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) {
Entity *e;
DeclInfo *d;
};
gbArray(Delay) delayed_const; gb_array_init_reserve(delayed_const, c->tmp_allocator, gb_array_count(stmts));
gbArray(Delay) delayed_type; gb_array_init_reserve(delayed_type, c->tmp_allocator, gb_array_count(stmts));
Array<Delay> delayed_const; array_init(&delayed_const, c->tmp_allocator, stmts.count);
Array<Delay> delayed_type; array_init(&delayed_type, c->tmp_allocator, stmts.count);
gb_for_array(i, stmts) {
for_array(i, stmts) {
AstNode *node = stmts[i];
switch (node->kind) {
case_ast_node(cd, ConstDecl, node);
gb_for_array(i, cd->values) {
for_array(i, cd->values) {
AstNode *name = cd->names[i];
AstNode *value = cd->values[i];
ExactValue v = {ExactValue_Invalid};
@@ -44,11 +44,11 @@ void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) {
add_entity_and_decl_info(c, name, e, d);
Delay delay = {e, d};
gb_array_append(delayed_const, delay);
array_add(&delayed_const, delay);
}
isize lhs_count = gb_array_count(cd->names);
isize rhs_count = gb_array_count(cd->values);
isize lhs_count = cd->names.count;
isize rhs_count = cd->values.count;
if (rhs_count == 0 && cd->type == NULL) {
error(ast_node_token(node), "Missing type or initial expression");
@@ -67,28 +67,28 @@ void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) {
add_entity_and_decl_info(c, td->name, e, d);
Delay delay = {e, d};
gb_array_append(delayed_type, delay);
array_add(&delayed_type, delay);
case_end;
}
}
gb_for_array(i, delayed_type) {
for_array(i, delayed_type) {
check_entity_decl(c, delayed_type[i].e, delayed_type[i].d, NULL);
}
gb_for_array(i, delayed_const) {
for_array(i, delayed_const) {
check_entity_decl(c, delayed_const[i].e, delayed_const[i].d, NULL);
}
b32 ft_ok = (flags & Stmt_FallthroughAllowed) != 0;
u32 f = flags & (~Stmt_FallthroughAllowed);
gb_for_array(i, stmts) {
for_array(i, stmts) {
AstNode *n = stmts[i];
if (n->kind == AstNode_EmptyStmt) {
continue;
}
u32 new_flags = f;
if (ft_ok && i+1 == gb_array_count(stmts)) {
if (ft_ok && i+1 == stmts.count) {
new_flags |= Stmt_FallthroughAllowed;
}
check_stmt(c, n, new_flags);
@@ -101,7 +101,7 @@ b32 check_has_break(AstNode *stmt, b32 implicit);
b32 check_is_terminating_list(AstNodeArray stmts) {
// Iterate backwards
for (isize n = gb_array_count(stmts)-1; n >= 0; n--) {
for (isize n = stmts.count-1; n >= 0; n--) {
AstNode *stmt = stmts[n];
if (stmt->kind != AstNode_EmptyStmt) {
return check_is_terminating(stmt);
@@ -112,7 +112,7 @@ b32 check_is_terminating_list(AstNodeArray stmts) {
}
b32 check_has_break_list(AstNodeArray stmts, b32 implicit) {
gb_for_array(i, stmts) {
for_array(i, stmts) {
AstNode *stmt = stmts[i];
if (check_has_break(stmt, implicit)) {
return true;
@@ -182,10 +182,10 @@ b32 check_is_terminating(AstNode *node) {
case_ast_node(ms, MatchStmt, node);
b32 has_default = false;
gb_for_array(i, ms->body->BlockStmt.stmts) {
for_array(i, ms->body->BlockStmt.stmts) {
AstNode *clause = ms->body->BlockStmt.stmts[i];
ast_node(cc, CaseClause, clause);
if (cc->list == NULL) {
if (cc->list.count == 0) {
has_default = true;
}
if (!check_is_terminating_list(cc->stmts) ||
@@ -198,10 +198,10 @@ b32 check_is_terminating(AstNode *node) {
case_ast_node(ms, TypeMatchStmt, node);
b32 has_default = false;
gb_for_array(i, ms->body->BlockStmt.stmts) {
for_array(i, ms->body->BlockStmt.stmts) {
AstNode *clause = ms->body->BlockStmt.stmts[i];
ast_node(cc, CaseClause, clause);
if (cc->list == NULL) {
if (cc->list.count == 0) {
has_default = true;
}
if (!check_is_terminating_list(cc->stmts) ||
@@ -336,7 +336,7 @@ Type *check_init_variable(Checker *c, Entity *e, Operand *operand, String contex
}
void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArray inits, String context_name) {
if ((lhs == NULL || lhs_count == 0) && (inits == NULL || gb_array_count(inits) == 0)) {
if ((lhs == NULL || lhs_count == 0) && inits.count == 0) {
return;
}
@@ -345,26 +345,26 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra
// NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be
// an extra allocation
gbArray(Operand) operands;
gb_array_init_reserve(operands, c->tmp_allocator, 2*lhs_count);
Array<Operand> operands;
array_init(&operands, c->tmp_allocator, 2*lhs_count);
gb_for_array(i, inits) {
for_array(i, inits) {
AstNode *rhs = inits[i];
Operand o = {};
check_multi_expr(c, &o, rhs);
if (o.type->kind != Type_Tuple) {
gb_array_append(operands, o);
array_add(&operands, o);
} else {
auto *tuple = &o.type->Tuple;
for (isize j = 0; j < tuple->variable_count; j++) {
o.type = tuple->variables[j]->type;
gb_array_append(operands, o);
array_add(&operands, o);
}
}
}
isize rhs_count = gb_array_count(operands);
gb_for_array(i, operands) {
isize rhs_count = operands.count;
for_array(i, operands) {
if (operands[i].mode == Addressing_Invalid) {
rhs_count--;
}
@@ -498,7 +498,7 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
if (is_type_struct(t) || is_type_raw_union(t)) {
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
GB_ASSERT(found != NULL);
gb_for_array(i, (*found)->elements.entries) {
for_array(i, (*found)->elements.entries) {
Entity *f = (*found)->elements.entries[i].value;
if (f->kind == Entity_Variable) {
Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type);
@@ -696,8 +696,8 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
}
AstNodeArray inits;
gb_array_init_reserve(inits, c->allocator, 1);
gb_array_append(inits, init_expr);
array_init(&inits, c->allocator, 1);
array_add(&inits, init_expr);
check_init_variables(c, entities, entity_count, inits, make_string("variable declaration"));
}
@@ -746,11 +746,11 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc
void check_var_decl_node(Checker *c, AstNode *node) {
ast_node(vd, VarDecl, node);
isize entity_count = gb_array_count(vd->names);
isize entity_count = vd->names.count;
isize entity_index = 0;
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
gb_for_array(i, vd->names) {
for_array(i, vd->names) {
AstNode *name = vd->names[i];
Entity *entity = NULL;
if (name->kind == AstNode_Ident) {
@@ -803,7 +803,7 @@ void check_var_decl_node(Checker *c, AstNode *node) {
check_init_variables(c, entities, entity_count, vd->values, make_string("variable declaration"));
gb_for_array(i, vd->names) {
for_array(i, vd->names) {
if (entities[i] != NULL) {
add_entity(c, c->context.scope, vd->names[i], entities[i]);
}
@@ -911,7 +911,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
switch (as->op.kind) {
case Token_Eq: {
// a, b, c = 1, 2, 3; // Multisided
if (gb_array_count(as->lhs) == 0) {
if (as->lhs.count == 0) {
error(as->op, "Missing lhs in assignment statement");
return;
}
@@ -921,29 +921,29 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
// NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be
// an extra allocation
gbArray(Operand) operands;
gb_array_init_reserve(operands, c->tmp_allocator, 2 * gb_array_count(as->lhs));
Array<Operand> operands;
array_init(&operands, c->tmp_allocator, 2 * as->lhs.count);
gb_for_array(i, as->rhs) {
for_array(i, as->rhs) {
AstNode *rhs = as->rhs[i];
Operand o = {};
check_multi_expr(c, &o, rhs);
if (o.type->kind != Type_Tuple) {
gb_array_append(operands, o);
array_add(&operands, o);
} else {
auto *tuple = &o.type->Tuple;
for (isize j = 0; j < tuple->variable_count; j++) {
o.type = tuple->variables[j]->type;
gb_array_append(operands, o);
array_add(&operands, o);
}
}
}
isize lhs_count = gb_array_count(as->lhs);
isize rhs_count = gb_array_count(operands);
isize lhs_count = as->lhs.count;
isize rhs_count = operands.count;
isize operand_index = 0;
gb_for_array(i, as->lhs) {
for_array(i, as->lhs) {
AstNode *lhs = as->lhs[i];
check_assignment_variable(c, &operands[i], lhs);
}
@@ -955,7 +955,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
default: {
// a += 1; // Single-sided
Token op = as->op;
if (gb_array_count(as->lhs) != 1 || gb_array_count(as->rhs) != 1) {
if (as->lhs.count != 1 || as->rhs.count != 1) {
error(op, "Assignment operation `%.*s` requires single-valued expressions", LIT(op.string));
return;
}
@@ -1019,7 +1019,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
case_end;
case_ast_node(rs, ReturnStmt, node);
GB_ASSERT(gb_array_count(c->proc_stack) > 0);
GB_ASSERT(c->proc_stack.count > 0);
if (c->in_defer) {
error(rs->token, "You cannot `return` within a defer statement");
@@ -1028,7 +1028,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
}
Type *proc_type = c->proc_stack[gb_array_count(c->proc_stack)-1];
Type *proc_type = c->proc_stack[c->proc_stack.count-1];
isize result_count = 0;
if (proc_type->Proc.results) {
result_count = proc_type->Proc.results->Tuple.variable_count;
@@ -1040,13 +1040,13 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
auto *tuple = &proc_type->Proc.results->Tuple;
variables = tuple->variables;
}
if (gb_array_count(rs->results) == 0) {
if (rs->results.count == 0) {
error(ast_node_token(node), "Expected %td return values, got 0", result_count);
} else {
check_init_variables(c, variables, result_count,
rs->results, make_string("return statement"));
}
} else if (gb_array_count(rs->results) > 0) {
} else if (rs->results.count > 0) {
error(ast_node_token(rs->results[0]), "No return values expected");
}
case_end;
@@ -1099,12 +1099,12 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
// NOTE(bill): Check for multiple defaults
AstNode *first_default = NULL;
ast_node(bs, BlockStmt, ms->body);
gb_for_array(i, bs->stmts) {
for_array(i, bs->stmts) {
AstNode *stmt = bs->stmts[i];
AstNode *default_stmt = NULL;
if (stmt->kind == AstNode_CaseClause) {
ast_node(cc, CaseClause, stmt);
if (gb_array_count(cc->list) == 0) {
if (cc->list.count == 0) {
default_stmt = stmt;
}
} else {
@@ -1132,7 +1132,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
Map<TypeAndToken> seen = {}; // Multimap
map_init(&seen, gb_heap_allocator());
defer (map_destroy(&seen));
gb_for_array(i, bs->stmts) {
for_array(i, bs->stmts) {
AstNode *stmt = bs->stmts[i];
if (stmt->kind != AstNode_CaseClause) {
// NOTE(bill): error handled by above multiple default checker
@@ -1141,7 +1141,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
ast_node(cc, CaseClause, stmt);
gb_for_array(j, cc->list) {
for_array(j, cc->list) {
AstNode *expr = cc->list[j];
Operand y = {};
Operand z = {};
@@ -1206,7 +1206,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
check_open_scope(c, stmt);
u32 ft_flags = mod_flags;
if (i+1 < gb_array_count(bs->stmts)) {
if (i+1 < bs->stmts.count) {
ft_flags |= Stmt_FallthroughAllowed;
}
check_stmt_list(c, cc->stmts, ft_flags);
@@ -1237,12 +1237,12 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
// NOTE(bill): Check for multiple defaults
AstNode *first_default = NULL;
ast_node(bs, BlockStmt, ms->body);
gb_for_array(i, bs->stmts) {
for_array(i, bs->stmts) {
AstNode *stmt = bs->stmts[i];
AstNode *default_stmt = NULL;
if (stmt->kind == AstNode_CaseClause) {
ast_node(cc, CaseClause, stmt);
if (gb_array_count(cc->list) == 0) {
if (cc->list.count == 0) {
default_stmt = stmt;
}
} else {
@@ -1271,7 +1271,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
defer (map_destroy(&seen));
gb_for_array(i, bs->stmts) {
for_array(i, bs->stmts) {
AstNode *stmt = bs->stmts[i];
if (stmt->kind != AstNode_CaseClause) {
// NOTE(bill): error handled by above multiple default checker
@@ -1428,7 +1428,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
case Entity_ImportName: {
Scope *scope = e->ImportName.scope;
gb_for_array(i, scope->elements.entries) {
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) {
@@ -1459,7 +1459,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
if (is_type_struct(t) || is_type_raw_union(t)) {
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
GB_ASSERT(found != NULL);
gb_for_array(i, (*found)->elements.entries) {
for_array(i, (*found)->elements.entries) {
Entity *f = (*found)->elements.entries[i].value;
if (f->kind == Entity_Variable) {
Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type);
@@ -1485,12 +1485,12 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
case_end;
case_ast_node(vd, VarDecl, us->node);
if (gb_array_count(vd->names) > 1 && vd->type != NULL) {
if (vd->names.count > 1 && vd->type != NULL) {
error(us->token, "`using` can only be applied to one variable of the same type");
}
check_var_decl_node(c, us->node);
gb_for_array(name_index, vd->names) {
for_array(name_index, vd->names) {
AstNode *item = vd->names[name_index];
ast_node(i, Ident, item);
String name = i->string;
@@ -1499,7 +1499,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
if (is_type_struct(t) || is_type_raw_union(t)) {
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
GB_ASSERT(found != NULL);
gb_for_array(i, (*found)->elements.entries) {
for_array(i, (*found)->elements.entries) {
Entity *f = (*found)->elements.entries[i].value;
if (f->kind == Entity_Variable) {
Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type);
+12 -13
View File
@@ -777,12 +777,12 @@ gb_global i64 basic_type_sizes[] = {
struct Selection {
Entity *entity;
gbArray(isize) index;
Array<isize> index;
b32 indirect; // Set if there was a pointer deref anywhere down the line
};
Selection empty_selection = {};
Selection make_selection(Entity *entity, gbArray(isize) index, b32 indirect) {
Selection make_selection(Entity *entity, Array<isize> index, b32 indirect) {
Selection s = {entity, index, indirect};
return s;
}
@@ -790,10 +790,10 @@ Selection make_selection(Entity *entity, gbArray(isize) index, b32 indirect) {
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
if (s->index == NULL) {
gb_array_init(s->index, gb_heap_allocator());
if (s->index.data == NULL) {
array_init(&s->index, gb_heap_allocator());
}
gb_array_append(s->index, index);
array_add(&s->index, index);
}
gb_global Entity *entity__any_type_info = NULL;
@@ -918,7 +918,8 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ
String str = f->token.string;
if (field_name == str) {
return make_selection(f, NULL, i);
Selection sel = {f, {}, i};
return sel;
}
}
}
@@ -929,7 +930,8 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ
String str = f->token.string;
if (field_name == str) {
return make_selection(f, NULL, i);
Selection sel = {f, {}, i};
return sel;
}
}
@@ -958,10 +960,7 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ
}
if (f->Variable.anonymous) {
isize prev_count = 0;
if (sel.index != NULL) {
prev_count = gb_array_count(sel.index);
}
isize prev_count = sel.index.count;
selection_add_index(&sel, i); // HACK(bill): Leaky memory
sel = lookup_field(a, f->type, field_name, is_type, sel);
@@ -971,7 +970,7 @@ Selection lookup_field(gbAllocator a, Type *type_, String field_name, b32 is_typ
sel.indirect = true;
return sel;
}
gb_array_count(sel.index) = prev_count;
sel.index.count = prev_count;
}
}
}
@@ -1208,7 +1207,7 @@ i64 type_offset_of(BaseTypeSizes s, gbAllocator allocator, Type *t, isize index)
i64 type_offset_of_from_selection(BaseTypeSizes s, gbAllocator allocator, Type *t, Selection sel) {
i64 offset = 0;
for (isize i = 0; i < gb_array_count(sel.index); i++) {
for_array(i, sel.index) {
isize index = sel.index[i];
t = base_type(t);
if (t->kind == Type_Record && t->Record.kind == TypeRecord_Struct) {