From 9adec628c1c6b3d24f7a8642bbf5c0c84586d161 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 14 Apr 2021 17:15:28 +0100 Subject: Add `@(cold)` attribute to procedure declarations --- src/entity.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/entity.cpp') diff --git a/src/entity.cpp b/src/entity.cpp index 2786fcc6d..a27b7cb37 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -32,7 +32,7 @@ String const entity_strings[] = { #undef ENTITY_KIND }; -enum EntityFlag : u32 { +enum EntityFlag : u64 { EntityFlag_Visited = 1<<0, EntityFlag_Used = 1<<1, EntityFlag_Using = 1<<2, @@ -63,12 +63,13 @@ enum EntityFlag : u32 { EntityFlag_AutoCast = 1<<22, EntityFlag_Disabled = 1<<24, + EntityFlag_Cold = 1<<25, // procedure is rarely called - EntityFlag_Test = 1<<25, + EntityFlag_Test = 1<<30, }; -enum EntityState { +enum EntityState : u32 { EntityState_Unresolved = 0, EntityState_InProgress = 1, EntityState_Resolved = 2, @@ -98,7 +99,7 @@ struct ParameterValue { struct Entity { EntityKind kind; u64 id; - u32 flags; + u64 flags; EntityState state; Token token; Scope * scope; -- cgit v1.2.3 From 3baddd4116e84c4f9175f42a074f3d2599aa4979 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 18 Apr 2021 20:13:20 +0100 Subject: Improve `init_string` determination for constants --- src/check_type.cpp | 3 +++ src/docs_writer.cpp | 20 +++++++++++++++++++- src/entity.cpp | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) (limited to 'src/entity.cpp') diff --git a/src/check_type.cpp b/src/check_type.cpp index de81592c8..39fea75db 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -731,6 +731,7 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast Ast *field = et->fields[i]; Ast *ident = nullptr; Ast *init = nullptr; + u32 entity_flags = 0; if (field->kind == Ast_FieldValue) { ast_node(fv, FieldValue, field); if (fv->field == nullptr || fv->field->kind != Ast_Ident) { @@ -764,6 +765,7 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast } } else { iota = exact_binary_operator_value(Token_Add, iota, exact_value_i64(1)); + entity_flags |= EntityConstantFlag_ImplicitEnumValue; } @@ -800,6 +802,7 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast e->identifier = ident; e->flags |= EntityFlag_Visited; e->state = EntityState_Resolved; + e->Constant.flags |= entity_flags; if (scope_lookup_current(ctx->scope, name) != nullptr) { error(ident, "'%.*s' is already declared in this enumeration", LIT(name)); diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index b5a9161dd..57bc4ec66 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -831,13 +831,31 @@ OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e) { break; } + OdinDocString init_string = {}; + if (init_expr) { + init_string = odin_doc_expr_string(w, init_expr); + } else { + if (e->kind == Entity_Constant) { + if (e->Constant.flags & EntityConstantFlag_ImplicitEnumValue) { + init_string = {}; // Blank + } else if (e->Constant.param_value.original_ast_expr) { + init_string = odin_doc_expr_string(w, e->Constant.param_value.original_ast_expr); + } else { + init_string = odin_doc_write_string(w, make_string_c(exact_value_to_string(e->Constant.value))); + } + } else if (e->kind == Entity_Variable) { + if (e->Variable.param_expr) { + init_string = odin_doc_expr_string(w, e->Variable.param_expr); + } + } + } doc_entity.kind = kind; doc_entity.flags = flags; doc_entity.pos = odin_doc_token_pos_cast(w, e->token.pos); doc_entity.name = odin_doc_write_string(w, e->token.string); doc_entity.type = 0; // Set later - doc_entity.init_string = odin_doc_expr_string(w, init_expr); + 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.foreign_library = 0; // Set later diff --git a/src/entity.cpp b/src/entity.cpp index a27b7cb37..3926678fd 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -93,7 +93,9 @@ struct ParameterValue { }; }; - +enum EntityConstantFlags : u32 { + EntityConstantFlag_ImplicitEnumValue = 1<<0, +}; // An Entity is a named "thing" in the language struct Entity { @@ -126,6 +128,7 @@ struct Entity { struct { ExactValue value; ParameterValue param_value; + u32 flags; } Constant; struct { Ast *init_expr; // only used for some variables within procedure bodies -- cgit v1.2.3