diff options
| author | gingerBill <bill@gingerbill.org> | 2017-11-04 10:53:47 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2017-11-04 10:53:47 +0000 |
| commit | 04b917a60aef2b60c6580899d191913004dbb2af (patch) | |
| tree | 88f674cdc19223e9d2fedf0ce5efb21fabd2092c /src/checker.cpp | |
| parent | e6c99cd2892cb34beaedfef0c8a786e2e0ef654e (diff) | |
More code clean up
Diffstat (limited to 'src/checker.cpp')
| -rw-r--r-- | src/checker.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/checker.cpp b/src/checker.cpp index 0ef3de9fd..a10b503b4 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1863,18 +1863,22 @@ struct AttributeContext { String link_name; String link_prefix; bool link_prefix_overridden; - Entity *entity; isize init_expr_list_count; + String thread_local_model; }; +AttributeContext make_attribute_context(String link_prefix) { + AttributeContext ac = {}; + ac.link_prefix = link_prefix; + return ac; +} + #define DECL_ATTRIBUTE_PROC(_name) bool _name(Checker *c, AstNode *elem, String name, ExactValue value, AttributeContext *ac) typedef DECL_ATTRIBUTE_PROC(DeclAttributeProc); void check_decl_attributes(Checker *c, Array<AstNode *> attributes, DeclAttributeProc *proc, AttributeContext *ac); - - DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { if (name == "default_calling_convention") { if (value.kind == ExactValue_String) { @@ -1905,8 +1909,6 @@ DECL_ATTRIBUTE_PROC(foreign_block_decl_attribute) { return false; } - - DECL_ATTRIBUTE_PROC(proc_decl_attribute) { if (name == "link_name") { if (value.kind == ExactValue_String) { @@ -1936,11 +1938,7 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) { } DECL_ATTRIBUTE_PROC(var_decl_attribute) { - GB_ASSERT(ac->entity != nullptr); - Entity *e = ac->entity; - GB_ASSERT(e->kind == Entity_Variable); - - if (!e->scope->is_file) { + if (c->context.curr_proc_decl != nullptr) { error(elem, "Only a variable at file scope can have a `%.*s`", LIT(name)); return true; } @@ -1971,14 +1969,16 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) { } else if (name == "thread_local") { if (ac->init_expr_list_count > 0) { error(elem, "A thread local variable declaration cannot have initialization values"); + } else if (c->context.foreign_context.curr_library || c->context.foreign_context.in_export) { + error(elem, "A foreign block variable cannot be thread local"); } else if (value.kind == ExactValue_Invalid) { - e->Variable.thread_local_model = str_lit("default"); + ac->thread_local_model = str_lit("default"); } else if (value.kind == ExactValue_String) { String model = value.value_string; if (model == "localdynamic" || model == "initialexec" || model == "localexec") { - e->Variable.thread_local_model = model; + ac->thread_local_model = model; } else { error(elem, "Invalid thread local model `%.*s`", LIT(model)); } @@ -1992,6 +1992,7 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) { + #include "check_expr.cpp" #include "check_type.cpp" #include "check_decl.cpp" |