mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-23 06:05:00 -07:00
Add SCOPED_TEMPORARY_BLOCK for temporary allocations within a block
This commit is contained in:
+15
-15
@@ -640,9 +640,10 @@ void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Oper
|
||||
HashKey key = hash_exact_value(operand.value);
|
||||
TypeAndToken *found = map_get(seen, key);
|
||||
if (found != nullptr) {
|
||||
SCOPED_TEMPORARY_BLOCK();
|
||||
|
||||
isize count = multi_map_count(seen, key);
|
||||
TypeAndToken *taps = gb_alloc_array(ctx->allocator, TypeAndToken, count);
|
||||
defer (gb_free(ctx->allocator, taps));
|
||||
TypeAndToken *taps = gb_alloc_array(temporary_allocator(), TypeAndToken, count);
|
||||
|
||||
multi_map_get_all(seen, key, taps);
|
||||
for (isize i = 0; i < count; i++) {
|
||||
@@ -859,7 +860,7 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
||||
token.pos = ast_token(ss->body).pos;
|
||||
token.string = str_lit("true");
|
||||
|
||||
x.expr = gb_alloc_item(ctx->allocator, Ast);
|
||||
x.expr = gb_alloc_item(permanent_allocator(), Ast);
|
||||
x.expr->kind = Ast_Ident;
|
||||
x.expr->Ident.token = token;
|
||||
}
|
||||
@@ -1025,8 +1026,8 @@ void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
||||
GB_ASSERT(is_type_enum(et));
|
||||
auto fields = et->Enum.fields;
|
||||
|
||||
auto unhandled = array_make<Entity *>(ctx->allocator, 0, fields.count);
|
||||
defer (array_free(&unhandled));
|
||||
SCOPED_TEMPORARY_BLOCK();
|
||||
auto unhandled = array_make<Entity *>(temporary_allocator(), 0, fields.count);
|
||||
|
||||
for_array(i, fields) {
|
||||
Entity *f = fields[i];
|
||||
@@ -1265,8 +1266,8 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
|
||||
GB_ASSERT(is_type_union(ut));
|
||||
auto variants = ut->Union.variants;
|
||||
|
||||
auto unhandled = array_make<Type *>(ctx->allocator, 0, variants.count);
|
||||
defer (array_free(&unhandled));
|
||||
SCOPED_TEMPORARY_BLOCK();
|
||||
auto unhandled = array_make<Type *>(temporary_allocator(), 0, variants.count);
|
||||
|
||||
for_array(i, variants) {
|
||||
Type *t = variants[i];
|
||||
@@ -1433,12 +1434,12 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCOPED_TEMPORARY_BLOCK();
|
||||
|
||||
// NOTE(bill): If there is a bad syntax error, rhs > lhs which would mean there would need to be
|
||||
// an extra allocation
|
||||
auto lhs_operands = array_make<Operand>(ctx->allocator, lhs_count);
|
||||
auto rhs_operands = array_make<Operand>(ctx->allocator, 0, 2*lhs_count);
|
||||
defer (array_free(&lhs_operands));
|
||||
defer (array_free(&rhs_operands));
|
||||
auto lhs_operands = array_make<Operand>(temporary_allocator(), lhs_count);
|
||||
auto rhs_operands = array_make<Operand>(temporary_allocator(), 0, 2*lhs_count);
|
||||
|
||||
for_array(i, as->lhs) {
|
||||
if (is_blank_ident(as->lhs[i])) {
|
||||
@@ -1462,8 +1463,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
}
|
||||
}
|
||||
|
||||
auto lhs_to_ignore = array_make<bool>(ctx->allocator, lhs_count);
|
||||
defer (array_free(&lhs_to_ignore));
|
||||
auto lhs_to_ignore = array_make<bool>(temporary_allocator(), lhs_count);
|
||||
|
||||
isize max = gb_min(lhs_count, rhs_count);
|
||||
// NOTE(bill, 2020-05-02): This is an utter hack to get these custom atom operations working
|
||||
@@ -1878,7 +1878,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
DeclInfo *d = decl_info_of_entity(e);
|
||||
GB_ASSERT(d == nullptr);
|
||||
add_entity(ctx->checker, ctx->scope, e->identifier, e);
|
||||
d = make_decl_info(ctx->allocator, ctx->scope, ctx->decl);
|
||||
d = make_decl_info(ctx->scope, ctx->decl);
|
||||
add_entity_and_decl_info(ctx, e->identifier, e, d);
|
||||
}
|
||||
|
||||
@@ -2036,7 +2036,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
|
||||
case_ast_node(vd, ValueDecl, node);
|
||||
if (vd->is_mutable) {
|
||||
Entity **entities = gb_alloc_array(ctx->allocator, Entity *, vd->names.count);
|
||||
Entity **entities = gb_alloc_array(permanent_allocator(), Entity *, vd->names.count);
|
||||
isize entity_count = 0;
|
||||
|
||||
isize new_name_count = 0;
|
||||
|
||||
Reference in New Issue
Block a user