aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-02-23 22:17:27 +0000
committergingerBill <bill@gingerbill.org>2019-02-23 22:17:27 +0000
commita9ab90bd2488783c3523fa30315f9754937fd52e (patch)
tree17c7e5398a7b95f106ccece88f709c0887750837 /src/check_stmt.cpp
parente551d2b25ea39afb95f7b8ee4309ef0cc8b502b8 (diff)
Make `static` an attribute rather than a keyword prefix
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 3262aea5d..c861cfdf3 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -1665,8 +1665,6 @@ 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,9 +1676,6 @@ 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,
@@ -1744,6 +1739,16 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
if (ac.link_name.len > 0) {
e->Variable.link_name = ac.link_name;
}
+
+ e->flags &= ~EntityFlag_Static;
+ if (ac.is_static) {
+ String name = e->token.string;
+ if (name == "_") {
+ error(e->token, "The 'static' attribute is not allowed to be applied to '_'");
+ } else {
+ e->flags |= EntityFlag_Static;
+ }
+ }
}
check_arity_match(ctx, vd);
@@ -1751,6 +1756,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
for (isize i = 0; i < entity_count; i++) {
Entity *e = entities[i];
+
if (e->Variable.is_foreign) {
if (vd->values.count > 0) {
error(e->token, "A foreign variable declaration cannot have a default value");
@@ -1842,6 +1848,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
}
}
}
+
} else {
// constant value declaration
// NOTE(bill): Check `_` declarations