mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52: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
|
||||
|
||||
+2
-1
@@ -15,7 +15,7 @@ struct OdinDocVersionType {
|
||||
|
||||
#define OdinDocVersionType_Major 0
|
||||
#define OdinDocVersionType_Minor 2
|
||||
#define OdinDocVersionType_Patch 2
|
||||
#define OdinDocVersionType_Patch 3
|
||||
|
||||
struct OdinDocHeaderBase {
|
||||
u8 magic[8];
|
||||
@@ -185,6 +185,7 @@ struct OdinDocEntity {
|
||||
u32 reserved_for_init;
|
||||
OdinDocString comment;
|
||||
OdinDocString docs;
|
||||
i32 field_group_index;
|
||||
OdinDocEntityIndex foreign_library;
|
||||
OdinDocString link_name;
|
||||
OdinDocArray<OdinDocAttribute> attributes;
|
||||
|
||||
+16
-4
@@ -512,10 +512,16 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
|
||||
doc_type.entities = odin_doc_add_entity_as_slice(w, type->Named.type_name);
|
||||
break;
|
||||
case Type_Generic:
|
||||
doc_type.kind = OdinDocType_Generic;
|
||||
doc_type.name = odin_doc_write_string(w, type->Generic.entity->token.string);
|
||||
if (type->Generic.specialized) {
|
||||
doc_type.types = odin_doc_type_as_slice(w, type->Generic.specialized);
|
||||
{
|
||||
String name = type->Generic.name;
|
||||
if (type->Generic.entity) {
|
||||
name = type->Generic.entity->token.string;
|
||||
}
|
||||
doc_type.kind = OdinDocType_Generic;
|
||||
doc_type.name = odin_doc_write_string(w, name);
|
||||
if (type->Generic.specialized) {
|
||||
doc_type.types = odin_doc_type_as_slice(w, type->Generic.specialized);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Type_Pointer:
|
||||
@@ -810,6 +816,7 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) {
|
||||
|
||||
OdinDocEntityKind kind = OdinDocEntity_Invalid;
|
||||
u32 flags = 0;
|
||||
i32 field_group_index = -1;
|
||||
|
||||
switch (e->kind) {
|
||||
case Entity_Invalid: kind = OdinDocEntity_Invalid; break;
|
||||
@@ -839,6 +846,10 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) {
|
||||
if (init_expr == nullptr) {
|
||||
init_expr = e->Variable.init_expr;
|
||||
}
|
||||
field_group_index = e->Variable.field_group_index;
|
||||
break;
|
||||
case Entity_Constant:
|
||||
field_group_index = e->Constant.field_group_index;
|
||||
break;
|
||||
case Entity_Procedure:
|
||||
if (e->Procedure.is_foreign) { flags |= OdinDocEntityFlag_Foreign; }
|
||||
@@ -883,6 +894,7 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) {
|
||||
doc_entity.init_string = init_string;
|
||||
doc_entity.comment = odin_doc_comment_group_string(w, comment);
|
||||
doc_entity.docs = odin_doc_comment_group_string(w, docs);
|
||||
doc_entity.field_group_index = field_group_index;
|
||||
doc_entity.foreign_library = 0; // Set later
|
||||
doc_entity.link_name = odin_doc_write_string(w, link_name);
|
||||
if (e->decl_info != nullptr) {
|
||||
|
||||
@@ -160,10 +160,12 @@ struct Entity {
|
||||
ExactValue value;
|
||||
ParameterValue param_value;
|
||||
u32 flags;
|
||||
i32 field_group_index;
|
||||
} Constant;
|
||||
struct {
|
||||
Ast *init_expr; // only used for some variables within procedure bodies
|
||||
i32 field_index;
|
||||
i32 field_group_index;
|
||||
|
||||
ParameterValue param_value;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user