mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-31 18:32:12 +00:00
Cleanup attribute handling
This commit is contained in:
@@ -1673,7 +1673,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
c->context.foreign_context.default_cc = ProcCC_CDecl;
|
||||
}
|
||||
|
||||
check_foreign_block_decl_attributes(c, fb);
|
||||
check_decl_attributes(c, fb->attributes, foreign_block_decl_attribute, nullptr);
|
||||
|
||||
for_array(i, fb->decls) {
|
||||
AstNode *decl = fb->decls[i];
|
||||
@@ -1692,59 +1692,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count);
|
||||
isize entity_count = 0;
|
||||
|
||||
if (vd->attributes.count > 0) {
|
||||
StringSet set = {};
|
||||
string_set_init(&set, heap_allocator());
|
||||
defer (string_set_destroy(&set));
|
||||
|
||||
for_array(i, vd->attributes) {
|
||||
AstNode *attr = vd->attributes[i];
|
||||
if (attr->kind != AstNode_Attribute) continue;
|
||||
for_array(j, attr->Attribute.elems) {
|
||||
AstNode *elem = attr->Attribute.elems[j];
|
||||
String name = {};
|
||||
AstNode *value = nullptr;
|
||||
|
||||
switch (elem->kind) {
|
||||
case_ast_node(i, Ident, elem);
|
||||
name = i->token.string;
|
||||
case_end;
|
||||
case_ast_node(fv, FieldValue, elem);
|
||||
GB_ASSERT(fv->field->kind == AstNode_Ident);
|
||||
name = fv->field->Ident.token.string;
|
||||
value = fv->value;
|
||||
case_end;
|
||||
default:
|
||||
error(elem, "Invalid attribute element");
|
||||
continue;
|
||||
}
|
||||
|
||||
ExactValue ev = {};
|
||||
if (value != nullptr) {
|
||||
Operand op = {};
|
||||
check_expr(c, &op, value);
|
||||
if (op.mode != Addressing_Constant) {
|
||||
error(value, "An attribute element must be constant");
|
||||
} else {
|
||||
ev = op.value;
|
||||
}
|
||||
}
|
||||
|
||||
if (string_set_exists(&set, name)) {
|
||||
error(elem, "Previous declaration of `%.*s`", LIT(name));
|
||||
continue;
|
||||
} else {
|
||||
string_set_add(&set, name);
|
||||
}
|
||||
|
||||
if (name == "thread_local") {
|
||||
error(elem, "Variable within a procedure cannot be thread local");
|
||||
} else {
|
||||
error(elem, "Unknown attribute element name `%.*s`", LIT(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for_array(i, vd->names) {
|
||||
AstNode *name = vd->names[i];
|
||||
@@ -1815,6 +1762,11 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
if (e->type == nullptr) {
|
||||
e->type = init_type;
|
||||
}
|
||||
|
||||
|
||||
AttributeContext ac = {};
|
||||
ac.entity = e;
|
||||
check_decl_attributes(c, vd->attributes, var_decl_attribute, &ac);
|
||||
}
|
||||
|
||||
check_arity_match(c, vd);
|
||||
|
||||
Reference in New Issue
Block a user