From e6c99cd2892cb34beaedfef0c8a786e2e0ef654e Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 4 Nov 2017 10:26:56 +0000 Subject: Cleanup attribute handling --- src/check_stmt.cpp | 60 ++++++------------------------------------------------ 1 file changed, 6 insertions(+), 54 deletions(-) (limited to 'src/check_stmt.cpp') diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index c0e336149..162a87994 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -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); -- cgit v1.2.3