mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52:22 -07:00
static variable declarations (Experimental)
This commit is contained in:
@@ -1667,6 +1667,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
if (!is_blank_ident(str)) {
|
||||
found = scope_lookup_current(ctx->scope, str);
|
||||
new_name_count += 1;
|
||||
} else if (vd->is_static) {
|
||||
error(name, "'static' is now allowed to be applied to '_'");
|
||||
}
|
||||
if (found == nullptr) {
|
||||
entity = alloc_entity_variable(ctx->scope, token, nullptr, false);
|
||||
@@ -1678,6 +1680,9 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
entity->Variable.is_foreign = true;
|
||||
entity->Variable.foreign_library_ident = fl;
|
||||
}
|
||||
if (vd->is_static) {
|
||||
entity->flags |= EntityFlag_Static;
|
||||
}
|
||||
} else {
|
||||
TokenPos pos = found->token.pos;
|
||||
error(token,
|
||||
@@ -1780,6 +1785,17 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
||||
} else {
|
||||
map_set(fp, key, e);
|
||||
}
|
||||
} else if (e->flags & EntityFlag_Static) {
|
||||
if (vd->values.count > 0) {
|
||||
if (entity_count != vd->values.count) {
|
||||
error(e->token, "A static variable declaration with a default value must be constant");
|
||||
} else {
|
||||
Ast *value = vd->values[i];
|
||||
if (value->tav.mode != Addressing_Constant) {
|
||||
error(e->token, "A static variable declaration with a default value must be constant");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add_entity(ctx->checker, ctx->scope, e->identifier, e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user