mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 17:32:22 -07:00
Allow for entity grouping in structs and procedure signatures with the Odin doc-format
This commit is contained in:
@@ -109,11 +109,14 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
|
||||
}
|
||||
|
||||
i32 field_src_index = 0;
|
||||
i32 field_group_index = -1;
|
||||
for_array(i, params) {
|
||||
Ast *param = params[i];
|
||||
if (param->kind != Ast_Field) {
|
||||
continue;
|
||||
}
|
||||
field_group_index += 1;
|
||||
|
||||
ast_node(p, Field, param);
|
||||
Ast *type_expr = p->type;
|
||||
Type *type = nullptr;
|
||||
@@ -152,6 +155,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
|
||||
|
||||
Entity *field = alloc_entity_field(ctx->scope, name_token, type, is_using, field_src_index);
|
||||
add_entity(ctx, ctx->scope, name, field);
|
||||
field->Variable.field_group_index = field_group_index;
|
||||
array_add(&fields_array, field);
|
||||
String tag = p->tag.string;
|
||||
if (tag.len != 0 && !unquote_string(permanent_allocator(), &tag, 0, tag.text[0] == '`')) {
|
||||
@@ -1366,11 +1370,13 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
|
||||
isize variadic_index = -1;
|
||||
bool is_c_vararg = false;
|
||||
auto variables = array_make<Entity *>(permanent_allocator(), 0, variable_count);
|
||||
i32 field_group_index = -1;
|
||||
for_array(i, params) {
|
||||
Ast *param = params[i];
|
||||
if (param->kind != Ast_Field) {
|
||||
continue;
|
||||
}
|
||||
field_group_index += 1;
|
||||
ast_node(p, Field, param);
|
||||
Ast *type_expr = unparen_expr(p->type);
|
||||
Type *type = nullptr;
|
||||
@@ -1671,9 +1677,11 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
|
||||
}
|
||||
|
||||
param = alloc_entity_const_param(scope, name->Ident.token, type, poly_const, is_type_polymorphic(type));
|
||||
param->Constant.field_group_index = field_group_index;
|
||||
} else {
|
||||
param = alloc_entity_param(scope, name->Ident.token, type, is_using, true);
|
||||
param->Variable.param_value = param_value;
|
||||
param->Variable.field_group_index = field_group_index;
|
||||
}
|
||||
}
|
||||
if (p->flags&FieldFlag_no_alias) {
|
||||
@@ -1767,7 +1775,10 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) {
|
||||
}
|
||||
|
||||
auto variables = array_make<Entity *>(permanent_allocator(), 0, variable_count);
|
||||
i32 field_group_index = -1;
|
||||
for_array(i, results) {
|
||||
field_group_index += 1;
|
||||
|
||||
ast_node(field, Field, results[i]);
|
||||
Ast *default_value = unparen_expr(field->default_value);
|
||||
ParameterValue param_value = {};
|
||||
@@ -1798,6 +1809,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) {
|
||||
token.string = str_lit("");
|
||||
Entity *param = alloc_entity_param(scope, token, type, false, false);
|
||||
param->Variable.param_value = param_value;
|
||||
param->Variable.field_group_index = -1;
|
||||
array_add(&variables, param);
|
||||
} else {
|
||||
for_array(j, field->names) {
|
||||
@@ -1821,6 +1833,7 @@ Type *check_get_results(CheckerContext *ctx, Scope *scope, Ast *_results) {
|
||||
Entity *param = alloc_entity_param(scope, token, type, false, false);
|
||||
param->flags |= EntityFlag_Result;
|
||||
param->Variable.param_value = param_value;
|
||||
param->Variable.field_group_index = field_group_index;
|
||||
array_add(&variables, param);
|
||||
add_entity(ctx, scope, name, param);
|
||||
// NOTE(bill): Removes `declared but not used` when using -vet
|
||||
|
||||
Reference in New Issue
Block a user