aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-12-28 13:31:06 +0000
committergingerBill <bill@gingerbill.org>2018-12-28 13:31:06 +0000
commita240a3d14660f6b33f839a3ebf142e20aac3e80a (patch)
treea32aea3ab5929ca1bda8c54cf839a0a956bc5225 /src/check_stmt.cpp
parent775f1e2c959e0db488615a44d30be3a59d371b08 (diff)
`static` variable declarations (Experimental)
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 811f59907..b6e0a7f58 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -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);
}