mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-22 14:25:21 +00:00
Merge pull request #5558 from odin-lang/bill/init-fini-changes
`@(init)` & `@(finit)` Changes.
This commit is contained in:
@@ -1851,6 +1851,12 @@ gb_internal void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d,
|
||||
c.scope = d->scope;
|
||||
c.decl = d;
|
||||
c.type_level = 0;
|
||||
c.curr_proc_calling_convention = ProcCC_Contextless;
|
||||
|
||||
auto prev_flags = c.scope->flags;
|
||||
defer (c.scope->flags = prev_flags);
|
||||
c.scope->flags &= ~ScopeFlag_ContextDefined;
|
||||
|
||||
|
||||
e->parent_proc_decl = c.curr_proc_decl;
|
||||
e->state = EntityState_InProgress;
|
||||
|
||||
@@ -8169,8 +8169,12 @@ gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *c
|
||||
if (pt->kind == Type_Proc && pt->Proc.calling_convention == ProcCC_Odin) {
|
||||
if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
|
||||
ERROR_BLOCK();
|
||||
error(call, "'context' has not been defined within this scope, but is required for this procedure call");
|
||||
error_line("\tSuggestion: 'context = runtime.default_context()'");
|
||||
if (c->scope->flags & ScopeFlag_File) {
|
||||
error(call, "Procedures requiring a 'context' cannot be called at the global scope");
|
||||
} else {
|
||||
error(call, "'context' has not been defined within this scope, but is required for this procedure call");
|
||||
error_line("\tSuggestion: 'context = runtime.default_context()'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2675,6 +2675,10 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
|
||||
is_init = false;
|
||||
}
|
||||
|
||||
if (t->Proc.calling_convention != ProcCC_Contextless) {
|
||||
error(e->token, "@(init) procedures must be declared as \"contextless\"");
|
||||
}
|
||||
|
||||
if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
|
||||
error(e->token, "@(init) procedures must be declared at the file scope");
|
||||
is_init = false;
|
||||
@@ -2689,6 +2693,7 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
|
||||
error(e->token, "An @(init) procedure must not use a blank identifier as its name");
|
||||
}
|
||||
|
||||
|
||||
if (is_init) {
|
||||
add_dependency_to_set(c, e);
|
||||
array_add(&c->info.init_procedures, e);
|
||||
@@ -2706,6 +2711,10 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
|
||||
is_fini = false;
|
||||
}
|
||||
|
||||
if (t->Proc.calling_convention != ProcCC_Contextless) {
|
||||
error(e->token, "@(fini) procedures must be declared as \"contextless\"");
|
||||
}
|
||||
|
||||
if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
|
||||
error(e->token, "@(fini) procedures must be declared at the file scope");
|
||||
is_fini = false;
|
||||
|
||||
Reference in New Issue
Block a user