mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 03:42:23 -07:00
Improve CheckerContext usage
This commit is contained in:
+15
-15
@@ -23,7 +23,7 @@ void populate_using_array_index(CheckerContext *ctx, Ast *node, AstField *field,
|
||||
tok.pos = ast_token(field->type).pos;
|
||||
}
|
||||
Entity *f = alloc_entity_array_elem(nullptr, tok, t->Array.elem, idx);
|
||||
add_entity(ctx->checker, ctx->scope, nullptr, f);
|
||||
add_entity(ctx, ctx->scope, nullptr, f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field
|
||||
error(e->token, "'%.*s' is already declared", LIT(name));
|
||||
}
|
||||
} else {
|
||||
add_entity(ctx->checker, ctx->scope, nullptr, f);
|
||||
add_entity(ctx, ctx->scope, nullptr, f);
|
||||
if (f->flags & EntityFlag_Using) {
|
||||
populate_using_entity_scope(ctx, node, field, f->type);
|
||||
}
|
||||
@@ -157,7 +157,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Array<Entity *> *fields
|
||||
Token name_token = name->Ident.token;
|
||||
|
||||
Entity *field = alloc_entity_field(ctx->scope, name_token, type, is_using, field_src_index);
|
||||
add_entity(ctx->checker, ctx->scope, name, field);
|
||||
add_entity(ctx, ctx->scope, name, field);
|
||||
array_add(fields, field);
|
||||
array_add(tags, p->tag.string);
|
||||
|
||||
@@ -483,7 +483,7 @@ Type *check_record_polymorphic_params(CheckerContext *ctx, Ast *polymorphic_para
|
||||
}
|
||||
|
||||
e->state = EntityState_Resolved;
|
||||
add_entity(ctx->checker, scope, name, e);
|
||||
add_entity(ctx, scope, name, e);
|
||||
array_add(&entities, e);
|
||||
}
|
||||
}
|
||||
@@ -795,7 +795,7 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast
|
||||
if (scope_lookup_current(ctx->scope, name) != nullptr) {
|
||||
error(ident, "'%.*s' is already declared in this enumeration", LIT(name));
|
||||
} else {
|
||||
add_entity(ctx->checker, ctx->scope, nullptr, e);
|
||||
add_entity(ctx, ctx->scope, nullptr, e);
|
||||
array_add(&fields, e);
|
||||
// TODO(bill): Should I add a use for the enum value?
|
||||
add_entity_use(ctx, field, e);
|
||||
@@ -1622,7 +1622,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
|
||||
}
|
||||
|
||||
param->state = EntityState_Resolved; // NOTE(bill): This should have be resolved whilst determining it
|
||||
add_entity(ctx->checker, scope, name, param);
|
||||
add_entity(ctx, scope, name, param);
|
||||
if (is_using) {
|
||||
add_entity_use(ctx, name, param);
|
||||
}
|
||||
@@ -1749,7 +1749,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) {
|
||||
param->flags |= EntityFlag_Result;
|
||||
param->Variable.param_value = param_value;
|
||||
array_add(&variables, param);
|
||||
add_entity(ctx->checker, scope, name, param);
|
||||
add_entity(ctx, scope, name, param);
|
||||
// NOTE(bill): Removes `declared but not used` when using -vet
|
||||
add_entity_use(ctx, name, param);
|
||||
}
|
||||
@@ -2243,7 +2243,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
|
||||
|
||||
Entity *new_field = alloc_entity_field(scope, token, field_type, false, cast(i32)i);
|
||||
soa_struct->Struct.fields[i] = new_field;
|
||||
add_entity(ctx->checker, scope, nullptr, new_field);
|
||||
add_entity(ctx, scope, nullptr, new_field);
|
||||
add_entity_use(ctx, nullptr, new_field);
|
||||
}
|
||||
|
||||
@@ -2277,7 +2277,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
|
||||
}
|
||||
Entity *new_field = alloc_entity_field(scope, old_field->token, field_type, false, old_field->Variable.field_src_index);
|
||||
soa_struct->Struct.fields[i] = new_field;
|
||||
add_entity(ctx->checker, scope, nullptr, new_field);
|
||||
add_entity(ctx, scope, nullptr, new_field);
|
||||
add_entity_use(ctx, nullptr, new_field);
|
||||
} else {
|
||||
soa_struct->Struct.fields[i] = old_field;
|
||||
@@ -2290,13 +2290,13 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
|
||||
if (soa_kind != StructSoa_Fixed) {
|
||||
Entity *len_field = alloc_entity_field(scope, empty_token, t_int, false, cast(i32)field_count+0);
|
||||
soa_struct->Struct.fields[field_count+0] = len_field;
|
||||
add_entity(ctx->checker, scope, nullptr, len_field);
|
||||
add_entity(ctx, scope, nullptr, len_field);
|
||||
add_entity_use(ctx, nullptr, len_field);
|
||||
|
||||
if (soa_kind == StructSoa_Dynamic) {
|
||||
Entity *cap_field = alloc_entity_field(scope, empty_token, t_int, false, cast(i32)field_count+1);
|
||||
soa_struct->Struct.fields[field_count+1] = cap_field;
|
||||
add_entity(ctx->checker, scope, nullptr, cap_field);
|
||||
add_entity(ctx, scope, nullptr, cap_field);
|
||||
add_entity_use(ctx, nullptr, cap_field);
|
||||
|
||||
Token token = {};
|
||||
@@ -2304,7 +2304,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
|
||||
init_mem_allocator(ctx->checker);
|
||||
Entity *allocator_field = alloc_entity_field(scope, token, t_allocator, false, cast(i32)field_count+2);
|
||||
soa_struct->Struct.fields[field_count+2] = allocator_field;
|
||||
add_entity(ctx->checker, scope, nullptr, allocator_field);
|
||||
add_entity(ctx, scope, nullptr, allocator_field);
|
||||
add_entity_use(ctx, nullptr, allocator_field);
|
||||
}
|
||||
}
|
||||
@@ -2312,7 +2312,7 @@ Type *make_soa_struct_internal(CheckerContext *ctx, Ast *array_typ_expr, Ast *el
|
||||
Token token = {};
|
||||
token.string = str_lit("Base_Type");
|
||||
Entity *base_type_entity = alloc_entity_type_name(scope, token, elem, EntityState_Resolved);
|
||||
add_entity(ctx->checker, scope, nullptr, base_type_entity);
|
||||
add_entity(ctx, scope, nullptr, base_type_entity);
|
||||
|
||||
add_type_info_type(ctx, soa_struct);
|
||||
|
||||
@@ -2425,8 +2425,8 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
|
||||
t->Generic.entity = e;
|
||||
e->TypeName.is_type_alias = true;
|
||||
e->state = EntityState_Resolved;
|
||||
add_entity(ctx->checker, ps, ident, e);
|
||||
add_entity(ctx->checker, s, ident, e);
|
||||
add_entity(ctx, ps, ident, e);
|
||||
add_entity(ctx, s, ident, e);
|
||||
} else {
|
||||
error(ident, "Invalid use of a polymorphic parameter '$%.*s'", LIT(token.string));
|
||||
*type = t_invalid;
|
||||
|
||||
Reference in New Issue
Block a user