mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-21 23:12:03 -07:00
More for_array(i, y) to for (x : y) translations
This commit is contained in:
+5
-10
@@ -96,8 +96,7 @@ gb_internal void check_or_else_expr_no_value_error(CheckerContext *c, String con
|
||||
gbString th = nullptr;
|
||||
if (type_hint != nullptr) {
|
||||
GB_ASSERT(bsrc->kind == Type_Union);
|
||||
for_array(i, bsrc->Union.variants) {
|
||||
Type *vt = bsrc->Union.variants[i];
|
||||
for (Type *vt : bsrc->Union.variants) {
|
||||
if (are_types_identical(vt, type_hint)) {
|
||||
th = type_to_string(type_hint);
|
||||
break;
|
||||
@@ -198,8 +197,7 @@ gb_internal void add_objc_proc_type(CheckerContext *c, Ast *call, Type *return_t
|
||||
{
|
||||
auto variables = array_make<Entity *>(permanent_allocator(), 0, param_types.count);
|
||||
|
||||
for_array(i, param_types) {
|
||||
Type *type = param_types[i];
|
||||
for (Type *type : param_types) {
|
||||
Entity *param = alloc_entity_param(scope, blank_token, type, false, true);
|
||||
array_add(&variables, param);
|
||||
}
|
||||
@@ -3071,8 +3069,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
bool first_is_field_value = (ce->args[0]->kind == Ast_FieldValue);
|
||||
|
||||
bool fail = false;
|
||||
for_array(i, ce->args) {
|
||||
Ast *arg = ce->args[i];
|
||||
for (Ast *arg : ce->args) {
|
||||
bool mix = false;
|
||||
if (first_is_field_value) {
|
||||
mix = arg->kind != Ast_FieldValue;
|
||||
@@ -3088,9 +3085,8 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
StringSet name_set = {};
|
||||
string_set_init(&name_set, 2*ce->args.count);
|
||||
|
||||
for_array(i, ce->args) {
|
||||
for (Ast *arg : ce->args) {
|
||||
String name = {};
|
||||
Ast *arg = ce->args[i];
|
||||
if (arg->kind == Ast_FieldValue) {
|
||||
Ast *ename = arg->FieldValue.field;
|
||||
if (!fail && ename->kind != Ast_Ident) {
|
||||
@@ -4987,8 +4983,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
|
||||
bool is_variant = false;
|
||||
|
||||
for_array(i, u->Union.variants) {
|
||||
Type *vt = u->Union.variants[i];
|
||||
for (Type *vt : u->Union.variants) {
|
||||
if (are_types_identical(v, vt)) {
|
||||
is_variant = true;
|
||||
break;
|
||||
|
||||
+11
-16
@@ -354,8 +354,7 @@ gb_internal void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr,
|
||||
|
||||
Type *t = base_type(e->type);
|
||||
if (t->kind == Type_Enum) {
|
||||
for_array(i, t->Enum.fields) {
|
||||
Entity *f = t->Enum.fields[i];
|
||||
for (Entity *f : t->Enum.fields) {
|
||||
if (f->kind != Entity_Constant) {
|
||||
continue;
|
||||
}
|
||||
@@ -1237,8 +1236,7 @@ gb_internal void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity,
|
||||
PtrSet<Entity *> entity_set = {};
|
||||
ptr_set_init(&entity_set, 2*pg->args.count);
|
||||
|
||||
for_array(i, pg->args) {
|
||||
Ast *arg = pg->args[i];
|
||||
for (Ast *arg : pg->args) {
|
||||
Entity *e = nullptr;
|
||||
Operand o = {};
|
||||
if (arg->kind == Ast_Ident) {
|
||||
@@ -1271,7 +1269,7 @@ gb_internal void check_proc_group_decl(CheckerContext *ctx, Entity *&pg_entity,
|
||||
|
||||
ptr_set_destroy(&entity_set);
|
||||
|
||||
for_array(j, pge->entities) {
|
||||
for (isize j = 0; j < pge->entities.count; j++) {
|
||||
Entity *p = pge->entities[j];
|
||||
if (p->type == t_invalid) {
|
||||
// NOTE(bill): This invalid overload has already been handled
|
||||
@@ -1462,8 +1460,7 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
||||
{
|
||||
if (type->Proc.param_count > 0) {
|
||||
TypeTuple *params = &type->Proc.params->Tuple;
|
||||
for_array(i, params->variables) {
|
||||
Entity *e = params->variables[i];
|
||||
for (Entity *e : params->variables) {
|
||||
if (e->kind != Entity_Variable) {
|
||||
continue;
|
||||
}
|
||||
@@ -1499,9 +1496,9 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
||||
}
|
||||
}
|
||||
|
||||
MUTEX_GUARD_BLOCK(ctx->scope->mutex) for_array(i, using_entities) {
|
||||
Entity *e = using_entities[i].e;
|
||||
Entity *uvar = using_entities[i].uvar;
|
||||
MUTEX_GUARD_BLOCK(ctx->scope->mutex) for (auto const &entry : using_entities) {
|
||||
Entity *e = entry.e;
|
||||
Entity *uvar = entry.uvar;
|
||||
Entity *prev = scope_insert_no_mutex(ctx->scope, uvar);
|
||||
if (prev != nullptr) {
|
||||
error(e->token, "Namespace collision while 'using' procedure argument '%.*s' of: %.*s", LIT(e->token.string), LIT(prev->token.string));
|
||||
@@ -1519,8 +1516,8 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
||||
|
||||
check_open_scope(ctx, body);
|
||||
{
|
||||
for_array(i, using_entities) {
|
||||
Entity *uvar = using_entities[i].uvar;
|
||||
for (auto const &entry : using_entities) {
|
||||
Entity *uvar = entry.uvar;
|
||||
Entity *prev = scope_insert(ctx->scope, uvar);
|
||||
gb_unused(prev);
|
||||
// NOTE(bill): Don't err here
|
||||
@@ -1537,12 +1534,10 @@ gb_internal bool check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *de
|
||||
|
||||
decl->defer_use_checked = true;
|
||||
|
||||
for_array(i, bs->stmts) {
|
||||
Ast *stmt = bs->stmts[i];
|
||||
for (Ast *stmt : bs->stmts) {
|
||||
if (stmt->kind == Ast_ValueDecl) {
|
||||
ast_node(vd, ValueDecl, stmt);
|
||||
for_array(j, vd->names) {
|
||||
Ast *name = vd->names[j];
|
||||
for (Ast *name : vd->names) {
|
||||
if (!is_blank_ident(name)) {
|
||||
if (name->kind == Ast_Ident) {
|
||||
GB_ASSERT(name->Ident.entity != nullptr);
|
||||
|
||||
+25
-48
@@ -931,16 +931,15 @@ gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags
|
||||
SeenMap seen = {}; // NOTE(bill): Multimap, Key: ExactValue
|
||||
defer (map_destroy(&seen));
|
||||
|
||||
for_array(stmt_index, bs->stmts) {
|
||||
Ast *stmt = bs->stmts[stmt_index];
|
||||
for (Ast *stmt : bs->stmts) {
|
||||
if (stmt->kind != Ast_CaseClause) {
|
||||
// NOTE(bill): error handled by above multiple default checker
|
||||
continue;
|
||||
}
|
||||
ast_node(cc, CaseClause, stmt);
|
||||
|
||||
for_array(j, cc->list) {
|
||||
Ast *expr = unparen_expr(cc->list[j]);
|
||||
for (Ast *expr : cc->list) {
|
||||
expr = unparen_expr(expr);
|
||||
|
||||
if (is_ast_range(expr)) {
|
||||
ast_node(be, BinaryExpr, expr);
|
||||
@@ -1052,8 +1051,7 @@ gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags
|
||||
|
||||
auto unhandled = array_make<Entity *>(temporary_allocator(), 0, fields.count);
|
||||
|
||||
for_array(i, fields) {
|
||||
Entity *f = fields[i];
|
||||
for (Entity *f : fields) {
|
||||
if (f->kind != Entity_Constant) {
|
||||
continue;
|
||||
}
|
||||
@@ -1072,8 +1070,7 @@ gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags
|
||||
error_no_newline(node, "Unhandled switch case: %.*s", LIT(unhandled[0]->token.string));
|
||||
} else {
|
||||
error(node, "Unhandled switch cases:");
|
||||
for_array(i, unhandled) {
|
||||
Entity *f = unhandled[i];
|
||||
for (Entity *f : unhandled) {
|
||||
error_line("\t%.*s\n", LIT(f->token.string));
|
||||
}
|
||||
}
|
||||
@@ -1154,8 +1151,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
// NOTE(bill): Check for multiple defaults
|
||||
Ast *first_default = nullptr;
|
||||
ast_node(bs, BlockStmt, ss->body);
|
||||
for_array(i, bs->stmts) {
|
||||
Ast *stmt = bs->stmts[i];
|
||||
for (Ast *stmt : bs->stmts) {
|
||||
Ast *default_stmt = nullptr;
|
||||
if (stmt->kind == Ast_CaseClause) {
|
||||
ast_node(cc, CaseClause, stmt);
|
||||
@@ -1186,8 +1182,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
PtrSet<Type *> seen = {};
|
||||
defer (ptr_set_destroy(&seen));
|
||||
|
||||
for_array(i, bs->stmts) {
|
||||
Ast *stmt = bs->stmts[i];
|
||||
for (Ast *stmt : bs->stmts) {
|
||||
if (stmt->kind != Ast_CaseClause) {
|
||||
// NOTE(bill): error handled by above multiple default checker
|
||||
continue;
|
||||
@@ -1198,8 +1193,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
Type *bt = base_type(type_deref(x.type));
|
||||
|
||||
Type *case_type = nullptr;
|
||||
for_array(type_index, cc->list) {
|
||||
Ast *type_expr = cc->list[type_index];
|
||||
for (Ast *type_expr : cc->list) {
|
||||
if (type_expr != nullptr) { // Otherwise it's a default expression
|
||||
Operand y = {};
|
||||
check_expr_or_type(ctx, &y, type_expr);
|
||||
@@ -1213,8 +1207,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
if (switch_kind == TypeSwitch_Union) {
|
||||
GB_ASSERT(is_type_union(bt));
|
||||
bool tag_type_found = false;
|
||||
for_array(j, bt->Union.variants) {
|
||||
Type *vt = bt->Union.variants[j];
|
||||
for (Type *vt : bt->Union.variants) {
|
||||
if (are_types_identical(vt, y.type)) {
|
||||
tag_type_found = true;
|
||||
break;
|
||||
@@ -1288,8 +1281,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
|
||||
auto unhandled = array_make<Type *>(temporary_allocator(), 0, variants.count);
|
||||
|
||||
for_array(i, variants) {
|
||||
Type *t = variants[i];
|
||||
for (Type *t : variants) {
|
||||
if (!type_ptr_set_exists(&seen, t)) {
|
||||
array_add(&unhandled, t);
|
||||
}
|
||||
@@ -1302,8 +1294,7 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_
|
||||
gb_string_free(s);
|
||||
} else {
|
||||
error_no_newline(node, "Unhandled switch cases:\n");
|
||||
for_array(i, unhandled) {
|
||||
Type *t = unhandled[i];
|
||||
for (Type *t : unhandled) {
|
||||
gbString s = type_to_string(t);
|
||||
error_line("\t%s\n", s);
|
||||
gb_string_free(s);
|
||||
@@ -1340,8 +1331,7 @@ gb_internal void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) {
|
||||
|
||||
isize stmt_count = 0;
|
||||
Ast *the_stmt = nullptr;
|
||||
for_array(i, bs->stmts) {
|
||||
Ast *stmt = bs->stmts[i];
|
||||
for (Ast *stmt : bs->stmts) {
|
||||
GB_ASSERT(stmt != nullptr);
|
||||
switch (stmt->kind) {
|
||||
case_ast_node(es, EmptyStmt, stmt);
|
||||
@@ -1359,8 +1349,7 @@ gb_internal void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) {
|
||||
|
||||
if (stmt_count == 1) {
|
||||
if (the_stmt->kind == Ast_ValueDecl) {
|
||||
for_array(i, the_stmt->ValueDecl.names) {
|
||||
Ast *name = the_stmt->ValueDecl.names[i];
|
||||
for (Ast *name : the_stmt->ValueDecl.names) {
|
||||
if (name->kind != Ast_Ident) {
|
||||
continue;
|
||||
}
|
||||
@@ -1376,8 +1365,8 @@ gb_internal void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) {
|
||||
|
||||
gb_internal bool all_operands_valid(Array<Operand> const &operands) {
|
||||
if (any_errors()) {
|
||||
for_array(i, operands) {
|
||||
if (operands[i].type == t_invalid) {
|
||||
for (Operand const &o : operands) {
|
||||
if (o.type == t_invalid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1548,16 +1537,9 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
|
||||
check_assignment_arguments(ctx, lhs_operands, &rhs_operands, as->rhs);
|
||||
|
||||
isize rhs_count = rhs_operands.count;
|
||||
for_array(i, rhs_operands) {
|
||||
if (rhs_operands[i].mode == Addressing_Invalid) {
|
||||
// TODO(bill): Should I ignore invalid parameters?
|
||||
// rhs_count--;
|
||||
}
|
||||
}
|
||||
|
||||
auto lhs_to_ignore = array_make<bool>(temporary_allocator(), lhs_count);
|
||||
|
||||
isize rhs_count = rhs_operands.count;
|
||||
isize max = gb_min(lhs_count, rhs_count);
|
||||
for (isize i = 0; i < max; i++) {
|
||||
if (lhs_to_ignore[i]) {
|
||||
@@ -1856,8 +1838,8 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
break;
|
||||
}
|
||||
|
||||
for_array(ti, t->Tuple.variables) {
|
||||
array_add(&vals, t->Tuple.variables[ti]->type);
|
||||
for (Entity *e : t->Tuple.variables) {
|
||||
array_add(&vals, e->type);
|
||||
}
|
||||
|
||||
if (rs->vals.count > 1 && rs->vals[1] != nullptr && count < 3) {
|
||||
@@ -1976,8 +1958,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
}
|
||||
}
|
||||
|
||||
for_array(i, entities) {
|
||||
Entity *e = entities[i];
|
||||
for (Entity *e : entities) {
|
||||
DeclInfo *d = decl_info_of_entity(e);
|
||||
GB_ASSERT(d == nullptr);
|
||||
add_entity(ctx, ctx->scope, e->identifier, e);
|
||||
@@ -2091,8 +2072,8 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
error(us->token, "Empty 'using' list");
|
||||
return;
|
||||
}
|
||||
for_array(i, us->list) {
|
||||
Ast *expr = unparen_expr(us->list[i]);
|
||||
for (Ast *expr : us->list) {
|
||||
expr = unparen_expr(expr);
|
||||
Entity *e = nullptr;
|
||||
|
||||
bool is_selector = false;
|
||||
@@ -2132,8 +2113,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
check_decl_attributes(&c, fb->attributes, foreign_block_decl_attribute, nullptr);
|
||||
|
||||
ast_node(block, BlockStmt, fb->body);
|
||||
for_array(i, block->stmts) {
|
||||
Ast *decl = block->stmts[i];
|
||||
for (Ast *decl : block->stmts) {
|
||||
if (decl->kind == Ast_ValueDecl && decl->ValueDecl.is_mutable) {
|
||||
check_stmt(&c, decl, flags);
|
||||
}
|
||||
@@ -2146,8 +2126,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
isize entity_count = 0;
|
||||
|
||||
isize new_name_count = 0;
|
||||
for_array(i, vd->names) {
|
||||
Ast *name = vd->names[i];
|
||||
for (Ast *name : vd->names) {
|
||||
Entity *entity = nullptr;
|
||||
if (name->kind != Ast_Ident) {
|
||||
error(name, "A variable declaration must be an identifier");
|
||||
@@ -2193,8 +2172,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
begin_error_block();
|
||||
error(node, "No new declarations on the left hand side");
|
||||
bool all_underscore = true;
|
||||
for_array(i, vd->names) {
|
||||
Ast *name = vd->names[i];
|
||||
for (Ast *name : vd->names) {
|
||||
if (name->kind == Ast_Ident) {
|
||||
if (!is_blank_ident(name)) {
|
||||
all_underscore = false;
|
||||
@@ -2388,8 +2366,7 @@ gb_internal void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags)
|
||||
} else {
|
||||
// constant value declaration
|
||||
// NOTE(bill): Check `_` declarations
|
||||
for_array(i, vd->names) {
|
||||
Ast *name = vd->names[i];
|
||||
for (Ast *name : vd->names) {
|
||||
if (is_blank_ident(name)) {
|
||||
Entity *e = name->Ident.entity;
|
||||
DeclInfo *d = decl_info_of_entity(e);
|
||||
|
||||
@@ -240,11 +240,10 @@ gb_internal lbValue lb_equal_proc_for_type(lbModule *m, Type *type) {
|
||||
LLVMValueRef v_switch = LLVMBuildSwitch(p->builder, left_tag.value, block_false->block, cast(unsigned)type->Union.variants.count);
|
||||
|
||||
|
||||
for_array(i, type->Union.variants) {
|
||||
for (Type *v : type->Union.variants) {
|
||||
lbBlock *case_block = lb_create_block(p, "bcase");
|
||||
lb_start_block(p, case_block);
|
||||
|
||||
Type *v = type->Union.variants[i];
|
||||
lbValue case_tag = lb_const_union_tag(p->module, type, v);
|
||||
|
||||
Type *vp = alloc_type_pointer(v);
|
||||
@@ -374,11 +373,10 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) {
|
||||
|
||||
LLVMValueRef v_switch = LLVMBuildSwitch(p->builder, tag.value, end_block->block, cast(unsigned)type->Union.variants.count);
|
||||
|
||||
for_array(i, type->Union.variants) {
|
||||
for (Type *v : type->Union.variants) {
|
||||
lbBlock *case_block = lb_create_block(p, "bcase");
|
||||
lb_start_block(p, case_block);
|
||||
|
||||
Type *v = type->Union.variants[i];
|
||||
lbValue case_tag = lb_const_union_tag(p->module, type, v);
|
||||
|
||||
lbValue variant_hasher = lb_hasher_proc_for_type(m, v);
|
||||
@@ -2235,8 +2233,7 @@ gb_internal void lb_generate_code(lbGenerator *gen) {
|
||||
|
||||
for (auto const &entry : gen->modules) {
|
||||
lbModule *m = entry.value;
|
||||
for_array(i, m->info->required_foreign_imports_through_force) {
|
||||
Entity *e = m->info->required_foreign_imports_through_force[i];
|
||||
for (Entity *e : m->info->required_foreign_imports_through_force) {
|
||||
lb_add_foreign_library_path(m, e);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,7 @@ gb_internal lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, As
|
||||
GB_ASSERT(incoming_values.count > 0);
|
||||
|
||||
LLVMTypeRef phi_type = nullptr;
|
||||
for_array(i, incoming_values) {
|
||||
LLVMValueRef incoming_value = incoming_values[i];
|
||||
for (LLVMValueRef incoming_value : incoming_values) {
|
||||
if (!LLVMIsConstant(incoming_value)) {
|
||||
phi_type = LLVMTypeOf(incoming_value);
|
||||
break;
|
||||
@@ -1921,8 +1920,7 @@ gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
}
|
||||
|
||||
if (is_type_union(dst)) {
|
||||
for_array(i, dst->Union.variants) {
|
||||
Type *vt = dst->Union.variants[i];
|
||||
for (Type *vt : dst->Union.variants) {
|
||||
if (are_types_identical(vt, src_type)) {
|
||||
lbAddr parent = lb_add_local_generated(p, t, true);
|
||||
lb_emit_store_union_variant(p, parent.addr, value, vt);
|
||||
@@ -3596,8 +3594,7 @@ gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *
|
||||
}
|
||||
}
|
||||
gb_internal void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLitElemTempData> const &temp_data) {
|
||||
for_array(i, temp_data) {
|
||||
auto td = temp_data[i];
|
||||
for (auto const &td : temp_data) {
|
||||
if (td.value.value != nullptr) {
|
||||
if (td.elem_length > 0) {
|
||||
auto loop_data = lb_loop_start(p, cast(isize)td.elem_length, t_i32);
|
||||
@@ -4129,8 +4126,7 @@ gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
lbValue err = lb_dynamic_map_reserve(p, v.addr, 2*cl->elems.count, pos);
|
||||
gb_unused(err);
|
||||
|
||||
for_array(field_index, cl->elems) {
|
||||
Ast *elem = cl->elems[field_index];
|
||||
for (Ast *elem : cl->elems) {
|
||||
ast_node(fv, FieldValue, elem);
|
||||
|
||||
lbValue key = lb_build_expr(p, fv->field);
|
||||
@@ -4304,8 +4300,7 @@ gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
lb_addr_store(p, v, lb_const_value(p->module, type, exact_value_compound(expr)));
|
||||
|
||||
lbValue lower = lb_const_value(p->module, t_int, exact_value_i64(bt->BitSet.lower));
|
||||
for_array(i, cl->elems) {
|
||||
Ast *elem = cl->elems[i];
|
||||
for (Ast *elem : cl->elems) {
|
||||
GB_ASSERT(elem->kind != Ast_FieldValue);
|
||||
|
||||
if (lb_is_elem_const(elem, et)) {
|
||||
@@ -4359,8 +4354,7 @@ gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
|
||||
// TODO(bill): reduce the need for individual `insertelement` if a `shufflevector`
|
||||
// might be a better option
|
||||
for_array(i, temp_data) {
|
||||
auto td = temp_data[i];
|
||||
for (auto const &td : temp_data) {
|
||||
if (td.value.value != nullptr) {
|
||||
if (td.elem_length > 0) {
|
||||
for (i64 k = 0; k < td.elem_length; k++) {
|
||||
|
||||
+30
-44
@@ -7,8 +7,7 @@ gb_internal void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd)
|
||||
|
||||
static i32 global_guid = 0;
|
||||
|
||||
for_array(i, vd->names) {
|
||||
Ast *ident = vd->names[i];
|
||||
for (Ast *ident : vd->names) {
|
||||
GB_ASSERT(ident->kind == Ast_Ident);
|
||||
Entity *e = entity_of_node(ident);
|
||||
GB_ASSERT(e != nullptr);
|
||||
@@ -106,8 +105,7 @@ gb_internal void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd)
|
||||
|
||||
|
||||
gb_internal void lb_build_stmt_list(lbProcedure *p, Slice<Ast *> const &stmts) {
|
||||
for_array(i, stmts) {
|
||||
Ast *stmt = stmts[i];
|
||||
for (Ast *stmt : stmts) {
|
||||
switch (stmt->kind) {
|
||||
case_ast_node(vd, ValueDecl, stmt);
|
||||
lb_build_constant_value_decl(p, vd);
|
||||
@@ -118,8 +116,8 @@ gb_internal void lb_build_stmt_list(lbProcedure *p, Slice<Ast *> const &stmts) {
|
||||
case_end;
|
||||
}
|
||||
}
|
||||
for_array(i, stmts) {
|
||||
lb_build_stmt(p, stmts[i]);
|
||||
for (Ast *stmt : stmts) {
|
||||
lb_build_stmt(p, stmt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +127,9 @@ gb_internal lbBranchBlocks lb_lookup_branch_blocks(lbProcedure *p, Ast *ident) {
|
||||
GB_ASSERT(ident->kind == Ast_Ident);
|
||||
Entity *e = entity_of_node(ident);
|
||||
GB_ASSERT(e->kind == Entity_Label);
|
||||
for_array(i, p->branch_blocks) {
|
||||
lbBranchBlocks *b = &p->branch_blocks[i];
|
||||
if (b->label == e->Label.node) {
|
||||
return *b;
|
||||
for (lbBranchBlocks const &b : p->branch_blocks) {
|
||||
if (b.label == e->Label.node) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,13 +150,12 @@ gb_internal lbTargetList *lb_push_target_list(lbProcedure *p, Ast *label, lbBloc
|
||||
if (label != nullptr) { // Set label blocks
|
||||
GB_ASSERT(label->kind == Ast_Label);
|
||||
|
||||
for_array(i, p->branch_blocks) {
|
||||
lbBranchBlocks *b = &p->branch_blocks[i];
|
||||
GB_ASSERT(b->label != nullptr && label != nullptr);
|
||||
GB_ASSERT(b->label->kind == Ast_Label);
|
||||
if (b->label == label) {
|
||||
b->break_ = break_;
|
||||
b->continue_ = continue_;
|
||||
for (lbBranchBlocks &b : p->branch_blocks) {
|
||||
GB_ASSERT(b.label != nullptr && label != nullptr);
|
||||
GB_ASSERT(b.label->kind == Ast_Label);
|
||||
if (b.label == label) {
|
||||
b.break_ = break_;
|
||||
b.continue_ = continue_;
|
||||
return tl;
|
||||
}
|
||||
}
|
||||
@@ -1095,8 +1091,7 @@ gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, boo
|
||||
}
|
||||
|
||||
ast_node(body, BlockStmt, ss->body);
|
||||
for_array(i, body->stmts) {
|
||||
Ast *clause = body->stmts[i];
|
||||
for (Ast *clause : body->stmts) {
|
||||
ast_node(cc, CaseClause, clause);
|
||||
|
||||
if (cc->list.count == 0) {
|
||||
@@ -1104,8 +1099,8 @@ gb_internal bool lb_switch_stmt_can_be_trivial_jump_table(AstSwitchStmt *ss, boo
|
||||
continue;
|
||||
}
|
||||
|
||||
for_array(j, cc->list) {
|
||||
Ast *expr = unparen_expr(cc->list[j]);
|
||||
for (Ast *expr : cc->list) {
|
||||
expr = unparen_expr(expr);
|
||||
if (is_ast_range(expr)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1166,8 +1161,7 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *
|
||||
LLVMValueRef switch_instr = nullptr;
|
||||
if (is_trivial) {
|
||||
isize num_cases = 0;
|
||||
for_array(i, body->stmts) {
|
||||
Ast *clause = body->stmts[i];
|
||||
for (Ast *clause : body->stmts) {
|
||||
ast_node(cc, CaseClause, clause);
|
||||
num_cases += cc->list.count;
|
||||
}
|
||||
@@ -1204,8 +1198,8 @@ gb_internal void lb_build_switch_stmt(lbProcedure *p, AstSwitchStmt *ss, Scope *
|
||||
}
|
||||
|
||||
lbBlock *next_cond = nullptr;
|
||||
for_array(j, cc->list) {
|
||||
Ast *expr = unparen_expr(cc->list[j]);
|
||||
for (Ast *expr : cc->list) {
|
||||
expr = unparen_expr(expr);
|
||||
|
||||
if (switch_instr != nullptr) {
|
||||
lbValue on_val = {};
|
||||
@@ -1384,8 +1378,7 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
|
||||
lbBlock *default_block = nullptr;
|
||||
isize num_cases = 0;
|
||||
|
||||
for_array(i, body->stmts) {
|
||||
Ast *clause = body->stmts[i];
|
||||
for (Ast *clause : body->stmts) {
|
||||
ast_node(cc, CaseClause, clause);
|
||||
num_cases += cc->list.count;
|
||||
if (cc->list.count == 0) {
|
||||
@@ -1405,8 +1398,7 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
|
||||
switch_instr = LLVMBuildSwitch(p->builder, tag.value, else_block->block, cast(unsigned)num_cases);
|
||||
}
|
||||
|
||||
for_array(i, body->stmts) {
|
||||
Ast *clause = body->stmts[i];
|
||||
for (Ast *clause : body->stmts) {
|
||||
ast_node(cc, CaseClause, clause);
|
||||
lb_open_scope(p, cc->scope);
|
||||
if (cc->list.count == 0) {
|
||||
@@ -1420,9 +1412,8 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
|
||||
if (p->debug_info != nullptr) {
|
||||
LLVMSetCurrentDebugLocation2(p->builder, lb_debug_location_from_ast(p, clause));
|
||||
}
|
||||
Type *case_type = nullptr;
|
||||
for_array(type_index, cc->list) {
|
||||
case_type = type_of_expr(cc->list[type_index]);
|
||||
for (Ast *type_expr : cc->list) {
|
||||
Type *case_type = type_of_expr(type_expr);
|
||||
lbValue on_val = {};
|
||||
if (switch_kind == TypeSwitch_Union) {
|
||||
Type *ut = base_type(type_deref(parent.type));
|
||||
@@ -1538,8 +1529,8 @@ gb_internal void lb_append_tuple_values(lbProcedure *p, Array<lbValue> *dst_valu
|
||||
if (t->kind == Type_Tuple) {
|
||||
lbTupleFix *tf = map_get(&p->tuple_fix_map, src_value.value);
|
||||
if (tf) {
|
||||
for_array(j, tf->values) {
|
||||
array_add(dst_values, tf->values[j]);
|
||||
for (lbValue const &value : tf->values) {
|
||||
array_add(dst_values, value);
|
||||
}
|
||||
} else {
|
||||
for_array(i, t->Tuple.variables) {
|
||||
@@ -1560,8 +1551,7 @@ gb_internal void lb_build_assignment(lbProcedure *p, Array<lbAddr> &lvals, Slice
|
||||
|
||||
auto inits = array_make<lbValue>(permanent_allocator(), 0, lvals.count);
|
||||
|
||||
for_array(i, values) {
|
||||
Ast *rhs = values[i];
|
||||
for (Ast *rhs : values) {
|
||||
lbValue init = lb_build_expr(p, rhs);
|
||||
lb_append_tuple_values(p, &inits, init);
|
||||
}
|
||||
@@ -1971,8 +1961,7 @@ gb_internal void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr
|
||||
auto indices_handled = slice_make<bool>(temporary_allocator(), bt->Array.count);
|
||||
auto indices = slice_make<i32>(temporary_allocator(), bt->Array.count);
|
||||
i32 index_count = 0;
|
||||
for_array(i, lhs.swizzle_large.indices) {
|
||||
i32 index = lhs.swizzle_large.indices[i];
|
||||
for (i32 index : lhs.swizzle_large.indices) {
|
||||
if (indices_handled[index]) {
|
||||
continue;
|
||||
}
|
||||
@@ -2049,8 +2038,7 @@ gb_internal void lb_build_assign_stmt(lbProcedure *p, AstAssignStmt *as) {
|
||||
if (as->op.kind == Token_Eq) {
|
||||
auto lvals = array_make<lbAddr>(permanent_allocator(), 0, as->lhs.count);
|
||||
|
||||
for_array(i, as->lhs) {
|
||||
Ast *lhs = as->lhs[i];
|
||||
for (Ast *lhs : as->lhs) {
|
||||
lbAddr lval = {};
|
||||
if (!is_blank_ident(lhs)) {
|
||||
lval = lb_build_addr(p, lhs);
|
||||
@@ -2185,8 +2173,7 @@ gb_internal void lb_build_stmt(lbProcedure *p, Ast *node) {
|
||||
|
||||
bool is_static = false;
|
||||
if (vd->names.count > 0) {
|
||||
for_array(i, vd->names) {
|
||||
Ast *name = vd->names[i];
|
||||
for (Ast *name : vd->names) {
|
||||
if (!is_blank_ident(name)) {
|
||||
GB_ASSERT(name->kind == Ast_Ident);
|
||||
Entity *e = entity_of_node(name);
|
||||
@@ -2208,8 +2195,7 @@ gb_internal void lb_build_stmt(lbProcedure *p, Ast *node) {
|
||||
|
||||
auto lvals = array_make<lbAddr>(permanent_allocator(), 0, vd->names.count);
|
||||
|
||||
for_array(i, vd->names) {
|
||||
Ast *name = vd->names[i];
|
||||
for (Ast *name : vd->names) {
|
||||
lbAddr lval = {};
|
||||
if (!is_blank_ident(name)) {
|
||||
Entity *e = entity_of_node(name);
|
||||
|
||||
Reference in New Issue
Block a user