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