mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-03 09:14:38 +00:00
Fix link_name overriding
This commit is contained in:
@@ -429,9 +429,9 @@ void init_entity_foreign_library(Checker *c, Entity *e) {
|
||||
}
|
||||
}
|
||||
|
||||
String handle_link_name(Checker *c, Token token, String link_name, String link_prefix, bool link_prefix_overridden) {
|
||||
String handle_link_name(Checker *c, Token token, String link_name, String link_prefix) {
|
||||
if (link_prefix.len > 0) {
|
||||
if (link_name.len > 0 && !link_prefix_overridden) {
|
||||
if (link_name.len > 0) {
|
||||
error(token, "`link_name` and `link_prefix` cannot be used together");
|
||||
} else {
|
||||
isize len = link_prefix.len + token.string.len;
|
||||
@@ -485,7 +485,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
|
||||
}
|
||||
|
||||
|
||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix, ac.link_prefix_overridden);
|
||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
|
||||
|
||||
if (d->scope->file != nullptr && e->token.string == "main") {
|
||||
if (pt->param_count != 0 ||
|
||||
@@ -635,7 +635,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
|
||||
check_decl_attributes(c, decl->attributes, var_decl_attribute, &ac);
|
||||
}
|
||||
|
||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix, ac.link_prefix_overridden);
|
||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
|
||||
e->Variable.thread_local_model = ac.thread_local_model;
|
||||
|
||||
String context_name = str_lit("variable declaration");
|
||||
|
||||
@@ -1762,7 +1762,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
if (e->type == nullptr) {
|
||||
e->type = init_type;
|
||||
}
|
||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix, ac.link_prefix_overridden);
|
||||
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
|
||||
e->Variable.thread_local_model = ac.thread_local_model;
|
||||
|
||||
if (ac.link_name.len > 0) {
|
||||
|
||||
@@ -1862,7 +1862,6 @@ void check_procedure_overloading(Checker *c, Entity *e) {
|
||||
struct AttributeContext {
|
||||
String link_name;
|
||||
String link_prefix;
|
||||
bool link_prefix_overridden;
|
||||
isize init_expr_list_count;
|
||||
String thread_local_model;
|
||||
};
|
||||
@@ -1922,9 +1921,6 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
|
||||
return true;
|
||||
} else if (name == "link_prefix") {
|
||||
if (value.kind == ExactValue_String) {
|
||||
if (ac->link_prefix.len > 0) {
|
||||
ac->link_prefix_overridden = true;
|
||||
}
|
||||
ac->link_prefix = value.value_string;
|
||||
if (!is_foreign_name_valid(ac->link_prefix)) {
|
||||
error(elem, "Invalid link prefix: %.*s", LIT(ac->link_prefix));
|
||||
@@ -1955,9 +1951,6 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) {
|
||||
return true;
|
||||
} else if (name == "link_prefix") {
|
||||
if (value.kind == ExactValue_String) {
|
||||
if (ac->link_prefix.len > 0) {
|
||||
ac->link_prefix_overridden = true;
|
||||
}
|
||||
ac->link_prefix = value.value_string;
|
||||
if (!is_foreign_name_valid(ac->link_prefix)) {
|
||||
error(elem, "Invalid link prefix: %.*s", LIT(ac->link_prefix));
|
||||
@@ -2002,6 +1995,12 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) {
|
||||
|
||||
void check_decl_attributes(Checker *c, Array<AstNode *> attributes, DeclAttributeProc *proc, AttributeContext *ac) {
|
||||
if (attributes.count == 0) return;
|
||||
|
||||
String original_link_prefix = {};
|
||||
if (ac) {
|
||||
original_link_prefix = ac->link_prefix;
|
||||
}
|
||||
|
||||
StringSet set = {};
|
||||
string_set_init(&set, heap_allocator());
|
||||
defer (string_set_destroy(&set));
|
||||
@@ -2051,6 +2050,15 @@ void check_decl_attributes(Checker *c, Array<AstNode *> attributes, DeclAttribut
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ac) {
|
||||
if (ac->link_prefix.text == original_link_prefix.text) {
|
||||
if (ac->link_name.len > 0) {
|
||||
ac->link_prefix.text = nullptr;
|
||||
ac->link_prefix.len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user